Advertisement
Guest User

Widget

a guest
Jan 24th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.85 KB | None | 0 0
  1. <?php
  2. // Register and load the widget
  3. add_action( 'widgets_init', 'wpb_load_widget' );
  4. function wpb_load_widget() {
  5.     register_widget( 'featured_product_widget' );
  6. }
  7.  
  8. // Creating the widget
  9. class featured_product_widget extends WP_Widget {
  10.     function __construct() {
  11.         parent::__construct(
  12.             // Base ID of your widget
  13.             'featured_product_widget',
  14.             // Widget name will appear in UI
  15.             __('Uitgelichte product', 'mediasoep'),
  16.             // Widget description
  17.             array( 'description' => __( 'Kies hier een product die je wilt tonen.', 'mediasoep' ), )
  18.         );
  19.     }
  20.  
  21.     /**
  22.     * Outputs the content of the widget
  23.     *
  24.     * @param array $args
  25.     * @param array $instance
  26.     */
  27.     public function widget( $args, $instance ) {
  28.         // Outputs the content of the widget
  29.         if ( ! isset( $args['widget_id'] ) ) {
  30.             $args['widget_id'] = $this->id;
  31.         }
  32.  
  33.         // Widget ID with prefix for use in ACF API functions
  34.         $widget_id = 'widget_' . $args['widget_id'];
  35.  
  36.         $product = get_field( 'product', $widget_id );
  37.  
  38.         echo $args['before_widget'];
  39.         echo '<pre>';
  40.         echo var_dump( $product );
  41.         echo '</pre>';
  42.         echo $args['after_widget'];
  43.     }
  44.  
  45.     /**
  46.      * Outputs the options form on admin
  47.      *
  48.      * @param array $instance The widget options
  49.      */
  50.     public function form( $instance ) {
  51.         // Outputs the options form on admin
  52.     }
  53.  
  54.     /**
  55.      * Processing widget options on save
  56.      *
  57.      * @param array $new_instance The new options
  58.      * @param array $old_instance The previous options
  59.      *
  60.      * @return array
  61.      */
  62.     public function update( $new_instance, $old_instance ) {
  63.         // Processes widget options to be saved
  64.     }
  65. } // Class featured_product_widget ends here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement