Adding a widget programmatically

Because your code is just like prototype, it doesn’t display anything. That’s why your are not seeing anything in dashboard. /** * Adds Foo_Widget widget. */ class Foo_Widget extends WP_Widget { /** * Register widget with WordPress. */ function __construct() { parent::__construct( ‘foo_widget’, // Base ID esc_html__( ‘Widget Title’, ‘text_domain’ ), // Name array( ‘description’ … Read more

Calling static method in the Widget Class

Try this instead: $gloabl $myxclass; $myxclass = new Xwidget(); add_action( ‘xxx_followers’, array(&$myxclass, “cron_addB” ) ); or add_action(‘xxx_followers’, “init_xclass_and_cron”); function init_xclass_and_cron() { $myxclass = new Xwidget(); $myxclass->cron_addB(); }

Use Media upload in custom widget on wordpress 3.5

Check if this works for you: Put this code in jQuery(document).ready( function(){ function media_upload( button_class) { var _custom_media = true, _orig_send_attachment = wp.media.editor.send.attachment; jQuery(‘body’).on(‘click’,button_class, function(e) { var button_id =’#’+jQuery(this).attr(‘id’); /* console.log(button_id); */ var self = jQuery(button_id); var send_attachment_bkp = wp.media.editor.send.attachment; var button = jQuery(button_id); var id = button.attr(‘id’).replace(‘_button’, ”); _custom_media = true; wp.media.editor.send.attachment = function(props, … Read more

Randomize widgets displayed in my sidebar [duplicate]

I couldn’t see that the answers in the possible duplicate link are using the sidebars_widgets filter, so let me add it here as another possibility: The following assumes you use dynamic_sidebar() function to display your sidebars/widgets or just anything that calls the wp_get_sidebars_widgets() function. Randomize widgets: This code snippet displays all the widgets in a … Read more

Is it possible to remove the filter from 4.8 text widget?

We now have a new filter widget_text_content introduced in 4.8 src, with the following default callbacks: add_filter( ‘widget_text_content’, ‘capital_P_dangit’, 11 ); add_filter( ‘widget_text_content’, ‘wptexturize’ ); add_filter( ‘widget_text_content’, ‘convert_smilies’, 20 ); add_filter( ‘widget_text_content’, ‘wpautop’ ); that are applied if the filter settings, for the widget instance, is set to ‘content’. When you remove the filter settings … Read more

How to build widget with arrays inside arrays?

get_field_id prepare prefix for field id, within one widget instance it’s always the same. Your form fields probably look similar to these: // — $element[0] — // $field[icontxt] <input class=”widefat” id=”widget-baseid-instance-inner_elements” name=”widget-baseid[instance][inner_elements][0]” value=”%4$s”> // $field[iconlnk] <input class=”widefat” id=”widget-baseid-instance-inner_elements” name=”widget-baseid[instance][inner_elements][0]” value=”%4$s”> //$field[iconlnktrgt] <input class=”widefat” id=”widget-baseid-instance-inner_elements” name=”widget-baseid[instance][inner_elements][0]” value=”%4$s”> // — $element[1] — <input class=”widefat” id=”widget-baseid-instance-inner_elements” name=”widget-baseid[instance][inner_elements][1]” value=”%4$s”> … Read more

How to Validate Widget Input

If you are using the Widget API then declare your widget as a class which extends WP_Widget class and there you can define an upadte function where you can do your validation, the codex as a nice example of doing just that.

Determining a Widget Instance and Sidebar Location?

The widget_display_callback hook takes 3 arguments as we can see in /wp-includes/widgets.php: (line 180, WP 3.4.2) $instance = apply_filters(‘widget_display_callback’, $instance, $this, $args); So, to make a complete hook, the code is: // Priority = 10 // Arguments = 3 add_filter(‘widget_display_callback’, ‘wpse_57546_widget_display_callback’, 10, 3); // Using “$this” as an argument produces errors, // as it is … Read more