Skip to content

Commit

Permalink
Merge branch 'trunk' into fix/settings-newsletter-1023-disabled-conne…
Browse files Browse the repository at this point in the history
…ction
  • Loading branch information
grzegorz-cp committed Oct 1, 2024
2 parents 969a8fc + c7e170e commit 242d276
Show file tree
Hide file tree
Showing 129 changed files with 810 additions and 595 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ jobs:
fi
exit $EXIT
- name: Install svn
run: command -v svn || sudo apt-get install -y subversion

- uses: actions/checkout@v4
with:
path: src
Expand Down
9 changes: 8 additions & 1 deletion .phan/stubs/wpcom-stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* `bin/teamcity-builds/jetpack-stubs/stub-defs.php` and regenerate the stubs
* by triggering the Jetpack Staging → Update WPCOM Stubs job in TeamCity.
*
* Stubs automatically generated from WordPress.com commit fc607c626f1d1faf6baaba974cb048312f3c5841.
* Stubs automatically generated from WordPress.com commit 2ed424b4493f3450b67bb248706d6e29170e6042.
*/

namespace {
Expand Down Expand Up @@ -171,6 +171,13 @@ public function get_product_slugs(): array
public static function get_existing_cart(?array $args = []): self
{
}
/**
* @param array|null $args
* @return bool
*/
public static function is_cart_empty(?array $args = []): bool
{
}
}
class Store_Product_List
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Fetch adminUrl current value on function run
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const {
apiNonce,
siteSuffix: defaultSiteSuffix,
} = window?.JP_CONNECTION_INITIAL_STATE || getScriptData()?.connection || {};
const defaultAdminUrl =
const defaultAdminUrl = () =>
typeof window !== 'undefined' ? window?.myJetpackInitialState?.adminUrl : null;

/**
Expand All @@ -38,7 +38,7 @@ export default function useProductCheckoutWorkflow( {
productSlug,
redirectUrl,
siteSuffix = defaultSiteSuffix,
adminUrl = defaultAdminUrl,
adminUrl = defaultAdminUrl(),
connectAfterCheckout = false,
siteProductAvailabilityHandler = null,
quantity = null,
Expand Down
4 changes: 4 additions & 0 deletions projects/js-packages/webpack-config/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 3.4.2 - 2024-09-26
### Changed
- Updated package dependencies. [#39534]

## 3.4.1 - 2024-09-10
### Changed
- Updated package dependencies. [#39302]
Expand Down
2 changes: 1 addition & 1 deletion projects/js-packages/webpack-config/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-webpack-config",
"version": "3.4.1",
"version": "3.4.2",
"description": "Library of pieces for webpack config in Jetpack projects.",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/js-packages/webpack-config/#readme",
"bugs": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Added a check for function presence to avoid fatal errors.
3 changes: 2 additions & 1 deletion projects/packages/a8c-mc-stats/src/class-a8c-mc-stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ public function do_server_side_stat( $url ) {
public function build_stats_url( $args ) {
$defaults = array(
'v' => 'wpcom2',
'rand' => md5( wp_rand( 0, 999 ) . time() ),
// phpcs:ignore WordPress.WP.AlternativeFunctions.rand_rand -- There can be a case where pluggables are not yet loaded.
'rand' => md5( ( function_exists( 'wp_rand' ) ? wp_rand( 0, 999 ) : rand( 0, 999 ) ) . time() ),
);
$args = wp_parse_args( $args, $defaults );
$gifname = true === $this->use_transparent_pixel ? 'b.gif' : 'g.gif';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Remove user connection nudges where they aren't needed. Add user connection nudges where needed
56 changes: 44 additions & 12 deletions projects/packages/blaze/src/class-blaze.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static function init() {
* @return void
*/
public static function add_post_links_actions() {
if ( self::should_initialize() ) {
if ( self::should_initialize()['can_init'] ) {
add_filter( 'post_row_actions', array( __CLASS__, 'jetpack_blaze_row_action' ), 10, 2 );
add_filter( 'page_row_actions', array( __CLASS__, 'jetpack_blaze_row_action' ), 10, 2 );
}
Expand Down Expand Up @@ -97,7 +97,7 @@ public static function is_dashboard_enabled() {
* @return void
*/
public static function enable_blaze_menu() {
if ( ! self::should_initialize() ) {
if ( ! self::should_initialize()['can_init'] ) {
return;
}

Expand Down Expand Up @@ -195,7 +195,7 @@ public static function site_supports_blaze( $blog_id ) {
* Determines if criteria is met to enable Blaze features.
* Keep in mind that this makes remote requests, so we want to avoid calling it when unnecessary, like in the frontend.
*
* @return bool
* @return array
*/
public static function should_initialize() {
$is_wpcom = defined( 'IS_WPCOM' ) && IS_WPCOM;
Expand All @@ -204,7 +204,10 @@ public static function should_initialize() {

// Only admins should be able to Blaze posts on a site.
if ( ! current_user_can( 'manage_options' ) ) {
return false;
return array(
'can_init' => false,
'reason' => 'user_not_admin',
);
}

// Allow short-circuiting the Blaze initialization via a filter.
Expand All @@ -216,7 +219,12 @@ public static function should_initialize() {
*
* @param bool $should_initialize Whether Blaze should be enabled. Default to true.
*/
return apply_filters( 'jetpack_blaze_enabled', true );
$should_init = apply_filters( 'jetpack_blaze_enabled', true );

return array(
'can_init' => $should_init,
'reason' => $should_init ? null : 'initialization_disabled',
);
}

// On self-hosted sites, we must do some additional checks.
Expand All @@ -227,25 +235,49 @@ public static function should_initialize() {
*/
if (
is_wp_error( $site_id )
|| ! $connection->is_connected()
|| ! $connection->is_user_connected()
) {
return false;
return array(
'can_init' => false,
'reason' => 'wp_error',
);
}

if ( ! $connection->is_connected() ) {
return array(
'can_init' => false,
'reason' => 'site_not_connected',
);
}

if ( ! $connection->is_user_connected() ) {
return array(
'can_init' => false,
'reason' => 'user_not_connected',
);
}

// The whole thing is powered by Sync!
if ( ! Sync_Settings::is_sync_enabled() ) {
return false;
return array(
'can_init' => false,
'reason' => 'sync_disabled',
);
}
}

// Check if the site supports Blaze.
if ( is_numeric( $site_id ) && ! self::site_supports_blaze( $site_id ) ) {
return false;
return array(
'can_init' => false,
'reason' => 'site_not_eligible',
);
}

// Final fallback.
return true;
return array(
'can_init' => true,
'reason' => null,
);
}

/**
Expand Down Expand Up @@ -368,7 +400,7 @@ public static function enqueue_block_editor_assets() {
return;
}
// Bail if criteria is not met to enable Blaze features.
if ( ! self::should_initialize() ) {
if ( ! self::should_initialize()['can_init'] ) {
return;
}

Expand Down
6 changes: 3 additions & 3 deletions projects/packages/blaze/tests/php/test-blaze.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ public function test_dashboard_filter_enable() {
* @covers Automattic\Jetpack\Blaze::should_initialize
*/
public function test_filter_overwrites_eligibility() {
$this->assertFalse( Blaze::should_initialize() );
$this->assertFalse( Blaze::should_initialize()['can_init'] );
wp_set_current_user( $this->admin_id );
add_filter( 'jetpack_blaze_enabled', '__return_true' );
$this->assertTrue( Blaze::should_initialize() );
$this->assertTrue( Blaze::should_initialize()['can_init'] );
add_filter( 'jetpack_blaze_enabled', '__return_false' );
}

Expand All @@ -111,7 +111,7 @@ public function test_filter_overwrites_eligibility() {
*/
public function test_editor_not_eligible() {
wp_set_current_user( $this->editor_id );
$this->assertFalse( Blaze::should_initialize() );
$this->assertFalse( Blaze::should_initialize()['can_init'] );
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

In 'connect_url_redirect' hook, redirect to 'redirect_after_auth` url if already connected (for connect_after_checkout flow).
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

My Jetpack Welcome Flow: Display default recommendations upfront first, then offer optional survey for customized recommendations.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public static function get_option_names( $type = 'compact' ) {
'dismissed_welcome_banner', // (bool) Determines if the welcome banner has been dismissed or not.
'recommendations_evaluation', // (object) Catalog of recommended modules with corresponding score following successful site evaluation in Welcome Banner.
'dismissed_recommendations', // (bool) Determines if the recommendations have been dismissed or not.
'recommendations_first_run', // (bool) Determines if the current recommendations are the initial default auto-loaded ones (without user input).
'historically_active_modules', // (array) List of installed plugins/enabled modules that have at one point in time been active and working
);
}
Expand Down
4 changes: 4 additions & 0 deletions projects/packages/connection/src/class-webhooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ public function handle_connect_url_redirect() {
wp_safe_redirect( $redirect );
$this->do_exit();
} else {
if ( 'connect-after-checkout' === $from && $redirect ) {
wp_safe_redirect( $redirect );
$this->do_exit();
}
$connect_url = add_query_arg(
array(
'from' => $from,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Blog Privacy: Do not add custom rules to wpcom's robots.txt if blog_public=0
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

jetpack-mu-wpcom: remove unneeded filter
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: changed

Launchpad: Added isset to avoid Warnings when finding about page id
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

wpcom_add_shopping_cart: Use Store_Shopping_Cart::is_cart_empty() when deciding to render icon for incrased performance
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: changed

Help Center: use Zendesk staging when proxied
18 changes: 0 additions & 18 deletions projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,6 @@ public static function init() {
return;
}

add_filter(
'load_script_textdomain_relative_path',
function ( $relative ) {
// Check if $relative is a string and contains the required segment
if ( str_contains( $relative, 'vendor/automattic/jetpack-mu-wpcom/' ) ) {
$pattern = '#^(?:production|staging|moon|sun)/#'; // Matches the environment prefix on Simple Sites

if ( preg_match( $pattern, $relative ) ) {
$relative = preg_replace( $pattern, '', $relative ); // Remove the environment prefix
}
}

return $relative;
},
10,
2
);

// Shared code for src/features.
require_once self::PKG_DIR . 'src/common/index.php'; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.NotAbsolutePath
require_once __DIR__ . '/utils.php';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ function robots_txt( string $output, $public ): string {
$public = (int) $public;

// If the site is completely private, don't bother with the additional restrictions.
if ( -1 === $public ) {
// For blog_public=0, WP.com Disallows all user agents and Core does not (relying on <meta name="robots">).
// Let wpcom do it's thing to not clutter the robots.txt file.
if ( -1 === $public || ( 0 === $public && defined( 'IS_WPCOM' ) && IS_WPCOM ) ) {
return $output;
}

// For blog_public=0, WP.com Disallows all user agents and Core does not (relying on <meta name="robots">).
// Always add Disallow blocks for blog_public=0 even on WP.com where it may be redundant.
// An option oddly named because of history.
if ( 0 === $public || get_option( 'wpcom_data_sharing_opt_out' ) ) {
$ai_bots = array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ function ( $wp_admin_bar ) {
'help-center',
'const helpCenterData = ' . wp_json_encode(
array(
'isProxied' => boolval( self::is_proxied() ),
'currentUser' => array(
'ID' => $user_id,
'username' => $username,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2134,11 +2134,14 @@ function wpcom_launchpad_find_site_about_page_id() {
$headstart_about_pages = array_filter(
$annotation['content'],
function ( $page ) {
if ( 'page' !== $page['post_type'] ) {
if ( isset( $page['post_type'] ) && 'page' !== $page['post_type'] ) {
return false;
}

if ( 'about' === $page['post_name'] || str_contains( $page['post_title'], 'About' ) ) {
if ( isset( $page['post_name'] ) && 'about' === $page['post_name'] ) {
return true;
}
if ( isset( $page['post_title'] ) && str_contains( $page['post_title'], 'About' ) ) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,15 @@ function wpcom_add_shopping_cart( $wp_admin_bar ) {
// Get the current blog ID.
$blog_id = get_current_blog_id();

// Retrieve the current user's shopping cart for the current blog.
$cart = \Store_Shopping_Cart::get_existing_cart(
$is_empty = \Store_Shopping_Cart::is_cart_empty(
array(
'blog_id' => $blog_id,
'user_id' => get_current_user_id(),
)
);

// If the cart is empty (no products), do not add the cart menu.
if ( ! $cart->get_product_slugs() ) {
if ( $is_empty ) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Remove user connection nudges where they aren't needed. Add user connection nudges where needed
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: removed

Masterbar: Remove User Info side-panel
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public function add_tools_menu() {
add_menu_page( esc_attr__( 'Tools', 'jetpack-masterbar' ), __( 'Tools', 'jetpack-masterbar' ), 'publish_posts', 'tools.php', null, 'dashicons-admin-tools', 75 );
add_submenu_page( 'tools.php', esc_attr__( 'Marketing', 'jetpack-masterbar' ), __( 'Marketing', 'jetpack-masterbar' ), 'publish_posts', 'https://wordpress.com/marketing/tools/' . $this->domain );

if ( Blaze::should_initialize() ) {
if ( Blaze::should_initialize()['can_init'] ) {
// @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539.
add_submenu_page( 'tools.php', esc_attr__( 'Advertising', 'jetpack-masterbar' ), __( 'Advertising', 'jetpack-masterbar' ), 'manage_options', 'https://wordpress.com/advertising/' . $this->domain, null, 1 );
}
Expand Down
Loading

0 comments on commit 242d276

Please sign in to comment.