Changeset 52721 for trunk/src/wp-admin/includes/misc.php
- Timestamp:
- 02/13/2022 05:07:09 PM (4 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-admin/includes/misc.php (modified) (49 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/misc.php
r52406 r52721 75 75 76 76 $state = false; 77 77 78 foreach ( $markerdata as $markerline ) { 78 79 if ( false !== strpos( $markerline, '# END ' . $marker ) ) { 79 80 $state = false; 80 81 } 82 81 83 if ( $state ) { 82 84 if ( '#' === substr( $markerline, 0, 1 ) ) { 83 85 continue; 84 86 } 87 85 88 $result[] = $markerline; 86 89 } 90 87 91 if ( false !== strpos( $markerline, '# BEGIN ' . $marker ) ) { 88 92 $state = true; … … 119 123 // Make sure the file is created with a minimum set of permissions. 120 124 $perms = fileperms( $filename ); 125 121 126 if ( $perms ) { 122 127 chmod( $filename, $perms | 0644 ); … … 143 148 144 149 $instructions = explode( "\n", $instructions ); 150 145 151 foreach ( $instructions as $line => $text ) { 146 152 $instructions[ $line ] = '# ' . $text; … … 167 173 168 174 $fp = fopen( $filename, 'r+' ); 175 169 176 if ( ! $fp ) { 170 177 return false; … … 175 182 176 183 $lines = array(); 184 177 185 while ( ! feof( $fp ) ) { 178 186 $lines[] = rtrim( fgets( $fp ), "\r\n" ); … … 185 193 $found_marker = false; 186 194 $found_end_marker = false; 195 187 196 foreach ( $lines as $line ) { 188 197 if ( ! $found_marker && false !== strpos( $line, $start_marker ) ) { … … 193 202 continue; 194 203 } 204 195 205 if ( ! $found_marker ) { 196 206 $pre_lines[] = $line; … … 225 235 fseek( $fp, 0 ); 226 236 $bytes = fwrite( $fp, $new_file_data ); 237 227 238 if ( $bytes ) { 228 239 ftruncate( $fp, ftell( $fp ) ); 229 240 } 241 230 242 fflush( $fp ); 231 243 flock( $fp, LOCK_UN ); … … 248 260 */ 249 261 function save_mod_rewrite_rules() { 262 global $wp_rewrite; 263 250 264 if ( is_multisite() ) { 251 265 return; 252 266 } 253 254 global $wp_rewrite;255 267 256 268 // Ensure get_home_path() is declared. … … 264 276 * and whether we have some rules. Else check for write access to the file. 265 277 */ 266 if ( ( ! file_exists( $htaccess_file ) && is_writable( $home_path ) && $wp_rewrite->using_mod_rewrite_permalinks() ) || is_writable( $htaccess_file ) ) { 278 if ( ! file_exists( $htaccess_file ) && is_writable( $home_path ) && $wp_rewrite->using_mod_rewrite_permalinks() 279 || is_writable( $htaccess_file ) 280 ) { 267 281 if ( got_mod_rewrite() ) { 268 282 $rules = explode( "\n", $wp_rewrite->mod_rewrite_rules() ); 283 269 284 return insert_with_markers( $htaccess_file, 'WordPress', $rules ); 270 285 } … … 285 300 */ 286 301 function iis7_save_url_rewrite_rules() { 302 global $wp_rewrite; 303 287 304 if ( is_multisite() ) { 288 305 return; 289 306 } 290 307 291 global $wp_rewrite;292 293 308 // Ensure get_home_path() is declared. 294 309 require_once ABSPATH . 'wp-admin/includes/file.php'; … … 298 313 299 314 // Using win_is_writable() instead of is_writable() because of a bug in Windows PHP. 300 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 ) ) ) { 315 if ( iis7_supports_permalinks() 316 && ( ! file_exists( $web_config_file ) && win_is_writable( $home_path ) && $wp_rewrite->using_mod_rewrite_permalinks() 317 || win_is_writable( $web_config_file ) ) 318 ) { 301 319 $rule = $wp_rewrite->iis7_url_rewrite_rules( false ); 320 302 321 if ( ! empty( $rule ) ) { 303 322 return iis7_add_rewrite_rule( $web_config_file, $rule ); … … 306 325 } 307 326 } 327 308 328 return false; 309 329 } … … 318 338 function update_recently_edited( $file ) { 319 339 $oldfiles = (array) get_option( 'recently_edited' ); 340 320 341 if ( $oldfiles ) { 321 342 $oldfiles = array_reverse( $oldfiles ); … … 323 344 $oldfiles = array_reverse( $oldfiles ); 324 345 $oldfiles = array_unique( $oldfiles ); 346 325 347 if ( 5 < count( $oldfiles ) ) { 326 348 array_pop( $oldfiles ); … … 329 351 $oldfiles[] = $file; 330 352 } 353 331 354 update_option( 'recently_edited', $oldfiles ); 332 355 } … … 343 366 function wp_make_theme_file_tree( $allowed_files ) { 344 367 $tree_list = array(); 368 345 369 foreach ( $allowed_files as $file_name => $absolute_filename ) { 346 370 $list = explode( '/', $file_name ); 347 371 $last_dir = &$tree_list; 372 348 373 foreach ( $list as $dir ) { 349 374 $last_dir =& $last_dir[ $dir ]; 350 375 } 376 351 377 $last_dir = $file_name; 352 378 } 379 353 380 return $tree_list; 354 381 } … … 375 402 $index = 0; 376 403 $size = count( $tree ); 404 377 405 foreach ( $tree as $label => $theme_file ) : 378 406 $index++; 407 379 408 if ( ! is_array( $theme_file ) ) { 380 409 wp_print_theme_file_tree( $theme_file, $level, $index, $size ); … … 409 438 <?php 410 439 $file_description = esc_html( get_file_description( $filename ) ); 440 411 441 if ( $file_description !== $filename && wp_basename( $filename ) !== $file_description ) { 412 442 $file_description .= '<br /><span class="nonessential">(' . esc_html( $filename ) . ')</span>'; … … 436 466 function wp_make_plugin_file_tree( $plugin_editable_files ) { 437 467 $tree_list = array(); 468 438 469 foreach ( $plugin_editable_files as $plugin_file ) { 439 470 $list = explode( '/', preg_replace( '#^.+?/#', '', $plugin_file ) ); 440 471 $last_dir = &$tree_list; 472 441 473 foreach ( $list as $dir ) { 442 474 $last_dir =& $last_dir[ $dir ]; 443 475 } 476 444 477 $last_dir = $plugin_file; 445 478 } 479 446 480 return $tree_list; 447 481 } … … 461 495 function wp_print_plugin_file_tree( $tree, $label = '', $level = 2, $size = 1, $index = 1 ) { 462 496 global $file, $plugin; 497 463 498 if ( is_array( $tree ) ) { 464 499 $index = 0; 465 500 $size = count( $tree ); 501 466 502 foreach ( $tree as $label => $plugin_file ) : 467 503 $index++; 504 468 505 if ( ! is_array( $plugin_file ) ) { 469 506 wp_print_plugin_file_tree( $plugin_file, $label, $level, $index, $size ); … … 569 606 } 570 607 } 608 571 609 echo "<p>$message</p>\n"; 572 610 wp_ob_end_flush_all(); … … 593 631 $functions = array(); 594 632 $ignore_functions = array(); 633 595 634 for ( $t = 0; $t < $count - 2; $t++ ) { 596 635 if ( ! is_array( $tokens[ $t ] ) ) { … … 598 637 } 599 638 600 if ( T_STRING == $tokens[ $t ][0] && ( '(' === $tokens[ $t + 1 ] || '(' === $tokens[ $t + 2 ] ) ) {639 if ( T_STRING === $tokens[ $t ][0] && ( '(' === $tokens[ $t + 1 ] || '(' === $tokens[ $t + 2 ] ) ) { 601 640 // If it's a function or class defined locally, there's not going to be any docs available. 602 641 if ( ( isset( $tokens[ $t - 2 ][1] ) && in_array( $tokens[ $t - 2 ][1], array( 'function', 'class' ), true ) ) 603 || ( isset( $tokens[ $t - 2 ][0] ) && T_OBJECT_OPERATOR == $tokens[ $t - 1 ][0] )642 || ( isset( $tokens[ $t - 2 ][0] ) && T_OBJECT_OPERATOR === $tokens[ $t - 1 ][0] ) 604 643 ) { 605 644 $ignore_functions[] = $tokens[ $t ][1]; 606 645 } 646 607 647 // Add this to our stack of unique references. 608 648 $functions[] = $tokens[ $t ][1]; … … 625 665 626 666 $out = array(); 667 627 668 foreach ( $functions as $function ) { 628 669 if ( in_array( $function, $ignore_functions, true ) ) { 629 670 continue; 630 671 } 672 631 673 $out[] = $function; 632 674 } … … 641 683 */ 642 684 function set_screen_options() { 643 644 if ( isset( $_POST['wp_screen_options'] ) && is_array( $_POST['wp_screen_options'] ) ) { 645 check_admin_referer( 'screen-options-nonce', 'screenoptionnonce' ); 646 647 $user = wp_get_current_user(); 648 if ( ! $user ) { 649 return; 650 } 651 $option = $_POST['wp_screen_options']['option']; 652 $value = $_POST['wp_screen_options']['value']; 653 654 if ( sanitize_key( $option ) != $option ) { 655 return; 656 } 657 658 $map_option = $option; 659 $type = str_replace( 'edit_', '', $map_option ); 660 $type = str_replace( '_per_page', '', $type ); 661 if ( in_array( $type, get_taxonomies(), true ) ) { 662 $map_option = 'edit_tags_per_page'; 663 } elseif ( in_array( $type, get_post_types(), true ) ) { 664 $map_option = 'edit_per_page'; 665 } else { 666 $option = str_replace( '-', '_', $option ); 667 } 668 669 switch ( $map_option ) { 670 case 'edit_per_page': 671 case 'users_per_page': 672 case 'edit_comments_per_page': 673 case 'upload_per_page': 674 case 'edit_tags_per_page': 675 case 'plugins_per_page': 676 case 'export_personal_data_requests_per_page': 677 case 'remove_personal_data_requests_per_page': 678 // Network admin. 679 case 'sites_network_per_page': 680 case 'users_network_per_page': 681 case 'site_users_network_per_page': 682 case 'plugins_network_per_page': 683 case 'themes_network_per_page': 684 case 'site_themes_network_per_page': 685 $value = (int) $value; 686 if ( $value < 1 || $value > 999 ) { 687 return; 688 } 689 break; 690 default: 691 $screen_option = false; 692 693 if ( '_page' === substr( $option, -5 ) || 'layout_columns' === $option ) { 694 /** 695 * Filters a screen option value before it is set. 696 * 697 * The filter can also be used to modify non-standard [items]_per_page 698 * settings. See the parent function for a full list of standard options. 699 * 700 * Returning false from the filter will skip saving the current option. 701 * 702 * @since 2.8.0 703 * @since 5.4.2 Only applied to options ending with '_page', 704 * or the 'layout_columns' option. 705 * 706 * @see set_screen_options() 707 * 708 * @param mixed $screen_option The value to save instead of the option value. 709 * Default false (to skip saving the current option). 710 * @param string $option The option name. 711 * @param int $value The option value. 712 */ 713 $screen_option = apply_filters( 'set-screen-option', $screen_option, $option, $value ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores 714 } 715 685 if ( ! isset( $_POST['wp_screen_options'] ) || ! is_array( $_POST['wp_screen_options'] ) ) { 686 return; 687 } 688 689 check_admin_referer( 'screen-options-nonce', 'screenoptionnonce' ); 690 691 $user = wp_get_current_user(); 692 693 if ( ! $user ) { 694 return; 695 } 696 697 $option = $_POST['wp_screen_options']['option']; 698 $value = $_POST['wp_screen_options']['value']; 699 700 if ( sanitize_key( $option ) !== $option ) { 701 return; 702 } 703 704 $map_option = $option; 705 $type = str_replace( 'edit_', '', $map_option ); 706 $type = str_replace( '_per_page', '', $type ); 707 708 if ( in_array( $type, get_taxonomies(), true ) ) { 709 $map_option = 'edit_tags_per_page'; 710 } elseif ( in_array( $type, get_post_types(), true ) ) { 711 $map_option = 'edit_per_page'; 712 } else { 713 $option = str_replace( '-', '_', $option ); 714 } 715 716 switch ( $map_option ) { 717 case 'edit_per_page': 718 case 'users_per_page': 719 case 'edit_comments_per_page': 720 case 'upload_per_page': 721 case 'edit_tags_per_page': 722 case 'plugins_per_page': 723 case 'export_personal_data_requests_per_page': 724 case 'remove_personal_data_requests_per_page': 725 // Network admin. 726 case 'sites_network_per_page': 727 case 'users_network_per_page': 728 case 'site_users_network_per_page': 729 case 'plugins_network_per_page': 730 case 'themes_network_per_page': 731 case 'site_themes_network_per_page': 732 $value = (int) $value; 733 734 if ( $value < 1 || $value > 999 ) { 735 return; 736 } 737 738 break; 739 740 default: 741 $screen_option = false; 742 743 if ( '_page' === substr( $option, -5 ) || 'layout_columns' === $option ) { 716 744 /** 717 745 * Filters a screen option value before it is set. 718 746 * 719 * The dynamic portion of the hook name, `$option`, refers to the option name. 747 * The filter can also be used to modify non-standard [items]_per_page 748 * settings. See the parent function for a full list of standard options. 720 749 * 721 750 * Returning false from the filter will skip saving the current option. 722 751 * 723 * @since 5.4.2 752 * @since 2.8.0 753 * @since 5.4.2 Only applied to options ending with '_page', 754 * or the 'layout_columns' option. 724 755 * 725 756 * @see set_screen_options() 726 757 * 727 * @param mixed $screen_option The value to save instead of the option value.728 * Default false (to skip saving the current option).729 * @param string $option The option name.730 * @param int $value The option value.758 * @param mixed $screen_option The value to save instead of the option value. 759 * Default false (to skip saving the current option). 760 * @param string $option The option name. 761 * @param int $value The option value. 731 762 */ 732 $value = apply_filters( "set_screen_option_{$option}", $screen_option, $option, $value ); 733 734 if ( false === $value ) { 735 return; 736 } 737 break; 738 } 739 740 update_user_meta( $user->ID, $option, $value ); 741 742 $url = remove_query_arg( array( 'pagenum', 'apage', 'paged' ), wp_get_referer() ); 743 if ( isset( $_POST['mode'] ) ) { 744 $url = add_query_arg( array( 'mode' => $_POST['mode'] ), $url ); 745 } 746 747 wp_safe_redirect( $url ); 748 exit; 749 } 763 $screen_option = apply_filters( 'set-screen-option', $screen_option, $option, $value ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores 764 } 765 766 /** 767 * Filters a screen option value before it is set. 768 * 769 * The dynamic portion of the hook name, `$option`, refers to the option name. 770 * 771 * Returning false from the filter will skip saving the current option. 772 * 773 * @since 5.4.2 774 * 775 * @see set_screen_options() 776 * 777 * @param mixed $screen_option The value to save instead of the option value. 778 * Default false (to skip saving the current option). 779 * @param string $option The option name. 780 * @param int $value The option value. 781 */ 782 $value = apply_filters( "set_screen_option_{$option}", $screen_option, $option, $value ); 783 784 if ( false === $value ) { 785 return; 786 } 787 788 break; 789 } 790 791 update_user_meta( $user->ID, $option, $value ); 792 793 $url = remove_query_arg( array( 'pagenum', 'apage', 'paged' ), wp_get_referer() ); 794 795 if ( isset( $_POST['mode'] ) ) { 796 $url = add_query_arg( array( 'mode' => $_POST['mode'] ), $url ); 797 } 798 799 wp_safe_redirect( $url ); 800 exit; 750 801 } 751 802 … … 755 806 * @since 2.8.0 756 807 * 808 * @param string $filename The file path to the configuration file 757 809 * @return bool 758 * @param string $filename The file path to the configuration file759 810 */ 760 811 function iis7_rewrite_rule_exists( $filename ) { … … 762 813 return false; 763 814 } 815 764 816 if ( ! class_exists( 'DOMDocument', false ) ) { 765 817 return false; … … 767 819 768 820 $doc = new DOMDocument(); 821 769 822 if ( $doc->load( $filename ) === false ) { 770 823 return false; 771 824 } 825 772 826 $xpath = new DOMXPath( $doc ); 773 827 $rules = $xpath->query( '/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')] | /configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'WordPress\')]' ); 774 if ( 0 == $rules->length ) { 828 829 if ( 0 === $rules->length ) { 775 830 return false; 776 } else {777 return true; 778 }831 } 832 833 return true; 779 834 } 780 835 … … 803 858 return false; 804 859 } 860 805 861 $xpath = new DOMXPath( $doc ); 806 862 $rules = $xpath->query( '/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')] | /configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'WordPress\')]' ); 863 807 864 if ( $rules->length > 0 ) { 808 865 $child = $rules->item( 0 ); … … 812 869 saveDomDocument( $doc, $filename ); 813 870 } 871 814 872 return true; 815 873 } … … 847 905 // First check if the rule already exists as in that case there is no need to re-add it. 848 906 $wordpress_rules = $xpath->query( '/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')] | /configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'WordPress\')]' ); 907 849 908 if ( $wordpress_rules->length > 0 ) { 850 909 return true; … … 853 912 // Check the XPath to the rewrite rule and create XML nodes if they do not exist. 854 913 $xmlnodes = $xpath->query( '/configuration/system.webServer/rewrite/rules' ); 914 855 915 if ( $xmlnodes->length > 0 ) { 856 916 $rules_node = $xmlnodes->item( 0 ); … … 859 919 860 920 $xmlnodes = $xpath->query( '/configuration/system.webServer/rewrite' ); 921 861 922 if ( $xmlnodes->length > 0 ) { 862 923 $rewrite_node = $xmlnodes->item( 0 ); … … 867 928 868 929 $xmlnodes = $xpath->query( '/configuration/system.webServer' ); 930 869 931 if ( $xmlnodes->length > 0 ) { 870 $system_web Server_node = $xmlnodes->item( 0 );871 $system_web Server_node->appendChild( $rewrite_node );932 $system_webserver_node = $xmlnodes->item( 0 ); 933 $system_webserver_node->appendChild( $rewrite_node ); 872 934 } else { 873 $system_web Server_node = $doc->createElement( 'system.webServer' );874 $system_web Server_node->appendChild( $rewrite_node );935 $system_webserver_node = $doc->createElement( 'system.webServer' ); 936 $system_webserver_node->appendChild( $rewrite_node ); 875 937 876 938 $xmlnodes = $xpath->query( '/configuration' ); 939 877 940 if ( $xmlnodes->length > 0 ) { 878 941 $config_node = $xmlnodes->item( 0 ); 879 $config_node->appendChild( $system_web Server_node );942 $config_node->appendChild( $system_webserver_node ); 880 943 } else { 881 944 $config_node = $doc->createElement( 'configuration' ); 882 945 $doc->appendChild( $config_node ); 883 $config_node->appendChild( $system_web Server_node );946 $config_node->appendChild( $system_webserver_node ); 884 947 } 885 948 } … … 909 972 $config = $doc->saveXML(); 910 973 $config = preg_replace( "/([^\r])\n/", "$1\r\n", $config ); 911 $fp = fopen( $filename, 'w' ); 974 975 $fp = fopen( $filename, 'w' ); 912 976 fwrite( $fp, $config ); 913 977 fclose( $fp ); … … 947 1011 $current_color = 'fresh'; 948 1012 } 949 950 1013 ?> 951 1014 <fieldset id="color-picker" class="scheme-list"> … … 956 1019 957 1020 ?> 958 <div class="color-option <?php echo ( $color == $current_color ) ? 'selected' : ''; ?>">1021 <div class="color-option <?php echo ( $color === $current_color ) ? 'selected' : ''; ?>"> 959 1022 <input name="admin_color" id="admin_color_<?php echo esc_attr( $color ); ?>" type="radio" value="<?php echo esc_attr( $color ); ?>" class="tog" <?php checked( $color, $current_color ); ?> /> 960 1023 <input type="hidden" class="css_url" value="<?php echo esc_url( $color_info->url ); ?>" /> … … 964 1027 <tr> 965 1028 <?php 966 967 1029 foreach ( $color_info->colors as $html_color ) { 968 1030 ?> … … 970 1032 <?php 971 1033 } 972 973 1034 ?> 974 1035 </tr> … … 978 1039 979 1040 endforeach; 980 981 1041 ?> 982 1042 </fieldset> … … 1066 1126 foreach ( $data['wp-check-locked-posts'] as $key ) { 1067 1127 $post_id = absint( substr( $key, 5 ) ); 1128 1068 1129 if ( ! $post_id ) { 1069 1130 continue; … … 1071 1132 1072 1133 $user_id = wp_check_post_lock( $post_id ); 1134 1073 1135 if ( $user_id ) { 1074 1136 $user = get_userdata( $user_id ); 1137 1075 1138 if ( $user && current_user_can( 'edit_post', $post_id ) ) { 1076 1139 $send = array( … … 1113 1176 1114 1177 $post_id = absint( $received['post_id'] ); 1178 1115 1179 if ( ! $post_id ) { 1116 1180 return $response; … … 1123 1187 $user_id = wp_check_post_lock( $post_id ); 1124 1188 $user = get_userdata( $user_id ); 1189 1125 1190 if ( $user ) { 1126 1191 $error = array( … … 1137 1202 } else { 1138 1203 $new_lock = wp_set_post_lock( $post_id ); 1204 1139 1205 if ( $new_lock ) { 1140 1206 $send['new_lock'] = implode( ':', $new_lock ); … … 1160 1226 function wp_refresh_post_nonces( $response, $data, $screen_id ) { 1161 1227 if ( array_key_exists( 'wp-refresh-post-nonces', $data ) ) { 1162 $received = $data['wp-refresh-post-nonces']; 1228 $received = $data['wp-refresh-post-nonces']; 1229 1163 1230 $response['wp-refresh-post-nonces'] = array( 'check' => 1 ); 1164 1231 1165 1232 $post_id = absint( $received['post_id'] ); 1233 1166 1234 if ( ! $post_id ) { 1167 1235 return $response; … … 1200 1268 // Refresh the Heartbeat nonce. 1201 1269 $response['heartbeat_nonce'] = wp_create_nonce( 'heartbeat-nonce' ); 1270 1202 1271 return $response; 1203 1272 } … … 1452 1521 1453 1522 $response = get_site_transient( 'php_check_' . $key ); 1523 1454 1524 if ( false === $response ) { 1455 1525 $url = 'http://api.wordpress.org/core/serve-happy/1.0/'; 1526 1456 1527 if ( wp_http_supports( array( 'ssl' ) ) ) { 1457 1528 $url = set_url_scheme( $url, 'https' );
Note: See TracChangeset
for help on using the changeset viewer.