Closed soyket closed 4 years ago
Does your widget include a WP_Editor field? If so, and if the editor is initialized with the 'media_buttons' setting set to true
, then the "Add Post Element" button will be automatically included there.
Hi! thanks for the quick replay ! And currently no . I just crated the widget because I saw that shortcode-ultimate has the widget system, which can be very useful time to time. They don't have the wp_editor , just a regular text area type widget with button on top . So following their code I came to this :
`<?php class Soykot_Widget extends WP_Widget { function __construct() { $widget_ops = array( 'classname' => 'theme-shortcode', 'description' => ( 'Theme Shotcode Widget', 'findarch' ) ); $control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'theme-shortcode' ); parent::construct( 'theme-shortcode', __( 'Theme Shortcodes', 'fidnarch' ), $widget_ops, $control_ops ); }
public static function register() {
register_widget( 'Soykot_Widget' );
}
function widget( $args, $instance ) {
extract( $args );
$title = apply_filters( 'widget_title', $instance['title'] );
$content = $instance['content'];
echo $before_widget;
if ( $title ) echo $before_title . $title . $after_title;
echo '<div class="textwidget">' . do_shortcode( $content ) . '</div>';
echo $after_widget;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['content'] = $new_instance['content'];
return $instance;
}
function form( $instance ) {
$defaults = array(
'title' => __( 'Soykot Widget', 'findarch' ),
'content' => ''
);
$instance = wp_parse_args( ( array ) $instance, $defaults );
?>
<p>
<?php
Shortcode_UI::action_media_buttons(10);
?>
<br/>
<textarea name="<?php echo $this->get_field_name( 'content' ); ?>" id="<?php echo $this->get_field_id( 'content' ); ?>" rows="7" class="widefat" style="margin-top:10px"><?php echo $instance['content']; ?>
</textarea>
</p>
<?php
}
}
add_action( 'widgets_init', array( 'Soykot_Widget', 'register' ) ); `
Now I have a field on the widget but : Deprecated: Non-static method Shortcode_UI::action_media_buttons() should not be called statically, assuming $this from incompatible context in C:\xampp\apps\wordpress\htdocs\wp-content\themes\findarch\inc\plugins\shortcodes\widget.php on line 49 Add Post Element -> this button appears but doesn't work
Hmm. I think this will not work very smoothly because:
In your code, you're using "10" as the editor ID which is passed to the Shortcake "Add Post Element" media buttons. Where did you get that ID from? It should be the $editor_id as passed to wp_editor().
The issue is due to elementor dequeuing things in it's text editor.
Hi! So i am trying to create a custom widget and I want to be able to add this button there , so that people can insert the shortcode directly in there ! How can I do that ? The shortcode-ultimate has something like this to load a button on their widget area : <?php Su_Generator::button( array( 'target' => $this->get_field_id( 'content' ) ) ); ?>
Need urgent help