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