Make WordPress Core

Ticket #44467: 44467.2.diff

File 44467.2.diff, 20.4 KB (added by spacedmonkey, 7 years ago)
  • src/wp-includes/comment.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    441441 * @return int|bool Meta ID on success, false on failure.
    442442 */
    443443function add_comment_meta( $comment_id, $meta_key, $meta_value, $unique = false ) {
    444         $added = add_metadata( 'comment', $comment_id, $meta_key, $meta_value, $unique );
    445         if ( $added ) {
    446                 wp_cache_set( 'last_changed', microtime(), 'comment' );
    447         }
    448         return $added;
     444        return add_metadata( 'comment', $comment_id, $meta_key, $meta_value, $unique );
    449445}
    450446
    451447/**
     
    464460 * @return bool True on success, false on failure.
    465461 */
    466462function delete_comment_meta( $comment_id, $meta_key, $meta_value = '' ) {
    467         $deleted = delete_metadata( 'comment', $comment_id, $meta_key, $meta_value );
    468         if ( $deleted ) {
    469                 wp_cache_set( 'last_changed', microtime(), 'comment' );
    470         }
    471         return $deleted;
     463        return delete_metadata( 'comment', $comment_id, $meta_key, $meta_value );
    472464}
    473465
    474466/**
     
    505497 * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure.
    506498 */
    507499function update_comment_meta( $comment_id, $meta_key, $meta_value, $prev_value = '' ) {
    508         $updated = update_metadata( 'comment', $comment_id, $meta_key, $meta_value, $prev_value );
    509         if ( $updated ) {
    510                 wp_cache_set( 'last_changed', microtime(), 'comment' );
    511         }
    512         return $updated;
     500        return update_metadata( 'comment', $comment_id, $meta_key, $meta_value, $prev_value );
    513501}
    514502
    515503/**
  • src/wp-includes/default-filters.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    9797
    9898// Meta
    9999add_filter( 'register_meta_args', '_wp_register_meta_args_whitelist', 10, 2 );
     100add_action( 'add_metadata', 'clean_object_last_changed', 10, 2 );
     101add_action( 'update_metadata', 'clean_object_last_changed', 10, 2 );
     102add_action( 'delete_metadata', 'clean_object_last_changed', 10, 2 );
     103
     104add_filter( 'update_term_metadata', '_disable_term_meta', 10, 1 );
     105add_filter( 'add_term_metadata', '_disable_term_meta', 10, 1 );
     106add_filter( 'delete_term_metadata', '_disable_term_meta', 10, 1 );
     107add_filter( 'get_term_metadata', '_disable_term_meta', 10, 1 );
     108add_filter( 'update_term_meta_cache', '_disable_term_meta', 10, 1 );
     109
     110add_filter( 'update_term_metadata', '_check_shared_term_meta', 10, 2 );
     111add_filter( 'add_term_metadata', '_check_shared_term_meta', 10, 2 );
     112add_filter( 'delete_term_metadata', '_check_shared_term_meta', 10, 2 );
     113
    100114
    101115// Places to balance tags on input
    102116foreach ( array( 'content_save_pre', 'excerpt_save_pre', 'comment_save_pre', 'pre_comment_content' ) as $filter ) {
  • src/wp-includes/functions.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    47984798        return (bool) $supported;
    47994799}
    48004800
     4801
     4802/**
     4803 * Determines whether term meta is enabled.
     4804 *
     4805 * @since x.x.x
     4806
     4807 *
     4808 * @return bool True if term meta is supported, false otherwise.
     4809 */
     4810function is_term_meta_supported() {
     4811        return ( get_option( 'db_version' ) < 34370 );
     4812}
     4813
    48014814/**
    48024815 * gmt_offset modification for smart timezone handling.
    48034816 *
  • src/wp-includes/meta.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    131131         */
    132132        do_action( "added_{$meta_type}_meta", $mid, $object_id, $meta_key, $_meta_value );
    133133
     134        /**
     135         * Fires immediately after meta of a specific type is added.
     136         *
     137         *
     138         * @since x.x.x
     139         *
     140         * @param string $meta_type  Type of object metadata is for (e.g., comment, post, or user)
     141         * @param int    $object_id  ID of the object metadata is for
     142         * @param string $meta_key   Metadata key
     143         * @param mixed  $meta_value Metadata value. Must be serializable if non-scalar.
     144         * @param bool   $unique     Optional, default is false.
     145         *                           Whether the specified metadata key should be unique for the object.
     146         *                           If true, and the object already has a value for the specified metadata key,
     147         *                           no change will be made.
     148         */
     149        do_action( "add_metadata", $meta_type, $object_id, $meta_key, $meta_value, $unique );
     150
    134151        return $mid;
    135152}
    136153
     
    299316                }
    300317        }
    301318
     319        /**
     320         * Fires immediately after updating metadata of a specific type.
     321         *
     322         * @since x.x.x
     323         *
     324         * @param string $meta_type  Type of object metadata is for (e.g., comment, post, or user)
     325         * @param int    $object_id  ID of the object metadata is for
     326         * @param string $meta_key   Metadata key
     327         * @param mixed  $meta_value Metadata value. Must be serializable if non-scalar.
     328         */
     329        do_action( "update_metadata", $meta_type, $object_id, $meta_key, $_meta_value );
     330
    302331        return true;
    303332}
    304333
     
    463492                do_action( 'deleted_postmeta', $meta_ids );
    464493        }
    465494
     495        /**
     496         * Fires immediately after deleting metadata of a specific type.
     497         *
     498         * @since x.x.x
     499         *
     500         * @param string $meta_type  Type of object metadata is for (e.g., comment, post, or user)
     501         * @param int    $object_id  ID of the object metadata is for
     502         * @param string $meta_key   Metadata key
     503         * @param mixed  $meta_value Optional. Metadata value. Must be serializable if non-scalar. If specified, only delete
     504         *                           metadata entries with this value. Otherwise, delete all entries with the specified meta_key.
     505         *                           Pass `null`, `false`, or an empty string to skip this check. (For backward compatibility,
     506         *                           it is not possible to pass an empty string to delete those entries with an empty string
     507         *                           for a value.)
     508         * @param bool   $delete_all Optional, default is false. If true, delete matching metadata entries for all objects,
     509         *                           ignoring the specified object_id. Otherwise, only delete matching metadata entries for
     510         *                           the specified object_id.
     511         */
     512        do_action( "delete_metadata", $meta_type, $object_id, $meta_key, $meta_value, $delete_all );
     513
    466514        return true;
    467515}
    468516
     
    707755                /** This action is documented in wp-includes/meta.php */
    708756                do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value );
    709757
     758                /** This action is documented in wp-includes/meta.php */
     759                do_action( "update_metadata", $meta_type, $object_id, $meta_key, $_meta_value );
     760
    710761                if ( 'post' == $meta_type ) {
    711762                        /** This action is documented in wp-includes/meta.php */
    712763                        do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value );
     
    783834                /** This action is documented in wp-includes/meta.php */
    784835                do_action( "deleted_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value );
    785836
     837                /** This action is documented in wp-includes/meta.php */
     838                do_action( "delete_metadata", $meta_type, $object_id, $meta->meta_key, $meta->meta_value , false );
     839
    786840                // Old-style action.
    787841                if ( 'post' == $meta_type || 'comment' == $meta_type ) {
    788842                        /**
     
    841895        $cache_key = $meta_type . '_meta';
    842896        $ids       = array();
    843897        $cache     = array();
    844         foreach ( $object_ids as $id ) {
    845                 $cached_object = wp_cache_get( $id, $cache_key );
     898        foreach ( $object_ids as $object_id ) {
     899                /**
     900                 * Filters whether to update metadata cache of a specific type.
     901                 *
     902                 * @since x.x.x
     903                 *
     904                 * @param null|bool $check      Whether to allow updating metadata cache for the given type.
     905                 * @param int       $object_id  Object ID.
     906                 **/
     907                $check = apply_filters( "update_{$meta_type}_meta_cache", null, $object_id );
     908                if ( null !== $check ) {
     909                        return (bool) $check;
     910                }
     911
     912                $cached_object = wp_cache_get( $object_id, $cache_key );
    846913                if ( false === $cached_object ) {
    847                         $ids[] = $id;
     914                        $ids[] = $object_id;
    848915                } else {
    849                         $cache[ $id ] = $cached_object;
     916                        $cache[ $object_id ] = $cached_object;
    850917                }
    851918        }
    852919
     
    13601427         */
    13611428        return apply_filters( "get_object_subtype_{$object_type}", $object_subtype, $object_id );
    13621429}
     1430
     1431
     1432/**
     1433 *
     1434 * @since x.x.x
     1435 *
     1436 * @param  string $meta_type   Type of object metadata is for (e.g., comment, post, or user)
     1437 * @param  int    $object_id   ID of the object.
     1438 * @return bool
     1439 */
     1440function clean_object_last_changed( $meta_type, $object_id = 0 ) {
     1441        switch ( $meta_type ) {
     1442                case 'blog':
     1443                        $group = 'sites';
     1444                        break;
     1445                case 'user':
     1446                        $group = 'users';
     1447                        break;
     1448                case 'term':
     1449                        $group = 'terms';
     1450                        break;
     1451                case 'comment':
     1452                        $group = 'comment';
     1453                        break;
     1454                case 'post':
     1455                        $group = 'posts';
     1456                        break;
     1457                default:
     1458                        $group = false;
     1459                        break;
     1460        }
     1461
     1462        /**
     1463         *
     1464         * @since x.x.x
     1465         *
     1466         * @param string $group      Group string to override.
     1467         * @param string $meta_type  Type of object metadata is for (e.g., comment, post, or user)
     1468         * @param int    $object_id  ID of the object to get the subtype for.
     1469         */
     1470        $group = apply_filters( "get_object_cache_group", $group, $meta_type, $object_id );
     1471
     1472        if ( ! $group ) {
     1473                return false;
     1474        }
     1475
     1476        return wp_cache_set( 'last_changed', microtime(), $group );
     1477}
     1478 No newline at end of file
  • src/wp-includes/ms-blogs.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    618618 * @return array|false Returns false if there is nothing to update. Returns an array of metadata on success.
    619619 */
    620620function update_sitemeta_cache( $site_ids ) {
     621        return update_meta_cache( 'blog', $site_ids );
     622}
     623
     624/**
     625 * @param $value
     626 *
     627 * @return mixed
     628 */
     629function _disable_site_meta( $value ) {
    621630        if ( ! is_site_meta_supported() ) {
    622631                return false;
    623632        }
    624633
    625         return update_meta_cache( 'blog', $site_ids );
     634        return $value;
    626635}
    627636
    628637/**
     
    838847 * @return int|false Meta ID on success, false on failure.
    839848 */
    840849function add_site_meta( $site_id, $meta_key, $meta_value, $unique = false ) {
    841         // Bail if site meta table is not installed.
    842         if ( ! is_site_meta_supported() ) {
    843                 /* translators: %s: database table name */
    844                 _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' );
    845                 return false;
    846         }
    847 
    848         $added = add_metadata( 'blog', $site_id, $meta_key, $meta_value, $unique );
    849 
    850         // Bust site query cache.
    851         if ( $added ) {
    852                 wp_cache_set( 'last_changed', microtime(), 'sites' );
    853         }
    854 
    855         return $added;
     850        return add_metadata( 'blog', $site_id, $meta_key, $meta_value, $unique );
    856851}
    857852
    858853/**
     
    871866 * @return bool True on success, false on failure.
    872867 */
    873868function delete_site_meta( $site_id, $meta_key, $meta_value = '' ) {
    874         // Bail if site meta table is not installed.
    875         if ( ! is_site_meta_supported() ) {
    876                 /* translators: %s: database table name */
    877                 _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' );
    878                 return false;
    879         }
    880 
    881         $deleted = delete_metadata( 'blog', $site_id, $meta_key, $meta_value );
    882 
    883         // Bust site query cache.
    884         if ( $deleted ) {
    885                 wp_cache_set( 'last_changed', microtime(), 'sites' );
    886         }
    887 
    888         return $deleted;
     869        return delete_metadata( 'blog', $site_id, $meta_key, $meta_value );
    889870}
    890871
    891872/**
     
    901882 *               field if $single is true.
    902883 */
    903884function get_site_meta( $site_id, $key = '', $single = false ) {
    904         // Bail if site meta table is not installed.
    905         if ( ! is_site_meta_supported() ) {
    906                 /* translators: %s: database table name */
    907                 _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' );
    908                 return false;
    909         }
    910 
    911885        return get_metadata( 'blog', $site_id, $key, $single );
    912886}
    913887
     
    930904 *                  false on failure.
    931905 */
    932906function update_site_meta( $site_id, $meta_key, $meta_value, $prev_value = '' ) {
    933         // Bail if site meta table is not installed.
    934         if ( ! is_site_meta_supported() ) {
    935                 /* translators: %s: database table name */
    936                 _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' );
    937                 return false;
    938         }
    939 
    940         $updated = update_metadata( 'blog', $site_id, $meta_key, $meta_value, $prev_value );
    941 
    942         // Bust site query cache.
    943         if ( $updated ) {
    944                 wp_cache_set( 'last_changed', microtime(), 'sites' );
    945         }
    946 
    947         return $updated;
     907        return update_metadata( 'blog', $site_id, $meta_key, $meta_value, $prev_value );
    948908}
    949909
    950910/**
     
    956916 * @return bool Whether the site meta key was deleted from the database.
    957917 */
    958918function delete_site_meta_by_key( $meta_key ) {
    959         // Bail if site meta table is not installed.
    960         if ( ! is_site_meta_supported() ) {
    961                 /* translators: %s: database table name */
    962                 _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' );
    963                 return false;
    964         }
    965 
    966         $deleted = delete_metadata( 'blog', null, $meta_key, '', true );
    967 
    968         // Bust site query cache.
    969         if ( $deleted ) {
    970                 wp_cache_set( 'last_changed', microtime(), 'sites' );
    971         }
    972 
    973         return $deleted;
     919        return delete_metadata( 'blog', null, $meta_key, '', true );
    974920}
    975921
    976922/**
  • src/wp-includes/ms-default-filters.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    4242add_action( 'wpmu_activate_blog', 'wpmu_welcome_notification', 10, 5 );
    4343add_action( 'after_signup_site', 'wpmu_signup_blog_notification', 10, 7 );
    4444
     45// Meta
     46add_filter( 'update_blog_metadata', '_disable_site_meta', 10, 1 );
     47add_filter( 'add_blog_metadata', '_disable_site_meta', 10, 1 );
     48add_filter( 'delete_blog_metadata', '_disable_site_meta', 10, 1 );
     49add_filter( 'get_blog_metadata', '_disable_site_meta', 10, 1 );
     50add_filter( 'update_blog_meta_cache', '_disable_site_meta', 10, 1 );
     51
    4552// Register Nonce
    4653add_action( 'signup_hidden_fields', 'signup_nonce_fields' );
    4754
  • src/wp-includes/post.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    19171917                $post_id = $the_post;
    19181918        }
    19191919
    1920         $deleted = delete_metadata( 'post', $post_id, $meta_key, $meta_value );
    1921         if ( $deleted ) {
    1922                 wp_cache_set( 'last_changed', microtime(), 'posts' );
    1923         }
    1924         return $deleted;
     1920        return delete_metadata( 'post', $post_id, $meta_key, $meta_value );
    19251921}
    19261922
    19271923/**
     
    19661962                $post_id = $the_post;
    19671963        }
    19681964
    1969         $updated = update_metadata( 'post', $post_id, $meta_key, $meta_value, $prev_value );
    1970         if ( $updated ) {
    1971                 wp_cache_set( 'last_changed', microtime(), 'posts' );
    1972         }
    1973         return $updated;
     1965        return update_metadata( 'post', $post_id, $meta_key, $meta_value, $prev_value );
    19741966}
    19751967
    19761968/**
     
    19821974 * @return bool Whether the post meta key was deleted from the database.
    19831975 */
    19841976function delete_post_meta_by_key( $post_meta_key ) {
    1985         $deleted = delete_metadata( 'post', null, $post_meta_key, '', true );
    1986         if ( $deleted ) {
    1987                 wp_cache_set( 'last_changed', microtime(), 'posts' );
    1988         }
    1989         return $deleted;
     1977        return delete_metadata( 'post', null, $post_meta_key, '', true );
    19901978}
    19911979
    19921980/**
  • src/wp-includes/taxonomy.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    11801180 *                           False on failure.
    11811181 */
    11821182function add_term_meta( $term_id, $meta_key, $meta_value, $unique = false ) {
    1183         // Bail if term meta table is not installed.
    1184         if ( get_option( 'db_version' ) < 34370 ) {
    1185                 return false;
    1186         }
    1187 
    1188         if ( wp_term_is_shared( $term_id ) ) {
    1189                 return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.' ), $term_id );
    1190         }
    1191 
    1192         $added = add_metadata( 'term', $term_id, $meta_key, $meta_value, $unique );
    1193 
    1194         // Bust term query cache.
    1195         if ( $added ) {
    1196                 wp_cache_set( 'last_changed', microtime(), 'terms' );
    1197         }
    1198 
    1199         return $added;
     1183        return add_metadata( 'term', $term_id, $meta_key, $meta_value, $unique );
    12001184}
    12011185
    12021186/**
     
    12101194 * @return bool True on success, false on failure.
    12111195 */
    12121196function delete_term_meta( $term_id, $meta_key, $meta_value = '' ) {
    1213         // Bail if term meta table is not installed.
    1214         if ( get_option( 'db_version' ) < 34370 ) {
    1215                 return false;
    1216         }
    1217 
    1218         $deleted = delete_metadata( 'term', $term_id, $meta_key, $meta_value );
    1219 
    1220         // Bust term query cache.
    1221         if ( $deleted ) {
    1222                 wp_cache_set( 'last_changed', microtime(), 'terms' );
    1223         }
    1224 
    1225         return $deleted;
     1197        return delete_metadata( 'term', $term_id, $meta_key, $meta_value );
    12261198}
    12271199
    12281200/**
     
    12371209 * @return mixed If `$single` is false, an array of metadata values. If `$single` is true, a single metadata value.
    12381210 */
    12391211function get_term_meta( $term_id, $key = '', $single = false ) {
    1240         // Bail if term meta table is not installed.
    1241         if ( get_option( 'db_version' ) < 34370 ) {
    1242                 return false;
    1243         }
    1244 
    12451212        return get_metadata( 'term', $term_id, $key, $single );
    12461213}
    12471214
     
    12621229 *                           WP_Error when term_id is ambiguous between taxonomies. False on failure.
    12631230 */
    12641231function update_term_meta( $term_id, $meta_key, $meta_value, $prev_value = '' ) {
    1265         // Bail if term meta table is not installed.
    1266         if ( get_option( 'db_version' ) < 34370 ) {
    1267                 return false;
    1268         }
    1269 
    1270         if ( wp_term_is_shared( $term_id ) ) {
    1271                 return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.' ), $term_id );
    1272         }
    1273 
    1274         $updated = update_metadata( 'term', $term_id, $meta_key, $meta_value, $prev_value );
    1275 
    1276         // Bust term query cache.
    1277         if ( $updated ) {
    1278                 wp_cache_set( 'last_changed', microtime(), 'terms' );
    1279         }
    1280 
    1281         return $updated;
     1232        return update_metadata( 'term', $term_id, $meta_key, $meta_value, $prev_value );
    12821233}
    12831234
    12841235/**
     
    12931244 * @return array|false Returns false if there is nothing to update. Returns an array of metadata on success.
    12941245 */
    12951246function update_termmeta_cache( $term_ids ) {
    1296         // Bail if term meta table is not installed.
    1297         if ( get_option( 'db_version' ) < 34370 ) {
    1298                 return;
    1299         }
    1300 
    13011247        return update_meta_cache( 'term', $term_ids );
    13021248}
    13031249
     
    13131259 */
    13141260function has_term_meta( $term_id ) {
    13151261        // Bail if term meta table is not installed.
    1316         if ( get_option( 'db_version' ) < 34370 ) {
     1262        if ( ! is_term_meta_supported() ) {
    13171263                return false;
    13181264        }
    13191265
     
    13551301        return unregister_meta_key( 'term', $meta_key, $taxonomy );
    13561302}
    13571303
     1304/**
     1305 * @param $value
     1306 *
     1307 * @return mixed
     1308 */
     1309function _disable_term_meta( $value ) {
     1310        if ( ! is_term_meta_supported() ) {
     1311                return false;
     1312        }
     1313
     1314        return $value;
     1315}
     1316
     1317/**
     1318 * @param $value
     1319 * @param $term_id
     1320 *
     1321 * @return mixed
     1322 */
     1323function _check_shared_term_meta( $value, $term_id ) {
     1324        if ( wp_term_is_shared( $term_id ) ) {
     1325                return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.' ), $term_id );
     1326        }
     1327
     1328        return $value;
     1329}
     1330
    13581331/**
    13591332 * Determines whether a term exists.
    13601333 *
  • src/wp-includes/user.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    13571357        wp_cache_delete( $user->user_email, 'useremail' );
    13581358        wp_cache_delete( $user->user_nicename, 'userslugs' );
    13591359
     1360        wp_cache_set( 'last_changed', microtime(), 'users' );
     1361
    13601362        /**
    13611363         * Fires immediately after the given user's cache is cleaned.
    13621364         *