| @@ -1,67 +1,67 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -namespace LearnPress\Widgets; | |
| 4 | - | |
| 5 | -use LearnPress\MetaBox\LPMetaBoxField; | |
| 6 | -use WP_Widget; | |
| 7 | - | |
| 8 | -/** | |
| 9 | - * Class AbstractWidget | |
| 10 | - * | |
| 11 | - * @package LearnPress\Widgets | |
| 12 | - * @since 4.2.3.2 | |
| 13 | - * @version 1.0.0 | |
| 14 | - */ | |
| 15 | -class LPWidgetBase extends WP_Widget { | |
| 16 | - protected $prefix = 'learnpress_'; | |
| 17 | - protected $lp_widget_id = ''; | |
| 18 | - protected $lp_widget_name = ''; | |
| 19 | - protected $lp_widget_description = ''; | |
| 20 | - protected $lp_widget_class = ''; | |
| 21 | - protected $lp_widget_options = []; | |
| 22 | - protected $lp_widget_setting = []; | |
| 23 | - | |
| 24 | - public function __construct() { | |
| 25 | - $id_base = $this->prefix . $this->lp_widget_id; | |
| 26 | - $name = $this->lp_widget_name; | |
| 27 | - $widget_options = array_merge( | |
| 28 | - [ | |
| 29 | - 'description' => $this->lp_widget_description, | |
| 30 | - 'classname' => $this->lp_widget_class, | |
| 31 | - 'customize_selective_refresh' => true, | |
| 32 | - ], | |
| 33 | - $this->lp_widget_options | |
| 34 | - ); | |
| 35 | - $control_options = $this->control_options; | |
| 36 | - parent::__construct( $id_base, $name, $widget_options, $control_options ); | |
| 37 | - } | |
| 38 | - | |
| 39 | - public function form( $instance ) { | |
| 40 | - if ( empty( $this->lp_widget_setting ) ) { | |
| 41 | - echo '<p>' . esc_html__( 'There are no options for this widget.', 'learnpress' ) . '</p>'; | |
| 42 | - return; | |
| 43 | - } | |
| 44 | - | |
| 45 | - foreach ( $this->lp_widget_setting as $key => $setting ) { | |
| 46 | - $extra = $setting; | |
| 47 | - $extra['value'] = $instance[ $key ] ?? ''; | |
| 48 | - $extra['default'] = $setting['std'] ?? ''; | |
| 49 | - $extra['id'] = $this->get_field_id( $key ); | |
| 50 | - | |
| 51 | - if ( isset( $setting['type'] ) && LPMetaBoxField::CHECKBOX === $setting['type'] ) { | |
| 52 | - $html_wrapper = [ | |
| 53 | - '<p style="display:flex;flex-direction:row-reverse;justify-content:left;align-items:center">' => '</p>', | |
| 54 | - '<label for="' . $extra['id'] . '">' . ( $setting['label'] ?? '' ) . '</label>' => '', | |
| 55 | - ]; | |
| 56 | - } else { | |
| 57 | - $html_wrapper = [ | |
| 58 | - '<p style="display:flex;flex-direction:column">' => '</p>', | |
| 59 | - '<label for="' . $extra['id'] . '">' . ( $setting['label'] ?? '' ) . '</label>' => '', | |
| 60 | - ]; | |
| 61 | - } | |
| 62 | - | |
| 63 | - LPMetaBoxField::render( $setting['type'], $this->get_field_name( $key ), $extra, $html_wrapper ); | |
| 64 | - } | |
| 65 | - } | |
| 66 | -} | |
| 67 | - | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace LearnPress\Widgets; | |
| 4 | + | |
| 5 | +use LearnPress\MetaBox\LPMetaBoxField; | |
| 6 | +use WP_Widget; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * Class AbstractWidget | |
| 10 | + * | |
| 11 | + * @package LearnPress\Widgets | |
| 12 | + * @since 4.2.3.2 | |
| 13 | + * @version 1.0.0 | |
| 14 | + */ | |
| 15 | +class LPWidgetBase extends WP_Widget { | |
| 16 | + protected $prefix = 'learnpress_'; | |
| 17 | + protected $lp_widget_id = ''; | |
| 18 | + protected $lp_widget_name = ''; | |
| 19 | + protected $lp_widget_description = ''; | |
| 20 | + protected $lp_widget_class = ''; | |
| 21 | + protected $lp_widget_options = []; | |
| 22 | + protected $lp_widget_setting = []; | |
| 23 | + | |
| 24 | + public function __construct() { | |
| 25 | + $id_base = $this->prefix . $this->lp_widget_id; | |
| 26 | + $name = $this->lp_widget_name; | |
| 27 | + $widget_options = array_merge( | |
| 28 | + [ | |
| 29 | + 'description' => $this->lp_widget_description, | |
| 30 | + 'classname' => $this->lp_widget_class, | |
| 31 | + 'customize_selective_refresh' => true, | |
| 32 | + ], | |
| 33 | + $this->lp_widget_options | |
| 34 | + ); | |
| 35 | + $control_options = $this->control_options; | |
| 36 | + parent::__construct( $id_base, $name, $widget_options, $control_options ); | |
| 37 | + } | |
| 38 | + | |
| 39 | + public function form( $instance ) { | |
| 40 | + if ( empty( $this->lp_widget_setting ) ) { | |
| 41 | + echo '<p>' . esc_html__( 'There are no options for this widget.', 'learnpress' ) . '</p>'; | |
| 42 | + return; | |
| 43 | + } | |
| 44 | + | |
| 45 | + foreach ( $this->lp_widget_setting as $key => $setting ) { | |
| 46 | + $extra = $setting; | |
| 47 | + $extra['value'] = $instance[ $key ] ?? ''; | |
| 48 | + $extra['default'] = $setting['std'] ?? ''; | |
| 49 | + $extra['id'] = $this->get_field_id( $key ); | |
| 50 | + | |
| 51 | + if ( isset( $setting['type'] ) && LPMetaBoxField::CHECKBOX === $setting['type'] ) { | |
| 52 | + $html_wrapper = [ | |
| 53 | + '<p style="display:flex;flex-direction:row-reverse;justify-content:left;align-items:center">' => '</p>', | |
| 54 | + '<label for="' . $extra['id'] . '">' . ( $setting['label'] ?? '' ) . '</label>' => '', | |
| 55 | + ]; | |
| 56 | + } else { | |
| 57 | + $html_wrapper = [ | |
| 58 | + '<p style="display:flex;flex-direction:column">' => '</p>', | |
| 59 | + '<label for="' . $extra['id'] . '">' . ( $setting['label'] ?? '' ) . '</label>' => '', | |
| 60 | + ]; | |
| 61 | + } | |
| 62 | + | |
| 63 | + LPMetaBoxField::render( $setting['type'], $this->get_field_name( $key ), $extra, $html_wrapper ); | |
| 64 | + } | |
| 65 | + } | |
| 66 | +} | |
| 67 | + | |