Code is Poetry.

WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.



git-svn-id: https://develop.svn.wordpress.org/trunk@42343 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast
2017-11-30 23:09:33 +00:00
parent ec6a089f98
commit 8f95800d52
1103 changed files with 105978 additions and 78184 deletions
+196 -147
View File
@@ -14,7 +14,7 @@
* @return bool
*/
function got_mod_rewrite() {
$got_rewrite = apache_mod_loaded('mod_rewrite', true);
$got_rewrite = apache_mod_loaded( 'mod_rewrite', true );
/**
* Filters whether Apache and mod_rewrite are present.
@@ -65,7 +65,7 @@ function got_url_rewrite() {
* @return array An array of strings from a file (.htaccess ) from between BEGIN and END markers.
*/
function extract_from_markers( $filename, $marker ) {
$result = array ();
$result = array();
if ( ! file_exists( $filename ) ) {
return $result;
@@ -136,7 +136,7 @@ function insert_with_markers( $filename, $marker, $insertion ) {
}
// Split out the existing file into the preceding lines, and those that appear after the marker
$pre_lines = $post_lines = $existing_lines = array();
$pre_lines = $post_lines = $existing_lines = array();
$found_marker = $found_end_marker = false;
foreach ( $lines as $line ) {
if ( ! $found_marker && false !== strpos( $line, $start_marker ) ) {
@@ -164,13 +164,15 @@ function insert_with_markers( $filename, $marker, $insertion ) {
}
// Generate the new file data
$new_file_data = implode( "\n", array_merge(
$pre_lines,
array( $start_marker ),
$insertion,
array( $end_marker ),
$post_lines
) );
$new_file_data = implode(
"\n", array_merge(
$pre_lines,
array( $start_marker ),
$insertion,
array( $end_marker ),
$post_lines
)
);
// Write to the start of the file, and truncate it to that length
fseek( $fp, 0 );
@@ -196,19 +198,20 @@ function insert_with_markers( $filename, $marker, $insertion ) {
* @global WP_Rewrite $wp_rewrite
*/
function save_mod_rewrite_rules() {
if ( is_multisite() )
if ( is_multisite() ) {
return;
}
global $wp_rewrite;
$home_path = get_home_path();
$htaccess_file = $home_path.'.htaccess';
$home_path = get_home_path();
$htaccess_file = $home_path . '.htaccess';
/*
* If the file doesn't already exist check for write access to the directory
* and whether we have some rules. Else check for write access to the file.
*/
if ((!file_exists($htaccess_file) && is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks()) || is_writable($htaccess_file)) {
if ( ( ! file_exists( $htaccess_file ) && is_writable( $home_path ) && $wp_rewrite->using_mod_rewrite_permalinks() ) || is_writable( $htaccess_file ) ) {
if ( got_mod_rewrite() ) {
$rules = explode( "\n", $wp_rewrite->mod_rewrite_rules() );
return insert_with_markers( $htaccess_file, 'WordPress', $rules );
@@ -228,22 +231,23 @@ function save_mod_rewrite_rules() {
*
* @return bool True if web.config was updated successfully
*/
function iis7_save_url_rewrite_rules(){
if ( is_multisite() )
function iis7_save_url_rewrite_rules() {
if ( is_multisite() ) {
return;
}
global $wp_rewrite;
$home_path = get_home_path();
$home_path = get_home_path();
$web_config_file = $home_path . 'web.config';
// Using win_is_writable() instead of is_writable() because of a bug in Windows PHP
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) ) ) {
$rule = $wp_rewrite->iis7_url_rewrite_rules(false, '', '');
if ( ! empty($rule) ) {
return iis7_add_rewrite_rule($web_config_file, $rule);
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 ) ) ) {
$rule = $wp_rewrite->iis7_url_rewrite_rules( false, '', '' );
if ( ! empty( $rule ) ) {
return iis7_add_rewrite_rule( $web_config_file, $rule );
} else {
return iis7_delete_rewrite_rule($web_config_file);
return iis7_delete_rewrite_rule( $web_config_file );
}
}
return false;
@@ -257,14 +261,15 @@ function iis7_save_url_rewrite_rules(){
* @param string $file
*/
function update_recently_edited( $file ) {
$oldfiles = (array ) get_option( 'recently_edited' );
$oldfiles = (array) get_option( 'recently_edited' );
if ( $oldfiles ) {
$oldfiles = array_reverse( $oldfiles );
$oldfiles = array_reverse( $oldfiles );
$oldfiles[] = $file;
$oldfiles = array_reverse( $oldfiles );
$oldfiles = array_unique( $oldfiles );
if ( 5 < count( $oldfiles ))
$oldfiles = array_reverse( $oldfiles );
$oldfiles = array_unique( $oldfiles );
if ( 5 < count( $oldfiles ) ) {
array_pop( $oldfiles );
}
} else {
$oldfiles[] = $file;
}
@@ -283,7 +288,7 @@ function update_recently_edited( $file ) {
function wp_make_theme_file_tree( $allowed_files ) {
$tree_list = array();
foreach ( $allowed_files as $file_name => $absolute_filename ) {
$list = explode( '/', $file_name );
$list = explode( '/', $file_name );
$last_dir = &$tree_list;
foreach ( $list as $dir ) {
$last_dir =& $last_dir[ $dir ];
@@ -309,7 +314,7 @@ function wp_print_theme_file_tree( $tree, $level = 2, $size = 1, $index = 1 ) {
if ( is_array( $tree ) ) {
$index = 0;
$size = count( $tree );
$size = count( $tree );
foreach ( $tree as $label => $theme_file ) :
$index++;
if ( ! is_array( $theme_file ) ) {
@@ -328,9 +333,9 @@ function wp_print_theme_file_tree( $tree, $level = 2, $size = 1, $index = 1 ) {
endforeach;
} else {
$filename = $tree;
$url = add_query_arg(
$url = add_query_arg(
array(
'file' => rawurlencode( $tree ),
'file' => rawurlencode( $tree ),
'theme' => rawurlencode( $stylesheet ),
),
self_admin_url( 'theme-editor.php' )
@@ -372,7 +377,7 @@ function wp_print_theme_file_tree( $tree, $level = 2, $size = 1, $index = 1 ) {
function wp_make_plugin_file_tree( $plugin_editable_files ) {
$tree_list = array();
foreach ( $plugin_editable_files as $plugin_file ) {
$list = explode( '/', preg_replace( '#^.+?/#', '', $plugin_file ) );
$list = explode( '/', preg_replace( '#^.+?/#', '', $plugin_file ) );
$last_dir = &$tree_list;
foreach ( $list as $dir ) {
$last_dir =& $last_dir[ $dir ];
@@ -398,7 +403,7 @@ function wp_print_plugin_file_tree( $tree, $label = '', $level = 2, $size = 1, $
global $file, $plugin;
if ( is_array( $tree ) ) {
$index = 0;
$size = count( $tree );
$size = count( $tree );
foreach ( $tree as $label => $plugin_file ) :
$index++;
if ( ! is_array( $plugin_file ) ) {
@@ -418,7 +423,7 @@ function wp_print_plugin_file_tree( $tree, $label = '', $level = 2, $size = 1, $
} else {
$url = add_query_arg(
array(
'file' => rawurlencode( $tree ),
'file' => rawurlencode( $tree ),
'plugin' => rawurlencode( $plugin ),
),
self_admin_url( 'plugin-editor.php' )
@@ -452,8 +457,9 @@ function wp_print_plugin_file_tree( $tree, $label = '', $level = 2, $size = 1, $
* @param string $value
*/
function update_home_siteurl( $old_value, $value ) {
if ( wp_installing() )
if ( wp_installing() ) {
return;
}
if ( is_multisite() && ms_is_switched() ) {
delete_option( 'rewrite_rules' );
@@ -495,12 +501,13 @@ function wp_reset_vars( $vars ) {
*
* @param string|WP_Error $message
*/
function show_message($message) {
if ( is_wp_error($message) ){
if ( $message->get_error_data() && is_string( $message->get_error_data() ) )
function show_message( $message ) {
if ( is_wp_error( $message ) ) {
if ( $message->get_error_data() && is_string( $message->get_error_data() ) ) {
$message = $message->get_error_message() . ': ' . $message->get_error_data();
else
} else {
$message = $message->get_error_message();
}
}
echo "<p>$message</p>\n";
wp_ob_end_flush_all();
@@ -514,15 +521,17 @@ function show_message($message) {
* @return array
*/
function wp_doc_link_parse( $content ) {
if ( !is_string( $content ) || empty( $content ) )
if ( ! is_string( $content ) || empty( $content ) ) {
return array();
}
if ( !function_exists('token_get_all') )
if ( ! function_exists( 'token_get_all' ) ) {
return array();
}
$tokens = token_get_all( $content );
$count = count( $tokens );
$functions = array();
$tokens = token_get_all( $content );
$count = count( $tokens );
$functions = array();
$ignore_functions = array();
for ( $t = 0; $t < $count - 2; $t++ ) {
if ( ! is_array( $tokens[ $t ] ) ) {
@@ -532,10 +541,10 @@ function wp_doc_link_parse( $content ) {
if ( T_STRING == $tokens[ $t ][0] && ( '(' == $tokens[ $t + 1 ] || '(' == $tokens[ $t + 2 ] ) ) {
// If it's a function or class defined locally, there's not going to be any docs available
if ( ( isset( $tokens[ $t - 2 ][1] ) && in_array( $tokens[ $t - 2 ][1], array( 'function', 'class' ) ) ) || ( isset( $tokens[ $t - 2 ][0] ) && T_OBJECT_OPERATOR == $tokens[ $t - 1 ][0] ) ) {
$ignore_functions[] = $tokens[$t][1];
$ignore_functions[] = $tokens[ $t ][1];
}
// Add this to our stack of unique references
$functions[] = $tokens[$t][1];
$functions[] = $tokens[ $t ][1];
}
}
@@ -555,8 +564,9 @@ function wp_doc_link_parse( $content ) {
$out = array();
foreach ( $functions as $function ) {
if ( in_array( $function, $ignore_functions ) )
if ( in_array( $function, $ignore_functions ) ) {
continue;
}
$out[] = $function;
}
@@ -570,26 +580,29 @@ function wp_doc_link_parse( $content ) {
*/
function set_screen_options() {
if ( isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options']) ) {
if ( isset( $_POST['wp_screen_options'] ) && is_array( $_POST['wp_screen_options'] ) ) {
check_admin_referer( 'screen-options-nonce', 'screenoptionnonce' );
if ( !$user = wp_get_current_user() )
if ( ! $user = wp_get_current_user() ) {
return;
}
$option = $_POST['wp_screen_options']['option'];
$value = $_POST['wp_screen_options']['value'];
$value = $_POST['wp_screen_options']['value'];
if ( $option != sanitize_key( $option ) )
if ( $option != sanitize_key( $option ) ) {
return;
}
$map_option = $option;
$type = str_replace('edit_', '', $map_option);
$type = str_replace('_per_page', '', $type);
if ( in_array( $type, get_taxonomies() ) )
$type = str_replace( 'edit_', '', $map_option );
$type = str_replace( '_per_page', '', $type );
if ( in_array( $type, get_taxonomies() ) ) {
$map_option = 'edit_tags_per_page';
elseif ( in_array( $type, get_post_types() ) )
} elseif ( in_array( $type, get_post_types() ) ) {
$map_option = 'edit_per_page';
else
$option = str_replace('-', '_', $option);
} else {
$option = str_replace( '-', '_', $option );
}
switch ( $map_option ) {
case 'edit_per_page':
@@ -598,7 +611,7 @@ function set_screen_options() {
case 'upload_per_page':
case 'edit_tags_per_page':
case 'plugins_per_page':
// Network admin
// Network admin
case 'sites_network_per_page':
case 'users_network_per_page':
case 'site_users_network_per_page':
@@ -606,11 +619,11 @@ function set_screen_options() {
case 'themes_network_per_page':
case 'site_themes_network_per_page':
$value = (int) $value;
if ( $value < 1 || $value > 999 )
if ( $value < 1 || $value > 999 ) {
return;
}
break;
default:
/**
* Filters a screen option value before it is set.
*
@@ -629,12 +642,13 @@ function set_screen_options() {
*/
$value = apply_filters( 'set-screen-option', false, $option, $value );
if ( false === $value )
if ( false === $value ) {
return;
}
break;
}
update_user_meta($user->ID, $option, $value);
update_user_meta( $user->ID, $option, $value );
$url = remove_query_arg( array( 'pagenum', 'apage', 'paged' ), wp_get_referer() );
if ( isset( $_POST['mode'] ) ) {
@@ -654,22 +668,25 @@ function set_screen_options() {
* @return bool
* @param string $filename The file path to the configuration file
*/
function iis7_rewrite_rule_exists($filename) {
if ( ! file_exists($filename) )
function iis7_rewrite_rule_exists( $filename ) {
if ( ! file_exists( $filename ) ) {
return false;
}
if ( ! class_exists( 'DOMDocument', false ) ) {
return false;
}
$doc = new DOMDocument();
if ( $doc->load($filename) === false )
if ( $doc->load( $filename ) === false ) {
return false;
$xpath = new DOMXPath($doc);
$rules = $xpath->query('/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')] | /configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'WordPress\')]');
if ( $rules->length == 0 )
}
$xpath = new DOMXPath( $doc );
$rules = $xpath->query( '/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')] | /configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'WordPress\')]' );
if ( $rules->length == 0 ) {
return false;
else
} else {
return true;
}
}
/**
@@ -680,28 +697,30 @@ function iis7_rewrite_rule_exists($filename) {
* @param string $filename Name of the configuration file
* @return bool
*/
function iis7_delete_rewrite_rule($filename) {
function iis7_delete_rewrite_rule( $filename ) {
// If configuration file does not exist then rules also do not exist so there is nothing to delete
if ( ! file_exists($filename) )
if ( ! file_exists( $filename ) ) {
return true;
}
if ( ! class_exists( 'DOMDocument', false ) ) {
return false;
}
$doc = new DOMDocument();
$doc = new DOMDocument();
$doc->preserveWhiteSpace = false;
if ( $doc -> load($filename) === false )
if ( $doc->load( $filename ) === false ) {
return false;
$xpath = new DOMXPath($doc);
$rules = $xpath->query('/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')] | /configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'WordPress\')]');
}
$xpath = new DOMXPath( $doc );
$rules = $xpath->query( '/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')] | /configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'WordPress\')]' );
if ( $rules->length > 0 ) {
$child = $rules->item(0);
$child = $rules->item( 0 );
$parent = $child->parentNode;
$parent->removeChild($child);
$parent->removeChild( $child );
$doc->formatOutput = true;
saveDomDocument($doc, $filename);
saveDomDocument( $doc, $filename );
}
return true;
}
@@ -715,74 +734,76 @@ function iis7_delete_rewrite_rule($filename) {
* @param string $rewrite_rule The XML fragment with URL Rewrite rule
* @return bool
*/
function iis7_add_rewrite_rule($filename, $rewrite_rule) {
function iis7_add_rewrite_rule( $filename, $rewrite_rule ) {
if ( ! class_exists( 'DOMDocument', false ) ) {
return false;
}
// If configuration file does not exist then we create one.
if ( ! file_exists($filename) ) {
$fp = fopen( $filename, 'w');
fwrite($fp, '<configuration/>');
fclose($fp);
if ( ! file_exists( $filename ) ) {
$fp = fopen( $filename, 'w' );
fwrite( $fp, '<configuration/>' );
fclose( $fp );
}
$doc = new DOMDocument();
$doc = new DOMDocument();
$doc->preserveWhiteSpace = false;
if ( $doc->load($filename) === false )
if ( $doc->load( $filename ) === false ) {
return false;
}
$xpath = new DOMXPath($doc);
$xpath = new DOMXPath( $doc );
// First check if the rule already exists as in that case there is no need to re-add it
$wordpress_rules = $xpath->query('/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')] | /configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'WordPress\')]');
if ( $wordpress_rules->length > 0 )
$wordpress_rules = $xpath->query( '/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')] | /configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'WordPress\')]' );
if ( $wordpress_rules->length > 0 ) {
return true;
}
// Check the XPath to the rewrite rule and create XML nodes if they do not exist
$xmlnodes = $xpath->query('/configuration/system.webServer/rewrite/rules');
$xmlnodes = $xpath->query( '/configuration/system.webServer/rewrite/rules' );
if ( $xmlnodes->length > 0 ) {
$rules_node = $xmlnodes->item(0);
$rules_node = $xmlnodes->item( 0 );
} else {
$rules_node = $doc->createElement('rules');
$rules_node = $doc->createElement( 'rules' );
$xmlnodes = $xpath->query('/configuration/system.webServer/rewrite');
$xmlnodes = $xpath->query( '/configuration/system.webServer/rewrite' );
if ( $xmlnodes->length > 0 ) {
$rewrite_node = $xmlnodes->item(0);
$rewrite_node->appendChild($rules_node);
$rewrite_node = $xmlnodes->item( 0 );
$rewrite_node->appendChild( $rules_node );
} else {
$rewrite_node = $doc->createElement('rewrite');
$rewrite_node->appendChild($rules_node);
$rewrite_node = $doc->createElement( 'rewrite' );
$rewrite_node->appendChild( $rules_node );
$xmlnodes = $xpath->query('/configuration/system.webServer');
$xmlnodes = $xpath->query( '/configuration/system.webServer' );
if ( $xmlnodes->length > 0 ) {
$system_webServer_node = $xmlnodes->item(0);
$system_webServer_node->appendChild($rewrite_node);
$system_webServer_node = $xmlnodes->item( 0 );
$system_webServer_node->appendChild( $rewrite_node );
} else {
$system_webServer_node = $doc->createElement('system.webServer');
$system_webServer_node->appendChild($rewrite_node);
$system_webServer_node = $doc->createElement( 'system.webServer' );
$system_webServer_node->appendChild( $rewrite_node );
$xmlnodes = $xpath->query('/configuration');
$xmlnodes = $xpath->query( '/configuration' );
if ( $xmlnodes->length > 0 ) {
$config_node = $xmlnodes->item(0);
$config_node->appendChild($system_webServer_node);
$config_node = $xmlnodes->item( 0 );
$config_node->appendChild( $system_webServer_node );
} else {
$config_node = $doc->createElement('configuration');
$doc->appendChild($config_node);
$config_node->appendChild($system_webServer_node);
$config_node = $doc->createElement( 'configuration' );
$doc->appendChild( $config_node );
$config_node->appendChild( $system_webServer_node );
}
}
}
}
$rule_fragment = $doc->createDocumentFragment();
$rule_fragment->appendXML($rewrite_rule);
$rules_node->appendChild($rule_fragment);
$rule_fragment->appendXML( $rewrite_rule );
$rules_node->appendChild( $rule_fragment );
$doc->encoding = "UTF-8";
$doc->encoding = 'UTF-8';
$doc->formatOutput = true;
saveDomDocument($doc, $filename);
saveDomDocument( $doc, $filename );
return true;
}
@@ -795,12 +816,12 @@ function iis7_add_rewrite_rule($filename, $rewrite_rule) {
* @param DOMDocument $doc
* @param string $filename
*/
function saveDomDocument($doc, $filename) {
function saveDomDocument( $doc, $filename ) {
$config = $doc->saveXML();
$config = preg_replace("/([^\r])\n/", "$1\r\n", $config);
$fp = fopen($filename, 'w');
fwrite($fp, $config);
fclose($fp);
$config = preg_replace( "/([^\r])\n/", "$1\r\n", $config );
$fp = fopen( $filename, 'w' );
fwrite( $fp, $config );
fclose( $fp );
}
/**
@@ -819,7 +840,14 @@ function admin_color_scheme_picker( $user_id ) {
if ( isset( $_wp_admin_css_colors['fresh'] ) ) {
// Set Default ('fresh') and Light should go first.
$_wp_admin_css_colors = array_filter( array_merge( array( 'fresh' => '', 'light' => '' ), $_wp_admin_css_colors ) );
$_wp_admin_css_colors = array_filter(
array_merge(
array(
'fresh' => '',
'light' => '',
), $_wp_admin_css_colors
)
);
}
$current_color = get_user_option( 'admin_color', $user_id );
@@ -865,7 +893,6 @@ function admin_color_scheme_picker( $user_id ) {
}
/**
*
* @global array $_wp_admin_css_colors
*/
function wp_color_scheme_settings() {
@@ -884,7 +911,11 @@ function wp_color_scheme_settings() {
$icon_colors = $_wp_admin_css_colors['fresh']->icon_colors;
} else {
// Fall back to the default set of icon colors if the default scheme is missing.
$icon_colors = array( 'base' => '#82878c', 'focus' => '#00a0d2', 'current' => '#fff' );
$icon_colors = array(
'base' => '#82878c',
'focus' => '#00a0d2',
'current' => '#fff',
);
}
echo '<script type="text/javascript">var _wpColorScheme = ' . wp_json_encode( array( 'icons' => $icon_colors ) ) . ";</script>\n";
@@ -916,22 +947,25 @@ function wp_check_locked_posts( $response, $data, $screen_id ) {
if ( array_key_exists( 'wp-check-locked-posts', $data ) && is_array( $data['wp-check-locked-posts'] ) ) {
foreach ( $data['wp-check-locked-posts'] as $key ) {
if ( ! $post_id = absint( substr( $key, 5 ) ) )
if ( ! $post_id = absint( substr( $key, 5 ) ) ) {
continue;
}
if ( ( $user_id = wp_check_post_lock( $post_id ) ) && ( $user = get_userdata( $user_id ) ) && current_user_can( 'edit_post', $post_id ) ) {
$send = array( 'text' => sprintf( __( '%s is currently editing' ), $user->display_name ) );
if ( ( $avatar = get_avatar( $user->ID, 18 ) ) && preg_match( "|src='([^']+)'|", $avatar, $matches ) )
if ( ( $avatar = get_avatar( $user->ID, 18 ) ) && preg_match( "|src='([^']+)'|", $avatar, $matches ) ) {
$send['avatar_src'] = $matches[1];
}
$checked[$key] = $send;
$checked[ $key ] = $send;
}
}
}
if ( ! empty( $checked ) )
if ( ! empty( $checked ) ) {
$response['wp-check-locked-posts'] = $checked;
}
return $response;
}
@@ -949,28 +983,32 @@ function wp_check_locked_posts( $response, $data, $screen_id ) {
function wp_refresh_post_lock( $response, $data, $screen_id ) {
if ( array_key_exists( 'wp-refresh-post-lock', $data ) ) {
$received = $data['wp-refresh-post-lock'];
$send = array();
$send = array();
if ( ! $post_id = absint( $received['post_id'] ) )
if ( ! $post_id = absint( $received['post_id'] ) ) {
return $response;
}
if ( ! current_user_can('edit_post', $post_id) )
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return $response;
}
if ( ( $user_id = wp_check_post_lock( $post_id ) ) && ( $user = get_userdata( $user_id ) ) ) {
$error = array(
'text' => sprintf( __( '%s has taken over and is currently editing.' ), $user->display_name )
'text' => sprintf( __( '%s has taken over and is currently editing.' ), $user->display_name ),
);
if ( $avatar = get_avatar( $user->ID, 64 ) ) {
if ( preg_match( "|src='([^']+)'|", $avatar, $matches ) )
if ( preg_match( "|src='([^']+)'|", $avatar, $matches ) ) {
$error['avatar_src'] = $matches[1];
}
}
$send['lock_error'] = $error;
} else {
if ( $new_lock = wp_set_post_lock( $post_id ) )
if ( $new_lock = wp_set_post_lock( $post_id ) ) {
$send['new_lock'] = implode( ':', $new_lock );
}
}
$response['wp-refresh-post-lock'] = $send;
@@ -991,7 +1029,7 @@ function wp_refresh_post_lock( $response, $data, $screen_id ) {
*/
function wp_refresh_post_nonces( $response, $data, $screen_id ) {
if ( array_key_exists( 'wp-refresh-post-nonces', $data ) ) {
$received = $data['wp-refresh-post-nonces'];
$received = $data['wp-refresh-post-nonces'];
$response['wp-refresh-post-nonces'] = array( 'check' => 1 );
if ( ! $post_id = absint( $received['post_id'] ) ) {
@@ -1003,12 +1041,12 @@ function wp_refresh_post_nonces( $response, $data, $screen_id ) {
}
$response['wp-refresh-post-nonces'] = array(
'replace' => array(
'getpermalinknonce' => wp_create_nonce('getpermalink'),
'samplepermalinknonce' => wp_create_nonce('samplepermalink'),
'closedpostboxesnonce' => wp_create_nonce('closedpostboxes'),
'_ajax_linking_nonce' => wp_create_nonce( 'internal-linking' ),
'_wpnonce' => wp_create_nonce( 'update-post_' . $post_id ),
'replace' => array(
'getpermalinknonce' => wp_create_nonce( 'getpermalink' ),
'samplepermalinknonce' => wp_create_nonce( 'samplepermalink' ),
'closedpostboxesnonce' => wp_create_nonce( 'closedpostboxes' ),
'_ajax_linking_nonce' => wp_create_nonce( 'internal-linking' ),
'_wpnonce' => wp_create_nonce( 'update-post_' . $post_id ),
),
'heartbeatNonce' => wp_create_nonce( 'heartbeat-nonce' ),
);
@@ -1051,14 +1089,23 @@ function heartbeat_autosave( $response, $data ) {
$saved = wp_autosave( $data['wp_autosave'] );
if ( is_wp_error( $saved ) ) {
$response['wp_autosave'] = array( 'success' => false, 'message' => $saved->get_error_message() );
$response['wp_autosave'] = array(
'success' => false,
'message' => $saved->get_error_message(),
);
} elseif ( empty( $saved ) ) {
$response['wp_autosave'] = array( 'success' => false, 'message' => __( 'Error while saving.' ) );
$response['wp_autosave'] = array(
'success' => false,
'message' => __( 'Error while saving.' ),
);
} else {
/* translators: draft saved date format, see https://secure.php.net/date */
$draft_saved_date_format = __( 'g:i:s a' );
/* translators: %s: date and time */
$response['wp_autosave'] = array( 'success' => true, 'message' => sprintf( __( 'Draft saved at %s.' ), date_i18n( $draft_saved_date_format ) ) );
$response['wp_autosave'] = array(
'success' => true,
'message' => sprintf( __( 'Draft saved at %s.' ), date_i18n( $draft_saved_date_format ) ),
);
}
}
@@ -1148,7 +1195,7 @@ function update_option_new_admin_email( $old_value, $value ) {
return;
}
$hash = md5( $value . time() . mt_rand() );
$hash = md5( $value . time() . mt_rand() );
$new_admin_email = array(
'hash' => $hash,
'newemail' => $value,
@@ -1158,7 +1205,8 @@ function update_option_new_admin_email( $old_value, $value ) {
$switched_locale = switch_to_locale( get_user_locale() );
/* translators: Do not translate USERNAME, ADMIN_URL, EMAIL, SITENAME, SITEURL: those are placeholders. */
$email_text = __( 'Howdy ###USERNAME###,
$email_text = __(
'Howdy ###USERNAME###,
You recently requested to have the administration email address on
your site changed.
@@ -1173,7 +1221,8 @@ This email has been sent to ###EMAIL###
Regards,
All at ###SITENAME###
###SITEURL###' );
###SITEURL###'
);
/**
* Filters the text of the email sent when a change of site admin email address is attempted.
@@ -1199,11 +1248,11 @@ All at ###SITENAME###
$content = apply_filters( 'new_admin_email_content', $email_text, $new_admin_email );
$current_user = wp_get_current_user();
$content = str_replace( '###USERNAME###', $current_user->user_login, $content );
$content = str_replace( '###ADMIN_URL###', esc_url( self_admin_url( 'options.php?adminhash=' . $hash ) ), $content );
$content = str_replace( '###EMAIL###', $value, $content );
$content = str_replace( '###SITENAME###', wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), $content );
$content = str_replace( '###SITEURL###', home_url(), $content );
$content = str_replace( '###USERNAME###', $current_user->user_login, $content );
$content = str_replace( '###ADMIN_URL###', esc_url( self_admin_url( 'options.php?adminhash=' . $hash ) ), $content );
$content = str_replace( '###EMAIL###', $value, $content );
$content = str_replace( '###SITENAME###', wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), $content );
$content = str_replace( '###SITEURL###', home_url(), $content );
wp_mail( $value, sprintf( __( '[%s] New Admin Email Address' ), wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ) ), $content );