web/wp-admin/includes/misc.php
changeset 194 32102edaa81b
parent 136 bde1974c263b
child 204 09a1c134465b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
     7  */
     7  */
     8 
     8 
     9 /**
     9 /**
    10  * {@internal Missing Short Description}}
    10  * {@internal Missing Short Description}}
    11  *
    11  *
    12  * @since unknown
    12  * @since 2.0.0
    13  *
    13  *
    14  * @return unknown
    14  * @return unknown
    15  */
    15  */
    16 function got_mod_rewrite() {
    16 function got_mod_rewrite() {
    17 	$got_rewrite = apache_mod_loaded('mod_rewrite', true);
    17 	$got_rewrite = apache_mod_loaded('mod_rewrite', true);
    19 }
    19 }
    20 
    20 
    21 /**
    21 /**
    22  * {@internal Missing Short Description}}
    22  * {@internal Missing Short Description}}
    23  *
    23  *
    24  * @since unknown
    24  * @since 1.5.0
    25  *
    25  *
    26  * @param unknown_type $filename
    26  * @param unknown_type $filename
    27  * @param unknown_type $marker
    27  * @param unknown_type $marker
    28  * @return array An array of strings from a file (.htaccess ) from between BEGIN and END markers.
    28  * @return array An array of strings from a file (.htaccess ) from between BEGIN and END markers.
    29  */
    29  */
    55  *
    55  *
    56  * Inserts an array of strings into a file (.htaccess ), placing it between
    56  * Inserts an array of strings into a file (.htaccess ), placing it between
    57  * BEGIN and END markers. Replaces existing marked info. Retains surrounding
    57  * BEGIN and END markers. Replaces existing marked info. Retains surrounding
    58  * data. Creates file if none exists.
    58  * data. Creates file if none exists.
    59  *
    59  *
    60  * @since unknown
    60  * @since 1.5.0
    61  *
    61  *
    62  * @param unknown_type $filename
    62  * @param unknown_type $filename
    63  * @param unknown_type $marker
    63  * @param unknown_type $marker
    64  * @param unknown_type $insertion
    64  * @param unknown_type $insertion
    65  * @return bool True on write success, false on failure.
    65  * @return bool True on write success, false on failure.
   115  * Updates the htaccess file with the current rules if it is writable.
   115  * Updates the htaccess file with the current rules if it is writable.
   116  *
   116  *
   117  * Always writes to the file if it exists and is writable to ensure that we
   117  * Always writes to the file if it exists and is writable to ensure that we
   118  * blank out old rules.
   118  * blank out old rules.
   119  *
   119  *
   120  * @since unknown
   120  * @since 1.5.0
   121  */
   121  */
   122 function save_mod_rewrite_rules() {
   122 function save_mod_rewrite_rules() {
       
   123 	if ( is_multisite() )
       
   124 		return;
       
   125 
   123 	global $wp_rewrite;
   126 	global $wp_rewrite;
   124 
   127 
   125 	$home_path = get_home_path();
   128 	$home_path = get_home_path();
   126 	$htaccess_file = $home_path.'.htaccess';
   129 	$htaccess_file = $home_path.'.htaccess';
   127 
   130 
   128 	// If the file doesn't already exists check for write access to the directory and whether of not we have some rules.
   131 	// If the file doesn't already exist check for write access to the directory and whether we have some rules.
   129 	// else check for write access to the file.
   132 	// else check for write access to the file.
   130 	if ((!file_exists($htaccess_file) && is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks()) || is_writable($htaccess_file)) {
   133 	if ((!file_exists($htaccess_file) && is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks()) || is_writable($htaccess_file)) {
   131 		if ( got_mod_rewrite() ) {
   134 		if ( got_mod_rewrite() ) {
   132 			$rules = explode( "\n", $wp_rewrite->mod_rewrite_rules() );
   135 			$rules = explode( "\n", $wp_rewrite->mod_rewrite_rules() );
   133 			return insert_with_markers( $htaccess_file, 'WordPress', $rules );
   136 			return insert_with_markers( $htaccess_file, 'WordPress', $rules );
   144  * @since 2.8.0
   147  * @since 2.8.0
   145  *
   148  *
   146  * @return bool True if web.config was updated successfully
   149  * @return bool True if web.config was updated successfully
   147  */
   150  */
   148 function iis7_save_url_rewrite_rules(){
   151 function iis7_save_url_rewrite_rules(){
       
   152 	if ( is_multisite() )
       
   153 		return;
       
   154 
   149 	global $wp_rewrite;
   155 	global $wp_rewrite;
   150 
   156 
   151 	$home_path = get_home_path();
   157 	$home_path = get_home_path();
   152 	$web_config_file = $home_path . 'web.config';
   158 	$web_config_file = $home_path . 'web.config';
   153 
   159 
   154 	// Using win_is_writable() instead of is_writable() because of a bug in Windows PHP
   160 	// Using win_is_writable() instead of is_writable() because of a bug in Windows PHP
   155 	if ( ( ! file_exists($web_config_file) && win_is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks() ) || win_is_writable($web_config_file) ) {
   161 	if ( iis7_supports_permalinks() && ( ( ! file_exists($web_config_file) && win_is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks() ) || win_is_writable($web_config_file) ) ) {
   156 		if ( iis7_supports_permalinks() ) {
   162 		$rule = $wp_rewrite->iis7_url_rewrite_rules(false, '', '');
   157 			$rule = $wp_rewrite->iis7_url_rewrite_rules(false, '', '');
   163 		if ( ! empty($rule) ) {
   158 			if ( ! empty($rule) ) {
   164 			return iis7_add_rewrite_rule($web_config_file, $rule);
   159 				return iis7_add_rewrite_rule($web_config_file, $rule);
   165 		} else {
   160 			} else {
   166 			return iis7_delete_rewrite_rule($web_config_file);
   161 				return iis7_delete_rewrite_rule($web_config_file);
       
   162 			}
       
   163 		}
   167 		}
   164 	}
   168 	}
   165 	return false;
   169 	return false;
   166 }
   170 }
   167 
   171 
   168 /**
   172 /**
   169  * {@internal Missing Short Description}}
   173  * {@internal Missing Short Description}}
   170  *
   174  *
   171  * @since unknown
   175  * @since 1.5.0
   172  *
   176  *
   173  * @param unknown_type $file
   177  * @param unknown_type $file
   174  */
   178  */
   175 function update_recently_edited( $file ) {
   179 function update_recently_edited( $file ) {
   176 	$oldfiles = (array ) get_option( 'recently_edited' );
   180 	$oldfiles = (array ) get_option( 'recently_edited' );
   188 }
   192 }
   189 
   193 
   190 /**
   194 /**
   191  * If siteurl or home changed, flush rewrite rules.
   195  * If siteurl or home changed, flush rewrite rules.
   192  *
   196  *
   193  * @since unknown
   197  * @since 2.1.0
   194  *
   198  *
   195  * @param unknown_type $old_value
   199  * @param string $old_value
   196  * @param unknown_type $value
   200  * @param string $value
   197  */
   201  */
   198 function update_home_siteurl( $old_value, $value ) {
   202 function update_home_siteurl( $old_value, $value ) {
   199 	global $wp_rewrite;
       
   200 
       
   201 	if ( defined( "WP_INSTALLING" ) )
   203 	if ( defined( "WP_INSTALLING" ) )
   202 		return;
   204 		return;
   203 
   205 
   204 	// If home changed, write rewrite rules to new location.
   206 	// If home changed, write rewrite rules to new location.
   205 	$wp_rewrite->flush_rules();
   207 	flush_rewrite_rules();
   206 }
   208 }
   207 
   209 
   208 add_action( 'update_option_home', 'update_home_siteurl', 10, 2 );
   210 add_action( 'update_option_home', 'update_home_siteurl', 10, 2 );
   209 add_action( 'update_option_siteurl', 'update_home_siteurl', 10, 2 );
   211 add_action( 'update_option_siteurl', 'update_home_siteurl', 10, 2 );
   210 
   212 
   211 /**
   213 /**
   212  * {@internal Missing Short Description}}
   214  * Shorten an URL, to be used as link text
   213  *
   215  *
   214  * @since unknown
   216  * @since 1.2.1
   215  *
   217  *
   216  * @param unknown_type $url
   218  * @param string $url
   217  * @return unknown
   219  * @return string
   218  */
   220  */
   219 function url_shorten( $url ) {
   221 function url_shorten( $url ) {
   220 	$short_url = str_replace( 'http://', '', stripslashes( $url ));
   222 	$short_url = str_replace( 'http://', '', stripslashes( $url ));
   221 	$short_url = str_replace( 'www.', '', $short_url );
   223 	$short_url = str_replace( 'www.', '', $short_url );
   222 	if ('/' == substr( $short_url, -1 ))
   224 	$short_url = untrailingslashit( $short_url );
   223 		$short_url = substr( $short_url, 0, -1 );
       
   224 	if ( strlen( $short_url ) > 35 )
   225 	if ( strlen( $short_url ) > 35 )
   225 		$short_url = substr( $short_url, 0, 32 ).'...';
   226 		$short_url = substr( $short_url, 0, 32 ) . '...';
   226 	return $short_url;
   227 	return $short_url;
   227 }
   228 }
   228 
   229 
   229 /**
   230 /**
   230  * {@internal Missing Short Description}}
   231  * Resets global variables based on $_GET and $_POST
   231  *
   232  *
   232  * @since unknown
   233  * This function resets global variables based on the names passed
   233  *
   234  * in the $vars array to the value of $_POST[$var] or $_GET[$var] or ''
   234  * @param unknown_type $vars
   235  * if neither is defined.
       
   236  *
       
   237  * @since 2.0.0
       
   238  *
       
   239  * @param array $vars An array of globals to reset.
   235  */
   240  */
   236 function wp_reset_vars( $vars ) {
   241 function wp_reset_vars( $vars ) {
   237 	for ( $i=0; $i<count( $vars ); $i += 1 ) {
   242 	for ( $i=0; $i<count( $vars ); $i += 1 ) {
   238 		$var = $vars[$i];
   243 		$var = $vars[$i];
   239 		global $$var;
   244 		global $$var;
   240 
   245 
   241 		if (!isset( $$var ) ) {
   246 		if ( empty( $_POST[$var] ) ) {
   242 			if ( empty( $_POST["$var"] ) ) {
   247 			if ( empty( $_GET[$var] ) )
   243 				if ( empty( $_GET["$var"] ) )
   248 				$$var = '';
   244 					$$var = '';
   249 			else
   245 				else
   250 				$$var = $_GET[$var];
   246 					$$var = $_GET["$var"];
   251 		} else {
   247 			} else {
   252 			$$var = $_POST[$var];
   248 				$$var = $_POST["$var"];
       
   249 			}
       
   250 		}
   253 		}
   251 	}
   254 	}
   252 }
   255 }
   253 
   256 
   254 /**
   257 /**
   255  * {@internal Missing Short Description}}
   258  * {@internal Missing Short Description}}
   256  *
   259  *
   257  * @since unknown
   260  * @since 2.1.0
   258  *
   261  *
   259  * @param unknown_type $message
   262  * @param unknown_type $message
   260  */
   263  */
   261 function show_message($message) {
   264 function show_message($message) {
   262 	if( is_wp_error($message) ){
   265 	if ( is_wp_error($message) ){
   263 		if( $message->get_error_data() )
   266 		if ( $message->get_error_data() )
   264 			$message = $message->get_error_message() . ': ' . $message->get_error_data();
   267 			$message = $message->get_error_message() . ': ' . $message->get_error_data();
   265 		else
   268 		else
   266 			$message = $message->get_error_message();
   269 			$message = $message->get_error_message();
   267 	}
   270 	}
   268 	echo "<p>$message</p>\n";
   271 	echo "<p>$message</p>\n";
       
   272 	wp_ob_end_flush_all();
       
   273 	flush();
   269 }
   274 }
   270 
   275 
   271 function wp_doc_link_parse( $content ) {
   276 function wp_doc_link_parse( $content ) {
   272 	if ( !is_string( $content ) || empty( $content ) )
   277 	if ( !is_string( $content ) || empty( $content ) )
   273 		return array();
   278 		return array();
   304 
   309 
   305 	return $out;
   310 	return $out;
   306 }
   311 }
   307 
   312 
   308 /**
   313 /**
   309  * Determines the language to use for CodePress syntax highlighting,
       
   310  * based only on a filename.
       
   311  *
       
   312  * @since 2.8
       
   313  *
       
   314  * @param string $filename The name of the file to be highlighting
       
   315 **/
       
   316 function codepress_get_lang( $filename ) {
       
   317 	$codepress_supported_langs = apply_filters( 'codepress_supported_langs',
       
   318 									array( '.css' => 'css',
       
   319 											'.js' => 'javascript',
       
   320 											'.php' => 'php',
       
   321 											'.html' => 'html',
       
   322 											'.htm' => 'html',
       
   323 											'.txt' => 'text'
       
   324 											) );
       
   325 	$extension = substr( $filename, strrpos( $filename, '.' ) );
       
   326 	if ( $extension && array_key_exists( $extension, $codepress_supported_langs ) )
       
   327 		return $codepress_supported_langs[$extension];
       
   328 
       
   329 	return 'generic';
       
   330 }
       
   331 
       
   332 /**
       
   333  * Adds Javascript required to make CodePress work on the theme/plugin editors.
       
   334  *
       
   335  * This code is attached to the action admin_print_footer_scripts.
       
   336  *
       
   337  * @since 2.8
       
   338 **/
       
   339 function codepress_footer_js() {
       
   340 	// Script-loader breaks CP's automatic path-detection, thus CodePress.path
       
   341 	// CP edits in an iframe, so we need to grab content back into normal form
       
   342 	?><script type="text/javascript">
       
   343 /* <![CDATA[ */
       
   344 var codepress_path = '<?php echo includes_url('js/codepress/'); ?>';
       
   345 jQuery('#template').submit(function(){
       
   346 	if (jQuery('#newcontent_cp').length)
       
   347 		jQuery('#newcontent_cp').val(newcontent.getCode()).removeAttr('disabled');
       
   348 });
       
   349 jQuery('#codepress-on').hide();
       
   350 jQuery('#codepress-off').show();
       
   351 /* ]]> */
       
   352 </script>
       
   353 <?php
       
   354 }
       
   355 
       
   356 /**
       
   357  * Determine whether to use CodePress or not.
       
   358  *
       
   359  * @since 2.8
       
   360 **/
       
   361 function use_codepress() {
       
   362 
       
   363 	if ( isset($_GET['codepress']) ) {
       
   364 		$on = 'on' == $_GET['codepress'] ? 'on' : 'off';
       
   365 		set_user_setting( 'codepress', $on );
       
   366 	} else {
       
   367 		$on = get_user_setting('codepress', 'on');
       
   368 	}
       
   369 
       
   370 	if ( 'on' == $on ) {
       
   371 		add_action( 'admin_print_footer_scripts', 'codepress_footer_js' );
       
   372 		return true;
       
   373 	}
       
   374 
       
   375 	return false;
       
   376 }
       
   377 
       
   378 /**
       
   379  * Saves option for number of rows when listing posts, pages, comments, etc.
   314  * Saves option for number of rows when listing posts, pages, comments, etc.
   380  *
   315  *
   381  * @since 2.8
   316  * @since 2.8
   382 **/
   317 **/
   383 function set_screen_options() {
   318 function set_screen_options() {
   393 		if ( !preg_match( '/^[a-z_-]+$/', $option ) )
   328 		if ( !preg_match( '/^[a-z_-]+$/', $option ) )
   394 			return;
   329 			return;
   395 
   330 
   396 		$option = str_replace('-', '_', $option);
   331 		$option = str_replace('-', '_', $option);
   397 
   332 
   398 		switch ( $option ) {
   333 		$map_option = $option;
       
   334 		$type = str_replace('edit_', '', $map_option);
       
   335 		$type = str_replace('_per_page', '', $type);
       
   336 		if ( in_array($type, get_post_types()) )
       
   337 			$map_option = 'edit_per_page';
       
   338 		if ( in_array( $type, get_taxonomies()) )
       
   339 			$map_option = 'edit_tags_per_page';
       
   340 
       
   341 		switch ( $map_option ) {
   399 			case 'edit_per_page':
   342 			case 'edit_per_page':
   400 			case 'edit_pages_per_page':
   343 			case 'users_per_page':
   401 			case 'edit_comments_per_page':
   344 			case 'edit_comments_per_page':
   402 			case 'upload_per_page':
   345 			case 'upload_per_page':
   403 			case 'categories_per_page':
       
   404 			case 'edit_tags_per_page':
   346 			case 'edit_tags_per_page':
   405 			case 'plugins_per_page':
   347 			case 'plugins_per_page':
       
   348 			// Network admin
       
   349 			case 'sites_network_per_page':
       
   350 			case 'users_network_per_page':
       
   351 			case 'site_users_network_per_page':
       
   352 			case 'plugins_network_per_page':
       
   353 			case 'themes_network_per_page':
       
   354 			case 'site_themes_network_per_page':
   406 				$value = (int) $value;
   355 				$value = (int) $value;
   407 				if ( $value < 1 || $value > 999 )
   356 				if ( $value < 1 || $value > 999 )
   408 					return;
   357 					return;
   409 				break;
   358 				break;
   410 			default:
   359 			default:
   412 				if ( false === $value )
   361 				if ( false === $value )
   413 					return;
   362 					return;
   414 				break;
   363 				break;
   415 		}
   364 		}
   416 
   365 
   417 		update_usermeta($user->ID, $option, $value);
   366 		update_user_meta($user->ID, $option, $value);
   418 		wp_redirect( remove_query_arg( array('pagenum', 'apage', 'paged'), wp_get_referer() ) );
   367 		wp_safe_redirect( remove_query_arg( array('pagenum', 'apage', 'paged'), wp_get_referer() ) );
   419 		exit;
   368 		exit;
   420 	}
   369 	}
   421 }
       
   422 
       
   423 function wp_menu_unfold() {
       
   424 	if ( isset($_GET['unfoldmenu']) ) {
       
   425 		delete_user_setting('mfold');
       
   426 		wp_redirect( remove_query_arg( 'unfoldmenu', stripslashes($_SERVER['REQUEST_URI']) ) );
       
   427 	 	exit;
       
   428 	}
       
   429 }
       
   430 
       
   431 /**
       
   432  * Check if IIS 7 supports pretty permalinks
       
   433  *
       
   434  * @since 2.8.0
       
   435  *
       
   436  * @return bool
       
   437  */
       
   438 function iis7_supports_permalinks() {
       
   439 	global $is_iis7;
       
   440 
       
   441 	$supports_permalinks = false;
       
   442 	if ( $is_iis7 ) {
       
   443 		/* First we check if the DOMDocument class exists. If it does not exist,
       
   444 		 * which is the case for PHP 4.X, then we cannot easily update the xml configuration file,
       
   445 		 * hence we just bail out and tell user that pretty permalinks cannot be used.
       
   446 		 * This is not a big issue because PHP 4.X is going to be depricated and for IIS it
       
   447 		 * is recommended to use PHP 5.X NTS.
       
   448 		 * Next we check if the URL Rewrite Module 1.1 is loaded and enabled for the web site. When
       
   449 		 * URL Rewrite 1.1 is loaded it always sets a server variable called 'IIS_UrlRewriteModule'.
       
   450 		 * Lastly we make sure that PHP is running via FastCGI. This is important because if it runs
       
   451 		 * via ISAPI then pretty permalinks will not work.
       
   452 		 */
       
   453 		$supports_permalinks = class_exists('DOMDocument') && isset($_SERVER['IIS_UrlRewriteModule']) && ( php_sapi_name() == 'cgi-fcgi' );
       
   454 	}
       
   455 
       
   456 	return apply_filters('iis7_supports_permalinks', $supports_permalinks);
       
   457 }
   370 }
   458 
   371 
   459 /**
   372 /**
   460  * Check if rewrite rule for WordPress already exists in the IIS 7 configuration file
   373  * Check if rewrite rule for WordPress already exists in the IIS 7 configuration file
   461  *
   374  *
   472 
   385 
   473 	$doc = new DOMDocument();
   386 	$doc = new DOMDocument();
   474 	if ( $doc->load($filename) === false )
   387 	if ( $doc->load($filename) === false )
   475 		return false;
   388 		return false;
   476 	$xpath = new DOMXPath($doc);
   389 	$xpath = new DOMXPath($doc);
   477 	$rules = $xpath->query('/configuration/system.webServer/rewrite/rules/rule[@name=\'wordpress\']');
   390 	$rules = $xpath->query('/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')]');
   478 	if ( $rules->length == 0 )
   391 	if ( $rules->length == 0 )
   479 		return false;
   392 		return false;
   480 	else
   393 	else
   481 		return true;
   394 		return true;
   482 }
   395 }
   501 	$doc->preserveWhiteSpace = false;
   414 	$doc->preserveWhiteSpace = false;
   502 
   415 
   503 	if ( $doc -> load($filename) === false )
   416 	if ( $doc -> load($filename) === false )
   504 		return false;
   417 		return false;
   505 	$xpath = new DOMXPath($doc);
   418 	$xpath = new DOMXPath($doc);
   506 	$rules = $xpath->query('/configuration/system.webServer/rewrite/rules/rule[@name=\'wordpress\']');
   419 	$rules = $xpath->query('/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')]');
   507 	if ( $rules->length > 0 ) {
   420 	if ( $rules->length > 0 ) {
   508 		$child = $rules->item(0);
   421 		$child = $rules->item(0);
   509 		$parent = $child->parentNode;
   422 		$parent = $child->parentNode;
   510 		$parent->removeChild($child);
   423 		$parent->removeChild($child);
   511 		$doc->formatOutput = true;
   424 		$doc->formatOutput = true;
   541 		return false;
   454 		return false;
   542 
   455 
   543 	$xpath = new DOMXPath($doc);
   456 	$xpath = new DOMXPath($doc);
   544 
   457 
   545 	// First check if the rule already exists as in that case there is no need to re-add it
   458 	// First check if the rule already exists as in that case there is no need to re-add it
   546 	$wordpress_rules = $xpath->query('/configuration/system.webServer/rewrite/rules/rule[@name=\'wordpress\']');
   459 	$wordpress_rules = $xpath->query('/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')]');
   547 	if ( $wordpress_rules->length > 0 )
   460 	if ( $wordpress_rules->length > 0 )
   548 		return true;
   461 		return true;
   549 
   462 
   550 	// Check the XPath to the rewrite rule and create XML nodes if they do not exist
   463 	// Check the XPath to the rewrite rule and create XML nodes if they do not exist
   551 	$xmlnodes = $xpath->query('/configuration/system.webServer/rewrite/rules');
   464 	$xmlnodes = $xpath->query('/configuration/system.webServer/rewrite/rules');
   613 /**
   526 /**
   614  * Workaround for Windows bug in is_writable() function
   527  * Workaround for Windows bug in is_writable() function
   615  *
   528  *
   616  * @since 2.8.0
   529  * @since 2.8.0
   617  *
   530  *
   618  * @param object $path
   531  * @param string $path
   619  * @return bool
   532  * @return bool
   620  */
   533  */
   621 function win_is_writable($path) {
   534 function win_is_writable( $path ) {
   622 	/* will work in despite of Windows ACLs bug
   535 	/* will work in despite of Windows ACLs bug
   623 	 * NOTE: use a trailing slash for folders!!!
   536 	 * NOTE: use a trailing slash for folders!!!
   624 	 * see http://bugs.php.net/bug.php?id=27609
   537 	 * see http://bugs.php.net/bug.php?id=27609
   625 	 * see http://bugs.php.net/bug.php?id=30931
   538 	 * see http://bugs.php.net/bug.php?id=30931
   626 	 */
   539 	 */
   627 
   540 
   628     if ( $path{strlen($path)-1} == '/' ) // recursively return a temporary file path
   541 	if ( $path[strlen( $path ) - 1] == '/' ) // recursively return a temporary file path
   629         return win_is_writable($path . uniqid(mt_rand()) . '.tmp');
   542 		return win_is_writable( $path . uniqid( mt_rand() ) . '.tmp');
   630     else if ( is_dir($path) )
   543 	else if ( is_dir( $path ) )
   631         return win_is_writable($path . '/' . uniqid(mt_rand()) . '.tmp');
   544 		return win_is_writable( $path . '/' . uniqid( mt_rand() ) . '.tmp' );
   632     // check tmp file for read/write capabilities
   545 	// check tmp file for read/write capabilities
   633     $rm = file_exists($path);
   546 	$should_delete_tmp_file = !file_exists( $path );
   634     $f = @fopen($path, 'a');
   547 	$f = @fopen( $path, 'a' );
   635     if ($f===false)
   548 	if ( $f === false )
   636         return false;
   549 		return false;
   637     fclose($f);
   550 	fclose( $f );
   638     if ( ! $rm )
   551 	if ( $should_delete_tmp_file )
   639         unlink($path);
   552 		unlink( $path );
   640     return true;
   553 	return true;
   641 }
   554 }
   642 ?>
   555 
       
   556 /**
       
   557  * Display the default admin color scheme picker (Used in user-edit.php)
       
   558  *
       
   559  * @since 3.0.0
       
   560  */
       
   561 function admin_color_scheme_picker() {
       
   562 	global $_wp_admin_css_colors, $user_id; ?>
       
   563 <fieldset><legend class="screen-reader-text"><span><?php _e('Admin Color Scheme')?></span></legend>
       
   564 <?php
       
   565 $current_color = get_user_option('admin_color', $user_id);
       
   566 if ( empty($current_color) )
       
   567 	$current_color = 'fresh';
       
   568 foreach ( $_wp_admin_css_colors as $color => $color_info ): ?>
       
   569 <div class="color-option"><input name="admin_color" id="admin_color_<?php echo $color; ?>" type="radio" value="<?php echo esc_attr($color) ?>" class="tog" <?php checked($color, $current_color); ?> />
       
   570 	<table class="color-palette">
       
   571 	<tr>
       
   572 	<?php foreach ( $color_info->colors as $html_color ): ?>
       
   573 	<td style="background-color: <?php echo $html_color ?>" title="<?php echo $color ?>">&nbsp;</td>
       
   574 	<?php endforeach; ?>
       
   575 	</tr>
       
   576 	</table>
       
   577 
       
   578 	<label for="admin_color_<?php echo $color; ?>"><?php echo $color_info->name ?></label>
       
   579 </div>
       
   580 	<?php endforeach; ?>
       
   581 </fieldset>
       
   582 <?php
       
   583 }
       
   584 
       
   585 function _ipad_meta() {
       
   586 	if ( wp_is_mobile() ) {
       
   587 		?>
       
   588 		<meta name="viewport" id="viewport-meta" content="width=device-width, initial-scale=1">
       
   589 		<?php
       
   590 	}
       
   591 }
       
   592 add_action('admin_head', '_ipad_meta');