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

SIT-3134: fix/232: Updated data type of keywords field to array. #233

Merged
merged 2 commits into from
Apr 14, 2022

Conversation

iamdharmesh
Copy link
Contributor

Description of the Change

As requested on #232, This PR updates the data type of the keywords field to array from string.

Closes #232

Alternate Designs

Possible Drawbacks

Verification Process

Verify that plugin sends an array of strings in the keywords field, further verification can be done on Sophi side logs.

Checklist:

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests passed.

Changelog Entry

Changed - The data type of keywords field to an array from string.

Credits

Props @iamdharmesh @jeffpaul

@iamdharmesh iamdharmesh self-assigned this Apr 13, 2022
@iamdharmesh iamdharmesh marked this pull request as ready for review April 13, 2022 16:54
@iamdharmesh iamdharmesh added this to the 1.0.13 milestone Apr 13, 2022
@@ -198,7 +198,11 @@ function get_post_data( $post ) {
$canonical_url = $yoast_canonical;
}

$keywords = get_post_meta( $post->ID, '_yoast_wpseo_focuskw', true );
$yoast_focuskw = get_post_meta( $post->ID, '_yoast_wpseo_focuskw', true );
if ( ! empty( $yoast_focuskw ) ) {
Copy link
Contributor

@oscarssanchez oscarssanchez Apr 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if $yoast_focuskw is empty, then $keywords will be still be an empty string. Do we want to change the initial data type as well?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if it's an empty string please have it as an empty array instead, or null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have array_filter on $data to remove all empty entries. So, in the case of empty $yoast_focuskw, the keywords field will be removed from $data and it will not be sent in request. As it is not going to send in a request, I think it's fine to keep it as it is. but it may create confusion for other devs too. So, I updated the initial value to [].
Thanks

$yoast_focuskw = get_post_meta( $post->ID, '_yoast_wpseo_focuskw', true );
if ( ! empty( $yoast_focuskw ) ) {
// Limit focus keyphrase to max length of 128.
$keywords = [ substr( $yoast_focuskw, 0, 128 ) ];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although we probably won't be sending anything over 100 strings as the array content, do we want to go ahead and implement that as well? Per requirement:

steps to fix: allow an array of strings with min 0 and max 100 strings.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes,
Thank you

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oscarssanchez $yoast_focuskw will be a single string. So, $keywords will be an array with 1 length always. However, the max length of the string can be up to 128, which I already implemented. Please let me know If I missed or misunderstood anything here.
Thanks.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sonds good to me.
How will this be populated if they are not using yoast?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@YMufleh it will be only populated if Yoast is installed. If they are not using Yoast, keywords field will be not sent in the request. (note: keywords field is optional)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noting here that WordPress, by default, does not provide keywords functionality and requires a plugin, like Yoast, to add on this SEO feature. There are some other SEO plugins, but by default the plugin only supports Yoast. If there are others that are determined to be in-use by other partners, then support for those SEO plugins can be added.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iamdharmesh , yes you are correct at this point we should not have more than 1 string, I was thinking more about future proofing, so something like if (count($array) > 100) limit array , but seems per @YMufleh we can leave this for now

Copy link
Contributor

@oscarssanchez oscarssanchez Apr 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l be only populated if Yoast is installed. If they are not using Yoast, keywords field will be n

Perhaps we could think using tags or something like that if no SEO plugin is installed @jeffpaul @YMufleh ? I'm not sure what effect would that have in Sophi though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe tags are sent across in a different field/variable, right? Just like categories?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link
Collaborator

@YMufleh YMufleh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
One question about functionality

$yoast_focuskw = get_post_meta( $post->ID, '_yoast_wpseo_focuskw', true );
if ( ! empty( $yoast_focuskw ) ) {
// Limit focus keyphrase to max length of 128.
$keywords = [ substr( $yoast_focuskw, 0, 128 ) ];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sonds good to me.
How will this be populated if they are not using yoast?

@jeffpaul
Copy link
Contributor

Given both @YMufleh and @oscarssanchez approved, I'm going to merge in so we can get this to our test site for further validation before a plugin minor release.

@jeffpaul jeffpaul merged commit 0527343 into develop Apr 14, 2022
@jeffpaul jeffpaul deleted the fix/232 branch April 14, 2022 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SIT-3134: Plugin update to correct the data type for keywords fields
4 participants