display-conditions
5 months ago
front
4 days ago
helpers
1 month ago
metas
3 months ago
multisite
5 months ago
palettes
3 years ago
provider
1 month ago
providers
4 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
4 days ago
class-hustle-settings-admin.php
1 month ago
class-hustle-wp-dashboard-page.php
5 months ago
class-opt-in.php
4 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
4 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
4 days ago
hustle-sshare-model.php
4 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
4 days ago
opt-in-wpmudev-api.php
5 months ago
class-hustle-admin-page-abstract.php
649 lines
| 1 | <?php |
| 2 | /** |
| 3 | * File for Hustle_Admin_Page_Abstract class. |
| 4 | * |
| 5 | * @package Hustle |
| 6 | * @since 4.0.1 |
| 7 | */ |
| 8 | |
| 9 | if ( ! class_exists( 'Hustle_Admin_Page_Abstract' ) ) : |
| 10 | /** |
| 11 | * Class Hustle_Admin_Page_Abstract. |
| 12 | * This is the base class for all Hustle's pages. |
| 13 | * |
| 14 | * @since 4.0.1 |
| 15 | */ |
| 16 | abstract class Hustle_Admin_Page_Abstract { |
| 17 | |
| 18 | /** |
| 19 | * Page slug defined by us. |
| 20 | * |
| 21 | * @since 4.0.1 |
| 22 | * @var string |
| 23 | */ |
| 24 | protected $page; |
| 25 | |
| 26 | /** |
| 27 | * Template path for the page relative to the 'views' folder. |
| 28 | * |
| 29 | * @since 4.0.1 |
| 30 | * @var string |
| 31 | */ |
| 32 | protected $page_template_path; |
| 33 | |
| 34 | /** |
| 35 | * Page title. |
| 36 | * |
| 37 | * @since 4.0.1 |
| 38 | * @var string |
| 39 | */ |
| 40 | protected $page_title; |
| 41 | |
| 42 | /** |
| 43 | * Page title for the WordPress menu. |
| 44 | * |
| 45 | * @since 4.0.1 |
| 46 | * @var string |
| 47 | */ |
| 48 | protected $page_menu_title; |
| 49 | |
| 50 | /** |
| 51 | * Required capability for the page to be available. |
| 52 | * |
| 53 | * @since 4.0.1 |
| 54 | * @var string |
| 55 | */ |
| 56 | protected $page_capability; |
| 57 | |
| 58 | /** |
| 59 | * The current page that's being requested. |
| 60 | * |
| 61 | * @since 4.0.2 |
| 62 | * @var string|bool |
| 63 | */ |
| 64 | protected $current_page; |
| 65 | |
| 66 | /** |
| 67 | * Page slug defined by WordPress when registering the page. |
| 68 | * |
| 69 | * @since 4.0.0 |
| 70 | * @var string |
| 71 | */ |
| 72 | protected $page_slug; |
| 73 | |
| 74 | /** |
| 75 | * Instance of Hustle_Layout_Helper |
| 76 | * |
| 77 | * @since 4.2.0 |
| 78 | * @var Hustle_Layout_Helper |
| 79 | */ |
| 80 | private $renderer; |
| 81 | |
| 82 | /** |
| 83 | * Class constructor. |
| 84 | * |
| 85 | * @since 4.0.1 |
| 86 | */ |
| 87 | public function __construct() { |
| 88 | |
| 89 | $this->current_page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_SPECIAL_CHARS ); |
| 90 | |
| 91 | $this->init(); |
| 92 | |
| 93 | add_action( 'admin_menu', array( $this, 'register_admin_menu' ) ); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Initiate the page's properties |
| 98 | * Should be overridden by each page. |
| 99 | * |
| 100 | * @since 4.0.1 |
| 101 | */ |
| 102 | abstract protected function init(); |
| 103 | |
| 104 | /** |
| 105 | * Get the template arguments for the page. |
| 106 | * |
| 107 | * @since 7.8.9 |
| 108 | * @return array |
| 109 | */ |
| 110 | abstract protected function get_page_template_args(); |
| 111 | |
| 112 | /** |
| 113 | * Register the admin menus. |
| 114 | * |
| 115 | * @since 4.0.1 |
| 116 | */ |
| 117 | public function register_admin_menu() { |
| 118 | $this->page_slug = add_submenu_page( 'hustle', $this->page_title, esc_html( $this->page_menu_title ), $this->page_capability, $this->page, array( $this, 'render_main_page' ) ); |
| 119 | |
| 120 | add_action( 'admin_init', array( $this, 'maybe_export' ) ); |
| 121 | add_action( 'load-' . $this->page_slug, array( $this, 'current_page_loaded' ) ); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Gets an instance of the renderer class. |
| 126 | * |
| 127 | * @since 4.2.1 |
| 128 | * @return Hustle_Layout_Helper |
| 129 | */ |
| 130 | protected function get_renderer() { |
| 131 | if ( ! $this->renderer ) { |
| 132 | $this->renderer = new Hustle_Layout_Helper( $this ); |
| 133 | } |
| 134 | return $this->renderer; |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Check if it's export - run the relevant action. |
| 139 | */ |
| 140 | public function maybe_export() { |
| 141 | $this->export_module(); |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Render the main page |
| 146 | * |
| 147 | * @since 4.0.1 |
| 148 | */ |
| 149 | public function render_main_page() { |
| 150 | ?> |
| 151 | <div class="<?php echo esc_attr( $this->get_sui_wrap_class() ); ?>"> |
| 152 | |
| 153 | <?php |
| 154 | $template_args = $this->get_page_template_args(); |
| 155 | $renderer = $this->get_renderer(); |
| 156 | $renderer->render( $this->page_template_path, $template_args ); |
| 157 | |
| 158 | $this->render_modals(); |
| 159 | ?> |
| 160 | |
| 161 | </div> |
| 162 | <?php |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Perform actions during the 'load-{page}' hook. |
| 167 | * |
| 168 | * @since 4.0.4 |
| 169 | */ |
| 170 | public function current_page_loaded() { |
| 171 | $this->maybe_export(); |
| 172 | add_action( 'admin_enqueue_scripts', array( $this, 'register_scripts' ), 99 ); |
| 173 | add_action( 'admin_print_styles', array( $this, 'register_styles' ) ); |
| 174 | add_filter( 'admin_body_class', array( $this, 'add_admin_body_class' ), 99 ); |
| 175 | add_filter( 'removable_query_args', array( $this, 'remove_notice_params' ) ); |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Print forminator scripts for preview. |
| 180 | * Used by Dashboard, Wizards, and Listings. |
| 181 | * |
| 182 | * @since 4.0.1 |
| 183 | */ |
| 184 | public function maybe_print_forminator_scripts() { |
| 185 | |
| 186 | // Add Forminator's front styles and scripts for preview. |
| 187 | if ( defined( 'FORMINATOR_VERSION' ) ) { |
| 188 | forminator_print_front_styles( FORMINATOR_VERSION ); |
| 189 | forminator_print_front_scripts( FORMINATOR_VERSION ); |
| 190 | |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Register scripts for the admin page. |
| 196 | * |
| 197 | * @since 4.3.1 |
| 198 | * |
| 199 | * @param string $page_slug Page slug. |
| 200 | */ |
| 201 | public function register_scripts( $page_slug ) { |
| 202 | |
| 203 | wp_enqueue_script( |
| 204 | 'shared-ui', |
| 205 | Opt_In::$plugin_url . 'assets/js/shared-ui.min.js', |
| 206 | array( 'jquery' ), |
| 207 | HUSTLE_SUI_VERSION, |
| 208 | true |
| 209 | ); |
| 210 | |
| 211 | /** |
| 212 | * Filters the variable to be localized into the js side of Hustle's admin pages. |
| 213 | * |
| 214 | * @since unknown |
| 215 | */ |
| 216 | $optin_vars = apply_filters( 'hustle_optin_vars', $this->get_vars_to_localize() ); |
| 217 | |
| 218 | wp_register_script( |
| 219 | 'optin_admin_scripts', |
| 220 | Opt_In::$plugin_url . 'assets/js/admin.min.js', |
| 221 | array( 'jquery', 'backbone', 'jquery-effects-core', 'shared-ui' ), |
| 222 | Opt_In::VERSION, |
| 223 | true |
| 224 | ); |
| 225 | wp_localize_script( 'optin_admin_scripts', 'optinVars', $optin_vars ); |
| 226 | wp_enqueue_script( 'optin_admin_scripts' ); |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * Register the js variables to be localized for this page. |
| 231 | * |
| 232 | * @since 4.3.1 |
| 233 | * |
| 234 | * @return array |
| 235 | */ |
| 236 | protected function get_vars_to_localize() { |
| 237 | $tutorials_removed = sprintf( /* translators: %1$s - plugin name, %2$s - opening <a> tag, %3$s - closing <a> tag */ |
| 238 | esc_html__( 'The widget has been removed. %1$s tutorials can still be found in the %2$sTutorials tab%3$s any time.', 'hustle' ), |
| 239 | Opt_In_Utils::get_plugin_name(), |
| 240 | '<a href=' . esc_url( menu_page_url( 'hustle_tutorials', false ) ) . '>', |
| 241 | '</a>' |
| 242 | ); |
| 243 | |
| 244 | $url_params = $_GET; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 245 | array_walk_recursive( |
| 246 | $url_params, |
| 247 | function ( &$val ) { |
| 248 | $val = esc_attr( $val ); |
| 249 | } |
| 250 | ); |
| 251 | |
| 252 | return array( |
| 253 | 'ss_preview_nonce' => wp_create_nonce( 'hustle-preview' ), |
| 254 | 'dismiss_notice_nonce' => wp_create_nonce( 'hustle_dismiss_notification' ), |
| 255 | 'urlParams' => $url_params, |
| 256 | 'module_page' => array( |
| 257 | 'popup' => Hustle_Data::POPUP_LISTING_PAGE, |
| 258 | 'slidein' => Hustle_Data::SLIDEIN_LISTING_PAGE, |
| 259 | 'embedded' => Hustle_Data::EMBEDDED_LISTING_PAGE, |
| 260 | 'social_sharing' => Hustle_Data::SOCIAL_SHARING_LISTING_PAGE, |
| 261 | ), |
| 262 | 'messages' => array( |
| 263 | 'something_went_wrong' => esc_html__( 'Something went wrong. Please try again', 'hustle' ), // everywhere. |
| 264 | 'something_went_wrong_reload' => '<label class="wpmudev-label--notice"><span>' . esc_html__( 'Something went wrong. Please reload this page and try again.', 'hustle' ) . '</span></label>', // everywhere. |
| 265 | /* translators: "Aweber" between "strong" tags */ |
| 266 | 'aweber_migration_success' => sprintf( esc_html__( '%s integration successfully migrated to the oAuth 2.0.', 'hustle' ), '<strong>' . esc_html__( 'Aweber', 'hustle' ) . '</strong>' ), // everywhere. views.js. |
| 267 | 'integraiton_required' => '<label class="wpmudev-label--notice"><span>' . esc_html__( 'An integration is required on opt-in module.', 'hustle' ) . '</span></label>', // wizard and integrations. |
| 268 | 'module_deleted' => esc_html__( 'Module successfully deleted.', 'hustle' ), // listing and dashboard. |
| 269 | 'shortcode_copied' => esc_html__( 'Shortcode copied successfully.', 'hustle' ), // listing and dashboard. |
| 270 | 'commons' => array( |
| 271 | 'published' => esc_html__( 'Published', 'hustle' ), // dashboard and wizard. |
| 272 | 'draft' => esc_html__( 'Draft', 'hustle' ), // dashboard and wizard. |
| 273 | 'dismiss' => esc_html__( 'Dismiss', 'hustle' ), // everywhere, views.js. |
| 274 | ), |
| 275 | 'request_error_reload_notice' => esc_html__( 'There was an issue processing your request. Please reload the page and try again.', 'hustle' ), |
| 276 | ), |
| 277 | ); |
| 278 | } |
| 279 | |
| 280 | /** |
| 281 | * Registers styles for the admin pages. |
| 282 | * |
| 283 | * @since 4.3.1 |
| 284 | * |
| 285 | * @param string $page_slug Slug of the current page. |
| 286 | */ |
| 287 | public function register_styles( $page_slug ) { |
| 288 | wp_enqueue_style( 'thickbox' ); |
| 289 | |
| 290 | wp_register_style( |
| 291 | 'hstl-roboto', |
| 292 | 'https://fonts.bunny.net/css?family=Roboto+Condensed:300,300i,400,400i,700,700i|Roboto:300,300i,400,400i,500,500i,700,700i', |
| 293 | array(), |
| 294 | Opt_In::VERSION |
| 295 | ); |
| 296 | wp_register_style( |
| 297 | 'hstl-opensans', |
| 298 | 'https://fonts.bunny.net/css?family=Open+Sans:400,400i,700,700i', |
| 299 | array(), |
| 300 | Opt_In::VERSION |
| 301 | ); |
| 302 | wp_register_style( |
| 303 | 'hstl-source', |
| 304 | 'https://fonts.bunny.net/css?family=Source+Code+Pro', |
| 305 | array(), |
| 306 | Opt_In::VERSION |
| 307 | ); |
| 308 | |
| 309 | wp_enqueue_style( 'wp-color-picker' ); |
| 310 | wp_enqueue_style( 'wdev_ui' ); |
| 311 | wp_enqueue_style( 'wdev_notice' ); |
| 312 | wp_enqueue_style( 'hstl-roboto' ); |
| 313 | wp_enqueue_style( 'hstl-opensans' ); |
| 314 | wp_enqueue_style( 'hstl-source' ); |
| 315 | |
| 316 | wp_enqueue_style( |
| 317 | 'sui_styles', |
| 318 | Opt_In::$plugin_url . 'assets/css/shared-ui.min.css', |
| 319 | array(), |
| 320 | HUSTLE_SUI_VERSION |
| 321 | ); |
| 322 | } |
| 323 | |
| 324 | /** |
| 325 | * Adds a class to the page body with the SUI version. |
| 326 | * |
| 327 | * @since 4.3.1 |
| 328 | * |
| 329 | * @param string $classes Current set of classes to be added. |
| 330 | * @return string |
| 331 | */ |
| 332 | public function add_admin_body_class( $classes ) { |
| 333 | $formatted_version = str_replace( '.', '-', HUSTLE_SUI_VERSION ); |
| 334 | |
| 335 | $classes .= ' sui-' . $formatted_version; |
| 336 | |
| 337 | /** |
| 338 | * Add high contrast mode. |
| 339 | */ |
| 340 | $accessibility = Hustle_Settings_Admin::get_hustle_settings( 'accessibility' ); |
| 341 | $is_high_contrast_mode = ! empty( $accessibility['accessibility_color'] ); |
| 342 | if ( $is_high_contrast_mode ) { |
| 343 | $classes .= ' sui-elements-accessible'; |
| 344 | } |
| 345 | |
| 346 | return $classes; |
| 347 | } |
| 348 | |
| 349 | /** |
| 350 | * Remove Get parameters for Hustle notices |
| 351 | * |
| 352 | * @since 4.3.1 |
| 353 | * |
| 354 | * @param string[] $vars An array of query variables to remove from a URL. |
| 355 | * @return array |
| 356 | */ |
| 357 | public function remove_notice_params( $vars ) { |
| 358 | $vars[] = 'show-notice'; |
| 359 | $vars[] = 'notice'; |
| 360 | $vars[] = 'notice-close'; |
| 361 | |
| 362 | return $vars; |
| 363 | } |
| 364 | |
| 365 | /** |
| 366 | * Exports a single module. |
| 367 | * Used by Dashboard and Listing. |
| 368 | * |
| 369 | * @since 4.0.0 |
| 370 | * @since 4.2.0 Moved from Hustle_Modules_Common_Admin to this class. |
| 371 | */ |
| 372 | protected function export_module() { |
| 373 | |
| 374 | $nonce = filter_input( INPUT_POST, '_wpnonce', FILTER_SANITIZE_SPECIAL_CHARS ); |
| 375 | if ( ! wp_verify_nonce( $nonce, 'hustle_module_export' ) ) { |
| 376 | return; |
| 377 | } |
| 378 | $id = filter_input( INPUT_POST, 'id', FILTER_VALIDATE_INT ); |
| 379 | if ( ! $id ) { |
| 380 | return; |
| 381 | } |
| 382 | // Plugin data. |
| 383 | $plugin = get_plugin_data( WP_PLUGIN_DIR . '/' . Opt_In::$plugin_base_file ); |
| 384 | |
| 385 | // Get module. |
| 386 | $module = Hustle_Module_Model::new_instance( $id ); |
| 387 | if ( is_wp_error( $module ) ) { |
| 388 | return; |
| 389 | } |
| 390 | |
| 391 | // Export data. |
| 392 | $settings = array( |
| 393 | 'plugin' => array( |
| 394 | 'name' => $plugin['Name'], |
| 395 | 'version' => Opt_In::VERSION, |
| 396 | 'network' => $plugin['Network'], |
| 397 | ), |
| 398 | 'timestamp' => time(), |
| 399 | 'attributes' => $module->get_attributes(), |
| 400 | 'data' => $module->get_data(), |
| 401 | 'meta' => array(), |
| 402 | ); |
| 403 | |
| 404 | if ( 'optin' === $module->module_mode ) { |
| 405 | $integrations = array(); |
| 406 | $providers = Hustle_Providers::get_instance()->get_providers(); |
| 407 | foreach ( $providers as $slug => $provider ) { |
| 408 | $provider_data = $module->get_provider_settings( $slug, false ); |
| 409 | if ( $provider_data && $provider->is_connected() |
| 410 | && $provider->is_form_connected( $id ) ) { |
| 411 | $integrations[ $slug ] = $provider_data; |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | $settings['meta']['integrations'] = $integrations; |
| 416 | } |
| 417 | |
| 418 | $meta_names = $module->get_module_meta_names(); |
| 419 | foreach ( $meta_names as $meta_key ) { |
| 420 | $settings['meta'][ $meta_key ] = json_decode( $module->get_meta( $meta_key ) ); |
| 421 | } |
| 422 | /** |
| 423 | * Filename |
| 424 | */ |
| 425 | $filename = sprintf( |
| 426 | 'hustle-%s-%s-%s-%s.json', |
| 427 | $module->module_type, |
| 428 | gmdate( 'Ymd-his' ), |
| 429 | get_bloginfo( 'name' ), |
| 430 | $module->module_name |
| 431 | ); |
| 432 | if ( ob_get_contents() ) { |
| 433 | // To prevent other plugins' errors fail the export. |
| 434 | ob_clean(); |
| 435 | } |
| 436 | $filename = strtolower( $filename ); |
| 437 | $filename = sanitize_file_name( $filename ); |
| 438 | /** |
| 439 | * Print HTTP headers |
| 440 | */ |
| 441 | header( 'Content-Description: File Transfer' ); |
| 442 | header( 'Content-Disposition: attachment; filename=' . $filename ); |
| 443 | header( 'Content-Type: application/bin; charset=' . get_option( 'blog_charset' ), true ); |
| 444 | /** |
| 445 | * Check PHP version, for PHP < 3 do not add options |
| 446 | */ |
| 447 | $version = phpversion(); |
| 448 | $compare = version_compare( $version, '5.3', '<' ); |
| 449 | if ( $compare ) { |
| 450 | echo wp_json_encode( $settings ); |
| 451 | exit; |
| 452 | } |
| 453 | $option = defined( 'JSON_PRETTY_PRINT' ) ? JSON_PRETTY_PRINT : null; |
| 454 | echo wp_json_encode( $settings, $option ); |
| 455 | exit; |
| 456 | } |
| 457 | |
| 458 | /** |
| 459 | * Filter related to TinyMCE |
| 460 | * Used by Settings and Wizard pages. |
| 461 | * |
| 462 | * @since 4.2.0 Moved from Hustle_Module_Admin to this class. |
| 463 | */ |
| 464 | protected function set_up_tinymce() { |
| 465 | |
| 466 | add_filter( 'tiny_mce_before_init', array( $this, 'set_tinymce_settings' ), 10, 2 ); |
| 467 | add_filter( 'wp_default_editor', array( $this, 'set_editor_to_tinymce' ) ); |
| 468 | add_filter( 'tiny_mce_plugins', array( $this, 'remove_despised_editor_plugins' ) ); |
| 469 | add_filter( 'mce_buttons', array( $this, 'remove_readmore_tag' ) ); |
| 470 | } |
| 471 | |
| 472 | /** |
| 473 | * Modify tinymce editor settings. |
| 474 | * |
| 475 | * @param array $settings Registered settings. |
| 476 | * @param string $editor_id Current editor ID. |
| 477 | */ |
| 478 | public function set_tinymce_settings( $settings, $editor_id ) { |
| 479 | $settings['paste_as_text'] = 'true'; |
| 480 | |
| 481 | return $settings; |
| 482 | } |
| 483 | |
| 484 | /** |
| 485 | * Sets default editor to tinymce for opt-in admin |
| 486 | * |
| 487 | * @param string $editor_type Current editor type. |
| 488 | * @return string |
| 489 | */ |
| 490 | public function set_editor_to_tinymce( $editor_type ) { |
| 491 | return 'tinymce'; |
| 492 | } |
| 493 | |
| 494 | /** |
| 495 | * Removes unnecessary editor plugins |
| 496 | * |
| 497 | * @param array $plugins Registered plugins. |
| 498 | * @return mixed |
| 499 | */ |
| 500 | public function remove_despised_editor_plugins( $plugins ) { |
| 501 | $k = array_search( 'fullscreen', $plugins, true ); |
| 502 | if ( false !== $k ) { |
| 503 | unset( $plugins[ $k ] ); |
| 504 | } |
| 505 | $plugins[] = 'paste'; |
| 506 | return $plugins; |
| 507 | } |
| 508 | |
| 509 | /** |
| 510 | * Removes the "Read more" tag from the editor. |
| 511 | * |
| 512 | * @param array $mce_buttons Array of TinyMCE buttons. |
| 513 | * @return array |
| 514 | */ |
| 515 | public function remove_readmore_tag( $mce_buttons ) { |
| 516 | $remove = array( 'wp_more' ); |
| 517 | return array_diff( $mce_buttons, $remove ); |
| 518 | } |
| 519 | |
| 520 | /** |
| 521 | * Gets the current tab the page is on load. |
| 522 | * Used by wizards and the global settings page. |
| 523 | * |
| 524 | * @since 4.3.1 |
| 525 | * |
| 526 | * @param boolean|string $default_value Default value. |
| 527 | * @return boolean|string |
| 528 | */ |
| 529 | protected function get_current_section( $default_value = false ) { |
| 530 | $section = filter_input( INPUT_GET, 'section', FILTER_SANITIZE_SPECIAL_CHARS ); |
| 531 | return empty( $section ) ? $default_value : $section; |
| 532 | } |
| 533 | |
| 534 | /** |
| 535 | * SUI summary config. |
| 536 | * |
| 537 | * @since 4.2.0 |
| 538 | * |
| 539 | * @param string|null $class_name Class to be added. |
| 540 | */ |
| 541 | protected function get_sui_summary_config( $class_name = null ) { |
| 542 | $style = ''; |
| 543 | $image_url = apply_filters( 'wpmudev_branding_hero_image', null ); |
| 544 | if ( ! empty( $image_url ) ) { |
| 545 | $style = 'background-image:url(' . esc_url( $image_url ) . ')'; |
| 546 | } |
| 547 | $sui = array( |
| 548 | 'summary' => array( |
| 549 | 'style' => $style, |
| 550 | 'classes' => array( |
| 551 | 'sui-box', |
| 552 | 'sui-summary', |
| 553 | ), |
| 554 | ), |
| 555 | ); |
| 556 | if ( ! empty( $class_name ) && is_string( $class_name ) ) { |
| 557 | $sui['summary']['classes'][] = $class_name; |
| 558 | } |
| 559 | /** |
| 560 | * Dash integration |
| 561 | * |
| 562 | * @since 4.0.0 |
| 563 | */ |
| 564 | $hide_branding = apply_filters( 'wpmudev_branding_hide_branding', false ); |
| 565 | $branding_image = apply_filters( 'wpmudev_branding_hero_image', null ); |
| 566 | if ( $hide_branding && ! empty( $branding_image ) ) { |
| 567 | $sui['summary']['classes'][] = 'sui-rebranded'; |
| 568 | } elseif ( $hide_branding && empty( $branding_image ) ) { |
| 569 | $sui['summary']['classes'][] = 'sui-unbranded'; |
| 570 | } |
| 571 | return $sui; |
| 572 | } |
| 573 | |
| 574 | /** |
| 575 | * Gets the SUI classes according to the selected setitngs in WPMU Dev dashboard. |
| 576 | * |
| 577 | * @since 4.3.1 |
| 578 | * |
| 579 | * @return string |
| 580 | */ |
| 581 | protected function get_sui_wrap_class() { |
| 582 | $classes = array( 'sui-wrap', 'sui-wrap-hustle' ); |
| 583 | |
| 584 | /** |
| 585 | * Add high contrast mode. |
| 586 | */ |
| 587 | $accessibility = Hustle_Settings_Admin::get_hustle_settings( 'accessibility' ); |
| 588 | $is_high_contrast_mode = ! empty( $accessibility['accessibility_color'] ); |
| 589 | if ( $is_high_contrast_mode ) { |
| 590 | $classes[] = 'sui-color-accessible'; |
| 591 | } |
| 592 | |
| 593 | /** |
| 594 | * Set hide branding. |
| 595 | * |
| 596 | * @since 4.0.0 |
| 597 | */ |
| 598 | $hide_branding = apply_filters( 'wpmudev_branding_hide_branding', false ); |
| 599 | if ( $hide_branding ) { |
| 600 | $classes[] = 'no-hustle'; |
| 601 | } |
| 602 | /** |
| 603 | * Hero image. |
| 604 | * |
| 605 | * @since 4.0.0 |
| 606 | */ |
| 607 | $image = apply_filters( 'wpmudev_branding_hero_image', 'hustle-default' ); |
| 608 | if ( empty( $image ) ) { |
| 609 | $classes[] = 'no-hustle-hero'; |
| 610 | } |
| 611 | |
| 612 | $classes = apply_filters( 'hustle_sui_wrap_class', $classes ); |
| 613 | |
| 614 | return implode( ' ', $classes ); |
| 615 | } |
| 616 | |
| 617 | /** |
| 618 | * Renders the modals. |
| 619 | * This abstract class renders the modals that are displayed on all hustle's pages. |
| 620 | * Each page should override this method to add the specific modals for it. |
| 621 | * |
| 622 | * @since 4.3.5 |
| 623 | */ |
| 624 | protected function render_modals() {} |
| 625 | |
| 626 | /** |
| 627 | * Add wp color picker |
| 628 | */ |
| 629 | protected static function add_color_picker() { |
| 630 | // Deregister other similar pickers if they load from other plugins or theme. |
| 631 | wp_deregister_script( 'wp-color-picker-alpha' ); |
| 632 | |
| 633 | wp_register_script( 'wp-color-picker-alpha', Opt_In::$plugin_url . 'assets/js/vendor/wp-color-picker-alpha.min.js', array( 'wp-color-picker' ), '3.0.2', true ); |
| 634 | |
| 635 | $color_picker_strings = array( |
| 636 | 'clear' => esc_html__( 'Clear', 'hustle' ), |
| 637 | 'clearAriaLabel' => esc_html__( 'Clear color', 'hustle' ), |
| 638 | 'defaultString' => esc_html__( 'Default', 'hustle' ), |
| 639 | 'defaultAriaLabel' => esc_html__( 'Select default color', 'hustle' ), |
| 640 | 'pick' => esc_html__( 'Select Color', 'hustle' ), |
| 641 | 'defaultLabel' => esc_html__( 'Color value', 'hustle' ), |
| 642 | ); |
| 643 | wp_localize_script( 'wp-color-picker-alpha', 'wpColorPickerL10n', $color_picker_strings ); |
| 644 | wp_enqueue_script( 'wp-color-picker-alpha' ); |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | endif; |
| 649 |