Commit inicial powerservice
This commit is contained in:
@@ -0,0 +1,475 @@
|
||||
<?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\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( 'add_meta_boxes', 'add_main_metabox', 30 );
|
||||
$this->action( 'rank_math/admin/enqueue_scripts', 'enqueue' );
|
||||
|
||||
if ( Helper::is_site_editor() ) {
|
||||
$this->action( 'enqueue_block_editor_assets', 'enqueue' );
|
||||
}
|
||||
|
||||
if ( Helper::has_cap( 'link_builder' ) ) {
|
||||
$this->action( 'add_meta_boxes', 'add_link_suggestion_metabox', 30 );
|
||||
}
|
||||
|
||||
// Add taxonomy metabox hooks.
|
||||
$this->action( 'init', 'add_taxonomy_metabox_hooks', 9999 );
|
||||
|
||||
// Add user metabox hooks.
|
||||
$this->action( 'edit_user_profile', 'add_user_profile_metabox' );
|
||||
$this->action( 'show_user_profile', 'add_user_profile_metabox' );
|
||||
}
|
||||
|
||||
$this->action( 'save_post', 'save_meta', 10, 2 );
|
||||
$this->action( 'edit_term', 'save_term_meta', 10, 3 );
|
||||
$this->action( 'save_post', 'invalidate_facebook_object_cache', 10, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
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
|
||||
) {
|
||||
wp_enqueue_style(
|
||||
'rank-math-metabox',
|
||||
rank_math()->plugin_url() . 'assets/admin/css/metabox.css',
|
||||
[
|
||||
'rank-math-common',
|
||||
'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', $this->screen );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add main metabox.
|
||||
*/
|
||||
public function add_main_metabox() {
|
||||
if ( $this->can_add_metabox() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$object_types = $this->screen->get_object_types();
|
||||
|
||||
// Add metabox for post types.
|
||||
if ( ! empty( $object_types ) ) {
|
||||
add_meta_box(
|
||||
$this->metabox_id,
|
||||
esc_html__( 'Rank Math SEO', 'seo-by-rank-math' ),
|
||||
[ $this, 'render_main_metabox' ],
|
||||
$object_types,
|
||||
'normal',
|
||||
$this->get_priority(),
|
||||
[ '__back_compat_meta_box' => \rank_math_is_gutenberg() ]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render main metabox content.
|
||||
*
|
||||
* @param WP_Post $post Current post object.
|
||||
*/
|
||||
public function render_main_metabox( $post ) {
|
||||
// Add nonce for security.
|
||||
wp_nonce_field( 'rank_math_save_meta', 'rank_math_metabox_nonce' );
|
||||
|
||||
echo '<div class="rank-math-metabox-wrap rank-math-sidebar-panel">';
|
||||
echo '<div id="rank-math-metabox-wrapper"></div>';
|
||||
|
||||
// Add primary term hidden fields.
|
||||
$this->render_primary_term_fields();
|
||||
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Render taxonomy metabox content.
|
||||
*
|
||||
* @param WP_Term $term Current term object.
|
||||
* @param string $taxonomy Current taxonomy slug.
|
||||
*/
|
||||
public function render_taxonomy_metabox( $term, $taxonomy ) {
|
||||
// Add nonce for security.
|
||||
wp_nonce_field( 'rank_math_save_term_meta', 'rank_math_term_metabox_nonce' );
|
||||
?>
|
||||
<div class="form-table rank-math-metabox-wrap rank-math-metabox-frame postbox">
|
||||
<div id="setting-panel-container-<?php echo esc_attr( $this->metabox_id ); ?>" class="rank-math-sidebar-panel rank-math-tabs">
|
||||
<h2 class="rank-math-metabox-frame-title"><?php esc_html_e( 'Rank Math SEO', 'seo-by-rank-math' ); ?></h2>
|
||||
<div id="rank-math-metabox-wrapper"></div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Add link suggestion metabox.
|
||||
*/
|
||||
public function add_link_suggestion_metabox() {
|
||||
if ( 'classic' !== Helper::get_current_editor() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
add_meta_box(
|
||||
$this->metabox_id . '_link_suggestions',
|
||||
esc_html__( 'Link Suggestions', 'seo-by-rank-math' ),
|
||||
[ $this, 'render_link_suggestion_metabox' ],
|
||||
$allowed_post_types,
|
||||
'side',
|
||||
'default'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render link suggestion metabox content.
|
||||
*
|
||||
* @param WP_Post $post Current post object.
|
||||
*/
|
||||
public function render_link_suggestion_metabox( $post ) {
|
||||
echo '<div id="rank-math-link-suggestions-wrapper"></div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Save post meta handler.
|
||||
*
|
||||
* @param int $post_id Post ID.
|
||||
* @param WP_Post $post Post object.
|
||||
*/
|
||||
public function save_meta( $post_id, $post ) {
|
||||
// Verify nonce.
|
||||
$nonce = isset( $_POST['rank_math_metabox_nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['rank_math_metabox_nonce'] ) ) : '';
|
||||
if ( ! $nonce || ! wp_verify_nonce( $nonce, 'rank_math_save_meta' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check autosave.
|
||||
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check permissions.
|
||||
if ( ! current_user_can( 'edit_post', $post_id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook into save handler for main metabox.
|
||||
*
|
||||
* @param int $post_id Post ID.
|
||||
* @param WP_Post $post Post object.
|
||||
*/
|
||||
$this->do_action( 'metabox/process_fields', $post_id, $post );
|
||||
}
|
||||
|
||||
/**
|
||||
* Save term meta handler.
|
||||
*
|
||||
* @param int $term_id Term ID.
|
||||
* @param int $tt_id Term taxonomy ID.
|
||||
* @param string $taxonomy Taxonomy slug.
|
||||
*/
|
||||
public function save_term_meta( $term_id, $tt_id, $taxonomy ) {
|
||||
// Verify nonce.
|
||||
$nonce = isset( $_POST['rank_math_term_metabox_nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['rank_math_term_metabox_nonce'] ) ) : '';
|
||||
if ( ! $nonce || ! wp_verify_nonce( $nonce, 'rank_math_save_term_meta' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook into save handler for taxonomy metabox.
|
||||
*
|
||||
* @param int $term_id Term ID.
|
||||
* @param int $tt_id Term taxonomy ID.
|
||||
* @param string $taxonomy Taxonomy slug.
|
||||
*/
|
||||
$this->do_action( 'metabox/process_term_fields', $term_id, $tt_id, $taxonomy );
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalidate facebook object cache for the post.
|
||||
*
|
||||
* @param int $post_id Post ID.
|
||||
* @param WP_Post $post Post object.
|
||||
*/
|
||||
public function invalidate_facebook_object_cache( $post_id, $post ) {
|
||||
// Check if any Facebook meta fields were updated.
|
||||
$facebook_fields = [ 'rank_math_facebook_title', 'rank_math_facebook_image', 'rank_math_facebook_description' ];
|
||||
$has_update = false;
|
||||
|
||||
foreach ( $facebook_fields as $field ) {
|
||||
if ( isset( $_POST[ $field ] ) ) {
|
||||
$has_update = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Early Bail!
|
||||
if ( ! $has_update ) {
|
||||
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( $post_id ),
|
||||
'scrape' => true,
|
||||
'access_token' => $app_id . '|' . $secret,
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add taxonomy metabox hooks.
|
||||
*/
|
||||
public function add_taxonomy_metabox_hooks() {
|
||||
if ( $this->can_add_metabox() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$taxonomies = Helper::get_allowed_taxonomies();
|
||||
if ( empty( $taxonomies ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->screen->get_object_types();
|
||||
|
||||
// Add metabox for taxonomies.
|
||||
foreach ( $taxonomies as $taxonomy ) {
|
||||
// For editing existing terms - renders after the table.
|
||||
add_action( "{$taxonomy}_edit_form", [ $this, 'render_taxonomy_metabox' ], 11, 2 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add SEO metabox on the User profile page.
|
||||
*/
|
||||
public function add_user_profile_metabox() {
|
||||
if ( $this->can_add_metabox() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
?>
|
||||
<div class="form-table rank-math-metabox-wrap rank-math-metabox-frame postbox">
|
||||
<div id="setting-panel-container-<?php echo esc_attr( $this->metabox_id ); ?>" class="rank-math-sidebar-panel rank-math-tabs">
|
||||
<h2 class="rank-math-metabox-frame-title"><?php esc_html_e( 'Rank Math SEO', 'seo-by-rank-math' ); ?></h2>
|
||||
<div id="rank-math-metabox-wrapper"></div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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', 'wp-url' ], rank_math()->version, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue translation.
|
||||
*/
|
||||
private function enqueue_translation() {
|
||||
if ( function_exists( 'wp_set_script_translations' ) ) {
|
||||
wp_set_script_translations( 'rank-math-analyzer', 'seo-by-rank-math', rank_math()->plugin_dir() . 'languages/' );
|
||||
wp_set_script_translations( 'rank-math-app', 'seo-by-rank-math', rank_math()->plugin_dir() . 'languages/' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render primary term hidden fields.
|
||||
*/
|
||||
private function render_primary_term_fields() {
|
||||
/**
|
||||
* Allow disabling the primary term feature.
|
||||
*
|
||||
* @param bool $return True to disable.
|
||||
*/
|
||||
if ( true === $this->do_filter( 'admin/disable_primary_term', false ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$taxonomies = Helper::get_object_taxonomies( Helper::get_post_type(), 'objects' );
|
||||
$taxonomies = wp_filter_object_list( $taxonomies, [ 'hierarchical' => true ], 'and', 'name' );
|
||||
foreach ( $taxonomies as $taxonomy ) {
|
||||
$value = get_post_meta( get_the_ID(), 'rank_math_primary_' . $taxonomy, true );
|
||||
$value = $value ? $value : 0;
|
||||
printf(
|
||||
'<input type="hidden" id="rank_math_primary_%1$s" name="rank_math_primary_%1$s" value="%2$s" data-primary-term="%1$s" />',
|
||||
esc_attr( $taxonomy ),
|
||||
esc_attr( $value )
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,460 @@
|
||||
<?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;
|
||||
use RankMath\Helpers\Param;
|
||||
|
||||
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 ! empty( $post->ID ) ? $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' );
|
||||
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();
|
||||
$link_suggestions = Helper::get_settings( 'titles.pt_' . $post_type . '_link_suggestions' );
|
||||
|
||||
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.', 'seo-by-rank-math' ),
|
||||
'pluginReviewed' => $this->plugin_reviewed(),
|
||||
'postSettings' => [
|
||||
'linkSuggestions' => $link_suggestions,
|
||||
'useFocusKeyword' => 'focus_keywords' === Helper::get_settings( 'titles.pt_' . $post_type . '_ls_use_fk' ),
|
||||
'linkSuggestionsData' => (
|
||||
Helper::has_cap( 'link_builder' ) &&
|
||||
false !== $link_suggestions &&
|
||||
! empty( rank_math()->admin )
|
||||
) ? ( rank_math()->admin->get_link_suggestions( get_post() ) ?? [] ) : false,
|
||||
],
|
||||
'frontEndScore' => Frontend_SEO_Score::show_on(),
|
||||
'postName' => get_post_field( 'post_name', get_post() ),
|
||||
'permalinkFormat' => $this->get_permalink_format(),
|
||||
'showLockModifiedDate' => Editor::can_add_lock_modified_date(),
|
||||
'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;
|
||||
if ( empty( $post ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
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() ),
|
||||
'lockModifiedDate' => ! empty( Helper::get_post_meta( 'lock_modified_date', $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 ( empty( $post ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
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 ) && function_exists( 'get_sample_permalink' ) ) {
|
||||
$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;
|
||||
if ( empty( $post ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$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' ) || Helper::get_current_time() < 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,416 @@
|
||||
<?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;
|
||||
use RankMath\Helpers\Param;
|
||||
|
||||
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(),
|
||||
'defaultOgImage' => 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' ),
|
||||
],
|
||||
'showKeywordIntent' => Helper::should_determine_search_intent(),
|
||||
'assessor' => [
|
||||
'serpData' => $this->get_object_values(),
|
||||
'powerWords' => $this->power_words(),
|
||||
'diacritics' => $this->diacritics(),
|
||||
'researchesTests' => $this->get_analysis(),
|
||||
'hasRedirection' => Helper::has_cap( 'redirections' ) && Helper::is_module_active( 'redirections' ),
|
||||
'hasBreadcrumb' => Helper::is_breadcrumbs_enabled(),
|
||||
],
|
||||
'isPro' => defined( 'RANK_MATH_PRO_FILE' ),
|
||||
'is_front_page' => Admin_Helper::is_home_page(),
|
||||
'frontPageId' => (int) get_option( 'page_on_front' ),
|
||||
'trendsUpgradeLink' => esc_url_raw( $trends_link ),
|
||||
'trendsUpgradeLabel' => esc_html__( 'Upgrade', 'seo-by-rank-math' ),
|
||||
'trendsPreviewImage' => esc_url( rank_math()->plugin_url() . 'assets/admin/img/trends-preview.jpg' ),
|
||||
'currentEditor' => $editor,
|
||||
'homepageData' => [
|
||||
'assessor' => [
|
||||
'powerWords' => $this->power_words(),
|
||||
'diacritics' => $this->diacritics(),
|
||||
'researchesTests' => $this->get_analysis(),
|
||||
'hasBreadcrumb' => Helper::is_breadcrumbs_enabled(),
|
||||
'serpData' => $this->get_homepage_serp_data(),
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
$values = $this->do_filter( 'metabox/values', $values, $this );
|
||||
return $this->do_filter( 'metabox/' . $this->get_object_type() . '/values', $values, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get serpData for the homepageData assessor.
|
||||
*
|
||||
* Uses the static front page's post meta when show_on_front = 'page',
|
||||
* otherwise falls back to global homepage settings.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function get_homepage_serp_data() {
|
||||
$title_tpl = Helper::get_settings( 'titles.pt_page_title', '%title% %sep% %sitename%' );
|
||||
$desc_tpl = Helper::get_settings( 'titles.pt_page_description', '' );
|
||||
$robots = $this->normalize_robots( Helper::get_settings( 'titles.homepage_robots' ) );
|
||||
$adv = $this->normalize_advanced_robots( Helper::get_settings( 'titles.homepage_advanced_robots' ) );
|
||||
|
||||
$id = 'page' === get_option( 'show_on_front' ) ? (int) get_option( 'page_on_front' ) : 0;
|
||||
if ( $id ) {
|
||||
$robots = $this->normalize_robots( Helper::get_post_meta( 'robots', $id ) );
|
||||
$adv = $this->normalize_advanced_robots( Helper::get_post_meta( 'advanced_robots', $id ) );
|
||||
}
|
||||
|
||||
$title = $id ? Helper::get_post_meta( 'title', $id ) : Helper::get_settings( 'titles.homepage_title' );
|
||||
$desc = $id ? Helper::get_post_meta( 'description', $id ) : Helper::get_settings( 'titles.homepage_description', '' );
|
||||
$keywords = $id ? Helper::get_post_meta( 'focus_keyword', $id ) : '';
|
||||
$breadcrumb = $id ? Helper::get_post_meta( 'breadcrumb_title', $id ) : Helper::get_settings( 'general.breadcrumbs_home_label' );
|
||||
$fb_title = $id ? Helper::get_post_meta( 'facebook_title', $id ) : Helper::get_settings( 'titles.homepage_facebook_title', '' );
|
||||
$fb_desc = $id ? Helper::get_post_meta( 'facebook_description', $id ) : Helper::get_settings( 'titles.homepage_facebook_description', '' );
|
||||
$fb_image = $id ? Helper::get_post_meta( 'facebook_image', $id ) : Helper::get_settings( 'titles.homepage_facebook_image', '' );
|
||||
$fb_img_id = $id ? Helper::get_post_meta( 'facebook_image_id', $id ) : Helper::get_settings( 'titles.homepage_facebook_image_id', '' );
|
||||
|
||||
return [
|
||||
'title' => $title,
|
||||
'description' => $desc,
|
||||
'titleTemplate' => $title_tpl,
|
||||
'descriptionTemplate' => $desc_tpl,
|
||||
'focusKeywords' => $keywords,
|
||||
'breadcrumbTitle' => $breadcrumb,
|
||||
'robots' => $robots,
|
||||
'advancedRobots' => $adv,
|
||||
'facebookTitle' => $fb_title,
|
||||
'facebookDescription' => $fb_desc,
|
||||
'facebookImage' => $fb_image,
|
||||
'facebookImageID' => $fb_img_id,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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', 'seo-by-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 || Helper::is_site_editor() ) {
|
||||
$this->screen = new Post_Screen();
|
||||
return;
|
||||
}
|
||||
|
||||
$doing_quick_edit = Param::request( 'action' ) === 'inline-save-tax';
|
||||
if ( Admin_Helper::is_term_edit() || 'term' === $manual || $doing_quick_edit ) {
|
||||
$this->screen = new Taxonomy_Screen();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( User_Screen::is_enable() || 'user' === $manual ) {
|
||||
$this->screen = new User_Screen();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
<?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() {
|
||||
add_action( 'init', [ $this, 'allow_tags' ], 999 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow tags in term description.
|
||||
*/
|
||||
public function allow_tags() {
|
||||
$taxonomies = Helper::get_allowed_taxonomies();
|
||||
if ( is_array( $taxonomies ) && ! empty( $taxonomies ) ) {
|
||||
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' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
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', 'seo-by-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;
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
Reference in New Issue
Block a user