WordPress.org

Make WordPress Core

Ticket #36819: 36819.4.diff

File 36819.4.diff, 2.7 KB (added by pento, 4 years ago)
  • src/wp-includes/plugin.php

     
    10191019 *
    10201020 * @return array the staticvar from the first time it is set.
    10211021 */
    1022 function _backup_plugin_globals(){
     1022function _backup_plugin_globals() {
    10231023        global $wp_filter, $wp_actions, $merged_filters, $wp_current_filter;
    10241024
    10251025        static $backup_globals = array();
     
    10311031                        'backup_merged_filters'    => $merged_filters,
    10321032                        'backup_wp_current_filter' => $wp_current_filter,
    10331033                );
    1034         };
     1034
     1035                $wp_filter = $wp_actions = array();
     1036        }
    10351037        return $backup_globals;
    10361038}
    10371039
     
    10471049 * @global array $wp_current_filter Stores the list of current filters with the current one last.
    10481050 * @staticvar array $backup_globals Backed up globals.
    10491051 */
    1050 function _restore_plugin_globals(){
     1052function _restore_plugin_globals() {
    10511053        global $wp_filter, $wp_actions, $merged_filters, $wp_current_filter;
    10521054
    10531055        $backup_globals = _backup_plugin_globals();
    10541056
    1055         if ( $wp_filter !== $backup_globals['backup_wp_filter'] ){
    1056                 $wp_filter = array_merge_recursive( $wp_filter, $backup_globals['backup_wp_filter'] );
     1057        if ( empty( $wp_filter ) ) {
     1058                $wp_filter = $backup_globals['backup_wp_filter'];
     1059        } else {
     1060                $added_filters = $wp_filter;
     1061                $wp_filter = $backup_globals['backup_wp_filter'];
     1062
     1063                foreach ( $added_filters as $tag => $callback_groups ) {
     1064                        // Loop through callback groups.
     1065                        foreach ( $callback_groups as $priority => $callbacks ) {
     1066
     1067                                // Loop through callbacks.
     1068                                foreach ( $callbacks as $cb ) {
     1069                                        add_filter( $tag, $cb['function'], $priority, $cb['accepted_args'] );
     1070                                }
     1071                        }
     1072                }
    10571073        }
    10581074
    1059         if ( $wp_actions !== $backup_globals['backup_wp_actions'] ){
    1060                 $wp_actions = array_merge_recursive( $wp_actions, $backup_globals['backup_wp_actions'] );
     1075        if ( empty ( $wp_actions ) ) {
     1076                $wp_actions = $backup_globals['backup_wp_actions'];
     1077        } else {
     1078                $run_actions = $wp_actions;
     1079                $wp_actions = $backup_globals['backup_wp_actions'];
     1080
     1081                foreach( $run_actions as $action => $count ) {
     1082                        if ( ! isset( $wp_actions[ $action ] ) ) {
     1083                                $wp_actions[ $action ] = 0;
     1084                        }
     1085
     1086                        $wp_actions[ $action ] += $count;
     1087                }
    10611088        }
    10621089
    1063         if ( $merged_filters !== $backup_globals['backup_merged_filters'] ){
     1090        if ( $merged_filters !== $backup_globals['backup_merged_filters'] ) {
    10641091                $merged_filters = array_merge_recursive( $merged_filters, $backup_globals['backup_merged_filters'] );
    10651092        }
    10661093
    1067         if ( $wp_current_filter !== $backup_globals['backup_wp_current_filter'] ){
     1094        if ( $wp_current_filter !== $backup_globals['backup_wp_current_filter'] ) {
    10681095                $wp_current_filter = array_merge_recursive( $wp_current_filter, $backup_globals['backup_wp_current_filter'] );
    10691096        }
    10701097}