Commit realizado el 12:13:52 08-04-2024

This commit is contained in:
Pagina Web Monito
2024-04-08 12:13:55 -04:00
commit 0c33094de9
7815 changed files with 1365694 additions and 0 deletions

View File

@@ -0,0 +1,375 @@
<?php
/**
* The metabox functionality of the plugin.
*
* @since 0.9.0
* @package RankMath
* @subpackage RankMath\Admin\Metabox
* @author Rank Math <support@rankmath.com>
*/
namespace RankMath\Admin\Metabox;
use RankMath\CMB2;
use RankMath\Runner;
use RankMath\Traits\Hooker;
use RankMath\Helper;
use RankMath\Helpers\Param;
use RankMath\Admin\Admin_Helper;
defined( 'ABSPATH' ) || exit;
/**
* Metabox class.
*/
class Metabox implements Runner {
use Hooker;
/**
* Metabox id.
*
* @var string
*/
private $metabox_id = 'rank_math_metabox';
/**
* Screen object.
*
* @var Screen
*/
private $screen;
/**
* Register hooks.
*/
public function hooks() {
if ( $this->dont_load() ) {
return;
}
$this->screen = new Screen();
if ( $this->screen->is_loaded() ) {
$this->action( 'cmb2_admin_init', 'add_main_metabox', 30 );
$this->action( 'rank_math/admin/enqueue_scripts', 'enqueue' );
if ( Helper::has_cap( 'link_builder' ) ) {
$this->action( 'cmb2_admin_init', 'add_link_suggestion_metabox', 30 );
}
}
$this->action( 'cmb2_' . CMB2::current_object_type() . '_process_fields_' . $this->metabox_id, 'save_meta' );
$this->action( 'cmb2_save_field', 'invalidate_facebook_object_cache', 10, 4 );
}
/**
* Enqueue styles and scripts for the metabox.
*/
public function enqueue() {
/**
* Allow other plugins to enqueue/dequeue admin styles or scripts before plugin assets.
*/
$this->do_action( 'admin/before_editor_scripts' );
$screen = get_current_screen();
$js = rank_math()->plugin_url() . 'assets/admin/js/';
$this->enqueue_commons();
$this->screen->enqueue();
$this->screen->localize();
$this->enqueue_translation();
rank_math()->variables->setup_json();
$is_gutenberg = Helper::is_block_editor() && \rank_math_is_gutenberg();
$is_elementor = 'elementor' === Param::get( 'action' );
Helper::add_json( 'knowledgegraphType', Helper::get_settings( 'titles.knowledgegraph_type' ) );
if (
! $is_gutenberg &&
! $is_elementor &&
'rank_math_schema' !== $screen->post_type &&
'edit-tags' !== $screen->base
) {
\CMB2_Hookup::enqueue_cmb_css();
wp_enqueue_style(
'rank-math-metabox',
rank_math()->plugin_url() . 'assets/admin/css/metabox.css',
[
'rank-math-common',
'rank-math-cmb2',
'rank-math-editor',
'wp-components',
],
rank_math()->version
);
wp_enqueue_media();
wp_enqueue_script(
'rank-math-editor',
rank_math()->plugin_url() . 'assets/admin/js/classic.js',
[
'clipboard',
'wp-hooks',
'moment',
'wp-date',
'wp-data',
'wp-api-fetch',
'wp-components',
'wp-element',
'wp-i18n',
'wp-url',
'wp-media-utils',
'rank-math-common',
'rank-math-analyzer',
'wp-block-editor',
'rank-math-app',
],
rank_math()->version,
true
);
}
$this->do_action( 'enqueue_scripts/assessor' );
/**
* Allow other plugins to enqueue/dequeue admin styles or scripts after plugin assets.
*/
$this->do_action( 'admin/editor_scripts' );
}
/**
* Enqueque scripts common for all builders.
*/
private function enqueue_commons() {
wp_register_style( 'rank-math-editor', rank_math()->plugin_url() . 'assets/admin/css/gutenberg.css', [ 'rank-math-common' ], rank_math()->version );
wp_register_script( 'rank-math-analyzer', rank_math()->plugin_url() . 'assets/admin/js/analyzer.js', [ 'lodash', 'wp-autop', 'wp-wordcount' ], rank_math()->version, true );
}
/**
* Enqueue translation.
*/
private function enqueue_translation() {
if ( function_exists( 'wp_set_script_translations' ) ) {
wp_set_script_translations( 'rank-math-analyzer', 'rank-math', rank_math()->plugin_dir() . 'languages/' );
wp_set_script_translations( 'rank-math-app', 'rank-math', rank_math()->plugin_dir() . 'languages/' );
}
}
/**
* Add main metabox.
*/
public function add_main_metabox() {
if ( $this->can_add_metabox() ) {
return;
}
$cmb = $this->create_metabox();
$cmb->add_field(
[
'id' => 'setting-panel-container-' . $this->metabox_id,
'type' => 'meta_tab_container_open',
'tabs' => [],
]
);
$cmb->add_field(
[
'id' => 'rank_math_metabox_wrapper',
'type' => 'raw',
'content' => '<div id="rank-math-metabox-wrapper"></div>',
'save_field' => false,
]
);
/**
* Allow disabling the primary term feature.
*
* @param bool $return True to disable.
*/
if ( false === apply_filters_deprecated( 'rank_math/primary_term', [ false ], '1.0.43', 'rank_math/admin/disable_primary_term' )
&& false === $this->do_filter( 'admin/disable_primary_term', false ) ) {
$taxonomies = Helper::get_object_taxonomies( Helper::get_post_type(), 'objects' );
$taxonomies = wp_filter_object_list( $taxonomies, [ 'hierarchical' => true ], 'and', 'name' );
foreach ( $taxonomies as $taxonomy ) {
$cmb->add_field(
[
'id' => 'rank_math_primary_' . $taxonomy,
'type' => 'hidden',
'default' => 0,
'attributes' => [
'data-primary-term' => $taxonomy,
],
]
);
}
}
$cmb->add_field(
[
'id' => 'setting-panel-container-close-' . $this->metabox_id,
'type' => 'tab_container_close',
]
);
CMB2::pre_init( $cmb );
}
/**
* Add link suggestion metabox.
*/
public function add_link_suggestion_metabox() {
$allowed_post_types = [];
foreach ( Helper::get_accessible_post_types() as $post_type ) {
if ( false === Helper::get_settings( 'titles.pt_' . $post_type . '_link_suggestions' ) ) {
continue;
}
$allowed_post_types[] = $post_type;
}
// Early bail.
if ( empty( $allowed_post_types ) ) {
return;
}
$cmb = new_cmb2_box(
[
'id' => $this->metabox_id . '_link_suggestions',
'title' => esc_html__( 'Link Suggestions', 'rank-math' ),
'object_types' => $allowed_post_types,
'context' => 'side',
'priority' => 'default',
]
);
$cmb->add_field(
[
'id' => $this->metabox_id . '_link_suggestions_tooltip',
'type' => 'raw',
'content' => '<div id="rank-math-link-suggestions-tooltip" class="hidden">' . Admin_Helper::get_tooltip( esc_html__( 'Click on the button to copy URL or insert link in content. You can also drag and drop links in the post content.', 'rank-math' ) ) . '</div>',
]
);
$cmb->add_field(
[
'id' => 'rank_math_social_tabs',
'type' => 'raw',
'file' => rank_math()->includes_dir() . 'metaboxes/link-suggestions.php',
'not_found' => '<em><small>' . esc_html__( 'We can\'t show any link suggestions for this post. Try selecting categories and tags for this post, and mark other posts as Pillar Content to make them show up here.', 'rank-math' ) . '</small></em>',
]
);
CMB2::pre_init( $cmb );
}
/**
* Save post meta handler.
*
* @param CMB2 $cmb CMB2 metabox object.
*/
public function save_meta( $cmb ) {
/**
* Hook into save handler for main metabox.
*
* @param CMB2 $cmb CMB2 object.
*/
$this->do_action( 'metabox/process_fields', $cmb );
}
/**
* Invalidate facebook object cache for the post.
*
* @param string $field_id The current field id paramater.
* @param bool $updated Whether the metadata update action occurred.
* @param string $action Action performed. Could be "repeatable", "updated", or "removed".
* @param CMB2_Field $field This field object.
*/
public function invalidate_facebook_object_cache( $field_id, $updated, $action, $field ) {
// Early Bail!
if ( ! in_array( $field_id, [ 'rank_math_facebook_title', 'rank_math_facebook_image', 'rank_math_facebook_description' ], true ) || ! $updated ) {
return;
}
$app_id = Helper::get_settings( 'titles.facebook_app_id' );
$secret = Helper::get_settings( 'titles.facebook_secret' );
// Early bail!
if ( ! $app_id || ! $secret ) {
return;
}
wp_remote_post(
'https://graph.facebook.com/',
[
'body' => [
'id' => get_permalink( $field->object_id() ),
'scrape' => true,
'access_token' => $app_id . '|' . $secret,
],
]
);
}
/**
* Create metabox
*
* @return CMB2
*/
private function create_metabox() {
return new_cmb2_box(
[
'id' => $this->metabox_id,
'title' => esc_html__( 'Rank Math SEO', 'rank-math' ),
'object_types' => $this->screen->get_object_types(),
'taxonomies' => Helper::get_allowed_taxonomies(),
'new_term_section' => false,
'new_user_section' => 'add-existing-user',
'context' => 'normal',
'priority' => $this->get_priority(),
'cmb_styles' => false,
'classes' => 'rank-math-metabox-wrap' . ( Admin_Helper::is_term_profile_page() ? ' rank-math-metabox-frame postbox' : '' ),
'mb_callback_args' => [ '__back_compat_meta_box' => \rank_math_is_gutenberg() ],
]
);
}
/**
* Get metabox priority
*
* @return string
*/
private function get_priority() {
$post_type = Param::get( 'post_type' );
if ( ! $post_type ) {
$post_type = get_post_type( Param::get( 'post', 0, FILTER_VALIDATE_INT ) );
}
$priority = 'product' === $post_type ? 'default' : 'high';
/**
* Filter: Change metabox priority.
*/
return $this->do_filter( 'metabox/priority', $priority );
}
/**
* Can add metabox
*
* @return bool
*/
private function can_add_metabox() {
return ! Helper::has_cap( 'onpage_general' ) &&
! Helper::has_cap( 'onpage_advanced' ) &&
! Helper::has_cap( 'onpage_snippet' ) &&
! Helper::has_cap( 'onpage_social' );
}
/**
* Can load metabox.
*
* @return bool
*/
private function dont_load() {
return Helper::is_heartbeat() || Helper::is_ajax() ||
( class_exists( 'Vc_Manager' ) && Param::get( 'vc_action' ) ) ||
is_network_admin();
}
}

View File

@@ -0,0 +1,444 @@
<?php
/**
* The post metabox screen.
*
* @since 1.0.25
* @package RankMath
* @subpackage RankMath\Admin\Metabox
* @author Rank Math <support@rankmath.com>
*/
namespace RankMath\Admin\Metabox;
use RankMath\KB;
use RankMath\Helper;
use RankMath\Traits\Hooker;
use RankMath\Helpers\Editor;
use RankMath\Frontend_SEO_Score;
use RankMath\Admin\Admin_Helper;
use RankMath\Helpers\Str;
use RankMath\Helpers\Url;
defined( 'ABSPATH' ) || exit;
/**
* Post metabox class.
*/
class Post_Screen implements IScreen {
use Hooker;
/**
* Hold primary taxonomy
*
* @var object
*/
private $primary_taxonomy = null;
/**
* Class construct
*/
public function __construct() {
$this->filter( 'rank_math/researches/tests', 'remove_tests', 10, 2 );
}
/**
* Get object id
*
* @return int
*/
public function get_object_id() {
global $post;
return $post->ID;
}
/**
* Get object type
*
* @return string
*/
public function get_object_type() {
return 'post';
}
/**
* Get object types to register metabox to
*
* @return array
*/
public function get_object_types() {
return Helper::get_allowed_post_types();
}
/**
* Enqueue Styles and Scripts required for screen.
*/
public function enqueue() {
$is_elementor = Helper::is_elementor_editor();
$is_block_editor = Helper::is_block_editor() && \rank_math_is_gutenberg();
Helper::add_json( 'postType', get_post_type() );
if ( ! $is_elementor ) {
$this->enqueue_custom_fields();
}
wp_register_script(
'rank-math-formats',
rank_math()->plugin_url() . 'assets/admin/js/gutenberg-formats.js',
[],
rank_math()->version,
true
);
if ( $is_block_editor || $is_elementor ) {
$this->enqueue_commons();
}
if ( $is_block_editor && ! $is_elementor && Editor::can_add_editor() ) {
$this->enqueue_for_gutenberg();
return;
}
if ( $is_elementor ) {
return;
}
// Classic.
if ( Helper::is_block_editor() ) {
wp_enqueue_script( 'rank-math-formats' );
}
if ( $is_block_editor ) {
wp_enqueue_script( 'rank-math-primary-term', rank_math()->plugin_url() . 'assets/admin/js/gutenberg-primary-term.js', [], rank_math()->version, true );
}
}
/**
* Get values for localize.
*
* @return array
*/
public function get_values() {
$post_type = $this->get_current_post_type();
return [
'parentDomain' => Url::get_domain( home_url() ),
'noFollowDomains' => Str::to_arr_no_empty( Helper::get_settings( 'general.nofollow_domains' ) ),
'noFollowExcludeDomains' => Str::to_arr_no_empty( Helper::get_settings( 'general.nofollow_exclude_domains' ) ),
'noFollowExternalLinks' => Helper::get_settings( 'general.nofollow_external_links' ),
'featuredImageNotice' => esc_html__( 'The featured image should be at least 200 by 200 pixels to be picked up by Facebook and other social media sites.', 'rank-math' ),
'pluginReviewed' => $this->plugin_reviewed(),
'postSettings' => [
'linkSuggestions' => Helper::get_settings( 'titles.pt_' . $post_type . '_link_suggestions' ),
'useFocusKeyword' => 'focus_keywords' === Helper::get_settings( 'titles.pt_' . $post_type . '_ls_use_fk' ),
],
'frontEndScore' => Frontend_SEO_Score::show_on(),
'postName' => get_post_field( 'post_name', get_post() ),
'permalinkFormat' => $this->get_permalink_format(),
'assessor' => [
'focusKeywordLink' => admin_url( 'edit.php?focus_keyword=%focus_keyword%&post_type=%post_type%' ),
'hasTOCPlugin' => $this->has_toc_plugin(),
'primaryTaxonomy' => $this->get_primary_taxonomy(),
],
];
}
/**
* Get object values for localize
*
* @return array
*/
public function get_object_values() {
global $post;
return [
'primaryTerm' => $this->get_primary_term_id(),
'authorName' => get_the_author_meta( 'display_name', $post->post_author ),
'titleTemplate' => Helper::get_settings( "titles.pt_{$post->post_type}_title", '%title% %sep% %sitename%' ),
'descriptionTemplate' => Helper::get_settings( "titles.pt_{$post->post_type}_description", '' ),
'showScoreFrontend' => ! Helper::get_post_meta( 'dont_show_seo_score', $this->get_object_id() ),
];
}
/**
* Get analysis to run.
*
* @return array
*/
public function get_analysis() {
$tests = [
'contentHasTOC' => true,
'contentHasShortParagraphs' => true,
'contentHasAssets' => true,
'keywordInTitle' => true,
'keywordInMetaDescription' => true,
'keywordInPermalink' => true,
'keywordIn10Percent' => true,
'keywordInContent' => true,
'keywordInSubheadings' => true,
'keywordInImageAlt' => true,
'keywordDensity' => true,
'keywordNotUsed' => true,
'lengthContent' => true,
'lengthPermalink' => true,
'linksHasInternal' => true,
'linksHasExternals' => true,
'linksNotAllExternals' => true,
'titleStartWithKeyword' => true,
'titleSentiment' => true,
'titleHasPowerWords' => true,
'titleHasNumber' => true,
'hasContentAI' => true,
];
return $tests;
}
/**
* Remove few tests on static Homepage.
*
* @since 1.0.42
*
* @param array $tests Array of tests with score.
* @param string $type Object type. Can be post, user or term.
*/
public function remove_tests( $tests, $type ) {
if ( ! Admin_Helper::is_home_page() && ! Admin_Helper::is_posts_page() ) {
return $tests;
}
return array_diff_assoc( $tests, $this->exclude_tests() );
}
/**
* Function to get the permalink format.
*
* @since 1.0.69.2
*/
private function get_permalink_format() {
$post_id = $this->get_object_id();
$post = get_post( $post_id );
if ( 'attachment' === $post->post_type ) {
return str_replace( $post->post_name, '%postname%', get_permalink( $post ) );
}
if ( 'auto-draft' !== $post->post_status || 'post' !== $post->post_type ) {
$sample_permalink = get_sample_permalink( $post_id, null, null );
return isset( $sample_permalink[0] ) ? $sample_permalink[0] : home_url();
}
$post_temp = $post;
$post_temp->post_status = 'publish';
return get_permalink( $post_temp, true );
}
/**
* Tests to exclude on Homepage and Blog page.
*
* @since 1.0.43
*
* @return array Array of excluded tests.
*/
private function exclude_tests() {
if ( Admin_Helper::is_home_page() ) {
return [
'contentHasTOC' => true,
'keywordInPermalink' => true,
'lengthPermalink' => true,
'linksHasExternals' => true,
'linksNotAllExternals' => true,
'titleSentiment' => true,
'titleHasPowerWords' => true,
'titleHasNumber' => true,
];
}
return [
'contentHasTOC' => true,
'contentHasShortParagraphs' => true,
'keywordIn10Percent' => true,
'keywordInContent' => true,
'keywordInSubheadings' => true,
'keywordDensity' => true,
'lengthContent' => true,
'linksHasInternal' => true,
'linksHasExternals' => true,
'linksNotAllExternals' => true,
];
}
/**
* Enqueque scripts common for all builders.
*/
private function enqueue_commons() {
wp_register_style( 'rank-math-editor', rank_math()->plugin_url() . 'assets/admin/css/gutenberg.css', [], rank_math()->version );
}
/**
* Enqueue script to analyze custom fields data.
*/
private function enqueue_custom_fields() {
global $post;
$custom_fields = Str::to_arr_no_empty( Helper::get_settings( 'titles.pt_' . $post->post_type . '_analyze_fields' ) );
if ( empty( $custom_fields ) ) {
return;
}
$file = Helper::is_block_editor() ? 'glue-custom-fields.js' : 'custom-fields.js';
wp_enqueue_script( 'rank-math-custom-fields', rank_math()->plugin_url() . 'assets/admin/js/' . $file, [ 'wp-hooks', 'rank-math-analyzer' ], rank_math()->version, true );
Helper::add_json( 'analyzeFields', $custom_fields );
}
/**
* Enqueue scripts for gutenberg screen.
*/
private function enqueue_for_gutenberg() {
wp_enqueue_style( 'rank-math-editor' );
wp_enqueue_script( 'rank-math-formats' );
wp_enqueue_script(
'rank-math-editor',
rank_math()->plugin_url() . 'assets/admin/js/gutenberg.js',
[
'clipboard',
'wp-autop',
'wp-blocks',
'wp-components',
'wp-editor',
'wp-edit-post',
'wp-element',
'wp-i18n',
'wp-plugins',
'wp-wordcount',
'rank-math-analyzer',
'rank-math-app',
],
rank_math()->version,
true
);
}
/**
* Get current post type.
*
* @return string
*/
private function get_current_post_type() {
$post_type = get_post_type();
if ( function_exists( 'get_current_screen' ) ) {
$screen = get_current_screen();
$post_type = isset( $screen->post_type ) ? $screen->post_type : $post_type;
}
return $post_type;
}
/**
* Check if any TOC plugin detected
*
* @return bool
*/
private function has_toc_plugin() {
if ( \defined( 'ELEMENTOR_PRO_VERSION' ) ) {
return true;
}
$plugins_found = [];
$active_plugins = get_option( 'active_plugins' );
$active_plugins = is_multisite() ? array_merge( $active_plugins, array_keys( get_site_option( 'active_sitewide_plugins', [] ) ) ) : $active_plugins;
/**
* Allow developers to add plugins to the TOC list.
*
* @param array TOC plugins.
*/
$toc_plugins = $this->do_filter(
'researches/toc_plugins',
[
'wp-shortcode/wp-shortcode.php' => 'WP Shortcode by RankMath',
'wp-shortcode-pro/wp-shortcode-pro.php' => 'WP Shortcode Pro by RankMath',
]
);
foreach ( $toc_plugins as $plugin_slug => $plugin_name ) {
if ( in_array( $plugin_slug, $active_plugins, true ) !== false ) {
$plugins_found[ $plugin_slug ] = $plugin_name;
}
}
return empty( $plugins_found ) ? false : $plugins_found;
}
/**
* Plugin already reviewed.
*
* @return bool
*/
private function plugin_reviewed() {
return get_option( 'rank_math_already_reviewed' ) || current_time( 'timestamp' ) < get_option( 'rank_math_install_date' ) + ( 2 * WEEK_IN_SECONDS );
}
/**
* Get primary taxonomy.
*
* @return bool|array
*/
private function get_primary_taxonomy() {
if ( ! is_null( $this->primary_taxonomy ) ) {
return $this->primary_taxonomy;
}
$taxonomy = false;
$post_type = $this->get_current_post_type();
/**
* Filter: Allow disabling the primary term feature.
* 'rank_math/primary_term' is deprecated,
* use 'rank_math/admin/disable_primary_term' instead.
*
* @param bool $return True to disable.
*/
if ( false === apply_filters_deprecated( 'rank_math/primary_term', [ false ], '1.0.43', 'rank_math/admin/disable_primary_term' )
&& false === $this->do_filter( 'admin/disable_primary_term', false ) ) {
$taxonomy = Helper::get_settings( 'titles.pt_' . $post_type . '_primary_taxonomy', false );
}
if ( ! $taxonomy ) {
return false;
}
$taxonomy = get_taxonomy( $taxonomy );
if ( empty( $taxonomy ) ) {
return false;
}
$this->primary_taxonomy = [
'title' => $taxonomy->labels->singular_name,
'name' => $taxonomy->name,
'singularLabel' => $taxonomy->labels->singular_name,
'restBase' => ( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name,
];
return $this->primary_taxonomy;
}
/**
* Get primary term ID.
*
* @return int
*/
private function get_primary_term_id() {
$taxonomy = $this->get_primary_taxonomy();
if ( ! $taxonomy ) {
return 0;
}
$id = Helper::get_post_meta( 'primary_' . $taxonomy['name'], $this->get_object_id() );
return $id ? absint( $id ) : 0;
}
}

View File

@@ -0,0 +1,358 @@
<?php
/**
* Metabox localization methods.
*
* @since 1.0.33
* @package RankMath
* @subpackage RankMath\Admin\Metabox
* @author Rank Math <support@rankmath.com>
*/
namespace RankMath\Admin\Metabox;
use RankMath\KB;
use RankMath\Helper;
use RankMath\Traits\Meta;
use RankMath\Traits\Hooker;
use RankMath\Helpers\Locale;
use RankMath\Admin\Admin_Helper;
use RankMath\Helpers\Url;
defined( 'ABSPATH' ) || exit;
/**
* Screen.
*/
class Screen implements IScreen {
use Meta;
use Hooker;
/**
* Current screen object.
*
* @var IScreen
*/
private $screen = null;
/**
* Class construct
*/
public function __construct() {
$this->load_screen();
}
/**
* Is creen loaded.
*
* @return bool
*/
public function is_loaded() {
return ! is_null( $this->screen );
}
/**
* Get object id
*
* @return int
*/
public function get_object_id() {
return $this->screen->get_object_id();
}
/**
* Get object type
*
* @return string
*/
public function get_object_type() {
return $this->screen->get_object_type();
}
/**
* Get object types to register metabox to
*
* @return array
*/
public function get_object_types() {
return $this->screen->get_object_types();
}
/**
* Enqueue Styles and Scripts required for screen.
*/
public function enqueue() {
$this->screen->enqueue();
}
/**
* Get analysis to run.
*
* @return array
*/
public function get_analysis() {
$analyses = $this->do_filter(
'researches/tests',
$this->screen->get_analysis(),
$this->screen->get_object_type()
);
return array_keys( $analyses );
}
/**
* Get values for localize.
*/
public function localize() {
$values = $this->get_values();
if ( empty( $values ) ) {
return;
}
foreach ( $values as $key => $value ) {
Helper::add_json( $key, $value );
}
}
/**
* Get common values.
*
* @return array
*/
public function get_values() {
$editor = Helper::get_current_editor();
$trends_link = KB::get( 'pro', 'CE General Tab Trends' );
if ( 'gutenberg' === $editor ) {
$trends_link = KB::get( 'pro', 'Gutenberg General Tab Trends' );
} elseif ( 'elementor' === $editor ) {
$trends_link = KB::get( 'pro', 'Elementor General Tab Trends' );
}
$values = array_merge_recursive(
$this->screen->get_values(),
[
'homeUrl' => home_url(),
'objectID' => $this->get_object_id(),
'objectType' => $this->get_object_type(),
'locale' => Locale::get_site_language(),
'localeFull' => get_locale(),
'overlayImages' => Helper::choices_overlay_images(),
'defautOgImage' => Helper::get_settings( 'titles.open_graph_image', rank_math()->plugin_url() . 'assets/admin/img/social-placeholder.jpg' ),
'customPermalinks' => (bool) get_option( 'permalink_structure', false ),
'isUserRegistered' => Helper::is_site_connected(),
'autoSuggestKeywords' => Helper::is_site_connected(),
'connectSiteUrl' => Admin_Helper::get_activate_url( Url::get_current_url() ),
'maxTags' => $this->do_filter( 'focus_keyword/maxtags', 5 ),
'trendsIcon' => Admin_Helper::get_trends_icon_svg(),
'showScore' => Helper::is_score_enabled(),
'siteFavIcon' => $this->get_site_icon(),
'canUser' => [
'general' => Helper::has_cap( 'onpage_general' ),
'advanced' => Helper::has_cap( 'onpage_advanced' ) && Helper::is_advanced_mode(),
'snippet' => Helper::has_cap( 'onpage_snippet' ),
'social' => Helper::has_cap( 'onpage_social' ),
'analysis' => Helper::has_cap( 'onpage_analysis' ),
'analytics' => Helper::has_cap( 'analytics' ),
'content_ai' => Helper::has_cap( 'content_ai' ),
],
'assessor' => [
'serpData' => $this->get_object_values(),
'powerWords' => $this->power_words(),
'diacritics' => $this->diacritics(),
'researchesTests' => $this->get_analysis(),
'hasRedirection' => Helper::is_module_active( 'redirections' ),
'hasBreadcrumb' => Helper::is_breadcrumbs_enabled(),
],
'isPro' => defined( 'RANK_MATH_PRO_FILE' ),
'is_front_page' => Admin_Helper::is_home_page(),
'trendsUpgradeLink' => esc_url_raw( $trends_link ),
'trendsUpgradeLabel' => esc_html__( 'Upgrade', 'rank-math' ),
'trendsPreviewImage' => esc_url( rank_math()->plugin_url() . 'assets/admin/img/trends-preview.jpg' ),
'currentEditor' => $editor,
]
);
$values = $this->do_filter( 'metabox/values', $values, $this );
return $this->do_filter( 'metabox/' . $this->get_object_type() . '/values', $values, $this );
}
/**
* Get object values for localize
*
* @return array
*/
public function get_object_values() {
$keys = $this->do_filter(
'metabox/' . $this->get_object_type() . '/meta_keys',
[
'title' => 'title',
'description' => 'description',
'focusKeywords' => 'focus_keyword',
'pillarContent' => 'pillar_content',
'canonicalUrl' => 'canonical_url',
'breadcrumbTitle' => 'breadcrumb_title',
'advancedRobots' => 'advanced_robots',
// Facebook.
'facebookTitle' => 'facebook_title',
'facebookDescription' => 'facebook_description',
'facebookImage' => 'facebook_image',
'facebookImageID' => 'facebook_image_id',
'facebookHasOverlay' => 'facebook_enable_image_overlay',
'facebookImageOverlay' => 'facebook_image_overlay',
'facebookAuthor' => 'facebook_author',
// Twitter.
'twitterCardType' => 'twitter_card_type',
'twitterUseFacebook' => 'twitter_use_facebook',
'twitterTitle' => 'twitter_title',
'twitterDescription' => 'twitter_description',
'twitterImage' => 'twitter_image',
'twitterImageID' => 'twitter_image_id',
'twitterHasOverlay' => 'twitter_enable_image_overlay',
'twitterImageOverlay' => 'twitter_image_overlay',
// Player.
'twitterPlayerUrl' => 'twitter_player_url',
'twitterPlayerSize' => 'twitter_player_size',
'twitterPlayerStream' => 'twitter_player_stream',
'twitterPlayerStreamCtype' => 'twitter_player_stream_ctype',
// App.
'twitterAppDescription' => 'twitter_app_description',
'twitterAppIphoneName' => 'twitter_app_iphone_name',
'twitterAppIphoneID' => 'twitter_app_iphone_id',
'twitterAppIphoneUrl' => 'twitter_app_iphone_url',
'twitterAppIpadName' => 'twitter_app_ipad_name',
'twitterAppIpadID' => 'twitter_app_ipad_id',
'twitterAppIpadUrl' => 'twitter_app_ipad_url',
'twitterAppGoogleplayName' => 'twitter_app_googleplay_name',
'twitterAppGoogleplayID' => 'twitter_app_googleplay_id',
'twitterAppGoogleplayUrl' => 'twitter_app_googleplay_url',
'twitterAppCountry' => 'twitter_app_country',
]
);
// Generate data.
$data = [];
$object_id = $this->get_object_id();
$object_type = $this->get_object_type();
foreach ( $keys as $id => $key ) {
$data[ $id ] = $this->get_meta( $object_type, $object_id, 'rank_math_' . $key );
}
// Robots.
$data['robots'] = $this->normalize_robots( $this->get_meta( $object_type, $object_id, 'rank_math_robots' ) );
// Advanced Robots.
$data['advancedRobots'] = $this->normalize_advanced_robots( $this->get_meta( $object_type, $object_id, 'rank_math_advanced_robots' ) );
$data['pillarContent'] = 'on' === $data['pillarContent'];
// Username, avatar & Name.
$twitter_username = Helper::get_settings( 'titles.twitter_author_names' );
$data['twitterAuthor'] = $twitter_username ? $twitter_username : esc_html__( 'username', 'rank-math' );
$data['twitterUseFacebook'] = 'off' === $data['twitterUseFacebook'] ? false : true;
$data['facebookHasOverlay'] = empty( $data['facebookHasOverlay'] ) || 'off' === $data['facebookHasOverlay'] ? false : true;
$data['twitterHasOverlay'] = empty( $data['twitterHasOverlay'] ) || 'off' === $data['twitterHasOverlay'] ? false : true;
return wp_parse_args( $this->screen->get_object_values(), $data );
}
/**
* Get site fav icon.
*
* @return string
*/
private function get_site_icon() {
$favicon = get_site_icon_url( 16 );
return ! empty( $favicon ) ? $favicon : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABs0lEQVR4AWL4//8/RRjO8Iucx+noO0MWUDo16FYABMGP6ZfUcRnWtm27jVPbtm3bttuH2t3eFPcY9pLz7NxiLjCyVd87pKnHyqXyxtCs8APd0rnyxiu4qSeA3QEDrAwBDrT1s1Rc/OrjLZwqVmOSu6+Lamcpp2KKMA9PH1BYXMe1mUP5qotvXTywsOEEYHXxrY+3cqk6TMkYpNr2FeoY3KIr0RPtn9wQ2unlA+GMkRw6+9TFw4YTwDUzx/JVvARj9KaedXRO8P5B1Du2S32smzqUrcKGEyA+uAgQjKX7zf0boWHGfn71jIKj2689gxp7OAGShNcBUmLMPVjZuiKcA2vuWHHDCQxMCz629kXAIU4ApY15QwggAFbfOP9DhgBJ+nWVJ1AZAfICAj1pAlY6hCADZnveQf7bQIwzVONGJonhLIlS9gr5mFg44Xd+4S3XHoGNPdJl1INIwKyEgHckEhgTe1bGiFY9GSFBYUwLh1IkiJUbY407E7syBSFxKTszEoiE/YdrgCEayDmtaJwCI9uu8TKMuZSVfSa4BpGgzvomBR/INhLGzrqDotp01ZR8pn/1L0JN9d9XNyx0AAAAAElFTkSuQmCC';
}
/**
* Normalize robots.
*
* @param array $robots Array to normalize.
*
* @return array
*/
private function normalize_robots( $robots ) {
if ( ! is_array( $robots ) || empty( $robots ) ) {
$robots = Helper::get_robots_defaults();
}
return array_fill_keys( $robots, true );
}
/**
* Normalize advanced robots.
*
* @param array $advanced_robots Array to normalize.
*
* @return array
*/
private function normalize_advanced_robots( $advanced_robots ) {
if ( ! empty( $advanced_robots ) ) {
return $advanced_robots;
}
return Helper::get_advanced_robots_defaults();
}
/**
* Return power words.
*
* @return array
*/
private function power_words() {
static $words;
$locale = Locale::get_site_language();
$file = rank_math()->plugin_dir() . 'assets/vendor/powerwords/' . $locale . '.php';
if ( ! file_exists( $file ) ) {
return $this->do_filter( 'metabox/power_words', [], $locale );
}
$words = $words ? $words : include $file;
return $this->do_filter( 'metabox/power_words', array_map( 'strtolower', $words ), $locale );
}
/**
* Get diacritics (accents).
*
* @return array
*/
private function diacritics() {
$locale = Locale::get_site_language();
$locale = in_array( $locale, [ 'en', 'de', 'ru' ], true ) ? $locale : 'en';
$file = rank_math()->plugin_dir() . 'assets/vendor/diacritics/' . $locale . '.php';
if ( ! file_exists( $file ) ) {
return false;
}
$diacritics = include_once $file;
return $this->do_filter( 'metabox/diacritics', $diacritics, $locale );
}
/**
* Load required screen.
*
* @param string $manual To load any screen manually.
*/
public function load_screen( $manual = '' ) {
if ( Admin_Helper::is_post_edit() || 'post' === $manual ) {
$this->screen = new Post_Screen();
return;
}
if ( Admin_Helper::is_term_edit() || 'term' === $manual ) {
$this->screen = new Taxonomy_Screen();
return;
}
if ( User_Screen::is_enable() || 'user' === $manual ) {
$this->screen = new User_Screen();
return;
}
}
}

View File

@@ -0,0 +1,183 @@
<?php
/**
* The metabox functionality of the plugin.
*
* @since 1.0.25
* @package RankMath
* @subpackage RankMath\Admin\Metabox
* @author Rank Math <support@rankmath.com>
*/
namespace RankMath\Admin\Metabox;
use RankMath\Helper;
use RankMath\Traits\Hooker;
use RankMath\Helpers\Param;
defined( 'ABSPATH' ) || exit;
/**
* Taxonomy metabox class.
*/
class Taxonomy_Screen implements IScreen {
use Hooker;
/**
* Class construct
*/
public function __construct() {
}
/**
* Get object ID.
*
* @return int
*/
public function get_object_id() {
return Param::request( 'tag_ID', 0, FILTER_VALIDATE_INT );
}
/**
* Get object type
*
* @return string
*/
public function get_object_type() {
return 'term';
}
/**
* Get object types to register metabox to
*
* @return array
*/
public function get_object_types() {
$object_types = [];
$taxonomies = Helper::get_allowed_taxonomies();
if ( is_array( $taxonomies ) && ! empty( $taxonomies ) ) {
$object_types[] = 'term';
$this->description_field_editor();
remove_filter( 'pre_term_description', 'wp_filter_kses' );
remove_filter( 'term_description', 'wp_kses_data' );
add_filter( 'pre_term_description', 'wp_kses_post' );
add_filter( 'term_description', 'wp_kses_post' );
}
return $object_types;
}
/**
* Enqueue Styles and Scripts required for screen.
*/
public function enqueue() {}
/**
* Get analysis to run.
*
* @return array
*/
public function get_analysis() {
return [
'keywordInTitle' => true,
'keywordInMetaDescription' => true,
'keywordInPermalink' => true,
'keywordNotUsed' => true,
'titleStartWithKeyword' => true,
];
}
/**
* Get values for localize.
*
* @return array
*/
public function get_values() {
$url = '';
if ( $this->get_object_id() ) {
$url = get_term_link( $this->get_object_id() );
$data = array_filter( explode( '/', $url ) );
$url = ! empty( $data ) ? str_replace( array_pop( $data ), '%term%', $url ) : '';
}
return [
'permalinkFormat' => $url ? $url : home_url(),
];
}
/**
* Get object values for localize
*
* @return array
*/
public function get_object_values() {
$taxonomy = $this->get_taxonomy();
return [
'titleTemplate' => Helper::get_settings( "titles.tax_{$taxonomy}_title", '%term% %sep% %sitename%' ),
'descriptionTemplate' => Helper::get_settings( "titles.tax_{$taxonomy}_description", '%term_description%' ),
];
}
/**
* Output the WordPress editor.
*
* @param object $term Current taxonomy term object.
*/
public function category_description_editor( $term ) {
?>
<tr class="form-field term-description-wrap rank-math-term-description-wrap">
<th scope="row"><label for="description"><?php esc_html_e( 'Description', 'rank-math' ); ?></label></th>
<td>
<?php
wp_editor(
html_entity_decode( $term->description, ENT_QUOTES, 'UTF-8' ),
'rank_math_description_editor',
[
'textarea_name' => 'description',
'textarea_rows' => 5,
]
);
?>
</td>
<script>
// Remove the non-html field
jQuery('textarea#description').closest('.form-field').remove();
</script>
</tr>
<?php
}
/**
* Add the description field to the edit taxonomy screen if the metabox is
* enabled for the current taxonomy.
*
* @return void
*/
private function description_field_editor() {
$taxonomy = $this->get_taxonomy();
if (
! Helper::get_settings( 'titles.tax_' . $taxonomy . '_add_meta_box' ) ||
$this->do_filter( 'admin/disable_rich_editor', false, $taxonomy )
) {
return;
}
$this->action( "{$taxonomy}_edit_form_fields", 'category_description_editor', 1 );
}
/**
* Get current taxonomy.
*
* @return {string} Taxonomy slug.
*/
private function get_taxonomy() {
$taxonomy = filter_input( INPUT_GET, 'taxonomy', FILTER_DEFAULT, [ 'options' => [ 'default' => '' ] ] );
$taxonomy_object = get_taxonomy( $taxonomy );
if ( empty( $taxonomy_object ) || empty( $taxonomy_object->public ) ) {
return;
}
return $taxonomy;
}
}

View File

@@ -0,0 +1,116 @@
<?php
/**
* The metabox functionality of the plugin.
*
* @since 1.0.25
* @package RankMath
* @subpackage RankMath\Admin\Metabox
* @author Rank Math <support@rankmath.com>
*/
namespace RankMath\Admin\Metabox;
use RankMath\Helper;
use RankMath\Traits\Hooker;
use RankMath\Admin\Admin_Helper;
defined( 'ABSPATH' ) || exit;
/**
* User metabox class.
*/
class User_Screen implements IScreen {
use Hooker;
/**
* Class construct
*/
public function __construct() {}
/**
* Get object ID.
*
* @return int
*/
public function get_object_id() {
global $user_id;
return $user_id;
}
/**
* Get object type
*
* @return string
*/
public function get_object_type() {
return 'user';
}
/**
* Get object types to register metabox to
*
* @return array
*/
public function get_object_types() {
return [ 'user' ];
}
/**
* Enqueue Styles and Scripts required for screen.
*/
public function enqueue() {
wp_enqueue_media();
}
/**
* Get analysis to run.
*
* @return array
*/
public function get_analysis() {
return [
'keywordInTitle' => true,
'keywordInMetaDescription' => true,
'keywordInPermalink' => true,
'keywordNotUsed' => true,
'titleStartWithKeyword' => true,
];
}
/**
* Get values for localize.
*
* @return array
*/
public function get_values() {
global $wp_rewrite;
return [
'permalinkFormat' => ! empty( $wp_rewrite->author_structure ) ? home_url( $wp_rewrite->author_structure ) : home_url(),
];
}
/**
* Get object values for localize
*
* @return array
*/
public function get_object_values() {
return [
'titleTemplate' => Helper::get_settings( 'titles.author_archive_title', '%name% %sep% %sitename% %page%' ),
'descriptionTemplate' => Helper::get_settings( 'titles.author_archive_description', '%user_description%' ),
];
}
/**
* Is user metabox enabled.
*
* @return bool
*/
public static function is_enable() {
return false === Helper::get_settings( 'titles.disable_author_archives' ) &&
Helper::get_settings( 'titles.author_add_meta_box' ) &&
Admin_Helper::is_user_edit();
}
}

View File

@@ -0,0 +1,66 @@
<?php
/**
* An interface for getting values for screen.
*
* @since 1.0.33
* @package RankMath
* @subpackage RankMath\Admin\Metabox
* @author Rank Math <support@rankmath.com>
*/
namespace RankMath\Admin\Metabox;
defined( 'ABSPATH' ) || exit;
/**
* Screen.
*/
interface IScreen {
/**
* Get object ID.
*
* @return int
*/
public function get_object_id();
/**
* Get object type
*
* @return string
*/
public function get_object_type();
/**
* Get object types to register metabox to
*
* @return array
*/
public function get_object_types();
/**
* Enqueue Styles and Scripts required for screen
*/
public function enqueue();
/**
* Get values for localize
*
* @return array
*/
public function get_values();
/**
* Get object values for localize
*
* @return array
*/
public function get_object_values();
/**
* Get analysis to run.
*
* @return array
*/
public function get_analysis();
}