Shortcode not working in Jetpack Top Posts & Pages widget

I’ve added [year] shortcode to some of my posts’ titles.

I used this in functions.php to enable this shortcode:

add_shortcode( 'year' , 'current_year' ); function current_year() {     $  year = date("Y");     return "$  year"; } 

I then added this too to enable shortcodes in widgets:

add_filter( 'widget_text', 'do_shortcode' ); 

But the shortcode doesn’t work in the post titles list shown by Top Posts & Pages widget by Jetpack.

How do I fix it?

Sidebar widget not partial refreshing for first widget on add and remove action

When you add the first widget in the sidebar it’s a refreshing customizer completely and not partial refreshing.

  • Go to Customizer
  • Go to the Widgets panel.
  • Remove all the widgets one by one.
  • At the last widget when you remove it, it refreshes the customizer.
  • When adding the first widget it again refreshes the customizer.
  • First onward, it partially refreshing the customizer as expected.

Please find the attached video for further reference: https://a.cl.ly/WnulD9r6

Is it the right behavior?

widget() method can’t access $instance variable WordPress

I followed a guide to create a WordPress plugin, which shows a youtube sub button on your page.

In the guide it works perfectly, but for some reason it doesn’t work for me.

This is my problem: When I var_dump($ instance) in widget() it prints out an empty array, but when I try to print_r($ instance) inside of my form() it prints out the correct information

Here is the widget file:

<?php  /**   * Adds Youtube_Subs widget.   */  class Youtube_Subs_Widget extends WP_Widget {    /**   * Register widget with WordPress.   */  function __construct() {    parent::__construct(      'youtubesubs_widget', // Base ID      esc_html__( 'YouTube Subs', 'mp_domain' ), // Name      array( 'description' => esc_html__( 'Widget to display YouTube subs', 'mp_domain' ), ) // Args    );  }    /**   * Front-end display of widget.   *   * @see WP_Widget::widget()   *   * @param array $  args     Widget arguments.   * @param array $  instance Saved values from database.   */  public function widget( $  args, $  instance ) {    echo $  args['before_widget']; // Whatever you want to display before widget (<div>, etc)    if ( ! empty( $  instance['title'] ) ) {      echo $  args['before_title'] . apply_filters( 'widget_title', $  instance['title'] ) . $  args['after_title'];    }     // Widget Content Output    var_dump($  instance);    // echo '<div class="g-ytsubscribe" data-channel="'.$  instance['channel'].'" data-layout="'.$  instance['layout'].'" data-count="'.$  instance['count'].'"></div>';      echo $  args['after_widget']; // Whatever you want to display after widget (</div>, etc)  }    /**   * Back-end widget form.   *   * @see WP_Widget::form()   *   * @param array $  instance Previously saved values from database.   */  public function form( $  instance ) {    $  title = (! empty( $  instance['title'] ) ? $  instance['title'] : esc_attr( 'YouTube Subs', 'mp_domain' ));      $  channel = (! empty( $  instance['channel'] ) ? $  instance['channel'] : esc_attr( 'techguyweb', 'mp_domain' ));      $  layout = (! empty( $  instance['layout'] ) ? $  instance['layout'] : esc_attr( 'default', 'mp_domain' ));      $  count = (! empty( $  instance['count'] ) ? $  instance['count'] : esc_attr( 'default', 'mp_domain' ));      ?>        <!-- TITLE -->    <p>      <label for="<?php echo esc_attr( $  this->get_field_id( 'title' ) ); ?>">        <?php esc_attr_e( 'Title:', 'mp_domain' ); ?>      </label>         <input         class="widefat"         id="<?php echo esc_attr( $  this->get_field_id( 'title' ) ); ?>"         name="<?php echo esc_attr( $  this->get_field_name( 'title' ) ); ?>"         type="text"         value="<?php echo esc_attr( $  title ); ?>">    </p>      <!-- CHANNEL -->    <p>      <label for="<?php echo esc_attr( $  this->get_field_id( 'channel' ) ); ?>">        <?php esc_attr_e( 'Channel:', 'mp_domain' ); ?>      </label>         <input         class="widefat"         id="<?php echo esc_attr( $  this->get_field_id( 'channel' ) ); ?>"         name="<?php echo esc_attr( $  this->get_field_name( 'channel' ) ); ?>"         type="text"         value="<?php echo esc_attr( $  channel ); ?>">    </p>      <!-- LAYOUT -->    <p>      <label for="<?php echo esc_attr( $  this->get_field_id( 'layout' ) ); ?>">        <?php esc_attr_e( 'Layout:', 'mp_domain' ); ?>      </label>         <select         class="widefat"         id="<?php echo esc_attr( $  this->get_field_id( 'layout' ) ); ?>"         name="<?php echo esc_attr( $  this->get_field_name( 'layout' ) ); ?>">        <option value="default" <?php echo ($  layout == 'default') ? 'selected' : ''; ?>>          Default        </option>        <option value="full" <?php echo ($  layout == 'full') ? 'selected' : ''; ?>>          Full        </option>      </select>    </p>      <!-- COUNT -->    <p>      <label for="<?php echo esc_attr( $  this->get_field_id( 'count' ) ); ?>">        <?php esc_attr_e( 'Count:', 'mp_domain' ); ?>      </label>         <select         class="widefat"         id="<?php echo esc_attr( $  this->get_field_id( 'count' ) ); ?>"         name="<?php echo esc_attr( $  this->get_field_name( 'count' ) ); ?>">        <option value="default" <?php echo ($  count == 'default') ? 'selected' : ''; ?>>          Default        </option>        <option value="hidden" <?php echo ($  count == 'hidden') ? 'selected' : ''; ?>>          Hidden        </option>      </select>    </p>    <?php       print_r($  instance);  }    /**   * Sanitize widget form values as they are saved.   *   * @see WP_Widget::update()   *   * @param array $  new_instance Values just sent to be saved.   * @param array $  old_instance Previously saved values from database.   *  * @return array Updated safe values to be saved.  */ public function update( $  new_instance, $  old_instance ) {   $  instance = $  old_instance;    $  instance['title'] = ( ! empty( $  new_instance['title'] ) ) ? strip_tags( $  new_instance['title'] ) : '';   $  instance['channel'] = ( ! empty( $  new_instance['channel'] ) ) ? strip_tags( $  new_instance['channel'] ) : '';   $  instance['layout'] = ( ! empty( $  new_instance['layout'] ) ) ? strip_tags( $  new_instance['layout'] ) : '';   $  instance['count'] = ( ! empty( $  new_instance['count'] ) ) ? strip_tags( $  new_instance['count'] ) :      '';         return $  instance;  } } 

I have this hooked up with my plugin file in where I register the widget:

 // Register Widget  function register_myplugin() {      register_widget('Youtube_Subs_Widget');  }   // Hook in function  add_action('widgets_init', 'register_myplugin'); 

I hope someone knows what is wrong and can help me correct my mistake, thanks in advance

Ajax contact form widget plugin data not insert in database

I have been working at this for weeks without success. I’ve figured out problem after problem with the code, but none of the corrections seem to fix my core problem. The form doesn’t insert anything into the database and I don’t know why. all my data’s passed in the ajax call but it doesn’t insert in the data in the database.

I’m new to ajax and to WordPress plugins so I might be missing something obvious. Please help me know where I am going wrong. Thanks in advance.

My widget form plugin code

public function widget( $  args, $  instance ) {       if ( ! isset( $  args['widget_id'] ) ) {          $  args['widget_id'] = $  this->id;                  }          $  title = ( ! empty( $  instance['title'] ) ) ? $  instance['title'] : __( 'Contact' );          $  title = apply_filters( 'widget_title', $  title, $  instance, $  this->id_base );                            ?>     <?php         if ( $  title ) {            echo '<h2 class="widget-title">'.$  args['before_title'] . $  title . $  args['after_title'].'</h2>';                    }        ?>      <form  class="form-group" method="POST" id="form" action="">         <label>Name</label><br>         <input class="form-control" type="text" id="name" name="name" ><br>         <label>Mobile</label><br>         <input type="text" class="form-control" id="mobileno" name="mobileno" required><br>         <label>Email</label><br>         <input class="form-control"  type="email" id="email" name="email" ><br>         <label>Message</label><br>         <textarea class="form-control" id="message" name="message"  maxlength="10" onKeyPress="lengthcheck()"></textarea><br><br>         <button  class="btn btn-warning" type="submit" id="submit">Send Message</button>     </form> <?php }    

This is my enqueue methods:

add_action( 'wp_enqueue_scripts', 'vs_con_enqueue_scripts' );  function vs_con_enqueue_scripts(){  wp_register_script(     'ajaxHandle',     plugins_url('valid.js', __FILE__),     array('jquery'),     false,     true   );  wp_enqueue_script( 'ajaxHandle');  wp_localize_script(     'ajaxHandle',     'ajax_object',     array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) )   );  wp_enqueue_style( 'bootstrap-style','https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' );  }   add_action( "wp_ajax_contact", "vs_contact_form" ); add_action( "wp_ajax_nopriv_contact", "vs_contact_form" );   function vs_contact_form(){     global $  wpdb;         $  name = $  _POST["name"];        $  email = $  _POST["email"];        $  mobileno = $  _POST["mobileno"];        $  messsage = $  _POST["messsage"];                $  tablename = $  wpdb->prefix.'contactdetails';        $  insert_row = $  wpdb->insert(           $  tablename,             array(                 'name' => $  name,                 'email' => $  email,                 'mobileno' => $  mobileno,                'messsage' => $  messsage             )          );            // if row inserted in table         if($  insert_row){            echo json_encode(array('res'=>true, 'message'=>__('Message Sent Successfully')));        }else{           echo json_encode(array('res'=>false, 'message'=>__('Something went wrong. Please try again later.')));        }        wp_die(); }  

Here this is my form submit jquery ajax call function

valid.js

jQuery(document).ready(function($  ){     $  ('form#form').on('submit', function(e){        e.preventDefault();        var name =jQuery('#name').val();        var email = jQuery('#email').val();        var mobileno = jQuery('#mobileno').val();        var message = jQuery('#message').val();        debugger;        var text;        if(name.length < 5){          text = "Please Enter valid Name";         alert(text);          return false;        }        if(isNaN(mobileno) || mobileno.length != 10){          text = "Please Enter valid mobileno Number";          alert(text);          return false;        }        if(email.indexOf("@") == -1 || email.length < 6){          text = "Please Enter valid Email";          alert(text);          return false;        }                $  .ajax({           url: ajax_object.ajaxurl,           type:"POST",           dataType:'json',           data: {              action:'contact',              name: name,              email: email,              mobileno: mobileno,              message: message         },   success: function(data){             if (data.res == true){                 alert(data.message);    // success message             }          }, error: function(data){             if (data.res == false){                 alert(data.message);    // success message             }            }        });     $  ('#form')[0].reset();       });     });  

please help me to find out where I am wrong?

Widget disappeared after updating widget_text directly in the wp_options table

I wanted to fix a typo in one of my widgets. I found that the following row in the wp_options table contains the text with the typo. I updated the option_value column with the fix but now, the widget has completely disappeared from the screen.

option_id, option_name, option_value, autoload 83,widget_text,"a:3:{i:2;a:3:{s:5:"title";s:16:"Location";s:4:"text";s:89:"Address";s:6:"filter";b:0;}i:3;a:3:{s:5:"title";s:0:"";s:4:"text";s:334:"<div class="attribution-text">Copyright text</div>";s:6:"filter";b:0;}s:12:"_multiwidget";i:1;}",yes 

I deleted the above row and refreshed the screen (to see if the old values come back), and now it has created this new row in the table

option_id, option_name, option_value, autoload '100000000000007', 'widget_text', 'a:1:{s:12:\"_multiwidget\";i:1;}', 'yes' 

Can someone help me bring back the widget’s text?

Note: I am looking to update entries directly in the database because the Appearance–> Customize got broken after a PHP version upgrade and can’t be accessed for a few days.

Woocommerce Filter Products by Price widget – filter by price in custom field

I have products with price per package in eshop. I also created custom field with product price per square meters. Products are sold only by package not by square meters, but on archive page I need filtering products by price per square meters. I unregistered WC_Widget_Price_Filter widget and registered modified version of that widget, which displays correct min and max prices in square meters in filter slider. I modified function price_filter_post_clauses to display correct products. Function is located in includes/class-wc-query.php.

public function price_filter_post_clauses( $  args, $  wp_query ) {     global $  wpdb;      // phpcs:ignore WordPress.Security.NonceVerification.Recommended     if ( ! $  wp_query->is_main_query() || ( ! isset( $  _GET['max_price'] ) && ! isset( $  _GET['min_price'] ) ) ) {         return $  args;     }      // phpcs:disable WordPress.Security.NonceVerification.Recommended     $  current_min_price = isset( $  _GET['min_price'] ) ? floatval( wp_unslash( $  _GET['min_price'] ) ) : 0;     $  current_max_price = isset( $  _GET['max_price'] ) ? floatval( wp_unslash( $  _GET['max_price'] ) ) : PHP_INT_MAX;     // phpcs:enable WordPress.Security.NonceVerification.Recommended      /**      * Adjust if the store taxes are not displayed how they are stored.      * Kicks in when prices excluding tax are displayed including tax.      */     if ( wc_tax_enabled() && 'incl' === get_option( 'woocommerce_tax_display_shop' ) && ! wc_prices_include_tax() ) {         $  tax_class = apply_filters( 'woocommerce_price_filter_widget_tax_class', '' ); // Uses standard tax class.         $  tax_rates = WC_Tax::get_rates( $  tax_class );          if ( $  tax_rates ) {             $  current_min_price -= WC_Tax::get_tax_total( WC_Tax::calc_inclusive_tax( $  current_min_price, $  tax_rates ) );             $  current_max_price -= WC_Tax::get_tax_total( WC_Tax::calc_inclusive_tax( $  current_max_price, $  tax_rates ) );         }     }      $  args['join']   = $  this->append_product_sorting_table_join( $  args['join'] );     $  args['where'] .= $  wpdb->prepare(         ' AND wc_product_meta_lookup.min_price >= %f AND wc_product_meta_lookup.max_price <= %f ',         $  current_min_price,         $  current_max_price     );     return $  args; } 

I modified sql in $ args[‘join’] and $ args[‘where’]. Is it possible to modify this function without modifying it directly?

Creating Conditional Fields in Elementor Custom Widget

How are conditional fields or field groups created in Elementor? I’ve not found anything in the documentation regarding conditional fields for widget development. A simple example of what I’d like to do is the following:

I have a dropdown:

    // Select Control     $  this->add_control(         'dropdown_Example',         [             'label' => __('Dropdown Example', 'vs'),             'type' => \Elementor\Controls_Manager::SELECT,             'options' => [                 'default' => __('Default', 'vs'),                 'yes' => __('Yes', 'vs'),                 'no' => __('No', 'vs'),             ],             'default' => 'default',         ]     ); 

If the answer in the dropdown is yes, then show text field 1:

    // Text 1     $  this->add_control(         'text1',         [             'label' => __('Text1', 'vs'),             'type' => Controls_Manager::TEXT,         ]     ); 

Else, show text field 2:

    // Text 2     $  this->add_control(         'text2',         [             'label' => __('Text2', 'vs'),             'type' => Controls_Manager::TEXT,         ]     ); 

Get category link to widget

I add this code and is working good, but open different category link, Any idea?

    $  category = get_the_category();  if($  category[0]){     echo '<p class="read-more-custom-widget">';     echo '<a href="'.get_category_link($  category[0]->term_id ).'"title="Read More">Read More &raquo;</a>';     echo '</p>'; } 

Trying to style Woocommerce sidebar Cart Widget

I have looked at length to find CSS that will change the background color, border radius and product info text color. I think this may not be a "mini cart". The price of the item, subtotal and View Cart / Checkout buttons follow the styling Ive done to the cart. I have successfully changed my product text color on my actual Cart page. So frustrating! Help is much appreciated.