Skip to content

Conversation

@crodriguezbrito
Copy link
Contributor

Proposed changes

Jira ticket

Type of Change

Production

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Dependency update
  • Refactoring / housekeeping (changes to files not directly related to functionality)

Development

  • Tests
  • Dependency update
  • Environment update / refactoring
  • Documentation Update

Visual

Checklist

  • I have read the CONTRIBUTING doc
  • I have viewed my change in a web-browser
  • Linting and tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

@crodriguezbrito crodriguezbrito requested review from a team and Copilot and removed request for Copilot November 17, 2025 15:14
@github-actions
Copy link
Contributor

github-actions bot commented Nov 17, 2025

Copilot finished reviewing on behalf of crodriguezbrito November 17, 2025 15:19
Copilot AI review requested due to automatic review settings November 17, 2025 15:21
Copilot finished reviewing on behalf of crodriguezbrito November 17, 2025 15:23
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds new event tracking capabilities for Yoast SEO plugin activities, including database upgrades and option updates. It also improves code documentation with proper docblocks and applies Yoast coding standards for comparison operators.

Key changes:

  • Adds tracking for Yoast SEO database upgrades via the wpseo_run_upgrade hook
  • Adds tracking for Yoast SEO option updates across four option groups: wpseo_titles, wpseo_social, wpseo, and wpseo_ms
  • Improves code style by using Yoast comparisons (constant first in comparisons) and adding comprehensive docblocks for class properties

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

'category' => 'yoast_event',
'data' => array(
'previous_version' => $previous_version,
'new_version' => WPSEO_VERSION,
Copy link

Copilot AI Nov 17, 2025

Choose a reason for hiding this comment

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

The constant WPSEO_VERSION is used without checking if it's defined. If Yoast SEO is not installed or the constant is not available, this will cause a fatal error. Add a check like defined( 'WPSEO_VERSION' ) ? WPSEO_VERSION : 'unknown' to prevent this issue.

Suggested change
'new_version' => WPSEO_VERSION,
'new_version' => defined( 'WPSEO_VERSION' ) ? WPSEO_VERSION : 'unknown',

Copilot uses AI. Check for mistakes.
Comment on lines 413 to 421
if ( $old_value !== $new_value ) {

$data = array(
'category' => 'yoast_event',
'data' => array(
'old_value' => $old_value,
'new_value' => $new_value,
),
);
Copy link

Copilot AI Nov 17, 2025

Choose a reason for hiding this comment

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

The entire option values are being sent without any sanitization or filtering. Yoast options can contain sensitive information such as API keys, personal data, or configuration details that should not be transmitted. Consider either: (1) filtering out sensitive keys/values, (2) sending only a hash or indication that the option changed, or (3) implementing a whitelist of safe-to-track option keys within these option groups.

Suggested change
if ( $old_value !== $new_value ) {
$data = array(
'category' => 'yoast_event',
'data' => array(
'old_value' => $old_value,
'new_value' => $new_value,
),
);
// Define a whitelist of safe option keys whose values can be sent in full.
$safe_option_keys = array(
'yoast_tracking', // Example safe option, add more as needed.
'yoast_wpseo_titles',
'yoast_wpseo_social',
// Add other safe option keys here.
);
if ( $old_value !== $new_value ) {
if ( in_array( $option, $safe_option_keys, true ) ) {
$data = array(
'category' => 'yoast_event',
'data' => array(
'old_value' => $old_value,
'new_value' => $new_value,
),
);
} else {
$data = array(
'category' => 'yoast_event',
'data' => array(
'old_value_hash' => is_scalar( $old_value ) ? hash( 'sha256', (string) $old_value ) : hash( 'sha256', json_encode( $old_value ) ),
'new_value_hash' => is_scalar( $new_value ) ? hash( 'sha256', (string) $new_value ) : hash( 'sha256', json_encode( $new_value ) ),
'changed' => true,
),
);
}

Copilot uses AI. Check for mistakes.
*
* @return void
*/
public function database_upgrade( $previous_version ) {
Copy link

Copilot AI Nov 17, 2025

Choose a reason for hiding this comment

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

The new database_upgrade method lacks test coverage. Other listeners in this codebase (Plugin, Commerce, Cron) have corresponding test files. Consider adding tests to verify this method correctly handles null/empty previous versions and properly formats the event data.

Copilot uses AI. Check for mistakes.
*
* @return void
*/
public function option_updated( $old_value, $new_value, $option ) {
Copy link

Copilot AI Nov 17, 2025

Choose a reason for hiding this comment

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

The new option_updated method lacks test coverage. Other listeners in this codebase (Plugin, Commerce, Cron) have corresponding test files. Consider adding tests to verify this method correctly handles different value types, properly checks for changes, and formats the event data correctly.

Copilot uses AI. Check for mistakes.
Comment on lines +57 to +59
add_action( 'update_option_wpseo_titles', array( $this, 'option_updated' ), 10, 3 );
add_action( 'update_option_wpseo_social', array( $this, 'option_updated' ), 10, 3 );
add_action( 'update_option_wpseo', array( $this, 'option_updated' ), 10, 3 );
Copy link
Member

Choose a reason for hiding this comment

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

@crodriguezbrito - It appears we have a generic hook and two more specific ones. To the point that Copilot made, the generic one could pick up changes to API keys and things we may not want to send. It would be worth it to look at anything we don't want to send and have a deny list.

@circlecube circlecube requested a review from wpscholar December 5, 2025 15:45
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.

3 participants