delete( $wpdb->postmeta, array( 'meta_key' => BSF_AIOSRS_PRO_CACHE_KEY ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching } } /** * Ajax handeler to return the pages based on the search query. * When searching for the pages only titles are searched for. * * @since 1.0.0 */ public function bsf_get_specific_pages() { if ( ! current_user_can( 'manage_options' ) ) { return false; } check_ajax_referer( 'spec_schema', 'nonce_ajax' ); $aiosrs_meta_default = array( array( 'ID' => '0', 'post_title' => '--None--', ), ); $search_string = isset( $_POST['q'] ) ? sanitize_text_field( $_POST['q'] ) : ''; $data = array(); global $wpdb; // WPCS: unprepared SQL OK. $aiosrs_meta_array = $wpdb->get_results( "SELECT DISTINCT ID, post_title FROM {$wpdb->posts} WHERE post_title LIKE '%{$search_string}%' && post_type = 'page'", ARRAY_A ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $aiosrs_meta_array = array_merge( $aiosrs_meta_default, $aiosrs_meta_array ); if ( isset( $aiosrs_meta_array ) && ! empty( $aiosrs_meta_array ) ) { foreach ( $aiosrs_meta_array as $value ) { $data[] = array( 'id' => $value['ID'], 'text' => preg_replace( '/^_/', '', esc_html( str_replace( '_', ' ', $value['post_title'] ) ) ), ); } wp_send_json( $data ); } } /** * Delete the cached structured data of all the posts. * * @return bool */ public function delete_schema_cache() { if ( ! current_user_can( 'manage_options' ) ) { return false; } check_ajax_referer( 'regenerate_schema', 'nonce' ); global $wpdb; $wpdb->delete( $wpdb->postmeta, array( 'meta_key' => BSF_AIOSRS_PRO_CACHE_KEY ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching wp_send_json( array( 'msg' => __( 'Schema Regenerated Successfully', 'wp-schema-pro' ) ) ); } /** * Initialize * * @since 1.1.0 * @return void */ public function init() { $all_pages = get_pages(); if ( ! empty( $all_pages ) && is_array( $all_pages ) ) { foreach ( $all_pages as $page ) { self::$pages[ $page->ID ] = $page->post_title; } } } /** * Save All admin settings here */ public function save_settings() { // Only admins can save settings. if ( ! current_user_can( 'manage_options' ) ) { return; } if ( isset( $_POST['wp-schema-pro-white-label-nonce'] ) && wp_verify_nonce( sanitize_text_field( $_POST['wp-schema-pro-white-label-nonce'] ), 'white-label' ) ) { $branding_options = BSF_AIOSRS_Pro_Helper::$settings['wp-schema-pro-branding-settings']; $input_settings = array(); $new_settings = array(); if ( isset( $_POST['wp-schema-pro-branding-settings'] ) ) { $input_settings = $_POST['wp-schema-pro-branding-settings']; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized // Loop through the input and sanitize each of the values. foreach ( $input_settings as $key => $val ) { if ( is_array( $val ) ) { foreach ( $val as $k => $v ) { $new_settings[ $key ][ $k ] = ( isset( $val[ $k ] ) ) ? sanitize_text_field( $v ) : ''; } } else { $new_settings[ $key ] = ( isset( $input_settings[ $key ] ) ) ? sanitize_text_field( $val ) : ''; } } $new_settings = wp_parse_args( $new_settings, $branding_options ); } // Update the site-wide option since we're in the network admin. if ( is_multisite() ) { update_site_option( 'wp-schema-pro-branding-settings', $new_settings ); update_site_option( 'hide_label', 'true' ); } else { update_option( 'wp-schema-pro-branding-settings', $new_settings ); update_option( 'hide_label', 'true' ); } } } /** * Redirect to astra page. */ public static function admin_redirects() { if ( isset( $_REQUEST['wp_schema_pro_admin_page_nonce'] ) && ! wp_verify_nonce( sanitize_text_field( $_REQUEST['wp_schema_pro_admin_page_nonce'] ), 'wp_schema_pro_admin_page' ) ) { return; } global $pagenow; if ( 'post-new.php' === $pagenow && isset( $_GET['post_type'] ) && 'aiosrs-schema' === $_GET['post_type'] ) { wp_safe_redirect( admin_url( 'index.php?page=aiosrs-pro-setup' ) ); exit; } } /** * Redirect to main schema page when white label is activated. */ public static function white_label_admin_redirects() { if ( is_multisite() ) { if ( 'true' === get_site_option( 'hide_label' ) ) { global $pagenow; if ( 'options-general.php' === $pagenow ) { delete_site_option( 'hide_label' ); wp_safe_redirect( admin_url( 'options-general.php?page=' . self::$plugin_slug . '&action=aiosrs-schema' ) ); exit; } } } else { if ( 'true' === get_option( 'hide_label' ) ) { global $pagenow; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.VariableRedeclaration if ( 'options-general.php' === $pagenow ) { delete_option( 'hide_label' ); wp_safe_redirect( admin_url( 'options-general.php?page=' . self::$plugin_slug . '&action=aiosrs-schema' ) ); exit; } } } } /** * Return White Label status to BSF Analytics. * Return true if the White Label is enabled from Schema Pro to the BSF Analytics library. * * @since 2.0.1 * @param array $bsf_wpsp_analytics_arr array of white labeled products. * @return array product name with white label status. */ public function bsf_wpsp_white_label_option( $bsf_wpsp_analytics_arr ) { if ( ! isset( $bsf_wpsp_analytics_arr['wp-schema-pro'] ) ) { $bsf_wpsp_analytics_arr['wp-schema-pro'] = true; } return $bsf_wpsp_analytics_arr; } /** * Include schema wizard */ public static function schema_wizard() { if ( isset( $_REQUEST['wp_schema_pro_admin_page_nonce'] ) && ! wp_verify_nonce( sanitize_text_field( $_REQUEST['wp_schema_pro_admin_page_nonce'] ), 'wp_schema_pro_admin_page' ) ) { return; } // Setup/welcome. if ( isset( $_GET['page'] ) && 'aiosrs-pro-setup' === $_GET['page'] ) { include_once BSF_AIOSRS_PRO_DIR . 'classes/class-bsf-aiosrs-pro-schema-wizard.php'; } if ( isset( $_GET['page'] ) && 'aiosrs-pro-setup-wizard' === $_GET['page'] ) { include_once BSF_AIOSRS_PRO_DIR . 'classes/class-bsf-aiosrs-pro-setup-wizard.php'; } } /** * Keep the Schema Pro menu open when editing the advanced headers. * Highlights the wanted admin (sub-) menu items for the CPT. * * @since 1.0.0 */ public function menu_highlight() { if ( isset( $_REQUEST['wp_schema_pro_admin_page_nonce'] ) && ! wp_verify_nonce( sanitize_text_field( $_REQUEST['wp_schema_pro_admin_page_nonce'] ), 'wp_schema_pro_admin_page' ) ) { return; } global $parent_file, $submenu_file, $post_type; $parent_page = self::$default_menu_position; $setting_options = BSF_AIOSRS_Pro_Helper::$settings['aiosrs-pro-settings']; $menu_position = isset( $setting_options['menu-position'] ) ? $setting_options['menu-position'] : $parent_page; $is_top_level_page = in_array( $menu_position, array( 'top', 'middle', 'bottom' ), true ); if ( $is_top_level_page && isset( $_GET['page'] ) && self::$plugin_slug === $_GET['page'] ) { $parent_file = self::$plugin_slug; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited if ( isset( $_GET['action'] ) && ! empty( $_GET['action'] ) ) { $submenu_file = esc_url( // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited add_query_arg( array( 'action' => sanitize_text_field( $_GET['action'] ), 'page' => self::$plugin_slug, ), admin_url() ) ); } else { $submenu_file = self::$plugin_slug; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited } } } /** * Register AIPRS Pro settings * * @return void */ public function register_settings() { register_setting( 'wp-schema-pro-general-settings-group', 'wp-schema-pro-general-settings' ); register_setting( 'wp-schema-pro-social-profiles-group', 'wp-schema-pro-social-profiles' ); register_setting( 'wp-schema-pro-social-profiles-repeater-group', 'wp-schema-pro-social-profiles-repeater' ); register_setting( 'wp-schema-pro-global-schemas-group', 'wp-schema-pro-global-schemas' ); register_setting( 'wp-schema-pro-breadcrumb-setting-group', 'wp-schema-pro-breadcrumb-setting' ); register_setting( 'aiosrs-pro-settings-group', 'aiosrs-pro-settings' ); register_setting( 'wp-schema-pro-branding-group', 'wp-schema-pro-branding-settings' ); register_setting( 'wp-schema-pro-corporate-contact-group', 'wp-schema-pro-corporate-contact' ); } /** * Redirect to menu position. * * @param string $location URL. * @return string */ public function redirect_menu_position( $location ) { $value = get_option( 'aiosrs-pro-settings' ); $current_parts = wp_parse_url( $location ); if ( isset( $current_parts['query'] ) ) { parse_str( $current_parts['query'], $current_query ); } if ( isset( $current_query['page'] ) && isset( $current_query['action'] ) && self::$plugin_slug === $current_query['page'] && 'wpsp-advanced-settings' === $current_query['action'] ) { // Menu position. $menu_position = isset( $value['menu-position'] ) ? $value['menu-position'] : self::$default_menu_position; $is_top_level_page = in_array( $menu_position, array( 'top', 'middle', 'bottom' ), true ); // If menu is at top level. if ( $is_top_level_page ) { $url = esc_url( // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited add_query_arg( array( 'page' => self::$plugin_slug, 'action' => 'wpsp-advanced-settings', ), admin_url() . 'admin.php' ) ); } else { if ( strpos( $menu_position, '?' ) !== false ) { $query_var = 'page=' . self::$plugin_slug . '&action=wpsp-advanced-settings'; } else { $query_var = '?page=' . self::$plugin_slug . '&action=wpsp-advanced-settings'; } $url = add_query_arg( $query_var, '', admin_url() . $menu_position ); } $new_parts = wp_parse_url( $url ); parse_str( $new_parts['query'], $new_query ); if ( $new_parts['path'] !== $current_parts['path'] || ( isset( $new_query['post_type'] ) && ! isset( $current_query['post_type'] ) ) || ( ! isset( $new_query['post_type'] ) && isset( $current_query['post_type'] ) ) || isset( $new_query['post_type'] ) !== isset( $current_query['post_type'] ) ) { $location = $url; } } return $location; } /** * Get Admin Menu Positions. * * @since 1.1.0 * @return array */ public static function get_admin_menu_positions() { // Get list of current General entries. $entries = array(); foreach ( $GLOBALS['menu'] as $entry ) { if ( false !== strpos( $entry[2], '.php' ) ) { $entries[ $entry[2] ] = $entry[0]; } } // Remove elements with notification bubbles (e.g. update or comment count). if ( isset( $entries['plugins.php'] ) ) { $entries['plugins.php'] = preg_replace( '/ /', '', $entries['plugins.php'] ); } if ( isset( $entries['edit-comments.php'] ) ) { $entries['edit-comments.php'] = preg_replace( '/ /', '', $entries['edit-comments.php'] ); } $entries['top'] = __( 'Top-Level (top)', 'wp-schema-pro' ); $entries['middle'] = __( 'Top-Level (middle)', 'wp-schema-pro' ); $entries['bottom'] = __( 'Top-Level (bottom)', 'wp-schema-pro' ); return $entries; } /** * Get Settings. * * @param string $setting Option name. * @return array */ /** * Show action links on the plugin screen. * * @param mixed $links Plugin Action links. * @return array */ public function action_links( $links ) { $admin_url = self::get_page_url( self::$parent_page_slug ); $action_links = array( 'settings' => '' . esc_html__( 'Settings', 'wp-schema-pro' ) . '', ); return array_merge( $action_links, $links ); } /** * Admin settings init */ public function init_admin_settings() { self::$menu_page_title = apply_filters( 'wp_schema_pro_menu_page_title', __( 'Schema Pro', 'wp-schema-pro' ) ); add_action( 'admin_menu', array( $this, 'aiosrs_admin_menu_register' ) ); add_action( 'admin_menu', array( $this, 'add_admin_menu_rename' ), 9999 ); } /** * Tooltip * * @since 1.1.0 * @param string $message Tooltips message. * @param string $title Tooltips title. * @return void */ public static function get_tooltip( $message = '', $title = '' ) { ?>

esc_html__( 'Website Information', 'wp-schema-pro' ), 'show' => ! is_network_admin(), ); return $actions; } /** * Add Plugin settings option in menu page * * @param array $actions Array of actions. * @return array Return the actions. */ public function wpsp_advanced_setting_options( $actions ) { $actions['wpsp-advanced-settings'] = array( 'label' => esc_html__( 'Plugin Settings', 'wp-schema-pro' ), 'show' => ! is_network_admin(), ); return $actions; } /** * Add White Label option in menu page * * @param array $actions Array of actions. * @return array Return the actions. */ public function branding_settings_options( $actions ) { $actions['branding-settings'] = array( 'label' => esc_html__( 'White Label', 'wp-schema-pro' ), 'show' => ! is_network_admin(), ); return $actions; } /** * Add extension option in menu page * * @param array $actions Array of actions. * @return array Return the actions. */ public function breadcrumb_settings_options( $actions ) { $actions['breadcrumb-settings'] = array( 'label' => esc_html__( 'Breadcrumbs', 'wp-schema-pro' ), 'show' => ! is_network_admin(), ); return $actions; } /** * Init Nav Menu * * @param mixed $action Action name. * @since 1.0 */ public static function init_nav_menu( $action = '' ) { if ( '' !== $action ) { ?>

id ) ) { return; } if ( 'plugins' !== get_current_screen()->id ) { return; } require_once BSF_AIOSRS_PRO_DIR . 'template/license-form.php'; if ( isset( $_GET['aiosrs-pro-license-form'] ) ) { ?> wp_create_nonce( 'schema_nonce' ), 'specified_field' => wp_create_nonce( 'spec_schema' ), ) ) ); } if ( isset( $_GET['page'] ) && 'aiosrs_pro_admin_menu_page' === $_GET['page'] ) { wp_enqueue_style( 'aiosrs-pro-admin-style', BSF_AIOSRS_PRO_URI . 'admin/assets/' . self::$minfy_css . 'settings-style.' . self::$minfy_css_ext, BSF_AIOSRS_PRO_VER, 'false' ); wp_enqueue_script( 'aiosrs-pro-settings-script', BSF_AIOSRS_PRO_URI . 'admin/assets/' . self::$minfy_js . 'settings-script.' . self::$minfy_js_ext, array( 'jquery', 'bsf-target-rule-select2', 'wp-i18n', 'wp-util' ), BSF_AIOSRS_PRO_VER, null, true ); wp_enqueue_media(); wp_enqueue_style( 'bsf-target-rule-select2', BSF_AIOSRS_PRO_URI . 'classes/lib/target-rule/select2.css', '', BSF_AIOSRS_PRO_VER, false ); wp_register_script( 'bsf-target-rule-select2', BSF_AIOSRS_PRO_URI . 'classes/lib/target-rule/select2.js', array( 'jquery', 'backbone', 'wp-util' ), BSF_AIOSRS_PRO_VER, true ); if ( function_exists( 'wp_set_script_translations' ) ) { wp_set_script_translations( 'aiosrs-pro-settings-script', 'wp-schema-pro' ); } wp_localize_script( 'aiosrs-pro-settings-script', 'AIOSRS_search', apply_filters( 'aiosrs_pro_settings_script_localize', array( 'search_field' => wp_create_nonce( 'spec_schema' ), 'ajax_url' => admin_url( 'admin-ajax.php' ), 'ajax_nonce' => wp_create_nonce( 'wpsp-block-nonce' ), 'activate' => __( 'Activate', 'wp-schema-pro' ), 'deactivate' => __( 'Deactivate', 'wp-schema-pro' ), ) ) ); } } /** * Admin bar menu * * @return void */ public function admin_bar() { $settings = BSF_AIOSRS_Pro_Helper::$settings['aiosrs-pro-settings']; $quick_test = isset( $settings['quick-test'] ) ? $settings['quick-test'] : ''; if ( '1' === $quick_test ) { global $wp_admin_bar; $http = ( ! empty( $_SERVER['HTTPS'] ) && 'on' === $_SERVER['HTTPS'] ) ? 'https' : 'http'; $actual_link = ( isset( $_SERVER['HTTP_HOST'] ) && isset( $_SERVER['REQUEST_URI'] ) ) ? $http . '://' . sanitize_text_field( $_SERVER['HTTP_HOST'] ) . esc_url_raw( $_SERVER['REQUEST_URI'] ) : ''; if ( ! is_super_admin() || ! is_admin_bar_showing() ) { return; } if ( ! is_admin() ) { $wp_admin_bar->add_menu( array( 'id' => 'aiosrs', 'title' => 'Test Schema', 'href' => 'https://search.google.com/test/rich-results?url=' . esc_url( $actual_link ), 'meta' => array( 'target' => '_blank', 'rel' => 'noopener', ), ) ); } } } /** * Setting Page markup. * * @return void */ public function setting_page() { require_once BSF_AIOSRS_PRO_DIR . 'template/settings.php'; } /** * Plugin Settings Page markup. * * @return void */ public function load_wpsp_advanced_setting_page() { require_once BSF_AIOSRS_PRO_DIR . 'template/wpsp-advanced-settings.php'; } /** * White Label setting Page markup. * * @return void */ public function load_branding_setting_page() { require_once BSF_AIOSRS_PRO_DIR . 'template/branding-settings.php'; } /** * Breadcrumb Setting Page markup. * * @return void */ public function load_breadcrumb_setting_page() { require_once BSF_AIOSRS_PRO_DIR . 'template/breadcrumb-settings.php'; } /** * Load plugin text domain. * * @since 2.4.0 */ public function load_textdomain() { // Traditional WordPress plugin locale filter. $locale = apply_filters( 'plugin_locale', get_locale(), 'wp-schema-pro' ); $mofile_locale = sprintf( '%1$s-%2$s.mo', 'wp-schema-pro', $locale ); // Setup paths to current locale file. $mofile_global = trailingslashit( WP_LANG_DIR ) . 'plugins/wp-schema-pro/' . $locale; $mofile_local = trailingslashit( BSF_AIOSRS_PRO_DIR ) . 'languages/' . $locale; // Setup new names to current locale file. $new_mofile_global = trailingslashit( WP_LANG_DIR ) . 'plugins/wp-schema-pro/' . $mofile_locale; $new_mofile_local = trailingslashit( BSF_AIOSRS_PRO_DIR ) . 'languages/' . $mofile_locale; if ( file_exists( $new_mofile_global ) ) { // Look in global /wp-content/languages/plugins/wp-schema-pro/ folder. return load_textdomain( 'wp-schema-pro', $new_mofile_global ); } elseif ( file_exists( $mofile_global ) ) { // Look in global /wp-content/languages/plugins/wp-schema-pro/ folder. return load_textdomain( 'wp-schema-pro', $mofile_global ); } elseif ( file_exists( $new_mofile_local ) ) { // Look in local /wp-content/plugins/wp-schema-pro/languages/ folder. return load_textdomain( 'wp-schema-pro', $new_mofile_local ); } elseif ( file_exists( $mofile_local ) ) { // Look in local /wp-content/plugins/wp-schema-pro/languages/ folder. return load_textdomain( 'wp-schema-pro', $mofile_local ); } // Nothing found. return false; } } } /** * Kicking this off by calling 'get_instance()' method */ BSF_AIOSRS_Pro_Admin::get_instance();