Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/#555-support-for-yoast-focus-keyword-meta-description #844

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions modules/yoastseo/assets/js/meta-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
67 changes: 67 additions & 0 deletions modules/yoastseo/lib/Requirement/Focus_Keyword.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

/**
* @package PublishPress\Checklists
* @author PublishPress <[email protected]>
* @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]);
}
}
68 changes: 68 additions & 0 deletions modules/yoastseo/lib/Requirement/Meta_Description.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

/**
* @package PublishPress\Checklists
* @author PublishPress <[email protected]>
* @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]);
}
}
4 changes: 4 additions & 0 deletions modules/yoastseo/yoastseo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
Loading