diff --git a/inc/meta-box-html.php b/inc/meta-box-html.php index 85fffc4..c7c4227 100644 --- a/inc/meta-box-html.php +++ b/inc/meta-box-html.php @@ -305,14 +305,14 @@ public function boolean_input( $meta_key, $value, $required, $label, $form_id = public function link_input( $meta_key, $value, $required, $label, $form_id = NULL ) { $post_id = get_the_ID(); - $existing = get_post_meta( $post_id, $meta_key, false); + $existing = get_post_meta( $post_id, $meta_key, true); ?> $url, 1 => $text ); - $existing = get_post_meta( $post_ID, $field['meta_key'], $single = false ); + $full_link = array( 'url' => $url, 'text' => $text ); + $existing = get_post_meta( $post_ID, $field['meta_key'], $single = true ); if ( empty( $_POST["{$field['meta_key']}_url"] ) or empty( $_POST["{$field['meta_key']}_text"] ) ) { delete_post_meta( $post_ID, $field['meta_key']); } elseif ( empty($existing) ) { - add_post_meta( $post_ID, $field['meta_key'], $url, false ); - add_post_meta( $post_ID, $field['meta_key'], $text, false ); + add_post_meta( $post_ID, $field['meta_key'], $full_link, false ); } elseif ( $existing != $full_link ) { - update_post_meta( $post_ID, $field['meta_key'], $url, $existing[0] ); - update_post_meta( $post_ID, $field['meta_key'], $text, $existing[1] ); + update_post_meta( $post_ID, $field['meta_key'], $full_link, $existing ); } } } diff --git a/tests/test-meta_box_models.php b/tests/test-meta_box_models.php index 7d1e84a..bd47ca4 100644 --- a/tests/test-meta_box_models.php +++ b/tests/test-meta_box_models.php @@ -1301,7 +1301,7 @@ function testValidateLinkExpectsAddPostMetaTwice() { $form->fields = $field; \WP_Mock::wpFunction( 'add_post_meta', - array( 'times' => 2, 'return' => true ) + array( 'times' => 1, 'return' => true ) ); $post = new \StdClass; \WP_Mock::wpFunction('get_post_meta', array( 'times' => 1, 'return' => false) ); @@ -1334,7 +1334,7 @@ function testValidateLinkCountNotGivenExpectsUpdatePostMetaCalledOnce() { $form->fields = $field; \WP_Mock::wpFunction( 'add_post_meta', - array( 'times' => 2, 'return' => true ) + array( 'times' => 1, 'return' => true ) ); $post = new \StdClass; \WP_Mock::wpFunction('get_post_meta', array( 'times' => 1, 'return' => false) ); @@ -1375,7 +1375,7 @@ function testValidateLinkWithExistingDataExpectsDataDeletedAndReplaced() { // ); \WP_Mock::wpFunction( 'update_post_meta', - array( 'times' => 2, 'return' => true) + array( 'times' => 1, 'return' => true) ); \WP_Mock::wpFunction( 'get_post_meta', @@ -1411,7 +1411,7 @@ function testValidateLinkWithExistingDataMatchingSubmittedExpectsNoaction() { 'meta_key' => 'link', 'howto' => "Some howto text", ); - $existing = array( 'http://example.com', 'example.com'); + $existing = array( 'url' => 'http://example.com', 'text' => 'example.com'); $form = new TestNumberField(); $post_id = 1; $form->fields = $field;