Changeset 34951
- Timestamp:
- 10/08/2015 07:06:32 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/template-functions.php
r34893 r34951 848 848 849 849 /** 850 * Add a meta box to an edit form.850 * Adds a meta box to one or more screens. 851 851 * 852 852 * @since 2.5.0 853 * @since 4.4.0 The `$screen` parameter now accepts an array of screen IDs. 853 854 * 854 855 * @global array $wp_meta_boxes … … 858 859 * @param callable $callback Function that fills the box with the desired content. 859 860 * The function should echo its output. 860 * @param string|WP_Screen $screen Optional. The screen on which to show the box (like a post 861 * type, 'link', or 'comment'). Default is the current screen. 861 * @param string|array|WP_Screen $screen Optional. The screen or screens on which to show the box 862 * (such as a post type, 'link', or 'comment'). Accepts a single 863 * screen ID, WP_Screen object, or array of screen IDs. Default 864 * is the current screen. 862 865 * @param string $context Optional. The context within the screen where the boxes 863 866 * should display. Available contexts vary from screen to … … 875 878 global $wp_meta_boxes; 876 879 877 if ( empty( $screen ) ) 880 if ( empty( $screen ) ) { 878 881 $screen = get_current_screen(); 879 elseif ( is_string( $screen ) )882 } elseif ( is_string( $screen ) ) { 880 883 $screen = convert_to_screen( $screen ); 884 } elseif ( is_array( $screen ) ) { 885 foreach ( $screen as $single_screen ) { 886 add_meta_box( $id, $title, $callback, $single_screen, $context, $priority, $callback_args ); 887 } 888 } 889 890 if ( ! isset( $screen->id ) ) { 891 return; 892 } 881 893 882 894 $page = $screen->id; … … 1012 1024 1013 1025 /** 1014 * Remove a meta box from an edit form.1026 * Removes a meta box from one or more screens. 1015 1027 * 1016 1028 * @since 2.6.0 1029 * @since 4.4.0 The `$screen` parameter now accepts an array of screen IDs. 1017 1030 * 1018 1031 * @global array $wp_meta_boxes 1019 1032 * 1020 1033 * @param string $id String for use in the 'id' attribute of tags. 1021 * @param string|object $screen The screen on which to show the box (post, page, link). 1034 * @param string|array|WP_Screen $screen The screen or screens on which the meta box is shown (such as a 1035 * post type, 'link', or 'comment'). Accepts a single screen ID, 1036 * WP_Screen object, or array of screen IDs. 1022 1037 * @param string $context The context within the page where the boxes should show ('normal', 'advanced'). 1023 1038 */ 1024 function remove_meta_box( $id, $screen, $context) {1039 function remove_meta_box( $id, $screen, $context ) { 1025 1040 global $wp_meta_boxes; 1026 1041 1027 if ( empty( $screen ) ) 1042 if ( empty( $screen ) ) { 1028 1043 $screen = get_current_screen(); 1029 elseif ( is_string( $screen ) )1044 } elseif ( is_string( $screen ) ) { 1030 1045 $screen = convert_to_screen( $screen ); 1046 } elseif ( is_array( $screen ) ) { 1047 foreach ( $screen as $single_screen ) { 1048 remove_meta_box( $id, $single_screen, $context ); 1049 } 1050 } 1051 1052 if ( ! isset( $screen->id ) ) { 1053 return; 1054 } 1031 1055 1032 1056 $page = $screen->id; -
trunk/tests/phpunit/tests/admin/includesTemplate.php
r25002 r34951 46 46 $this->assertEquals('', checked(0,false,false)); 47 47 } 48 49 public function test_add_meta_box() { 50 global $wp_meta_boxes; 51 52 add_meta_box( 'testbox1', 'Test Metabox', '__return_false', 'post' ); 53 54 $this->assertArrayHasKey( 'testbox1', $wp_meta_boxes['post']['advanced']['default'] ); 55 } 56 57 public function test_remove_meta_box() { 58 global $wp_meta_boxes; 59 60 // Add a meta boxes to remove. 61 add_meta_box( 'testbox1', 'Test Metabox', '__return_false', $current_screen = 'post' ); 62 63 // Confirm it's there. 64 $this->assertArrayHasKey( 'testbox1', $wp_meta_boxes[ $current_screen ]['advanced']['default'] ); 65 66 // Remove the meta box. 67 remove_meta_box( 'testbox1', $current_screen, 'advanced' ); 68 69 // Check that it was removed properly (The meta box should be set to false once that it has been removed) 70 $this->assertFalse( $wp_meta_boxes[ $current_screen ]['advanced']['default']['testbox1'] ); 71 } 72 73 /** 74 * @ticket 15000 75 */ 76 public function test_add_meta_box_on_multiple_screens() { 77 global $wp_meta_boxes; 78 79 // Add a meta box to three different post types 80 add_meta_box( 'testbox1', 'Test Metabox', '__return_false', array( 'post', 'comment', 'attachment' ) ); 81 82 $this->assertArrayHasKey( 'testbox1', $wp_meta_boxes['post']['advanced']['default'] ); 83 $this->assertArrayHasKey( 'testbox1', $wp_meta_boxes['comment']['advanced']['default'] ); 84 $this->assertArrayHasKey( 'testbox1', $wp_meta_boxes['attachment']['advanced']['default'] ); 85 } 86 87 /** 88 * @ticket 15000 89 */ 90 public function test_remove_meta_box_from_multiple_screens() { 91 global $wp_meta_boxes; 92 93 // Add a meta box to three different screens. 94 add_meta_box( 'testbox1', 'Test Metabox', '__return_false', array( 'post', 'comment', 'attachment' ) ); 95 96 // Remove meta box from posts. 97 remove_meta_box( 'testbox1', 'post', 'advanced' ); 98 99 // Check that we have removed the meta boxes only from posts 100 $this->assertFalse( $wp_meta_boxes['post']['advanced']['default']['testbox1'] ); 101 $this->assertArrayHasKey( 'testbox1', $wp_meta_boxes['comment']['advanced']['default'] ); 102 $this->assertArrayHasKey( 'testbox1', $wp_meta_boxes['attachment']['advanced']['default'] ); 103 104 // Remove the meta box from the other screens. 105 remove_meta_box( 'testbox1', array( 'comment', 'attachment' ), 'advanced' ); 106 107 $this->assertFalse( $wp_meta_boxes['comment']['advanced']['default']['testbox1'] ); 108 $this->assertFalse( $wp_meta_boxes['attachment']['advanced']['default']['testbox1'] ); 109 } 110 48 111 }
Note: See TracChangeset
for help on using the changeset viewer.