Create a widget that allows text input

Complete code: class My_Widget_Avatar extends WP_Widget { function My_Widget_Avatar() { $widget_ops = array( ‘classname’ => ‘widget_avatar’, ‘description’ => __( “My Avatar Widget” ) ); $this->WP_Widget(‘my_avatar’, __(‘My Avatar’), $widget_ops); } function widget( $args, $instance ) { extract($args); $text = apply_filters( ‘widget_text’, $instance[‘text’], $instance ); echo $before_widget; ?> <div class=”textwidget”> <div class=”avatar”> <div class=”avatartext”> <p><?php echo $text; … Read more

How/where is the global variable $wp_registered_widgets filled?

As you can see here, $wp_registered_widgets is defined in wp-includes/widgets.php (as expected). You should be able to debug it by doing something like this: function yoast_print_active_widgets() { global $wp_registered_widgets; echo ‘<pre>’.print_r( $wp_registered_widgets, 1 ).'</pre>’; } add_action(‘init’,’yoast_print_active_widgets’); Then you could loop through the different stages, from init, to send_headers to wp_head and see where stuff goes … Read more

Custom dashboard widget search box

The following will do, although it redirects to the Posts listing page /wp-admin/edit.php… Also included, search boxes for Pages and CPTs. Code /** * PLEASE NOTE THAT THE FOLLOWING CODE DOESN’T HAVE ANY SANITIZATION or NONCE methods */ add_action(‘wp_dashboard_setup’, ‘wpse_58520_dashboard_search_widget’); function wpse_58520_dashboard_search_widget() { wp_add_dashboard_widget( ‘wpse_54742_active_site_plugins’, __( ‘Search Posts/Pages/CPTs’ ), ‘wpse_58520_make_dashboard_search_widget’ ); } function wpse_58520_make_dashboard_search_widget() { … Read more

Show widget when not using SSL

WordPress has built-in function for this purpose – is_ssl(). http://codex.wordpress.org/Function_Reference/is_ssl So, you should edit this widget and put something like if ( is_ssl() ) { } else { echo ‘you should use ssl’; }

Radio buttons in widget not saving

Got it, it turns out… The label for each radio button must be the field id / variable, in my example is ‘radio_buttons’ The IF statement for each radio button must refer to this same ID – $radio_buttons === ‘radio_option_1’ & $radio_buttons === ‘radio_option_2’ My new code which works is… <p> <label for=”<?php echo $this->get_field_id(‘text_area’); … Read more

How to add new sidebar widget area to child theme?

Well, this is what worked for me. In my functions.php file I put the following code: function header_widgets_init() { register_sidebar( array( ‘name’ => ‘Header Sidebar’, ‘id’ => ‘header_sidebar’, ‘before_widget’ => ‘<aside class=”widget %2$s”>’, ‘after_widget’ => ‘</aside>’, ‘before_title’ => ‘<h2 class=”widget-title”>’, ‘after_title’ => ‘</h2>’, ) ); } add_action( ‘widgets_init’, ‘header_widgets_init’ ); …and in my header.php file … Read more

Check if widget is active

According to the Codex, you may add some additional parameters to is_active_widget() to make it work. So try this one: if ( is_active_widget(false, false, ‘Search_Widget_Page’, true) ) { // check if search widget is used // Do not display this widget } else { // Display this widget }

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)