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-legacy.php
175 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Legacy class for old widgets. |
| 4 | * |
| 5 | * @package Hustle |
| 6 | */ |
| 7 | |
| 8 | /** |
| 9 | * Class Hustle_Module_Widget_Legacy |
| 10 | */ |
| 11 | class Hustle_Module_Widget_Legacy extends WP_Widget { |
| 12 | |
| 13 | /** |
| 14 | * Widget Id. |
| 15 | * |
| 16 | * @var string |
| 17 | */ |
| 18 | const WIDGET_ID = 'inc_opt_widget'; |
| 19 | |
| 20 | |
| 21 | /** |
| 22 | * Registers the widget |
| 23 | */ |
| 24 | public function __construct() { |
| 25 | parent::__construct( |
| 26 | self::WIDGET_ID, |
| 27 | __( 'Hustle Legacy', 'hustle' ), |
| 28 | array( 'description' => __( 'A legacy widget to add Opt-ins', 'hustle' ) ) |
| 29 | ); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Get module id from old optin id. |
| 34 | * |
| 35 | * @param int $optin_id Option ID. |
| 36 | * @return mixed Module id or bool. |
| 37 | */ |
| 38 | private function get_module_id( $optin_id ) { |
| 39 | global $wpdb; |
| 40 | $data = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM `{$wpdb->prefix}optins` WHERE `optin_id`=%d", $optin_id ), OBJECT ); |
| 41 | |
| 42 | if ( isset( $data->optin_name ) ) { |
| 43 | $type = 'embedded'; |
| 44 | $type = ( 'social_sharing' === $data->optin_provider ) ? 'social_sharing' : $type; |
| 45 | $data = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM `{$wpdb->prefix}hustle_modules` WHERE `module_name`=%s and `module_type` = %s", $data->optin_name, $type ), OBJECT ); |
| 46 | return ( isset( $data->module_id ) ) ? (int) $data->module_id : false; |
| 47 | } |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * |
| 53 | * Front-end display of widget. |
| 54 | * |
| 55 | * @param array $args Args. |
| 56 | * @param array $instance Previously saved values from database. |
| 57 | * @return string |
| 58 | */ |
| 59 | public function widget( $args, $instance ) { |
| 60 | if ( isset( $instance['optin_id'] ) && ! empty( $instance['optin_id'] ) ) { |
| 61 | $instance['module_id'] = $this->get_module_id( $instance['optin_id'] ); |
| 62 | } |
| 63 | $show_select = false; |
| 64 | |
| 65 | // phpcs:disable |
| 66 | if ( empty( $instance['module_id'] ) ) { |
| 67 | $show_select = true; |
| 68 | } |
| 69 | if ( ! $show_select ) { |
| 70 | $module = new Hustle_Module_Model( $instance['module_id'] ); |
| 71 | if ( is_wp_error( $module ) ) { |
| 72 | $show_select = true; |
| 73 | } |
| 74 | } |
| 75 | if ( $show_select ) { |
| 76 | echo $args['before_widget']; |
| 77 | if ( ! empty( $instance['title'] ) ) { |
| 78 | echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title']; |
| 79 | } |
| 80 | esc_attr_e( 'Select Module', 'hustle' ); |
| 81 | echo $args['after_widget']; |
| 82 | return; |
| 83 | } |
| 84 | |
| 85 | // if( !$module->settings->widget->show_in_front() ){ |
| 86 | // echo $args['before_widget']; |
| 87 | // echo $args['after_widget']; |
| 88 | // return; |
| 89 | // } |
| 90 | |
| 91 | echo $args['before_widget']; |
| 92 | |
| 93 | if ( ! empty( $instance['title'] ) ) { |
| 94 | echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title']; |
| 95 | } |
| 96 | |
| 97 | $widget_css_class = ( 'social_sharing' === $module->module_type ) |
| 98 | ? 'hustle_sshare_module_widget_wrap' |
| 99 | : 'hustle_module_widget_wrap'; |
| 100 | |
| 101 | ?> |
| 102 | |
| 103 | <div class="<?php echo esc_attr( $widget_css_class ); ?> module_id_<?php echo esc_attr( $instance['module_id'] ); ?>" data-type="widget" data-id="<?php echo esc_attr( $instance['module_id'] ); ?>"></div> |
| 104 | <?php |
| 105 | |
| 106 | echo $args['after_widget']; |
| 107 | // phpcs:enable |
| 108 | } |
| 109 | |
| 110 | |
| 111 | /** |
| 112 | * |
| 113 | * Back-end widget form. |
| 114 | * |
| 115 | * @see WP_Widget::form() |
| 116 | * @param array $instance Previously saved values from database. |
| 117 | * |
| 118 | * @return void |
| 119 | */ |
| 120 | public function form( $instance ) { |
| 121 | if ( isset( $instance['optin_id'] ) && ! empty( $instance['optin_id'] ) ) { |
| 122 | $instance['module_id'] = $this->get_module_id( $instance['optin_id'] ); |
| 123 | } |
| 124 | $title = ! empty( $instance['title'] ) ? $instance['title'] : __( 'New title', 'hustle' ); |
| 125 | if ( empty( $instance['module_id'] ) ) { |
| 126 | $instance['module_id'] = -1; } |
| 127 | ?> |
| 128 | <p> |
| 129 | <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_attr_e( 'Title:', 'hustle' ); ?></label> |
| 130 | <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 ); ?>"> |
| 131 | </p> |
| 132 | <p> |
| 133 | <label for="<?php echo esc_attr( $this->get_field_id( 'module_id' ) ); ?>"><?php esc_attr_e( 'Select Module:', 'hustle' ); ?></label> |
| 134 | <select name="<?php echo esc_attr( $this->get_field_name( 'module_id' ) ); ?>" id="hustle_module_id"> |
| 135 | <option value=""><?php esc_attr_e( 'Select Module', 'hustle' ); ?></option> |
| 136 | <?php |
| 137 | $types = array( 'embedded', 'social_sharing' ); |
| 138 | foreach ( Hustle_Module_Collection::instance()->get_embed_id_names( $types ) as $mod ) : |
| 139 | $module = new Hustle_Module_Model( $mod->module_id ); |
| 140 | if ( is_wp_error( $module ) ) { |
| 141 | continue; |
| 142 | } |
| 143 | // if( $module->settings->widget->show_in_front() ): |
| 144 | ?> |
| 145 | <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> |
| 146 | |
| 147 | <?php |
| 148 | // endif; |
| 149 | endforeach; |
| 150 | ?> |
| 151 | </select> |
| 152 | </p> |
| 153 | <?php |
| 154 | } |
| 155 | |
| 156 | |
| 157 | /** |
| 158 | * Sanitize widget form values as they are saved. |
| 159 | * |
| 160 | * @see WP_Widget::update() |
| 161 | * |
| 162 | * @param array $new_instance Values just sent to be saved. |
| 163 | * @param array $old_instance Previously saved values from database. |
| 164 | * |
| 165 | * @return array Updated safe values to be saved. |
| 166 | */ |
| 167 | public function update( $new_instance, $old_instance ) { |
| 168 | $instance = array(); |
| 169 | $instance['title'] = ! empty( $new_instance['title'] ) ? wp_strip_all_tags( $new_instance['title'] ) : ''; |
| 170 | $instance['module_id'] = ! empty( $new_instance['module_id'] ) ? wp_strip_all_tags( $new_instance['module_id'] ) : ''; |
| 171 | |
| 172 | return $instance; |
| 173 | } |
| 174 | } |
| 175 |