From adffb45f4915d6a1f390bfd5259c096dc977397b Mon Sep 17 00:00:00 2001 From: Manzoor Wani Date: Thu, 28 Nov 2024 12:07:41 +0530 Subject: [PATCH 1/2] Social | Fix publicize crashing when activated in the editor --- .../changelog/fix-publicize-activation-crash-in-the-editor | 4 ++++ .../packages/publicize/src/class-publicize-script-data.php | 3 +-- projects/packages/publicize/src/class-publicize-utils.php | 4 ---- .../changelog/fix-publicize-activation-crash-in-the-editor | 4 ++++ .../changelog/fix-publicize-activation-crash-in-the-editor | 4 ++++ projects/plugins/social/src/class-jetpack-social.php | 5 +++++ 6 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 projects/packages/publicize/changelog/fix-publicize-activation-crash-in-the-editor create mode 100644 projects/plugins/jetpack/changelog/fix-publicize-activation-crash-in-the-editor create mode 100644 projects/plugins/social/changelog/fix-publicize-activation-crash-in-the-editor diff --git a/projects/packages/publicize/changelog/fix-publicize-activation-crash-in-the-editor b/projects/packages/publicize/changelog/fix-publicize-activation-crash-in-the-editor new file mode 100644 index 0000000000000..18cb7b183c157 --- /dev/null +++ b/projects/packages/publicize/changelog/fix-publicize-activation-crash-in-the-editor @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Social | Fixed publicize crashing when activated in the editor diff --git a/projects/packages/publicize/src/class-publicize-script-data.php b/projects/packages/publicize/src/class-publicize-script-data.php index 1b285f1d09801..21743c7cba8e7 100644 --- a/projects/packages/publicize/src/class-publicize-script-data.php +++ b/projects/packages/publicize/src/class-publicize-script-data.php @@ -91,7 +91,7 @@ public static function get_admin_script_data() { } $basic_data = array( - 'api_paths' => array(), + 'api_paths' => self::get_api_paths(), 'is_publicize_enabled' => Utils::is_publicize_active(), 'feature_flags' => self::get_feature_flags(), 'supported_services' => array(), @@ -114,7 +114,6 @@ public static function get_admin_script_data() { return array_merge( $basic_data, array( - 'api_paths' => self::get_api_paths(), 'supported_services' => self::get_supported_services(), 'shares_data' => self::get_shares_data(), 'urls' => self::get_urls(), diff --git a/projects/packages/publicize/src/class-publicize-utils.php b/projects/packages/publicize/src/class-publicize-utils.php index 77f5272f0ba93..bbabb54272a0d 100644 --- a/projects/packages/publicize/src/class-publicize-utils.php +++ b/projects/packages/publicize/src/class-publicize-utils.php @@ -56,10 +56,6 @@ public static function should_block_editor_have_social() { return false; } - if ( ! self::is_publicize_active() ) { - return false; - } - $post_type = get_post_type(); if ( empty( $post_type ) || ! post_type_supports( $post_type, 'publicize' ) ) { diff --git a/projects/plugins/jetpack/changelog/fix-publicize-activation-crash-in-the-editor b/projects/plugins/jetpack/changelog/fix-publicize-activation-crash-in-the-editor new file mode 100644 index 0000000000000..0af9f98a252a8 --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-publicize-activation-crash-in-the-editor @@ -0,0 +1,4 @@ +Significance: patch +Type: bugfix + +Social | Fixed publicize crashing when activated in the editor diff --git a/projects/plugins/social/changelog/fix-publicize-activation-crash-in-the-editor b/projects/plugins/social/changelog/fix-publicize-activation-crash-in-the-editor new file mode 100644 index 0000000000000..cdb89762a5ffe --- /dev/null +++ b/projects/plugins/social/changelog/fix-publicize-activation-crash-in-the-editor @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Fixed publicize crashing when activated in the editor diff --git a/projects/plugins/social/src/class-jetpack-social.php b/projects/plugins/social/src/class-jetpack-social.php index 2d8b351f6ac08..a9a96b55fea7d 100644 --- a/projects/plugins/social/src/class-jetpack-social.php +++ b/projects/plugins/social/src/class-jetpack-social.php @@ -18,6 +18,7 @@ use Automattic\Jetpack\Modules; use Automattic\Jetpack\My_Jetpack\Initializer as My_Jetpack_Initializer; use Automattic\Jetpack\Publicize\Jetpack_Social_Settings\Dismissed_Notices; +use Automattic\Jetpack\Publicize\Publicize_Utils; use Automattic\Jetpack\Status; use Automattic\Jetpack\Terms_Of_Service; use Automattic\Jetpack\Tracking; @@ -224,6 +225,10 @@ public function get_shares_info() { * @return array */ public function set_social_admin_script_data( $data ) { + // We need this data only on the social settings page. + if ( ! Publicize_Utils::is_social_settings_page() ) { + return $data; + } $data['plugin_info']['social'] = array( 'version' => $this->get_plugin_version(), From cc2ac142a6904b52bd0cb377091f9c0083ad8d37 Mon Sep 17 00:00:00 2001 From: Manzoor Wani Date: Thu, 28 Nov 2024 17:31:08 +0530 Subject: [PATCH 2/2] Restore should_block_editor_have_social with a flag --- .../publicize/src/class-publicize-script-data.php | 2 +- projects/packages/publicize/src/class-publicize-utils.php | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/projects/packages/publicize/src/class-publicize-script-data.php b/projects/packages/publicize/src/class-publicize-script-data.php index 21743c7cba8e7..70ce959194f12 100644 --- a/projects/packages/publicize/src/class-publicize-script-data.php +++ b/projects/packages/publicize/src/class-publicize-script-data.php @@ -84,7 +84,7 @@ public static function get_admin_script_data() { // the Jetpack settings page, or the block editor. $should_set_script_data = Utils::is_jetpack_settings_page() || Utils::is_social_settings_page() - || Utils::should_block_editor_have_social(); + || Utils::should_block_editor_have_social( false ); if ( ! $should_set_script_data ) { return array(); diff --git a/projects/packages/publicize/src/class-publicize-utils.php b/projects/packages/publicize/src/class-publicize-utils.php index bbabb54272a0d..96048880cd8e2 100644 --- a/projects/packages/publicize/src/class-publicize-utils.php +++ b/projects/packages/publicize/src/class-publicize-utils.php @@ -37,9 +37,11 @@ public static function is_jetpack_settings_page() { /** * Whether the block editor should have the social features. * + * @param bool $should_publicize_be_active Whether the Publicize module should be active. + * * @return bool */ - public static function should_block_editor_have_social() { + public static function should_block_editor_have_social( $should_publicize_be_active = true ) { if ( ! is_admin() ) { return false; } @@ -56,6 +58,10 @@ public static function should_block_editor_have_social() { return false; } + if ( $should_publicize_be_active && ! self::is_publicize_active() ) { + return false; + } + $post_type = get_post_type(); if ( empty( $post_type ) || ! post_type_supports( $post_type, 'publicize' ) ) {