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

Limited Global Styles: Port feature from ETK to jetpack-mu-wpcom #38333

Merged
merged 25 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9b00824
MU WPCOM: Port `wpcom-global-styles` from ETK
mmtr Jul 15, 2024
2a3e24e
Add changelog
mmtr Jul 15, 2024
ac6bb97
Enqueue scripts/styles and handle tracking
mmtr Jul 16, 2024
65c084d
Fix namespace and fetch plan name
mmtr Jul 16, 2024
62c951f
Regenerate lock file
mmtr Jul 16, 2024
553e008
Get correct data from initial state
mmtr Jul 16, 2024
14b1738
Update @package info
mmtr Jul 16, 2024
907853e
Fix unit test
mmtr Jul 16, 2024
ecce328
Fix image in modal
mmtr Jul 16, 2024
cdb2074
Add custom tracking tool to keep using calypso_ and wpcom_ events
mmtr Jul 16, 2024
9a58abc
Remove unused dependency
mmtr Jul 16, 2024
8d653ed
Merge branch 'trunk' into add/wpcom-global-styles
rcrdortiz Jul 17, 2024
596d769
Merge branch 'add/wpcom-global-styles' of github.com:Automattic/jetpa…
rcrdortiz Jul 17, 2024
70904b7
Merge branch 'trunk' into add/wpcom-global-styles
rcrdortiz Jul 17, 2024
d828513
Fixed a phan check about a redundant boolean cast
rcrdortiz Jul 17, 2024
dba9c53
Added masterbar.php to phan stubs
rcrdortiz Jul 17, 2024
f297ad5
Ignored some phan rules until we remove the main Global Styles ETK rules
rcrdortiz Jul 17, 2024
ccaafdc
Ignored some phan rules until we remove the main Global Styles ETK rules
rcrdortiz Jul 17, 2024
20b3396
Ignored some phan rules until we remove the main Global Styles ETK rules
rcrdortiz Jul 17, 2024
7e9b72c
Added a stub generator for Gutenberg, deleted the global styles stub …
rcrdortiz Jul 17, 2024
4eb1d3b
Added Gutenberg stub to phan config
rcrdortiz Jul 17, 2024
52eb202
We only load the Gutenberg stub on wpcom
rcrdortiz Jul 18, 2024
f05d5f5
Updated GS code to remove Gutenberg specific type. Removed Phan code …
rcrdortiz Jul 18, 2024
853ddb6
Merge branch 'trunk' into add/wpcom-global-styles
rcrdortiz Jul 18, 2024
8971895
Bumped version
rcrdortiz Jul 18, 2024
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
2 changes: 2 additions & 0 deletions .phan/config.base.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function make_phan_config( $dir, $options = array() ) {
$extra_stubs = array();
$global_stubs = array();
$internal_stubs = array();

foreach ( array_merge( $options['stubs'], $options['+stubs'] ) as $stub ) {
switch ( $stub ) {
case 'akismet':
Expand Down Expand Up @@ -104,6 +105,7 @@ function make_phan_config( $dir, $options = array() ) {
$stubs[] = "$root/.phan/stubs/wpcom-stubs.php";
if ( $dir !== "$root/projects/plugins/wpcomsh" ) {
$extra_stubs[] = "$root/projects/plugins/wpcomsh/feature-plugins/nav-redesign.php";
$extra_stubs[] = "$root/projects/plugins/wpcomsh/feature-plugins/masterbar.php";
$extra_stubs[] = "$root/projects/plugins/wpcomsh/footer-credit/footer-credit/customizer.php";
$extra_stubs[] = "$root/projects/plugins/wpcomsh/footer-credit/theme-optimizations.php";
$extra_stubs[] = "$root/projects/plugins/wpcomsh/lib/require-lib.php";
Expand Down
2 changes: 1 addition & 1 deletion .phan/stubs/akismet-stubs.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Stubs automatically generated from Akismet 5.3.2
* Stubs automatically generated from Akismet 5.3.3
* using the definition file `tools/stubs/akismet-stub-defs.php` in the Jetpack monorepo.
*
* Do not edit this directly! Run tools/stubs/update-stubs.sh to regenerate it.
Expand Down
2 changes: 1 addition & 1 deletion .phan/stubs/amp-stubs.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Stubs automatically generated from AMP 2.5.3 and AMP for WP 1.0.96.1
* Stubs automatically generated from AMP 2.5.4 and AMP for WP 1.0.96.1
* using the definition file `tools/stubs/amp-stub-defs.php` in the Jetpack monorepo.
*
* Do not edit this directly! Run tools/stubs/update-stubs.sh to regenerate it.
Expand Down
68 changes: 22 additions & 46 deletions .phan/stubs/full-site-editing-stubs.php
Original file line number Diff line number Diff line change
@@ -1,55 +1,31 @@
<?php
/**
* Stubs automatically generated from WordPress.com Editing Toolkit 4.27610
* Stubs automatically generated from WordPress.com Editing Toolkit 4.28277
* using the definition file `tools/stubs/full-site-editing-stub-defs.php` in the Jetpack monorepo.
*
* Do not edit this directly! Run tools/stubs/update-stubs.sh to regenerate it.
*/

namespace {
/**
* Limit Global Styles on WP.com to paid plans.
*
* @package full-site-editing-plugin
*/
/**
* Checks if Global Styles should be limited on the given site.
*
* @param int $blog_id Blog ID.
* @return bool Whether Global Styles are limited.
*/
function wpcom_should_limit_global_styles($blog_id = 0)
{
}
/**
* Checks if the current blog has custom styles in use.
*
* @return bool Returns true if custom styles are in use.
*/
function wpcom_global_styles_in_use()
{
}
namespace A8C\FSE;

/**
* Whether or not FSE is active.
* If false, FSE functionality should be disabled.
*
* @returns bool True if FSE is active, false otherwise.
* @phan-return mixed Dummy doc for stub.
*/
function is_full_site_editing_active()
{
}
namespace A8C\FSE {
/**
* Whether or not FSE is active.
* If false, FSE functionality should be disabled.
*
* @returns bool True if FSE is active, false otherwise.
* @phan-return mixed Dummy doc for stub.
*/
function is_full_site_editing_active()
{
}
/**
* Whether or not the site is eligible for FSE. This is essentially a feature
* gate to disable FSE on some sites which could theoretically otherwise use it.
*
* By default, sites should not be eligible.
*
* @return bool True if current site is eligible for FSE, false otherwise.
*/
function is_site_eligible_for_full_site_editing()
{
}
/**
* Whether or not the site is eligible for FSE. This is essentially a feature
* gate to disable FSE on some sites which could theoretically otherwise use it.
*
* By default, sites should not be eligible.
*
* @return bool True if current site is eligible for FSE, false otherwise.
*/
function is_site_eligible_for_full_site_editing()
{
}
2 changes: 1 addition & 1 deletion .phan/stubs/phpunit-stubs.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Stubs automatically generated from PHPUnit 9.6.19
* Stubs automatically generated from PHPUnit 9.6.20
* using the definition file `tools/stubs/phpunit-stub-defs.php` in the Jetpack monorepo.
*
* Do not edit this directly! Run tools/stubs/update-stubs.sh to regenerate it.
Expand Down
2 changes: 1 addition & 1 deletion .phan/stubs/woocommerce-internal-stubs.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Stubs automatically generated from WooCommerce 9.0.2
* Stubs automatically generated from WooCommerce 9.1.1
* using the definition file `tools/stubs/woocommerce-internal-stub-defs.php` in the Jetpack monorepo.
*
* Do not edit this directly! Run tools/stubs/update-stubs.sh to regenerate it.
Expand Down
2 changes: 1 addition & 1 deletion .phan/stubs/woocommerce-payments-stubs.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Stubs automatically generated from WooPayments 7.8.1
* Stubs automatically generated from WooPayments 7.9.1
* using the definition file `tools/stubs/woocommerce-payments-stub-defs.php` in the Jetpack monorepo.
*
* Do not edit this directly! Run tools/stubs/update-stubs.sh to regenerate it.
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Limited Global Styles: Port feature from ETK
2 changes: 1 addition & 1 deletion projects/packages/jetpack-mu-wpcom/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
},
"autotagger": true,
"branch-alias": {
"dev-trunk": "5.45.x-dev"
"dev-trunk": "5.46.x-dev"
},
"textdomain": "jetpack-mu-wpcom",
"version-constants": {
Expand Down
4 changes: 3 additions & 1 deletion projects/packages/jetpack-mu-wpcom/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-mu-wpcom",
"version": "5.45.0",
"version": "5.46.0-alpha",
"description": "Enhances your site with features powered by WordPress.com",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/jetpack-mu-wpcom/#readme",
"bugs": {
Expand Down Expand Up @@ -51,12 +51,14 @@
"@automattic/typography": "1.0.0",
"@preact/signals": "^1.2.2",
"@sentry/browser": "7.80.1",
"@tanstack/react-query": "^5.15.5",
"@wordpress/api-fetch": "7.2.0",
"@wordpress/base-styles": "5.2.0",
"@wordpress/blocks": "13.2.0",
"@wordpress/components": "28.2.0",
"@wordpress/data": "10.2.0",
"@wordpress/dom-ready": "^4.0.0",
"@wordpress/element": "6.2.0",
"@wordpress/hooks": "4.2.0",
"@wordpress/i18n": "5.2.0",
"@wordpress/plugins": "7.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Jetpack_Mu_Wpcom main class.
*/
class Jetpack_Mu_Wpcom {
const PACKAGE_VERSION = '5.45.0';
const PACKAGE_VERSION = '5.46.0-alpha';
const PKG_DIR = __DIR__ . '/../';
const BASE_DIR = __DIR__ . '/';
const BASE_FILE = __FILE__;
Expand Down Expand Up @@ -160,6 +160,7 @@ public static function load_etk_features() {
require_once __DIR__ . '/features/wpcom-blocks/event-countdown/event-countdown.php';
require_once __DIR__ . '/features/wpcom-blocks/timeline/timeline.php';
require_once __DIR__ . '/features/wpcom-documentation-links/wpcom-documentation-links.php';
require_once __DIR__ . '/features/wpcom-global-styles/index.php';
require_once __DIR__ . '/features/wpcom-whats-new/wpcom-whats-new.php';
}

Expand Down
24 changes: 24 additions & 0 deletions projects/packages/jetpack-mu-wpcom/src/common/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

namespace Automattic\Jetpack\Jetpack_Mu_Wpcom\Common;

use Automattic\Jetpack\Connection\Initial_State as Connection_Initial_State;
use Automattic\Jetpack\Connection\Manager as Connection_Manager;
use Automattic\Jetpack\Status;
use Automattic\Jetpack\Terms_Of_Service;
use Automattic\Jetpack\Tracking;

/**
* Returns ISO 639 conforming locale string.
*
Expand Down Expand Up @@ -39,3 +45,21 @@ function determine_iso_639_locale() {
$locale = get_user_locale();
return get_iso_639_locale( $locale );
}

/**
* Enqueue the tracking scripts for the given script handle.
*
* @param string $handle A script handle.
*/
function wpcom_enqueue_tracking_scripts( string $handle ) {
Connection_Initial_State::render_script( $handle );

$status = new Status();
$connection = new Connection_Manager();
$tracking = new Tracking( 'jetpack-mu-wpcom', $connection );
$can_use_analytics = $tracking->should_enable_tracking( new Terms_Of_Service(), $status );

if ( $can_use_analytics ) {
Tracking::register_tracks_functions_scripts( true );
}
}
27 changes: 27 additions & 0 deletions projects/packages/jetpack-mu-wpcom/src/common/tracks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* global JP_CONNECTION_INITIAL_STATE */

export const wpcomTrackEvent = (
eventName,
eventProperties = {},
eventUserId = null,
eventUsername = null
) => {
const currentUser = JP_CONNECTION_INITIAL_STATE?.userConnectionData?.currentUser ?? {};

const userId = eventUserId ?? currentUser.id;
const username = eventUsername ?? currentUser.username;
const blogId = eventProperties.blogId ?? currentUser.blogId;

window._tkq = window._tkq || [];
if ( username && userId ) {
window._tkq.push( [ 'identifyUser', userId, username ] );
}
window._tkq.push( [
'recordEvent',
eventName,
{
...eventProperties,
blog_id: blogId,
},
] );
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@
* @package automattic/jetpack-mu-wpcom
*/

use Automattic\Jetpack\Connection\Initial_State as Connection_Initial_State;
use Automattic\Jetpack\Connection\Manager as Connection_Manager;
use Automattic\Jetpack\Jetpack_Mu_Wpcom;
use Automattic\Jetpack\Status;
use Automattic\Jetpack\Terms_Of_Service;
use Automattic\Jetpack\Tracking;
use Automattic\Jetpack\Jetpack_Mu_Wpcom\Common;

define( 'MU_WPCOM_TAGS_EDUCATION', true );

Expand All @@ -34,16 +30,7 @@ function wpcom_enqueue_tags_education_assets() {
array( 'actionText' => __( 'Build your audience with tags', 'jetpack-mu-wpcom' ) )
);

Connection_Initial_State::render_script( 'wpcom-tags-education-script' );

$status = new Status();
$connection = new Connection_Manager();
$tracking = new Tracking( 'jetpack-mu-wpcom', $connection );
$can_use_analytics = $tracking->should_enable_tracking( new Terms_Of_Service(), $status );

if ( $can_use_analytics ) {
Tracking::register_tracks_functions_scripts( true );
}
Common\wpcom_enqueue_tracking_scripts( 'wpcom-tags-education-script' );
}

add_action( 'enqueue_block_editor_assets', 'wpcom_enqueue_tags_education_assets', 100 );
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@
* @package automattic/jetpack-mu-wpcom
*/

use Automattic\Jetpack\Connection\Initial_State as Connection_Initial_State;
use Automattic\Jetpack\Connection\Manager as Connection_Manager;
use Automattic\Jetpack\Jetpack_Mu_Wpcom;
use Automattic\Jetpack\Status;
use Automattic\Jetpack\Terms_Of_Service;
use Automattic\Jetpack\Tracking;
use Automattic\Jetpack\Jetpack_Mu_Wpcom\Common;

define( 'MU_WPCOM_BLOCK_DESCRIPTION_LINKS', true );

Expand All @@ -28,16 +24,7 @@ function wpcom_enqueue_block_description_links_assets() {
true
);

Connection_Initial_State::render_script( 'wpcom-block-description-links-script' );

$status = new Status();
$connection = new Connection_Manager();
$tracking = new Tracking( 'jetpack-mu-wpcom', $connection );
$can_use_analytics = $tracking->should_enable_tracking( new Terms_Of_Service(), $status );

if ( $can_use_analytics ) {
Tracking::register_tracks_functions_scripts( true );
}
Common\wpcom_enqueue_tracking_scripts( 'wpcom-block-description-links-script' );
}

add_action( 'enqueue_block_editor_assets', 'wpcom_enqueue_block_description_links_assets', 100 );
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# WP.com Global Styles

Functionality that limits the Global Styles feature on WordPress.com sites to paid plans.

## Highlights

- The site editor displays a modal after opening the Global Styles panel to alert customers that it is a paid feature.
- When the site's plan isn't a paid plan we will override the Global Styles loaded and will return the default Global Styles for the active theme.
- The pre-save panel of the site editor displays a notice to alert customers that any Global Styles change won't be public.
Loading
Loading