Skip to content

Commit 3561331

Browse files
committed
Docs.
1 parent 96d3494 commit 3561331

6 files changed

Lines changed: 132 additions & 15 deletions

File tree

src/wp-includes/comment.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,9 @@ function get_comment_count( $post_id = 0 ) {
446446
/**
447447
* Adds meta data field to a comment.
448448
*
449+
* For historial reasons both the meta key and the meta value are expected to be "slashed" (slashes escaped) on input.
450+
* This means if data is coming from user-generated content you need to wp_slash() it before passing it to this function.
451+
*
449452
* @since 2.9.0
450453
*
451454
* @link https://developer.wordpress.org/reference/functions/add_comment_meta/
@@ -470,7 +473,18 @@ function add_comment_meta( $comment_id, $meta_key, $meta_value, $unique = false
470473
/**
471474
* Adds multiple items of meta data to a comment.
472475
*
473-
* @todo docs
476+
* Examples:
477+
*
478+
* bulk_add_comment_meta(
479+
* $comment->comment_ID,
480+
* array(
481+
* 'meta_key_1' => 'value_1',
482+
* 'meta_key_2' => 'value_2',
483+
* )
484+
* );
485+
*
486+
* For historial reasons both the meta key and the meta value are expected to be "slashed" (slashes escaped) on input.
487+
* This means if data is coming from user-generated content you need to wp_slash() it before passing it to this function.
474488
*
475489
* @since x.y.z
476490
*
@@ -489,6 +503,9 @@ function bulk_add_comment_meta( $comment_id, array $meta_fields ) {
489503
* value, will keep from removing duplicate metadata with the same key. It also
490504
* allows removing all metadata matching key, if needed.
491505
*
506+
* For historial reasons both the meta key and the meta value are expected to be "slashed" (slashes escaped) on input.
507+
* This means if data is coming from user-generated content you need to wp_slash() it before passing it to this function.
508+
*
492509
* @since 2.9.0
493510
*
494511
* @link https://developer.wordpress.org/reference/functions/delete_comment_meta/
@@ -555,6 +572,9 @@ function wp_lazyload_comment_meta( array $comment_ids ) {
555572
*
556573
* If the meta field for the comment does not exist, it will be added.
557574
*
575+
* For historial reasons both the meta key and the meta value are expected to be "slashed" (slashes escaped) on input.
576+
* This means if data is coming from user-generated content you need to wp_slash() it before passing it to this function.
577+
*
558578
* @since 2.9.0
559579
*
560580
* @link https://developer.wordpress.org/reference/functions/update_comment_meta/

src/wp-includes/meta.php

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
/**
1616
* Adds metadata for the specified object.
1717
*
18+
* For historial reasons both the meta key and the meta value are expected to be "slashed" (slashes escaped) on input.
19+
* This means if data is coming from user-generated content you need to wp_slash() it before passing it to this function.
20+
*
1821
* @since 2.9.0
1922
*
2023
* @global wpdb $wpdb WordPress database abstraction object.
@@ -167,19 +170,27 @@ function add_metadata( $meta_type, $object_id, $meta_key, $meta_value, $unique =
167170
/**
168171
* Adds multiple items of metadata for the specified object.
169172
*
170-
* For historial reasons both the meta key and the meta value are expected to be "slashed" (slashes
171-
* escaped) on input. This means if the data is coming from user-generated
172-
* content you will need to wp_slash() it before passing it to this function.
173+
* For historial reasons both the meta key and the meta value are expected to be "slashed" (slashes escaped) on input.
174+
* This means if data is coming from user-generated content you need to wp_slash() it before passing it to this function.
175+
*
176+
* This function will always insert all of the provided metadata even if matching keys already exist. This behaviour
177+
* matches that of add_metadata() when its `$unique` parameter is set to false.
178+
*
179+
* If the insert fails, no metadata will be inserted. It's not possible for some rows to be inserted and not others.
173180
*
174-
* This function will always insert all of the provided metadata even if matching keys
175-
* already exist. This behaviour matches that of add_metadata() when its `$unique`
176-
* parameter is set to false.
181+
* This is more performant than calling `add_metadata()` multiple times because it only queries the database once and
182+
* only clears the meta cache once.
177183
*
178-
* If the insert fails, no metadata will be inserted. It's not possible for some rows
179-
* to be inserted and not others.
184+
* Examples:
180185
*
181-
* This is more performant than calling `add_metadata()` multiple times because it
182-
* only queries the database once and only clears the meta cache once.
186+
* bulk_add_metadata(
187+
* 'post',
188+
* $post_id,
189+
* array(
190+
* 'meta_key_1' => 'value_1',
191+
* 'meta_key_2' => 'value_2',
192+
* )
193+
* );
183194
*
184195
* @todo:
185196
*
@@ -283,6 +294,9 @@ function bulk_add_metadata( string $meta_type, $object_id, array $meta_fields )
283294
* Updates metadata for the specified object. If no value already exists for the specified object
284295
* ID and metadata key, the metadata will be added.
285296
*
297+
* For historial reasons both the meta key and the meta value are expected to be "slashed" (slashes escaped) on input.
298+
* This means if data is coming from user-generated content you need to wp_slash() it before passing it to this function.
299+
*
286300
* @since 2.9.0
287301
*
288302
* @global wpdb $wpdb WordPress database abstraction object.
@@ -478,6 +492,9 @@ function update_metadata( $meta_type, $object_id, $meta_key, $meta_value, $prev_
478492
/**
479493
* Deletes metadata for the specified object.
480494
*
495+
* For historial reasons both the meta key and the meta value are expected to be "slashed" (slashes escaped) on input.
496+
* This means if data is coming from user-generated content you need to wp_slash() it before passing it to this function.
497+
*
481498
* @since 2.9.0
482499
*
483500
* @global wpdb $wpdb WordPress database abstraction object.

src/wp-includes/ms-site.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,9 @@ function clean_blog_cache( $blog ) {
10221022
/**
10231023
* Adds metadata to a site.
10241024
*
1025+
* For historial reasons both the meta key and the meta value are expected to be "slashed" (slashes escaped) on input.
1026+
* This means if data is coming from user-generated content you need to wp_slash() it before passing it to this function.
1027+
*
10251028
* @since 5.1.0
10261029
*
10271030
* @param int $site_id Site ID.
@@ -1044,7 +1047,18 @@ function add_site_meta( $site_id, $meta_key, $meta_value, $unique = false ) {
10441047
/**
10451048
* Adds multiple items of meta data to a site.
10461049
*
1047-
* @todo docs
1050+
* Examples:
1051+
*
1052+
* bulk_add_site_meta(
1053+
* $site_id,
1054+
* array(
1055+
* 'meta_key_1' => 'value_1',
1056+
* 'meta_key_2' => 'value_2',
1057+
* )
1058+
* );
1059+
*
1060+
* For historial reasons both the meta key and the meta value are expected to be "slashed" (slashes escaped) on input.
1061+
* This means if data is coming from user-generated content you need to wp_slash() it before passing it to this function.
10481062
*
10491063
* @since x.y.z
10501064
*
@@ -1063,6 +1077,9 @@ function bulk_add_site_meta( $site_id, array $meta_fields ) {
10631077
* value, will keep from removing duplicate metadata with the same key. It also
10641078
* allows removing all metadata matching key, if needed.
10651079
*
1080+
* For historial reasons both the meta key and the meta value are expected to be "slashed" (slashes escaped) on input.
1081+
* This means if data is coming from user-generated content you need to wp_slash() it before passing it to this function.
1082+
*
10661083
* @since 5.1.0
10671084
*
10681085
* @param int $site_id Site ID.
@@ -1110,6 +1127,9 @@ function get_site_meta( $site_id, $key = '', $single = false ) {
11101127
*
11111128
* If the meta field for the site does not exist, it will be added.
11121129
*
1130+
* For historial reasons both the meta key and the meta value are expected to be "slashed" (slashes escaped) on input.
1131+
* This means if data is coming from user-generated content you need to wp_slash() it before passing it to this function.
1132+
*
11131133
* @since 5.1.0
11141134
*
11151135
* @param int $site_id Site ID.

src/wp-includes/post.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2608,6 +2608,9 @@ function get_posts( $args = null ) {
26082608
*
26092609
* Post meta data is called "Custom Fields" on the Administration Screen.
26102610
*
2611+
* For historial reasons both the meta key and the meta value are expected to be "slashed" (slashes escaped) on input.
2612+
* This means if data is coming from user-generated content you need to wp_slash() it before passing it to this function.
2613+
*
26112614
* @since 1.5.0
26122615
*
26132616
* @param int $post_id Post ID.
@@ -2636,7 +2639,18 @@ function add_post_meta( $post_id, $meta_key, $meta_value, $unique = false ) {
26362639
/**
26372640
* Adds multiple items of meta data to a post.
26382641
*
2639-
* @todo docs
2642+
* Examples:
2643+
*
2644+
* bulk_add_post_meta(
2645+
* $post->ID,
2646+
* array(
2647+
* 'meta_key_1' => 'value_1',
2648+
* 'meta_key_2' => 'value_2',
2649+
* )
2650+
* );
2651+
*
2652+
* For historial reasons both the meta key and the meta value are expected to be "slashed" (slashes escaped) on input.
2653+
* This means if data is coming from user-generated content you need to wp_slash() it before passing it to this function.
26402654
*
26412655
* @since x.y.z
26422656
*
@@ -2655,6 +2669,9 @@ function bulk_add_post_meta( $post_id, array $meta_fields ) {
26552669
* value, will keep from removing duplicate metadata with the same key. It also
26562670
* allows removing all metadata matching the key, if needed.
26572671
*
2672+
* For historial reasons both the meta key and the meta value are expected to be "slashed" (slashes escaped) on input.
2673+
* This means if data is coming from user-generated content you need to wp_slash() it before passing it to this function.
2674+
*
26582675
* @since 1.5.0
26592676
*
26602677
* @param int $post_id Post ID.
@@ -2710,6 +2727,9 @@ function get_post_meta( $post_id, $key = '', $single = false ) {
27102727
*
27112728
* Can be used in place of add_post_meta().
27122729
*
2730+
* For historial reasons both the meta key and the meta value are expected to be "slashed" (slashes escaped) on input.
2731+
* This means if data is coming from user-generated content you need to wp_slash() it before passing it to this function.
2732+
*
27132733
* @since 1.5.0
27142734
*
27152735
* @param int $post_id Post ID.

src/wp-includes/taxonomy.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,9 @@ function get_terms( $args = array(), $deprecated = '' ) {
13821382
/**
13831383
* Adds metadata to a term.
13841384
*
1385+
* For historial reasons both the meta key and the meta value are expected to be "slashed" (slashes escaped) on input.
1386+
* This means if data is coming from user-generated content you need to wp_slash() it before passing it to this function.
1387+
*
13851388
* @since 4.4.0
13861389
*
13871390
* @param int $term_id Term ID.
@@ -1409,7 +1412,18 @@ function add_term_meta( $term_id, $meta_key, $meta_value, $unique = false ) {
14091412
/**
14101413
* Adds multiple items of meta data to a term.
14111414
*
1412-
* @todo docs
1415+
* Examples:
1416+
*
1417+
* bulk_add_term_meta(
1418+
* $term->term_id,
1419+
* array(
1420+
* 'meta_key_1' => 'value_1',
1421+
* 'meta_key_2' => 'value_2',
1422+
* )
1423+
* );
1424+
*
1425+
* For historial reasons both the meta key and the meta value are expected to be "slashed" (slashes escaped) on input.
1426+
* This means if data is coming from user-generated content you need to wp_slash() it before passing it to this function.
14131427
*
14141428
* @since x.y.z
14151429
*
@@ -1429,6 +1443,9 @@ function bulk_add_term_meta( $term_id, array $meta_fields ) {
14291443
/**
14301444
* Removes metadata matching criteria from a term.
14311445
*
1446+
* For historial reasons both the meta key and the meta value are expected to be "slashed" (slashes escaped) on input.
1447+
* This means if data is coming from user-generated content you need to wp_slash() it before passing it to this function.
1448+
*
14321449
* @since 4.4.0
14331450
*
14341451
* @param int $term_id Term ID.
@@ -1475,6 +1492,9 @@ function get_term_meta( $term_id, $key = '', $single = false ) {
14751492
*
14761493
* If the meta field for the term does not exist, it will be added.
14771494
*
1495+
* For historial reasons both the meta key and the meta value are expected to be "slashed" (slashes escaped) on input.
1496+
* This means if data is coming from user-generated content you need to wp_slash() it before passing it to this function.
1497+
*
14781498
* @since 4.4.0
14791499
*
14801500
* @param int $term_id Term ID.

src/wp-includes/user.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,9 @@ function is_user_member_of_blog( $user_id = 0, $blog_id = 0 ) {
12021202
/**
12031203
* Adds meta data to a user.
12041204
*
1205+
* For historial reasons both the meta key and the meta value are expected to be "slashed" (slashes escaped) on input.
1206+
* This means if data is coming from user-generated content you need to wp_slash() it before passing it to this function.
1207+
*
12051208
* @since 3.0.0
12061209
*
12071210
* @param int $user_id User ID.
@@ -1224,7 +1227,18 @@ function add_user_meta( $user_id, $meta_key, $meta_value, $unique = false ) {
12241227
/**
12251228
* Adds multiple items of meta data to a user.
12261229
*
1227-
* @todo docs
1230+
* Examples:
1231+
*
1232+
* bulk_add_user_meta(
1233+
* $user->ID,
1234+
* array(
1235+
* 'meta_key_1' => 'value_1',
1236+
* 'meta_key_2' => 'value_2',
1237+
* )
1238+
* );
1239+
*
1240+
* For historial reasons both the meta key and the meta value are expected to be "slashed" (slashes escaped) on input.
1241+
* This means if data is coming from user-generated content you need to wp_slash() it before passing it to this function.
12281242
*
12291243
* @since x.y.z
12301244
*
@@ -1243,6 +1257,9 @@ function bulk_add_user_meta( $user_id, array $meta_fields ) {
12431257
* value, will keep from removing duplicate metadata with the same key. It also
12441258
* allows removing all metadata matching key, if needed.
12451259
*
1260+
* For historial reasons both the meta key and the meta value are expected to be "slashed" (slashes escaped) on input.
1261+
* This means if data is coming from user-generated content you need to wp_slash() it before passing it to this function.
1262+
*
12461263
* @since 3.0.0
12471264
*
12481265
* @link https://developer.wordpress.org/reference/functions/delete_user_meta/
@@ -1294,6 +1311,9 @@ function get_user_meta( $user_id, $key = '', $single = false ) {
12941311
*
12951312
* If the meta field for the user does not exist, it will be added.
12961313
*
1314+
* For historial reasons both the meta key and the meta value are expected to be "slashed" (slashes escaped) on input.
1315+
* This means if data is coming from user-generated content you need to wp_slash() it before passing it to this function.
1316+
*
12971317
* @since 3.0.0
12981318
*
12991319
* @link https://developer.wordpress.org/reference/functions/update_user_meta/

0 commit comments

Comments
 (0)