Make WordPress Core

Changeset 43811


Ignore:
Timestamp:
10/23/2018 06:55:45 PM (6 years ago)
Author:
danielbachhuber
Message:

Meta: Allow empty strings to be set by Custom Fields meta box.

Because the REST API allows meta keys to have empty values, the Custom Fields meta box should permit the same behavior.

Props charlestonsw, soulseekah.
Fixes #43559.

Location:
branches/5.0
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0/src/wp-admin/includes/ajax-actions.php

    r43807 r43811  
    13421342        if ( '' == trim($key) )
    13431343            wp_die( __( 'Please provide a custom field name.' ) );
    1344         if ( '' == trim($value) )
    1345             wp_die( __( 'Please provide a custom field value.' ) );
    13461344        if ( ! $meta = get_metadata_by_mid( 'post', $mid ) )
    13471345            wp_die( 0 ); // if meta doesn't exist
  • branches/5.0/src/wp-admin/includes/post.php

    r43792 r43811  
    815815        $metavalue = trim( $metavalue );
    816816
    817     if ( ('0' === $metavalue || ! empty ( $metavalue ) ) && ( ( ( '#NONE#' != $metakeyselect ) && !empty ( $metakeyselect) ) || !empty ( $metakeyinput ) ) ) {
     817    if ( ( ( '#NONE#' != $metakeyselect ) && ! empty( $metakeyselect ) ) || ! empty( $metakeyinput ) ) {
    818818        /*
    819819         * We have a key/value pair. If both the select and the input
  • branches/5.0/tests/phpunit/tests/admin/includesPost.php

    r43762 r43811  
    708708        $this->assertSame( array( 'icon' => 'text' ), $blocks[ $name ] );
    709709    }
     710
     711    /**
     712     * @ticket 43559
     713     */
     714    public function test_post_add_meta_empty_is_allowed() {
     715        $p     = self::factory()->post->create();
     716
     717        $_POST = array(
     718            'metakeyinput' => 'testkey',
     719            'metavalue'    => '',
     720        );
     721
     722        wp_set_current_user( self::$admin_id );
     723
     724        $this->assertNotFalse( add_meta( $p ) );
     725        $this->assertEquals( '', get_post_meta( $p, 'testkey', true ) );
     726    }
    710727}
Note: See TracChangeset for help on using the changeset viewer.