Skip to content

Commit

Permalink
Fix the Privacy Policy help notice (#11999)
Browse files Browse the repository at this point in the history
* Display the privacy policy help notice with the `admin_notices` action hook.

The new editor does not support the `edit_form_after_title` action hook. Because WordPress Core uses this hook to output the notice, it is not printed to the screen.

After #11604 is merged, legacy style admin notices (`<div class="notice">...notice content...</div>`) will be consumed by the Notices API and displayed. This change ensures that when #11604 is merged the privacy policy notice will appear again when editing the privacy policy page.

* Use `get_post()` instead of `global $post`.

* Add missing `@since` documentation tag.

* Only display the notice if the function is actually hooked to `edit_form_after_title`.

This prevents the notice from displaying twice if the notice has already been moved to the `admin_notices` hook (as would happen in https://core.trac.wordpress.org/attachment/ticket/45057/45057.diff).
  • Loading branch information
desrosj authored and gziolo committed Nov 19, 2018
1 parent 56b9553 commit c5e146e
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ function gutenberg_wpautop( $content ) {
remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'gutenberg_wpautop', 6 );


/**
* Check if we need to load the block warning in the Classic Editor.
*
Expand Down Expand Up @@ -304,3 +303,22 @@ function gutenberg_warn_classic_about_blocks() {
</script>
<?php
}

/**
* Display the privacy policy help notice.
*
* In Gutenberg, the `edit_form_after_title` hook is not supported. Because
* WordPress Core uses this hook to display this notice, it never displays.
* Outputting the notice on the `admin_notices` hook allows Gutenberg to
* consume the notice and display it with the Notices API.
*
* @since 4.5.0
*/
function gutenberg_show_privacy_policy_help_text() {
if ( is_gutenberg_page() && has_action( 'edit_form_after_title', array( 'WP_Privacy_Policy_Content', 'notice' ) ) ) {
remove_action( 'edit_form_after_title', array( 'WP_Privacy_Policy_Content', 'notice' ) );

WP_Privacy_Policy_Content::notice( get_post() );
}
}
add_action( 'admin_notices', 'gutenberg_show_privacy_policy_help_text' );

0 comments on commit c5e146e

Please sign in to comment.