New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The instance was missing #52
Conversation
The widget's instance was missing on get_widget
thanks! |
Actually, i reverted this. The instance is taken care of here: https://github.com/WebDevStudios/CMB2-Snippet-Library/blob/master/widgets/widget-example.php#L174-L178 |
You're welcome! 2016-10-28 12:33 GMT-02:00 Justin Sternberg notifications@github.com:
|
What about with that change ^? |
I tested here and it still doesn't work. I only could get what i wanted with this change: 'instance' => $atts['instance'], 2016-10-28 13:47 GMT-02:00 Justin Sternberg notifications@github.com:
|
can you show me your code? |
Do you want me to create another pull request? My code is actually a little bit different and is not pretty :(. I'm using ';
// Title
$widget .= ( $instance['title'] ) ? $atts['before_title'] . esc_html(
$instance['title'] ) . $atts['after_title'] : '';
$taxonomies = $atts['instance'][self::META_TAXONOMIES];
$widget .= ' ';
// After widget hook
$widget .= $atts['after_widget'];
wp_cache_set( $atts['cache_id'], $widget, 'widget', WEEK_IN_SECONDS );
}
return $widget;
}
/**
- Update form values as they are saved.
*
- @param array $new_instance New settings for this instance as input by
the user.
- @param array $old_instance Old settings for this instance.
- @return array Settings to save or bool false to cancel saving.
_/
public function update( $new_instance, $old_instance ) {
$this->flush_widget_cache();
$sanitized = $this->cmb2( true )->get_sanitized_values( $new_instance );
return $sanitized;
}
/_*
- Back-end widget form with defaults.
*
- @param array $instance Current settings.
_/
public function form( $instance ) {
// If there are no settings, set up defaults
$this->_instance = wp_parse_args( (array) $instance, self::$defaults );
$cmb2 = $this->cmb2();
$cmb2->object_id( $this->option_name );
\CMB2_hookup::enqueue_cmb_css();
\CMB2_hookup::enqueue_cmb_js();
$cmb2->show_form();
?>
<style>
.cmb-th + .cmb-td{
float:none !important;
}
</style>
$this->option_name .'_box', // Option name is taken from the
WP_Widget class.
'hookup' => false,
'show_on' => array(
'key' => 'options-page', // Tells CMB2 to handle this as an option
'value' => array( $this->option_name )
),
), $this->option_name );
foreach ( $this->cmb2_fields as $field ) {
if ( ! $saving ) {
$field['id'] = $this->get_field_name( $field['id'] );
}
$field['default_cb'] = array( $this, 'default_cb' );
$cmb2->add_field( $field );
}
return $cmb2;
}
/_*
- Sets the field default, or the field value.
*
- @param array $field_args CMB2 field args array
- @param CMB2_Field $field CMB2 Field object.
*
- @return mixed Field value.
*/
public function default_cb( $field_args, $field ) {
return isset( $this->_instance[ $field->args( 'id_key' ) ] )
? $this->_instance[ $field->args( 'id_key' ) ]
: null;
}
}
2016-10-28 15:01 GMT-02:00 Justin Sternberg notifications@github.com:
> can you show me your code?
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> https://github.com//pull/52#issuecomment-256973570,
> or mute the thread
> https://github.com/notifications/unsubscribe-auth/AH0FfKeTObnvvNq8lZBQdWTZ-Qk6JHRrks5q4ipdgaJpZM4KjfEH
> .
';
foreach ($taxonomies as $key => $tax) {
$widget .=' ';
//$widget .= wpautop( wp_kses_post( $instance['desc'] ) );
//$widget .= '
'.custom_dropdown(array("width"=>"100%","tax_slug"=>$tax,
"show_option_all"=>get_taxonomy($tax)->labels->name)).'
';
}
$widget .='';
$widget .=' |
The widget's instance was missing on get_widget