| 54 | case 'edit_user_meta': |
| 55 | case 'delete_user_meta': |
| 56 | case 'add_user_meta': |
| 57 | $user = get_user_by( 'id', $args[0] ); |
| 58 | if( ! $user ){ |
| 59 | $caps[] = 'do_not_allow'; |
| 60 | break; |
| 61 | } |
| 62 | |
| 63 | $caps = map_meta_cap( 'edit_user', $user_id, $user->ID ); |
| 64 | |
| 65 | $meta_key = isset( $args[ 1 ] ) ? $args[ 1 ] : false; |
| 66 | |
| 67 | if ( $meta_key && ( has_filter( "auth_user_meta_{$meta_key}" ) ) ) { |
| 68 | /** |
| 69 | * Filters whether the user is allowed to add user meta to a user. |
| 70 | * |
| 71 | * The dynamic portion of the hook name, `$meta_key`, refers to the |
| 72 | * meta key passed to map_meta_cap(). |
| 73 | * |
| 74 | * @since 4.7.0 |
| 75 | * |
| 76 | * @param bool $allowed Whether the user can add the user meta. Default false. |
| 77 | * @param string $meta_key The meta key. |
| 78 | * @param int $user->ID The user being edited. |
| 79 | * @param int $user_id User ID. |
| 80 | * @param string $cap Capability name. |
| 81 | * @param array $caps User capabilities. |
| 82 | */ |
| 83 | $allowed = apply_filters( "auth_user_meta_{$meta_key}", false, $meta_key, $user->ID, $user_id, $cap, $caps ); |
| 84 | |
| 85 | if ( ! $allowed ){ |
| 86 | $caps[] = $cap; |
| 87 | } |
| 88 | } |
| 89 | break; |
| 90 | |
| 354 | case 'edit_comment_meta': |
| 355 | case 'delete_comment_meta': |
| 356 | case 'add_comment_meta': |
| 357 | $comment = get_comment( $args[0] ); |
| 358 | if ( ! $comment ) { |
| 359 | $caps[] = 'do_not_allow'; |
| 360 | break; |
| 361 | } |
| 362 | |
| 363 | $caps = map_meta_cap( 'edit_comment', $user_id, $comment->comment_post_ID ); |
| 364 | |
| 365 | $meta_key = isset( $args[ 1 ] ) ? $args[ 1 ] : false; |
| 366 | |
| 367 | if ( $meta_key && ( has_filter( "auth_comment_meta_{$meta_key}" ) ) ) { |
| 368 | /** |
| 369 | * Filters whether the user is allowed to add comment meta to a comment. |
| 370 | * |
| 371 | * The dynamic portion of the hook name, `$meta_key`, refers to the |
| 372 | * meta key passed to map_meta_cap(). |
| 373 | * |
| 374 | * @since 4.7.0 |
| 375 | * |
| 376 | * @param bool $allowed Whether the user can add the comment meta. Default false. |
| 377 | * @param string $meta_key The meta key. |
| 378 | * @param int $comment_id Post ID. |
| 379 | * @param int $user_id User ID. |
| 380 | * @param string $cap Capability name. |
| 381 | * @param array $caps User capabilities. |
| 382 | */ |
| 383 | $allowed = apply_filters( "auth_comment_meta_{$meta_key}", false, $meta_key, $comment->comment_post_ID, $user_id, $cap, $caps ); |
| 384 | |
| 385 | if ( ! $allowed ){ |
| 386 | $caps[] = $cap; |
| 387 | } |
| 388 | } |
| 389 | break; |
| 504 | case 'edit_term_meta': |
| 505 | case 'delete_term_meta': |
| 506 | case 'add_term_meta': |
| 507 | $term_id = $args[0]; |
| 508 | $term = get_term( $term_id ); |
| 509 | if ( ! $term || is_wp_error( $term ) ) { |
| 510 | $caps[] = 'do_not_allow'; |
| 511 | break; |
| 512 | } |
| 513 | |
| 514 | $caps = map_meta_cap( 'edit_term', $user_id, $term_id ); |
| 515 | |
| 516 | $meta_key = isset( $args[ 1 ] ) ? $args[ 1 ] : false; |
| 517 | |
| 518 | if ( $meta_key && ( has_filter( "auth_term_meta_{$meta_key}" ) ) ) { |
| 519 | /** |
| 520 | * Filters whether the user is allowed to add comment meta to a comment. |
| 521 | * |
| 522 | * The dynamic portion of the hook name, `$meta_key`, refers to the |
| 523 | * meta key passed to map_meta_cap(). |
| 524 | * |
| 525 | * @since 4.7.0 |
| 526 | * |
| 527 | * @param bool $allowed Whether the user can add the comment meta. Default false. |
| 528 | * @param string $meta_key The meta key. |
| 529 | * @param int $comment_id Post ID. |
| 530 | * @param int $user_id User ID. |
| 531 | * @param string $cap Capability name. |
| 532 | * @param array $caps User capabilities. |
| 533 | */ |
| 534 | $allowed = apply_filters( "auth_term_meta_{$meta_key}", false, $meta_key, $term_id, $user_id, $cap, $caps ); |
| 535 | |
| 536 | if ( ! $allowed ){ |
| 537 | $caps[] = $cap; |
| 538 | } |
| 539 | } |
| 540 | break; |
| 541 | |