diff --git a/modules/yoastseo/assets/js/meta-box.js b/modules/yoastseo/assets/js/meta-box.js index 2fb765da..8053f667 100644 --- a/modules/yoastseo/assets/js/meta-box.js +++ b/modules/yoastseo/assets/js/meta-box.js @@ -94,6 +94,62 @@ } + /** + * + * Yoast SEO Focus Keyword + * + * + */ + + if ($('#pp-checklists-req-focus_keyword').length > 0) { + $(document).on(PP_Checklists.EVENT_TIC, function (event) { + var count = 0, + obj = null, + min_value = parseInt(ppChecklists.requirements.focus_keyword.value[0]), + max_value = parseInt(ppChecklists.requirements.focus_keyword.value[1]); + + if ($('#focus-keyword-input-metabox').length === 0) { + return; + } + + obj = $('#focus-keyword-input-metabox').val(); + + if (typeof obj !== 'undefined') { + count = obj.length; + + $('#pp-checklists-req-focus_keyword').trigger( + PP_Checklists.EVENT_UPDATE_REQUIREMENT_STATE, + PP_Checklists.check_valid_quantity(count, min_value, max_value), + ); + } + }); + } + + /** + * + * Yoast SEO Meta Description + * + */ + + if ($('#pp-checklists-req-meta_description').length > 0) { + $(document).on(PP_Checklists.EVENT_TIC, function (event) { + var count = 0, + obj = '', + min_value = parseInt(ppChecklists.requirements.meta_description.value[0]), + max_value = parseInt(ppChecklists.requirements.meta_description.value[1]); + + + obj = $('#yoast-google-preview-description-metabox').find('span[data-text="true"]').text() || ''; + + count = obj.length; + + $('#pp-checklists-req-meta_description').trigger( + PP_Checklists.EVENT_UPDATE_REQUIREMENT_STATE, + PP_Checklists.check_valid_quantity(count, min_value, max_value), + ); + }); + } + }); })(jQuery, window, document, PP_Checklists); diff --git a/modules/yoastseo/lib/Requirement/Focus_Keyword.php b/modules/yoastseo/lib/Requirement/Focus_Keyword.php new file mode 100644 index 00000000..ea9649ba --- /dev/null +++ b/modules/yoastseo/lib/Requirement/Focus_Keyword.php @@ -0,0 +1,67 @@ + + * @copyright Copyright (C) 2018 PublishPress. All rights reserved. + * @license GPLv2 or later + * @since 1.0.0 + */ + +namespace PublishPress\Checklists\Yoastseo\Requirement; + +use PublishPress\Checklists\Core\Requirement\Base_counter; +use stdClass; + +class Focus_Keyword extends Base_counter +{ + /** + * The name of the requirement, in a slug format + * + * @var string + */ + public $name = 'focus_keyword'; + + /** + * The name of the requirement, in a slug format + * + * @var string + */ + public $group = 'yoastseo'; + + /** + * Initialize the language strings for the instance + * + * @return void + */ + public function init_language() + { + $this->lang['label'] = __('Number of characters in Yoast SEO focus keyword', 'publishpress-checklists'); + $this->lang['label_settings'] = __('Number of characters in Yoast SEO focus keyword', 'publishpress-checklists'); + $this->lang['label_min_singular'] = __('Minimum of %d character in Yoast SEO focus keyword', 'publishpress-checklists'); + $this->lang['label_min_plural'] = __('Minimum of %d characters in Yoast SEO focus keyword', 'publishpress-checklists'); + $this->lang['label_max_singular'] = __('Maximum of %d character in Yoast SEO focus keyword', 'publishpress-checklists'); + $this->lang['label_max_plural'] = __('Maximum of %d characters in Yoast SEO focus keyword', 'publishpress-checklists'); + $this->lang['label_exact_singular'] = __('%d character in Yoast SEO focus keyword', 'publishpress-checklists'); + $this->lang['label_exact_plural'] = __('%d characters in Yoast SEO focus keyword', 'publishpress-checklists'); + $this->lang['label_between'] = __('Between %d and %d characters in Yoast SEO focus keyword', 'publishpress-checklists'); + } + + /** + * Returns the current status of the requirement. + * + * @param stdClass $post + * @param mixed $option_value + * + * @return mixed + */ + public function get_current_status($post, $option_value) + { + // Get focus keyword from Yoast SEO meta + $focus_keyword = get_post_meta($post->ID, '_yoast_wpseo_focuskw', true); + + $count = strlen(trim($focus_keyword)); + + return ($count >= $option_value[0]) && ($option_value[1] == 0 || $count <= $option_value[1]); + } +} diff --git a/modules/yoastseo/lib/Requirement/Meta_Description.php b/modules/yoastseo/lib/Requirement/Meta_Description.php new file mode 100644 index 00000000..6e25a5d7 --- /dev/null +++ b/modules/yoastseo/lib/Requirement/Meta_Description.php @@ -0,0 +1,68 @@ + + * @copyright Copyright (C) 2018 PublishPress. All rights reserved. + * @license GPLv2 or later + * @since 1.0.0 + */ + +namespace PublishPress\Checklists\Yoastseo\Requirement; + +use PublishPress\Checklists\Core\Requirement\Base_counter; +use stdClass; + +class Meta_Description extends Base_counter +{ + /** + * The name of the requirement, in a slug format + * + * @var string + */ + public $name = 'meta_description'; + + /** + * The name of the requirement, in a slug format + * + * @var string + */ + public $group = 'yoastseo'; + + /** + * Initialize the language strings for the instance + * + * @return void + */ + public function init_language() + { + $this->lang['label'] = __('Number of characters in Yoast SEO meta description', 'publishpress-checklists'); + $this->lang['label_settings'] = __('Number of characters in Yoast SEO meta description', 'publishpress-checklists'); + $this->lang['label_min_singular'] = __('Minimum of %d character in Yoast SEO meta description', 'publishpress-checklists'); + $this->lang['label_min_plural'] = __('Minimum of %d characters in Yoast SEO meta description', 'publishpress-checklists'); + $this->lang['label_max_singular'] = __('Maximum of %d character in Yoast SEO meta description', 'publishpress-checklists'); + $this->lang['label_max_plural'] = __('Maximum of %d characters in Yoast SEO meta description', 'publishpress-checklists'); + $this->lang['label_exact_singular'] = __('%d character in Yoast SEO meta description', 'publishpress-checklists'); + $this->lang['label_exact_plural'] = __('%d characters in Yoast SEO meta description', 'publishpress-checklists'); + $this->lang['label_between'] = __('Between %d and %d characters in Yoast SEO meta description', 'publishpress-checklists'); + } + + /** + * Returns the current status of the requirement. + * + * @param stdClass $post + * @param mixed $option_value + * + * @return mixed + */ + public function get_current_status($post, $option_value) + { + + // Get focus keyword from Yoast SEO meta + $meta_description = get_post_meta($post->ID, '_yoast_wpseo_metadesc', true); + + $count = strlen(trim($meta_description)); + + return ($count >= $option_value[0]) && ($option_value[1] == 0 || $count <= $option_value[1]); + } +} diff --git a/modules/yoastseo/yoastseo.php b/modules/yoastseo/yoastseo.php index 247e8e3d..eb536144 100644 --- a/modules/yoastseo/yoastseo.php +++ b/modules/yoastseo/yoastseo.php @@ -5,6 +5,8 @@ use PublishPress\Checklists\Core\Legacy\Module; use PublishPress\Checklists\Yoastseo\Requirement\Readability_Analysis; use PublishPress\Checklists\Yoastseo\Requirement\Seo_Analysis; +use PublishPress\Checklists\Yoastseo\Requirement\Focus_Keyword; +use PublishPress\Checklists\Yoastseo\Requirement\Meta_Description; /** * @package PublishPress\Checklists @@ -150,6 +152,8 @@ public function filterPostTypeRequirements($requirements, $postType) { $requirements[] = Readability_Analysis::class; $requirements[] = Seo_Analysis::class; + $requirements[] = Focus_Keyword::class; + $requirements[] = Meta_Description::class; return $requirements; }