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

Update approved screens for JITMs to a const #41748

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from

Conversation

getdave
Copy link
Contributor

@getdave getdave commented Feb 12, 2025

Proposed changes:

Sub PR of #41252.

Prepares for that PR to land by refactoring the screens where JITMs can be shown to a const for easier maintenance.

Allows us to ship a smaller diff in #41252.

Note that themes is ommitted from the "approved" list in this PR and will be added in #41252.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

Does this pull request change what data or activity we track or use?

Testing instructions:

⚠️ There is no need to test this code on Simple sites as the JITM feature is not active there unless you are using Calypso. This code does not affect Calypso routes.

Setup

  • Create a WoA testing site, transfer to the pool.
  • Go to WPAdmin - upload the Jetpack Beta Plugin (get a copy from the Gitub repo)
  • Go to Jetpack -> Beta Tester
  • In the list of modules look for the Jetpack entry and click "Manage"
  • Search for the name of this PR's branch and enable it. That will make this PR active on your test site.
  • Create a file called jitm-testing-mu-plugin.php. Create a .zip and upload it to your site. Check it's active. This Plugin will:
    • disable caching in the Engine.
    • disable Jetpack site caching via jetpack_options.
    • ensure JITMs are "on"
    • create a Test JITM which will show on all available screens.
JITMs Testing MU Plugin
<?php
/**
 * Plugin Name: Force JITM Display
 * Plugin URI: 
 * Description: Adds a test JITM with configurable settings
 * Version: 1.0
 * Author: Your Name
 * Author URI: 
 * License: GPL2
 */

// Prevent direct access to this file
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

// Configuration constants
const TEST_JITM_MAX_DISMISSALS = 1;     // Maximum number of times the test JITM can be dismissed
const TEST_JITM_EXPIRY_TIME = 1209600;  // How long before the test JITM expires (in seconds, default 14 days)

// Disable JITM cache during development
add_filter( 'jetpack_just_in_time_msg_cache', '__return_false', 1000 );

// Always return JITMs
add_filter( 'jetpack_jitm_should_return_jitms', '__return_true', 1000 );

// Filter the jetpack_options to ensure hide_jitm is always empty
add_filter( 'option_jetpack_options', function( $options ) {
    if ( is_array( $options ) ) {
        $options['hide_jitm'] = array();
    }
    return $options;
}, 1000 );

// Add our test JITM
add_filter( 'jetpack_jitm_received_envelopes', function( $envelopes ) {
    // Create a test JITM message
    $test_jitm = (object) array(
        'content' => (object) array(
            'message' => 'This is a test JITM message',
            'icon' => '',
            'iconPath' => '',
            'list' => array(),
            'description' => 'This is a test description for the JITM',
            'classes' => '',
            'title' => '',
            'disclaimer' => array(),
        ),
        'CTA' => (object) array(
            'message' => 'Click Here',
            'hook' => '',
            'newWindow' => 1,
            'primary' => 1,
            'link' => 'https://example.com',
            'target' => '_self'
        ),
        'template' => 'default',
        'ttl' => 300,
        'id' => 'test-jitm',
        'feature_class' => 'test-feature',
        'expires' => TEST_JITM_EXPIRY_TIME,
        'max_dismissal' => TEST_JITM_MAX_DISMISSALS,
        'activate_module' => '',
        'module_settings_link' => '',
        'is_dismissible' => 1,
        'is_user_created_by_partner' => '',
        'message_expiration' => '',
        'tracks' => (object) array(
            'click' => (object) array(
                'name' => 'jitm-test-click',
                'props' => (object) array(
                    'cta_feature' => 'test-feature'
                )
            )
        )
    );

    // Add the test JITM to the existing envelopes
    $envelopes[] = $test_jitm;

    return $envelopes;
}, 1000 );

Testing

  • Go to wp-admin/admin.php?page=jetpack-search.
  • You should see the Test JITM.
  • Try going to another WPAdmin page which is not in the screens whitelist (e.g. wp-admin/edit.php?post_type=feedback). You should not see JITM message.

Copy link
Contributor

github-actions bot commented Feb 12, 2025

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WordPress.com Simple site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin, and enable the update/jitm-approved-screens-to-const branch.

    • For jetpack-mu-wpcom changes, also add define( 'JETPACK_MU_WPCOM_LOAD_VIA_BETA_PLUGIN', true ); to your wp-config.php file.
  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack update/jitm-approved-screens-to-const
    
    bin/jetpack-downloader test jetpack-mu-wpcom-plugin update/jitm-approved-screens-to-const
    

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

Copy link
Contributor

github-actions bot commented Feb 12, 2025

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Choose a review path based on your changes:
    • A. Team Review: add the "[Status] Needs Team Review" label
      • For most changes, including minor cross-team impacts.
      • Example: Updating a team-specific component or a small change to a shared library.
    • B. Crew Review: add the "[Status] Needs Review" label
      • For significant changes to core functionality.
      • Example: Major updates to a shared library or complex features.
    • C. Both: Start with Team, then request Crew
      • For complex changes or when you need extra confidence.
      • Example: Refactor affecting multiple systems.
  3. Get at least one approval before merging.

Still unsure? Reach out in #jetpack-developers for guidance!

@github-actions github-actions bot added the [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! label Feb 12, 2025
Copy link
Contributor

github-actions bot commented Feb 12, 2025

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/jitm/src/class-jitm.php 68/123 (55.28%) 1.12% 0 💚

Full summary · PHP report · JS report

@getdave getdave requested a review from jeherve February 13, 2025 11:03
@getdave getdave self-assigned this Feb 13, 2025
@getdave getdave marked this pull request as ready for review February 13, 2025 11:04
Copy link
Member

@scruffian scruffian left a comment

Choose a reason for hiding this comment

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

I tested on my Atomic site and it works as described. Just a few questions about the changes to when we load the JITM class.

@getdave getdave requested a review from scruffian February 13, 2025 16:57
@getdave getdave removed the [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! label Feb 13, 2025
@getdave
Copy link
Contributor Author

getdave commented Feb 13, 2025

@scruffian I cleaned this up a bit. How is it looking / testing now for you?

Copy link
Member

@scruffian scruffian left a comment

Choose a reason for hiding this comment

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

🚢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants