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