Make WordPress Core

Ticket #44467: 44467.3.diff

File 44467.3.diff, 19.3 KB (added by flixos90, 7 years ago)
  • src/wp-includes/comment.php

     
    442442 * @return int|bool Meta ID on success, false on failure.
    443443 */
    444444function add_comment_meta( $comment_id, $meta_key, $meta_value, $unique = false ) {
    445         $added = add_metadata( 'comment', $comment_id, $meta_key, $meta_value, $unique );
    446         if ( $added ) {
    447                 wp_cache_set( 'last_changed', microtime(), 'comment' );
    448         }
    449         return $added;
     445        return add_metadata( 'comment', $comment_id, $meta_key, $meta_value, $unique );
    450446}
    451447
    452448/**
     
    465461 * @return bool True on success, false on failure.
    466462 */
    467463function delete_comment_meta( $comment_id, $meta_key, $meta_value = '' ) {
    468         $deleted = delete_metadata( 'comment', $comment_id, $meta_key, $meta_value );
    469         if ( $deleted ) {
    470                 wp_cache_set( 'last_changed', microtime(), 'comment' );
    471         }
    472         return $deleted;
     464        return delete_metadata( 'comment', $comment_id, $meta_key, $meta_value );
    473465}
    474466
    475467/**
     
    506498 * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure.
    507499 */
    508500function update_comment_meta( $comment_id, $meta_key, $meta_value, $prev_value = '' ) {
    509         $updated = update_metadata( 'comment', $comment_id, $meta_key, $meta_value, $prev_value );
    510         if ( $updated ) {
    511                 wp_cache_set( 'last_changed', microtime(), 'comment' );
    512         }
    513         return $updated;
     501        return update_metadata( 'comment', $comment_id, $meta_key, $meta_value, $prev_value );
    514502}
    515503
    516504/**
     
    35123500                'done'           => $done,
    35133501        );
    35143502}
     3503
     3504/**
     3505 * Sets the last changed time for the 'comment' cache group.
     3506 *
     3507 * @since 5.0.0
     3508 */
     3509function wp_cache_set_comments_last_changed() {
     3510        wp_cache_set( 'last_changed', microtime(), 'comment' );
     3511}
  • 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

     
    613613
    614614        $id_column = ( 'user' == $meta_type ) ? 'umeta_id' : 'meta_id';
    615615
     616        /**
     617         * Filters whether to retrieve metadata of a specific type by meta ID.
     618         *
     619         * The dynamic portion of the hook, `$meta_type`, refers to the meta
     620         * object type (comment, post, term, or user). Returning a non-null value
     621         * will effectively short-circuit the function.
     622         *
     623         * @since 5.0.0
     624         *
     625         * @param mixed $value    The value get_metadata_by_mid() should return.
     626         * @param int   $meta_id  Meta ID.
     627         */
     628        $check = apply_filters( "get_{$meta_type}_metadata_by_mid", null, $meta_id );
     629        if ( null !== $check ) {
     630                return $check;
     631        }
     632
    616633        $meta = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table WHERE $id_column = %d", $meta_id ) );
    617634
    618635        if ( empty( $meta ) ) {
     
    660677        $column    = sanitize_key( $meta_type . '_id' );
    661678        $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id';
    662679
     680        /**
     681         * Filters whether to update metadata of a specific type by meta ID.
     682         *
     683         * The dynamic portion of the hook, `$meta_type`, refers to the meta
     684         * object type (comment, post, term, or user). Returning a non-null value
     685         * will effectively short-circuit the function.
     686         *
     687         * @since 5.0.0
     688         *
     689         * @param null|bool   $check      Whether to allow updating metadata for the given type.
     690         * @param int         $meta_id    Meta ID.
     691         * @param mixed       $meta_value Meta value. Must be serializable if non-scalar.
     692         * @param string|bool $meta_key   Meta key, if provided.
     693         */
     694        $check = apply_filters( "update_{$meta_type}_metadata_by_mid", null, $meta_id, $meta_value, $meta_key );
     695        if ( null !== $check ) {
     696                return (bool) $check;
     697        }
     698
    663699        // Fetch the meta and go on if it's found.
    664700        if ( $meta = get_metadata_by_mid( $meta_type, $meta_id ) ) {
    665701                $original_key = $meta->meta_key;
     
    755791        $column    = sanitize_key( $meta_type . '_id' );
    756792        $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id';
    757793
     794        /**
     795         * Filters whether to delete metadata of a specific type by meta ID.
     796         *
     797         * The dynamic portion of the hook, `$meta_type`, refers to the meta
     798         * object type (comment, post, term, or user). Returning a non-null value
     799         * will effectively short-circuit the function.
     800         *
     801         * @since 5.0.0
     802         *
     803         * @param null|bool $delete  Whether to allow metadata deletion of the given type.
     804         * @param int       $meta_id Meta ID.
     805         */
     806        $check = apply_filters( "delete_{$meta_type}_metadata_by_mid", null, $meta_id );
     807        if ( null !== $check ) {
     808                return (bool) $check;
     809        }
     810
    758811        // Fetch the meta and go on if it's found.
    759812        if ( $meta = get_metadata_by_mid( $meta_type, $meta_id ) ) {
    760813                $object_id = $meta->{$column};
     
    841894
    842895        $object_ids = array_map( 'intval', $object_ids );
    843896
     897        /**
     898         * Filters whether to update the metadata cache of a specific type.
     899         *
     900         * The dynamic portion of the hook, `$meta_type`, refers to the meta
     901         * object type (comment, post, term, or user). Returning a non-null value
     902         * will effectively short-circuit the function.
     903         *
     904         * @since 5.0.0
     905         *
     906         * @param mixed $check      Whether to allow updating the meta cache of the given type.
     907         * @param array $object_ids Array of object IDs to update the meta cache for.
     908         */
     909        $check = apply_filters( "update_{$meta_type}_metadata_cache", null, $object_ids );
     910        if ( null !== $check ) {
     911                return (bool) $check;
     912        }
     913
    844914        $cache_key = $meta_type . '_meta';
    845915        $ids       = array();
    846916        $cache     = array();
  • src/wp-includes/ms-blogs.php

     
    662662 * @return array|false Returns false if there is nothing to update. Returns an array of metadata on success.
    663663 */
    664664function update_sitemeta_cache( $site_ids ) {
    665         if ( ! is_site_meta_supported() ) {
    666                 return false;
    667         }
    668 
    669665        return update_meta_cache( 'blog', $site_ids );
    670666}
    671667
     
    10631059 * @return int|false Meta ID on success, false on failure.
    10641060 */
    10651061function add_site_meta( $site_id, $meta_key, $meta_value, $unique = false ) {
    1066         // Bail if site meta table is not installed.
    1067         if ( ! is_site_meta_supported() ) {
    1068                 /* translators: %s: database table name */
    1069                 _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' );
    1070                 return false;
    1071         }
    1072 
    1073         $added = add_metadata( 'blog', $site_id, $meta_key, $meta_value, $unique );
    1074 
    1075         // Bust site query cache.
    1076         if ( $added ) {
    1077                 wp_cache_set( 'last_changed', microtime(), 'sites' );
    1078         }
    1079 
    1080         return $added;
     1062        return add_metadata( 'blog', $site_id, $meta_key, $meta_value, $unique );
    10811063}
    10821064
    10831065/**
     
    10961078 * @return bool True on success, false on failure.
    10971079 */
    10981080function delete_site_meta( $site_id, $meta_key, $meta_value = '' ) {
    1099         // Bail if site meta table is not installed.
    1100         if ( ! is_site_meta_supported() ) {
    1101                 /* translators: %s: database table name */
    1102                 _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' );
    1103                 return false;
    1104         }
    1105 
    1106         $deleted = delete_metadata( 'blog', $site_id, $meta_key, $meta_value );
    1107 
    1108         // Bust site query cache.
    1109         if ( $deleted ) {
    1110                 wp_cache_set( 'last_changed', microtime(), 'sites' );
    1111         }
    1112 
    1113         return $deleted;
     1081        return delete_metadata( 'blog', $site_id, $meta_key, $meta_value );
    11141082}
    11151083
    11161084/**
     
    11261094 *               field if $single is true.
    11271095 */
    11281096function get_site_meta( $site_id, $key = '', $single = false ) {
    1129         // Bail if site meta table is not installed.
    1130         if ( ! is_site_meta_supported() ) {
    1131                 /* translators: %s: database table name */
    1132                 _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' );
    1133                 return false;
    1134         }
    1135 
    11361097        return get_metadata( 'blog', $site_id, $key, $single );
    11371098}
    11381099
     
    11551116 *                  false on failure.
    11561117 */
    11571118function update_site_meta( $site_id, $meta_key, $meta_value, $prev_value = '' ) {
    1158         // Bail if site meta table is not installed.
    1159         if ( ! is_site_meta_supported() ) {
    1160                 /* translators: %s: database table name */
    1161                 _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' );
    1162                 return false;
    1163         }
    1164 
    1165         $updated = update_metadata( 'blog', $site_id, $meta_key, $meta_value, $prev_value );
    1166 
    1167         // Bust site query cache.
    1168         if ( $updated ) {
    1169                 wp_cache_set( 'last_changed', microtime(), 'sites' );
    1170         }
    1171 
    1172         return $updated;
     1119        return update_metadata( 'blog', $site_id, $meta_key, $meta_value, $prev_value );
    11731120}
    11741121
    11751122/**
     
    11811128 * @return bool Whether the site meta key was deleted from the database.
    11821129 */
    11831130function delete_site_meta_by_key( $meta_key ) {
    1184         // Bail if site meta table is not installed.
    1185         if ( ! is_site_meta_supported() ) {
    1186                 /* translators: %s: database table name */
    1187                 _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' );
    1188                 return false;
    1189         }
    1190 
    1191         $deleted = delete_metadata( 'blog', null, $meta_key, '', true );
    1192 
    1193         // Bust site query cache.
    1194         if ( $deleted ) {
    1195                 wp_cache_set( 'last_changed', microtime(), 'sites' );
    1196         }
    1197 
    1198         return $deleted;
     1131        return delete_metadata( 'blog', null, $meta_key, '', true );
    11991132}
    12001133
    12011134/**
     
    18911824function wp_update_blog_public_option_on_site_update( $site_id, $public ) {
    18921825        update_blog_option( $site_id, 'blog_public', $public );
    18931826}
     1827
     1828/**
     1829 * Sets the last changed time for the 'sites' cache group.
     1830 *
     1831 * @since 5.0.0
     1832 */
     1833function wp_cache_set_sites_last_changed() {
     1834        wp_cache_set( 'last_changed', microtime(), 'sites' );
     1835}
     1836
     1837/**
     1838 * Aborts calls to site meta if it is not supported.
     1839 *
     1840 * @since 5.0.0
     1841 *
     1842 * @param mixed $check Skip-value for whether to proceed site meta function execution.
     1843 * @return mixed Original value of $check, or false if site meta is not supported.
     1844 */
     1845function wp_check_site_meta_support_prefilter( $check ) {
     1846        if ( ! is_site_meta_supported() ) {
     1847                /* translators: %s: database table name */
     1848                _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' );
     1849                return false;
     1850        }
     1851
     1852        return $check;
     1853}
  • src/wp-includes/ms-default-filters.php

     
    5151add_action( 'wp_update_site', 'wp_maybe_clean_new_site_cache_on_update', 10, 2 );
    5252add_action( 'update_blog_public', 'wp_update_blog_public_option_on_site_update', 1, 2 );
    5353
     54// Site meta
     55add_action( 'added_blog_meta', 'wp_cache_set_sites_last_changed' );
     56add_action( 'updated_blog_meta', 'wp_cache_set_sites_last_changed' );
     57add_action( 'deleted_blog_meta', 'wp_cache_set_sites_last_changed' );
     58add_filter( 'get_blog_metadata', 'wp_check_site_meta_support_prefilter' );
     59add_filter( 'add_blog_metadata', 'wp_check_site_meta_support_prefilter' );
     60add_filter( 'update_blog_metadata', 'wp_check_site_meta_support_prefilter' );
     61add_filter( 'delete_blog_metadata', 'wp_check_site_meta_support_prefilter' );
     62add_filter( 'get_blog_metadata_by_mid', 'wp_check_site_meta_support_prefilter' );
     63add_filter( 'update_blog_metadata_by_mid', 'wp_check_site_meta_support_prefilter' );
     64add_filter( 'delete_blog_metadata_by_mid', 'wp_check_site_meta_support_prefilter' );
     65add_filter( 'update_blog_metadata_cache', 'wp_check_site_meta_support_prefilter' );
     66
    5467// Register Nonce
    5568add_action( 'signup_hidden_fields', 'signup_nonce_fields' );
    5669
  • src/wp-includes/post.php

     
    19101910                $post_id = $the_post;
    19111911        }
    19121912
    1913         $added = add_metadata( 'post', $post_id, $meta_key, $meta_value, $unique );
    1914         if ( $added ) {
    1915                 wp_cache_set( 'last_changed', microtime(), 'posts' );
    1916         }
    1917         return $added;
     1913        return add_metadata( 'post', $post_id, $meta_key, $meta_value, $unique );
    19181914}
    19191915
    19201916/**
     
    19381934                $post_id = $the_post;
    19391935        }
    19401936
    1941         $deleted = delete_metadata( 'post', $post_id, $meta_key, $meta_value );
    1942         if ( $deleted ) {
    1943                 wp_cache_set( 'last_changed', microtime(), 'posts' );
    1944         }
    1945         return $deleted;
     1937        return delete_metadata( 'post', $post_id, $meta_key, $meta_value );
    19461938}
    19471939
    19481940/**
     
    19851977                $post_id = $the_post;
    19861978        }
    19871979
    1988         $updated = update_metadata( 'post', $post_id, $meta_key, $meta_value, $prev_value );
    1989         if ( $updated ) {
    1990                 wp_cache_set( 'last_changed', microtime(), 'posts' );
    1991         }
    1992         return $updated;
     1980        return update_metadata( 'post', $post_id, $meta_key, $meta_value, $prev_value );
    19931981}
    19941982
    19951983/**
     
    20011989 * @return bool Whether the post meta key was deleted from the database.
    20021990 */
    20031991function delete_post_meta_by_key( $post_meta_key ) {
    2004         $deleted = delete_metadata( 'post', null, $post_meta_key, '', true );
    2005         if ( $deleted ) {
    2006                 wp_cache_set( 'last_changed', microtime(), 'posts' );
    2007         }
    2008         return $deleted;
     1992        return delete_metadata( 'post', null, $post_meta_key, '', true );
    20091993}
    20101994
    20111995/**
     
    67856769
    67866770        return $clauses;
    67876771}
     6772
     6773/**
     6774 * Sets the last changed time for the 'posts' cache group.
     6775 *
     6776 * @since 5.0.0
     6777 */
     6778function wp_cache_set_posts_last_changed() {
     6779        wp_cache_set( 'last_changed', microtime(), 'posts' );
     6780}
  • src/wp-includes/taxonomy.php

     
    12111211 *                           False on failure.
    12121212 */
    12131213function add_term_meta( $term_id, $meta_key, $meta_value, $unique = false ) {
    1214         // Bail if term meta table is not installed.
    1215         if ( get_option( 'db_version' ) < 34370 ) {
    1216                 return false;
    1217         }
    1218 
    12191214        if ( wp_term_is_shared( $term_id ) ) {
    12201215                return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.' ), $term_id );
    12211216        }
    12221217
    1223         $added = add_metadata( 'term', $term_id, $meta_key, $meta_value, $unique );
    1224 
    1225         // Bust term query cache.
    1226         if ( $added ) {
    1227                 wp_cache_set( 'last_changed', microtime(), 'terms' );
    1228         }
    1229 
    1230         return $added;
     1218        return add_metadata( 'term', $term_id, $meta_key, $meta_value, $unique );
    12311219}
    12321220
    12331221/**
     
    12411229 * @return bool True on success, false on failure.
    12421230 */
    12431231function delete_term_meta( $term_id, $meta_key, $meta_value = '' ) {
    1244         // Bail if term meta table is not installed.
    1245         if ( get_option( 'db_version' ) < 34370 ) {
    1246                 return false;
    1247         }
    1248 
    1249         $deleted = delete_metadata( 'term', $term_id, $meta_key, $meta_value );
    1250 
    1251         // Bust term query cache.
    1252         if ( $deleted ) {
    1253                 wp_cache_set( 'last_changed', microtime(), 'terms' );
    1254         }
    1255 
    1256         return $deleted;
     1232        return delete_metadata( 'term', $term_id, $meta_key, $meta_value );
    12571233}
    12581234
    12591235/**
     
    12681244 * @return mixed If `$single` is false, an array of metadata values. If `$single` is true, a single metadata value.
    12691245 */
    12701246function get_term_meta( $term_id, $key = '', $single = false ) {
    1271         // Bail if term meta table is not installed.
    1272         if ( get_option( 'db_version' ) < 34370 ) {
    1273                 return false;
    1274         }
    1275 
    12761247        return get_metadata( 'term', $term_id, $key, $single );
    12771248}
    12781249
     
    12931264 *                           WP_Error when term_id is ambiguous between taxonomies. False on failure.
    12941265 */
    12951266function update_term_meta( $term_id, $meta_key, $meta_value, $prev_value = '' ) {
    1296         // Bail if term meta table is not installed.
    1297         if ( get_option( 'db_version' ) < 34370 ) {
    1298                 return false;
    1299         }
    1300 
    13011267        if ( wp_term_is_shared( $term_id ) ) {
    13021268                return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.' ), $term_id );
    13031269        }
    13041270
    1305         $updated = update_metadata( 'term', $term_id, $meta_key, $meta_value, $prev_value );
    1306 
    1307         // Bust term query cache.
    1308         if ( $updated ) {
    1309                 wp_cache_set( 'last_changed', microtime(), 'terms' );
    1310         }
    1311 
    1312         return $updated;
     1271        return update_metadata( 'term', $term_id, $meta_key, $meta_value, $prev_value );
    13131272}
    13141273
    13151274/**
     
    13241283 * @return array|false Returns false if there is nothing to update. Returns an array of metadata on success.
    13251284 */
    13261285function update_termmeta_cache( $term_ids ) {
    1327         // Bail if term meta table is not installed.
    1328         if ( get_option( 'db_version' ) < 34370 ) {
    1329                 return;
    1330         }
    1331 
    13321286        return update_meta_cache( 'term', $term_ids );
    13331287}
    13341288
     
    13431297 * @return array|false Array with meta data, or false when the meta table is not installed.
    13441298 */
    13451299function has_term_meta( $term_id ) {
    1346         // Bail if term meta table is not installed.
    1347         if ( get_option( 'db_version' ) < 34370 ) {
    1348                 return false;
     1300        $check = wp_check_term_meta_support_prefilter( null );
     1301        if ( null !== $check ) {
     1302                return $check;
    13491303        }
    13501304
    13511305        global $wpdb;
     
    46324586
    46334587        return $taxonomy->publicly_queryable;
    46344588}
     4589
     4590/**
     4591 * Sets the last changed time for the 'terms' cache group.
     4592 *
     4593 * @since 5.0.0
     4594 */
     4595function wp_cache_set_terms_last_changed() {
     4596        wp_cache_set( 'last_changed', microtime(), 'terms' );
     4597}
     4598
     4599/**
     4600 * Aborts calls to term meta if it is not supported.
     4601 *
     4602 * @since 5.0.0
     4603 *
     4604 * @param mixed $check Skip-value for whether to proceed term meta function execution.
     4605 * @return mixed Original value of $check, or false if term meta is not supported.
     4606 */
     4607function wp_check_term_meta_support_prefilter( $check ) {
     4608        if ( get_option( 'db_version' ) < 34370 ) {
     4609                return false;
     4610        }
     4611
     4612        return $check;
     4613}