Make WordPress Core

Ticket #44467: 44467.diff

File 44467.diff, 19.2 KB (added by flixos90, 6 years ago)
  • src/wp-includes/comment.php

     
    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/**
     
    35023490                'done'           => $done,
    35033491        );
    35043492}
     3493
     3494/**
     3495 * Sets the last changed time for the 'comment' cache group.
     3496 *
     3497 * @since 5.0.0
     3498 */
     3499function wp_cache_set_comments_last_changed() {
     3500        wp_cache_set( 'last_changed', microtime(), 'comment' );
     3501}
  • src/wp-includes/default-filters.php

     
    9898// Meta
    9999add_filter( 'register_meta_args', '_wp_register_meta_args_whitelist', 10, 2 );
    100100
     101// Post meta
     102add_action( 'added_post_meta', 'wp_cache_set_posts_last_changed' );
     103add_action( 'updated_post_meta', 'wp_cache_set_posts_last_changed' );
     104add_action( 'deleted_post_meta', 'wp_cache_set_posts_last_changed' );
     105
     106// Term meta
     107add_action( 'added_term_meta', 'wp_cache_set_terms_last_changed' );
     108add_action( 'updated_term_meta', 'wp_cache_set_terms_last_changed' );
     109add_action( 'deleted_term_meta', 'wp_cache_set_terms_last_changed' );
     110add_filter( 'get_term_metadata', 'wp_check_term_meta_support_prefilter' );
     111add_filter( 'add_term_metadata', 'wp_check_term_meta_support_prefilter' );
     112add_filter( 'update_term_metadata', 'wp_check_term_meta_support_prefilter' );
     113add_filter( 'delete_term_metadata', 'wp_check_term_meta_support_prefilter' );
     114add_filter( 'get_term_metadata_by_mid', 'wp_check_term_meta_support_prefilter' );
     115add_filter( 'update_term_metadata_by_mid', 'wp_check_term_meta_support_prefilter' );
     116add_filter( 'delete_term_metadata_by_mid', 'wp_check_term_meta_support_prefilter' );
     117add_filter( 'update_term_metadata_cache', 'wp_check_term_meta_support_prefilter' );
     118
     119// Comment meta
     120add_action( 'added_comment_meta', 'wp_cache_set_comments_last_changed' );
     121add_action( 'updated_comment_meta', 'wp_cache_set_comments_last_changed' );
     122add_action( 'deleted_comment_meta', 'wp_cache_set_comments_last_changed' );
     123
    101124// Places to balance tags on input
    102125foreach ( array( 'content_save_pre', 'excerpt_save_pre', 'comment_save_pre', 'pre_comment_content' ) as $filter ) {
    103126        add_filter( $filter, 'convert_invalid_entities' );
  • src/wp-includes/meta.php

     
    610610
    611611        $id_column = ( 'user' == $meta_type ) ? 'umeta_id' : 'meta_id';
    612612
     613        /**
     614         * Filters whether to retrieve metadata of a specific type by meta ID.
     615         *
     616         * The dynamic portion of the hook, `$meta_type`, refers to the meta
     617         * object type (comment, post, term, or user). Returning a non-null value
     618         * will effectively short-circuit the function.
     619         *
     620         * @since 5.0.0
     621         *
     622         * @param mixed  $value    The value get_metadata_by_mid() should return.
     623         * @param int    $meta_id  Meta ID.
     624         * @param string $meta_key Meta key.
     625         */
     626        $check = apply_filters( "get_{$meta_type}_metadata_by_mid", null, $meta_id, $meta_key );
     627        if ( null !== $check ) {
     628                return $check;
     629        }
     630
    613631        $meta = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table WHERE $id_column = %d", $meta_id ) );
    614632
    615633        if ( empty( $meta ) ) {
     
    657675        $column    = sanitize_key( $meta_type . '_id' );
    658676        $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id';
    659677
     678        /**
     679         * Filters whether to update metadata of a specific type by meta ID.
     680         *
     681         * The dynamic portion of the hook, `$meta_type`, refers to the meta
     682         * object type (comment, post, term, or user). Returning a non-null value
     683         * will effectively short-circuit the function.
     684         *
     685         * @since 5.0.0
     686         *
     687         * @param null|bool $check      Whether to allow updating metadata for the given type.
     688         * @param int       $meta_id    Meta ID.
     689         * @param mixed     $meta_value Meta value. Must be serializable if non-scalar.
     690         * @param string    $meta_key   Meta key, if provided.
     691         */
     692        $check = apply_filters( "update_{$meta_type}_metadata_by_mid", null, $meta_id, $meta_value, $meta_key );
     693        if ( null !== $check ) {
     694                return (bool) $check;
     695        }
     696
    660697        // Fetch the meta and go on if it's found.
    661698        if ( $meta = get_metadata_by_mid( $meta_type, $meta_id ) ) {
    662699                $original_key = $meta->meta_key;
     
    752789        $column    = sanitize_key( $meta_type . '_id' );
    753790        $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id';
    754791
     792        /**
     793         * Filters whether to delete metadata of a specific type by meta ID.
     794         *
     795         * The dynamic portion of the hook, `$meta_type`, refers to the meta
     796         * object type (comment, post, term, or user). Returning a non-null value
     797         * will effectively short-circuit the function.
     798         *
     799         * @since 5.0.0
     800         *
     801         * @param null|bool $delete  Whether to allow metadata deletion of the given type.
     802         * @param int       $meta_id Meta ID.
     803         */
     804        $check = apply_filters( "delete_{$meta_type}_metadata_by_mid", null, $meta_id );
     805        if ( null !== $check ) {
     806                return (bool) $check;
     807        }
     808
    755809        // Fetch the meta and go on if it's found.
    756810        if ( $meta = get_metadata_by_mid( $meta_type, $meta_id ) ) {
    757811                $object_id = $meta->{$column};
     
    838892
    839893        $object_ids = array_map( 'intval', $object_ids );
    840894
     895        /**
     896         * Filters whether to update the metadata cache of a specific type.
     897         *
     898         * The dynamic portion of the hook, `$meta_type`, refers to the meta
     899         * object type (comment, post, term, or user). Returning a non-null value
     900         * will effectively short-circuit the function.
     901         *
     902         * @since 5.0.0
     903         *
     904         * @param mixed $check      Whether to allow updating the meta cache of the given type.
     905         * @param array $object_ids Array of object IDs to update the meta cache for.
     906         */
     907        $check = apply_filters( "update_{$meta_type}_metadata_cache", null, $object_ids );
     908        if ( null !== $check ) {
     909                return (bool) $check;
     910        }
     911
    841912        $cache_key = $meta_type . '_meta';
    842913        $ids       = array();
    843914        $cache     = array();
  • src/wp-includes/ms-blogs.php

     
    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         if ( ! is_site_meta_supported() ) {
    622                 return false;
    623         }
    624 
    625621        return update_meta_cache( 'blog', $site_ids );
    626622}
    627623
     
    838834 * @return int|false Meta ID on success, false on failure.
    839835 */
    840836function 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;
     837        return add_metadata( 'blog', $site_id, $meta_key, $meta_value, $unique );
    856838}
    857839
    858840/**
     
    871853 * @return bool True on success, false on failure.
    872854 */
    873855function 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;
     856        return delete_metadata( 'blog', $site_id, $meta_key, $meta_value );
    889857}
    890858
    891859/**
     
    901869 *               field if $single is true.
    902870 */
    903871function 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 
    911872        return get_metadata( 'blog', $site_id, $key, $single );
    912873}
    913874
     
    930891 *                  false on failure.
    931892 */
    932893function 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;
     894        return update_metadata( 'blog', $site_id, $meta_key, $meta_value, $prev_value );
    948895}
    949896
    950897/**
     
    956903 * @return bool Whether the site meta key was deleted from the database.
    957904 */
    958905function 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;
     906        return delete_metadata( 'blog', null, $meta_key, '', true );
    974907}
    975908
    976909/**
     
    15371470
    15381471        update_posts_count();
    15391472}
     1473
     1474/**
     1475 * Sets the last changed time for the 'sites' cache group.
     1476 *
     1477 * @since 5.0.0
     1478 */
     1479function wp_cache_set_sites_last_changed() {
     1480        wp_cache_set( 'last_changed', microtime(), 'sites' );
     1481}
     1482
     1483/**
     1484 * Aborts calls to site meta if it is not supported.
     1485 *
     1486 * @since 5.0.0
     1487 *
     1488 * @param mixed $check Skip-value for whether to proceed site meta function execution.
     1489 * @return mixed Original value of $check, or false if site meta is not supported.
     1490 */
     1491function wp_check_site_meta_support_prefilter( $check ) {
     1492        if ( ! is_site_meta_supported() ) {
     1493                /* translators: %s: database table name */
     1494                _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' );
     1495                return false;
     1496        }
     1497
     1498        return $check;
     1499}
  • src/wp-includes/ms-default-filters.php

     
    4242add_action( 'wpmu_activate_blog', 'wpmu_welcome_notification', 10, 5 );
    4343add_action( 'after_signup_site', 'wpmu_signup_blog_notification', 10, 7 );
    4444
     45// Site meta
     46add_action( 'added_blog_meta', 'wp_cache_set_sites_last_changed' );
     47add_action( 'updated_blog_meta', 'wp_cache_set_sites_last_changed' );
     48add_action( 'deleted_blog_meta', 'wp_cache_set_sites_last_changed' );
     49add_filter( 'get_blog_metadata', 'wp_check_site_meta_support_prefilter' );
     50add_filter( 'add_blog_metadata', 'wp_check_site_meta_support_prefilter' );
     51add_filter( 'update_blog_metadata', 'wp_check_site_meta_support_prefilter' );
     52add_filter( 'delete_blog_metadata', 'wp_check_site_meta_support_prefilter' );
     53add_filter( 'get_blog_metadata_by_mid', 'wp_check_site_meta_support_prefilter' );
     54add_filter( 'update_blog_metadata_by_mid', 'wp_check_site_meta_support_prefilter' );
     55add_filter( 'delete_blog_metadata_by_mid', 'wp_check_site_meta_support_prefilter' );
     56add_filter( 'update_blog_metadata_cache', 'wp_check_site_meta_support_prefilter' );
     57
    4558// Register Nonce
    4659add_action( 'signup_hidden_fields', 'signup_nonce_fields' );
    4760
  • src/wp-includes/post.php

     
    18891889                $post_id = $the_post;
    18901890        }
    18911891
    1892         $added = add_metadata( 'post', $post_id, $meta_key, $meta_value, $unique );
    1893         if ( $added ) {
    1894                 wp_cache_set( 'last_changed', microtime(), 'posts' );
    1895         }
    1896         return $added;
     1892        return add_metadata( 'post', $post_id, $meta_key, $meta_value, $unique );
    18971893}
    18981894
    18991895/**
     
    19171913                $post_id = $the_post;
    19181914        }
    19191915
    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;
     1916        return delete_metadata( 'post', $post_id, $meta_key, $meta_value );
    19251917}
    19261918
    19271919/**
     
    19661958                $post_id = $the_post;
    19671959        }
    19681960
    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;
     1961        return update_metadata( 'post', $post_id, $meta_key, $meta_value, $prev_value );
    19741962}
    19751963
    19761964/**
     
    19821970 * @return bool Whether the post meta key was deleted from the database.
    19831971 */
    19841972function 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;
     1973        return delete_metadata( 'post', null, $post_meta_key, '', true );
    19901974}
    19911975
    19921976/**
     
    67466730
    67476731        return $clauses;
    67486732}
     6733
     6734/**
     6735 * Sets the last changed time for the 'posts' cache group.
     6736 *
     6737 * @since 5.0.0
     6738 */
     6739function wp_cache_set_posts_last_changed() {
     6740        wp_cache_set( 'last_changed', microtime(), 'posts' );
     6741}
  • src/wp-includes/taxonomy.php

     
    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 
    11881183        if ( wp_term_is_shared( $term_id ) ) {
    11891184                return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.' ), $term_id );
    11901185        }
    11911186
    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;
     1187        return add_metadata( 'term', $term_id, $meta_key, $meta_value, $unique );
    12001188}
    12011189
    12021190/**
     
    12101198 * @return bool True on success, false on failure.
    12111199 */
    12121200function 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;
     1201        return delete_metadata( 'term', $term_id, $meta_key, $meta_value );
    12261202}
    12271203
    12281204/**
     
    12371213 * @return mixed If `$single` is false, an array of metadata values. If `$single` is true, a single metadata value.
    12381214 */
    12391215function 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 
    12451216        return get_metadata( 'term', $term_id, $key, $single );
    12461217}
    12471218
     
    12621233 *                           WP_Error when term_id is ambiguous between taxonomies. False on failure.
    12631234 */
    12641235function 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 
    12701236        if ( wp_term_is_shared( $term_id ) ) {
    12711237                return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.' ), $term_id );
    12721238        }
    12731239
    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;
     1240        return update_metadata( 'term', $term_id, $meta_key, $meta_value, $prev_value );
    12821241}
    12831242
    12841243/**
     
    12931252 * @return array|false Returns false if there is nothing to update. Returns an array of metadata on success.
    12941253 */
    12951254function 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 
    13011255        return update_meta_cache( 'term', $term_ids );
    13021256}
    13031257
     
    13121266 * @return array|false Array with meta data, or false when the meta table is not installed.
    13131267 */
    13141268function has_term_meta( $term_id ) {
    1315         // Bail if term meta table is not installed.
    1316         if ( get_option( 'db_version' ) < 34370 ) {
    1317                 return false;
     1269        $check = wp_check_term_meta_support_prefilter( null );
     1270        if ( null !== $check ) {
     1271                return $check;
    13181272        }
    13191273
    13201274        global $wpdb;
     
    45674521
    45684522        return $taxonomy->publicly_queryable;
    45694523}
     4524
     4525/**
     4526 * Sets the last changed time for the 'terms' cache group.
     4527 *
     4528 * @since 5.0.0
     4529 */
     4530function wp_cache_set_terms_last_changed() {
     4531        wp_cache_set( 'last_changed', microtime(), 'terms' );
     4532}
     4533
     4534/**
     4535 * Aborts calls to term meta if it is not supported.
     4536 *
     4537 * @since 5.0.0
     4538 *
     4539 * @param mixed $check Skip-value for whether to proceed term meta function execution.
     4540 * @return mixed Original value of $check, or false if term meta is not supported.
     4541 */
     4542function wp_check_term_meta_support_prefilter( $check ) {
     4543        if ( get_option( 'db_version' ) < 34370 ) {
     4544                return false;
     4545        }
     4546
     4547        return $check;
     4548}