display-conditions
5 years ago
front
5 years ago
helpers
5 years ago
metas
5 years ago
palettes
5 years ago
provider
5 years ago
providers
5 years ago
templates
5 years ago
update
5 years ago
class-hustle-admin-page-abstract.php
5 years ago
class-hustle-condition-factory.php
6 years ago
class-hustle-dashboard-admin.php
5 years ago
class-hustle-data.php
5 years ago
class-hustle-db.php
6 years ago
class-hustle-module-admin.php
5 years ago
class-hustle-module-collection.php
5 years ago
class-hustle-module-decorator.php
5 years ago
class-hustle-module-page-abstract.php
5 years ago
class-hustle-notifications.php
5 years ago
class-hustle-settings-admin.php
5 years ago
class-hustle-upsell-page.php
5 years ago
class-hustle-wp-dashboard-page.php
5 years ago
hustle-collection.php
6 years ago
hustle-deletion.php
5 years ago
hustle-embedded-admin.php
6 years ago
hustle-entries-admin.php
5 years ago
hustle-entry-model.php
5 years ago
hustle-general-data-protection.php
6 years ago
hustle-init.php
5 years ago
hustle-mail.php
5 years ago
hustle-meta.php
5 years ago
hustle-migration.php
5 years ago
hustle-model.php
5 years ago
hustle-module-model.php
5 years ago
hustle-module-widget-legacy.php
5 years ago
hustle-module-widget.php
5 years ago
hustle-modules-common-admin-ajax.php
5 years ago
hustle-popup-admin.php
6 years ago
hustle-providers-admin.php
5 years ago
hustle-providers.php
6 years ago
hustle-settings-admin-ajax.php
5 years ago
hustle-settings-page.php
5 years ago
hustle-slidein-admin.php
6 years ago
hustle-sshare-admin.php
5 years ago
hustle-sshare-model.php
5 years ago
hustle-tracking-model.php
5 years ago
opt-in-geo.php
5 years ago
opt-in-utils.php
5 years ago
opt-in-wpmudev-api.php
6 years ago
hustle-module-widget.php
132 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Class Hustle_Module_Widget |
| 5 | */ |
| 6 | class Hustle_Module_Widget extends WP_Widget { |
| 7 | |
| 8 | /** |
| 9 | * @var string Widget Id |
| 10 | */ |
| 11 | const WIDGET_ID = 'hustle_module_widget'; |
| 12 | |
| 13 | |
| 14 | /** |
| 15 | * Registers the widget |
| 16 | */ |
| 17 | public function __construct() { |
| 18 | parent::__construct( |
| 19 | self::WIDGET_ID, |
| 20 | __( 'Hustle', 'hustle' ), |
| 21 | array( 'description' => __( 'A widget to add Hustle Embeds and Social Sharing.', 'hustle' ) ) |
| 22 | ); |
| 23 | } |
| 24 | |
| 25 | |
| 26 | |
| 27 | /** |
| 28 | * |
| 29 | * Front-end display of widget. |
| 30 | * |
| 31 | * @param array $args |
| 32 | * @param array $instance Previously saved values from database. |
| 33 | * @return string |
| 34 | */ |
| 35 | public function widget( $args, $instance ) { |
| 36 | // phpcs:disable |
| 37 | if ( empty( $instance['module_id'] ) ) { |
| 38 | |
| 39 | echo $args['before_widget']; |
| 40 | |
| 41 | if ( ! empty( $instance['title'] ) ) { |
| 42 | echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title']; |
| 43 | } |
| 44 | echo esc_attr__( 'Select Module', 'hustle' ); |
| 45 | |
| 46 | echo $args['after_widget']; |
| 47 | |
| 48 | return; |
| 49 | } |
| 50 | |
| 51 | $module = Hustle_Module_Collection::instance()->return_model_from_id( $instance['module_id'] ); |
| 52 | |
| 53 | if ( is_wp_error( $module ) || ! $module || empty( $module->active ) || ! $module->is_display_type_active( Hustle_Module_Model::WIDGET_MODULE ) ) { |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | echo $args['before_widget']; |
| 58 | |
| 59 | if ( ! empty( $instance['title'] ) ) { |
| 60 | echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title']; |
| 61 | } |
| 62 | |
| 63 | $custom_classes = apply_filters( 'hustle_widget_module_custom_classes', '', $module ); |
| 64 | $module->display( Hustle_Module_Model::WIDGET_MODULE, $custom_classes ); |
| 65 | |
| 66 | echo $args['after_widget']; |
| 67 | // phpcs:enable |
| 68 | } |
| 69 | |
| 70 | |
| 71 | /** |
| 72 | * |
| 73 | * Back-end widget form. |
| 74 | * |
| 75 | * @see WP_Widget::form() |
| 76 | * @param array $instance Previously saved values from database. |
| 77 | * |
| 78 | * @return void |
| 79 | */ |
| 80 | public function form( $instance ) { |
| 81 | $title = ! empty( $instance['title'] ) ? $instance['title'] : __( 'New title', 'hustle' ); |
| 82 | if ( empty( $instance['module_id'] ) ) { |
| 83 | $instance['module_id'] = -1; } |
| 84 | ?> |
| 85 | <p> |
| 86 | <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php echo esc_attr__( 'Title:', 'hustle' ); ?></label> |
| 87 | <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 ); ?>"> |
| 88 | </p> |
| 89 | <p> |
| 90 | <label for="<?php echo esc_attr( $this->get_field_id( 'module_id' ) ); ?>"><?php echo esc_attr__( 'Select Module:', 'hustle' ); ?></label> |
| 91 | <select name="<?php echo esc_attr( $this->get_field_name( 'module_id' ) ); ?>" id="hustle_module_id"> |
| 92 | <option value=""><?php echo esc_attr__( 'Select Module', 'hustle' ); ?></option> |
| 93 | <?php |
| 94 | $types = array( 'embedded', 'social_sharing' ); |
| 95 | foreach ( Hustle_Module_Collection::instance()->get_embed_id_names( $types ) as $mod ) : |
| 96 | $module = new Hustle_Module_Model( $mod->module_id ); |
| 97 | if ( is_wp_error( $module ) ) { |
| 98 | continue; |
| 99 | } |
| 100 | // if( $module->settings->widget->show_in_front() ): |
| 101 | ?> |
| 102 | <option <?php selected( $instance['module_id'], $mod->module_id ); ?> value="<?php echo esc_attr( $mod->module_id ); ?>"><?php echo esc_attr( $mod->module_name ); ?></option> |
| 103 | |
| 104 | <?php |
| 105 | // endif; |
| 106 | endforeach; |
| 107 | ?> |
| 108 | </select> |
| 109 | </p> |
| 110 | <?php |
| 111 | } |
| 112 | |
| 113 | |
| 114 | /** |
| 115 | * Sanitize widget form values as they are saved. |
| 116 | * |
| 117 | * @see WP_Widget::update() |
| 118 | * |
| 119 | * @param array $new_instance Values just sent to be saved. |
| 120 | * @param array $old_instance Previously saved values from database. |
| 121 | * |
| 122 | * @return array Updated safe values to be saved. |
| 123 | */ |
| 124 | public function update( $new_instance, $old_instance ) { |
| 125 | $instance = array(); |
| 126 | $instance['title'] = ! empty( $new_instance['title'] ) ? wp_strip_all_tags( $new_instance['title'] ) : ''; |
| 127 | $instance['module_id'] = ! empty( $new_instance['module_id'] ) ? wp_strip_all_tags( $new_instance['module_id'] ) : ''; |
| 128 | |
| 129 | return $instance; |
| 130 | } |
| 131 | } |
| 132 |