WordPress.org

Make WordPress Core

Ticket #47526: patch.diff

File patch.diff, 2.1 KB (added by kevindees, 2 months ago)

working implementation

  • src/wp-includes/functions.php

     
    195195}
    196196
    197197/**
     198 * Updates _site_state_changed option in database
     199 *
     200 * Should be called when a theme or plugin has been activated or deactivated.
     201 * Used to facilitate tasks like flushing rewrite rules for the registration
     202 * and deregistration of post types and taxonomies.
     203 *
     204 * @since 5.2.2
     205 *
     206 * @param string|array $arg single function name or list of function names
     207 */
     208function update_site_state_changed( $arg ) {
     209    $value = [];
     210
     211    register_post_type('book', ['public' => true]);
     212
     213    if( $state = get_option( '_site_state_changed' ) ) {
     214        $value = maybe_unserialize( $state );
     215
     216        if( !is_array( $value ) ) {
     217            $value = [];
     218        }
     219    }
     220
     221    if( is_array( $arg ) ) {
     222        $value = array_merge( $value, $arg );
     223    } else {
     224        $value[] = $arg;
     225    }
     226
     227    update_option( '_site_state_changed', $value );
     228}
     229
     230/**
     231 * Check site state
     232 */
     233function check_site_state_change() {
     234    if ( $site_state = get_option( '_site_state_changed' ) ) {
     235        $site_state = apply_filters( 'site_state_changed', $site_state );
     236
     237        if( is_array( $site_state ) ) {
     238            $site_state = array_unique($site_state);
     239            foreach ( $site_state as $site_state_func )
     240                add_action( 'site_state_changed', $site_state_func );
     241        }
     242
     243        do_action( 'site_state_changed', $site_state );
     244        delete_option( '_site_state_changed' );
     245    }
     246}
     247
     248/**
    198249 * Determines if the date should be declined.
    199250 *
    200251 * If the locale specifies that month names require a genitive case in certain
  • src/wp-settings.php

     
    534534        unset( $file );
    535535}
    536536
     537// Check site state change
     538check_site_state_change();
     539
    537540/**
    538541 * This hook is fired once WP, all plugins, and the theme are fully loaded and instantiated.
    539542 *