Skip to content

Conversation

@creativecoder
Copy link
Contributor

Changes proposed in this Pull Request:

Modifies the filter added in #27778 to differentiate it from the jetpack_are_blogging_prompts_enabled setting.

With this change, the writing prompt loading logic now looks like this

  • If the jetpack_blogging_prompts_hidden filter is true
    • The wp-admin settings and placeholder prompt are not loaded.
  • If the filter is false (the default)
    • Thejetpack_are_blogging_prompts_enabled setting field loads in wp-admin
    • If the setting is true, show the placeholder prompt in the editor
    • If the setting is false, no placeholder prompt is shown in the editor
  • If the answer_prompt query param is set when loading the editor, it bypasses the filter and setting, allowing answering a prompt from an external link (email, notifications, etc)

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?

Jetpack product discussion

See previous PRs (e.g. #26680, #27746, and #27778)

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

No.

Testing instructions:

  • Set up your site to display blogging prompts, by setting posts to show in the front page, or enabling the setting from Settings > Writing
  • Verify you can see the placeholder prompts when starting a new post
  • Add the following code (such as an mu-plugin) to disable the prompts and setting
  • Verify the placeholder prompt and setting no longer show
add_filter( 'jetpack_blogging_prompts_hidden', '__return_true' );

@creativecoder creativecoder added [Status] Needs Review This PR is ready for review. [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Block] Writing Prompts labels Dec 6, 2022
@creativecoder creativecoder self-assigned this Dec 6, 2022
@creativecoder creativecoder requested a review from jeherve December 6, 2022 18:51
@github-actions
Copy link
Contributor

github-actions bot commented Dec 6, 2022

Are you an Automattician? You can now test your Pull Request on WordPress.com. On your sandbox, run bin/jetpack-downloader test jetpack update/blogging-prompts-enabled-filter to get started. More details: p9dueE-5Nn-p2

@github-actions
Copy link
Contributor

github-actions bot commented Dec 6, 2022

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.
  • ✅ All commits were linted before commit.
  • 🔴 Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ 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.


Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team review" label and ask someone from your team review the code.
Once you’ve done so, switch to the "[Status] Needs Review" label; someone from Jetpack Crew will then review this PR and merge it to be included in the next Jetpack release.


Jetpack plugin:

  • Next scheduled release: January 3, 2023.
  • Scheduled code freeze: December 26, 2022.

Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

That should work. I had an idea on simplifying things a bit, let me know what you think about it:

diff --git a/projects/plugins/jetpack/_inc/blogging-prompts.php b/projects/plugins/jetpack/_inc/blogging-prompts.php
index c49a5bd3bc..588b99c19c 100644
--- a/projects/plugins/jetpack/_inc/blogging-prompts.php
+++ b/projects/plugins/jetpack/_inc/blogging-prompts.php
@@ -57,7 +57,16 @@ add_action( 'wp_insert_post', 'jetpack_setup_blogging_prompt_response' );
  * @return boolean
  */
 function jetpack_are_blogging_prompts_enabled() {
-	return (bool) get_option( 'jetpack_blogging_prompts_enabled', jetpack_has_write_intent() || jetpack_has_posts_page() );
+	$prompts_enabled = (bool) get_option( 'jetpack_blogging_prompts_enabled', jetpack_has_write_intent() || jetpack_has_posts_page() );
+
+	/**
+	 * Filters whether blogging prompts are enabled.
+	 *
+	 * @since $$next-version$$
+	 *
+	 * @param bool $prompts_enabled Whether blogging prompts are enabled.
+	 */
+	return apply_filters( 'jetpack_are_blogging_prompts_enabled', $prompts_enabled );
 }
 
 /**
diff --git a/projects/plugins/jetpack/extensions/blocks/blogging-prompts/blogging-prompts.php b/projects/plugins/jetpack/extensions/blocks/blogging-prompts/blogging-prompts.php
index 4b1a98d86f..34603f832c 100644
--- a/projects/plugins/jetpack/extensions/blocks/blogging-prompts/blogging-prompts.php
+++ b/projects/plugins/jetpack/extensions/blocks/blogging-prompts/blogging-prompts.php
@@ -18,42 +18,34 @@ const BLOCK_NAME   = 'jetpack/' . FEATURE_NAME;
 /**
  * Registers the blogging prompt integration for the block editor.
  */
-function register_extension() {
-	Blocks::jetpack_register_block( BLOCK_NAME );
-
-	// Load the blogging-prompts endpoint here on init so its route will be registered.
-	// We can use it with `WPCOM_API_Direct::do_request` to avoid a network request on Simple Sites.
-	if ( defined( 'IS_WPCOM' ) && IS_WPCOM && should_load_blogging_prompts() ) {
-		wpcom_rest_api_v2_load_plugin_files( 'wp-content/rest-api-plugins/endpoints/blogging-prompts.php' );
-	}
-}
-
-/**
- * Adds the blogging prompt settings to wp-admin, if appropriate.
- *
- * @return void
- */
-function load_settings() {
+function register_extension_and_settings() {
 	// If editor extensions are not loaded, don't show the settings.
 	if ( ! \Jetpack_Gutenberg::should_load() ) {
 		return;
 	}
 
-	// Blogging prompts is an expermental extension: if expermental blocks are not enabled, don't show the settings.
+	// Blogging prompts is an expermental extension: if experimental blocks are not enabled, don't show the settings.
 	if ( ! Constants::is_true( 'JETPACK_EXPERIMENTAL_BLOCKS' ) && ! Constants::is_true( 'JETPACK_BETA_BLOCKS' ) ) {
 		return;
 	}
 
-	/**
-	 * Filter to hide the blogging prompts settings.
-	 *
-	 * @since $$next-version$$
-	 * @param bool $is_hidden Should the blogging prompts be hidden. Defaults to false.
+	/*
+	 * Do not register the block and settings if the site opted out
+	 * (either via a filter, or because it is not a blogging site)
 	 */
-	if ( apply_filters( 'jetpack_blogging_prompts_hidden', false ) ) {
+	if ( ! should_load_blogging_prompts() ) {
 		return;
 	}
 
+	Blocks::jetpack_register_block( BLOCK_NAME );
+
+	// Load the blogging-prompts endpoint here on init so its route will be registered.
+	// We can use it with `WPCOM_API_Direct::do_request` to avoid a network request on Simple Sites.
+	if ( defined( 'IS_WPCOM' ) && IS_WPCOM && should_load_blogging_prompts() ) {
+		wpcom_rest_api_v2_load_plugin_files( 'wp-content/rest-api-plugins/endpoints/blogging-prompts.php' );
+	}
+
+	// Add the blogging prompt settings to wp-admin.
 	require_once __DIR__ . '/settings.php';
 }
 
@@ -71,17 +63,18 @@ function inject_blogging_prompts() {
 		return;
 	}
 
-	// And only for blogging sites or those explicitly responding to the prompt.
-	if ( should_load_blogging_prompts() ) {
-		$daily_prompts = jetpack_get_daily_blogging_prompts();
+	// Or if the blogging prompts are not enabled.
+	if ( ! should_load_blogging_prompts() ) {
+		return;
+	}
 
-		if ( $daily_prompts ) {
-			wp_add_inline_script(
-				'jetpack-blocks-editor',
-				'var Jetpack_BloggingPrompts = ' . wp_json_encode( $daily_prompts, JSON_HEX_TAG | JSON_HEX_AMP ) . ';',
-				'before'
-			);
-		}
+	$daily_prompts = jetpack_get_daily_blogging_prompts();
+	if ( $daily_prompts ) {
+		wp_add_inline_script(
+			'jetpack-blocks-editor',
+			'var Jetpack_BloggingPrompts = ' . wp_json_encode( $daily_prompts, JSON_HEX_TAG | JSON_HEX_AMP ) . ';',
+			'before'
+		);
 	}
 }
 
@@ -91,11 +84,9 @@ function inject_blogging_prompts() {
  * @return bool
  */
 function should_load_blogging_prompts() {
-	$show_placeholder_prompt = ! apply_filters( 'jetpack_blogging_prompts_hidden', false ) && jetpack_are_blogging_prompts_enabled();
 	 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Clicking a prompt response link can happen from notifications, Calypso, wp-admin, email, etc and only sets up a response post (tag, meta, prompt text); the user must take action to actually publish the post.
-	return $show_placeholder_prompt || ( isset( $_GET['answer_prompt'] ) && absint( $_GET['answer_prompt'] ) );
+	return jetpack_are_blogging_prompts_enabled() || ( isset( $_GET['answer_prompt'] ) && absint( $_GET['answer_prompt'] ) );
 }
 
-add_action( 'init', __NAMESPACE__ . '\register_extension' );
-add_action( 'init', __NAMESPACE__ . '\load_settings' );
+add_action( 'init', __NAMESPACE__ . '\register_extension_and_settings' );
 add_action( 'enqueue_block_assets', __NAMESPACE__ . '\inject_blogging_prompts' );

@jeherve jeherve added [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it and removed [Status] Needs Review This PR is ready for review. labels Dec 7, 2022
@coder-karen coder-karen added this to the Jetpack 11.7 milestone Dec 9, 2022
@coder-karen coder-karen modified the milestones: Jetpack 11.7, Jetpack 11.8 Jan 4, 2023
@roo2
Copy link
Contributor

roo2 commented Jan 19, 2023

Is this PR obsolete now that the setting is removed in #28387?

@creativecoder
Copy link
Contributor Author

Yes, thanks--meant to close this.

@github-actions github-actions bot removed the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Blogging Prompts [Block] Writing Prompts [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants