Make WordPress Core

Changeset 43361


Ignore:
Timestamp:
06/16/2018 01:01:42 PM (8 years ago)
Author:
SergeyBiryukov
Message:

Privacy: Make sure wp_add_privacy_policy_content() does not cause a fatal error by unintentionally flushing rewrite rules outside of the admin context.

Add a _doing_it_wrong() message describing the correct usage of the function.

Props kraftbj, azaozz, SergeyBiryukov, YuriV.
Fixes #44142.

Location:
trunk/src/wp-admin/includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/misc.php

    r43350 r43361  
    205205        global $wp_rewrite;
    206206
     207        // Ensure get_home_path is declared.
     208        require_once( ABSPATH . 'wp-admin/includes/file.php' );
     209
    207210        $home_path     = get_home_path();
    208211        $htaccess_file = $home_path . '.htaccess';
     
    238241
    239242        global $wp_rewrite;
     243
     244        // Ensure get_home_path is declared.
     245        require_once( ABSPATH . 'wp-admin/includes/file.php' );
    240246
    241247        $home_path       = get_home_path();
  • trunk/src/wp-admin/includes/plugin.php

    r43003 r43361  
    20172017
    20182018/**
    2019  * Helper function for adding content to the postbox shown when editing the privacy policy.
     2019 * Helper function for adding content to the Privacy Policy Guide.
    20202020 *
    20212021 * Plugins and themes should suggest text for inclusion in the site's privacy policy.
    20222022 * The suggested text should contain information about any functionality that affects user privacy,
    2023  * and will be shown in the Suggested Privacy Policy Content postbox.
     2023 * and will be shown on the Privacy Policy Guide screen.
    20242024 *
    20252025 * A plugin or theme can use this function multiple times as long as it will help to better present
    20262026 * the suggested policy content. For example modular plugins such as WooCommerse or Jetpack
    20272027 * can add or remove suggested content depending on the modules/extensions that are enabled.
     2028 * For more information see the Plugin Handbook:
     2029 * https://developer.wordpress.org/plugins/privacy/suggesting-text-for-the-site-privacy-policy/.
    20282030 *
    20292031 * Intended for use with the `'admin_init'` action.
     
    20332035 * @param string $plugin_name The name of the plugin or theme that is suggesting content for the site's privacy policy.
    20342036 * @param string $policy_text The suggested content for inclusion in the policy.
    2035  *                            For more information see the Plugins Handbook https://developer.wordpress.org/plugins/.
    20362037 */
    20372038function wp_add_privacy_policy_content( $plugin_name, $policy_text ) {
     2039        if ( ! is_admin() ) {
     2040                _doing_it_wrong(
     2041                        __FUNCTION__,
     2042                        sprintf(
     2043                                /* translators: %s: admin_init */
     2044                                __( 'The suggested privacy policy content should be added only in wp-admin by using the %s (or later) action.' ),
     2045                                '<code>admin_init</code>'
     2046                        ),
     2047                        '4.9.7'
     2048                );
     2049                return;
     2050        } elseif ( ! doing_action( 'admin_init' ) && ! did_action( 'admin_init' ) ) {
     2051                _doing_it_wrong(
     2052                        __FUNCTION__,
     2053                        sprintf(
     2054                                /* translators: %s: admin_init */
     2055                                __( 'The suggested privacy policy content should be added by using the %s (or later) action. Please see the inline documentation.' ),
     2056                                '<code>admin_init</code>'
     2057                        ),
     2058                        '4.9.7'
     2059                );
     2060                return;
     2061        }
     2062
    20382063        if ( ! class_exists( 'WP_Privacy_Policy_Content' ) ) {
    20392064                require_once( ABSPATH . 'wp-admin/includes/misc.php' );
Note: See TracChangeset for help on using the changeset viewer.