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

Move WordPress.com themes api into jetpack-mu-wpcom package #41770

Open
wants to merge 20 commits into
base: update/php-8.1
Choose a base branch
from

Conversation

jeryj
Copy link
Contributor

@jeryj jeryj commented Feb 12, 2025

Part of the Theme Untangling project. This PR should not impact any functionality.

Proposed changes:

We modify some WordPress.com themes API calls using hooks while in the wp-admin view on WordPress.com sites.

Currently we do this only for Atomic sites. This PR moves that modification code into a place where the modifications can also work for Simple sites.

Note: currently as of this PR the modifications will only be loaded on Atomic until such time as we want to include them on Simple. This matches existing Production but sets us up for future development.

In #41374 we are modifying these files, so it makes sense to move them first in one PR, so that we can see what modifications are being made in the other PR.

We need to think about how to release this, since the release cycle for wpcom's mu-jetpack-wcom plugin and wpcomsh differ.

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:

This PR should not change any functionality.

On a simple site

  • Open wp-admin/themes.php
  • Confirm that you see the same list of themes as on trunk
  • Try switching themes
  • Confirm that it works the same as trunk
  • Try deleting a theme (this option is in the theme details modal)
  • Confirm that it works the same as trunk

On an Atomic site

  • Follow the instructions above
  • Go to wp-admin/theme-install.php
  • Search for a theme and confirm that the results are the same as trunk
  • Try installing a new theme - it should continue to work as trunk

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 WoA dev 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 (WordPress.com Site Helper), and enable the update/move-wpcom-themes-api branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack-mu-wpcom-plugin update/move-wpcom-themes-api

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.


🔴 Action required: Please add missing changelog entries for the following projects: projects/plugins/mu-wpcom-plugin

Use the Jetpack CLI tool to generate changelog entries by running the following command: jetpack changelog add.
Guidelines: /docs/writing-a-good-changelog-entry.md


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!


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen semi-continuously (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly. The next release is scheduled for none scheduled (scheduled code freeze on undefined).

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Mu Wpcom plugin:

  • Next scheduled release: WordPress.com Simple releases happen semi-continuously (PCYsg-Jjm-p2).

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Wpcomsh plugin:

  • Next scheduled release: Atomic deploys happen twice daily on weekdays (p9o2xV-2EN-p2).

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@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 2 files.

File Coverage Δ% Δ Uncovered
projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php 0/217 (0.00%) 0.00% 2 ❤️‍🩹
projects/plugins/wpcomsh/wpcom-themes/themes.php 0/26 (0.00%) 0.00% -55 💚

6 files are newly checked for coverage. Only the first 5 are listed here.

File Coverage
projects/packages/jetpack-mu-wpcom/src/features/wpcom-themes/includes/class-wpcom-themes-api.php 0/33 (0.00%) 💔
projects/packages/jetpack-mu-wpcom/src/features/wpcom-themes/includes/class-wpcom-themes-cache.php 0/5 (0.00%) 💔
projects/packages/jetpack-mu-wpcom/src/features/wpcom-themes/includes/class-wpcom-themes-mapper.php 0/36 (0.00%) 💔
projects/packages/jetpack-mu-wpcom/src/features/wpcom-themes/includes/class-wpcom-themes-merger.php 0/34 (0.00%) 💔
projects/packages/jetpack-mu-wpcom/src/features/wpcom-themes/includes/class-wpcom-themes-service.php 0/37 (0.00%) 💔

Full summary · PHP report · JS report

Add label I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. to override the failing coverage check.

@ryelle
Copy link
Member

ryelle commented Feb 12, 2025

Haven't tested thoroughly, but this seems to work well on a WoA dev site (with both WordPress.com Site Helper and WordPress.com Features using this branch) — theme-install.php returns wpcom themes 👍🏻

When I deactivate "WordPress.com Features" though, the themes return to what's in core. I think that's expected with the dev process, but I just want to check that we're sure this code will load on both simple and atomic sites.

Haven't tested on wpcom simple yet (though it should not do anything there, since these filters are never called).

@scruffian scruffian added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. [Type] Feature Development of a new feature and removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! labels Feb 13, 2025
@scruffian
Copy link
Member

I made some changes here:

  1. Only move the files, don't change any function names etc. yet, so that we don't risk breakages
  2. Load the files with the same conditions as before (both Atomic and not WP_CLI)

Testing:
✅ I tested on a Simple site. Nothing should change.
✅ I tested on an Atomic site - searching, installing, activating and deleting a theme.

@scruffian
Copy link
Member

scruffian commented Feb 13, 2025

Actually, thinking about this some more, I wonder if we should leave some of this in wpcomsh, as it isn't relevant to Simple sites - particularly the stuff about symlinks etc. However the requires are used for both. Maybe this is simpler. 🤔

@@ -160,6 +160,11 @@ public static function load_wpcom_user_features() {
require_once __DIR__ . '/features/wpcom-sidebar-notice/wpcom-sidebar-notice.php';
require_once __DIR__ . '/features/wpcom-themes/wpcom-themes.php';

// We include WPCom Themes results and installation on WoA sites only and non-WP_CLI context.
Copy link
Contributor

@getdave getdave Feb 13, 2025

Choose a reason for hiding this comment

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

Nit: I think it would be really helpful to future developers if we explained why we only enable in these contexts. Otherwise I think we can just remove the comment entirely.

@ryelle ryelle mentioned this pull request Feb 17, 2025
3 tasks
Copy link

jp-launch-control bot commented Feb 18, 2025

Code Coverage Summary

Coverage changed in 2 files.

File Coverage Δ% Δ Uncovered
projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php 0/225 (0.00%) 0.00% 2 ❤️‍🩹
projects/plugins/wpcomsh/wpcom-themes/themes.php 0/26 (0.00%) 0.00% -55 💚

6 files are newly checked for coverage. Only the first 5 are listed here.

File Coverage
projects/packages/jetpack-mu-wpcom/src/features/wpcom-themes/includes/class-wpcom-themes-api.php 0/35 (0.00%) 💔
projects/packages/jetpack-mu-wpcom/src/features/wpcom-themes/includes/class-wpcom-themes-cache.php 0/7 (0.00%) 💔
projects/packages/jetpack-mu-wpcom/src/features/wpcom-themes/includes/class-wpcom-themes-mapper.php 0/38 (0.00%) 💔
projects/packages/jetpack-mu-wpcom/src/features/wpcom-themes/includes/class-wpcom-themes-merger.php 0/36 (0.00%) 💔
projects/packages/jetpack-mu-wpcom/src/features/wpcom-themes/includes/class-wpcom-themes-service.php 0/39 (0.00%) 💔

Full summary · PHP report

Add label I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. to override the failing coverage check.

// Add results to the resulting array.
return $wpcom_themes_service->filter_themes_api_result_recommended( $res );
}
add_filter( 'themes_api_result', 'wpcomsh_popular_wpcom_themes_api_result', 0, 3 );
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 will want these to also run on WPcom in the untangling themes PR, right? Should we move them to run on WPcom now, or only in the untangling themes PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I a bit torn on if we should rename these functions and move the filters over entirely or not. I think it's best to leave it as is. We don't need any of this on WPcom yet. It's probably best to enable it in untangling themes as that's when it's actually needed.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I agree. If we keep this PR as just a code moving task, then we can consider changes in the future on a case by case basis. If we start changing things as well as moving them its gets harder to reason about.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, when I thought about the deploy process for this - because wpcomsh and jetpack-mu-wpcom are deployed at different times, I think it does make more sense to rename the functions now - that way we avoid errors when a function is redefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was worried about this too, but I think it's not an issue. I believe WoA sites run jetpack-mu-wpcom bundled as wpcomsh. They don't run the WPcom mu-plugin AND wpcomsh. So there should only be one version of anything running, even if deploy cycles are different. We should absolutely confirm to be sure though!

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I wasn't sure exactly how they fit together but @zinigor suggested it might be a problem and I thought better safe than sorry, since we want to rename anyway.

Copy link
Member

@zinigor zinigor Feb 19, 2025

Choose a reason for hiding this comment

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

I believe WoA sites run jetpack-mu-wpcom bundled as wpcomsh. They don't run the WPcom mu-plugin AND wpcomsh.

That's correct! I sometimes get confused with what environment gets affected with what. WoA and Atomic sites should be fine in this regard. The WordPress.com environment though will have these files removed added, but not used?

If that's so, then I'm sorry for causing additional anxiety about deploying this.

return $wpcom_themes_service->get_theme( $args->slug ) ?? $res;
}
add_filter( 'themes_api_result', 'wpcomsh_theme_information_wpcom_themes_api_result', 0, 3 );

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we move over this whole file? Or is what's left in this file separate enough that it's fine to leave in a separate location? As in, if someone needed to fix something related to the themes API, then they wouldn't need to work in both this file and jetpack-mu-wpcom/src/features/wpcom-themes/wpcomsh-themes.php?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I reviewed more thoroughly. I think this file can stay here and the separation is good. What's left in this file isn't about API calls. It's about symlinking wpcom themes for atomic sites, and doesn't run on api calls.

@jeryj
Copy link
Contributor Author

jeryj commented Feb 18, 2025

I think this PR code-wise is good to go. I'm going to take time this afternoon to test it on atomic. @scruffian - did you check any network requests in your testing?

@@ -5,174 +5,6 @@
* @package wpcom-themes
*/

/**
Copy link
Member

@ryelle ryelle Feb 18, 2025

Choose a reason for hiding this comment

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

Since this file isn't doing API things anymore, can you update the file comment ^?

Another idea (not blocking for this PR) would be to moved these symlink functions to
managed-themes.php — since there are other wpcom theme related functions there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another idea (not blocking for this PR) would be to moved these symlink functions to
managed-themes.php

I think it's a good idea to move it. Those functions all fit together since they're about managing symlinked themes. I don't see a reason to have them in different files.

Copy link
Member

Choose a reason for hiding this comment

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

The problem with moving it is that the conditions for loading wpcom-themes are different for the conditions for loading managed-themes. (wpcom-themes is not loaded in a CLI context). I'm not sure how deliberate this is.

Comment on lines 165 to 197
if ( ( defined( 'IS_ATOMIC' ) && IS_ATOMIC ) && ( ! defined( 'WP_CLI' ) || ! WP_CLI ) ) {
require_once __DIR__ . '/features/wpcom-themes/wpcomsh-themes.php';
}
Copy link
Member

Choose a reason for hiding this comment

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

What is the plan for removing this atomic gate? Can that be done here, or as part of a follow-up PR? Asking because I think it will help with a PR for the atomic transfer process (Automattic/wp-calypso#99761). And technically this shouldn't have any effect on simple sites yet anyway, since they don't call any install code.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I see the PR description says "This matches existing Production but sets us up for future development", so I assume a future PR.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I think its good to keep the PR purely for moving the code.

@scruffian scruffian force-pushed the update/move-wpcom-themes-api branch from 07b61ce to 06513b1 Compare February 19, 2025 11:21
@github-actions github-actions bot added the [Plugin] mu wpcom jetpack-mu-wpcom plugin label Feb 19, 2025
@scruffian
Copy link
Member

I renamed the duplicated functions so that we can deploy without worrying about name conflicts. I also added class_exists checks before each of the classes in case they get included twice.

@jeryj jeryj force-pushed the update/move-wpcom-themes-api branch from d4eb451 to d0a6f06 Compare February 20, 2025 21:42
@jeryj jeryj changed the base branch from trunk to update/php-8.1 February 20, 2025 21:43
@github-actions github-actions bot added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Feb 20, 2025
@jeryj
Copy link
Contributor Author

jeryj commented Feb 20, 2025

@scruffian - I split out the PHP 8.1 upgrade (#41928) and Phan (#41931) commits to separate PRs since they were necessary but unrelated to this work. Then I rebased this branch off of the PHP 8.1 upgrade branch and cherry-picked all the commits from this branch back. I have a local copy of the branch pre-rebasing if something is messed up.

@jeryj
Copy link
Contributor Author

jeryj commented Feb 20, 2025

I also added class_exists checks before each of the classes in case they get included twice.

@scruffian - It seems like this is unnecessary too. Was the worry here if both the jetpack-mu-wpcom-plugin and wpcomsh get loaded?

Copy link
Contributor Author

@jeryj jeryj left a comment

Choose a reason for hiding this comment

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

Flagging the code that can probably be removed.

Comment on lines +9 to +11
if ( class_exists( 'WPCom_Themes_Api' ) ) {
return;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Potentially unnecessary.

Comment on lines +9 to +11
if ( class_exists( 'WPCom_Themes_Cache' ) ) {
return;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Potentially unnecessary.

Comment on lines +9 to +11
if ( class_exists( 'WPCom_Themes_Mapper' ) ) {
return;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Potentially unnecessary.

Comment on lines +9 to +11
if ( class_exists( 'WPCom_Themes_Merger' ) ) {
return;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Potentially unnecessary.

Comment on lines +9 to +11
if ( class_exists( 'WPCom_Themes_Service' ) ) {
return;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Potentially unnecessary.

@scruffian
Copy link
Member

scruffian commented Feb 20, 2025

@scruffian - It seems like this is unnecessary too. Was the worry here if both the jetpack-mu-wpcom-plugin and wpcomsh get loaded?

Yeah, i was thinking about what might happen if the the mu plugin is running at the same time as wpcomsh - since that plugin will be deployed before this one - I think we want to ensure that both changes can happen independently of each other since we can't guarantee the timings.

I do also think it's generally good practice to check a class doesn't exist before you define it, just in case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Masterbar WordPress.com Toolbar and Dashboard customizations [mu wpcom Feature] Wpcom Themes Api [mu wpcom Feature] Wpcom Themes [Package] Jetpack mu wpcom WordPress.com Features [Package] Masterbar [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] mu wpcom jetpack-mu-wpcom plugin [Plugin] Wpcomsh [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! [Tests] Includes Tests [Type] Feature Development of a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants