false, 'enable_prefetch' => false, 'block_keyboard_reload' => false, // Cache/Prefetch settings. 'prefetch_on_mousedown' => false, 'prefetch_ignore_visited' => false, // Advanced. 'ignore_elements' => '', // Progressbar. 'progressbar_position' => 'top', 'progressbar_class' => '', 'progressbar_id' => '', 'progressbar_color' => '#037bff', 'progressbar_weight' => 'thin', 'progressbar_weight_custom' => '7px', 'progressbar_opacity' => 80, 'progressbar_animate' => true, 'progressbar_animation_speed' => 1.5, 'progressbar_auto_hide' => true, // Spinner. 'loader_layout' => 'icon_only', 'loader_class' => '', 'loader_id' => '', 'animate_cursor' => true, 'cursor_mode' => 'wait', 'disable_mouse_clicks' => false, 'loader_image' => AJAXPRESS_URL . 'public/images/loading/1.gif', 'loader_image_size' => 40, 'loader_image_rotation' => 0, 'loader_gap' => 10, 'loader_message' => 'Loading...', 'loader_color' => '#000000', 'loader_font_family' => '', 'loader_font_weight' => 'normal', 'loader_font_size' => 14, 'loader_letter_spacing' => 0, 'loader_background' => '#ffffff', 'loader_background_opacity' => 70, // Content animation. 'content_animation' => false, 'content_animation_name' => 'fade', 'content_animation_duration' => '0.3', ); } /** * Types of the Pro settings, for the settings sanitizer. * * @return array */ public static function get_pro_schema() { $bool = array( 'type' => 'bool' ); return array( 'enable_admin_spa' => $bool, 'enable_prefetch' => $bool, 'block_keyboard_reload' => $bool, 'prefetch_on_mousedown' => $bool, 'prefetch_ignore_visited' => $bool, 'ignore_elements' => array( 'type' => 'selectors' ), 'progressbar_position' => array( 'type' => 'enum', 'values' => array( 'top', 'bottom' ) ), 'progressbar_class' => array( 'type' => 'html_classes' ), 'progressbar_id' => array( 'type' => 'html_id' ), 'progressbar_color' => array( 'type' => 'color' ), 'progressbar_weight' => array( 'type' => 'bar_weight' ), 'progressbar_weight_custom' => array( 'type' => 'css_length' ), 'progressbar_opacity' => array( 'type' => 'int', 'min' => 0, 'max' => 100 ), 'progressbar_animate' => $bool, 'progressbar_animation_speed' => array( 'type' => 'float', 'min' => 0.1, 'max' => 10 ), 'progressbar_auto_hide' => $bool, 'loader_layout' => array( 'type' => 'enum', 'values' => array( 'icon_only', 'icon_left', 'icon_right', 'icon_top', 'icon_bottom', 'text_only' ) ), 'loader_class' => array( 'type' => 'html_classes' ), 'loader_id' => array( 'type' => 'html_id' ), 'animate_cursor' => $bool, 'cursor_mode' => array( 'type' => 'enum', 'values' => array( 'wait', 'progress', 'not-allowed', 'auto', 'default', 'pointer', 'crosshair' ) ), 'disable_mouse_clicks' => $bool, 'loader_image' => array( 'type' => 'url' ), 'loader_image_size' => array( 'type' => 'int', 'min' => 0, 'max' => 1000 ), 'loader_image_rotation' => array( 'type' => 'int', 'min' => -360, 'max' => 360 ), 'loader_gap' => array( 'type' => 'int', 'min' => 0, 'max' => 200 ), 'loader_message' => array( 'type' => 'text' ), 'loader_color' => array( 'type' => 'color' ), 'loader_font_family' => array( 'type' => 'text' ), 'loader_font_weight' => array( 'type' => 'font_weight' ), 'loader_font_size' => array( 'type' => 'int', 'min' => 1, 'max' => 200 ), 'loader_letter_spacing' => array( 'type' => 'float', 'min' => -20, 'max' => 50 ), 'loader_background' => array( 'type' => 'color' ), 'loader_background_opacity' => array( 'type' => 'int', 'min' => 0, 'max' => 100 ), 'content_animation' => $bool, 'content_animation_name' => array( 'type' => 'enum', 'values' => array( 'fade', 'slide', 'scale', 'flip' ) ), 'content_animation_duration' => array( 'type' => 'duration' ), ); } /** * Add the Pro settings' types to the sanitizer's schema. * * @param array $schema Rules keyed by setting name. * @return array */ public function settings_schema( $schema ) { if ( ! self::is_active() ) { return $schema; } return array_merge( $schema, self::get_pro_schema() ); } /** * Keys of the settings that need a license. Every Pro setting. * * @return array */ public static function get_premium_features() { return array_keys( self::get_pro_defaults() ); } /** * Add the Pro settings to the defaults. * * @param array $defaults Default settings. * @return array */ public function default_settings( $defaults ) { if ( ! self::is_active() ) { return $defaults; } return array_merge( $defaults, self::get_pro_defaults() ); } /** * Carry old Pro settings forward. * * @param array $settings Merged settings. * @param array $options_from_db Raw options from the database. * @return array */ public function migrate_settings( $settings, $options_from_db ) { if ( ! self::is_active() ) { return $settings; } // Migrate loader_image_position → loader_layout. if ( isset( $options_from_db['loader_image_position'] ) && ! isset( $options_from_db['loader_layout'] ) ) { $position_map = array( 'left' => 'icon_left', 'right' => 'icon_right', 'top' => 'icon_top', 'bottom' => 'icon_bottom', ); $old_position = $options_from_db['loader_image_position']; $settings['loader_layout'] = isset( $position_map[ $old_position ] ) ? $position_map[ $old_position ] : 'icon_left'; } return $settings; } /** * Whether the site holds an active license. * * @return bool */ public static function is_licensed() { $license = get_option( 'ajaxpress_license', array() ); return ! empty( $license['key'] ) && 'active' === ( isset( $license['status'] ) ? $license['status'] : '' ); } /** * Reset the Pro settings to their defaults for output while the * license is inactive. Runtime only: the saved values are untouched, * so they come back as soon as the license does. * * @param array $settings Settings about to be used. * @return array */ public function filter_premium_settings( $settings ) { if ( ! self::is_active() || self::is_licensed() ) { return $settings; } $defaults = self::get_pro_defaults(); foreach ( $defaults as $feature => $default ) { if ( array_key_exists( $feature, $settings ) ) { $settings[ $feature ] = $default; } } return $settings; } /** * Cursor and animation timing for the frontend's inline CSS. * * @param array $vars CSS variables. * @param array $settings Public settings. * @return array */ public function inline_css_vars( $vars, $settings ) { if ( ! self::is_active() ) { return $vars; } $vars['cursor'] = isset( $settings['cursor_mode'] ) ? $settings['cursor_mode'] : 'auto'; $vars['duration'] = floatval( isset( $settings['content_animation_duration'] ) ? $settings['content_animation_duration'] : 0.3 ); return $vars; } /** * Tell the frontend bundle to register its bundled Pro modules. * * @param array $vars Frontend variables. * @return array */ public function frontend_vars( $vars ) { $vars['legacy_pro'] = self::is_active(); return $vars; } /** * Run the SPA across wp-admin when the Admin SPA setting is on. * * @return bool */ public function enqueue_admin_spa() { if ( ! self::is_active() ) { return false; } $settings = Options::get_instance()->get_settings( true ); // Only load if admin SPA is enabled. if ( empty( $settings['enable_admin_spa'] ) ) { return false; } // Enqueue the frontend script (reuse iframe-container). wp_enqueue_style( 'ajaxpress', AJAXPRESS_URL . 'public/css/ajaxpress.min.css', array(), AJAXPRESS_VERSION ); wp_enqueue_script( 'ajaxpress', AJAXPRESS_URL . 'public/js/ajaxpress.min.js', array(), AJAXPRESS_VERSION, true ); // Pass settings to script. wp_localize_script( 'ajaxpress', 'ajaxpress_vars', array( 'settings' => $settings, 'is_admin' => true, 'admin_url' => admin_url(), 'legacy_pro' => true, ) ); return true; } /** * Print the pre-2.3 loader markup in the footer. * * @return void */ public function load_templates() { if ( ! self::is_active() || ! class_exists( __NAMESPACE__ . '\Templates' ) ) { return; } Templates::get_instance()->load_templates(); } } Legacy_Pro::start(); }