display-conditions
3 years ago
front
10 months ago
helpers
10 months ago
metas
3 years ago
multisite
3 years ago
palettes
3 years ago
provider
3 years ago
providers
10 months ago
templates
3 years ago
update
3 years ago
class-hustle-admin-page-abstract.php
10 months ago
class-hustle-black-friday-campaign.php
7 months ago
class-hustle-condition-factory.php
6 years ago
class-hustle-cross-sell.php
10 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
10 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
10 months ago
hustle-module-widget-legacy.php
3 years ago
hustle-module-widget.php
3 years ago
hustle-modules-common-admin-ajax.php
10 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
10 months ago
opt-in-utils.php
3 years ago
opt-in-wpmudev-api.php
3 years ago
hustle-settings-page.php
155 lines
| 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | /** |
| 3 | * Hustle_Settings_Page |
| 4 | * |
| 5 | * @package Hustle |
| 6 | */ |
| 7 | |
| 8 | /** |
| 9 | * Class Hustle_Settings_Page |
| 10 | */ |
| 11 | class Hustle_Settings_Page extends Hustle_Admin_Page_Abstract { |
| 12 | |
| 13 | /** |
| 14 | * Key of the Hustle's settings in wp_options. |
| 15 | * |
| 16 | * @since 4.0 |
| 17 | */ |
| 18 | const SETTINGS_OPTION_KEY = 'hustle_settings'; |
| 19 | |
| 20 | /** |
| 21 | * Init |
| 22 | */ |
| 23 | public function init() { |
| 24 | |
| 25 | $this->page = 'hustle_settings'; |
| 26 | |
| 27 | /* translators: Plugin name */ |
| 28 | $this->page_title = sprintf( __( '%s Settings', 'hustle' ), Opt_In_Utils::get_plugin_name() ); |
| 29 | |
| 30 | $this->page_menu_title = __( 'Settings', 'hustle' ); |
| 31 | |
| 32 | $this->page_capability = 'hustle_edit_settings'; |
| 33 | |
| 34 | $this->page_template_path = 'admin/settings'; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Actions to be performed on Settings page. |
| 39 | * |
| 40 | * @since 4.1.0 |
| 41 | */ |
| 42 | public function current_page_loaded() { |
| 43 | parent::current_page_loaded(); |
| 44 | |
| 45 | // Set up all the filters and buttons for tinymce editors. |
| 46 | $this->set_up_tinymce(); |
| 47 | |
| 48 | add_filter( 'mce_external_plugins', array( $this, 'remove_all_mce_external_plugins' ), -1 ); |
| 49 | |
| 50 | add_action( 'admin_enqueue_scripts', array( 'Hustle_Module_Front', 'add_hui_scripts' ) ); |
| 51 | |
| 52 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Enqueue colorpicker scripts |
| 57 | * |
| 58 | * @since 4.2.0 |
| 59 | */ |
| 60 | public function enqueue_scripts() { |
| 61 | self::add_color_picker(); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Get page template args |
| 66 | * |
| 67 | * @return array |
| 68 | */ |
| 69 | public function get_page_template_args() { |
| 70 | $current_user = wp_get_current_user(); |
| 71 | $general_settings = Hustle_Settings_Admin::get_general_settings(); |
| 72 | $migration = Hustle_Migration::get_instance(); |
| 73 | |
| 74 | return array( |
| 75 | 'user_name' => ucfirst( $current_user->display_name ), |
| 76 | 'email_name' => $general_settings['sender_email_name'], |
| 77 | 'email_address' => $general_settings['sender_email_address'], |
| 78 | 'unsubscription_messages' => Hustle_Settings_Admin::get_unsubscribe_messages(), |
| 79 | 'unsubscription_email' => Hustle_Settings_Admin::get_unsubscribe_email_settings(), |
| 80 | 'hustle_settings' => Hustle_Settings_Admin::get_hustle_settings(), |
| 81 | 'section' => $this->get_current_section( 'general' ), |
| 82 | ); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Add data to the current json array. |
| 87 | * |
| 88 | * @since 4.3.1 |
| 89 | * |
| 90 | * @return array |
| 91 | */ |
| 92 | protected function get_vars_to_localize() { |
| 93 | $current_array = parent::get_vars_to_localize(); |
| 94 | |
| 95 | // Error messages for 4.0.x restoring. |
| 96 | $current_array['messages']['restricted_access'] = esc_html__( "You can't perform this action", 'hustle' ); |
| 97 | $current_array['messages']['restore_40x_failed'] = esc_html__( "The restore failed. It could be that there's no data to restore. Please check the logs.", 'hustle' ); |
| 98 | |
| 99 | $current_array['settings_palettes_action_nonce'] = wp_create_nonce( 'hustle_palette_action' ); |
| 100 | |
| 101 | $current_array['palettes'] = Hustle_Palettes_Helper::get_all_palettes(); |
| 102 | |
| 103 | $saved_id = filter_input( INPUT_GET, 'saved-id', FILTER_SANITIZE_SPECIAL_CHARS ); |
| 104 | if ( $saved_id ) { |
| 105 | |
| 106 | $saved_palettes = Hustle_Palettes_Helper::get_all_palettes_slug_and_name(); |
| 107 | if ( ! empty( $saved_palettes[ $saved_id ] ) ) { |
| 108 | |
| 109 | $saved_name = '<span style="color:#333;"><strong>' . esc_html( $saved_palettes[ $saved_id ] ) . '</strong></span>'; |
| 110 | /* translators: %s: palette name */ |
| 111 | $current_array['messages']['palette_saved'] = sprintf( esc_html__( '%s - Palette saved successfully.', 'hustle' ), $saved_name ); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | $deleted_name = filter_input( INPUT_GET, 'deleted-name', FILTER_SANITIZE_SPECIAL_CHARS ); |
| 116 | if ( $deleted_name ) { |
| 117 | |
| 118 | $deleted_name = '<span style="color:#333;"><strong>' . esc_html( $deleted_name ) . '</strong></span>'; |
| 119 | /* translators: %s: palette name */ |
| 120 | $current_array['messages']['palette_deleted'] = esc_html( sprintf( __( '%s - Palette deleted successfully.', 'hustle' ), $deleted_name ) ); |
| 121 | } |
| 122 | |
| 123 | $palettes = array(); |
| 124 | $args = array( 'except_types' => array( Hustle_Module_Model::SOCIAL_SHARING_MODULE ) ); |
| 125 | $modules = Hustle_Module_Collection::instance()->get_all( null, $args ); |
| 126 | |
| 127 | foreach ( $modules as $module ) { |
| 128 | $palettes[ $module->module_type ][ $module->module_id ] = esc_html( $module->module_name ); |
| 129 | } |
| 130 | $current_array['current'] = $palettes; |
| 131 | $current_array['current']['save_settings_nonce'] = wp_create_nonce( 'hustle_settings_save' ); |
| 132 | |
| 133 | $current_array['messages']['generic_ajax_error'] = esc_html__( 'Something went wrong with the request. Please reload the page and try again.', 'hustle' ); |
| 134 | $current_array['messages']['settings_saved'] = esc_html__( 'Settings saved.', 'hustle' ); |
| 135 | $current_array['messages']['settings_was_reset'] = '<label class="wpmudev-label--notice"><span>' . esc_html__( 'Plugin was successfully reset.', 'hustle' ) . '</span></label>'; |
| 136 | |
| 137 | return $current_array; |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Removing all MCE external plugins which often break our pages |
| 142 | * |
| 143 | * @since 3.0.8 |
| 144 | * @param array $external_plugins External plugins. |
| 145 | * @return array |
| 146 | */ |
| 147 | public function remove_all_mce_external_plugins( $external_plugins ) { |
| 148 | |
| 149 | remove_all_filters( 'mce_external_plugins' ); |
| 150 | $external_plugins = array(); |
| 151 | |
| 152 | return $external_plugins; |
| 153 | } |
| 154 | } |
| 155 |