Ticket #32605: 32605.patch
File 32605.patch, 4.1 KB (added by , 10 years ago) |
---|
-
src/wp-includes/meta.php
576 576 return false; 577 577 } 578 578 579 /** 580 * Filter whether to retrieve metadata of a specific type by its meta ID. 581 * 582 * The dynamic portion of the hook, `$meta_type`, refers to the meta 583 * object type (comment, post, or user). Returning a non-null value 584 * will effectively short-circuit the retrieval. 585 * 586 * @since x.y.z 587 * 588 * @param null|object $value Whether to retrieve the meta row object. 589 * @param int mixed $meta_id Meta row ID. 590 */ 591 $check = apply_filters( "get_{$meta_type}_meta_by_mid", null, $meta_id ); 592 if ( null !== $check ) { 593 if ( empty( $check ) ) { 594 return false; 595 } 596 597 if ( isset( $check->meta_value ) ) { 598 $check->meta_value = maybe_unserialize( $check->meta_value ); 599 } 600 601 return $check; 602 } 603 579 604 $id_column = ( 'user' == $meta_type ) ? 'umeta_id' : 'meta_id'; 580 605 581 606 $meta = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table WHERE $id_column = %d", $meta_id ) ); … … 621 646 $column = sanitize_key($meta_type . '_id'); 622 647 $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id'; 623 648 649 /** 650 * Filter whether to update metadata of a specific type by its meta ID. 651 * 652 * The dynamic portion of the hook, `$meta_type`, refers to the meta 653 * object type (comment, post, or user). Returning a non-null value 654 * will effectively short-circuit the update. 655 * 656 * @since x.y.z 657 * 658 * @param null|bool $check Whether to allow updating metadata for the given type. 659 * @param int $meta_id Meta row ID. 660 * @param mixed $meta_value Meta value. Must be serializable if non-scalar. 661 * @param string|bool $meta_key Meta key to update. 662 */ 663 $check = apply_filters( "update_{$meta_type}_meta_by_mid", null, $meta_id, $meta_value, $meta_key ); 664 if ( null !== $check ) { 665 return false; 666 } 667 624 668 // Fetch the meta and go on if it's found. 625 669 if ( $meta = get_metadata_by_mid( $meta_type, $meta_id ) ) { 626 670 $original_key = $meta->meta_key; … … 711 755 $column = sanitize_key($meta_type . '_id'); 712 756 $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id'; 713 757 758 /** 759 * Filter whether to delete metadata of a specific type by its meta ID. 760 * 761 * The dynamic portion of the hook, `$meta_type`, refers to the meta 762 * object type (comment, post, or user). Returning a non-null value 763 * will effectively short-circuit the deletion. 764 * 765 * @since x.y.z 766 * 767 * @param null|bool $check Whether to allow deleting metadata for the given type. 768 * @param int $meta_id Meta row ID. 769 */ 770 $check = apply_filters( "delete_{$meta_type}_meta_by_mid", null, $meta_id ); 771 if ( null !== $check ) { 772 return false; 773 } 774 714 775 // Fetch the meta and go on if it's found. 715 776 if ( $meta = get_metadata_by_mid( $meta_type, $meta_id ) ) { 716 777 $object_id = $meta->{$column}; -
tests/phpunit/tests/meta.php
31 31 $this->assertFalse( delete_metadata_by_mid( 'user', 0 ) ); 32 32 $this->assertFalse( delete_metadata_by_mid( 'non_existing_meta', $this->delete_meta_id ) ); 33 33 34 // Test short-circuiting deletion. 35 add_filter( 'delete_user_meta_by_mid', '__return_true' ); 36 $this->assertFalse( delete_metadata_by_mid( 'user', $this->delete_meta_id ) ); 37 remove_filter( 'delete_user_meta_by_mid', '__return_true' ); 38 34 39 // Now let's delete the real meta data 35 40 $this->assertTrue( delete_metadata_by_mid( 'user', $this->delete_meta_id ) ); 36 41 … … 76 81 $this->assertTrue( update_metadata_by_mid( 'user', $this->meta_id, 'other_meta_value' ) ); 77 82 $second = get_user_meta( $meta->user_id, $meta->meta_key ); 78 83 $this->assertFalse( $first === $second ); 84 85 // Test short-circuiting updates. 86 add_filter( 'update_user_meta_by_mid', '__return_true' ); 87 $this->assertFalse( update_metadata_by_mid( 'user', $this->meta_id, 'meta_new_value' ) ); 88 remove_filter( 'update_user_meta_by_mid', '__return_true' ); 79 89 } 80 90 81 91 /**