true, 'enable_comments' => false, 'enable_search' => false, 'enable_live_search' => false, // Beta controls. 'enable_forms' => false, 'ignore_forms' => '', 'prevent_reloads' => false, 'disable_for_mobile' => false, 'disable_logged_in_users' => false, // Advanced. 'target' => '', 'ignore_elements' => '', 'ignore_links' => '', // progressbar. 'progressbar' => true, 'progressbar_position' => 'top', 'progressbar_auto_hide' => false, 'progressbar_weight' => 7, 'progressbar_color' => '#037bff', 'progressbar_opacity' => 80, 'progressbar_class' => '', 'progressbar_id' => '', 'progressbar_css' => '', // Loader. 'loader' => false, 'loader_image' => AJAXPRESS_URL . 'public/images/loading.gif', 'loader_image_size' => 40, 'loader_image_rotation' => 0, 'loader_image_position' => 'left', 'loader_message' => 'Please wait..', 'loader_font_family' => 'sans-serif', 'loader_font_size' => 13, 'loader_font_weight' => 500, 'loader_letter_spacing' => 1.1, 'loader_color' => '#000000', 'loader_background' => '#ffffff', 'loader_background_opacity' => 70, 'loader_gap' => 5, 'loader_class' => '', 'loader_id' => '', 'loader_css' => '', 'animate_cursor' => true, 'cursor_mode' => 'wait', 'disable_mouse_clicks' => false, 'content_animation' => false, 'content_animation_name' => 'fade', 'content_animation_delay' => 0, 'content_animation_duration' => .3, 'scroll_to_top' => true, ]; return apply_filters( 'ajaxpress_default_options', $options ); } /** * Get settings. * * @param bool $filter_premium Whether to filter premium features based on license. * @return array */ public function get_settings( $filter_premium = false ): array { global $wpdb; $defaults = $this->get_default_settings(); if ( empty( $defaults ) ) { return []; } // Fetch all ajaxpress options in a single query. $prefix = $wpdb->esc_like( AJAXPRESS_PREFIX ) . '%'; $results = $wpdb->get_results( $wpdb->prepare( "SELECT option_name, option_value FROM {$wpdb->options} WHERE option_name LIKE %s", $prefix ), ARRAY_A ); // Build options array from query results. $options_from_db = []; if ( ! empty( $results ) ) { foreach ( $results as $row ) { $option_name = str_replace( AJAXPRESS_PREFIX, '', $row['option_name'] ); $options_from_db[ $option_name ] = maybe_unserialize( $row['option_value'] ); } } // Merge with defaults (use DB values if exist, otherwise use defaults). $settings = []; foreach ( $defaults as $name => $default_value ) { $settings[ $name ] = isset( $options_from_db[ $name ] ) ? $options_from_db[ $name ] : $default_value; } // Filter premium features if requested and license is not active. if ( $filter_premium ) { $settings = $this->filter_premium_settings( $settings ); } return $settings; } /** * Get premium features list. * * @return array List of premium feature keys. */ public function get_premium_features(): array { return array( // Feature toggles. 'enable_search', 'enable_forms', 'prevent_reloads', 'disable_for_mobile', 'disable_logged_in_users', // Advanced settings. 'target', 'ignore_elements', 'ignore_links', // Progressbar customization. 'progressbar_position', 'progressbar_auto_hide', 'progressbar_weight', 'progressbar_color', 'progressbar_opacity', 'progressbar_class', 'progressbar_id', 'progressbar_css', // Loader customization. 'loader_image', 'loader_image_size', 'loader_image_rotation', 'loader_image_position', 'loader_message', 'loader_font_family', 'loader_font_size', 'loader_font_weight', 'loader_letter_spacing', 'loader_color', 'loader_background', 'loader_background_opacity', 'loader_gap', 'loader_class', 'loader_id', 'loader_css', // Content animation. 'content_animation', 'content_animation_name', 'content_animation_delay', 'content_animation_duration', ); } /** * Filter premium settings based on license status. * * @param array $settings Settings array. * @return array Filtered settings. */ public function filter_premium_settings( $settings ): array { $license = \AjaxPress\Common\License::get_license(); $is_license_active = ! empty( $license ) && isset( $license['key'] ) && isset( $license['status'] ) && 'active' === $license['status']; // If license is active, return settings as is. if ( $is_license_active ) { return $settings; } $defaults = $this->get_default_settings(); $premium_features = $this->get_premium_features(); // Reset premium features to defaults. foreach ( $premium_features as $feature ) { if ( isset( $defaults[ $feature ] ) ) { $settings[ $feature ] = $defaults[ $feature ]; } } return $settings; } /** * Reset premium settings to defaults in database. * * @return bool */ public function reset_premium_settings(): bool { $defaults = $this->get_default_settings(); $premium_features = $this->get_premium_features(); // Reset premium features to defaults in database. foreach ( $premium_features as $feature ) { if ( isset( $defaults[ $feature ] ) ) { update_option( AJAXPRESS_PREFIX . $feature, $defaults[ $feature ] ); } } return true; } /** * Update settings. * * @param $new_settings New settings Array. * @return bool */ public function update_settings( $new_settings = [] ): bool { $default_keys = array_keys( $this->get_default_settings() ); if ( empty( $default_keys ) ) { return false; } foreach ( $default_keys as $name ) { update_option( AJAXPRESS_PREFIX . $name, $new_settings[ $name ] ); } return true; } /** * Get animation templates. * * @return array */ protected function get_animation_templates(): array { $templates = [ 'simple' => [ 'icon_position' => 'left', //left, right, none 'icon_url' => '', 'icon_size' => '20px', 'icon_animation' => 'spin', 'text' => '', 'typography' => [ 'font_family' => '', 'font_size' => '14px', 'font_weight' => '500', 'letter_space' => 1, 'line_height' => 1, 'color' => '#343434', ], 'background' => '#f0f0f0', 'background_opacity' => .3, ], 'xor' => [ 'icon_position' => 'left', //left, right, none 'icon_url' => '', 'icon_size' => '20px', 'icon_animation' => 'spin', 'text' => '', 'typography' => [ 'font_family' => '', 'font_size' => '14px', 'font_weight' => '500', 'letter_space' => 1, 'line_height' => 1, 'color' => '#343434', ], 'background' => '#f0f0f0', 'background_opacity' => .3, ], ]; return apply_filters( 'ajaxpress_animation_templates', $templates ); } } }