Ticket #9864: 9864.2.diff
File 9864.2.diff, 8.3 KB (added by , 11 years ago) |
---|
-
src/wp-admin/admin-ajax.php
diff --git src/wp-admin/admin-ajax.php src/wp-admin/admin-ajax.php index d57d56b..3f1e3ca 100644
do_action( 'admin_init' ); 43 43 44 44 $core_actions_get = array( 45 45 'fetch-list', 'ajax-tag-search', 'wp-compression-test', 'imgedit-preview', 'oembed-cache', 46 'autocomplete-user', 'dashboard-widgets', 'logged-in', 46 'autocomplete-user', 'dashboard-widgets', 'logged-in', 'autocomplete-page', 47 47 ); 48 48 49 49 $core_actions_post = array( -
src/wp-admin/includes/ajax-actions.php
diff --git src/wp-admin/includes/ajax-actions.php src/wp-admin/includes/ajax-actions.php index caf6311..8e505c9 100644
function wp_ajax_autocomplete_user() { 241 241 wp_die( json_encode( $return ) ); 242 242 } 243 243 244 function wp_ajax_autocomplete_page() { 245 $return = array(); 246 247 // Check the type of request 248 // Current allowed values are `search` 249 if ( isset( $_REQUEST['autocomplete_type'] ) && 'search' === $_REQUEST['autocomplete_type'] ) { 250 $type = $_REQUEST['autocomplete_type']; 251 } else { 252 $type = 'search'; 253 } 254 255 // Check the desired field for value 256 // Current allowed values are `post_title` and `post_slug` 257 if ( isset( $_REQUEST['autocomplete_field'] ) && 'ID' === $_REQUEST['autocomplete_field'] ) { 258 $field = $_REQUEST['autocomplete_field']; 259 } else { 260 $field = 'post_title'; 261 } 262 263 $pages = get_pages( array( 264 'depth' => 0, 'child_of' => 0, 265 'selected' => 0, 'echo' => 1, 266 'name' => 'page_id', 'id' => '', 267 'show_option_none' => '', 'post_status' => array('publish'), 268 'search' => '*' . $_REQUEST['term'] . '*', 269 'search_columns' => array( 'post_title' ) 270 ) ); 271 272 foreach ($pages as $page) { 273 $return[] = array( 274 /* translators: 1: post_title */ 275 'id' => $page->{$field}, 276 'label' => esc_html( $page->post_title ), 277 'value' => esc_html( $page->post_title ) 278 ); 279 } 280 281 wp_die( json_encode( $return ) ); 282 } 283 244 284 function wp_ajax_dashboard_widgets() { 245 285 require_once ABSPATH . 'wp-admin/includes/dashboard.php'; 246 286 -
new file src/wp-admin/js/page-suggest.js
diff --git src/wp-admin/js/page-suggest.js src/wp-admin/js/page-suggest.js new file mode 100644 index 0000000..b8cb1d3
- + 1 /* global ajaxurl, isRtl */ 2 3 (function( $ ) { 4 $(document).ready( function() { 5 var position = { offset: '0, -1' }; 6 if ( typeof isRtl !== 'undefined' && isRtl ) { 7 position.my = 'right top'; 8 position.at = 'right bottom'; 9 } 10 $( '.wp-suggest-page' ).each( function(){ 11 var $this = $( this ), 12 autocompleteType = ( typeof $this.data( 'autocompleteType' ) !== 'undefined' ) ? $this.data( 'autocompleteType' ) : 'add', 13 autocompleteField = ( typeof $this.data( 'autocompleteField' ) !== 'undefined' ) ? $this.data( 'autocompleteField' ) : 'post_title'; 14 15 $this.autocomplete({ 16 source: ajaxurl + '?action=autocomplete-page&autocomplete_type=' + autocompleteType + '&autocomplete_field=' + autocompleteField, 17 delay: 500, 18 minLength: 2, 19 position: position, 20 select: function (event, ui) { 21 $('#parent_id').val(ui.item.id); 22 }, 23 open: function() { 24 $( this ).addClass( 'open' ); 25 }, 26 close: function() { 27 $( this ).removeClass( 'open' ); 28 } 29 }); 30 }); 31 }); 32 })( jQuery ); -
src/wp-includes/post-template.php
diff --git src/wp-includes/post-template.php src/wp-includes/post-template.php index 64aee53..0bebb2c 100644
function wp_dropdown_pages($args = '') { 780 780 'selected' => 0, 'echo' => 1, 781 781 'name' => 'page_id', 'id' => '', 782 782 'show_option_none' => '', 'show_option_no_change' => '', 783 'option_none_value' => '' 783 'option_none_value' => '', 'autocomplete' => false, 784 784 ); 785 785 786 786 $r = wp_parse_args( $args, $defaults ); 787 787 extract( $r, EXTR_SKIP ); 788 788 789 789 $pages = get_pages($r); 790 791 if ( is_admin() ) { 792 $autocomplete = apply_filters( 'admin_page_dropdown_autocomplete', count( $pages ) > 100, $pages, $args ); 793 } 794 790 795 $output = ''; 791 796 // Back-compat with old system where both id and name were based on $name argument 792 797 if ( empty($id) ) 793 798 $id = $name; 794 799 795 800 if ( ! empty($pages) ) { 796 $output = "<select name='" . esc_attr( $name ) . "' id='" . esc_attr( $id ) . "'>\n"; 797 if ( $show_option_no_change ) 798 $output .= "\t<option value=\"-1\">$show_option_no_change</option>"; 799 if ( $show_option_none ) 800 $output .= "\t<option value=\"" . esc_attr($option_none_value) . "\">$show_option_none</option>\n"; 801 $output .= walk_page_dropdown_tree($pages, $depth, $r); 802 $output .= "</select>\n"; 803 } 801 if ( $autocomplete ) { 802 wp_enqueue_script( 'page-suggest' ); 803 804 $display = ''; 805 $parent_id = 0; 806 if ( $selected > 0) { 807 $display = get_the_title( $selected ); 808 } 809 810 $output = "<input name='{$name}' type='text' size='25' class='wp-suggest-page' data-autocomplete-type='search' data-autocomplete-field='ID' title='" . esc_attr__( 'Page Title' ) . "' value='" . esc_attr( $display ) . "'/>\n"; 811 $output .= "<input type='hidden' name='{$name}' id='" . esc_attr( $id ) . "' value='" . esc_attr($selected) . "'/>\n"; 804 812 805 $output = apply_filters('wp_dropdown_pages', $output); 813 $output = apply_filters('wp_autocomplete_pages', $output); 814 } else { 815 $output = "<select name='" . esc_attr( $name ) . "' id='" . esc_attr( $id ) . "'>\n"; 816 if ( $show_option_no_change ) 817 $output .= "\t<option value=\"-1\">$show_option_no_change</option>"; 818 if ( $show_option_none ) 819 $output .= "\t<option value=\"" . esc_attr($option_none_value) . "\">$show_option_none</option>\n"; 820 $output .= walk_page_dropdown_tree($pages, $depth, $r); 821 $output .= "</select>\n"; 822 823 $output = apply_filters('wp_dropdown_pages', $output); 824 } 825 } 806 826 807 827 if ( $echo ) 808 828 echo $output; -
src/wp-includes/post.php
diff --git src/wp-includes/post.php src/wp-includes/post.php index 50b9c44..6db7cd6 100644
function get_pages( $args = array() ) { 3708 3708 'authors' => '', 'parent' => -1, 'exclude_tree' => '', 3709 3709 'number' => '', 'offset' => 0, 3710 3710 'post_type' => 'page', 'post_status' => 'publish', 3711 'search' => '', 'search_columns' => '', 3711 3712 ); 3712 3713 3713 3714 $r = wp_parse_args( $args, $defaults ); … … function get_pages( $args = array() ) { 3824 3825 $where_post_type = $wpdb->prepare( "post_type = %s AND post_status IN ('$post_status')", $post_type ); 3825 3826 } 3826 3827 3828 if ( $search ) { 3829 $leading_wild = ( ltrim($search, '*') != $search ); 3830 $trailing_wild = ( rtrim($search, '*') != $search ); 3831 if ( $leading_wild && $trailing_wild ) 3832 $wild = 'both'; 3833 elseif ( $leading_wild ) 3834 $wild = 'leading'; 3835 elseif ( $trailing_wild ) 3836 $wild = 'trailing'; 3837 else 3838 $wild = false; 3839 if ( $wild ) 3840 $search = trim($search, '*'); 3841 3842 if ( $search_columns ) 3843 $search_columns = array_intersect( $search_columns, array( 'ID', 'post_title' ) ); 3844 if ( ! $search_columns ) 3845 $search_columns = array('post_title'); 3846 3847 // Maybe a filter here? 3848 // $search_columns = apply_filters( 'user_search_columns', $search_columns, $search, $this ); 3849 3850 $search = esc_sql( $search ); 3851 3852 $searches = array(); 3853 $leading_wild = ( 'leading' == $wild || 'both' == $wild ) ? '%' : ''; 3854 $trailing_wild = ( 'trailing' == $wild || 'both' == $wild ) ? '%' : ''; 3855 foreach ( $search_columns as $col ) { 3856 if ( 'ID' == $col ) 3857 $searches[] = "$col = '$search'"; 3858 else 3859 $searches[] = "$col LIKE '$leading_wild" . like_escape($search) . "$trailing_wild'"; 3860 } 3861 3862 $where .= ' AND (' . implode(' OR ', $searches) . ')'; 3863 } 3864 3827 3865 $orderby_array = array(); 3828 3866 $allowed_keys = array('author', 'post_author', 'date', 'post_date', 'title', 'post_title', 'name', 'post_name', 'modified', 3829 3867 'post_modified', 'modified_gmt', 'post_modified_gmt', 'menu_order', 'parent', 'post_parent', -
src/wp-includes/script-loader.php
diff --git src/wp-includes/script-loader.php src/wp-includes/script-loader.php index a098b19..c375991 100644
function wp_default_scripts( &$scripts ) { 341 341 342 342 $scripts->add( 'user-suggest', "/wp-admin/js/user-suggest$suffix.js", array( 'jquery-ui-autocomplete' ), false, 1 ); 343 343 344 $scripts->add( 'page-suggest', "/wp-admin/js/page-suggest$suffix.js", array( 'jquery-ui-autocomplete' ), false, 1 ); 345 344 346 $scripts->add( 'admin-bar', "/wp-includes/js/admin-bar$suffix.js", array(), false, 1 ); 345 347 346 348 $scripts->add( 'wplink', "/wp-includes/js/wplink$suffix.js", array( 'jquery', 'wpdialogs' ), false, 1 );