Ticket #25947: 25947.diff
| File 25947.diff, 36.0 KB (added by , 13 years ago) |
|---|
-
wp-admin/js/editor.js
1 2 1 var switchEditors = { 3 2 4 switchto: function(el) { 5 var aid = el.id, l = aid.length, id = aid.substr(0, l - 5), mode = aid.substr(l - 4); 3 switchto: function( el ) { 4 var aid = el.id, 5 l = aid.length, 6 id = aid.substr( 0, l - 5 ), 7 mode = aid.substr( l - 4 ); 6 8 7 9 this.go(id, mode); 8 10 }, 9 11 10 go: function( id, mode) { // mode can be 'html', 'tmce', or 'toggle'; 'html' is used for the "Text" editor tab.12 go: function( id, mode ) { // mode can be 'html', 'tmce', or 'toggle'; 'html' is used for the "Text" editor tab. 11 13 id = id || 'content'; 12 14 mode = mode || 'toggle'; 13 15 14 var t = this, ed = tinyMCE.get( id), wrap_id, txtarea_el, dom = tinymce.DOM;16 var t = this, ed = tinyMCE.get( id ), wrap_id, txtarea_el, dom = tinymce.DOM; 15 17 16 wrap_id = 'wp-' +id+'-wrap';17 txtarea_el = dom.get( id);18 wrap_id = 'wp-' + id + '-wrap'; 19 txtarea_el = dom.get( id ); 18 20 19 21 if ( 'toggle' == mode ) { 20 if ( ed && ! ed.isHidden() )22 if ( ed && ! ed.isHidden() ) 21 23 mode = 'html'; 22 24 else 23 25 mode = 'tmce'; … … 27 29 if ( ed && ! ed.isHidden() ) 28 30 return false; 29 31 30 if ( typeof( QTags) != 'undefined' )31 QTags.closeAllTags( id);32 if ( typeof( QTags ) != 'undefined' ) 33 QTags.closeAllTags( id ); 32 34 33 if ( tinyMCEPreInit.mceInit[ id] && tinyMCEPreInit.mceInit[id].wpautop )35 if ( tinyMCEPreInit.mceInit[ id ] && tinyMCEPreInit.mceInit[ id ].wpautop ) 34 36 txtarea_el.value = t.wpautop( txtarea_el.value ); 35 37 36 38 if ( ed ) { 37 39 ed.show(); 38 40 } else { 39 ed = new tinymce.Editor( id, tinyMCEPreInit.mceInit[id]);41 ed = new tinymce.Editor( id, tinyMCEPreInit.mceInit[ id ] ); 40 42 ed.render(); 41 43 } 42 44 43 dom.removeClass( wrap_id, 'html-active');44 dom.addClass( wrap_id, 'tmce-active');45 setUserSetting( 'editor', 'tinymce');45 dom.removeClass( wrap_id, 'html-active' ); 46 dom.addClass( wrap_id, 'tmce-active' ); 47 setUserSetting( 'editor', 'tinymce' ); 46 48 47 49 } else if ( 'html' == mode ) { 48 50 … … 53 55 ed.hide(); 54 56 } else { 55 57 // The TinyMCE instance doesn't exist, run the content through "pre_wpautop()" and show the textarea 56 if ( tinyMCEPreInit.mceInit[ id] && tinyMCEPreInit.mceInit[id].wpautop )58 if ( tinyMCEPreInit.mceInit[ id ] && tinyMCEPreInit.mceInit[ id ].wpautop ) 57 59 txtarea_el.value = t.pre_wpautop( txtarea_el.value ); 58 60 59 dom.setStyles( txtarea_el, {'display': '', 'visibility': ''});61 dom.setStyles( txtarea_el, {'display': '', 'visibility': ''} ); 60 62 } 61 63 62 dom.removeClass( wrap_id, 'tmce-active');63 dom.addClass( wrap_id, 'html-active');64 setUserSetting( 'editor', 'html');64 dom.removeClass( wrap_id, 'tmce-active' ); 65 dom.addClass( wrap_id, 'html-active' ); 66 setUserSetting( 'editor', 'html' ); 65 67 } 66 68 return false; 67 69 }, 68 70 69 _wp_Nop : function(content) { 70 var blocklist1, blocklist2, preserve_linebreaks = false, preserve_br = false; 71 _wp_Nop: function( content ) { 72 var blocklist1, 73 blocklist2, 74 preserve_linebreaks = false, 75 preserve_br = false; 71 76 72 77 // Protect pre|script tags 73 if ( content.indexOf( '<pre') != -1 || content.indexOf('<script') != -1 ) {78 if ( content.indexOf( '<pre' ) != -1 || content.indexOf( '<script' ) != -1 ) { 74 79 preserve_linebreaks = true; 75 content = content.replace( /<(pre|script)[^>]*>[\s\S]+?<\/\1>/g, function(a) {76 a = a.replace( /<br ?\/?>(\r\n|\n)?/g, '<wp-temp-lb>');77 return a.replace( /<\/?p( [^>]*)?>(\r\n|\n)?/g, '<wp-temp-lb>');80 content = content.replace( /<(pre|script)[^>]*>[\s\S]+?<\/\1>/g, function( a ) { 81 a = a.replace( /<br ?\/?>(\r\n|\n)?/g, '<wp-temp-lb>' ); 82 return a.replace( /<\/?p( [^>]*)?>(\r\n|\n)?/g, '<wp-temp-lb>' ); 78 83 }); 79 84 } 80 85 81 86 // keep <br> tags inside captions and remove line breaks 82 if ( content.indexOf( '[caption') != -1 ) {87 if ( content.indexOf( '[caption' ) != -1 ) { 83 88 preserve_br = true; 84 content = content.replace( /\[caption[\s\S]+?\[\/caption\]/g, function(a) {85 return a.replace( /<br([^>]*)>/g, '<wp-temp-br$1>').replace(/[\r\n\t]+/, '');89 content = content.replace( /\[caption[\s\S]+?\[\/caption\]/g, function( a ) { 90 return a.replace( /<br([^>]*)>/g, '<wp-temp-br$1>' ).replace( /[\r\n\t]+/, '' ); 86 91 }); 87 92 } 88 93 89 94 // Pretty it up for the source editor 90 95 blocklist1 = 'blockquote|ul|ol|li|table|thead|tbody|tfoot|tr|th|td|div|h[1-6]|p|fieldset'; 91 content = content.replace( new RegExp('\\s*</('+blocklist1+')>\\s*', 'g'), '</$1>\n');92 content = content.replace( new RegExp('\\s*<((?:'+blocklist1+')(?: [^>]*)?)>', 'g'), '\n<$1>');96 content = content.replace( new RegExp( '\\s*</(' + blocklist1 + ')>\\s*', 'g' ), '</$1>\n' ); 97 content = content.replace( new RegExp( '\\s*<((?:' + blocklist1 + ')(?: [^>]*)?)>', 'g' ), '\n<$1>' ); 93 98 94 99 // Mark </p> if it has any attributes. 95 content = content.replace( /(<p [^>]+>.*?)<\/p>/g, '$1</p#>');100 content = content.replace( /(<p [^>]+>.*?)<\/p>/g, '$1</p#>' ); 96 101 97 102 // Separate <div> containing <p> 98 content = content.replace( /<div( [^>]*)?>\s*<p>/gi, '<div$1>\n\n');103 content = content.replace( /<div( [^>]*)?>\s*<p>/gi, '<div$1>\n\n' ); 99 104 100 105 // Remove <p> and <br /> 101 content = content.replace( /\s*<p>/gi, '');102 content = content.replace( /\s*<\/p>\s*/gi, '\n\n');103 content = content.replace( /\n[\s\u00a0]+\n/g, '\n\n');104 content = content.replace( /\s*<br ?\/?>\s*/gi, '\n');106 content = content.replace( /\s*<p>/gi, '' ); 107 content = content.replace( /\s*<\/p>\s*/gi, '\n\n' ); 108 content = content.replace( /\n[\s\u00a0]+\n/g, '\n\n' ); 109 content = content.replace( /\s*<br ?\/?>\s*/gi, '\n' ); 105 110 106 111 // Fix some block element newline issues 107 content = content.replace( /\s*<div/g, '\n<div');108 content = content.replace( /<\/div>\s*/g, '</div>\n');109 content = content.replace( /\s*\[caption([^\[]+)\[\/caption\]\s*/gi, '\n\n[caption$1[/caption]\n\n');110 content = content.replace( /caption\]\n\n+\[caption/g, 'caption]\n\n[caption');112 content = content.replace( /\s*<div/g, '\n<div' ); 113 content = content.replace( /<\/div>\s*/g, '</div>\n' ); 114 content = content.replace( /\s*\[caption([^\[]+)\[\/caption\]\s*/gi, '\n\n[caption$1[/caption]\n\n' ); 115 content = content.replace( /caption\]\n\n+\[caption/g, 'caption]\n\n[caption' ); 111 116 112 117 blocklist2 = 'blockquote|ul|ol|li|table|thead|tbody|tfoot|tr|th|td|h[1-6]|pre|fieldset'; 113 content = content.replace( new RegExp('\\s*<((?:'+blocklist2+')(?: [^>]*)?)\\s*>', 'g'), '\n<$1>');114 content = content.replace( new RegExp('\\s*</('+blocklist2+')>\\s*', 'g'), '</$1>\n');115 content = content.replace( /<li([^>]*)>/g, '\t<li$1>');118 content = content.replace( new RegExp('\\s*<((?:' + blocklist2 + ')(?: [^>]*)?)\\s*>', 'g' ), '\n<$1>' ); 119 content = content.replace( new RegExp('\\s*</(' + blocklist2 + ')>\\s*', 'g' ), '</$1>\n' ); 120 content = content.replace( /<li([^>]*)>/g, '\t<li$1>' ); 116 121 117 if ( content.indexOf( '<hr') != -1 ) {118 content = content.replace( /\s*<hr( [^>]*)?>\s*/g, '\n\n<hr$1>\n\n');122 if ( content.indexOf( '<hr' ) != -1 ) { 123 content = content.replace( /\s*<hr( [^>]*)?>\s*/g, '\n\n<hr$1>\n\n' ); 119 124 } 120 125 121 if ( content.indexOf( '<object') != -1 ) {122 content = content.replace( /<object[\s\S]+?<\/object>/g, function(a){123 return a.replace( /[\r\n]+/g, '');126 if ( content.indexOf( '<object' ) != -1 ) { 127 content = content.replace( /<object[\s\S]+?<\/object>/g, function( a ) { 128 return a.replace( /[\r\n]+/g, '' ); 124 129 }); 125 130 } 126 131 127 132 // Unmark special paragraph closing tags 128 content = content.replace( /<\/p#>/g, '</p>\n');129 content = content.replace( /\s*(<p [^>]+>[\s\S]*?<\/p>)/g, '\n$1');133 content = content.replace( /<\/p#>/g, '</p>\n' ); 134 content = content.replace( /\s*(<p [^>]+>[\s\S]*?<\/p>)/g, '\n$1' ); 130 135 131 136 // Trim whitespace 132 content = content.replace( /^\s+/, '');133 content = content.replace( /[\s\u00a0]+$/, '');137 content = content.replace( /^\s+/, '' ); 138 content = content.replace( /[\s\u00a0]+$/, '' ); 134 139 135 140 // put back the line breaks in pre|script 136 141 if ( preserve_linebreaks ) 137 content = content.replace( /<wp-temp-lb>/g, '\n');142 content = content.replace( /<wp-temp-lb>/g, '\n' ); 138 143 139 144 // and the <br> tags in captions 140 145 if ( preserve_br ) 141 content = content.replace( /<wp-temp-br([^>]*)>/g, '<br$1>');146 content = content.replace( /<wp-temp-br([^>]*)>/g, '<br$1>' ); 142 147 143 148 return content; 144 149 }, 145 150 146 _wp_Autop : function(pee) {151 _wp_Autop: function(pee) { 147 152 var preserve_linebreaks = false, preserve_br = false, 148 153 blocklist = 'table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary'; 149 154 150 if ( pee.indexOf( '<object') != -1 ) {151 pee = pee.replace( /<object[\s\S]+?<\/object>/g, function(a){152 return a.replace( /[\r\n]+/g, '');155 if ( pee.indexOf( '<object' ) != -1 ) { 156 pee = pee.replace( /<object[\s\S]+?<\/object>/g, function( a ) { 157 return a.replace( /[\r\n]+/g, '' ); 153 158 }); 154 159 } 155 160 156 pee = pee.replace( /<[^<>]+>/g, function(a){157 return a.replace( /[\r\n]+/g, ' ');161 pee = pee.replace( /<[^<>]+>/g, function( a ){ 162 return a.replace( /[\r\n]+/g, ' ' ); 158 163 }); 159 164 160 165 // Protect pre|script tags 161 if ( pee.indexOf( '<pre') != -1 || pee.indexOf('<script') != -1 ) {166 if ( pee.indexOf( '<pre' ) != -1 || pee.indexOf( '<script' ) != -1 ) { 162 167 preserve_linebreaks = true; 163 pee = pee.replace( /<(pre|script)[^>]*>[\s\S]+?<\/\1>/g, function(a) {164 return a.replace( /(\r\n|\n)/g, '<wp-temp-lb>');168 pee = pee.replace( /<(pre|script)[^>]*>[\s\S]+?<\/\1>/g, function( a ) { 169 return a.replace( /(\r\n|\n)/g, '<wp-temp-lb>' ); 165 170 }); 166 171 } 167 172 168 173 // keep <br> tags inside captions and convert line breaks 169 if ( pee.indexOf( '[caption') != -1 ) {174 if ( pee.indexOf( '[caption' ) != -1 ) { 170 175 preserve_br = true; 171 pee = pee.replace( /\[caption[\s\S]+?\[\/caption\]/g, function(a) {176 pee = pee.replace( /\[caption[\s\S]+?\[\/caption\]/g, function( a ) { 172 177 // keep existing <br> 173 a = a.replace( /<br([^>]*)>/g, '<wp-temp-br$1>');178 a = a.replace( /<br([^>]*)>/g, '<wp-temp-br$1>' ); 174 179 // no line breaks inside HTML tags 175 a = a.replace( /<[a-zA-Z0-9]+( [^<>]+)?>/g, function(b){176 return b.replace( /[\r\n\t]+/, ' ');180 a = a.replace( /<[a-zA-Z0-9]+( [^<>]+)?>/g, function( b ){ 181 return b.replace( /[\r\n\t]+/, ' ' ); 177 182 }); 178 183 // convert remaining line breaks to <br> 179 return a.replace( /\s*\n\s*/g, '<wp-temp-br />');184 return a.replace( /\s*\n\s*/g, '<wp-temp-br />' ); 180 185 }); 181 186 } 182 187 183 188 pee = pee + '\n\n'; 184 pee = pee.replace( /<br \/>\s*<br \/>/gi, '\n\n');185 pee = pee.replace( new RegExp('(<(?:'+blocklist+')(?: [^>]*)?>)', 'gi'), '\n$1');186 pee = pee.replace( new RegExp('(</(?:'+blocklist+')>)', 'gi'), '$1\n\n');187 pee = pee.replace( /<hr( [^>]*)?>/gi, '<hr$1>\n\n'); // hr is self closing block element188 pee = pee.replace( /\r\n|\r/g, '\n');189 pee = pee.replace( /\n\s*\n+/g, '\n\n');190 pee = pee.replace( /([\s\S]+?)\n\n/g, '<p>$1</p>\n');191 pee = pee.replace( /<p>\s*?<\/p>/gi, '');192 pee = pee.replace( new RegExp('<p>\\s*(</?(?:'+blocklist+')(?: [^>]*)?>)\\s*</p>', 'gi'), "$1");193 pee = pee.replace( /<p>(<li.+?)<\/p>/gi, '$1');194 pee = pee.replace( /<p>\s*<blockquote([^>]*)>/gi, '<blockquote$1><p>');195 pee = pee.replace( /<\/blockquote>\s*<\/p>/gi, '</p></blockquote>');196 pee = pee.replace( new RegExp('<p>\\s*(</?(?:'+blocklist+')(?: [^>]*)?>)', 'gi'), "$1");197 pee = pee.replace( new RegExp('(</?(?:'+blocklist+')(?: [^>]*)?>)\\s*</p>', 'gi'), "$1");198 pee = pee.replace( /\s*\n/gi, '<br />\n');199 pee = pee.replace( new RegExp('(</?(?:'+blocklist+')[^>]*>)\\s*<br />', 'gi'), "$1");200 pee = pee.replace( /<br \/>(\s*<\/?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)/gi, '$1');201 pee = pee.replace( /(?:<p>|<br ?\/?>)*\s*\[caption([^\[]+)\[\/caption\]\s*(?:<\/p>|<br ?\/?>)*/gi, '[caption$1[/caption]');189 pee = pee.replace( /<br \/>\s*<br \/>/gi, '\n\n' ); 190 pee = pee.replace( new RegExp( '(<(?:' + blocklist + ')(?: [^>]*)?>)', 'gi' ), '\n$1' ); 191 pee = pee.replace( new RegExp( '(</(?:' + blocklist + ')>)', 'gi' ), '$1\n\n' ); 192 pee = pee.replace( /<hr( [^>]*)?>/gi, '<hr$1>\n\n' ); // hr is self closing block element 193 pee = pee.replace( /\r\n|\r/g, '\n' ); 194 pee = pee.replace( /\n\s*\n+/g, '\n\n' ); 195 pee = pee.replace( /([\s\S]+?)\n\n/g, '<p>$1</p>\n' ); 196 pee = pee.replace( /<p>\s*?<\/p>/gi, ''); 197 pee = pee.replace( new RegExp( '<p>\\s*(</?(?:' + blocklist + ')(?: [^>]*)?>)\\s*</p>', 'gi' ), "$1" ); 198 pee = pee.replace( /<p>(<li.+?)<\/p>/gi, '$1'); 199 pee = pee.replace( /<p>\s*<blockquote([^>]*)>/gi, '<blockquote$1><p>'); 200 pee = pee.replace( /<\/blockquote>\s*<\/p>/gi, '</p></blockquote>'); 201 pee = pee.replace( new RegExp( '<p>\\s*(</?(?:' + blocklist + ')(?: [^>]*)?>)', 'gi' ), "$1" ); 202 pee = pee.replace( new RegExp( '(</?(?:' + blocklist + ')(?: [^>]*)?>)\\s*</p>', 'gi' ), "$1" ); 203 pee = pee.replace( /\s*\n/gi, '<br />\n'); 204 pee = pee.replace( new RegExp( '(</?(?:' + blocklist + ')[^>]*>)\\s*<br />', 'gi' ), "$1" ); 205 pee = pee.replace( /<br \/>(\s*<\/?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)/gi, '$1' ); 206 pee = pee.replace( /(?:<p>|<br ?\/?>)*\s*\[caption([^\[]+)\[\/caption\]\s*(?:<\/p>|<br ?\/?>)*/gi, '[caption$1[/caption]' ); 202 207 203 pee = pee.replace( /(<(?:div|th|td|form|fieldset|dd)[^>]*>)(.*?)<\/p>/g, function(a, b, c) {204 if ( c.match( /<p( [^>]*)?>/) )208 pee = pee.replace( /(<(?:div|th|td|form|fieldset|dd)[^>]*>)(.*?)<\/p>/g, function( a, b, c ) { 209 if ( c.match( /<p( [^>]*)?>/ ) ) 205 210 return a; 206 211 207 212 return b + '<p>' + c + '</p>'; … … 209 214 210 215 // put back the line breaks in pre|script 211 216 if ( preserve_linebreaks ) 212 pee = pee.replace( /<wp-temp-lb>/g, '\n');217 pee = pee.replace( /<wp-temp-lb>/g, '\n' ); 213 218 214 219 if ( preserve_br ) 215 pee = pee.replace( /<wp-temp-br([^>]*)>/g, '<br$1>');220 pee = pee.replace( /<wp-temp-br([^>]*)>/g, '<br$1>' ); 216 221 217 222 return pee; 218 223 }, 219 224 220 pre_wpautop : function(content) {225 pre_wpautop: function( content ) { 221 226 var t = this, o = { o: t, data: content, unfiltered: content }, 222 q = typeof( jQuery) != 'undefined';227 q = typeof( jQuery ) != 'undefined'; 223 228 224 229 if ( q ) 225 jQuery( 'body').trigger('beforePreWpautop', [o]);226 o.data = t._wp_Nop( o.data);230 jQuery( 'body' ).trigger( 'beforePreWpautop', [ o ] ); 231 o.data = t._wp_Nop( o.data ); 227 232 if ( q ) 228 jQuery('body').trigger('afterPreWpautop', [ o]);233 jQuery('body').trigger('afterPreWpautop', [ o ] ); 229 234 230 235 return o.data; 231 236 }, 232 237 233 wpautop : function(pee) {238 wpautop: function( pee ) { 234 239 var t = this, o = { o: t, data: pee, unfiltered: pee }, 235 q = typeof( jQuery) != 'undefined';240 q = typeof( jQuery ) != 'undefined'; 236 241 237 242 if ( q ) 238 jQuery( 'body').trigger('beforeWpautop', [o]);239 o.data = t._wp_Autop( o.data);243 jQuery( 'body' ).trigger('beforeWpautop', [ o ] ); 244 o.data = t._wp_Autop( o.data ); 240 245 if ( q ) 241 jQuery( 'body').trigger('afterWpautop', [o]);246 jQuery( 'body' ).trigger('afterWpautop', [ o ] ); 242 247 243 248 return o.data; 244 249 } 245 } 250 }; 251 No newline at end of file -
wp-includes/query.php
1709 1709 $this->query_vars_hash = md5( serialize( $this->query_vars ) ); 1710 1710 $this->query_vars_changed = false; 1711 1711 1712 do_action_ref_array('parse_query', array(&$this)); 1712 /** 1713 * Fires after parse_query is complete. 1714 * 1715 * @since 1.5.2 1716 * 1717 * @param WP_Query &$this The WP_Query instance (passed by reference). 1718 */ 1719 do_action_ref_array( 'parse_query', array( &$this ) ); 1713 1720 } 1714 1721 1715 1722 /** … … 1916 1923 1917 1924 $this->tax_query = new WP_Tax_Query( $tax_query ); 1918 1925 1926 /** 1927 * Fires after parse_tax_query is complete. 1928 * 1929 * @since 3.7.0 1930 * 1931 * @param WP_Query $this The WP_Query instance. 1932 */ 1919 1933 do_action( 'parse_tax_query', $this ); 1920 1934 } 1921 1935 … … 2151 2165 2152 2166 $this->parse_query(); 2153 2167 2154 do_action_ref_array('pre_get_posts', array(&$this)); 2168 /** 2169 * Fires after the query variable object is created, but before the actual query is run. 2170 * 2171 * Note: keep in mind the context of any conditional tags you use. For example, to test 2172 * if THIS instance is the main query, use $this->is_main_query(). This is because the 2173 * global function versions, such as is_main_query(), are run on the global $wp_query instance. 2174 * 2175 * @since 2.0.0 2176 * 2177 * @param WP_Query &$this The WP_Query instance (passed by reference). 2178 */ 2179 do_action_ref_array( 'pre_get_posts', array( &$this ) ); 2155 2180 2156 2181 // Shorthand. 2157 2182 $q = &$this->query_vars; … … 2791 2816 // Apply filters on where and join prior to paging so that any 2792 2817 // manipulations to them are reflected in the paging by day queries. 2793 2818 if ( !$q['suppress_filters'] ) { 2794 $where = apply_filters_ref_array('posts_where', array( $where, &$this ) ); 2795 $join = apply_filters_ref_array('posts_join', array( $join, &$this ) ); 2819 /** 2820 * Filter the WHERE clause of the query. 2821 * 2822 * @since 1.5.2 2823 * 2824 * @param string $where The WHERE clause of the query. 2825 * @param WP_Query &$this The WP_Query instance (passed by reference). 2826 */ 2827 $where = apply_filters_ref_array( 'posts_where', array( $where, &$this ) ); 2828 2829 /** 2830 * Filter the JOIN clause of the query. 2831 * 2832 * @since 1.5.2 2833 * 2834 * @param string $where The JOIN clause of the query. 2835 * @param WP_Query &$this The WP_Query instance (passed by reference). 2836 */ 2837 $join = apply_filters_ref_array( 'posts_join', array( $join, &$this ) ); 2796 2838 } 2797 2839 2798 2840 // Paging … … 2823 2865 } 2824 2866 2825 2867 if ( !$q['suppress_filters'] ) { 2826 $cjoin = apply_filters_ref_array('comment_feed_join', array( $cjoin, &$this ) ); 2827 $cwhere = apply_filters_ref_array('comment_feed_where', array( $cwhere, &$this ) ); 2828 $cgroupby = apply_filters_ref_array('comment_feed_groupby', array( $cgroupby, &$this ) ); 2829 $corderby = apply_filters_ref_array('comment_feed_orderby', array( 'comment_date_gmt DESC', &$this ) ); 2830 $climits = apply_filters_ref_array('comment_feed_limits', array( 'LIMIT ' . get_option('posts_per_rss'), &$this ) ); 2868 /** 2869 * Filter the JOIN clause of the comments feed query before sending. 2870 * 2871 * @since 1.5.2 2872 * 2873 * @param string $cjoin The JOIN clause of the query. 2874 * @param WP_Query &$this The WP_Query instance (passed by reference). 2875 */ 2876 $cjoin = apply_filters_ref_array( 'comment_feed_join', array( $cjoin, &$this ) ); 2877 2878 /** 2879 * Filter the WHERE clause of the comments feed query before sending. 2880 * 2881 * @since 1.5.2 2882 * 2883 * @param string $cwhere The WHERE clause of the query. 2884 * @param WP_Query &$this The WP_Query instance (passed by reference). 2885 */ 2886 $cwhere = apply_filters_ref_array( 'comment_feed_where', array( $cwhere, &$this ) ); 2887 2888 /** 2889 * Filter the GROUP BY clause of the comments feed query before sending. 2890 * 2891 * @since 1.5.2 2892 * 2893 * @param string $cgroupby The GROUP BY clause of the query. 2894 * @param WP_Query &$this The WP_Query instance (passed by reference). 2895 */ 2896 $cgroupby = apply_filters_ref_array( 'comment_feed_groupby', array( $cgroupby, &$this ) ); 2897 2898 /** 2899 * Filter the ORDER BY clause of the comments feed query before sending. 2900 * 2901 * @since 1.5.2 2902 * 2903 * @param string $corderby The ORDER BY clause of the query. 2904 * @param WP_Query &$this The WP_Query instance (passed by reference). 2905 */ 2906 $corderby = apply_filters_ref_array( 'comment_feed_orderby', array( 'comment_date_gmt DESC', &$this ) ); 2907 2908 /** 2909 * Filter the LIMIT clause of the comments feed query before sending. 2910 * 2911 * @since 1.5.2 2912 * 2913 * @param string $climits The JOIN clause of the query. 2914 * @param WP_Query &$this The WP_Query instance (passed by reference). 2915 */ 2916 $climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option('posts_per_rss'), &$this ) ); 2831 2917 } 2832 2918 $cgroupby = ( ! empty( $cgroupby ) ) ? 'GROUP BY ' . $cgroupby : ''; 2833 2919 $corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : ''; … … 2850 2936 2851 2937 $pieces = array( 'where', 'groupby', 'join', 'orderby', 'distinct', 'fields', 'limits' ); 2852 2938 2853 // Apply post-paging filters on where and join. Only plugins that2854 // manipulate paging queries should use these hooks.2855 2939 if ( !$q['suppress_filters'] ) { 2940 /** 2941 * Filter the WHERE clause of the query. 2942 * 2943 * Specifically for manipulating paging queries. 2944 * 2945 * @since 1.5.2 2946 * 2947 * @param string $where The WHERE clause of the query. 2948 * @param WP_Query &$this The WP_Query instance (passed by reference). 2949 */ 2856 2950 $where = apply_filters_ref_array( 'posts_where_paged', array( $where, &$this ) ); 2951 2952 /** 2953 * Filter the GROUP BY clause of the query. 2954 * 2955 * @since 2.0.0 2956 * 2957 * @param string $groupby The GROUP BY clause of the query. 2958 * @param WP_Query &$this The WP_Query instance (passed by reference). 2959 */ 2857 2960 $groupby = apply_filters_ref_array( 'posts_groupby', array( $groupby, &$this ) ); 2961 2962 /** 2963 * Filter the JOIN clause of the query. 2964 * 2965 * Specifically for manipulating paging queries. 2966 * 2967 * @since 1.5.2 2968 * 2969 * @param string $join The JOIN clause of the query. 2970 * @param WP_Query &$this The WP_Query instance (passed by reference). 2971 */ 2858 2972 $join = apply_filters_ref_array( 'posts_join_paged', array( $join, &$this ) ); 2973 2974 /** 2975 * Filter the ORDER BY clause of the query. 2976 * 2977 * @since 1.5.2 2978 * 2979 * @param string $orderby The ORDER BY clause of the query. 2980 * @param WP_Query &$this The WP_Query instance (passed by reference). 2981 */ 2859 2982 $orderby = apply_filters_ref_array( 'posts_orderby', array( $orderby, &$this ) ); 2983 2984 /** 2985 * Filter the DISTINCT clause of the query. 2986 * 2987 * @since 2.1.0 2988 * 2989 * @param string $distinct The DISTINCT clause of the query. 2990 * @param WP_Query &$this The WP_Query instance (passed by reference). 2991 */ 2860 2992 $distinct = apply_filters_ref_array( 'posts_distinct', array( $distinct, &$this ) ); 2993 2994 /** 2995 * Filter the LIMIT clause of the query. 2996 * 2997 * @since 2.1.0 2998 * 2999 * @param string $limits The LIMIT clause of the query. 3000 * @param WP_Query &$this The WP_Query instance (passed by reference). 3001 */ 2861 3002 $limits = apply_filters_ref_array( 'post_limits', array( $limits, &$this ) ); 3003 3004 /** 3005 * Filter the SELECT clause of the query. 3006 * 3007 * @since 2.1.0 3008 * 3009 * @param string $fields The SELECT clause of the query. 3010 * @param WP_Query &$this The WP_Query instance (passed by reference). 3011 */ 2862 3012 $fields = apply_filters_ref_array( 'posts_fields', array( $fields, &$this ) ); 2863 3013 2864 // Filter all clauses at once, for convenience 2865 $clauses = (array) apply_filters_ref_array( 'posts_clauses', array( compact( $pieces ), &$this ) ); 3014 $clauses = compact( $pieces ); 3015 /** 3016 * Filter all clauses at once, for convenience. 3017 * 3018 * Covers the WHERE, GROUP BY, JOIN, ORDER BY, DISTINCT, 3019 * fields (SELECT), and LIMITS clauses. 3020 * 3021 * @since 3.1.0 3022 * 3023 * @param array $clauses The list of clauses for the query. 3024 * @param WP_Query &$this The WP_Query instance (passed by reference). 3025 */ 3026 $clauses = (array) apply_filters_ref_array( 'posts_clauses', array( $clauses, &$this ) ); 3027 2866 3028 foreach ( $pieces as $piece ) 2867 3029 $$piece = isset( $clauses[ $piece ] ) ? $clauses[ $piece ] : ''; 2868 3030 } 2869 3031 2870 // Announce current selection parameters. For use by caching plugins. 2871 do_action( 'posts_selection', $where . $groupby . $orderby . $limits . $join ); 3032 $selection = $where . $groupby . $orderby . $limits . $join; 3033 /** 3034 * Fires to announce current selection parameters. 3035 * 3036 * For use by caching plugins. 3037 * 3038 * @since 2.3.0 3039 * 3040 * @param string $selection The assembled selection query. 3041 */ 3042 do_action( 'posts_selection', $selection ); 2872 3043 2873 3044 // Filter again for the benefit of caching plugins. Regular plugins should use the hooks above. 2874 3045 if ( !$q['suppress_filters'] ) { 3046 /** 3047 * Filter the WHERE clause of the query. 3048 * 3049 * For use by caching plugins. 3050 * 3051 * @since 2.5.0 3052 * 3053 * @param string $where The WHERE clause of the query. 3054 * @param WP_Query &$this The WP_Query instance (passed by reference). 3055 */ 2875 3056 $where = apply_filters_ref_array( 'posts_where_request', array( $where, &$this ) ); 3057 3058 /** 3059 * Filter the GROUP BY clause of the query. 3060 * 3061 * For use by caching plugins. 3062 * 3063 * @since 2.5.0 3064 * 3065 * @param string $groupby The GROUP BY clause of the query. 3066 * @param WP_Query &$this The WP_Query instance (passed by reference). 3067 */ 2876 3068 $groupby = apply_filters_ref_array( 'posts_groupby_request', array( $groupby, &$this ) ); 3069 3070 /** 3071 * Filter the JOIN clause of the query. 3072 * 3073 * For use by caching plugins. 3074 * 3075 * @since 2.5.0 3076 * 3077 * @param string $join The JOIN clause of the query. 3078 * @param WP_Query &$this The WP_Query instance (passed by reference). 3079 */ 2877 3080 $join = apply_filters_ref_array( 'posts_join_request', array( $join, &$this ) ); 3081 3082 /** 3083 * Filter the ORDER BY clause of the query. 3084 * 3085 * For use by caching plugins. 3086 * 3087 * @since 2.5.0 3088 * 3089 * @param string $orderby The ORDER BY clause of the query. 3090 * @param WP_Query &$this The WP_Query instance (passed by reference). 3091 */ 2878 3092 $orderby = apply_filters_ref_array( 'posts_orderby_request', array( $orderby, &$this ) ); 3093 3094 /** 3095 * Filter the DISTINCT clause of the query. 3096 * 3097 * For use by caching plugins. 3098 * 3099 * @since 2.5.0 3100 * 3101 * @param string $distinct The DISTINCT clause of the query. 3102 * @param WP_Query &$this The WP_Query instance (passed by reference). 3103 */ 2879 3104 $distinct = apply_filters_ref_array( 'posts_distinct_request', array( $distinct, &$this ) ); 3105 3106 /** 3107 * Filter the SELECT clause of the query. 3108 * 3109 * For use by caching plugins. 3110 * 3111 * @since 2.5.0 3112 * 3113 * @param string $fields The SELECT clause of the query. 3114 * @param WP_Query &$this The WP_Query instance (passed by reference). 3115 */ 2880 3116 $fields = apply_filters_ref_array( 'posts_fields_request', array( $fields, &$this ) ); 3117 3118 /** 3119 * Filter the LIMIT clause of the query. 3120 * 3121 * For use by caching plugins. 3122 * 3123 * @since 2.5.0 3124 * 3125 * @param string $limits The LIMIT clause of the query. 3126 * @param WP_Query &$this The WP_Query instance (passed by reference). 3127 */ 2881 3128 $limits = apply_filters_ref_array( 'post_limits_request', array( $limits, &$this ) ); 2882 3129 2883 // Filter all clauses at once, for convenience 2884 $clauses = (array) apply_filters_ref_array( 'posts_clauses_request', array( compact( $pieces ), &$this ) ); 3130 $clauses = compact( $pieces ); 3131 /** 3132 * Filter all clauses at once, for convenience. 3133 * 3134 * For use by caching plugins. 3135 * 3136 * Covers the WHERE, GROUP BY, JOIN, ORDER BY, DISTINCT, 3137 * fields (SELECT), and LIMITS clauses. 3138 * 3139 * @since 3.1.0 3140 * 3141 * @param array $pieces The pieces of the query. 3142 * @param WP_Query &$this The WP_Query instance (passed by reference). 3143 */ 3144 $clauses = (array) apply_filters_ref_array( 'posts_clauses_request', array( $clauses, &$this ) ); 2885 3145 foreach ( $pieces as $piece ) 2886 3146 $$piece = isset( $clauses[ $piece ] ) ? $clauses[ $piece ] : ''; 2887 3147 } … … 2898 3158 $this->request = $old_request = "SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits"; 2899 3159 2900 3160 if ( !$q['suppress_filters'] ) { 2901 $this->request = apply_filters_ref_array( 'posts_request', array( $this->request, &$this ) ); 3161 $request = $this->request; 3162 /** 3163 * Filter the completed SQL query before sending. 3164 * 3165 * @since 2.0.0 3166 * 3167 * @param array $request The complete SQL query. 3168 * @param WP_Query &$this The WP_Query instance (passed by reference). 3169 */ 3170 $this->request = apply_filters_ref_array( 'posts_request', array( $request, &$this ) ); 2902 3171 } 2903 3172 2904 3173 if ( 'ids' == $q['fields'] ) { … … 2922 3191 } 2923 3192 2924 3193 $split_the_query = ( $old_request == $this->request && "$wpdb->posts.*" == $fields && !empty( $limits ) && $q['posts_per_page'] < 500 ); 3194 3195 /** 3196 * Filter the $split_the_query boolean. 3197 * 3198 * Splitting the query will cause it to fetch just the IDs of the found posts 3199 * (and then individually fetch each post by ID), rather than fetching every 3200 * complete row at once. One massive result vs. many small results. 3201 * 3202 * @since 3.4.0 3203 * 3204 * @param bool $split_the_query Whether or not to split the query. 3205 * @param WP_Query $this The WP_Query instance. 3206 */ 2925 3207 $split_the_query = apply_filters( 'split_the_query', $split_the_query, $this ); 2926 3208 2927 3209 if ( $split_the_query ) { … … 2929 3211 2930 3212 $this->request = "SELECT $found_rows $distinct $wpdb->posts.ID FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits"; 2931 3213 2932 $this->request = apply_filters( 'posts_request_ids', $this->request, $this ); 3214 $request = $this->request; 3215 /** 3216 * Filter the Post IDs SQL request before sending. 3217 * 3218 * @since 3.4.0 3219 * 3220 * @param string $request The post ID request. 3221 * @param WP_Query $this The WP_Query instance. 3222 */ 3223 $this->request = apply_filters( 'posts_request_ids', $request, $this ); 2933 3224 2934 3225 $ids = $wpdb->get_col( $this->request ); 2935 3226 … … 2949 3240 if ( $this->posts ) 2950 3241 $this->posts = array_map( 'get_post', $this->posts ); 2951 3242 2952 // Raw results filter. Prior to status checks. 2953 if ( !$q['suppress_filters'] ) 2954 $this->posts = apply_filters_ref_array('posts_results', array( $this->posts, &$this ) ); 3243 if ( !$q['suppress_filters'] ){ 3244 $posts = $this->posts; 3245 /** 3246 * Filter the raw post results array, prior to status checks. 3247 * 3248 * @since 2.3.0 3249 * 3250 * @param array $posts The post results array. 3251 * @param WP_Query &$this The WP_Query instance (passed by reference). 3252 */ 3253 $this->posts = apply_filters_ref_array( 'posts_results', array( $posts, &$this ) ); 3254 } 2955 3255 2956 3256 if ( !empty($this->posts) && $this->is_comment_feed && $this->is_singular ) { 2957 $cjoin = apply_filters_ref_array('comment_feed_join', array( '', &$this ) ); 2958 $cwhere = apply_filters_ref_array('comment_feed_where', array( "WHERE comment_post_ID = '{$this->posts[0]->ID}' AND comment_approved = '1'", &$this ) ); 2959 $cgroupby = apply_filters_ref_array('comment_feed_groupby', array( '', &$this ) ); 3257 // duplicate_hook 3258 $cjoin = apply_filters_ref_array( 'comment_feed_join', array( '', &$this ) ); 3259 3260 // duplicate_hook 3261 $cwhere = apply_filters_ref_array( 'comment_feed_where', array( "WHERE comment_post_ID = '{$this->posts[0]->ID}' AND comment_approved = '1'", &$this ) ); 3262 3263 // duplicate_hook 3264 $cgroupby = apply_filters_ref_array( 'comment_feed_groupby', array( '', &$this ) ); 2960 3265 $cgroupby = ( ! empty( $cgroupby ) ) ? 'GROUP BY ' . $cgroupby : ''; 2961 $corderby = apply_filters_ref_array('comment_feed_orderby', array( 'comment_date_gmt DESC', &$this ) ); 3266 3267 // duplicate_hook 3268 $corderby = apply_filters_ref_array( 'comment_feed_orderby', array( 'comment_date_gmt DESC', &$this ) ); 2962 3269 $corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : ''; 2963 $climits = apply_filters_ref_array('comment_feed_limits', array( 'LIMIT ' . get_option('posts_per_rss'), &$this ) ); 3270 3271 // duplicate_hook 3272 $climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option('posts_per_rss'), &$this ) ); 3273 2964 3274 $comments_request = "SELECT $wpdb->comments.* FROM $wpdb->comments $cjoin $cwhere $cgroupby $corderby $climits"; 2965 3275 $this->comments = $wpdb->get_results($comments_request); 2966 3276 $this->comment_count = count($this->comments); … … 2994 3304 } 2995 3305 } 2996 3306 2997 if ( $this->is_preview && $this->posts && current_user_can( $edit_cap, $this->posts[0]->ID ) ) 2998 $this->posts[0] = get_post( apply_filters_ref_array( 'the_preview', array( $this->posts[0], &$this ) ) ); 3307 if ( $this->is_preview && $this->posts && current_user_can( $edit_cap, $this->posts[0]->ID ) ){ 3308 $post_preview = $this->posts[0]; 3309 /** 3310 * Filter the single post for preview mode. 3311 * 3312 * @since 2.7.0 3313 * 3314 * @param WP_Post $post_preview The Post object. 3315 * @param WP_Query &$this The WP_Query instance (passed by reference). 3316 */ 3317 $this->posts[0] = get_post( apply_filters_ref_array( 'the_preview', array( $post_preview, &$this ) ) ); 3318 } 2999 3319 } 3000 3320 3001 3321 // Put sticky posts at the top of the posts array … … 3039 3359 } 3040 3360 } 3041 3361 3042 if ( !$q['suppress_filters'] ) 3043 $this->posts = apply_filters_ref_array('the_posts', array( $this->posts, &$this ) ); 3362 if ( !$q['suppress_filters'] ){ 3363 $posts = $this->posts; 3364 /** 3365 * Filter the array of retrieved posts after they've been fetched and 3366 * internally processed. 3367 * 3368 * @since 1.5.2 3369 * 3370 * @param array $posts The array of retrieved posts. 3371 * @param WP_Query &$this The WP_Query instance (passed by reference). 3372 */ 3373 $this->posts = apply_filters_ref_array( 'the_posts', array( $posts, &$this ) ); 3374 } 3044 3375 3045 3376 // Ensure that any posts added/modified via one of the filters above are 3046 3377 // of the type WP_Post and are filtered. … … 3076 3407 if ( $q['no_found_rows'] || ( is_array( $this->posts ) && ! $this->posts ) ) 3077 3408 return; 3078 3409 3079 if ( ! empty( $limits ) ) 3080 $this->found_posts = $wpdb->get_var( apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ) ); 3081 else 3410 if ( ! empty( $limits ) ){ 3411 $found_posts = 'SELECT FOUND_ROWS()'; 3412 /** 3413 * Filter the query to run for retrieving the found posts. 3414 * 3415 * @since 2.1.0 3416 * 3417 * @param string $found_posts The query to run to find the found posts. 3418 * @param WP_Query &$this The WP_Query instance (passed by reference). 3419 */ 3420 $this->found_posts = $wpdb->get_var( apply_filters_ref_array( 'found_posts_query', array( $found_posts, &$this ) ) ); 3421 } 3422 else{ 3082 3423 $this->found_posts = count( $this->posts ); 3424 } 3083 3425 3084 $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) ); 3426 $found_posts = $this->found_posts; 3427 /** 3428 * Filter the number of found posts. 3429 * 3430 * @since 2.1.0 3431 * 3432 * @param int $found_posts The number of posts found. 3433 * @param WP_Query &$this The WP_Query instance (passed by reference). 3434 */ 3435 $this->found_posts = apply_filters_ref_array( 'found_posts', array( $found_posts, &$this ) ); 3085 3436 3086 3437 if ( ! empty( $limits ) ) 3087 3438 $this->max_num_pages = ceil( $this->found_posts / $q['posts_per_page'] ); … … 3119 3470 $this->in_the_loop = true; 3120 3471 3121 3472 if ( $this->current_post == -1 ) // loop has just started 3122 do_action_ref_array('loop_start', array(&$this)); 3473 /** 3474 * Fires once the loop is started. 3475 * 3476 * @since 2.0.0 3477 * 3478 * @param WP_Query &$this The WP_Query instance (passed by reference). 3479 */ 3480 do_action_ref_array( 'loop_start', array( &$this ) ); 3123 3481 3124 3482 $post = $this->next_post(); 3125 3483 setup_postdata($post); … … 3140 3498 if ( $this->current_post + 1 < $this->post_count ) { 3141 3499 return true; 3142 3500 } elseif ( $this->current_post + 1 == $this->post_count && $this->post_count > 0 ) { 3143 do_action_ref_array('loop_end', array(&$this)); 3501 /** 3502 * Fires once the loop has ended. 3503 * 3504 * @since 2.0.0 3505 * 3506 * @param WP_Query &$this The WP_Query instance (passed by reference). 3507 */ 3508 do_action_ref_array( 'loop_end', array( &$this ) ); 3144 3509 // Do some cleaning up after the loop 3145 3510 $this->rewind_posts(); 3146 3511 } … … 3191 3556 $comment = $this->next_comment(); 3192 3557 3193 3558 if ( $this->current_comment == 0 ) { 3194 do_action('comment_loop_start'); 3559 /** 3560 * Fires once the comment loop is started. 3561 * 3562 * @since 2.2.0 3563 */ 3564 do_action( 'comment_loop_start' ); 3195 3565 } 3196 3566 } 3197 3567 … … 3957 4327 $pages = array( $post->post_content ); 3958 4328 } 3959 4329 3960 do_action_ref_array('the_post', array(&$post)); 4330 /** 4331 * Fires once the post data has been setup. 4332 * 4333 * @since 2.8.0 4334 * 4335 * @param WP_Post &$post The Post object (passed by reference). 4336 */ 4337 do_action_ref_array( 'the_post', array( &$post ) ); 3961 4338 3962 4339 return true; 3963 4340 }