display-conditions
5 months ago
front
2 days ago
helpers
1 month ago
metas
3 months ago
multisite
5 months ago
palettes
3 years ago
provider
1 month ago
providers
2 days ago
templates
3 years ago
update
5 months ago
class-hustle-admin-page-abstract.php
1 month ago
class-hustle-auth-token.php
5 months ago
class-hustle-condition-factory.php
6 years ago
class-hustle-cross-sell.php
10 months ago
class-hustle-dashboard-admin.php
1 month ago
class-hustle-data.php
1 month 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
1 month ago
class-hustle-module-collection.php
5 months ago
class-hustle-module-fields.php
3 months ago
class-hustle-module-page-abstract.php
1 month ago
class-hustle-module-validator.php
3 months ago
class-hustle-notifications.php
2 days ago
class-hustle-settings-admin.php
1 month ago
class-hustle-wp-dashboard-page.php
5 months ago
class-opt-in.php
2 days ago
hustle-background-conversion-log.php
3 months ago
hustle-deletion.php
3 months ago
hustle-embedded-admin.php
3 years ago
hustle-entries-admin.php
5 months ago
hustle-entry-model.php
1 month ago
hustle-general-data-protection.php
5 months ago
hustle-init.php
1 month ago
hustle-mail.php
5 months ago
hustle-migration.php
5 months ago
hustle-model.php
2 days ago
hustle-module-model.php
1 month ago
hustle-module-widget-legacy.php
5 months ago
hustle-module-widget.php
5 months ago
hustle-modules-common-admin-ajax.php
1 month ago
hustle-popup-admin.php
3 years ago
hustle-providers-admin.php
1 month ago
hustle-providers.php
5 months ago
hustle-settings-admin-ajax.php
1 month ago
hustle-settings-page.php
3 years ago
hustle-slidein-admin.php
3 years ago
hustle-sshare-admin.php
2 days ago
hustle-sshare-model.php
2 days ago
hustle-tracking-model.php
3 months ago
interface-hustle-auth-provider.php
5 months ago
opt-in-geo.php
5 months ago
opt-in-utils.php
2 days ago
opt-in-wpmudev-api.php
5 months ago
hustle-module-widget-legacy.php
155 lines
| 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 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 | /* translators: Plugin name */ |
| 28 | sprintf( __( '%s Legacy', 'hustle' ), Opt_In_Utils::get_plugin_name() ), |
| 29 | array( 'description' => __( 'A legacy widget to add Opt-ins', 'hustle' ) ) |
| 30 | ); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Get module id from old optin id. |
| 35 | * |
| 36 | * @param int $optin_id Option ID. |
| 37 | * @return mixed Module id or bool. |
| 38 | */ |
| 39 | private function get_module_id( $optin_id ) { |
| 40 | global $wpdb; |
| 41 | $data = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM `{$wpdb->prefix}optins` WHERE `optin_id`=%d", $optin_id ), OBJECT );// phpcs:ignore |
| 42 | |
| 43 | if ( isset( $data->optin_name ) ) { |
| 44 | $type = 'embedded'; |
| 45 | $type = ( 'social_sharing' === $data->optin_provider ) ? 'social_sharing' : $type; |
| 46 | $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 );// phpcs:ignore |
| 47 | return ( isset( $data->module_id ) ) ? (int) $data->module_id : false; |
| 48 | } |
| 49 | return false; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * |
| 54 | * Front-end display of widget. |
| 55 | * |
| 56 | * @param array $args Args. |
| 57 | * @param array $instance Previously saved values from database. |
| 58 | */ |
| 59 | public function widget( $args, $instance ) { |
| 60 | if ( ! empty( $instance['optin_id'] ) ) { |
| 61 | $instance['module_id'] = $this->get_module_id( $instance['optin_id'] ); |
| 62 | } |
| 63 | $show_select = false; |
| 64 | |
| 65 | if ( empty( $instance['module_id'] ) ) { |
| 66 | $show_select = true; |
| 67 | } else { |
| 68 | $module = Hustle_Module_Model::new_instance( $instance['module_id'] ); |
| 69 | if ( is_wp_error( $module ) ) { |
| 70 | $show_select = true; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | echo wp_kses_post( $args['before_widget'] ); |
| 75 | |
| 76 | if ( ! empty( $instance['title'] ) ) { |
| 77 | echo wp_kses_post( $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title'] ); |
| 78 | } |
| 79 | |
| 80 | if ( $show_select ) { |
| 81 | esc_attr_e( 'Select Module', 'hustle' ); |
| 82 | } else { |
| 83 | $widget_css_class = ( 'social_sharing' === $module->module_type ) |
| 84 | ? 'hustle_sshare_module_widget_wrap' |
| 85 | : 'hustle_module_widget_wrap'; |
| 86 | ?> |
| 87 | <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> |
| 88 | <?php |
| 89 | } |
| 90 | |
| 91 | echo wp_kses_post( $args['after_widget'] ); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * |
| 96 | * Back-end widget form. |
| 97 | * |
| 98 | * @see WP_Widget::form() |
| 99 | * @param array $instance Previously saved values from database. |
| 100 | * |
| 101 | * @return void |
| 102 | */ |
| 103 | public function form( $instance ) { |
| 104 | if ( isset( $instance['optin_id'] ) && ! empty( $instance['optin_id'] ) ) { |
| 105 | $instance['module_id'] = $this->get_module_id( $instance['optin_id'] ); |
| 106 | } |
| 107 | $title = ! empty( $instance['title'] ) ? $instance['title'] : __( 'New title', 'hustle' ); |
| 108 | if ( empty( $instance['module_id'] ) ) { |
| 109 | $instance['module_id'] = -1; } |
| 110 | ?> |
| 111 | <p> |
| 112 | <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_attr_e( 'Title:', 'hustle' ); ?></label> |
| 113 | <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 ); ?>"> |
| 114 | </p> |
| 115 | <p> |
| 116 | <label for="<?php echo esc_attr( $this->get_field_id( 'module_id' ) ); ?>"><?php esc_attr_e( 'Select Module:', 'hustle' ); ?></label> |
| 117 | <select name="<?php echo esc_attr( $this->get_field_name( 'module_id' ) ); ?>" id="hustle_module_id"> |
| 118 | <option value=""><?php esc_attr_e( 'Select Module', 'hustle' ); ?></option> |
| 119 | <?php |
| 120 | $types = array( 'embedded', 'social_sharing' ); |
| 121 | foreach ( Hustle_Module_Collection::instance()->get_embed_id_names( $types ) as $mod ) : |
| 122 | $module = Hustle_Module_Model::new_instance( $mod->module_id ); |
| 123 | if ( is_wp_error( $module ) ) { |
| 124 | continue; |
| 125 | } |
| 126 | ?> |
| 127 | <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> |
| 128 | |
| 129 | <?php |
| 130 | endforeach; |
| 131 | ?> |
| 132 | </select> |
| 133 | </p> |
| 134 | <?php |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Sanitize widget form values as they are saved. |
| 139 | * |
| 140 | * @see WP_Widget::update() |
| 141 | * |
| 142 | * @param array $new_instance Values just sent to be saved. |
| 143 | * @param array $old_instance Previously saved values from database. |
| 144 | * |
| 145 | * @return array Updated safe values to be saved. |
| 146 | */ |
| 147 | public function update( $new_instance, $old_instance ) { |
| 148 | $instance = array(); |
| 149 | $instance['title'] = ! empty( $new_instance['title'] ) ? wp_strip_all_tags( $new_instance['title'] ) : ''; |
| 150 | $instance['module_id'] = ! empty( $new_instance['module_id'] ) ? wp_strip_all_tags( $new_instance['module_id'] ) : ''; |
| 151 | |
| 152 | return $instance; |
| 153 | } |
| 154 | } |
| 155 |