Ticket #18088: 18088.5.diff
| File 18088.5.diff, 6.2 KB (added by , 9 years ago) |
|---|
-
src/wp-admin/includes/template.php
1394 1394 * action hook). 1395 1395 * 1396 1396 * @since 3.0.0 1397 * @since 4.7.0 The function now supports getting network settings errors from a transient. 1397 1398 * 1398 1399 * @global array $wp_settings_errors Storage array of errors registered during this pageload 1399 1400 * … … 1412 1413 if ( $sanitize ) 1413 1414 sanitize_option( $setting, get_option( $setting ) ); 1414 1415 1415 // If settings were passed back from options.php then use them.1416 // If settings were passed back from options.php or network/settings.php then use them. 1416 1417 if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] && get_transient( 'settings_errors' ) ) { 1417 1418 $wp_settings_errors = array_merge( (array) $wp_settings_errors, get_transient( 'settings_errors' ) ); 1418 1419 delete_transient( 'settings_errors' ); 1420 } elseif ( is_network_admin() && isset( $_GET['updated'] ) && $_GET['updated'] && get_site_transient( 'settings_errors' ) ) { 1421 $wp_settings_errors = array_merge( (array) $wp_settings_errors, get_site_transient( 'settings_errors' ) ); 1422 delete_site_transient( 'settings_errors' ); 1419 1423 } 1420 1424 1421 1425 // Check global in case errors have been added on this pageload. -
src/wp-admin/network/settings.php
84 84 */ 85 85 do_action( 'update_wpmu_options' ); 86 86 87 // If no settings errors were registered, add a general 'updated' message. 88 if ( ! count( get_settings_errors() ) ) { 89 add_settings_error( 'general', 'settings_updated', __( 'Settings saved.' ), 'updated' ); 90 } 91 92 set_site_transient( 'settings_errors', get_settings_errors(), 30 ); 93 87 94 wp_redirect( add_query_arg( 'updated', 'true', network_admin_url( 'settings.php' ) ) ); 88 95 exit(); 89 96 } … … 91 98 include( ABSPATH . 'wp-admin/admin-header.php' ); 92 99 93 100 if ( isset( $_GET['updated'] ) ) { 94 ?><div id="message" class="updated notice is-dismissible"><p><?php _e( 'Settings saved.' ) ?></p></div><?php101 settings_errors(); 95 102 } 96 103 ?> 97 104 -
tests/phpunit/tests/admin/includesTemplate.php
50 50 global $wp_meta_boxes; 51 51 52 52 add_meta_box( 'testbox1', 'Test Metabox', '__return_false', 'post' ); 53 53 54 54 $this->assertArrayHasKey( 'testbox1', $wp_meta_boxes['post']['advanced']['default'] ); 55 55 } 56 56 … … 79 79 // Add a meta box to three different post types 80 80 add_meta_box( 'testbox1', 'Test Metabox', '__return_false', array( 'post', 'comment', 'attachment' ) ); 81 81 82 $this->assertArrayHasKey( 'testbox1', $wp_meta_boxes['post']['advanced']['default'] ); 82 $this->assertArrayHasKey( 'testbox1', $wp_meta_boxes['post']['advanced']['default'] ); 83 83 $this->assertArrayHasKey( 'testbox1', $wp_meta_boxes['comment']['advanced']['default'] ); 84 84 $this->assertArrayHasKey( 'testbox1', $wp_meta_boxes['attachment']['advanced']['default'] ); 85 85 } … … 108 108 $this->assertFalse( $wp_meta_boxes['attachment']['advanced']['default']['testbox1'] ); 109 109 } 110 110 111 } 112 No newline at end of file 111 /** 112 * @ticket 18088 113 */ 114 public function test_get_settings_errors() { 115 global $wp_settings_errors; 116 117 $_orig_settings_errors = $wp_settings_errors; 118 119 $wp_settings_errors = array(); 120 121 $foo_codes = range( 0, 4 ); 122 $bar_codes = range( 13, 16 ); 123 124 foreach ( $foo_codes as $foo_code ) { 125 $wp_settings_errors[] = array( 126 'setting' => 'foo', 127 'code' => $foo_code, 128 'message' => 'Foo.', 129 'type' => 'error', 130 ); 131 } 132 133 foreach ( $bar_codes as $bar_code ) { 134 $wp_settings_errors[] = array( 135 'setting' => 'bar', 136 'code' => $bar_code, 137 'message' => 'Bar.', 138 'type' => 'error', 139 ); 140 } 141 142 // Get all settings errors. 143 $result = get_settings_errors(); 144 $this->assertEquals( array_merge( $foo_codes, $bar_codes ), wp_list_pluck( $result, 'code' ) ); 145 146 // Get all foo errors. 147 $result = get_settings_errors( 'foo' ); 148 $this->assertEquals( $foo_codes, wp_list_pluck( $result, 'code' ) ); 149 150 // Get all foobar errors. 151 $result = get_settings_errors( 'foobar' ); 152 $this->assertEmpty( $result ); 153 154 $wp_settings_errors = $_orig_settings_errors; 155 } 156 157 /** 158 * @ticket 18088 159 */ 160 public function test_get_settings_errors_transient() { 161 global $wp_settings_errors; 162 163 $_orig_settings_errors = $wp_settings_errors; 164 165 $wp_settings_errors = array(); 166 167 $codes = range( 0, 4 ); 168 169 $errors = array(); 170 foreach ( $codes as $code ) { 171 $errors[] = array( 172 'setting' => 'foo', 173 'code' => $code, 174 'message' => 'Foo.', 175 'type' => 'error', 176 ); 177 } 178 179 set_transient( 'settings_errors', $errors, 30 ); 180 181 $_GET['settings-updated'] = 'true'; 182 183 $result = get_settings_errors(); 184 $this->assertEquals( $codes, wp_list_pluck( $result, 'code' ) ); 185 186 unset( $_GET['settings-updated'] ); 187 188 $wp_settings_errors = $_orig_settings_errors; 189 } 190 191 /** 192 * @ticket 18088 193 */ 194 public function test_get_settings_errors_network_transient() { 195 if ( ! is_multisite() ) { 196 $this->markTestSkipped( 'Test only runs in multisite' ); 197 } 198 199 global $wp_settings_errors, $current_screen; 200 201 $_orig_settings_errors = $wp_settings_errors; 202 $_orig_screen = $current_screen; 203 204 $wp_settings_errors = array(); 205 $current_screen = WP_Screen::get( 'dashboard-network' ); 206 207 $codes = range( 3, 8 ); 208 209 $errors = array(); 210 foreach ( $codes as $code ) { 211 $errors[] = array( 212 'setting' => 'foo', 213 'code' => $code, 214 'message' => 'Foo.', 215 'type' => 'error', 216 ); 217 } 218 219 set_site_transient( 'settings_errors', $errors, 30 ); 220 221 $_GET['updated'] = 'true'; 222 223 $result = get_settings_errors(); 224 $this->assertEquals( $codes, wp_list_pluck( $result, 'code' ) ); 225 226 unset( $_GET['updated'] ); 227 228 $wp_settings_errors = $_orig_settings_errors; 229 $current_screen = $_orig_screen; 230 } 231 232 }