@@ -388,7 +388,7 @@ discard block |
||
| 388 | 388 | * @since 1.0.0 |
| 389 | 389 | * |
| 390 | 390 | * @param string $post Post content. |
| 391 | - * @return array Post before ('main'), after ('extended'), and custom read more ('more_text'). |
|
| 391 | + * @return integer Post before ('main'), after ('extended'), and custom read more ('more_text'). |
|
| 392 | 392 | */ |
| 393 | 393 | function get_extended( $post ) { |
| 394 | 394 | //Match the new style more links. |
@@ -1801,7 +1801,7 @@ discard block |
||
| 1801 | 1801 | * |
| 1802 | 1802 | * @param int $post_id Post ID. |
| 1803 | 1803 | * @param string $meta_key Metadata name. |
| 1804 | - * @param mixed $meta_value Optional. Metadata value. Must be serializable if |
|
| 1804 | + * @param string $meta_value Optional. Metadata value. Must be serializable if |
|
| 1805 | 1805 | * non-scalar. Default empty. |
| 1806 | 1806 | * @return bool True on success, false on failure. |
| 1807 | 1807 | */ |
@@ -2729,7 +2729,7 @@ discard block |
||
| 2729 | 2729 | * |
| 2730 | 2730 | * @global wpdb $wpdb WordPress database abstraction object. |
| 2731 | 2731 | * |
| 2732 | - * @param int|WP_Post|null $post Optional. Post ID or post object. Defaults to global $post. |
|
| 2732 | + * @param integer $post Optional. Post ID or post object. Defaults to global $post. |
|
| 2733 | 2733 | * @return mixed|void False on failure. |
| 2734 | 2734 | */ |
| 2735 | 2735 | function wp_trash_post_comments( $post = null ) { |
@@ -2785,8 +2785,8 @@ discard block |
||
| 2785 | 2785 | * |
| 2786 | 2786 | * @global wpdb $wpdb WordPress database abstraction object. |
| 2787 | 2787 | * |
| 2788 | - * @param int|WP_Post|null $post Optional. Post ID or post object. Defaults to global $post. |
|
| 2789 | - * @return true|void |
|
| 2788 | + * @param integer $post Optional. Post ID or post object. Defaults to global $post. |
|
| 2789 | + * @return null|boolean |
|
| 2790 | 2790 | */ |
| 2791 | 2791 | function wp_untrash_post_comments( $post = null ) { |
| 2792 | 2792 | global $wpdb; |
@@ -5130,7 +5130,7 @@ discard block |
||
| 5130 | 5130 | * @since 4.2.0 |
| 5131 | 5131 | * |
| 5132 | 5132 | * @param string $type Attachment type. Accepts 'image', 'audio', or 'video'. |
| 5133 | - * @param int|WP_Post $post_id Optional. Attachment ID. Default 0. |
|
| 5133 | + * @param integer $post_id Optional. Attachment ID. Default 0. |
|
| 5134 | 5134 | * @return bool True if one of the accepted types, false otherwise. |
| 5135 | 5135 | */ |
| 5136 | 5136 | function wp_attachment_is( $type, $post_id = 0 ) { |
@@ -5180,7 +5180,7 @@ discard block |
||
| 5180 | 5180 | * @since 4.2.0 Modified into wrapper for wp_attachment_is() and |
| 5181 | 5181 | * allowed WP_Post object to be passed. |
| 5182 | 5182 | * |
| 5183 | - * @param int|WP_Post $post Optional. Attachment ID. Default 0. |
|
| 5183 | + * @param integer $post Optional. Attachment ID. Default 0. |
|
| 5184 | 5184 | * @return bool Whether the attachment is an image. |
| 5185 | 5185 | */ |
| 5186 | 5186 | function wp_attachment_is_image( $post = 0 ) { |
@@ -5192,7 +5192,7 @@ discard block |
||
| 5192 | 5192 | * |
| 5193 | 5193 | * @since 2.1.0 |
| 5194 | 5194 | * |
| 5195 | - * @param string|int $mime MIME type or attachment ID. |
|
| 5195 | + * @param integer $mime MIME type or attachment ID. |
|
| 5196 | 5196 | * @return string|false Icon, false otherwise. |
| 5197 | 5197 | */ |
| 5198 | 5198 | function wp_mime_type_icon( $mime = 0 ) { |
@@ -5967,7 +5967,7 @@ discard block |
||
| 5967 | 5967 | * |
| 5968 | 5968 | * @since 3.3.0 |
| 5969 | 5969 | * |
| 5970 | - * @param int|WP_Post $post Post ID or post object where thumbnail should be removed from. |
|
| 5970 | + * @param integer $post Post ID or post object where thumbnail should be removed from. |
|
| 5971 | 5971 | * @return bool True on success, false on failure. |
| 5972 | 5972 | */ |
| 5973 | 5973 | function delete_post_thumbnail( $post ) { |
@@ -6090,7 +6090,7 @@ discard block |
||
| 6090 | 6090 | * @access private |
| 6091 | 6091 | * |
| 6092 | 6092 | * @param string $post_name Slug. |
| 6093 | - * @param string $post_ID Optional. Post ID that should be ignored. Default 0. |
|
| 6093 | + * @param integer $post_ID Optional. Post ID that should be ignored. Default 0. |
|
| 6094 | 6094 | */ |
| 6095 | 6095 | function wp_add_trashed_suffix_to_post_name_for_trashed_posts( $post_name, $post_ID = 0 ) { |
| 6096 | 6096 | $trashed_posts_with_desired_slug = get_posts( array( |
@@ -1,10 +1,10 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Core Post API |
|
| 4 | - * |
|
| 5 | - * @package WordPress |
|
| 6 | - * @subpackage Post |
|
| 7 | - */ |
|
| 3 | + * Core Post API |
|
| 4 | + * |
|
| 5 | + * @package WordPress |
|
| 6 | + * @subpackage Post |
|
| 7 | + */ |
|
| 8 | 8 | |
| 9 | 9 | // |
| 10 | 10 | // Post Type Registration |
@@ -16,9 +16,9 @@ discard block |
||
| 16 | 16 | * @since 2.9.0 |
| 17 | 17 | */ |
| 18 | 18 | function create_initial_post_types() { |
| 19 | - register_post_type( 'post', array( |
|
| 19 | + register_post_type('post', array( |
|
| 20 | 20 | 'labels' => array( |
| 21 | - 'name_admin_bar' => _x( 'Post', 'add new on admin bar' ), |
|
| 21 | + 'name_admin_bar' => _x('Post', 'add new on admin bar'), |
|
| 22 | 22 | ), |
| 23 | 23 | 'public' => true, |
| 24 | 24 | '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ |
@@ -30,12 +30,12 @@ discard block |
||
| 30 | 30 | 'rewrite' => false, |
| 31 | 31 | 'query_var' => false, |
| 32 | 32 | 'delete_with_user' => true, |
| 33 | - 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'post-formats' ), |
|
| 34 | - ) ); |
|
| 33 | + 'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'post-formats'), |
|
| 34 | + )); |
|
| 35 | 35 | |
| 36 | - register_post_type( 'page', array( |
|
| 36 | + register_post_type('page', array( |
|
| 37 | 37 | 'labels' => array( |
| 38 | - 'name_admin_bar' => _x( 'Page', 'add new on admin bar' ), |
|
| 38 | + 'name_admin_bar' => _x('Page', 'add new on admin bar'), |
|
| 39 | 39 | ), |
| 40 | 40 | 'public' => true, |
| 41 | 41 | 'publicly_queryable' => false, |
@@ -48,16 +48,16 @@ discard block |
||
| 48 | 48 | 'rewrite' => false, |
| 49 | 49 | 'query_var' => false, |
| 50 | 50 | 'delete_with_user' => true, |
| 51 | - 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'comments', 'revisions' ), |
|
| 52 | - ) ); |
|
| 51 | + 'supports' => array('title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'comments', 'revisions'), |
|
| 52 | + )); |
|
| 53 | 53 | |
| 54 | - register_post_type( 'attachment', array( |
|
| 54 | + register_post_type('attachment', array( |
|
| 55 | 55 | 'labels' => array( |
| 56 | 56 | 'name' => _x('Media', 'post type general name'), |
| 57 | - 'name_admin_bar' => _x( 'Media', 'add new from admin bar' ), |
|
| 58 | - 'add_new' => _x( 'Add New', 'add new media' ), |
|
| 59 | - 'edit_item' => __( 'Edit Media' ), |
|
| 60 | - 'view_item' => __( 'View Attachment Page' ), |
|
| 57 | + 'name_admin_bar' => _x('Media', 'add new from admin bar'), |
|
| 58 | + 'add_new' => _x('Add New', 'add new media'), |
|
| 59 | + 'edit_item' => __('Edit Media'), |
|
| 60 | + 'view_item' => __('View Attachment Page'), |
|
| 61 | 61 | ), |
| 62 | 62 | 'public' => true, |
| 63 | 63 | 'show_ui' => true, |
@@ -73,15 +73,15 @@ discard block |
||
| 73 | 73 | 'query_var' => false, |
| 74 | 74 | 'show_in_nav_menus' => false, |
| 75 | 75 | 'delete_with_user' => true, |
| 76 | - 'supports' => array( 'title', 'author', 'comments' ), |
|
| 77 | - ) ); |
|
| 78 | - add_post_type_support( 'attachment:audio', 'thumbnail' ); |
|
| 79 | - add_post_type_support( 'attachment:video', 'thumbnail' ); |
|
| 76 | + 'supports' => array('title', 'author', 'comments'), |
|
| 77 | + )); |
|
| 78 | + add_post_type_support('attachment:audio', 'thumbnail'); |
|
| 79 | + add_post_type_support('attachment:video', 'thumbnail'); |
|
| 80 | 80 | |
| 81 | - register_post_type( 'revision', array( |
|
| 81 | + register_post_type('revision', array( |
|
| 82 | 82 | 'labels' => array( |
| 83 | - 'name' => __( 'Revisions' ), |
|
| 84 | - 'singular_name' => __( 'Revision' ), |
|
| 83 | + 'name' => __('Revisions'), |
|
| 84 | + 'singular_name' => __('Revision'), |
|
| 85 | 85 | ), |
| 86 | 86 | 'public' => false, |
| 87 | 87 | '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ |
@@ -93,13 +93,13 @@ discard block |
||
| 93 | 93 | 'query_var' => false, |
| 94 | 94 | 'can_export' => false, |
| 95 | 95 | 'delete_with_user' => true, |
| 96 | - 'supports' => array( 'author' ), |
|
| 97 | - ) ); |
|
| 96 | + 'supports' => array('author'), |
|
| 97 | + )); |
|
| 98 | 98 | |
| 99 | - register_post_type( 'nav_menu_item', array( |
|
| 99 | + register_post_type('nav_menu_item', array( |
|
| 100 | 100 | 'labels' => array( |
| 101 | - 'name' => __( 'Navigation Menu Items' ), |
|
| 102 | - 'singular_name' => __( 'Navigation Menu Item' ), |
|
| 101 | + 'name' => __('Navigation Menu Items'), |
|
| 102 | + 'singular_name' => __('Navigation Menu Item'), |
|
| 103 | 103 | ), |
| 104 | 104 | 'public' => false, |
| 105 | 105 | '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ |
@@ -107,63 +107,63 @@ discard block |
||
| 107 | 107 | 'rewrite' => false, |
| 108 | 108 | 'delete_with_user' => false, |
| 109 | 109 | 'query_var' => false, |
| 110 | - ) ); |
|
| 110 | + )); |
|
| 111 | 111 | |
| 112 | - register_post_status( 'publish', array( |
|
| 113 | - 'label' => _x( 'Published', 'post status' ), |
|
| 112 | + register_post_status('publish', array( |
|
| 113 | + 'label' => _x('Published', 'post status'), |
|
| 114 | 114 | 'public' => true, |
| 115 | 115 | '_builtin' => true, /* internal use only. */ |
| 116 | - 'label_count' => _n_noop( 'Published <span class="count">(%s)</span>', 'Published <span class="count">(%s)</span>' ), |
|
| 117 | - ) ); |
|
| 116 | + 'label_count' => _n_noop('Published <span class="count">(%s)</span>', 'Published <span class="count">(%s)</span>'), |
|
| 117 | + )); |
|
| 118 | 118 | |
| 119 | - register_post_status( 'future', array( |
|
| 120 | - 'label' => _x( 'Scheduled', 'post status' ), |
|
| 119 | + register_post_status('future', array( |
|
| 120 | + 'label' => _x('Scheduled', 'post status'), |
|
| 121 | 121 | 'protected' => true, |
| 122 | 122 | '_builtin' => true, /* internal use only. */ |
| 123 | - 'label_count' => _n_noop('Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>' ), |
|
| 124 | - ) ); |
|
| 123 | + 'label_count' => _n_noop('Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>'), |
|
| 124 | + )); |
|
| 125 | 125 | |
| 126 | - register_post_status( 'draft', array( |
|
| 127 | - 'label' => _x( 'Draft', 'post status' ), |
|
| 126 | + register_post_status('draft', array( |
|
| 127 | + 'label' => _x('Draft', 'post status'), |
|
| 128 | 128 | 'protected' => true, |
| 129 | 129 | '_builtin' => true, /* internal use only. */ |
| 130 | - 'label_count' => _n_noop( 'Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>' ), |
|
| 131 | - ) ); |
|
| 130 | + 'label_count' => _n_noop('Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>'), |
|
| 131 | + )); |
|
| 132 | 132 | |
| 133 | - register_post_status( 'pending', array( |
|
| 134 | - 'label' => _x( 'Pending', 'post status' ), |
|
| 133 | + register_post_status('pending', array( |
|
| 134 | + 'label' => _x('Pending', 'post status'), |
|
| 135 | 135 | 'protected' => true, |
| 136 | 136 | '_builtin' => true, /* internal use only. */ |
| 137 | - 'label_count' => _n_noop( 'Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>' ), |
|
| 138 | - ) ); |
|
| 137 | + 'label_count' => _n_noop('Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>'), |
|
| 138 | + )); |
|
| 139 | 139 | |
| 140 | - register_post_status( 'private', array( |
|
| 141 | - 'label' => _x( 'Private', 'post status' ), |
|
| 140 | + register_post_status('private', array( |
|
| 141 | + 'label' => _x('Private', 'post status'), |
|
| 142 | 142 | 'private' => true, |
| 143 | 143 | '_builtin' => true, /* internal use only. */ |
| 144 | - 'label_count' => _n_noop( 'Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>' ), |
|
| 145 | - ) ); |
|
| 144 | + 'label_count' => _n_noop('Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>'), |
|
| 145 | + )); |
|
| 146 | 146 | |
| 147 | - register_post_status( 'trash', array( |
|
| 148 | - 'label' => _x( 'Trash', 'post status' ), |
|
| 147 | + register_post_status('trash', array( |
|
| 148 | + 'label' => _x('Trash', 'post status'), |
|
| 149 | 149 | 'internal' => true, |
| 150 | 150 | '_builtin' => true, /* internal use only. */ |
| 151 | - 'label_count' => _n_noop( 'Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>' ), |
|
| 151 | + 'label_count' => _n_noop('Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>'), |
|
| 152 | 152 | 'show_in_admin_status_list' => true, |
| 153 | - ) ); |
|
| 153 | + )); |
|
| 154 | 154 | |
| 155 | - register_post_status( 'auto-draft', array( |
|
| 155 | + register_post_status('auto-draft', array( |
|
| 156 | 156 | 'label' => 'auto-draft', |
| 157 | 157 | 'internal' => true, |
| 158 | 158 | '_builtin' => true, /* internal use only. */ |
| 159 | - ) ); |
|
| 159 | + )); |
|
| 160 | 160 | |
| 161 | - register_post_status( 'inherit', array( |
|
| 161 | + register_post_status('inherit', array( |
|
| 162 | 162 | 'label' => 'inherit', |
| 163 | 163 | 'internal' => true, |
| 164 | 164 | '_builtin' => true, /* internal use only. */ |
| 165 | 165 | 'exclude_from_search' => false, |
| 166 | - ) ); |
|
| 166 | + )); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
@@ -184,15 +184,15 @@ discard block |
||
| 184 | 184 | * @param bool $unfiltered Optional. Whether to apply filters. Default false. |
| 185 | 185 | * @return string|false The file path to where the attached file should be, false otherwise. |
| 186 | 186 | */ |
| 187 | -function get_attached_file( $attachment_id, $unfiltered = false ) { |
|
| 188 | - $file = get_post_meta( $attachment_id, '_wp_attached_file', true ); |
|
| 187 | +function get_attached_file($attachment_id, $unfiltered = false) { |
|
| 188 | + $file = get_post_meta($attachment_id, '_wp_attached_file', true); |
|
| 189 | 189 | |
| 190 | 190 | // If the file is relative, prepend upload dir. |
| 191 | - if ( $file && 0 !== strpos( $file, '/' ) && ! preg_match( '|^.:\\\|', $file ) && ( ( $uploads = wp_get_upload_dir() ) && false === $uploads['error'] ) ) { |
|
| 192 | - $file = $uploads['basedir'] . "/$file"; |
|
| 191 | + if ($file && 0 !== strpos($file, '/') && ! preg_match('|^.:\\\|', $file) && (($uploads = wp_get_upload_dir()) && false === $uploads['error'])) { |
|
| 192 | + $file = $uploads['basedir']."/$file"; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - if ( $unfiltered ) { |
|
| 195 | + if ($unfiltered) { |
|
| 196 | 196 | return $file; |
| 197 | 197 | } |
| 198 | 198 | |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | * @param string $file Path to attached file. |
| 205 | 205 | * @param int $attachment_id Attachment ID. |
| 206 | 206 | */ |
| 207 | - return apply_filters( 'get_attached_file', $file, $attachment_id ); |
|
| 207 | + return apply_filters('get_attached_file', $file, $attachment_id); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /** |
@@ -219,8 +219,8 @@ discard block |
||
| 219 | 219 | * @param string $file File path for the attachment. |
| 220 | 220 | * @return bool True on success, false on failure. |
| 221 | 221 | */ |
| 222 | -function update_attached_file( $attachment_id, $file ) { |
|
| 223 | - if ( !get_post( $attachment_id ) ) |
|
| 222 | +function update_attached_file($attachment_id, $file) { |
|
| 223 | + if ( ! get_post($attachment_id)) |
|
| 224 | 224 | return false; |
| 225 | 225 | |
| 226 | 226 | /** |
@@ -231,12 +231,12 @@ discard block |
||
| 231 | 231 | * @param string $file Path to the attached file to update. |
| 232 | 232 | * @param int $attachment_id Attachment ID. |
| 233 | 233 | */ |
| 234 | - $file = apply_filters( 'update_attached_file', $file, $attachment_id ); |
|
| 234 | + $file = apply_filters('update_attached_file', $file, $attachment_id); |
|
| 235 | 235 | |
| 236 | - if ( $file = _wp_relative_upload_path( $file ) ) |
|
| 237 | - return update_post_meta( $attachment_id, '_wp_attached_file', $file ); |
|
| 236 | + if ($file = _wp_relative_upload_path($file)) |
|
| 237 | + return update_post_meta($attachment_id, '_wp_attached_file', $file); |
|
| 238 | 238 | else |
| 239 | - return delete_post_meta( $attachment_id, '_wp_attached_file' ); |
|
| 239 | + return delete_post_meta($attachment_id, '_wp_attached_file'); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -249,13 +249,13 @@ discard block |
||
| 249 | 249 | * @param string $path Full path to the file. |
| 250 | 250 | * @return string Relative path on success, unchanged path on failure. |
| 251 | 251 | */ |
| 252 | -function _wp_relative_upload_path( $path ) { |
|
| 252 | +function _wp_relative_upload_path($path) { |
|
| 253 | 253 | $new_path = $path; |
| 254 | 254 | |
| 255 | 255 | $uploads = wp_get_upload_dir(); |
| 256 | - if ( 0 === strpos( $new_path, $uploads['basedir'] ) ) { |
|
| 257 | - $new_path = str_replace( $uploads['basedir'], '', $new_path ); |
|
| 258 | - $new_path = ltrim( $new_path, '/' ); |
|
| 256 | + if (0 === strpos($new_path, $uploads['basedir'])) { |
|
| 257 | + $new_path = str_replace($uploads['basedir'], '', $new_path); |
|
| 258 | + $new_path = ltrim($new_path, '/'); |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | /** |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | * @param string $new_path Relative path to the file. |
| 267 | 267 | * @param string $path Full path to the file. |
| 268 | 268 | */ |
| 269 | - return apply_filters( '_wp_relative_upload_path', $new_path, $path ); |
|
| 269 | + return apply_filters('_wp_relative_upload_path', $new_path, $path); |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | /** |
@@ -321,17 +321,17 @@ discard block |
||
| 321 | 321 | * @return array Array of children, where the type of each element is determined by $output parameter. |
| 322 | 322 | * Empty array on failure. |
| 323 | 323 | */ |
| 324 | -function get_children( $args = '', $output = OBJECT ) { |
|
| 324 | +function get_children($args = '', $output = OBJECT) { |
|
| 325 | 325 | $kids = array(); |
| 326 | - if ( empty( $args ) ) { |
|
| 327 | - if ( isset( $GLOBALS['post'] ) ) { |
|
| 328 | - $args = array('post_parent' => (int) $GLOBALS['post']->post_parent ); |
|
| 326 | + if (empty($args)) { |
|
| 327 | + if (isset($GLOBALS['post'])) { |
|
| 328 | + $args = array('post_parent' => (int) $GLOBALS['post']->post_parent); |
|
| 329 | 329 | } else { |
| 330 | 330 | return $kids; |
| 331 | 331 | } |
| 332 | - } elseif ( is_object( $args ) ) { |
|
| 333 | - $args = array('post_parent' => (int) $args->post_parent ); |
|
| 334 | - } elseif ( is_numeric( $args ) ) { |
|
| 332 | + } elseif (is_object($args)) { |
|
| 333 | + $args = array('post_parent' => (int) $args->post_parent); |
|
| 334 | + } elseif (is_numeric($args)) { |
|
| 335 | 335 | $args = array('post_parent' => (int) $args); |
| 336 | 336 | } |
| 337 | 337 | |
@@ -340,32 +340,32 @@ discard block |
||
| 340 | 340 | 'post_status' => 'any', 'post_parent' => 0, |
| 341 | 341 | ); |
| 342 | 342 | |
| 343 | - $r = wp_parse_args( $args, $defaults ); |
|
| 343 | + $r = wp_parse_args($args, $defaults); |
|
| 344 | 344 | |
| 345 | - $children = get_posts( $r ); |
|
| 345 | + $children = get_posts($r); |
|
| 346 | 346 | |
| 347 | - if ( ! $children ) |
|
| 347 | + if ( ! $children) |
|
| 348 | 348 | return $kids; |
| 349 | 349 | |
| 350 | - if ( ! empty( $r['fields'] ) ) |
|
| 350 | + if ( ! empty($r['fields'])) |
|
| 351 | 351 | return $children; |
| 352 | 352 | |
| 353 | 353 | update_post_cache($children); |
| 354 | 354 | |
| 355 | - foreach ( $children as $key => $child ) |
|
| 355 | + foreach ($children as $key => $child) |
|
| 356 | 356 | $kids[$child->ID] = $children[$key]; |
| 357 | 357 | |
| 358 | - if ( $output == OBJECT ) { |
|
| 358 | + if ($output == OBJECT) { |
|
| 359 | 359 | return $kids; |
| 360 | - } elseif ( $output == ARRAY_A ) { |
|
| 360 | + } elseif ($output == ARRAY_A) { |
|
| 361 | 361 | $weeuns = array(); |
| 362 | - foreach ( (array) $kids as $kid ) { |
|
| 362 | + foreach ((array) $kids as $kid) { |
|
| 363 | 363 | $weeuns[$kid->ID] = get_object_vars($kids[$kid->ID]); |
| 364 | 364 | } |
| 365 | 365 | return $weeuns; |
| 366 | - } elseif ( $output == ARRAY_N ) { |
|
| 366 | + } elseif ($output == ARRAY_N) { |
|
| 367 | 367 | $babes = array(); |
| 368 | - foreach ( (array) $kids as $kid ) { |
|
| 368 | + foreach ((array) $kids as $kid) { |
|
| 369 | 369 | $babes[$kid->ID] = array_values(get_object_vars($kids[$kid->ID])); |
| 370 | 370 | } |
| 371 | 371 | return $babes; |
@@ -390,9 +390,9 @@ discard block |
||
| 390 | 390 | * @param string $post Post content. |
| 391 | 391 | * @return array Post before ('main'), after ('extended'), and custom read more ('more_text'). |
| 392 | 392 | */ |
| 393 | -function get_extended( $post ) { |
|
| 393 | +function get_extended($post) { |
|
| 394 | 394 | //Match the new style more links. |
| 395 | - if ( preg_match('/<!--more(.*?)?-->/', $post, $matches) ) { |
|
| 395 | + if (preg_match('/<!--more(.*?)?-->/', $post, $matches)) { |
|
| 396 | 396 | list($main, $extended) = explode($matches[0], $post, 2); |
| 397 | 397 | $more_text = $matches[1]; |
| 398 | 398 | } else { |
@@ -406,7 +406,7 @@ discard block |
||
| 406 | 406 | $extended = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $extended); |
| 407 | 407 | $more_text = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $more_text); |
| 408 | 408 | |
| 409 | - return array( 'main' => $main, 'extended' => $extended, 'more_text' => $more_text ); |
|
| 409 | + return array('main' => $main, 'extended' => $extended, 'more_text' => $more_text); |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** |
@@ -427,34 +427,34 @@ discard block |
||
| 427 | 427 | * @return WP_Post|array|null Type corresponding to $output on success or null on failure. |
| 428 | 428 | * When $output is OBJECT, a `WP_Post` instance is returned. |
| 429 | 429 | */ |
| 430 | -function get_post( $post = null, $output = OBJECT, $filter = 'raw' ) { |
|
| 431 | - if ( empty( $post ) && isset( $GLOBALS['post'] ) ) |
|
| 430 | +function get_post($post = null, $output = OBJECT, $filter = 'raw') { |
|
| 431 | + if (empty($post) && isset($GLOBALS['post'])) |
|
| 432 | 432 | $post = $GLOBALS['post']; |
| 433 | 433 | |
| 434 | - if ( $post instanceof WP_Post ) { |
|
| 434 | + if ($post instanceof WP_Post) { |
|
| 435 | 435 | $_post = $post; |
| 436 | - } elseif ( is_object( $post ) ) { |
|
| 437 | - if ( empty( $post->filter ) ) { |
|
| 438 | - $_post = sanitize_post( $post, 'raw' ); |
|
| 439 | - $_post = new WP_Post( $_post ); |
|
| 440 | - } elseif ( 'raw' == $post->filter ) { |
|
| 441 | - $_post = new WP_Post( $post ); |
|
| 436 | + } elseif (is_object($post)) { |
|
| 437 | + if (empty($post->filter)) { |
|
| 438 | + $_post = sanitize_post($post, 'raw'); |
|
| 439 | + $_post = new WP_Post($_post); |
|
| 440 | + } elseif ('raw' == $post->filter) { |
|
| 441 | + $_post = new WP_Post($post); |
|
| 442 | 442 | } else { |
| 443 | - $_post = WP_Post::get_instance( $post->ID ); |
|
| 443 | + $_post = WP_Post::get_instance($post->ID); |
|
| 444 | 444 | } |
| 445 | 445 | } else { |
| 446 | - $_post = WP_Post::get_instance( $post ); |
|
| 446 | + $_post = WP_Post::get_instance($post); |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | - if ( ! $_post ) |
|
| 449 | + if ( ! $_post) |
|
| 450 | 450 | return null; |
| 451 | 451 | |
| 452 | - $_post = $_post->filter( $filter ); |
|
| 452 | + $_post = $_post->filter($filter); |
|
| 453 | 453 | |
| 454 | - if ( $output == ARRAY_A ) |
|
| 454 | + if ($output == ARRAY_A) |
|
| 455 | 455 | return $_post->to_array(); |
| 456 | - elseif ( $output == ARRAY_N ) |
|
| 457 | - return array_values( $_post->to_array() ); |
|
| 456 | + elseif ($output == ARRAY_N) |
|
| 457 | + return array_values($_post->to_array()); |
|
| 458 | 458 | |
| 459 | 459 | return $_post; |
| 460 | 460 | } |
@@ -467,19 +467,19 @@ discard block |
||
| 467 | 467 | * @param int|WP_Post $post Post ID or post object. |
| 468 | 468 | * @return array Ancestor IDs or empty array if none are found. |
| 469 | 469 | */ |
| 470 | -function get_post_ancestors( $post ) { |
|
| 471 | - $post = get_post( $post ); |
|
| 470 | +function get_post_ancestors($post) { |
|
| 471 | + $post = get_post($post); |
|
| 472 | 472 | |
| 473 | - if ( ! $post || empty( $post->post_parent ) || $post->post_parent == $post->ID ) |
|
| 473 | + if ( ! $post || empty($post->post_parent) || $post->post_parent == $post->ID) |
|
| 474 | 474 | return array(); |
| 475 | 475 | |
| 476 | 476 | $ancestors = array(); |
| 477 | 477 | |
| 478 | 478 | $id = $ancestors[] = $post->post_parent; |
| 479 | 479 | |
| 480 | - while ( $ancestor = get_post( $id ) ) { |
|
| 480 | + while ($ancestor = get_post($id)) { |
|
| 481 | 481 | // Loop detection: If the ancestor has been seen before, break. |
| 482 | - if ( empty( $ancestor->post_parent ) || ( $ancestor->post_parent == $post->ID ) || in_array( $ancestor->post_parent, $ancestors ) ) |
|
| 482 | + if (empty($ancestor->post_parent) || ($ancestor->post_parent == $post->ID) || in_array($ancestor->post_parent, $ancestors)) |
|
| 483 | 483 | break; |
| 484 | 484 | |
| 485 | 485 | $id = $ancestors[] = $ancestor->post_parent; |
@@ -508,13 +508,13 @@ discard block |
||
| 508 | 508 | * or 'display'. Default 'display'. |
| 509 | 509 | * @return string The value of the post field on success, empty string on failure. |
| 510 | 510 | */ |
| 511 | -function get_post_field( $field, $post = null, $context = 'display' ) { |
|
| 512 | - $post = get_post( $post ); |
|
| 511 | +function get_post_field($field, $post = null, $context = 'display') { |
|
| 512 | + $post = get_post($post); |
|
| 513 | 513 | |
| 514 | - if ( !$post ) |
|
| 514 | + if ( ! $post) |
|
| 515 | 515 | return ''; |
| 516 | 516 | |
| 517 | - if ( !isset($post->$field) ) |
|
| 517 | + if ( ! isset($post->$field)) |
|
| 518 | 518 | return ''; |
| 519 | 519 | |
| 520 | 520 | return sanitize_post_field($field, $post->$field, $post->ID, $context); |
@@ -531,10 +531,10 @@ discard block |
||
| 531 | 531 | * @param int|WP_Post $ID Optional. Post ID or post object. Default empty. |
| 532 | 532 | * @return string|false The mime type on success, false on failure. |
| 533 | 533 | */ |
| 534 | -function get_post_mime_type( $ID = '' ) { |
|
| 534 | +function get_post_mime_type($ID = '') { |
|
| 535 | 535 | $post = get_post($ID); |
| 536 | 536 | |
| 537 | - if ( is_object($post) ) |
|
| 537 | + if (is_object($post)) |
|
| 538 | 538 | return $post->post_mime_type; |
| 539 | 539 | |
| 540 | 540 | return false; |
@@ -551,25 +551,25 @@ discard block |
||
| 551 | 551 | * @param int|WP_Post $ID Optional. Post ID or post object. Default empty. |
| 552 | 552 | * @return string|false Post status on success, false on failure. |
| 553 | 553 | */ |
| 554 | -function get_post_status( $ID = '' ) { |
|
| 554 | +function get_post_status($ID = '') { |
|
| 555 | 555 | $post = get_post($ID); |
| 556 | 556 | |
| 557 | - if ( !is_object($post) ) |
|
| 557 | + if ( ! is_object($post)) |
|
| 558 | 558 | return false; |
| 559 | 559 | |
| 560 | - if ( 'attachment' == $post->post_type ) { |
|
| 561 | - if ( 'private' == $post->post_status ) |
|
| 560 | + if ('attachment' == $post->post_type) { |
|
| 561 | + if ('private' == $post->post_status) |
|
| 562 | 562 | return 'private'; |
| 563 | 563 | |
| 564 | 564 | // Unattached attachments are assumed to be published. |
| 565 | - if ( ( 'inherit' == $post->post_status ) && ( 0 == $post->post_parent) ) |
|
| 565 | + if (('inherit' == $post->post_status) && (0 == $post->post_parent)) |
|
| 566 | 566 | return 'publish'; |
| 567 | 567 | |
| 568 | 568 | // Inherit status from the parent. |
| 569 | - if ( $post->post_parent && ( $post->ID != $post->post_parent ) ) { |
|
| 570 | - $parent_post_status = get_post_status( $post->post_parent ); |
|
| 571 | - if ( 'trash' == $parent_post_status ) { |
|
| 572 | - return get_post_meta( $post->post_parent, '_wp_trash_meta_status', true ); |
|
| 569 | + if ($post->post_parent && ($post->ID != $post->post_parent)) { |
|
| 570 | + $parent_post_status = get_post_status($post->post_parent); |
|
| 571 | + if ('trash' == $parent_post_status) { |
|
| 572 | + return get_post_meta($post->post_parent, '_wp_trash_meta_status', true); |
|
| 573 | 573 | } else { |
| 574 | 574 | return $parent_post_status; |
| 575 | 575 | } |
@@ -585,7 +585,7 @@ discard block |
||
| 585 | 585 | * @param string $post_status The post status. |
| 586 | 586 | * @param WP_Post $post The post object. |
| 587 | 587 | */ |
| 588 | - return apply_filters( 'get_post_status', $post->post_status, $post ); |
|
| 588 | + return apply_filters('get_post_status', $post->post_status, $post); |
|
| 589 | 589 | } |
| 590 | 590 | |
| 591 | 591 | /** |
@@ -600,10 +600,10 @@ discard block |
||
| 600 | 600 | */ |
| 601 | 601 | function get_post_statuses() { |
| 602 | 602 | $status = array( |
| 603 | - 'draft' => __( 'Draft' ), |
|
| 604 | - 'pending' => __( 'Pending Review' ), |
|
| 605 | - 'private' => __( 'Private' ), |
|
| 606 | - 'publish' => __( 'Published' ) |
|
| 603 | + 'draft' => __('Draft'), |
|
| 604 | + 'pending' => __('Pending Review'), |
|
| 605 | + 'private' => __('Private'), |
|
| 606 | + 'publish' => __('Published') |
|
| 607 | 607 | ); |
| 608 | 608 | |
| 609 | 609 | return $status; |
@@ -621,9 +621,9 @@ discard block |
||
| 621 | 621 | */ |
| 622 | 622 | function get_page_statuses() { |
| 623 | 623 | $status = array( |
| 624 | - 'draft' => __( 'Draft' ), |
|
| 625 | - 'private' => __( 'Private' ), |
|
| 626 | - 'publish' => __( 'Published' ) |
|
| 624 | + 'draft' => __('Draft'), |
|
| 625 | + 'private' => __('Private'), |
|
| 626 | + 'publish' => __('Published') |
|
| 627 | 627 | ); |
| 628 | 628 | |
| 629 | 629 | return $status; |
@@ -672,10 +672,10 @@ discard block |
||
| 672 | 672 | * } |
| 673 | 673 | * @return object |
| 674 | 674 | */ |
| 675 | -function register_post_status( $post_status, $args = array() ) { |
|
| 675 | +function register_post_status($post_status, $args = array()) { |
|
| 676 | 676 | global $wp_post_statuses; |
| 677 | 677 | |
| 678 | - if (!is_array($wp_post_statuses)) |
|
| 678 | + if ( ! is_array($wp_post_statuses)) |
|
| 679 | 679 | $wp_post_statuses = array(); |
| 680 | 680 | |
| 681 | 681 | // Args prefixed with an underscore are reserved for internal use. |
@@ -699,38 +699,38 @@ discard block |
||
| 699 | 699 | $args->name = $post_status; |
| 700 | 700 | |
| 701 | 701 | // Set various defaults. |
| 702 | - if ( null === $args->public && null === $args->internal && null === $args->protected && null === $args->private ) |
|
| 702 | + if (null === $args->public && null === $args->internal && null === $args->protected && null === $args->private) |
|
| 703 | 703 | $args->internal = true; |
| 704 | 704 | |
| 705 | - if ( null === $args->public ) |
|
| 705 | + if (null === $args->public) |
|
| 706 | 706 | $args->public = false; |
| 707 | 707 | |
| 708 | - if ( null === $args->private ) |
|
| 708 | + if (null === $args->private) |
|
| 709 | 709 | $args->private = false; |
| 710 | 710 | |
| 711 | - if ( null === $args->protected ) |
|
| 711 | + if (null === $args->protected) |
|
| 712 | 712 | $args->protected = false; |
| 713 | 713 | |
| 714 | - if ( null === $args->internal ) |
|
| 714 | + if (null === $args->internal) |
|
| 715 | 715 | $args->internal = false; |
| 716 | 716 | |
| 717 | - if ( null === $args->publicly_queryable ) |
|
| 717 | + if (null === $args->publicly_queryable) |
|
| 718 | 718 | $args->publicly_queryable = $args->public; |
| 719 | 719 | |
| 720 | - if ( null === $args->exclude_from_search ) |
|
| 720 | + if (null === $args->exclude_from_search) |
|
| 721 | 721 | $args->exclude_from_search = $args->internal; |
| 722 | 722 | |
| 723 | - if ( null === $args->show_in_admin_all_list ) |
|
| 724 | - $args->show_in_admin_all_list = !$args->internal; |
|
| 723 | + if (null === $args->show_in_admin_all_list) |
|
| 724 | + $args->show_in_admin_all_list = ! $args->internal; |
|
| 725 | 725 | |
| 726 | - if ( null === $args->show_in_admin_status_list ) |
|
| 727 | - $args->show_in_admin_status_list = !$args->internal; |
|
| 726 | + if (null === $args->show_in_admin_status_list) |
|
| 727 | + $args->show_in_admin_status_list = ! $args->internal; |
|
| 728 | 728 | |
| 729 | - if ( false === $args->label ) |
|
| 729 | + if (false === $args->label) |
|
| 730 | 730 | $args->label = $post_status; |
| 731 | 731 | |
| 732 | - if ( false === $args->label_count ) |
|
| 733 | - $args->label_count = array( $args->label, $args->label ); |
|
| 732 | + if (false === $args->label_count) |
|
| 733 | + $args->label_count = array($args->label, $args->label); |
|
| 734 | 734 | |
| 735 | 735 | $wp_post_statuses[$post_status] = $args; |
| 736 | 736 | |
@@ -749,10 +749,10 @@ discard block |
||
| 749 | 749 | * @param string $post_status The name of a registered post status. |
| 750 | 750 | * @return object|null A post status object. |
| 751 | 751 | */ |
| 752 | -function get_post_status_object( $post_status ) { |
|
| 752 | +function get_post_status_object($post_status) { |
|
| 753 | 753 | global $wp_post_statuses; |
| 754 | 754 | |
| 755 | - if ( empty($wp_post_statuses[$post_status]) ) |
|
| 755 | + if (empty($wp_post_statuses[$post_status])) |
|
| 756 | 756 | return null; |
| 757 | 757 | |
| 758 | 758 | return $wp_post_statuses[$post_status]; |
@@ -775,7 +775,7 @@ discard block |
||
| 775 | 775 | * Default 'and'. |
| 776 | 776 | * @return array A list of post status names or objects. |
| 777 | 777 | */ |
| 778 | -function get_post_stati( $args = array(), $output = 'names', $operator = 'and' ) { |
|
| 778 | +function get_post_stati($args = array(), $output = 'names', $operator = 'and') { |
|
| 779 | 779 | global $wp_post_statuses; |
| 780 | 780 | |
| 781 | 781 | $field = ('names' == $output) ? 'name' : false; |
@@ -795,11 +795,11 @@ discard block |
||
| 795 | 795 | * @param string $post_type Post type name |
| 796 | 796 | * @return bool Whether post type is hierarchical. |
| 797 | 797 | */ |
| 798 | -function is_post_type_hierarchical( $post_type ) { |
|
| 799 | - if ( ! post_type_exists( $post_type ) ) |
|
| 798 | +function is_post_type_hierarchical($post_type) { |
|
| 799 | + if ( ! post_type_exists($post_type)) |
|
| 800 | 800 | return false; |
| 801 | 801 | |
| 802 | - $post_type = get_post_type_object( $post_type ); |
|
| 802 | + $post_type = get_post_type_object($post_type); |
|
| 803 | 803 | return $post_type->hierarchical; |
| 804 | 804 | } |
| 805 | 805 | |
@@ -813,8 +813,8 @@ discard block |
||
| 813 | 813 | * @param string $post_type Post type name. |
| 814 | 814 | * @return bool Whether post type is registered. |
| 815 | 815 | */ |
| 816 | -function post_type_exists( $post_type ) { |
|
| 817 | - return (bool) get_post_type_object( $post_type ); |
|
| 816 | +function post_type_exists($post_type) { |
|
| 817 | + return (bool) get_post_type_object($post_type); |
|
| 818 | 818 | } |
| 819 | 819 | |
| 820 | 820 | /** |
@@ -825,8 +825,8 @@ discard block |
||
| 825 | 825 | * @param int|WP_Post|null $post Optional. Post ID or post object. Default is global $post. |
| 826 | 826 | * @return string|false Post type on success, false on failure. |
| 827 | 827 | */ |
| 828 | -function get_post_type( $post = null ) { |
|
| 829 | - if ( $post = get_post( $post ) ) |
|
| 828 | +function get_post_type($post = null) { |
|
| 829 | + if ($post = get_post($post)) |
|
| 830 | 830 | return $post->post_type; |
| 831 | 831 | |
| 832 | 832 | return false; |
@@ -844,14 +844,14 @@ discard block |
||
| 844 | 844 | * @param string $post_type The name of a registered post type. |
| 845 | 845 | * @return object|null A post type object. |
| 846 | 846 | */ |
| 847 | -function get_post_type_object( $post_type ) { |
|
| 847 | +function get_post_type_object($post_type) { |
|
| 848 | 848 | global $wp_post_types; |
| 849 | 849 | |
| 850 | - if ( ! is_scalar( $post_type ) || empty( $wp_post_types[ $post_type ] ) ) { |
|
| 850 | + if ( ! is_scalar($post_type) || empty($wp_post_types[$post_type])) { |
|
| 851 | 851 | return null; |
| 852 | 852 | } |
| 853 | 853 | |
| 854 | - return $wp_post_types[ $post_type ]; |
|
| 854 | + return $wp_post_types[$post_type]; |
|
| 855 | 855 | } |
| 856 | 856 | |
| 857 | 857 | /** |
@@ -872,7 +872,7 @@ discard block |
||
| 872 | 872 | * must match; 'not' means no elements may match. Default 'and'. |
| 873 | 873 | * @return array A list of post type names or objects. |
| 874 | 874 | */ |
| 875 | -function get_post_types( $args = array(), $output = 'names', $operator = 'and' ) { |
|
| 875 | +function get_post_types($args = array(), $output = 'names', $operator = 'and') { |
|
| 876 | 876 | global $wp_post_types; |
| 877 | 877 | |
| 878 | 878 | $field = ('names' == $output) ? 'name' : false; |
@@ -995,16 +995,16 @@ discard block |
||
| 995 | 995 | * } |
| 996 | 996 | * @return object|WP_Error The registered post type object, or an error object. |
| 997 | 997 | */ |
| 998 | -function register_post_type( $post_type, $args = array() ) { |
|
| 998 | +function register_post_type($post_type, $args = array()) { |
|
| 999 | 999 | global $wp_post_types, $wp_rewrite, $wp; |
| 1000 | 1000 | |
| 1001 | - if ( ! is_array( $wp_post_types ) ) { |
|
| 1001 | + if ( ! is_array($wp_post_types)) { |
|
| 1002 | 1002 | $wp_post_types = array(); |
| 1003 | 1003 | } |
| 1004 | 1004 | |
| 1005 | 1005 | // Sanitize post type name |
| 1006 | - $post_type = sanitize_key( $post_type ); |
|
| 1007 | - $args = wp_parse_args( $args ); |
|
| 1006 | + $post_type = sanitize_key($post_type); |
|
| 1007 | + $args = wp_parse_args($args); |
|
| 1008 | 1008 | |
| 1009 | 1009 | /** |
| 1010 | 1010 | * Filter the arguments for registering a post type. |
@@ -1014,9 +1014,9 @@ discard block |
||
| 1014 | 1014 | * @param array $args Array of arguments for registering a post type. |
| 1015 | 1015 | * @param string $post_type Post type key. |
| 1016 | 1016 | */ |
| 1017 | - $args = apply_filters( 'register_post_type_args', $args, $post_type ); |
|
| 1017 | + $args = apply_filters('register_post_type_args', $args, $post_type); |
|
| 1018 | 1018 | |
| 1019 | - $has_edit_link = ! empty( $args['_edit_link'] ); |
|
| 1019 | + $has_edit_link = ! empty($args['_edit_link']); |
|
| 1020 | 1020 | |
| 1021 | 1021 | // Args prefixed with an underscore are reserved for internal use. |
| 1022 | 1022 | $defaults = array( |
@@ -1046,136 +1046,136 @@ discard block |
||
| 1046 | 1046 | '_builtin' => false, |
| 1047 | 1047 | '_edit_link' => 'post.php?post=%d', |
| 1048 | 1048 | ); |
| 1049 | - $args = array_merge( $defaults, $args ); |
|
| 1049 | + $args = array_merge($defaults, $args); |
|
| 1050 | 1050 | $args = (object) $args; |
| 1051 | 1051 | |
| 1052 | 1052 | $args->name = $post_type; |
| 1053 | 1053 | |
| 1054 | - if ( empty( $post_type ) || strlen( $post_type ) > 20 ) { |
|
| 1055 | - _doing_it_wrong( __FUNCTION__, __( 'Post type names must be between 1 and 20 characters in length.' ), '4.2' ); |
|
| 1056 | - return new WP_Error( 'post_type_length_invalid', __( 'Post type names must be between 1 and 20 characters in length.' ) ); |
|
| 1054 | + if (empty($post_type) || strlen($post_type) > 20) { |
|
| 1055 | + _doing_it_wrong(__FUNCTION__, __('Post type names must be between 1 and 20 characters in length.'), '4.2'); |
|
| 1056 | + return new WP_Error('post_type_length_invalid', __('Post type names must be between 1 and 20 characters in length.')); |
|
| 1057 | 1057 | } |
| 1058 | 1058 | |
| 1059 | 1059 | // If not set, default to the setting for public. |
| 1060 | - if ( null === $args->publicly_queryable ) |
|
| 1060 | + if (null === $args->publicly_queryable) |
|
| 1061 | 1061 | $args->publicly_queryable = $args->public; |
| 1062 | 1062 | |
| 1063 | 1063 | // If not set, default to the setting for public. |
| 1064 | - if ( null === $args->show_ui ) |
|
| 1064 | + if (null === $args->show_ui) |
|
| 1065 | 1065 | $args->show_ui = $args->public; |
| 1066 | 1066 | |
| 1067 | 1067 | // If not set, default to the setting for show_ui. |
| 1068 | - if ( null === $args->show_in_menu || ! $args->show_ui ) |
|
| 1068 | + if (null === $args->show_in_menu || ! $args->show_ui) |
|
| 1069 | 1069 | $args->show_in_menu = $args->show_ui; |
| 1070 | 1070 | |
| 1071 | 1071 | // If not set, default to the whether the full UI is shown. |
| 1072 | - if ( null === $args->show_in_admin_bar ) |
|
| 1072 | + if (null === $args->show_in_admin_bar) |
|
| 1073 | 1073 | $args->show_in_admin_bar = (bool) $args->show_in_menu; |
| 1074 | 1074 | |
| 1075 | 1075 | // If not set, default to the setting for public. |
| 1076 | - if ( null === $args->show_in_nav_menus ) |
|
| 1076 | + if (null === $args->show_in_nav_menus) |
|
| 1077 | 1077 | $args->show_in_nav_menus = $args->public; |
| 1078 | 1078 | |
| 1079 | 1079 | // If not set, default to true if not public, false if public. |
| 1080 | - if ( null === $args->exclude_from_search ) |
|
| 1081 | - $args->exclude_from_search = !$args->public; |
|
| 1080 | + if (null === $args->exclude_from_search) |
|
| 1081 | + $args->exclude_from_search = ! $args->public; |
|
| 1082 | 1082 | |
| 1083 | 1083 | // Back compat with quirky handling in version 3.0. #14122. |
| 1084 | - if ( empty( $args->capabilities ) && null === $args->map_meta_cap && in_array( $args->capability_type, array( 'post', 'page' ) ) ) |
|
| 1084 | + if (empty($args->capabilities) && null === $args->map_meta_cap && in_array($args->capability_type, array('post', 'page'))) |
|
| 1085 | 1085 | $args->map_meta_cap = true; |
| 1086 | 1086 | |
| 1087 | 1087 | // If not set, default to false. |
| 1088 | - if ( null === $args->map_meta_cap ) |
|
| 1088 | + if (null === $args->map_meta_cap) |
|
| 1089 | 1089 | $args->map_meta_cap = false; |
| 1090 | 1090 | |
| 1091 | 1091 | // If there's no specified edit link and no UI, remove the edit link. |
| 1092 | - if ( ! $args->show_ui && ! $has_edit_link ) { |
|
| 1092 | + if ( ! $args->show_ui && ! $has_edit_link) { |
|
| 1093 | 1093 | $args->_edit_link = ''; |
| 1094 | 1094 | } |
| 1095 | 1095 | |
| 1096 | - $args->cap = get_post_type_capabilities( $args ); |
|
| 1097 | - unset( $args->capabilities ); |
|
| 1096 | + $args->cap = get_post_type_capabilities($args); |
|
| 1097 | + unset($args->capabilities); |
|
| 1098 | 1098 | |
| 1099 | - if ( is_array( $args->capability_type ) ) |
|
| 1099 | + if (is_array($args->capability_type)) |
|
| 1100 | 1100 | $args->capability_type = $args->capability_type[0]; |
| 1101 | 1101 | |
| 1102 | - if ( ! empty( $args->supports ) ) { |
|
| 1103 | - add_post_type_support( $post_type, $args->supports ); |
|
| 1104 | - unset( $args->supports ); |
|
| 1105 | - } elseif ( false !== $args->supports ) { |
|
| 1102 | + if ( ! empty($args->supports)) { |
|
| 1103 | + add_post_type_support($post_type, $args->supports); |
|
| 1104 | + unset($args->supports); |
|
| 1105 | + } elseif (false !== $args->supports) { |
|
| 1106 | 1106 | // Add default features |
| 1107 | - add_post_type_support( $post_type, array( 'title', 'editor' ) ); |
|
| 1107 | + add_post_type_support($post_type, array('title', 'editor')); |
|
| 1108 | 1108 | } |
| 1109 | 1109 | |
| 1110 | - if ( false !== $args->query_var ) { |
|
| 1111 | - if ( true === $args->query_var ) |
|
| 1110 | + if (false !== $args->query_var) { |
|
| 1111 | + if (true === $args->query_var) |
|
| 1112 | 1112 | $args->query_var = $post_type; |
| 1113 | 1113 | else |
| 1114 | - $args->query_var = sanitize_title_with_dashes( $args->query_var ); |
|
| 1114 | + $args->query_var = sanitize_title_with_dashes($args->query_var); |
|
| 1115 | 1115 | |
| 1116 | - if ( $wp && is_post_type_viewable( $args ) ) { |
|
| 1117 | - $wp->add_query_var( $args->query_var ); |
|
| 1116 | + if ($wp && is_post_type_viewable($args)) { |
|
| 1117 | + $wp->add_query_var($args->query_var); |
|
| 1118 | 1118 | } |
| 1119 | 1119 | } |
| 1120 | 1120 | |
| 1121 | - if ( false !== $args->rewrite && ( is_admin() || '' != get_option( 'permalink_structure' ) ) ) { |
|
| 1122 | - if ( ! is_array( $args->rewrite ) ) |
|
| 1121 | + if (false !== $args->rewrite && (is_admin() || '' != get_option('permalink_structure'))) { |
|
| 1122 | + if ( ! is_array($args->rewrite)) |
|
| 1123 | 1123 | $args->rewrite = array(); |
| 1124 | - if ( empty( $args->rewrite['slug'] ) ) |
|
| 1124 | + if (empty($args->rewrite['slug'])) |
|
| 1125 | 1125 | $args->rewrite['slug'] = $post_type; |
| 1126 | - if ( ! isset( $args->rewrite['with_front'] ) ) |
|
| 1126 | + if ( ! isset($args->rewrite['with_front'])) |
|
| 1127 | 1127 | $args->rewrite['with_front'] = true; |
| 1128 | - if ( ! isset( $args->rewrite['pages'] ) ) |
|
| 1128 | + if ( ! isset($args->rewrite['pages'])) |
|
| 1129 | 1129 | $args->rewrite['pages'] = true; |
| 1130 | - if ( ! isset( $args->rewrite['feeds'] ) || ! $args->has_archive ) |
|
| 1130 | + if ( ! isset($args->rewrite['feeds']) || ! $args->has_archive) |
|
| 1131 | 1131 | $args->rewrite['feeds'] = (bool) $args->has_archive; |
| 1132 | - if ( ! isset( $args->rewrite['ep_mask'] ) ) { |
|
| 1133 | - if ( isset( $args->permalink_epmask ) ) |
|
| 1132 | + if ( ! isset($args->rewrite['ep_mask'])) { |
|
| 1133 | + if (isset($args->permalink_epmask)) |
|
| 1134 | 1134 | $args->rewrite['ep_mask'] = $args->permalink_epmask; |
| 1135 | 1135 | else |
| 1136 | 1136 | $args->rewrite['ep_mask'] = EP_PERMALINK; |
| 1137 | 1137 | } |
| 1138 | 1138 | |
| 1139 | - if ( $args->hierarchical ) |
|
| 1140 | - add_rewrite_tag( "%$post_type%", '(.+?)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&pagename=" ); |
|
| 1139 | + if ($args->hierarchical) |
|
| 1140 | + add_rewrite_tag("%$post_type%", '(.+?)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&pagename="); |
|
| 1141 | 1141 | else |
| 1142 | - add_rewrite_tag( "%$post_type%", '([^/]+)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name=" ); |
|
| 1142 | + add_rewrite_tag("%$post_type%", '([^/]+)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name="); |
|
| 1143 | 1143 | |
| 1144 | - if ( $args->has_archive ) { |
|
| 1144 | + if ($args->has_archive) { |
|
| 1145 | 1145 | $archive_slug = $args->has_archive === true ? $args->rewrite['slug'] : $args->has_archive; |
| 1146 | - if ( $args->rewrite['with_front'] ) |
|
| 1147 | - $archive_slug = substr( $wp_rewrite->front, 1 ) . $archive_slug; |
|
| 1146 | + if ($args->rewrite['with_front']) |
|
| 1147 | + $archive_slug = substr($wp_rewrite->front, 1).$archive_slug; |
|
| 1148 | 1148 | else |
| 1149 | - $archive_slug = $wp_rewrite->root . $archive_slug; |
|
| 1149 | + $archive_slug = $wp_rewrite->root.$archive_slug; |
|
| 1150 | 1150 | |
| 1151 | - add_rewrite_rule( "{$archive_slug}/?$", "index.php?post_type=$post_type", 'top' ); |
|
| 1152 | - if ( $args->rewrite['feeds'] && $wp_rewrite->feeds ) { |
|
| 1153 | - $feeds = '(' . trim( implode( '|', $wp_rewrite->feeds ) ) . ')'; |
|
| 1154 | - add_rewrite_rule( "{$archive_slug}/feed/$feeds/?$", "index.php?post_type=$post_type" . '&feed=$matches[1]', 'top' ); |
|
| 1155 | - add_rewrite_rule( "{$archive_slug}/$feeds/?$", "index.php?post_type=$post_type" . '&feed=$matches[1]', 'top' ); |
|
| 1151 | + add_rewrite_rule("{$archive_slug}/?$", "index.php?post_type=$post_type", 'top'); |
|
| 1152 | + if ($args->rewrite['feeds'] && $wp_rewrite->feeds) { |
|
| 1153 | + $feeds = '('.trim(implode('|', $wp_rewrite->feeds)).')'; |
|
| 1154 | + add_rewrite_rule("{$archive_slug}/feed/$feeds/?$", "index.php?post_type=$post_type".'&feed=$matches[1]', 'top'); |
|
| 1155 | + add_rewrite_rule("{$archive_slug}/$feeds/?$", "index.php?post_type=$post_type".'&feed=$matches[1]', 'top'); |
|
| 1156 | 1156 | } |
| 1157 | - if ( $args->rewrite['pages'] ) |
|
| 1158 | - add_rewrite_rule( "{$archive_slug}/{$wp_rewrite->pagination_base}/([0-9]{1,})/?$", "index.php?post_type=$post_type" . '&paged=$matches[1]', 'top' ); |
|
| 1157 | + if ($args->rewrite['pages']) |
|
| 1158 | + add_rewrite_rule("{$archive_slug}/{$wp_rewrite->pagination_base}/([0-9]{1,})/?$", "index.php?post_type=$post_type".'&paged=$matches[1]', 'top'); |
|
| 1159 | 1159 | } |
| 1160 | 1160 | |
| 1161 | 1161 | $permastruct_args = $args->rewrite; |
| 1162 | 1162 | $permastruct_args['feed'] = $permastruct_args['feeds']; |
| 1163 | - add_permastruct( $post_type, "{$args->rewrite['slug']}/%$post_type%", $permastruct_args ); |
|
| 1163 | + add_permastruct($post_type, "{$args->rewrite['slug']}/%$post_type%", $permastruct_args); |
|
| 1164 | 1164 | } |
| 1165 | 1165 | |
| 1166 | 1166 | // Register the post type meta box if a custom callback was specified. |
| 1167 | - if ( $args->register_meta_box_cb ) |
|
| 1168 | - add_action( 'add_meta_boxes_' . $post_type, $args->register_meta_box_cb, 10, 1 ); |
|
| 1167 | + if ($args->register_meta_box_cb) |
|
| 1168 | + add_action('add_meta_boxes_'.$post_type, $args->register_meta_box_cb, 10, 1); |
|
| 1169 | 1169 | |
| 1170 | - $args->labels = get_post_type_labels( $args ); |
|
| 1170 | + $args->labels = get_post_type_labels($args); |
|
| 1171 | 1171 | $args->label = $args->labels->name; |
| 1172 | 1172 | |
| 1173 | - $wp_post_types[ $post_type ] = $args; |
|
| 1173 | + $wp_post_types[$post_type] = $args; |
|
| 1174 | 1174 | |
| 1175 | - add_action( 'future_' . $post_type, '_future_post_hook', 5, 2 ); |
|
| 1175 | + add_action('future_'.$post_type, '_future_post_hook', 5, 2); |
|
| 1176 | 1176 | |
| 1177 | - foreach ( $args->taxonomies as $taxonomy ) { |
|
| 1178 | - register_taxonomy_for_object_type( $taxonomy, $post_type ); |
|
| 1177 | + foreach ($args->taxonomies as $taxonomy) { |
|
| 1178 | + register_taxonomy_for_object_type($taxonomy, $post_type); |
|
| 1179 | 1179 | } |
| 1180 | 1180 | |
| 1181 | 1181 | /** |
@@ -1186,7 +1186,7 @@ discard block |
||
| 1186 | 1186 | * @param string $post_type Post type. |
| 1187 | 1187 | * @param object $args Arguments used to register the post type. |
| 1188 | 1188 | */ |
| 1189 | - do_action( 'registered_post_type', $post_type, $args ); |
|
| 1189 | + do_action('registered_post_type', $post_type, $args); |
|
| 1190 | 1190 | |
| 1191 | 1191 | return $args; |
| 1192 | 1192 | } |
@@ -1207,59 +1207,59 @@ discard block |
||
| 1207 | 1207 | * @param string $post_type Post type to unregister. |
| 1208 | 1208 | * @return bool|WP_Error True on success, WP_Error on failure or if the post type doesn't exist. |
| 1209 | 1209 | */ |
| 1210 | -function unregister_post_type( $post_type ) { |
|
| 1211 | - if ( ! post_type_exists( $post_type ) ) { |
|
| 1212 | - return new WP_Error( 'invalid_post_type', __( 'Invalid post type' ) ); |
|
| 1210 | +function unregister_post_type($post_type) { |
|
| 1211 | + if ( ! post_type_exists($post_type)) { |
|
| 1212 | + return new WP_Error('invalid_post_type', __('Invalid post type')); |
|
| 1213 | 1213 | } |
| 1214 | 1214 | |
| 1215 | - $post_type_args = get_post_type_object( $post_type ); |
|
| 1215 | + $post_type_args = get_post_type_object($post_type); |
|
| 1216 | 1216 | |
| 1217 | 1217 | // Do not allow unregistering internal post types. |
| 1218 | - if ( $post_type_args->_builtin ) { |
|
| 1219 | - return new WP_Error( 'invalid_post_type', __( 'Unregistering a built-in post type is not allowed' ) ); |
|
| 1218 | + if ($post_type_args->_builtin) { |
|
| 1219 | + return new WP_Error('invalid_post_type', __('Unregistering a built-in post type is not allowed')); |
|
| 1220 | 1220 | } |
| 1221 | 1221 | |
| 1222 | 1222 | global $wp, $wp_rewrite, $_wp_post_type_features, $post_type_meta_caps, $wp_post_types; |
| 1223 | 1223 | |
| 1224 | 1224 | // Remove query var. |
| 1225 | - if ( false !== $post_type_args->query_var ) { |
|
| 1226 | - $wp->remove_query_var( $post_type_args->query_var ); |
|
| 1225 | + if (false !== $post_type_args->query_var) { |
|
| 1226 | + $wp->remove_query_var($post_type_args->query_var); |
|
| 1227 | 1227 | } |
| 1228 | 1228 | |
| 1229 | 1229 | // Remove any rewrite rules, permastructs, and rules. |
| 1230 | - if ( false !== $post_type_args->rewrite ) { |
|
| 1231 | - remove_rewrite_tag( "%$post_type%" ); |
|
| 1232 | - remove_permastruct( $post_type ); |
|
| 1233 | - foreach ( $wp_rewrite->extra_rules_top as $regex => $query ) { |
|
| 1234 | - if ( false !== strpos( $query, "index.php?post_type=$post_type" ) ) { |
|
| 1235 | - unset( $wp_rewrite->extra_rules_top[ $regex ] ); |
|
| 1230 | + if (false !== $post_type_args->rewrite) { |
|
| 1231 | + remove_rewrite_tag("%$post_type%"); |
|
| 1232 | + remove_permastruct($post_type); |
|
| 1233 | + foreach ($wp_rewrite->extra_rules_top as $regex => $query) { |
|
| 1234 | + if (false !== strpos($query, "index.php?post_type=$post_type")) { |
|
| 1235 | + unset($wp_rewrite->extra_rules_top[$regex]); |
|
| 1236 | 1236 | } |
| 1237 | 1237 | } |
| 1238 | 1238 | } |
| 1239 | 1239 | |
| 1240 | 1240 | // Remove registered custom meta capabilities. |
| 1241 | - foreach ( $post_type_args->cap as $cap ) { |
|
| 1242 | - unset( $post_type_meta_caps[ $cap ] ); |
|
| 1241 | + foreach ($post_type_args->cap as $cap) { |
|
| 1242 | + unset($post_type_meta_caps[$cap]); |
|
| 1243 | 1243 | } |
| 1244 | 1244 | |
| 1245 | 1245 | // Remove all post type support. |
| 1246 | - unset( $_wp_post_type_features[ $post_type ] ); |
|
| 1246 | + unset($_wp_post_type_features[$post_type]); |
|
| 1247 | 1247 | |
| 1248 | 1248 | // Unregister the post type meta box if a custom callback was specified. |
| 1249 | - if ( $post_type_args->register_meta_box_cb ) { |
|
| 1250 | - remove_action( 'add_meta_boxes_' . $post_type, $post_type_args->register_meta_box_cb ); |
|
| 1249 | + if ($post_type_args->register_meta_box_cb) { |
|
| 1250 | + remove_action('add_meta_boxes_'.$post_type, $post_type_args->register_meta_box_cb); |
|
| 1251 | 1251 | } |
| 1252 | 1252 | |
| 1253 | 1253 | // Remove the post type from all taxonomies. |
| 1254 | - foreach ( get_object_taxonomies( $post_type ) as $taxonomy ) { |
|
| 1255 | - unregister_taxonomy_for_object_type( $taxonomy, $post_type ); |
|
| 1254 | + foreach (get_object_taxonomies($post_type) as $taxonomy) { |
|
| 1255 | + unregister_taxonomy_for_object_type($taxonomy, $post_type); |
|
| 1256 | 1256 | } |
| 1257 | 1257 | |
| 1258 | 1258 | // Remove the future post hook action. |
| 1259 | - remove_action( 'future_' . $post_type, '_future_post_hook', 5 ); |
|
| 1259 | + remove_action('future_'.$post_type, '_future_post_hook', 5); |
|
| 1260 | 1260 | |
| 1261 | 1261 | // Remove the post type. |
| 1262 | - unset( $wp_post_types[ $post_type ] ); |
|
| 1262 | + unset($wp_post_types[$post_type]); |
|
| 1263 | 1263 | |
| 1264 | 1264 | /** |
| 1265 | 1265 | * Fires after a post type was unregistered. |
@@ -1268,7 +1268,7 @@ discard block |
||
| 1268 | 1268 | * |
| 1269 | 1269 | * @param string $post_type Post type key. |
| 1270 | 1270 | */ |
| 1271 | - do_action( 'unregistered_post_type', $post_type ); |
|
| 1271 | + do_action('unregistered_post_type', $post_type); |
|
| 1272 | 1272 | |
| 1273 | 1273 | return true; |
| 1274 | 1274 | } |
@@ -1328,48 +1328,48 @@ discard block |
||
| 1328 | 1328 | * @param object $args Post type registration arguments. |
| 1329 | 1329 | * @return object object with all the capabilities as member variables. |
| 1330 | 1330 | */ |
| 1331 | -function get_post_type_capabilities( $args ) { |
|
| 1332 | - if ( ! is_array( $args->capability_type ) ) |
|
| 1333 | - $args->capability_type = array( $args->capability_type, $args->capability_type . 's' ); |
|
| 1331 | +function get_post_type_capabilities($args) { |
|
| 1332 | + if ( ! is_array($args->capability_type)) |
|
| 1333 | + $args->capability_type = array($args->capability_type, $args->capability_type.'s'); |
|
| 1334 | 1334 | |
| 1335 | 1335 | // Singular base for meta capabilities, plural base for primitive capabilities. |
| 1336 | - list( $singular_base, $plural_base ) = $args->capability_type; |
|
| 1336 | + list($singular_base, $plural_base) = $args->capability_type; |
|
| 1337 | 1337 | |
| 1338 | 1338 | $default_capabilities = array( |
| 1339 | 1339 | // Meta capabilities |
| 1340 | - 'edit_post' => 'edit_' . $singular_base, |
|
| 1341 | - 'read_post' => 'read_' . $singular_base, |
|
| 1342 | - 'delete_post' => 'delete_' . $singular_base, |
|
| 1340 | + 'edit_post' => 'edit_'.$singular_base, |
|
| 1341 | + 'read_post' => 'read_'.$singular_base, |
|
| 1342 | + 'delete_post' => 'delete_'.$singular_base, |
|
| 1343 | 1343 | // Primitive capabilities used outside of map_meta_cap(): |
| 1344 | - 'edit_posts' => 'edit_' . $plural_base, |
|
| 1345 | - 'edit_others_posts' => 'edit_others_' . $plural_base, |
|
| 1346 | - 'publish_posts' => 'publish_' . $plural_base, |
|
| 1347 | - 'read_private_posts' => 'read_private_' . $plural_base, |
|
| 1344 | + 'edit_posts' => 'edit_'.$plural_base, |
|
| 1345 | + 'edit_others_posts' => 'edit_others_'.$plural_base, |
|
| 1346 | + 'publish_posts' => 'publish_'.$plural_base, |
|
| 1347 | + 'read_private_posts' => 'read_private_'.$plural_base, |
|
| 1348 | 1348 | ); |
| 1349 | 1349 | |
| 1350 | 1350 | // Primitive capabilities used within map_meta_cap(): |
| 1351 | - if ( $args->map_meta_cap ) { |
|
| 1351 | + if ($args->map_meta_cap) { |
|
| 1352 | 1352 | $default_capabilities_for_mapping = array( |
| 1353 | 1353 | 'read' => 'read', |
| 1354 | - 'delete_posts' => 'delete_' . $plural_base, |
|
| 1355 | - 'delete_private_posts' => 'delete_private_' . $plural_base, |
|
| 1356 | - 'delete_published_posts' => 'delete_published_' . $plural_base, |
|
| 1357 | - 'delete_others_posts' => 'delete_others_' . $plural_base, |
|
| 1358 | - 'edit_private_posts' => 'edit_private_' . $plural_base, |
|
| 1359 | - 'edit_published_posts' => 'edit_published_' . $plural_base, |
|
| 1354 | + 'delete_posts' => 'delete_'.$plural_base, |
|
| 1355 | + 'delete_private_posts' => 'delete_private_'.$plural_base, |
|
| 1356 | + 'delete_published_posts' => 'delete_published_'.$plural_base, |
|
| 1357 | + 'delete_others_posts' => 'delete_others_'.$plural_base, |
|
| 1358 | + 'edit_private_posts' => 'edit_private_'.$plural_base, |
|
| 1359 | + 'edit_published_posts' => 'edit_published_'.$plural_base, |
|
| 1360 | 1360 | ); |
| 1361 | - $default_capabilities = array_merge( $default_capabilities, $default_capabilities_for_mapping ); |
|
| 1361 | + $default_capabilities = array_merge($default_capabilities, $default_capabilities_for_mapping); |
|
| 1362 | 1362 | } |
| 1363 | 1363 | |
| 1364 | - $capabilities = array_merge( $default_capabilities, $args->capabilities ); |
|
| 1364 | + $capabilities = array_merge($default_capabilities, $args->capabilities); |
|
| 1365 | 1365 | |
| 1366 | 1366 | // Post creation capability simply maps to edit_posts by default: |
| 1367 | - if ( ! isset( $capabilities['create_posts'] ) ) |
|
| 1367 | + if ( ! isset($capabilities['create_posts'])) |
|
| 1368 | 1368 | $capabilities['create_posts'] = $capabilities['edit_posts']; |
| 1369 | 1369 | |
| 1370 | 1370 | // Remember meta capabilities for future reference. |
| 1371 | - if ( $args->map_meta_cap ) |
|
| 1372 | - _post_type_meta_capabilities( $capabilities ); |
|
| 1371 | + if ($args->map_meta_cap) |
|
| 1372 | + _post_type_meta_capabilities($capabilities); |
|
| 1373 | 1373 | |
| 1374 | 1374 | return (object) $capabilities; |
| 1375 | 1375 | } |
@@ -1384,12 +1384,12 @@ discard block |
||
| 1384 | 1384 | * |
| 1385 | 1385 | * @param array $capabilities Post type meta capabilities. |
| 1386 | 1386 | */ |
| 1387 | -function _post_type_meta_capabilities( $capabilities = null ) { |
|
| 1387 | +function _post_type_meta_capabilities($capabilities = null) { |
|
| 1388 | 1388 | global $post_type_meta_caps; |
| 1389 | 1389 | |
| 1390 | - foreach ( $capabilities as $core => $custom ) { |
|
| 1391 | - if ( in_array( $core, array( 'read_post', 'delete_post', 'edit_post' ) ) ) { |
|
| 1392 | - $post_type_meta_caps[ $custom ] = $core; |
|
| 1390 | + foreach ($capabilities as $core => $custom) { |
|
| 1391 | + if (in_array($core, array('read_post', 'delete_post', 'edit_post'))) { |
|
| 1392 | + $post_type_meta_caps[$custom] = $core; |
|
| 1393 | 1393 | } |
| 1394 | 1394 | } |
| 1395 | 1395 | } |
@@ -1442,34 +1442,34 @@ discard block |
||
| 1442 | 1442 | * @param object $post_type_object Post type object. |
| 1443 | 1443 | * @return object object with all the labels as member variables. |
| 1444 | 1444 | */ |
| 1445 | -function get_post_type_labels( $post_type_object ) { |
|
| 1445 | +function get_post_type_labels($post_type_object) { |
|
| 1446 | 1446 | $nohier_vs_hier_defaults = array( |
| 1447 | - 'name' => array( _x('Posts', 'post type general name'), _x('Pages', 'post type general name') ), |
|
| 1448 | - 'singular_name' => array( _x('Post', 'post type singular name'), _x('Page', 'post type singular name') ), |
|
| 1449 | - 'add_new' => array( _x('Add New', 'post'), _x('Add New', 'page') ), |
|
| 1450 | - 'add_new_item' => array( __('Add New Post'), __('Add New Page') ), |
|
| 1451 | - 'edit_item' => array( __('Edit Post'), __('Edit Page') ), |
|
| 1452 | - 'new_item' => array( __('New Post'), __('New Page') ), |
|
| 1453 | - 'view_item' => array( __('View Post'), __('View Page') ), |
|
| 1454 | - 'search_items' => array( __('Search Posts'), __('Search Pages') ), |
|
| 1455 | - 'not_found' => array( __('No posts found.'), __('No pages found.') ), |
|
| 1456 | - 'not_found_in_trash' => array( __('No posts found in Trash.'), __('No pages found in Trash.') ), |
|
| 1457 | - 'parent_item_colon' => array( null, __('Parent Page:') ), |
|
| 1458 | - 'all_items' => array( __( 'All Posts' ), __( 'All Pages' ) ), |
|
| 1459 | - 'archives' => array( __( 'Post Archives' ), __( 'Page Archives' ) ), |
|
| 1460 | - 'insert_into_item' => array( __( 'Insert into post' ), __( 'Insert into page' ) ), |
|
| 1461 | - 'uploaded_to_this_item' => array( __( 'Uploaded to this post' ), __( 'Uploaded to this page' ) ), |
|
| 1462 | - 'featured_image' => array( __( 'Featured Image' ), __( 'Featured Image' ) ), |
|
| 1463 | - 'set_featured_image' => array( __( 'Set featured image' ), __( 'Set featured image' ) ), |
|
| 1464 | - 'remove_featured_image' => array( __( 'Remove featured image' ), __( 'Remove featured image' ) ), |
|
| 1465 | - 'use_featured_image' => array( __( 'Use as featured image' ), __( 'Use as featured image' ) ), |
|
| 1466 | - 'filter_items_list' => array( __( 'Filter posts list' ), __( 'Filter pages list' ) ), |
|
| 1467 | - 'items_list_navigation' => array( __( 'Posts list navigation' ), __( 'Pages list navigation' ) ), |
|
| 1468 | - 'items_list' => array( __( 'Posts list' ), __( 'Pages list' ) ), |
|
| 1447 | + 'name' => array(_x('Posts', 'post type general name'), _x('Pages', 'post type general name')), |
|
| 1448 | + 'singular_name' => array(_x('Post', 'post type singular name'), _x('Page', 'post type singular name')), |
|
| 1449 | + 'add_new' => array(_x('Add New', 'post'), _x('Add New', 'page')), |
|
| 1450 | + 'add_new_item' => array(__('Add New Post'), __('Add New Page')), |
|
| 1451 | + 'edit_item' => array(__('Edit Post'), __('Edit Page')), |
|
| 1452 | + 'new_item' => array(__('New Post'), __('New Page')), |
|
| 1453 | + 'view_item' => array(__('View Post'), __('View Page')), |
|
| 1454 | + 'search_items' => array(__('Search Posts'), __('Search Pages')), |
|
| 1455 | + 'not_found' => array(__('No posts found.'), __('No pages found.')), |
|
| 1456 | + 'not_found_in_trash' => array(__('No posts found in Trash.'), __('No pages found in Trash.')), |
|
| 1457 | + 'parent_item_colon' => array(null, __('Parent Page:')), |
|
| 1458 | + 'all_items' => array(__('All Posts'), __('All Pages')), |
|
| 1459 | + 'archives' => array(__('Post Archives'), __('Page Archives')), |
|
| 1460 | + 'insert_into_item' => array(__('Insert into post'), __('Insert into page')), |
|
| 1461 | + 'uploaded_to_this_item' => array(__('Uploaded to this post'), __('Uploaded to this page')), |
|
| 1462 | + 'featured_image' => array(__('Featured Image'), __('Featured Image')), |
|
| 1463 | + 'set_featured_image' => array(__('Set featured image'), __('Set featured image')), |
|
| 1464 | + 'remove_featured_image' => array(__('Remove featured image'), __('Remove featured image')), |
|
| 1465 | + 'use_featured_image' => array(__('Use as featured image'), __('Use as featured image')), |
|
| 1466 | + 'filter_items_list' => array(__('Filter posts list'), __('Filter pages list')), |
|
| 1467 | + 'items_list_navigation' => array(__('Posts list navigation'), __('Pages list navigation')), |
|
| 1468 | + 'items_list' => array(__('Posts list'), __('Pages list')), |
|
| 1469 | 1469 | ); |
| 1470 | 1470 | $nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name']; |
| 1471 | 1471 | |
| 1472 | - $labels = _get_custom_object_labels( $post_type_object, $nohier_vs_hier_defaults ); |
|
| 1472 | + $labels = _get_custom_object_labels($post_type_object, $nohier_vs_hier_defaults); |
|
| 1473 | 1473 | |
| 1474 | 1474 | $post_type = $post_type_object->name; |
| 1475 | 1475 | |
@@ -1487,10 +1487,10 @@ discard block |
||
| 1487 | 1487 | * |
| 1488 | 1488 | * @param object $labels Object with labels for the post type as member variables. |
| 1489 | 1489 | */ |
| 1490 | - $labels = apply_filters( "post_type_labels_{$post_type}", $labels ); |
|
| 1490 | + $labels = apply_filters("post_type_labels_{$post_type}", $labels); |
|
| 1491 | 1491 | |
| 1492 | 1492 | // Ensure that the filtered labels contain all required default values. |
| 1493 | - $labels = (object) array_merge( (array) $default_labels, (array) $labels ); |
|
| 1493 | + $labels = (object) array_merge((array) $default_labels, (array) $labels); |
|
| 1494 | 1494 | |
| 1495 | 1495 | return $labels; |
| 1496 | 1496 | } |
@@ -1506,33 +1506,33 @@ discard block |
||
| 1506 | 1506 | * @param array $nohier_vs_hier_defaults Hierarchical vs non-hierarchical default labels. |
| 1507 | 1507 | * @return object Object containing labels for the given custom-something object. |
| 1508 | 1508 | */ |
| 1509 | -function _get_custom_object_labels( $object, $nohier_vs_hier_defaults ) { |
|
| 1509 | +function _get_custom_object_labels($object, $nohier_vs_hier_defaults) { |
|
| 1510 | 1510 | $object->labels = (array) $object->labels; |
| 1511 | 1511 | |
| 1512 | - if ( isset( $object->label ) && empty( $object->labels['name'] ) ) |
|
| 1512 | + if (isset($object->label) && empty($object->labels['name'])) |
|
| 1513 | 1513 | $object->labels['name'] = $object->label; |
| 1514 | 1514 | |
| 1515 | - if ( !isset( $object->labels['singular_name'] ) && isset( $object->labels['name'] ) ) |
|
| 1515 | + if ( ! isset($object->labels['singular_name']) && isset($object->labels['name'])) |
|
| 1516 | 1516 | $object->labels['singular_name'] = $object->labels['name']; |
| 1517 | 1517 | |
| 1518 | - if ( ! isset( $object->labels['name_admin_bar'] ) ) |
|
| 1519 | - $object->labels['name_admin_bar'] = isset( $object->labels['singular_name'] ) ? $object->labels['singular_name'] : $object->name; |
|
| 1518 | + if ( ! isset($object->labels['name_admin_bar'])) |
|
| 1519 | + $object->labels['name_admin_bar'] = isset($object->labels['singular_name']) ? $object->labels['singular_name'] : $object->name; |
|
| 1520 | 1520 | |
| 1521 | - if ( !isset( $object->labels['menu_name'] ) && isset( $object->labels['name'] ) ) |
|
| 1521 | + if ( ! isset($object->labels['menu_name']) && isset($object->labels['name'])) |
|
| 1522 | 1522 | $object->labels['menu_name'] = $object->labels['name']; |
| 1523 | 1523 | |
| 1524 | - if ( !isset( $object->labels['all_items'] ) && isset( $object->labels['menu_name'] ) ) |
|
| 1524 | + if ( ! isset($object->labels['all_items']) && isset($object->labels['menu_name'])) |
|
| 1525 | 1525 | $object->labels['all_items'] = $object->labels['menu_name']; |
| 1526 | 1526 | |
| 1527 | - if ( !isset( $object->labels['archives'] ) && isset( $object->labels['all_items'] ) ) { |
|
| 1527 | + if ( ! isset($object->labels['archives']) && isset($object->labels['all_items'])) { |
|
| 1528 | 1528 | $object->labels['archives'] = $object->labels['all_items']; |
| 1529 | 1529 | } |
| 1530 | 1530 | |
| 1531 | 1531 | $defaults = array(); |
| 1532 | - foreach ( $nohier_vs_hier_defaults as $key => $value ) { |
|
| 1532 | + foreach ($nohier_vs_hier_defaults as $key => $value) { |
|
| 1533 | 1533 | $defaults[$key] = $object->hierarchical ? $value[1] : $value[0]; |
| 1534 | 1534 | } |
| 1535 | - $labels = array_merge( $defaults, $object->labels ); |
|
| 1535 | + $labels = array_merge($defaults, $object->labels); |
|
| 1536 | 1536 | $object->labels = (object) $object->labels; |
| 1537 | 1537 | |
| 1538 | 1538 | return (object) $labels; |
@@ -1545,12 +1545,12 @@ discard block |
||
| 1545 | 1545 | * @since 3.1.0 |
| 1546 | 1546 | */ |
| 1547 | 1547 | function _add_post_type_submenus() { |
| 1548 | - foreach ( get_post_types( array( 'show_ui' => true ) ) as $ptype ) { |
|
| 1549 | - $ptype_obj = get_post_type_object( $ptype ); |
|
| 1548 | + foreach (get_post_types(array('show_ui' => true)) as $ptype) { |
|
| 1549 | + $ptype_obj = get_post_type_object($ptype); |
|
| 1550 | 1550 | // Sub-menus only. |
| 1551 | - if ( ! $ptype_obj->show_in_menu || $ptype_obj->show_in_menu === true ) |
|
| 1551 | + if ( ! $ptype_obj->show_in_menu || $ptype_obj->show_in_menu === true) |
|
| 1552 | 1552 | continue; |
| 1553 | - add_submenu_page( $ptype_obj->show_in_menu, $ptype_obj->labels->name, $ptype_obj->labels->all_items, $ptype_obj->cap->edit_posts, "edit.php?post_type=$ptype" ); |
|
| 1553 | + add_submenu_page($ptype_obj->show_in_menu, $ptype_obj->labels->name, $ptype_obj->labels->all_items, $ptype_obj->cap->edit_posts, "edit.php?post_type=$ptype"); |
|
| 1554 | 1554 | } |
| 1555 | 1555 | } |
| 1556 | 1556 | |
@@ -1574,15 +1574,15 @@ discard block |
||
| 1574 | 1574 | * @param string|array $feature The feature being added, accepts an array of |
| 1575 | 1575 | * feature strings or a single string. |
| 1576 | 1576 | */ |
| 1577 | -function add_post_type_support( $post_type, $feature ) { |
|
| 1577 | +function add_post_type_support($post_type, $feature) { |
|
| 1578 | 1578 | global $_wp_post_type_features; |
| 1579 | 1579 | |
| 1580 | 1580 | $features = (array) $feature; |
| 1581 | 1581 | foreach ($features as $feature) { |
| 1582 | - if ( func_num_args() == 2 ) |
|
| 1582 | + if (func_num_args() == 2) |
|
| 1583 | 1583 | $_wp_post_type_features[$post_type][$feature] = true; |
| 1584 | 1584 | else |
| 1585 | - $_wp_post_type_features[$post_type][$feature] = array_slice( func_get_args(), 2 ); |
|
| 1585 | + $_wp_post_type_features[$post_type][$feature] = array_slice(func_get_args(), 2); |
|
| 1586 | 1586 | } |
| 1587 | 1587 | } |
| 1588 | 1588 | |
@@ -1596,10 +1596,10 @@ discard block |
||
| 1596 | 1596 | * @param string $post_type The post type for which to remove the feature. |
| 1597 | 1597 | * @param string $feature The feature being removed. |
| 1598 | 1598 | */ |
| 1599 | -function remove_post_type_support( $post_type, $feature ) { |
|
| 1599 | +function remove_post_type_support($post_type, $feature) { |
|
| 1600 | 1600 | global $_wp_post_type_features; |
| 1601 | 1601 | |
| 1602 | - unset( $_wp_post_type_features[ $post_type ][ $feature ] ); |
|
| 1602 | + unset($_wp_post_type_features[$post_type][$feature]); |
|
| 1603 | 1603 | } |
| 1604 | 1604 | |
| 1605 | 1605 | /** |
@@ -1612,10 +1612,10 @@ discard block |
||
| 1612 | 1612 | * @param string $post_type The post type. |
| 1613 | 1613 | * @return array Post type supports list. |
| 1614 | 1614 | */ |
| 1615 | -function get_all_post_type_supports( $post_type ) { |
|
| 1615 | +function get_all_post_type_supports($post_type) { |
|
| 1616 | 1616 | global $_wp_post_type_features; |
| 1617 | 1617 | |
| 1618 | - if ( isset( $_wp_post_type_features[$post_type] ) ) |
|
| 1618 | + if (isset($_wp_post_type_features[$post_type])) |
|
| 1619 | 1619 | return $_wp_post_type_features[$post_type]; |
| 1620 | 1620 | |
| 1621 | 1621 | return array(); |
@@ -1632,10 +1632,10 @@ discard block |
||
| 1632 | 1632 | * @param string $feature The feature being checked. |
| 1633 | 1633 | * @return bool Whether the post type supports the given feature. |
| 1634 | 1634 | */ |
| 1635 | -function post_type_supports( $post_type, $feature ) { |
|
| 1635 | +function post_type_supports($post_type, $feature) { |
|
| 1636 | 1636 | global $_wp_post_type_features; |
| 1637 | 1637 | |
| 1638 | - return ( isset( $_wp_post_type_features[$post_type][$feature] ) ); |
|
| 1638 | + return (isset($_wp_post_type_features[$post_type][$feature])); |
|
| 1639 | 1639 | } |
| 1640 | 1640 | |
| 1641 | 1641 | /** |
@@ -1652,12 +1652,12 @@ discard block |
||
| 1652 | 1652 | * match. Default 'and'. |
| 1653 | 1653 | * @return array A list of post type names. |
| 1654 | 1654 | */ |
| 1655 | -function get_post_types_by_support( $feature, $operator = 'and' ) { |
|
| 1655 | +function get_post_types_by_support($feature, $operator = 'and') { |
|
| 1656 | 1656 | global $_wp_post_type_features; |
| 1657 | 1657 | |
| 1658 | - $features = array_fill_keys( (array) $feature, true ); |
|
| 1658 | + $features = array_fill_keys((array) $feature, true); |
|
| 1659 | 1659 | |
| 1660 | - return array_keys( wp_filter_object_list( $_wp_post_type_features, $features, $operator ) ); |
|
| 1660 | + return array_keys(wp_filter_object_list($_wp_post_type_features, $features, $operator)); |
|
| 1661 | 1661 | } |
| 1662 | 1662 | |
| 1663 | 1663 | /** |
@@ -1674,13 +1674,13 @@ discard block |
||
| 1674 | 1674 | * name a few. Default 'post'. |
| 1675 | 1675 | * @return int|false Amount of rows changed. Should be 1 for success and 0 for failure. |
| 1676 | 1676 | */ |
| 1677 | -function set_post_type( $post_id = 0, $post_type = 'post' ) { |
|
| 1677 | +function set_post_type($post_id = 0, $post_type = 'post') { |
|
| 1678 | 1678 | global $wpdb; |
| 1679 | 1679 | |
| 1680 | 1680 | $post_type = sanitize_post_field('post_type', $post_type, $post_id, 'db'); |
| 1681 | - $return = $wpdb->update( $wpdb->posts, array('post_type' => $post_type), array('ID' => $post_id) ); |
|
| 1681 | + $return = $wpdb->update($wpdb->posts, array('post_type' => $post_type), array('ID' => $post_id)); |
|
| 1682 | 1682 | |
| 1683 | - clean_post_cache( $post_id ); |
|
| 1683 | + clean_post_cache($post_id); |
|
| 1684 | 1684 | |
| 1685 | 1685 | return $return; |
| 1686 | 1686 | } |
@@ -1697,15 +1697,15 @@ discard block |
||
| 1697 | 1697 | * @param object $post_type Post type name or object. |
| 1698 | 1698 | * @return bool Whether the post type should be considered viewable. |
| 1699 | 1699 | */ |
| 1700 | -function is_post_type_viewable( $post_type ) { |
|
| 1701 | - if ( is_scalar( $post_type ) ) { |
|
| 1702 | - $post_type = get_post_type_object( $post_type ); |
|
| 1703 | - if ( ! $post_type ) { |
|
| 1700 | +function is_post_type_viewable($post_type) { |
|
| 1701 | + if (is_scalar($post_type)) { |
|
| 1702 | + $post_type = get_post_type_object($post_type); |
|
| 1703 | + if ( ! $post_type) { |
|
| 1704 | 1704 | return false; |
| 1705 | 1705 | } |
| 1706 | 1706 | } |
| 1707 | 1707 | |
| 1708 | - return $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public ); |
|
| 1708 | + return $post_type->publicly_queryable || ($post_type->_builtin && $post_type->public); |
|
| 1709 | 1709 | } |
| 1710 | 1710 | |
| 1711 | 1711 | /** |
@@ -1732,7 +1732,7 @@ discard block |
||
| 1732 | 1732 | * } |
| 1733 | 1733 | * @return array List of posts. |
| 1734 | 1734 | */ |
| 1735 | -function get_posts( $args = null ) { |
|
| 1735 | +function get_posts($args = null) { |
|
| 1736 | 1736 | $defaults = array( |
| 1737 | 1737 | 'numberposts' => 5, |
| 1738 | 1738 | 'category' => 0, 'orderby' => 'date', |
@@ -1742,19 +1742,19 @@ discard block |
||
| 1742 | 1742 | 'suppress_filters' => true |
| 1743 | 1743 | ); |
| 1744 | 1744 | |
| 1745 | - $r = wp_parse_args( $args, $defaults ); |
|
| 1746 | - if ( empty( $r['post_status'] ) ) |
|
| 1747 | - $r['post_status'] = ( 'attachment' == $r['post_type'] ) ? 'inherit' : 'publish'; |
|
| 1748 | - if ( ! empty($r['numberposts']) && empty($r['posts_per_page']) ) |
|
| 1745 | + $r = wp_parse_args($args, $defaults); |
|
| 1746 | + if (empty($r['post_status'])) |
|
| 1747 | + $r['post_status'] = ('attachment' == $r['post_type']) ? 'inherit' : 'publish'; |
|
| 1748 | + if ( ! empty($r['numberposts']) && empty($r['posts_per_page'])) |
|
| 1749 | 1749 | $r['posts_per_page'] = $r['numberposts']; |
| 1750 | - if ( ! empty($r['category']) ) |
|
| 1750 | + if ( ! empty($r['category'])) |
|
| 1751 | 1751 | $r['cat'] = $r['category']; |
| 1752 | - if ( ! empty($r['include']) ) { |
|
| 1753 | - $incposts = wp_parse_id_list( $r['include'] ); |
|
| 1754 | - $r['posts_per_page'] = count($incposts); // only the number of posts included |
|
| 1752 | + if ( ! empty($r['include'])) { |
|
| 1753 | + $incposts = wp_parse_id_list($r['include']); |
|
| 1754 | + $r['posts_per_page'] = count($incposts); // only the number of posts included |
|
| 1755 | 1755 | $r['post__in'] = $incposts; |
| 1756 | - } elseif ( ! empty($r['exclude']) ) |
|
| 1757 | - $r['post__not_in'] = wp_parse_id_list( $r['exclude'] ); |
|
| 1756 | + } elseif ( ! empty($r['exclude'])) |
|
| 1757 | + $r['post__not_in'] = wp_parse_id_list($r['exclude']); |
|
| 1758 | 1758 | |
| 1759 | 1759 | $r['ignore_sticky_posts'] = true; |
| 1760 | 1760 | $r['no_found_rows'] = true; |
@@ -1782,9 +1782,9 @@ discard block |
||
| 1782 | 1782 | * Default false. |
| 1783 | 1783 | * @return int|false Meta ID on success, false on failure. |
| 1784 | 1784 | */ |
| 1785 | -function add_post_meta( $post_id, $meta_key, $meta_value, $unique = false ) { |
|
| 1785 | +function add_post_meta($post_id, $meta_key, $meta_value, $unique = false) { |
|
| 1786 | 1786 | // Make sure meta is added to the post, not a revision. |
| 1787 | - if ( $the_post = wp_is_post_revision($post_id) ) |
|
| 1787 | + if ($the_post = wp_is_post_revision($post_id)) |
|
| 1788 | 1788 | $post_id = $the_post; |
| 1789 | 1789 | |
| 1790 | 1790 | return add_metadata('post', $post_id, $meta_key, $meta_value, $unique); |
@@ -1805,9 +1805,9 @@ discard block |
||
| 1805 | 1805 | * non-scalar. Default empty. |
| 1806 | 1806 | * @return bool True on success, false on failure. |
| 1807 | 1807 | */ |
| 1808 | -function delete_post_meta( $post_id, $meta_key, $meta_value = '' ) { |
|
| 1808 | +function delete_post_meta($post_id, $meta_key, $meta_value = '') { |
|
| 1809 | 1809 | // Make sure meta is added to the post, not a revision. |
| 1810 | - if ( $the_post = wp_is_post_revision($post_id) ) |
|
| 1810 | + if ($the_post = wp_is_post_revision($post_id)) |
|
| 1811 | 1811 | $post_id = $the_post; |
| 1812 | 1812 | |
| 1813 | 1813 | return delete_metadata('post', $post_id, $meta_key, $meta_value); |
@@ -1825,7 +1825,7 @@ discard block |
||
| 1825 | 1825 | * @return mixed Will be an array if $single is false. Will be value of meta data |
| 1826 | 1826 | * field if $single is true. |
| 1827 | 1827 | */ |
| 1828 | -function get_post_meta( $post_id, $key = '', $single = false ) { |
|
| 1828 | +function get_post_meta($post_id, $key = '', $single = false) { |
|
| 1829 | 1829 | return get_metadata('post', $post_id, $key, $single); |
| 1830 | 1830 | } |
| 1831 | 1831 | |
@@ -1847,9 +1847,9 @@ discard block |
||
| 1847 | 1847 | * @return int|bool Meta ID if the key didn't exist, true on successful update, |
| 1848 | 1848 | * false on failure. |
| 1849 | 1849 | */ |
| 1850 | -function update_post_meta( $post_id, $meta_key, $meta_value, $prev_value = '' ) { |
|
| 1850 | +function update_post_meta($post_id, $meta_key, $meta_value, $prev_value = '') { |
|
| 1851 | 1851 | // Make sure meta is added to the post, not a revision. |
| 1852 | - if ( $the_post = wp_is_post_revision($post_id) ) |
|
| 1852 | + if ($the_post = wp_is_post_revision($post_id)) |
|
| 1853 | 1853 | $post_id = $the_post; |
| 1854 | 1854 | |
| 1855 | 1855 | return update_metadata('post', $post_id, $meta_key, $meta_value, $prev_value); |
@@ -1863,8 +1863,8 @@ discard block |
||
| 1863 | 1863 | * @param string $post_meta_key Key to search for when deleting. |
| 1864 | 1864 | * @return bool Whether the post meta key was deleted from the database. |
| 1865 | 1865 | */ |
| 1866 | -function delete_post_meta_by_key( $post_meta_key ) { |
|
| 1867 | - return delete_metadata( 'post', null, $post_meta_key, '', true ); |
|
| 1866 | +function delete_post_meta_by_key($post_meta_key) { |
|
| 1867 | + return delete_metadata('post', null, $post_meta_key, '', true); |
|
| 1868 | 1868 | } |
| 1869 | 1869 | |
| 1870 | 1870 | /** |
@@ -1878,12 +1878,12 @@ discard block |
||
| 1878 | 1878 | * @param int $post_id Optional. Post ID. Default is ID of the global $post. |
| 1879 | 1879 | * @return array Post meta for the given post. |
| 1880 | 1880 | */ |
| 1881 | -function get_post_custom( $post_id = 0 ) { |
|
| 1882 | - $post_id = absint( $post_id ); |
|
| 1883 | - if ( ! $post_id ) |
|
| 1881 | +function get_post_custom($post_id = 0) { |
|
| 1882 | + $post_id = absint($post_id); |
|
| 1883 | + if ( ! $post_id) |
|
| 1884 | 1884 | $post_id = get_the_ID(); |
| 1885 | 1885 | |
| 1886 | - return get_post_meta( $post_id ); |
|
| 1886 | + return get_post_meta($post_id); |
|
| 1887 | 1887 | } |
| 1888 | 1888 | |
| 1889 | 1889 | /** |
@@ -1896,13 +1896,13 @@ discard block |
||
| 1896 | 1896 | * @param int $post_id Optional. Post ID. Default is ID of the global $post. |
| 1897 | 1897 | * @return array|void Array of the keys, if retrieved. |
| 1898 | 1898 | */ |
| 1899 | -function get_post_custom_keys( $post_id = 0 ) { |
|
| 1900 | - $custom = get_post_custom( $post_id ); |
|
| 1899 | +function get_post_custom_keys($post_id = 0) { |
|
| 1900 | + $custom = get_post_custom($post_id); |
|
| 1901 | 1901 | |
| 1902 | - if ( !is_array($custom) ) |
|
| 1902 | + if ( ! is_array($custom)) |
|
| 1903 | 1903 | return; |
| 1904 | 1904 | |
| 1905 | - if ( $keys = array_keys($custom) ) |
|
| 1905 | + if ($keys = array_keys($custom)) |
|
| 1906 | 1906 | return $keys; |
| 1907 | 1907 | } |
| 1908 | 1908 | |
@@ -1918,8 +1918,8 @@ discard block |
||
| 1918 | 1918 | * @param int $post_id Optional. Post ID. Default is ID of the global $post. |
| 1919 | 1919 | * @return array|null Meta field values. |
| 1920 | 1920 | */ |
| 1921 | -function get_post_custom_values( $key = '', $post_id = 0 ) { |
|
| 1922 | - if ( !$key ) |
|
| 1921 | +function get_post_custom_values($key = '', $post_id = 0) { |
|
| 1922 | + if ( ! $key) |
|
| 1923 | 1923 | return null; |
| 1924 | 1924 | |
| 1925 | 1925 | $custom = get_post_custom($post_id); |
@@ -1938,18 +1938,18 @@ discard block |
||
| 1938 | 1938 | * @param int $post_id Optional. Post ID. Default is ID of the global $post. |
| 1939 | 1939 | * @return bool Whether post is sticky. |
| 1940 | 1940 | */ |
| 1941 | -function is_sticky( $post_id = 0 ) { |
|
| 1942 | - $post_id = absint( $post_id ); |
|
| 1941 | +function is_sticky($post_id = 0) { |
|
| 1942 | + $post_id = absint($post_id); |
|
| 1943 | 1943 | |
| 1944 | - if ( ! $post_id ) |
|
| 1944 | + if ( ! $post_id) |
|
| 1945 | 1945 | $post_id = get_the_ID(); |
| 1946 | 1946 | |
| 1947 | - $stickies = get_option( 'sticky_posts' ); |
|
| 1947 | + $stickies = get_option('sticky_posts'); |
|
| 1948 | 1948 | |
| 1949 | - if ( ! is_array( $stickies ) ) |
|
| 1949 | + if ( ! is_array($stickies)) |
|
| 1950 | 1950 | return false; |
| 1951 | 1951 | |
| 1952 | - if ( in_array( $post_id, $stickies ) ) |
|
| 1952 | + if (in_array($post_id, $stickies)) |
|
| 1953 | 1953 | return true; |
| 1954 | 1954 | |
| 1955 | 1955 | return false; |
@@ -1972,23 +1972,23 @@ discard block |
||
| 1972 | 1972 | * @return object|WP_Post|array The now sanitized Post Object or Array (will be the |
| 1973 | 1973 | * same type as $post). |
| 1974 | 1974 | */ |
| 1975 | -function sanitize_post( $post, $context = 'display' ) { |
|
| 1976 | - if ( is_object($post) ) { |
|
| 1975 | +function sanitize_post($post, $context = 'display') { |
|
| 1976 | + if (is_object($post)) { |
|
| 1977 | 1977 | // Check if post already filtered for this context. |
| 1978 | - if ( isset($post->filter) && $context == $post->filter ) |
|
| 1978 | + if (isset($post->filter) && $context == $post->filter) |
|
| 1979 | 1979 | return $post; |
| 1980 | - if ( !isset($post->ID) ) |
|
| 1980 | + if ( ! isset($post->ID)) |
|
| 1981 | 1981 | $post->ID = 0; |
| 1982 | - foreach ( array_keys(get_object_vars($post)) as $field ) |
|
| 1982 | + foreach (array_keys(get_object_vars($post)) as $field) |
|
| 1983 | 1983 | $post->$field = sanitize_post_field($field, $post->$field, $post->ID, $context); |
| 1984 | 1984 | $post->filter = $context; |
| 1985 | - } elseif ( is_array( $post ) ) { |
|
| 1985 | + } elseif (is_array($post)) { |
|
| 1986 | 1986 | // Check if post already filtered for this context. |
| 1987 | - if ( isset($post['filter']) && $context == $post['filter'] ) |
|
| 1987 | + if (isset($post['filter']) && $context == $post['filter']) |
|
| 1988 | 1988 | return $post; |
| 1989 | - if ( !isset($post['ID']) ) |
|
| 1989 | + if ( ! isset($post['ID'])) |
|
| 1990 | 1990 | $post['ID'] = 0; |
| 1991 | - foreach ( array_keys($post) as $field ) |
|
| 1991 | + foreach (array_keys($post) as $field) |
|
| 1992 | 1992 | $post[$field] = sanitize_post_field($field, $post[$field], $post['ID'], $context); |
| 1993 | 1993 | $post['filter'] = $context; |
| 1994 | 1994 | } |
@@ -2012,31 +2012,31 @@ discard block |
||
| 2012 | 2012 | * 'db', 'display', 'attribute' and 'js'. Default 'display'. |
| 2013 | 2013 | * @return mixed Sanitized value. |
| 2014 | 2014 | */ |
| 2015 | -function sanitize_post_field( $field, $value, $post_id, $context = 'display' ) { |
|
| 2015 | +function sanitize_post_field($field, $value, $post_id, $context = 'display') { |
|
| 2016 | 2016 | $int_fields = array('ID', 'post_parent', 'menu_order'); |
| 2017 | - if ( in_array($field, $int_fields) ) |
|
| 2017 | + if (in_array($field, $int_fields)) |
|
| 2018 | 2018 | $value = (int) $value; |
| 2019 | 2019 | |
| 2020 | 2020 | // Fields which contain arrays of integers. |
| 2021 | - $array_int_fields = array( 'ancestors' ); |
|
| 2022 | - if ( in_array($field, $array_int_fields) ) { |
|
| 2023 | - $value = array_map( 'absint', $value); |
|
| 2021 | + $array_int_fields = array('ancestors'); |
|
| 2022 | + if (in_array($field, $array_int_fields)) { |
|
| 2023 | + $value = array_map('absint', $value); |
|
| 2024 | 2024 | return $value; |
| 2025 | 2025 | } |
| 2026 | 2026 | |
| 2027 | - if ( 'raw' == $context ) |
|
| 2027 | + if ('raw' == $context) |
|
| 2028 | 2028 | return $value; |
| 2029 | 2029 | |
| 2030 | 2030 | $prefixed = false; |
| 2031 | - if ( false !== strpos($field, 'post_') ) { |
|
| 2031 | + if (false !== strpos($field, 'post_')) { |
|
| 2032 | 2032 | $prefixed = true; |
| 2033 | 2033 | $field_no_prefix = str_replace('post_', '', $field); |
| 2034 | 2034 | } |
| 2035 | 2035 | |
| 2036 | - if ( 'edit' == $context ) { |
|
| 2036 | + if ('edit' == $context) { |
|
| 2037 | 2037 | $format_to_edit = array('post_content', 'post_excerpt', 'post_title', 'post_password'); |
| 2038 | 2038 | |
| 2039 | - if ( $prefixed ) { |
|
| 2039 | + if ($prefixed) { |
|
| 2040 | 2040 | |
| 2041 | 2041 | /** |
| 2042 | 2042 | * Filter the value of a specific post field to edit. |
@@ -2049,7 +2049,7 @@ discard block |
||
| 2049 | 2049 | * @param mixed $value Value of the post field. |
| 2050 | 2050 | * @param int $post_id Post ID. |
| 2051 | 2051 | */ |
| 2052 | - $value = apply_filters( "edit_{$field}", $value, $post_id ); |
|
| 2052 | + $value = apply_filters("edit_{$field}", $value, $post_id); |
|
| 2053 | 2053 | |
| 2054 | 2054 | /** |
| 2055 | 2055 | * Filter the value of a specific post field to edit. |
@@ -2062,21 +2062,21 @@ discard block |
||
| 2062 | 2062 | * @param mixed $value Value of the post field. |
| 2063 | 2063 | * @param int $post_id Post ID. |
| 2064 | 2064 | */ |
| 2065 | - $value = apply_filters( "{$field_no_prefix}_edit_pre", $value, $post_id ); |
|
| 2065 | + $value = apply_filters("{$field_no_prefix}_edit_pre", $value, $post_id); |
|
| 2066 | 2066 | } else { |
| 2067 | - $value = apply_filters( "edit_post_{$field}", $value, $post_id ); |
|
| 2067 | + $value = apply_filters("edit_post_{$field}", $value, $post_id); |
|
| 2068 | 2068 | } |
| 2069 | 2069 | |
| 2070 | - if ( in_array($field, $format_to_edit) ) { |
|
| 2071 | - if ( 'post_content' == $field ) |
|
| 2070 | + if (in_array($field, $format_to_edit)) { |
|
| 2071 | + if ('post_content' == $field) |
|
| 2072 | 2072 | $value = format_to_edit($value, user_can_richedit()); |
| 2073 | 2073 | else |
| 2074 | 2074 | $value = format_to_edit($value); |
| 2075 | 2075 | } else { |
| 2076 | 2076 | $value = esc_attr($value); |
| 2077 | 2077 | } |
| 2078 | - } elseif ( 'db' == $context ) { |
|
| 2079 | - if ( $prefixed ) { |
|
| 2078 | + } elseif ('db' == $context) { |
|
| 2079 | + if ($prefixed) { |
|
| 2080 | 2080 | |
| 2081 | 2081 | /** |
| 2082 | 2082 | * Filter the value of a specific post field before saving. |
@@ -2088,7 +2088,7 @@ discard block |
||
| 2088 | 2088 | * |
| 2089 | 2089 | * @param mixed $value Value of the post field. |
| 2090 | 2090 | */ |
| 2091 | - $value = apply_filters( "pre_{$field}", $value ); |
|
| 2091 | + $value = apply_filters("pre_{$field}", $value); |
|
| 2092 | 2092 | |
| 2093 | 2093 | /** |
| 2094 | 2094 | * Filter the value of a specific field before saving. |
@@ -2100,9 +2100,9 @@ discard block |
||
| 2100 | 2100 | * |
| 2101 | 2101 | * @param mixed $value Value of the post field. |
| 2102 | 2102 | */ |
| 2103 | - $value = apply_filters( "{$field_no_prefix}_save_pre", $value ); |
|
| 2103 | + $value = apply_filters("{$field_no_prefix}_save_pre", $value); |
|
| 2104 | 2104 | } else { |
| 2105 | - $value = apply_filters( "pre_post_{$field}", $value ); |
|
| 2105 | + $value = apply_filters("pre_post_{$field}", $value); |
|
| 2106 | 2106 | |
| 2107 | 2107 | /** |
| 2108 | 2108 | * Filter the value of a specific post field before saving. |
@@ -2114,12 +2114,12 @@ discard block |
||
| 2114 | 2114 | * |
| 2115 | 2115 | * @param mixed $value Value of the post field. |
| 2116 | 2116 | */ |
| 2117 | - $value = apply_filters( "{$field}_pre", $value ); |
|
| 2117 | + $value = apply_filters("{$field}_pre", $value); |
|
| 2118 | 2118 | } |
| 2119 | 2119 | } else { |
| 2120 | 2120 | |
| 2121 | 2121 | // Use display filters by default. |
| 2122 | - if ( $prefixed ) { |
|
| 2122 | + if ($prefixed) { |
|
| 2123 | 2123 | |
| 2124 | 2124 | /** |
| 2125 | 2125 | * Filter the value of a specific post field for display. |
@@ -2135,15 +2135,15 @@ discard block |
||
| 2135 | 2135 | * values include 'raw', 'edit', 'db', 'display', |
| 2136 | 2136 | * 'attribute' and 'js'. |
| 2137 | 2137 | */ |
| 2138 | - $value = apply_filters( $field, $value, $post_id, $context ); |
|
| 2138 | + $value = apply_filters($field, $value, $post_id, $context); |
|
| 2139 | 2139 | } else { |
| 2140 | - $value = apply_filters( "post_{$field}", $value, $post_id, $context ); |
|
| 2140 | + $value = apply_filters("post_{$field}", $value, $post_id, $context); |
|
| 2141 | 2141 | } |
| 2142 | 2142 | } |
| 2143 | 2143 | |
| 2144 | - if ( 'attribute' == $context ) |
|
| 2144 | + if ('attribute' == $context) |
|
| 2145 | 2145 | $value = esc_attr($value); |
| 2146 | - elseif ( 'js' == $context ) |
|
| 2146 | + elseif ('js' == $context) |
|
| 2147 | 2147 | $value = esc_js($value); |
| 2148 | 2148 | |
| 2149 | 2149 | return $value; |
@@ -2158,13 +2158,13 @@ discard block |
||
| 2158 | 2158 | * |
| 2159 | 2159 | * @param int $post_id Post ID. |
| 2160 | 2160 | */ |
| 2161 | -function stick_post( $post_id ) { |
|
| 2161 | +function stick_post($post_id) { |
|
| 2162 | 2162 | $stickies = get_option('sticky_posts'); |
| 2163 | 2163 | |
| 2164 | - if ( !is_array($stickies) ) |
|
| 2164 | + if ( ! is_array($stickies)) |
|
| 2165 | 2165 | $stickies = array($post_id); |
| 2166 | 2166 | |
| 2167 | - if ( ! in_array($post_id, $stickies) ) |
|
| 2167 | + if ( ! in_array($post_id, $stickies)) |
|
| 2168 | 2168 | $stickies[] = $post_id; |
| 2169 | 2169 | |
| 2170 | 2170 | update_option('sticky_posts', $stickies); |
@@ -2179,17 +2179,17 @@ discard block |
||
| 2179 | 2179 | * |
| 2180 | 2180 | * @param int $post_id Post ID. |
| 2181 | 2181 | */ |
| 2182 | -function unstick_post( $post_id ) { |
|
| 2182 | +function unstick_post($post_id) { |
|
| 2183 | 2183 | $stickies = get_option('sticky_posts'); |
| 2184 | 2184 | |
| 2185 | - if ( !is_array($stickies) ) |
|
| 2185 | + if ( ! is_array($stickies)) |
|
| 2186 | 2186 | return; |
| 2187 | 2187 | |
| 2188 | - if ( ! in_array($post_id, $stickies) ) |
|
| 2188 | + if ( ! in_array($post_id, $stickies)) |
|
| 2189 | 2189 | return; |
| 2190 | 2190 | |
| 2191 | 2191 | $offset = array_search($post_id, $stickies); |
| 2192 | - if ( false === $offset ) |
|
| 2192 | + if (false === $offset) |
|
| 2193 | 2193 | return; |
| 2194 | 2194 | |
| 2195 | 2195 | array_splice($stickies, $offset, 1); |
@@ -2206,12 +2206,12 @@ discard block |
||
| 2206 | 2206 | * @param string $perm Optional. 'readable' or empty. Default empty. |
| 2207 | 2207 | * @return string The cache key. |
| 2208 | 2208 | */ |
| 2209 | -function _count_posts_cache_key( $type = 'post', $perm = '' ) { |
|
| 2210 | - $cache_key = 'posts-' . $type; |
|
| 2211 | - if ( 'readable' == $perm && is_user_logged_in() ) { |
|
| 2212 | - $post_type_object = get_post_type_object( $type ); |
|
| 2213 | - if ( $post_type_object && ! current_user_can( $post_type_object->cap->read_private_posts ) ) { |
|
| 2214 | - $cache_key .= '_' . $perm . '_' . get_current_user_id(); |
|
| 2209 | +function _count_posts_cache_key($type = 'post', $perm = '') { |
|
| 2210 | + $cache_key = 'posts-'.$type; |
|
| 2211 | + if ('readable' == $perm && is_user_logged_in()) { |
|
| 2212 | + $post_type_object = get_post_type_object($type); |
|
| 2213 | + if ($post_type_object && ! current_user_can($post_type_object->cap->read_private_posts)) { |
|
| 2214 | + $cache_key .= '_'.$perm.'_'.get_current_user_id(); |
|
| 2215 | 2215 | } |
| 2216 | 2216 | } |
| 2217 | 2217 | return $cache_key; |
@@ -2236,40 +2236,40 @@ discard block |
||
| 2236 | 2236 | * @param string $perm Optional. 'readable' or empty. Default empty. |
| 2237 | 2237 | * @return object Number of posts for each status. |
| 2238 | 2238 | */ |
| 2239 | -function wp_count_posts( $type = 'post', $perm = '' ) { |
|
| 2239 | +function wp_count_posts($type = 'post', $perm = '') { |
|
| 2240 | 2240 | global $wpdb; |
| 2241 | 2241 | |
| 2242 | - if ( ! post_type_exists( $type ) ) |
|
| 2242 | + if ( ! post_type_exists($type)) |
|
| 2243 | 2243 | return new stdClass; |
| 2244 | 2244 | |
| 2245 | - $cache_key = _count_posts_cache_key( $type, $perm ); |
|
| 2245 | + $cache_key = _count_posts_cache_key($type, $perm); |
|
| 2246 | 2246 | |
| 2247 | - $counts = wp_cache_get( $cache_key, 'counts' ); |
|
| 2248 | - if ( false !== $counts ) { |
|
| 2247 | + $counts = wp_cache_get($cache_key, 'counts'); |
|
| 2248 | + if (false !== $counts) { |
|
| 2249 | 2249 | /** This filter is documented in wp-includes/post.php */ |
| 2250 | - return apply_filters( 'wp_count_posts', $counts, $type, $perm ); |
|
| 2250 | + return apply_filters('wp_count_posts', $counts, $type, $perm); |
|
| 2251 | 2251 | } |
| 2252 | 2252 | |
| 2253 | 2253 | $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s"; |
| 2254 | - if ( 'readable' == $perm && is_user_logged_in() ) { |
|
| 2254 | + if ('readable' == $perm && is_user_logged_in()) { |
|
| 2255 | 2255 | $post_type_object = get_post_type_object($type); |
| 2256 | - if ( ! current_user_can( $post_type_object->cap->read_private_posts ) ) { |
|
| 2257 | - $query .= $wpdb->prepare( " AND (post_status != 'private' OR ( post_author = %d AND post_status = 'private' ))", |
|
| 2256 | + if ( ! current_user_can($post_type_object->cap->read_private_posts)) { |
|
| 2257 | + $query .= $wpdb->prepare(" AND (post_status != 'private' OR ( post_author = %d AND post_status = 'private' ))", |
|
| 2258 | 2258 | get_current_user_id() |
| 2259 | 2259 | ); |
| 2260 | 2260 | } |
| 2261 | 2261 | } |
| 2262 | 2262 | $query .= ' GROUP BY post_status'; |
| 2263 | 2263 | |
| 2264 | - $results = (array) $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A ); |
|
| 2265 | - $counts = array_fill_keys( get_post_stati(), 0 ); |
|
| 2264 | + $results = (array) $wpdb->get_results($wpdb->prepare($query, $type), ARRAY_A); |
|
| 2265 | + $counts = array_fill_keys(get_post_stati(), 0); |
|
| 2266 | 2266 | |
| 2267 | - foreach ( $results as $row ) { |
|
| 2268 | - $counts[ $row['post_status'] ] = $row['num_posts']; |
|
| 2267 | + foreach ($results as $row) { |
|
| 2268 | + $counts[$row['post_status']] = $row['num_posts']; |
|
| 2269 | 2269 | } |
| 2270 | 2270 | |
| 2271 | 2271 | $counts = (object) $counts; |
| 2272 | - wp_cache_set( $cache_key, $counts, 'counts' ); |
|
| 2272 | + wp_cache_set($cache_key, $counts, 'counts'); |
|
| 2273 | 2273 | |
| 2274 | 2274 | /** |
| 2275 | 2275 | * Modify returned post counts by status for the current post type. |
@@ -2282,7 +2282,7 @@ discard block |
||
| 2282 | 2282 | * @param string $perm The permission to determine if the posts are 'readable' |
| 2283 | 2283 | * by the current user. |
| 2284 | 2284 | */ |
| 2285 | - return apply_filters( 'wp_count_posts', $counts, $type, $perm ); |
|
| 2285 | + return apply_filters('wp_count_posts', $counts, $type, $perm); |
|
| 2286 | 2286 | } |
| 2287 | 2287 | |
| 2288 | 2288 | /** |
@@ -2301,17 +2301,17 @@ discard block |
||
| 2301 | 2301 | * MIME patterns. Default empty. |
| 2302 | 2302 | * @return object An object containing the attachment counts by mime type. |
| 2303 | 2303 | */ |
| 2304 | -function wp_count_attachments( $mime_type = '' ) { |
|
| 2304 | +function wp_count_attachments($mime_type = '') { |
|
| 2305 | 2305 | global $wpdb; |
| 2306 | 2306 | |
| 2307 | - $and = wp_post_mime_type_where( $mime_type ); |
|
| 2308 | - $count = $wpdb->get_results( "SELECT post_mime_type, COUNT( * ) AS num_posts FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' $and GROUP BY post_mime_type", ARRAY_A ); |
|
| 2307 | + $and = wp_post_mime_type_where($mime_type); |
|
| 2308 | + $count = $wpdb->get_results("SELECT post_mime_type, COUNT( * ) AS num_posts FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' $and GROUP BY post_mime_type", ARRAY_A); |
|
| 2309 | 2309 | |
| 2310 | 2310 | $counts = array(); |
| 2311 | - foreach ( (array) $count as $row ) { |
|
| 2312 | - $counts[ $row['post_mime_type'] ] = $row['num_posts']; |
|
| 2311 | + foreach ((array) $count as $row) { |
|
| 2312 | + $counts[$row['post_mime_type']] = $row['num_posts']; |
|
| 2313 | 2313 | } |
| 2314 | - $counts['trash'] = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status = 'trash' $and"); |
|
| 2314 | + $counts['trash'] = $wpdb->get_var("SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status = 'trash' $and"); |
|
| 2315 | 2315 | |
| 2316 | 2316 | /** |
| 2317 | 2317 | * Modify returned attachment counts by mime type. |
@@ -2323,7 +2323,7 @@ discard block |
||
| 2323 | 2323 | * @param string $mime_type The mime type pattern used to filter the attachments |
| 2324 | 2324 | * counted. |
| 2325 | 2325 | */ |
| 2326 | - return apply_filters( 'wp_count_attachments', (object) $counts, $mime_type ); |
|
| 2326 | + return apply_filters('wp_count_attachments', (object) $counts, $mime_type); |
|
| 2327 | 2327 | } |
| 2328 | 2328 | |
| 2329 | 2329 | /** |
@@ -2347,7 +2347,7 @@ discard block |
||
| 2347 | 2347 | * |
| 2348 | 2348 | * @param array $post_mime_types Default list of post mime types. |
| 2349 | 2349 | */ |
| 2350 | - return apply_filters( 'post_mime_types', $post_mime_types ); |
|
| 2350 | + return apply_filters('post_mime_types', $post_mime_types); |
|
| 2351 | 2351 | } |
| 2352 | 2352 | |
| 2353 | 2353 | /** |
@@ -2364,35 +2364,35 @@ discard block |
||
| 2364 | 2364 | * @param string|array $real_mime_types Real post mime type values. |
| 2365 | 2365 | * @return array array(wildcard=>array(real types)). |
| 2366 | 2366 | */ |
| 2367 | -function wp_match_mime_types( $wildcard_mime_types, $real_mime_types ) { |
|
| 2367 | +function wp_match_mime_types($wildcard_mime_types, $real_mime_types) { |
|
| 2368 | 2368 | $matches = array(); |
| 2369 | - if ( is_string( $wildcard_mime_types ) ) { |
|
| 2370 | - $wildcard_mime_types = array_map( 'trim', explode( ',', $wildcard_mime_types ) ); |
|
| 2369 | + if (is_string($wildcard_mime_types)) { |
|
| 2370 | + $wildcard_mime_types = array_map('trim', explode(',', $wildcard_mime_types)); |
|
| 2371 | 2371 | } |
| 2372 | - if ( is_string( $real_mime_types ) ) { |
|
| 2373 | - $real_mime_types = array_map( 'trim', explode( ',', $real_mime_types ) ); |
|
| 2372 | + if (is_string($real_mime_types)) { |
|
| 2373 | + $real_mime_types = array_map('trim', explode(',', $real_mime_types)); |
|
| 2374 | 2374 | } |
| 2375 | 2375 | |
| 2376 | 2376 | $patternses = array(); |
| 2377 | 2377 | $wild = '[-._a-z0-9]*'; |
| 2378 | 2378 | |
| 2379 | - foreach ( (array) $wildcard_mime_types as $type ) { |
|
| 2380 | - $mimes = array_map( 'trim', explode( ',', $type ) ); |
|
| 2381 | - foreach ( $mimes as $mime ) { |
|
| 2382 | - $regex = str_replace( '__wildcard__', $wild, preg_quote( str_replace( '*', '__wildcard__', $mime ) ) ); |
|
| 2379 | + foreach ((array) $wildcard_mime_types as $type) { |
|
| 2380 | + $mimes = array_map('trim', explode(',', $type)); |
|
| 2381 | + foreach ($mimes as $mime) { |
|
| 2382 | + $regex = str_replace('__wildcard__', $wild, preg_quote(str_replace('*', '__wildcard__', $mime))); |
|
| 2383 | 2383 | $patternses[][$type] = "^$regex$"; |
| 2384 | - if ( false === strpos( $mime, '/' ) ) { |
|
| 2384 | + if (false === strpos($mime, '/')) { |
|
| 2385 | 2385 | $patternses[][$type] = "^$regex/"; |
| 2386 | 2386 | $patternses[][$type] = $regex; |
| 2387 | 2387 | } |
| 2388 | 2388 | } |
| 2389 | 2389 | } |
| 2390 | - asort( $patternses ); |
|
| 2390 | + asort($patternses); |
|
| 2391 | 2391 | |
| 2392 | - foreach ( $patternses as $patterns ) { |
|
| 2393 | - foreach ( $patterns as $type => $pattern ) { |
|
| 2394 | - foreach ( (array) $real_mime_types as $real ) { |
|
| 2395 | - if ( preg_match( "#$pattern#", $real ) && ( empty( $matches[$type] ) || false === array_search( $real, $matches[$type] ) ) ) { |
|
| 2392 | + foreach ($patternses as $patterns) { |
|
| 2393 | + foreach ($patterns as $type => $pattern) { |
|
| 2394 | + foreach ((array) $real_mime_types as $real) { |
|
| 2395 | + if (preg_match("#$pattern#", $real) && (empty($matches[$type]) || false === array_search($real, $matches[$type]))) { |
|
| 2396 | 2396 | $matches[$type][] = $real; |
| 2397 | 2397 | } |
| 2398 | 2398 | } |
@@ -2412,43 +2412,43 @@ discard block |
||
| 2412 | 2412 | * Default empty. |
| 2413 | 2413 | * @return string The SQL AND clause for mime searching. |
| 2414 | 2414 | */ |
| 2415 | -function wp_post_mime_type_where( $post_mime_types, $table_alias = '' ) { |
|
| 2415 | +function wp_post_mime_type_where($post_mime_types, $table_alias = '') { |
|
| 2416 | 2416 | $where = ''; |
| 2417 | 2417 | $wildcards = array('', '%', '%/%'); |
| 2418 | - if ( is_string($post_mime_types) ) |
|
| 2418 | + if (is_string($post_mime_types)) |
|
| 2419 | 2419 | $post_mime_types = array_map('trim', explode(',', $post_mime_types)); |
| 2420 | 2420 | |
| 2421 | 2421 | $wheres = array(); |
| 2422 | 2422 | |
| 2423 | - foreach ( (array) $post_mime_types as $mime_type ) { |
|
| 2423 | + foreach ((array) $post_mime_types as $mime_type) { |
|
| 2424 | 2424 | $mime_type = preg_replace('/\s/', '', $mime_type); |
| 2425 | 2425 | $slashpos = strpos($mime_type, '/'); |
| 2426 | - if ( false !== $slashpos ) { |
|
| 2426 | + if (false !== $slashpos) { |
|
| 2427 | 2427 | $mime_group = preg_replace('/[^-*.a-zA-Z0-9]/', '', substr($mime_type, 0, $slashpos)); |
| 2428 | 2428 | $mime_subgroup = preg_replace('/[^-*.+a-zA-Z0-9]/', '', substr($mime_type, $slashpos + 1)); |
| 2429 | - if ( empty($mime_subgroup) ) |
|
| 2429 | + if (empty($mime_subgroup)) |
|
| 2430 | 2430 | $mime_subgroup = '*'; |
| 2431 | 2431 | else |
| 2432 | 2432 | $mime_subgroup = str_replace('/', '', $mime_subgroup); |
| 2433 | 2433 | $mime_pattern = "$mime_group/$mime_subgroup"; |
| 2434 | 2434 | } else { |
| 2435 | 2435 | $mime_pattern = preg_replace('/[^-*.a-zA-Z0-9]/', '', $mime_type); |
| 2436 | - if ( false === strpos($mime_pattern, '*') ) |
|
| 2436 | + if (false === strpos($mime_pattern, '*')) |
|
| 2437 | 2437 | $mime_pattern .= '/*'; |
| 2438 | 2438 | } |
| 2439 | 2439 | |
| 2440 | 2440 | $mime_pattern = preg_replace('/\*+/', '%', $mime_pattern); |
| 2441 | 2441 | |
| 2442 | - if ( in_array( $mime_type, $wildcards ) ) |
|
| 2442 | + if (in_array($mime_type, $wildcards)) |
|
| 2443 | 2443 | return ''; |
| 2444 | 2444 | |
| 2445 | - if ( false !== strpos($mime_pattern, '%') ) |
|
| 2445 | + if (false !== strpos($mime_pattern, '%')) |
|
| 2446 | 2446 | $wheres[] = empty($table_alias) ? "post_mime_type LIKE '$mime_pattern'" : "$table_alias.post_mime_type LIKE '$mime_pattern'"; |
| 2447 | 2447 | else |
| 2448 | 2448 | $wheres[] = empty($table_alias) ? "post_mime_type = '$mime_pattern'" : "$table_alias.post_mime_type = '$mime_pattern'"; |
| 2449 | 2449 | } |
| 2450 | - if ( !empty($wheres) ) |
|
| 2451 | - $where = ' AND (' . join(' OR ', $wheres) . ') '; |
|
| 2450 | + if ( ! empty($wheres)) |
|
| 2451 | + $where = ' AND ('.join(' OR ', $wheres).') '; |
|
| 2452 | 2452 | return $where; |
| 2453 | 2453 | } |
| 2454 | 2454 | |
@@ -2473,17 +2473,17 @@ discard block |
||
| 2473 | 2473 | * Default false. |
| 2474 | 2474 | * @return array|false|WP_Post False on failure. |
| 2475 | 2475 | */ |
| 2476 | -function wp_delete_post( $postid = 0, $force_delete = false ) { |
|
| 2476 | +function wp_delete_post($postid = 0, $force_delete = false) { |
|
| 2477 | 2477 | global $wpdb; |
| 2478 | 2478 | |
| 2479 | - if ( !$post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d", $postid)) ) |
|
| 2479 | + if ( ! $post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d", $postid))) |
|
| 2480 | 2480 | return $post; |
| 2481 | 2481 | |
| 2482 | - if ( !$force_delete && ( $post->post_type == 'post' || $post->post_type == 'page') && get_post_status( $postid ) != 'trash' && EMPTY_TRASH_DAYS ) |
|
| 2483 | - return wp_trash_post( $postid ); |
|
| 2482 | + if ( ! $force_delete && ($post->post_type == 'post' || $post->post_type == 'page') && get_post_status($postid) != 'trash' && EMPTY_TRASH_DAYS) |
|
| 2483 | + return wp_trash_post($postid); |
|
| 2484 | 2484 | |
| 2485 | - if ( $post->post_type == 'attachment' ) |
|
| 2486 | - return wp_delete_attachment( $postid, $force_delete ); |
|
| 2485 | + if ($post->post_type == 'attachment') |
|
| 2486 | + return wp_delete_attachment($postid, $force_delete); |
|
| 2487 | 2487 | |
| 2488 | 2488 | /** |
| 2489 | 2489 | * Filter whether a post deletion should take place. |
@@ -2494,8 +2494,8 @@ discard block |
||
| 2494 | 2494 | * @param WP_Post $post Post object. |
| 2495 | 2495 | * @param bool $force_delete Whether to bypass the trash. |
| 2496 | 2496 | */ |
| 2497 | - $check = apply_filters( 'pre_delete_post', null, $post, $force_delete ); |
|
| 2498 | - if ( null !== $check ) { |
|
| 2497 | + $check = apply_filters('pre_delete_post', null, $post, $force_delete); |
|
| 2498 | + if (null !== $check) { |
|
| 2499 | 2499 | return $check; |
| 2500 | 2500 | } |
| 2501 | 2501 | |
@@ -2508,46 +2508,46 @@ discard block |
||
| 2508 | 2508 | * |
| 2509 | 2509 | * @param int $postid Post ID. |
| 2510 | 2510 | */ |
| 2511 | - do_action( 'before_delete_post', $postid ); |
|
| 2511 | + do_action('before_delete_post', $postid); |
|
| 2512 | 2512 | |
| 2513 | - delete_post_meta($postid,'_wp_trash_meta_status'); |
|
| 2514 | - delete_post_meta($postid,'_wp_trash_meta_time'); |
|
| 2513 | + delete_post_meta($postid, '_wp_trash_meta_status'); |
|
| 2514 | + delete_post_meta($postid, '_wp_trash_meta_time'); |
|
| 2515 | 2515 | |
| 2516 | 2516 | wp_delete_object_term_relationships($postid, get_object_taxonomies($post->post_type)); |
| 2517 | 2517 | |
| 2518 | - $parent_data = array( 'post_parent' => $post->post_parent ); |
|
| 2519 | - $parent_where = array( 'post_parent' => $postid ); |
|
| 2518 | + $parent_data = array('post_parent' => $post->post_parent); |
|
| 2519 | + $parent_where = array('post_parent' => $postid); |
|
| 2520 | 2520 | |
| 2521 | - if ( is_post_type_hierarchical( $post->post_type ) ) { |
|
| 2521 | + if (is_post_type_hierarchical($post->post_type)) { |
|
| 2522 | 2522 | // Point children of this page to its parent, also clean the cache of affected children. |
| 2523 | - $children_query = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_parent = %d AND post_type = %s", $postid, $post->post_type ); |
|
| 2524 | - $children = $wpdb->get_results( $children_query ); |
|
| 2525 | - if ( $children ) { |
|
| 2526 | - $wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => $post->post_type ) ); |
|
| 2523 | + $children_query = $wpdb->prepare("SELECT * FROM $wpdb->posts WHERE post_parent = %d AND post_type = %s", $postid, $post->post_type); |
|
| 2524 | + $children = $wpdb->get_results($children_query); |
|
| 2525 | + if ($children) { |
|
| 2526 | + $wpdb->update($wpdb->posts, $parent_data, $parent_where + array('post_type' => $post->post_type)); |
|
| 2527 | 2527 | } |
| 2528 | 2528 | } |
| 2529 | 2529 | |
| 2530 | 2530 | // Do raw query. wp_get_post_revisions() is filtered. |
| 2531 | - $revision_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'revision'", $postid ) ); |
|
| 2531 | + $revision_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'revision'", $postid)); |
|
| 2532 | 2532 | // Use wp_delete_post (via wp_delete_post_revision) again. Ensures any meta/misplaced data gets cleaned up. |
| 2533 | - foreach ( $revision_ids as $revision_id ) |
|
| 2534 | - wp_delete_post_revision( $revision_id ); |
|
| 2533 | + foreach ($revision_ids as $revision_id) |
|
| 2534 | + wp_delete_post_revision($revision_id); |
|
| 2535 | 2535 | |
| 2536 | 2536 | // Point all attachments to this post up one level. |
| 2537 | - $wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => 'attachment' ) ); |
|
| 2537 | + $wpdb->update($wpdb->posts, $parent_data, $parent_where + array('post_type' => 'attachment')); |
|
| 2538 | 2538 | |
| 2539 | - wp_defer_comment_counting( true ); |
|
| 2539 | + wp_defer_comment_counting(true); |
|
| 2540 | 2540 | |
| 2541 | - $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $postid )); |
|
| 2542 | - foreach ( $comment_ids as $comment_id ) { |
|
| 2543 | - wp_delete_comment( $comment_id, true ); |
|
| 2541 | + $comment_ids = $wpdb->get_col($wpdb->prepare("SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $postid)); |
|
| 2542 | + foreach ($comment_ids as $comment_id) { |
|
| 2543 | + wp_delete_comment($comment_id, true); |
|
| 2544 | 2544 | } |
| 2545 | 2545 | |
| 2546 | - wp_defer_comment_counting( false ); |
|
| 2546 | + wp_defer_comment_counting(false); |
|
| 2547 | 2547 | |
| 2548 | - $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $postid )); |
|
| 2549 | - foreach ( $post_meta_ids as $mid ) |
|
| 2550 | - delete_metadata_by_mid( 'post', $mid ); |
|
| 2548 | + $post_meta_ids = $wpdb->get_col($wpdb->prepare("SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $postid)); |
|
| 2549 | + foreach ($post_meta_ids as $mid) |
|
| 2550 | + delete_metadata_by_mid('post', $mid); |
|
| 2551 | 2551 | |
| 2552 | 2552 | /** |
| 2553 | 2553 | * Fires immediately before a post is deleted from the database. |
@@ -2556,9 +2556,9 @@ discard block |
||
| 2556 | 2556 | * |
| 2557 | 2557 | * @param int $postid Post ID. |
| 2558 | 2558 | */ |
| 2559 | - do_action( 'delete_post', $postid ); |
|
| 2560 | - $result = $wpdb->delete( $wpdb->posts, array( 'ID' => $postid ) ); |
|
| 2561 | - if ( ! $result ) { |
|
| 2559 | + do_action('delete_post', $postid); |
|
| 2560 | + $result = $wpdb->delete($wpdb->posts, array('ID' => $postid)); |
|
| 2561 | + if ( ! $result) { |
|
| 2562 | 2562 | return false; |
| 2563 | 2563 | } |
| 2564 | 2564 | |
@@ -2569,16 +2569,16 @@ discard block |
||
| 2569 | 2569 | * |
| 2570 | 2570 | * @param int $postid Post ID. |
| 2571 | 2571 | */ |
| 2572 | - do_action( 'deleted_post', $postid ); |
|
| 2572 | + do_action('deleted_post', $postid); |
|
| 2573 | 2573 | |
| 2574 | - clean_post_cache( $post ); |
|
| 2574 | + clean_post_cache($post); |
|
| 2575 | 2575 | |
| 2576 | - if ( is_post_type_hierarchical( $post->post_type ) && $children ) { |
|
| 2577 | - foreach ( $children as $child ) |
|
| 2578 | - clean_post_cache( $child ); |
|
| 2576 | + if (is_post_type_hierarchical($post->post_type) && $children) { |
|
| 2577 | + foreach ($children as $child) |
|
| 2578 | + clean_post_cache($child); |
|
| 2579 | 2579 | } |
| 2580 | 2580 | |
| 2581 | - wp_clear_scheduled_hook('publish_future_post', array( $postid ) ); |
|
| 2581 | + wp_clear_scheduled_hook('publish_future_post', array($postid)); |
|
| 2582 | 2582 | |
| 2583 | 2583 | /** |
| 2584 | 2584 | * Fires after a post is deleted, at the conclusion of wp_delete_post(). |
@@ -2589,7 +2589,7 @@ discard block |
||
| 2589 | 2589 | * |
| 2590 | 2590 | * @param int $postid Post ID. |
| 2591 | 2591 | */ |
| 2592 | - do_action( 'after_delete_post', $postid ); |
|
| 2592 | + do_action('after_delete_post', $postid); |
|
| 2593 | 2593 | |
| 2594 | 2594 | return $post; |
| 2595 | 2595 | } |
@@ -2605,22 +2605,22 @@ discard block |
||
| 2605 | 2605 | * |
| 2606 | 2606 | * @param int $post_id Post ID. |
| 2607 | 2607 | */ |
| 2608 | -function _reset_front_page_settings_for_post( $post_id ) { |
|
| 2609 | - $post = get_post( $post_id ); |
|
| 2610 | - if ( 'page' == $post->post_type ) { |
|
| 2608 | +function _reset_front_page_settings_for_post($post_id) { |
|
| 2609 | + $post = get_post($post_id); |
|
| 2610 | + if ('page' == $post->post_type) { |
|
| 2611 | 2611 | /* |
| 2612 | 2612 | * If the page is defined in option page_on_front or post_for_posts, |
| 2613 | 2613 | * adjust the corresponding options. |
| 2614 | 2614 | */ |
| 2615 | - if ( get_option( 'page_on_front' ) == $post->ID ) { |
|
| 2616 | - update_option( 'show_on_front', 'posts' ); |
|
| 2617 | - update_option( 'page_on_front', 0 ); |
|
| 2615 | + if (get_option('page_on_front') == $post->ID) { |
|
| 2616 | + update_option('show_on_front', 'posts'); |
|
| 2617 | + update_option('page_on_front', 0); |
|
| 2618 | 2618 | } |
| 2619 | - if ( get_option( 'page_for_posts' ) == $post->ID ) { |
|
| 2620 | - delete_option( 'page_for_posts', 0 ); |
|
| 2619 | + if (get_option('page_for_posts') == $post->ID) { |
|
| 2620 | + delete_option('page_for_posts', 0); |
|
| 2621 | 2621 | } |
| 2622 | 2622 | } |
| 2623 | - unstick_post( $post->ID ); |
|
| 2623 | + unstick_post($post->ID); |
|
| 2624 | 2624 | } |
| 2625 | 2625 | |
| 2626 | 2626 | /** |
@@ -2636,14 +2636,14 @@ discard block |
||
| 2636 | 2636 | * if EMPTY_TRASH_DAYS equals true. |
| 2637 | 2637 | * @return false|array|WP_Post|null Post data array, otherwise false. |
| 2638 | 2638 | */ |
| 2639 | -function wp_trash_post( $post_id = 0 ) { |
|
| 2640 | - if ( !EMPTY_TRASH_DAYS ) |
|
| 2639 | +function wp_trash_post($post_id = 0) { |
|
| 2640 | + if ( ! EMPTY_TRASH_DAYS) |
|
| 2641 | 2641 | return wp_delete_post($post_id, true); |
| 2642 | 2642 | |
| 2643 | - if ( !$post = get_post($post_id, ARRAY_A) ) |
|
| 2643 | + if ( ! $post = get_post($post_id, ARRAY_A)) |
|
| 2644 | 2644 | return $post; |
| 2645 | 2645 | |
| 2646 | - if ( $post['post_status'] == 'trash' ) |
|
| 2646 | + if ($post['post_status'] == 'trash') |
|
| 2647 | 2647 | return false; |
| 2648 | 2648 | |
| 2649 | 2649 | /** |
@@ -2653,13 +2653,13 @@ discard block |
||
| 2653 | 2653 | * |
| 2654 | 2654 | * @param int $post_id Post ID. |
| 2655 | 2655 | */ |
| 2656 | - do_action( 'wp_trash_post', $post_id ); |
|
| 2656 | + do_action('wp_trash_post', $post_id); |
|
| 2657 | 2657 | |
| 2658 | - add_post_meta($post_id,'_wp_trash_meta_status', $post['post_status']); |
|
| 2659 | - add_post_meta($post_id,'_wp_trash_meta_time', time()); |
|
| 2658 | + add_post_meta($post_id, '_wp_trash_meta_status', $post['post_status']); |
|
| 2659 | + add_post_meta($post_id, '_wp_trash_meta_time', time()); |
|
| 2660 | 2660 | |
| 2661 | 2661 | $post['post_status'] = 'trash'; |
| 2662 | - wp_insert_post( wp_slash( $post ) ); |
|
| 2662 | + wp_insert_post(wp_slash($post)); |
|
| 2663 | 2663 | |
| 2664 | 2664 | wp_trash_post_comments($post_id); |
| 2665 | 2665 | |
@@ -2670,7 +2670,7 @@ discard block |
||
| 2670 | 2670 | * |
| 2671 | 2671 | * @param int $post_id Post ID. |
| 2672 | 2672 | */ |
| 2673 | - do_action( 'trashed_post', $post_id ); |
|
| 2673 | + do_action('trashed_post', $post_id); |
|
| 2674 | 2674 | |
| 2675 | 2675 | return $post; |
| 2676 | 2676 | } |
@@ -2683,11 +2683,11 @@ discard block |
||
| 2683 | 2683 | * @param int $post_id Optional. Post ID. Default is ID of the global $post. |
| 2684 | 2684 | * @return WP_Post|false WP_Post object. False on failure. |
| 2685 | 2685 | */ |
| 2686 | -function wp_untrash_post( $post_id = 0 ) { |
|
| 2687 | - if ( !$post = get_post($post_id, ARRAY_A) ) |
|
| 2686 | +function wp_untrash_post($post_id = 0) { |
|
| 2687 | + if ( ! $post = get_post($post_id, ARRAY_A)) |
|
| 2688 | 2688 | return $post; |
| 2689 | 2689 | |
| 2690 | - if ( $post['post_status'] != 'trash' ) |
|
| 2690 | + if ($post['post_status'] != 'trash') |
|
| 2691 | 2691 | return false; |
| 2692 | 2692 | |
| 2693 | 2693 | /** |
@@ -2697,7 +2697,7 @@ discard block |
||
| 2697 | 2697 | * |
| 2698 | 2698 | * @param int $post_id Post ID. |
| 2699 | 2699 | */ |
| 2700 | - do_action( 'untrash_post', $post_id ); |
|
| 2700 | + do_action('untrash_post', $post_id); |
|
| 2701 | 2701 | |
| 2702 | 2702 | $post_status = get_post_meta($post_id, '_wp_trash_meta_status', true); |
| 2703 | 2703 | |
@@ -2706,7 +2706,7 @@ discard block |
||
| 2706 | 2706 | delete_post_meta($post_id, '_wp_trash_meta_status'); |
| 2707 | 2707 | delete_post_meta($post_id, '_wp_trash_meta_time'); |
| 2708 | 2708 | |
| 2709 | - wp_insert_post( wp_slash( $post ) ); |
|
| 2709 | + wp_insert_post(wp_slash($post)); |
|
| 2710 | 2710 | |
| 2711 | 2711 | wp_untrash_post_comments($post_id); |
| 2712 | 2712 | |
@@ -2717,7 +2717,7 @@ discard block |
||
| 2717 | 2717 | * |
| 2718 | 2718 | * @param int $post_id Post ID. |
| 2719 | 2719 | */ |
| 2720 | - do_action( 'untrashed_post', $post_id ); |
|
| 2720 | + do_action('untrashed_post', $post_id); |
|
| 2721 | 2721 | |
| 2722 | 2722 | return $post; |
| 2723 | 2723 | } |
@@ -2732,11 +2732,11 @@ discard block |
||
| 2732 | 2732 | * @param int|WP_Post|null $post Optional. Post ID or post object. Defaults to global $post. |
| 2733 | 2733 | * @return mixed|void False on failure. |
| 2734 | 2734 | */ |
| 2735 | -function wp_trash_post_comments( $post = null ) { |
|
| 2735 | +function wp_trash_post_comments($post = null) { |
|
| 2736 | 2736 | global $wpdb; |
| 2737 | 2737 | |
| 2738 | 2738 | $post = get_post($post); |
| 2739 | - if ( empty($post) ) |
|
| 2739 | + if (empty($post)) |
|
| 2740 | 2740 | return; |
| 2741 | 2741 | |
| 2742 | 2742 | $post_id = $post->ID; |
@@ -2748,22 +2748,22 @@ discard block |
||
| 2748 | 2748 | * |
| 2749 | 2749 | * @param int $post_id Post ID. |
| 2750 | 2750 | */ |
| 2751 | - do_action( 'trash_post_comments', $post_id ); |
|
| 2751 | + do_action('trash_post_comments', $post_id); |
|
| 2752 | 2752 | |
| 2753 | - $comments = $wpdb->get_results( $wpdb->prepare("SELECT comment_ID, comment_approved FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id) ); |
|
| 2754 | - if ( empty($comments) ) |
|
| 2753 | + $comments = $wpdb->get_results($wpdb->prepare("SELECT comment_ID, comment_approved FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id)); |
|
| 2754 | + if (empty($comments)) |
|
| 2755 | 2755 | return; |
| 2756 | 2756 | |
| 2757 | 2757 | // Cache current status for each comment. |
| 2758 | 2758 | $statuses = array(); |
| 2759 | - foreach ( $comments as $comment ) |
|
| 2759 | + foreach ($comments as $comment) |
|
| 2760 | 2760 | $statuses[$comment->comment_ID] = $comment->comment_approved; |
| 2761 | 2761 | add_post_meta($post_id, '_wp_trash_meta_comments_status', $statuses); |
| 2762 | 2762 | |
| 2763 | 2763 | // Set status for all comments to post-trashed. |
| 2764 | 2764 | $result = $wpdb->update($wpdb->comments, array('comment_approved' => 'post-trashed'), array('comment_post_ID' => $post_id)); |
| 2765 | 2765 | |
| 2766 | - clean_comment_cache( array_keys($statuses) ); |
|
| 2766 | + clean_comment_cache(array_keys($statuses)); |
|
| 2767 | 2767 | |
| 2768 | 2768 | /** |
| 2769 | 2769 | * Fires after comments are sent to the trash. |
@@ -2773,7 +2773,7 @@ discard block |
||
| 2773 | 2773 | * @param int $post_id Post ID. |
| 2774 | 2774 | * @param array $statuses Array of comment statuses. |
| 2775 | 2775 | */ |
| 2776 | - do_action( 'trashed_post_comments', $post_id, $statuses ); |
|
| 2776 | + do_action('trashed_post_comments', $post_id, $statuses); |
|
| 2777 | 2777 | |
| 2778 | 2778 | return $result; |
| 2779 | 2779 | } |
@@ -2788,18 +2788,18 @@ discard block |
||
| 2788 | 2788 | * @param int|WP_Post|null $post Optional. Post ID or post object. Defaults to global $post. |
| 2789 | 2789 | * @return true|void |
| 2790 | 2790 | */ |
| 2791 | -function wp_untrash_post_comments( $post = null ) { |
|
| 2791 | +function wp_untrash_post_comments($post = null) { |
|
| 2792 | 2792 | global $wpdb; |
| 2793 | 2793 | |
| 2794 | 2794 | $post = get_post($post); |
| 2795 | - if ( empty($post) ) |
|
| 2795 | + if (empty($post)) |
|
| 2796 | 2796 | return; |
| 2797 | 2797 | |
| 2798 | 2798 | $post_id = $post->ID; |
| 2799 | 2799 | |
| 2800 | 2800 | $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true); |
| 2801 | 2801 | |
| 2802 | - if ( empty($statuses) ) |
|
| 2802 | + if (empty($statuses)) |
|
| 2803 | 2803 | return true; |
| 2804 | 2804 | |
| 2805 | 2805 | /** |
@@ -2809,23 +2809,23 @@ discard block |
||
| 2809 | 2809 | * |
| 2810 | 2810 | * @param int $post_id Post ID. |
| 2811 | 2811 | */ |
| 2812 | - do_action( 'untrash_post_comments', $post_id ); |
|
| 2812 | + do_action('untrash_post_comments', $post_id); |
|
| 2813 | 2813 | |
| 2814 | 2814 | // Restore each comment to its original status. |
| 2815 | 2815 | $group_by_status = array(); |
| 2816 | - foreach ( $statuses as $comment_id => $comment_status ) |
|
| 2816 | + foreach ($statuses as $comment_id => $comment_status) |
|
| 2817 | 2817 | $group_by_status[$comment_status][] = $comment_id; |
| 2818 | 2818 | |
| 2819 | - foreach ( $group_by_status as $status => $comments ) { |
|
| 2819 | + foreach ($group_by_status as $status => $comments) { |
|
| 2820 | 2820 | // Sanity check. This shouldn't happen. |
| 2821 | - if ( 'post-trashed' == $status ) { |
|
| 2821 | + if ('post-trashed' == $status) { |
|
| 2822 | 2822 | $status = '0'; |
| 2823 | 2823 | } |
| 2824 | - $comments_in = implode( ', ', array_map( 'intval', $comments ) ); |
|
| 2825 | - $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->comments SET comment_approved = %s WHERE comment_ID IN ($comments_in)", $status ) ); |
|
| 2824 | + $comments_in = implode(', ', array_map('intval', $comments)); |
|
| 2825 | + $wpdb->query($wpdb->prepare("UPDATE $wpdb->comments SET comment_approved = %s WHERE comment_ID IN ($comments_in)", $status)); |
|
| 2826 | 2826 | } |
| 2827 | 2827 | |
| 2828 | - clean_comment_cache( array_keys($statuses) ); |
|
| 2828 | + clean_comment_cache(array_keys($statuses)); |
|
| 2829 | 2829 | |
| 2830 | 2830 | delete_post_meta($post_id, '_wp_trash_meta_comments_status'); |
| 2831 | 2831 | |
@@ -2836,7 +2836,7 @@ discard block |
||
| 2836 | 2836 | * |
| 2837 | 2837 | * @param int $post_id Post ID. |
| 2838 | 2838 | */ |
| 2839 | - do_action( 'untrashed_post_comments', $post_id ); |
|
| 2839 | + do_action('untrashed_post_comments', $post_id); |
|
| 2840 | 2840 | } |
| 2841 | 2841 | |
| 2842 | 2842 | /** |
@@ -2854,11 +2854,11 @@ discard block |
||
| 2854 | 2854 | * @param array $args Optional. Category arguments. Default empty. |
| 2855 | 2855 | * @return array List of categories. |
| 2856 | 2856 | */ |
| 2857 | -function wp_get_post_categories( $post_id = 0, $args = array() ) { |
|
| 2857 | +function wp_get_post_categories($post_id = 0, $args = array()) { |
|
| 2858 | 2858 | $post_id = (int) $post_id; |
| 2859 | 2859 | |
| 2860 | 2860 | $defaults = array('fields' => 'ids'); |
| 2861 | - $args = wp_parse_args( $args, $defaults ); |
|
| 2861 | + $args = wp_parse_args($args, $defaults); |
|
| 2862 | 2862 | |
| 2863 | 2863 | $cats = wp_get_object_terms($post_id, 'category', $args); |
| 2864 | 2864 | return $cats; |
@@ -2878,8 +2878,8 @@ discard block |
||
| 2878 | 2878 | * @param array $args Optional. Overwrite the defaults |
| 2879 | 2879 | * @return array List of post tags. |
| 2880 | 2880 | */ |
| 2881 | -function wp_get_post_tags( $post_id = 0, $args = array() ) { |
|
| 2882 | - return wp_get_post_terms( $post_id, 'post_tag', $args); |
|
| 2881 | +function wp_get_post_tags($post_id = 0, $args = array()) { |
|
| 2882 | + return wp_get_post_terms($post_id, 'post_tag', $args); |
|
| 2883 | 2883 | } |
| 2884 | 2884 | |
| 2885 | 2885 | /** |
@@ -2898,11 +2898,11 @@ discard block |
||
| 2898 | 2898 | * @return array|WP_Error List of post terms or empty array if no terms were found. WP_Error object |
| 2899 | 2899 | * if `$taxonomy` doesn't exist. |
| 2900 | 2900 | */ |
| 2901 | -function wp_get_post_terms( $post_id = 0, $taxonomy = 'post_tag', $args = array() ) { |
|
| 2901 | +function wp_get_post_terms($post_id = 0, $taxonomy = 'post_tag', $args = array()) { |
|
| 2902 | 2902 | $post_id = (int) $post_id; |
| 2903 | 2903 | |
| 2904 | 2904 | $defaults = array('fields' => 'all'); |
| 2905 | - $args = wp_parse_args( $args, $defaults ); |
|
| 2905 | + $args = wp_parse_args($args, $defaults); |
|
| 2906 | 2906 | |
| 2907 | 2907 | $tags = wp_get_object_terms($post_id, $taxonomy, $args); |
| 2908 | 2908 | |
@@ -2920,11 +2920,11 @@ discard block |
||
| 2920 | 2920 | * @param string $output Optional. Type of output. Accepts ARRAY_A or ''. Default ARRAY_A. |
| 2921 | 2921 | * @return array|false Associative array if $output equals ARRAY_A, array or false if no results. |
| 2922 | 2922 | */ |
| 2923 | -function wp_get_recent_posts( $args = array(), $output = ARRAY_A ) { |
|
| 2923 | +function wp_get_recent_posts($args = array(), $output = ARRAY_A) { |
|
| 2924 | 2924 | |
| 2925 | - if ( is_numeric( $args ) ) { |
|
| 2926 | - _deprecated_argument( __FUNCTION__, '3.1', __( 'Passing an integer number of posts is deprecated. Pass an array of arguments instead.' ) ); |
|
| 2927 | - $args = array( 'numberposts' => absint( $args ) ); |
|
| 2925 | + if (is_numeric($args)) { |
|
| 2926 | + _deprecated_argument(__FUNCTION__, '3.1', __('Passing an integer number of posts is deprecated. Pass an array of arguments instead.')); |
|
| 2927 | + $args = array('numberposts' => absint($args)); |
|
| 2928 | 2928 | } |
| 2929 | 2929 | |
| 2930 | 2930 | // Set default arguments. |
@@ -2937,14 +2937,14 @@ discard block |
||
| 2937 | 2937 | 'suppress_filters' => true |
| 2938 | 2938 | ); |
| 2939 | 2939 | |
| 2940 | - $r = wp_parse_args( $args, $defaults ); |
|
| 2940 | + $r = wp_parse_args($args, $defaults); |
|
| 2941 | 2941 | |
| 2942 | - $results = get_posts( $r ); |
|
| 2942 | + $results = get_posts($r); |
|
| 2943 | 2943 | |
| 2944 | 2944 | // Backward compatibility. Prior to 3.1 expected posts to be returned in array. |
| 2945 | - if ( ARRAY_A == $output ){ |
|
| 2946 | - foreach ( $results as $key => $result ) { |
|
| 2947 | - $results[$key] = get_object_vars( $result ); |
|
| 2945 | + if (ARRAY_A == $output) { |
|
| 2946 | + foreach ($results as $key => $result) { |
|
| 2947 | + $results[$key] = get_object_vars($result); |
|
| 2948 | 2948 | } |
| 2949 | 2949 | return $results ? $results : array(); |
| 2950 | 2950 | } |
@@ -3010,7 +3010,7 @@ discard block |
||
| 3010 | 3010 | * @param bool $wp_error Optional. Whether to allow return of WP_Error on failure. Default false. |
| 3011 | 3011 | * @return int|WP_Error The post ID on success. The value 0 or WP_Error on failure. |
| 3012 | 3012 | */ |
| 3013 | -function wp_insert_post( $postarr, $wp_error = false ) { |
|
| 3013 | +function wp_insert_post($postarr, $wp_error = false) { |
|
| 3014 | 3014 | global $wpdb; |
| 3015 | 3015 | |
| 3016 | 3016 | $user_id = get_current_user_id(); |
@@ -3037,7 +3037,7 @@ discard block |
||
| 3037 | 3037 | |
| 3038 | 3038 | $postarr = wp_parse_args($postarr, $defaults); |
| 3039 | 3039 | |
| 3040 | - unset( $postarr[ 'filter' ] ); |
|
| 3040 | + unset($postarr['filter']); |
|
| 3041 | 3041 | |
| 3042 | 3042 | $postarr = sanitize_post($postarr, 'db'); |
| 3043 | 3043 | |
@@ -3046,42 +3046,42 @@ discard block |
||
| 3046 | 3046 | $update = false; |
| 3047 | 3047 | $guid = $postarr['guid']; |
| 3048 | 3048 | |
| 3049 | - if ( ! empty( $postarr['ID'] ) ) { |
|
| 3049 | + if ( ! empty($postarr['ID'])) { |
|
| 3050 | 3050 | $update = true; |
| 3051 | 3051 | |
| 3052 | 3052 | // Get the post ID and GUID. |
| 3053 | 3053 | $post_ID = $postarr['ID']; |
| 3054 | - $post_before = get_post( $post_ID ); |
|
| 3055 | - if ( is_null( $post_before ) ) { |
|
| 3056 | - if ( $wp_error ) { |
|
| 3057 | - return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) ); |
|
| 3054 | + $post_before = get_post($post_ID); |
|
| 3055 | + if (is_null($post_before)) { |
|
| 3056 | + if ($wp_error) { |
|
| 3057 | + return new WP_Error('invalid_post', __('Invalid post ID.')); |
|
| 3058 | 3058 | } |
| 3059 | 3059 | return 0; |
| 3060 | 3060 | } |
| 3061 | 3061 | |
| 3062 | - $guid = get_post_field( 'guid', $post_ID ); |
|
| 3063 | - $previous_status = get_post_field('post_status', $post_ID ); |
|
| 3062 | + $guid = get_post_field('guid', $post_ID); |
|
| 3063 | + $previous_status = get_post_field('post_status', $post_ID); |
|
| 3064 | 3064 | } else { |
| 3065 | 3065 | $previous_status = 'new'; |
| 3066 | 3066 | } |
| 3067 | 3067 | |
| 3068 | - $post_type = empty( $postarr['post_type'] ) ? 'post' : $postarr['post_type']; |
|
| 3068 | + $post_type = empty($postarr['post_type']) ? 'post' : $postarr['post_type']; |
|
| 3069 | 3069 | |
| 3070 | 3070 | $post_title = $postarr['post_title']; |
| 3071 | 3071 | $post_content = $postarr['post_content']; |
| 3072 | 3072 | $post_excerpt = $postarr['post_excerpt']; |
| 3073 | - if ( isset( $postarr['post_name'] ) ) { |
|
| 3073 | + if (isset($postarr['post_name'])) { |
|
| 3074 | 3074 | $post_name = $postarr['post_name']; |
| 3075 | - } elseif ( $update ) { |
|
| 3075 | + } elseif ($update) { |
|
| 3076 | 3076 | // For an update, don't modify the post_name if it wasn't supplied as an argument. |
| 3077 | 3077 | $post_name = $post_before->post_name; |
| 3078 | 3078 | } |
| 3079 | 3079 | |
| 3080 | 3080 | $maybe_empty = 'attachment' !== $post_type |
| 3081 | 3081 | && ! $post_content && ! $post_title && ! $post_excerpt |
| 3082 | - && post_type_supports( $post_type, 'editor' ) |
|
| 3083 | - && post_type_supports( $post_type, 'title' ) |
|
| 3084 | - && post_type_supports( $post_type, 'excerpt' ); |
|
| 3082 | + && post_type_supports($post_type, 'editor') |
|
| 3083 | + && post_type_supports($post_type, 'title') |
|
| 3084 | + && post_type_supports($post_type, 'excerpt'); |
|
| 3085 | 3085 | |
| 3086 | 3086 | /** |
| 3087 | 3087 | * Filter whether the post should be considered "empty". |
@@ -3099,36 +3099,36 @@ discard block |
||
| 3099 | 3099 | * @param bool $maybe_empty Whether the post should be considered "empty". |
| 3100 | 3100 | * @param array $postarr Array of post data. |
| 3101 | 3101 | */ |
| 3102 | - if ( apply_filters( 'wp_insert_post_empty_content', $maybe_empty, $postarr ) ) { |
|
| 3103 | - if ( $wp_error ) { |
|
| 3104 | - return new WP_Error( 'empty_content', __( 'Content, title, and excerpt are empty.' ) ); |
|
| 3102 | + if (apply_filters('wp_insert_post_empty_content', $maybe_empty, $postarr)) { |
|
| 3103 | + if ($wp_error) { |
|
| 3104 | + return new WP_Error('empty_content', __('Content, title, and excerpt are empty.')); |
|
| 3105 | 3105 | } else { |
| 3106 | 3106 | return 0; |
| 3107 | 3107 | } |
| 3108 | 3108 | } |
| 3109 | 3109 | |
| 3110 | - $post_status = empty( $postarr['post_status'] ) ? 'draft' : $postarr['post_status']; |
|
| 3111 | - if ( 'attachment' === $post_type && ! in_array( $post_status, array( 'inherit', 'private', 'trash' ) ) ) { |
|
| 3110 | + $post_status = empty($postarr['post_status']) ? 'draft' : $postarr['post_status']; |
|
| 3111 | + if ('attachment' === $post_type && ! in_array($post_status, array('inherit', 'private', 'trash'))) { |
|
| 3112 | 3112 | $post_status = 'inherit'; |
| 3113 | 3113 | } |
| 3114 | 3114 | |
| 3115 | - if ( ! empty( $postarr['post_category'] ) ) { |
|
| 3115 | + if ( ! empty($postarr['post_category'])) { |
|
| 3116 | 3116 | // Filter out empty terms. |
| 3117 | - $post_category = array_filter( $postarr['post_category'] ); |
|
| 3117 | + $post_category = array_filter($postarr['post_category']); |
|
| 3118 | 3118 | } |
| 3119 | 3119 | |
| 3120 | 3120 | // Make sure we set a valid category. |
| 3121 | - if ( empty( $post_category ) || 0 == count( $post_category ) || ! is_array( $post_category ) ) { |
|
| 3121 | + if (empty($post_category) || 0 == count($post_category) || ! is_array($post_category)) { |
|
| 3122 | 3122 | // 'post' requires at least one category. |
| 3123 | - if ( 'post' == $post_type && 'auto-draft' != $post_status ) { |
|
| 3124 | - $post_category = array( get_option('default_category') ); |
|
| 3123 | + if ('post' == $post_type && 'auto-draft' != $post_status) { |
|
| 3124 | + $post_category = array(get_option('default_category')); |
|
| 3125 | 3125 | } else { |
| 3126 | 3126 | $post_category = array(); |
| 3127 | 3127 | } |
| 3128 | 3128 | } |
| 3129 | 3129 | |
| 3130 | 3130 | // Don't allow contributors to set the post slug for pending review posts. |
| 3131 | - if ( 'pending' == $post_status && !current_user_can( 'publish_posts' ) ) { |
|
| 3131 | + if ('pending' == $post_status && ! current_user_can('publish_posts')) { |
|
| 3132 | 3132 | $post_name = ''; |
| 3133 | 3133 | } |
| 3134 | 3134 | |
@@ -3136,16 +3136,16 @@ discard block |
||
| 3136 | 3136 | * Create a valid post name. Drafts and pending posts are allowed to have |
| 3137 | 3137 | * an empty post name. |
| 3138 | 3138 | */ |
| 3139 | - if ( empty($post_name) ) { |
|
| 3140 | - if ( !in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) { |
|
| 3139 | + if (empty($post_name)) { |
|
| 3140 | + if ( ! in_array($post_status, array('draft', 'pending', 'auto-draft'))) { |
|
| 3141 | 3141 | $post_name = sanitize_title($post_title); |
| 3142 | 3142 | } else { |
| 3143 | 3143 | $post_name = ''; |
| 3144 | 3144 | } |
| 3145 | 3145 | } else { |
| 3146 | 3146 | // On updates, we need to check to see if it's using the old, fixed sanitization context. |
| 3147 | - $check_name = sanitize_title( $post_name, '', 'old-save' ); |
|
| 3148 | - if ( $update && strtolower( urlencode( $post_name ) ) == $check_name && get_post_field( 'post_name', $post_ID ) == $check_name ) { |
|
| 3147 | + $check_name = sanitize_title($post_name, '', 'old-save'); |
|
| 3148 | + if ($update && strtolower(urlencode($post_name)) == $check_name && get_post_field('post_name', $post_ID) == $check_name) { |
|
| 3149 | 3149 | $post_name = $check_name; |
| 3150 | 3150 | } else { // new post, or slug has changed. |
| 3151 | 3151 | $post_name = sanitize_title($post_name); |
@@ -3156,32 +3156,32 @@ discard block |
||
| 3156 | 3156 | * If the post date is empty (due to having been new or a draft) and status |
| 3157 | 3157 | * is not 'draft' or 'pending', set date to now. |
| 3158 | 3158 | */ |
| 3159 | - if ( empty( $postarr['post_date'] ) || '0000-00-00 00:00:00' == $postarr['post_date'] ) { |
|
| 3160 | - if ( empty( $postarr['post_date_gmt'] ) || '0000-00-00 00:00:00' == $postarr['post_date_gmt'] ) { |
|
| 3161 | - $post_date = current_time( 'mysql' ); |
|
| 3159 | + if (empty($postarr['post_date']) || '0000-00-00 00:00:00' == $postarr['post_date']) { |
|
| 3160 | + if (empty($postarr['post_date_gmt']) || '0000-00-00 00:00:00' == $postarr['post_date_gmt']) { |
|
| 3161 | + $post_date = current_time('mysql'); |
|
| 3162 | 3162 | } else { |
| 3163 | - $post_date = get_date_from_gmt( $postarr['post_date_gmt'] ); |
|
| 3163 | + $post_date = get_date_from_gmt($postarr['post_date_gmt']); |
|
| 3164 | 3164 | } |
| 3165 | 3165 | } else { |
| 3166 | 3166 | $post_date = $postarr['post_date']; |
| 3167 | 3167 | } |
| 3168 | 3168 | |
| 3169 | 3169 | // Validate the date. |
| 3170 | - $mm = substr( $post_date, 5, 2 ); |
|
| 3171 | - $jj = substr( $post_date, 8, 2 ); |
|
| 3172 | - $aa = substr( $post_date, 0, 4 ); |
|
| 3173 | - $valid_date = wp_checkdate( $mm, $jj, $aa, $post_date ); |
|
| 3174 | - if ( ! $valid_date ) { |
|
| 3175 | - if ( $wp_error ) { |
|
| 3176 | - return new WP_Error( 'invalid_date', __( 'Whoops, the provided date is invalid.' ) ); |
|
| 3170 | + $mm = substr($post_date, 5, 2); |
|
| 3171 | + $jj = substr($post_date, 8, 2); |
|
| 3172 | + $aa = substr($post_date, 0, 4); |
|
| 3173 | + $valid_date = wp_checkdate($mm, $jj, $aa, $post_date); |
|
| 3174 | + if ( ! $valid_date) { |
|
| 3175 | + if ($wp_error) { |
|
| 3176 | + return new WP_Error('invalid_date', __('Whoops, the provided date is invalid.')); |
|
| 3177 | 3177 | } else { |
| 3178 | 3178 | return 0; |
| 3179 | 3179 | } |
| 3180 | 3180 | } |
| 3181 | 3181 | |
| 3182 | - if ( empty( $postarr['post_date_gmt'] ) || '0000-00-00 00:00:00' == $postarr['post_date_gmt'] ) { |
|
| 3183 | - if ( ! in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) { |
|
| 3184 | - $post_date_gmt = get_gmt_from_date( $post_date ); |
|
| 3182 | + if (empty($postarr['post_date_gmt']) || '0000-00-00 00:00:00' == $postarr['post_date_gmt']) { |
|
| 3183 | + if ( ! in_array($post_status, array('draft', 'pending', 'auto-draft'))) { |
|
| 3184 | + $post_date_gmt = get_gmt_from_date($post_date); |
|
| 3185 | 3185 | } else { |
| 3186 | 3186 | $post_date_gmt = '0000-00-00 00:00:00'; |
| 3187 | 3187 | } |
@@ -3189,34 +3189,34 @@ discard block |
||
| 3189 | 3189 | $post_date_gmt = $postarr['post_date_gmt']; |
| 3190 | 3190 | } |
| 3191 | 3191 | |
| 3192 | - if ( $update || '0000-00-00 00:00:00' == $post_date ) { |
|
| 3193 | - $post_modified = current_time( 'mysql' ); |
|
| 3194 | - $post_modified_gmt = current_time( 'mysql', 1 ); |
|
| 3192 | + if ($update || '0000-00-00 00:00:00' == $post_date) { |
|
| 3193 | + $post_modified = current_time('mysql'); |
|
| 3194 | + $post_modified_gmt = current_time('mysql', 1); |
|
| 3195 | 3195 | } else { |
| 3196 | 3196 | $post_modified = $post_date; |
| 3197 | 3197 | $post_modified_gmt = $post_date_gmt; |
| 3198 | 3198 | } |
| 3199 | 3199 | |
| 3200 | - if ( 'attachment' !== $post_type ) { |
|
| 3201 | - if ( 'publish' == $post_status ) { |
|
| 3200 | + if ('attachment' !== $post_type) { |
|
| 3201 | + if ('publish' == $post_status) { |
|
| 3202 | 3202 | $now = gmdate('Y-m-d H:i:59'); |
| 3203 | - if ( mysql2date('U', $post_date_gmt, false) > mysql2date('U', $now, false) ) { |
|
| 3203 | + if (mysql2date('U', $post_date_gmt, false) > mysql2date('U', $now, false)) { |
|
| 3204 | 3204 | $post_status = 'future'; |
| 3205 | 3205 | } |
| 3206 | - } elseif ( 'future' == $post_status ) { |
|
| 3206 | + } elseif ('future' == $post_status) { |
|
| 3207 | 3207 | $now = gmdate('Y-m-d H:i:59'); |
| 3208 | - if ( mysql2date('U', $post_date_gmt, false) <= mysql2date('U', $now, false) ) { |
|
| 3208 | + if (mysql2date('U', $post_date_gmt, false) <= mysql2date('U', $now, false)) { |
|
| 3209 | 3209 | $post_status = 'publish'; |
| 3210 | 3210 | } |
| 3211 | 3211 | } |
| 3212 | 3212 | } |
| 3213 | 3213 | |
| 3214 | 3214 | // Comment status. |
| 3215 | - if ( empty( $postarr['comment_status'] ) ) { |
|
| 3216 | - if ( $update ) { |
|
| 3215 | + if (empty($postarr['comment_status'])) { |
|
| 3216 | + if ($update) { |
|
| 3217 | 3217 | $comment_status = 'closed'; |
| 3218 | 3218 | } else { |
| 3219 | - $comment_status = get_default_comment_status( $post_type ); |
|
| 3219 | + $comment_status = get_default_comment_status($post_type); |
|
| 3220 | 3220 | } |
| 3221 | 3221 | } else { |
| 3222 | 3222 | $comment_status = $postarr['comment_status']; |
@@ -3224,28 +3224,28 @@ discard block |
||
| 3224 | 3224 | |
| 3225 | 3225 | // These variables are needed by compact() later. |
| 3226 | 3226 | $post_content_filtered = $postarr['post_content_filtered']; |
| 3227 | - $post_author = isset( $postarr['post_author'] ) ? $postarr['post_author'] : $user_id; |
|
| 3228 | - $ping_status = empty( $postarr['ping_status'] ) ? get_default_comment_status( $post_type, 'pingback' ) : $postarr['ping_status']; |
|
| 3229 | - $to_ping = isset( $postarr['to_ping'] ) ? sanitize_trackback_urls( $postarr['to_ping'] ) : ''; |
|
| 3230 | - $pinged = isset( $postarr['pinged'] ) ? $postarr['pinged'] : ''; |
|
| 3231 | - $import_id = isset( $postarr['import_id'] ) ? $postarr['import_id'] : 0; |
|
| 3227 | + $post_author = isset($postarr['post_author']) ? $postarr['post_author'] : $user_id; |
|
| 3228 | + $ping_status = empty($postarr['ping_status']) ? get_default_comment_status($post_type, 'pingback') : $postarr['ping_status']; |
|
| 3229 | + $to_ping = isset($postarr['to_ping']) ? sanitize_trackback_urls($postarr['to_ping']) : ''; |
|
| 3230 | + $pinged = isset($postarr['pinged']) ? $postarr['pinged'] : ''; |
|
| 3231 | + $import_id = isset($postarr['import_id']) ? $postarr['import_id'] : 0; |
|
| 3232 | 3232 | |
| 3233 | 3233 | /* |
| 3234 | 3234 | * The 'wp_insert_post_parent' filter expects all variables to be present. |
| 3235 | 3235 | * Previously, these variables would have already been extracted |
| 3236 | 3236 | */ |
| 3237 | - if ( isset( $postarr['menu_order'] ) ) { |
|
| 3237 | + if (isset($postarr['menu_order'])) { |
|
| 3238 | 3238 | $menu_order = (int) $postarr['menu_order']; |
| 3239 | 3239 | } else { |
| 3240 | 3240 | $menu_order = 0; |
| 3241 | 3241 | } |
| 3242 | 3242 | |
| 3243 | - $post_password = isset( $postarr['post_password'] ) ? $postarr['post_password'] : ''; |
|
| 3244 | - if ( 'private' == $post_status ) { |
|
| 3243 | + $post_password = isset($postarr['post_password']) ? $postarr['post_password'] : ''; |
|
| 3244 | + if ('private' == $post_status) { |
|
| 3245 | 3245 | $post_password = ''; |
| 3246 | 3246 | } |
| 3247 | 3247 | |
| 3248 | - if ( isset( $postarr['post_parent'] ) ) { |
|
| 3248 | + if (isset($postarr['post_parent'])) { |
|
| 3249 | 3249 | $post_parent = (int) $postarr['post_parent']; |
| 3250 | 3250 | } else { |
| 3251 | 3251 | $post_parent = 0; |
@@ -3261,50 +3261,50 @@ discard block |
||
| 3261 | 3261 | * @param array $new_postarr Array of parsed post data. |
| 3262 | 3262 | * @param array $postarr Array of sanitized, but otherwise unmodified post data. |
| 3263 | 3263 | */ |
| 3264 | - $post_parent = apply_filters( 'wp_insert_post_parent', $post_parent, $post_ID, compact( array_keys( $postarr ) ), $postarr ); |
|
| 3264 | + $post_parent = apply_filters('wp_insert_post_parent', $post_parent, $post_ID, compact(array_keys($postarr)), $postarr); |
|
| 3265 | 3265 | |
| 3266 | 3266 | /* |
| 3267 | 3267 | * If the post is being untrashed and it has a desired slug stored in post meta, |
| 3268 | 3268 | * reassign it. |
| 3269 | 3269 | */ |
| 3270 | - if ( 'trash' === $previous_status && 'trash' !== $post_status ) { |
|
| 3271 | - $desired_post_slug = get_post_meta( $post_ID, '_wp_desired_post_slug', true ); |
|
| 3272 | - if ( $desired_post_slug ) { |
|
| 3273 | - delete_post_meta( $post_ID, '_wp_desired_post_slug' ); |
|
| 3270 | + if ('trash' === $previous_status && 'trash' !== $post_status) { |
|
| 3271 | + $desired_post_slug = get_post_meta($post_ID, '_wp_desired_post_slug', true); |
|
| 3272 | + if ($desired_post_slug) { |
|
| 3273 | + delete_post_meta($post_ID, '_wp_desired_post_slug'); |
|
| 3274 | 3274 | $post_name = $desired_post_slug; |
| 3275 | 3275 | } |
| 3276 | 3276 | } |
| 3277 | 3277 | |
| 3278 | 3278 | // If a trashed post has the desired slug, change it and let this post have it. |
| 3279 | - if ( 'trash' !== $post_status && $post_name ) { |
|
| 3280 | - wp_add_trashed_suffix_to_post_name_for_trashed_posts( $post_name, $post_ID ); |
|
| 3279 | + if ('trash' !== $post_status && $post_name) { |
|
| 3280 | + wp_add_trashed_suffix_to_post_name_for_trashed_posts($post_name, $post_ID); |
|
| 3281 | 3281 | } |
| 3282 | 3282 | |
| 3283 | 3283 | // When trashing an existing post, change its slug to allow non-trashed posts to use it. |
| 3284 | - if ( 'trash' === $post_status && 'trash' !== $previous_status && 'new' !== $previous_status ) { |
|
| 3285 | - $post_name = wp_add_trashed_suffix_to_post_name_for_post( $post_ID ); |
|
| 3284 | + if ('trash' === $post_status && 'trash' !== $previous_status && 'new' !== $previous_status) { |
|
| 3285 | + $post_name = wp_add_trashed_suffix_to_post_name_for_post($post_ID); |
|
| 3286 | 3286 | } |
| 3287 | 3287 | |
| 3288 | - $post_name = wp_unique_post_slug( $post_name, $post_ID, $post_status, $post_type, $post_parent ); |
|
| 3288 | + $post_name = wp_unique_post_slug($post_name, $post_ID, $post_status, $post_type, $post_parent); |
|
| 3289 | 3289 | |
| 3290 | 3290 | // Don't unslash. |
| 3291 | - $post_mime_type = isset( $postarr['post_mime_type'] ) ? $postarr['post_mime_type'] : ''; |
|
| 3291 | + $post_mime_type = isset($postarr['post_mime_type']) ? $postarr['post_mime_type'] : ''; |
|
| 3292 | 3292 | |
| 3293 | 3293 | // Expected_slashed (everything!). |
| 3294 | - $data = compact( 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_content_filtered', 'post_title', 'post_excerpt', 'post_status', 'post_type', 'comment_status', 'ping_status', 'post_password', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_parent', 'menu_order', 'post_mime_type', 'guid' ); |
|
| 3294 | + $data = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_content_filtered', 'post_title', 'post_excerpt', 'post_status', 'post_type', 'comment_status', 'ping_status', 'post_password', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_parent', 'menu_order', 'post_mime_type', 'guid'); |
|
| 3295 | 3295 | |
| 3296 | - $emoji_fields = array( 'post_title', 'post_content', 'post_excerpt' ); |
|
| 3296 | + $emoji_fields = array('post_title', 'post_content', 'post_excerpt'); |
|
| 3297 | 3297 | |
| 3298 | - foreach ( $emoji_fields as $emoji_field ) { |
|
| 3299 | - if ( isset( $data[ $emoji_field ] ) ) { |
|
| 3300 | - $charset = $wpdb->get_col_charset( $wpdb->posts, $emoji_field ); |
|
| 3301 | - if ( 'utf8' === $charset ) { |
|
| 3302 | - $data[ $emoji_field ] = wp_encode_emoji( $data[ $emoji_field ] ); |
|
| 3298 | + foreach ($emoji_fields as $emoji_field) { |
|
| 3299 | + if (isset($data[$emoji_field])) { |
|
| 3300 | + $charset = $wpdb->get_col_charset($wpdb->posts, $emoji_field); |
|
| 3301 | + if ('utf8' === $charset) { |
|
| 3302 | + $data[$emoji_field] = wp_encode_emoji($data[$emoji_field]); |
|
| 3303 | 3303 | } |
| 3304 | 3304 | } |
| 3305 | 3305 | } |
| 3306 | 3306 | |
| 3307 | - if ( 'attachment' === $post_type ) { |
|
| 3307 | + if ('attachment' === $post_type) { |
|
| 3308 | 3308 | /** |
| 3309 | 3309 | * Filter attachment post data before it is updated in or added to the database. |
| 3310 | 3310 | * |
@@ -3313,7 +3313,7 @@ discard block |
||
| 3313 | 3313 | * @param array $data An array of sanitized attachment post data. |
| 3314 | 3314 | * @param array $postarr An array of unsanitized attachment post data. |
| 3315 | 3315 | */ |
| 3316 | - $data = apply_filters( 'wp_insert_attachment_data', $data, $postarr ); |
|
| 3316 | + $data = apply_filters('wp_insert_attachment_data', $data, $postarr); |
|
| 3317 | 3317 | } else { |
| 3318 | 3318 | /** |
| 3319 | 3319 | * Filter slashed post data just before it is inserted into the database. |
@@ -3323,12 +3323,12 @@ discard block |
||
| 3323 | 3323 | * @param array $data An array of slashed post data. |
| 3324 | 3324 | * @param array $postarr An array of sanitized, but otherwise unmodified post data. |
| 3325 | 3325 | */ |
| 3326 | - $data = apply_filters( 'wp_insert_post_data', $data, $postarr ); |
|
| 3326 | + $data = apply_filters('wp_insert_post_data', $data, $postarr); |
|
| 3327 | 3327 | } |
| 3328 | - $data = wp_unslash( $data ); |
|
| 3329 | - $where = array( 'ID' => $post_ID ); |
|
| 3328 | + $data = wp_unslash($data); |
|
| 3329 | + $where = array('ID' => $post_ID); |
|
| 3330 | 3330 | |
| 3331 | - if ( $update ) { |
|
| 3331 | + if ($update) { |
|
| 3332 | 3332 | /** |
| 3333 | 3333 | * Fires immediately before an existing post is updated in the database. |
| 3334 | 3334 | * |
@@ -3337,9 +3337,9 @@ discard block |
||
| 3337 | 3337 | * @param int $post_ID Post ID. |
| 3338 | 3338 | * @param array $data Array of unslashed post data. |
| 3339 | 3339 | */ |
| 3340 | - do_action( 'pre_post_update', $post_ID, $data ); |
|
| 3341 | - if ( false === $wpdb->update( $wpdb->posts, $data, $where ) ) { |
|
| 3342 | - if ( $wp_error ) { |
|
| 3340 | + do_action('pre_post_update', $post_ID, $data); |
|
| 3341 | + if (false === $wpdb->update($wpdb->posts, $data, $where)) { |
|
| 3342 | + if ($wp_error) { |
|
| 3343 | 3343 | return new WP_Error('db_update_error', __('Could not update post in the database'), $wpdb->last_error); |
| 3344 | 3344 | } else { |
| 3345 | 3345 | return 0; |
@@ -3347,14 +3347,14 @@ discard block |
||
| 3347 | 3347 | } |
| 3348 | 3348 | } else { |
| 3349 | 3349 | // If there is a suggested ID, use it if not already present. |
| 3350 | - if ( ! empty( $import_id ) ) { |
|
| 3350 | + if ( ! empty($import_id)) { |
|
| 3351 | 3351 | $import_id = (int) $import_id; |
| 3352 | - if ( ! $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE ID = %d", $import_id) ) ) { |
|
| 3352 | + if ( ! $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE ID = %d", $import_id))) { |
|
| 3353 | 3353 | $data['ID'] = $import_id; |
| 3354 | 3354 | } |
| 3355 | 3355 | } |
| 3356 | - if ( false === $wpdb->insert( $wpdb->posts, $data ) ) { |
|
| 3357 | - if ( $wp_error ) { |
|
| 3356 | + if (false === $wpdb->insert($wpdb->posts, $data)) { |
|
| 3357 | + if ($wp_error) { |
|
| 3358 | 3358 | return new WP_Error('db_insert_error', __('Could not insert post into the database'), $wpdb->last_error); |
| 3359 | 3359 | } else { |
| 3360 | 3360 | return 0; |
@@ -3363,87 +3363,87 @@ discard block |
||
| 3363 | 3363 | $post_ID = (int) $wpdb->insert_id; |
| 3364 | 3364 | |
| 3365 | 3365 | // Use the newly generated $post_ID. |
| 3366 | - $where = array( 'ID' => $post_ID ); |
|
| 3366 | + $where = array('ID' => $post_ID); |
|
| 3367 | 3367 | } |
| 3368 | 3368 | |
| 3369 | - if ( empty( $data['post_name'] ) && ! in_array( $data['post_status'], array( 'draft', 'pending', 'auto-draft' ) ) ) { |
|
| 3370 | - $data['post_name'] = wp_unique_post_slug( sanitize_title( $data['post_title'], $post_ID ), $post_ID, $data['post_status'], $post_type, $post_parent ); |
|
| 3371 | - $wpdb->update( $wpdb->posts, array( 'post_name' => $data['post_name'] ), $where ); |
|
| 3372 | - clean_post_cache( $post_ID ); |
|
| 3369 | + if (empty($data['post_name']) && ! in_array($data['post_status'], array('draft', 'pending', 'auto-draft'))) { |
|
| 3370 | + $data['post_name'] = wp_unique_post_slug(sanitize_title($data['post_title'], $post_ID), $post_ID, $data['post_status'], $post_type, $post_parent); |
|
| 3371 | + $wpdb->update($wpdb->posts, array('post_name' => $data['post_name']), $where); |
|
| 3372 | + clean_post_cache($post_ID); |
|
| 3373 | 3373 | } |
| 3374 | 3374 | |
| 3375 | - if ( is_object_in_taxonomy( $post_type, 'category' ) ) { |
|
| 3376 | - wp_set_post_categories( $post_ID, $post_category ); |
|
| 3375 | + if (is_object_in_taxonomy($post_type, 'category')) { |
|
| 3376 | + wp_set_post_categories($post_ID, $post_category); |
|
| 3377 | 3377 | } |
| 3378 | 3378 | |
| 3379 | - if ( isset( $postarr['tags_input'] ) && is_object_in_taxonomy( $post_type, 'post_tag' ) ) { |
|
| 3380 | - wp_set_post_tags( $post_ID, $postarr['tags_input'] ); |
|
| 3379 | + if (isset($postarr['tags_input']) && is_object_in_taxonomy($post_type, 'post_tag')) { |
|
| 3380 | + wp_set_post_tags($post_ID, $postarr['tags_input']); |
|
| 3381 | 3381 | } |
| 3382 | 3382 | |
| 3383 | 3383 | // New-style support for all custom taxonomies. |
| 3384 | - if ( ! empty( $postarr['tax_input'] ) ) { |
|
| 3385 | - foreach ( $postarr['tax_input'] as $taxonomy => $tags ) { |
|
| 3384 | + if ( ! empty($postarr['tax_input'])) { |
|
| 3385 | + foreach ($postarr['tax_input'] as $taxonomy => $tags) { |
|
| 3386 | 3386 | $taxonomy_obj = get_taxonomy($taxonomy); |
| 3387 | - if ( ! $taxonomy_obj ) { |
|
| 3387 | + if ( ! $taxonomy_obj) { |
|
| 3388 | 3388 | /* translators: %s: taxonomy name */ |
| 3389 | - _doing_it_wrong( __FUNCTION__, sprintf( __( 'Invalid taxonomy: %s.' ), $taxonomy ), '4.4.0' ); |
|
| 3389 | + _doing_it_wrong(__FUNCTION__, sprintf(__('Invalid taxonomy: %s.'), $taxonomy), '4.4.0'); |
|
| 3390 | 3390 | continue; |
| 3391 | 3391 | } |
| 3392 | 3392 | |
| 3393 | 3393 | // array = hierarchical, string = non-hierarchical. |
| 3394 | - if ( is_array( $tags ) ) { |
|
| 3394 | + if (is_array($tags)) { |
|
| 3395 | 3395 | $tags = array_filter($tags); |
| 3396 | 3396 | } |
| 3397 | - if ( current_user_can( $taxonomy_obj->cap->assign_terms ) ) { |
|
| 3398 | - wp_set_post_terms( $post_ID, $tags, $taxonomy ); |
|
| 3397 | + if (current_user_can($taxonomy_obj->cap->assign_terms)) { |
|
| 3398 | + wp_set_post_terms($post_ID, $tags, $taxonomy); |
|
| 3399 | 3399 | } |
| 3400 | 3400 | } |
| 3401 | 3401 | } |
| 3402 | 3402 | |
| 3403 | - if ( ! empty( $postarr['meta_input'] ) ) { |
|
| 3404 | - foreach ( $postarr['meta_input'] as $field => $value ) { |
|
| 3405 | - update_post_meta( $post_ID, $field, $value ); |
|
| 3403 | + if ( ! empty($postarr['meta_input'])) { |
|
| 3404 | + foreach ($postarr['meta_input'] as $field => $value) { |
|
| 3405 | + update_post_meta($post_ID, $field, $value); |
|
| 3406 | 3406 | } |
| 3407 | 3407 | } |
| 3408 | 3408 | |
| 3409 | - $current_guid = get_post_field( 'guid', $post_ID ); |
|
| 3409 | + $current_guid = get_post_field('guid', $post_ID); |
|
| 3410 | 3410 | |
| 3411 | 3411 | // Set GUID. |
| 3412 | - if ( ! $update && '' == $current_guid ) { |
|
| 3413 | - $wpdb->update( $wpdb->posts, array( 'guid' => get_permalink( $post_ID ) ), $where ); |
|
| 3412 | + if ( ! $update && '' == $current_guid) { |
|
| 3413 | + $wpdb->update($wpdb->posts, array('guid' => get_permalink($post_ID)), $where); |
|
| 3414 | 3414 | } |
| 3415 | 3415 | |
| 3416 | - if ( 'attachment' === $postarr['post_type'] ) { |
|
| 3417 | - if ( ! empty( $postarr['file'] ) ) { |
|
| 3418 | - update_attached_file( $post_ID, $postarr['file'] ); |
|
| 3416 | + if ('attachment' === $postarr['post_type']) { |
|
| 3417 | + if ( ! empty($postarr['file'])) { |
|
| 3418 | + update_attached_file($post_ID, $postarr['file']); |
|
| 3419 | 3419 | } |
| 3420 | 3420 | |
| 3421 | - if ( ! empty( $postarr['context'] ) ) { |
|
| 3422 | - add_post_meta( $post_ID, '_wp_attachment_context', $postarr['context'], true ); |
|
| 3421 | + if ( ! empty($postarr['context'])) { |
|
| 3422 | + add_post_meta($post_ID, '_wp_attachment_context', $postarr['context'], true); |
|
| 3423 | 3423 | } |
| 3424 | 3424 | } |
| 3425 | 3425 | |
| 3426 | - clean_post_cache( $post_ID ); |
|
| 3426 | + clean_post_cache($post_ID); |
|
| 3427 | 3427 | |
| 3428 | - $post = get_post( $post_ID ); |
|
| 3428 | + $post = get_post($post_ID); |
|
| 3429 | 3429 | |
| 3430 | - if ( ! empty( $postarr['page_template'] ) && 'page' == $data['post_type'] ) { |
|
| 3430 | + if ( ! empty($postarr['page_template']) && 'page' == $data['post_type']) { |
|
| 3431 | 3431 | $post->page_template = $postarr['page_template']; |
| 3432 | - $page_templates = wp_get_theme()->get_page_templates( $post ); |
|
| 3433 | - if ( 'default' != $postarr['page_template'] && ! isset( $page_templates[ $postarr['page_template'] ] ) ) { |
|
| 3434 | - if ( $wp_error ) { |
|
| 3432 | + $page_templates = wp_get_theme()->get_page_templates($post); |
|
| 3433 | + if ('default' != $postarr['page_template'] && ! isset($page_templates[$postarr['page_template']])) { |
|
| 3434 | + if ($wp_error) { |
|
| 3435 | 3435 | return new WP_Error('invalid_page_template', __('The page template is invalid.')); |
| 3436 | 3436 | } |
| 3437 | - update_post_meta( $post_ID, '_wp_page_template', 'default' ); |
|
| 3437 | + update_post_meta($post_ID, '_wp_page_template', 'default'); |
|
| 3438 | 3438 | } else { |
| 3439 | - update_post_meta( $post_ID, '_wp_page_template', $postarr['page_template'] ); |
|
| 3439 | + update_post_meta($post_ID, '_wp_page_template', $postarr['page_template']); |
|
| 3440 | 3440 | } |
| 3441 | 3441 | } |
| 3442 | 3442 | |
| 3443 | - if ( 'attachment' !== $postarr['post_type'] ) { |
|
| 3444 | - wp_transition_post_status( $data['post_status'], $previous_status, $post ); |
|
| 3443 | + if ('attachment' !== $postarr['post_type']) { |
|
| 3444 | + wp_transition_post_status($data['post_status'], $previous_status, $post); |
|
| 3445 | 3445 | } else { |
| 3446 | - if ( $update ) { |
|
| 3446 | + if ($update) { |
|
| 3447 | 3447 | /** |
| 3448 | 3448 | * Fires once an existing attachment has been updated. |
| 3449 | 3449 | * |
@@ -3451,8 +3451,8 @@ discard block |
||
| 3451 | 3451 | * |
| 3452 | 3452 | * @param int $post_ID Attachment ID. |
| 3453 | 3453 | */ |
| 3454 | - do_action( 'edit_attachment', $post_ID ); |
|
| 3455 | - $post_after = get_post( $post_ID ); |
|
| 3454 | + do_action('edit_attachment', $post_ID); |
|
| 3455 | + $post_after = get_post($post_ID); |
|
| 3456 | 3456 | |
| 3457 | 3457 | /** |
| 3458 | 3458 | * Fires once an existing attachment has been updated. |
@@ -3463,7 +3463,7 @@ discard block |
||
| 3463 | 3463 | * @param WP_Post $post_after Post object following the update. |
| 3464 | 3464 | * @param WP_Post $post_before Post object before the update. |
| 3465 | 3465 | */ |
| 3466 | - do_action( 'attachment_updated', $post_ID, $post_after, $post_before ); |
|
| 3466 | + do_action('attachment_updated', $post_ID, $post_after, $post_before); |
|
| 3467 | 3467 | } else { |
| 3468 | 3468 | |
| 3469 | 3469 | /** |
@@ -3473,13 +3473,13 @@ discard block |
||
| 3473 | 3473 | * |
| 3474 | 3474 | * @param int $post_ID Attachment ID. |
| 3475 | 3475 | */ |
| 3476 | - do_action( 'add_attachment', $post_ID ); |
|
| 3476 | + do_action('add_attachment', $post_ID); |
|
| 3477 | 3477 | } |
| 3478 | 3478 | |
| 3479 | 3479 | return $post_ID; |
| 3480 | 3480 | } |
| 3481 | 3481 | |
| 3482 | - if ( $update ) { |
|
| 3482 | + if ($update) { |
|
| 3483 | 3483 | /** |
| 3484 | 3484 | * Fires once an existing post has been updated. |
| 3485 | 3485 | * |
@@ -3488,7 +3488,7 @@ discard block |
||
| 3488 | 3488 | * @param int $post_ID Post ID. |
| 3489 | 3489 | * @param WP_Post $post Post object. |
| 3490 | 3490 | */ |
| 3491 | - do_action( 'edit_post', $post_ID, $post ); |
|
| 3491 | + do_action('edit_post', $post_ID, $post); |
|
| 3492 | 3492 | $post_after = get_post($post_ID); |
| 3493 | 3493 | |
| 3494 | 3494 | /** |
@@ -3500,7 +3500,7 @@ discard block |
||
| 3500 | 3500 | * @param WP_Post $post_after Post object following the update. |
| 3501 | 3501 | * @param WP_Post $post_before Post object before the update. |
| 3502 | 3502 | */ |
| 3503 | - do_action( 'post_updated', $post_ID, $post_after, $post_before); |
|
| 3503 | + do_action('post_updated', $post_ID, $post_after, $post_before); |
|
| 3504 | 3504 | } |
| 3505 | 3505 | |
| 3506 | 3506 | /** |
@@ -3515,7 +3515,7 @@ discard block |
||
| 3515 | 3515 | * @param WP_Post $post Post object. |
| 3516 | 3516 | * @param bool $update Whether this is an existing post being updated or not. |
| 3517 | 3517 | */ |
| 3518 | - do_action( "save_post_{$post->post_type}", $post_ID, $post, $update ); |
|
| 3518 | + do_action("save_post_{$post->post_type}", $post_ID, $post, $update); |
|
| 3519 | 3519 | |
| 3520 | 3520 | /** |
| 3521 | 3521 | * Fires once a post has been saved. |
@@ -3526,7 +3526,7 @@ discard block |
||
| 3526 | 3526 | * @param WP_Post $post Post object. |
| 3527 | 3527 | * @param bool $update Whether this is an existing post being updated or not. |
| 3528 | 3528 | */ |
| 3529 | - do_action( 'save_post', $post_ID, $post, $update ); |
|
| 3529 | + do_action('save_post', $post_ID, $post, $update); |
|
| 3530 | 3530 | |
| 3531 | 3531 | /** |
| 3532 | 3532 | * Fires once a post has been saved. |
@@ -3537,7 +3537,7 @@ discard block |
||
| 3537 | 3537 | * @param WP_Post $post Post object. |
| 3538 | 3538 | * @param bool $update Whether this is an existing post being updated or not. |
| 3539 | 3539 | */ |
| 3540 | - do_action( 'wp_insert_post', $post_ID, $post, $update ); |
|
| 3540 | + do_action('wp_insert_post', $post_ID, $post, $update); |
|
| 3541 | 3541 | |
| 3542 | 3542 | return $post_ID; |
| 3543 | 3543 | } |
@@ -3555,8 +3555,8 @@ discard block |
||
| 3555 | 3555 | * @param bool $wp_error Optional. Allow return of WP_Error on failure. Default false. |
| 3556 | 3556 | * @return int|WP_Error The value 0 or WP_Error on failure. The post ID on success. |
| 3557 | 3557 | */ |
| 3558 | -function wp_update_post( $postarr = array(), $wp_error = false ) { |
|
| 3559 | - if ( is_object($postarr) ) { |
|
| 3558 | +function wp_update_post($postarr = array(), $wp_error = false) { |
|
| 3559 | + if (is_object($postarr)) { |
|
| 3560 | 3560 | // Non-escaped post was passed. |
| 3561 | 3561 | $postarr = get_object_vars($postarr); |
| 3562 | 3562 | $postarr = wp_slash($postarr); |
@@ -3565,9 +3565,9 @@ discard block |
||
| 3565 | 3565 | // First, get all of the original fields. |
| 3566 | 3566 | $post = get_post($postarr['ID'], ARRAY_A); |
| 3567 | 3567 | |
| 3568 | - if ( is_null( $post ) ) { |
|
| 3569 | - if ( $wp_error ) |
|
| 3570 | - return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) ); |
|
| 3568 | + if (is_null($post)) { |
|
| 3569 | + if ($wp_error) |
|
| 3570 | + return new WP_Error('invalid_post', __('Invalid post ID.')); |
|
| 3571 | 3571 | return 0; |
| 3572 | 3572 | } |
| 3573 | 3573 | |
@@ -3575,15 +3575,15 @@ discard block |
||
| 3575 | 3575 | $post = wp_slash($post); |
| 3576 | 3576 | |
| 3577 | 3577 | // Passed post category list overwrites existing category list if not empty. |
| 3578 | - if ( isset($postarr['post_category']) && is_array($postarr['post_category']) |
|
| 3579 | - && 0 != count($postarr['post_category']) ) |
|
| 3578 | + if (isset($postarr['post_category']) && is_array($postarr['post_category']) |
|
| 3579 | + && 0 != count($postarr['post_category'])) |
|
| 3580 | 3580 | $post_cats = $postarr['post_category']; |
| 3581 | 3581 | else |
| 3582 | 3582 | $post_cats = $post['post_category']; |
| 3583 | 3583 | |
| 3584 | 3584 | // Drafts shouldn't be assigned a date unless explicitly done so by the user. |
| 3585 | - if ( isset( $post['post_status'] ) && in_array($post['post_status'], array('draft', 'pending', 'auto-draft')) && empty($postarr['edit_date']) && |
|
| 3586 | - ('0000-00-00 00:00:00' == $post['post_date_gmt']) ) |
|
| 3585 | + if (isset($post['post_status']) && in_array($post['post_status'], array('draft', 'pending', 'auto-draft')) && empty($postarr['edit_date']) && |
|
| 3586 | + ('0000-00-00 00:00:00' == $post['post_date_gmt'])) |
|
| 3587 | 3587 | $clear_date = true; |
| 3588 | 3588 | else |
| 3589 | 3589 | $clear_date = false; |
@@ -3591,7 +3591,7 @@ discard block |
||
| 3591 | 3591 | // Merge old and new fields with new fields overwriting old ones. |
| 3592 | 3592 | $postarr = array_merge($post, $postarr); |
| 3593 | 3593 | $postarr['post_category'] = $post_cats; |
| 3594 | - if ( $clear_date ) { |
|
| 3594 | + if ($clear_date) { |
|
| 3595 | 3595 | $postarr['post_date'] = current_time('mysql'); |
| 3596 | 3596 | $postarr['post_date_gmt'] = ''; |
| 3597 | 3597 | } |
@@ -3599,7 +3599,7 @@ discard block |
||
| 3599 | 3599 | if ($postarr['post_type'] == 'attachment') |
| 3600 | 3600 | return wp_insert_attachment($postarr); |
| 3601 | 3601 | |
| 3602 | - return wp_insert_post( $postarr, $wp_error ); |
|
| 3602 | + return wp_insert_post($postarr, $wp_error); |
|
| 3603 | 3603 | } |
| 3604 | 3604 | |
| 3605 | 3605 | /** |
@@ -3611,34 +3611,34 @@ discard block |
||
| 3611 | 3611 | * |
| 3612 | 3612 | * @param int|WP_Post $post Post ID or post object. |
| 3613 | 3613 | */ |
| 3614 | -function wp_publish_post( $post ) { |
|
| 3614 | +function wp_publish_post($post) { |
|
| 3615 | 3615 | global $wpdb; |
| 3616 | 3616 | |
| 3617 | - if ( ! $post = get_post( $post ) ) |
|
| 3617 | + if ( ! $post = get_post($post)) |
|
| 3618 | 3618 | return; |
| 3619 | 3619 | |
| 3620 | - if ( 'publish' == $post->post_status ) |
|
| 3620 | + if ('publish' == $post->post_status) |
|
| 3621 | 3621 | return; |
| 3622 | 3622 | |
| 3623 | - $wpdb->update( $wpdb->posts, array( 'post_status' => 'publish' ), array( 'ID' => $post->ID ) ); |
|
| 3623 | + $wpdb->update($wpdb->posts, array('post_status' => 'publish'), array('ID' => $post->ID)); |
|
| 3624 | 3624 | |
| 3625 | - clean_post_cache( $post->ID ); |
|
| 3625 | + clean_post_cache($post->ID); |
|
| 3626 | 3626 | |
| 3627 | 3627 | $old_status = $post->post_status; |
| 3628 | 3628 | $post->post_status = 'publish'; |
| 3629 | - wp_transition_post_status( 'publish', $old_status, $post ); |
|
| 3629 | + wp_transition_post_status('publish', $old_status, $post); |
|
| 3630 | 3630 | |
| 3631 | 3631 | /** This action is documented in wp-includes/post.php */ |
| 3632 | - do_action( 'edit_post', $post->ID, $post ); |
|
| 3632 | + do_action('edit_post', $post->ID, $post); |
|
| 3633 | 3633 | |
| 3634 | 3634 | /** This action is documented in wp-includes/post.php */ |
| 3635 | - do_action( "save_post_{$post->post_type}", $post->ID, $post, true ); |
|
| 3635 | + do_action("save_post_{$post->post_type}", $post->ID, $post, true); |
|
| 3636 | 3636 | |
| 3637 | 3637 | /** This action is documented in wp-includes/post.php */ |
| 3638 | - do_action( 'save_post', $post->ID, $post, true ); |
|
| 3638 | + do_action('save_post', $post->ID, $post, true); |
|
| 3639 | 3639 | |
| 3640 | 3640 | /** This action is documented in wp-includes/post.php */ |
| 3641 | - do_action( 'wp_insert_post', $post->ID, $post, true ); |
|
| 3641 | + do_action('wp_insert_post', $post->ID, $post, true); |
|
| 3642 | 3642 | } |
| 3643 | 3643 | |
| 3644 | 3644 | /** |
@@ -3651,26 +3651,26 @@ discard block |
||
| 3651 | 3651 | * |
| 3652 | 3652 | * @param int|WP_Post $post_id Post ID or post object. |
| 3653 | 3653 | */ |
| 3654 | -function check_and_publish_future_post( $post_id ) { |
|
| 3654 | +function check_and_publish_future_post($post_id) { |
|
| 3655 | 3655 | $post = get_post($post_id); |
| 3656 | 3656 | |
| 3657 | - if ( empty($post) ) |
|
| 3657 | + if (empty($post)) |
|
| 3658 | 3658 | return; |
| 3659 | 3659 | |
| 3660 | - if ( 'future' != $post->post_status ) |
|
| 3660 | + if ('future' != $post->post_status) |
|
| 3661 | 3661 | return; |
| 3662 | 3662 | |
| 3663 | - $time = strtotime( $post->post_date_gmt . ' GMT' ); |
|
| 3663 | + $time = strtotime($post->post_date_gmt.' GMT'); |
|
| 3664 | 3664 | |
| 3665 | 3665 | // Uh oh, someone jumped the gun! |
| 3666 | - if ( $time > time() ) { |
|
| 3667 | - wp_clear_scheduled_hook( 'publish_future_post', array( $post_id ) ); // clear anything else in the system |
|
| 3668 | - wp_schedule_single_event( $time, 'publish_future_post', array( $post_id ) ); |
|
| 3666 | + if ($time > time()) { |
|
| 3667 | + wp_clear_scheduled_hook('publish_future_post', array($post_id)); // clear anything else in the system |
|
| 3668 | + wp_schedule_single_event($time, 'publish_future_post', array($post_id)); |
|
| 3669 | 3669 | return; |
| 3670 | 3670 | } |
| 3671 | 3671 | |
| 3672 | 3672 | // wp_publish_post(_ returns no meaningful value. |
| 3673 | - wp_publish_post( $post_id ); |
|
| 3673 | + wp_publish_post($post_id); |
|
| 3674 | 3674 | } |
| 3675 | 3675 | |
| 3676 | 3676 | /** |
@@ -3688,8 +3688,8 @@ discard block |
||
| 3688 | 3688 | * @param int $post_parent Post parent ID. |
| 3689 | 3689 | * @return string Unique slug for the post, based on $post_name (with a -1, -2, etc. suffix) |
| 3690 | 3690 | */ |
| 3691 | -function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent ) { |
|
| 3692 | - if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) || ( 'inherit' == $post_status && 'revision' == $post_type ) ) |
|
| 3691 | +function wp_unique_post_slug($slug, $post_ID, $post_status, $post_type, $post_parent) { |
|
| 3692 | + if (in_array($post_status, array('draft', 'pending', 'auto-draft')) || ('inherit' == $post_status && 'revision' == $post_type)) |
|
| 3693 | 3693 | return $slug; |
| 3694 | 3694 | |
| 3695 | 3695 | global $wpdb, $wp_rewrite; |
@@ -3697,13 +3697,13 @@ discard block |
||
| 3697 | 3697 | $original_slug = $slug; |
| 3698 | 3698 | |
| 3699 | 3699 | $feeds = $wp_rewrite->feeds; |
| 3700 | - if ( ! is_array( $feeds ) ) |
|
| 3700 | + if ( ! is_array($feeds)) |
|
| 3701 | 3701 | $feeds = array(); |
| 3702 | 3702 | |
| 3703 | - if ( 'attachment' == $post_type ) { |
|
| 3703 | + if ('attachment' == $post_type) { |
|
| 3704 | 3704 | // Attachment slugs must be unique across all types. |
| 3705 | 3705 | $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d LIMIT 1"; |
| 3706 | - $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_ID ) ); |
|
| 3706 | + $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_ID)); |
|
| 3707 | 3707 | |
| 3708 | 3708 | /** |
| 3709 | 3709 | * Filter whether the post slug would make a bad attachment slug. |
@@ -3713,17 +3713,17 @@ discard block |
||
| 3713 | 3713 | * @param bool $bad_slug Whether the slug would be bad as an attachment slug. |
| 3714 | 3714 | * @param string $slug The post slug. |
| 3715 | 3715 | */ |
| 3716 | - if ( $post_name_check || in_array( $slug, $feeds ) || 'embed' === $slug || apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $slug ) ) { |
|
| 3716 | + if ($post_name_check || in_array($slug, $feeds) || 'embed' === $slug || apply_filters('wp_unique_post_slug_is_bad_attachment_slug', false, $slug)) { |
|
| 3717 | 3717 | $suffix = 2; |
| 3718 | 3718 | do { |
| 3719 | - $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; |
|
| 3720 | - $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_ID ) ); |
|
| 3719 | + $alt_post_name = _truncate_post_slug($slug, 200 - (strlen($suffix) + 1))."-$suffix"; |
|
| 3720 | + $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name, $post_ID)); |
|
| 3721 | 3721 | $suffix++; |
| 3722 | - } while ( $post_name_check ); |
|
| 3722 | + } while ($post_name_check); |
|
| 3723 | 3723 | $slug = $alt_post_name; |
| 3724 | 3724 | } |
| 3725 | - } elseif ( is_post_type_hierarchical( $post_type ) ) { |
|
| 3726 | - if ( 'nav_menu_item' == $post_type ) |
|
| 3725 | + } elseif (is_post_type_hierarchical($post_type)) { |
|
| 3726 | + if ('nav_menu_item' == $post_type) |
|
| 3727 | 3727 | return $slug; |
| 3728 | 3728 | |
| 3729 | 3729 | /* |
@@ -3731,7 +3731,7 @@ discard block |
||
| 3731 | 3731 | * namespace than posts so page slugs are allowed to overlap post slugs. |
| 3732 | 3732 | */ |
| 3733 | 3733 | $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( %s, 'attachment' ) AND ID != %d AND post_parent = %d LIMIT 1"; |
| 3734 | - $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID, $post_parent ) ); |
|
| 3734 | + $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_type, $post_ID, $post_parent)); |
|
| 3735 | 3735 | |
| 3736 | 3736 | /** |
| 3737 | 3737 | * Filter whether the post slug would make a bad hierarchical post slug. |
@@ -3743,26 +3743,26 @@ discard block |
||
| 3743 | 3743 | * @param string $post_type Post type. |
| 3744 | 3744 | * @param int $post_parent Post parent ID. |
| 3745 | 3745 | */ |
| 3746 | - if ( $post_name_check || in_array( $slug, $feeds ) || 'embed' === $slug || preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug ) || apply_filters( 'wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post_type, $post_parent ) ) { |
|
| 3746 | + if ($post_name_check || in_array($slug, $feeds) || 'embed' === $slug || preg_match("@^($wp_rewrite->pagination_base)?\d+$@", $slug) || apply_filters('wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post_type, $post_parent)) { |
|
| 3747 | 3747 | $suffix = 2; |
| 3748 | 3748 | do { |
| 3749 | - $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; |
|
| 3750 | - $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_ID, $post_parent ) ); |
|
| 3749 | + $alt_post_name = _truncate_post_slug($slug, 200 - (strlen($suffix) + 1))."-$suffix"; |
|
| 3750 | + $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name, $post_type, $post_ID, $post_parent)); |
|
| 3751 | 3751 | $suffix++; |
| 3752 | - } while ( $post_name_check ); |
|
| 3752 | + } while ($post_name_check); |
|
| 3753 | 3753 | $slug = $alt_post_name; |
| 3754 | 3754 | } |
| 3755 | 3755 | } else { |
| 3756 | 3756 | // Post slugs must be unique across all posts. |
| 3757 | 3757 | $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1"; |
| 3758 | - $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID ) ); |
|
| 3758 | + $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_type, $post_ID)); |
|
| 3759 | 3759 | |
| 3760 | 3760 | // Prevent new post slugs that could result in URLs that conflict with date archives. |
| 3761 | - $post = get_post( $post_ID ); |
|
| 3761 | + $post = get_post($post_ID); |
|
| 3762 | 3762 | $conflicts_with_date_archive = false; |
| 3763 | - if ( 'post' === $post_type && ( ! $post || $post->post_name !== $slug ) && preg_match( '/^[0-9]+$/', $slug ) && $slug_num = intval( $slug ) ) { |
|
| 3764 | - $permastructs = array_values( array_filter( explode( '/', get_option( 'permalink_structure' ) ) ) ); |
|
| 3765 | - $postname_index = array_search( '%postname%', $permastructs ); |
|
| 3763 | + if ('post' === $post_type && ( ! $post || $post->post_name !== $slug) && preg_match('/^[0-9]+$/', $slug) && $slug_num = intval($slug)) { |
|
| 3764 | + $permastructs = array_values(array_filter(explode('/', get_option('permalink_structure')))); |
|
| 3765 | + $postname_index = array_search('%postname%', $permastructs); |
|
| 3766 | 3766 | |
| 3767 | 3767 | /* |
| 3768 | 3768 | * Potential date clashes are as follows: |
@@ -3771,9 +3771,9 @@ discard block |
||
| 3771 | 3771 | * - An integer between 1 and 12 that follows 'year' conflicts with 'monthnum'. |
| 3772 | 3772 | * - An integer between 1 and 31 that follows 'monthnum' conflicts with 'day'. |
| 3773 | 3773 | */ |
| 3774 | - if ( 0 === $postname_index || |
|
| 3775 | - ( $postname_index && '%year%' === $permastructs[ $postname_index - 1 ] && 13 > $slug_num ) || |
|
| 3776 | - ( $postname_index && '%monthnum%' === $permastructs[ $postname_index - 1 ] && 32 > $slug_num ) |
|
| 3774 | + if (0 === $postname_index || |
|
| 3775 | + ($postname_index && '%year%' === $permastructs[$postname_index - 1] && 13 > $slug_num) || |
|
| 3776 | + ($postname_index && '%monthnum%' === $permastructs[$postname_index - 1] && 32 > $slug_num) |
|
| 3777 | 3777 | ) { |
| 3778 | 3778 | $conflicts_with_date_archive = true; |
| 3779 | 3779 | } |
@@ -3788,13 +3788,13 @@ discard block |
||
| 3788 | 3788 | * @param string $slug The post slug. |
| 3789 | 3789 | * @param string $post_type Post type. |
| 3790 | 3790 | */ |
| 3791 | - if ( $post_name_check || in_array( $slug, $feeds ) || 'embed' === $slug || $conflicts_with_date_archive || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type ) ) { |
|
| 3791 | + if ($post_name_check || in_array($slug, $feeds) || 'embed' === $slug || $conflicts_with_date_archive || apply_filters('wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type)) { |
|
| 3792 | 3792 | $suffix = 2; |
| 3793 | 3793 | do { |
| 3794 | - $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; |
|
| 3795 | - $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_ID ) ); |
|
| 3794 | + $alt_post_name = _truncate_post_slug($slug, 200 - (strlen($suffix) + 1))."-$suffix"; |
|
| 3795 | + $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name, $post_type, $post_ID)); |
|
| 3796 | 3796 | $suffix++; |
| 3797 | - } while ( $post_name_check ); |
|
| 3797 | + } while ($post_name_check); |
|
| 3798 | 3798 | $slug = $alt_post_name; |
| 3799 | 3799 | } |
| 3800 | 3800 | } |
@@ -3811,7 +3811,7 @@ discard block |
||
| 3811 | 3811 | * @param int $post_parent Post parent ID |
| 3812 | 3812 | * @param string $original_slug The original post slug. |
| 3813 | 3813 | */ |
| 3814 | - return apply_filters( 'wp_unique_post_slug', $slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug ); |
|
| 3814 | + return apply_filters('wp_unique_post_slug', $slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug); |
|
| 3815 | 3815 | } |
| 3816 | 3816 | |
| 3817 | 3817 | /** |
@@ -3826,16 +3826,16 @@ discard block |
||
| 3826 | 3826 | * @param int $length Optional. Max length of the slug. Default 200 (characters). |
| 3827 | 3827 | * @return string The truncated slug. |
| 3828 | 3828 | */ |
| 3829 | -function _truncate_post_slug( $slug, $length = 200 ) { |
|
| 3830 | - if ( strlen( $slug ) > $length ) { |
|
| 3831 | - $decoded_slug = urldecode( $slug ); |
|
| 3832 | - if ( $decoded_slug === $slug ) |
|
| 3833 | - $slug = substr( $slug, 0, $length ); |
|
| 3829 | +function _truncate_post_slug($slug, $length = 200) { |
|
| 3830 | + if (strlen($slug) > $length) { |
|
| 3831 | + $decoded_slug = urldecode($slug); |
|
| 3832 | + if ($decoded_slug === $slug) |
|
| 3833 | + $slug = substr($slug, 0, $length); |
|
| 3834 | 3834 | else |
| 3835 | - $slug = utf8_uri_encode( $decoded_slug, $length ); |
|
| 3835 | + $slug = utf8_uri_encode($decoded_slug, $length); |
|
| 3836 | 3836 | } |
| 3837 | 3837 | |
| 3838 | - return rtrim( $slug, '-' ); |
|
| 3838 | + return rtrim($slug, '-'); |
|
| 3839 | 3839 | } |
| 3840 | 3840 | |
| 3841 | 3841 | /** |
@@ -3850,7 +3850,7 @@ discard block |
||
| 3850 | 3850 | * separated by commas. Default empty. |
| 3851 | 3851 | * @return array|false|WP_Error Array of affected term IDs. WP_Error or false on failure. |
| 3852 | 3852 | */ |
| 3853 | -function wp_add_post_tags( $post_id = 0, $tags = '' ) { |
|
| 3853 | +function wp_add_post_tags($post_id = 0, $tags = '') { |
|
| 3854 | 3854 | return wp_set_post_tags($post_id, $tags, true); |
| 3855 | 3855 | } |
| 3856 | 3856 | |
@@ -3868,8 +3868,8 @@ discard block |
||
| 3868 | 3868 | * replace the tags with the new tags. Default false. |
| 3869 | 3869 | * @return array|false|WP_Error Array of term taxonomy IDs of affected terms. WP_Error or false on failure. |
| 3870 | 3870 | */ |
| 3871 | -function wp_set_post_tags( $post_id = 0, $tags = '', $append = false ) { |
|
| 3872 | - return wp_set_post_terms( $post_id, $tags, 'post_tag', $append); |
|
| 3871 | +function wp_set_post_tags($post_id = 0, $tags = '', $append = false) { |
|
| 3872 | + return wp_set_post_terms($post_id, $tags, 'post_tag', $append); |
|
| 3873 | 3873 | } |
| 3874 | 3874 | |
| 3875 | 3875 | /** |
@@ -3887,31 +3887,31 @@ discard block |
||
| 3887 | 3887 | * replace the terms with the new terms. Default false. |
| 3888 | 3888 | * @return array|false|WP_Error Array of term taxonomy IDs of affected terms. WP_Error or false on failure. |
| 3889 | 3889 | */ |
| 3890 | -function wp_set_post_terms( $post_id = 0, $tags = '', $taxonomy = 'post_tag', $append = false ) { |
|
| 3890 | +function wp_set_post_terms($post_id = 0, $tags = '', $taxonomy = 'post_tag', $append = false) { |
|
| 3891 | 3891 | $post_id = (int) $post_id; |
| 3892 | 3892 | |
| 3893 | - if ( !$post_id ) |
|
| 3893 | + if ( ! $post_id) |
|
| 3894 | 3894 | return false; |
| 3895 | 3895 | |
| 3896 | - if ( empty($tags) ) |
|
| 3896 | + if (empty($tags)) |
|
| 3897 | 3897 | $tags = array(); |
| 3898 | 3898 | |
| 3899 | - if ( ! is_array( $tags ) ) { |
|
| 3900 | - $comma = _x( ',', 'tag delimiter' ); |
|
| 3901 | - if ( ',' !== $comma ) |
|
| 3902 | - $tags = str_replace( $comma, ',', $tags ); |
|
| 3903 | - $tags = explode( ',', trim( $tags, " \n\t\r\0\x0B," ) ); |
|
| 3899 | + if ( ! is_array($tags)) { |
|
| 3900 | + $comma = _x(',', 'tag delimiter'); |
|
| 3901 | + if (',' !== $comma) |
|
| 3902 | + $tags = str_replace($comma, ',', $tags); |
|
| 3903 | + $tags = explode(',', trim($tags, " \n\t\r\0\x0B,")); |
|
| 3904 | 3904 | } |
| 3905 | 3905 | |
| 3906 | 3906 | /* |
| 3907 | 3907 | * Hierarchical taxonomies must always pass IDs rather than names so that |
| 3908 | 3908 | * children with the same names but different parents aren't confused. |
| 3909 | 3909 | */ |
| 3910 | - if ( is_taxonomy_hierarchical( $taxonomy ) ) { |
|
| 3911 | - $tags = array_unique( array_map( 'intval', $tags ) ); |
|
| 3910 | + if (is_taxonomy_hierarchical($taxonomy)) { |
|
| 3911 | + $tags = array_unique(array_map('intval', $tags)); |
|
| 3912 | 3912 | } |
| 3913 | 3913 | |
| 3914 | - return wp_set_object_terms( $post_id, $tags, $taxonomy, $append ); |
|
| 3914 | + return wp_set_object_terms($post_id, $tags, $taxonomy, $append); |
|
| 3915 | 3915 | } |
| 3916 | 3916 | |
| 3917 | 3917 | /** |
@@ -3930,24 +3930,24 @@ discard block |
||
| 3930 | 3930 | * If false, replace the categories with the new categories. |
| 3931 | 3931 | * @return array|false|WP_Error Array of term taxonomy IDs of affected categories. WP_Error or false on failure. |
| 3932 | 3932 | */ |
| 3933 | -function wp_set_post_categories( $post_ID = 0, $post_categories = array(), $append = false ) { |
|
| 3933 | +function wp_set_post_categories($post_ID = 0, $post_categories = array(), $append = false) { |
|
| 3934 | 3934 | $post_ID = (int) $post_ID; |
| 3935 | - $post_type = get_post_type( $post_ID ); |
|
| 3936 | - $post_status = get_post_status( $post_ID ); |
|
| 3935 | + $post_type = get_post_type($post_ID); |
|
| 3936 | + $post_status = get_post_status($post_ID); |
|
| 3937 | 3937 | // If $post_categories isn't already an array, make it one: |
| 3938 | 3938 | $post_categories = (array) $post_categories; |
| 3939 | - if ( empty( $post_categories ) ) { |
|
| 3940 | - if ( 'post' == $post_type && 'auto-draft' != $post_status ) { |
|
| 3941 | - $post_categories = array( get_option('default_category') ); |
|
| 3939 | + if (empty($post_categories)) { |
|
| 3940 | + if ('post' == $post_type && 'auto-draft' != $post_status) { |
|
| 3941 | + $post_categories = array(get_option('default_category')); |
|
| 3942 | 3942 | $append = false; |
| 3943 | 3943 | } else { |
| 3944 | 3944 | $post_categories = array(); |
| 3945 | 3945 | } |
| 3946 | - } elseif ( 1 == count( $post_categories ) && '' == reset( $post_categories ) ) { |
|
| 3946 | + } elseif (1 == count($post_categories) && '' == reset($post_categories)) { |
|
| 3947 | 3947 | return true; |
| 3948 | 3948 | } |
| 3949 | 3949 | |
| 3950 | - return wp_set_post_terms( $post_ID, $post_categories, 'category', $append ); |
|
| 3950 | + return wp_set_post_terms($post_ID, $post_categories, 'category', $append); |
|
| 3951 | 3951 | } |
| 3952 | 3952 | |
| 3953 | 3953 | /** |
@@ -3971,7 +3971,7 @@ discard block |
||
| 3971 | 3971 | * @param string $old_status Previous post status. |
| 3972 | 3972 | * @param WP_Post $post Post data. |
| 3973 | 3973 | */ |
| 3974 | -function wp_transition_post_status( $new_status, $old_status, $post ) { |
|
| 3974 | +function wp_transition_post_status($new_status, $old_status, $post) { |
|
| 3975 | 3975 | /** |
| 3976 | 3976 | * Fires when a post is transitioned from one status to another. |
| 3977 | 3977 | * |
@@ -3981,7 +3981,7 @@ discard block |
||
| 3981 | 3981 | * @param string $old_status Old post status. |
| 3982 | 3982 | * @param WP_Post $post Post object. |
| 3983 | 3983 | */ |
| 3984 | - do_action( 'transition_post_status', $new_status, $old_status, $post ); |
|
| 3984 | + do_action('transition_post_status', $new_status, $old_status, $post); |
|
| 3985 | 3985 | |
| 3986 | 3986 | /** |
| 3987 | 3987 | * Fires when a post is transitioned from one status to another. |
@@ -3993,7 +3993,7 @@ discard block |
||
| 3993 | 3993 | * |
| 3994 | 3994 | * @param WP_Post $post Post object. |
| 3995 | 3995 | */ |
| 3996 | - do_action( "{$old_status}_to_{$new_status}", $post ); |
|
| 3996 | + do_action("{$old_status}_to_{$new_status}", $post); |
|
| 3997 | 3997 | |
| 3998 | 3998 | /** |
| 3999 | 3999 | * Fires when a post is transitioned from one status to another. |
@@ -4014,7 +4014,7 @@ discard block |
||
| 4014 | 4014 | * @param int $post_id Post ID. |
| 4015 | 4015 | * @param WP_Post $post Post object. |
| 4016 | 4016 | */ |
| 4017 | - do_action( "{$new_status}_{$post->post_type}", $post->ID, $post ); |
|
| 4017 | + do_action("{$new_status}_{$post->post_type}", $post->ID, $post); |
|
| 4018 | 4018 | } |
| 4019 | 4019 | |
| 4020 | 4020 | // |
@@ -4032,9 +4032,9 @@ discard block |
||
| 4032 | 4032 | * @param string $uri Ping URI. |
| 4033 | 4033 | * @return int|false How many rows were updated. |
| 4034 | 4034 | */ |
| 4035 | -function add_ping( $post_id, $uri ) { |
|
| 4035 | +function add_ping($post_id, $uri) { |
|
| 4036 | 4036 | global $wpdb; |
| 4037 | - $pung = $wpdb->get_var( $wpdb->prepare( "SELECT pinged FROM $wpdb->posts WHERE ID = %d", $post_id )); |
|
| 4037 | + $pung = $wpdb->get_var($wpdb->prepare("SELECT pinged FROM $wpdb->posts WHERE ID = %d", $post_id)); |
|
| 4038 | 4038 | $pung = trim($pung); |
| 4039 | 4039 | $pung = preg_split('/\s/', $pung); |
| 4040 | 4040 | $pung[] = $uri; |
@@ -4047,11 +4047,11 @@ discard block |
||
| 4047 | 4047 | * |
| 4048 | 4048 | * @param string $new New ping URL to add. |
| 4049 | 4049 | */ |
| 4050 | - $new = apply_filters( 'add_ping', $new ); |
|
| 4050 | + $new = apply_filters('add_ping', $new); |
|
| 4051 | 4051 | |
| 4052 | 4052 | // expected_slashed ($new). |
| 4053 | 4053 | $new = wp_unslash($new); |
| 4054 | - return $wpdb->update( $wpdb->posts, array( 'pinged' => $new ), array( 'ID' => $post_id ) ); |
|
| 4054 | + return $wpdb->update($wpdb->posts, array('pinged' => $new), array('ID' => $post_id)); |
|
| 4055 | 4055 | } |
| 4056 | 4056 | |
| 4057 | 4057 | /** |
@@ -4062,18 +4062,18 @@ discard block |
||
| 4062 | 4062 | * @param int $post_id Post ID. |
| 4063 | 4063 | * @return array List of enclosures. |
| 4064 | 4064 | */ |
| 4065 | -function get_enclosed( $post_id ) { |
|
| 4066 | - $custom_fields = get_post_custom( $post_id ); |
|
| 4065 | +function get_enclosed($post_id) { |
|
| 4066 | + $custom_fields = get_post_custom($post_id); |
|
| 4067 | 4067 | $pung = array(); |
| 4068 | - if ( !is_array( $custom_fields ) ) |
|
| 4068 | + if ( ! is_array($custom_fields)) |
|
| 4069 | 4069 | return $pung; |
| 4070 | 4070 | |
| 4071 | - foreach ( $custom_fields as $key => $val ) { |
|
| 4072 | - if ( 'enclosure' != $key || !is_array( $val ) ) |
|
| 4071 | + foreach ($custom_fields as $key => $val) { |
|
| 4072 | + if ('enclosure' != $key || ! is_array($val)) |
|
| 4073 | 4073 | continue; |
| 4074 | - foreach ( $val as $enc ) { |
|
| 4075 | - $enclosure = explode( "\n", $enc ); |
|
| 4076 | - $pung[] = trim( $enclosure[ 0 ] ); |
|
| 4074 | + foreach ($val as $enc) { |
|
| 4075 | + $enclosure = explode("\n", $enc); |
|
| 4076 | + $pung[] = trim($enclosure[0]); |
|
| 4077 | 4077 | } |
| 4078 | 4078 | } |
| 4079 | 4079 | |
@@ -4085,7 +4085,7 @@ discard block |
||
| 4085 | 4085 | * @param array $pung Array of enclosures for the given post. |
| 4086 | 4086 | * @param int $post_id Post ID. |
| 4087 | 4087 | */ |
| 4088 | - return apply_filters( 'get_enclosed', $pung, $post_id ); |
|
| 4088 | + return apply_filters('get_enclosed', $pung, $post_id); |
|
| 4089 | 4089 | } |
| 4090 | 4090 | |
| 4091 | 4091 | /** |
@@ -4098,9 +4098,9 @@ discard block |
||
| 4098 | 4098 | * @param int $post_id Post ID. |
| 4099 | 4099 | * @return array |
| 4100 | 4100 | */ |
| 4101 | -function get_pung( $post_id ) { |
|
| 4101 | +function get_pung($post_id) { |
|
| 4102 | 4102 | global $wpdb; |
| 4103 | - $pung = $wpdb->get_var( $wpdb->prepare( "SELECT pinged FROM $wpdb->posts WHERE ID = %d", $post_id )); |
|
| 4103 | + $pung = $wpdb->get_var($wpdb->prepare("SELECT pinged FROM $wpdb->posts WHERE ID = %d", $post_id)); |
|
| 4104 | 4104 | $pung = trim($pung); |
| 4105 | 4105 | $pung = preg_split('/\s/', $pung); |
| 4106 | 4106 | |
@@ -4111,7 +4111,7 @@ discard block |
||
| 4111 | 4111 | * |
| 4112 | 4112 | * @param array $pung Array of URLs already pinged for the given post. |
| 4113 | 4113 | */ |
| 4114 | - return apply_filters( 'get_pung', $pung ); |
|
| 4114 | + return apply_filters('get_pung', $pung); |
|
| 4115 | 4115 | } |
| 4116 | 4116 | |
| 4117 | 4117 | /** |
@@ -4124,10 +4124,10 @@ discard block |
||
| 4124 | 4124 | * @param int $post_id Post ID |
| 4125 | 4125 | * @return array |
| 4126 | 4126 | */ |
| 4127 | -function get_to_ping( $post_id ) { |
|
| 4127 | +function get_to_ping($post_id) { |
|
| 4128 | 4128 | global $wpdb; |
| 4129 | - $to_ping = $wpdb->get_var( $wpdb->prepare( "SELECT to_ping FROM $wpdb->posts WHERE ID = %d", $post_id )); |
|
| 4130 | - $to_ping = sanitize_trackback_urls( $to_ping ); |
|
| 4129 | + $to_ping = $wpdb->get_var($wpdb->prepare("SELECT to_ping FROM $wpdb->posts WHERE ID = %d", $post_id)); |
|
| 4130 | + $to_ping = sanitize_trackback_urls($to_ping); |
|
| 4131 | 4131 | $to_ping = preg_split('/\s/', $to_ping, -1, PREG_SPLIT_NO_EMPTY); |
| 4132 | 4132 | |
| 4133 | 4133 | /** |
@@ -4137,7 +4137,7 @@ discard block |
||
| 4137 | 4137 | * |
| 4138 | 4138 | * @param array $to_ping List of URLs yet to ping. |
| 4139 | 4139 | */ |
| 4140 | - return apply_filters( 'get_to_ping', $to_ping ); |
|
| 4140 | + return apply_filters('get_to_ping', $to_ping); |
|
| 4141 | 4141 | } |
| 4142 | 4142 | |
| 4143 | 4143 | /** |
@@ -4148,22 +4148,22 @@ discard block |
||
| 4148 | 4148 | * @param string $tb_list Comma separated list of URLs. |
| 4149 | 4149 | * @param int $post_id Post ID. |
| 4150 | 4150 | */ |
| 4151 | -function trackback_url_list( $tb_list, $post_id ) { |
|
| 4152 | - if ( ! empty( $tb_list ) ) { |
|
| 4151 | +function trackback_url_list($tb_list, $post_id) { |
|
| 4152 | + if ( ! empty($tb_list)) { |
|
| 4153 | 4153 | // Get post data. |
| 4154 | - $postdata = get_post( $post_id, ARRAY_A ); |
|
| 4154 | + $postdata = get_post($post_id, ARRAY_A); |
|
| 4155 | 4155 | |
| 4156 | 4156 | // Form an excerpt. |
| 4157 | - $excerpt = strip_tags( $postdata['post_excerpt'] ? $postdata['post_excerpt'] : $postdata['post_content'] ); |
|
| 4157 | + $excerpt = strip_tags($postdata['post_excerpt'] ? $postdata['post_excerpt'] : $postdata['post_content']); |
|
| 4158 | 4158 | |
| 4159 | - if ( strlen( $excerpt ) > 255 ) { |
|
| 4160 | - $excerpt = substr( $excerpt, 0, 252 ) . '…'; |
|
| 4159 | + if (strlen($excerpt) > 255) { |
|
| 4160 | + $excerpt = substr($excerpt, 0, 252).'…'; |
|
| 4161 | 4161 | } |
| 4162 | 4162 | |
| 4163 | - $trackback_urls = explode( ',', $tb_list ); |
|
| 4164 | - foreach ( (array) $trackback_urls as $tb_url ) { |
|
| 4165 | - $tb_url = trim( $tb_url ); |
|
| 4166 | - trackback( $tb_url, wp_unslash( $postdata['post_title'] ), $excerpt, $post_id ); |
|
| 4163 | + $trackback_urls = explode(',', $tb_list); |
|
| 4164 | + foreach ((array) $trackback_urls as $tb_url) { |
|
| 4165 | + $tb_url = trim($tb_url); |
|
| 4166 | + trackback($tb_url, wp_unslash($postdata['post_title']), $excerpt, $post_id); |
|
| 4167 | 4167 | } |
| 4168 | 4168 | } |
| 4169 | 4169 | } |
@@ -4185,7 +4185,7 @@ discard block |
||
| 4185 | 4185 | global $wpdb; |
| 4186 | 4186 | |
| 4187 | 4187 | $page_ids = wp_cache_get('all_page_ids', 'posts'); |
| 4188 | - if ( ! is_array( $page_ids ) ) { |
|
| 4188 | + if ( ! is_array($page_ids)) { |
|
| 4189 | 4189 | $page_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type = 'page'"); |
| 4190 | 4190 | wp_cache_add('all_page_ids', $page_ids, 'posts'); |
| 4191 | 4191 | } |
@@ -4208,8 +4208,8 @@ discard block |
||
| 4208 | 4208 | * 'edit', 'db', 'display'. Default 'raw'. |
| 4209 | 4209 | * @return WP_Post|array|null WP_Post on success or null on failure. |
| 4210 | 4210 | */ |
| 4211 | -function get_page( $page, $output = OBJECT, $filter = 'raw') { |
|
| 4212 | - return get_post( $page, $output, $filter ); |
|
| 4211 | +function get_page($page, $output = OBJECT, $filter = 'raw') { |
|
| 4212 | + return get_post($page, $output, $filter); |
|
| 4213 | 4213 | } |
| 4214 | 4214 | |
| 4215 | 4215 | /** |
@@ -4225,26 +4225,26 @@ discard block |
||
| 4225 | 4225 | * @param string|array $post_type Optional. Post type or array of post types. Default 'page'. |
| 4226 | 4226 | * @return WP_Post|array|void WP_Post on success. |
| 4227 | 4227 | */ |
| 4228 | -function get_page_by_path( $page_path, $output = OBJECT, $post_type = 'page' ) { |
|
| 4228 | +function get_page_by_path($page_path, $output = OBJECT, $post_type = 'page') { |
|
| 4229 | 4229 | global $wpdb; |
| 4230 | 4230 | |
| 4231 | 4231 | $page_path = rawurlencode(urldecode($page_path)); |
| 4232 | 4232 | $page_path = str_replace('%2F', '/', $page_path); |
| 4233 | 4233 | $page_path = str_replace('%20', ' ', $page_path); |
| 4234 | - $parts = explode( '/', trim( $page_path, '/' ) ); |
|
| 4235 | - $parts = esc_sql( $parts ); |
|
| 4236 | - $parts = array_map( 'sanitize_title_for_query', $parts ); |
|
| 4234 | + $parts = explode('/', trim($page_path, '/')); |
|
| 4235 | + $parts = esc_sql($parts); |
|
| 4236 | + $parts = array_map('sanitize_title_for_query', $parts); |
|
| 4237 | 4237 | |
| 4238 | - $in_string = "'" . implode( "','", $parts ) . "'"; |
|
| 4238 | + $in_string = "'".implode("','", $parts)."'"; |
|
| 4239 | 4239 | |
| 4240 | - if ( is_array( $post_type ) ) { |
|
| 4240 | + if (is_array($post_type)) { |
|
| 4241 | 4241 | $post_types = $post_type; |
| 4242 | 4242 | } else { |
| 4243 | - $post_types = array( $post_type, 'attachment' ); |
|
| 4243 | + $post_types = array($post_type, 'attachment'); |
|
| 4244 | 4244 | } |
| 4245 | 4245 | |
| 4246 | - $post_types = esc_sql( $post_types ); |
|
| 4247 | - $post_type_in_string = "'" . implode( "','", $post_types ) . "'"; |
|
| 4246 | + $post_types = esc_sql($post_types); |
|
| 4247 | + $post_type_in_string = "'".implode("','", $post_types)."'"; |
|
| 4248 | 4248 | $sql = " |
| 4249 | 4249 | SELECT ID, post_name, post_parent, post_type |
| 4250 | 4250 | FROM $wpdb->posts |
@@ -4252,13 +4252,13 @@ discard block |
||
| 4252 | 4252 | AND post_type IN ($post_type_in_string) |
| 4253 | 4253 | "; |
| 4254 | 4254 | |
| 4255 | - $pages = $wpdb->get_results( $sql, OBJECT_K ); |
|
| 4255 | + $pages = $wpdb->get_results($sql, OBJECT_K); |
|
| 4256 | 4256 | |
| 4257 | - $revparts = array_reverse( $parts ); |
|
| 4257 | + $revparts = array_reverse($parts); |
|
| 4258 | 4258 | |
| 4259 | 4259 | $foundid = 0; |
| 4260 | - foreach ( (array) $pages as $page ) { |
|
| 4261 | - if ( $page->post_name == $revparts[0] ) { |
|
| 4260 | + foreach ((array) $pages as $page) { |
|
| 4261 | + if ($page->post_name == $revparts[0]) { |
|
| 4262 | 4262 | $count = 0; |
| 4263 | 4263 | $p = $page; |
| 4264 | 4264 | |
@@ -4266,24 +4266,24 @@ discard block |
||
| 4266 | 4266 | * Loop through the given path parts from right to left, |
| 4267 | 4267 | * ensuring each matches the post ancestry. |
| 4268 | 4268 | */ |
| 4269 | - while ( $p->post_parent != 0 && isset( $pages[ $p->post_parent ] ) ) { |
|
| 4269 | + while ($p->post_parent != 0 && isset($pages[$p->post_parent])) { |
|
| 4270 | 4270 | $count++; |
| 4271 | - $parent = $pages[ $p->post_parent ]; |
|
| 4272 | - if ( ! isset( $revparts[ $count ] ) || $parent->post_name != $revparts[ $count ] ) |
|
| 4271 | + $parent = $pages[$p->post_parent]; |
|
| 4272 | + if ( ! isset($revparts[$count]) || $parent->post_name != $revparts[$count]) |
|
| 4273 | 4273 | break; |
| 4274 | 4274 | $p = $parent; |
| 4275 | 4275 | } |
| 4276 | 4276 | |
| 4277 | - if ( $p->post_parent == 0 && $count+1 == count( $revparts ) && $p->post_name == $revparts[ $count ] ) { |
|
| 4277 | + if ($p->post_parent == 0 && $count + 1 == count($revparts) && $p->post_name == $revparts[$count]) { |
|
| 4278 | 4278 | $foundid = $page->ID; |
| 4279 | - if ( $page->post_type == $post_type ) |
|
| 4279 | + if ($page->post_type == $post_type) |
|
| 4280 | 4280 | break; |
| 4281 | 4281 | } |
| 4282 | 4282 | } |
| 4283 | 4283 | } |
| 4284 | 4284 | |
| 4285 | - if ( $foundid ) { |
|
| 4286 | - return get_post( $foundid, $output ); |
|
| 4285 | + if ($foundid) { |
|
| 4286 | + return get_post($foundid, $output); |
|
| 4287 | 4287 | } |
| 4288 | 4288 | } |
| 4289 | 4289 | |
@@ -4300,31 +4300,31 @@ discard block |
||
| 4300 | 4300 | * @param string|array $post_type Optional. Post type or array of post types. Default 'page'. |
| 4301 | 4301 | * @return WP_Post|array|void WP_Post on success or null on failure |
| 4302 | 4302 | */ |
| 4303 | -function get_page_by_title( $page_title, $output = OBJECT, $post_type = 'page' ) { |
|
| 4303 | +function get_page_by_title($page_title, $output = OBJECT, $post_type = 'page') { |
|
| 4304 | 4304 | global $wpdb; |
| 4305 | 4305 | |
| 4306 | - if ( is_array( $post_type ) ) { |
|
| 4307 | - $post_type = esc_sql( $post_type ); |
|
| 4308 | - $post_type_in_string = "'" . implode( "','", $post_type ) . "'"; |
|
| 4309 | - $sql = $wpdb->prepare( " |
|
| 4306 | + if (is_array($post_type)) { |
|
| 4307 | + $post_type = esc_sql($post_type); |
|
| 4308 | + $post_type_in_string = "'".implode("','", $post_type)."'"; |
|
| 4309 | + $sql = $wpdb->prepare(" |
|
| 4310 | 4310 | SELECT ID |
| 4311 | 4311 | FROM $wpdb->posts |
| 4312 | 4312 | WHERE post_title = %s |
| 4313 | 4313 | AND post_type IN ($post_type_in_string) |
| 4314 | - ", $page_title ); |
|
| 4314 | + ", $page_title); |
|
| 4315 | 4315 | } else { |
| 4316 | - $sql = $wpdb->prepare( " |
|
| 4316 | + $sql = $wpdb->prepare(" |
|
| 4317 | 4317 | SELECT ID |
| 4318 | 4318 | FROM $wpdb->posts |
| 4319 | 4319 | WHERE post_title = %s |
| 4320 | 4320 | AND post_type = %s |
| 4321 | - ", $page_title, $post_type ); |
|
| 4321 | + ", $page_title, $post_type); |
|
| 4322 | 4322 | } |
| 4323 | 4323 | |
| 4324 | - $page = $wpdb->get_var( $sql ); |
|
| 4324 | + $page = $wpdb->get_var($sql); |
|
| 4325 | 4325 | |
| 4326 | - if ( $page ) { |
|
| 4327 | - return get_post( $page, $output ); |
|
| 4326 | + if ($page) { |
|
| 4327 | + return get_post($page, $output); |
|
| 4328 | 4328 | } |
| 4329 | 4329 | } |
| 4330 | 4330 | |
@@ -4339,25 +4339,25 @@ discard block |
||
| 4339 | 4339 | * @param array $pages List of page objects from which descendants should be identified. |
| 4340 | 4340 | * @return array List of page children. |
| 4341 | 4341 | */ |
| 4342 | -function get_page_children( $page_id, $pages ) { |
|
| 4342 | +function get_page_children($page_id, $pages) { |
|
| 4343 | 4343 | // Build a hash of ID -> children. |
| 4344 | 4344 | $children = array(); |
| 4345 | - foreach ( (array) $pages as $page ) { |
|
| 4346 | - $children[ intval( $page->post_parent ) ][] = $page; |
|
| 4345 | + foreach ((array) $pages as $page) { |
|
| 4346 | + $children[intval($page->post_parent)][] = $page; |
|
| 4347 | 4347 | } |
| 4348 | 4348 | |
| 4349 | 4349 | $page_list = array(); |
| 4350 | 4350 | |
| 4351 | 4351 | // Start the search by looking at immediate children. |
| 4352 | - if ( isset( $children[ $page_id ] ) ) { |
|
| 4352 | + if (isset($children[$page_id])) { |
|
| 4353 | 4353 | // Always start at the end of the stack in order to preserve original `$pages` order. |
| 4354 | - $to_look = array_reverse( $children[ $page_id ] ); |
|
| 4354 | + $to_look = array_reverse($children[$page_id]); |
|
| 4355 | 4355 | |
| 4356 | - while ( $to_look ) { |
|
| 4357 | - $p = array_pop( $to_look ); |
|
| 4356 | + while ($to_look) { |
|
| 4357 | + $p = array_pop($to_look); |
|
| 4358 | 4358 | $page_list[] = $p; |
| 4359 | - if ( isset( $children[ $p->ID ] ) ) { |
|
| 4360 | - foreach ( array_reverse( $children[ $p->ID ] ) as $child ) { |
|
| 4359 | + if (isset($children[$p->ID])) { |
|
| 4360 | + foreach (array_reverse($children[$p->ID]) as $child) { |
|
| 4361 | 4361 | // Append to the `$to_look` stack to descend the tree. |
| 4362 | 4362 | $to_look[] = $child; |
| 4363 | 4363 | } |
@@ -4380,19 +4380,19 @@ discard block |
||
| 4380 | 4380 | * @param int $page_id Optional. Parent page ID. Default 0. |
| 4381 | 4381 | * @return array A list arranged by hierarchy. Children immediately follow their parents. |
| 4382 | 4382 | */ |
| 4383 | -function get_page_hierarchy( &$pages, $page_id = 0 ) { |
|
| 4384 | - if ( empty( $pages ) ) { |
|
| 4383 | +function get_page_hierarchy(&$pages, $page_id = 0) { |
|
| 4384 | + if (empty($pages)) { |
|
| 4385 | 4385 | return array(); |
| 4386 | 4386 | } |
| 4387 | 4387 | |
| 4388 | 4388 | $children = array(); |
| 4389 | - foreach ( (array) $pages as $p ) { |
|
| 4390 | - $parent_id = intval( $p->post_parent ); |
|
| 4391 | - $children[ $parent_id ][] = $p; |
|
| 4389 | + foreach ((array) $pages as $p) { |
|
| 4390 | + $parent_id = intval($p->post_parent); |
|
| 4391 | + $children[$parent_id][] = $p; |
|
| 4392 | 4392 | } |
| 4393 | 4393 | |
| 4394 | 4394 | $result = array(); |
| 4395 | - _page_traverse_name( $page_id, $children, $result ); |
|
| 4395 | + _page_traverse_name($page_id, $children, $result); |
|
| 4396 | 4396 | |
| 4397 | 4397 | return $result; |
| 4398 | 4398 | } |
@@ -4410,11 +4410,11 @@ discard block |
||
| 4410 | 4410 | * @param array $children Parent-children relations, passed by reference. |
| 4411 | 4411 | * @param array $result Result, passed by reference. |
| 4412 | 4412 | */ |
| 4413 | -function _page_traverse_name( $page_id, &$children, &$result ){ |
|
| 4414 | - if ( isset( $children[ $page_id ] ) ){ |
|
| 4415 | - foreach ( (array)$children[ $page_id ] as $child ) { |
|
| 4416 | - $result[ $child->ID ] = $child->post_name; |
|
| 4417 | - _page_traverse_name( $child->ID, $children, $result ); |
|
| 4413 | +function _page_traverse_name($page_id, &$children, &$result) { |
|
| 4414 | + if (isset($children[$page_id])) { |
|
| 4415 | + foreach ((array) $children[$page_id] as $child) { |
|
| 4416 | + $result[$child->ID] = $child->post_name; |
|
| 4417 | + _page_traverse_name($child->ID, $children, $result); |
|
| 4418 | 4418 | } |
| 4419 | 4419 | } |
| 4420 | 4420 | } |
@@ -4429,20 +4429,20 @@ discard block |
||
| 4429 | 4429 | * @param WP_Post|object|int $page Page object or page ID. |
| 4430 | 4430 | * @return string|false Page URI, false on error. |
| 4431 | 4431 | */ |
| 4432 | -function get_page_uri( $page ) { |
|
| 4433 | - if ( ! $page instanceof WP_Post ) { |
|
| 4434 | - $page = get_post( $page ); |
|
| 4432 | +function get_page_uri($page) { |
|
| 4433 | + if ( ! $page instanceof WP_Post) { |
|
| 4434 | + $page = get_post($page); |
|
| 4435 | 4435 | } |
| 4436 | 4436 | |
| 4437 | - if ( ! $page ) |
|
| 4437 | + if ( ! $page) |
|
| 4438 | 4438 | return false; |
| 4439 | 4439 | |
| 4440 | 4440 | $uri = $page->post_name; |
| 4441 | 4441 | |
| 4442 | - foreach ( $page->ancestors as $parent ) { |
|
| 4443 | - $parent = get_post( $parent ); |
|
| 4444 | - if ( $parent ) { |
|
| 4445 | - $uri = $parent->post_name . '/' . $uri; |
|
| 4442 | + foreach ($page->ancestors as $parent) { |
|
| 4443 | + $parent = get_post($parent); |
|
| 4444 | + if ($parent) { |
|
| 4445 | + $uri = $parent->post_name.'/'.$uri; |
|
| 4446 | 4446 | } |
| 4447 | 4447 | } |
| 4448 | 4448 | |
@@ -4454,7 +4454,7 @@ discard block |
||
| 4454 | 4454 | * @param string $uri Page URI. |
| 4455 | 4455 | * @param WP_Post $page Page object. |
| 4456 | 4456 | */ |
| 4457 | - return apply_filters( 'get_page_uri', $uri, $page ); |
|
| 4457 | + return apply_filters('get_page_uri', $uri, $page); |
|
| 4458 | 4458 | } |
| 4459 | 4459 | |
| 4460 | 4460 | /** |
@@ -4499,7 +4499,7 @@ discard block |
||
| 4499 | 4499 | * } |
| 4500 | 4500 | * @return array|false List of pages matching defaults or `$args`. |
| 4501 | 4501 | */ |
| 4502 | -function get_pages( $args = array() ) { |
|
| 4502 | +function get_pages($args = array()) { |
|
| 4503 | 4503 | global $wpdb; |
| 4504 | 4504 | |
| 4505 | 4505 | $defaults = array( |
@@ -4512,7 +4512,7 @@ discard block |
||
| 4512 | 4512 | 'post_type' => 'page', 'post_status' => 'publish', |
| 4513 | 4513 | ); |
| 4514 | 4514 | |
| 4515 | - $r = wp_parse_args( $args, $defaults ); |
|
| 4515 | + $r = wp_parse_args($args, $defaults); |
|
| 4516 | 4516 | |
| 4517 | 4517 | $number = (int) $r['number']; |
| 4518 | 4518 | $offset = (int) $r['offset']; |
@@ -4525,87 +4525,87 @@ discard block |
||
| 4525 | 4525 | $post_status = $r['post_status']; |
| 4526 | 4526 | |
| 4527 | 4527 | // Make sure the post type is hierarchical. |
| 4528 | - $hierarchical_post_types = get_post_types( array( 'hierarchical' => true ) ); |
|
| 4529 | - if ( ! in_array( $r['post_type'], $hierarchical_post_types ) ) { |
|
| 4528 | + $hierarchical_post_types = get_post_types(array('hierarchical' => true)); |
|
| 4529 | + if ( ! in_array($r['post_type'], $hierarchical_post_types)) { |
|
| 4530 | 4530 | return false; |
| 4531 | 4531 | } |
| 4532 | 4532 | |
| 4533 | - if ( $parent > 0 && ! $child_of ) { |
|
| 4533 | + if ($parent > 0 && ! $child_of) { |
|
| 4534 | 4534 | $hierarchical = false; |
| 4535 | 4535 | } |
| 4536 | 4536 | |
| 4537 | 4537 | // Make sure we have a valid post status. |
| 4538 | - if ( ! is_array( $post_status ) ) { |
|
| 4539 | - $post_status = explode( ',', $post_status ); |
|
| 4538 | + if ( ! is_array($post_status)) { |
|
| 4539 | + $post_status = explode(',', $post_status); |
|
| 4540 | 4540 | } |
| 4541 | - if ( array_diff( $post_status, get_post_stati() ) ) { |
|
| 4541 | + if (array_diff($post_status, get_post_stati())) { |
|
| 4542 | 4542 | return false; |
| 4543 | 4543 | } |
| 4544 | 4544 | |
| 4545 | 4545 | // $args can be whatever, only use the args defined in defaults to compute the key. |
| 4546 | - $key = md5( serialize( wp_array_slice_assoc( $r, array_keys( $defaults ) ) ) ); |
|
| 4547 | - $last_changed = wp_cache_get( 'last_changed', 'posts' ); |
|
| 4548 | - if ( ! $last_changed ) { |
|
| 4546 | + $key = md5(serialize(wp_array_slice_assoc($r, array_keys($defaults)))); |
|
| 4547 | + $last_changed = wp_cache_get('last_changed', 'posts'); |
|
| 4548 | + if ( ! $last_changed) { |
|
| 4549 | 4549 | $last_changed = microtime(); |
| 4550 | - wp_cache_set( 'last_changed', $last_changed, 'posts' ); |
|
| 4550 | + wp_cache_set('last_changed', $last_changed, 'posts'); |
|
| 4551 | 4551 | } |
| 4552 | 4552 | |
| 4553 | 4553 | $cache_key = "get_pages:$key:$last_changed"; |
| 4554 | - if ( $cache = wp_cache_get( $cache_key, 'posts' ) ) { |
|
| 4554 | + if ($cache = wp_cache_get($cache_key, 'posts')) { |
|
| 4555 | 4555 | // Convert to WP_Post instances. |
| 4556 | - $pages = array_map( 'get_post', $cache ); |
|
| 4556 | + $pages = array_map('get_post', $cache); |
|
| 4557 | 4557 | /** This filter is documented in wp-includes/post.php */ |
| 4558 | - $pages = apply_filters( 'get_pages', $pages, $r ); |
|
| 4558 | + $pages = apply_filters('get_pages', $pages, $r); |
|
| 4559 | 4559 | return $pages; |
| 4560 | 4560 | } |
| 4561 | 4561 | |
| 4562 | 4562 | $inclusions = ''; |
| 4563 | - if ( ! empty( $r['include'] ) ) { |
|
| 4563 | + if ( ! empty($r['include'])) { |
|
| 4564 | 4564 | $child_of = 0; //ignore child_of, parent, exclude, meta_key, and meta_value params if using include |
| 4565 | 4565 | $parent = -1; |
| 4566 | 4566 | $exclude = ''; |
| 4567 | 4567 | $meta_key = ''; |
| 4568 | 4568 | $meta_value = ''; |
| 4569 | 4569 | $hierarchical = false; |
| 4570 | - $incpages = wp_parse_id_list( $r['include'] ); |
|
| 4571 | - if ( ! empty( $incpages ) ) { |
|
| 4572 | - $inclusions = ' AND ID IN (' . implode( ',', $incpages ) . ')'; |
|
| 4570 | + $incpages = wp_parse_id_list($r['include']); |
|
| 4571 | + if ( ! empty($incpages)) { |
|
| 4572 | + $inclusions = ' AND ID IN ('.implode(',', $incpages).')'; |
|
| 4573 | 4573 | } |
| 4574 | 4574 | } |
| 4575 | 4575 | |
| 4576 | 4576 | $exclusions = ''; |
| 4577 | - if ( ! empty( $exclude ) ) { |
|
| 4578 | - $expages = wp_parse_id_list( $exclude ); |
|
| 4579 | - if ( ! empty( $expages ) ) { |
|
| 4580 | - $exclusions = ' AND ID NOT IN (' . implode( ',', $expages ) . ')'; |
|
| 4577 | + if ( ! empty($exclude)) { |
|
| 4578 | + $expages = wp_parse_id_list($exclude); |
|
| 4579 | + if ( ! empty($expages)) { |
|
| 4580 | + $exclusions = ' AND ID NOT IN ('.implode(',', $expages).')'; |
|
| 4581 | 4581 | } |
| 4582 | 4582 | } |
| 4583 | 4583 | |
| 4584 | 4584 | $author_query = ''; |
| 4585 | - if ( ! empty( $r['authors'] ) ) { |
|
| 4586 | - $post_authors = preg_split( '/[\s,]+/', $r['authors'] ); |
|
| 4585 | + if ( ! empty($r['authors'])) { |
|
| 4586 | + $post_authors = preg_split('/[\s,]+/', $r['authors']); |
|
| 4587 | 4587 | |
| 4588 | - if ( ! empty( $post_authors ) ) { |
|
| 4589 | - foreach ( $post_authors as $post_author ) { |
|
| 4588 | + if ( ! empty($post_authors)) { |
|
| 4589 | + foreach ($post_authors as $post_author) { |
|
| 4590 | 4590 | //Do we have an author id or an author login? |
| 4591 | - if ( 0 == intval($post_author) ) { |
|
| 4591 | + if (0 == intval($post_author)) { |
|
| 4592 | 4592 | $post_author = get_user_by('login', $post_author); |
| 4593 | - if ( empty( $post_author ) ) { |
|
| 4593 | + if (empty($post_author)) { |
|
| 4594 | 4594 | continue; |
| 4595 | 4595 | } |
| 4596 | - if ( empty( $post_author->ID ) ) { |
|
| 4596 | + if (empty($post_author->ID)) { |
|
| 4597 | 4597 | continue; |
| 4598 | 4598 | } |
| 4599 | 4599 | $post_author = $post_author->ID; |
| 4600 | 4600 | } |
| 4601 | 4601 | |
| 4602 | - if ( '' == $author_query ) { |
|
| 4602 | + if ('' == $author_query) { |
|
| 4603 | 4603 | $author_query = $wpdb->prepare(' post_author = %d ', $post_author); |
| 4604 | 4604 | } else { |
| 4605 | 4605 | $author_query .= $wpdb->prepare(' OR post_author = %d ', $post_author); |
| 4606 | 4606 | } |
| 4607 | 4607 | } |
| 4608 | - if ( '' != $author_query ) { |
|
| 4608 | + if ('' != $author_query) { |
|
| 4609 | 4609 | $author_query = " AND ($author_query)"; |
| 4610 | 4610 | } |
| 4611 | 4611 | } |
@@ -4613,49 +4613,49 @@ discard block |
||
| 4613 | 4613 | |
| 4614 | 4614 | $join = ''; |
| 4615 | 4615 | $where = "$exclusions $inclusions "; |
| 4616 | - if ( '' !== $meta_key || '' !== $meta_value ) { |
|
| 4616 | + if ('' !== $meta_key || '' !== $meta_value) { |
|
| 4617 | 4617 | $join = " LEFT JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id )"; |
| 4618 | 4618 | |
| 4619 | 4619 | // meta_key and meta_value might be slashed |
| 4620 | 4620 | $meta_key = wp_unslash($meta_key); |
| 4621 | 4621 | $meta_value = wp_unslash($meta_value); |
| 4622 | - if ( '' !== $meta_key ) { |
|
| 4622 | + if ('' !== $meta_key) { |
|
| 4623 | 4623 | $where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_key = %s", $meta_key); |
| 4624 | 4624 | } |
| 4625 | - if ( '' !== $meta_value ) { |
|
| 4625 | + if ('' !== $meta_value) { |
|
| 4626 | 4626 | $where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_value = %s", $meta_value); |
| 4627 | 4627 | } |
| 4628 | 4628 | |
| 4629 | 4629 | } |
| 4630 | 4630 | |
| 4631 | - if ( is_array( $parent ) ) { |
|
| 4632 | - $post_parent__in = implode( ',', array_map( 'absint', (array) $parent ) ); |
|
| 4633 | - if ( ! empty( $post_parent__in ) ) { |
|
| 4631 | + if (is_array($parent)) { |
|
| 4632 | + $post_parent__in = implode(',', array_map('absint', (array) $parent)); |
|
| 4633 | + if ( ! empty($post_parent__in)) { |
|
| 4634 | 4634 | $where .= " AND post_parent IN ($post_parent__in)"; |
| 4635 | 4635 | } |
| 4636 | - } elseif ( $parent >= 0 ) { |
|
| 4636 | + } elseif ($parent >= 0) { |
|
| 4637 | 4637 | $where .= $wpdb->prepare(' AND post_parent = %d ', $parent); |
| 4638 | 4638 | } |
| 4639 | 4639 | |
| 4640 | - if ( 1 == count( $post_status ) ) { |
|
| 4641 | - $where_post_type = $wpdb->prepare( "post_type = %s AND post_status = %s", $r['post_type'], reset( $post_status ) ); |
|
| 4640 | + if (1 == count($post_status)) { |
|
| 4641 | + $where_post_type = $wpdb->prepare("post_type = %s AND post_status = %s", $r['post_type'], reset($post_status)); |
|
| 4642 | 4642 | } else { |
| 4643 | - $post_status = implode( "', '", $post_status ); |
|
| 4644 | - $where_post_type = $wpdb->prepare( "post_type = %s AND post_status IN ('$post_status')", $r['post_type'] ); |
|
| 4643 | + $post_status = implode("', '", $post_status); |
|
| 4644 | + $where_post_type = $wpdb->prepare("post_type = %s AND post_status IN ('$post_status')", $r['post_type']); |
|
| 4645 | 4645 | } |
| 4646 | 4646 | |
| 4647 | 4647 | $orderby_array = array(); |
| 4648 | - $allowed_keys = array( 'author', 'post_author', 'date', 'post_date', 'title', 'post_title', 'name', 'post_name', 'modified', |
|
| 4648 | + $allowed_keys = array('author', 'post_author', 'date', 'post_date', 'title', 'post_title', 'name', 'post_name', 'modified', |
|
| 4649 | 4649 | 'post_modified', 'modified_gmt', 'post_modified_gmt', 'menu_order', 'parent', 'post_parent', |
| 4650 | - 'ID', 'rand', 'comment_count' ); |
|
| 4650 | + 'ID', 'rand', 'comment_count'); |
|
| 4651 | 4651 | |
| 4652 | - foreach ( explode( ',', $r['sort_column'] ) as $orderby ) { |
|
| 4653 | - $orderby = trim( $orderby ); |
|
| 4654 | - if ( ! in_array( $orderby, $allowed_keys ) ) { |
|
| 4652 | + foreach (explode(',', $r['sort_column']) as $orderby) { |
|
| 4653 | + $orderby = trim($orderby); |
|
| 4654 | + if ( ! in_array($orderby, $allowed_keys)) { |
|
| 4655 | 4655 | continue; |
| 4656 | 4656 | } |
| 4657 | 4657 | |
| 4658 | - switch ( $orderby ) { |
|
| 4658 | + switch ($orderby) { |
|
| 4659 | 4659 | case 'menu_order': |
| 4660 | 4660 | break; |
| 4661 | 4661 | case 'ID': |
@@ -4668,36 +4668,36 @@ discard block |
||
| 4668 | 4668 | $orderby = "$wpdb->posts.comment_count"; |
| 4669 | 4669 | break; |
| 4670 | 4670 | default: |
| 4671 | - if ( 0 === strpos( $orderby, 'post_' ) ) { |
|
| 4672 | - $orderby = "$wpdb->posts." . $orderby; |
|
| 4671 | + if (0 === strpos($orderby, 'post_')) { |
|
| 4672 | + $orderby = "$wpdb->posts.".$orderby; |
|
| 4673 | 4673 | } else { |
| 4674 | - $orderby = "$wpdb->posts.post_" . $orderby; |
|
| 4674 | + $orderby = "$wpdb->posts.post_".$orderby; |
|
| 4675 | 4675 | } |
| 4676 | 4676 | } |
| 4677 | 4677 | |
| 4678 | 4678 | $orderby_array[] = $orderby; |
| 4679 | 4679 | |
| 4680 | 4680 | } |
| 4681 | - $sort_column = ! empty( $orderby_array ) ? implode( ',', $orderby_array ) : "$wpdb->posts.post_title"; |
|
| 4681 | + $sort_column = ! empty($orderby_array) ? implode(',', $orderby_array) : "$wpdb->posts.post_title"; |
|
| 4682 | 4682 | |
| 4683 | - $sort_order = strtoupper( $r['sort_order'] ); |
|
| 4684 | - if ( '' !== $sort_order && ! in_array( $sort_order, array( 'ASC', 'DESC' ) ) ) { |
|
| 4683 | + $sort_order = strtoupper($r['sort_order']); |
|
| 4684 | + if ('' !== $sort_order && ! in_array($sort_order, array('ASC', 'DESC'))) { |
|
| 4685 | 4685 | $sort_order = 'ASC'; |
| 4686 | 4686 | } |
| 4687 | 4687 | |
| 4688 | 4688 | $query = "SELECT * FROM $wpdb->posts $join WHERE ($where_post_type) $where "; |
| 4689 | 4689 | $query .= $author_query; |
| 4690 | - $query .= " ORDER BY " . $sort_column . " " . $sort_order ; |
|
| 4690 | + $query .= " ORDER BY ".$sort_column." ".$sort_order; |
|
| 4691 | 4691 | |
| 4692 | - if ( ! empty( $number ) ) { |
|
| 4693 | - $query .= ' LIMIT ' . $offset . ',' . $number; |
|
| 4692 | + if ( ! empty($number)) { |
|
| 4693 | + $query .= ' LIMIT '.$offset.','.$number; |
|
| 4694 | 4694 | } |
| 4695 | 4695 | |
| 4696 | 4696 | $pages = $wpdb->get_results($query); |
| 4697 | 4697 | |
| 4698 | - if ( empty($pages) ) { |
|
| 4698 | + if (empty($pages)) { |
|
| 4699 | 4699 | /** This filter is documented in wp-includes/post.php */ |
| 4700 | - $pages = apply_filters( 'get_pages', array(), $r ); |
|
| 4700 | + $pages = apply_filters('get_pages', array(), $r); |
|
| 4701 | 4701 | return $pages; |
| 4702 | 4702 | } |
| 4703 | 4703 | |
@@ -4708,38 +4708,38 @@ discard block |
||
| 4708 | 4708 | } |
| 4709 | 4709 | |
| 4710 | 4710 | // Update cache. |
| 4711 | - update_post_cache( $pages ); |
|
| 4711 | + update_post_cache($pages); |
|
| 4712 | 4712 | |
| 4713 | - if ( $child_of || $hierarchical ) { |
|
| 4713 | + if ($child_of || $hierarchical) { |
|
| 4714 | 4714 | $pages = get_page_children($child_of, $pages); |
| 4715 | 4715 | } |
| 4716 | 4716 | |
| 4717 | - if ( ! empty( $r['exclude_tree'] ) ) { |
|
| 4718 | - $exclude = wp_parse_id_list( $r['exclude_tree'] ); |
|
| 4719 | - foreach ( $exclude as $id ) { |
|
| 4720 | - $children = get_page_children( $id, $pages ); |
|
| 4721 | - foreach ( $children as $child ) { |
|
| 4717 | + if ( ! empty($r['exclude_tree'])) { |
|
| 4718 | + $exclude = wp_parse_id_list($r['exclude_tree']); |
|
| 4719 | + foreach ($exclude as $id) { |
|
| 4720 | + $children = get_page_children($id, $pages); |
|
| 4721 | + foreach ($children as $child) { |
|
| 4722 | 4722 | $exclude[] = $child->ID; |
| 4723 | 4723 | } |
| 4724 | 4724 | } |
| 4725 | 4725 | |
| 4726 | - $num_pages = count( $pages ); |
|
| 4727 | - for ( $i = 0; $i < $num_pages; $i++ ) { |
|
| 4728 | - if ( in_array( $pages[$i]->ID, $exclude ) ) { |
|
| 4729 | - unset( $pages[$i] ); |
|
| 4726 | + $num_pages = count($pages); |
|
| 4727 | + for ($i = 0; $i < $num_pages; $i++) { |
|
| 4728 | + if (in_array($pages[$i]->ID, $exclude)) { |
|
| 4729 | + unset($pages[$i]); |
|
| 4730 | 4730 | } |
| 4731 | 4731 | } |
| 4732 | 4732 | } |
| 4733 | 4733 | |
| 4734 | 4734 | $page_structure = array(); |
| 4735 | - foreach ( $pages as $page ) { |
|
| 4735 | + foreach ($pages as $page) { |
|
| 4736 | 4736 | $page_structure[] = $page->ID; |
| 4737 | 4737 | } |
| 4738 | 4738 | |
| 4739 | - wp_cache_set( $cache_key, $page_structure, 'posts' ); |
|
| 4739 | + wp_cache_set($cache_key, $page_structure, 'posts'); |
|
| 4740 | 4740 | |
| 4741 | 4741 | // Convert to WP_Post instances |
| 4742 | - $pages = array_map( 'get_post', $pages ); |
|
| 4742 | + $pages = array_map('get_post', $pages); |
|
| 4743 | 4743 | |
| 4744 | 4744 | /** |
| 4745 | 4745 | * Filter the retrieved list of pages. |
@@ -4749,7 +4749,7 @@ discard block |
||
| 4749 | 4749 | * @param array $pages List of pages to retrieve. |
| 4750 | 4750 | * @param array $r Array of get_pages() arguments. |
| 4751 | 4751 | */ |
| 4752 | - return apply_filters( 'get_pages', $pages, $r ); |
|
| 4752 | + return apply_filters('get_pages', $pages, $r); |
|
| 4753 | 4753 | } |
| 4754 | 4754 | |
| 4755 | 4755 | // |
@@ -4769,9 +4769,9 @@ discard block |
||
| 4769 | 4769 | return false; |
| 4770 | 4770 | if (strpos($url, home_url('/?attachment_id=')) !== false) |
| 4771 | 4771 | return true; |
| 4772 | - if ( $id = url_to_postid($url) ) { |
|
| 4772 | + if ($id = url_to_postid($url)) { |
|
| 4773 | 4773 | $post = get_post($id); |
| 4774 | - if ( 'attachment' == $post->post_type ) |
|
| 4774 | + if ('attachment' == $post->post_type) |
|
| 4775 | 4775 | return true; |
| 4776 | 4776 | } |
| 4777 | 4777 | return false; |
@@ -4800,21 +4800,21 @@ discard block |
||
| 4800 | 4800 | * @param int $parent Optional. Parent post ID. |
| 4801 | 4801 | * @return int Attachment ID. |
| 4802 | 4802 | */ |
| 4803 | -function wp_insert_attachment( $args, $file = false, $parent = 0 ) { |
|
| 4803 | +function wp_insert_attachment($args, $file = false, $parent = 0) { |
|
| 4804 | 4804 | $defaults = array( |
| 4805 | 4805 | 'file' => $file, |
| 4806 | 4806 | 'post_parent' => 0 |
| 4807 | 4807 | ); |
| 4808 | 4808 | |
| 4809 | - $data = wp_parse_args( $args, $defaults ); |
|
| 4809 | + $data = wp_parse_args($args, $defaults); |
|
| 4810 | 4810 | |
| 4811 | - if ( ! empty( $parent ) ) { |
|
| 4811 | + if ( ! empty($parent)) { |
|
| 4812 | 4812 | $data['post_parent'] = $parent; |
| 4813 | 4813 | } |
| 4814 | 4814 | |
| 4815 | 4815 | $data['post_type'] = 'attachment'; |
| 4816 | 4816 | |
| 4817 | - return wp_insert_post( $data ); |
|
| 4817 | + return wp_insert_post($data); |
|
| 4818 | 4818 | } |
| 4819 | 4819 | |
| 4820 | 4820 | /** |
@@ -4836,27 +4836,27 @@ discard block |
||
| 4836 | 4836 | * Default false. |
| 4837 | 4837 | * @return mixed False on failure. Post data on success. |
| 4838 | 4838 | */ |
| 4839 | -function wp_delete_attachment( $post_id, $force_delete = false ) { |
|
| 4839 | +function wp_delete_attachment($post_id, $force_delete = false) { |
|
| 4840 | 4840 | global $wpdb; |
| 4841 | 4841 | |
| 4842 | - if ( !$post = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d", $post_id) ) ) |
|
| 4842 | + if ( ! $post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d", $post_id))) |
|
| 4843 | 4843 | return $post; |
| 4844 | 4844 | |
| 4845 | - if ( 'attachment' != $post->post_type ) |
|
| 4845 | + if ('attachment' != $post->post_type) |
|
| 4846 | 4846 | return false; |
| 4847 | 4847 | |
| 4848 | - if ( !$force_delete && EMPTY_TRASH_DAYS && MEDIA_TRASH && 'trash' != $post->post_status ) |
|
| 4849 | - return wp_trash_post( $post_id ); |
|
| 4848 | + if ( ! $force_delete && EMPTY_TRASH_DAYS && MEDIA_TRASH && 'trash' != $post->post_status) |
|
| 4849 | + return wp_trash_post($post_id); |
|
| 4850 | 4850 | |
| 4851 | 4851 | delete_post_meta($post_id, '_wp_trash_meta_status'); |
| 4852 | 4852 | delete_post_meta($post_id, '_wp_trash_meta_time'); |
| 4853 | 4853 | |
| 4854 | - $meta = wp_get_attachment_metadata( $post_id ); |
|
| 4855 | - $backup_sizes = get_post_meta( $post->ID, '_wp_attachment_backup_sizes', true ); |
|
| 4856 | - $file = get_attached_file( $post_id ); |
|
| 4854 | + $meta = wp_get_attachment_metadata($post_id); |
|
| 4855 | + $backup_sizes = get_post_meta($post->ID, '_wp_attachment_backup_sizes', true); |
|
| 4856 | + $file = get_attached_file($post_id); |
|
| 4857 | 4857 | |
| 4858 | - if ( is_multisite() ) |
|
| 4859 | - delete_transient( 'dirsize_cache' ); |
|
| 4858 | + if (is_multisite()) |
|
| 4859 | + delete_transient('dirsize_cache'); |
|
| 4860 | 4860 | |
| 4861 | 4861 | /** |
| 4862 | 4862 | * Fires before an attachment is deleted, at the start of wp_delete_attachment(). |
@@ -4865,70 +4865,70 @@ discard block |
||
| 4865 | 4865 | * |
| 4866 | 4866 | * @param int $post_id Attachment ID. |
| 4867 | 4867 | */ |
| 4868 | - do_action( 'delete_attachment', $post_id ); |
|
| 4868 | + do_action('delete_attachment', $post_id); |
|
| 4869 | 4869 | |
| 4870 | 4870 | wp_delete_object_term_relationships($post_id, array('category', 'post_tag')); |
| 4871 | 4871 | wp_delete_object_term_relationships($post_id, get_object_taxonomies($post->post_type)); |
| 4872 | 4872 | |
| 4873 | 4873 | // Delete all for any posts. |
| 4874 | - delete_metadata( 'post', null, '_thumbnail_id', $post_id, true ); |
|
| 4874 | + delete_metadata('post', null, '_thumbnail_id', $post_id, true); |
|
| 4875 | 4875 | |
| 4876 | - wp_defer_comment_counting( true ); |
|
| 4876 | + wp_defer_comment_counting(true); |
|
| 4877 | 4877 | |
| 4878 | - $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id )); |
|
| 4879 | - foreach ( $comment_ids as $comment_id ) { |
|
| 4880 | - wp_delete_comment( $comment_id, true ); |
|
| 4878 | + $comment_ids = $wpdb->get_col($wpdb->prepare("SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id)); |
|
| 4879 | + foreach ($comment_ids as $comment_id) { |
|
| 4880 | + wp_delete_comment($comment_id, true); |
|
| 4881 | 4881 | } |
| 4882 | 4882 | |
| 4883 | - wp_defer_comment_counting( false ); |
|
| 4883 | + wp_defer_comment_counting(false); |
|
| 4884 | 4884 | |
| 4885 | - $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $post_id )); |
|
| 4886 | - foreach ( $post_meta_ids as $mid ) |
|
| 4887 | - delete_metadata_by_mid( 'post', $mid ); |
|
| 4885 | + $post_meta_ids = $wpdb->get_col($wpdb->prepare("SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $post_id)); |
|
| 4886 | + foreach ($post_meta_ids as $mid) |
|
| 4887 | + delete_metadata_by_mid('post', $mid); |
|
| 4888 | 4888 | |
| 4889 | 4889 | /** This action is documented in wp-includes/post.php */ |
| 4890 | - do_action( 'delete_post', $post_id ); |
|
| 4891 | - $result = $wpdb->delete( $wpdb->posts, array( 'ID' => $post_id ) ); |
|
| 4892 | - if ( ! $result ) { |
|
| 4890 | + do_action('delete_post', $post_id); |
|
| 4891 | + $result = $wpdb->delete($wpdb->posts, array('ID' => $post_id)); |
|
| 4892 | + if ( ! $result) { |
|
| 4893 | 4893 | return false; |
| 4894 | 4894 | } |
| 4895 | 4895 | /** This action is documented in wp-includes/post.php */ |
| 4896 | - do_action( 'deleted_post', $post_id ); |
|
| 4896 | + do_action('deleted_post', $post_id); |
|
| 4897 | 4897 | |
| 4898 | 4898 | $uploadpath = wp_get_upload_dir(); |
| 4899 | 4899 | |
| 4900 | - if ( ! empty($meta['thumb']) ) { |
|
| 4900 | + if ( ! empty($meta['thumb'])) { |
|
| 4901 | 4901 | // Don't delete the thumb if another attachment uses it. |
| 4902 | - if (! $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE %s AND post_id <> %d", '%' . $wpdb->esc_like( $meta['thumb'] ) . '%', $post_id)) ) { |
|
| 4902 | + if ( ! $wpdb->get_row($wpdb->prepare("SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE %s AND post_id <> %d", '%'.$wpdb->esc_like($meta['thumb']).'%', $post_id))) { |
|
| 4903 | 4903 | $thumbfile = str_replace(basename($file), $meta['thumb'], $file); |
| 4904 | 4904 | /** This filter is documented in wp-includes/functions.php */ |
| 4905 | - $thumbfile = apply_filters( 'wp_delete_file', $thumbfile ); |
|
| 4906 | - @ unlink( path_join($uploadpath['basedir'], $thumbfile) ); |
|
| 4905 | + $thumbfile = apply_filters('wp_delete_file', $thumbfile); |
|
| 4906 | + @ unlink(path_join($uploadpath['basedir'], $thumbfile)); |
|
| 4907 | 4907 | } |
| 4908 | 4908 | } |
| 4909 | 4909 | |
| 4910 | 4910 | // Remove intermediate and backup images if there are any. |
| 4911 | - if ( isset( $meta['sizes'] ) && is_array( $meta['sizes'] ) ) { |
|
| 4912 | - foreach ( $meta['sizes'] as $size => $sizeinfo ) { |
|
| 4913 | - $intermediate_file = str_replace( basename( $file ), $sizeinfo['file'], $file ); |
|
| 4911 | + if (isset($meta['sizes']) && is_array($meta['sizes'])) { |
|
| 4912 | + foreach ($meta['sizes'] as $size => $sizeinfo) { |
|
| 4913 | + $intermediate_file = str_replace(basename($file), $sizeinfo['file'], $file); |
|
| 4914 | 4914 | /** This filter is documented in wp-includes/functions.php */ |
| 4915 | - $intermediate_file = apply_filters( 'wp_delete_file', $intermediate_file ); |
|
| 4916 | - @ unlink( path_join( $uploadpath['basedir'], $intermediate_file ) ); |
|
| 4915 | + $intermediate_file = apply_filters('wp_delete_file', $intermediate_file); |
|
| 4916 | + @ unlink(path_join($uploadpath['basedir'], $intermediate_file)); |
|
| 4917 | 4917 | } |
| 4918 | 4918 | } |
| 4919 | 4919 | |
| 4920 | - if ( is_array($backup_sizes) ) { |
|
| 4921 | - foreach ( $backup_sizes as $size ) { |
|
| 4922 | - $del_file = path_join( dirname($meta['file']), $size['file'] ); |
|
| 4920 | + if (is_array($backup_sizes)) { |
|
| 4921 | + foreach ($backup_sizes as $size) { |
|
| 4922 | + $del_file = path_join(dirname($meta['file']), $size['file']); |
|
| 4923 | 4923 | /** This filter is documented in wp-includes/functions.php */ |
| 4924 | - $del_file = apply_filters( 'wp_delete_file', $del_file ); |
|
| 4925 | - @ unlink( path_join($uploadpath['basedir'], $del_file) ); |
|
| 4924 | + $del_file = apply_filters('wp_delete_file', $del_file); |
|
| 4925 | + @ unlink(path_join($uploadpath['basedir'], $del_file)); |
|
| 4926 | 4926 | } |
| 4927 | 4927 | } |
| 4928 | 4928 | |
| 4929 | - wp_delete_file( $file ); |
|
| 4929 | + wp_delete_file($file); |
|
| 4930 | 4930 | |
| 4931 | - clean_post_cache( $post ); |
|
| 4931 | + clean_post_cache($post); |
|
| 4932 | 4932 | |
| 4933 | 4933 | return $post; |
| 4934 | 4934 | } |
@@ -4942,14 +4942,14 @@ discard block |
||
| 4942 | 4942 | * @param bool $unfiltered Optional. If true, filters are not run. Default false. |
| 4943 | 4943 | * @return mixed Attachment meta field. False on failure. |
| 4944 | 4944 | */ |
| 4945 | -function wp_get_attachment_metadata( $post_id = 0, $unfiltered = false ) { |
|
| 4945 | +function wp_get_attachment_metadata($post_id = 0, $unfiltered = false) { |
|
| 4946 | 4946 | $post_id = (int) $post_id; |
| 4947 | - if ( !$post = get_post( $post_id ) ) |
|
| 4947 | + if ( ! $post = get_post($post_id)) |
|
| 4948 | 4948 | return false; |
| 4949 | 4949 | |
| 4950 | - $data = get_post_meta( $post->ID, '_wp_attachment_metadata', true ); |
|
| 4950 | + $data = get_post_meta($post->ID, '_wp_attachment_metadata', true); |
|
| 4951 | 4951 | |
| 4952 | - if ( $unfiltered ) |
|
| 4952 | + if ($unfiltered) |
|
| 4953 | 4953 | return $data; |
| 4954 | 4954 | |
| 4955 | 4955 | /** |
@@ -4961,7 +4961,7 @@ discard block |
||
| 4961 | 4961 | * if the object does not exist. |
| 4962 | 4962 | * @param int $post_id Attachment ID. |
| 4963 | 4963 | */ |
| 4964 | - return apply_filters( 'wp_get_attachment_metadata', $data, $post->ID ); |
|
| 4964 | + return apply_filters('wp_get_attachment_metadata', $data, $post->ID); |
|
| 4965 | 4965 | } |
| 4966 | 4966 | |
| 4967 | 4967 | /** |
@@ -4973,9 +4973,9 @@ discard block |
||
| 4973 | 4973 | * @param array $data Attachment data. |
| 4974 | 4974 | * @return int|bool False if $post is invalid. |
| 4975 | 4975 | */ |
| 4976 | -function wp_update_attachment_metadata( $post_id, $data ) { |
|
| 4976 | +function wp_update_attachment_metadata($post_id, $data) { |
|
| 4977 | 4977 | $post_id = (int) $post_id; |
| 4978 | - if ( !$post = get_post( $post_id ) ) |
|
| 4978 | + if ( ! $post = get_post($post_id)) |
|
| 4979 | 4979 | return false; |
| 4980 | 4980 | |
| 4981 | 4981 | /** |
@@ -4986,10 +4986,10 @@ discard block |
||
| 4986 | 4986 | * @param array $data Array of updated attachment meta data. |
| 4987 | 4987 | * @param int $post_id Attachment ID. |
| 4988 | 4988 | */ |
| 4989 | - if ( $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID ) ) |
|
| 4990 | - return update_post_meta( $post->ID, '_wp_attachment_metadata', $data ); |
|
| 4989 | + if ($data = apply_filters('wp_update_attachment_metadata', $data, $post->ID)) |
|
| 4990 | + return update_post_meta($post->ID, '_wp_attachment_metadata', $data); |
|
| 4991 | 4991 | else |
| 4992 | - return delete_post_meta( $post->ID, '_wp_attachment_metadata' ); |
|
| 4992 | + return delete_post_meta($post->ID, '_wp_attachment_metadata'); |
|
| 4993 | 4993 | } |
| 4994 | 4994 | |
| 4995 | 4995 | /** |
@@ -5002,29 +5002,29 @@ discard block |
||
| 5002 | 5002 | * @param int $post_id Optional. Attachment ID. Default 0. |
| 5003 | 5003 | * @return string|false Attachment URL, otherwise false. |
| 5004 | 5004 | */ |
| 5005 | -function wp_get_attachment_url( $post_id = 0 ) { |
|
| 5005 | +function wp_get_attachment_url($post_id = 0) { |
|
| 5006 | 5006 | $post_id = (int) $post_id; |
| 5007 | - if ( !$post = get_post( $post_id ) ) |
|
| 5007 | + if ( ! $post = get_post($post_id)) |
|
| 5008 | 5008 | return false; |
| 5009 | 5009 | |
| 5010 | - if ( 'attachment' != $post->post_type ) |
|
| 5010 | + if ('attachment' != $post->post_type) |
|
| 5011 | 5011 | return false; |
| 5012 | 5012 | |
| 5013 | 5013 | $url = ''; |
| 5014 | 5014 | // Get attached file. |
| 5015 | - if ( $file = get_post_meta( $post->ID, '_wp_attached_file', true ) ) { |
|
| 5015 | + if ($file = get_post_meta($post->ID, '_wp_attached_file', true)) { |
|
| 5016 | 5016 | // Get upload directory. |
| 5017 | - if ( ( $uploads = wp_get_upload_dir() ) && false === $uploads['error'] ) { |
|
| 5017 | + if (($uploads = wp_get_upload_dir()) && false === $uploads['error']) { |
|
| 5018 | 5018 | // Check that the upload base exists in the file location. |
| 5019 | - if ( 0 === strpos( $file, $uploads['basedir'] ) ) { |
|
| 5019 | + if (0 === strpos($file, $uploads['basedir'])) { |
|
| 5020 | 5020 | // Replace file location with url location. |
| 5021 | 5021 | $url = str_replace($uploads['basedir'], $uploads['baseurl'], $file); |
| 5022 | - } elseif ( false !== strpos($file, 'wp-content/uploads') ) { |
|
| 5022 | + } elseif (false !== strpos($file, 'wp-content/uploads')) { |
|
| 5023 | 5023 | // Get the directory name relative to the basedir (back compat for pre-2.7 uploads) |
| 5024 | - $url = trailingslashit( $uploads['baseurl'] . '/' . _wp_get_attachment_relative_path( $file ) ) . basename( $file ); |
|
| 5024 | + $url = trailingslashit($uploads['baseurl'].'/'._wp_get_attachment_relative_path($file)).basename($file); |
|
| 5025 | 5025 | } else { |
| 5026 | 5026 | // It's a newly-uploaded file, therefore $file is relative to the basedir. |
| 5027 | - $url = $uploads['baseurl'] . "/$file"; |
|
| 5027 | + $url = $uploads['baseurl']."/$file"; |
|
| 5028 | 5028 | } |
| 5029 | 5029 | } |
| 5030 | 5030 | } |
@@ -5033,13 +5033,13 @@ discard block |
||
| 5033 | 5033 | * If any of the above options failed, Fallback on the GUID as used pre-2.7, |
| 5034 | 5034 | * not recommended to rely upon this. |
| 5035 | 5035 | */ |
| 5036 | - if ( empty($url) ) { |
|
| 5037 | - $url = get_the_guid( $post->ID ); |
|
| 5036 | + if (empty($url)) { |
|
| 5037 | + $url = get_the_guid($post->ID); |
|
| 5038 | 5038 | } |
| 5039 | 5039 | |
| 5040 | 5040 | // On SSL front end, URLs should be HTTPS. |
| 5041 | - if ( is_ssl() && ! is_admin() && 'wp-login.php' !== $GLOBALS['pagenow'] ) { |
|
| 5042 | - $url = set_url_scheme( $url ); |
|
| 5041 | + if (is_ssl() && ! is_admin() && 'wp-login.php' !== $GLOBALS['pagenow']) { |
|
| 5042 | + $url = set_url_scheme($url); |
|
| 5043 | 5043 | } |
| 5044 | 5044 | |
| 5045 | 5045 | /** |
@@ -5050,9 +5050,9 @@ discard block |
||
| 5050 | 5050 | * @param string $url URL for the given attachment. |
| 5051 | 5051 | * @param int $post_id Attachment ID. |
| 5052 | 5052 | */ |
| 5053 | - $url = apply_filters( 'wp_get_attachment_url', $url, $post->ID ); |
|
| 5053 | + $url = apply_filters('wp_get_attachment_url', $url, $post->ID); |
|
| 5054 | 5054 | |
| 5055 | - if ( empty( $url ) ) |
|
| 5055 | + if (empty($url)) |
|
| 5056 | 5056 | return false; |
| 5057 | 5057 | |
| 5058 | 5058 | return $url; |
@@ -5066,16 +5066,16 @@ discard block |
||
| 5066 | 5066 | * @param int $post_id Optional. Attachment ID. Default 0. |
| 5067 | 5067 | * @return string|false False on failure. Thumbnail file path on success. |
| 5068 | 5068 | */ |
| 5069 | -function wp_get_attachment_thumb_file( $post_id = 0 ) { |
|
| 5069 | +function wp_get_attachment_thumb_file($post_id = 0) { |
|
| 5070 | 5070 | $post_id = (int) $post_id; |
| 5071 | - if ( !$post = get_post( $post_id ) ) |
|
| 5071 | + if ( ! $post = get_post($post_id)) |
|
| 5072 | 5072 | return false; |
| 5073 | - if ( !is_array( $imagedata = wp_get_attachment_metadata( $post->ID ) ) ) |
|
| 5073 | + if ( ! is_array($imagedata = wp_get_attachment_metadata($post->ID))) |
|
| 5074 | 5074 | return false; |
| 5075 | 5075 | |
| 5076 | - $file = get_attached_file( $post->ID ); |
|
| 5076 | + $file = get_attached_file($post->ID); |
|
| 5077 | 5077 | |
| 5078 | - if ( !empty($imagedata['thumb']) && ($thumbfile = str_replace(basename($file), $imagedata['thumb'], $file)) && file_exists($thumbfile) ) { |
|
| 5078 | + if ( ! empty($imagedata['thumb']) && ($thumbfile = str_replace(basename($file), $imagedata['thumb'], $file)) && file_exists($thumbfile)) { |
|
| 5079 | 5079 | /** |
| 5080 | 5080 | * Filter the attachment thumbnail file path. |
| 5081 | 5081 | * |
@@ -5084,7 +5084,7 @@ discard block |
||
| 5084 | 5084 | * @param string $thumbfile File path to the attachment thumbnail. |
| 5085 | 5085 | * @param int $post_id Attachment ID. |
| 5086 | 5086 | */ |
| 5087 | - return apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post->ID ); |
|
| 5087 | + return apply_filters('wp_get_attachment_thumb_file', $thumbfile, $post->ID); |
|
| 5088 | 5088 | } |
| 5089 | 5089 | return false; |
| 5090 | 5090 | } |
@@ -5097,18 +5097,18 @@ discard block |
||
| 5097 | 5097 | * @param int $post_id Optional. Attachment ID. Default 0. |
| 5098 | 5098 | * @return string|false False on failure. Thumbnail URL on success. |
| 5099 | 5099 | */ |
| 5100 | -function wp_get_attachment_thumb_url( $post_id = 0 ) { |
|
| 5100 | +function wp_get_attachment_thumb_url($post_id = 0) { |
|
| 5101 | 5101 | $post_id = (int) $post_id; |
| 5102 | - if ( !$post = get_post( $post_id ) ) |
|
| 5102 | + if ( ! $post = get_post($post_id)) |
|
| 5103 | 5103 | return false; |
| 5104 | - if ( !$url = wp_get_attachment_url( $post->ID ) ) |
|
| 5104 | + if ( ! $url = wp_get_attachment_url($post->ID)) |
|
| 5105 | 5105 | return false; |
| 5106 | 5106 | |
| 5107 | - $sized = image_downsize( $post_id, 'thumbnail' ); |
|
| 5108 | - if ( $sized ) |
|
| 5107 | + $sized = image_downsize($post_id, 'thumbnail'); |
|
| 5108 | + if ($sized) |
|
| 5109 | 5109 | return $sized[0]; |
| 5110 | 5110 | |
| 5111 | - if ( !$thumb = wp_get_attachment_thumb_file( $post->ID ) ) |
|
| 5111 | + if ( ! $thumb = wp_get_attachment_thumb_file($post->ID)) |
|
| 5112 | 5112 | return false; |
| 5113 | 5113 | |
| 5114 | 5114 | $url = str_replace(basename($url), basename($thumb), $url); |
@@ -5121,7 +5121,7 @@ discard block |
||
| 5121 | 5121 | * @param string $url URL for the attachment thumbnail. |
| 5122 | 5122 | * @param int $post_id Attachment ID. |
| 5123 | 5123 | */ |
| 5124 | - return apply_filters( 'wp_get_attachment_thumb_url', $url, $post->ID ); |
|
| 5124 | + return apply_filters('wp_get_attachment_thumb_url', $url, $post->ID); |
|
| 5125 | 5125 | } |
| 5126 | 5126 | |
| 5127 | 5127 | /** |
@@ -5133,40 +5133,40 @@ discard block |
||
| 5133 | 5133 | * @param int|WP_Post $post_id Optional. Attachment ID. Default 0. |
| 5134 | 5134 | * @return bool True if one of the accepted types, false otherwise. |
| 5135 | 5135 | */ |
| 5136 | -function wp_attachment_is( $type, $post_id = 0 ) { |
|
| 5137 | - if ( ! $post = get_post( $post_id ) ) { |
|
| 5136 | +function wp_attachment_is($type, $post_id = 0) { |
|
| 5137 | + if ( ! $post = get_post($post_id)) { |
|
| 5138 | 5138 | return false; |
| 5139 | 5139 | } |
| 5140 | 5140 | |
| 5141 | - if ( ! $file = get_attached_file( $post->ID ) ) { |
|
| 5141 | + if ( ! $file = get_attached_file($post->ID)) { |
|
| 5142 | 5142 | return false; |
| 5143 | 5143 | } |
| 5144 | 5144 | |
| 5145 | - if ( 0 === strpos( $post->post_mime_type, $type . '/' ) ) { |
|
| 5145 | + if (0 === strpos($post->post_mime_type, $type.'/')) { |
|
| 5146 | 5146 | return true; |
| 5147 | 5147 | } |
| 5148 | 5148 | |
| 5149 | - $check = wp_check_filetype( $file ); |
|
| 5150 | - if ( empty( $check['ext'] ) ) { |
|
| 5149 | + $check = wp_check_filetype($file); |
|
| 5150 | + if (empty($check['ext'])) { |
|
| 5151 | 5151 | return false; |
| 5152 | 5152 | } |
| 5153 | 5153 | |
| 5154 | 5154 | $ext = $check['ext']; |
| 5155 | 5155 | |
| 5156 | - if ( 'import' !== $post->post_mime_type ) { |
|
| 5156 | + if ('import' !== $post->post_mime_type) { |
|
| 5157 | 5157 | return $type === $ext; |
| 5158 | 5158 | } |
| 5159 | 5159 | |
| 5160 | - switch ( $type ) { |
|
| 5160 | + switch ($type) { |
|
| 5161 | 5161 | case 'image': |
| 5162 | - $image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' ); |
|
| 5163 | - return in_array( $ext, $image_exts ); |
|
| 5162 | + $image_exts = array('jpg', 'jpeg', 'jpe', 'gif', 'png'); |
|
| 5163 | + return in_array($ext, $image_exts); |
|
| 5164 | 5164 | |
| 5165 | 5165 | case 'audio': |
| 5166 | - return in_array( $ext, wp_get_audio_extensions() ); |
|
| 5166 | + return in_array($ext, wp_get_audio_extensions()); |
|
| 5167 | 5167 | |
| 5168 | 5168 | case 'video': |
| 5169 | - return in_array( $ext, wp_get_video_extensions() ); |
|
| 5169 | + return in_array($ext, wp_get_video_extensions()); |
|
| 5170 | 5170 | |
| 5171 | 5171 | default: |
| 5172 | 5172 | return $type === $ext; |
@@ -5183,8 +5183,8 @@ discard block |
||
| 5183 | 5183 | * @param int|WP_Post $post Optional. Attachment ID. Default 0. |
| 5184 | 5184 | * @return bool Whether the attachment is an image. |
| 5185 | 5185 | */ |
| 5186 | -function wp_attachment_is_image( $post = 0 ) { |
|
| 5187 | - return wp_attachment_is( 'image', $post ); |
|
| 5186 | +function wp_attachment_is_image($post = 0) { |
|
| 5187 | + return wp_attachment_is('image', $post); |
|
| 5188 | 5188 | } |
| 5189 | 5189 | |
| 5190 | 5190 | /** |
@@ -5195,22 +5195,22 @@ discard block |
||
| 5195 | 5195 | * @param string|int $mime MIME type or attachment ID. |
| 5196 | 5196 | * @return string|false Icon, false otherwise. |
| 5197 | 5197 | */ |
| 5198 | -function wp_mime_type_icon( $mime = 0 ) { |
|
| 5199 | - if ( !is_numeric($mime) ) |
|
| 5198 | +function wp_mime_type_icon($mime = 0) { |
|
| 5199 | + if ( ! is_numeric($mime)) |
|
| 5200 | 5200 | $icon = wp_cache_get("mime_type_icon_$mime"); |
| 5201 | 5201 | |
| 5202 | 5202 | $post_id = 0; |
| 5203 | - if ( empty($icon) ) { |
|
| 5203 | + if (empty($icon)) { |
|
| 5204 | 5204 | $post_mimes = array(); |
| 5205 | - if ( is_numeric($mime) ) { |
|
| 5205 | + if (is_numeric($mime)) { |
|
| 5206 | 5206 | $mime = (int) $mime; |
| 5207 | - if ( $post = get_post( $mime ) ) { |
|
| 5207 | + if ($post = get_post($mime)) { |
|
| 5208 | 5208 | $post_id = (int) $post->ID; |
| 5209 | - $file = get_attached_file( $post_id ); |
|
| 5209 | + $file = get_attached_file($post_id); |
|
| 5210 | 5210 | $ext = preg_replace('/^.+?\.([^.]+)$/', '$1', $file); |
| 5211 | - if ( !empty($ext) ) { |
|
| 5211 | + if ( ! empty($ext)) { |
|
| 5212 | 5212 | $post_mimes[] = $ext; |
| 5213 | - if ( $ext_type = wp_ext2type( $ext ) ) |
|
| 5213 | + if ($ext_type = wp_ext2type($ext)) |
|
| 5214 | 5214 | $post_mimes[] = $ext_type; |
| 5215 | 5215 | } |
| 5216 | 5216 | $mime = $post->post_mime_type; |
@@ -5223,7 +5223,7 @@ discard block |
||
| 5223 | 5223 | |
| 5224 | 5224 | $icon_files = wp_cache_get('icon_files'); |
| 5225 | 5225 | |
| 5226 | - if ( !is_array($icon_files) ) { |
|
| 5226 | + if ( ! is_array($icon_files)) { |
|
| 5227 | 5227 | /** |
| 5228 | 5228 | * Filter the icon directory path. |
| 5229 | 5229 | * |
@@ -5231,7 +5231,7 @@ discard block |
||
| 5231 | 5231 | * |
| 5232 | 5232 | * @param string $path Icon directory absolute path. |
| 5233 | 5233 | */ |
| 5234 | - $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' ); |
|
| 5234 | + $icon_dir = apply_filters('icon_dir', ABSPATH.WPINC.'/images/media'); |
|
| 5235 | 5235 | |
| 5236 | 5236 | /** |
| 5237 | 5237 | * Filter the icon directory URI. |
@@ -5240,7 +5240,7 @@ discard block |
||
| 5240 | 5240 | * |
| 5241 | 5241 | * @param string $uri Icon directory URI. |
| 5242 | 5242 | */ |
| 5243 | - $icon_dir_uri = apply_filters( 'icon_dir_uri', includes_url( 'images/media' ) ); |
|
| 5243 | + $icon_dir_uri = apply_filters('icon_dir_uri', includes_url('images/media')); |
|
| 5244 | 5244 | |
| 5245 | 5245 | /** |
| 5246 | 5246 | * Filter the list of icon directory URIs. |
@@ -5249,19 +5249,19 @@ discard block |
||
| 5249 | 5249 | * |
| 5250 | 5250 | * @param array $uris List of icon directory URIs. |
| 5251 | 5251 | */ |
| 5252 | - $dirs = apply_filters( 'icon_dirs', array( $icon_dir => $icon_dir_uri ) ); |
|
| 5252 | + $dirs = apply_filters('icon_dirs', array($icon_dir => $icon_dir_uri)); |
|
| 5253 | 5253 | $icon_files = array(); |
| 5254 | - while ( $dirs ) { |
|
| 5255 | - $keys = array_keys( $dirs ); |
|
| 5256 | - $dir = array_shift( $keys ); |
|
| 5254 | + while ($dirs) { |
|
| 5255 | + $keys = array_keys($dirs); |
|
| 5256 | + $dir = array_shift($keys); |
|
| 5257 | 5257 | $uri = array_shift($dirs); |
| 5258 | - if ( $dh = opendir($dir) ) { |
|
| 5259 | - while ( false !== $file = readdir($dh) ) { |
|
| 5258 | + if ($dh = opendir($dir)) { |
|
| 5259 | + while (false !== $file = readdir($dh)) { |
|
| 5260 | 5260 | $file = basename($file); |
| 5261 | - if ( substr($file, 0, 1) == '.' ) |
|
| 5261 | + if (substr($file, 0, 1) == '.') |
|
| 5262 | 5262 | continue; |
| 5263 | - if ( !in_array(strtolower(substr($file, -4)), array('.png', '.gif', '.jpg') ) ) { |
|
| 5264 | - if ( is_dir("$dir/$file") ) |
|
| 5263 | + if ( ! in_array(strtolower(substr($file, -4)), array('.png', '.gif', '.jpg'))) { |
|
| 5264 | + if (is_dir("$dir/$file")) |
|
| 5265 | 5265 | $dirs["$dir/$file"] = "$uri/$file"; |
| 5266 | 5266 | continue; |
| 5267 | 5267 | } |
@@ -5270,15 +5270,15 @@ discard block |
||
| 5270 | 5270 | closedir($dh); |
| 5271 | 5271 | } |
| 5272 | 5272 | } |
| 5273 | - wp_cache_add( 'icon_files', $icon_files, 'default', 600 ); |
|
| 5273 | + wp_cache_add('icon_files', $icon_files, 'default', 600); |
|
| 5274 | 5274 | } |
| 5275 | 5275 | |
| 5276 | 5276 | $types = array(); |
| 5277 | 5277 | // Icon basename - extension = MIME wildcard. |
| 5278 | - foreach ( $icon_files as $file => $uri ) |
|
| 5279 | - $types[ preg_replace('/^([^.]*).*$/', '$1', basename($file)) ] =& $icon_files[$file]; |
|
| 5278 | + foreach ($icon_files as $file => $uri) |
|
| 5279 | + $types[preg_replace('/^([^.]*).*$/', '$1', basename($file))] = & $icon_files[$file]; |
|
| 5280 | 5280 | |
| 5281 | - if ( ! empty($mime) ) { |
|
| 5281 | + if ( ! empty($mime)) { |
|
| 5282 | 5282 | $post_mimes[] = substr($mime, 0, strpos($mime, '/')); |
| 5283 | 5283 | $post_mimes[] = substr($mime, strpos($mime, '/') + 1); |
| 5284 | 5284 | $post_mimes[] = str_replace('/', '_', $mime); |
@@ -5287,15 +5287,15 @@ discard block |
||
| 5287 | 5287 | $matches = wp_match_mime_types(array_keys($types), $post_mimes); |
| 5288 | 5288 | $matches['default'] = array('default'); |
| 5289 | 5289 | |
| 5290 | - foreach ( $matches as $match => $wilds ) { |
|
| 5291 | - foreach ( $wilds as $wild ) { |
|
| 5292 | - if ( ! isset( $types[ $wild ] ) ) { |
|
| 5290 | + foreach ($matches as $match => $wilds) { |
|
| 5291 | + foreach ($wilds as $wild) { |
|
| 5292 | + if ( ! isset($types[$wild])) { |
|
| 5293 | 5293 | continue; |
| 5294 | 5294 | } |
| 5295 | 5295 | |
| 5296 | - $icon = $types[ $wild ]; |
|
| 5297 | - if ( ! is_numeric( $mime ) ) { |
|
| 5298 | - wp_cache_add( "mime_type_icon_$mime", $icon ); |
|
| 5296 | + $icon = $types[$wild]; |
|
| 5297 | + if ( ! is_numeric($mime)) { |
|
| 5298 | + wp_cache_add("mime_type_icon_$mime", $icon); |
|
| 5299 | 5299 | } |
| 5300 | 5300 | break 2; |
| 5301 | 5301 | } |
@@ -5312,7 +5312,7 @@ discard block |
||
| 5312 | 5312 | * @param int $post_id Attachment ID. Will equal 0 if the function passed |
| 5313 | 5313 | * the mime type. |
| 5314 | 5314 | */ |
| 5315 | - return apply_filters( 'wp_mime_type_icon', $icon, $mime, $post_id ); |
|
| 5315 | + return apply_filters('wp_mime_type_icon', $icon, $mime, $post_id); |
|
| 5316 | 5316 | } |
| 5317 | 5317 | |
| 5318 | 5318 | /** |
@@ -5334,27 +5334,27 @@ discard block |
||
| 5334 | 5334 | * @param WP_Post $post The Post Object |
| 5335 | 5335 | * @param WP_Post $post_before The Previous Post Object |
| 5336 | 5336 | */ |
| 5337 | -function wp_check_for_changed_slugs( $post_id, $post, $post_before ) { |
|
| 5337 | +function wp_check_for_changed_slugs($post_id, $post, $post_before) { |
|
| 5338 | 5338 | // Don't bother if it hasn't changed. |
| 5339 | - if ( $post->post_name == $post_before->post_name ) { |
|
| 5339 | + if ($post->post_name == $post_before->post_name) { |
|
| 5340 | 5340 | return; |
| 5341 | 5341 | } |
| 5342 | 5342 | |
| 5343 | 5343 | // We're only concerned with published, non-hierarchical objects. |
| 5344 | - if ( ! ( 'publish' === $post->post_status || ( 'attachment' === get_post_type( $post ) && 'inherit' === $post->post_status ) ) || is_post_type_hierarchical( $post->post_type ) ) { |
|
| 5344 | + if ( ! ('publish' === $post->post_status || ('attachment' === get_post_type($post) && 'inherit' === $post->post_status)) || is_post_type_hierarchical($post->post_type)) { |
|
| 5345 | 5345 | return; |
| 5346 | 5346 | } |
| 5347 | 5347 | |
| 5348 | - $old_slugs = (array) get_post_meta( $post_id, '_wp_old_slug' ); |
|
| 5348 | + $old_slugs = (array) get_post_meta($post_id, '_wp_old_slug'); |
|
| 5349 | 5349 | |
| 5350 | 5350 | // If we haven't added this old slug before, add it now. |
| 5351 | - if ( ! empty( $post_before->post_name ) && ! in_array( $post_before->post_name, $old_slugs ) ) { |
|
| 5352 | - add_post_meta( $post_id, '_wp_old_slug', $post_before->post_name ); |
|
| 5351 | + if ( ! empty($post_before->post_name) && ! in_array($post_before->post_name, $old_slugs)) { |
|
| 5352 | + add_post_meta($post_id, '_wp_old_slug', $post_before->post_name); |
|
| 5353 | 5353 | } |
| 5354 | 5354 | |
| 5355 | 5355 | // If the new slug was used previously, delete it from the list. |
| 5356 | - if ( in_array( $post->post_name, $old_slugs ) ) { |
|
| 5357 | - delete_post_meta( $post_id, '_wp_old_slug', $post->post_name ); |
|
| 5356 | + if (in_array($post->post_name, $old_slugs)) { |
|
| 5357 | + delete_post_meta($post_id, '_wp_old_slug', $post->post_name); |
|
| 5358 | 5358 | } |
| 5359 | 5359 | } |
| 5360 | 5360 | |
@@ -5372,8 +5372,8 @@ discard block |
||
| 5372 | 5372 | * @param string|array $post_type Single post type or an array of post types. Currently only supports 'post' or 'page'. |
| 5373 | 5373 | * @return string SQL code that can be added to a where clause. |
| 5374 | 5374 | */ |
| 5375 | -function get_private_posts_cap_sql( $post_type ) { |
|
| 5376 | - return get_posts_by_author_sql( $post_type, false ); |
|
| 5375 | +function get_private_posts_cap_sql($post_type) { |
|
| 5376 | + return get_posts_by_author_sql($post_type, false); |
|
| 5377 | 5377 | } |
| 5378 | 5378 | |
| 5379 | 5379 | /** |
@@ -5393,19 +5393,19 @@ discard block |
||
| 5393 | 5393 | * $current_user. Default false. |
| 5394 | 5394 | * @return string SQL WHERE code that can be added to a query. |
| 5395 | 5395 | */ |
| 5396 | -function get_posts_by_author_sql( $post_type, $full = true, $post_author = null, $public_only = false ) { |
|
| 5396 | +function get_posts_by_author_sql($post_type, $full = true, $post_author = null, $public_only = false) { |
|
| 5397 | 5397 | global $wpdb; |
| 5398 | 5398 | |
| 5399 | - if ( is_array( $post_type ) ) { |
|
| 5399 | + if (is_array($post_type)) { |
|
| 5400 | 5400 | $post_types = $post_type; |
| 5401 | 5401 | } else { |
| 5402 | - $post_types = array( $post_type ); |
|
| 5402 | + $post_types = array($post_type); |
|
| 5403 | 5403 | } |
| 5404 | 5404 | |
| 5405 | 5405 | $post_type_clauses = array(); |
| 5406 | - foreach ( $post_types as $post_type ) { |
|
| 5407 | - $post_type_obj = get_post_type_object( $post_type ); |
|
| 5408 | - if ( ! $post_type_obj ) { |
|
| 5406 | + foreach ($post_types as $post_type) { |
|
| 5407 | + $post_type_obj = get_post_type_object($post_type); |
|
| 5408 | + if ( ! $post_type_obj) { |
|
| 5409 | 5409 | continue; |
| 5410 | 5410 | } |
| 5411 | 5411 | |
@@ -5418,42 +5418,42 @@ discard block |
||
| 5418 | 5418 | * |
| 5419 | 5419 | * @param string $cap Capability. |
| 5420 | 5420 | */ |
| 5421 | - if ( ! $cap = apply_filters( 'pub_priv_sql_capability', '' ) ) { |
|
| 5422 | - $cap = current_user_can( $post_type_obj->cap->read_private_posts ); |
|
| 5421 | + if ( ! $cap = apply_filters('pub_priv_sql_capability', '')) { |
|
| 5422 | + $cap = current_user_can($post_type_obj->cap->read_private_posts); |
|
| 5423 | 5423 | } |
| 5424 | 5424 | |
| 5425 | 5425 | // Only need to check the cap if $public_only is false. |
| 5426 | 5426 | $post_status_sql = "post_status = 'publish'"; |
| 5427 | - if ( false === $public_only ) { |
|
| 5428 | - if ( $cap ) { |
|
| 5427 | + if (false === $public_only) { |
|
| 5428 | + if ($cap) { |
|
| 5429 | 5429 | // Does the user have the capability to view private posts? Guess so. |
| 5430 | 5430 | $post_status_sql .= " OR post_status = 'private'"; |
| 5431 | - } elseif ( is_user_logged_in() ) { |
|
| 5431 | + } elseif (is_user_logged_in()) { |
|
| 5432 | 5432 | // Users can view their own private posts. |
| 5433 | 5433 | $id = get_current_user_id(); |
| 5434 | - if ( null === $post_author || ! $full ) { |
|
| 5434 | + if (null === $post_author || ! $full) { |
|
| 5435 | 5435 | $post_status_sql .= " OR post_status = 'private' AND post_author = $id"; |
| 5436 | - } elseif ( $id == (int) $post_author ) { |
|
| 5436 | + } elseif ($id == (int) $post_author) { |
|
| 5437 | 5437 | $post_status_sql .= " OR post_status = 'private'"; |
| 5438 | 5438 | } // else none |
| 5439 | 5439 | } // else none |
| 5440 | 5440 | } |
| 5441 | 5441 | |
| 5442 | - $post_type_clauses[] = "( post_type = '" . $post_type . "' AND ( $post_status_sql ) )"; |
|
| 5442 | + $post_type_clauses[] = "( post_type = '".$post_type."' AND ( $post_status_sql ) )"; |
|
| 5443 | 5443 | } |
| 5444 | 5444 | |
| 5445 | - if ( empty( $post_type_clauses ) ) { |
|
| 5445 | + if (empty($post_type_clauses)) { |
|
| 5446 | 5446 | return $full ? 'WHERE 1 = 0' : '1 = 0'; |
| 5447 | 5447 | } |
| 5448 | 5448 | |
| 5449 | - $sql = '( '. implode( ' OR ', $post_type_clauses ) . ' )'; |
|
| 5449 | + $sql = '( '.implode(' OR ', $post_type_clauses).' )'; |
|
| 5450 | 5450 | |
| 5451 | - if ( null !== $post_author ) { |
|
| 5452 | - $sql .= $wpdb->prepare( ' AND post_author = %d', $post_author ); |
|
| 5451 | + if (null !== $post_author) { |
|
| 5452 | + $sql .= $wpdb->prepare(' AND post_author = %d', $post_author); |
|
| 5453 | 5453 | } |
| 5454 | 5454 | |
| 5455 | - if ( $full ) { |
|
| 5456 | - $sql = 'WHERE ' . $sql; |
|
| 5455 | + if ($full) { |
|
| 5456 | + $sql = 'WHERE '.$sql; |
|
| 5457 | 5457 | } |
| 5458 | 5458 | |
| 5459 | 5459 | return $sql; |
@@ -5477,7 +5477,7 @@ discard block |
||
| 5477 | 5477 | * @param string $post_type Optional. The post type to check. Default 'any'. |
| 5478 | 5478 | * @return string The date of the last post. |
| 5479 | 5479 | */ |
| 5480 | -function get_lastpostdate( $timezone = 'server', $post_type = 'any' ) { |
|
| 5480 | +function get_lastpostdate($timezone = 'server', $post_type = 'any') { |
|
| 5481 | 5481 | /** |
| 5482 | 5482 | * Filter the date the last post was published. |
| 5483 | 5483 | * |
@@ -5487,7 +5487,7 @@ discard block |
||
| 5487 | 5487 | * @param string $timezone Location to use for getting the post published date. |
| 5488 | 5488 | * See {@see get_lastpostdate()} for accepted `$timezone` values. |
| 5489 | 5489 | */ |
| 5490 | - return apply_filters( 'get_lastpostdate', _get_last_post_time( $timezone, 'date', $post_type ), $timezone ); |
|
| 5490 | + return apply_filters('get_lastpostdate', _get_last_post_time($timezone, 'date', $post_type), $timezone); |
|
| 5491 | 5491 | } |
| 5492 | 5492 | |
| 5493 | 5493 | /** |
@@ -5506,7 +5506,7 @@ discard block |
||
| 5506 | 5506 | * @param string $post_type Optional. The post type to check. Default 'any'. |
| 5507 | 5507 | * @return string The timestamp. |
| 5508 | 5508 | */ |
| 5509 | -function get_lastpostmodified( $timezone = 'server', $post_type = 'any' ) { |
|
| 5509 | +function get_lastpostmodified($timezone = 'server', $post_type = 'any') { |
|
| 5510 | 5510 | /** |
| 5511 | 5511 | * Pre-filter the return value of get_lastpostmodified() before the query is run. |
| 5512 | 5512 | * |
@@ -5518,15 +5518,15 @@ discard block |
||
| 5518 | 5518 | * See {@see get_lastpostdate()} for accepted `$timezone` values. |
| 5519 | 5519 | * @param string $post_type The post type to check. |
| 5520 | 5520 | */ |
| 5521 | - $lastpostmodified = apply_filters( 'pre_get_lastpostmodified', false, $timezone, $post_type ); |
|
| 5522 | - if ( false !== $lastpostmodified ) { |
|
| 5521 | + $lastpostmodified = apply_filters('pre_get_lastpostmodified', false, $timezone, $post_type); |
|
| 5522 | + if (false !== $lastpostmodified) { |
|
| 5523 | 5523 | return $lastpostmodified; |
| 5524 | 5524 | } |
| 5525 | 5525 | |
| 5526 | - $lastpostmodified = _get_last_post_time( $timezone, 'modified', $post_type ); |
|
| 5526 | + $lastpostmodified = _get_last_post_time($timezone, 'modified', $post_type); |
|
| 5527 | 5527 | |
| 5528 | 5528 | $lastpostdate = get_lastpostdate($timezone); |
| 5529 | - if ( $lastpostdate > $lastpostmodified ) { |
|
| 5529 | + if ($lastpostdate > $lastpostmodified) { |
|
| 5530 | 5530 | $lastpostmodified = $lastpostdate; |
| 5531 | 5531 | } |
| 5532 | 5532 | |
@@ -5539,7 +5539,7 @@ discard block |
||
| 5539 | 5539 | * @param string $timezone Location to use for getting the post modified date. |
| 5540 | 5540 | * See {@see get_lastpostdate()} for accepted `$timezone` values. |
| 5541 | 5541 | */ |
| 5542 | - return apply_filters( 'get_lastpostmodified', $lastpostmodified, $timezone ); |
|
| 5542 | + return apply_filters('get_lastpostmodified', $lastpostmodified, $timezone); |
|
| 5543 | 5543 | } |
| 5544 | 5544 | |
| 5545 | 5545 | /** |
@@ -5557,32 +5557,32 @@ discard block |
||
| 5557 | 5557 | * @param string $post_type Optional. The post type to check. Default 'any'. |
| 5558 | 5558 | * @return string|false The timestamp. |
| 5559 | 5559 | */ |
| 5560 | -function _get_last_post_time( $timezone, $field, $post_type = 'any' ) { |
|
| 5560 | +function _get_last_post_time($timezone, $field, $post_type = 'any') { |
|
| 5561 | 5561 | global $wpdb; |
| 5562 | 5562 | |
| 5563 | - if ( ! in_array( $field, array( 'date', 'modified' ) ) ) { |
|
| 5563 | + if ( ! in_array($field, array('date', 'modified'))) { |
|
| 5564 | 5564 | return false; |
| 5565 | 5565 | } |
| 5566 | 5566 | |
| 5567 | - $timezone = strtolower( $timezone ); |
|
| 5567 | + $timezone = strtolower($timezone); |
|
| 5568 | 5568 | |
| 5569 | 5569 | $key = "lastpost{$field}:$timezone"; |
| 5570 | - if ( 'any' !== $post_type ) { |
|
| 5571 | - $key .= ':' . sanitize_key( $post_type ); |
|
| 5570 | + if ('any' !== $post_type) { |
|
| 5571 | + $key .= ':'.sanitize_key($post_type); |
|
| 5572 | 5572 | } |
| 5573 | 5573 | |
| 5574 | - $date = wp_cache_get( $key, 'timeinfo' ); |
|
| 5574 | + $date = wp_cache_get($key, 'timeinfo'); |
|
| 5575 | 5575 | |
| 5576 | - if ( ! $date ) { |
|
| 5577 | - if ( 'any' === $post_type ) { |
|
| 5578 | - $post_types = get_post_types( array( 'public' => true ) ); |
|
| 5579 | - array_walk( $post_types, array( $wpdb, 'escape_by_ref' ) ); |
|
| 5580 | - $post_types = "'" . implode( "', '", $post_types ) . "'"; |
|
| 5576 | + if ( ! $date) { |
|
| 5577 | + if ('any' === $post_type) { |
|
| 5578 | + $post_types = get_post_types(array('public' => true)); |
|
| 5579 | + array_walk($post_types, array($wpdb, 'escape_by_ref')); |
|
| 5580 | + $post_types = "'".implode("', '", $post_types)."'"; |
|
| 5581 | 5581 | } else { |
| 5582 | - $post_types = "'" . sanitize_key( $post_type ) . "'"; |
|
| 5582 | + $post_types = "'".sanitize_key($post_type)."'"; |
|
| 5583 | 5583 | } |
| 5584 | 5584 | |
| 5585 | - switch ( $timezone ) { |
|
| 5585 | + switch ($timezone) { |
|
| 5586 | 5586 | case 'gmt': |
| 5587 | 5587 | $date = $wpdb->get_var("SELECT post_{$field}_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1"); |
| 5588 | 5588 | break; |
@@ -5590,13 +5590,13 @@ discard block |
||
| 5590 | 5590 | $date = $wpdb->get_var("SELECT post_{$field} FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1"); |
| 5591 | 5591 | break; |
| 5592 | 5592 | case 'server': |
| 5593 | - $add_seconds_server = date( 'Z' ); |
|
| 5593 | + $add_seconds_server = date('Z'); |
|
| 5594 | 5594 | $date = $wpdb->get_var("SELECT DATE_ADD(post_{$field}_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1"); |
| 5595 | 5595 | break; |
| 5596 | 5596 | } |
| 5597 | 5597 | |
| 5598 | - if ( $date ) { |
|
| 5599 | - wp_cache_set( $key, $date, 'timeinfo' ); |
|
| 5598 | + if ($date) { |
|
| 5599 | + wp_cache_set($key, $date, 'timeinfo'); |
|
| 5600 | 5600 | } |
| 5601 | 5601 | } |
| 5602 | 5602 | |
@@ -5610,12 +5610,12 @@ discard block |
||
| 5610 | 5610 | * |
| 5611 | 5611 | * @param array $posts Array of post objects, passed by reference. |
| 5612 | 5612 | */ |
| 5613 | -function update_post_cache( &$posts ) { |
|
| 5614 | - if ( ! $posts ) |
|
| 5613 | +function update_post_cache(&$posts) { |
|
| 5614 | + if ( ! $posts) |
|
| 5615 | 5615 | return; |
| 5616 | 5616 | |
| 5617 | - foreach ( $posts as $post ) |
|
| 5618 | - wp_cache_add( $post->ID, $post, 'posts' ); |
|
| 5617 | + foreach ($posts as $post) |
|
| 5618 | + wp_cache_add($post->ID, $post, 'posts'); |
|
| 5619 | 5619 | } |
| 5620 | 5620 | |
| 5621 | 5621 | /** |
@@ -5633,22 +5633,22 @@ discard block |
||
| 5633 | 5633 | * |
| 5634 | 5634 | * @param int|WP_Post $post Post ID or post object to remove from the cache. |
| 5635 | 5635 | */ |
| 5636 | -function clean_post_cache( $post ) { |
|
| 5636 | +function clean_post_cache($post) { |
|
| 5637 | 5637 | global $_wp_suspend_cache_invalidation; |
| 5638 | 5638 | |
| 5639 | - if ( ! empty( $_wp_suspend_cache_invalidation ) ) |
|
| 5639 | + if ( ! empty($_wp_suspend_cache_invalidation)) |
|
| 5640 | 5640 | return; |
| 5641 | 5641 | |
| 5642 | - $post = get_post( $post ); |
|
| 5643 | - if ( empty( $post ) ) |
|
| 5642 | + $post = get_post($post); |
|
| 5643 | + if (empty($post)) |
|
| 5644 | 5644 | return; |
| 5645 | 5645 | |
| 5646 | - wp_cache_delete( $post->ID, 'posts' ); |
|
| 5647 | - wp_cache_delete( $post->ID, 'post_meta' ); |
|
| 5646 | + wp_cache_delete($post->ID, 'posts'); |
|
| 5647 | + wp_cache_delete($post->ID, 'post_meta'); |
|
| 5648 | 5648 | |
| 5649 | - clean_object_term_cache( $post->ID, $post->post_type ); |
|
| 5649 | + clean_object_term_cache($post->ID, $post->post_type); |
|
| 5650 | 5650 | |
| 5651 | - wp_cache_delete( 'wp_get_archives', 'general' ); |
|
| 5651 | + wp_cache_delete('wp_get_archives', 'general'); |
|
| 5652 | 5652 | |
| 5653 | 5653 | /** |
| 5654 | 5654 | * Fires immediately after the given post's cache is cleaned. |
@@ -5658,10 +5658,10 @@ discard block |
||
| 5658 | 5658 | * @param int $post_id Post ID. |
| 5659 | 5659 | * @param WP_Post $post Post object. |
| 5660 | 5660 | */ |
| 5661 | - do_action( 'clean_post_cache', $post->ID, $post ); |
|
| 5661 | + do_action('clean_post_cache', $post->ID, $post); |
|
| 5662 | 5662 | |
| 5663 | - if ( 'page' == $post->post_type ) { |
|
| 5664 | - wp_cache_delete( 'all_page_ids', 'posts' ); |
|
| 5663 | + if ('page' == $post->post_type) { |
|
| 5664 | + wp_cache_delete('all_page_ids', 'posts'); |
|
| 5665 | 5665 | |
| 5666 | 5666 | /** |
| 5667 | 5667 | * Fires immediately after the given page's cache is cleaned. |
@@ -5670,10 +5670,10 @@ discard block |
||
| 5670 | 5670 | * |
| 5671 | 5671 | * @param int $post_id Post ID. |
| 5672 | 5672 | */ |
| 5673 | - do_action( 'clean_page_cache', $post->ID ); |
|
| 5673 | + do_action('clean_page_cache', $post->ID); |
|
| 5674 | 5674 | } |
| 5675 | 5675 | |
| 5676 | - wp_cache_set( 'last_changed', microtime(), 'posts' ); |
|
| 5676 | + wp_cache_set('last_changed', microtime(), 'posts'); |
|
| 5677 | 5677 | } |
| 5678 | 5678 | |
| 5679 | 5679 | /** |
@@ -5686,27 +5686,27 @@ discard block |
||
| 5686 | 5686 | * @param bool $update_term_cache Optional. Whether to update the term cache. Default true. |
| 5687 | 5687 | * @param bool $update_meta_cache Optional. Whether to update the meta cache. Default true. |
| 5688 | 5688 | */ |
| 5689 | -function update_post_caches( &$posts, $post_type = 'post', $update_term_cache = true, $update_meta_cache = true ) { |
|
| 5689 | +function update_post_caches(&$posts, $post_type = 'post', $update_term_cache = true, $update_meta_cache = true) { |
|
| 5690 | 5690 | // No point in doing all this work if we didn't match any posts. |
| 5691 | - if ( !$posts ) |
|
| 5691 | + if ( ! $posts) |
|
| 5692 | 5692 | return; |
| 5693 | 5693 | |
| 5694 | 5694 | update_post_cache($posts); |
| 5695 | 5695 | |
| 5696 | 5696 | $post_ids = array(); |
| 5697 | - foreach ( $posts as $post ) |
|
| 5697 | + foreach ($posts as $post) |
|
| 5698 | 5698 | $post_ids[] = $post->ID; |
| 5699 | 5699 | |
| 5700 | - if ( ! $post_type ) |
|
| 5700 | + if ( ! $post_type) |
|
| 5701 | 5701 | $post_type = 'any'; |
| 5702 | 5702 | |
| 5703 | - if ( $update_term_cache ) { |
|
| 5704 | - if ( is_array($post_type) ) { |
|
| 5703 | + if ($update_term_cache) { |
|
| 5704 | + if (is_array($post_type)) { |
|
| 5705 | 5705 | $ptypes = $post_type; |
| 5706 | - } elseif ( 'any' == $post_type ) { |
|
| 5706 | + } elseif ('any' == $post_type) { |
|
| 5707 | 5707 | $ptypes = array(); |
| 5708 | 5708 | // Just use the post_types in the supplied posts. |
| 5709 | - foreach ( $posts as $post ) { |
|
| 5709 | + foreach ($posts as $post) { |
|
| 5710 | 5710 | $ptypes[] = $post->post_type; |
| 5711 | 5711 | } |
| 5712 | 5712 | $ptypes = array_unique($ptypes); |
@@ -5714,11 +5714,11 @@ discard block |
||
| 5714 | 5714 | $ptypes = array($post_type); |
| 5715 | 5715 | } |
| 5716 | 5716 | |
| 5717 | - if ( ! empty($ptypes) ) |
|
| 5717 | + if ( ! empty($ptypes)) |
|
| 5718 | 5718 | update_object_term_cache($post_ids, $ptypes); |
| 5719 | 5719 | } |
| 5720 | 5720 | |
| 5721 | - if ( $update_meta_cache ) |
|
| 5721 | + if ($update_meta_cache) |
|
| 5722 | 5722 | update_postmeta_cache($post_ids); |
| 5723 | 5723 | } |
| 5724 | 5724 | |
@@ -5735,7 +5735,7 @@ discard block |
||
| 5735 | 5735 | * @return array|false Returns false if there is nothing to update or an array |
| 5736 | 5736 | * of metadata. |
| 5737 | 5737 | */ |
| 5738 | -function update_postmeta_cache( $post_ids ) { |
|
| 5738 | +function update_postmeta_cache($post_ids) { |
|
| 5739 | 5739 | return update_meta_cache('post', $post_ids); |
| 5740 | 5740 | } |
| 5741 | 5741 | |
@@ -5754,10 +5754,10 @@ discard block |
||
| 5754 | 5754 | * @param int $id The attachment ID in the cache to clean. |
| 5755 | 5755 | * @param bool $clean_terms Optional. Whether to clean terms cache. Default false. |
| 5756 | 5756 | */ |
| 5757 | -function clean_attachment_cache( $id, $clean_terms = false ) { |
|
| 5757 | +function clean_attachment_cache($id, $clean_terms = false) { |
|
| 5758 | 5758 | global $_wp_suspend_cache_invalidation; |
| 5759 | 5759 | |
| 5760 | - if ( !empty($_wp_suspend_cache_invalidation) ) |
|
| 5760 | + if ( ! empty($_wp_suspend_cache_invalidation)) |
|
| 5761 | 5761 | return; |
| 5762 | 5762 | |
| 5763 | 5763 | $id = (int) $id; |
@@ -5765,7 +5765,7 @@ discard block |
||
| 5765 | 5765 | wp_cache_delete($id, 'posts'); |
| 5766 | 5766 | wp_cache_delete($id, 'post_meta'); |
| 5767 | 5767 | |
| 5768 | - if ( $clean_terms ) |
|
| 5768 | + if ($clean_terms) |
|
| 5769 | 5769 | clean_object_term_cache($id, 'attachment'); |
| 5770 | 5770 | |
| 5771 | 5771 | /** |
@@ -5775,7 +5775,7 @@ discard block |
||
| 5775 | 5775 | * |
| 5776 | 5776 | * @param int $id Attachment ID. |
| 5777 | 5777 | */ |
| 5778 | - do_action( 'clean_attachment_cache', $id ); |
|
| 5778 | + do_action('clean_attachment_cache', $id); |
|
| 5779 | 5779 | } |
| 5780 | 5780 | |
| 5781 | 5781 | // |
@@ -5795,13 +5795,13 @@ discard block |
||
| 5795 | 5795 | * @param string $old_status Previous post status. |
| 5796 | 5796 | * @param WP_Post $post Post object. |
| 5797 | 5797 | */ |
| 5798 | -function _transition_post_status( $new_status, $old_status, $post ) { |
|
| 5798 | +function _transition_post_status($new_status, $old_status, $post) { |
|
| 5799 | 5799 | global $wpdb; |
| 5800 | 5800 | |
| 5801 | - if ( $old_status != 'publish' && $new_status == 'publish' ) { |
|
| 5801 | + if ($old_status != 'publish' && $new_status == 'publish') { |
|
| 5802 | 5802 | // Reset GUID if transitioning to publish and it is empty. |
| 5803 | - if ( '' == get_the_guid($post->ID) ) |
|
| 5804 | - $wpdb->update( $wpdb->posts, array( 'guid' => get_permalink( $post->ID ) ), array( 'ID' => $post->ID ) ); |
|
| 5803 | + if ('' == get_the_guid($post->ID)) |
|
| 5804 | + $wpdb->update($wpdb->posts, array('guid' => get_permalink($post->ID)), array('ID' => $post->ID)); |
|
| 5805 | 5805 | |
| 5806 | 5806 | /** |
| 5807 | 5807 | * Fires when a post's status is transitioned from private to published. |
@@ -5815,21 +5815,21 @@ discard block |
||
| 5815 | 5815 | } |
| 5816 | 5816 | |
| 5817 | 5817 | // If published posts changed clear the lastpostmodified cache. |
| 5818 | - if ( 'publish' == $new_status || 'publish' == $old_status) { |
|
| 5819 | - foreach ( array( 'server', 'gmt', 'blog' ) as $timezone ) { |
|
| 5820 | - wp_cache_delete( "lastpostmodified:$timezone", 'timeinfo' ); |
|
| 5821 | - wp_cache_delete( "lastpostdate:$timezone", 'timeinfo' ); |
|
| 5822 | - wp_cache_delete( "lastpostdate:$timezone:{$post->post_type}", 'timeinfo' ); |
|
| 5818 | + if ('publish' == $new_status || 'publish' == $old_status) { |
|
| 5819 | + foreach (array('server', 'gmt', 'blog') as $timezone) { |
|
| 5820 | + wp_cache_delete("lastpostmodified:$timezone", 'timeinfo'); |
|
| 5821 | + wp_cache_delete("lastpostdate:$timezone", 'timeinfo'); |
|
| 5822 | + wp_cache_delete("lastpostdate:$timezone:{$post->post_type}", 'timeinfo'); |
|
| 5823 | 5823 | } |
| 5824 | 5824 | } |
| 5825 | 5825 | |
| 5826 | - if ( $new_status !== $old_status ) { |
|
| 5827 | - wp_cache_delete( _count_posts_cache_key( $post->post_type ), 'counts' ); |
|
| 5828 | - wp_cache_delete( _count_posts_cache_key( $post->post_type, 'readable' ), 'counts' ); |
|
| 5826 | + if ($new_status !== $old_status) { |
|
| 5827 | + wp_cache_delete(_count_posts_cache_key($post->post_type), 'counts'); |
|
| 5828 | + wp_cache_delete(_count_posts_cache_key($post->post_type, 'readable'), 'counts'); |
|
| 5829 | 5829 | } |
| 5830 | 5830 | |
| 5831 | 5831 | // Always clears the hook in case the post status bounced from future to draft. |
| 5832 | - wp_clear_scheduled_hook('publish_future_post', array( $post->ID ) ); |
|
| 5832 | + wp_clear_scheduled_hook('publish_future_post', array($post->ID)); |
|
| 5833 | 5833 | } |
| 5834 | 5834 | |
| 5835 | 5835 | /** |
@@ -5846,9 +5846,9 @@ discard block |
||
| 5846 | 5846 | * {@see _future_post_hook()}. |
| 5847 | 5847 | * @param WP_Post $post Post object. |
| 5848 | 5848 | */ |
| 5849 | -function _future_post_hook( $deprecated, $post ) { |
|
| 5850 | - wp_clear_scheduled_hook( 'publish_future_post', array( $post->ID ) ); |
|
| 5851 | - wp_schedule_single_event( strtotime( get_gmt_from_date( $post->post_date ) . ' GMT') , 'publish_future_post', array( $post->ID ) ); |
|
| 5849 | +function _future_post_hook($deprecated, $post) { |
|
| 5850 | + wp_clear_scheduled_hook('publish_future_post', array($post->ID)); |
|
| 5851 | + wp_schedule_single_event(strtotime(get_gmt_from_date($post->post_date).' GMT'), 'publish_future_post', array($post->ID)); |
|
| 5852 | 5852 | } |
| 5853 | 5853 | |
| 5854 | 5854 | /** |
@@ -5861,8 +5861,8 @@ discard block |
||
| 5861 | 5861 | * |
| 5862 | 5862 | * @param int $post_id The ID in the database table of the post being published. |
| 5863 | 5863 | */ |
| 5864 | -function _publish_post_hook( $post_id ) { |
|
| 5865 | - if ( defined( 'XMLRPC_REQUEST' ) ) { |
|
| 5864 | +function _publish_post_hook($post_id) { |
|
| 5865 | + if (defined('XMLRPC_REQUEST')) { |
|
| 5866 | 5866 | /** |
| 5867 | 5867 | * Fires when _publish_post_hook() is called during an XML-RPC request. |
| 5868 | 5868 | * |
@@ -5870,15 +5870,15 @@ discard block |
||
| 5870 | 5870 | * |
| 5871 | 5871 | * @param int $post_id Post ID. |
| 5872 | 5872 | */ |
| 5873 | - do_action( 'xmlrpc_publish_post', $post_id ); |
|
| 5873 | + do_action('xmlrpc_publish_post', $post_id); |
|
| 5874 | 5874 | } |
| 5875 | 5875 | |
| 5876 | - if ( defined('WP_IMPORTING') ) |
|
| 5876 | + if (defined('WP_IMPORTING')) |
|
| 5877 | 5877 | return; |
| 5878 | 5878 | |
| 5879 | - if ( get_option('default_pingback_flag') ) |
|
| 5880 | - add_post_meta( $post_id, '_pingme', '1' ); |
|
| 5881 | - add_post_meta( $post_id, '_encloseme', '1' ); |
|
| 5879 | + if (get_option('default_pingback_flag')) |
|
| 5880 | + add_post_meta($post_id, '_pingme', '1'); |
|
| 5881 | + add_post_meta($post_id, '_encloseme', '1'); |
|
| 5882 | 5882 | |
| 5883 | 5883 | wp_schedule_single_event(time(), 'do_pings'); |
| 5884 | 5884 | } |
@@ -5892,9 +5892,9 @@ discard block |
||
| 5892 | 5892 | * |
| 5893 | 5893 | * @return int|false Post parent ID, otherwise false. |
| 5894 | 5894 | */ |
| 5895 | -function wp_get_post_parent_id( $post_ID ) { |
|
| 5896 | - $post = get_post( $post_ID ); |
|
| 5897 | - if ( !$post || is_wp_error( $post ) ) |
|
| 5895 | +function wp_get_post_parent_id($post_ID) { |
|
| 5896 | + $post = get_post($post_ID); |
|
| 5897 | + if ( ! $post || is_wp_error($post)) |
|
| 5898 | 5898 | return false; |
| 5899 | 5899 | return (int) $post->post_parent; |
| 5900 | 5900 | } |
@@ -5913,30 +5913,30 @@ discard block |
||
| 5913 | 5913 | * @param int $post_ID ID of the post we're checking. |
| 5914 | 5914 | * @return int The new post_parent for the post, 0 otherwise. |
| 5915 | 5915 | */ |
| 5916 | -function wp_check_post_hierarchy_for_loops( $post_parent, $post_ID ) { |
|
| 5916 | +function wp_check_post_hierarchy_for_loops($post_parent, $post_ID) { |
|
| 5917 | 5917 | // Nothing fancy here - bail. |
| 5918 | - if ( !$post_parent ) |
|
| 5918 | + if ( ! $post_parent) |
|
| 5919 | 5919 | return 0; |
| 5920 | 5920 | |
| 5921 | 5921 | // New post can't cause a loop. |
| 5922 | - if ( empty( $post_ID ) ) |
|
| 5922 | + if (empty($post_ID)) |
|
| 5923 | 5923 | return $post_parent; |
| 5924 | 5924 | |
| 5925 | 5925 | // Can't be its own parent. |
| 5926 | - if ( $post_parent == $post_ID ) |
|
| 5926 | + if ($post_parent == $post_ID) |
|
| 5927 | 5927 | return 0; |
| 5928 | 5928 | |
| 5929 | 5929 | // Now look for larger loops. |
| 5930 | - if ( !$loop = wp_find_hierarchy_loop( 'wp_get_post_parent_id', $post_ID, $post_parent ) ) |
|
| 5930 | + if ( ! $loop = wp_find_hierarchy_loop('wp_get_post_parent_id', $post_ID, $post_parent)) |
|
| 5931 | 5931 | return $post_parent; // No loop |
| 5932 | 5932 | |
| 5933 | 5933 | // Setting $post_parent to the given value causes a loop. |
| 5934 | - if ( isset( $loop[$post_ID] ) ) |
|
| 5934 | + if (isset($loop[$post_ID])) |
|
| 5935 | 5935 | return 0; |
| 5936 | 5936 | |
| 5937 | 5937 | // There's a loop, but it doesn't contain $post_ID. Break the loop. |
| 5938 | - foreach ( array_keys( $loop ) as $loop_member ) |
|
| 5939 | - wp_update_post( array( 'ID' => $loop_member, 'post_parent' => 0 ) ); |
|
| 5938 | + foreach (array_keys($loop) as $loop_member) |
|
| 5939 | + wp_update_post(array('ID' => $loop_member, 'post_parent' => 0)); |
|
| 5940 | 5940 | |
| 5941 | 5941 | return $post_parent; |
| 5942 | 5942 | } |
@@ -5950,14 +5950,14 @@ discard block |
||
| 5950 | 5950 | * @param int $thumbnail_id Thumbnail to attach. |
| 5951 | 5951 | * @return int|bool True on success, false on failure. |
| 5952 | 5952 | */ |
| 5953 | -function set_post_thumbnail( $post, $thumbnail_id ) { |
|
| 5954 | - $post = get_post( $post ); |
|
| 5955 | - $thumbnail_id = absint( $thumbnail_id ); |
|
| 5956 | - if ( $post && $thumbnail_id && get_post( $thumbnail_id ) ) { |
|
| 5957 | - if ( wp_get_attachment_image( $thumbnail_id, 'thumbnail' ) ) |
|
| 5958 | - return update_post_meta( $post->ID, '_thumbnail_id', $thumbnail_id ); |
|
| 5953 | +function set_post_thumbnail($post, $thumbnail_id) { |
|
| 5954 | + $post = get_post($post); |
|
| 5955 | + $thumbnail_id = absint($thumbnail_id); |
|
| 5956 | + if ($post && $thumbnail_id && get_post($thumbnail_id)) { |
|
| 5957 | + if (wp_get_attachment_image($thumbnail_id, 'thumbnail')) |
|
| 5958 | + return update_post_meta($post->ID, '_thumbnail_id', $thumbnail_id); |
|
| 5959 | 5959 | else |
| 5960 | - return delete_post_meta( $post->ID, '_thumbnail_id' ); |
|
| 5960 | + return delete_post_meta($post->ID, '_thumbnail_id'); |
|
| 5961 | 5961 | } |
| 5962 | 5962 | return false; |
| 5963 | 5963 | } |
@@ -5970,10 +5970,10 @@ discard block |
||
| 5970 | 5970 | * @param int|WP_Post $post Post ID or post object where thumbnail should be removed from. |
| 5971 | 5971 | * @return bool True on success, false on failure. |
| 5972 | 5972 | */ |
| 5973 | -function delete_post_thumbnail( $post ) { |
|
| 5974 | - $post = get_post( $post ); |
|
| 5975 | - if ( $post ) |
|
| 5976 | - return delete_post_meta( $post->ID, '_thumbnail_id' ); |
|
| 5973 | +function delete_post_thumbnail($post) { |
|
| 5974 | + $post = get_post($post); |
|
| 5975 | + if ($post) |
|
| 5976 | + return delete_post_meta($post->ID, '_thumbnail_id'); |
|
| 5977 | 5977 | return false; |
| 5978 | 5978 | } |
| 5979 | 5979 | |
@@ -5988,10 +5988,10 @@ discard block |
||
| 5988 | 5988 | global $wpdb; |
| 5989 | 5989 | |
| 5990 | 5990 | // Cleanup old auto-drafts more than 7 days old. |
| 5991 | - $old_posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date" ); |
|
| 5992 | - foreach ( (array) $old_posts as $delete ) { |
|
| 5991 | + $old_posts = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date"); |
|
| 5992 | + foreach ((array) $old_posts as $delete) { |
|
| 5993 | 5993 | // Force delete. |
| 5994 | - wp_delete_post( $delete, true ); |
|
| 5994 | + wp_delete_post($delete, true); |
|
| 5995 | 5995 | } |
| 5996 | 5996 | } |
| 5997 | 5997 | |
@@ -6002,23 +6002,23 @@ discard block |
||
| 6002 | 6002 | * |
| 6003 | 6003 | * @param array $posts Array of WP_Post objects. |
| 6004 | 6004 | */ |
| 6005 | -function wp_queue_posts_for_term_meta_lazyload( $posts ) { |
|
| 6005 | +function wp_queue_posts_for_term_meta_lazyload($posts) { |
|
| 6006 | 6006 | $post_type_taxonomies = $term_ids = array(); |
| 6007 | - foreach ( $posts as $post ) { |
|
| 6008 | - if ( ! ( $post instanceof WP_Post ) ) { |
|
| 6007 | + foreach ($posts as $post) { |
|
| 6008 | + if ( ! ($post instanceof WP_Post)) { |
|
| 6009 | 6009 | continue; |
| 6010 | 6010 | } |
| 6011 | 6011 | |
| 6012 | - if ( ! isset( $post_type_taxonomies[ $post->post_type ] ) ) { |
|
| 6013 | - $post_type_taxonomies[ $post->post_type ] = get_object_taxonomies( $post->post_type ); |
|
| 6012 | + if ( ! isset($post_type_taxonomies[$post->post_type])) { |
|
| 6013 | + $post_type_taxonomies[$post->post_type] = get_object_taxonomies($post->post_type); |
|
| 6014 | 6014 | } |
| 6015 | 6015 | |
| 6016 | - foreach ( $post_type_taxonomies[ $post->post_type ] as $taxonomy ) { |
|
| 6016 | + foreach ($post_type_taxonomies[$post->post_type] as $taxonomy) { |
|
| 6017 | 6017 | // Term cache should already be primed by `update_post_term_cache()`. |
| 6018 | - $terms = get_object_term_cache( $post->ID, $taxonomy ); |
|
| 6019 | - if ( false !== $terms ) { |
|
| 6020 | - foreach ( $terms as $term ) { |
|
| 6021 | - if ( ! isset( $term_ids[ $term->term_id ] ) ) { |
|
| 6018 | + $terms = get_object_term_cache($post->ID, $taxonomy); |
|
| 6019 | + if (false !== $terms) { |
|
| 6020 | + foreach ($terms as $term) { |
|
| 6021 | + if ( ! isset($term_ids[$term->term_id])) { |
|
| 6022 | 6022 | $term_ids[] = $term->term_id; |
| 6023 | 6023 | } |
| 6024 | 6024 | } |
@@ -6026,9 +6026,9 @@ discard block |
||
| 6026 | 6026 | } |
| 6027 | 6027 | } |
| 6028 | 6028 | |
| 6029 | - if ( $term_ids ) { |
|
| 6029 | + if ($term_ids) { |
|
| 6030 | 6030 | $lazyloader = wp_metadata_lazyloader(); |
| 6031 | - $lazyloader->queue_objects( 'term', $term_ids ); |
|
| 6031 | + $lazyloader->queue_objects('term', $term_ids); |
|
| 6032 | 6032 | } |
| 6033 | 6033 | } |
| 6034 | 6034 | |
@@ -6045,11 +6045,11 @@ discard block |
||
| 6045 | 6045 | * @param string $old_status Old post status. |
| 6046 | 6046 | * @param WP_Post $post Post object. |
| 6047 | 6047 | */ |
| 6048 | -function _update_term_count_on_transition_post_status( $new_status, $old_status, $post ) { |
|
| 6048 | +function _update_term_count_on_transition_post_status($new_status, $old_status, $post) { |
|
| 6049 | 6049 | // Update counts for the post's terms. |
| 6050 | - foreach ( (array) get_object_taxonomies( $post->post_type ) as $taxonomy ) { |
|
| 6051 | - $tt_ids = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'tt_ids' ) ); |
|
| 6052 | - wp_update_term_count( $tt_ids, $taxonomy ); |
|
| 6050 | + foreach ((array) get_object_taxonomies($post->post_type) as $taxonomy) { |
|
| 6051 | + $tt_ids = wp_get_object_terms($post->ID, $taxonomy, array('fields' => 'tt_ids')); |
|
| 6052 | + wp_update_term_count($tt_ids, $taxonomy); |
|
| 6053 | 6053 | } |
| 6054 | 6054 | } |
| 6055 | 6055 | |
@@ -6067,14 +6067,14 @@ discard block |
||
| 6067 | 6067 | * @param bool $update_term_cache Optional. Whether to update the term cache. Default true. |
| 6068 | 6068 | * @param bool $update_meta_cache Optional. Whether to update the meta cache. Default true. |
| 6069 | 6069 | */ |
| 6070 | -function _prime_post_caches( $ids, $update_term_cache = true, $update_meta_cache = true ) { |
|
| 6070 | +function _prime_post_caches($ids, $update_term_cache = true, $update_meta_cache = true) { |
|
| 6071 | 6071 | global $wpdb; |
| 6072 | 6072 | |
| 6073 | - $non_cached_ids = _get_non_cached_ids( $ids, 'posts' ); |
|
| 6074 | - if ( !empty( $non_cached_ids ) ) { |
|
| 6075 | - $fresh_posts = $wpdb->get_results( sprintf( "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE ID IN (%s)", join( ",", $non_cached_ids ) ) ); |
|
| 6073 | + $non_cached_ids = _get_non_cached_ids($ids, 'posts'); |
|
| 6074 | + if ( ! empty($non_cached_ids)) { |
|
| 6075 | + $fresh_posts = $wpdb->get_results(sprintf("SELECT $wpdb->posts.* FROM $wpdb->posts WHERE ID IN (%s)", join(",", $non_cached_ids))); |
|
| 6076 | 6076 | |
| 6077 | - update_post_caches( $fresh_posts, 'any', $update_term_cache, $update_meta_cache ); |
|
| 6077 | + update_post_caches($fresh_posts, 'any', $update_term_cache, $update_meta_cache); |
|
| 6078 | 6078 | } |
| 6079 | 6079 | } |
| 6080 | 6080 | |
@@ -6092,18 +6092,18 @@ discard block |
||
| 6092 | 6092 | * @param string $post_name Slug. |
| 6093 | 6093 | * @param string $post_ID Optional. Post ID that should be ignored. Default 0. |
| 6094 | 6094 | */ |
| 6095 | -function wp_add_trashed_suffix_to_post_name_for_trashed_posts( $post_name, $post_ID = 0 ) { |
|
| 6096 | - $trashed_posts_with_desired_slug = get_posts( array( |
|
| 6095 | +function wp_add_trashed_suffix_to_post_name_for_trashed_posts($post_name, $post_ID = 0) { |
|
| 6096 | + $trashed_posts_with_desired_slug = get_posts(array( |
|
| 6097 | 6097 | 'name' => $post_name, |
| 6098 | 6098 | 'post_status' => 'trash', |
| 6099 | 6099 | 'post_type' => 'any', |
| 6100 | 6100 | 'nopaging' => true, |
| 6101 | - 'post__not_in' => array( $post_ID ) |
|
| 6102 | - ) ); |
|
| 6101 | + 'post__not_in' => array($post_ID) |
|
| 6102 | + )); |
|
| 6103 | 6103 | |
| 6104 | - if ( ! empty( $trashed_posts_with_desired_slug ) ) { |
|
| 6105 | - foreach ( $trashed_posts_with_desired_slug as $_post ) { |
|
| 6106 | - wp_add_trashed_suffix_to_post_name_for_post( $_post ); |
|
| 6104 | + if ( ! empty($trashed_posts_with_desired_slug)) { |
|
| 6105 | + foreach ($trashed_posts_with_desired_slug as $_post) { |
|
| 6106 | + wp_add_trashed_suffix_to_post_name_for_post($_post); |
|
| 6107 | 6107 | } |
| 6108 | 6108 | } |
| 6109 | 6109 | } |
@@ -6121,17 +6121,17 @@ discard block |
||
| 6121 | 6121 | * |
| 6122 | 6122 | * @param WP_Post $post The post. |
| 6123 | 6123 | */ |
| 6124 | -function wp_add_trashed_suffix_to_post_name_for_post( $post ) { |
|
| 6124 | +function wp_add_trashed_suffix_to_post_name_for_post($post) { |
|
| 6125 | 6125 | global $wpdb; |
| 6126 | 6126 | |
| 6127 | - $post = get_post( $post ); |
|
| 6127 | + $post = get_post($post); |
|
| 6128 | 6128 | |
| 6129 | - if ( strpos( $post->post_name, '-%trashed%' ) ) { |
|
| 6129 | + if (strpos($post->post_name, '-%trashed%')) { |
|
| 6130 | 6130 | return $post->post_name; |
| 6131 | 6131 | } |
| 6132 | - add_post_meta( $post->ID, '_wp_desired_post_slug', $post->post_name ); |
|
| 6133 | - $post_name = _truncate_post_slug( $post->post_name, 190 ) . '-%trashed%'; |
|
| 6134 | - $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) ); |
|
| 6135 | - clean_post_cache( $post->ID ); |
|
| 6132 | + add_post_meta($post->ID, '_wp_desired_post_slug', $post->post_name); |
|
| 6133 | + $post_name = _truncate_post_slug($post->post_name, 190).'-%trashed%'; |
|
| 6134 | + $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $post->ID)); |
|
| 6135 | + clean_post_cache($post->ID); |
|
| 6136 | 6136 | return $post_name; |
| 6137 | 6137 | } |
@@ -220,8 +220,9 @@ discard block |
||
| 220 | 220 | * @return bool True on success, false on failure. |
| 221 | 221 | */ |
| 222 | 222 | function update_attached_file( $attachment_id, $file ) { |
| 223 | - if ( !get_post( $attachment_id ) ) |
|
| 224 | - return false; |
|
| 223 | + if ( !get_post( $attachment_id ) ) { |
|
| 224 | + return false; |
|
| 225 | + } |
|
| 225 | 226 | |
| 226 | 227 | /** |
| 227 | 228 | * Filter the path to the attached file to update. |
@@ -233,11 +234,12 @@ discard block |
||
| 233 | 234 | */ |
| 234 | 235 | $file = apply_filters( 'update_attached_file', $file, $attachment_id ); |
| 235 | 236 | |
| 236 | - if ( $file = _wp_relative_upload_path( $file ) ) |
|
| 237 | - return update_post_meta( $attachment_id, '_wp_attached_file', $file ); |
|
| 238 | - else |
|
| 239 | - return delete_post_meta( $attachment_id, '_wp_attached_file' ); |
|
| 240 | -} |
|
| 237 | + if ( $file = _wp_relative_upload_path( $file ) ) { |
|
| 238 | + return update_post_meta( $attachment_id, '_wp_attached_file', $file ); |
|
| 239 | + } else { |
|
| 240 | + return delete_post_meta( $attachment_id, '_wp_attached_file' ); |
|
| 241 | + } |
|
| 242 | + } |
|
| 241 | 243 | |
| 242 | 244 | /** |
| 243 | 245 | * Return relative path to an uploaded file. |
@@ -344,16 +346,19 @@ discard block |
||
| 344 | 346 | |
| 345 | 347 | $children = get_posts( $r ); |
| 346 | 348 | |
| 347 | - if ( ! $children ) |
|
| 348 | - return $kids; |
|
| 349 | + if ( ! $children ) { |
|
| 350 | + return $kids; |
|
| 351 | + } |
|
| 349 | 352 | |
| 350 | - if ( ! empty( $r['fields'] ) ) |
|
| 351 | - return $children; |
|
| 353 | + if ( ! empty( $r['fields'] ) ) { |
|
| 354 | + return $children; |
|
| 355 | + } |
|
| 352 | 356 | |
| 353 | 357 | update_post_cache($children); |
| 354 | 358 | |
| 355 | - foreach ( $children as $key => $child ) |
|
| 356 | - $kids[$child->ID] = $children[$key]; |
|
| 359 | + foreach ( $children as $key => $child ) { |
|
| 360 | + $kids[$child->ID] = $children[$key]; |
|
| 361 | + } |
|
| 357 | 362 | |
| 358 | 363 | if ( $output == OBJECT ) { |
| 359 | 364 | return $kids; |
@@ -428,8 +433,9 @@ discard block |
||
| 428 | 433 | * When $output is OBJECT, a `WP_Post` instance is returned. |
| 429 | 434 | */ |
| 430 | 435 | function get_post( $post = null, $output = OBJECT, $filter = 'raw' ) { |
| 431 | - if ( empty( $post ) && isset( $GLOBALS['post'] ) ) |
|
| 432 | - $post = $GLOBALS['post']; |
|
| 436 | + if ( empty( $post ) && isset( $GLOBALS['post'] ) ) { |
|
| 437 | + $post = $GLOBALS['post']; |
|
| 438 | + } |
|
| 433 | 439 | |
| 434 | 440 | if ( $post instanceof WP_Post ) { |
| 435 | 441 | $_post = $post; |
@@ -446,15 +452,17 @@ discard block |
||
| 446 | 452 | $_post = WP_Post::get_instance( $post ); |
| 447 | 453 | } |
| 448 | 454 | |
| 449 | - if ( ! $_post ) |
|
| 450 | - return null; |
|
| 455 | + if ( ! $_post ) { |
|
| 456 | + return null; |
|
| 457 | + } |
|
| 451 | 458 | |
| 452 | 459 | $_post = $_post->filter( $filter ); |
| 453 | 460 | |
| 454 | - if ( $output == ARRAY_A ) |
|
| 455 | - return $_post->to_array(); |
|
| 456 | - elseif ( $output == ARRAY_N ) |
|
| 457 | - return array_values( $_post->to_array() ); |
|
| 461 | + if ( $output == ARRAY_A ) { |
|
| 462 | + return $_post->to_array(); |
|
| 463 | + } elseif ( $output == ARRAY_N ) { |
|
| 464 | + return array_values( $_post->to_array() ); |
|
| 465 | + } |
|
| 458 | 466 | |
| 459 | 467 | return $_post; |
| 460 | 468 | } |
@@ -470,8 +478,9 @@ discard block |
||
| 470 | 478 | function get_post_ancestors( $post ) { |
| 471 | 479 | $post = get_post( $post ); |
| 472 | 480 | |
| 473 | - if ( ! $post || empty( $post->post_parent ) || $post->post_parent == $post->ID ) |
|
| 474 | - return array(); |
|
| 481 | + if ( ! $post || empty( $post->post_parent ) || $post->post_parent == $post->ID ) { |
|
| 482 | + return array(); |
|
| 483 | + } |
|
| 475 | 484 | |
| 476 | 485 | $ancestors = array(); |
| 477 | 486 | |
@@ -479,8 +488,9 @@ discard block |
||
| 479 | 488 | |
| 480 | 489 | while ( $ancestor = get_post( $id ) ) { |
| 481 | 490 | // Loop detection: If the ancestor has been seen before, break. |
| 482 | - if ( empty( $ancestor->post_parent ) || ( $ancestor->post_parent == $post->ID ) || in_array( $ancestor->post_parent, $ancestors ) ) |
|
| 483 | - break; |
|
| 491 | + if ( empty( $ancestor->post_parent ) || ( $ancestor->post_parent == $post->ID ) || in_array( $ancestor->post_parent, $ancestors ) ) { |
|
| 492 | + break; |
|
| 493 | + } |
|
| 484 | 494 | |
| 485 | 495 | $id = $ancestors[] = $ancestor->post_parent; |
| 486 | 496 | } |
@@ -511,11 +521,13 @@ discard block |
||
| 511 | 521 | function get_post_field( $field, $post = null, $context = 'display' ) { |
| 512 | 522 | $post = get_post( $post ); |
| 513 | 523 | |
| 514 | - if ( !$post ) |
|
| 515 | - return ''; |
|
| 524 | + if ( !$post ) { |
|
| 525 | + return ''; |
|
| 526 | + } |
|
| 516 | 527 | |
| 517 | - if ( !isset($post->$field) ) |
|
| 518 | - return ''; |
|
| 528 | + if ( !isset($post->$field) ) { |
|
| 529 | + return ''; |
|
| 530 | + } |
|
| 519 | 531 | |
| 520 | 532 | return sanitize_post_field($field, $post->$field, $post->ID, $context); |
| 521 | 533 | } |
@@ -534,8 +546,9 @@ discard block |
||
| 534 | 546 | function get_post_mime_type( $ID = '' ) { |
| 535 | 547 | $post = get_post($ID); |
| 536 | 548 | |
| 537 | - if ( is_object($post) ) |
|
| 538 | - return $post->post_mime_type; |
|
| 549 | + if ( is_object($post) ) { |
|
| 550 | + return $post->post_mime_type; |
|
| 551 | + } |
|
| 539 | 552 | |
| 540 | 553 | return false; |
| 541 | 554 | } |
@@ -554,16 +567,19 @@ discard block |
||
| 554 | 567 | function get_post_status( $ID = '' ) { |
| 555 | 568 | $post = get_post($ID); |
| 556 | 569 | |
| 557 | - if ( !is_object($post) ) |
|
| 558 | - return false; |
|
| 570 | + if ( !is_object($post) ) { |
|
| 571 | + return false; |
|
| 572 | + } |
|
| 559 | 573 | |
| 560 | 574 | if ( 'attachment' == $post->post_type ) { |
| 561 | - if ( 'private' == $post->post_status ) |
|
| 562 | - return 'private'; |
|
| 575 | + if ( 'private' == $post->post_status ) { |
|
| 576 | + return 'private'; |
|
| 577 | + } |
|
| 563 | 578 | |
| 564 | 579 | // Unattached attachments are assumed to be published. |
| 565 | - if ( ( 'inherit' == $post->post_status ) && ( 0 == $post->post_parent) ) |
|
| 566 | - return 'publish'; |
|
| 580 | + if ( ( 'inherit' == $post->post_status ) && ( 0 == $post->post_parent) ) { |
|
| 581 | + return 'publish'; |
|
| 582 | + } |
|
| 567 | 583 | |
| 568 | 584 | // Inherit status from the parent. |
| 569 | 585 | if ( $post->post_parent && ( $post->ID != $post->post_parent ) ) { |
@@ -675,8 +691,9 @@ discard block |
||
| 675 | 691 | function register_post_status( $post_status, $args = array() ) { |
| 676 | 692 | global $wp_post_statuses; |
| 677 | 693 | |
| 678 | - if (!is_array($wp_post_statuses)) |
|
| 679 | - $wp_post_statuses = array(); |
|
| 694 | + if (!is_array($wp_post_statuses)) { |
|
| 695 | + $wp_post_statuses = array(); |
|
| 696 | + } |
|
| 680 | 697 | |
| 681 | 698 | // Args prefixed with an underscore are reserved for internal use. |
| 682 | 699 | $defaults = array( |
@@ -699,38 +716,49 @@ discard block |
||
| 699 | 716 | $args->name = $post_status; |
| 700 | 717 | |
| 701 | 718 | // Set various defaults. |
| 702 | - if ( null === $args->public && null === $args->internal && null === $args->protected && null === $args->private ) |
|
| 703 | - $args->internal = true; |
|
| 719 | + if ( null === $args->public && null === $args->internal && null === $args->protected && null === $args->private ) { |
|
| 720 | + $args->internal = true; |
|
| 721 | + } |
|
| 704 | 722 | |
| 705 | - if ( null === $args->public ) |
|
| 706 | - $args->public = false; |
|
| 723 | + if ( null === $args->public ) { |
|
| 724 | + $args->public = false; |
|
| 725 | + } |
|
| 707 | 726 | |
| 708 | - if ( null === $args->private ) |
|
| 709 | - $args->private = false; |
|
| 727 | + if ( null === $args->private ) { |
|
| 728 | + $args->private = false; |
|
| 729 | + } |
|
| 710 | 730 | |
| 711 | - if ( null === $args->protected ) |
|
| 712 | - $args->protected = false; |
|
| 731 | + if ( null === $args->protected ) { |
|
| 732 | + $args->protected = false; |
|
| 733 | + } |
|
| 713 | 734 | |
| 714 | - if ( null === $args->internal ) |
|
| 715 | - $args->internal = false; |
|
| 735 | + if ( null === $args->internal ) { |
|
| 736 | + $args->internal = false; |
|
| 737 | + } |
|
| 716 | 738 | |
| 717 | - if ( null === $args->publicly_queryable ) |
|
| 718 | - $args->publicly_queryable = $args->public; |
|
| 739 | + if ( null === $args->publicly_queryable ) { |
|
| 740 | + $args->publicly_queryable = $args->public; |
|
| 741 | + } |
|
| 719 | 742 | |
| 720 | - if ( null === $args->exclude_from_search ) |
|
| 721 | - $args->exclude_from_search = $args->internal; |
|
| 743 | + if ( null === $args->exclude_from_search ) { |
|
| 744 | + $args->exclude_from_search = $args->internal; |
|
| 745 | + } |
|
| 722 | 746 | |
| 723 | - if ( null === $args->show_in_admin_all_list ) |
|
| 724 | - $args->show_in_admin_all_list = !$args->internal; |
|
| 747 | + if ( null === $args->show_in_admin_all_list ) { |
|
| 748 | + $args->show_in_admin_all_list = !$args->internal; |
|
| 749 | + } |
|
| 725 | 750 | |
| 726 | - if ( null === $args->show_in_admin_status_list ) |
|
| 727 | - $args->show_in_admin_status_list = !$args->internal; |
|
| 751 | + if ( null === $args->show_in_admin_status_list ) { |
|
| 752 | + $args->show_in_admin_status_list = !$args->internal; |
|
| 753 | + } |
|
| 728 | 754 | |
| 729 | - if ( false === $args->label ) |
|
| 730 | - $args->label = $post_status; |
|
| 755 | + if ( false === $args->label ) { |
|
| 756 | + $args->label = $post_status; |
|
| 757 | + } |
|
| 731 | 758 | |
| 732 | - if ( false === $args->label_count ) |
|
| 733 | - $args->label_count = array( $args->label, $args->label ); |
|
| 759 | + if ( false === $args->label_count ) { |
|
| 760 | + $args->label_count = array( $args->label, $args->label ); |
|
| 761 | + } |
|
| 734 | 762 | |
| 735 | 763 | $wp_post_statuses[$post_status] = $args; |
| 736 | 764 | |
@@ -752,8 +780,9 @@ discard block |
||
| 752 | 780 | function get_post_status_object( $post_status ) { |
| 753 | 781 | global $wp_post_statuses; |
| 754 | 782 | |
| 755 | - if ( empty($wp_post_statuses[$post_status]) ) |
|
| 756 | - return null; |
|
| 783 | + if ( empty($wp_post_statuses[$post_status]) ) { |
|
| 784 | + return null; |
|
| 785 | + } |
|
| 757 | 786 | |
| 758 | 787 | return $wp_post_statuses[$post_status]; |
| 759 | 788 | } |
@@ -796,8 +825,9 @@ discard block |
||
| 796 | 825 | * @return bool Whether post type is hierarchical. |
| 797 | 826 | */ |
| 798 | 827 | function is_post_type_hierarchical( $post_type ) { |
| 799 | - if ( ! post_type_exists( $post_type ) ) |
|
| 800 | - return false; |
|
| 828 | + if ( ! post_type_exists( $post_type ) ) { |
|
| 829 | + return false; |
|
| 830 | + } |
|
| 801 | 831 | |
| 802 | 832 | $post_type = get_post_type_object( $post_type ); |
| 803 | 833 | return $post_type->hierarchical; |
@@ -826,8 +856,9 @@ discard block |
||
| 826 | 856 | * @return string|false Post type on success, false on failure. |
| 827 | 857 | */ |
| 828 | 858 | function get_post_type( $post = null ) { |
| 829 | - if ( $post = get_post( $post ) ) |
|
| 830 | - return $post->post_type; |
|
| 859 | + if ( $post = get_post( $post ) ) { |
|
| 860 | + return $post->post_type; |
|
| 861 | + } |
|
| 831 | 862 | |
| 832 | 863 | return false; |
| 833 | 864 | } |
@@ -1057,36 +1088,44 @@ discard block |
||
| 1057 | 1088 | } |
| 1058 | 1089 | |
| 1059 | 1090 | // If not set, default to the setting for public. |
| 1060 | - if ( null === $args->publicly_queryable ) |
|
| 1061 | - $args->publicly_queryable = $args->public; |
|
| 1091 | + if ( null === $args->publicly_queryable ) { |
|
| 1092 | + $args->publicly_queryable = $args->public; |
|
| 1093 | + } |
|
| 1062 | 1094 | |
| 1063 | 1095 | // If not set, default to the setting for public. |
| 1064 | - if ( null === $args->show_ui ) |
|
| 1065 | - $args->show_ui = $args->public; |
|
| 1096 | + if ( null === $args->show_ui ) { |
|
| 1097 | + $args->show_ui = $args->public; |
|
| 1098 | + } |
|
| 1066 | 1099 | |
| 1067 | 1100 | // If not set, default to the setting for show_ui. |
| 1068 | - if ( null === $args->show_in_menu || ! $args->show_ui ) |
|
| 1069 | - $args->show_in_menu = $args->show_ui; |
|
| 1101 | + if ( null === $args->show_in_menu || ! $args->show_ui ) { |
|
| 1102 | + $args->show_in_menu = $args->show_ui; |
|
| 1103 | + } |
|
| 1070 | 1104 | |
| 1071 | 1105 | // If not set, default to the whether the full UI is shown. |
| 1072 | - if ( null === $args->show_in_admin_bar ) |
|
| 1073 | - $args->show_in_admin_bar = (bool) $args->show_in_menu; |
|
| 1106 | + if ( null === $args->show_in_admin_bar ) { |
|
| 1107 | + $args->show_in_admin_bar = (bool) $args->show_in_menu; |
|
| 1108 | + } |
|
| 1074 | 1109 | |
| 1075 | 1110 | // If not set, default to the setting for public. |
| 1076 | - if ( null === $args->show_in_nav_menus ) |
|
| 1077 | - $args->show_in_nav_menus = $args->public; |
|
| 1111 | + if ( null === $args->show_in_nav_menus ) { |
|
| 1112 | + $args->show_in_nav_menus = $args->public; |
|
| 1113 | + } |
|
| 1078 | 1114 | |
| 1079 | 1115 | // If not set, default to true if not public, false if public. |
| 1080 | - if ( null === $args->exclude_from_search ) |
|
| 1081 | - $args->exclude_from_search = !$args->public; |
|
| 1116 | + if ( null === $args->exclude_from_search ) { |
|
| 1117 | + $args->exclude_from_search = !$args->public; |
|
| 1118 | + } |
|
| 1082 | 1119 | |
| 1083 | 1120 | // Back compat with quirky handling in version 3.0. #14122. |
| 1084 | - if ( empty( $args->capabilities ) && null === $args->map_meta_cap && in_array( $args->capability_type, array( 'post', 'page' ) ) ) |
|
| 1085 | - $args->map_meta_cap = true; |
|
| 1121 | + if ( empty( $args->capabilities ) && null === $args->map_meta_cap && in_array( $args->capability_type, array( 'post', 'page' ) ) ) { |
|
| 1122 | + $args->map_meta_cap = true; |
|
| 1123 | + } |
|
| 1086 | 1124 | |
| 1087 | 1125 | // If not set, default to false. |
| 1088 | - if ( null === $args->map_meta_cap ) |
|
| 1089 | - $args->map_meta_cap = false; |
|
| 1126 | + if ( null === $args->map_meta_cap ) { |
|
| 1127 | + $args->map_meta_cap = false; |
|
| 1128 | + } |
|
| 1090 | 1129 | |
| 1091 | 1130 | // If there's no specified edit link and no UI, remove the edit link. |
| 1092 | 1131 | if ( ! $args->show_ui && ! $has_edit_link ) { |
@@ -1096,8 +1135,9 @@ discard block |
||
| 1096 | 1135 | $args->cap = get_post_type_capabilities( $args ); |
| 1097 | 1136 | unset( $args->capabilities ); |
| 1098 | 1137 | |
| 1099 | - if ( is_array( $args->capability_type ) ) |
|
| 1100 | - $args->capability_type = $args->capability_type[0]; |
|
| 1138 | + if ( is_array( $args->capability_type ) ) { |
|
| 1139 | + $args->capability_type = $args->capability_type[0]; |
|
| 1140 | + } |
|
| 1101 | 1141 | |
| 1102 | 1142 | if ( ! empty( $args->supports ) ) { |
| 1103 | 1143 | add_post_type_support( $post_type, $args->supports ); |
@@ -1108,10 +1148,11 @@ discard block |
||
| 1108 | 1148 | } |
| 1109 | 1149 | |
| 1110 | 1150 | if ( false !== $args->query_var ) { |
| 1111 | - if ( true === $args->query_var ) |
|
| 1112 | - $args->query_var = $post_type; |
|
| 1113 | - else |
|
| 1114 | - $args->query_var = sanitize_title_with_dashes( $args->query_var ); |
|
| 1151 | + if ( true === $args->query_var ) { |
|
| 1152 | + $args->query_var = $post_type; |
|
| 1153 | + } else { |
|
| 1154 | + $args->query_var = sanitize_title_with_dashes( $args->query_var ); |
|
| 1155 | + } |
|
| 1115 | 1156 | |
| 1116 | 1157 | if ( $wp && is_post_type_viewable( $args ) ) { |
| 1117 | 1158 | $wp->add_query_var( $args->query_var ); |
@@ -1119,34 +1160,42 @@ discard block |
||
| 1119 | 1160 | } |
| 1120 | 1161 | |
| 1121 | 1162 | if ( false !== $args->rewrite && ( is_admin() || '' != get_option( 'permalink_structure' ) ) ) { |
| 1122 | - if ( ! is_array( $args->rewrite ) ) |
|
| 1123 | - $args->rewrite = array(); |
|
| 1124 | - if ( empty( $args->rewrite['slug'] ) ) |
|
| 1125 | - $args->rewrite['slug'] = $post_type; |
|
| 1126 | - if ( ! isset( $args->rewrite['with_front'] ) ) |
|
| 1127 | - $args->rewrite['with_front'] = true; |
|
| 1128 | - if ( ! isset( $args->rewrite['pages'] ) ) |
|
| 1129 | - $args->rewrite['pages'] = true; |
|
| 1130 | - if ( ! isset( $args->rewrite['feeds'] ) || ! $args->has_archive ) |
|
| 1131 | - $args->rewrite['feeds'] = (bool) $args->has_archive; |
|
| 1163 | + if ( ! is_array( $args->rewrite ) ) { |
|
| 1164 | + $args->rewrite = array(); |
|
| 1165 | + } |
|
| 1166 | + if ( empty( $args->rewrite['slug'] ) ) { |
|
| 1167 | + $args->rewrite['slug'] = $post_type; |
|
| 1168 | + } |
|
| 1169 | + if ( ! isset( $args->rewrite['with_front'] ) ) { |
|
| 1170 | + $args->rewrite['with_front'] = true; |
|
| 1171 | + } |
|
| 1172 | + if ( ! isset( $args->rewrite['pages'] ) ) { |
|
| 1173 | + $args->rewrite['pages'] = true; |
|
| 1174 | + } |
|
| 1175 | + if ( ! isset( $args->rewrite['feeds'] ) || ! $args->has_archive ) { |
|
| 1176 | + $args->rewrite['feeds'] = (bool) $args->has_archive; |
|
| 1177 | + } |
|
| 1132 | 1178 | if ( ! isset( $args->rewrite['ep_mask'] ) ) { |
| 1133 | - if ( isset( $args->permalink_epmask ) ) |
|
| 1134 | - $args->rewrite['ep_mask'] = $args->permalink_epmask; |
|
| 1135 | - else |
|
| 1136 | - $args->rewrite['ep_mask'] = EP_PERMALINK; |
|
| 1179 | + if ( isset( $args->permalink_epmask ) ) { |
|
| 1180 | + $args->rewrite['ep_mask'] = $args->permalink_epmask; |
|
| 1181 | + } else { |
|
| 1182 | + $args->rewrite['ep_mask'] = EP_PERMALINK; |
|
| 1183 | + } |
|
| 1137 | 1184 | } |
| 1138 | 1185 | |
| 1139 | - if ( $args->hierarchical ) |
|
| 1140 | - add_rewrite_tag( "%$post_type%", '(.+?)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&pagename=" ); |
|
| 1141 | - else |
|
| 1142 | - add_rewrite_tag( "%$post_type%", '([^/]+)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name=" ); |
|
| 1186 | + if ( $args->hierarchical ) { |
|
| 1187 | + add_rewrite_tag( "%$post_type%", '(.+?)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&pagename=" ); |
|
| 1188 | + } else { |
|
| 1189 | + add_rewrite_tag( "%$post_type%", '([^/]+)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name=" ); |
|
| 1190 | + } |
|
| 1143 | 1191 | |
| 1144 | 1192 | if ( $args->has_archive ) { |
| 1145 | 1193 | $archive_slug = $args->has_archive === true ? $args->rewrite['slug'] : $args->has_archive; |
| 1146 | - if ( $args->rewrite['with_front'] ) |
|
| 1147 | - $archive_slug = substr( $wp_rewrite->front, 1 ) . $archive_slug; |
|
| 1148 | - else |
|
| 1149 | - $archive_slug = $wp_rewrite->root . $archive_slug; |
|
| 1194 | + if ( $args->rewrite['with_front'] ) { |
|
| 1195 | + $archive_slug = substr( $wp_rewrite->front, 1 ) . $archive_slug; |
|
| 1196 | + } else { |
|
| 1197 | + $archive_slug = $wp_rewrite->root . $archive_slug; |
|
| 1198 | + } |
|
| 1150 | 1199 | |
| 1151 | 1200 | add_rewrite_rule( "{$archive_slug}/?$", "index.php?post_type=$post_type", 'top' ); |
| 1152 | 1201 | if ( $args->rewrite['feeds'] && $wp_rewrite->feeds ) { |
@@ -1154,8 +1203,9 @@ discard block |
||
| 1154 | 1203 | add_rewrite_rule( "{$archive_slug}/feed/$feeds/?$", "index.php?post_type=$post_type" . '&feed=$matches[1]', 'top' ); |
| 1155 | 1204 | add_rewrite_rule( "{$archive_slug}/$feeds/?$", "index.php?post_type=$post_type" . '&feed=$matches[1]', 'top' ); |
| 1156 | 1205 | } |
| 1157 | - if ( $args->rewrite['pages'] ) |
|
| 1158 | - add_rewrite_rule( "{$archive_slug}/{$wp_rewrite->pagination_base}/([0-9]{1,})/?$", "index.php?post_type=$post_type" . '&paged=$matches[1]', 'top' ); |
|
| 1206 | + if ( $args->rewrite['pages'] ) { |
|
| 1207 | + add_rewrite_rule( "{$archive_slug}/{$wp_rewrite->pagination_base}/([0-9]{1,})/?$", "index.php?post_type=$post_type" . '&paged=$matches[1]', 'top' ); |
|
| 1208 | + } |
|
| 1159 | 1209 | } |
| 1160 | 1210 | |
| 1161 | 1211 | $permastruct_args = $args->rewrite; |
@@ -1164,8 +1214,9 @@ discard block |
||
| 1164 | 1214 | } |
| 1165 | 1215 | |
| 1166 | 1216 | // Register the post type meta box if a custom callback was specified. |
| 1167 | - if ( $args->register_meta_box_cb ) |
|
| 1168 | - add_action( 'add_meta_boxes_' . $post_type, $args->register_meta_box_cb, 10, 1 ); |
|
| 1217 | + if ( $args->register_meta_box_cb ) { |
|
| 1218 | + add_action( 'add_meta_boxes_' . $post_type, $args->register_meta_box_cb, 10, 1 ); |
|
| 1219 | + } |
|
| 1169 | 1220 | |
| 1170 | 1221 | $args->labels = get_post_type_labels( $args ); |
| 1171 | 1222 | $args->label = $args->labels->name; |
@@ -1329,8 +1380,9 @@ discard block |
||
| 1329 | 1380 | * @return object object with all the capabilities as member variables. |
| 1330 | 1381 | */ |
| 1331 | 1382 | function get_post_type_capabilities( $args ) { |
| 1332 | - if ( ! is_array( $args->capability_type ) ) |
|
| 1333 | - $args->capability_type = array( $args->capability_type, $args->capability_type . 's' ); |
|
| 1383 | + if ( ! is_array( $args->capability_type ) ) { |
|
| 1384 | + $args->capability_type = array( $args->capability_type, $args->capability_type . 's' ); |
|
| 1385 | + } |
|
| 1334 | 1386 | |
| 1335 | 1387 | // Singular base for meta capabilities, plural base for primitive capabilities. |
| 1336 | 1388 | list( $singular_base, $plural_base ) = $args->capability_type; |
@@ -1364,12 +1416,14 @@ discard block |
||
| 1364 | 1416 | $capabilities = array_merge( $default_capabilities, $args->capabilities ); |
| 1365 | 1417 | |
| 1366 | 1418 | // Post creation capability simply maps to edit_posts by default: |
| 1367 | - if ( ! isset( $capabilities['create_posts'] ) ) |
|
| 1368 | - $capabilities['create_posts'] = $capabilities['edit_posts']; |
|
| 1419 | + if ( ! isset( $capabilities['create_posts'] ) ) { |
|
| 1420 | + $capabilities['create_posts'] = $capabilities['edit_posts']; |
|
| 1421 | + } |
|
| 1369 | 1422 | |
| 1370 | 1423 | // Remember meta capabilities for future reference. |
| 1371 | - if ( $args->map_meta_cap ) |
|
| 1372 | - _post_type_meta_capabilities( $capabilities ); |
|
| 1424 | + if ( $args->map_meta_cap ) { |
|
| 1425 | + _post_type_meta_capabilities( $capabilities ); |
|
| 1426 | + } |
|
| 1373 | 1427 | |
| 1374 | 1428 | return (object) $capabilities; |
| 1375 | 1429 | } |
@@ -1509,20 +1563,25 @@ discard block |
||
| 1509 | 1563 | function _get_custom_object_labels( $object, $nohier_vs_hier_defaults ) { |
| 1510 | 1564 | $object->labels = (array) $object->labels; |
| 1511 | 1565 | |
| 1512 | - if ( isset( $object->label ) && empty( $object->labels['name'] ) ) |
|
| 1513 | - $object->labels['name'] = $object->label; |
|
| 1566 | + if ( isset( $object->label ) && empty( $object->labels['name'] ) ) { |
|
| 1567 | + $object->labels['name'] = $object->label; |
|
| 1568 | + } |
|
| 1514 | 1569 | |
| 1515 | - if ( !isset( $object->labels['singular_name'] ) && isset( $object->labels['name'] ) ) |
|
| 1516 | - $object->labels['singular_name'] = $object->labels['name']; |
|
| 1570 | + if ( !isset( $object->labels['singular_name'] ) && isset( $object->labels['name'] ) ) { |
|
| 1571 | + $object->labels['singular_name'] = $object->labels['name']; |
|
| 1572 | + } |
|
| 1517 | 1573 | |
| 1518 | - if ( ! isset( $object->labels['name_admin_bar'] ) ) |
|
| 1519 | - $object->labels['name_admin_bar'] = isset( $object->labels['singular_name'] ) ? $object->labels['singular_name'] : $object->name; |
|
| 1574 | + if ( ! isset( $object->labels['name_admin_bar'] ) ) { |
|
| 1575 | + $object->labels['name_admin_bar'] = isset( $object->labels['singular_name'] ) ? $object->labels['singular_name'] : $object->name; |
|
| 1576 | + } |
|
| 1520 | 1577 | |
| 1521 | - if ( !isset( $object->labels['menu_name'] ) && isset( $object->labels['name'] ) ) |
|
| 1522 | - $object->labels['menu_name'] = $object->labels['name']; |
|
| 1578 | + if ( !isset( $object->labels['menu_name'] ) && isset( $object->labels['name'] ) ) { |
|
| 1579 | + $object->labels['menu_name'] = $object->labels['name']; |
|
| 1580 | + } |
|
| 1523 | 1581 | |
| 1524 | - if ( !isset( $object->labels['all_items'] ) && isset( $object->labels['menu_name'] ) ) |
|
| 1525 | - $object->labels['all_items'] = $object->labels['menu_name']; |
|
| 1582 | + if ( !isset( $object->labels['all_items'] ) && isset( $object->labels['menu_name'] ) ) { |
|
| 1583 | + $object->labels['all_items'] = $object->labels['menu_name']; |
|
| 1584 | + } |
|
| 1526 | 1585 | |
| 1527 | 1586 | if ( !isset( $object->labels['archives'] ) && isset( $object->labels['all_items'] ) ) { |
| 1528 | 1587 | $object->labels['archives'] = $object->labels['all_items']; |
@@ -1548,8 +1607,9 @@ discard block |
||
| 1548 | 1607 | foreach ( get_post_types( array( 'show_ui' => true ) ) as $ptype ) { |
| 1549 | 1608 | $ptype_obj = get_post_type_object( $ptype ); |
| 1550 | 1609 | // Sub-menus only. |
| 1551 | - if ( ! $ptype_obj->show_in_menu || $ptype_obj->show_in_menu === true ) |
|
| 1552 | - continue; |
|
| 1610 | + if ( ! $ptype_obj->show_in_menu || $ptype_obj->show_in_menu === true ) { |
|
| 1611 | + continue; |
|
| 1612 | + } |
|
| 1553 | 1613 | add_submenu_page( $ptype_obj->show_in_menu, $ptype_obj->labels->name, $ptype_obj->labels->all_items, $ptype_obj->cap->edit_posts, "edit.php?post_type=$ptype" ); |
| 1554 | 1614 | } |
| 1555 | 1615 | } |
@@ -1579,10 +1639,11 @@ discard block |
||
| 1579 | 1639 | |
| 1580 | 1640 | $features = (array) $feature; |
| 1581 | 1641 | foreach ($features as $feature) { |
| 1582 | - if ( func_num_args() == 2 ) |
|
| 1583 | - $_wp_post_type_features[$post_type][$feature] = true; |
|
| 1584 | - else |
|
| 1585 | - $_wp_post_type_features[$post_type][$feature] = array_slice( func_get_args(), 2 ); |
|
| 1642 | + if ( func_num_args() == 2 ) { |
|
| 1643 | + $_wp_post_type_features[$post_type][$feature] = true; |
|
| 1644 | + } else { |
|
| 1645 | + $_wp_post_type_features[$post_type][$feature] = array_slice( func_get_args(), 2 ); |
|
| 1646 | + } |
|
| 1586 | 1647 | } |
| 1587 | 1648 | } |
| 1588 | 1649 | |
@@ -1615,8 +1676,9 @@ discard block |
||
| 1615 | 1676 | function get_all_post_type_supports( $post_type ) { |
| 1616 | 1677 | global $_wp_post_type_features; |
| 1617 | 1678 | |
| 1618 | - if ( isset( $_wp_post_type_features[$post_type] ) ) |
|
| 1619 | - return $_wp_post_type_features[$post_type]; |
|
| 1679 | + if ( isset( $_wp_post_type_features[$post_type] ) ) { |
|
| 1680 | + return $_wp_post_type_features[$post_type]; |
|
| 1681 | + } |
|
| 1620 | 1682 | |
| 1621 | 1683 | return array(); |
| 1622 | 1684 | } |
@@ -1743,18 +1805,22 @@ discard block |
||
| 1743 | 1805 | ); |
| 1744 | 1806 | |
| 1745 | 1807 | $r = wp_parse_args( $args, $defaults ); |
| 1746 | - if ( empty( $r['post_status'] ) ) |
|
| 1747 | - $r['post_status'] = ( 'attachment' == $r['post_type'] ) ? 'inherit' : 'publish'; |
|
| 1748 | - if ( ! empty($r['numberposts']) && empty($r['posts_per_page']) ) |
|
| 1749 | - $r['posts_per_page'] = $r['numberposts']; |
|
| 1750 | - if ( ! empty($r['category']) ) |
|
| 1751 | - $r['cat'] = $r['category']; |
|
| 1808 | + if ( empty( $r['post_status'] ) ) { |
|
| 1809 | + $r['post_status'] = ( 'attachment' == $r['post_type'] ) ? 'inherit' : 'publish'; |
|
| 1810 | + } |
|
| 1811 | + if ( ! empty($r['numberposts']) && empty($r['posts_per_page']) ) { |
|
| 1812 | + $r['posts_per_page'] = $r['numberposts']; |
|
| 1813 | + } |
|
| 1814 | + if ( ! empty($r['category']) ) { |
|
| 1815 | + $r['cat'] = $r['category']; |
|
| 1816 | + } |
|
| 1752 | 1817 | if ( ! empty($r['include']) ) { |
| 1753 | 1818 | $incposts = wp_parse_id_list( $r['include'] ); |
| 1754 | 1819 | $r['posts_per_page'] = count($incposts); // only the number of posts included |
| 1755 | 1820 | $r['post__in'] = $incposts; |
| 1756 | - } elseif ( ! empty($r['exclude']) ) |
|
| 1757 | - $r['post__not_in'] = wp_parse_id_list( $r['exclude'] ); |
|
| 1821 | + } elseif ( ! empty($r['exclude']) ) { |
|
| 1822 | + $r['post__not_in'] = wp_parse_id_list( $r['exclude'] ); |
|
| 1823 | + } |
|
| 1758 | 1824 | |
| 1759 | 1825 | $r['ignore_sticky_posts'] = true; |
| 1760 | 1826 | $r['no_found_rows'] = true; |
@@ -1784,8 +1850,9 @@ discard block |
||
| 1784 | 1850 | */ |
| 1785 | 1851 | function add_post_meta( $post_id, $meta_key, $meta_value, $unique = false ) { |
| 1786 | 1852 | // Make sure meta is added to the post, not a revision. |
| 1787 | - if ( $the_post = wp_is_post_revision($post_id) ) |
|
| 1788 | - $post_id = $the_post; |
|
| 1853 | + if ( $the_post = wp_is_post_revision($post_id) ) { |
|
| 1854 | + $post_id = $the_post; |
|
| 1855 | + } |
|
| 1789 | 1856 | |
| 1790 | 1857 | return add_metadata('post', $post_id, $meta_key, $meta_value, $unique); |
| 1791 | 1858 | } |
@@ -1807,8 +1874,9 @@ discard block |
||
| 1807 | 1874 | */ |
| 1808 | 1875 | function delete_post_meta( $post_id, $meta_key, $meta_value = '' ) { |
| 1809 | 1876 | // Make sure meta is added to the post, not a revision. |
| 1810 | - if ( $the_post = wp_is_post_revision($post_id) ) |
|
| 1811 | - $post_id = $the_post; |
|
| 1877 | + if ( $the_post = wp_is_post_revision($post_id) ) { |
|
| 1878 | + $post_id = $the_post; |
|
| 1879 | + } |
|
| 1812 | 1880 | |
| 1813 | 1881 | return delete_metadata('post', $post_id, $meta_key, $meta_value); |
| 1814 | 1882 | } |
@@ -1849,8 +1917,9 @@ discard block |
||
| 1849 | 1917 | */ |
| 1850 | 1918 | function update_post_meta( $post_id, $meta_key, $meta_value, $prev_value = '' ) { |
| 1851 | 1919 | // Make sure meta is added to the post, not a revision. |
| 1852 | - if ( $the_post = wp_is_post_revision($post_id) ) |
|
| 1853 | - $post_id = $the_post; |
|
| 1920 | + if ( $the_post = wp_is_post_revision($post_id) ) { |
|
| 1921 | + $post_id = $the_post; |
|
| 1922 | + } |
|
| 1854 | 1923 | |
| 1855 | 1924 | return update_metadata('post', $post_id, $meta_key, $meta_value, $prev_value); |
| 1856 | 1925 | } |
@@ -1880,8 +1949,9 @@ discard block |
||
| 1880 | 1949 | */ |
| 1881 | 1950 | function get_post_custom( $post_id = 0 ) { |
| 1882 | 1951 | $post_id = absint( $post_id ); |
| 1883 | - if ( ! $post_id ) |
|
| 1884 | - $post_id = get_the_ID(); |
|
| 1952 | + if ( ! $post_id ) { |
|
| 1953 | + $post_id = get_the_ID(); |
|
| 1954 | + } |
|
| 1885 | 1955 | |
| 1886 | 1956 | return get_post_meta( $post_id ); |
| 1887 | 1957 | } |
@@ -1899,12 +1969,14 @@ discard block |
||
| 1899 | 1969 | function get_post_custom_keys( $post_id = 0 ) { |
| 1900 | 1970 | $custom = get_post_custom( $post_id ); |
| 1901 | 1971 | |
| 1902 | - if ( !is_array($custom) ) |
|
| 1903 | - return; |
|
| 1972 | + if ( !is_array($custom) ) { |
|
| 1973 | + return; |
|
| 1974 | + } |
|
| 1904 | 1975 | |
| 1905 | - if ( $keys = array_keys($custom) ) |
|
| 1906 | - return $keys; |
|
| 1907 | -} |
|
| 1976 | + if ( $keys = array_keys($custom) ) { |
|
| 1977 | + return $keys; |
|
| 1978 | + } |
|
| 1979 | + } |
|
| 1908 | 1980 | |
| 1909 | 1981 | /** |
| 1910 | 1982 | * Retrieve values for a custom post field. |
@@ -1919,8 +1991,9 @@ discard block |
||
| 1919 | 1991 | * @return array|null Meta field values. |
| 1920 | 1992 | */ |
| 1921 | 1993 | function get_post_custom_values( $key = '', $post_id = 0 ) { |
| 1922 | - if ( !$key ) |
|
| 1923 | - return null; |
|
| 1994 | + if ( !$key ) { |
|
| 1995 | + return null; |
|
| 1996 | + } |
|
| 1924 | 1997 | |
| 1925 | 1998 | $custom = get_post_custom($post_id); |
| 1926 | 1999 | |
@@ -1941,16 +2014,19 @@ discard block |
||
| 1941 | 2014 | function is_sticky( $post_id = 0 ) { |
| 1942 | 2015 | $post_id = absint( $post_id ); |
| 1943 | 2016 | |
| 1944 | - if ( ! $post_id ) |
|
| 1945 | - $post_id = get_the_ID(); |
|
| 2017 | + if ( ! $post_id ) { |
|
| 2018 | + $post_id = get_the_ID(); |
|
| 2019 | + } |
|
| 1946 | 2020 | |
| 1947 | 2021 | $stickies = get_option( 'sticky_posts' ); |
| 1948 | 2022 | |
| 1949 | - if ( ! is_array( $stickies ) ) |
|
| 1950 | - return false; |
|
| 2023 | + if ( ! is_array( $stickies ) ) { |
|
| 2024 | + return false; |
|
| 2025 | + } |
|
| 1951 | 2026 | |
| 1952 | - if ( in_array( $post_id, $stickies ) ) |
|
| 1953 | - return true; |
|
| 2027 | + if ( in_array( $post_id, $stickies ) ) { |
|
| 2028 | + return true; |
|
| 2029 | + } |
|
| 1954 | 2030 | |
| 1955 | 2031 | return false; |
| 1956 | 2032 | } |
@@ -1975,21 +2051,27 @@ discard block |
||
| 1975 | 2051 | function sanitize_post( $post, $context = 'display' ) { |
| 1976 | 2052 | if ( is_object($post) ) { |
| 1977 | 2053 | // Check if post already filtered for this context. |
| 1978 | - if ( isset($post->filter) && $context == $post->filter ) |
|
| 1979 | - return $post; |
|
| 1980 | - if ( !isset($post->ID) ) |
|
| 1981 | - $post->ID = 0; |
|
| 1982 | - foreach ( array_keys(get_object_vars($post)) as $field ) |
|
| 1983 | - $post->$field = sanitize_post_field($field, $post->$field, $post->ID, $context); |
|
| 2054 | + if ( isset($post->filter) && $context == $post->filter ) { |
|
| 2055 | + return $post; |
|
| 2056 | + } |
|
| 2057 | + if ( !isset($post->ID) ) { |
|
| 2058 | + $post->ID = 0; |
|
| 2059 | + } |
|
| 2060 | + foreach ( array_keys(get_object_vars($post)) as $field ) { |
|
| 2061 | + $post->$field = sanitize_post_field($field, $post->$field, $post->ID, $context); |
|
| 2062 | + } |
|
| 1984 | 2063 | $post->filter = $context; |
| 1985 | 2064 | } elseif ( is_array( $post ) ) { |
| 1986 | 2065 | // Check if post already filtered for this context. |
| 1987 | - if ( isset($post['filter']) && $context == $post['filter'] ) |
|
| 1988 | - return $post; |
|
| 1989 | - if ( !isset($post['ID']) ) |
|
| 1990 | - $post['ID'] = 0; |
|
| 1991 | - foreach ( array_keys($post) as $field ) |
|
| 1992 | - $post[$field] = sanitize_post_field($field, $post[$field], $post['ID'], $context); |
|
| 2066 | + if ( isset($post['filter']) && $context == $post['filter'] ) { |
|
| 2067 | + return $post; |
|
| 2068 | + } |
|
| 2069 | + if ( !isset($post['ID']) ) { |
|
| 2070 | + $post['ID'] = 0; |
|
| 2071 | + } |
|
| 2072 | + foreach ( array_keys($post) as $field ) { |
|
| 2073 | + $post[$field] = sanitize_post_field($field, $post[$field], $post['ID'], $context); |
|
| 2074 | + } |
|
| 1993 | 2075 | $post['filter'] = $context; |
| 1994 | 2076 | } |
| 1995 | 2077 | return $post; |
@@ -2014,8 +2096,9 @@ discard block |
||
| 2014 | 2096 | */ |
| 2015 | 2097 | function sanitize_post_field( $field, $value, $post_id, $context = 'display' ) { |
| 2016 | 2098 | $int_fields = array('ID', 'post_parent', 'menu_order'); |
| 2017 | - if ( in_array($field, $int_fields) ) |
|
| 2018 | - $value = (int) $value; |
|
| 2099 | + if ( in_array($field, $int_fields) ) { |
|
| 2100 | + $value = (int) $value; |
|
| 2101 | + } |
|
| 2019 | 2102 | |
| 2020 | 2103 | // Fields which contain arrays of integers. |
| 2021 | 2104 | $array_int_fields = array( 'ancestors' ); |
@@ -2024,8 +2107,9 @@ discard block |
||
| 2024 | 2107 | return $value; |
| 2025 | 2108 | } |
| 2026 | 2109 | |
| 2027 | - if ( 'raw' == $context ) |
|
| 2028 | - return $value; |
|
| 2110 | + if ( 'raw' == $context ) { |
|
| 2111 | + return $value; |
|
| 2112 | + } |
|
| 2029 | 2113 | |
| 2030 | 2114 | $prefixed = false; |
| 2031 | 2115 | if ( false !== strpos($field, 'post_') ) { |
@@ -2068,10 +2152,11 @@ discard block |
||
| 2068 | 2152 | } |
| 2069 | 2153 | |
| 2070 | 2154 | if ( in_array($field, $format_to_edit) ) { |
| 2071 | - if ( 'post_content' == $field ) |
|
| 2072 | - $value = format_to_edit($value, user_can_richedit()); |
|
| 2073 | - else |
|
| 2074 | - $value = format_to_edit($value); |
|
| 2155 | + if ( 'post_content' == $field ) { |
|
| 2156 | + $value = format_to_edit($value, user_can_richedit()); |
|
| 2157 | + } else { |
|
| 2158 | + $value = format_to_edit($value); |
|
| 2159 | + } |
|
| 2075 | 2160 | } else { |
| 2076 | 2161 | $value = esc_attr($value); |
| 2077 | 2162 | } |
@@ -2141,10 +2226,11 @@ discard block |
||
| 2141 | 2226 | } |
| 2142 | 2227 | } |
| 2143 | 2228 | |
| 2144 | - if ( 'attribute' == $context ) |
|
| 2145 | - $value = esc_attr($value); |
|
| 2146 | - elseif ( 'js' == $context ) |
|
| 2147 | - $value = esc_js($value); |
|
| 2229 | + if ( 'attribute' == $context ) { |
|
| 2230 | + $value = esc_attr($value); |
|
| 2231 | + } elseif ( 'js' == $context ) { |
|
| 2232 | + $value = esc_js($value); |
|
| 2233 | + } |
|
| 2148 | 2234 | |
| 2149 | 2235 | return $value; |
| 2150 | 2236 | } |
@@ -2161,11 +2247,13 @@ discard block |
||
| 2161 | 2247 | function stick_post( $post_id ) { |
| 2162 | 2248 | $stickies = get_option('sticky_posts'); |
| 2163 | 2249 | |
| 2164 | - if ( !is_array($stickies) ) |
|
| 2165 | - $stickies = array($post_id); |
|
| 2250 | + if ( !is_array($stickies) ) { |
|
| 2251 | + $stickies = array($post_id); |
|
| 2252 | + } |
|
| 2166 | 2253 | |
| 2167 | - if ( ! in_array($post_id, $stickies) ) |
|
| 2168 | - $stickies[] = $post_id; |
|
| 2254 | + if ( ! in_array($post_id, $stickies) ) { |
|
| 2255 | + $stickies[] = $post_id; |
|
| 2256 | + } |
|
| 2169 | 2257 | |
| 2170 | 2258 | update_option('sticky_posts', $stickies); |
| 2171 | 2259 | } |
@@ -2182,15 +2270,18 @@ discard block |
||
| 2182 | 2270 | function unstick_post( $post_id ) { |
| 2183 | 2271 | $stickies = get_option('sticky_posts'); |
| 2184 | 2272 | |
| 2185 | - if ( !is_array($stickies) ) |
|
| 2186 | - return; |
|
| 2273 | + if ( !is_array($stickies) ) { |
|
| 2274 | + return; |
|
| 2275 | + } |
|
| 2187 | 2276 | |
| 2188 | - if ( ! in_array($post_id, $stickies) ) |
|
| 2189 | - return; |
|
| 2277 | + if ( ! in_array($post_id, $stickies) ) { |
|
| 2278 | + return; |
|
| 2279 | + } |
|
| 2190 | 2280 | |
| 2191 | 2281 | $offset = array_search($post_id, $stickies); |
| 2192 | - if ( false === $offset ) |
|
| 2193 | - return; |
|
| 2282 | + if ( false === $offset ) { |
|
| 2283 | + return; |
|
| 2284 | + } |
|
| 2194 | 2285 | |
| 2195 | 2286 | array_splice($stickies, $offset, 1); |
| 2196 | 2287 | |
@@ -2239,8 +2330,9 @@ discard block |
||
| 2239 | 2330 | function wp_count_posts( $type = 'post', $perm = '' ) { |
| 2240 | 2331 | global $wpdb; |
| 2241 | 2332 | |
| 2242 | - if ( ! post_type_exists( $type ) ) |
|
| 2243 | - return new stdClass; |
|
| 2333 | + if ( ! post_type_exists( $type ) ) { |
|
| 2334 | + return new stdClass; |
|
| 2335 | + } |
|
| 2244 | 2336 | |
| 2245 | 2337 | $cache_key = _count_posts_cache_key( $type, $perm ); |
| 2246 | 2338 | |
@@ -2415,8 +2507,9 @@ discard block |
||
| 2415 | 2507 | function wp_post_mime_type_where( $post_mime_types, $table_alias = '' ) { |
| 2416 | 2508 | $where = ''; |
| 2417 | 2509 | $wildcards = array('', '%', '%/%'); |
| 2418 | - if ( is_string($post_mime_types) ) |
|
| 2419 | - $post_mime_types = array_map('trim', explode(',', $post_mime_types)); |
|
| 2510 | + if ( is_string($post_mime_types) ) { |
|
| 2511 | + $post_mime_types = array_map('trim', explode(',', $post_mime_types)); |
|
| 2512 | + } |
|
| 2420 | 2513 | |
| 2421 | 2514 | $wheres = array(); |
| 2422 | 2515 | |
@@ -2426,29 +2519,34 @@ discard block |
||
| 2426 | 2519 | if ( false !== $slashpos ) { |
| 2427 | 2520 | $mime_group = preg_replace('/[^-*.a-zA-Z0-9]/', '', substr($mime_type, 0, $slashpos)); |
| 2428 | 2521 | $mime_subgroup = preg_replace('/[^-*.+a-zA-Z0-9]/', '', substr($mime_type, $slashpos + 1)); |
| 2429 | - if ( empty($mime_subgroup) ) |
|
| 2430 | - $mime_subgroup = '*'; |
|
| 2431 | - else |
|
| 2432 | - $mime_subgroup = str_replace('/', '', $mime_subgroup); |
|
| 2522 | + if ( empty($mime_subgroup) ) { |
|
| 2523 | + $mime_subgroup = '*'; |
|
| 2524 | + } else { |
|
| 2525 | + $mime_subgroup = str_replace('/', '', $mime_subgroup); |
|
| 2526 | + } |
|
| 2433 | 2527 | $mime_pattern = "$mime_group/$mime_subgroup"; |
| 2434 | 2528 | } else { |
| 2435 | 2529 | $mime_pattern = preg_replace('/[^-*.a-zA-Z0-9]/', '', $mime_type); |
| 2436 | - if ( false === strpos($mime_pattern, '*') ) |
|
| 2437 | - $mime_pattern .= '/*'; |
|
| 2530 | + if ( false === strpos($mime_pattern, '*') ) { |
|
| 2531 | + $mime_pattern .= '/*'; |
|
| 2532 | + } |
|
| 2438 | 2533 | } |
| 2439 | 2534 | |
| 2440 | 2535 | $mime_pattern = preg_replace('/\*+/', '%', $mime_pattern); |
| 2441 | 2536 | |
| 2442 | - if ( in_array( $mime_type, $wildcards ) ) |
|
| 2443 | - return ''; |
|
| 2537 | + if ( in_array( $mime_type, $wildcards ) ) { |
|
| 2538 | + return ''; |
|
| 2539 | + } |
|
| 2444 | 2540 | |
| 2445 | - if ( false !== strpos($mime_pattern, '%') ) |
|
| 2446 | - $wheres[] = empty($table_alias) ? "post_mime_type LIKE '$mime_pattern'" : "$table_alias.post_mime_type LIKE '$mime_pattern'"; |
|
| 2447 | - else |
|
| 2448 | - $wheres[] = empty($table_alias) ? "post_mime_type = '$mime_pattern'" : "$table_alias.post_mime_type = '$mime_pattern'"; |
|
| 2541 | + if ( false !== strpos($mime_pattern, '%') ) { |
|
| 2542 | + $wheres[] = empty($table_alias) ? "post_mime_type LIKE '$mime_pattern'" : "$table_alias.post_mime_type LIKE '$mime_pattern'"; |
|
| 2543 | + } else { |
|
| 2544 | + $wheres[] = empty($table_alias) ? "post_mime_type = '$mime_pattern'" : "$table_alias.post_mime_type = '$mime_pattern'"; |
|
| 2545 | + } |
|
| 2546 | + } |
|
| 2547 | + if ( !empty($wheres) ) { |
|
| 2548 | + $where = ' AND (' . join(' OR ', $wheres) . ') '; |
|
| 2449 | 2549 | } |
| 2450 | - if ( !empty($wheres) ) |
|
| 2451 | - $where = ' AND (' . join(' OR ', $wheres) . ') '; |
|
| 2452 | 2550 | return $where; |
| 2453 | 2551 | } |
| 2454 | 2552 | |
@@ -2476,14 +2574,17 @@ discard block |
||
| 2476 | 2574 | function wp_delete_post( $postid = 0, $force_delete = false ) { |
| 2477 | 2575 | global $wpdb; |
| 2478 | 2576 | |
| 2479 | - if ( !$post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d", $postid)) ) |
|
| 2480 | - return $post; |
|
| 2577 | + if ( !$post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d", $postid)) ) { |
|
| 2578 | + return $post; |
|
| 2579 | + } |
|
| 2481 | 2580 | |
| 2482 | - if ( !$force_delete && ( $post->post_type == 'post' || $post->post_type == 'page') && get_post_status( $postid ) != 'trash' && EMPTY_TRASH_DAYS ) |
|
| 2483 | - return wp_trash_post( $postid ); |
|
| 2581 | + if ( !$force_delete && ( $post->post_type == 'post' || $post->post_type == 'page') && get_post_status( $postid ) != 'trash' && EMPTY_TRASH_DAYS ) { |
|
| 2582 | + return wp_trash_post( $postid ); |
|
| 2583 | + } |
|
| 2484 | 2584 | |
| 2485 | - if ( $post->post_type == 'attachment' ) |
|
| 2486 | - return wp_delete_attachment( $postid, $force_delete ); |
|
| 2585 | + if ( $post->post_type == 'attachment' ) { |
|
| 2586 | + return wp_delete_attachment( $postid, $force_delete ); |
|
| 2587 | + } |
|
| 2487 | 2588 | |
| 2488 | 2589 | /** |
| 2489 | 2590 | * Filter whether a post deletion should take place. |
@@ -2530,8 +2631,9 @@ discard block |
||
| 2530 | 2631 | // Do raw query. wp_get_post_revisions() is filtered. |
| 2531 | 2632 | $revision_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'revision'", $postid ) ); |
| 2532 | 2633 | // Use wp_delete_post (via wp_delete_post_revision) again. Ensures any meta/misplaced data gets cleaned up. |
| 2533 | - foreach ( $revision_ids as $revision_id ) |
|
| 2534 | - wp_delete_post_revision( $revision_id ); |
|
| 2634 | + foreach ( $revision_ids as $revision_id ) { |
|
| 2635 | + wp_delete_post_revision( $revision_id ); |
|
| 2636 | + } |
|
| 2535 | 2637 | |
| 2536 | 2638 | // Point all attachments to this post up one level. |
| 2537 | 2639 | $wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => 'attachment' ) ); |
@@ -2546,8 +2648,9 @@ discard block |
||
| 2546 | 2648 | wp_defer_comment_counting( false ); |
| 2547 | 2649 | |
| 2548 | 2650 | $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $postid )); |
| 2549 | - foreach ( $post_meta_ids as $mid ) |
|
| 2550 | - delete_metadata_by_mid( 'post', $mid ); |
|
| 2651 | + foreach ( $post_meta_ids as $mid ) { |
|
| 2652 | + delete_metadata_by_mid( 'post', $mid ); |
|
| 2653 | + } |
|
| 2551 | 2654 | |
| 2552 | 2655 | /** |
| 2553 | 2656 | * Fires immediately before a post is deleted from the database. |
@@ -2574,8 +2677,9 @@ discard block |
||
| 2574 | 2677 | clean_post_cache( $post ); |
| 2575 | 2678 | |
| 2576 | 2679 | if ( is_post_type_hierarchical( $post->post_type ) && $children ) { |
| 2577 | - foreach ( $children as $child ) |
|
| 2578 | - clean_post_cache( $child ); |
|
| 2680 | + foreach ( $children as $child ) { |
|
| 2681 | + clean_post_cache( $child ); |
|
| 2682 | + } |
|
| 2579 | 2683 | } |
| 2580 | 2684 | |
| 2581 | 2685 | wp_clear_scheduled_hook('publish_future_post', array( $postid ) ); |
@@ -2637,14 +2741,17 @@ discard block |
||
| 2637 | 2741 | * @return false|array|WP_Post|null Post data array, otherwise false. |
| 2638 | 2742 | */ |
| 2639 | 2743 | function wp_trash_post( $post_id = 0 ) { |
| 2640 | - if ( !EMPTY_TRASH_DAYS ) |
|
| 2641 | - return wp_delete_post($post_id, true); |
|
| 2744 | + if ( !EMPTY_TRASH_DAYS ) { |
|
| 2745 | + return wp_delete_post($post_id, true); |
|
| 2746 | + } |
|
| 2642 | 2747 | |
| 2643 | - if ( !$post = get_post($post_id, ARRAY_A) ) |
|
| 2644 | - return $post; |
|
| 2748 | + if ( !$post = get_post($post_id, ARRAY_A) ) { |
|
| 2749 | + return $post; |
|
| 2750 | + } |
|
| 2645 | 2751 | |
| 2646 | - if ( $post['post_status'] == 'trash' ) |
|
| 2647 | - return false; |
|
| 2752 | + if ( $post['post_status'] == 'trash' ) { |
|
| 2753 | + return false; |
|
| 2754 | + } |
|
| 2648 | 2755 | |
| 2649 | 2756 | /** |
| 2650 | 2757 | * Fires before a post is sent to the trash. |
@@ -2684,11 +2791,13 @@ discard block |
||
| 2684 | 2791 | * @return WP_Post|false WP_Post object. False on failure. |
| 2685 | 2792 | */ |
| 2686 | 2793 | function wp_untrash_post( $post_id = 0 ) { |
| 2687 | - if ( !$post = get_post($post_id, ARRAY_A) ) |
|
| 2688 | - return $post; |
|
| 2794 | + if ( !$post = get_post($post_id, ARRAY_A) ) { |
|
| 2795 | + return $post; |
|
| 2796 | + } |
|
| 2689 | 2797 | |
| 2690 | - if ( $post['post_status'] != 'trash' ) |
|
| 2691 | - return false; |
|
| 2798 | + if ( $post['post_status'] != 'trash' ) { |
|
| 2799 | + return false; |
|
| 2800 | + } |
|
| 2692 | 2801 | |
| 2693 | 2802 | /** |
| 2694 | 2803 | * Fires before a post is restored from the trash. |
@@ -2736,8 +2845,9 @@ discard block |
||
| 2736 | 2845 | global $wpdb; |
| 2737 | 2846 | |
| 2738 | 2847 | $post = get_post($post); |
| 2739 | - if ( empty($post) ) |
|
| 2740 | - return; |
|
| 2848 | + if ( empty($post) ) { |
|
| 2849 | + return; |
|
| 2850 | + } |
|
| 2741 | 2851 | |
| 2742 | 2852 | $post_id = $post->ID; |
| 2743 | 2853 | |
@@ -2751,13 +2861,15 @@ discard block |
||
| 2751 | 2861 | do_action( 'trash_post_comments', $post_id ); |
| 2752 | 2862 | |
| 2753 | 2863 | $comments = $wpdb->get_results( $wpdb->prepare("SELECT comment_ID, comment_approved FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id) ); |
| 2754 | - if ( empty($comments) ) |
|
| 2755 | - return; |
|
| 2864 | + if ( empty($comments) ) { |
|
| 2865 | + return; |
|
| 2866 | + } |
|
| 2756 | 2867 | |
| 2757 | 2868 | // Cache current status for each comment. |
| 2758 | 2869 | $statuses = array(); |
| 2759 | - foreach ( $comments as $comment ) |
|
| 2760 | - $statuses[$comment->comment_ID] = $comment->comment_approved; |
|
| 2870 | + foreach ( $comments as $comment ) { |
|
| 2871 | + $statuses[$comment->comment_ID] = $comment->comment_approved; |
|
| 2872 | + } |
|
| 2761 | 2873 | add_post_meta($post_id, '_wp_trash_meta_comments_status', $statuses); |
| 2762 | 2874 | |
| 2763 | 2875 | // Set status for all comments to post-trashed. |
@@ -2792,15 +2904,17 @@ discard block |
||
| 2792 | 2904 | global $wpdb; |
| 2793 | 2905 | |
| 2794 | 2906 | $post = get_post($post); |
| 2795 | - if ( empty($post) ) |
|
| 2796 | - return; |
|
| 2907 | + if ( empty($post) ) { |
|
| 2908 | + return; |
|
| 2909 | + } |
|
| 2797 | 2910 | |
| 2798 | 2911 | $post_id = $post->ID; |
| 2799 | 2912 | |
| 2800 | 2913 | $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true); |
| 2801 | 2914 | |
| 2802 | - if ( empty($statuses) ) |
|
| 2803 | - return true; |
|
| 2915 | + if ( empty($statuses) ) { |
|
| 2916 | + return true; |
|
| 2917 | + } |
|
| 2804 | 2918 | |
| 2805 | 2919 | /** |
| 2806 | 2920 | * Fires before comments are restored for a post from the trash. |
@@ -2813,8 +2927,9 @@ discard block |
||
| 2813 | 2927 | |
| 2814 | 2928 | // Restore each comment to its original status. |
| 2815 | 2929 | $group_by_status = array(); |
| 2816 | - foreach ( $statuses as $comment_id => $comment_status ) |
|
| 2817 | - $group_by_status[$comment_status][] = $comment_id; |
|
| 2930 | + foreach ( $statuses as $comment_id => $comment_status ) { |
|
| 2931 | + $group_by_status[$comment_status][] = $comment_id; |
|
| 2932 | + } |
|
| 2818 | 2933 | |
| 2819 | 2934 | foreach ( $group_by_status as $status => $comments ) { |
| 2820 | 2935 | // Sanity check. This shouldn't happen. |
@@ -3566,8 +3681,9 @@ discard block |
||
| 3566 | 3681 | $post = get_post($postarr['ID'], ARRAY_A); |
| 3567 | 3682 | |
| 3568 | 3683 | if ( is_null( $post ) ) { |
| 3569 | - if ( $wp_error ) |
|
| 3570 | - return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) ); |
|
| 3684 | + if ( $wp_error ) { |
|
| 3685 | + return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) ); |
|
| 3686 | + } |
|
| 3571 | 3687 | return 0; |
| 3572 | 3688 | } |
| 3573 | 3689 | |
@@ -3576,17 +3692,19 @@ discard block |
||
| 3576 | 3692 | |
| 3577 | 3693 | // Passed post category list overwrites existing category list if not empty. |
| 3578 | 3694 | if ( isset($postarr['post_category']) && is_array($postarr['post_category']) |
| 3579 | - && 0 != count($postarr['post_category']) ) |
|
| 3580 | - $post_cats = $postarr['post_category']; |
|
| 3581 | - else |
|
| 3582 | - $post_cats = $post['post_category']; |
|
| 3695 | + && 0 != count($postarr['post_category']) ) { |
|
| 3696 | + $post_cats = $postarr['post_category']; |
|
| 3697 | + } else { |
|
| 3698 | + $post_cats = $post['post_category']; |
|
| 3699 | + } |
|
| 3583 | 3700 | |
| 3584 | 3701 | // Drafts shouldn't be assigned a date unless explicitly done so by the user. |
| 3585 | 3702 | if ( isset( $post['post_status'] ) && in_array($post['post_status'], array('draft', 'pending', 'auto-draft')) && empty($postarr['edit_date']) && |
| 3586 | - ('0000-00-00 00:00:00' == $post['post_date_gmt']) ) |
|
| 3587 | - $clear_date = true; |
|
| 3588 | - else |
|
| 3589 | - $clear_date = false; |
|
| 3703 | + ('0000-00-00 00:00:00' == $post['post_date_gmt']) ) { |
|
| 3704 | + $clear_date = true; |
|
| 3705 | + } else { |
|
| 3706 | + $clear_date = false; |
|
| 3707 | + } |
|
| 3590 | 3708 | |
| 3591 | 3709 | // Merge old and new fields with new fields overwriting old ones. |
| 3592 | 3710 | $postarr = array_merge($post, $postarr); |
@@ -3596,8 +3714,9 @@ discard block |
||
| 3596 | 3714 | $postarr['post_date_gmt'] = ''; |
| 3597 | 3715 | } |
| 3598 | 3716 | |
| 3599 | - if ($postarr['post_type'] == 'attachment') |
|
| 3600 | - return wp_insert_attachment($postarr); |
|
| 3717 | + if ($postarr['post_type'] == 'attachment') { |
|
| 3718 | + return wp_insert_attachment($postarr); |
|
| 3719 | + } |
|
| 3601 | 3720 | |
| 3602 | 3721 | return wp_insert_post( $postarr, $wp_error ); |
| 3603 | 3722 | } |
@@ -3614,11 +3733,13 @@ discard block |
||
| 3614 | 3733 | function wp_publish_post( $post ) { |
| 3615 | 3734 | global $wpdb; |
| 3616 | 3735 | |
| 3617 | - if ( ! $post = get_post( $post ) ) |
|
| 3618 | - return; |
|
| 3736 | + if ( ! $post = get_post( $post ) ) { |
|
| 3737 | + return; |
|
| 3738 | + } |
|
| 3619 | 3739 | |
| 3620 | - if ( 'publish' == $post->post_status ) |
|
| 3621 | - return; |
|
| 3740 | + if ( 'publish' == $post->post_status ) { |
|
| 3741 | + return; |
|
| 3742 | + } |
|
| 3622 | 3743 | |
| 3623 | 3744 | $wpdb->update( $wpdb->posts, array( 'post_status' => 'publish' ), array( 'ID' => $post->ID ) ); |
| 3624 | 3745 | |
@@ -3654,11 +3775,13 @@ discard block |
||
| 3654 | 3775 | function check_and_publish_future_post( $post_id ) { |
| 3655 | 3776 | $post = get_post($post_id); |
| 3656 | 3777 | |
| 3657 | - if ( empty($post) ) |
|
| 3658 | - return; |
|
| 3778 | + if ( empty($post) ) { |
|
| 3779 | + return; |
|
| 3780 | + } |
|
| 3659 | 3781 | |
| 3660 | - if ( 'future' != $post->post_status ) |
|
| 3661 | - return; |
|
| 3782 | + if ( 'future' != $post->post_status ) { |
|
| 3783 | + return; |
|
| 3784 | + } |
|
| 3662 | 3785 | |
| 3663 | 3786 | $time = strtotime( $post->post_date_gmt . ' GMT' ); |
| 3664 | 3787 | |
@@ -3689,16 +3812,18 @@ discard block |
||
| 3689 | 3812 | * @return string Unique slug for the post, based on $post_name (with a -1, -2, etc. suffix) |
| 3690 | 3813 | */ |
| 3691 | 3814 | function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent ) { |
| 3692 | - if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) || ( 'inherit' == $post_status && 'revision' == $post_type ) ) |
|
| 3693 | - return $slug; |
|
| 3815 | + if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) || ( 'inherit' == $post_status && 'revision' == $post_type ) ) { |
|
| 3816 | + return $slug; |
|
| 3817 | + } |
|
| 3694 | 3818 | |
| 3695 | 3819 | global $wpdb, $wp_rewrite; |
| 3696 | 3820 | |
| 3697 | 3821 | $original_slug = $slug; |
| 3698 | 3822 | |
| 3699 | 3823 | $feeds = $wp_rewrite->feeds; |
| 3700 | - if ( ! is_array( $feeds ) ) |
|
| 3701 | - $feeds = array(); |
|
| 3824 | + if ( ! is_array( $feeds ) ) { |
|
| 3825 | + $feeds = array(); |
|
| 3826 | + } |
|
| 3702 | 3827 | |
| 3703 | 3828 | if ( 'attachment' == $post_type ) { |
| 3704 | 3829 | // Attachment slugs must be unique across all types. |
@@ -3723,8 +3848,9 @@ discard block |
||
| 3723 | 3848 | $slug = $alt_post_name; |
| 3724 | 3849 | } |
| 3725 | 3850 | } elseif ( is_post_type_hierarchical( $post_type ) ) { |
| 3726 | - if ( 'nav_menu_item' == $post_type ) |
|
| 3727 | - return $slug; |
|
| 3851 | + if ( 'nav_menu_item' == $post_type ) { |
|
| 3852 | + return $slug; |
|
| 3853 | + } |
|
| 3728 | 3854 | |
| 3729 | 3855 | /* |
| 3730 | 3856 | * Page slugs must be unique within their own trees. Pages are in a separate |
@@ -3829,10 +3955,11 @@ discard block |
||
| 3829 | 3955 | function _truncate_post_slug( $slug, $length = 200 ) { |
| 3830 | 3956 | if ( strlen( $slug ) > $length ) { |
| 3831 | 3957 | $decoded_slug = urldecode( $slug ); |
| 3832 | - if ( $decoded_slug === $slug ) |
|
| 3833 | - $slug = substr( $slug, 0, $length ); |
|
| 3834 | - else |
|
| 3835 | - $slug = utf8_uri_encode( $decoded_slug, $length ); |
|
| 3958 | + if ( $decoded_slug === $slug ) { |
|
| 3959 | + $slug = substr( $slug, 0, $length ); |
|
| 3960 | + } else { |
|
| 3961 | + $slug = utf8_uri_encode( $decoded_slug, $length ); |
|
| 3962 | + } |
|
| 3836 | 3963 | } |
| 3837 | 3964 | |
| 3838 | 3965 | return rtrim( $slug, '-' ); |
@@ -3890,16 +4017,19 @@ discard block |
||
| 3890 | 4017 | function wp_set_post_terms( $post_id = 0, $tags = '', $taxonomy = 'post_tag', $append = false ) { |
| 3891 | 4018 | $post_id = (int) $post_id; |
| 3892 | 4019 | |
| 3893 | - if ( !$post_id ) |
|
| 3894 | - return false; |
|
| 4020 | + if ( !$post_id ) { |
|
| 4021 | + return false; |
|
| 4022 | + } |
|
| 3895 | 4023 | |
| 3896 | - if ( empty($tags) ) |
|
| 3897 | - $tags = array(); |
|
| 4024 | + if ( empty($tags) ) { |
|
| 4025 | + $tags = array(); |
|
| 4026 | + } |
|
| 3898 | 4027 | |
| 3899 | 4028 | if ( ! is_array( $tags ) ) { |
| 3900 | 4029 | $comma = _x( ',', 'tag delimiter' ); |
| 3901 | - if ( ',' !== $comma ) |
|
| 3902 | - $tags = str_replace( $comma, ',', $tags ); |
|
| 4030 | + if ( ',' !== $comma ) { |
|
| 4031 | + $tags = str_replace( $comma, ',', $tags ); |
|
| 4032 | + } |
|
| 3903 | 4033 | $tags = explode( ',', trim( $tags, " \n\t\r\0\x0B," ) ); |
| 3904 | 4034 | } |
| 3905 | 4035 | |
@@ -4065,12 +4195,14 @@ discard block |
||
| 4065 | 4195 | function get_enclosed( $post_id ) { |
| 4066 | 4196 | $custom_fields = get_post_custom( $post_id ); |
| 4067 | 4197 | $pung = array(); |
| 4068 | - if ( !is_array( $custom_fields ) ) |
|
| 4069 | - return $pung; |
|
| 4198 | + if ( !is_array( $custom_fields ) ) { |
|
| 4199 | + return $pung; |
|
| 4200 | + } |
|
| 4070 | 4201 | |
| 4071 | 4202 | foreach ( $custom_fields as $key => $val ) { |
| 4072 | - if ( 'enclosure' != $key || !is_array( $val ) ) |
|
| 4073 | - continue; |
|
| 4203 | + if ( 'enclosure' != $key || !is_array( $val ) ) { |
|
| 4204 | + continue; |
|
| 4205 | + } |
|
| 4074 | 4206 | foreach ( $val as $enc ) { |
| 4075 | 4207 | $enclosure = explode( "\n", $enc ); |
| 4076 | 4208 | $pung[] = trim( $enclosure[ 0 ] ); |
@@ -4269,15 +4401,17 @@ discard block |
||
| 4269 | 4401 | while ( $p->post_parent != 0 && isset( $pages[ $p->post_parent ] ) ) { |
| 4270 | 4402 | $count++; |
| 4271 | 4403 | $parent = $pages[ $p->post_parent ]; |
| 4272 | - if ( ! isset( $revparts[ $count ] ) || $parent->post_name != $revparts[ $count ] ) |
|
| 4273 | - break; |
|
| 4404 | + if ( ! isset( $revparts[ $count ] ) || $parent->post_name != $revparts[ $count ] ) { |
|
| 4405 | + break; |
|
| 4406 | + } |
|
| 4274 | 4407 | $p = $parent; |
| 4275 | 4408 | } |
| 4276 | 4409 | |
| 4277 | 4410 | if ( $p->post_parent == 0 && $count+1 == count( $revparts ) && $p->post_name == $revparts[ $count ] ) { |
| 4278 | 4411 | $foundid = $page->ID; |
| 4279 | - if ( $page->post_type == $post_type ) |
|
| 4280 | - break; |
|
| 4412 | + if ( $page->post_type == $post_type ) { |
|
| 4413 | + break; |
|
| 4414 | + } |
|
| 4281 | 4415 | } |
| 4282 | 4416 | } |
| 4283 | 4417 | } |
@@ -4434,8 +4568,9 @@ discard block |
||
| 4434 | 4568 | $page = get_post( $page ); |
| 4435 | 4569 | } |
| 4436 | 4570 | |
| 4437 | - if ( ! $page ) |
|
| 4438 | - return false; |
|
| 4571 | + if ( ! $page ) { |
|
| 4572 | + return false; |
|
| 4573 | + } |
|
| 4439 | 4574 | |
| 4440 | 4575 | $uri = $page->post_name; |
| 4441 | 4576 | |
@@ -4765,14 +4900,17 @@ discard block |
||
| 4765 | 4900 | * @return bool True on success, false on failure. |
| 4766 | 4901 | */ |
| 4767 | 4902 | function is_local_attachment($url) { |
| 4768 | - if (strpos($url, home_url()) === false) |
|
| 4769 | - return false; |
|
| 4770 | - if (strpos($url, home_url('/?attachment_id=')) !== false) |
|
| 4771 | - return true; |
|
| 4903 | + if (strpos($url, home_url()) === false) { |
|
| 4904 | + return false; |
|
| 4905 | + } |
|
| 4906 | + if (strpos($url, home_url('/?attachment_id=')) !== false) { |
|
| 4907 | + return true; |
|
| 4908 | + } |
|
| 4772 | 4909 | if ( $id = url_to_postid($url) ) { |
| 4773 | 4910 | $post = get_post($id); |
| 4774 | - if ( 'attachment' == $post->post_type ) |
|
| 4775 | - return true; |
|
| 4911 | + if ( 'attachment' == $post->post_type ) { |
|
| 4912 | + return true; |
|
| 4913 | + } |
|
| 4776 | 4914 | } |
| 4777 | 4915 | return false; |
| 4778 | 4916 | } |
@@ -4839,14 +4977,17 @@ discard block |
||
| 4839 | 4977 | function wp_delete_attachment( $post_id, $force_delete = false ) { |
| 4840 | 4978 | global $wpdb; |
| 4841 | 4979 | |
| 4842 | - if ( !$post = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d", $post_id) ) ) |
|
| 4843 | - return $post; |
|
| 4980 | + if ( !$post = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d", $post_id) ) ) { |
|
| 4981 | + return $post; |
|
| 4982 | + } |
|
| 4844 | 4983 | |
| 4845 | - if ( 'attachment' != $post->post_type ) |
|
| 4846 | - return false; |
|
| 4984 | + if ( 'attachment' != $post->post_type ) { |
|
| 4985 | + return false; |
|
| 4986 | + } |
|
| 4847 | 4987 | |
| 4848 | - if ( !$force_delete && EMPTY_TRASH_DAYS && MEDIA_TRASH && 'trash' != $post->post_status ) |
|
| 4849 | - return wp_trash_post( $post_id ); |
|
| 4988 | + if ( !$force_delete && EMPTY_TRASH_DAYS && MEDIA_TRASH && 'trash' != $post->post_status ) { |
|
| 4989 | + return wp_trash_post( $post_id ); |
|
| 4990 | + } |
|
| 4850 | 4991 | |
| 4851 | 4992 | delete_post_meta($post_id, '_wp_trash_meta_status'); |
| 4852 | 4993 | delete_post_meta($post_id, '_wp_trash_meta_time'); |
@@ -4855,8 +4996,9 @@ discard block |
||
| 4855 | 4996 | $backup_sizes = get_post_meta( $post->ID, '_wp_attachment_backup_sizes', true ); |
| 4856 | 4997 | $file = get_attached_file( $post_id ); |
| 4857 | 4998 | |
| 4858 | - if ( is_multisite() ) |
|
| 4859 | - delete_transient( 'dirsize_cache' ); |
|
| 4999 | + if ( is_multisite() ) { |
|
| 5000 | + delete_transient( 'dirsize_cache' ); |
|
| 5001 | + } |
|
| 4860 | 5002 | |
| 4861 | 5003 | /** |
| 4862 | 5004 | * Fires before an attachment is deleted, at the start of wp_delete_attachment(). |
@@ -4883,8 +5025,9 @@ discard block |
||
| 4883 | 5025 | wp_defer_comment_counting( false ); |
| 4884 | 5026 | |
| 4885 | 5027 | $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $post_id )); |
| 4886 | - foreach ( $post_meta_ids as $mid ) |
|
| 4887 | - delete_metadata_by_mid( 'post', $mid ); |
|
| 5028 | + foreach ( $post_meta_ids as $mid ) { |
|
| 5029 | + delete_metadata_by_mid( 'post', $mid ); |
|
| 5030 | + } |
|
| 4888 | 5031 | |
| 4889 | 5032 | /** This action is documented in wp-includes/post.php */ |
| 4890 | 5033 | do_action( 'delete_post', $post_id ); |
@@ -4944,13 +5087,15 @@ discard block |
||
| 4944 | 5087 | */ |
| 4945 | 5088 | function wp_get_attachment_metadata( $post_id = 0, $unfiltered = false ) { |
| 4946 | 5089 | $post_id = (int) $post_id; |
| 4947 | - if ( !$post = get_post( $post_id ) ) |
|
| 4948 | - return false; |
|
| 5090 | + if ( !$post = get_post( $post_id ) ) { |
|
| 5091 | + return false; |
|
| 5092 | + } |
|
| 4949 | 5093 | |
| 4950 | 5094 | $data = get_post_meta( $post->ID, '_wp_attachment_metadata', true ); |
| 4951 | 5095 | |
| 4952 | - if ( $unfiltered ) |
|
| 4953 | - return $data; |
|
| 5096 | + if ( $unfiltered ) { |
|
| 5097 | + return $data; |
|
| 5098 | + } |
|
| 4954 | 5099 | |
| 4955 | 5100 | /** |
| 4956 | 5101 | * Filter the attachment meta data. |
@@ -4975,8 +5120,9 @@ discard block |
||
| 4975 | 5120 | */ |
| 4976 | 5121 | function wp_update_attachment_metadata( $post_id, $data ) { |
| 4977 | 5122 | $post_id = (int) $post_id; |
| 4978 | - if ( !$post = get_post( $post_id ) ) |
|
| 4979 | - return false; |
|
| 5123 | + if ( !$post = get_post( $post_id ) ) { |
|
| 5124 | + return false; |
|
| 5125 | + } |
|
| 4980 | 5126 | |
| 4981 | 5127 | /** |
| 4982 | 5128 | * Filter the updated attachment meta data. |
@@ -4986,11 +5132,12 @@ discard block |
||
| 4986 | 5132 | * @param array $data Array of updated attachment meta data. |
| 4987 | 5133 | * @param int $post_id Attachment ID. |
| 4988 | 5134 | */ |
| 4989 | - if ( $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID ) ) |
|
| 4990 | - return update_post_meta( $post->ID, '_wp_attachment_metadata', $data ); |
|
| 4991 | - else |
|
| 4992 | - return delete_post_meta( $post->ID, '_wp_attachment_metadata' ); |
|
| 4993 | -} |
|
| 5135 | + if ( $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID ) ) { |
|
| 5136 | + return update_post_meta( $post->ID, '_wp_attachment_metadata', $data ); |
|
| 5137 | + } else { |
|
| 5138 | + return delete_post_meta( $post->ID, '_wp_attachment_metadata' ); |
|
| 5139 | + } |
|
| 5140 | + } |
|
| 4994 | 5141 | |
| 4995 | 5142 | /** |
| 4996 | 5143 | * Retrieve the URL for an attachment. |
@@ -5004,11 +5151,13 @@ discard block |
||
| 5004 | 5151 | */ |
| 5005 | 5152 | function wp_get_attachment_url( $post_id = 0 ) { |
| 5006 | 5153 | $post_id = (int) $post_id; |
| 5007 | - if ( !$post = get_post( $post_id ) ) |
|
| 5008 | - return false; |
|
| 5154 | + if ( !$post = get_post( $post_id ) ) { |
|
| 5155 | + return false; |
|
| 5156 | + } |
|
| 5009 | 5157 | |
| 5010 | - if ( 'attachment' != $post->post_type ) |
|
| 5011 | - return false; |
|
| 5158 | + if ( 'attachment' != $post->post_type ) { |
|
| 5159 | + return false; |
|
| 5160 | + } |
|
| 5012 | 5161 | |
| 5013 | 5162 | $url = ''; |
| 5014 | 5163 | // Get attached file. |
@@ -5052,8 +5201,9 @@ discard block |
||
| 5052 | 5201 | */ |
| 5053 | 5202 | $url = apply_filters( 'wp_get_attachment_url', $url, $post->ID ); |
| 5054 | 5203 | |
| 5055 | - if ( empty( $url ) ) |
|
| 5056 | - return false; |
|
| 5204 | + if ( empty( $url ) ) { |
|
| 5205 | + return false; |
|
| 5206 | + } |
|
| 5057 | 5207 | |
| 5058 | 5208 | return $url; |
| 5059 | 5209 | } |
@@ -5068,10 +5218,12 @@ discard block |
||
| 5068 | 5218 | */ |
| 5069 | 5219 | function wp_get_attachment_thumb_file( $post_id = 0 ) { |
| 5070 | 5220 | $post_id = (int) $post_id; |
| 5071 | - if ( !$post = get_post( $post_id ) ) |
|
| 5072 | - return false; |
|
| 5073 | - if ( !is_array( $imagedata = wp_get_attachment_metadata( $post->ID ) ) ) |
|
| 5074 | - return false; |
|
| 5221 | + if ( !$post = get_post( $post_id ) ) { |
|
| 5222 | + return false; |
|
| 5223 | + } |
|
| 5224 | + if ( !is_array( $imagedata = wp_get_attachment_metadata( $post->ID ) ) ) { |
|
| 5225 | + return false; |
|
| 5226 | + } |
|
| 5075 | 5227 | |
| 5076 | 5228 | $file = get_attached_file( $post->ID ); |
| 5077 | 5229 | |
@@ -5099,17 +5251,21 @@ discard block |
||
| 5099 | 5251 | */ |
| 5100 | 5252 | function wp_get_attachment_thumb_url( $post_id = 0 ) { |
| 5101 | 5253 | $post_id = (int) $post_id; |
| 5102 | - if ( !$post = get_post( $post_id ) ) |
|
| 5103 | - return false; |
|
| 5104 | - if ( !$url = wp_get_attachment_url( $post->ID ) ) |
|
| 5105 | - return false; |
|
| 5254 | + if ( !$post = get_post( $post_id ) ) { |
|
| 5255 | + return false; |
|
| 5256 | + } |
|
| 5257 | + if ( !$url = wp_get_attachment_url( $post->ID ) ) { |
|
| 5258 | + return false; |
|
| 5259 | + } |
|
| 5106 | 5260 | |
| 5107 | 5261 | $sized = image_downsize( $post_id, 'thumbnail' ); |
| 5108 | - if ( $sized ) |
|
| 5109 | - return $sized[0]; |
|
| 5262 | + if ( $sized ) { |
|
| 5263 | + return $sized[0]; |
|
| 5264 | + } |
|
| 5110 | 5265 | |
| 5111 | - if ( !$thumb = wp_get_attachment_thumb_file( $post->ID ) ) |
|
| 5112 | - return false; |
|
| 5266 | + if ( !$thumb = wp_get_attachment_thumb_file( $post->ID ) ) { |
|
| 5267 | + return false; |
|
| 5268 | + } |
|
| 5113 | 5269 | |
| 5114 | 5270 | $url = str_replace(basename($url), basename($thumb), $url); |
| 5115 | 5271 | |
@@ -5196,8 +5352,9 @@ discard block |
||
| 5196 | 5352 | * @return string|false Icon, false otherwise. |
| 5197 | 5353 | */ |
| 5198 | 5354 | function wp_mime_type_icon( $mime = 0 ) { |
| 5199 | - if ( !is_numeric($mime) ) |
|
| 5200 | - $icon = wp_cache_get("mime_type_icon_$mime"); |
|
| 5355 | + if ( !is_numeric($mime) ) { |
|
| 5356 | + $icon = wp_cache_get("mime_type_icon_$mime"); |
|
| 5357 | + } |
|
| 5201 | 5358 | |
| 5202 | 5359 | $post_id = 0; |
| 5203 | 5360 | if ( empty($icon) ) { |
@@ -5210,8 +5367,9 @@ discard block |
||
| 5210 | 5367 | $ext = preg_replace('/^.+?\.([^.]+)$/', '$1', $file); |
| 5211 | 5368 | if ( !empty($ext) ) { |
| 5212 | 5369 | $post_mimes[] = $ext; |
| 5213 | - if ( $ext_type = wp_ext2type( $ext ) ) |
|
| 5214 | - $post_mimes[] = $ext_type; |
|
| 5370 | + if ( $ext_type = wp_ext2type( $ext ) ) { |
|
| 5371 | + $post_mimes[] = $ext_type; |
|
| 5372 | + } |
|
| 5215 | 5373 | } |
| 5216 | 5374 | $mime = $post->post_mime_type; |
| 5217 | 5375 | } else { |
@@ -5258,11 +5416,13 @@ discard block |
||
| 5258 | 5416 | if ( $dh = opendir($dir) ) { |
| 5259 | 5417 | while ( false !== $file = readdir($dh) ) { |
| 5260 | 5418 | $file = basename($file); |
| 5261 | - if ( substr($file, 0, 1) == '.' ) |
|
| 5262 | - continue; |
|
| 5419 | + if ( substr($file, 0, 1) == '.' ) { |
|
| 5420 | + continue; |
|
| 5421 | + } |
|
| 5263 | 5422 | if ( !in_array(strtolower(substr($file, -4)), array('.png', '.gif', '.jpg') ) ) { |
| 5264 | - if ( is_dir("$dir/$file") ) |
|
| 5265 | - $dirs["$dir/$file"] = "$uri/$file"; |
|
| 5423 | + if ( is_dir("$dir/$file") ) { |
|
| 5424 | + $dirs["$dir/$file"] = "$uri/$file"; |
|
| 5425 | + } |
|
| 5266 | 5426 | continue; |
| 5267 | 5427 | } |
| 5268 | 5428 | $icon_files["$dir/$file"] = "$uri/$file"; |
@@ -5275,8 +5435,9 @@ discard block |
||
| 5275 | 5435 | |
| 5276 | 5436 | $types = array(); |
| 5277 | 5437 | // Icon basename - extension = MIME wildcard. |
| 5278 | - foreach ( $icon_files as $file => $uri ) |
|
| 5279 | - $types[ preg_replace('/^([^.]*).*$/', '$1', basename($file)) ] =& $icon_files[$file]; |
|
| 5438 | + foreach ( $icon_files as $file => $uri ) { |
|
| 5439 | + $types[ preg_replace('/^([^.]*).*$/', '$1', basename($file)) ] =& $icon_files[$file]; |
|
| 5440 | + } |
|
| 5280 | 5441 | |
| 5281 | 5442 | if ( ! empty($mime) ) { |
| 5282 | 5443 | $post_mimes[] = substr($mime, 0, strpos($mime, '/')); |
@@ -5611,12 +5772,14 @@ discard block |
||
| 5611 | 5772 | * @param array $posts Array of post objects, passed by reference. |
| 5612 | 5773 | */ |
| 5613 | 5774 | function update_post_cache( &$posts ) { |
| 5614 | - if ( ! $posts ) |
|
| 5615 | - return; |
|
| 5775 | + if ( ! $posts ) { |
|
| 5776 | + return; |
|
| 5777 | + } |
|
| 5616 | 5778 | |
| 5617 | - foreach ( $posts as $post ) |
|
| 5618 | - wp_cache_add( $post->ID, $post, 'posts' ); |
|
| 5619 | -} |
|
| 5779 | + foreach ( $posts as $post ) { |
|
| 5780 | + wp_cache_add( $post->ID, $post, 'posts' ); |
|
| 5781 | + } |
|
| 5782 | + } |
|
| 5620 | 5783 | |
| 5621 | 5784 | /** |
| 5622 | 5785 | * Will clean the post in the cache. |
@@ -5636,12 +5799,14 @@ discard block |
||
| 5636 | 5799 | function clean_post_cache( $post ) { |
| 5637 | 5800 | global $_wp_suspend_cache_invalidation; |
| 5638 | 5801 | |
| 5639 | - if ( ! empty( $_wp_suspend_cache_invalidation ) ) |
|
| 5640 | - return; |
|
| 5802 | + if ( ! empty( $_wp_suspend_cache_invalidation ) ) { |
|
| 5803 | + return; |
|
| 5804 | + } |
|
| 5641 | 5805 | |
| 5642 | 5806 | $post = get_post( $post ); |
| 5643 | - if ( empty( $post ) ) |
|
| 5644 | - return; |
|
| 5807 | + if ( empty( $post ) ) { |
|
| 5808 | + return; |
|
| 5809 | + } |
|
| 5645 | 5810 | |
| 5646 | 5811 | wp_cache_delete( $post->ID, 'posts' ); |
| 5647 | 5812 | wp_cache_delete( $post->ID, 'post_meta' ); |
@@ -5688,17 +5853,20 @@ discard block |
||
| 5688 | 5853 | */ |
| 5689 | 5854 | function update_post_caches( &$posts, $post_type = 'post', $update_term_cache = true, $update_meta_cache = true ) { |
| 5690 | 5855 | // No point in doing all this work if we didn't match any posts. |
| 5691 | - if ( !$posts ) |
|
| 5692 | - return; |
|
| 5856 | + if ( !$posts ) { |
|
| 5857 | + return; |
|
| 5858 | + } |
|
| 5693 | 5859 | |
| 5694 | 5860 | update_post_cache($posts); |
| 5695 | 5861 | |
| 5696 | 5862 | $post_ids = array(); |
| 5697 | - foreach ( $posts as $post ) |
|
| 5698 | - $post_ids[] = $post->ID; |
|
| 5863 | + foreach ( $posts as $post ) { |
|
| 5864 | + $post_ids[] = $post->ID; |
|
| 5865 | + } |
|
| 5699 | 5866 | |
| 5700 | - if ( ! $post_type ) |
|
| 5701 | - $post_type = 'any'; |
|
| 5867 | + if ( ! $post_type ) { |
|
| 5868 | + $post_type = 'any'; |
|
| 5869 | + } |
|
| 5702 | 5870 | |
| 5703 | 5871 | if ( $update_term_cache ) { |
| 5704 | 5872 | if ( is_array($post_type) ) { |
@@ -5714,13 +5882,15 @@ discard block |
||
| 5714 | 5882 | $ptypes = array($post_type); |
| 5715 | 5883 | } |
| 5716 | 5884 | |
| 5717 | - if ( ! empty($ptypes) ) |
|
| 5718 | - update_object_term_cache($post_ids, $ptypes); |
|
| 5885 | + if ( ! empty($ptypes) ) { |
|
| 5886 | + update_object_term_cache($post_ids, $ptypes); |
|
| 5887 | + } |
|
| 5719 | 5888 | } |
| 5720 | 5889 | |
| 5721 | - if ( $update_meta_cache ) |
|
| 5722 | - update_postmeta_cache($post_ids); |
|
| 5723 | -} |
|
| 5890 | + if ( $update_meta_cache ) { |
|
| 5891 | + update_postmeta_cache($post_ids); |
|
| 5892 | + } |
|
| 5893 | + } |
|
| 5724 | 5894 | |
| 5725 | 5895 | /** |
| 5726 | 5896 | * Updates metadata cache for list of post IDs. |
@@ -5757,16 +5927,18 @@ discard block |
||
| 5757 | 5927 | function clean_attachment_cache( $id, $clean_terms = false ) { |
| 5758 | 5928 | global $_wp_suspend_cache_invalidation; |
| 5759 | 5929 | |
| 5760 | - if ( !empty($_wp_suspend_cache_invalidation) ) |
|
| 5761 | - return; |
|
| 5930 | + if ( !empty($_wp_suspend_cache_invalidation) ) { |
|
| 5931 | + return; |
|
| 5932 | + } |
|
| 5762 | 5933 | |
| 5763 | 5934 | $id = (int) $id; |
| 5764 | 5935 | |
| 5765 | 5936 | wp_cache_delete($id, 'posts'); |
| 5766 | 5937 | wp_cache_delete($id, 'post_meta'); |
| 5767 | 5938 | |
| 5768 | - if ( $clean_terms ) |
|
| 5769 | - clean_object_term_cache($id, 'attachment'); |
|
| 5939 | + if ( $clean_terms ) { |
|
| 5940 | + clean_object_term_cache($id, 'attachment'); |
|
| 5941 | + } |
|
| 5770 | 5942 | |
| 5771 | 5943 | /** |
| 5772 | 5944 | * Fires after the given attachment's cache is cleaned. |
@@ -5800,8 +5972,9 @@ discard block |
||
| 5800 | 5972 | |
| 5801 | 5973 | if ( $old_status != 'publish' && $new_status == 'publish' ) { |
| 5802 | 5974 | // Reset GUID if transitioning to publish and it is empty. |
| 5803 | - if ( '' == get_the_guid($post->ID) ) |
|
| 5804 | - $wpdb->update( $wpdb->posts, array( 'guid' => get_permalink( $post->ID ) ), array( 'ID' => $post->ID ) ); |
|
| 5975 | + if ( '' == get_the_guid($post->ID) ) { |
|
| 5976 | + $wpdb->update( $wpdb->posts, array( 'guid' => get_permalink( $post->ID ) ), array( 'ID' => $post->ID ) ); |
|
| 5977 | + } |
|
| 5805 | 5978 | |
| 5806 | 5979 | /** |
| 5807 | 5980 | * Fires when a post's status is transitioned from private to published. |
@@ -5873,11 +6046,13 @@ discard block |
||
| 5873 | 6046 | do_action( 'xmlrpc_publish_post', $post_id ); |
| 5874 | 6047 | } |
| 5875 | 6048 | |
| 5876 | - if ( defined('WP_IMPORTING') ) |
|
| 5877 | - return; |
|
| 6049 | + if ( defined('WP_IMPORTING') ) { |
|
| 6050 | + return; |
|
| 6051 | + } |
|
| 5878 | 6052 | |
| 5879 | - if ( get_option('default_pingback_flag') ) |
|
| 5880 | - add_post_meta( $post_id, '_pingme', '1' ); |
|
| 6053 | + if ( get_option('default_pingback_flag') ) { |
|
| 6054 | + add_post_meta( $post_id, '_pingme', '1' ); |
|
| 6055 | + } |
|
| 5881 | 6056 | add_post_meta( $post_id, '_encloseme', '1' ); |
| 5882 | 6057 | |
| 5883 | 6058 | wp_schedule_single_event(time(), 'do_pings'); |
@@ -5894,8 +6069,9 @@ discard block |
||
| 5894 | 6069 | */ |
| 5895 | 6070 | function wp_get_post_parent_id( $post_ID ) { |
| 5896 | 6071 | $post = get_post( $post_ID ); |
| 5897 | - if ( !$post || is_wp_error( $post ) ) |
|
| 5898 | - return false; |
|
| 6072 | + if ( !$post || is_wp_error( $post ) ) { |
|
| 6073 | + return false; |
|
| 6074 | + } |
|
| 5899 | 6075 | return (int) $post->post_parent; |
| 5900 | 6076 | } |
| 5901 | 6077 | |
@@ -5915,28 +6091,35 @@ discard block |
||
| 5915 | 6091 | */ |
| 5916 | 6092 | function wp_check_post_hierarchy_for_loops( $post_parent, $post_ID ) { |
| 5917 | 6093 | // Nothing fancy here - bail. |
| 5918 | - if ( !$post_parent ) |
|
| 5919 | - return 0; |
|
| 6094 | + if ( !$post_parent ) { |
|
| 6095 | + return 0; |
|
| 6096 | + } |
|
| 5920 | 6097 | |
| 5921 | 6098 | // New post can't cause a loop. |
| 5922 | - if ( empty( $post_ID ) ) |
|
| 5923 | - return $post_parent; |
|
| 6099 | + if ( empty( $post_ID ) ) { |
|
| 6100 | + return $post_parent; |
|
| 6101 | + } |
|
| 5924 | 6102 | |
| 5925 | 6103 | // Can't be its own parent. |
| 5926 | - if ( $post_parent == $post_ID ) |
|
| 5927 | - return 0; |
|
| 6104 | + if ( $post_parent == $post_ID ) { |
|
| 6105 | + return 0; |
|
| 6106 | + } |
|
| 5928 | 6107 | |
| 5929 | 6108 | // Now look for larger loops. |
| 5930 | - if ( !$loop = wp_find_hierarchy_loop( 'wp_get_post_parent_id', $post_ID, $post_parent ) ) |
|
| 5931 | - return $post_parent; // No loop |
|
| 6109 | + if ( !$loop = wp_find_hierarchy_loop( 'wp_get_post_parent_id', $post_ID, $post_parent ) ) { |
|
| 6110 | + return $post_parent; |
|
| 6111 | + } |
|
| 6112 | + // No loop |
|
| 5932 | 6113 | |
| 5933 | 6114 | // Setting $post_parent to the given value causes a loop. |
| 5934 | - if ( isset( $loop[$post_ID] ) ) |
|
| 5935 | - return 0; |
|
| 6115 | + if ( isset( $loop[$post_ID] ) ) { |
|
| 6116 | + return 0; |
|
| 6117 | + } |
|
| 5936 | 6118 | |
| 5937 | 6119 | // There's a loop, but it doesn't contain $post_ID. Break the loop. |
| 5938 | - foreach ( array_keys( $loop ) as $loop_member ) |
|
| 5939 | - wp_update_post( array( 'ID' => $loop_member, 'post_parent' => 0 ) ); |
|
| 6120 | + foreach ( array_keys( $loop ) as $loop_member ) { |
|
| 6121 | + wp_update_post( array( 'ID' => $loop_member, 'post_parent' => 0 ) ); |
|
| 6122 | + } |
|
| 5940 | 6123 | |
| 5941 | 6124 | return $post_parent; |
| 5942 | 6125 | } |
@@ -5954,10 +6137,11 @@ discard block |
||
| 5954 | 6137 | $post = get_post( $post ); |
| 5955 | 6138 | $thumbnail_id = absint( $thumbnail_id ); |
| 5956 | 6139 | if ( $post && $thumbnail_id && get_post( $thumbnail_id ) ) { |
| 5957 | - if ( wp_get_attachment_image( $thumbnail_id, 'thumbnail' ) ) |
|
| 5958 | - return update_post_meta( $post->ID, '_thumbnail_id', $thumbnail_id ); |
|
| 5959 | - else |
|
| 5960 | - return delete_post_meta( $post->ID, '_thumbnail_id' ); |
|
| 6140 | + if ( wp_get_attachment_image( $thumbnail_id, 'thumbnail' ) ) { |
|
| 6141 | + return update_post_meta( $post->ID, '_thumbnail_id', $thumbnail_id ); |
|
| 6142 | + } else { |
|
| 6143 | + return delete_post_meta( $post->ID, '_thumbnail_id' ); |
|
| 6144 | + } |
|
| 5961 | 6145 | } |
| 5962 | 6146 | return false; |
| 5963 | 6147 | } |
@@ -5972,8 +6156,9 @@ discard block |
||
| 5972 | 6156 | */ |
| 5973 | 6157 | function delete_post_thumbnail( $post ) { |
| 5974 | 6158 | $post = get_post( $post ); |
| 5975 | - if ( $post ) |
|
| 5976 | - return delete_post_meta( $post->ID, '_thumbnail_id' ); |
|
| 6159 | + if ( $post ) { |
|
| 6160 | + return delete_post_meta( $post->ID, '_thumbnail_id' ); |
|
| 6161 | + } |
|
| 5977 | 6162 | return false; |
| 5978 | 6163 | } |
| 5979 | 6164 | |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * @global WP_Query $wp_query Global WP_Query instance. |
| 21 | 21 | * |
| 22 | 22 | * @param string $var The variable key to retrieve. |
| 23 | - * @param mixed $default Optional. Value to return if the query variable is not set. Default empty. |
|
| 23 | + * @param boolean $default Optional. Value to return if the query variable is not set. Default empty. |
|
| 24 | 24 | * @return mixed Contents of the query variable. |
| 25 | 25 | */ |
| 26 | 26 | function get_query_var( $var, $default = '' ) { |
@@ -281,8 +281,8 @@ discard block |
||
| 281 | 281 | * |
| 282 | 282 | * @global WP_Query $wp_query Global WP_Query instance. |
| 283 | 283 | * |
| 284 | - * @param string|array $taxonomy Optional. Taxonomy slug or slugs. |
|
| 285 | - * @param int|string|array $term Optional. Term ID, name, slug or array of Term IDs, names, and slugs. |
|
| 284 | + * @param string $taxonomy Optional. Taxonomy slug or slugs. |
|
| 285 | + * @param string $term Optional. Term ID, name, slug or array of Term IDs, names, and slugs. |
|
| 286 | 286 | * @return bool |
| 287 | 287 | */ |
| 288 | 288 | function is_tax( $taxonomy = '', $term = '' ) { |
@@ -2178,7 +2178,7 @@ discard block |
||
| 2178 | 2178 | * |
| 2179 | 2179 | * @since 3.7.0 |
| 2180 | 2180 | * |
| 2181 | - * @param array $terms Terms to check. |
|
| 2181 | + * @param string[] $terms Terms to check. |
|
| 2182 | 2182 | * @return array Terms that are not stopwords. |
| 2183 | 2183 | */ |
| 2184 | 2184 | protected function parse_search_terms( $terms ) { |
@@ -4140,7 +4140,7 @@ discard block |
||
| 4140 | 4140 | * @access public |
| 4141 | 4141 | * |
| 4142 | 4142 | * @param string $name Property to check if set. |
| 4143 | - * @return bool Whether the property is set. |
|
| 4143 | + * @return boolean|null Whether the property is set. |
|
| 4144 | 4144 | */ |
| 4145 | 4145 | public function __isset( $name ) { |
| 4146 | 4146 | if ( in_array( $name, $this->compat_fields ) ) { |
@@ -4739,8 +4739,8 @@ discard block |
||
| 4739 | 4739 | * @global int $more |
| 4740 | 4740 | * @global int $numpages |
| 4741 | 4741 | * |
| 4742 | - * @param WP_Post|object|int $post WP_Post instance or Post ID/object. |
|
| 4743 | - * @return true True when finished. |
|
| 4742 | + * @param WP_Post $post WP_Post instance or Post ID/object. |
|
| 4743 | + * @return null|boolean True when finished. |
|
| 4744 | 4744 | */ |
| 4745 | 4745 | public function setup_postdata( $post ) { |
| 4746 | 4746 | global $id, $authordata, $currentday, $currentmonth, $page, $pages, $multipage, $more, $numpages; |
@@ -1,15 +1,15 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * WordPress Query API |
|
| 4 | - * |
|
| 5 | - * The query API attempts to get which part of WordPress the user is on. It |
|
| 6 | - * also provides functionality for getting URL query information. |
|
| 7 | - * |
|
| 8 | - * @link https://codex.wordpress.org/The_Loop More information on The Loop. |
|
| 9 | - * |
|
| 10 | - * @package WordPress |
|
| 11 | - * @subpackage Query |
|
| 12 | - */ |
|
| 3 | + * WordPress Query API |
|
| 4 | + * |
|
| 5 | + * The query API attempts to get which part of WordPress the user is on. It |
|
| 6 | + * also provides functionality for getting URL query information. |
|
| 7 | + * |
|
| 8 | + * @link https://codex.wordpress.org/The_Loop More information on The Loop. |
|
| 9 | + * |
|
| 10 | + * @package WordPress |
|
| 11 | + * @subpackage Query |
|
| 12 | + */ |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * Retrieve variable in the WP_Query class. |
@@ -4166,14 +4166,14 @@ discard block |
||
| 4166 | 4166 | } |
| 4167 | 4167 | |
| 4168 | 4168 | /** |
| 4169 | - * Is the query for an existing archive page? |
|
| 4170 | - * |
|
| 4171 | - * Month, Year, Category, Author, Post Type archive... |
|
| 4172 | - * |
|
| 4173 | - * @since 3.1.0 |
|
| 4174 | - * |
|
| 4175 | - * @return bool |
|
| 4176 | - */ |
|
| 4169 | + * Is the query for an existing archive page? |
|
| 4170 | + * |
|
| 4171 | + * Month, Year, Category, Author, Post Type archive... |
|
| 4172 | + * |
|
| 4173 | + * @since 3.1.0 |
|
| 4174 | + * |
|
| 4175 | + * @return bool |
|
| 4176 | + */ |
|
| 4177 | 4177 | public function is_archive() { |
| 4178 | 4178 | return (bool) $this->is_archive; |
| 4179 | 4179 | } |
@@ -23,9 +23,9 @@ discard block |
||
| 23 | 23 | * @param mixed $default Optional. Value to return if the query variable is not set. Default empty. |
| 24 | 24 | * @return mixed Contents of the query variable. |
| 25 | 25 | */ |
| 26 | -function get_query_var( $var, $default = '' ) { |
|
| 26 | +function get_query_var($var, $default = '') { |
|
| 27 | 27 | global $wp_query; |
| 28 | - return $wp_query->get( $var, $default ); |
|
| 28 | + return $wp_query->get($var, $default); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
@@ -71,9 +71,9 @@ discard block |
||
| 71 | 71 | * @param string $var Query variable key. |
| 72 | 72 | * @param mixed $value Query variable value. |
| 73 | 73 | */ |
| 74 | -function set_query_var( $var, $value ) { |
|
| 74 | +function set_query_var($var, $value) { |
|
| 75 | 75 | global $wp_query; |
| 76 | - $wp_query->set( $var, $value ); |
|
| 76 | + $wp_query->set($var, $value); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | function wp_reset_postdata() { |
| 123 | 123 | global $wp_query; |
| 124 | 124 | |
| 125 | - if ( isset( $wp_query ) ) { |
|
| 125 | + if (isset($wp_query)) { |
|
| 126 | 126 | $wp_query->reset_postdata(); |
| 127 | 127 | } |
| 128 | 128 | } |
@@ -145,8 +145,8 @@ discard block |
||
| 145 | 145 | function is_archive() { |
| 146 | 146 | global $wp_query; |
| 147 | 147 | |
| 148 | - if ( ! isset( $wp_query ) ) { |
|
| 149 | - _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' ); |
|
| 148 | + if ( ! isset($wp_query)) { |
|
| 149 | + _doing_it_wrong(__FUNCTION__, __('Conditional query tags do not work before the query is run. Before then, they always return false.'), '3.1'); |
|
| 150 | 150 | return false; |
| 151 | 151 | } |
| 152 | 152 | |
@@ -163,15 +163,15 @@ discard block |
||
| 163 | 163 | * @param string|array $post_types Optional. Post type or array of posts types to check against. |
| 164 | 164 | * @return bool |
| 165 | 165 | */ |
| 166 | -function is_post_type_archive( $post_types = '' ) { |
|
| 166 | +function is_post_type_archive($post_types = '') { |
|
| 167 | 167 | global $wp_query; |
| 168 | 168 | |
| 169 | - if ( ! isset( $wp_query ) ) { |
|
| 170 | - _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' ); |
|
| 169 | + if ( ! isset($wp_query)) { |
|
| 170 | + _doing_it_wrong(__FUNCTION__, __('Conditional query tags do not work before the query is run. Before then, they always return false.'), '3.1'); |
|
| 171 | 171 | return false; |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | - return $wp_query->is_post_type_archive( $post_types ); |
|
| 174 | + return $wp_query->is_post_type_archive($post_types); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
@@ -184,15 +184,15 @@ discard block |
||
| 184 | 184 | * @param int|string|array|object $attachment Attachment ID, title, slug, or array of such. |
| 185 | 185 | * @return bool |
| 186 | 186 | */ |
| 187 | -function is_attachment( $attachment = '' ) { |
|
| 187 | +function is_attachment($attachment = '') { |
|
| 188 | 188 | global $wp_query; |
| 189 | 189 | |
| 190 | - if ( ! isset( $wp_query ) ) { |
|
| 191 | - _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' ); |
|
| 190 | + if ( ! isset($wp_query)) { |
|
| 191 | + _doing_it_wrong(__FUNCTION__, __('Conditional query tags do not work before the query is run. Before then, they always return false.'), '3.1'); |
|
| 192 | 192 | return false; |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - return $wp_query->is_attachment( $attachment ); |
|
| 195 | + return $wp_query->is_attachment($attachment); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | /** |
@@ -208,15 +208,15 @@ discard block |
||
| 208 | 208 | * @param mixed $author Optional. User ID, nickname, nicename, or array of User IDs, nicknames, and nicenames |
| 209 | 209 | * @return bool |
| 210 | 210 | */ |
| 211 | -function is_author( $author = '' ) { |
|
| 211 | +function is_author($author = '') { |
|
| 212 | 212 | global $wp_query; |
| 213 | 213 | |
| 214 | - if ( ! isset( $wp_query ) ) { |
|
| 215 | - _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' ); |
|
| 214 | + if ( ! isset($wp_query)) { |
|
| 215 | + _doing_it_wrong(__FUNCTION__, __('Conditional query tags do not work before the query is run. Before then, they always return false.'), '3.1'); |
|
| 216 | 216 | return false; |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | - return $wp_query->is_author( $author ); |
|
| 219 | + return $wp_query->is_author($author); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -232,15 +232,15 @@ discard block |
||
| 232 | 232 | * @param mixed $category Optional. Category ID, name, slug, or array of Category IDs, names, and slugs. |
| 233 | 233 | * @return bool |
| 234 | 234 | */ |
| 235 | -function is_category( $category = '' ) { |
|
| 235 | +function is_category($category = '') { |
|
| 236 | 236 | global $wp_query; |
| 237 | 237 | |
| 238 | - if ( ! isset( $wp_query ) ) { |
|
| 239 | - _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' ); |
|
| 238 | + if ( ! isset($wp_query)) { |
|
| 239 | + _doing_it_wrong(__FUNCTION__, __('Conditional query tags do not work before the query is run. Before then, they always return false.'), '3.1'); |
|
| 240 | 240 | return false; |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - return $wp_query->is_category( $category ); |
|
| 243 | + return $wp_query->is_category($category); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | /** |
@@ -256,15 +256,15 @@ discard block |
||
| 256 | 256 | * @param mixed $tag Optional. Tag ID, name, slug, or array of Tag IDs, names, and slugs. |
| 257 | 257 | * @return bool |
| 258 | 258 | */ |
| 259 | -function is_tag( $tag = '' ) { |
|
| 259 | +function is_tag($tag = '') { |
|
| 260 | 260 | global $wp_query; |
| 261 | 261 | |
| 262 | - if ( ! isset( $wp_query ) ) { |
|
| 263 | - _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' ); |
|
| 262 | + if ( ! isset($wp_query)) { |
|
| 263 | + _doing_it_wrong(__FUNCTION__, __('Conditional query tags do not work before the query is run. Before then, they always return false.'), '3.1'); |
|
| 264 | 264 | return false; |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | - return $wp_query->is_tag( $tag ); |
|
| 267 | + return $wp_query->is_tag($tag); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | /** |
@@ -285,15 +285,15 @@ discard block |
||
| 285 | 285 | * @param int|string|array $term Optional. Term ID, name, slug or array of Term IDs, names, and slugs. |
| 286 | 286 | * @return bool |
| 287 | 287 | */ |
| 288 | -function is_tax( $taxonomy = '', $term = '' ) { |
|
| 288 | +function is_tax($taxonomy = '', $term = '') { |
|
| 289 | 289 | global $wp_query; |
| 290 | 290 | |
| 291 | - if ( ! isset( $wp_query ) ) { |
|
| 292 | - _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' ); |
|
| 291 | + if ( ! isset($wp_query)) { |
|
| 292 | + _doing_it_wrong(__FUNCTION__, __('Conditional query tags do not work before the query is run. Before then, they always return false.'), '3.1'); |
|
| 293 | 293 | return false; |
| 294 | 294 | } |
| 295 | 295 | |
| 296 | - return $wp_query->is_tax( $taxonomy, $term ); |
|
| 296 | + return $wp_query->is_tax($taxonomy, $term); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | /** |
@@ -308,8 +308,8 @@ discard block |
||
| 308 | 308 | function is_date() { |
| 309 | 309 | global $wp_query; |
| 310 | 310 | |
| 311 | - if ( ! isset( $wp_query ) ) { |
|
| 312 | - _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' ); |
|
| 311 | + if ( ! isset($wp_query)) { |
|
| 312 | + _doing_it_wrong(__FUNCTION__, __('Conditional query tags do not work before the query is run. Before then, they always return false.'), '3.1'); |
|
| 313 | 313 | return false; |
| 314 | 314 | } |
| 315 | 315 | |
@@ -328,8 +328,8 @@ discard block |
||
| 328 | 328 | function is_day() { |
| 329 | 329 | global $wp_query; |
| 330 | 330 | |
| 331 | - if ( ! isset( $wp_query ) ) { |
|
| 332 | - _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' ); |
|
| 331 | + if ( ! isset($wp_query)) { |
|
| 332 | + _doing_it_wrong(__FUNCTION__, __('Conditional query tags do not work before the query is run. Before then, they always return false.'), '3.1'); |
|
| 333 | 333 | return false; |
| 334 | 334 | } |
| 335 | 335 | |
@@ -346,15 +346,15 @@ discard block |
||
| 346 | 346 | * @param string|array $feeds Optional feed types to check. |
| 347 | 347 | * @return bool |
| 348 | 348 | */ |
| 349 | -function is_feed( $feeds = '' ) { |
|
| 349 | +function is_feed($feeds = '') { |
|
| 350 | 350 | global $wp_query; |
| 351 | 351 | |
| 352 | - if ( ! isset( $wp_query ) ) { |
|
| 353 | - _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' ); |
|
| 352 | + if ( ! isset($wp_query)) { |
|
| 353 | + _doing_it_wrong(__FUNCTION__, __('Conditional query tags do not work before the query is run. Before then, they always return false.'), '3.1'); |
|
| 354 | 354 | return false; |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | - return $wp_query->is_feed( $feeds ); |
|
| 357 | + return $wp_query->is_feed($feeds); |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | /** |
@@ -369,8 +369,8 @@ discard block |
||
| 369 | 369 | function is_comment_feed() { |
| 370 | 370 | global $wp_query; |
| 371 | 371 | |
| 372 | - if ( ! isset( $wp_query ) ) { |
|
| 373 | - _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' ); |
|
| 372 | + if ( ! isset($wp_query)) { |
|
| 373 | + _doing_it_wrong(__FUNCTION__, __('Conditional query tags do not work before the query is run. Before then, they always return false.'), '3.1'); |
|
| 374 | 374 | return false; |
| 375 | 375 | } |
| 376 | 376 | |
@@ -398,8 +398,8 @@ discard block |
||
| 398 | 398 | function is_front_page() { |
| 399 | 399 | global $wp_query; |
| 400 | 400 | |
| 401 | - if ( ! isset( $wp_query ) ) { |
|
| 402 | - _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' ); |
|
| 401 | + if ( ! isset($wp_query)) { |
|
| 402 | + _doing_it_wrong(__FUNCTION__, __('Conditional query tags do not work before the query is run. Before then, they always return false.'), '3.1'); |
|
| 403 | 403 | return false; |
| 404 | 404 | } |
| 405 | 405 | |
@@ -427,8 +427,8 @@ discard block |
||
| 427 | 427 | function is_home() { |
| 428 | 428 | global $wp_query; |
| 429 | 429 | |
| 430 | - if ( ! isset( $wp_query ) ) { |
|
| 431 | - _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' ); |
|
| 430 | + if ( ! isset($wp_query)) { |
|
| 431 | + _doing_it_wrong(__FUNCTION__, __('Conditional query tags do not work before the query is run. Before then, they always return false.'), '3.1'); |
|
| 432 | 432 | return false; |
| 433 | 433 | } |
| 434 | 434 | |
@@ -447,8 +447,8 @@ discard block |
||
| 447 | 447 | function is_month() { |
| 448 | 448 | global $wp_query; |
| 449 | 449 | |
| 450 | - if ( ! isset( $wp_query ) ) { |
|
| 451 | - _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' ); |
|
| 450 | + if ( ! isset($wp_query)) { |
|
| 451 | + _doing_it_wrong(__FUNCTION__, __('Conditional query tags do not work before the query is run. Before then, they always return false.'), '3.1'); |
|
| 452 | 452 | return false; |
| 453 | 453 | } |
| 454 | 454 | |
@@ -471,15 +471,15 @@ discard block |
||
| 471 | 471 | * @param int|string|array $page Optional. Page ID, title, slug, or array of such. Default empty. |
| 472 | 472 | * @return bool Whether the query is for an existing single page. |
| 473 | 473 | */ |
| 474 | -function is_page( $page = '' ) { |
|
| 474 | +function is_page($page = '') { |
|
| 475 | 475 | global $wp_query; |
| 476 | 476 | |
| 477 | - if ( ! isset( $wp_query ) ) { |
|
| 478 | - _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' ); |
|
| 477 | + if ( ! isset($wp_query)) { |
|
| 478 | + _doing_it_wrong(__FUNCTION__, __('Conditional query tags do not work before the query is run. Before then, they always return false.'), '3.1'); |
|
| 479 | 479 | return false; |
| 480 | 480 | } |
| 481 | 481 | |
| 482 | - return $wp_query->is_page( $page ); |
|
| 482 | + return $wp_query->is_page($page); |
|
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | /** |
@@ -494,8 +494,8 @@ discard block |
||
| 494 | 494 | function is_paged() { |
| 495 | 495 | global $wp_query; |
| 496 | 496 | |
| 497 | - if ( ! isset( $wp_query ) ) { |
|
| 498 | - _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' ); |
|
| 497 | + if ( ! isset($wp_query)) { |
|
| 498 | + _doing_it_wrong(__FUNCTION__, __('Conditional query tags do not work before the query is run. Before then, they always return false.'), '3.1'); |
|
| 499 | 499 | return false; |
| 500 | 500 | } |
| 501 | 501 | |
@@ -514,8 +514,8 @@ discard block |
||
| 514 | 514 | function is_preview() { |
| 515 | 515 | global $wp_query; |
| 516 | 516 | |
| 517 | - if ( ! isset( $wp_query ) ) { |
|
| 518 | - _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' ); |
|
| 517 | + if ( ! isset($wp_query)) { |
|
| 518 | + _doing_it_wrong(__FUNCTION__, __('Conditional query tags do not work before the query is run. Before then, they always return false.'), '3.1'); |
|
| 519 | 519 | return false; |
| 520 | 520 | } |
| 521 | 521 | |
@@ -534,8 +534,8 @@ discard block |
||
| 534 | 534 | function is_robots() { |
| 535 | 535 | global $wp_query; |
| 536 | 536 | |
| 537 | - if ( ! isset( $wp_query ) ) { |
|
| 538 | - _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' ); |
|
| 537 | + if ( ! isset($wp_query)) { |
|
| 538 | + _doing_it_wrong(__FUNCTION__, __('Conditional query tags do not work before the query is run. Before then, they always return false.'), '3.1'); |
|
| 539 | 539 | return false; |
| 540 | 540 | } |
| 541 | 541 | |
@@ -554,8 +554,8 @@ discard block |
||
| 554 | 554 | function is_search() { |
| 555 | 555 | global $wp_query; |
| 556 | 556 | |
| 557 | - if ( ! isset( $wp_query ) ) { |
|
| 558 | - _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' ); |
|
| 557 | + if ( ! isset($wp_query)) { |
|
| 558 | + _doing_it_wrong(__FUNCTION__, __('Conditional query tags do not work before the query is run. Before then, they always return false.'), '3.1'); |
|
| 559 | 559 | return false; |
| 560 | 560 | } |
| 561 | 561 | |
@@ -580,15 +580,15 @@ discard block |
||
| 580 | 580 | * @param int|string|array $post Optional. Post ID, title, slug, or array of such. Default empty. |
| 581 | 581 | * @return bool Whether the query is for an existing single post. |
| 582 | 582 | */ |
| 583 | -function is_single( $post = '' ) { |
|
| 583 | +function is_single($post = '') { |
|
| 584 | 584 | global $wp_query; |
| 585 | 585 | |
| 586 | - if ( ! isset( $wp_query ) ) { |
|
| 587 | - _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' ); |
|
| 586 | + if ( ! isset($wp_query)) { |
|
| 587 | + _doing_it_wrong(__FUNCTION__, __('Conditional query tags do not work before the query is run. Before then, they always return false.'), '3.1'); |
|
| 588 | 588 | return false; |
| 589 | 589 | } |
| 590 | 590 | |
| 591 | - return $wp_query->is_single( $post ); |
|
| 591 | + return $wp_query->is_single($post); |
|
| 592 | 592 | } |
| 593 | 593 | |
| 594 | 594 | /** |
@@ -607,15 +607,15 @@ discard block |
||
| 607 | 607 | * @param string|array $post_types Optional. Post type or array of post types. Default empty. |
| 608 | 608 | * @return bool Whether the query is for an existing single post of any of the given post types. |
| 609 | 609 | */ |
| 610 | -function is_singular( $post_types = '' ) { |
|
| 610 | +function is_singular($post_types = '') { |
|
| 611 | 611 | global $wp_query; |
| 612 | 612 | |
| 613 | - if ( ! isset( $wp_query ) ) { |
|
| 614 | - _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' ); |
|
| 613 | + if ( ! isset($wp_query)) { |
|
| 614 | + _doing_it_wrong(__FUNCTION__, __('Conditional query tags do not work before the query is run. Before then, they always return false.'), '3.1'); |
|
| 615 | 615 | return false; |
| 616 | 616 | } |
| 617 | 617 | |
| 618 | - return $wp_query->is_singular( $post_types ); |
|
| 618 | + return $wp_query->is_singular($post_types); |
|
| 619 | 619 | } |
| 620 | 620 | |
| 621 | 621 | /** |
@@ -630,8 +630,8 @@ discard block |
||
| 630 | 630 | function is_time() { |
| 631 | 631 | global $wp_query; |
| 632 | 632 | |
| 633 | - if ( ! isset( $wp_query ) ) { |
|
| 634 | - _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' ); |
|
| 633 | + if ( ! isset($wp_query)) { |
|
| 634 | + _doing_it_wrong(__FUNCTION__, __('Conditional query tags do not work before the query is run. Before then, they always return false.'), '3.1'); |
|
| 635 | 635 | return false; |
| 636 | 636 | } |
| 637 | 637 | |
@@ -650,8 +650,8 @@ discard block |
||
| 650 | 650 | function is_trackback() { |
| 651 | 651 | global $wp_query; |
| 652 | 652 | |
| 653 | - if ( ! isset( $wp_query ) ) { |
|
| 654 | - _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' ); |
|
| 653 | + if ( ! isset($wp_query)) { |
|
| 654 | + _doing_it_wrong(__FUNCTION__, __('Conditional query tags do not work before the query is run. Before then, they always return false.'), '3.1'); |
|
| 655 | 655 | return false; |
| 656 | 656 | } |
| 657 | 657 | |
@@ -670,8 +670,8 @@ discard block |
||
| 670 | 670 | function is_year() { |
| 671 | 671 | global $wp_query; |
| 672 | 672 | |
| 673 | - if ( ! isset( $wp_query ) ) { |
|
| 674 | - _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' ); |
|
| 673 | + if ( ! isset($wp_query)) { |
|
| 674 | + _doing_it_wrong(__FUNCTION__, __('Conditional query tags do not work before the query is run. Before then, they always return false.'), '3.1'); |
|
| 675 | 675 | return false; |
| 676 | 676 | } |
| 677 | 677 | |
@@ -690,8 +690,8 @@ discard block |
||
| 690 | 690 | function is_404() { |
| 691 | 691 | global $wp_query; |
| 692 | 692 | |
| 693 | - if ( ! isset( $wp_query ) ) { |
|
| 694 | - _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' ); |
|
| 693 | + if ( ! isset($wp_query)) { |
|
| 694 | + _doing_it_wrong(__FUNCTION__, __('Conditional query tags do not work before the query is run. Before then, they always return false.'), '3.1'); |
|
| 695 | 695 | return false; |
| 696 | 696 | } |
| 697 | 697 | |
@@ -710,8 +710,8 @@ discard block |
||
| 710 | 710 | function is_embed() { |
| 711 | 711 | global $wp_query; |
| 712 | 712 | |
| 713 | - if ( ! isset( $wp_query ) ) { |
|
| 714 | - _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' ); |
|
| 713 | + if ( ! isset($wp_query)) { |
|
| 714 | + _doing_it_wrong(__FUNCTION__, __('Conditional query tags do not work before the query is run. Before then, they always return false.'), '3.1'); |
|
| 715 | 715 | return false; |
| 716 | 716 | } |
| 717 | 717 | |
@@ -728,16 +728,16 @@ discard block |
||
| 728 | 728 | * @return bool |
| 729 | 729 | */ |
| 730 | 730 | function is_main_query() { |
| 731 | - if ( 'pre_get_posts' === current_filter() ) { |
|
| 731 | + if ('pre_get_posts' === current_filter()) { |
|
| 732 | 732 | $message = sprintf( |
| 733 | 733 | /* translators: 1: pre_get_posts 2: WP_Query->is_main_query() 3: is_main_query() 4: link to codex is_main_query() page. */ |
| 734 | - __( 'In %1$s, use the %2$s method, not the %3$s function. See %4$s.' ), |
|
| 734 | + __('In %1$s, use the %2$s method, not the %3$s function. See %4$s.'), |
|
| 735 | 735 | '<code>pre_get_posts</code>', |
| 736 | 736 | '<code>WP_Query->is_main_query()</code>', |
| 737 | 737 | '<code>is_main_query()</code>', |
| 738 | - __( 'https://codex.wordpress.org/Function_Reference/is_main_query' ) |
|
| 738 | + __('https://codex.wordpress.org/Function_Reference/is_main_query') |
|
| 739 | 739 | ); |
| 740 | - _doing_it_wrong( __FUNCTION__, $message, '3.7' ); |
|
| 740 | + _doing_it_wrong(__FUNCTION__, $message, '3.7'); |
|
| 741 | 741 | } |
| 742 | 742 | |
| 743 | 743 | global $wp_query; |
@@ -1311,9 +1311,9 @@ discard block |
||
| 1311 | 1311 | */ |
| 1312 | 1312 | private $stopwords; |
| 1313 | 1313 | |
| 1314 | - private $compat_fields = array( 'query_vars_hash', 'query_vars_changed' ); |
|
| 1314 | + private $compat_fields = array('query_vars_hash', 'query_vars_changed'); |
|
| 1315 | 1315 | |
| 1316 | - private $compat_methods = array( 'init_query_flags', 'parse_tax_query' ); |
|
| 1316 | + private $compat_methods = array('init_query_flags', 'parse_tax_query'); |
|
| 1317 | 1317 | |
| 1318 | 1318 | /** |
| 1319 | 1319 | * Resets query flags to false. |
@@ -1367,10 +1367,10 @@ discard block |
||
| 1367 | 1367 | $this->post_count = 0; |
| 1368 | 1368 | $this->current_post = -1; |
| 1369 | 1369 | $this->in_the_loop = false; |
| 1370 | - unset( $this->request ); |
|
| 1371 | - unset( $this->post ); |
|
| 1372 | - unset( $this->comments ); |
|
| 1373 | - unset( $this->comment ); |
|
| 1370 | + unset($this->request); |
|
| 1371 | + unset($this->post); |
|
| 1372 | + unset($this->comments); |
|
| 1373 | + unset($this->comment); |
|
| 1374 | 1374 | $this->comment_count = 0; |
| 1375 | 1375 | $this->current_comment = -1; |
| 1376 | 1376 | $this->found_posts = 0; |
@@ -1441,17 +1441,17 @@ discard block |
||
| 1441 | 1441 | , 'embed' |
| 1442 | 1442 | ); |
| 1443 | 1443 | |
| 1444 | - foreach ( $keys as $key ) { |
|
| 1445 | - if ( !isset($array[$key]) ) |
|
| 1444 | + foreach ($keys as $key) { |
|
| 1445 | + if ( ! isset($array[$key])) |
|
| 1446 | 1446 | $array[$key] = ''; |
| 1447 | 1447 | } |
| 1448 | 1448 | |
| 1449 | - $array_keys = array( 'category__in', 'category__not_in', 'category__and', 'post__in', 'post__not_in', 'post_name__in', |
|
| 1449 | + $array_keys = array('category__in', 'category__not_in', 'category__and', 'post__in', 'post__not_in', 'post_name__in', |
|
| 1450 | 1450 | 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'post_parent__in', 'post_parent__not_in', |
| 1451 | - 'author__in', 'author__not_in' ); |
|
| 1451 | + 'author__in', 'author__not_in'); |
|
| 1452 | 1452 | |
| 1453 | - foreach ( $array_keys as $key ) { |
|
| 1454 | - if ( !isset($array[$key]) ) |
|
| 1453 | + foreach ($array_keys as $key) { |
|
| 1454 | + if ( ! isset($array[$key])) |
|
| 1455 | 1455 | $array[$key] = array(); |
| 1456 | 1456 | } |
| 1457 | 1457 | return $array; |
@@ -1570,11 +1570,11 @@ discard block |
||
| 1570 | 1570 | * @type int $year The four-digit year. Default empty. Accepts any four-digit year. |
| 1571 | 1571 | * } |
| 1572 | 1572 | */ |
| 1573 | - public function parse_query( $query = '' ) { |
|
| 1574 | - if ( ! empty( $query ) ) { |
|
| 1573 | + public function parse_query($query = '') { |
|
| 1574 | + if ( ! empty($query)) { |
|
| 1575 | 1575 | $this->init(); |
| 1576 | - $this->query = $this->query_vars = wp_parse_args( $query ); |
|
| 1577 | - } elseif ( ! isset( $this->query ) ) { |
|
| 1576 | + $this->query = $this->query_vars = wp_parse_args($query); |
|
| 1577 | + } elseif ( ! isset($this->query)) { |
|
| 1578 | 1578 | $this->query = $this->query_vars; |
| 1579 | 1579 | } |
| 1580 | 1580 | |
@@ -1582,80 +1582,80 @@ discard block |
||
| 1582 | 1582 | $qv = &$this->query_vars; |
| 1583 | 1583 | $this->query_vars_changed = true; |
| 1584 | 1584 | |
| 1585 | - if ( ! empty($qv['robots']) ) |
|
| 1585 | + if ( ! empty($qv['robots'])) |
|
| 1586 | 1586 | $this->is_robots = true; |
| 1587 | 1587 | |
| 1588 | - $qv['p'] = absint($qv['p']); |
|
| 1589 | - $qv['page_id'] = absint($qv['page_id']); |
|
| 1588 | + $qv['p'] = absint($qv['p']); |
|
| 1589 | + $qv['page_id'] = absint($qv['page_id']); |
|
| 1590 | 1590 | $qv['year'] = absint($qv['year']); |
| 1591 | 1591 | $qv['monthnum'] = absint($qv['monthnum']); |
| 1592 | 1592 | $qv['day'] = absint($qv['day']); |
| 1593 | 1593 | $qv['w'] = absint($qv['w']); |
| 1594 | - $qv['m'] = preg_replace( '|[^0-9]|', '', $qv['m'] ); |
|
| 1594 | + $qv['m'] = preg_replace('|[^0-9]|', '', $qv['m']); |
|
| 1595 | 1595 | $qv['paged'] = absint($qv['paged']); |
| 1596 | - $qv['cat'] = preg_replace( '|[^0-9,-]|', '', $qv['cat'] ); // comma separated list of positive or negative integers |
|
| 1597 | - $qv['author'] = preg_replace( '|[^0-9,-]|', '', $qv['author'] ); // comma separated list of positive or negative integers |
|
| 1598 | - $qv['pagename'] = trim( $qv['pagename'] ); |
|
| 1599 | - $qv['name'] = trim( $qv['name'] ); |
|
| 1600 | - $qv['title'] = trim( $qv['title'] ); |
|
| 1601 | - if ( '' !== $qv['hour'] ) $qv['hour'] = absint($qv['hour']); |
|
| 1602 | - if ( '' !== $qv['minute'] ) $qv['minute'] = absint($qv['minute']); |
|
| 1603 | - if ( '' !== $qv['second'] ) $qv['second'] = absint($qv['second']); |
|
| 1604 | - if ( '' !== $qv['menu_order'] ) $qv['menu_order'] = absint($qv['menu_order']); |
|
| 1596 | + $qv['cat'] = preg_replace('|[^0-9,-]|', '', $qv['cat']); // comma separated list of positive or negative integers |
|
| 1597 | + $qv['author'] = preg_replace('|[^0-9,-]|', '', $qv['author']); // comma separated list of positive or negative integers |
|
| 1598 | + $qv['pagename'] = trim($qv['pagename']); |
|
| 1599 | + $qv['name'] = trim($qv['name']); |
|
| 1600 | + $qv['title'] = trim($qv['title']); |
|
| 1601 | + if ('' !== $qv['hour']) $qv['hour'] = absint($qv['hour']); |
|
| 1602 | + if ('' !== $qv['minute']) $qv['minute'] = absint($qv['minute']); |
|
| 1603 | + if ('' !== $qv['second']) $qv['second'] = absint($qv['second']); |
|
| 1604 | + if ('' !== $qv['menu_order']) $qv['menu_order'] = absint($qv['menu_order']); |
|
| 1605 | 1605 | |
| 1606 | 1606 | // Fairly insane upper bound for search string lengths. |
| 1607 | - if ( ! is_scalar( $qv['s'] ) || ( ! empty( $qv['s'] ) && strlen( $qv['s'] ) > 1600 ) ) { |
|
| 1607 | + if ( ! is_scalar($qv['s']) || ( ! empty($qv['s']) && strlen($qv['s']) > 1600)) { |
|
| 1608 | 1608 | $qv['s'] = ''; |
| 1609 | 1609 | } |
| 1610 | 1610 | |
| 1611 | 1611 | // Compat. Map subpost to attachment. |
| 1612 | - if ( '' != $qv['subpost'] ) |
|
| 1612 | + if ('' != $qv['subpost']) |
|
| 1613 | 1613 | $qv['attachment'] = $qv['subpost']; |
| 1614 | - if ( '' != $qv['subpost_id'] ) |
|
| 1614 | + if ('' != $qv['subpost_id']) |
|
| 1615 | 1615 | $qv['attachment_id'] = $qv['subpost_id']; |
| 1616 | 1616 | |
| 1617 | 1617 | $qv['attachment_id'] = absint($qv['attachment_id']); |
| 1618 | 1618 | |
| 1619 | - if ( ('' != $qv['attachment']) || !empty($qv['attachment_id']) ) { |
|
| 1619 | + if (('' != $qv['attachment']) || ! empty($qv['attachment_id'])) { |
|
| 1620 | 1620 | $this->is_single = true; |
| 1621 | 1621 | $this->is_attachment = true; |
| 1622 | - } elseif ( '' != $qv['name'] ) { |
|
| 1622 | + } elseif ('' != $qv['name']) { |
|
| 1623 | 1623 | $this->is_single = true; |
| 1624 | - } elseif ( $qv['p'] ) { |
|
| 1624 | + } elseif ($qv['p']) { |
|
| 1625 | 1625 | $this->is_single = true; |
| 1626 | - } elseif ( ('' !== $qv['hour']) && ('' !== $qv['minute']) &&('' !== $qv['second']) && ('' != $qv['year']) && ('' != $qv['monthnum']) && ('' != $qv['day']) ) { |
|
| 1626 | + } elseif (('' !== $qv['hour']) && ('' !== $qv['minute']) && ('' !== $qv['second']) && ('' != $qv['year']) && ('' != $qv['monthnum']) && ('' != $qv['day'])) { |
|
| 1627 | 1627 | // If year, month, day, hour, minute, and second are set, a single |
| 1628 | 1628 | // post is being queried. |
| 1629 | 1629 | $this->is_single = true; |
| 1630 | - } elseif ( '' != $qv['static'] || '' != $qv['pagename'] || !empty($qv['page_id']) ) { |
|
| 1630 | + } elseif ('' != $qv['static'] || '' != $qv['pagename'] || ! empty($qv['page_id'])) { |
|
| 1631 | 1631 | $this->is_page = true; |
| 1632 | 1632 | $this->is_single = false; |
| 1633 | 1633 | } else { |
| 1634 | 1634 | // Look for archive queries. Dates, categories, authors, search, post type archives. |
| 1635 | 1635 | |
| 1636 | - if ( isset( $this->query['s'] ) ) { |
|
| 1636 | + if (isset($this->query['s'])) { |
|
| 1637 | 1637 | $this->is_search = true; |
| 1638 | 1638 | } |
| 1639 | 1639 | |
| 1640 | - if ( '' !== $qv['second'] ) { |
|
| 1640 | + if ('' !== $qv['second']) { |
|
| 1641 | 1641 | $this->is_time = true; |
| 1642 | 1642 | $this->is_date = true; |
| 1643 | 1643 | } |
| 1644 | 1644 | |
| 1645 | - if ( '' !== $qv['minute'] ) { |
|
| 1645 | + if ('' !== $qv['minute']) { |
|
| 1646 | 1646 | $this->is_time = true; |
| 1647 | 1647 | $this->is_date = true; |
| 1648 | 1648 | } |
| 1649 | 1649 | |
| 1650 | - if ( '' !== $qv['hour'] ) { |
|
| 1650 | + if ('' !== $qv['hour']) { |
|
| 1651 | 1651 | $this->is_time = true; |
| 1652 | 1652 | $this->is_date = true; |
| 1653 | 1653 | } |
| 1654 | 1654 | |
| 1655 | - if ( $qv['day'] ) { |
|
| 1656 | - if ( ! $this->is_date ) { |
|
| 1657 | - $date = sprintf( '%04d-%02d-%02d', $qv['year'], $qv['monthnum'], $qv['day'] ); |
|
| 1658 | - if ( $qv['monthnum'] && $qv['year'] && ! wp_checkdate( $qv['monthnum'], $qv['day'], $qv['year'], $date ) ) { |
|
| 1655 | + if ($qv['day']) { |
|
| 1656 | + if ( ! $this->is_date) { |
|
| 1657 | + $date = sprintf('%04d-%02d-%02d', $qv['year'], $qv['monthnum'], $qv['day']); |
|
| 1658 | + if ($qv['monthnum'] && $qv['year'] && ! wp_checkdate($qv['monthnum'], $qv['day'], $qv['year'], $date)) { |
|
| 1659 | 1659 | $qv['error'] = '404'; |
| 1660 | 1660 | } else { |
| 1661 | 1661 | $this->is_day = true; |
@@ -1664,9 +1664,9 @@ discard block |
||
| 1664 | 1664 | } |
| 1665 | 1665 | } |
| 1666 | 1666 | |
| 1667 | - if ( $qv['monthnum'] ) { |
|
| 1668 | - if ( ! $this->is_date ) { |
|
| 1669 | - if ( 12 < $qv['monthnum'] ) { |
|
| 1667 | + if ($qv['monthnum']) { |
|
| 1668 | + if ( ! $this->is_date) { |
|
| 1669 | + if (12 < $qv['monthnum']) { |
|
| 1670 | 1670 | $qv['error'] = '404'; |
| 1671 | 1671 | } else { |
| 1672 | 1672 | $this->is_month = true; |
@@ -1675,40 +1675,40 @@ discard block |
||
| 1675 | 1675 | } |
| 1676 | 1676 | } |
| 1677 | 1677 | |
| 1678 | - if ( $qv['year'] ) { |
|
| 1679 | - if ( ! $this->is_date ) { |
|
| 1678 | + if ($qv['year']) { |
|
| 1679 | + if ( ! $this->is_date) { |
|
| 1680 | 1680 | $this->is_year = true; |
| 1681 | 1681 | $this->is_date = true; |
| 1682 | 1682 | } |
| 1683 | 1683 | } |
| 1684 | 1684 | |
| 1685 | - if ( $qv['m'] ) { |
|
| 1685 | + if ($qv['m']) { |
|
| 1686 | 1686 | $this->is_date = true; |
| 1687 | - if ( strlen($qv['m']) > 9 ) { |
|
| 1687 | + if (strlen($qv['m']) > 9) { |
|
| 1688 | 1688 | $this->is_time = true; |
| 1689 | - } elseif ( strlen( $qv['m'] ) > 7 ) { |
|
| 1689 | + } elseif (strlen($qv['m']) > 7) { |
|
| 1690 | 1690 | $this->is_day = true; |
| 1691 | - } elseif ( strlen( $qv['m'] ) > 5 ) { |
|
| 1691 | + } elseif (strlen($qv['m']) > 5) { |
|
| 1692 | 1692 | $this->is_month = true; |
| 1693 | 1693 | } else { |
| 1694 | 1694 | $this->is_year = true; |
| 1695 | 1695 | } |
| 1696 | 1696 | } |
| 1697 | 1697 | |
| 1698 | - if ( '' != $qv['w'] ) { |
|
| 1698 | + if ('' != $qv['w']) { |
|
| 1699 | 1699 | $this->is_date = true; |
| 1700 | 1700 | } |
| 1701 | 1701 | |
| 1702 | 1702 | $this->query_vars_hash = false; |
| 1703 | - $this->parse_tax_query( $qv ); |
|
| 1703 | + $this->parse_tax_query($qv); |
|
| 1704 | 1704 | |
| 1705 | - foreach ( $this->tax_query->queries as $tax_query ) { |
|
| 1706 | - if ( ! is_array( $tax_query ) ) { |
|
| 1705 | + foreach ($this->tax_query->queries as $tax_query) { |
|
| 1706 | + if ( ! is_array($tax_query)) { |
|
| 1707 | 1707 | continue; |
| 1708 | 1708 | } |
| 1709 | 1709 | |
| 1710 | - if ( isset( $tax_query['operator'] ) && 'NOT IN' != $tax_query['operator'] ) { |
|
| 1711 | - switch ( $tax_query['taxonomy'] ) { |
|
| 1710 | + if (isset($tax_query['operator']) && 'NOT IN' != $tax_query['operator']) { |
|
| 1711 | + switch ($tax_query['taxonomy']) { |
|
| 1712 | 1712 | case 'category': |
| 1713 | 1713 | $this->is_category = true; |
| 1714 | 1714 | break; |
@@ -1720,89 +1720,89 @@ discard block |
||
| 1720 | 1720 | } |
| 1721 | 1721 | } |
| 1722 | 1722 | } |
| 1723 | - unset( $tax_query ); |
|
| 1723 | + unset($tax_query); |
|
| 1724 | 1724 | |
| 1725 | - if ( empty($qv['author']) || ($qv['author'] == '0') ) { |
|
| 1725 | + if (empty($qv['author']) || ($qv['author'] == '0')) { |
|
| 1726 | 1726 | $this->is_author = false; |
| 1727 | 1727 | } else { |
| 1728 | 1728 | $this->is_author = true; |
| 1729 | 1729 | } |
| 1730 | 1730 | |
| 1731 | - if ( '' != $qv['author_name'] ) |
|
| 1731 | + if ('' != $qv['author_name']) |
|
| 1732 | 1732 | $this->is_author = true; |
| 1733 | 1733 | |
| 1734 | - if ( !empty( $qv['post_type'] ) && ! is_array( $qv['post_type'] ) ) { |
|
| 1735 | - $post_type_obj = get_post_type_object( $qv['post_type'] ); |
|
| 1736 | - if ( ! empty( $post_type_obj->has_archive ) ) |
|
| 1734 | + if ( ! empty($qv['post_type']) && ! is_array($qv['post_type'])) { |
|
| 1735 | + $post_type_obj = get_post_type_object($qv['post_type']); |
|
| 1736 | + if ( ! empty($post_type_obj->has_archive)) |
|
| 1737 | 1737 | $this->is_post_type_archive = true; |
| 1738 | 1738 | } |
| 1739 | 1739 | |
| 1740 | - if ( $this->is_post_type_archive || $this->is_date || $this->is_author || $this->is_category || $this->is_tag || $this->is_tax ) |
|
| 1740 | + if ($this->is_post_type_archive || $this->is_date || $this->is_author || $this->is_category || $this->is_tag || $this->is_tax) |
|
| 1741 | 1741 | $this->is_archive = true; |
| 1742 | 1742 | } |
| 1743 | 1743 | |
| 1744 | - if ( '' != $qv['feed'] ) |
|
| 1744 | + if ('' != $qv['feed']) |
|
| 1745 | 1745 | $this->is_feed = true; |
| 1746 | 1746 | |
| 1747 | - if ( '' != $qv['embed'] ) { |
|
| 1747 | + if ('' != $qv['embed']) { |
|
| 1748 | 1748 | $this->is_embed = true; |
| 1749 | 1749 | } |
| 1750 | 1750 | |
| 1751 | - if ( '' != $qv['tb'] ) |
|
| 1751 | + if ('' != $qv['tb']) |
|
| 1752 | 1752 | $this->is_trackback = true; |
| 1753 | 1753 | |
| 1754 | - if ( '' != $qv['paged'] && ( intval($qv['paged']) > 1 ) ) |
|
| 1754 | + if ('' != $qv['paged'] && (intval($qv['paged']) > 1)) |
|
| 1755 | 1755 | $this->is_paged = true; |
| 1756 | 1756 | |
| 1757 | 1757 | // if we're previewing inside the write screen |
| 1758 | - if ( '' != $qv['preview'] ) |
|
| 1758 | + if ('' != $qv['preview']) |
|
| 1759 | 1759 | $this->is_preview = true; |
| 1760 | 1760 | |
| 1761 | - if ( is_admin() ) |
|
| 1761 | + if (is_admin()) |
|
| 1762 | 1762 | $this->is_admin = true; |
| 1763 | 1763 | |
| 1764 | - if ( false !== strpos($qv['feed'], 'comments-') ) { |
|
| 1764 | + if (false !== strpos($qv['feed'], 'comments-')) { |
|
| 1765 | 1765 | $qv['feed'] = str_replace('comments-', '', $qv['feed']); |
| 1766 | 1766 | $qv['withcomments'] = 1; |
| 1767 | 1767 | } |
| 1768 | 1768 | |
| 1769 | 1769 | $this->is_singular = $this->is_single || $this->is_page || $this->is_attachment; |
| 1770 | 1770 | |
| 1771 | - if ( $this->is_feed && ( !empty($qv['withcomments']) || ( empty($qv['withoutcomments']) && $this->is_singular ) ) ) |
|
| 1771 | + if ($this->is_feed && ( ! empty($qv['withcomments']) || (empty($qv['withoutcomments']) && $this->is_singular))) |
|
| 1772 | 1772 | $this->is_comment_feed = true; |
| 1773 | 1773 | |
| 1774 | - if ( !( $this->is_singular || $this->is_archive || $this->is_search || $this->is_feed || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) || $this->is_trackback || $this->is_404 || $this->is_admin || $this->is_robots ) ) |
|
| 1774 | + if ( ! ($this->is_singular || $this->is_archive || $this->is_search || $this->is_feed || (defined('REST_REQUEST') && REST_REQUEST) || $this->is_trackback || $this->is_404 || $this->is_admin || $this->is_robots)) |
|
| 1775 | 1775 | $this->is_home = true; |
| 1776 | 1776 | |
| 1777 | 1777 | // Correct is_* for page_on_front and page_for_posts |
| 1778 | - if ( $this->is_home && 'page' == get_option('show_on_front') && get_option('page_on_front') ) { |
|
| 1778 | + if ($this->is_home && 'page' == get_option('show_on_front') && get_option('page_on_front')) { |
|
| 1779 | 1779 | $_query = wp_parse_args($this->query); |
| 1780 | 1780 | // pagename can be set and empty depending on matched rewrite rules. Ignore an empty pagename. |
| 1781 | - if ( isset($_query['pagename']) && '' == $_query['pagename'] ) |
|
| 1781 | + if (isset($_query['pagename']) && '' == $_query['pagename']) |
|
| 1782 | 1782 | unset($_query['pagename']); |
| 1783 | 1783 | |
| 1784 | - unset( $_query['embed'] ); |
|
| 1784 | + unset($_query['embed']); |
|
| 1785 | 1785 | |
| 1786 | - if ( empty($_query) || !array_diff( array_keys($_query), array('preview', 'page', 'paged', 'cpage') ) ) { |
|
| 1786 | + if (empty($_query) || ! array_diff(array_keys($_query), array('preview', 'page', 'paged', 'cpage'))) { |
|
| 1787 | 1787 | $this->is_page = true; |
| 1788 | 1788 | $this->is_home = false; |
| 1789 | 1789 | $qv['page_id'] = get_option('page_on_front'); |
| 1790 | 1790 | // Correct <!--nextpage--> for page_on_front |
| 1791 | - if ( !empty($qv['paged']) ) { |
|
| 1791 | + if ( ! empty($qv['paged'])) { |
|
| 1792 | 1792 | $qv['page'] = $qv['paged']; |
| 1793 | 1793 | unset($qv['paged']); |
| 1794 | 1794 | } |
| 1795 | 1795 | } |
| 1796 | 1796 | } |
| 1797 | 1797 | |
| 1798 | - if ( '' != $qv['pagename'] ) { |
|
| 1799 | - $this->queried_object = get_page_by_path( $qv['pagename'] ); |
|
| 1798 | + if ('' != $qv['pagename']) { |
|
| 1799 | + $this->queried_object = get_page_by_path($qv['pagename']); |
|
| 1800 | 1800 | |
| 1801 | - if ( $this->queried_object && 'attachment' == $this->queried_object->post_type ) { |
|
| 1802 | - if ( preg_match( "/^[^%]*%(?:postname)%/", get_option( 'permalink_structure' ) ) ) { |
|
| 1801 | + if ($this->queried_object && 'attachment' == $this->queried_object->post_type) { |
|
| 1802 | + if (preg_match("/^[^%]*%(?:postname)%/", get_option('permalink_structure'))) { |
|
| 1803 | 1803 | // See if we also have a post with the same slug |
| 1804 | - $post = get_page_by_path( $qv['pagename'], OBJECT, 'post' ); |
|
| 1805 | - if ( $post ) { |
|
| 1804 | + $post = get_page_by_path($qv['pagename'], OBJECT, 'post'); |
|
| 1805 | + if ($post) { |
|
| 1806 | 1806 | $this->queried_object = $post; |
| 1807 | 1807 | $this->is_page = false; |
| 1808 | 1808 | $this->is_single = true; |
@@ -1810,53 +1810,53 @@ discard block |
||
| 1810 | 1810 | } |
| 1811 | 1811 | } |
| 1812 | 1812 | |
| 1813 | - if ( ! empty( $this->queried_object ) ) { |
|
| 1813 | + if ( ! empty($this->queried_object)) { |
|
| 1814 | 1814 | $this->queried_object_id = (int) $this->queried_object->ID; |
| 1815 | 1815 | } else { |
| 1816 | - unset( $this->queried_object ); |
|
| 1816 | + unset($this->queried_object); |
|
| 1817 | 1817 | } |
| 1818 | 1818 | |
| 1819 | - if ( 'page' == get_option('show_on_front') && isset($this->queried_object_id) && $this->queried_object_id == get_option('page_for_posts') ) { |
|
| 1819 | + if ('page' == get_option('show_on_front') && isset($this->queried_object_id) && $this->queried_object_id == get_option('page_for_posts')) { |
|
| 1820 | 1820 | $this->is_page = false; |
| 1821 | 1821 | $this->is_home = true; |
| 1822 | 1822 | $this->is_posts_page = true; |
| 1823 | 1823 | } |
| 1824 | 1824 | } |
| 1825 | 1825 | |
| 1826 | - if ( $qv['page_id'] ) { |
|
| 1827 | - if ( 'page' == get_option('show_on_front') && $qv['page_id'] == get_option('page_for_posts') ) { |
|
| 1826 | + if ($qv['page_id']) { |
|
| 1827 | + if ('page' == get_option('show_on_front') && $qv['page_id'] == get_option('page_for_posts')) { |
|
| 1828 | 1828 | $this->is_page = false; |
| 1829 | 1829 | $this->is_home = true; |
| 1830 | 1830 | $this->is_posts_page = true; |
| 1831 | 1831 | } |
| 1832 | 1832 | } |
| 1833 | 1833 | |
| 1834 | - if ( !empty($qv['post_type']) ) { |
|
| 1835 | - if ( is_array($qv['post_type']) ) |
|
| 1834 | + if ( ! empty($qv['post_type'])) { |
|
| 1835 | + if (is_array($qv['post_type'])) |
|
| 1836 | 1836 | $qv['post_type'] = array_map('sanitize_key', $qv['post_type']); |
| 1837 | 1837 | else |
| 1838 | 1838 | $qv['post_type'] = sanitize_key($qv['post_type']); |
| 1839 | 1839 | } |
| 1840 | 1840 | |
| 1841 | - if ( ! empty( $qv['post_status'] ) ) { |
|
| 1842 | - if ( is_array( $qv['post_status'] ) ) |
|
| 1841 | + if ( ! empty($qv['post_status'])) { |
|
| 1842 | + if (is_array($qv['post_status'])) |
|
| 1843 | 1843 | $qv['post_status'] = array_map('sanitize_key', $qv['post_status']); |
| 1844 | 1844 | else |
| 1845 | 1845 | $qv['post_status'] = preg_replace('|[^a-z0-9_,-]|', '', $qv['post_status']); |
| 1846 | 1846 | } |
| 1847 | 1847 | |
| 1848 | - if ( $this->is_posts_page && ( ! isset($qv['withcomments']) || ! $qv['withcomments'] ) ) |
|
| 1848 | + if ($this->is_posts_page && ( ! isset($qv['withcomments']) || ! $qv['withcomments'])) |
|
| 1849 | 1849 | $this->is_comment_feed = false; |
| 1850 | 1850 | |
| 1851 | 1851 | $this->is_singular = $this->is_single || $this->is_page || $this->is_attachment; |
| 1852 | 1852 | // Done correcting is_* for page_on_front and page_for_posts |
| 1853 | 1853 | |
| 1854 | - if ( '404' == $qv['error'] ) |
|
| 1854 | + if ('404' == $qv['error']) |
|
| 1855 | 1855 | $this->set_404(); |
| 1856 | 1856 | |
| 1857 | - $this->is_embed = $this->is_embed && ( $this->is_singular || $this->is_404 ); |
|
| 1857 | + $this->is_embed = $this->is_embed && ($this->is_singular || $this->is_404); |
|
| 1858 | 1858 | |
| 1859 | - $this->query_vars_hash = md5( serialize( $this->query_vars ) ); |
|
| 1859 | + $this->query_vars_hash = md5(serialize($this->query_vars)); |
|
| 1860 | 1860 | $this->query_vars_changed = false; |
| 1861 | 1861 | |
| 1862 | 1862 | /** |
@@ -1866,7 +1866,7 @@ discard block |
||
| 1866 | 1866 | * |
| 1867 | 1867 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 1868 | 1868 | */ |
| 1869 | - do_action_ref_array( 'parse_query', array( &$this ) ); |
|
| 1869 | + do_action_ref_array('parse_query', array(&$this)); |
|
| 1870 | 1870 | } |
| 1871 | 1871 | |
| 1872 | 1872 | /** |
@@ -1879,77 +1879,77 @@ discard block |
||
| 1879 | 1879 | * |
| 1880 | 1880 | * @param array $q The query variables. Passed by reference. |
| 1881 | 1881 | */ |
| 1882 | - public function parse_tax_query( &$q ) { |
|
| 1883 | - if ( ! empty( $q['tax_query'] ) && is_array( $q['tax_query'] ) ) { |
|
| 1882 | + public function parse_tax_query(&$q) { |
|
| 1883 | + if ( ! empty($q['tax_query']) && is_array($q['tax_query'])) { |
|
| 1884 | 1884 | $tax_query = $q['tax_query']; |
| 1885 | 1885 | } else { |
| 1886 | 1886 | $tax_query = array(); |
| 1887 | 1887 | } |
| 1888 | 1888 | |
| 1889 | - if ( !empty($q['taxonomy']) && !empty($q['term']) ) { |
|
| 1889 | + if ( ! empty($q['taxonomy']) && ! empty($q['term'])) { |
|
| 1890 | 1890 | $tax_query[] = array( |
| 1891 | 1891 | 'taxonomy' => $q['taxonomy'], |
| 1892 | - 'terms' => array( $q['term'] ), |
|
| 1892 | + 'terms' => array($q['term']), |
|
| 1893 | 1893 | 'field' => 'slug', |
| 1894 | 1894 | ); |
| 1895 | 1895 | } |
| 1896 | 1896 | |
| 1897 | - foreach ( get_taxonomies( array() , 'objects' ) as $taxonomy => $t ) { |
|
| 1898 | - if ( 'post_tag' == $taxonomy ) |
|
| 1899 | - continue; // Handled further down in the $q['tag'] block |
|
| 1897 | + foreach (get_taxonomies(array(), 'objects') as $taxonomy => $t) { |
|
| 1898 | + if ('post_tag' == $taxonomy) |
|
| 1899 | + continue; // Handled further down in the $q['tag'] block |
|
| 1900 | 1900 | |
| 1901 | - if ( $t->query_var && !empty( $q[$t->query_var] ) ) { |
|
| 1901 | + if ($t->query_var && ! empty($q[$t->query_var])) { |
|
| 1902 | 1902 | $tax_query_defaults = array( |
| 1903 | 1903 | 'taxonomy' => $taxonomy, |
| 1904 | 1904 | 'field' => 'slug', |
| 1905 | 1905 | ); |
| 1906 | 1906 | |
| 1907 | - if ( isset( $t->rewrite['hierarchical'] ) && $t->rewrite['hierarchical'] ) { |
|
| 1908 | - $q[$t->query_var] = wp_basename( $q[$t->query_var] ); |
|
| 1907 | + if (isset($t->rewrite['hierarchical']) && $t->rewrite['hierarchical']) { |
|
| 1908 | + $q[$t->query_var] = wp_basename($q[$t->query_var]); |
|
| 1909 | 1909 | } |
| 1910 | 1910 | |
| 1911 | 1911 | $term = $q[$t->query_var]; |
| 1912 | 1912 | |
| 1913 | - if ( is_array( $term ) ) { |
|
| 1914 | - $term = implode( ',', $term ); |
|
| 1913 | + if (is_array($term)) { |
|
| 1914 | + $term = implode(',', $term); |
|
| 1915 | 1915 | } |
| 1916 | 1916 | |
| 1917 | - if ( strpos($term, '+') !== false ) { |
|
| 1918 | - $terms = preg_split( '/[+]+/', $term ); |
|
| 1919 | - foreach ( $terms as $term ) { |
|
| 1920 | - $tax_query[] = array_merge( $tax_query_defaults, array( |
|
| 1921 | - 'terms' => array( $term ) |
|
| 1922 | - ) ); |
|
| 1917 | + if (strpos($term, '+') !== false) { |
|
| 1918 | + $terms = preg_split('/[+]+/', $term); |
|
| 1919 | + foreach ($terms as $term) { |
|
| 1920 | + $tax_query[] = array_merge($tax_query_defaults, array( |
|
| 1921 | + 'terms' => array($term) |
|
| 1922 | + )); |
|
| 1923 | 1923 | } |
| 1924 | 1924 | } else { |
| 1925 | - $tax_query[] = array_merge( $tax_query_defaults, array( |
|
| 1926 | - 'terms' => preg_split( '/[,]+/', $term ) |
|
| 1927 | - ) ); |
|
| 1925 | + $tax_query[] = array_merge($tax_query_defaults, array( |
|
| 1926 | + 'terms' => preg_split('/[,]+/', $term) |
|
| 1927 | + )); |
|
| 1928 | 1928 | } |
| 1929 | 1929 | } |
| 1930 | 1930 | } |
| 1931 | 1931 | |
| 1932 | 1932 | // If querystring 'cat' is an array, implode it. |
| 1933 | - if ( is_array( $q['cat'] ) ) { |
|
| 1934 | - $q['cat'] = implode( ',', $q['cat'] ); |
|
| 1933 | + if (is_array($q['cat'])) { |
|
| 1934 | + $q['cat'] = implode(',', $q['cat']); |
|
| 1935 | 1935 | } |
| 1936 | 1936 | |
| 1937 | 1937 | // Category stuff |
| 1938 | - if ( ! empty( $q['cat'] ) && ! $this->is_singular ) { |
|
| 1938 | + if ( ! empty($q['cat']) && ! $this->is_singular) { |
|
| 1939 | 1939 | $cat_in = $cat_not_in = array(); |
| 1940 | 1940 | |
| 1941 | - $cat_array = preg_split( '/[,\s]+/', urldecode( $q['cat'] ) ); |
|
| 1942 | - $cat_array = array_map( 'intval', $cat_array ); |
|
| 1943 | - $q['cat'] = implode( ',', $cat_array ); |
|
| 1941 | + $cat_array = preg_split('/[,\s]+/', urldecode($q['cat'])); |
|
| 1942 | + $cat_array = array_map('intval', $cat_array); |
|
| 1943 | + $q['cat'] = implode(',', $cat_array); |
|
| 1944 | 1944 | |
| 1945 | - foreach ( $cat_array as $cat ) { |
|
| 1946 | - if ( $cat > 0 ) |
|
| 1945 | + foreach ($cat_array as $cat) { |
|
| 1946 | + if ($cat > 0) |
|
| 1947 | 1947 | $cat_in[] = $cat; |
| 1948 | - elseif ( $cat < 0 ) |
|
| 1949 | - $cat_not_in[] = abs( $cat ); |
|
| 1948 | + elseif ($cat < 0) |
|
| 1949 | + $cat_not_in[] = abs($cat); |
|
| 1950 | 1950 | } |
| 1951 | 1951 | |
| 1952 | - if ( ! empty( $cat_in ) ) { |
|
| 1952 | + if ( ! empty($cat_in)) { |
|
| 1953 | 1953 | $tax_query[] = array( |
| 1954 | 1954 | 'taxonomy' => 'category', |
| 1955 | 1955 | 'terms' => $cat_in, |
@@ -1958,7 +1958,7 @@ discard block |
||
| 1958 | 1958 | ); |
| 1959 | 1959 | } |
| 1960 | 1960 | |
| 1961 | - if ( ! empty( $cat_not_in ) ) { |
|
| 1961 | + if ( ! empty($cat_not_in)) { |
|
| 1962 | 1962 | $tax_query[] = array( |
| 1963 | 1963 | 'taxonomy' => 'category', |
| 1964 | 1964 | 'terms' => $cat_not_in, |
@@ -1967,19 +1967,19 @@ discard block |
||
| 1967 | 1967 | 'include_children' => true |
| 1968 | 1968 | ); |
| 1969 | 1969 | } |
| 1970 | - unset( $cat_array, $cat_in, $cat_not_in ); |
|
| 1970 | + unset($cat_array, $cat_in, $cat_not_in); |
|
| 1971 | 1971 | } |
| 1972 | 1972 | |
| 1973 | - if ( ! empty( $q['category__and'] ) && 1 === count( (array) $q['category__and'] ) ) { |
|
| 1973 | + if ( ! empty($q['category__and']) && 1 === count((array) $q['category__and'])) { |
|
| 1974 | 1974 | $q['category__and'] = (array) $q['category__and']; |
| 1975 | - if ( ! isset( $q['category__in'] ) ) |
|
| 1975 | + if ( ! isset($q['category__in'])) |
|
| 1976 | 1976 | $q['category__in'] = array(); |
| 1977 | - $q['category__in'][] = absint( reset( $q['category__and'] ) ); |
|
| 1978 | - unset( $q['category__and'] ); |
|
| 1977 | + $q['category__in'][] = absint(reset($q['category__and'])); |
|
| 1978 | + unset($q['category__and']); |
|
| 1979 | 1979 | } |
| 1980 | 1980 | |
| 1981 | - if ( ! empty( $q['category__in'] ) ) { |
|
| 1982 | - $q['category__in'] = array_map( 'absint', array_unique( (array) $q['category__in'] ) ); |
|
| 1981 | + if ( ! empty($q['category__in'])) { |
|
| 1982 | + $q['category__in'] = array_map('absint', array_unique((array) $q['category__in'])); |
|
| 1983 | 1983 | $tax_query[] = array( |
| 1984 | 1984 | 'taxonomy' => 'category', |
| 1985 | 1985 | 'terms' => $q['category__in'], |
@@ -1988,8 +1988,8 @@ discard block |
||
| 1988 | 1988 | ); |
| 1989 | 1989 | } |
| 1990 | 1990 | |
| 1991 | - if ( ! empty($q['category__not_in']) ) { |
|
| 1992 | - $q['category__not_in'] = array_map( 'absint', array_unique( (array) $q['category__not_in'] ) ); |
|
| 1991 | + if ( ! empty($q['category__not_in'])) { |
|
| 1992 | + $q['category__not_in'] = array_map('absint', array_unique((array) $q['category__not_in'])); |
|
| 1993 | 1993 | $tax_query[] = array( |
| 1994 | 1994 | 'taxonomy' => 'category', |
| 1995 | 1995 | 'terms' => $q['category__not_in'], |
@@ -1998,8 +1998,8 @@ discard block |
||
| 1998 | 1998 | ); |
| 1999 | 1999 | } |
| 2000 | 2000 | |
| 2001 | - if ( ! empty($q['category__and']) ) { |
|
| 2002 | - $q['category__and'] = array_map( 'absint', array_unique( (array) $q['category__and'] ) ); |
|
| 2001 | + if ( ! empty($q['category__and'])) { |
|
| 2002 | + $q['category__and'] = array_map('absint', array_unique((array) $q['category__and'])); |
|
| 2003 | 2003 | $tax_query[] = array( |
| 2004 | 2004 | 'taxonomy' => 'category', |
| 2005 | 2005 | 'terms' => $q['category__and'], |
@@ -2010,21 +2010,21 @@ discard block |
||
| 2010 | 2010 | } |
| 2011 | 2011 | |
| 2012 | 2012 | // If querystring 'tag' is array, implode it. |
| 2013 | - if ( is_array( $q['tag'] ) ) { |
|
| 2014 | - $q['tag'] = implode( ',', $q['tag'] ); |
|
| 2013 | + if (is_array($q['tag'])) { |
|
| 2014 | + $q['tag'] = implode(',', $q['tag']); |
|
| 2015 | 2015 | } |
| 2016 | 2016 | |
| 2017 | 2017 | // Tag stuff |
| 2018 | - if ( '' != $q['tag'] && !$this->is_singular && $this->query_vars_changed ) { |
|
| 2019 | - if ( strpos($q['tag'], ',') !== false ) { |
|
| 2018 | + if ('' != $q['tag'] && ! $this->is_singular && $this->query_vars_changed) { |
|
| 2019 | + if (strpos($q['tag'], ',') !== false) { |
|
| 2020 | 2020 | $tags = preg_split('/[,\r\n\t ]+/', $q['tag']); |
| 2021 | - foreach ( (array) $tags as $tag ) { |
|
| 2021 | + foreach ((array) $tags as $tag) { |
|
| 2022 | 2022 | $tag = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db'); |
| 2023 | 2023 | $q['tag_slug__in'][] = $tag; |
| 2024 | 2024 | } |
| 2025 | - } elseif ( preg_match('/[+\r\n\t ]+/', $q['tag'] ) || ! empty( $q['cat'] ) ) { |
|
| 2025 | + } elseif (preg_match('/[+\r\n\t ]+/', $q['tag']) || ! empty($q['cat'])) { |
|
| 2026 | 2026 | $tags = preg_split('/[+\r\n\t ]+/', $q['tag']); |
| 2027 | - foreach ( (array) $tags as $tag ) { |
|
| 2027 | + foreach ((array) $tags as $tag) { |
|
| 2028 | 2028 | $tag = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db'); |
| 2029 | 2029 | $q['tag_slug__and'][] = $tag; |
| 2030 | 2030 | } |
@@ -2034,24 +2034,24 @@ discard block |
||
| 2034 | 2034 | } |
| 2035 | 2035 | } |
| 2036 | 2036 | |
| 2037 | - if ( !empty($q['tag_id']) ) { |
|
| 2038 | - $q['tag_id'] = absint( $q['tag_id'] ); |
|
| 2037 | + if ( ! empty($q['tag_id'])) { |
|
| 2038 | + $q['tag_id'] = absint($q['tag_id']); |
|
| 2039 | 2039 | $tax_query[] = array( |
| 2040 | 2040 | 'taxonomy' => 'post_tag', |
| 2041 | 2041 | 'terms' => $q['tag_id'] |
| 2042 | 2042 | ); |
| 2043 | 2043 | } |
| 2044 | 2044 | |
| 2045 | - if ( !empty($q['tag__in']) ) { |
|
| 2046 | - $q['tag__in'] = array_map('absint', array_unique( (array) $q['tag__in'] ) ); |
|
| 2045 | + if ( ! empty($q['tag__in'])) { |
|
| 2046 | + $q['tag__in'] = array_map('absint', array_unique((array) $q['tag__in'])); |
|
| 2047 | 2047 | $tax_query[] = array( |
| 2048 | 2048 | 'taxonomy' => 'post_tag', |
| 2049 | 2049 | 'terms' => $q['tag__in'] |
| 2050 | 2050 | ); |
| 2051 | 2051 | } |
| 2052 | 2052 | |
| 2053 | - if ( !empty($q['tag__not_in']) ) { |
|
| 2054 | - $q['tag__not_in'] = array_map('absint', array_unique( (array) $q['tag__not_in'] ) ); |
|
| 2053 | + if ( ! empty($q['tag__not_in'])) { |
|
| 2054 | + $q['tag__not_in'] = array_map('absint', array_unique((array) $q['tag__not_in'])); |
|
| 2055 | 2055 | $tax_query[] = array( |
| 2056 | 2056 | 'taxonomy' => 'post_tag', |
| 2057 | 2057 | 'terms' => $q['tag__not_in'], |
@@ -2059,8 +2059,8 @@ discard block |
||
| 2059 | 2059 | ); |
| 2060 | 2060 | } |
| 2061 | 2061 | |
| 2062 | - if ( !empty($q['tag__and']) ) { |
|
| 2063 | - $q['tag__and'] = array_map('absint', array_unique( (array) $q['tag__and'] ) ); |
|
| 2062 | + if ( ! empty($q['tag__and'])) { |
|
| 2063 | + $q['tag__and'] = array_map('absint', array_unique((array) $q['tag__and'])); |
|
| 2064 | 2064 | $tax_query[] = array( |
| 2065 | 2065 | 'taxonomy' => 'post_tag', |
| 2066 | 2066 | 'terms' => $q['tag__and'], |
@@ -2068,8 +2068,8 @@ discard block |
||
| 2068 | 2068 | ); |
| 2069 | 2069 | } |
| 2070 | 2070 | |
| 2071 | - if ( !empty($q['tag_slug__in']) ) { |
|
| 2072 | - $q['tag_slug__in'] = array_map('sanitize_title_for_query', array_unique( (array) $q['tag_slug__in'] ) ); |
|
| 2071 | + if ( ! empty($q['tag_slug__in'])) { |
|
| 2072 | + $q['tag_slug__in'] = array_map('sanitize_title_for_query', array_unique((array) $q['tag_slug__in'])); |
|
| 2073 | 2073 | $tax_query[] = array( |
| 2074 | 2074 | 'taxonomy' => 'post_tag', |
| 2075 | 2075 | 'terms' => $q['tag_slug__in'], |
@@ -2077,8 +2077,8 @@ discard block |
||
| 2077 | 2077 | ); |
| 2078 | 2078 | } |
| 2079 | 2079 | |
| 2080 | - if ( !empty($q['tag_slug__and']) ) { |
|
| 2081 | - $q['tag_slug__and'] = array_map('sanitize_title_for_query', array_unique( (array) $q['tag_slug__and'] ) ); |
|
| 2080 | + if ( ! empty($q['tag_slug__and'])) { |
|
| 2081 | + $q['tag_slug__and'] = array_map('sanitize_title_for_query', array_unique((array) $q['tag_slug__and'])); |
|
| 2082 | 2082 | $tax_query[] = array( |
| 2083 | 2083 | 'taxonomy' => 'post_tag', |
| 2084 | 2084 | 'terms' => $q['tag_slug__and'], |
@@ -2087,7 +2087,7 @@ discard block |
||
| 2087 | 2087 | ); |
| 2088 | 2088 | } |
| 2089 | 2089 | |
| 2090 | - $this->tax_query = new WP_Tax_Query( $tax_query ); |
|
| 2090 | + $this->tax_query = new WP_Tax_Query($tax_query); |
|
| 2091 | 2091 | |
| 2092 | 2092 | /** |
| 2093 | 2093 | * Fires after taxonomy-related query vars have been parsed. |
@@ -2096,7 +2096,7 @@ discard block |
||
| 2096 | 2096 | * |
| 2097 | 2097 | * @param WP_Query $this The WP_Query instance. |
| 2098 | 2098 | */ |
| 2099 | - do_action( 'parse_tax_query', $this ); |
|
| 2099 | + do_action('parse_tax_query', $this); |
|
| 2100 | 2100 | } |
| 2101 | 2101 | |
| 2102 | 2102 | /** |
@@ -2109,60 +2109,60 @@ discard block |
||
| 2109 | 2109 | * @param array $q Query variables. |
| 2110 | 2110 | * @return string WHERE clause. |
| 2111 | 2111 | */ |
| 2112 | - protected function parse_search( &$q ) { |
|
| 2112 | + protected function parse_search(&$q) { |
|
| 2113 | 2113 | global $wpdb; |
| 2114 | 2114 | |
| 2115 | 2115 | $search = ''; |
| 2116 | 2116 | |
| 2117 | 2117 | // added slashes screw with quote grouping when done early, so done later |
| 2118 | - $q['s'] = stripslashes( $q['s'] ); |
|
| 2119 | - if ( empty( $_GET['s'] ) && $this->is_main_query() ) |
|
| 2120 | - $q['s'] = urldecode( $q['s'] ); |
|
| 2118 | + $q['s'] = stripslashes($q['s']); |
|
| 2119 | + if (empty($_GET['s']) && $this->is_main_query()) |
|
| 2120 | + $q['s'] = urldecode($q['s']); |
|
| 2121 | 2121 | // there are no line breaks in <input /> fields |
| 2122 | - $q['s'] = str_replace( array( "\r", "\n" ), '', $q['s'] ); |
|
| 2122 | + $q['s'] = str_replace(array("\r", "\n"), '', $q['s']); |
|
| 2123 | 2123 | $q['search_terms_count'] = 1; |
| 2124 | - if ( ! empty( $q['sentence'] ) ) { |
|
| 2125 | - $q['search_terms'] = array( $q['s'] ); |
|
| 2124 | + if ( ! empty($q['sentence'])) { |
|
| 2125 | + $q['search_terms'] = array($q['s']); |
|
| 2126 | 2126 | } else { |
| 2127 | - if ( preg_match_all( '/".*?("|$)|((?<=[\t ",+])|^)[^\t ",+]+/', $q['s'], $matches ) ) { |
|
| 2128 | - $q['search_terms_count'] = count( $matches[0] ); |
|
| 2129 | - $q['search_terms'] = $this->parse_search_terms( $matches[0] ); |
|
| 2127 | + if (preg_match_all('/".*?("|$)|((?<=[\t ",+])|^)[^\t ",+]+/', $q['s'], $matches)) { |
|
| 2128 | + $q['search_terms_count'] = count($matches[0]); |
|
| 2129 | + $q['search_terms'] = $this->parse_search_terms($matches[0]); |
|
| 2130 | 2130 | // if the search string has only short terms or stopwords, or is 10+ terms long, match it as sentence |
| 2131 | - if ( empty( $q['search_terms'] ) || count( $q['search_terms'] ) > 9 ) |
|
| 2132 | - $q['search_terms'] = array( $q['s'] ); |
|
| 2131 | + if (empty($q['search_terms']) || count($q['search_terms']) > 9) |
|
| 2132 | + $q['search_terms'] = array($q['s']); |
|
| 2133 | 2133 | } else { |
| 2134 | - $q['search_terms'] = array( $q['s'] ); |
|
| 2134 | + $q['search_terms'] = array($q['s']); |
|
| 2135 | 2135 | } |
| 2136 | 2136 | } |
| 2137 | 2137 | |
| 2138 | - $n = ! empty( $q['exact'] ) ? '' : '%'; |
|
| 2138 | + $n = ! empty($q['exact']) ? '' : '%'; |
|
| 2139 | 2139 | $searchand = ''; |
| 2140 | 2140 | $q['search_orderby_title'] = array(); |
| 2141 | - foreach ( $q['search_terms'] as $term ) { |
|
| 2141 | + foreach ($q['search_terms'] as $term) { |
|
| 2142 | 2142 | // Terms prefixed with '-' should be excluded. |
| 2143 | - $include = '-' !== substr( $term, 0, 1 ); |
|
| 2144 | - if ( $include ) { |
|
| 2143 | + $include = '-' !== substr($term, 0, 1); |
|
| 2144 | + if ($include) { |
|
| 2145 | 2145 | $like_op = 'LIKE'; |
| 2146 | 2146 | $andor_op = 'OR'; |
| 2147 | 2147 | } else { |
| 2148 | 2148 | $like_op = 'NOT LIKE'; |
| 2149 | 2149 | $andor_op = 'AND'; |
| 2150 | - $term = substr( $term, 1 ); |
|
| 2150 | + $term = substr($term, 1); |
|
| 2151 | 2151 | } |
| 2152 | 2152 | |
| 2153 | - if ( $n && $include ) { |
|
| 2154 | - $like = '%' . $wpdb->esc_like( $term ) . '%'; |
|
| 2155 | - $q['search_orderby_title'][] = $wpdb->prepare( "$wpdb->posts.post_title LIKE %s", $like ); |
|
| 2153 | + if ($n && $include) { |
|
| 2154 | + $like = '%'.$wpdb->esc_like($term).'%'; |
|
| 2155 | + $q['search_orderby_title'][] = $wpdb->prepare("$wpdb->posts.post_title LIKE %s", $like); |
|
| 2156 | 2156 | } |
| 2157 | 2157 | |
| 2158 | - $like = $n . $wpdb->esc_like( $term ) . $n; |
|
| 2159 | - $search .= $wpdb->prepare( "{$searchand}(($wpdb->posts.post_title $like_op %s) $andor_op ($wpdb->posts.post_excerpt $like_op %s) $andor_op ($wpdb->posts.post_content $like_op %s))", $like, $like, $like ); |
|
| 2158 | + $like = $n.$wpdb->esc_like($term).$n; |
|
| 2159 | + $search .= $wpdb->prepare("{$searchand}(($wpdb->posts.post_title $like_op %s) $andor_op ($wpdb->posts.post_excerpt $like_op %s) $andor_op ($wpdb->posts.post_content $like_op %s))", $like, $like, $like); |
|
| 2160 | 2160 | $searchand = ' AND '; |
| 2161 | 2161 | } |
| 2162 | 2162 | |
| 2163 | - if ( ! empty( $search ) ) { |
|
| 2163 | + if ( ! empty($search)) { |
|
| 2164 | 2164 | $search = " AND ({$search}) "; |
| 2165 | - if ( ! is_user_logged_in() ) |
|
| 2165 | + if ( ! is_user_logged_in()) |
|
| 2166 | 2166 | $search .= " AND ($wpdb->posts.post_password = '') "; |
| 2167 | 2167 | } |
| 2168 | 2168 | |
@@ -2181,24 +2181,24 @@ discard block |
||
| 2181 | 2181 | * @param array $terms Terms to check. |
| 2182 | 2182 | * @return array Terms that are not stopwords. |
| 2183 | 2183 | */ |
| 2184 | - protected function parse_search_terms( $terms ) { |
|
| 2185 | - $strtolower = function_exists( 'mb_strtolower' ) ? 'mb_strtolower' : 'strtolower'; |
|
| 2184 | + protected function parse_search_terms($terms) { |
|
| 2185 | + $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower'; |
|
| 2186 | 2186 | $checked = array(); |
| 2187 | 2187 | |
| 2188 | 2188 | $stopwords = $this->get_search_stopwords(); |
| 2189 | 2189 | |
| 2190 | - foreach ( $terms as $term ) { |
|
| 2190 | + foreach ($terms as $term) { |
|
| 2191 | 2191 | // keep before/after spaces when term is for exact match |
| 2192 | - if ( preg_match( '/^".+"$/', $term ) ) |
|
| 2193 | - $term = trim( $term, "\"'" ); |
|
| 2192 | + if (preg_match('/^".+"$/', $term)) |
|
| 2193 | + $term = trim($term, "\"'"); |
|
| 2194 | 2194 | else |
| 2195 | - $term = trim( $term, "\"' " ); |
|
| 2195 | + $term = trim($term, "\"' "); |
|
| 2196 | 2196 | |
| 2197 | 2197 | // Avoid single A-Z and single dashes. |
| 2198 | - if ( ! $term || ( 1 === strlen( $term ) && preg_match( '/^[a-z\-]$/i', $term ) ) ) |
|
| 2198 | + if ( ! $term || (1 === strlen($term) && preg_match('/^[a-z\-]$/i', $term))) |
|
| 2199 | 2199 | continue; |
| 2200 | 2200 | |
| 2201 | - if ( in_array( call_user_func( $strtolower, $term ), $stopwords, true ) ) |
|
| 2201 | + if (in_array(call_user_func($strtolower, $term), $stopwords, true)) |
|
| 2202 | 2202 | continue; |
| 2203 | 2203 | |
| 2204 | 2204 | $checked[] = $term; |
@@ -2215,20 +2215,20 @@ discard block |
||
| 2215 | 2215 | * @return array Stopwords. |
| 2216 | 2216 | */ |
| 2217 | 2217 | protected function get_search_stopwords() { |
| 2218 | - if ( isset( $this->stopwords ) ) |
|
| 2218 | + if (isset($this->stopwords)) |
|
| 2219 | 2219 | return $this->stopwords; |
| 2220 | 2220 | |
| 2221 | 2221 | /* translators: This is a comma-separated list of very common words that should be excluded from a search, |
| 2222 | 2222 | * like a, an, and the. These are usually called "stopwords". You should not simply translate these individual |
| 2223 | 2223 | * words into your language. Instead, look for and provide commonly accepted stopwords in your language. |
| 2224 | 2224 | */ |
| 2225 | - $words = explode( ',', _x( 'about,an,are,as,at,be,by,com,for,from,how,in,is,it,of,on,or,that,the,this,to,was,what,when,where,who,will,with,www', |
|
| 2226 | - 'Comma-separated list of search stopwords in your language' ) ); |
|
| 2225 | + $words = explode(',', _x('about,an,are,as,at,be,by,com,for,from,how,in,is,it,of,on,or,that,the,this,to,was,what,when,where,who,will,with,www', |
|
| 2226 | + 'Comma-separated list of search stopwords in your language')); |
|
| 2227 | 2227 | |
| 2228 | 2228 | $stopwords = array(); |
| 2229 | - foreach ( $words as $word ) { |
|
| 2230 | - $word = trim( $word, "\r\n\t " ); |
|
| 2231 | - if ( $word ) |
|
| 2229 | + foreach ($words as $word) { |
|
| 2230 | + $word = trim($word, "\r\n\t "); |
|
| 2231 | + if ($word) |
|
| 2232 | 2232 | $stopwords[] = $word; |
| 2233 | 2233 | } |
| 2234 | 2234 | |
@@ -2239,7 +2239,7 @@ discard block |
||
| 2239 | 2239 | * |
| 2240 | 2240 | * @param array $stopwords Stopwords. |
| 2241 | 2241 | */ |
| 2242 | - $this->stopwords = apply_filters( 'wp_search_stopwords', $stopwords ); |
|
| 2242 | + $this->stopwords = apply_filters('wp_search_stopwords', $stopwords); |
|
| 2243 | 2243 | return $this->stopwords; |
| 2244 | 2244 | } |
| 2245 | 2245 | |
@@ -2251,47 +2251,47 @@ discard block |
||
| 2251 | 2251 | * @param array $q Query variables. |
| 2252 | 2252 | * @return string ORDER BY clause. |
| 2253 | 2253 | */ |
| 2254 | - protected function parse_search_order( &$q ) { |
|
| 2254 | + protected function parse_search_order(&$q) { |
|
| 2255 | 2255 | global $wpdb; |
| 2256 | 2256 | |
| 2257 | - if ( $q['search_terms_count'] > 1 ) { |
|
| 2258 | - $num_terms = count( $q['search_orderby_title'] ); |
|
| 2257 | + if ($q['search_terms_count'] > 1) { |
|
| 2258 | + $num_terms = count($q['search_orderby_title']); |
|
| 2259 | 2259 | |
| 2260 | 2260 | // If the search terms contain negative queries, don't bother ordering by sentence matches. |
| 2261 | 2261 | $like = ''; |
| 2262 | - if ( ! preg_match( '/(?:\s|^)\-/', $q['s'] ) ) { |
|
| 2263 | - $like = '%' . $wpdb->esc_like( $q['s'] ) . '%'; |
|
| 2262 | + if ( ! preg_match('/(?:\s|^)\-/', $q['s'])) { |
|
| 2263 | + $like = '%'.$wpdb->esc_like($q['s']).'%'; |
|
| 2264 | 2264 | } |
| 2265 | 2265 | |
| 2266 | 2266 | $search_orderby = ''; |
| 2267 | 2267 | |
| 2268 | 2268 | // sentence match in 'post_title' |
| 2269 | - if ( $like ) { |
|
| 2270 | - $search_orderby .= $wpdb->prepare( "WHEN $wpdb->posts.post_title LIKE %s THEN 1 ", $like ); |
|
| 2269 | + if ($like) { |
|
| 2270 | + $search_orderby .= $wpdb->prepare("WHEN $wpdb->posts.post_title LIKE %s THEN 1 ", $like); |
|
| 2271 | 2271 | } |
| 2272 | 2272 | |
| 2273 | 2273 | // sanity limit, sort as sentence when more than 6 terms |
| 2274 | 2274 | // (few searches are longer than 6 terms and most titles are not) |
| 2275 | - if ( $num_terms < 7 ) { |
|
| 2275 | + if ($num_terms < 7) { |
|
| 2276 | 2276 | // all words in title |
| 2277 | - $search_orderby .= 'WHEN ' . implode( ' AND ', $q['search_orderby_title'] ) . ' THEN 2 '; |
|
| 2277 | + $search_orderby .= 'WHEN '.implode(' AND ', $q['search_orderby_title']).' THEN 2 '; |
|
| 2278 | 2278 | // any word in title, not needed when $num_terms == 1 |
| 2279 | - if ( $num_terms > 1 ) |
|
| 2280 | - $search_orderby .= 'WHEN ' . implode( ' OR ', $q['search_orderby_title'] ) . ' THEN 3 '; |
|
| 2279 | + if ($num_terms > 1) |
|
| 2280 | + $search_orderby .= 'WHEN '.implode(' OR ', $q['search_orderby_title']).' THEN 3 '; |
|
| 2281 | 2281 | } |
| 2282 | 2282 | |
| 2283 | 2283 | // Sentence match in 'post_content' and 'post_excerpt'. |
| 2284 | - if ( $like ) { |
|
| 2285 | - $search_orderby .= $wpdb->prepare( "WHEN $wpdb->posts.post_excerpt LIKE %s THEN 4 ", $like ); |
|
| 2286 | - $search_orderby .= $wpdb->prepare( "WHEN $wpdb->posts.post_content LIKE %s THEN 5 ", $like ); |
|
| 2284 | + if ($like) { |
|
| 2285 | + $search_orderby .= $wpdb->prepare("WHEN $wpdb->posts.post_excerpt LIKE %s THEN 4 ", $like); |
|
| 2286 | + $search_orderby .= $wpdb->prepare("WHEN $wpdb->posts.post_content LIKE %s THEN 5 ", $like); |
|
| 2287 | 2287 | } |
| 2288 | 2288 | |
| 2289 | - if ( $search_orderby ) { |
|
| 2290 | - $search_orderby = '(CASE ' . $search_orderby . 'ELSE 6 END)'; |
|
| 2289 | + if ($search_orderby) { |
|
| 2290 | + $search_orderby = '(CASE '.$search_orderby.'ELSE 6 END)'; |
|
| 2291 | 2291 | } |
| 2292 | 2292 | } else { |
| 2293 | 2293 | // single word or sentence search |
| 2294 | - $search_orderby = reset( $q['search_orderby_title'] ) . ' DESC'; |
|
| 2294 | + $search_orderby = reset($q['search_orderby_title']).' DESC'; |
|
| 2295 | 2295 | } |
| 2296 | 2296 | |
| 2297 | 2297 | return $search_orderby; |
@@ -2309,7 +2309,7 @@ discard block |
||
| 2309 | 2309 | * @param string $orderby Alias for the field to order by. |
| 2310 | 2310 | * @return string|false Table-prefixed value to used in the ORDER clause. False otherwise. |
| 2311 | 2311 | */ |
| 2312 | - protected function parse_orderby( $orderby ) { |
|
| 2312 | + protected function parse_orderby($orderby) { |
|
| 2313 | 2313 | global $wpdb; |
| 2314 | 2314 | |
| 2315 | 2315 | // Used to filter values. |
@@ -2322,32 +2322,32 @@ discard block |
||
| 2322 | 2322 | $primary_meta_key = ''; |
| 2323 | 2323 | $primary_meta_query = false; |
| 2324 | 2324 | $meta_clauses = $this->meta_query->get_clauses(); |
| 2325 | - if ( ! empty( $meta_clauses ) ) { |
|
| 2326 | - $primary_meta_query = reset( $meta_clauses ); |
|
| 2325 | + if ( ! empty($meta_clauses)) { |
|
| 2326 | + $primary_meta_query = reset($meta_clauses); |
|
| 2327 | 2327 | |
| 2328 | - if ( ! empty( $primary_meta_query['key'] ) ) { |
|
| 2328 | + if ( ! empty($primary_meta_query['key'])) { |
|
| 2329 | 2329 | $primary_meta_key = $primary_meta_query['key']; |
| 2330 | 2330 | $allowed_keys[] = $primary_meta_key; |
| 2331 | 2331 | } |
| 2332 | 2332 | |
| 2333 | 2333 | $allowed_keys[] = 'meta_value'; |
| 2334 | 2334 | $allowed_keys[] = 'meta_value_num'; |
| 2335 | - $allowed_keys = array_merge( $allowed_keys, array_keys( $meta_clauses ) ); |
|
| 2335 | + $allowed_keys = array_merge($allowed_keys, array_keys($meta_clauses)); |
|
| 2336 | 2336 | } |
| 2337 | 2337 | |
| 2338 | 2338 | // If RAND() contains a seed value, sanitize and add to allowed keys. |
| 2339 | 2339 | $rand_with_seed = false; |
| 2340 | - if ( preg_match( '/RAND\(([0-9]+)\)/i', $orderby, $matches ) ) { |
|
| 2341 | - $orderby = sprintf( 'RAND(%s)', intval( $matches[1] ) ); |
|
| 2340 | + if (preg_match('/RAND\(([0-9]+)\)/i', $orderby, $matches)) { |
|
| 2341 | + $orderby = sprintf('RAND(%s)', intval($matches[1])); |
|
| 2342 | 2342 | $allowed_keys[] = $orderby; |
| 2343 | 2343 | $rand_with_seed = true; |
| 2344 | 2344 | } |
| 2345 | 2345 | |
| 2346 | - if ( ! in_array( $orderby, $allowed_keys, true ) ) { |
|
| 2346 | + if ( ! in_array($orderby, $allowed_keys, true)) { |
|
| 2347 | 2347 | return false; |
| 2348 | 2348 | } |
| 2349 | 2349 | |
| 2350 | - switch ( $orderby ) { |
|
| 2350 | + switch ($orderby) { |
|
| 2351 | 2351 | case 'post_name': |
| 2352 | 2352 | case 'post_author': |
| 2353 | 2353 | case 'post_date': |
@@ -2365,7 +2365,7 @@ discard block |
||
| 2365 | 2365 | break; |
| 2366 | 2366 | case $primary_meta_key: |
| 2367 | 2367 | case 'meta_value': |
| 2368 | - if ( ! empty( $primary_meta_query['type'] ) ) { |
|
| 2368 | + if ( ! empty($primary_meta_query['type'])) { |
|
| 2369 | 2369 | $orderby_clause = "CAST({$primary_meta_query['alias']}.meta_value AS {$primary_meta_query['cast']})"; |
| 2370 | 2370 | } else { |
| 2371 | 2371 | $orderby_clause = "{$primary_meta_query['alias']}.meta_value"; |
@@ -2375,15 +2375,15 @@ discard block |
||
| 2375 | 2375 | $orderby_clause = "{$primary_meta_query['alias']}.meta_value+0"; |
| 2376 | 2376 | break; |
| 2377 | 2377 | default: |
| 2378 | - if ( array_key_exists( $orderby, $meta_clauses ) ) { |
|
| 2378 | + if (array_key_exists($orderby, $meta_clauses)) { |
|
| 2379 | 2379 | // $orderby corresponds to a meta_query clause. |
| 2380 | - $meta_clause = $meta_clauses[ $orderby ]; |
|
| 2380 | + $meta_clause = $meta_clauses[$orderby]; |
|
| 2381 | 2381 | $orderby_clause = "CAST({$meta_clause['alias']}.meta_value AS {$meta_clause['cast']})"; |
| 2382 | - } elseif ( $rand_with_seed ) { |
|
| 2382 | + } elseif ($rand_with_seed) { |
|
| 2383 | 2383 | $orderby_clause = $orderby; |
| 2384 | 2384 | } else { |
| 2385 | 2385 | // Default: order by post field. |
| 2386 | - $orderby_clause = "$wpdb->posts.post_" . sanitize_key( $orderby ); |
|
| 2386 | + $orderby_clause = "$wpdb->posts.post_".sanitize_key($orderby); |
|
| 2387 | 2387 | } |
| 2388 | 2388 | |
| 2389 | 2389 | break; |
@@ -2401,12 +2401,12 @@ discard block |
||
| 2401 | 2401 | * @param string $order The 'order' query variable. |
| 2402 | 2402 | * @return string The sanitized 'order' query variable. |
| 2403 | 2403 | */ |
| 2404 | - protected function parse_order( $order ) { |
|
| 2405 | - if ( ! is_string( $order ) || empty( $order ) ) { |
|
| 2404 | + protected function parse_order($order) { |
|
| 2405 | + if ( ! is_string($order) || empty($order)) { |
|
| 2406 | 2406 | return 'DESC'; |
| 2407 | 2407 | } |
| 2408 | 2408 | |
| 2409 | - if ( 'ASC' === strtoupper( $order ) ) { |
|
| 2409 | + if ('ASC' === strtoupper($order)) { |
|
| 2410 | 2410 | return 'ASC'; |
| 2411 | 2411 | } else { |
| 2412 | 2412 | return 'DESC'; |
@@ -2440,9 +2440,9 @@ discard block |
||
| 2440 | 2440 | * @param mixed $default Optional. Value to return if the query variable is not set. Default empty. |
| 2441 | 2441 | * @return mixed Contents of the query variable. |
| 2442 | 2442 | */ |
| 2443 | - public function get( $query_var, $default = '' ) { |
|
| 2444 | - if ( isset( $this->query_vars[ $query_var ] ) ) { |
|
| 2445 | - return $this->query_vars[ $query_var ]; |
|
| 2443 | + public function get($query_var, $default = '') { |
|
| 2444 | + if (isset($this->query_vars[$query_var])) { |
|
| 2445 | + return $this->query_vars[$query_var]; |
|
| 2446 | 2446 | } |
| 2447 | 2447 | |
| 2448 | 2448 | return $default; |
@@ -2490,7 +2490,7 @@ discard block |
||
| 2490 | 2490 | * |
| 2491 | 2491 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 2492 | 2492 | */ |
| 2493 | - do_action_ref_array( 'pre_get_posts', array( &$this ) ); |
|
| 2493 | + do_action_ref_array('pre_get_posts', array(&$this)); |
|
| 2494 | 2494 | |
| 2495 | 2495 | // Shorthand. |
| 2496 | 2496 | $q = &$this->query_vars; |
@@ -2500,11 +2500,11 @@ discard block |
||
| 2500 | 2500 | |
| 2501 | 2501 | // Parse meta query |
| 2502 | 2502 | $this->meta_query = new WP_Meta_Query(); |
| 2503 | - $this->meta_query->parse_query_vars( $q ); |
|
| 2503 | + $this->meta_query->parse_query_vars($q); |
|
| 2504 | 2504 | |
| 2505 | 2505 | // Set a flag if a pre_get_posts hook changed the query vars. |
| 2506 | - $hash = md5( serialize( $this->query_vars ) ); |
|
| 2507 | - if ( $hash != $this->query_vars_hash ) { |
|
| 2506 | + $hash = md5(serialize($this->query_vars)); |
|
| 2507 | + if ($hash != $this->query_vars_hash) { |
|
| 2508 | 2508 | $this->query_vars_changed = true; |
| 2509 | 2509 | $this->query_vars_hash = $hash; |
| 2510 | 2510 | } |
@@ -2522,91 +2522,91 @@ discard block |
||
| 2522 | 2522 | $post_status_join = false; |
| 2523 | 2523 | $page = 1; |
| 2524 | 2524 | |
| 2525 | - if ( isset( $q['caller_get_posts'] ) ) { |
|
| 2526 | - _deprecated_argument( 'WP_Query', '3.1', __( '"caller_get_posts" is deprecated. Use "ignore_sticky_posts" instead.' ) ); |
|
| 2527 | - if ( !isset( $q['ignore_sticky_posts'] ) ) |
|
| 2525 | + if (isset($q['caller_get_posts'])) { |
|
| 2526 | + _deprecated_argument('WP_Query', '3.1', __('"caller_get_posts" is deprecated. Use "ignore_sticky_posts" instead.')); |
|
| 2527 | + if ( ! isset($q['ignore_sticky_posts'])) |
|
| 2528 | 2528 | $q['ignore_sticky_posts'] = $q['caller_get_posts']; |
| 2529 | 2529 | } |
| 2530 | 2530 | |
| 2531 | - if ( !isset( $q['ignore_sticky_posts'] ) ) |
|
| 2531 | + if ( ! isset($q['ignore_sticky_posts'])) |
|
| 2532 | 2532 | $q['ignore_sticky_posts'] = false; |
| 2533 | 2533 | |
| 2534 | - if ( !isset($q['suppress_filters']) ) |
|
| 2534 | + if ( ! isset($q['suppress_filters'])) |
|
| 2535 | 2535 | $q['suppress_filters'] = false; |
| 2536 | 2536 | |
| 2537 | - if ( !isset($q['cache_results']) ) { |
|
| 2538 | - if ( wp_using_ext_object_cache() ) |
|
| 2537 | + if ( ! isset($q['cache_results'])) { |
|
| 2538 | + if (wp_using_ext_object_cache()) |
|
| 2539 | 2539 | $q['cache_results'] = false; |
| 2540 | 2540 | else |
| 2541 | 2541 | $q['cache_results'] = true; |
| 2542 | 2542 | } |
| 2543 | 2543 | |
| 2544 | - if ( !isset($q['update_post_term_cache']) ) |
|
| 2544 | + if ( ! isset($q['update_post_term_cache'])) |
|
| 2545 | 2545 | $q['update_post_term_cache'] = true; |
| 2546 | 2546 | |
| 2547 | - if ( !isset($q['update_post_meta_cache']) ) |
|
| 2547 | + if ( ! isset($q['update_post_meta_cache'])) |
|
| 2548 | 2548 | $q['update_post_meta_cache'] = true; |
| 2549 | 2549 | |
| 2550 | - if ( !isset($q['post_type']) ) { |
|
| 2551 | - if ( $this->is_search ) |
|
| 2550 | + if ( ! isset($q['post_type'])) { |
|
| 2551 | + if ($this->is_search) |
|
| 2552 | 2552 | $q['post_type'] = 'any'; |
| 2553 | 2553 | else |
| 2554 | 2554 | $q['post_type'] = ''; |
| 2555 | 2555 | } |
| 2556 | 2556 | $post_type = $q['post_type']; |
| 2557 | - if ( empty( $q['posts_per_page'] ) ) { |
|
| 2558 | - $q['posts_per_page'] = get_option( 'posts_per_page' ); |
|
| 2557 | + if (empty($q['posts_per_page'])) { |
|
| 2558 | + $q['posts_per_page'] = get_option('posts_per_page'); |
|
| 2559 | 2559 | } |
| 2560 | - if ( isset($q['showposts']) && $q['showposts'] ) { |
|
| 2560 | + if (isset($q['showposts']) && $q['showposts']) { |
|
| 2561 | 2561 | $q['showposts'] = (int) $q['showposts']; |
| 2562 | 2562 | $q['posts_per_page'] = $q['showposts']; |
| 2563 | 2563 | } |
| 2564 | - if ( (isset($q['posts_per_archive_page']) && $q['posts_per_archive_page'] != 0) && ($this->is_archive || $this->is_search) ) |
|
| 2564 | + if ((isset($q['posts_per_archive_page']) && $q['posts_per_archive_page'] != 0) && ($this->is_archive || $this->is_search)) |
|
| 2565 | 2565 | $q['posts_per_page'] = $q['posts_per_archive_page']; |
| 2566 | - if ( !isset($q['nopaging']) ) { |
|
| 2567 | - if ( $q['posts_per_page'] == -1 ) { |
|
| 2566 | + if ( ! isset($q['nopaging'])) { |
|
| 2567 | + if ($q['posts_per_page'] == -1) { |
|
| 2568 | 2568 | $q['nopaging'] = true; |
| 2569 | 2569 | } else { |
| 2570 | 2570 | $q['nopaging'] = false; |
| 2571 | 2571 | } |
| 2572 | 2572 | } |
| 2573 | 2573 | |
| 2574 | - if ( $this->is_feed ) { |
|
| 2574 | + if ($this->is_feed) { |
|
| 2575 | 2575 | // This overrides posts_per_page. |
| 2576 | - if ( ! empty( $q['posts_per_rss'] ) ) { |
|
| 2576 | + if ( ! empty($q['posts_per_rss'])) { |
|
| 2577 | 2577 | $q['posts_per_page'] = $q['posts_per_rss']; |
| 2578 | 2578 | } else { |
| 2579 | - $q['posts_per_page'] = get_option( 'posts_per_rss' ); |
|
| 2579 | + $q['posts_per_page'] = get_option('posts_per_rss'); |
|
| 2580 | 2580 | } |
| 2581 | 2581 | $q['nopaging'] = false; |
| 2582 | 2582 | } |
| 2583 | 2583 | $q['posts_per_page'] = (int) $q['posts_per_page']; |
| 2584 | - if ( $q['posts_per_page'] < -1 ) |
|
| 2584 | + if ($q['posts_per_page'] < -1) |
|
| 2585 | 2585 | $q['posts_per_page'] = abs($q['posts_per_page']); |
| 2586 | - elseif ( $q['posts_per_page'] == 0 ) |
|
| 2586 | + elseif ($q['posts_per_page'] == 0) |
|
| 2587 | 2587 | $q['posts_per_page'] = 1; |
| 2588 | 2588 | |
| 2589 | - if ( !isset($q['comments_per_page']) || $q['comments_per_page'] == 0 ) |
|
| 2589 | + if ( ! isset($q['comments_per_page']) || $q['comments_per_page'] == 0) |
|
| 2590 | 2590 | $q['comments_per_page'] = get_option('comments_per_page'); |
| 2591 | 2591 | |
| 2592 | - if ( $this->is_home && (empty($this->query) || $q['preview'] == 'true') && ( 'page' == get_option('show_on_front') ) && get_option('page_on_front') ) { |
|
| 2592 | + if ($this->is_home && (empty($this->query) || $q['preview'] == 'true') && ('page' == get_option('show_on_front')) && get_option('page_on_front')) { |
|
| 2593 | 2593 | $this->is_page = true; |
| 2594 | 2594 | $this->is_home = false; |
| 2595 | 2595 | $q['page_id'] = get_option('page_on_front'); |
| 2596 | 2596 | } |
| 2597 | 2597 | |
| 2598 | - if ( isset($q['page']) ) { |
|
| 2598 | + if (isset($q['page'])) { |
|
| 2599 | 2599 | $q['page'] = trim($q['page'], '/'); |
| 2600 | 2600 | $q['page'] = absint($q['page']); |
| 2601 | 2601 | } |
| 2602 | 2602 | |
| 2603 | 2603 | // If true, forcibly turns off SQL_CALC_FOUND_ROWS even when limits are present. |
| 2604 | - if ( isset($q['no_found_rows']) ) |
|
| 2604 | + if (isset($q['no_found_rows'])) |
|
| 2605 | 2605 | $q['no_found_rows'] = (bool) $q['no_found_rows']; |
| 2606 | 2606 | else |
| 2607 | 2607 | $q['no_found_rows'] = false; |
| 2608 | 2608 | |
| 2609 | - switch ( $q['fields'] ) { |
|
| 2609 | + switch ($q['fields']) { |
|
| 2610 | 2610 | case 'ids': |
| 2611 | 2611 | $fields = "$wpdb->posts.ID"; |
| 2612 | 2612 | break; |
@@ -2617,74 +2617,74 @@ discard block |
||
| 2617 | 2617 | $fields = "$wpdb->posts.*"; |
| 2618 | 2618 | } |
| 2619 | 2619 | |
| 2620 | - if ( '' !== $q['menu_order'] ) |
|
| 2621 | - $where .= " AND $wpdb->posts.menu_order = " . $q['menu_order']; |
|
| 2620 | + if ('' !== $q['menu_order']) |
|
| 2621 | + $where .= " AND $wpdb->posts.menu_order = ".$q['menu_order']; |
|
| 2622 | 2622 | |
| 2623 | 2623 | // The "m" parameter is meant for months but accepts datetimes of varying specificity |
| 2624 | - if ( $q['m'] ) { |
|
| 2625 | - $where .= " AND YEAR($wpdb->posts.post_date)=" . substr($q['m'], 0, 4); |
|
| 2626 | - if ( strlen($q['m']) > 5 ) |
|
| 2627 | - $where .= " AND MONTH($wpdb->posts.post_date)=" . substr($q['m'], 4, 2); |
|
| 2628 | - if ( strlen($q['m']) > 7 ) |
|
| 2629 | - $where .= " AND DAYOFMONTH($wpdb->posts.post_date)=" . substr($q['m'], 6, 2); |
|
| 2630 | - if ( strlen($q['m']) > 9 ) |
|
| 2631 | - $where .= " AND HOUR($wpdb->posts.post_date)=" . substr($q['m'], 8, 2); |
|
| 2632 | - if ( strlen($q['m']) > 11 ) |
|
| 2633 | - $where .= " AND MINUTE($wpdb->posts.post_date)=" . substr($q['m'], 10, 2); |
|
| 2634 | - if ( strlen($q['m']) > 13 ) |
|
| 2635 | - $where .= " AND SECOND($wpdb->posts.post_date)=" . substr($q['m'], 12, 2); |
|
| 2624 | + if ($q['m']) { |
|
| 2625 | + $where .= " AND YEAR($wpdb->posts.post_date)=".substr($q['m'], 0, 4); |
|
| 2626 | + if (strlen($q['m']) > 5) |
|
| 2627 | + $where .= " AND MONTH($wpdb->posts.post_date)=".substr($q['m'], 4, 2); |
|
| 2628 | + if (strlen($q['m']) > 7) |
|
| 2629 | + $where .= " AND DAYOFMONTH($wpdb->posts.post_date)=".substr($q['m'], 6, 2); |
|
| 2630 | + if (strlen($q['m']) > 9) |
|
| 2631 | + $where .= " AND HOUR($wpdb->posts.post_date)=".substr($q['m'], 8, 2); |
|
| 2632 | + if (strlen($q['m']) > 11) |
|
| 2633 | + $where .= " AND MINUTE($wpdb->posts.post_date)=".substr($q['m'], 10, 2); |
|
| 2634 | + if (strlen($q['m']) > 13) |
|
| 2635 | + $where .= " AND SECOND($wpdb->posts.post_date)=".substr($q['m'], 12, 2); |
|
| 2636 | 2636 | } |
| 2637 | 2637 | |
| 2638 | 2638 | // Handle the other individual date parameters |
| 2639 | 2639 | $date_parameters = array(); |
| 2640 | 2640 | |
| 2641 | - if ( '' !== $q['hour'] ) |
|
| 2641 | + if ('' !== $q['hour']) |
|
| 2642 | 2642 | $date_parameters['hour'] = $q['hour']; |
| 2643 | 2643 | |
| 2644 | - if ( '' !== $q['minute'] ) |
|
| 2644 | + if ('' !== $q['minute']) |
|
| 2645 | 2645 | $date_parameters['minute'] = $q['minute']; |
| 2646 | 2646 | |
| 2647 | - if ( '' !== $q['second'] ) |
|
| 2647 | + if ('' !== $q['second']) |
|
| 2648 | 2648 | $date_parameters['second'] = $q['second']; |
| 2649 | 2649 | |
| 2650 | - if ( $q['year'] ) |
|
| 2650 | + if ($q['year']) |
|
| 2651 | 2651 | $date_parameters['year'] = $q['year']; |
| 2652 | 2652 | |
| 2653 | - if ( $q['monthnum'] ) |
|
| 2653 | + if ($q['monthnum']) |
|
| 2654 | 2654 | $date_parameters['monthnum'] = $q['monthnum']; |
| 2655 | 2655 | |
| 2656 | - if ( $q['w'] ) |
|
| 2656 | + if ($q['w']) |
|
| 2657 | 2657 | $date_parameters['week'] = $q['w']; |
| 2658 | 2658 | |
| 2659 | - if ( $q['day'] ) |
|
| 2659 | + if ($q['day']) |
|
| 2660 | 2660 | $date_parameters['day'] = $q['day']; |
| 2661 | 2661 | |
| 2662 | - if ( $date_parameters ) { |
|
| 2663 | - $date_query = new WP_Date_Query( array( $date_parameters ) ); |
|
| 2662 | + if ($date_parameters) { |
|
| 2663 | + $date_query = new WP_Date_Query(array($date_parameters)); |
|
| 2664 | 2664 | $where .= $date_query->get_sql(); |
| 2665 | 2665 | } |
| 2666 | - unset( $date_parameters, $date_query ); |
|
| 2666 | + unset($date_parameters, $date_query); |
|
| 2667 | 2667 | |
| 2668 | 2668 | // Handle complex date queries |
| 2669 | - if ( ! empty( $q['date_query'] ) ) { |
|
| 2670 | - $this->date_query = new WP_Date_Query( $q['date_query'] ); |
|
| 2669 | + if ( ! empty($q['date_query'])) { |
|
| 2670 | + $this->date_query = new WP_Date_Query($q['date_query']); |
|
| 2671 | 2671 | $where .= $this->date_query->get_sql(); |
| 2672 | 2672 | } |
| 2673 | 2673 | |
| 2674 | 2674 | |
| 2675 | 2675 | // If we've got a post_type AND it's not "any" post_type. |
| 2676 | - if ( !empty($q['post_type']) && 'any' != $q['post_type'] ) { |
|
| 2677 | - foreach ( (array)$q['post_type'] as $_post_type ) { |
|
| 2676 | + if ( ! empty($q['post_type']) && 'any' != $q['post_type']) { |
|
| 2677 | + foreach ((array) $q['post_type'] as $_post_type) { |
|
| 2678 | 2678 | $ptype_obj = get_post_type_object($_post_type); |
| 2679 | - if ( !$ptype_obj || !$ptype_obj->query_var || empty($q[ $ptype_obj->query_var ]) ) |
|
| 2679 | + if ( ! $ptype_obj || ! $ptype_obj->query_var || empty($q[$ptype_obj->query_var])) |
|
| 2680 | 2680 | continue; |
| 2681 | 2681 | |
| 2682 | - if ( ! $ptype_obj->hierarchical ) { |
|
| 2682 | + if ( ! $ptype_obj->hierarchical) { |
|
| 2683 | 2683 | // Non-hierarchical post types can directly use 'name'. |
| 2684 | - $q['name'] = $q[ $ptype_obj->query_var ]; |
|
| 2684 | + $q['name'] = $q[$ptype_obj->query_var]; |
|
| 2685 | 2685 | } else { |
| 2686 | 2686 | // Hierarchical post types will operate through 'pagename'. |
| 2687 | - $q['pagename'] = $q[ $ptype_obj->query_var ]; |
|
| 2687 | + $q['pagename'] = $q[$ptype_obj->query_var]; |
|
| 2688 | 2688 | $q['name'] = ''; |
| 2689 | 2689 | } |
| 2690 | 2690 | |
@@ -2694,98 +2694,98 @@ discard block |
||
| 2694 | 2694 | unset($ptype_obj); |
| 2695 | 2695 | } |
| 2696 | 2696 | |
| 2697 | - if ( '' !== $q['title'] ) { |
|
| 2698 | - $where .= $wpdb->prepare( " AND $wpdb->posts.post_title = %s", stripslashes( $q['title'] ) ); |
|
| 2697 | + if ('' !== $q['title']) { |
|
| 2698 | + $where .= $wpdb->prepare(" AND $wpdb->posts.post_title = %s", stripslashes($q['title'])); |
|
| 2699 | 2699 | } |
| 2700 | 2700 | |
| 2701 | 2701 | // Parameters related to 'post_name'. |
| 2702 | - if ( '' != $q['name'] ) { |
|
| 2703 | - $q['name'] = sanitize_title_for_query( $q['name'] ); |
|
| 2704 | - $where .= " AND $wpdb->posts.post_name = '" . $q['name'] . "'"; |
|
| 2705 | - } elseif ( '' != $q['pagename'] ) { |
|
| 2706 | - if ( isset($this->queried_object_id) ) { |
|
| 2702 | + if ('' != $q['name']) { |
|
| 2703 | + $q['name'] = sanitize_title_for_query($q['name']); |
|
| 2704 | + $where .= " AND $wpdb->posts.post_name = '".$q['name']."'"; |
|
| 2705 | + } elseif ('' != $q['pagename']) { |
|
| 2706 | + if (isset($this->queried_object_id)) { |
|
| 2707 | 2707 | $reqpage = $this->queried_object_id; |
| 2708 | 2708 | } else { |
| 2709 | - if ( 'page' != $q['post_type'] ) { |
|
| 2710 | - foreach ( (array)$q['post_type'] as $_post_type ) { |
|
| 2709 | + if ('page' != $q['post_type']) { |
|
| 2710 | + foreach ((array) $q['post_type'] as $_post_type) { |
|
| 2711 | 2711 | $ptype_obj = get_post_type_object($_post_type); |
| 2712 | - if ( !$ptype_obj || !$ptype_obj->hierarchical ) |
|
| 2712 | + if ( ! $ptype_obj || ! $ptype_obj->hierarchical) |
|
| 2713 | 2713 | continue; |
| 2714 | 2714 | |
| 2715 | 2715 | $reqpage = get_page_by_path($q['pagename'], OBJECT, $_post_type); |
| 2716 | - if ( $reqpage ) |
|
| 2716 | + if ($reqpage) |
|
| 2717 | 2717 | break; |
| 2718 | 2718 | } |
| 2719 | 2719 | unset($ptype_obj); |
| 2720 | 2720 | } else { |
| 2721 | 2721 | $reqpage = get_page_by_path($q['pagename']); |
| 2722 | 2722 | } |
| 2723 | - if ( !empty($reqpage) ) |
|
| 2723 | + if ( ! empty($reqpage)) |
|
| 2724 | 2724 | $reqpage = $reqpage->ID; |
| 2725 | 2725 | else |
| 2726 | 2726 | $reqpage = 0; |
| 2727 | 2727 | } |
| 2728 | 2728 | |
| 2729 | 2729 | $page_for_posts = get_option('page_for_posts'); |
| 2730 | - if ( ('page' != get_option('show_on_front') ) || empty($page_for_posts) || ( $reqpage != $page_for_posts ) ) { |
|
| 2731 | - $q['pagename'] = sanitize_title_for_query( wp_basename( $q['pagename'] ) ); |
|
| 2730 | + if (('page' != get_option('show_on_front')) || empty($page_for_posts) || ($reqpage != $page_for_posts)) { |
|
| 2731 | + $q['pagename'] = sanitize_title_for_query(wp_basename($q['pagename'])); |
|
| 2732 | 2732 | $q['name'] = $q['pagename']; |
| 2733 | 2733 | $where .= " AND ($wpdb->posts.ID = '$reqpage')"; |
| 2734 | - $reqpage_obj = get_post( $reqpage ); |
|
| 2735 | - if ( is_object($reqpage_obj) && 'attachment' == $reqpage_obj->post_type ) { |
|
| 2734 | + $reqpage_obj = get_post($reqpage); |
|
| 2735 | + if (is_object($reqpage_obj) && 'attachment' == $reqpage_obj->post_type) { |
|
| 2736 | 2736 | $this->is_attachment = true; |
| 2737 | 2737 | $post_type = $q['post_type'] = 'attachment'; |
| 2738 | 2738 | $this->is_page = true; |
| 2739 | 2739 | $q['attachment_id'] = $reqpage; |
| 2740 | 2740 | } |
| 2741 | 2741 | } |
| 2742 | - } elseif ( '' != $q['attachment'] ) { |
|
| 2743 | - $q['attachment'] = sanitize_title_for_query( wp_basename( $q['attachment'] ) ); |
|
| 2742 | + } elseif ('' != $q['attachment']) { |
|
| 2743 | + $q['attachment'] = sanitize_title_for_query(wp_basename($q['attachment'])); |
|
| 2744 | 2744 | $q['name'] = $q['attachment']; |
| 2745 | - $where .= " AND $wpdb->posts.post_name = '" . $q['attachment'] . "'"; |
|
| 2746 | - } elseif ( is_array( $q['post_name__in'] ) && ! empty( $q['post_name__in'] ) ) { |
|
| 2747 | - $q['post_name__in'] = array_map( 'sanitize_title_for_query', $q['post_name__in'] ); |
|
| 2748 | - $where .= " AND $wpdb->posts.post_name IN ('" . implode( "' ,'", $q['post_name__in'] ) . "')"; |
|
| 2745 | + $where .= " AND $wpdb->posts.post_name = '".$q['attachment']."'"; |
|
| 2746 | + } elseif (is_array($q['post_name__in']) && ! empty($q['post_name__in'])) { |
|
| 2747 | + $q['post_name__in'] = array_map('sanitize_title_for_query', $q['post_name__in']); |
|
| 2748 | + $where .= " AND $wpdb->posts.post_name IN ('".implode("' ,'", $q['post_name__in'])."')"; |
|
| 2749 | 2749 | } |
| 2750 | 2750 | |
| 2751 | 2751 | // If an attachment is requested by number, let it supersede any post number. |
| 2752 | - if ( $q['attachment_id'] ) |
|
| 2752 | + if ($q['attachment_id']) |
|
| 2753 | 2753 | $q['p'] = absint($q['attachment_id']); |
| 2754 | 2754 | |
| 2755 | 2755 | // If a post number is specified, load that post |
| 2756 | - if ( $q['p'] ) { |
|
| 2757 | - $where .= " AND {$wpdb->posts}.ID = " . $q['p']; |
|
| 2758 | - } elseif ( $q['post__in'] ) { |
|
| 2759 | - $post__in = implode(',', array_map( 'absint', $q['post__in'] )); |
|
| 2756 | + if ($q['p']) { |
|
| 2757 | + $where .= " AND {$wpdb->posts}.ID = ".$q['p']; |
|
| 2758 | + } elseif ($q['post__in']) { |
|
| 2759 | + $post__in = implode(',', array_map('absint', $q['post__in'])); |
|
| 2760 | 2760 | $where .= " AND {$wpdb->posts}.ID IN ($post__in)"; |
| 2761 | - } elseif ( $q['post__not_in'] ) { |
|
| 2762 | - $post__not_in = implode(',', array_map( 'absint', $q['post__not_in'] )); |
|
| 2761 | + } elseif ($q['post__not_in']) { |
|
| 2762 | + $post__not_in = implode(',', array_map('absint', $q['post__not_in'])); |
|
| 2763 | 2763 | $where .= " AND {$wpdb->posts}.ID NOT IN ($post__not_in)"; |
| 2764 | 2764 | } |
| 2765 | 2765 | |
| 2766 | - if ( is_numeric( $q['post_parent'] ) ) { |
|
| 2767 | - $where .= $wpdb->prepare( " AND $wpdb->posts.post_parent = %d ", $q['post_parent'] ); |
|
| 2768 | - } elseif ( $q['post_parent__in'] ) { |
|
| 2769 | - $post_parent__in = implode( ',', array_map( 'absint', $q['post_parent__in'] ) ); |
|
| 2766 | + if (is_numeric($q['post_parent'])) { |
|
| 2767 | + $where .= $wpdb->prepare(" AND $wpdb->posts.post_parent = %d ", $q['post_parent']); |
|
| 2768 | + } elseif ($q['post_parent__in']) { |
|
| 2769 | + $post_parent__in = implode(',', array_map('absint', $q['post_parent__in'])); |
|
| 2770 | 2770 | $where .= " AND {$wpdb->posts}.post_parent IN ($post_parent__in)"; |
| 2771 | - } elseif ( $q['post_parent__not_in'] ) { |
|
| 2772 | - $post_parent__not_in = implode( ',', array_map( 'absint', $q['post_parent__not_in'] ) ); |
|
| 2771 | + } elseif ($q['post_parent__not_in']) { |
|
| 2772 | + $post_parent__not_in = implode(',', array_map('absint', $q['post_parent__not_in'])); |
|
| 2773 | 2773 | $where .= " AND {$wpdb->posts}.post_parent NOT IN ($post_parent__not_in)"; |
| 2774 | 2774 | } |
| 2775 | 2775 | |
| 2776 | - if ( $q['page_id'] ) { |
|
| 2777 | - if ( ('page' != get_option('show_on_front') ) || ( $q['page_id'] != get_option('page_for_posts') ) ) { |
|
| 2776 | + if ($q['page_id']) { |
|
| 2777 | + if (('page' != get_option('show_on_front')) || ($q['page_id'] != get_option('page_for_posts'))) { |
|
| 2778 | 2778 | $q['p'] = $q['page_id']; |
| 2779 | - $where = " AND {$wpdb->posts}.ID = " . $q['page_id']; |
|
| 2779 | + $where = " AND {$wpdb->posts}.ID = ".$q['page_id']; |
|
| 2780 | 2780 | } |
| 2781 | 2781 | } |
| 2782 | 2782 | |
| 2783 | 2783 | // If a search pattern is specified, load the posts that match. |
| 2784 | - if ( strlen( $q['s'] ) ) { |
|
| 2785 | - $search = $this->parse_search( $q ); |
|
| 2784 | + if (strlen($q['s'])) { |
|
| 2785 | + $search = $this->parse_search($q); |
|
| 2786 | 2786 | } |
| 2787 | 2787 | |
| 2788 | - if ( ! $q['suppress_filters'] ) { |
|
| 2788 | + if ( ! $q['suppress_filters']) { |
|
| 2789 | 2789 | /** |
| 2790 | 2790 | * Filter the search SQL that is used in the WHERE clause of WP_Query. |
| 2791 | 2791 | * |
@@ -2794,36 +2794,36 @@ discard block |
||
| 2794 | 2794 | * @param string $search Search SQL for WHERE clause. |
| 2795 | 2795 | * @param WP_Query $this The current WP_Query object. |
| 2796 | 2796 | */ |
| 2797 | - $search = apply_filters_ref_array( 'posts_search', array( $search, &$this ) ); |
|
| 2797 | + $search = apply_filters_ref_array('posts_search', array($search, &$this)); |
|
| 2798 | 2798 | } |
| 2799 | 2799 | |
| 2800 | 2800 | // Taxonomies |
| 2801 | - if ( !$this->is_singular ) { |
|
| 2802 | - $this->parse_tax_query( $q ); |
|
| 2801 | + if ( ! $this->is_singular) { |
|
| 2802 | + $this->parse_tax_query($q); |
|
| 2803 | 2803 | |
| 2804 | - $clauses = $this->tax_query->get_sql( $wpdb->posts, 'ID' ); |
|
| 2804 | + $clauses = $this->tax_query->get_sql($wpdb->posts, 'ID'); |
|
| 2805 | 2805 | |
| 2806 | 2806 | $join .= $clauses['join']; |
| 2807 | 2807 | $where .= $clauses['where']; |
| 2808 | 2808 | } |
| 2809 | 2809 | |
| 2810 | - if ( $this->is_tax ) { |
|
| 2811 | - if ( empty($post_type) ) { |
|
| 2810 | + if ($this->is_tax) { |
|
| 2811 | + if (empty($post_type)) { |
|
| 2812 | 2812 | // Do a fully inclusive search for currently registered post types of queried taxonomies |
| 2813 | 2813 | $post_type = array(); |
| 2814 | - $taxonomies = array_keys( $this->tax_query->queried_terms ); |
|
| 2815 | - foreach ( get_post_types( array( 'exclude_from_search' => false ) ) as $pt ) { |
|
| 2816 | - $object_taxonomies = $pt === 'attachment' ? get_taxonomies_for_attachments() : get_object_taxonomies( $pt ); |
|
| 2817 | - if ( array_intersect( $taxonomies, $object_taxonomies ) ) |
|
| 2814 | + $taxonomies = array_keys($this->tax_query->queried_terms); |
|
| 2815 | + foreach (get_post_types(array('exclude_from_search' => false)) as $pt) { |
|
| 2816 | + $object_taxonomies = $pt === 'attachment' ? get_taxonomies_for_attachments() : get_object_taxonomies($pt); |
|
| 2817 | + if (array_intersect($taxonomies, $object_taxonomies)) |
|
| 2818 | 2818 | $post_type[] = $pt; |
| 2819 | 2819 | } |
| 2820 | - if ( ! $post_type ) |
|
| 2820 | + if ( ! $post_type) |
|
| 2821 | 2821 | $post_type = 'any'; |
| 2822 | - elseif ( count( $post_type ) == 1 ) |
|
| 2822 | + elseif (count($post_type) == 1) |
|
| 2823 | 2823 | $post_type = $post_type[0]; |
| 2824 | 2824 | |
| 2825 | 2825 | $post_status_join = true; |
| 2826 | - } elseif ( in_array('attachment', (array) $post_type) ) { |
|
| 2826 | + } elseif (in_array('attachment', (array) $post_type)) { |
|
| 2827 | 2827 | $post_status_join = true; |
| 2828 | 2828 | } |
| 2829 | 2829 | } |
@@ -2832,22 +2832,22 @@ discard block |
||
| 2832 | 2832 | * Ensure that 'taxonomy', 'term', 'term_id', 'cat', and |
| 2833 | 2833 | * 'category_name' vars are set for backward compatibility. |
| 2834 | 2834 | */ |
| 2835 | - if ( ! empty( $this->tax_query->queried_terms ) ) { |
|
| 2835 | + if ( ! empty($this->tax_query->queried_terms)) { |
|
| 2836 | 2836 | |
| 2837 | 2837 | /* |
| 2838 | 2838 | * Set 'taxonomy', 'term', and 'term_id' to the |
| 2839 | 2839 | * first taxonomy other than 'post_tag' or 'category'. |
| 2840 | 2840 | */ |
| 2841 | - if ( ! isset( $q['taxonomy'] ) ) { |
|
| 2842 | - foreach ( $this->tax_query->queried_terms as $queried_taxonomy => $queried_items ) { |
|
| 2843 | - if ( empty( $queried_items['terms'][0] ) ) { |
|
| 2841 | + if ( ! isset($q['taxonomy'])) { |
|
| 2842 | + foreach ($this->tax_query->queried_terms as $queried_taxonomy => $queried_items) { |
|
| 2843 | + if (empty($queried_items['terms'][0])) { |
|
| 2844 | 2844 | continue; |
| 2845 | 2845 | } |
| 2846 | 2846 | |
| 2847 | - if ( ! in_array( $queried_taxonomy, array( 'category', 'post_tag' ) ) ) { |
|
| 2847 | + if ( ! in_array($queried_taxonomy, array('category', 'post_tag'))) { |
|
| 2848 | 2848 | $q['taxonomy'] = $queried_taxonomy; |
| 2849 | 2849 | |
| 2850 | - if ( 'slug' === $queried_items['field'] ) { |
|
| 2850 | + if ('slug' === $queried_items['field']) { |
|
| 2851 | 2851 | $q['term'] = $queried_items['terms'][0]; |
| 2852 | 2852 | } else { |
| 2853 | 2853 | $q['term_id'] = $queried_items['terms'][0]; |
@@ -2860,154 +2860,154 @@ discard block |
||
| 2860 | 2860 | } |
| 2861 | 2861 | |
| 2862 | 2862 | // 'cat', 'category_name', 'tag_id' |
| 2863 | - foreach ( $this->tax_query->queried_terms as $queried_taxonomy => $queried_items ) { |
|
| 2864 | - if ( empty( $queried_items['terms'][0] ) ) { |
|
| 2863 | + foreach ($this->tax_query->queried_terms as $queried_taxonomy => $queried_items) { |
|
| 2864 | + if (empty($queried_items['terms'][0])) { |
|
| 2865 | 2865 | continue; |
| 2866 | 2866 | } |
| 2867 | 2867 | |
| 2868 | - if ( 'category' === $queried_taxonomy ) { |
|
| 2869 | - $the_cat = get_term_by( $queried_items['field'], $queried_items['terms'][0], 'category' ); |
|
| 2870 | - if ( $the_cat ) { |
|
| 2871 | - $this->set( 'cat', $the_cat->term_id ); |
|
| 2872 | - $this->set( 'category_name', $the_cat->slug ); |
|
| 2868 | + if ('category' === $queried_taxonomy) { |
|
| 2869 | + $the_cat = get_term_by($queried_items['field'], $queried_items['terms'][0], 'category'); |
|
| 2870 | + if ($the_cat) { |
|
| 2871 | + $this->set('cat', $the_cat->term_id); |
|
| 2872 | + $this->set('category_name', $the_cat->slug); |
|
| 2873 | 2873 | } |
| 2874 | - unset( $the_cat ); |
|
| 2874 | + unset($the_cat); |
|
| 2875 | 2875 | } |
| 2876 | 2876 | |
| 2877 | - if ( 'post_tag' === $queried_taxonomy ) { |
|
| 2878 | - $the_tag = get_term_by( $queried_items['field'], $queried_items['terms'][0], 'post_tag' ); |
|
| 2879 | - if ( $the_tag ) { |
|
| 2880 | - $this->set( 'tag_id', $the_tag->term_id ); |
|
| 2877 | + if ('post_tag' === $queried_taxonomy) { |
|
| 2878 | + $the_tag = get_term_by($queried_items['field'], $queried_items['terms'][0], 'post_tag'); |
|
| 2879 | + if ($the_tag) { |
|
| 2880 | + $this->set('tag_id', $the_tag->term_id); |
|
| 2881 | 2881 | } |
| 2882 | - unset( $the_tag ); |
|
| 2882 | + unset($the_tag); |
|
| 2883 | 2883 | } |
| 2884 | 2884 | } |
| 2885 | 2885 | } |
| 2886 | 2886 | |
| 2887 | - if ( !empty( $this->tax_query->queries ) || !empty( $this->meta_query->queries ) ) { |
|
| 2887 | + if ( ! empty($this->tax_query->queries) || ! empty($this->meta_query->queries)) { |
|
| 2888 | 2888 | $groupby = "{$wpdb->posts}.ID"; |
| 2889 | 2889 | } |
| 2890 | 2890 | |
| 2891 | 2891 | // Author/user stuff |
| 2892 | 2892 | |
| 2893 | - if ( ! empty( $q['author'] ) && $q['author'] != '0' ) { |
|
| 2894 | - $q['author'] = addslashes_gpc( '' . urldecode( $q['author'] ) ); |
|
| 2895 | - $authors = array_unique( array_map( 'intval', preg_split( '/[,\s]+/', $q['author'] ) ) ); |
|
| 2896 | - foreach ( $authors as $author ) { |
|
| 2893 | + if ( ! empty($q['author']) && $q['author'] != '0') { |
|
| 2894 | + $q['author'] = addslashes_gpc(''.urldecode($q['author'])); |
|
| 2895 | + $authors = array_unique(array_map('intval', preg_split('/[,\s]+/', $q['author']))); |
|
| 2896 | + foreach ($authors as $author) { |
|
| 2897 | 2897 | $key = $author > 0 ? 'author__in' : 'author__not_in'; |
| 2898 | - $q[$key][] = abs( $author ); |
|
| 2898 | + $q[$key][] = abs($author); |
|
| 2899 | 2899 | } |
| 2900 | - $q['author'] = implode( ',', $authors ); |
|
| 2900 | + $q['author'] = implode(',', $authors); |
|
| 2901 | 2901 | } |
| 2902 | 2902 | |
| 2903 | - if ( ! empty( $q['author__not_in'] ) ) { |
|
| 2904 | - $author__not_in = implode( ',', array_map( 'absint', array_unique( (array) $q['author__not_in'] ) ) ); |
|
| 2903 | + if ( ! empty($q['author__not_in'])) { |
|
| 2904 | + $author__not_in = implode(',', array_map('absint', array_unique((array) $q['author__not_in']))); |
|
| 2905 | 2905 | $where .= " AND {$wpdb->posts}.post_author NOT IN ($author__not_in) "; |
| 2906 | - } elseif ( ! empty( $q['author__in'] ) ) { |
|
| 2907 | - $author__in = implode( ',', array_map( 'absint', array_unique( (array) $q['author__in'] ) ) ); |
|
| 2906 | + } elseif ( ! empty($q['author__in'])) { |
|
| 2907 | + $author__in = implode(',', array_map('absint', array_unique((array) $q['author__in']))); |
|
| 2908 | 2908 | $where .= " AND {$wpdb->posts}.post_author IN ($author__in) "; |
| 2909 | 2909 | } |
| 2910 | 2910 | |
| 2911 | 2911 | // Author stuff for nice URLs |
| 2912 | 2912 | |
| 2913 | - if ( '' != $q['author_name'] ) { |
|
| 2914 | - if ( strpos($q['author_name'], '/') !== false ) { |
|
| 2913 | + if ('' != $q['author_name']) { |
|
| 2914 | + if (strpos($q['author_name'], '/') !== false) { |
|
| 2915 | 2915 | $q['author_name'] = explode('/', $q['author_name']); |
| 2916 | - if ( $q['author_name'][ count($q['author_name'])-1 ] ) { |
|
| 2917 | - $q['author_name'] = $q['author_name'][count($q['author_name'])-1]; // no trailing slash |
|
| 2916 | + if ($q['author_name'][count($q['author_name']) - 1]) { |
|
| 2917 | + $q['author_name'] = $q['author_name'][count($q['author_name']) - 1]; // no trailing slash |
|
| 2918 | 2918 | } else { |
| 2919 | - $q['author_name'] = $q['author_name'][count($q['author_name'])-2]; // there was a trailing slash |
|
| 2919 | + $q['author_name'] = $q['author_name'][count($q['author_name']) - 2]; // there was a trailing slash |
|
| 2920 | 2920 | } |
| 2921 | 2921 | } |
| 2922 | - $q['author_name'] = sanitize_title_for_query( $q['author_name'] ); |
|
| 2922 | + $q['author_name'] = sanitize_title_for_query($q['author_name']); |
|
| 2923 | 2923 | $q['author'] = get_user_by('slug', $q['author_name']); |
| 2924 | - if ( $q['author'] ) |
|
| 2924 | + if ($q['author']) |
|
| 2925 | 2925 | $q['author'] = $q['author']->ID; |
| 2926 | - $whichauthor .= " AND ($wpdb->posts.post_author = " . absint($q['author']) . ')'; |
|
| 2926 | + $whichauthor .= " AND ($wpdb->posts.post_author = ".absint($q['author']).')'; |
|
| 2927 | 2927 | } |
| 2928 | 2928 | |
| 2929 | 2929 | // MIME-Type stuff for attachment browsing |
| 2930 | 2930 | |
| 2931 | - if ( isset( $q['post_mime_type'] ) && '' != $q['post_mime_type'] ) |
|
| 2932 | - $whichmimetype = wp_post_mime_type_where( $q['post_mime_type'], $wpdb->posts ); |
|
| 2931 | + if (isset($q['post_mime_type']) && '' != $q['post_mime_type']) |
|
| 2932 | + $whichmimetype = wp_post_mime_type_where($q['post_mime_type'], $wpdb->posts); |
|
| 2933 | 2933 | |
| 2934 | - $where .= $search . $whichauthor . $whichmimetype; |
|
| 2934 | + $where .= $search.$whichauthor.$whichmimetype; |
|
| 2935 | 2935 | |
| 2936 | - if ( ! empty( $this->meta_query->queries ) ) { |
|
| 2937 | - $clauses = $this->meta_query->get_sql( 'post', $wpdb->posts, 'ID', $this ); |
|
| 2936 | + if ( ! empty($this->meta_query->queries)) { |
|
| 2937 | + $clauses = $this->meta_query->get_sql('post', $wpdb->posts, 'ID', $this); |
|
| 2938 | 2938 | $join .= $clauses['join']; |
| 2939 | 2939 | $where .= $clauses['where']; |
| 2940 | 2940 | } |
| 2941 | 2941 | |
| 2942 | - $rand = ( isset( $q['orderby'] ) && 'rand' === $q['orderby'] ); |
|
| 2943 | - if ( ! isset( $q['order'] ) ) { |
|
| 2942 | + $rand = (isset($q['orderby']) && 'rand' === $q['orderby']); |
|
| 2943 | + if ( ! isset($q['order'])) { |
|
| 2944 | 2944 | $q['order'] = $rand ? '' : 'DESC'; |
| 2945 | 2945 | } else { |
| 2946 | - $q['order'] = $rand ? '' : $this->parse_order( $q['order'] ); |
|
| 2946 | + $q['order'] = $rand ? '' : $this->parse_order($q['order']); |
|
| 2947 | 2947 | } |
| 2948 | 2948 | |
| 2949 | 2949 | // Order by. |
| 2950 | - if ( empty( $q['orderby'] ) ) { |
|
| 2950 | + if (empty($q['orderby'])) { |
|
| 2951 | 2951 | /* |
| 2952 | 2952 | * Boolean false or empty array blanks out ORDER BY, |
| 2953 | 2953 | * while leaving the value unset or otherwise empty sets the default. |
| 2954 | 2954 | */ |
| 2955 | - if ( isset( $q['orderby'] ) && ( is_array( $q['orderby'] ) || false === $q['orderby'] ) ) { |
|
| 2955 | + if (isset($q['orderby']) && (is_array($q['orderby']) || false === $q['orderby'])) { |
|
| 2956 | 2956 | $orderby = ''; |
| 2957 | 2957 | } else { |
| 2958 | - $orderby = "$wpdb->posts.post_date " . $q['order']; |
|
| 2958 | + $orderby = "$wpdb->posts.post_date ".$q['order']; |
|
| 2959 | 2959 | } |
| 2960 | - } elseif ( 'none' == $q['orderby'] ) { |
|
| 2960 | + } elseif ('none' == $q['orderby']) { |
|
| 2961 | 2961 | $orderby = ''; |
| 2962 | - } elseif ( $q['orderby'] == 'post__in' && ! empty( $post__in ) ) { |
|
| 2962 | + } elseif ($q['orderby'] == 'post__in' && ! empty($post__in)) { |
|
| 2963 | 2963 | $orderby = "FIELD( {$wpdb->posts}.ID, $post__in )"; |
| 2964 | - } elseif ( $q['orderby'] == 'post_parent__in' && ! empty( $post_parent__in ) ) { |
|
| 2964 | + } elseif ($q['orderby'] == 'post_parent__in' && ! empty($post_parent__in)) { |
|
| 2965 | 2965 | $orderby = "FIELD( {$wpdb->posts}.post_parent, $post_parent__in )"; |
| 2966 | 2966 | } else { |
| 2967 | 2967 | $orderby_array = array(); |
| 2968 | - if ( is_array( $q['orderby'] ) ) { |
|
| 2969 | - foreach ( $q['orderby'] as $_orderby => $order ) { |
|
| 2970 | - $orderby = addslashes_gpc( urldecode( $_orderby ) ); |
|
| 2971 | - $parsed = $this->parse_orderby( $orderby ); |
|
| 2968 | + if (is_array($q['orderby'])) { |
|
| 2969 | + foreach ($q['orderby'] as $_orderby => $order) { |
|
| 2970 | + $orderby = addslashes_gpc(urldecode($_orderby)); |
|
| 2971 | + $parsed = $this->parse_orderby($orderby); |
|
| 2972 | 2972 | |
| 2973 | - if ( ! $parsed ) { |
|
| 2973 | + if ( ! $parsed) { |
|
| 2974 | 2974 | continue; |
| 2975 | 2975 | } |
| 2976 | 2976 | |
| 2977 | - $orderby_array[] = $parsed . ' ' . $this->parse_order( $order ); |
|
| 2977 | + $orderby_array[] = $parsed.' '.$this->parse_order($order); |
|
| 2978 | 2978 | } |
| 2979 | - $orderby = implode( ', ', $orderby_array ); |
|
| 2979 | + $orderby = implode(', ', $orderby_array); |
|
| 2980 | 2980 | |
| 2981 | 2981 | } else { |
| 2982 | - $q['orderby'] = urldecode( $q['orderby'] ); |
|
| 2983 | - $q['orderby'] = addslashes_gpc( $q['orderby'] ); |
|
| 2982 | + $q['orderby'] = urldecode($q['orderby']); |
|
| 2983 | + $q['orderby'] = addslashes_gpc($q['orderby']); |
|
| 2984 | 2984 | |
| 2985 | - foreach ( explode( ' ', $q['orderby'] ) as $i => $orderby ) { |
|
| 2986 | - $parsed = $this->parse_orderby( $orderby ); |
|
| 2985 | + foreach (explode(' ', $q['orderby']) as $i => $orderby) { |
|
| 2986 | + $parsed = $this->parse_orderby($orderby); |
|
| 2987 | 2987 | // Only allow certain values for safety. |
| 2988 | - if ( ! $parsed ) { |
|
| 2988 | + if ( ! $parsed) { |
|
| 2989 | 2989 | continue; |
| 2990 | 2990 | } |
| 2991 | 2991 | |
| 2992 | 2992 | $orderby_array[] = $parsed; |
| 2993 | 2993 | } |
| 2994 | - $orderby = implode( ' ' . $q['order'] . ', ', $orderby_array ); |
|
| 2994 | + $orderby = implode(' '.$q['order'].', ', $orderby_array); |
|
| 2995 | 2995 | |
| 2996 | - if ( empty( $orderby ) ) { |
|
| 2997 | - $orderby = "$wpdb->posts.post_date " . $q['order']; |
|
| 2998 | - } elseif ( ! empty( $q['order'] ) ) { |
|
| 2996 | + if (empty($orderby)) { |
|
| 2997 | + $orderby = "$wpdb->posts.post_date ".$q['order']; |
|
| 2998 | + } elseif ( ! empty($q['order'])) { |
|
| 2999 | 2999 | $orderby .= " {$q['order']}"; |
| 3000 | 3000 | } |
| 3001 | 3001 | } |
| 3002 | 3002 | } |
| 3003 | 3003 | |
| 3004 | 3004 | // Order search results by relevance only when another "orderby" is not specified in the query. |
| 3005 | - if ( ! empty( $q['s'] ) ) { |
|
| 3005 | + if ( ! empty($q['s'])) { |
|
| 3006 | 3006 | $search_orderby = ''; |
| 3007 | - if ( ! empty( $q['search_orderby_title'] ) && ( empty( $q['orderby'] ) && ! $this->is_feed ) || ( isset( $q['orderby'] ) && 'relevance' === $q['orderby'] ) ) |
|
| 3008 | - $search_orderby = $this->parse_search_order( $q ); |
|
| 3007 | + if ( ! empty($q['search_orderby_title']) && (empty($q['orderby']) && ! $this->is_feed) || (isset($q['orderby']) && 'relevance' === $q['orderby'])) |
|
| 3008 | + $search_orderby = $this->parse_search_order($q); |
|
| 3009 | 3009 | |
| 3010 | - if ( ! $q['suppress_filters'] ) { |
|
| 3010 | + if ( ! $q['suppress_filters']) { |
|
| 3011 | 3011 | /** |
| 3012 | 3012 | * Filter the ORDER BY used when ordering search results. |
| 3013 | 3013 | * |
@@ -3016,94 +3016,94 @@ discard block |
||
| 3016 | 3016 | * @param string $search_orderby The ORDER BY clause. |
| 3017 | 3017 | * @param WP_Query $this The current WP_Query instance. |
| 3018 | 3018 | */ |
| 3019 | - $search_orderby = apply_filters( 'posts_search_orderby', $search_orderby, $this ); |
|
| 3019 | + $search_orderby = apply_filters('posts_search_orderby', $search_orderby, $this); |
|
| 3020 | 3020 | } |
| 3021 | 3021 | |
| 3022 | - if ( $search_orderby ) |
|
| 3023 | - $orderby = $orderby ? $search_orderby . ', ' . $orderby : $search_orderby; |
|
| 3022 | + if ($search_orderby) |
|
| 3023 | + $orderby = $orderby ? $search_orderby.', '.$orderby : $search_orderby; |
|
| 3024 | 3024 | } |
| 3025 | 3025 | |
| 3026 | - if ( is_array( $post_type ) && count( $post_type ) > 1 ) { |
|
| 3026 | + if (is_array($post_type) && count($post_type) > 1) { |
|
| 3027 | 3027 | $post_type_cap = 'multiple_post_type'; |
| 3028 | 3028 | } else { |
| 3029 | - if ( is_array( $post_type ) ) |
|
| 3030 | - $post_type = reset( $post_type ); |
|
| 3031 | - $post_type_object = get_post_type_object( $post_type ); |
|
| 3032 | - if ( empty( $post_type_object ) ) |
|
| 3029 | + if (is_array($post_type)) |
|
| 3030 | + $post_type = reset($post_type); |
|
| 3031 | + $post_type_object = get_post_type_object($post_type); |
|
| 3032 | + if (empty($post_type_object)) |
|
| 3033 | 3033 | $post_type_cap = $post_type; |
| 3034 | 3034 | } |
| 3035 | 3035 | |
| 3036 | - if ( isset( $q['post_password'] ) ) { |
|
| 3037 | - $where .= $wpdb->prepare( " AND $wpdb->posts.post_password = %s", $q['post_password'] ); |
|
| 3038 | - if ( empty( $q['perm'] ) ) { |
|
| 3036 | + if (isset($q['post_password'])) { |
|
| 3037 | + $where .= $wpdb->prepare(" AND $wpdb->posts.post_password = %s", $q['post_password']); |
|
| 3038 | + if (empty($q['perm'])) { |
|
| 3039 | 3039 | $q['perm'] = 'readable'; |
| 3040 | 3040 | } |
| 3041 | - } elseif ( isset( $q['has_password'] ) ) { |
|
| 3042 | - $where .= sprintf( " AND $wpdb->posts.post_password %s ''", $q['has_password'] ? '!=' : '=' ); |
|
| 3041 | + } elseif (isset($q['has_password'])) { |
|
| 3042 | + $where .= sprintf(" AND $wpdb->posts.post_password %s ''", $q['has_password'] ? '!=' : '='); |
|
| 3043 | 3043 | } |
| 3044 | 3044 | |
| 3045 | - if ( ! empty( $q['comment_status'] ) ) { |
|
| 3046 | - $where .= $wpdb->prepare( " AND $wpdb->posts.comment_status = %s ", $q['comment_status'] ); |
|
| 3045 | + if ( ! empty($q['comment_status'])) { |
|
| 3046 | + $where .= $wpdb->prepare(" AND $wpdb->posts.comment_status = %s ", $q['comment_status']); |
|
| 3047 | 3047 | } |
| 3048 | 3048 | |
| 3049 | - if ( ! empty( $q['ping_status'] ) ) { |
|
| 3050 | - $where .= $wpdb->prepare( " AND $wpdb->posts.ping_status = %s ", $q['ping_status'] ); |
|
| 3049 | + if ( ! empty($q['ping_status'])) { |
|
| 3050 | + $where .= $wpdb->prepare(" AND $wpdb->posts.ping_status = %s ", $q['ping_status']); |
|
| 3051 | 3051 | } |
| 3052 | 3052 | |
| 3053 | - if ( 'any' == $post_type ) { |
|
| 3054 | - $in_search_post_types = get_post_types( array('exclude_from_search' => false) ); |
|
| 3055 | - if ( empty( $in_search_post_types ) ) |
|
| 3053 | + if ('any' == $post_type) { |
|
| 3054 | + $in_search_post_types = get_post_types(array('exclude_from_search' => false)); |
|
| 3055 | + if (empty($in_search_post_types)) |
|
| 3056 | 3056 | $where .= ' AND 1=0 '; |
| 3057 | 3057 | else |
| 3058 | - $where .= " AND $wpdb->posts.post_type IN ('" . join("', '", $in_search_post_types ) . "')"; |
|
| 3059 | - } elseif ( !empty( $post_type ) && is_array( $post_type ) ) { |
|
| 3060 | - $where .= " AND $wpdb->posts.post_type IN ('" . join("', '", $post_type) . "')"; |
|
| 3061 | - } elseif ( ! empty( $post_type ) ) { |
|
| 3058 | + $where .= " AND $wpdb->posts.post_type IN ('".join("', '", $in_search_post_types)."')"; |
|
| 3059 | + } elseif ( ! empty($post_type) && is_array($post_type)) { |
|
| 3060 | + $where .= " AND $wpdb->posts.post_type IN ('".join("', '", $post_type)."')"; |
|
| 3061 | + } elseif ( ! empty($post_type)) { |
|
| 3062 | 3062 | $where .= " AND $wpdb->posts.post_type = '$post_type'"; |
| 3063 | - $post_type_object = get_post_type_object ( $post_type ); |
|
| 3064 | - } elseif ( $this->is_attachment ) { |
|
| 3063 | + $post_type_object = get_post_type_object($post_type); |
|
| 3064 | + } elseif ($this->is_attachment) { |
|
| 3065 | 3065 | $where .= " AND $wpdb->posts.post_type = 'attachment'"; |
| 3066 | - $post_type_object = get_post_type_object ( 'attachment' ); |
|
| 3067 | - } elseif ( $this->is_page ) { |
|
| 3066 | + $post_type_object = get_post_type_object('attachment'); |
|
| 3067 | + } elseif ($this->is_page) { |
|
| 3068 | 3068 | $where .= " AND $wpdb->posts.post_type = 'page'"; |
| 3069 | - $post_type_object = get_post_type_object ( 'page' ); |
|
| 3069 | + $post_type_object = get_post_type_object('page'); |
|
| 3070 | 3070 | } else { |
| 3071 | 3071 | $where .= " AND $wpdb->posts.post_type = 'post'"; |
| 3072 | - $post_type_object = get_post_type_object ( 'post' ); |
|
| 3072 | + $post_type_object = get_post_type_object('post'); |
|
| 3073 | 3073 | } |
| 3074 | 3074 | |
| 3075 | 3075 | $edit_cap = 'edit_post'; |
| 3076 | 3076 | $read_cap = 'read_post'; |
| 3077 | 3077 | |
| 3078 | - if ( ! empty( $post_type_object ) ) { |
|
| 3078 | + if ( ! empty($post_type_object)) { |
|
| 3079 | 3079 | $edit_others_cap = $post_type_object->cap->edit_others_posts; |
| 3080 | 3080 | $read_private_cap = $post_type_object->cap->read_private_posts; |
| 3081 | 3081 | } else { |
| 3082 | - $edit_others_cap = 'edit_others_' . $post_type_cap . 's'; |
|
| 3083 | - $read_private_cap = 'read_private_' . $post_type_cap . 's'; |
|
| 3082 | + $edit_others_cap = 'edit_others_'.$post_type_cap.'s'; |
|
| 3083 | + $read_private_cap = 'read_private_'.$post_type_cap.'s'; |
|
| 3084 | 3084 | } |
| 3085 | 3085 | |
| 3086 | 3086 | $user_id = get_current_user_id(); |
| 3087 | 3087 | |
| 3088 | 3088 | $q_status = array(); |
| 3089 | - if ( ! empty( $q['post_status'] ) ) { |
|
| 3089 | + if ( ! empty($q['post_status'])) { |
|
| 3090 | 3090 | $statuswheres = array(); |
| 3091 | 3091 | $q_status = $q['post_status']; |
| 3092 | - if ( ! is_array( $q_status ) ) |
|
| 3092 | + if ( ! is_array($q_status)) |
|
| 3093 | 3093 | $q_status = explode(',', $q_status); |
| 3094 | 3094 | $r_status = array(); |
| 3095 | 3095 | $p_status = array(); |
| 3096 | 3096 | $e_status = array(); |
| 3097 | - if ( in_array( 'any', $q_status ) ) { |
|
| 3098 | - foreach ( get_post_stati( array( 'exclude_from_search' => true ) ) as $status ) { |
|
| 3099 | - if ( ! in_array( $status, $q_status ) ) { |
|
| 3097 | + if (in_array('any', $q_status)) { |
|
| 3098 | + foreach (get_post_stati(array('exclude_from_search' => true)) as $status) { |
|
| 3099 | + if ( ! in_array($status, $q_status)) { |
|
| 3100 | 3100 | $e_status[] = "$wpdb->posts.post_status <> '$status'"; |
| 3101 | 3101 | } |
| 3102 | 3102 | } |
| 3103 | 3103 | } else { |
| 3104 | - foreach ( get_post_stati() as $status ) { |
|
| 3105 | - if ( in_array( $status, $q_status ) ) { |
|
| 3106 | - if ( 'private' == $status ) |
|
| 3104 | + foreach (get_post_stati() as $status) { |
|
| 3105 | + if (in_array($status, $q_status)) { |
|
| 3106 | + if ('private' == $status) |
|
| 3107 | 3107 | $p_status[] = "$wpdb->posts.post_status = '$status'"; |
| 3108 | 3108 | else |
| 3109 | 3109 | $r_status[] = "$wpdb->posts.post_status = '$status'"; |
@@ -3111,58 +3111,58 @@ discard block |
||
| 3111 | 3111 | } |
| 3112 | 3112 | } |
| 3113 | 3113 | |
| 3114 | - if ( empty($q['perm'] ) || 'readable' != $q['perm'] ) { |
|
| 3114 | + if (empty($q['perm']) || 'readable' != $q['perm']) { |
|
| 3115 | 3115 | $r_status = array_merge($r_status, $p_status); |
| 3116 | 3116 | unset($p_status); |
| 3117 | 3117 | } |
| 3118 | 3118 | |
| 3119 | - if ( !empty($e_status) ) { |
|
| 3120 | - $statuswheres[] = "(" . join( ' AND ', $e_status ) . ")"; |
|
| 3119 | + if ( ! empty($e_status)) { |
|
| 3120 | + $statuswheres[] = "(".join(' AND ', $e_status).")"; |
|
| 3121 | 3121 | } |
| 3122 | - if ( !empty($r_status) ) { |
|
| 3123 | - if ( !empty($q['perm'] ) && 'editable' == $q['perm'] && !current_user_can($edit_others_cap) ) |
|
| 3124 | - $statuswheres[] = "($wpdb->posts.post_author = $user_id " . "AND (" . join( ' OR ', $r_status ) . "))"; |
|
| 3122 | + if ( ! empty($r_status)) { |
|
| 3123 | + if ( ! empty($q['perm']) && 'editable' == $q['perm'] && ! current_user_can($edit_others_cap)) |
|
| 3124 | + $statuswheres[] = "($wpdb->posts.post_author = $user_id "."AND (".join(' OR ', $r_status)."))"; |
|
| 3125 | 3125 | else |
| 3126 | - $statuswheres[] = "(" . join( ' OR ', $r_status ) . ")"; |
|
| 3126 | + $statuswheres[] = "(".join(' OR ', $r_status).")"; |
|
| 3127 | 3127 | } |
| 3128 | - if ( !empty($p_status) ) { |
|
| 3129 | - if ( !empty($q['perm'] ) && 'readable' == $q['perm'] && !current_user_can($read_private_cap) ) |
|
| 3130 | - $statuswheres[] = "($wpdb->posts.post_author = $user_id " . "AND (" . join( ' OR ', $p_status ) . "))"; |
|
| 3128 | + if ( ! empty($p_status)) { |
|
| 3129 | + if ( ! empty($q['perm']) && 'readable' == $q['perm'] && ! current_user_can($read_private_cap)) |
|
| 3130 | + $statuswheres[] = "($wpdb->posts.post_author = $user_id "."AND (".join(' OR ', $p_status)."))"; |
|
| 3131 | 3131 | else |
| 3132 | - $statuswheres[] = "(" . join( ' OR ', $p_status ) . ")"; |
|
| 3132 | + $statuswheres[] = "(".join(' OR ', $p_status).")"; |
|
| 3133 | 3133 | } |
| 3134 | - if ( $post_status_join ) { |
|
| 3134 | + if ($post_status_join) { |
|
| 3135 | 3135 | $join .= " LEFT JOIN $wpdb->posts AS p2 ON ($wpdb->posts.post_parent = p2.ID) "; |
| 3136 | - foreach ( $statuswheres as $index => $statuswhere ) |
|
| 3137 | - $statuswheres[$index] = "($statuswhere OR ($wpdb->posts.post_status = 'inherit' AND " . str_replace($wpdb->posts, 'p2', $statuswhere) . "))"; |
|
| 3136 | + foreach ($statuswheres as $index => $statuswhere) |
|
| 3137 | + $statuswheres[$index] = "($statuswhere OR ($wpdb->posts.post_status = 'inherit' AND ".str_replace($wpdb->posts, 'p2', $statuswhere)."))"; |
|
| 3138 | 3138 | } |
| 3139 | - $where_status = implode( ' OR ', $statuswheres ); |
|
| 3140 | - if ( ! empty( $where_status ) ) { |
|
| 3139 | + $where_status = implode(' OR ', $statuswheres); |
|
| 3140 | + if ( ! empty($where_status)) { |
|
| 3141 | 3141 | $where .= " AND ($where_status)"; |
| 3142 | 3142 | } |
| 3143 | - } elseif ( !$this->is_singular ) { |
|
| 3143 | + } elseif ( ! $this->is_singular) { |
|
| 3144 | 3144 | $where .= " AND ($wpdb->posts.post_status = 'publish'"; |
| 3145 | 3145 | |
| 3146 | 3146 | // Add public states. |
| 3147 | - $public_states = get_post_stati( array('public' => true) ); |
|
| 3148 | - foreach ( (array) $public_states as $state ) { |
|
| 3149 | - if ( 'publish' == $state ) // Publish is hard-coded above. |
|
| 3147 | + $public_states = get_post_stati(array('public' => true)); |
|
| 3148 | + foreach ((array) $public_states as $state) { |
|
| 3149 | + if ('publish' == $state) // Publish is hard-coded above. |
|
| 3150 | 3150 | continue; |
| 3151 | 3151 | $where .= " OR $wpdb->posts.post_status = '$state'"; |
| 3152 | 3152 | } |
| 3153 | 3153 | |
| 3154 | - if ( $this->is_admin ) { |
|
| 3154 | + if ($this->is_admin) { |
|
| 3155 | 3155 | // Add protected states that should show in the admin all list. |
| 3156 | - $admin_all_states = get_post_stati( array('protected' => true, 'show_in_admin_all_list' => true) ); |
|
| 3157 | - foreach ( (array) $admin_all_states as $state ) |
|
| 3156 | + $admin_all_states = get_post_stati(array('protected' => true, 'show_in_admin_all_list' => true)); |
|
| 3157 | + foreach ((array) $admin_all_states as $state) |
|
| 3158 | 3158 | $where .= " OR $wpdb->posts.post_status = '$state'"; |
| 3159 | 3159 | } |
| 3160 | 3160 | |
| 3161 | - if ( is_user_logged_in() ) { |
|
| 3161 | + if (is_user_logged_in()) { |
|
| 3162 | 3162 | // Add private states that are limited to viewing by the author of a post or someone who has caps to read private states. |
| 3163 | - $private_states = get_post_stati( array('private' => true) ); |
|
| 3164 | - foreach ( (array) $private_states as $state ) |
|
| 3165 | - $where .= current_user_can( $read_private_cap ) ? " OR $wpdb->posts.post_status = '$state'" : " OR $wpdb->posts.post_author = $user_id AND $wpdb->posts.post_status = '$state'"; |
|
| 3163 | + $private_states = get_post_stati(array('private' => true)); |
|
| 3164 | + foreach ((array) $private_states as $state) |
|
| 3165 | + $where .= current_user_can($read_private_cap) ? " OR $wpdb->posts.post_status = '$state'" : " OR $wpdb->posts.post_author = $user_id AND $wpdb->posts.post_status = '$state'"; |
|
| 3166 | 3166 | } |
| 3167 | 3167 | |
| 3168 | 3168 | $where .= ')'; |
@@ -3172,7 +3172,7 @@ discard block |
||
| 3172 | 3172 | * Apply filters on where and join prior to paging so that any |
| 3173 | 3173 | * manipulations to them are reflected in the paging by day queries. |
| 3174 | 3174 | */ |
| 3175 | - if ( !$q['suppress_filters'] ) { |
|
| 3175 | + if ( ! $q['suppress_filters']) { |
|
| 3176 | 3176 | /** |
| 3177 | 3177 | * Filter the WHERE clause of the query. |
| 3178 | 3178 | * |
@@ -3181,7 +3181,7 @@ discard block |
||
| 3181 | 3181 | * @param string $where The WHERE clause of the query. |
| 3182 | 3182 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3183 | 3183 | */ |
| 3184 | - $where = apply_filters_ref_array( 'posts_where', array( $where, &$this ) ); |
|
| 3184 | + $where = apply_filters_ref_array('posts_where', array($where, &$this)); |
|
| 3185 | 3185 | |
| 3186 | 3186 | /** |
| 3187 | 3187 | * Filter the JOIN clause of the query. |
@@ -3191,28 +3191,28 @@ discard block |
||
| 3191 | 3191 | * @param string $where The JOIN clause of the query. |
| 3192 | 3192 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3193 | 3193 | */ |
| 3194 | - $join = apply_filters_ref_array( 'posts_join', array( $join, &$this ) ); |
|
| 3194 | + $join = apply_filters_ref_array('posts_join', array($join, &$this)); |
|
| 3195 | 3195 | } |
| 3196 | 3196 | |
| 3197 | 3197 | // Paging |
| 3198 | - if ( empty($q['nopaging']) && !$this->is_singular ) { |
|
| 3198 | + if (empty($q['nopaging']) && ! $this->is_singular) { |
|
| 3199 | 3199 | $page = absint($q['paged']); |
| 3200 | - if ( !$page ) |
|
| 3200 | + if ( ! $page) |
|
| 3201 | 3201 | $page = 1; |
| 3202 | 3202 | |
| 3203 | 3203 | // If 'offset' is provided, it takes precedence over 'paged'. |
| 3204 | - if ( isset( $q['offset'] ) && is_numeric( $q['offset'] ) ) { |
|
| 3205 | - $q['offset'] = absint( $q['offset'] ); |
|
| 3206 | - $pgstrt = $q['offset'] . ', '; |
|
| 3204 | + if (isset($q['offset']) && is_numeric($q['offset'])) { |
|
| 3205 | + $q['offset'] = absint($q['offset']); |
|
| 3206 | + $pgstrt = $q['offset'].', '; |
|
| 3207 | 3207 | } else { |
| 3208 | - $pgstrt = absint( ( $page - 1 ) * $q['posts_per_page'] ) . ', '; |
|
| 3208 | + $pgstrt = absint(($page - 1) * $q['posts_per_page']).', '; |
|
| 3209 | 3209 | } |
| 3210 | - $limits = 'LIMIT ' . $pgstrt . $q['posts_per_page']; |
|
| 3210 | + $limits = 'LIMIT '.$pgstrt.$q['posts_per_page']; |
|
| 3211 | 3211 | } |
| 3212 | 3212 | |
| 3213 | 3213 | // Comments feeds |
| 3214 | - if ( $this->is_comment_feed && ! $this->is_singular ) { |
|
| 3215 | - if ( $this->is_archive || $this->is_search ) { |
|
| 3214 | + if ($this->is_comment_feed && ! $this->is_singular) { |
|
| 3215 | + if ($this->is_archive || $this->is_search) { |
|
| 3216 | 3216 | $cjoin = "JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) $join "; |
| 3217 | 3217 | $cwhere = "WHERE comment_approved = '1' $where"; |
| 3218 | 3218 | $cgroupby = "$wpdb->comments.comment_id"; |
@@ -3222,7 +3222,7 @@ discard block |
||
| 3222 | 3222 | $cgroupby = ''; |
| 3223 | 3223 | } |
| 3224 | 3224 | |
| 3225 | - if ( !$q['suppress_filters'] ) { |
|
| 3225 | + if ( ! $q['suppress_filters']) { |
|
| 3226 | 3226 | /** |
| 3227 | 3227 | * Filter the JOIN clause of the comments feed query before sending. |
| 3228 | 3228 | * |
@@ -3231,7 +3231,7 @@ discard block |
||
| 3231 | 3231 | * @param string $cjoin The JOIN clause of the query. |
| 3232 | 3232 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3233 | 3233 | */ |
| 3234 | - $cjoin = apply_filters_ref_array( 'comment_feed_join', array( $cjoin, &$this ) ); |
|
| 3234 | + $cjoin = apply_filters_ref_array('comment_feed_join', array($cjoin, &$this)); |
|
| 3235 | 3235 | |
| 3236 | 3236 | /** |
| 3237 | 3237 | * Filter the WHERE clause of the comments feed query before sending. |
@@ -3241,7 +3241,7 @@ discard block |
||
| 3241 | 3241 | * @param string $cwhere The WHERE clause of the query. |
| 3242 | 3242 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3243 | 3243 | */ |
| 3244 | - $cwhere = apply_filters_ref_array( 'comment_feed_where', array( $cwhere, &$this ) ); |
|
| 3244 | + $cwhere = apply_filters_ref_array('comment_feed_where', array($cwhere, &$this)); |
|
| 3245 | 3245 | |
| 3246 | 3246 | /** |
| 3247 | 3247 | * Filter the GROUP BY clause of the comments feed query before sending. |
@@ -3251,7 +3251,7 @@ discard block |
||
| 3251 | 3251 | * @param string $cgroupby The GROUP BY clause of the query. |
| 3252 | 3252 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3253 | 3253 | */ |
| 3254 | - $cgroupby = apply_filters_ref_array( 'comment_feed_groupby', array( $cgroupby, &$this ) ); |
|
| 3254 | + $cgroupby = apply_filters_ref_array('comment_feed_groupby', array($cgroupby, &$this)); |
|
| 3255 | 3255 | |
| 3256 | 3256 | /** |
| 3257 | 3257 | * Filter the ORDER BY clause of the comments feed query before sending. |
@@ -3261,7 +3261,7 @@ discard block |
||
| 3261 | 3261 | * @param string $corderby The ORDER BY clause of the query. |
| 3262 | 3262 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3263 | 3263 | */ |
| 3264 | - $corderby = apply_filters_ref_array( 'comment_feed_orderby', array( 'comment_date_gmt DESC', &$this ) ); |
|
| 3264 | + $corderby = apply_filters_ref_array('comment_feed_orderby', array('comment_date_gmt DESC', &$this)); |
|
| 3265 | 3265 | |
| 3266 | 3266 | /** |
| 3267 | 3267 | * Filter the LIMIT clause of the comments feed query before sending. |
@@ -3271,36 +3271,36 @@ discard block |
||
| 3271 | 3271 | * @param string $climits The JOIN clause of the query. |
| 3272 | 3272 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3273 | 3273 | */ |
| 3274 | - $climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option('posts_per_rss'), &$this ) ); |
|
| 3274 | + $climits = apply_filters_ref_array('comment_feed_limits', array('LIMIT '.get_option('posts_per_rss'), &$this)); |
|
| 3275 | 3275 | } |
| 3276 | - $cgroupby = ( ! empty( $cgroupby ) ) ? 'GROUP BY ' . $cgroupby : ''; |
|
| 3277 | - $corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : ''; |
|
| 3276 | + $cgroupby = ( ! empty($cgroupby)) ? 'GROUP BY '.$cgroupby : ''; |
|
| 3277 | + $corderby = ( ! empty($corderby)) ? 'ORDER BY '.$corderby : ''; |
|
| 3278 | 3278 | |
| 3279 | 3279 | $comments = (array) $wpdb->get_results("SELECT $distinct $wpdb->comments.* FROM $wpdb->comments $cjoin $cwhere $cgroupby $corderby $climits"); |
| 3280 | 3280 | // Convert to WP_Comment |
| 3281 | - $this->comments = array_map( 'get_comment', $comments ); |
|
| 3281 | + $this->comments = array_map('get_comment', $comments); |
|
| 3282 | 3282 | $this->comment_count = count($this->comments); |
| 3283 | 3283 | |
| 3284 | 3284 | $post_ids = array(); |
| 3285 | 3285 | |
| 3286 | - foreach ( $this->comments as $comment ) |
|
| 3286 | + foreach ($this->comments as $comment) |
|
| 3287 | 3287 | $post_ids[] = (int) $comment->comment_post_ID; |
| 3288 | 3288 | |
| 3289 | 3289 | $post_ids = join(',', $post_ids); |
| 3290 | 3290 | $join = ''; |
| 3291 | - if ( $post_ids ) |
|
| 3291 | + if ($post_ids) |
|
| 3292 | 3292 | $where = "AND $wpdb->posts.ID IN ($post_ids) "; |
| 3293 | 3293 | else |
| 3294 | 3294 | $where = "AND 0"; |
| 3295 | 3295 | } |
| 3296 | 3296 | |
| 3297 | - $pieces = array( 'where', 'groupby', 'join', 'orderby', 'distinct', 'fields', 'limits' ); |
|
| 3297 | + $pieces = array('where', 'groupby', 'join', 'orderby', 'distinct', 'fields', 'limits'); |
|
| 3298 | 3298 | |
| 3299 | 3299 | /* |
| 3300 | 3300 | * Apply post-paging filters on where and join. Only plugins that |
| 3301 | 3301 | * manipulate paging queries should use these hooks. |
| 3302 | 3302 | */ |
| 3303 | - if ( !$q['suppress_filters'] ) { |
|
| 3303 | + if ( ! $q['suppress_filters']) { |
|
| 3304 | 3304 | /** |
| 3305 | 3305 | * Filter the WHERE clause of the query. |
| 3306 | 3306 | * |
@@ -3311,7 +3311,7 @@ discard block |
||
| 3311 | 3311 | * @param string $where The WHERE clause of the query. |
| 3312 | 3312 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3313 | 3313 | */ |
| 3314 | - $where = apply_filters_ref_array( 'posts_where_paged', array( $where, &$this ) ); |
|
| 3314 | + $where = apply_filters_ref_array('posts_where_paged', array($where, &$this)); |
|
| 3315 | 3315 | |
| 3316 | 3316 | /** |
| 3317 | 3317 | * Filter the GROUP BY clause of the query. |
@@ -3321,7 +3321,7 @@ discard block |
||
| 3321 | 3321 | * @param string $groupby The GROUP BY clause of the query. |
| 3322 | 3322 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3323 | 3323 | */ |
| 3324 | - $groupby = apply_filters_ref_array( 'posts_groupby', array( $groupby, &$this ) ); |
|
| 3324 | + $groupby = apply_filters_ref_array('posts_groupby', array($groupby, &$this)); |
|
| 3325 | 3325 | |
| 3326 | 3326 | /** |
| 3327 | 3327 | * Filter the JOIN clause of the query. |
@@ -3333,7 +3333,7 @@ discard block |
||
| 3333 | 3333 | * @param string $join The JOIN clause of the query. |
| 3334 | 3334 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3335 | 3335 | */ |
| 3336 | - $join = apply_filters_ref_array( 'posts_join_paged', array( $join, &$this ) ); |
|
| 3336 | + $join = apply_filters_ref_array('posts_join_paged', array($join, &$this)); |
|
| 3337 | 3337 | |
| 3338 | 3338 | /** |
| 3339 | 3339 | * Filter the ORDER BY clause of the query. |
@@ -3343,7 +3343,7 @@ discard block |
||
| 3343 | 3343 | * @param string $orderby The ORDER BY clause of the query. |
| 3344 | 3344 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3345 | 3345 | */ |
| 3346 | - $orderby = apply_filters_ref_array( 'posts_orderby', array( $orderby, &$this ) ); |
|
| 3346 | + $orderby = apply_filters_ref_array('posts_orderby', array($orderby, &$this)); |
|
| 3347 | 3347 | |
| 3348 | 3348 | /** |
| 3349 | 3349 | * Filter the DISTINCT clause of the query. |
@@ -3353,7 +3353,7 @@ discard block |
||
| 3353 | 3353 | * @param string $distinct The DISTINCT clause of the query. |
| 3354 | 3354 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3355 | 3355 | */ |
| 3356 | - $distinct = apply_filters_ref_array( 'posts_distinct', array( $distinct, &$this ) ); |
|
| 3356 | + $distinct = apply_filters_ref_array('posts_distinct', array($distinct, &$this)); |
|
| 3357 | 3357 | |
| 3358 | 3358 | /** |
| 3359 | 3359 | * Filter the LIMIT clause of the query. |
@@ -3363,7 +3363,7 @@ discard block |
||
| 3363 | 3363 | * @param string $limits The LIMIT clause of the query. |
| 3364 | 3364 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3365 | 3365 | */ |
| 3366 | - $limits = apply_filters_ref_array( 'post_limits', array( $limits, &$this ) ); |
|
| 3366 | + $limits = apply_filters_ref_array('post_limits', array($limits, &$this)); |
|
| 3367 | 3367 | |
| 3368 | 3368 | /** |
| 3369 | 3369 | * Filter the SELECT clause of the query. |
@@ -3373,7 +3373,7 @@ discard block |
||
| 3373 | 3373 | * @param string $fields The SELECT clause of the query. |
| 3374 | 3374 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3375 | 3375 | */ |
| 3376 | - $fields = apply_filters_ref_array( 'posts_fields', array( $fields, &$this ) ); |
|
| 3376 | + $fields = apply_filters_ref_array('posts_fields', array($fields, &$this)); |
|
| 3377 | 3377 | |
| 3378 | 3378 | /** |
| 3379 | 3379 | * Filter all query clauses at once, for convenience. |
@@ -3386,15 +3386,15 @@ discard block |
||
| 3386 | 3386 | * @param array $clauses The list of clauses for the query. |
| 3387 | 3387 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3388 | 3388 | */ |
| 3389 | - $clauses = (array) apply_filters_ref_array( 'posts_clauses', array( compact( $pieces ), &$this ) ); |
|
| 3390 | - |
|
| 3391 | - $where = isset( $clauses[ 'where' ] ) ? $clauses[ 'where' ] : ''; |
|
| 3392 | - $groupby = isset( $clauses[ 'groupby' ] ) ? $clauses[ 'groupby' ] : ''; |
|
| 3393 | - $join = isset( $clauses[ 'join' ] ) ? $clauses[ 'join' ] : ''; |
|
| 3394 | - $orderby = isset( $clauses[ 'orderby' ] ) ? $clauses[ 'orderby' ] : ''; |
|
| 3395 | - $distinct = isset( $clauses[ 'distinct' ] ) ? $clauses[ 'distinct' ] : ''; |
|
| 3396 | - $fields = isset( $clauses[ 'fields' ] ) ? $clauses[ 'fields' ] : ''; |
|
| 3397 | - $limits = isset( $clauses[ 'limits' ] ) ? $clauses[ 'limits' ] : ''; |
|
| 3389 | + $clauses = (array) apply_filters_ref_array('posts_clauses', array(compact($pieces), &$this)); |
|
| 3390 | + |
|
| 3391 | + $where = isset($clauses['where']) ? $clauses['where'] : ''; |
|
| 3392 | + $groupby = isset($clauses['groupby']) ? $clauses['groupby'] : ''; |
|
| 3393 | + $join = isset($clauses['join']) ? $clauses['join'] : ''; |
|
| 3394 | + $orderby = isset($clauses['orderby']) ? $clauses['orderby'] : ''; |
|
| 3395 | + $distinct = isset($clauses['distinct']) ? $clauses['distinct'] : ''; |
|
| 3396 | + $fields = isset($clauses['fields']) ? $clauses['fields'] : ''; |
|
| 3397 | + $limits = isset($clauses['limits']) ? $clauses['limits'] : ''; |
|
| 3398 | 3398 | } |
| 3399 | 3399 | |
| 3400 | 3400 | /** |
@@ -3406,13 +3406,13 @@ discard block |
||
| 3406 | 3406 | * |
| 3407 | 3407 | * @param string $selection The assembled selection query. |
| 3408 | 3408 | */ |
| 3409 | - do_action( 'posts_selection', $where . $groupby . $orderby . $limits . $join ); |
|
| 3409 | + do_action('posts_selection', $where.$groupby.$orderby.$limits.$join); |
|
| 3410 | 3410 | |
| 3411 | 3411 | /* |
| 3412 | 3412 | * Filter again for the benefit of caching plugins. |
| 3413 | 3413 | * Regular plugins should use the hooks above. |
| 3414 | 3414 | */ |
| 3415 | - if ( !$q['suppress_filters'] ) { |
|
| 3415 | + if ( ! $q['suppress_filters']) { |
|
| 3416 | 3416 | /** |
| 3417 | 3417 | * Filter the WHERE clause of the query. |
| 3418 | 3418 | * |
@@ -3423,7 +3423,7 @@ discard block |
||
| 3423 | 3423 | * @param string $where The WHERE clause of the query. |
| 3424 | 3424 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3425 | 3425 | */ |
| 3426 | - $where = apply_filters_ref_array( 'posts_where_request', array( $where, &$this ) ); |
|
| 3426 | + $where = apply_filters_ref_array('posts_where_request', array($where, &$this)); |
|
| 3427 | 3427 | |
| 3428 | 3428 | /** |
| 3429 | 3429 | * Filter the GROUP BY clause of the query. |
@@ -3435,7 +3435,7 @@ discard block |
||
| 3435 | 3435 | * @param string $groupby The GROUP BY clause of the query. |
| 3436 | 3436 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3437 | 3437 | */ |
| 3438 | - $groupby = apply_filters_ref_array( 'posts_groupby_request', array( $groupby, &$this ) ); |
|
| 3438 | + $groupby = apply_filters_ref_array('posts_groupby_request', array($groupby, &$this)); |
|
| 3439 | 3439 | |
| 3440 | 3440 | /** |
| 3441 | 3441 | * Filter the JOIN clause of the query. |
@@ -3447,7 +3447,7 @@ discard block |
||
| 3447 | 3447 | * @param string $join The JOIN clause of the query. |
| 3448 | 3448 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3449 | 3449 | */ |
| 3450 | - $join = apply_filters_ref_array( 'posts_join_request', array( $join, &$this ) ); |
|
| 3450 | + $join = apply_filters_ref_array('posts_join_request', array($join, &$this)); |
|
| 3451 | 3451 | |
| 3452 | 3452 | /** |
| 3453 | 3453 | * Filter the ORDER BY clause of the query. |
@@ -3459,7 +3459,7 @@ discard block |
||
| 3459 | 3459 | * @param string $orderby The ORDER BY clause of the query. |
| 3460 | 3460 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3461 | 3461 | */ |
| 3462 | - $orderby = apply_filters_ref_array( 'posts_orderby_request', array( $orderby, &$this ) ); |
|
| 3462 | + $orderby = apply_filters_ref_array('posts_orderby_request', array($orderby, &$this)); |
|
| 3463 | 3463 | |
| 3464 | 3464 | /** |
| 3465 | 3465 | * Filter the DISTINCT clause of the query. |
@@ -3471,7 +3471,7 @@ discard block |
||
| 3471 | 3471 | * @param string $distinct The DISTINCT clause of the query. |
| 3472 | 3472 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3473 | 3473 | */ |
| 3474 | - $distinct = apply_filters_ref_array( 'posts_distinct_request', array( $distinct, &$this ) ); |
|
| 3474 | + $distinct = apply_filters_ref_array('posts_distinct_request', array($distinct, &$this)); |
|
| 3475 | 3475 | |
| 3476 | 3476 | /** |
| 3477 | 3477 | * Filter the SELECT clause of the query. |
@@ -3483,7 +3483,7 @@ discard block |
||
| 3483 | 3483 | * @param string $fields The SELECT clause of the query. |
| 3484 | 3484 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3485 | 3485 | */ |
| 3486 | - $fields = apply_filters_ref_array( 'posts_fields_request', array( $fields, &$this ) ); |
|
| 3486 | + $fields = apply_filters_ref_array('posts_fields_request', array($fields, &$this)); |
|
| 3487 | 3487 | |
| 3488 | 3488 | /** |
| 3489 | 3489 | * Filter the LIMIT clause of the query. |
@@ -3495,7 +3495,7 @@ discard block |
||
| 3495 | 3495 | * @param string $limits The LIMIT clause of the query. |
| 3496 | 3496 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3497 | 3497 | */ |
| 3498 | - $limits = apply_filters_ref_array( 'post_limits_request', array( $limits, &$this ) ); |
|
| 3498 | + $limits = apply_filters_ref_array('post_limits_request', array($limits, &$this)); |
|
| 3499 | 3499 | |
| 3500 | 3500 | /** |
| 3501 | 3501 | * Filter all query clauses at once, for convenience. |
@@ -3510,29 +3510,29 @@ discard block |
||
| 3510 | 3510 | * @param array $pieces The pieces of the query. |
| 3511 | 3511 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3512 | 3512 | */ |
| 3513 | - $clauses = (array) apply_filters_ref_array( 'posts_clauses_request', array( compact( $pieces ), &$this ) ); |
|
| 3514 | - |
|
| 3515 | - $where = isset( $clauses[ 'where' ] ) ? $clauses[ 'where' ] : ''; |
|
| 3516 | - $groupby = isset( $clauses[ 'groupby' ] ) ? $clauses[ 'groupby' ] : ''; |
|
| 3517 | - $join = isset( $clauses[ 'join' ] ) ? $clauses[ 'join' ] : ''; |
|
| 3518 | - $orderby = isset( $clauses[ 'orderby' ] ) ? $clauses[ 'orderby' ] : ''; |
|
| 3519 | - $distinct = isset( $clauses[ 'distinct' ] ) ? $clauses[ 'distinct' ] : ''; |
|
| 3520 | - $fields = isset( $clauses[ 'fields' ] ) ? $clauses[ 'fields' ] : ''; |
|
| 3521 | - $limits = isset( $clauses[ 'limits' ] ) ? $clauses[ 'limits' ] : ''; |
|
| 3513 | + $clauses = (array) apply_filters_ref_array('posts_clauses_request', array(compact($pieces), &$this)); |
|
| 3514 | + |
|
| 3515 | + $where = isset($clauses['where']) ? $clauses['where'] : ''; |
|
| 3516 | + $groupby = isset($clauses['groupby']) ? $clauses['groupby'] : ''; |
|
| 3517 | + $join = isset($clauses['join']) ? $clauses['join'] : ''; |
|
| 3518 | + $orderby = isset($clauses['orderby']) ? $clauses['orderby'] : ''; |
|
| 3519 | + $distinct = isset($clauses['distinct']) ? $clauses['distinct'] : ''; |
|
| 3520 | + $fields = isset($clauses['fields']) ? $clauses['fields'] : ''; |
|
| 3521 | + $limits = isset($clauses['limits']) ? $clauses['limits'] : ''; |
|
| 3522 | 3522 | } |
| 3523 | 3523 | |
| 3524 | - if ( ! empty($groupby) ) |
|
| 3525 | - $groupby = 'GROUP BY ' . $groupby; |
|
| 3526 | - if ( !empty( $orderby ) ) |
|
| 3527 | - $orderby = 'ORDER BY ' . $orderby; |
|
| 3524 | + if ( ! empty($groupby)) |
|
| 3525 | + $groupby = 'GROUP BY '.$groupby; |
|
| 3526 | + if ( ! empty($orderby)) |
|
| 3527 | + $orderby = 'ORDER BY '.$orderby; |
|
| 3528 | 3528 | |
| 3529 | 3529 | $found_rows = ''; |
| 3530 | - if ( !$q['no_found_rows'] && !empty($limits) ) |
|
| 3530 | + if ( ! $q['no_found_rows'] && ! empty($limits)) |
|
| 3531 | 3531 | $found_rows = 'SQL_CALC_FOUND_ROWS'; |
| 3532 | 3532 | |
| 3533 | 3533 | $this->request = $old_request = "SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits"; |
| 3534 | 3534 | |
| 3535 | - if ( !$q['suppress_filters'] ) { |
|
| 3535 | + if ( ! $q['suppress_filters']) { |
|
| 3536 | 3536 | /** |
| 3537 | 3537 | * Filter the completed SQL query before sending. |
| 3538 | 3538 | * |
@@ -3541,35 +3541,35 @@ discard block |
||
| 3541 | 3541 | * @param array $request The complete SQL query. |
| 3542 | 3542 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3543 | 3543 | */ |
| 3544 | - $this->request = apply_filters_ref_array( 'posts_request', array( $this->request, &$this ) ); |
|
| 3544 | + $this->request = apply_filters_ref_array('posts_request', array($this->request, &$this)); |
|
| 3545 | 3545 | } |
| 3546 | 3546 | |
| 3547 | - if ( 'ids' == $q['fields'] ) { |
|
| 3548 | - $this->posts = $wpdb->get_col( $this->request ); |
|
| 3549 | - $this->posts = array_map( 'intval', $this->posts ); |
|
| 3550 | - $this->post_count = count( $this->posts ); |
|
| 3551 | - $this->set_found_posts( $q, $limits ); |
|
| 3547 | + if ('ids' == $q['fields']) { |
|
| 3548 | + $this->posts = $wpdb->get_col($this->request); |
|
| 3549 | + $this->posts = array_map('intval', $this->posts); |
|
| 3550 | + $this->post_count = count($this->posts); |
|
| 3551 | + $this->set_found_posts($q, $limits); |
|
| 3552 | 3552 | |
| 3553 | 3553 | return $this->posts; |
| 3554 | 3554 | } |
| 3555 | 3555 | |
| 3556 | - if ( 'id=>parent' == $q['fields'] ) { |
|
| 3557 | - $this->posts = $wpdb->get_results( $this->request ); |
|
| 3558 | - $this->post_count = count( $this->posts ); |
|
| 3559 | - $this->set_found_posts( $q, $limits ); |
|
| 3556 | + if ('id=>parent' == $q['fields']) { |
|
| 3557 | + $this->posts = $wpdb->get_results($this->request); |
|
| 3558 | + $this->post_count = count($this->posts); |
|
| 3559 | + $this->set_found_posts($q, $limits); |
|
| 3560 | 3560 | |
| 3561 | 3561 | $r = array(); |
| 3562 | - foreach ( $this->posts as $key => $post ) { |
|
| 3563 | - $this->posts[ $key ]->ID = (int) $post->ID; |
|
| 3564 | - $this->posts[ $key ]->post_parent = (int) $post->post_parent; |
|
| 3562 | + foreach ($this->posts as $key => $post) { |
|
| 3563 | + $this->posts[$key]->ID = (int) $post->ID; |
|
| 3564 | + $this->posts[$key]->post_parent = (int) $post->post_parent; |
|
| 3565 | 3565 | |
| 3566 | - $r[ (int) $post->ID ] = (int) $post->post_parent; |
|
| 3566 | + $r[(int) $post->ID] = (int) $post->post_parent; |
|
| 3567 | 3567 | } |
| 3568 | 3568 | |
| 3569 | 3569 | return $r; |
| 3570 | 3570 | } |
| 3571 | 3571 | |
| 3572 | - $split_the_query = ( $old_request == $this->request && "$wpdb->posts.*" == $fields && !empty( $limits ) && $q['posts_per_page'] < 500 ); |
|
| 3572 | + $split_the_query = ($old_request == $this->request && "$wpdb->posts.*" == $fields && ! empty($limits) && $q['posts_per_page'] < 500); |
|
| 3573 | 3573 | |
| 3574 | 3574 | /** |
| 3575 | 3575 | * Filter whether to split the query. |
@@ -3583,9 +3583,9 @@ discard block |
||
| 3583 | 3583 | * @param bool $split_the_query Whether or not to split the query. |
| 3584 | 3584 | * @param WP_Query $this The WP_Query instance. |
| 3585 | 3585 | */ |
| 3586 | - $split_the_query = apply_filters( 'split_the_query', $split_the_query, $this ); |
|
| 3586 | + $split_the_query = apply_filters('split_the_query', $split_the_query, $this); |
|
| 3587 | 3587 | |
| 3588 | - if ( $split_the_query ) { |
|
| 3588 | + if ($split_the_query) { |
|
| 3589 | 3589 | // First get the IDs and then fill in the objects |
| 3590 | 3590 | |
| 3591 | 3591 | $this->request = "SELECT $found_rows $distinct $wpdb->posts.ID FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits"; |
@@ -3598,27 +3598,27 @@ discard block |
||
| 3598 | 3598 | * @param string $request The post ID request. |
| 3599 | 3599 | * @param WP_Query $this The WP_Query instance. |
| 3600 | 3600 | */ |
| 3601 | - $this->request = apply_filters( 'posts_request_ids', $this->request, $this ); |
|
| 3601 | + $this->request = apply_filters('posts_request_ids', $this->request, $this); |
|
| 3602 | 3602 | |
| 3603 | - $ids = $wpdb->get_col( $this->request ); |
|
| 3603 | + $ids = $wpdb->get_col($this->request); |
|
| 3604 | 3604 | |
| 3605 | - if ( $ids ) { |
|
| 3605 | + if ($ids) { |
|
| 3606 | 3606 | $this->posts = $ids; |
| 3607 | - $this->set_found_posts( $q, $limits ); |
|
| 3608 | - _prime_post_caches( $ids, $q['update_post_term_cache'], $q['update_post_meta_cache'] ); |
|
| 3607 | + $this->set_found_posts($q, $limits); |
|
| 3608 | + _prime_post_caches($ids, $q['update_post_term_cache'], $q['update_post_meta_cache']); |
|
| 3609 | 3609 | } else { |
| 3610 | 3610 | $this->posts = array(); |
| 3611 | 3611 | } |
| 3612 | 3612 | } else { |
| 3613 | - $this->posts = $wpdb->get_results( $this->request ); |
|
| 3614 | - $this->set_found_posts( $q, $limits ); |
|
| 3613 | + $this->posts = $wpdb->get_results($this->request); |
|
| 3614 | + $this->set_found_posts($q, $limits); |
|
| 3615 | 3615 | } |
| 3616 | 3616 | |
| 3617 | 3617 | // Convert to WP_Post objects |
| 3618 | - if ( $this->posts ) |
|
| 3619 | - $this->posts = array_map( 'get_post', $this->posts ); |
|
| 3618 | + if ($this->posts) |
|
| 3619 | + $this->posts = array_map('get_post', $this->posts); |
|
| 3620 | 3620 | |
| 3621 | - if ( ! $q['suppress_filters'] ) { |
|
| 3621 | + if ( ! $q['suppress_filters']) { |
|
| 3622 | 3622 | /** |
| 3623 | 3623 | * Filter the raw post results array, prior to status checks. |
| 3624 | 3624 | * |
@@ -3627,38 +3627,38 @@ discard block |
||
| 3627 | 3627 | * @param array $posts The post results array. |
| 3628 | 3628 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3629 | 3629 | */ |
| 3630 | - $this->posts = apply_filters_ref_array( 'posts_results', array( $this->posts, &$this ) ); |
|
| 3630 | + $this->posts = apply_filters_ref_array('posts_results', array($this->posts, &$this)); |
|
| 3631 | 3631 | } |
| 3632 | 3632 | |
| 3633 | - if ( !empty($this->posts) && $this->is_comment_feed && $this->is_singular ) { |
|
| 3633 | + if ( ! empty($this->posts) && $this->is_comment_feed && $this->is_singular) { |
|
| 3634 | 3634 | /** This filter is documented in wp-includes/query.php */ |
| 3635 | - $cjoin = apply_filters_ref_array( 'comment_feed_join', array( '', &$this ) ); |
|
| 3635 | + $cjoin = apply_filters_ref_array('comment_feed_join', array('', &$this)); |
|
| 3636 | 3636 | |
| 3637 | 3637 | /** This filter is documented in wp-includes/query.php */ |
| 3638 | - $cwhere = apply_filters_ref_array( 'comment_feed_where', array( "WHERE comment_post_ID = '{$this->posts[0]->ID}' AND comment_approved = '1'", &$this ) ); |
|
| 3638 | + $cwhere = apply_filters_ref_array('comment_feed_where', array("WHERE comment_post_ID = '{$this->posts[0]->ID}' AND comment_approved = '1'", &$this)); |
|
| 3639 | 3639 | |
| 3640 | 3640 | /** This filter is documented in wp-includes/query.php */ |
| 3641 | - $cgroupby = apply_filters_ref_array( 'comment_feed_groupby', array( '', &$this ) ); |
|
| 3642 | - $cgroupby = ( ! empty( $cgroupby ) ) ? 'GROUP BY ' . $cgroupby : ''; |
|
| 3641 | + $cgroupby = apply_filters_ref_array('comment_feed_groupby', array('', &$this)); |
|
| 3642 | + $cgroupby = ( ! empty($cgroupby)) ? 'GROUP BY '.$cgroupby : ''; |
|
| 3643 | 3643 | |
| 3644 | 3644 | /** This filter is documented in wp-includes/query.php */ |
| 3645 | - $corderby = apply_filters_ref_array( 'comment_feed_orderby', array( 'comment_date_gmt DESC', &$this ) ); |
|
| 3646 | - $corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : ''; |
|
| 3645 | + $corderby = apply_filters_ref_array('comment_feed_orderby', array('comment_date_gmt DESC', &$this)); |
|
| 3646 | + $corderby = ( ! empty($corderby)) ? 'ORDER BY '.$corderby : ''; |
|
| 3647 | 3647 | |
| 3648 | 3648 | /** This filter is documented in wp-includes/query.php */ |
| 3649 | - $climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option('posts_per_rss'), &$this ) ); |
|
| 3649 | + $climits = apply_filters_ref_array('comment_feed_limits', array('LIMIT '.get_option('posts_per_rss'), &$this)); |
|
| 3650 | 3650 | |
| 3651 | 3651 | $comments_request = "SELECT $wpdb->comments.* FROM $wpdb->comments $cjoin $cwhere $cgroupby $corderby $climits"; |
| 3652 | 3652 | $comments = $wpdb->get_results($comments_request); |
| 3653 | 3653 | // Convert to WP_Comment |
| 3654 | - $this->comments = array_map( 'get_comment', $comments ); |
|
| 3654 | + $this->comments = array_map('get_comment', $comments); |
|
| 3655 | 3655 | $this->comment_count = count($this->comments); |
| 3656 | 3656 | } |
| 3657 | 3657 | |
| 3658 | 3658 | // Check post status to determine if post should be displayed. |
| 3659 | - if ( !empty($this->posts) && ($this->is_single || $this->is_page) ) { |
|
| 3659 | + if ( ! empty($this->posts) && ($this->is_single || $this->is_page)) { |
|
| 3660 | 3660 | $status = get_post_status($this->posts[0]); |
| 3661 | - if ( 'attachment' === $this->posts[0]->post_type && 0 === (int) $this->posts[0]->post_parent ) { |
|
| 3661 | + if ('attachment' === $this->posts[0]->post_type && 0 === (int) $this->posts[0]->post_parent) { |
|
| 3662 | 3662 | $this->is_page = false; |
| 3663 | 3663 | $this->is_single = true; |
| 3664 | 3664 | $this->is_attachment = true; |
@@ -3666,23 +3666,23 @@ discard block |
||
| 3666 | 3666 | $post_status_obj = get_post_status_object($status); |
| 3667 | 3667 | |
| 3668 | 3668 | // If the post_status was specifically requested, let it pass through. |
| 3669 | - if ( !$post_status_obj->public && ! in_array( $status, $q_status ) ) { |
|
| 3669 | + if ( ! $post_status_obj->public && ! in_array($status, $q_status)) { |
|
| 3670 | 3670 | |
| 3671 | - if ( ! is_user_logged_in() ) { |
|
| 3671 | + if ( ! is_user_logged_in()) { |
|
| 3672 | 3672 | // User must be logged in to view unpublished posts. |
| 3673 | 3673 | $this->posts = array(); |
| 3674 | 3674 | } else { |
| 3675 | - if ( $post_status_obj->protected ) { |
|
| 3675 | + if ($post_status_obj->protected) { |
|
| 3676 | 3676 | // User must have edit permissions on the draft to preview. |
| 3677 | - if ( ! current_user_can($edit_cap, $this->posts[0]->ID) ) { |
|
| 3677 | + if ( ! current_user_can($edit_cap, $this->posts[0]->ID)) { |
|
| 3678 | 3678 | $this->posts = array(); |
| 3679 | 3679 | } else { |
| 3680 | 3680 | $this->is_preview = true; |
| 3681 | - if ( 'future' != $status ) |
|
| 3681 | + if ('future' != $status) |
|
| 3682 | 3682 | $this->posts[0]->post_date = current_time('mysql'); |
| 3683 | 3683 | } |
| 3684 | - } elseif ( $post_status_obj->private ) { |
|
| 3685 | - if ( ! current_user_can($read_cap, $this->posts[0]->ID) ) |
|
| 3684 | + } elseif ($post_status_obj->private) { |
|
| 3685 | + if ( ! current_user_can($read_cap, $this->posts[0]->ID)) |
|
| 3686 | 3686 | $this->posts = array(); |
| 3687 | 3687 | } else { |
| 3688 | 3688 | $this->posts = array(); |
@@ -3690,7 +3690,7 @@ discard block |
||
| 3690 | 3690 | } |
| 3691 | 3691 | } |
| 3692 | 3692 | |
| 3693 | - if ( $this->is_preview && $this->posts && current_user_can( $edit_cap, $this->posts[0]->ID ) ) { |
|
| 3693 | + if ($this->is_preview && $this->posts && current_user_can($edit_cap, $this->posts[0]->ID)) { |
|
| 3694 | 3694 | /** |
| 3695 | 3695 | * Filter the single post for preview mode. |
| 3696 | 3696 | * |
@@ -3699,18 +3699,18 @@ discard block |
||
| 3699 | 3699 | * @param WP_Post $post_preview The Post object. |
| 3700 | 3700 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3701 | 3701 | */ |
| 3702 | - $this->posts[0] = get_post( apply_filters_ref_array( 'the_preview', array( $this->posts[0], &$this ) ) ); |
|
| 3702 | + $this->posts[0] = get_post(apply_filters_ref_array('the_preview', array($this->posts[0], &$this))); |
|
| 3703 | 3703 | } |
| 3704 | 3704 | } |
| 3705 | 3705 | |
| 3706 | 3706 | // Put sticky posts at the top of the posts array |
| 3707 | 3707 | $sticky_posts = get_option('sticky_posts'); |
| 3708 | - if ( $this->is_home && $page <= 1 && is_array($sticky_posts) && !empty($sticky_posts) && !$q['ignore_sticky_posts'] ) { |
|
| 3708 | + if ($this->is_home && $page <= 1 && is_array($sticky_posts) && ! empty($sticky_posts) && ! $q['ignore_sticky_posts']) { |
|
| 3709 | 3709 | $num_posts = count($this->posts); |
| 3710 | 3710 | $sticky_offset = 0; |
| 3711 | 3711 | // Loop over posts and relocate stickies to the front. |
| 3712 | - for ( $i = 0; $i < $num_posts; $i++ ) { |
|
| 3713 | - if ( in_array($this->posts[$i]->ID, $sticky_posts) ) { |
|
| 3712 | + for ($i = 0; $i < $num_posts; $i++) { |
|
| 3713 | + if (in_array($this->posts[$i]->ID, $sticky_posts)) { |
|
| 3714 | 3714 | $sticky_post = $this->posts[$i]; |
| 3715 | 3715 | // Remove sticky from current position |
| 3716 | 3716 | array_splice($this->posts, $i, 1); |
@@ -3720,36 +3720,36 @@ discard block |
||
| 3720 | 3720 | $sticky_offset++; |
| 3721 | 3721 | // Remove post from sticky posts array |
| 3722 | 3722 | $offset = array_search($sticky_post->ID, $sticky_posts); |
| 3723 | - unset( $sticky_posts[$offset] ); |
|
| 3723 | + unset($sticky_posts[$offset]); |
|
| 3724 | 3724 | } |
| 3725 | 3725 | } |
| 3726 | 3726 | |
| 3727 | 3727 | // If any posts have been excluded specifically, Ignore those that are sticky. |
| 3728 | - if ( !empty($sticky_posts) && !empty($q['post__not_in']) ) |
|
| 3728 | + if ( ! empty($sticky_posts) && ! empty($q['post__not_in'])) |
|
| 3729 | 3729 | $sticky_posts = array_diff($sticky_posts, $q['post__not_in']); |
| 3730 | 3730 | |
| 3731 | 3731 | // Fetch sticky posts that weren't in the query results |
| 3732 | - if ( !empty($sticky_posts) ) { |
|
| 3733 | - $stickies = get_posts( array( |
|
| 3732 | + if ( ! empty($sticky_posts)) { |
|
| 3733 | + $stickies = get_posts(array( |
|
| 3734 | 3734 | 'post__in' => $sticky_posts, |
| 3735 | 3735 | 'post_type' => $post_type, |
| 3736 | 3736 | 'post_status' => 'publish', |
| 3737 | 3737 | 'nopaging' => true |
| 3738 | - ) ); |
|
| 3738 | + )); |
|
| 3739 | 3739 | |
| 3740 | - foreach ( $stickies as $sticky_post ) { |
|
| 3741 | - array_splice( $this->posts, $sticky_offset, 0, array( $sticky_post ) ); |
|
| 3740 | + foreach ($stickies as $sticky_post) { |
|
| 3741 | + array_splice($this->posts, $sticky_offset, 0, array($sticky_post)); |
|
| 3742 | 3742 | $sticky_offset++; |
| 3743 | 3743 | } |
| 3744 | 3744 | } |
| 3745 | 3745 | } |
| 3746 | 3746 | |
| 3747 | 3747 | // If comments have been fetched as part of the query, make sure comment meta lazy-loading is set up. |
| 3748 | - if ( ! empty( $this->comments ) ) { |
|
| 3749 | - wp_queue_comments_for_comment_meta_lazyload( $this->comments ); |
|
| 3748 | + if ( ! empty($this->comments)) { |
|
| 3749 | + wp_queue_comments_for_comment_meta_lazyload($this->comments); |
|
| 3750 | 3750 | } |
| 3751 | 3751 | |
| 3752 | - if ( ! $q['suppress_filters'] ) { |
|
| 3752 | + if ( ! $q['suppress_filters']) { |
|
| 3753 | 3753 | /** |
| 3754 | 3754 | * Filter the array of retrieved posts after they've been fetched and |
| 3755 | 3755 | * internally processed. |
@@ -3759,27 +3759,27 @@ discard block |
||
| 3759 | 3759 | * @param array $posts The array of retrieved posts. |
| 3760 | 3760 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3761 | 3761 | */ |
| 3762 | - $this->posts = apply_filters_ref_array( 'the_posts', array( $this->posts, &$this ) ); |
|
| 3762 | + $this->posts = apply_filters_ref_array('the_posts', array($this->posts, &$this)); |
|
| 3763 | 3763 | } |
| 3764 | 3764 | |
| 3765 | 3765 | // Ensure that any posts added/modified via one of the filters above are |
| 3766 | 3766 | // of the type WP_Post and are filtered. |
| 3767 | - if ( $this->posts ) { |
|
| 3768 | - $this->post_count = count( $this->posts ); |
|
| 3767 | + if ($this->posts) { |
|
| 3768 | + $this->post_count = count($this->posts); |
|
| 3769 | 3769 | |
| 3770 | - $this->posts = array_map( 'get_post', $this->posts ); |
|
| 3770 | + $this->posts = array_map('get_post', $this->posts); |
|
| 3771 | 3771 | |
| 3772 | - if ( $q['cache_results'] ) |
|
| 3772 | + if ($q['cache_results']) |
|
| 3773 | 3773 | update_post_caches($this->posts, $post_type, $q['update_post_term_cache'], $q['update_post_meta_cache']); |
| 3774 | 3774 | |
| 3775 | - $this->post = reset( $this->posts ); |
|
| 3775 | + $this->post = reset($this->posts); |
|
| 3776 | 3776 | } else { |
| 3777 | 3777 | $this->post_count = 0; |
| 3778 | 3778 | $this->posts = array(); |
| 3779 | 3779 | } |
| 3780 | 3780 | |
| 3781 | - if ( $q['update_post_term_cache'] ) { |
|
| 3782 | - wp_queue_posts_for_term_meta_lazyload( $this->posts ); |
|
| 3781 | + if ($q['update_post_term_cache']) { |
|
| 3782 | + wp_queue_posts_for_term_meta_lazyload($this->posts); |
|
| 3783 | 3783 | } |
| 3784 | 3784 | |
| 3785 | 3785 | return $this->posts; |
@@ -3797,15 +3797,15 @@ discard block |
||
| 3797 | 3797 | * @param array $q Query variables. |
| 3798 | 3798 | * @param string $limits LIMIT clauses of the query. |
| 3799 | 3799 | */ |
| 3800 | - private function set_found_posts( $q, $limits ) { |
|
| 3800 | + private function set_found_posts($q, $limits) { |
|
| 3801 | 3801 | global $wpdb; |
| 3802 | 3802 | |
| 3803 | 3803 | // Bail if posts is an empty array. Continue if posts is an empty string, |
| 3804 | 3804 | // null, or false to accommodate caching plugins that fill posts later. |
| 3805 | - if ( $q['no_found_rows'] || ( is_array( $this->posts ) && ! $this->posts ) ) |
|
| 3805 | + if ($q['no_found_rows'] || (is_array($this->posts) && ! $this->posts)) |
|
| 3806 | 3806 | return; |
| 3807 | 3807 | |
| 3808 | - if ( ! empty( $limits ) ) { |
|
| 3808 | + if ( ! empty($limits)) { |
|
| 3809 | 3809 | /** |
| 3810 | 3810 | * Filter the query to run for retrieving the found posts. |
| 3811 | 3811 | * |
@@ -3814,9 +3814,9 @@ discard block |
||
| 3814 | 3814 | * @param string $found_posts The query to run to find the found posts. |
| 3815 | 3815 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3816 | 3816 | */ |
| 3817 | - $this->found_posts = $wpdb->get_var( apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ) ); |
|
| 3817 | + $this->found_posts = $wpdb->get_var(apply_filters_ref_array('found_posts_query', array('SELECT FOUND_ROWS()', &$this))); |
|
| 3818 | 3818 | } else { |
| 3819 | - $this->found_posts = count( $this->posts ); |
|
| 3819 | + $this->found_posts = count($this->posts); |
|
| 3820 | 3820 | } |
| 3821 | 3821 | |
| 3822 | 3822 | /** |
@@ -3827,10 +3827,10 @@ discard block |
||
| 3827 | 3827 | * @param int $found_posts The number of posts found. |
| 3828 | 3828 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3829 | 3829 | */ |
| 3830 | - $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) ); |
|
| 3830 | + $this->found_posts = apply_filters_ref_array('found_posts', array($this->found_posts, &$this)); |
|
| 3831 | 3831 | |
| 3832 | - if ( ! empty( $limits ) ) |
|
| 3833 | - $this->max_num_pages = ceil( $this->found_posts / $q['posts_per_page'] ); |
|
| 3832 | + if ( ! empty($limits)) |
|
| 3833 | + $this->max_num_pages = ceil($this->found_posts / $q['posts_per_page']); |
|
| 3834 | 3834 | } |
| 3835 | 3835 | |
| 3836 | 3836 | /** |
@@ -3864,7 +3864,7 @@ discard block |
||
| 3864 | 3864 | global $post; |
| 3865 | 3865 | $this->in_the_loop = true; |
| 3866 | 3866 | |
| 3867 | - if ( $this->current_post == -1 ) // loop has just started |
|
| 3867 | + if ($this->current_post == -1) // loop has just started |
|
| 3868 | 3868 | /** |
| 3869 | 3869 | * Fires once the loop is started. |
| 3870 | 3870 | * |
@@ -3872,10 +3872,10 @@ discard block |
||
| 3872 | 3872 | * |
| 3873 | 3873 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3874 | 3874 | */ |
| 3875 | - do_action_ref_array( 'loop_start', array( &$this ) ); |
|
| 3875 | + do_action_ref_array('loop_start', array(&$this)); |
|
| 3876 | 3876 | |
| 3877 | 3877 | $post = $this->next_post(); |
| 3878 | - $this->setup_postdata( $post ); |
|
| 3878 | + $this->setup_postdata($post); |
|
| 3879 | 3879 | } |
| 3880 | 3880 | |
| 3881 | 3881 | /** |
@@ -3889,9 +3889,9 @@ discard block |
||
| 3889 | 3889 | * @return bool True if posts are available, false if end of loop. |
| 3890 | 3890 | */ |
| 3891 | 3891 | public function have_posts() { |
| 3892 | - if ( $this->current_post + 1 < $this->post_count ) { |
|
| 3892 | + if ($this->current_post + 1 < $this->post_count) { |
|
| 3893 | 3893 | return true; |
| 3894 | - } elseif ( $this->current_post + 1 == $this->post_count && $this->post_count > 0 ) { |
|
| 3894 | + } elseif ($this->current_post + 1 == $this->post_count && $this->post_count > 0) { |
|
| 3895 | 3895 | /** |
| 3896 | 3896 | * Fires once the loop has ended. |
| 3897 | 3897 | * |
@@ -3899,7 +3899,7 @@ discard block |
||
| 3899 | 3899 | * |
| 3900 | 3900 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3901 | 3901 | */ |
| 3902 | - do_action_ref_array( 'loop_end', array( &$this ) ); |
|
| 3902 | + do_action_ref_array('loop_end', array(&$this)); |
|
| 3903 | 3903 | // Do some cleaning up after the loop |
| 3904 | 3904 | $this->rewind_posts(); |
| 3905 | 3905 | } |
@@ -3916,7 +3916,7 @@ discard block |
||
| 3916 | 3916 | */ |
| 3917 | 3917 | public function rewind_posts() { |
| 3918 | 3918 | $this->current_post = -1; |
| 3919 | - if ( $this->post_count > 0 ) { |
|
| 3919 | + if ($this->post_count > 0) { |
|
| 3920 | 3920 | $this->post = $this->posts[0]; |
| 3921 | 3921 | } |
| 3922 | 3922 | } |
@@ -3948,13 +3948,13 @@ discard block |
||
| 3948 | 3948 | |
| 3949 | 3949 | $comment = $this->next_comment(); |
| 3950 | 3950 | |
| 3951 | - if ( $this->current_comment == 0 ) { |
|
| 3951 | + if ($this->current_comment == 0) { |
|
| 3952 | 3952 | /** |
| 3953 | 3953 | * Fires once the comment loop is started. |
| 3954 | 3954 | * |
| 3955 | 3955 | * @since 2.2.0 |
| 3956 | 3956 | */ |
| 3957 | - do_action( 'comment_loop_start' ); |
|
| 3957 | + do_action('comment_loop_start'); |
|
| 3958 | 3958 | } |
| 3959 | 3959 | } |
| 3960 | 3960 | |
@@ -3969,9 +3969,9 @@ discard block |
||
| 3969 | 3969 | * @return bool True, if more comments. False, if no more posts. |
| 3970 | 3970 | */ |
| 3971 | 3971 | public function have_comments() { |
| 3972 | - if ( $this->current_comment + 1 < $this->comment_count ) { |
|
| 3972 | + if ($this->current_comment + 1 < $this->comment_count) { |
|
| 3973 | 3973 | return true; |
| 3974 | - } elseif ( $this->current_comment + 1 == $this->comment_count ) { |
|
| 3974 | + } elseif ($this->current_comment + 1 == $this->comment_count) { |
|
| 3975 | 3975 | $this->rewind_comments(); |
| 3976 | 3976 | } |
| 3977 | 3977 | |
@@ -3986,7 +3986,7 @@ discard block |
||
| 3986 | 3986 | */ |
| 3987 | 3987 | public function rewind_comments() { |
| 3988 | 3988 | $this->current_comment = -1; |
| 3989 | - if ( $this->comment_count > 0 ) { |
|
| 3989 | + if ($this->comment_count > 0) { |
|
| 3990 | 3990 | $this->comment = $this->comments[0]; |
| 3991 | 3991 | } |
| 3992 | 3992 | } |
@@ -4000,9 +4000,9 @@ discard block |
||
| 4000 | 4000 | * @param string $query URL query string. |
| 4001 | 4001 | * @return array List of posts. |
| 4002 | 4002 | */ |
| 4003 | - public function query( $query ) { |
|
| 4003 | + public function query($query) { |
|
| 4004 | 4004 | $this->init(); |
| 4005 | - $this->query = $this->query_vars = wp_parse_args( $query ); |
|
| 4005 | + $this->query = $this->query_vars = wp_parse_args($query); |
|
| 4006 | 4006 | return $this->get_posts(); |
| 4007 | 4007 | } |
| 4008 | 4008 | |
@@ -4019,66 +4019,66 @@ discard block |
||
| 4019 | 4019 | * @return object |
| 4020 | 4020 | */ |
| 4021 | 4021 | public function get_queried_object() { |
| 4022 | - if ( isset($this->queried_object) ) |
|
| 4022 | + if (isset($this->queried_object)) |
|
| 4023 | 4023 | return $this->queried_object; |
| 4024 | 4024 | |
| 4025 | 4025 | $this->queried_object = null; |
| 4026 | 4026 | $this->queried_object_id = null; |
| 4027 | 4027 | |
| 4028 | - if ( $this->is_category || $this->is_tag || $this->is_tax ) { |
|
| 4029 | - if ( $this->is_category ) { |
|
| 4030 | - if ( $this->get( 'cat' ) ) { |
|
| 4031 | - $term = get_term( $this->get( 'cat' ), 'category' ); |
|
| 4032 | - } elseif ( $this->get( 'category_name' ) ) { |
|
| 4033 | - $term = get_term_by( 'slug', $this->get( 'category_name' ), 'category' ); |
|
| 4028 | + if ($this->is_category || $this->is_tag || $this->is_tax) { |
|
| 4029 | + if ($this->is_category) { |
|
| 4030 | + if ($this->get('cat')) { |
|
| 4031 | + $term = get_term($this->get('cat'), 'category'); |
|
| 4032 | + } elseif ($this->get('category_name')) { |
|
| 4033 | + $term = get_term_by('slug', $this->get('category_name'), 'category'); |
|
| 4034 | 4034 | } |
| 4035 | - } elseif ( $this->is_tag ) { |
|
| 4036 | - if ( $this->get( 'tag_id' ) ) { |
|
| 4037 | - $term = get_term( $this->get( 'tag_id' ), 'post_tag' ); |
|
| 4038 | - } elseif ( $this->get( 'tag' ) ) { |
|
| 4039 | - $term = get_term_by( 'slug', $this->get( 'tag' ), 'post_tag' ); |
|
| 4035 | + } elseif ($this->is_tag) { |
|
| 4036 | + if ($this->get('tag_id')) { |
|
| 4037 | + $term = get_term($this->get('tag_id'), 'post_tag'); |
|
| 4038 | + } elseif ($this->get('tag')) { |
|
| 4039 | + $term = get_term_by('slug', $this->get('tag'), 'post_tag'); |
|
| 4040 | 4040 | } |
| 4041 | 4041 | } else { |
| 4042 | 4042 | // For other tax queries, grab the first term from the first clause. |
| 4043 | - $tax_query_in_and = wp_list_filter( $this->tax_query->queried_terms, array( 'operator' => 'NOT IN' ), 'NOT' ); |
|
| 4043 | + $tax_query_in_and = wp_list_filter($this->tax_query->queried_terms, array('operator' => 'NOT IN'), 'NOT'); |
|
| 4044 | 4044 | |
| 4045 | - if ( ! empty( $tax_query_in_and ) ) { |
|
| 4046 | - $queried_taxonomies = array_keys( $tax_query_in_and ); |
|
| 4047 | - $matched_taxonomy = reset( $queried_taxonomies ); |
|
| 4048 | - $query = $tax_query_in_and[ $matched_taxonomy ]; |
|
| 4045 | + if ( ! empty($tax_query_in_and)) { |
|
| 4046 | + $queried_taxonomies = array_keys($tax_query_in_and); |
|
| 4047 | + $matched_taxonomy = reset($queried_taxonomies); |
|
| 4048 | + $query = $tax_query_in_and[$matched_taxonomy]; |
|
| 4049 | 4049 | |
| 4050 | - if ( $query['terms'] ) { |
|
| 4051 | - if ( 'term_id' == $query['field'] ) { |
|
| 4052 | - $term = get_term( reset( $query['terms'] ), $matched_taxonomy ); |
|
| 4050 | + if ($query['terms']) { |
|
| 4051 | + if ('term_id' == $query['field']) { |
|
| 4052 | + $term = get_term(reset($query['terms']), $matched_taxonomy); |
|
| 4053 | 4053 | } else { |
| 4054 | - $term = get_term_by( $query['field'], reset( $query['terms'] ), $matched_taxonomy ); |
|
| 4054 | + $term = get_term_by($query['field'], reset($query['terms']), $matched_taxonomy); |
|
| 4055 | 4055 | } |
| 4056 | 4056 | } |
| 4057 | 4057 | } |
| 4058 | 4058 | } |
| 4059 | 4059 | |
| 4060 | - if ( ! empty( $term ) && ! is_wp_error( $term ) ) { |
|
| 4060 | + if ( ! empty($term) && ! is_wp_error($term)) { |
|
| 4061 | 4061 | $this->queried_object = $term; |
| 4062 | 4062 | $this->queried_object_id = (int) $term->term_id; |
| 4063 | 4063 | |
| 4064 | - if ( $this->is_category && 'category' === $this->queried_object->taxonomy ) |
|
| 4065 | - _make_cat_compat( $this->queried_object ); |
|
| 4064 | + if ($this->is_category && 'category' === $this->queried_object->taxonomy) |
|
| 4065 | + _make_cat_compat($this->queried_object); |
|
| 4066 | 4066 | } |
| 4067 | - } elseif ( $this->is_post_type_archive ) { |
|
| 4068 | - $post_type = $this->get( 'post_type' ); |
|
| 4069 | - if ( is_array( $post_type ) ) |
|
| 4070 | - $post_type = reset( $post_type ); |
|
| 4071 | - $this->queried_object = get_post_type_object( $post_type ); |
|
| 4072 | - } elseif ( $this->is_posts_page ) { |
|
| 4067 | + } elseif ($this->is_post_type_archive) { |
|
| 4068 | + $post_type = $this->get('post_type'); |
|
| 4069 | + if (is_array($post_type)) |
|
| 4070 | + $post_type = reset($post_type); |
|
| 4071 | + $this->queried_object = get_post_type_object($post_type); |
|
| 4072 | + } elseif ($this->is_posts_page) { |
|
| 4073 | 4073 | $page_for_posts = get_option('page_for_posts'); |
| 4074 | - $this->queried_object = get_post( $page_for_posts ); |
|
| 4074 | + $this->queried_object = get_post($page_for_posts); |
|
| 4075 | 4075 | $this->queried_object_id = (int) $this->queried_object->ID; |
| 4076 | - } elseif ( $this->is_singular && ! empty( $this->post ) ) { |
|
| 4076 | + } elseif ($this->is_singular && ! empty($this->post)) { |
|
| 4077 | 4077 | $this->queried_object = $this->post; |
| 4078 | 4078 | $this->queried_object_id = (int) $this->post->ID; |
| 4079 | - } elseif ( $this->is_author ) { |
|
| 4079 | + } elseif ($this->is_author) { |
|
| 4080 | 4080 | $this->queried_object_id = (int) $this->get('author'); |
| 4081 | - $this->queried_object = get_userdata( $this->queried_object_id ); |
|
| 4081 | + $this->queried_object = get_userdata($this->queried_object_id); |
|
| 4082 | 4082 | } |
| 4083 | 4083 | |
| 4084 | 4084 | return $this->queried_object; |
@@ -4095,7 +4095,7 @@ discard block |
||
| 4095 | 4095 | public function get_queried_object_id() { |
| 4096 | 4096 | $this->get_queried_object(); |
| 4097 | 4097 | |
| 4098 | - if ( isset($this->queried_object_id) ) { |
|
| 4098 | + if (isset($this->queried_object_id)) { |
|
| 4099 | 4099 | return $this->queried_object_id; |
| 4100 | 4100 | } |
| 4101 | 4101 | |
@@ -4113,7 +4113,7 @@ discard block |
||
| 4113 | 4113 | * @param string|array $query URL query string or array of vars. |
| 4114 | 4114 | */ |
| 4115 | 4115 | public function __construct($query = '') { |
| 4116 | - if ( ! empty($query) ) { |
|
| 4116 | + if ( ! empty($query)) { |
|
| 4117 | 4117 | $this->query($query); |
| 4118 | 4118 | } |
| 4119 | 4119 | } |
@@ -4127,8 +4127,8 @@ discard block |
||
| 4127 | 4127 | * @param string $name Property to get. |
| 4128 | 4128 | * @return mixed Property. |
| 4129 | 4129 | */ |
| 4130 | - public function __get( $name ) { |
|
| 4131 | - if ( in_array( $name, $this->compat_fields ) ) { |
|
| 4130 | + public function __get($name) { |
|
| 4131 | + if (in_array($name, $this->compat_fields)) { |
|
| 4132 | 4132 | return $this->$name; |
| 4133 | 4133 | } |
| 4134 | 4134 | } |
@@ -4142,9 +4142,9 @@ discard block |
||
| 4142 | 4142 | * @param string $name Property to check if set. |
| 4143 | 4143 | * @return bool Whether the property is set. |
| 4144 | 4144 | */ |
| 4145 | - public function __isset( $name ) { |
|
| 4146 | - if ( in_array( $name, $this->compat_fields ) ) { |
|
| 4147 | - return isset( $this->$name ); |
|
| 4145 | + public function __isset($name) { |
|
| 4146 | + if (in_array($name, $this->compat_fields)) { |
|
| 4147 | + return isset($this->$name); |
|
| 4148 | 4148 | } |
| 4149 | 4149 | } |
| 4150 | 4150 | |
@@ -4158,9 +4158,9 @@ discard block |
||
| 4158 | 4158 | * @param array $arguments Arguments to pass when calling. |
| 4159 | 4159 | * @return mixed|false Return value of the callback, false otherwise. |
| 4160 | 4160 | */ |
| 4161 | - public function __call( $name, $arguments ) { |
|
| 4162 | - if ( in_array( $name, $this->compat_methods ) ) { |
|
| 4163 | - return call_user_func_array( array( $this, $name ), $arguments ); |
|
| 4161 | + public function __call($name, $arguments) { |
|
| 4162 | + if (in_array($name, $this->compat_methods)) { |
|
| 4163 | + return call_user_func_array(array($this, $name), $arguments); |
|
| 4164 | 4164 | } |
| 4165 | 4165 | return false; |
| 4166 | 4166 | } |
@@ -4186,16 +4186,16 @@ discard block |
||
| 4186 | 4186 | * @param mixed $post_types Optional. Post type or array of posts types to check against. |
| 4187 | 4187 | * @return bool |
| 4188 | 4188 | */ |
| 4189 | - public function is_post_type_archive( $post_types = '' ) { |
|
| 4190 | - if ( empty( $post_types ) || ! $this->is_post_type_archive ) |
|
| 4189 | + public function is_post_type_archive($post_types = '') { |
|
| 4190 | + if (empty($post_types) || ! $this->is_post_type_archive) |
|
| 4191 | 4191 | return (bool) $this->is_post_type_archive; |
| 4192 | 4192 | |
| 4193 | - $post_type = $this->get( 'post_type' ); |
|
| 4194 | - if ( is_array( $post_type ) ) |
|
| 4195 | - $post_type = reset( $post_type ); |
|
| 4196 | - $post_type_object = get_post_type_object( $post_type ); |
|
| 4193 | + $post_type = $this->get('post_type'); |
|
| 4194 | + if (is_array($post_type)) |
|
| 4195 | + $post_type = reset($post_type); |
|
| 4196 | + $post_type_object = get_post_type_object($post_type); |
|
| 4197 | 4197 | |
| 4198 | - return in_array( $post_type_object->name, (array) $post_types ); |
|
| 4198 | + return in_array($post_type_object->name, (array) $post_types); |
|
| 4199 | 4199 | } |
| 4200 | 4200 | |
| 4201 | 4201 | /** |
@@ -4206,24 +4206,24 @@ discard block |
||
| 4206 | 4206 | * @param mixed $attachment Attachment ID, title, slug, or array of such. |
| 4207 | 4207 | * @return bool |
| 4208 | 4208 | */ |
| 4209 | - public function is_attachment( $attachment = '' ) { |
|
| 4210 | - if ( ! $this->is_attachment ) { |
|
| 4209 | + public function is_attachment($attachment = '') { |
|
| 4210 | + if ( ! $this->is_attachment) { |
|
| 4211 | 4211 | return false; |
| 4212 | 4212 | } |
| 4213 | 4213 | |
| 4214 | - if ( empty( $attachment ) ) { |
|
| 4214 | + if (empty($attachment)) { |
|
| 4215 | 4215 | return true; |
| 4216 | 4216 | } |
| 4217 | 4217 | |
| 4218 | - $attachment = array_map( 'strval', (array) $attachment ); |
|
| 4218 | + $attachment = array_map('strval', (array) $attachment); |
|
| 4219 | 4219 | |
| 4220 | 4220 | $post_obj = $this->get_queried_object(); |
| 4221 | 4221 | |
| 4222 | - if ( in_array( (string) $post_obj->ID, $attachment ) ) { |
|
| 4222 | + if (in_array((string) $post_obj->ID, $attachment)) { |
|
| 4223 | 4223 | return true; |
| 4224 | - } elseif ( in_array( $post_obj->post_title, $attachment ) ) { |
|
| 4224 | + } elseif (in_array($post_obj->post_title, $attachment)) { |
|
| 4225 | 4225 | return true; |
| 4226 | - } elseif ( in_array( $post_obj->post_name, $attachment ) ) { |
|
| 4226 | + } elseif (in_array($post_obj->post_name, $attachment)) { |
|
| 4227 | 4227 | return true; |
| 4228 | 4228 | } |
| 4229 | 4229 | return false; |
@@ -4240,22 +4240,22 @@ discard block |
||
| 4240 | 4240 | * @param mixed $author Optional. User ID, nickname, nicename, or array of User IDs, nicknames, and nicenames |
| 4241 | 4241 | * @return bool |
| 4242 | 4242 | */ |
| 4243 | - public function is_author( $author = '' ) { |
|
| 4244 | - if ( !$this->is_author ) |
|
| 4243 | + public function is_author($author = '') { |
|
| 4244 | + if ( ! $this->is_author) |
|
| 4245 | 4245 | return false; |
| 4246 | 4246 | |
| 4247 | - if ( empty($author) ) |
|
| 4247 | + if (empty($author)) |
|
| 4248 | 4248 | return true; |
| 4249 | 4249 | |
| 4250 | 4250 | $author_obj = $this->get_queried_object(); |
| 4251 | 4251 | |
| 4252 | - $author = array_map( 'strval', (array) $author ); |
|
| 4252 | + $author = array_map('strval', (array) $author); |
|
| 4253 | 4253 | |
| 4254 | - if ( in_array( (string) $author_obj->ID, $author ) ) |
|
| 4254 | + if (in_array((string) $author_obj->ID, $author)) |
|
| 4255 | 4255 | return true; |
| 4256 | - elseif ( in_array( $author_obj->nickname, $author ) ) |
|
| 4256 | + elseif (in_array($author_obj->nickname, $author)) |
|
| 4257 | 4257 | return true; |
| 4258 | - elseif ( in_array( $author_obj->user_nicename, $author ) ) |
|
| 4258 | + elseif (in_array($author_obj->user_nicename, $author)) |
|
| 4259 | 4259 | return true; |
| 4260 | 4260 | |
| 4261 | 4261 | return false; |
@@ -4272,22 +4272,22 @@ discard block |
||
| 4272 | 4272 | * @param mixed $category Optional. Category ID, name, slug, or array of Category IDs, names, and slugs. |
| 4273 | 4273 | * @return bool |
| 4274 | 4274 | */ |
| 4275 | - public function is_category( $category = '' ) { |
|
| 4276 | - if ( !$this->is_category ) |
|
| 4275 | + public function is_category($category = '') { |
|
| 4276 | + if ( ! $this->is_category) |
|
| 4277 | 4277 | return false; |
| 4278 | 4278 | |
| 4279 | - if ( empty($category) ) |
|
| 4279 | + if (empty($category)) |
|
| 4280 | 4280 | return true; |
| 4281 | 4281 | |
| 4282 | 4282 | $cat_obj = $this->get_queried_object(); |
| 4283 | 4283 | |
| 4284 | - $category = array_map( 'strval', (array) $category ); |
|
| 4284 | + $category = array_map('strval', (array) $category); |
|
| 4285 | 4285 | |
| 4286 | - if ( in_array( (string) $cat_obj->term_id, $category ) ) |
|
| 4286 | + if (in_array((string) $cat_obj->term_id, $category)) |
|
| 4287 | 4287 | return true; |
| 4288 | - elseif ( in_array( $cat_obj->name, $category ) ) |
|
| 4288 | + elseif (in_array($cat_obj->name, $category)) |
|
| 4289 | 4289 | return true; |
| 4290 | - elseif ( in_array( $cat_obj->slug, $category ) ) |
|
| 4290 | + elseif (in_array($cat_obj->slug, $category)) |
|
| 4291 | 4291 | return true; |
| 4292 | 4292 | |
| 4293 | 4293 | return false; |
@@ -4304,22 +4304,22 @@ discard block |
||
| 4304 | 4304 | * @param mixed $tag Optional. Tag ID, name, slug, or array of Tag IDs, names, and slugs. |
| 4305 | 4305 | * @return bool |
| 4306 | 4306 | */ |
| 4307 | - public function is_tag( $tag = '' ) { |
|
| 4308 | - if ( ! $this->is_tag ) |
|
| 4307 | + public function is_tag($tag = '') { |
|
| 4308 | + if ( ! $this->is_tag) |
|
| 4309 | 4309 | return false; |
| 4310 | 4310 | |
| 4311 | - if ( empty( $tag ) ) |
|
| 4311 | + if (empty($tag)) |
|
| 4312 | 4312 | return true; |
| 4313 | 4313 | |
| 4314 | 4314 | $tag_obj = $this->get_queried_object(); |
| 4315 | 4315 | |
| 4316 | - $tag = array_map( 'strval', (array) $tag ); |
|
| 4316 | + $tag = array_map('strval', (array) $tag); |
|
| 4317 | 4317 | |
| 4318 | - if ( in_array( (string) $tag_obj->term_id, $tag ) ) |
|
| 4318 | + if (in_array((string) $tag_obj->term_id, $tag)) |
|
| 4319 | 4319 | return true; |
| 4320 | - elseif ( in_array( $tag_obj->name, $tag ) ) |
|
| 4320 | + elseif (in_array($tag_obj->name, $tag)) |
|
| 4321 | 4321 | return true; |
| 4322 | - elseif ( in_array( $tag_obj->slug, $tag ) ) |
|
| 4322 | + elseif (in_array($tag_obj->slug, $tag)) |
|
| 4323 | 4323 | return true; |
| 4324 | 4324 | |
| 4325 | 4325 | return false; |
@@ -4343,32 +4343,32 @@ discard block |
||
| 4343 | 4343 | * @param mixed $term Optional. Term ID, name, slug or array of Term IDs, names, and slugs. |
| 4344 | 4344 | * @return bool |
| 4345 | 4345 | */ |
| 4346 | - public function is_tax( $taxonomy = '', $term = '' ) { |
|
| 4346 | + public function is_tax($taxonomy = '', $term = '') { |
|
| 4347 | 4347 | global $wp_taxonomies; |
| 4348 | 4348 | |
| 4349 | - if ( !$this->is_tax ) |
|
| 4349 | + if ( ! $this->is_tax) |
|
| 4350 | 4350 | return false; |
| 4351 | 4351 | |
| 4352 | - if ( empty( $taxonomy ) ) |
|
| 4352 | + if (empty($taxonomy)) |
|
| 4353 | 4353 | return true; |
| 4354 | 4354 | |
| 4355 | 4355 | $queried_object = $this->get_queried_object(); |
| 4356 | - $tax_array = array_intersect( array_keys( $wp_taxonomies ), (array) $taxonomy ); |
|
| 4356 | + $tax_array = array_intersect(array_keys($wp_taxonomies), (array) $taxonomy); |
|
| 4357 | 4357 | $term_array = (array) $term; |
| 4358 | 4358 | |
| 4359 | 4359 | // Check that the taxonomy matches. |
| 4360 | - if ( ! ( isset( $queried_object->taxonomy ) && count( $tax_array ) && in_array( $queried_object->taxonomy, $tax_array ) ) ) |
|
| 4360 | + if ( ! (isset($queried_object->taxonomy) && count($tax_array) && in_array($queried_object->taxonomy, $tax_array))) |
|
| 4361 | 4361 | return false; |
| 4362 | 4362 | |
| 4363 | 4363 | // Only a Taxonomy provided. |
| 4364 | - if ( empty( $term ) ) |
|
| 4364 | + if (empty($term)) |
|
| 4365 | 4365 | return true; |
| 4366 | 4366 | |
| 4367 | - return isset( $queried_object->term_id ) && |
|
| 4368 | - count( array_intersect( |
|
| 4369 | - array( $queried_object->term_id, $queried_object->name, $queried_object->slug ), |
|
| 4367 | + return isset($queried_object->term_id) && |
|
| 4368 | + count(array_intersect( |
|
| 4369 | + array($queried_object->term_id, $queried_object->name, $queried_object->slug), |
|
| 4370 | 4370 | $term_array |
| 4371 | - ) ); |
|
| 4371 | + )); |
|
| 4372 | 4372 | } |
| 4373 | 4373 | |
| 4374 | 4374 | /** |
@@ -4380,7 +4380,7 @@ discard block |
||
| 4380 | 4380 | * @return bool |
| 4381 | 4381 | */ |
| 4382 | 4382 | public function is_comments_popup() { |
| 4383 | - _deprecated_function( __FUNCTION__, '4.5' ); |
|
| 4383 | + _deprecated_function(__FUNCTION__, '4.5'); |
|
| 4384 | 4384 | |
| 4385 | 4385 | return false; |
| 4386 | 4386 | } |
@@ -4415,13 +4415,13 @@ discard block |
||
| 4415 | 4415 | * @param string|array $feeds Optional feed types to check. |
| 4416 | 4416 | * @return bool |
| 4417 | 4417 | */ |
| 4418 | - public function is_feed( $feeds = '' ) { |
|
| 4419 | - if ( empty( $feeds ) || ! $this->is_feed ) |
|
| 4418 | + public function is_feed($feeds = '') { |
|
| 4419 | + if (empty($feeds) || ! $this->is_feed) |
|
| 4420 | 4420 | return (bool) $this->is_feed; |
| 4421 | - $qv = $this->get( 'feed' ); |
|
| 4422 | - if ( 'feed' == $qv ) |
|
| 4421 | + $qv = $this->get('feed'); |
|
| 4422 | + if ('feed' == $qv) |
|
| 4423 | 4423 | $qv = get_default_feed(); |
| 4424 | - return in_array( $qv, (array) $feeds ); |
|
| 4424 | + return in_array($qv, (array) $feeds); |
|
| 4425 | 4425 | } |
| 4426 | 4426 | |
| 4427 | 4427 | /** |
@@ -4453,9 +4453,9 @@ discard block |
||
| 4453 | 4453 | */ |
| 4454 | 4454 | public function is_front_page() { |
| 4455 | 4455 | // most likely case |
| 4456 | - if ( 'posts' == get_option( 'show_on_front') && $this->is_home() ) |
|
| 4456 | + if ('posts' == get_option('show_on_front') && $this->is_home()) |
|
| 4457 | 4457 | return true; |
| 4458 | - elseif ( 'page' == get_option( 'show_on_front') && get_option( 'page_on_front' ) && $this->is_page( get_option( 'page_on_front' ) ) ) |
|
| 4458 | + elseif ('page' == get_option('show_on_front') && get_option('page_on_front') && $this->is_page(get_option('page_on_front'))) |
|
| 4459 | 4459 | return true; |
| 4460 | 4460 | else |
| 4461 | 4461 | return false; |
@@ -4506,31 +4506,31 @@ discard block |
||
| 4506 | 4506 | * @param int|string|array $page Optional. Page ID, title, slug, path, or array of such. Default empty. |
| 4507 | 4507 | * @return bool Whether the query is for an existing single page. |
| 4508 | 4508 | */ |
| 4509 | - public function is_page( $page = '' ) { |
|
| 4510 | - if ( !$this->is_page ) |
|
| 4509 | + public function is_page($page = '') { |
|
| 4510 | + if ( ! $this->is_page) |
|
| 4511 | 4511 | return false; |
| 4512 | 4512 | |
| 4513 | - if ( empty( $page ) ) |
|
| 4513 | + if (empty($page)) |
|
| 4514 | 4514 | return true; |
| 4515 | 4515 | |
| 4516 | 4516 | $page_obj = $this->get_queried_object(); |
| 4517 | 4517 | |
| 4518 | - $page = array_map( 'strval', (array) $page ); |
|
| 4518 | + $page = array_map('strval', (array) $page); |
|
| 4519 | 4519 | |
| 4520 | - if ( in_array( (string) $page_obj->ID, $page ) ) { |
|
| 4520 | + if (in_array((string) $page_obj->ID, $page)) { |
|
| 4521 | 4521 | return true; |
| 4522 | - } elseif ( in_array( $page_obj->post_title, $page ) ) { |
|
| 4522 | + } elseif (in_array($page_obj->post_title, $page)) { |
|
| 4523 | 4523 | return true; |
| 4524 | - } elseif ( in_array( $page_obj->post_name, $page ) ) { |
|
| 4524 | + } elseif (in_array($page_obj->post_name, $page)) { |
|
| 4525 | 4525 | return true; |
| 4526 | 4526 | } else { |
| 4527 | - foreach ( $page as $pagepath ) { |
|
| 4528 | - if ( ! strpos( $pagepath, '/' ) ) { |
|
| 4527 | + foreach ($page as $pagepath) { |
|
| 4528 | + if ( ! strpos($pagepath, '/')) { |
|
| 4529 | 4529 | continue; |
| 4530 | 4530 | } |
| 4531 | - $pagepath_obj = get_page_by_path( $pagepath ); |
|
| 4531 | + $pagepath_obj = get_page_by_path($pagepath); |
|
| 4532 | 4532 | |
| 4533 | - if ( $pagepath_obj && ( $pagepath_obj->ID == $page_obj->ID ) ) { |
|
| 4533 | + if ($pagepath_obj && ($pagepath_obj->ID == $page_obj->ID)) { |
|
| 4534 | 4534 | return true; |
| 4535 | 4535 | } |
| 4536 | 4536 | } |
@@ -4599,31 +4599,31 @@ discard block |
||
| 4599 | 4599 | * @param int|string|array $post Optional. Post ID, title, slug, path, or array of such. Default empty. |
| 4600 | 4600 | * @return bool Whether the query is for an existing single post. |
| 4601 | 4601 | */ |
| 4602 | - public function is_single( $post = '' ) { |
|
| 4603 | - if ( !$this->is_single ) |
|
| 4602 | + public function is_single($post = '') { |
|
| 4603 | + if ( ! $this->is_single) |
|
| 4604 | 4604 | return false; |
| 4605 | 4605 | |
| 4606 | - if ( empty($post) ) |
|
| 4606 | + if (empty($post)) |
|
| 4607 | 4607 | return true; |
| 4608 | 4608 | |
| 4609 | 4609 | $post_obj = $this->get_queried_object(); |
| 4610 | 4610 | |
| 4611 | - $post = array_map( 'strval', (array) $post ); |
|
| 4611 | + $post = array_map('strval', (array) $post); |
|
| 4612 | 4612 | |
| 4613 | - if ( in_array( (string) $post_obj->ID, $post ) ) { |
|
| 4613 | + if (in_array((string) $post_obj->ID, $post)) { |
|
| 4614 | 4614 | return true; |
| 4615 | - } elseif ( in_array( $post_obj->post_title, $post ) ) { |
|
| 4615 | + } elseif (in_array($post_obj->post_title, $post)) { |
|
| 4616 | 4616 | return true; |
| 4617 | - } elseif ( in_array( $post_obj->post_name, $post ) ) { |
|
| 4617 | + } elseif (in_array($post_obj->post_name, $post)) { |
|
| 4618 | 4618 | return true; |
| 4619 | 4619 | } else { |
| 4620 | - foreach ( $post as $postpath ) { |
|
| 4621 | - if ( ! strpos( $postpath, '/' ) ) { |
|
| 4620 | + foreach ($post as $postpath) { |
|
| 4621 | + if ( ! strpos($postpath, '/')) { |
|
| 4622 | 4622 | continue; |
| 4623 | 4623 | } |
| 4624 | - $postpath_obj = get_page_by_path( $postpath, OBJECT, $post_obj->post_type ); |
|
| 4624 | + $postpath_obj = get_page_by_path($postpath, OBJECT, $post_obj->post_type); |
|
| 4625 | 4625 | |
| 4626 | - if ( $postpath_obj && ( $postpath_obj->ID == $post_obj->ID ) ) { |
|
| 4626 | + if ($postpath_obj && ($postpath_obj->ID == $post_obj->ID)) { |
|
| 4627 | 4627 | return true; |
| 4628 | 4628 | } |
| 4629 | 4629 | } |
@@ -4645,13 +4645,13 @@ discard block |
||
| 4645 | 4645 | * @param string|array $post_types Optional. Post type or array of post types. Default empty. |
| 4646 | 4646 | * @return bool Whether the query is for an existing single post of any of the given post types. |
| 4647 | 4647 | */ |
| 4648 | - public function is_singular( $post_types = '' ) { |
|
| 4649 | - if ( empty( $post_types ) || !$this->is_singular ) |
|
| 4648 | + public function is_singular($post_types = '') { |
|
| 4649 | + if (empty($post_types) || ! $this->is_singular) |
|
| 4650 | 4650 | return (bool) $this->is_singular; |
| 4651 | 4651 | |
| 4652 | 4652 | $post_obj = $this->get_queried_object(); |
| 4653 | 4653 | |
| 4654 | - return in_array( $post_obj->post_type, (array) $post_types ); |
|
| 4654 | + return in_array($post_obj->post_type, (array) $post_types); |
|
| 4655 | 4655 | } |
| 4656 | 4656 | |
| 4657 | 4657 | /** |
@@ -4742,14 +4742,14 @@ discard block |
||
| 4742 | 4742 | * @param WP_Post|object|int $post WP_Post instance or Post ID/object. |
| 4743 | 4743 | * @return true True when finished. |
| 4744 | 4744 | */ |
| 4745 | - public function setup_postdata( $post ) { |
|
| 4745 | + public function setup_postdata($post) { |
|
| 4746 | 4746 | global $id, $authordata, $currentday, $currentmonth, $page, $pages, $multipage, $more, $numpages; |
| 4747 | 4747 | |
| 4748 | - if ( ! ( $post instanceof WP_Post ) ) { |
|
| 4749 | - $post = get_post( $post ); |
|
| 4748 | + if ( ! ($post instanceof WP_Post)) { |
|
| 4749 | + $post = get_post($post); |
|
| 4750 | 4750 | } |
| 4751 | 4751 | |
| 4752 | - if ( ! $post ) { |
|
| 4752 | + if ( ! $post) { |
|
| 4753 | 4753 | return; |
| 4754 | 4754 | } |
| 4755 | 4755 | |
@@ -4761,35 +4761,35 @@ discard block |
||
| 4761 | 4761 | $currentmonth = mysql2date('m', $post->post_date, false); |
| 4762 | 4762 | $numpages = 1; |
| 4763 | 4763 | $multipage = 0; |
| 4764 | - $page = $this->get( 'page' ); |
|
| 4765 | - if ( ! $page ) |
|
| 4764 | + $page = $this->get('page'); |
|
| 4765 | + if ( ! $page) |
|
| 4766 | 4766 | $page = 1; |
| 4767 | 4767 | |
| 4768 | 4768 | /* |
| 4769 | 4769 | * Force full post content when viewing the permalink for the $post, |
| 4770 | 4770 | * or when on an RSS feed. Otherwise respect the 'more' tag. |
| 4771 | 4771 | */ |
| 4772 | - if ( $post->ID === get_queried_object_id() && ( $this->is_page() || $this->is_single() ) ) { |
|
| 4772 | + if ($post->ID === get_queried_object_id() && ($this->is_page() || $this->is_single())) { |
|
| 4773 | 4773 | $more = 1; |
| 4774 | - } elseif ( $this->is_feed() ) { |
|
| 4774 | + } elseif ($this->is_feed()) { |
|
| 4775 | 4775 | $more = 1; |
| 4776 | 4776 | } else { |
| 4777 | 4777 | $more = 0; |
| 4778 | 4778 | } |
| 4779 | 4779 | |
| 4780 | 4780 | $content = $post->post_content; |
| 4781 | - if ( false !== strpos( $content, '<!--nextpage-->' ) ) { |
|
| 4782 | - $content = str_replace( "\n<!--nextpage-->\n", '<!--nextpage-->', $content ); |
|
| 4783 | - $content = str_replace( "\n<!--nextpage-->", '<!--nextpage-->', $content ); |
|
| 4784 | - $content = str_replace( "<!--nextpage-->\n", '<!--nextpage-->', $content ); |
|
| 4781 | + if (false !== strpos($content, '<!--nextpage-->')) { |
|
| 4782 | + $content = str_replace("\n<!--nextpage-->\n", '<!--nextpage-->', $content); |
|
| 4783 | + $content = str_replace("\n<!--nextpage-->", '<!--nextpage-->', $content); |
|
| 4784 | + $content = str_replace("<!--nextpage-->\n", '<!--nextpage-->', $content); |
|
| 4785 | 4785 | |
| 4786 | 4786 | // Ignore nextpage at the beginning of the content. |
| 4787 | - if ( 0 === strpos( $content, '<!--nextpage-->' ) ) |
|
| 4788 | - $content = substr( $content, 15 ); |
|
| 4787 | + if (0 === strpos($content, '<!--nextpage-->')) |
|
| 4788 | + $content = substr($content, 15); |
|
| 4789 | 4789 | |
| 4790 | 4790 | $pages = explode('<!--nextpage-->', $content); |
| 4791 | 4791 | } else { |
| 4792 | - $pages = array( $post->post_content ); |
|
| 4792 | + $pages = array($post->post_content); |
|
| 4793 | 4793 | } |
| 4794 | 4794 | |
| 4795 | 4795 | /** |
@@ -4804,12 +4804,12 @@ discard block |
||
| 4804 | 4804 | * of `<!-- nextpage -->` tags.. |
| 4805 | 4805 | * @param WP_Post $post Current post object. |
| 4806 | 4806 | */ |
| 4807 | - $pages = apply_filters( 'content_pagination', $pages, $post ); |
|
| 4807 | + $pages = apply_filters('content_pagination', $pages, $post); |
|
| 4808 | 4808 | |
| 4809 | - $numpages = count( $pages ); |
|
| 4809 | + $numpages = count($pages); |
|
| 4810 | 4810 | |
| 4811 | - if ( $numpages > 1 ) { |
|
| 4812 | - if ( $page > 1 ) { |
|
| 4811 | + if ($numpages > 1) { |
|
| 4812 | + if ($page > 1) { |
|
| 4813 | 4813 | $more = 1; |
| 4814 | 4814 | } |
| 4815 | 4815 | $multipage = 1; |
@@ -4826,7 +4826,7 @@ discard block |
||
| 4826 | 4826 | * @param WP_Post &$post The Post object (passed by reference). |
| 4827 | 4827 | * @param WP_Query &$this The current Query object (passed by reference). |
| 4828 | 4828 | */ |
| 4829 | - do_action_ref_array( 'the_post', array( &$post, &$this ) ); |
|
| 4829 | + do_action_ref_array('the_post', array(&$post, &$this)); |
|
| 4830 | 4830 | |
| 4831 | 4831 | return true; |
| 4832 | 4832 | } |
@@ -4839,9 +4839,9 @@ discard block |
||
| 4839 | 4839 | * @global WP_Post $post |
| 4840 | 4840 | */ |
| 4841 | 4841 | public function reset_postdata() { |
| 4842 | - if ( ! empty( $this->post ) ) { |
|
| 4842 | + if ( ! empty($this->post)) { |
|
| 4843 | 4843 | $GLOBALS['post'] = $this->post; |
| 4844 | - $this->setup_postdata( $this->post ); |
|
| 4844 | + $this->setup_postdata($this->post); |
|
| 4845 | 4845 | } |
| 4846 | 4846 | } |
| 4847 | 4847 | |
@@ -4855,8 +4855,8 @@ discard block |
||
| 4855 | 4855 | * @param int $term_id |
| 4856 | 4856 | * @return mixed |
| 4857 | 4857 | */ |
| 4858 | - public function lazyload_term_meta( $check, $term_id ) { |
|
| 4859 | - _deprecated_function( __METHOD__, '4.5.0' ); |
|
| 4858 | + public function lazyload_term_meta($check, $term_id) { |
|
| 4859 | + _deprecated_function(__METHOD__, '4.5.0'); |
|
| 4860 | 4860 | return $check; |
| 4861 | 4861 | } |
| 4862 | 4862 | |
@@ -4870,8 +4870,8 @@ discard block |
||
| 4870 | 4870 | * @param int $comment_id |
| 4871 | 4871 | * @return mixed |
| 4872 | 4872 | */ |
| 4873 | - public function lazyload_comment_meta( $check, $comment_id ) { |
|
| 4874 | - _deprecated_function( __METHOD__, '4.5.0' ); |
|
| 4873 | + public function lazyload_comment_meta($check, $comment_id) { |
|
| 4874 | + _deprecated_function(__METHOD__, '4.5.0'); |
|
| 4875 | 4875 | return $check; |
| 4876 | 4876 | } |
| 4877 | 4877 | } |
@@ -4890,63 +4890,63 @@ discard block |
||
| 4890 | 4890 | function wp_old_slug_redirect() { |
| 4891 | 4891 | global $wp_query, $wp_rewrite; |
| 4892 | 4892 | |
| 4893 | - if ( get_queried_object() ) { |
|
| 4893 | + if (get_queried_object()) { |
|
| 4894 | 4894 | return; |
| 4895 | 4895 | } |
| 4896 | 4896 | |
| 4897 | - if ( '' !== $wp_query->query_vars['name'] ) : |
|
| 4897 | + if ('' !== $wp_query->query_vars['name']) : |
|
| 4898 | 4898 | global $wpdb; |
| 4899 | 4899 | |
| 4900 | 4900 | // Guess the current post_type based on the query vars. |
| 4901 | - if ( get_query_var( 'post_type' ) ) { |
|
| 4902 | - $post_type = get_query_var( 'post_type' ); |
|
| 4903 | - } elseif ( get_query_var( 'attachment' ) ) { |
|
| 4901 | + if (get_query_var('post_type')) { |
|
| 4902 | + $post_type = get_query_var('post_type'); |
|
| 4903 | + } elseif (get_query_var('attachment')) { |
|
| 4904 | 4904 | $post_type = 'attachment'; |
| 4905 | - } elseif ( ! empty( $wp_query->query_vars['pagename'] ) ) { |
|
| 4905 | + } elseif ( ! empty($wp_query->query_vars['pagename'])) { |
|
| 4906 | 4906 | $post_type = 'page'; |
| 4907 | 4907 | } else { |
| 4908 | 4908 | $post_type = 'post'; |
| 4909 | 4909 | } |
| 4910 | 4910 | |
| 4911 | - if ( is_array( $post_type ) ) { |
|
| 4912 | - if ( count( $post_type ) > 1 ) |
|
| 4911 | + if (is_array($post_type)) { |
|
| 4912 | + if (count($post_type) > 1) |
|
| 4913 | 4913 | return; |
| 4914 | - $post_type = reset( $post_type ); |
|
| 4914 | + $post_type = reset($post_type); |
|
| 4915 | 4915 | } |
| 4916 | 4916 | |
| 4917 | 4917 | // Do not attempt redirect for hierarchical post types |
| 4918 | - if ( is_post_type_hierarchical( $post_type ) ) |
|
| 4918 | + if (is_post_type_hierarchical($post_type)) |
|
| 4919 | 4919 | return; |
| 4920 | 4920 | |
| 4921 | 4921 | $query = $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta, $wpdb->posts WHERE ID = post_id AND post_type = %s AND meta_key = '_wp_old_slug' AND meta_value = %s", $post_type, $wp_query->query_vars['name']); |
| 4922 | 4922 | |
| 4923 | 4923 | // if year, monthnum, or day have been specified, make our query more precise |
| 4924 | 4924 | // just in case there are multiple identical _wp_old_slug values |
| 4925 | - if ( '' != $wp_query->query_vars['year'] ) |
|
| 4925 | + if ('' != $wp_query->query_vars['year']) |
|
| 4926 | 4926 | $query .= $wpdb->prepare(" AND YEAR(post_date) = %d", $wp_query->query_vars['year']); |
| 4927 | - if ( '' != $wp_query->query_vars['monthnum'] ) |
|
| 4927 | + if ('' != $wp_query->query_vars['monthnum']) |
|
| 4928 | 4928 | $query .= $wpdb->prepare(" AND MONTH(post_date) = %d", $wp_query->query_vars['monthnum']); |
| 4929 | - if ( '' != $wp_query->query_vars['day'] ) |
|
| 4929 | + if ('' != $wp_query->query_vars['day']) |
|
| 4930 | 4930 | $query .= $wpdb->prepare(" AND DAYOFMONTH(post_date) = %d", $wp_query->query_vars['day']); |
| 4931 | 4931 | |
| 4932 | 4932 | $id = (int) $wpdb->get_var($query); |
| 4933 | 4933 | |
| 4934 | - if ( ! $id ) |
|
| 4934 | + if ( ! $id) |
|
| 4935 | 4935 | return; |
| 4936 | 4936 | |
| 4937 | - $link = get_permalink( $id ); |
|
| 4937 | + $link = get_permalink($id); |
|
| 4938 | 4938 | |
| 4939 | - if ( is_feed() ) { |
|
| 4940 | - $link = user_trailingslashit( trailingslashit( $link ) . 'feed' ); |
|
| 4941 | - } elseif ( isset( $GLOBALS['wp_query']->query_vars['paged'] ) && $GLOBALS['wp_query']->query_vars['paged'] > 1 ) { |
|
| 4942 | - $link = user_trailingslashit( trailingslashit( $link ) . 'page/' . $GLOBALS['wp_query']->query_vars['paged'] ); |
|
| 4943 | - } elseif( is_embed() ) { |
|
| 4944 | - $link = user_trailingslashit( trailingslashit( $link ) . 'embed' ); |
|
| 4945 | - } elseif ( is_404() ) { |
|
| 4939 | + if (is_feed()) { |
|
| 4940 | + $link = user_trailingslashit(trailingslashit($link).'feed'); |
|
| 4941 | + } elseif (isset($GLOBALS['wp_query']->query_vars['paged']) && $GLOBALS['wp_query']->query_vars['paged'] > 1) { |
|
| 4942 | + $link = user_trailingslashit(trailingslashit($link).'page/'.$GLOBALS['wp_query']->query_vars['paged']); |
|
| 4943 | + } elseif (is_embed()) { |
|
| 4944 | + $link = user_trailingslashit(trailingslashit($link).'embed'); |
|
| 4945 | + } elseif (is_404()) { |
|
| 4946 | 4946 | // Add rewrite endpoints if necessary. |
| 4947 | - foreach ( $wp_rewrite->endpoints as $endpoint ) { |
|
| 4948 | - if ( $endpoint[2] && false !== get_query_var( $endpoint[2], false ) ) { |
|
| 4949 | - $link = user_trailingslashit( trailingslashit( $link ) . $endpoint[1] ); |
|
| 4947 | + foreach ($wp_rewrite->endpoints as $endpoint) { |
|
| 4948 | + if ($endpoint[2] && false !== get_query_var($endpoint[2], false)) { |
|
| 4949 | + $link = user_trailingslashit(trailingslashit($link).$endpoint[1]); |
|
| 4950 | 4950 | } |
| 4951 | 4951 | } |
| 4952 | 4952 | } |
@@ -4958,13 +4958,13 @@ discard block |
||
| 4958 | 4958 | * |
| 4959 | 4959 | * @param string $link The redirect URL. |
| 4960 | 4960 | */ |
| 4961 | - $link = apply_filters( 'old_slug_redirect_url', $link ); |
|
| 4961 | + $link = apply_filters('old_slug_redirect_url', $link); |
|
| 4962 | 4962 | |
| 4963 | - if ( ! $link ) { |
|
| 4963 | + if ( ! $link) { |
|
| 4964 | 4964 | return; |
| 4965 | 4965 | } |
| 4966 | 4966 | |
| 4967 | - wp_redirect( $link, 301 ); // Permanent redirect |
|
| 4967 | + wp_redirect($link, 301); // Permanent redirect |
|
| 4968 | 4968 | exit; |
| 4969 | 4969 | endif; |
| 4970 | 4970 | } |
@@ -4980,11 +4980,11 @@ discard block |
||
| 4980 | 4980 | * @param WP_Post|object|int $post WP_Post instance or Post ID/object. |
| 4981 | 4981 | * @return bool True when finished. |
| 4982 | 4982 | */ |
| 4983 | -function setup_postdata( $post ) { |
|
| 4983 | +function setup_postdata($post) { |
|
| 4984 | 4984 | global $wp_query; |
| 4985 | 4985 | |
| 4986 | - if ( ! empty( $wp_query ) && $wp_query instanceof WP_Query ) { |
|
| 4987 | - return $wp_query->setup_postdata( $post ); |
|
| 4986 | + if ( ! empty($wp_query) && $wp_query instanceof WP_Query) { |
|
| 4987 | + return $wp_query->setup_postdata($post); |
|
| 4988 | 4988 | } |
| 4989 | 4989 | |
| 4990 | 4990 | return false; |
@@ -1442,8 +1442,9 @@ discard block |
||
| 1442 | 1442 | ); |
| 1443 | 1443 | |
| 1444 | 1444 | foreach ( $keys as $key ) { |
| 1445 | - if ( !isset($array[$key]) ) |
|
| 1446 | - $array[$key] = ''; |
|
| 1445 | + if ( !isset($array[$key]) ) { |
|
| 1446 | + $array[$key] = ''; |
|
| 1447 | + } |
|
| 1447 | 1448 | } |
| 1448 | 1449 | |
| 1449 | 1450 | $array_keys = array( 'category__in', 'category__not_in', 'category__and', 'post__in', 'post__not_in', 'post_name__in', |
@@ -1451,8 +1452,9 @@ discard block |
||
| 1451 | 1452 | 'author__in', 'author__not_in' ); |
| 1452 | 1453 | |
| 1453 | 1454 | foreach ( $array_keys as $key ) { |
| 1454 | - if ( !isset($array[$key]) ) |
|
| 1455 | - $array[$key] = array(); |
|
| 1455 | + if ( !isset($array[$key]) ) { |
|
| 1456 | + $array[$key] = array(); |
|
| 1457 | + } |
|
| 1456 | 1458 | } |
| 1457 | 1459 | return $array; |
| 1458 | 1460 | } |
@@ -1582,8 +1584,9 @@ discard block |
||
| 1582 | 1584 | $qv = &$this->query_vars; |
| 1583 | 1585 | $this->query_vars_changed = true; |
| 1584 | 1586 | |
| 1585 | - if ( ! empty($qv['robots']) ) |
|
| 1586 | - $this->is_robots = true; |
|
| 1587 | + if ( ! empty($qv['robots']) ) { |
|
| 1588 | + $this->is_robots = true; |
|
| 1589 | + } |
|
| 1587 | 1590 | |
| 1588 | 1591 | $qv['p'] = absint($qv['p']); |
| 1589 | 1592 | $qv['page_id'] = absint($qv['page_id']); |
@@ -1598,10 +1601,18 @@ discard block |
||
| 1598 | 1601 | $qv['pagename'] = trim( $qv['pagename'] ); |
| 1599 | 1602 | $qv['name'] = trim( $qv['name'] ); |
| 1600 | 1603 | $qv['title'] = trim( $qv['title'] ); |
| 1601 | - if ( '' !== $qv['hour'] ) $qv['hour'] = absint($qv['hour']); |
|
| 1602 | - if ( '' !== $qv['minute'] ) $qv['minute'] = absint($qv['minute']); |
|
| 1603 | - if ( '' !== $qv['second'] ) $qv['second'] = absint($qv['second']); |
|
| 1604 | - if ( '' !== $qv['menu_order'] ) $qv['menu_order'] = absint($qv['menu_order']); |
|
| 1604 | + if ( '' !== $qv['hour'] ) { |
|
| 1605 | + $qv['hour'] = absint($qv['hour']); |
|
| 1606 | + } |
|
| 1607 | + if ( '' !== $qv['minute'] ) { |
|
| 1608 | + $qv['minute'] = absint($qv['minute']); |
|
| 1609 | + } |
|
| 1610 | + if ( '' !== $qv['second'] ) { |
|
| 1611 | + $qv['second'] = absint($qv['second']); |
|
| 1612 | + } |
|
| 1613 | + if ( '' !== $qv['menu_order'] ) { |
|
| 1614 | + $qv['menu_order'] = absint($qv['menu_order']); |
|
| 1615 | + } |
|
| 1605 | 1616 | |
| 1606 | 1617 | // Fairly insane upper bound for search string lengths. |
| 1607 | 1618 | if ( ! is_scalar( $qv['s'] ) || ( ! empty( $qv['s'] ) && strlen( $qv['s'] ) > 1600 ) ) { |
@@ -1609,10 +1620,12 @@ discard block |
||
| 1609 | 1620 | } |
| 1610 | 1621 | |
| 1611 | 1622 | // Compat. Map subpost to attachment. |
| 1612 | - if ( '' != $qv['subpost'] ) |
|
| 1613 | - $qv['attachment'] = $qv['subpost']; |
|
| 1614 | - if ( '' != $qv['subpost_id'] ) |
|
| 1615 | - $qv['attachment_id'] = $qv['subpost_id']; |
|
| 1623 | + if ( '' != $qv['subpost'] ) { |
|
| 1624 | + $qv['attachment'] = $qv['subpost']; |
|
| 1625 | + } |
|
| 1626 | + if ( '' != $qv['subpost_id'] ) { |
|
| 1627 | + $qv['attachment_id'] = $qv['subpost_id']; |
|
| 1628 | + } |
|
| 1616 | 1629 | |
| 1617 | 1630 | $qv['attachment_id'] = absint($qv['attachment_id']); |
| 1618 | 1631 | |
@@ -1728,38 +1741,46 @@ discard block |
||
| 1728 | 1741 | $this->is_author = true; |
| 1729 | 1742 | } |
| 1730 | 1743 | |
| 1731 | - if ( '' != $qv['author_name'] ) |
|
| 1732 | - $this->is_author = true; |
|
| 1744 | + if ( '' != $qv['author_name'] ) { |
|
| 1745 | + $this->is_author = true; |
|
| 1746 | + } |
|
| 1733 | 1747 | |
| 1734 | 1748 | if ( !empty( $qv['post_type'] ) && ! is_array( $qv['post_type'] ) ) { |
| 1735 | 1749 | $post_type_obj = get_post_type_object( $qv['post_type'] ); |
| 1736 | - if ( ! empty( $post_type_obj->has_archive ) ) |
|
| 1737 | - $this->is_post_type_archive = true; |
|
| 1750 | + if ( ! empty( $post_type_obj->has_archive ) ) { |
|
| 1751 | + $this->is_post_type_archive = true; |
|
| 1752 | + } |
|
| 1738 | 1753 | } |
| 1739 | 1754 | |
| 1740 | - if ( $this->is_post_type_archive || $this->is_date || $this->is_author || $this->is_category || $this->is_tag || $this->is_tax ) |
|
| 1741 | - $this->is_archive = true; |
|
| 1755 | + if ( $this->is_post_type_archive || $this->is_date || $this->is_author || $this->is_category || $this->is_tag || $this->is_tax ) { |
|
| 1756 | + $this->is_archive = true; |
|
| 1757 | + } |
|
| 1742 | 1758 | } |
| 1743 | 1759 | |
| 1744 | - if ( '' != $qv['feed'] ) |
|
| 1745 | - $this->is_feed = true; |
|
| 1760 | + if ( '' != $qv['feed'] ) { |
|
| 1761 | + $this->is_feed = true; |
|
| 1762 | + } |
|
| 1746 | 1763 | |
| 1747 | 1764 | if ( '' != $qv['embed'] ) { |
| 1748 | 1765 | $this->is_embed = true; |
| 1749 | 1766 | } |
| 1750 | 1767 | |
| 1751 | - if ( '' != $qv['tb'] ) |
|
| 1752 | - $this->is_trackback = true; |
|
| 1768 | + if ( '' != $qv['tb'] ) { |
|
| 1769 | + $this->is_trackback = true; |
|
| 1770 | + } |
|
| 1753 | 1771 | |
| 1754 | - if ( '' != $qv['paged'] && ( intval($qv['paged']) > 1 ) ) |
|
| 1755 | - $this->is_paged = true; |
|
| 1772 | + if ( '' != $qv['paged'] && ( intval($qv['paged']) > 1 ) ) { |
|
| 1773 | + $this->is_paged = true; |
|
| 1774 | + } |
|
| 1756 | 1775 | |
| 1757 | 1776 | // if we're previewing inside the write screen |
| 1758 | - if ( '' != $qv['preview'] ) |
|
| 1759 | - $this->is_preview = true; |
|
| 1777 | + if ( '' != $qv['preview'] ) { |
|
| 1778 | + $this->is_preview = true; |
|
| 1779 | + } |
|
| 1760 | 1780 | |
| 1761 | - if ( is_admin() ) |
|
| 1762 | - $this->is_admin = true; |
|
| 1781 | + if ( is_admin() ) { |
|
| 1782 | + $this->is_admin = true; |
|
| 1783 | + } |
|
| 1763 | 1784 | |
| 1764 | 1785 | if ( false !== strpos($qv['feed'], 'comments-') ) { |
| 1765 | 1786 | $qv['feed'] = str_replace('comments-', '', $qv['feed']); |
@@ -1768,18 +1789,21 @@ discard block |
||
| 1768 | 1789 | |
| 1769 | 1790 | $this->is_singular = $this->is_single || $this->is_page || $this->is_attachment; |
| 1770 | 1791 | |
| 1771 | - if ( $this->is_feed && ( !empty($qv['withcomments']) || ( empty($qv['withoutcomments']) && $this->is_singular ) ) ) |
|
| 1772 | - $this->is_comment_feed = true; |
|
| 1792 | + if ( $this->is_feed && ( !empty($qv['withcomments']) || ( empty($qv['withoutcomments']) && $this->is_singular ) ) ) { |
|
| 1793 | + $this->is_comment_feed = true; |
|
| 1794 | + } |
|
| 1773 | 1795 | |
| 1774 | - if ( !( $this->is_singular || $this->is_archive || $this->is_search || $this->is_feed || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) || $this->is_trackback || $this->is_404 || $this->is_admin || $this->is_robots ) ) |
|
| 1775 | - $this->is_home = true; |
|
| 1796 | + if ( !( $this->is_singular || $this->is_archive || $this->is_search || $this->is_feed || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) || $this->is_trackback || $this->is_404 || $this->is_admin || $this->is_robots ) ) { |
|
| 1797 | + $this->is_home = true; |
|
| 1798 | + } |
|
| 1776 | 1799 | |
| 1777 | 1800 | // Correct is_* for page_on_front and page_for_posts |
| 1778 | 1801 | if ( $this->is_home && 'page' == get_option('show_on_front') && get_option('page_on_front') ) { |
| 1779 | 1802 | $_query = wp_parse_args($this->query); |
| 1780 | 1803 | // pagename can be set and empty depending on matched rewrite rules. Ignore an empty pagename. |
| 1781 | - if ( isset($_query['pagename']) && '' == $_query['pagename'] ) |
|
| 1782 | - unset($_query['pagename']); |
|
| 1804 | + if ( isset($_query['pagename']) && '' == $_query['pagename'] ) { |
|
| 1805 | + unset($_query['pagename']); |
|
| 1806 | + } |
|
| 1783 | 1807 | |
| 1784 | 1808 | unset( $_query['embed'] ); |
| 1785 | 1809 | |
@@ -1832,27 +1856,31 @@ discard block |
||
| 1832 | 1856 | } |
| 1833 | 1857 | |
| 1834 | 1858 | if ( !empty($qv['post_type']) ) { |
| 1835 | - if ( is_array($qv['post_type']) ) |
|
| 1836 | - $qv['post_type'] = array_map('sanitize_key', $qv['post_type']); |
|
| 1837 | - else |
|
| 1838 | - $qv['post_type'] = sanitize_key($qv['post_type']); |
|
| 1859 | + if ( is_array($qv['post_type']) ) { |
|
| 1860 | + $qv['post_type'] = array_map('sanitize_key', $qv['post_type']); |
|
| 1861 | + } else { |
|
| 1862 | + $qv['post_type'] = sanitize_key($qv['post_type']); |
|
| 1863 | + } |
|
| 1839 | 1864 | } |
| 1840 | 1865 | |
| 1841 | 1866 | if ( ! empty( $qv['post_status'] ) ) { |
| 1842 | - if ( is_array( $qv['post_status'] ) ) |
|
| 1843 | - $qv['post_status'] = array_map('sanitize_key', $qv['post_status']); |
|
| 1844 | - else |
|
| 1845 | - $qv['post_status'] = preg_replace('|[^a-z0-9_,-]|', '', $qv['post_status']); |
|
| 1867 | + if ( is_array( $qv['post_status'] ) ) { |
|
| 1868 | + $qv['post_status'] = array_map('sanitize_key', $qv['post_status']); |
|
| 1869 | + } else { |
|
| 1870 | + $qv['post_status'] = preg_replace('|[^a-z0-9_,-]|', '', $qv['post_status']); |
|
| 1871 | + } |
|
| 1846 | 1872 | } |
| 1847 | 1873 | |
| 1848 | - if ( $this->is_posts_page && ( ! isset($qv['withcomments']) || ! $qv['withcomments'] ) ) |
|
| 1849 | - $this->is_comment_feed = false; |
|
| 1874 | + if ( $this->is_posts_page && ( ! isset($qv['withcomments']) || ! $qv['withcomments'] ) ) { |
|
| 1875 | + $this->is_comment_feed = false; |
|
| 1876 | + } |
|
| 1850 | 1877 | |
| 1851 | 1878 | $this->is_singular = $this->is_single || $this->is_page || $this->is_attachment; |
| 1852 | 1879 | // Done correcting is_* for page_on_front and page_for_posts |
| 1853 | 1880 | |
| 1854 | - if ( '404' == $qv['error'] ) |
|
| 1855 | - $this->set_404(); |
|
| 1881 | + if ( '404' == $qv['error'] ) { |
|
| 1882 | + $this->set_404(); |
|
| 1883 | + } |
|
| 1856 | 1884 | |
| 1857 | 1885 | $this->is_embed = $this->is_embed && ( $this->is_singular || $this->is_404 ); |
| 1858 | 1886 | |
@@ -1895,8 +1923,10 @@ discard block |
||
| 1895 | 1923 | } |
| 1896 | 1924 | |
| 1897 | 1925 | foreach ( get_taxonomies( array() , 'objects' ) as $taxonomy => $t ) { |
| 1898 | - if ( 'post_tag' == $taxonomy ) |
|
| 1899 | - continue; // Handled further down in the $q['tag'] block |
|
| 1926 | + if ( 'post_tag' == $taxonomy ) { |
|
| 1927 | + continue; |
|
| 1928 | + } |
|
| 1929 | + // Handled further down in the $q['tag'] block |
|
| 1900 | 1930 | |
| 1901 | 1931 | if ( $t->query_var && !empty( $q[$t->query_var] ) ) { |
| 1902 | 1932 | $tax_query_defaults = array( |
@@ -1943,10 +1973,11 @@ discard block |
||
| 1943 | 1973 | $q['cat'] = implode( ',', $cat_array ); |
| 1944 | 1974 | |
| 1945 | 1975 | foreach ( $cat_array as $cat ) { |
| 1946 | - if ( $cat > 0 ) |
|
| 1947 | - $cat_in[] = $cat; |
|
| 1948 | - elseif ( $cat < 0 ) |
|
| 1949 | - $cat_not_in[] = abs( $cat ); |
|
| 1976 | + if ( $cat > 0 ) { |
|
| 1977 | + $cat_in[] = $cat; |
|
| 1978 | + } elseif ( $cat < 0 ) { |
|
| 1979 | + $cat_not_in[] = abs( $cat ); |
|
| 1980 | + } |
|
| 1950 | 1981 | } |
| 1951 | 1982 | |
| 1952 | 1983 | if ( ! empty( $cat_in ) ) { |
@@ -1972,8 +2003,9 @@ discard block |
||
| 1972 | 2003 | |
| 1973 | 2004 | if ( ! empty( $q['category__and'] ) && 1 === count( (array) $q['category__and'] ) ) { |
| 1974 | 2005 | $q['category__and'] = (array) $q['category__and']; |
| 1975 | - if ( ! isset( $q['category__in'] ) ) |
|
| 1976 | - $q['category__in'] = array(); |
|
| 2006 | + if ( ! isset( $q['category__in'] ) ) { |
|
| 2007 | + $q['category__in'] = array(); |
|
| 2008 | + } |
|
| 1977 | 2009 | $q['category__in'][] = absint( reset( $q['category__and'] ) ); |
| 1978 | 2010 | unset( $q['category__and'] ); |
| 1979 | 2011 | } |
@@ -2116,8 +2148,9 @@ discard block |
||
| 2116 | 2148 | |
| 2117 | 2149 | // added slashes screw with quote grouping when done early, so done later |
| 2118 | 2150 | $q['s'] = stripslashes( $q['s'] ); |
| 2119 | - if ( empty( $_GET['s'] ) && $this->is_main_query() ) |
|
| 2120 | - $q['s'] = urldecode( $q['s'] ); |
|
| 2151 | + if ( empty( $_GET['s'] ) && $this->is_main_query() ) { |
|
| 2152 | + $q['s'] = urldecode( $q['s'] ); |
|
| 2153 | + } |
|
| 2121 | 2154 | // there are no line breaks in <input /> fields |
| 2122 | 2155 | $q['s'] = str_replace( array( "\r", "\n" ), '', $q['s'] ); |
| 2123 | 2156 | $q['search_terms_count'] = 1; |
@@ -2128,8 +2161,9 @@ discard block |
||
| 2128 | 2161 | $q['search_terms_count'] = count( $matches[0] ); |
| 2129 | 2162 | $q['search_terms'] = $this->parse_search_terms( $matches[0] ); |
| 2130 | 2163 | // if the search string has only short terms or stopwords, or is 10+ terms long, match it as sentence |
| 2131 | - if ( empty( $q['search_terms'] ) || count( $q['search_terms'] ) > 9 ) |
|
| 2132 | - $q['search_terms'] = array( $q['s'] ); |
|
| 2164 | + if ( empty( $q['search_terms'] ) || count( $q['search_terms'] ) > 9 ) { |
|
| 2165 | + $q['search_terms'] = array( $q['s'] ); |
|
| 2166 | + } |
|
| 2133 | 2167 | } else { |
| 2134 | 2168 | $q['search_terms'] = array( $q['s'] ); |
| 2135 | 2169 | } |
@@ -2162,8 +2196,9 @@ discard block |
||
| 2162 | 2196 | |
| 2163 | 2197 | if ( ! empty( $search ) ) { |
| 2164 | 2198 | $search = " AND ({$search}) "; |
| 2165 | - if ( ! is_user_logged_in() ) |
|
| 2166 | - $search .= " AND ($wpdb->posts.post_password = '') "; |
|
| 2199 | + if ( ! is_user_logged_in() ) { |
|
| 2200 | + $search .= " AND ($wpdb->posts.post_password = '') "; |
|
| 2201 | + } |
|
| 2167 | 2202 | } |
| 2168 | 2203 | |
| 2169 | 2204 | return $search; |
@@ -2189,17 +2224,20 @@ discard block |
||
| 2189 | 2224 | |
| 2190 | 2225 | foreach ( $terms as $term ) { |
| 2191 | 2226 | // keep before/after spaces when term is for exact match |
| 2192 | - if ( preg_match( '/^".+"$/', $term ) ) |
|
| 2193 | - $term = trim( $term, "\"'" ); |
|
| 2194 | - else |
|
| 2195 | - $term = trim( $term, "\"' " ); |
|
| 2227 | + if ( preg_match( '/^".+"$/', $term ) ) { |
|
| 2228 | + $term = trim( $term, "\"'" ); |
|
| 2229 | + } else { |
|
| 2230 | + $term = trim( $term, "\"' " ); |
|
| 2231 | + } |
|
| 2196 | 2232 | |
| 2197 | 2233 | // Avoid single A-Z and single dashes. |
| 2198 | - if ( ! $term || ( 1 === strlen( $term ) && preg_match( '/^[a-z\-]$/i', $term ) ) ) |
|
| 2199 | - continue; |
|
| 2234 | + if ( ! $term || ( 1 === strlen( $term ) && preg_match( '/^[a-z\-]$/i', $term ) ) ) { |
|
| 2235 | + continue; |
|
| 2236 | + } |
|
| 2200 | 2237 | |
| 2201 | - if ( in_array( call_user_func( $strtolower, $term ), $stopwords, true ) ) |
|
| 2202 | - continue; |
|
| 2238 | + if ( in_array( call_user_func( $strtolower, $term ), $stopwords, true ) ) { |
|
| 2239 | + continue; |
|
| 2240 | + } |
|
| 2203 | 2241 | |
| 2204 | 2242 | $checked[] = $term; |
| 2205 | 2243 | } |
@@ -2215,8 +2253,9 @@ discard block |
||
| 2215 | 2253 | * @return array Stopwords. |
| 2216 | 2254 | */ |
| 2217 | 2255 | protected function get_search_stopwords() { |
| 2218 | - if ( isset( $this->stopwords ) ) |
|
| 2219 | - return $this->stopwords; |
|
| 2256 | + if ( isset( $this->stopwords ) ) { |
|
| 2257 | + return $this->stopwords; |
|
| 2258 | + } |
|
| 2220 | 2259 | |
| 2221 | 2260 | /* translators: This is a comma-separated list of very common words that should be excluded from a search, |
| 2222 | 2261 | * like a, an, and the. These are usually called "stopwords". You should not simply translate these individual |
@@ -2228,8 +2267,9 @@ discard block |
||
| 2228 | 2267 | $stopwords = array(); |
| 2229 | 2268 | foreach ( $words as $word ) { |
| 2230 | 2269 | $word = trim( $word, "\r\n\t " ); |
| 2231 | - if ( $word ) |
|
| 2232 | - $stopwords[] = $word; |
|
| 2270 | + if ( $word ) { |
|
| 2271 | + $stopwords[] = $word; |
|
| 2272 | + } |
|
| 2233 | 2273 | } |
| 2234 | 2274 | |
| 2235 | 2275 | /** |
@@ -2276,8 +2316,9 @@ discard block |
||
| 2276 | 2316 | // all words in title |
| 2277 | 2317 | $search_orderby .= 'WHEN ' . implode( ' AND ', $q['search_orderby_title'] ) . ' THEN 2 '; |
| 2278 | 2318 | // any word in title, not needed when $num_terms == 1 |
| 2279 | - if ( $num_terms > 1 ) |
|
| 2280 | - $search_orderby .= 'WHEN ' . implode( ' OR ', $q['search_orderby_title'] ) . ' THEN 3 '; |
|
| 2319 | + if ( $num_terms > 1 ) { |
|
| 2320 | + $search_orderby .= 'WHEN ' . implode( ' OR ', $q['search_orderby_title'] ) . ' THEN 3 '; |
|
| 2321 | + } |
|
| 2281 | 2322 | } |
| 2282 | 2323 | |
| 2283 | 2324 | // Sentence match in 'post_content' and 'post_excerpt'. |
@@ -2524,34 +2565,41 @@ discard block |
||
| 2524 | 2565 | |
| 2525 | 2566 | if ( isset( $q['caller_get_posts'] ) ) { |
| 2526 | 2567 | _deprecated_argument( 'WP_Query', '3.1', __( '"caller_get_posts" is deprecated. Use "ignore_sticky_posts" instead.' ) ); |
| 2527 | - if ( !isset( $q['ignore_sticky_posts'] ) ) |
|
| 2528 | - $q['ignore_sticky_posts'] = $q['caller_get_posts']; |
|
| 2568 | + if ( !isset( $q['ignore_sticky_posts'] ) ) { |
|
| 2569 | + $q['ignore_sticky_posts'] = $q['caller_get_posts']; |
|
| 2570 | + } |
|
| 2529 | 2571 | } |
| 2530 | 2572 | |
| 2531 | - if ( !isset( $q['ignore_sticky_posts'] ) ) |
|
| 2532 | - $q['ignore_sticky_posts'] = false; |
|
| 2573 | + if ( !isset( $q['ignore_sticky_posts'] ) ) { |
|
| 2574 | + $q['ignore_sticky_posts'] = false; |
|
| 2575 | + } |
|
| 2533 | 2576 | |
| 2534 | - if ( !isset($q['suppress_filters']) ) |
|
| 2535 | - $q['suppress_filters'] = false; |
|
| 2577 | + if ( !isset($q['suppress_filters']) ) { |
|
| 2578 | + $q['suppress_filters'] = false; |
|
| 2579 | + } |
|
| 2536 | 2580 | |
| 2537 | 2581 | if ( !isset($q['cache_results']) ) { |
| 2538 | - if ( wp_using_ext_object_cache() ) |
|
| 2539 | - $q['cache_results'] = false; |
|
| 2540 | - else |
|
| 2541 | - $q['cache_results'] = true; |
|
| 2582 | + if ( wp_using_ext_object_cache() ) { |
|
| 2583 | + $q['cache_results'] = false; |
|
| 2584 | + } else { |
|
| 2585 | + $q['cache_results'] = true; |
|
| 2586 | + } |
|
| 2542 | 2587 | } |
| 2543 | 2588 | |
| 2544 | - if ( !isset($q['update_post_term_cache']) ) |
|
| 2545 | - $q['update_post_term_cache'] = true; |
|
| 2589 | + if ( !isset($q['update_post_term_cache']) ) { |
|
| 2590 | + $q['update_post_term_cache'] = true; |
|
| 2591 | + } |
|
| 2546 | 2592 | |
| 2547 | - if ( !isset($q['update_post_meta_cache']) ) |
|
| 2548 | - $q['update_post_meta_cache'] = true; |
|
| 2593 | + if ( !isset($q['update_post_meta_cache']) ) { |
|
| 2594 | + $q['update_post_meta_cache'] = true; |
|
| 2595 | + } |
|
| 2549 | 2596 | |
| 2550 | 2597 | if ( !isset($q['post_type']) ) { |
| 2551 | - if ( $this->is_search ) |
|
| 2552 | - $q['post_type'] = 'any'; |
|
| 2553 | - else |
|
| 2554 | - $q['post_type'] = ''; |
|
| 2598 | + if ( $this->is_search ) { |
|
| 2599 | + $q['post_type'] = 'any'; |
|
| 2600 | + } else { |
|
| 2601 | + $q['post_type'] = ''; |
|
| 2602 | + } |
|
| 2555 | 2603 | } |
| 2556 | 2604 | $post_type = $q['post_type']; |
| 2557 | 2605 | if ( empty( $q['posts_per_page'] ) ) { |
@@ -2561,8 +2609,9 @@ discard block |
||
| 2561 | 2609 | $q['showposts'] = (int) $q['showposts']; |
| 2562 | 2610 | $q['posts_per_page'] = $q['showposts']; |
| 2563 | 2611 | } |
| 2564 | - if ( (isset($q['posts_per_archive_page']) && $q['posts_per_archive_page'] != 0) && ($this->is_archive || $this->is_search) ) |
|
| 2565 | - $q['posts_per_page'] = $q['posts_per_archive_page']; |
|
| 2612 | + if ( (isset($q['posts_per_archive_page']) && $q['posts_per_archive_page'] != 0) && ($this->is_archive || $this->is_search) ) { |
|
| 2613 | + $q['posts_per_page'] = $q['posts_per_archive_page']; |
|
| 2614 | + } |
|
| 2566 | 2615 | if ( !isset($q['nopaging']) ) { |
| 2567 | 2616 | if ( $q['posts_per_page'] == -1 ) { |
| 2568 | 2617 | $q['nopaging'] = true; |
@@ -2581,13 +2630,15 @@ discard block |
||
| 2581 | 2630 | $q['nopaging'] = false; |
| 2582 | 2631 | } |
| 2583 | 2632 | $q['posts_per_page'] = (int) $q['posts_per_page']; |
| 2584 | - if ( $q['posts_per_page'] < -1 ) |
|
| 2585 | - $q['posts_per_page'] = abs($q['posts_per_page']); |
|
| 2586 | - elseif ( $q['posts_per_page'] == 0 ) |
|
| 2587 | - $q['posts_per_page'] = 1; |
|
| 2633 | + if ( $q['posts_per_page'] < -1 ) { |
|
| 2634 | + $q['posts_per_page'] = abs($q['posts_per_page']); |
|
| 2635 | + } elseif ( $q['posts_per_page'] == 0 ) { |
|
| 2636 | + $q['posts_per_page'] = 1; |
|
| 2637 | + } |
|
| 2588 | 2638 | |
| 2589 | - if ( !isset($q['comments_per_page']) || $q['comments_per_page'] == 0 ) |
|
| 2590 | - $q['comments_per_page'] = get_option('comments_per_page'); |
|
| 2639 | + if ( !isset($q['comments_per_page']) || $q['comments_per_page'] == 0 ) { |
|
| 2640 | + $q['comments_per_page'] = get_option('comments_per_page'); |
|
| 2641 | + } |
|
| 2591 | 2642 | |
| 2592 | 2643 | if ( $this->is_home && (empty($this->query) || $q['preview'] == 'true') && ( 'page' == get_option('show_on_front') ) && get_option('page_on_front') ) { |
| 2593 | 2644 | $this->is_page = true; |
@@ -2601,10 +2652,11 @@ discard block |
||
| 2601 | 2652 | } |
| 2602 | 2653 | |
| 2603 | 2654 | // If true, forcibly turns off SQL_CALC_FOUND_ROWS even when limits are present. |
| 2604 | - if ( isset($q['no_found_rows']) ) |
|
| 2605 | - $q['no_found_rows'] = (bool) $q['no_found_rows']; |
|
| 2606 | - else |
|
| 2607 | - $q['no_found_rows'] = false; |
|
| 2655 | + if ( isset($q['no_found_rows']) ) { |
|
| 2656 | + $q['no_found_rows'] = (bool) $q['no_found_rows']; |
|
| 2657 | + } else { |
|
| 2658 | + $q['no_found_rows'] = false; |
|
| 2659 | + } |
|
| 2608 | 2660 | |
| 2609 | 2661 | switch ( $q['fields'] ) { |
| 2610 | 2662 | case 'ids': |
@@ -2617,47 +2669,60 @@ discard block |
||
| 2617 | 2669 | $fields = "$wpdb->posts.*"; |
| 2618 | 2670 | } |
| 2619 | 2671 | |
| 2620 | - if ( '' !== $q['menu_order'] ) |
|
| 2621 | - $where .= " AND $wpdb->posts.menu_order = " . $q['menu_order']; |
|
| 2672 | + if ( '' !== $q['menu_order'] ) { |
|
| 2673 | + $where .= " AND $wpdb->posts.menu_order = " . $q['menu_order']; |
|
| 2674 | + } |
|
| 2622 | 2675 | |
| 2623 | 2676 | // The "m" parameter is meant for months but accepts datetimes of varying specificity |
| 2624 | 2677 | if ( $q['m'] ) { |
| 2625 | 2678 | $where .= " AND YEAR($wpdb->posts.post_date)=" . substr($q['m'], 0, 4); |
| 2626 | - if ( strlen($q['m']) > 5 ) |
|
| 2627 | - $where .= " AND MONTH($wpdb->posts.post_date)=" . substr($q['m'], 4, 2); |
|
| 2628 | - if ( strlen($q['m']) > 7 ) |
|
| 2629 | - $where .= " AND DAYOFMONTH($wpdb->posts.post_date)=" . substr($q['m'], 6, 2); |
|
| 2630 | - if ( strlen($q['m']) > 9 ) |
|
| 2631 | - $where .= " AND HOUR($wpdb->posts.post_date)=" . substr($q['m'], 8, 2); |
|
| 2632 | - if ( strlen($q['m']) > 11 ) |
|
| 2633 | - $where .= " AND MINUTE($wpdb->posts.post_date)=" . substr($q['m'], 10, 2); |
|
| 2634 | - if ( strlen($q['m']) > 13 ) |
|
| 2635 | - $where .= " AND SECOND($wpdb->posts.post_date)=" . substr($q['m'], 12, 2); |
|
| 2679 | + if ( strlen($q['m']) > 5 ) { |
|
| 2680 | + $where .= " AND MONTH($wpdb->posts.post_date)=" . substr($q['m'], 4, 2); |
|
| 2681 | + } |
|
| 2682 | + if ( strlen($q['m']) > 7 ) { |
|
| 2683 | + $where .= " AND DAYOFMONTH($wpdb->posts.post_date)=" . substr($q['m'], 6, 2); |
|
| 2684 | + } |
|
| 2685 | + if ( strlen($q['m']) > 9 ) { |
|
| 2686 | + $where .= " AND HOUR($wpdb->posts.post_date)=" . substr($q['m'], 8, 2); |
|
| 2687 | + } |
|
| 2688 | + if ( strlen($q['m']) > 11 ) { |
|
| 2689 | + $where .= " AND MINUTE($wpdb->posts.post_date)=" . substr($q['m'], 10, 2); |
|
| 2690 | + } |
|
| 2691 | + if ( strlen($q['m']) > 13 ) { |
|
| 2692 | + $where .= " AND SECOND($wpdb->posts.post_date)=" . substr($q['m'], 12, 2); |
|
| 2693 | + } |
|
| 2636 | 2694 | } |
| 2637 | 2695 | |
| 2638 | 2696 | // Handle the other individual date parameters |
| 2639 | 2697 | $date_parameters = array(); |
| 2640 | 2698 | |
| 2641 | - if ( '' !== $q['hour'] ) |
|
| 2642 | - $date_parameters['hour'] = $q['hour']; |
|
| 2699 | + if ( '' !== $q['hour'] ) { |
|
| 2700 | + $date_parameters['hour'] = $q['hour']; |
|
| 2701 | + } |
|
| 2643 | 2702 | |
| 2644 | - if ( '' !== $q['minute'] ) |
|
| 2645 | - $date_parameters['minute'] = $q['minute']; |
|
| 2703 | + if ( '' !== $q['minute'] ) { |
|
| 2704 | + $date_parameters['minute'] = $q['minute']; |
|
| 2705 | + } |
|
| 2646 | 2706 | |
| 2647 | - if ( '' !== $q['second'] ) |
|
| 2648 | - $date_parameters['second'] = $q['second']; |
|
| 2707 | + if ( '' !== $q['second'] ) { |
|
| 2708 | + $date_parameters['second'] = $q['second']; |
|
| 2709 | + } |
|
| 2649 | 2710 | |
| 2650 | - if ( $q['year'] ) |
|
| 2651 | - $date_parameters['year'] = $q['year']; |
|
| 2711 | + if ( $q['year'] ) { |
|
| 2712 | + $date_parameters['year'] = $q['year']; |
|
| 2713 | + } |
|
| 2652 | 2714 | |
| 2653 | - if ( $q['monthnum'] ) |
|
| 2654 | - $date_parameters['monthnum'] = $q['monthnum']; |
|
| 2715 | + if ( $q['monthnum'] ) { |
|
| 2716 | + $date_parameters['monthnum'] = $q['monthnum']; |
|
| 2717 | + } |
|
| 2655 | 2718 | |
| 2656 | - if ( $q['w'] ) |
|
| 2657 | - $date_parameters['week'] = $q['w']; |
|
| 2719 | + if ( $q['w'] ) { |
|
| 2720 | + $date_parameters['week'] = $q['w']; |
|
| 2721 | + } |
|
| 2658 | 2722 | |
| 2659 | - if ( $q['day'] ) |
|
| 2660 | - $date_parameters['day'] = $q['day']; |
|
| 2723 | + if ( $q['day'] ) { |
|
| 2724 | + $date_parameters['day'] = $q['day']; |
|
| 2725 | + } |
|
| 2661 | 2726 | |
| 2662 | 2727 | if ( $date_parameters ) { |
| 2663 | 2728 | $date_query = new WP_Date_Query( array( $date_parameters ) ); |
@@ -2676,8 +2741,9 @@ discard block |
||
| 2676 | 2741 | if ( !empty($q['post_type']) && 'any' != $q['post_type'] ) { |
| 2677 | 2742 | foreach ( (array)$q['post_type'] as $_post_type ) { |
| 2678 | 2743 | $ptype_obj = get_post_type_object($_post_type); |
| 2679 | - if ( !$ptype_obj || !$ptype_obj->query_var || empty($q[ $ptype_obj->query_var ]) ) |
|
| 2680 | - continue; |
|
| 2744 | + if ( !$ptype_obj || !$ptype_obj->query_var || empty($q[ $ptype_obj->query_var ]) ) { |
|
| 2745 | + continue; |
|
| 2746 | + } |
|
| 2681 | 2747 | |
| 2682 | 2748 | if ( ! $ptype_obj->hierarchical ) { |
| 2683 | 2749 | // Non-hierarchical post types can directly use 'name'. |
@@ -2709,21 +2775,24 @@ discard block |
||
| 2709 | 2775 | if ( 'page' != $q['post_type'] ) { |
| 2710 | 2776 | foreach ( (array)$q['post_type'] as $_post_type ) { |
| 2711 | 2777 | $ptype_obj = get_post_type_object($_post_type); |
| 2712 | - if ( !$ptype_obj || !$ptype_obj->hierarchical ) |
|
| 2713 | - continue; |
|
| 2778 | + if ( !$ptype_obj || !$ptype_obj->hierarchical ) { |
|
| 2779 | + continue; |
|
| 2780 | + } |
|
| 2714 | 2781 | |
| 2715 | 2782 | $reqpage = get_page_by_path($q['pagename'], OBJECT, $_post_type); |
| 2716 | - if ( $reqpage ) |
|
| 2717 | - break; |
|
| 2783 | + if ( $reqpage ) { |
|
| 2784 | + break; |
|
| 2785 | + } |
|
| 2718 | 2786 | } |
| 2719 | 2787 | unset($ptype_obj); |
| 2720 | 2788 | } else { |
| 2721 | 2789 | $reqpage = get_page_by_path($q['pagename']); |
| 2722 | 2790 | } |
| 2723 | - if ( !empty($reqpage) ) |
|
| 2724 | - $reqpage = $reqpage->ID; |
|
| 2725 | - else |
|
| 2726 | - $reqpage = 0; |
|
| 2791 | + if ( !empty($reqpage) ) { |
|
| 2792 | + $reqpage = $reqpage->ID; |
|
| 2793 | + } else { |
|
| 2794 | + $reqpage = 0; |
|
| 2795 | + } |
|
| 2727 | 2796 | } |
| 2728 | 2797 | |
| 2729 | 2798 | $page_for_posts = get_option('page_for_posts'); |
@@ -2749,8 +2818,9 @@ discard block |
||
| 2749 | 2818 | } |
| 2750 | 2819 | |
| 2751 | 2820 | // If an attachment is requested by number, let it supersede any post number. |
| 2752 | - if ( $q['attachment_id'] ) |
|
| 2753 | - $q['p'] = absint($q['attachment_id']); |
|
| 2821 | + if ( $q['attachment_id'] ) { |
|
| 2822 | + $q['p'] = absint($q['attachment_id']); |
|
| 2823 | + } |
|
| 2754 | 2824 | |
| 2755 | 2825 | // If a post number is specified, load that post |
| 2756 | 2826 | if ( $q['p'] ) { |
@@ -2814,13 +2884,15 @@ discard block |
||
| 2814 | 2884 | $taxonomies = array_keys( $this->tax_query->queried_terms ); |
| 2815 | 2885 | foreach ( get_post_types( array( 'exclude_from_search' => false ) ) as $pt ) { |
| 2816 | 2886 | $object_taxonomies = $pt === 'attachment' ? get_taxonomies_for_attachments() : get_object_taxonomies( $pt ); |
| 2817 | - if ( array_intersect( $taxonomies, $object_taxonomies ) ) |
|
| 2818 | - $post_type[] = $pt; |
|
| 2887 | + if ( array_intersect( $taxonomies, $object_taxonomies ) ) { |
|
| 2888 | + $post_type[] = $pt; |
|
| 2889 | + } |
|
| 2890 | + } |
|
| 2891 | + if ( ! $post_type ) { |
|
| 2892 | + $post_type = 'any'; |
|
| 2893 | + } elseif ( count( $post_type ) == 1 ) { |
|
| 2894 | + $post_type = $post_type[0]; |
|
| 2819 | 2895 | } |
| 2820 | - if ( ! $post_type ) |
|
| 2821 | - $post_type = 'any'; |
|
| 2822 | - elseif ( count( $post_type ) == 1 ) |
|
| 2823 | - $post_type = $post_type[0]; |
|
| 2824 | 2896 | |
| 2825 | 2897 | $post_status_join = true; |
| 2826 | 2898 | } elseif ( in_array('attachment', (array) $post_type) ) { |
@@ -2921,15 +2993,17 @@ discard block |
||
| 2921 | 2993 | } |
| 2922 | 2994 | $q['author_name'] = sanitize_title_for_query( $q['author_name'] ); |
| 2923 | 2995 | $q['author'] = get_user_by('slug', $q['author_name']); |
| 2924 | - if ( $q['author'] ) |
|
| 2925 | - $q['author'] = $q['author']->ID; |
|
| 2996 | + if ( $q['author'] ) { |
|
| 2997 | + $q['author'] = $q['author']->ID; |
|
| 2998 | + } |
|
| 2926 | 2999 | $whichauthor .= " AND ($wpdb->posts.post_author = " . absint($q['author']) . ')'; |
| 2927 | 3000 | } |
| 2928 | 3001 | |
| 2929 | 3002 | // MIME-Type stuff for attachment browsing |
| 2930 | 3003 | |
| 2931 | - if ( isset( $q['post_mime_type'] ) && '' != $q['post_mime_type'] ) |
|
| 2932 | - $whichmimetype = wp_post_mime_type_where( $q['post_mime_type'], $wpdb->posts ); |
|
| 3004 | + if ( isset( $q['post_mime_type'] ) && '' != $q['post_mime_type'] ) { |
|
| 3005 | + $whichmimetype = wp_post_mime_type_where( $q['post_mime_type'], $wpdb->posts ); |
|
| 3006 | + } |
|
| 2933 | 3007 | |
| 2934 | 3008 | $where .= $search . $whichauthor . $whichmimetype; |
| 2935 | 3009 | |
@@ -3004,8 +3078,9 @@ discard block |
||
| 3004 | 3078 | // Order search results by relevance only when another "orderby" is not specified in the query. |
| 3005 | 3079 | if ( ! empty( $q['s'] ) ) { |
| 3006 | 3080 | $search_orderby = ''; |
| 3007 | - if ( ! empty( $q['search_orderby_title'] ) && ( empty( $q['orderby'] ) && ! $this->is_feed ) || ( isset( $q['orderby'] ) && 'relevance' === $q['orderby'] ) ) |
|
| 3008 | - $search_orderby = $this->parse_search_order( $q ); |
|
| 3081 | + if ( ! empty( $q['search_orderby_title'] ) && ( empty( $q['orderby'] ) && ! $this->is_feed ) || ( isset( $q['orderby'] ) && 'relevance' === $q['orderby'] ) ) { |
|
| 3082 | + $search_orderby = $this->parse_search_order( $q ); |
|
| 3083 | + } |
|
| 3009 | 3084 | |
| 3010 | 3085 | if ( ! $q['suppress_filters'] ) { |
| 3011 | 3086 | /** |
@@ -3019,18 +3094,21 @@ discard block |
||
| 3019 | 3094 | $search_orderby = apply_filters( 'posts_search_orderby', $search_orderby, $this ); |
| 3020 | 3095 | } |
| 3021 | 3096 | |
| 3022 | - if ( $search_orderby ) |
|
| 3023 | - $orderby = $orderby ? $search_orderby . ', ' . $orderby : $search_orderby; |
|
| 3097 | + if ( $search_orderby ) { |
|
| 3098 | + $orderby = $orderby ? $search_orderby . ', ' . $orderby : $search_orderby; |
|
| 3099 | + } |
|
| 3024 | 3100 | } |
| 3025 | 3101 | |
| 3026 | 3102 | if ( is_array( $post_type ) && count( $post_type ) > 1 ) { |
| 3027 | 3103 | $post_type_cap = 'multiple_post_type'; |
| 3028 | 3104 | } else { |
| 3029 | - if ( is_array( $post_type ) ) |
|
| 3030 | - $post_type = reset( $post_type ); |
|
| 3105 | + if ( is_array( $post_type ) ) { |
|
| 3106 | + $post_type = reset( $post_type ); |
|
| 3107 | + } |
|
| 3031 | 3108 | $post_type_object = get_post_type_object( $post_type ); |
| 3032 | - if ( empty( $post_type_object ) ) |
|
| 3033 | - $post_type_cap = $post_type; |
|
| 3109 | + if ( empty( $post_type_object ) ) { |
|
| 3110 | + $post_type_cap = $post_type; |
|
| 3111 | + } |
|
| 3034 | 3112 | } |
| 3035 | 3113 | |
| 3036 | 3114 | if ( isset( $q['post_password'] ) ) { |
@@ -3052,10 +3130,11 @@ discard block |
||
| 3052 | 3130 | |
| 3053 | 3131 | if ( 'any' == $post_type ) { |
| 3054 | 3132 | $in_search_post_types = get_post_types( array('exclude_from_search' => false) ); |
| 3055 | - if ( empty( $in_search_post_types ) ) |
|
| 3056 | - $where .= ' AND 1=0 '; |
|
| 3057 | - else |
|
| 3058 | - $where .= " AND $wpdb->posts.post_type IN ('" . join("', '", $in_search_post_types ) . "')"; |
|
| 3133 | + if ( empty( $in_search_post_types ) ) { |
|
| 3134 | + $where .= ' AND 1=0 '; |
|
| 3135 | + } else { |
|
| 3136 | + $where .= " AND $wpdb->posts.post_type IN ('" . join("', '", $in_search_post_types ) . "')"; |
|
| 3137 | + } |
|
| 3059 | 3138 | } elseif ( !empty( $post_type ) && is_array( $post_type ) ) { |
| 3060 | 3139 | $where .= " AND $wpdb->posts.post_type IN ('" . join("', '", $post_type) . "')"; |
| 3061 | 3140 | } elseif ( ! empty( $post_type ) ) { |
@@ -3089,8 +3168,9 @@ discard block |
||
| 3089 | 3168 | if ( ! empty( $q['post_status'] ) ) { |
| 3090 | 3169 | $statuswheres = array(); |
| 3091 | 3170 | $q_status = $q['post_status']; |
| 3092 | - if ( ! is_array( $q_status ) ) |
|
| 3093 | - $q_status = explode(',', $q_status); |
|
| 3171 | + if ( ! is_array( $q_status ) ) { |
|
| 3172 | + $q_status = explode(',', $q_status); |
|
| 3173 | + } |
|
| 3094 | 3174 | $r_status = array(); |
| 3095 | 3175 | $p_status = array(); |
| 3096 | 3176 | $e_status = array(); |
@@ -3103,10 +3183,11 @@ discard block |
||
| 3103 | 3183 | } else { |
| 3104 | 3184 | foreach ( get_post_stati() as $status ) { |
| 3105 | 3185 | if ( in_array( $status, $q_status ) ) { |
| 3106 | - if ( 'private' == $status ) |
|
| 3107 | - $p_status[] = "$wpdb->posts.post_status = '$status'"; |
|
| 3108 | - else |
|
| 3109 | - $r_status[] = "$wpdb->posts.post_status = '$status'"; |
|
| 3186 | + if ( 'private' == $status ) { |
|
| 3187 | + $p_status[] = "$wpdb->posts.post_status = '$status'"; |
|
| 3188 | + } else { |
|
| 3189 | + $r_status[] = "$wpdb->posts.post_status = '$status'"; |
|
| 3190 | + } |
|
| 3110 | 3191 | } |
| 3111 | 3192 | } |
| 3112 | 3193 | } |
@@ -3120,21 +3201,24 @@ discard block |
||
| 3120 | 3201 | $statuswheres[] = "(" . join( ' AND ', $e_status ) . ")"; |
| 3121 | 3202 | } |
| 3122 | 3203 | if ( !empty($r_status) ) { |
| 3123 | - if ( !empty($q['perm'] ) && 'editable' == $q['perm'] && !current_user_can($edit_others_cap) ) |
|
| 3124 | - $statuswheres[] = "($wpdb->posts.post_author = $user_id " . "AND (" . join( ' OR ', $r_status ) . "))"; |
|
| 3125 | - else |
|
| 3126 | - $statuswheres[] = "(" . join( ' OR ', $r_status ) . ")"; |
|
| 3204 | + if ( !empty($q['perm'] ) && 'editable' == $q['perm'] && !current_user_can($edit_others_cap) ) { |
|
| 3205 | + $statuswheres[] = "($wpdb->posts.post_author = $user_id " . "AND (" . join( ' OR ', $r_status ) . "))"; |
|
| 3206 | + } else { |
|
| 3207 | + $statuswheres[] = "(" . join( ' OR ', $r_status ) . ")"; |
|
| 3208 | + } |
|
| 3127 | 3209 | } |
| 3128 | 3210 | if ( !empty($p_status) ) { |
| 3129 | - if ( !empty($q['perm'] ) && 'readable' == $q['perm'] && !current_user_can($read_private_cap) ) |
|
| 3130 | - $statuswheres[] = "($wpdb->posts.post_author = $user_id " . "AND (" . join( ' OR ', $p_status ) . "))"; |
|
| 3131 | - else |
|
| 3132 | - $statuswheres[] = "(" . join( ' OR ', $p_status ) . ")"; |
|
| 3211 | + if ( !empty($q['perm'] ) && 'readable' == $q['perm'] && !current_user_can($read_private_cap) ) { |
|
| 3212 | + $statuswheres[] = "($wpdb->posts.post_author = $user_id " . "AND (" . join( ' OR ', $p_status ) . "))"; |
|
| 3213 | + } else { |
|
| 3214 | + $statuswheres[] = "(" . join( ' OR ', $p_status ) . ")"; |
|
| 3215 | + } |
|
| 3133 | 3216 | } |
| 3134 | 3217 | if ( $post_status_join ) { |
| 3135 | 3218 | $join .= " LEFT JOIN $wpdb->posts AS p2 ON ($wpdb->posts.post_parent = p2.ID) "; |
| 3136 | - foreach ( $statuswheres as $index => $statuswhere ) |
|
| 3137 | - $statuswheres[$index] = "($statuswhere OR ($wpdb->posts.post_status = 'inherit' AND " . str_replace($wpdb->posts, 'p2', $statuswhere) . "))"; |
|
| 3219 | + foreach ( $statuswheres as $index => $statuswhere ) { |
|
| 3220 | + $statuswheres[$index] = "($statuswhere OR ($wpdb->posts.post_status = 'inherit' AND " . str_replace($wpdb->posts, 'p2', $statuswhere) . "))"; |
|
| 3221 | + } |
|
| 3138 | 3222 | } |
| 3139 | 3223 | $where_status = implode( ' OR ', $statuswheres ); |
| 3140 | 3224 | if ( ! empty( $where_status ) ) { |
@@ -3146,23 +3230,27 @@ discard block |
||
| 3146 | 3230 | // Add public states. |
| 3147 | 3231 | $public_states = get_post_stati( array('public' => true) ); |
| 3148 | 3232 | foreach ( (array) $public_states as $state ) { |
| 3149 | - if ( 'publish' == $state ) // Publish is hard-coded above. |
|
| 3233 | + if ( 'publish' == $state ) { |
|
| 3234 | + // Publish is hard-coded above. |
|
| 3150 | 3235 | continue; |
| 3236 | + } |
|
| 3151 | 3237 | $where .= " OR $wpdb->posts.post_status = '$state'"; |
| 3152 | 3238 | } |
| 3153 | 3239 | |
| 3154 | 3240 | if ( $this->is_admin ) { |
| 3155 | 3241 | // Add protected states that should show in the admin all list. |
| 3156 | 3242 | $admin_all_states = get_post_stati( array('protected' => true, 'show_in_admin_all_list' => true) ); |
| 3157 | - foreach ( (array) $admin_all_states as $state ) |
|
| 3158 | - $where .= " OR $wpdb->posts.post_status = '$state'"; |
|
| 3243 | + foreach ( (array) $admin_all_states as $state ) { |
|
| 3244 | + $where .= " OR $wpdb->posts.post_status = '$state'"; |
|
| 3245 | + } |
|
| 3159 | 3246 | } |
| 3160 | 3247 | |
| 3161 | 3248 | if ( is_user_logged_in() ) { |
| 3162 | 3249 | // Add private states that are limited to viewing by the author of a post or someone who has caps to read private states. |
| 3163 | 3250 | $private_states = get_post_stati( array('private' => true) ); |
| 3164 | - foreach ( (array) $private_states as $state ) |
|
| 3165 | - $where .= current_user_can( $read_private_cap ) ? " OR $wpdb->posts.post_status = '$state'" : " OR $wpdb->posts.post_author = $user_id AND $wpdb->posts.post_status = '$state'"; |
|
| 3251 | + foreach ( (array) $private_states as $state ) { |
|
| 3252 | + $where .= current_user_can( $read_private_cap ) ? " OR $wpdb->posts.post_status = '$state'" : " OR $wpdb->posts.post_author = $user_id AND $wpdb->posts.post_status = '$state'"; |
|
| 3253 | + } |
|
| 3166 | 3254 | } |
| 3167 | 3255 | |
| 3168 | 3256 | $where .= ')'; |
@@ -3197,8 +3285,9 @@ discard block |
||
| 3197 | 3285 | // Paging |
| 3198 | 3286 | if ( empty($q['nopaging']) && !$this->is_singular ) { |
| 3199 | 3287 | $page = absint($q['paged']); |
| 3200 | - if ( !$page ) |
|
| 3201 | - $page = 1; |
|
| 3288 | + if ( !$page ) { |
|
| 3289 | + $page = 1; |
|
| 3290 | + } |
|
| 3202 | 3291 | |
| 3203 | 3292 | // If 'offset' is provided, it takes precedence over 'paged'. |
| 3204 | 3293 | if ( isset( $q['offset'] ) && is_numeric( $q['offset'] ) ) { |
@@ -3283,15 +3372,17 @@ discard block |
||
| 3283 | 3372 | |
| 3284 | 3373 | $post_ids = array(); |
| 3285 | 3374 | |
| 3286 | - foreach ( $this->comments as $comment ) |
|
| 3287 | - $post_ids[] = (int) $comment->comment_post_ID; |
|
| 3375 | + foreach ( $this->comments as $comment ) { |
|
| 3376 | + $post_ids[] = (int) $comment->comment_post_ID; |
|
| 3377 | + } |
|
| 3288 | 3378 | |
| 3289 | 3379 | $post_ids = join(',', $post_ids); |
| 3290 | 3380 | $join = ''; |
| 3291 | - if ( $post_ids ) |
|
| 3292 | - $where = "AND $wpdb->posts.ID IN ($post_ids) "; |
|
| 3293 | - else |
|
| 3294 | - $where = "AND 0"; |
|
| 3381 | + if ( $post_ids ) { |
|
| 3382 | + $where = "AND $wpdb->posts.ID IN ($post_ids) "; |
|
| 3383 | + } else { |
|
| 3384 | + $where = "AND 0"; |
|
| 3385 | + } |
|
| 3295 | 3386 | } |
| 3296 | 3387 | |
| 3297 | 3388 | $pieces = array( 'where', 'groupby', 'join', 'orderby', 'distinct', 'fields', 'limits' ); |
@@ -3521,14 +3612,17 @@ discard block |
||
| 3521 | 3612 | $limits = isset( $clauses[ 'limits' ] ) ? $clauses[ 'limits' ] : ''; |
| 3522 | 3613 | } |
| 3523 | 3614 | |
| 3524 | - if ( ! empty($groupby) ) |
|
| 3525 | - $groupby = 'GROUP BY ' . $groupby; |
|
| 3526 | - if ( !empty( $orderby ) ) |
|
| 3527 | - $orderby = 'ORDER BY ' . $orderby; |
|
| 3615 | + if ( ! empty($groupby) ) { |
|
| 3616 | + $groupby = 'GROUP BY ' . $groupby; |
|
| 3617 | + } |
|
| 3618 | + if ( !empty( $orderby ) ) { |
|
| 3619 | + $orderby = 'ORDER BY ' . $orderby; |
|
| 3620 | + } |
|
| 3528 | 3621 | |
| 3529 | 3622 | $found_rows = ''; |
| 3530 | - if ( !$q['no_found_rows'] && !empty($limits) ) |
|
| 3531 | - $found_rows = 'SQL_CALC_FOUND_ROWS'; |
|
| 3623 | + if ( !$q['no_found_rows'] && !empty($limits) ) { |
|
| 3624 | + $found_rows = 'SQL_CALC_FOUND_ROWS'; |
|
| 3625 | + } |
|
| 3532 | 3626 | |
| 3533 | 3627 | $this->request = $old_request = "SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits"; |
| 3534 | 3628 | |
@@ -3615,8 +3709,9 @@ discard block |
||
| 3615 | 3709 | } |
| 3616 | 3710 | |
| 3617 | 3711 | // Convert to WP_Post objects |
| 3618 | - if ( $this->posts ) |
|
| 3619 | - $this->posts = array_map( 'get_post', $this->posts ); |
|
| 3712 | + if ( $this->posts ) { |
|
| 3713 | + $this->posts = array_map( 'get_post', $this->posts ); |
|
| 3714 | + } |
|
| 3620 | 3715 | |
| 3621 | 3716 | if ( ! $q['suppress_filters'] ) { |
| 3622 | 3717 | /** |
@@ -3678,12 +3773,14 @@ discard block |
||
| 3678 | 3773 | $this->posts = array(); |
| 3679 | 3774 | } else { |
| 3680 | 3775 | $this->is_preview = true; |
| 3681 | - if ( 'future' != $status ) |
|
| 3682 | - $this->posts[0]->post_date = current_time('mysql'); |
|
| 3776 | + if ( 'future' != $status ) { |
|
| 3777 | + $this->posts[0]->post_date = current_time('mysql'); |
|
| 3778 | + } |
|
| 3683 | 3779 | } |
| 3684 | 3780 | } elseif ( $post_status_obj->private ) { |
| 3685 | - if ( ! current_user_can($read_cap, $this->posts[0]->ID) ) |
|
| 3686 | - $this->posts = array(); |
|
| 3781 | + if ( ! current_user_can($read_cap, $this->posts[0]->ID) ) { |
|
| 3782 | + $this->posts = array(); |
|
| 3783 | + } |
|
| 3687 | 3784 | } else { |
| 3688 | 3785 | $this->posts = array(); |
| 3689 | 3786 | } |
@@ -3725,8 +3822,9 @@ discard block |
||
| 3725 | 3822 | } |
| 3726 | 3823 | |
| 3727 | 3824 | // If any posts have been excluded specifically, Ignore those that are sticky. |
| 3728 | - if ( !empty($sticky_posts) && !empty($q['post__not_in']) ) |
|
| 3729 | - $sticky_posts = array_diff($sticky_posts, $q['post__not_in']); |
|
| 3825 | + if ( !empty($sticky_posts) && !empty($q['post__not_in']) ) { |
|
| 3826 | + $sticky_posts = array_diff($sticky_posts, $q['post__not_in']); |
|
| 3827 | + } |
|
| 3730 | 3828 | |
| 3731 | 3829 | // Fetch sticky posts that weren't in the query results |
| 3732 | 3830 | if ( !empty($sticky_posts) ) { |
@@ -3769,8 +3867,9 @@ discard block |
||
| 3769 | 3867 | |
| 3770 | 3868 | $this->posts = array_map( 'get_post', $this->posts ); |
| 3771 | 3869 | |
| 3772 | - if ( $q['cache_results'] ) |
|
| 3773 | - update_post_caches($this->posts, $post_type, $q['update_post_term_cache'], $q['update_post_meta_cache']); |
|
| 3870 | + if ( $q['cache_results'] ) { |
|
| 3871 | + update_post_caches($this->posts, $post_type, $q['update_post_term_cache'], $q['update_post_meta_cache']); |
|
| 3872 | + } |
|
| 3774 | 3873 | |
| 3775 | 3874 | $this->post = reset( $this->posts ); |
| 3776 | 3875 | } else { |
@@ -3802,8 +3901,9 @@ discard block |
||
| 3802 | 3901 | |
| 3803 | 3902 | // Bail if posts is an empty array. Continue if posts is an empty string, |
| 3804 | 3903 | // null, or false to accommodate caching plugins that fill posts later. |
| 3805 | - if ( $q['no_found_rows'] || ( is_array( $this->posts ) && ! $this->posts ) ) |
|
| 3806 | - return; |
|
| 3904 | + if ( $q['no_found_rows'] || ( is_array( $this->posts ) && ! $this->posts ) ) { |
|
| 3905 | + return; |
|
| 3906 | + } |
|
| 3807 | 3907 | |
| 3808 | 3908 | if ( ! empty( $limits ) ) { |
| 3809 | 3909 | /** |
@@ -3829,8 +3929,9 @@ discard block |
||
| 3829 | 3929 | */ |
| 3830 | 3930 | $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) ); |
| 3831 | 3931 | |
| 3832 | - if ( ! empty( $limits ) ) |
|
| 3833 | - $this->max_num_pages = ceil( $this->found_posts / $q['posts_per_page'] ); |
|
| 3932 | + if ( ! empty( $limits ) ) { |
|
| 3933 | + $this->max_num_pages = ceil( $this->found_posts / $q['posts_per_page'] ); |
|
| 3934 | + } |
|
| 3834 | 3935 | } |
| 3835 | 3936 | |
| 3836 | 3937 | /** |
@@ -3864,7 +3965,8 @@ discard block |
||
| 3864 | 3965 | global $post; |
| 3865 | 3966 | $this->in_the_loop = true; |
| 3866 | 3967 | |
| 3867 | - if ( $this->current_post == -1 ) // loop has just started |
|
| 3968 | + if ( $this->current_post == -1 ) { |
|
| 3969 | + // loop has just started |
|
| 3868 | 3970 | /** |
| 3869 | 3971 | * Fires once the loop is started. |
| 3870 | 3972 | * |
@@ -3873,6 +3975,7 @@ discard block |
||
| 3873 | 3975 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3874 | 3976 | */ |
| 3875 | 3977 | do_action_ref_array( 'loop_start', array( &$this ) ); |
| 3978 | + } |
|
| 3876 | 3979 | |
| 3877 | 3980 | $post = $this->next_post(); |
| 3878 | 3981 | $this->setup_postdata( $post ); |
@@ -4019,8 +4122,9 @@ discard block |
||
| 4019 | 4122 | * @return object |
| 4020 | 4123 | */ |
| 4021 | 4124 | public function get_queried_object() { |
| 4022 | - if ( isset($this->queried_object) ) |
|
| 4023 | - return $this->queried_object; |
|
| 4125 | + if ( isset($this->queried_object) ) { |
|
| 4126 | + return $this->queried_object; |
|
| 4127 | + } |
|
| 4024 | 4128 | |
| 4025 | 4129 | $this->queried_object = null; |
| 4026 | 4130 | $this->queried_object_id = null; |
@@ -4061,13 +4165,15 @@ discard block |
||
| 4061 | 4165 | $this->queried_object = $term; |
| 4062 | 4166 | $this->queried_object_id = (int) $term->term_id; |
| 4063 | 4167 | |
| 4064 | - if ( $this->is_category && 'category' === $this->queried_object->taxonomy ) |
|
| 4065 | - _make_cat_compat( $this->queried_object ); |
|
| 4168 | + if ( $this->is_category && 'category' === $this->queried_object->taxonomy ) { |
|
| 4169 | + _make_cat_compat( $this->queried_object ); |
|
| 4170 | + } |
|
| 4066 | 4171 | } |
| 4067 | 4172 | } elseif ( $this->is_post_type_archive ) { |
| 4068 | 4173 | $post_type = $this->get( 'post_type' ); |
| 4069 | - if ( is_array( $post_type ) ) |
|
| 4070 | - $post_type = reset( $post_type ); |
|
| 4174 | + if ( is_array( $post_type ) ) { |
|
| 4175 | + $post_type = reset( $post_type ); |
|
| 4176 | + } |
|
| 4071 | 4177 | $this->queried_object = get_post_type_object( $post_type ); |
| 4072 | 4178 | } elseif ( $this->is_posts_page ) { |
| 4073 | 4179 | $page_for_posts = get_option('page_for_posts'); |
@@ -4187,12 +4293,14 @@ discard block |
||
| 4187 | 4293 | * @return bool |
| 4188 | 4294 | */ |
| 4189 | 4295 | public function is_post_type_archive( $post_types = '' ) { |
| 4190 | - if ( empty( $post_types ) || ! $this->is_post_type_archive ) |
|
| 4191 | - return (bool) $this->is_post_type_archive; |
|
| 4296 | + if ( empty( $post_types ) || ! $this->is_post_type_archive ) { |
|
| 4297 | + return (bool) $this->is_post_type_archive; |
|
| 4298 | + } |
|
| 4192 | 4299 | |
| 4193 | 4300 | $post_type = $this->get( 'post_type' ); |
| 4194 | - if ( is_array( $post_type ) ) |
|
| 4195 | - $post_type = reset( $post_type ); |
|
| 4301 | + if ( is_array( $post_type ) ) { |
|
| 4302 | + $post_type = reset( $post_type ); |
|
| 4303 | + } |
|
| 4196 | 4304 | $post_type_object = get_post_type_object( $post_type ); |
| 4197 | 4305 | |
| 4198 | 4306 | return in_array( $post_type_object->name, (array) $post_types ); |
@@ -4241,22 +4349,25 @@ discard block |
||
| 4241 | 4349 | * @return bool |
| 4242 | 4350 | */ |
| 4243 | 4351 | public function is_author( $author = '' ) { |
| 4244 | - if ( !$this->is_author ) |
|
| 4245 | - return false; |
|
| 4352 | + if ( !$this->is_author ) { |
|
| 4353 | + return false; |
|
| 4354 | + } |
|
| 4246 | 4355 | |
| 4247 | - if ( empty($author) ) |
|
| 4248 | - return true; |
|
| 4356 | + if ( empty($author) ) { |
|
| 4357 | + return true; |
|
| 4358 | + } |
|
| 4249 | 4359 | |
| 4250 | 4360 | $author_obj = $this->get_queried_object(); |
| 4251 | 4361 | |
| 4252 | 4362 | $author = array_map( 'strval', (array) $author ); |
| 4253 | 4363 | |
| 4254 | - if ( in_array( (string) $author_obj->ID, $author ) ) |
|
| 4255 | - return true; |
|
| 4256 | - elseif ( in_array( $author_obj->nickname, $author ) ) |
|
| 4257 | - return true; |
|
| 4258 | - elseif ( in_array( $author_obj->user_nicename, $author ) ) |
|
| 4259 | - return true; |
|
| 4364 | + if ( in_array( (string) $author_obj->ID, $author ) ) { |
|
| 4365 | + return true; |
|
| 4366 | + } elseif ( in_array( $author_obj->nickname, $author ) ) { |
|
| 4367 | + return true; |
|
| 4368 | + } elseif ( in_array( $author_obj->user_nicename, $author ) ) { |
|
| 4369 | + return true; |
|
| 4370 | + } |
|
| 4260 | 4371 | |
| 4261 | 4372 | return false; |
| 4262 | 4373 | } |
@@ -4273,22 +4384,25 @@ discard block |
||
| 4273 | 4384 | * @return bool |
| 4274 | 4385 | */ |
| 4275 | 4386 | public function is_category( $category = '' ) { |
| 4276 | - if ( !$this->is_category ) |
|
| 4277 | - return false; |
|
| 4387 | + if ( !$this->is_category ) { |
|
| 4388 | + return false; |
|
| 4389 | + } |
|
| 4278 | 4390 | |
| 4279 | - if ( empty($category) ) |
|
| 4280 | - return true; |
|
| 4391 | + if ( empty($category) ) { |
|
| 4392 | + return true; |
|
| 4393 | + } |
|
| 4281 | 4394 | |
| 4282 | 4395 | $cat_obj = $this->get_queried_object(); |
| 4283 | 4396 | |
| 4284 | 4397 | $category = array_map( 'strval', (array) $category ); |
| 4285 | 4398 | |
| 4286 | - if ( in_array( (string) $cat_obj->term_id, $category ) ) |
|
| 4287 | - return true; |
|
| 4288 | - elseif ( in_array( $cat_obj->name, $category ) ) |
|
| 4289 | - return true; |
|
| 4290 | - elseif ( in_array( $cat_obj->slug, $category ) ) |
|
| 4291 | - return true; |
|
| 4399 | + if ( in_array( (string) $cat_obj->term_id, $category ) ) { |
|
| 4400 | + return true; |
|
| 4401 | + } elseif ( in_array( $cat_obj->name, $category ) ) { |
|
| 4402 | + return true; |
|
| 4403 | + } elseif ( in_array( $cat_obj->slug, $category ) ) { |
|
| 4404 | + return true; |
|
| 4405 | + } |
|
| 4292 | 4406 | |
| 4293 | 4407 | return false; |
| 4294 | 4408 | } |
@@ -4305,22 +4419,25 @@ discard block |
||
| 4305 | 4419 | * @return bool |
| 4306 | 4420 | */ |
| 4307 | 4421 | public function is_tag( $tag = '' ) { |
| 4308 | - if ( ! $this->is_tag ) |
|
| 4309 | - return false; |
|
| 4422 | + if ( ! $this->is_tag ) { |
|
| 4423 | + return false; |
|
| 4424 | + } |
|
| 4310 | 4425 | |
| 4311 | - if ( empty( $tag ) ) |
|
| 4312 | - return true; |
|
| 4426 | + if ( empty( $tag ) ) { |
|
| 4427 | + return true; |
|
| 4428 | + } |
|
| 4313 | 4429 | |
| 4314 | 4430 | $tag_obj = $this->get_queried_object(); |
| 4315 | 4431 | |
| 4316 | 4432 | $tag = array_map( 'strval', (array) $tag ); |
| 4317 | 4433 | |
| 4318 | - if ( in_array( (string) $tag_obj->term_id, $tag ) ) |
|
| 4319 | - return true; |
|
| 4320 | - elseif ( in_array( $tag_obj->name, $tag ) ) |
|
| 4321 | - return true; |
|
| 4322 | - elseif ( in_array( $tag_obj->slug, $tag ) ) |
|
| 4323 | - return true; |
|
| 4434 | + if ( in_array( (string) $tag_obj->term_id, $tag ) ) { |
|
| 4435 | + return true; |
|
| 4436 | + } elseif ( in_array( $tag_obj->name, $tag ) ) { |
|
| 4437 | + return true; |
|
| 4438 | + } elseif ( in_array( $tag_obj->slug, $tag ) ) { |
|
| 4439 | + return true; |
|
| 4440 | + } |
|
| 4324 | 4441 | |
| 4325 | 4442 | return false; |
| 4326 | 4443 | } |
@@ -4346,23 +4463,27 @@ discard block |
||
| 4346 | 4463 | public function is_tax( $taxonomy = '', $term = '' ) { |
| 4347 | 4464 | global $wp_taxonomies; |
| 4348 | 4465 | |
| 4349 | - if ( !$this->is_tax ) |
|
| 4350 | - return false; |
|
| 4466 | + if ( !$this->is_tax ) { |
|
| 4467 | + return false; |
|
| 4468 | + } |
|
| 4351 | 4469 | |
| 4352 | - if ( empty( $taxonomy ) ) |
|
| 4353 | - return true; |
|
| 4470 | + if ( empty( $taxonomy ) ) { |
|
| 4471 | + return true; |
|
| 4472 | + } |
|
| 4354 | 4473 | |
| 4355 | 4474 | $queried_object = $this->get_queried_object(); |
| 4356 | 4475 | $tax_array = array_intersect( array_keys( $wp_taxonomies ), (array) $taxonomy ); |
| 4357 | 4476 | $term_array = (array) $term; |
| 4358 | 4477 | |
| 4359 | 4478 | // Check that the taxonomy matches. |
| 4360 | - if ( ! ( isset( $queried_object->taxonomy ) && count( $tax_array ) && in_array( $queried_object->taxonomy, $tax_array ) ) ) |
|
| 4361 | - return false; |
|
| 4479 | + if ( ! ( isset( $queried_object->taxonomy ) && count( $tax_array ) && in_array( $queried_object->taxonomy, $tax_array ) ) ) { |
|
| 4480 | + return false; |
|
| 4481 | + } |
|
| 4362 | 4482 | |
| 4363 | 4483 | // Only a Taxonomy provided. |
| 4364 | - if ( empty( $term ) ) |
|
| 4365 | - return true; |
|
| 4484 | + if ( empty( $term ) ) { |
|
| 4485 | + return true; |
|
| 4486 | + } |
|
| 4366 | 4487 | |
| 4367 | 4488 | return isset( $queried_object->term_id ) && |
| 4368 | 4489 | count( array_intersect( |
@@ -4416,11 +4537,13 @@ discard block |
||
| 4416 | 4537 | * @return bool |
| 4417 | 4538 | */ |
| 4418 | 4539 | public function is_feed( $feeds = '' ) { |
| 4419 | - if ( empty( $feeds ) || ! $this->is_feed ) |
|
| 4420 | - return (bool) $this->is_feed; |
|
| 4540 | + if ( empty( $feeds ) || ! $this->is_feed ) { |
|
| 4541 | + return (bool) $this->is_feed; |
|
| 4542 | + } |
|
| 4421 | 4543 | $qv = $this->get( 'feed' ); |
| 4422 | - if ( 'feed' == $qv ) |
|
| 4423 | - $qv = get_default_feed(); |
|
| 4544 | + if ( 'feed' == $qv ) { |
|
| 4545 | + $qv = get_default_feed(); |
|
| 4546 | + } |
|
| 4424 | 4547 | return in_array( $qv, (array) $feeds ); |
| 4425 | 4548 | } |
| 4426 | 4549 | |
@@ -4453,12 +4576,13 @@ discard block |
||
| 4453 | 4576 | */ |
| 4454 | 4577 | public function is_front_page() { |
| 4455 | 4578 | // most likely case |
| 4456 | - if ( 'posts' == get_option( 'show_on_front') && $this->is_home() ) |
|
| 4457 | - return true; |
|
| 4458 | - elseif ( 'page' == get_option( 'show_on_front') && get_option( 'page_on_front' ) && $this->is_page( get_option( 'page_on_front' ) ) ) |
|
| 4459 | - return true; |
|
| 4460 | - else |
|
| 4461 | - return false; |
|
| 4579 | + if ( 'posts' == get_option( 'show_on_front') && $this->is_home() ) { |
|
| 4580 | + return true; |
|
| 4581 | + } elseif ( 'page' == get_option( 'show_on_front') && get_option( 'page_on_front' ) && $this->is_page( get_option( 'page_on_front' ) ) ) { |
|
| 4582 | + return true; |
|
| 4583 | + } else { |
|
| 4584 | + return false; |
|
| 4585 | + } |
|
| 4462 | 4586 | } |
| 4463 | 4587 | |
| 4464 | 4588 | /** |
@@ -4507,11 +4631,13 @@ discard block |
||
| 4507 | 4631 | * @return bool Whether the query is for an existing single page. |
| 4508 | 4632 | */ |
| 4509 | 4633 | public function is_page( $page = '' ) { |
| 4510 | - if ( !$this->is_page ) |
|
| 4511 | - return false; |
|
| 4634 | + if ( !$this->is_page ) { |
|
| 4635 | + return false; |
|
| 4636 | + } |
|
| 4512 | 4637 | |
| 4513 | - if ( empty( $page ) ) |
|
| 4514 | - return true; |
|
| 4638 | + if ( empty( $page ) ) { |
|
| 4639 | + return true; |
|
| 4640 | + } |
|
| 4515 | 4641 | |
| 4516 | 4642 | $page_obj = $this->get_queried_object(); |
| 4517 | 4643 | |
@@ -4600,11 +4726,13 @@ discard block |
||
| 4600 | 4726 | * @return bool Whether the query is for an existing single post. |
| 4601 | 4727 | */ |
| 4602 | 4728 | public function is_single( $post = '' ) { |
| 4603 | - if ( !$this->is_single ) |
|
| 4604 | - return false; |
|
| 4729 | + if ( !$this->is_single ) { |
|
| 4730 | + return false; |
|
| 4731 | + } |
|
| 4605 | 4732 | |
| 4606 | - if ( empty($post) ) |
|
| 4607 | - return true; |
|
| 4733 | + if ( empty($post) ) { |
|
| 4734 | + return true; |
|
| 4735 | + } |
|
| 4608 | 4736 | |
| 4609 | 4737 | $post_obj = $this->get_queried_object(); |
| 4610 | 4738 | |
@@ -4646,8 +4774,9 @@ discard block |
||
| 4646 | 4774 | * @return bool Whether the query is for an existing single post of any of the given post types. |
| 4647 | 4775 | */ |
| 4648 | 4776 | public function is_singular( $post_types = '' ) { |
| 4649 | - if ( empty( $post_types ) || !$this->is_singular ) |
|
| 4650 | - return (bool) $this->is_singular; |
|
| 4777 | + if ( empty( $post_types ) || !$this->is_singular ) { |
|
| 4778 | + return (bool) $this->is_singular; |
|
| 4779 | + } |
|
| 4651 | 4780 | |
| 4652 | 4781 | $post_obj = $this->get_queried_object(); |
| 4653 | 4782 | |
@@ -4762,8 +4891,9 @@ discard block |
||
| 4762 | 4891 | $numpages = 1; |
| 4763 | 4892 | $multipage = 0; |
| 4764 | 4893 | $page = $this->get( 'page' ); |
| 4765 | - if ( ! $page ) |
|
| 4766 | - $page = 1; |
|
| 4894 | + if ( ! $page ) { |
|
| 4895 | + $page = 1; |
|
| 4896 | + } |
|
| 4767 | 4897 | |
| 4768 | 4898 | /* |
| 4769 | 4899 | * Force full post content when viewing the permalink for the $post, |
@@ -4784,8 +4914,9 @@ discard block |
||
| 4784 | 4914 | $content = str_replace( "<!--nextpage-->\n", '<!--nextpage-->', $content ); |
| 4785 | 4915 | |
| 4786 | 4916 | // Ignore nextpage at the beginning of the content. |
| 4787 | - if ( 0 === strpos( $content, '<!--nextpage-->' ) ) |
|
| 4788 | - $content = substr( $content, 15 ); |
|
| 4917 | + if ( 0 === strpos( $content, '<!--nextpage-->' ) ) { |
|
| 4918 | + $content = substr( $content, 15 ); |
|
| 4919 | + } |
|
| 4789 | 4920 | |
| 4790 | 4921 | $pages = explode('<!--nextpage-->', $content); |
| 4791 | 4922 | } else { |
@@ -4909,30 +5040,36 @@ discard block |
||
| 4909 | 5040 | } |
| 4910 | 5041 | |
| 4911 | 5042 | if ( is_array( $post_type ) ) { |
| 4912 | - if ( count( $post_type ) > 1 ) |
|
| 4913 | - return; |
|
| 5043 | + if ( count( $post_type ) > 1 ) { |
|
| 5044 | + return; |
|
| 5045 | + } |
|
| 4914 | 5046 | $post_type = reset( $post_type ); |
| 4915 | 5047 | } |
| 4916 | 5048 | |
| 4917 | 5049 | // Do not attempt redirect for hierarchical post types |
| 4918 | - if ( is_post_type_hierarchical( $post_type ) ) |
|
| 4919 | - return; |
|
| 5050 | + if ( is_post_type_hierarchical( $post_type ) ) { |
|
| 5051 | + return; |
|
| 5052 | + } |
|
| 4920 | 5053 | |
| 4921 | 5054 | $query = $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta, $wpdb->posts WHERE ID = post_id AND post_type = %s AND meta_key = '_wp_old_slug' AND meta_value = %s", $post_type, $wp_query->query_vars['name']); |
| 4922 | 5055 | |
| 4923 | 5056 | // if year, monthnum, or day have been specified, make our query more precise |
| 4924 | 5057 | // just in case there are multiple identical _wp_old_slug values |
| 4925 | - if ( '' != $wp_query->query_vars['year'] ) |
|
| 4926 | - $query .= $wpdb->prepare(" AND YEAR(post_date) = %d", $wp_query->query_vars['year']); |
|
| 4927 | - if ( '' != $wp_query->query_vars['monthnum'] ) |
|
| 4928 | - $query .= $wpdb->prepare(" AND MONTH(post_date) = %d", $wp_query->query_vars['monthnum']); |
|
| 4929 | - if ( '' != $wp_query->query_vars['day'] ) |
|
| 4930 | - $query .= $wpdb->prepare(" AND DAYOFMONTH(post_date) = %d", $wp_query->query_vars['day']); |
|
| 5058 | + if ( '' != $wp_query->query_vars['year'] ) { |
|
| 5059 | + $query .= $wpdb->prepare(" AND YEAR(post_date) = %d", $wp_query->query_vars['year']); |
|
| 5060 | + } |
|
| 5061 | + if ( '' != $wp_query->query_vars['monthnum'] ) { |
|
| 5062 | + $query .= $wpdb->prepare(" AND MONTH(post_date) = %d", $wp_query->query_vars['monthnum']); |
|
| 5063 | + } |
|
| 5064 | + if ( '' != $wp_query->query_vars['day'] ) { |
|
| 5065 | + $query .= $wpdb->prepare(" AND DAYOFMONTH(post_date) = %d", $wp_query->query_vars['day']); |
|
| 5066 | + } |
|
| 4931 | 5067 | |
| 4932 | 5068 | $id = (int) $wpdb->get_var($query); |
| 4933 | 5069 | |
| 4934 | - if ( ! $id ) |
|
| 4935 | - return; |
|
| 5070 | + if ( ! $id ) { |
|
| 5071 | + return; |
|
| 5072 | + } |
|
| 4936 | 5073 | |
| 4937 | 5074 | $link = get_permalink( $id ); |
| 4938 | 5075 | |
@@ -479,7 +479,7 @@ discard block |
||
| 479 | 479 | * @since 4.4.0 |
| 480 | 480 | * @access public |
| 481 | 481 | * |
| 482 | - * @param array $params Parameter map of key to value. |
|
| 482 | + * @param string[] $params Parameter map of key to value. |
|
| 483 | 483 | */ |
| 484 | 484 | public function set_url_params( $params ) { |
| 485 | 485 | $this->params['URL'] = $params; |
@@ -781,7 +781,7 @@ discard block |
||
| 781 | 781 | * @since 4.4.0 |
| 782 | 782 | * @access public |
| 783 | 783 | * |
| 784 | - * @return true|null True if there are no parameters to sanitize, null otherwise. |
|
| 784 | + * @return boolean|null True if there are no parameters to sanitize, null otherwise. |
|
| 785 | 785 | */ |
| 786 | 786 | public function sanitize_params() { |
| 787 | 787 | |
@@ -1,11 +1,11 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * REST API: WP_REST_Request class |
|
| 4 | - * |
|
| 5 | - * @package WordPress |
|
| 6 | - * @subpackage REST_API |
|
| 7 | - * @since 4.4.0 |
|
| 8 | - */ |
|
| 3 | + * REST API: WP_REST_Request class |
|
| 4 | + * |
|
| 5 | + * @package WordPress |
|
| 6 | + * @subpackage REST_API |
|
| 7 | + * @since 4.4.0 |
|
| 8 | + */ |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * Core class used to implement a REST request object. |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | * @param string $route Optional. Request route. Default empty. |
| 120 | 120 | * @param array $attributes Optional. Request attributes. Default empty array. |
| 121 | 121 | */ |
| 122 | - public function __construct( $method = '', $route = '', $attributes = array() ) { |
|
| 122 | + public function __construct($method = '', $route = '', $attributes = array()) { |
|
| 123 | 123 | $this->params = array( |
| 124 | 124 | 'URL' => array(), |
| 125 | 125 | 'GET' => array(), |
@@ -132,9 +132,9 @@ discard block |
||
| 132 | 132 | 'defaults' => array(), |
| 133 | 133 | ); |
| 134 | 134 | |
| 135 | - $this->set_method( $method ); |
|
| 136 | - $this->set_route( $route ); |
|
| 137 | - $this->set_attributes( $attributes ); |
|
| 135 | + $this->set_method($method); |
|
| 136 | + $this->set_route($route); |
|
| 137 | + $this->set_attributes($attributes); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -157,8 +157,8 @@ discard block |
||
| 157 | 157 | * |
| 158 | 158 | * @param string $method HTTP method. |
| 159 | 159 | */ |
| 160 | - public function set_method( $method ) { |
|
| 161 | - $this->method = strtoupper( $method ); |
|
| 160 | + public function set_method($method) { |
|
| 161 | + $this->method = strtoupper($method); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
@@ -193,9 +193,9 @@ discard block |
||
| 193 | 193 | * @param string $key Header name. |
| 194 | 194 | * @return string Canonicalized name. |
| 195 | 195 | */ |
| 196 | - public static function canonicalize_header_name( $key ) { |
|
| 197 | - $key = strtolower( $key ); |
|
| 198 | - $key = str_replace( '-', '_', $key ); |
|
| 196 | + public static function canonicalize_header_name($key) { |
|
| 197 | + $key = strtolower($key); |
|
| 198 | + $key = str_replace('-', '_', $key); |
|
| 199 | 199 | |
| 200 | 200 | return $key; |
| 201 | 201 | } |
@@ -213,14 +213,14 @@ discard block |
||
| 213 | 213 | * @param string $key Header name, will be canonicalized to lowercase. |
| 214 | 214 | * @return string|null String value if set, null otherwise. |
| 215 | 215 | */ |
| 216 | - public function get_header( $key ) { |
|
| 217 | - $key = $this->canonicalize_header_name( $key ); |
|
| 216 | + public function get_header($key) { |
|
| 217 | + $key = $this->canonicalize_header_name($key); |
|
| 218 | 218 | |
| 219 | - if ( ! isset( $this->headers[ $key ] ) ) { |
|
| 219 | + if ( ! isset($this->headers[$key])) { |
|
| 220 | 220 | return null; |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - return implode( ',', $this->headers[ $key ] ); |
|
| 223 | + return implode(',', $this->headers[$key]); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | /** |
@@ -232,14 +232,14 @@ discard block |
||
| 232 | 232 | * @param string $key Header name, will be canonicalized to lowercase. |
| 233 | 233 | * @return array|null List of string values if set, null otherwise. |
| 234 | 234 | */ |
| 235 | - public function get_header_as_array( $key ) { |
|
| 236 | - $key = $this->canonicalize_header_name( $key ); |
|
| 235 | + public function get_header_as_array($key) { |
|
| 236 | + $key = $this->canonicalize_header_name($key); |
|
| 237 | 237 | |
| 238 | - if ( ! isset( $this->headers[ $key ] ) ) { |
|
| 238 | + if ( ! isset($this->headers[$key])) { |
|
| 239 | 239 | return null; |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | - return $this->headers[ $key ]; |
|
| 242 | + return $this->headers[$key]; |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | /** |
@@ -251,11 +251,11 @@ discard block |
||
| 251 | 251 | * @param string $key Header name. |
| 252 | 252 | * @param string $value Header value, or list of values. |
| 253 | 253 | */ |
| 254 | - public function set_header( $key, $value ) { |
|
| 255 | - $key = $this->canonicalize_header_name( $key ); |
|
| 254 | + public function set_header($key, $value) { |
|
| 255 | + $key = $this->canonicalize_header_name($key); |
|
| 256 | 256 | $value = (array) $value; |
| 257 | 257 | |
| 258 | - $this->headers[ $key ] = $value; |
|
| 258 | + $this->headers[$key] = $value; |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | /** |
@@ -267,15 +267,15 @@ discard block |
||
| 267 | 267 | * @param string $key Header name. |
| 268 | 268 | * @param string $value Header value, or list of values. |
| 269 | 269 | */ |
| 270 | - public function add_header( $key, $value ) { |
|
| 271 | - $key = $this->canonicalize_header_name( $key ); |
|
| 270 | + public function add_header($key, $value) { |
|
| 271 | + $key = $this->canonicalize_header_name($key); |
|
| 272 | 272 | $value = (array) $value; |
| 273 | 273 | |
| 274 | - if ( ! isset( $this->headers[ $key ] ) ) { |
|
| 275 | - $this->headers[ $key ] = array(); |
|
| 274 | + if ( ! isset($this->headers[$key])) { |
|
| 275 | + $this->headers[$key] = array(); |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | - $this->headers[ $key ] = array_merge( $this->headers[ $key ], $value ); |
|
| 278 | + $this->headers[$key] = array_merge($this->headers[$key], $value); |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | /** |
@@ -286,8 +286,8 @@ discard block |
||
| 286 | 286 | * |
| 287 | 287 | * @param string $key Header name. |
| 288 | 288 | */ |
| 289 | - public function remove_header( $key ) { |
|
| 290 | - unset( $this->headers[ $key ] ); |
|
| 289 | + public function remove_header($key) { |
|
| 290 | + unset($this->headers[$key]); |
|
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | /** |
@@ -299,13 +299,13 @@ discard block |
||
| 299 | 299 | * @param array $headers Map of header name to value. |
| 300 | 300 | * @param bool $override If true, replace the request's headers. Otherwise, merge with existing. |
| 301 | 301 | */ |
| 302 | - public function set_headers( $headers, $override = true ) { |
|
| 303 | - if ( true === $override ) { |
|
| 302 | + public function set_headers($headers, $override = true) { |
|
| 303 | + if (true === $override) { |
|
| 304 | 304 | $this->headers = array(); |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | - foreach ( $headers as $key => $value ) { |
|
| 308 | - $this->set_header( $key, $value ); |
|
| 307 | + foreach ($headers as $key => $value) { |
|
| 308 | + $this->set_header($key, $value); |
|
| 309 | 309 | } |
| 310 | 310 | } |
| 311 | 311 | |
@@ -318,26 +318,26 @@ discard block |
||
| 318 | 318 | * @return array Map containing 'value' and 'parameters' keys. |
| 319 | 319 | */ |
| 320 | 320 | public function get_content_type() { |
| 321 | - $value = $this->get_header( 'content-type' ); |
|
| 322 | - if ( empty( $value ) ) { |
|
| 321 | + $value = $this->get_header('content-type'); |
|
| 322 | + if (empty($value)) { |
|
| 323 | 323 | return null; |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | $parameters = ''; |
| 327 | - if ( strpos( $value, ';' ) ) { |
|
| 328 | - list( $value, $parameters ) = explode( ';', $value, 2 ); |
|
| 327 | + if (strpos($value, ';')) { |
|
| 328 | + list($value, $parameters) = explode(';', $value, 2); |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | - $value = strtolower( $value ); |
|
| 332 | - if ( strpos( $value, '/' ) === false ) { |
|
| 331 | + $value = strtolower($value); |
|
| 332 | + if (strpos($value, '/') === false) { |
|
| 333 | 333 | return null; |
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | // Parse type and subtype out. |
| 337 | - list( $type, $subtype ) = explode( '/', $value, 2 ); |
|
| 337 | + list($type, $subtype) = explode('/', $value, 2); |
|
| 338 | 338 | |
| 339 | - $data = compact( 'value', 'type', 'subtype', 'parameters' ); |
|
| 340 | - $data = array_map( 'trim', $data ); |
|
| 339 | + $data = compact('value', 'type', 'subtype', 'parameters'); |
|
| 340 | + $data = array_map('trim', $data); |
|
| 341 | 341 | |
| 342 | 342 | return $data; |
| 343 | 343 | } |
@@ -360,12 +360,12 @@ discard block |
||
| 360 | 360 | |
| 361 | 361 | // Ensure we parse the body data. |
| 362 | 362 | $body = $this->get_body(); |
| 363 | - if ( $this->method !== 'POST' && ! empty( $body ) ) { |
|
| 363 | + if ($this->method !== 'POST' && ! empty($body)) { |
|
| 364 | 364 | $this->parse_body_params(); |
| 365 | 365 | } |
| 366 | 366 | |
| 367 | - $accepts_body_data = array( 'POST', 'PUT', 'PATCH' ); |
|
| 368 | - if ( in_array( $this->method, $accepts_body_data ) ) { |
|
| 367 | + $accepts_body_data = array('POST', 'PUT', 'PATCH'); |
|
| 368 | + if (in_array($this->method, $accepts_body_data)) { |
|
| 369 | 369 | $order[] = 'POST'; |
| 370 | 370 | } |
| 371 | 371 | |
@@ -388,7 +388,7 @@ discard block |
||
| 388 | 388 | * } |
| 389 | 389 | * @param WP_REST_Request $this The request object. |
| 390 | 390 | */ |
| 391 | - return apply_filters( 'rest_request_parameter_order', $order, $this ); |
|
| 391 | + return apply_filters('rest_request_parameter_order', $order, $this); |
|
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | /** |
@@ -400,13 +400,13 @@ discard block |
||
| 400 | 400 | * @param string $key Parameter name. |
| 401 | 401 | * @return mixed|null Value if set, null otherwise. |
| 402 | 402 | */ |
| 403 | - public function get_param( $key ) { |
|
| 403 | + public function get_param($key) { |
|
| 404 | 404 | $order = $this->get_parameter_order(); |
| 405 | 405 | |
| 406 | - foreach ( $order as $type ) { |
|
| 406 | + foreach ($order as $type) { |
|
| 407 | 407 | // Determine if we have the parameter for this type. |
| 408 | - if ( isset( $this->params[ $type ][ $key ] ) ) { |
|
| 409 | - return $this->params[ $type ][ $key ]; |
|
| 408 | + if (isset($this->params[$type][$key])) { |
|
| 409 | + return $this->params[$type][$key]; |
|
| 410 | 410 | } |
| 411 | 411 | } |
| 412 | 412 | |
@@ -422,14 +422,14 @@ discard block |
||
| 422 | 422 | * @param string $key Parameter name. |
| 423 | 423 | * @param mixed $value Parameter value. |
| 424 | 424 | */ |
| 425 | - public function set_param( $key, $value ) { |
|
| 426 | - switch ( $this->method ) { |
|
| 425 | + public function set_param($key, $value) { |
|
| 426 | + switch ($this->method) { |
|
| 427 | 427 | case 'POST': |
| 428 | - $this->params['POST'][ $key ] = $value; |
|
| 428 | + $this->params['POST'][$key] = $value; |
|
| 429 | 429 | break; |
| 430 | 430 | |
| 431 | 431 | default: |
| 432 | - $this->params['GET'][ $key ] = $value; |
|
| 432 | + $this->params['GET'][$key] = $value; |
|
| 433 | 433 | break; |
| 434 | 434 | } |
| 435 | 435 | } |
@@ -447,11 +447,11 @@ discard block |
||
| 447 | 447 | */ |
| 448 | 448 | public function get_params() { |
| 449 | 449 | $order = $this->get_parameter_order(); |
| 450 | - $order = array_reverse( $order, true ); |
|
| 450 | + $order = array_reverse($order, true); |
|
| 451 | 451 | |
| 452 | 452 | $params = array(); |
| 453 | - foreach ( $order as $type ) { |
|
| 454 | - $params = array_merge( $params, (array) $this->params[ $type ] ); |
|
| 453 | + foreach ($order as $type) { |
|
| 454 | + $params = array_merge($params, (array) $this->params[$type]); |
|
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | return $params; |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | * |
| 482 | 482 | * @param array $params Parameter map of key to value. |
| 483 | 483 | */ |
| 484 | - public function set_url_params( $params ) { |
|
| 484 | + public function set_url_params($params) { |
|
| 485 | 485 | $this->params['URL'] = $params; |
| 486 | 486 | } |
| 487 | 487 | |
@@ -509,7 +509,7 @@ discard block |
||
| 509 | 509 | * |
| 510 | 510 | * @param array $params Parameter map of key to value. |
| 511 | 511 | */ |
| 512 | - public function set_query_params( $params ) { |
|
| 512 | + public function set_query_params($params) { |
|
| 513 | 513 | $this->params['GET'] = $params; |
| 514 | 514 | } |
| 515 | 515 | |
@@ -537,7 +537,7 @@ discard block |
||
| 537 | 537 | * |
| 538 | 538 | * @param array $params Parameter map of key to value. |
| 539 | 539 | */ |
| 540 | - public function set_body_params( $params ) { |
|
| 540 | + public function set_body_params($params) { |
|
| 541 | 541 | $this->params['POST'] = $params; |
| 542 | 542 | } |
| 543 | 543 | |
@@ -565,7 +565,7 @@ discard block |
||
| 565 | 565 | * |
| 566 | 566 | * @param array $params Parameter map of key to value. |
| 567 | 567 | */ |
| 568 | - public function set_file_params( $params ) { |
|
| 568 | + public function set_file_params($params) { |
|
| 569 | 569 | $this->params['FILES'] = $params; |
| 570 | 570 | } |
| 571 | 571 | |
@@ -593,7 +593,7 @@ discard block |
||
| 593 | 593 | * |
| 594 | 594 | * @param array $params Parameter map of key to value. |
| 595 | 595 | */ |
| 596 | - public function set_default_params( $params ) { |
|
| 596 | + public function set_default_params($params) { |
|
| 597 | 597 | $this->params['defaults'] = $params; |
| 598 | 598 | } |
| 599 | 599 | |
@@ -617,7 +617,7 @@ discard block |
||
| 617 | 617 | * |
| 618 | 618 | * @param string $data Binary data from the request body. |
| 619 | 619 | */ |
| 620 | - public function set_body( $data ) { |
|
| 620 | + public function set_body($data) { |
|
| 621 | 621 | $this->body = $data; |
| 622 | 622 | |
| 623 | 623 | // Enable lazy parsing. |
@@ -650,7 +650,7 @@ discard block |
||
| 650 | 650 | * @access protected |
| 651 | 651 | */ |
| 652 | 652 | protected function parse_json_params() { |
| 653 | - if ( $this->parsed_json ) { |
|
| 653 | + if ($this->parsed_json) { |
|
| 654 | 654 | return; |
| 655 | 655 | } |
| 656 | 656 | |
@@ -659,11 +659,11 @@ discard block |
||
| 659 | 659 | // Check that we actually got JSON. |
| 660 | 660 | $content_type = $this->get_content_type(); |
| 661 | 661 | |
| 662 | - if ( empty( $content_type ) || 'application/json' !== $content_type['value'] ) { |
|
| 662 | + if (empty($content_type) || 'application/json' !== $content_type['value']) { |
|
| 663 | 663 | return; |
| 664 | 664 | } |
| 665 | 665 | |
| 666 | - $params = json_decode( $this->get_body(), true ); |
|
| 666 | + $params = json_decode($this->get_body(), true); |
|
| 667 | 667 | |
| 668 | 668 | /* |
| 669 | 669 | * Check for a parsing error. |
@@ -671,7 +671,7 @@ discard block |
||
| 671 | 671 | * Note that due to WP's JSON compatibility functions, json_last_error |
| 672 | 672 | * might not be defined: https://core.trac.wordpress.org/ticket/27799 |
| 673 | 673 | */ |
| 674 | - if ( null === $params && ( ! function_exists( 'json_last_error' ) || JSON_ERROR_NONE !== json_last_error() ) ) { |
|
| 674 | + if (null === $params && ( ! function_exists('json_last_error') || JSON_ERROR_NONE !== json_last_error())) { |
|
| 675 | 675 | return; |
| 676 | 676 | } |
| 677 | 677 | |
@@ -688,7 +688,7 @@ discard block |
||
| 688 | 688 | * @access protected |
| 689 | 689 | */ |
| 690 | 690 | protected function parse_body_params() { |
| 691 | - if ( $this->parsed_body ) { |
|
| 691 | + if ($this->parsed_body) { |
|
| 692 | 692 | return; |
| 693 | 693 | } |
| 694 | 694 | |
@@ -700,26 +700,26 @@ discard block |
||
| 700 | 700 | */ |
| 701 | 701 | $content_type = $this->get_content_type(); |
| 702 | 702 | |
| 703 | - if ( ! empty( $content_type ) && 'application/x-www-form-urlencoded' !== $content_type['value'] ) { |
|
| 703 | + if ( ! empty($content_type) && 'application/x-www-form-urlencoded' !== $content_type['value']) { |
|
| 704 | 704 | return; |
| 705 | 705 | } |
| 706 | 706 | |
| 707 | - parse_str( $this->get_body(), $params ); |
|
| 707 | + parse_str($this->get_body(), $params); |
|
| 708 | 708 | |
| 709 | 709 | /* |
| 710 | 710 | * Amazingly, parse_str follows magic quote rules. Sigh. |
| 711 | 711 | * |
| 712 | 712 | * NOTE: Do not refactor to use `wp_unslash`. |
| 713 | 713 | */ |
| 714 | - if ( get_magic_quotes_gpc() ) { |
|
| 715 | - $params = stripslashes_deep( $params ); |
|
| 714 | + if (get_magic_quotes_gpc()) { |
|
| 715 | + $params = stripslashes_deep($params); |
|
| 716 | 716 | } |
| 717 | 717 | |
| 718 | 718 | /* |
| 719 | 719 | * Add to the POST parameters stored internally. If a user has already |
| 720 | 720 | * set these manually (via `set_body_params`), don't override them. |
| 721 | 721 | */ |
| 722 | - $this->params['POST'] = array_merge( $params, $this->params['POST'] ); |
|
| 722 | + $this->params['POST'] = array_merge($params, $this->params['POST']); |
|
| 723 | 723 | } |
| 724 | 724 | |
| 725 | 725 | /** |
@@ -742,7 +742,7 @@ discard block |
||
| 742 | 742 | * |
| 743 | 743 | * @param string $route Route matching regex. |
| 744 | 744 | */ |
| 745 | - public function set_route( $route ) { |
|
| 745 | + public function set_route($route) { |
|
| 746 | 746 | $this->route = $route; |
| 747 | 747 | } |
| 748 | 748 | |
@@ -768,7 +768,7 @@ discard block |
||
| 768 | 768 | * |
| 769 | 769 | * @param array $attributes Attributes for the request. |
| 770 | 770 | */ |
| 771 | - public function set_attributes( $attributes ) { |
|
| 771 | + public function set_attributes($attributes) { |
|
| 772 | 772 | $this->attributes = $attributes; |
| 773 | 773 | } |
| 774 | 774 | |
@@ -788,20 +788,20 @@ discard block |
||
| 788 | 788 | $attributes = $this->get_attributes(); |
| 789 | 789 | |
| 790 | 790 | // No arguments set, skip sanitizing. |
| 791 | - if ( empty( $attributes['args'] ) ) { |
|
| 791 | + if (empty($attributes['args'])) { |
|
| 792 | 792 | return true; |
| 793 | 793 | } |
| 794 | 794 | |
| 795 | 795 | $order = $this->get_parameter_order(); |
| 796 | 796 | |
| 797 | - foreach ( $order as $type ) { |
|
| 798 | - if ( empty( $this->params[ $type ] ) ) { |
|
| 797 | + foreach ($order as $type) { |
|
| 798 | + if (empty($this->params[$type])) { |
|
| 799 | 799 | continue; |
| 800 | 800 | } |
| 801 | - foreach ( $this->params[ $type ] as $key => $value ) { |
|
| 801 | + foreach ($this->params[$type] as $key => $value) { |
|
| 802 | 802 | // Check if this param has a sanitize_callback added. |
| 803 | - if ( isset( $attributes['args'][ $key ] ) && ! empty( $attributes['args'][ $key ]['sanitize_callback'] ) ) { |
|
| 804 | - $this->params[ $type ][ $key ] = call_user_func( $attributes['args'][ $key ]['sanitize_callback'], $value, $this, $key ); |
|
| 803 | + if (isset($attributes['args'][$key]) && ! empty($attributes['args'][$key]['sanitize_callback'])) { |
|
| 804 | + $this->params[$type][$key] = call_user_func($attributes['args'][$key]['sanitize_callback'], $value, $this, $key); |
|
| 805 | 805 | } |
| 806 | 806 | } |
| 807 | 807 | } |
@@ -823,20 +823,20 @@ discard block |
||
| 823 | 823 | $required = array(); |
| 824 | 824 | |
| 825 | 825 | // No arguments set, skip validation. |
| 826 | - if ( empty( $attributes['args'] ) ) { |
|
| 826 | + if (empty($attributes['args'])) { |
|
| 827 | 827 | return true; |
| 828 | 828 | } |
| 829 | 829 | |
| 830 | - foreach ( $attributes['args'] as $key => $arg ) { |
|
| 830 | + foreach ($attributes['args'] as $key => $arg) { |
|
| 831 | 831 | |
| 832 | - $param = $this->get_param( $key ); |
|
| 833 | - if ( isset( $arg['required'] ) && true === $arg['required'] && null === $param ) { |
|
| 832 | + $param = $this->get_param($key); |
|
| 833 | + if (isset($arg['required']) && true === $arg['required'] && null === $param) { |
|
| 834 | 834 | $required[] = $key; |
| 835 | 835 | } |
| 836 | 836 | } |
| 837 | 837 | |
| 838 | - if ( ! empty( $required ) ) { |
|
| 839 | - return new WP_Error( 'rest_missing_callback_param', sprintf( __( 'Missing parameter(s): %s' ), implode( ', ', $required ) ), array( 'status' => 400, 'params' => $required ) ); |
|
| 838 | + if ( ! empty($required)) { |
|
| 839 | + return new WP_Error('rest_missing_callback_param', sprintf(__('Missing parameter(s): %s'), implode(', ', $required)), array('status' => 400, 'params' => $required)); |
|
| 840 | 840 | } |
| 841 | 841 | |
| 842 | 842 | /* |
@@ -846,25 +846,25 @@ discard block |
||
| 846 | 846 | */ |
| 847 | 847 | $invalid_params = array(); |
| 848 | 848 | |
| 849 | - foreach ( $attributes['args'] as $key => $arg ) { |
|
| 849 | + foreach ($attributes['args'] as $key => $arg) { |
|
| 850 | 850 | |
| 851 | - $param = $this->get_param( $key ); |
|
| 851 | + $param = $this->get_param($key); |
|
| 852 | 852 | |
| 853 | - if ( null !== $param && ! empty( $arg['validate_callback'] ) ) { |
|
| 854 | - $valid_check = call_user_func( $arg['validate_callback'], $param, $this, $key ); |
|
| 853 | + if (null !== $param && ! empty($arg['validate_callback'])) { |
|
| 854 | + $valid_check = call_user_func($arg['validate_callback'], $param, $this, $key); |
|
| 855 | 855 | |
| 856 | - if ( false === $valid_check ) { |
|
| 857 | - $invalid_params[ $key ] = __( 'Invalid parameter.' ); |
|
| 856 | + if (false === $valid_check) { |
|
| 857 | + $invalid_params[$key] = __('Invalid parameter.'); |
|
| 858 | 858 | } |
| 859 | 859 | |
| 860 | - if ( is_wp_error( $valid_check ) ) { |
|
| 861 | - $invalid_params[ $key ] = $valid_check->get_error_message(); |
|
| 860 | + if (is_wp_error($valid_check)) { |
|
| 861 | + $invalid_params[$key] = $valid_check->get_error_message(); |
|
| 862 | 862 | } |
| 863 | 863 | } |
| 864 | 864 | } |
| 865 | 865 | |
| 866 | - if ( $invalid_params ) { |
|
| 867 | - return new WP_Error( 'rest_invalid_param', sprintf( __( 'Invalid parameter(s): %s' ), implode( ', ', array_keys( $invalid_params ) ) ), array( 'status' => 400, 'params' => $invalid_params ) ); |
|
| 866 | + if ($invalid_params) { |
|
| 867 | + return new WP_Error('rest_invalid_param', sprintf(__('Invalid parameter(s): %s'), implode(', ', array_keys($invalid_params))), array('status' => 400, 'params' => $invalid_params)); |
|
| 868 | 868 | } |
| 869 | 869 | |
| 870 | 870 | return true; |
@@ -880,11 +880,11 @@ discard block |
||
| 880 | 880 | * @param string $offset Parameter name. |
| 881 | 881 | * @return bool Whether the parameter is set. |
| 882 | 882 | */ |
| 883 | - public function offsetExists( $offset ) { |
|
| 883 | + public function offsetExists($offset) { |
|
| 884 | 884 | $order = $this->get_parameter_order(); |
| 885 | 885 | |
| 886 | - foreach ( $order as $type ) { |
|
| 887 | - if ( isset( $this->params[ $type ][ $offset ] ) ) { |
|
| 886 | + foreach ($order as $type) { |
|
| 887 | + if (isset($this->params[$type][$offset])) { |
|
| 888 | 888 | return true; |
| 889 | 889 | } |
| 890 | 890 | } |
@@ -901,8 +901,8 @@ discard block |
||
| 901 | 901 | * @param string $offset Parameter name. |
| 902 | 902 | * @return mixed|null Value if set, null otherwise. |
| 903 | 903 | */ |
| 904 | - public function offsetGet( $offset ) { |
|
| 905 | - return $this->get_param( $offset ); |
|
| 904 | + public function offsetGet($offset) { |
|
| 905 | + return $this->get_param($offset); |
|
| 906 | 906 | } |
| 907 | 907 | |
| 908 | 908 | /** |
@@ -914,8 +914,8 @@ discard block |
||
| 914 | 914 | * @param string $offset Parameter name. |
| 915 | 915 | * @param mixed $value Parameter value. |
| 916 | 916 | */ |
| 917 | - public function offsetSet( $offset, $value ) { |
|
| 918 | - $this->set_param( $offset, $value ); |
|
| 917 | + public function offsetSet($offset, $value) { |
|
| 918 | + $this->set_param($offset, $value); |
|
| 919 | 919 | } |
| 920 | 920 | |
| 921 | 921 | /** |
@@ -926,12 +926,12 @@ discard block |
||
| 926 | 926 | * |
| 927 | 927 | * @param string $offset Parameter name. |
| 928 | 928 | */ |
| 929 | - public function offsetUnset( $offset ) { |
|
| 929 | + public function offsetUnset($offset) { |
|
| 930 | 930 | $order = $this->get_parameter_order(); |
| 931 | 931 | |
| 932 | 932 | // Remove the offset from every group. |
| 933 | - foreach ( $order as $type ) { |
|
| 934 | - unset( $this->params[ $type ][ $offset ] ); |
|
| 933 | + foreach ($order as $type) { |
|
| 934 | + unset($this->params[$type][$offset]); |
|
| 935 | 935 | } |
| 936 | 936 | } |
| 937 | 937 | |
@@ -945,29 +945,29 @@ discard block |
||
| 945 | 945 | * @param string $url URL with protocol, domain, path and query args. |
| 946 | 946 | * @return WP_REST_Request|false WP_REST_Request object on success, false on failure. |
| 947 | 947 | */ |
| 948 | - public static function from_url( $url ) { |
|
| 949 | - $bits = parse_url( $url ); |
|
| 948 | + public static function from_url($url) { |
|
| 949 | + $bits = parse_url($url); |
|
| 950 | 950 | $query_params = array(); |
| 951 | 951 | |
| 952 | - if ( ! empty( $bits['query'] ) ) { |
|
| 953 | - wp_parse_str( $bits['query'], $query_params ); |
|
| 952 | + if ( ! empty($bits['query'])) { |
|
| 953 | + wp_parse_str($bits['query'], $query_params); |
|
| 954 | 954 | } |
| 955 | 955 | |
| 956 | 956 | $api_root = rest_url(); |
| 957 | - if ( get_option( 'permalink_structure' ) && 0 === strpos( $url, $api_root ) ) { |
|
| 957 | + if (get_option('permalink_structure') && 0 === strpos($url, $api_root)) { |
|
| 958 | 958 | // Pretty permalinks on, and URL is under the API root |
| 959 | - $api_url_part = substr( $url, strlen( untrailingslashit( $api_root ) ) ); |
|
| 960 | - $route = parse_url( $api_url_part, PHP_URL_PATH ); |
|
| 961 | - } elseif ( ! empty( $query_params['rest_route'] ) ) { |
|
| 959 | + $api_url_part = substr($url, strlen(untrailingslashit($api_root))); |
|
| 960 | + $route = parse_url($api_url_part, PHP_URL_PATH); |
|
| 961 | + } elseif ( ! empty($query_params['rest_route'])) { |
|
| 962 | 962 | // ?rest_route=... set directly |
| 963 | 963 | $route = $query_params['rest_route']; |
| 964 | - unset( $query_params['rest_route'] ); |
|
| 964 | + unset($query_params['rest_route']); |
|
| 965 | 965 | } |
| 966 | 966 | |
| 967 | 967 | $request = false; |
| 968 | - if ( ! empty( $route ) ) { |
|
| 969 | - $request = new WP_REST_Request( 'GET', $route ); |
|
| 970 | - $request->set_query_params( $query_params ); |
|
| 968 | + if ( ! empty($route)) { |
|
| 969 | + $request = new WP_REST_Request('GET', $route); |
|
| 970 | + $request->set_query_params($query_params); |
|
| 971 | 971 | } |
| 972 | 972 | |
| 973 | 973 | /** |
@@ -979,6 +979,6 @@ discard block |
||
| 979 | 979 | * could not be parsed. |
| 980 | 980 | * @param string $url URL the request was generated from. |
| 981 | 981 | */ |
| 982 | - return apply_filters( 'rest_request_from_url', $request, $url ); |
|
| 982 | + return apply_filters('rest_request_from_url', $request, $url); |
|
| 983 | 983 | } |
| 984 | 984 | } |
@@ -907,7 +907,7 @@ |
||
| 907 | 907 | * @since 4.4.0 |
| 908 | 908 | * @access protected |
| 909 | 909 | * |
| 910 | - * @return bool|string Boolean false or string error message. |
|
| 910 | + * @return false|string Boolean false or string error message. |
|
| 911 | 911 | */ |
| 912 | 912 | protected function get_json_last_error() { |
| 913 | 913 | // See https://core.trac.wordpress.org/ticket/27799. |
@@ -1,11 +1,11 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * REST API: WP_REST_Server class |
|
| 4 | - * |
|
| 5 | - * @package WordPress |
|
| 6 | - * @subpackage REST_API |
|
| 7 | - * @since 4.4.0 |
|
| 8 | - */ |
|
| 3 | + * REST API: WP_REST_Server class |
|
| 4 | + * |
|
| 5 | + * @package WordPress |
|
| 6 | + * @subpackage REST_API |
|
| 7 | + * @since 4.4.0 |
|
| 8 | + */ |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * Core class used to implement the WordPress REST API server. |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | $this->endpoints = array( |
| 92 | 92 | // Meta endpoints. |
| 93 | 93 | '/' => array( |
| 94 | - 'callback' => array( $this, 'get_index' ), |
|
| 94 | + 'callback' => array($this, 'get_index'), |
|
| 95 | 95 | 'methods' => 'GET', |
| 96 | 96 | 'args' => array( |
| 97 | 97 | 'context' => array( |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | * @param WP_Error|null|bool WP_Error if authentication error, null if authentication |
| 138 | 138 | * method wasn't used, true if authentication succeeded. |
| 139 | 139 | */ |
| 140 | - return apply_filters( 'rest_authentication_errors', null ); |
|
| 140 | + return apply_filters('rest_authentication_errors', null); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -153,10 +153,10 @@ discard block |
||
| 153 | 153 | * @param WP_Error $error WP_Error instance. |
| 154 | 154 | * @return WP_REST_Response List of associative arrays with code and message keys. |
| 155 | 155 | */ |
| 156 | - protected function error_to_response( $error ) { |
|
| 156 | + protected function error_to_response($error) { |
|
| 157 | 157 | $error_data = $error->get_error_data(); |
| 158 | 158 | |
| 159 | - if ( is_array( $error_data ) && isset( $error_data['status'] ) ) { |
|
| 159 | + if (is_array($error_data) && isset($error_data['status'])) { |
|
| 160 | 160 | $status = $error_data['status']; |
| 161 | 161 | } else { |
| 162 | 162 | $status = 500; |
@@ -164,20 +164,20 @@ discard block |
||
| 164 | 164 | |
| 165 | 165 | $errors = array(); |
| 166 | 166 | |
| 167 | - foreach ( (array) $error->errors as $code => $messages ) { |
|
| 168 | - foreach ( (array) $messages as $message ) { |
|
| 169 | - $errors[] = array( 'code' => $code, 'message' => $message, 'data' => $error->get_error_data( $code ) ); |
|
| 167 | + foreach ((array) $error->errors as $code => $messages) { |
|
| 168 | + foreach ((array) $messages as $message) { |
|
| 169 | + $errors[] = array('code' => $code, 'message' => $message, 'data' => $error->get_error_data($code)); |
|
| 170 | 170 | } |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | $data = $errors[0]; |
| 174 | - if ( count( $errors ) > 1 ) { |
|
| 174 | + if (count($errors) > 1) { |
|
| 175 | 175 | // Remove the primary error. |
| 176 | - array_shift( $errors ); |
|
| 176 | + array_shift($errors); |
|
| 177 | 177 | $data['additional_errors'] = $errors; |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - $response = new WP_REST_Response( $data, $status ); |
|
| 180 | + $response = new WP_REST_Response($data, $status); |
|
| 181 | 181 | |
| 182 | 182 | return $response; |
| 183 | 183 | } |
@@ -198,14 +198,14 @@ discard block |
||
| 198 | 198 | * @param int $status Optional. HTTP status code to send. Default null. |
| 199 | 199 | * @return string JSON representation of the error |
| 200 | 200 | */ |
| 201 | - protected function json_error( $code, $message, $status = null ) { |
|
| 202 | - if ( $status ) { |
|
| 203 | - $this->set_status( $status ); |
|
| 201 | + protected function json_error($code, $message, $status = null) { |
|
| 202 | + if ($status) { |
|
| 203 | + $this->set_status($status); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - $error = compact( 'code', 'message' ); |
|
| 206 | + $error = compact('code', 'message'); |
|
| 207 | 207 | |
| 208 | - return wp_json_encode( $error ); |
|
| 208 | + return wp_json_encode($error); |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /** |
@@ -223,18 +223,18 @@ discard block |
||
| 223 | 223 | * Default null. |
| 224 | 224 | * @return false|null Null if not served and a HEAD request, false otherwise. |
| 225 | 225 | */ |
| 226 | - public function serve_request( $path = null ) { |
|
| 227 | - $content_type = isset( $_GET['_jsonp'] ) ? 'application/javascript' : 'application/json'; |
|
| 228 | - $this->send_header( 'Content-Type', $content_type . '; charset=' . get_option( 'blog_charset' ) ); |
|
| 226 | + public function serve_request($path = null) { |
|
| 227 | + $content_type = isset($_GET['_jsonp']) ? 'application/javascript' : 'application/json'; |
|
| 228 | + $this->send_header('Content-Type', $content_type.'; charset='.get_option('blog_charset')); |
|
| 229 | 229 | |
| 230 | 230 | /* |
| 231 | 231 | * Mitigate possible JSONP Flash attacks. |
| 232 | 232 | * |
| 233 | 233 | * http://miki.it/blog/2014/7/8/abusing-jsonp-with-rosetta-flash/ |
| 234 | 234 | */ |
| 235 | - $this->send_header( 'X-Content-Type-Options', 'nosniff' ); |
|
| 236 | - $this->send_header( 'Access-Control-Expose-Headers', 'X-WP-Total, X-WP-TotalPages' ); |
|
| 237 | - $this->send_header( 'Access-Control-Allow-Headers', 'Authorization' ); |
|
| 235 | + $this->send_header('X-Content-Type-Options', 'nosniff'); |
|
| 236 | + $this->send_header('Access-Control-Expose-Headers', 'X-WP-Total, X-WP-TotalPages'); |
|
| 237 | + $this->send_header('Access-Control-Allow-Headers', 'Authorization'); |
|
| 238 | 238 | |
| 239 | 239 | /** |
| 240 | 240 | * Send nocache headers on authenticated requests. |
@@ -243,10 +243,10 @@ discard block |
||
| 243 | 243 | * |
| 244 | 244 | * @param bool $rest_send_nocache_headers Whether to send no-cache headers. |
| 245 | 245 | */ |
| 246 | - $send_no_cache_headers = apply_filters( 'rest_send_nocache_headers', is_user_logged_in() ); |
|
| 247 | - if ( $send_no_cache_headers ) { |
|
| 248 | - foreach ( wp_get_nocache_headers() as $header => $header_value ) { |
|
| 249 | - $this->send_header( $header, $header_value ); |
|
| 246 | + $send_no_cache_headers = apply_filters('rest_send_nocache_headers', is_user_logged_in()); |
|
| 247 | + if ($send_no_cache_headers) { |
|
| 248 | + foreach (wp_get_nocache_headers() as $header => $header_value) { |
|
| 249 | + $this->send_header($header, $header_value); |
|
| 250 | 250 | } |
| 251 | 251 | } |
| 252 | 252 | |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | * |
| 258 | 258 | * @param bool $rest_enabled Whether the REST API is enabled. Default true. |
| 259 | 259 | */ |
| 260 | - $enabled = apply_filters( 'rest_enabled', true ); |
|
| 260 | + $enabled = apply_filters('rest_enabled', true); |
|
| 261 | 261 | |
| 262 | 262 | /** |
| 263 | 263 | * Filter whether jsonp is enabled. |
@@ -266,72 +266,72 @@ discard block |
||
| 266 | 266 | * |
| 267 | 267 | * @param bool $jsonp_enabled Whether jsonp is enabled. Default true. |
| 268 | 268 | */ |
| 269 | - $jsonp_enabled = apply_filters( 'rest_jsonp_enabled', true ); |
|
| 269 | + $jsonp_enabled = apply_filters('rest_jsonp_enabled', true); |
|
| 270 | 270 | |
| 271 | 271 | $jsonp_callback = null; |
| 272 | 272 | |
| 273 | - if ( ! $enabled ) { |
|
| 274 | - echo $this->json_error( 'rest_disabled', __( 'The REST API is disabled on this site.' ), 404 ); |
|
| 273 | + if ( ! $enabled) { |
|
| 274 | + echo $this->json_error('rest_disabled', __('The REST API is disabled on this site.'), 404); |
|
| 275 | 275 | return false; |
| 276 | 276 | } |
| 277 | - if ( isset( $_GET['_jsonp'] ) ) { |
|
| 278 | - if ( ! $jsonp_enabled ) { |
|
| 279 | - echo $this->json_error( 'rest_callback_disabled', __( 'JSONP support is disabled on this site.' ), 400 ); |
|
| 277 | + if (isset($_GET['_jsonp'])) { |
|
| 278 | + if ( ! $jsonp_enabled) { |
|
| 279 | + echo $this->json_error('rest_callback_disabled', __('JSONP support is disabled on this site.'), 400); |
|
| 280 | 280 | return false; |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | // Check for invalid characters (only alphanumeric allowed). |
| 284 | - if ( is_string( $_GET['_jsonp'] ) ) { |
|
| 285 | - $jsonp_callback = preg_replace( '/[^\w\.]/', '', wp_unslash( $_GET['_jsonp'] ), -1, $illegal_char_count ); |
|
| 286 | - if ( 0 !== $illegal_char_count ) { |
|
| 284 | + if (is_string($_GET['_jsonp'])) { |
|
| 285 | + $jsonp_callback = preg_replace('/[^\w\.]/', '', wp_unslash($_GET['_jsonp']), -1, $illegal_char_count); |
|
| 286 | + if (0 !== $illegal_char_count) { |
|
| 287 | 287 | $jsonp_callback = null; |
| 288 | 288 | } |
| 289 | 289 | } |
| 290 | - if ( null === $jsonp_callback ) { |
|
| 291 | - echo $this->json_error( 'rest_callback_invalid', __( 'The JSONP callback function is invalid.' ), 400 ); |
|
| 290 | + if (null === $jsonp_callback) { |
|
| 291 | + echo $this->json_error('rest_callback_invalid', __('The JSONP callback function is invalid.'), 400); |
|
| 292 | 292 | return false; |
| 293 | 293 | } |
| 294 | 294 | } |
| 295 | 295 | |
| 296 | - if ( empty( $path ) ) { |
|
| 297 | - if ( isset( $_SERVER['PATH_INFO'] ) ) { |
|
| 296 | + if (empty($path)) { |
|
| 297 | + if (isset($_SERVER['PATH_INFO'])) { |
|
| 298 | 298 | $path = $_SERVER['PATH_INFO']; |
| 299 | 299 | } else { |
| 300 | 300 | $path = '/'; |
| 301 | 301 | } |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | - $request = new WP_REST_Request( $_SERVER['REQUEST_METHOD'], $path ); |
|
| 304 | + $request = new WP_REST_Request($_SERVER['REQUEST_METHOD'], $path); |
|
| 305 | 305 | |
| 306 | - $request->set_query_params( $_GET ); |
|
| 307 | - $request->set_body_params( $_POST ); |
|
| 308 | - $request->set_file_params( $_FILES ); |
|
| 309 | - $request->set_headers( $this->get_headers( $_SERVER ) ); |
|
| 310 | - $request->set_body( $this->get_raw_data() ); |
|
| 306 | + $request->set_query_params($_GET); |
|
| 307 | + $request->set_body_params($_POST); |
|
| 308 | + $request->set_file_params($_FILES); |
|
| 309 | + $request->set_headers($this->get_headers($_SERVER)); |
|
| 310 | + $request->set_body($this->get_raw_data()); |
|
| 311 | 311 | |
| 312 | 312 | /* |
| 313 | 313 | * HTTP method override for clients that can't use PUT/PATCH/DELETE. First, we check |
| 314 | 314 | * $_GET['_method']. If that is not set, we check for the HTTP_X_HTTP_METHOD_OVERRIDE |
| 315 | 315 | * header. |
| 316 | 316 | */ |
| 317 | - if ( isset( $_GET['_method'] ) ) { |
|
| 318 | - $request->set_method( $_GET['_method'] ); |
|
| 319 | - } elseif ( isset( $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] ) ) { |
|
| 320 | - $request->set_method( $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] ); |
|
| 317 | + if (isset($_GET['_method'])) { |
|
| 318 | + $request->set_method($_GET['_method']); |
|
| 319 | + } elseif (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) { |
|
| 320 | + $request->set_method($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']); |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | $result = $this->check_authentication(); |
| 324 | 324 | |
| 325 | - if ( ! is_wp_error( $result ) ) { |
|
| 326 | - $result = $this->dispatch( $request ); |
|
| 325 | + if ( ! is_wp_error($result)) { |
|
| 326 | + $result = $this->dispatch($request); |
|
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | // Normalize to either WP_Error or WP_REST_Response... |
| 330 | - $result = rest_ensure_response( $result ); |
|
| 330 | + $result = rest_ensure_response($result); |
|
| 331 | 331 | |
| 332 | 332 | // ...then convert WP_Error across. |
| 333 | - if ( is_wp_error( $result ) ) { |
|
| 334 | - $result = $this->error_to_response( $result ); |
|
| 333 | + if (is_wp_error($result)) { |
|
| 334 | + $result = $this->error_to_response($result); |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | /** |
@@ -346,19 +346,19 @@ discard block |
||
| 346 | 346 | * @param WP_REST_Server $this Server instance. |
| 347 | 347 | * @param WP_REST_Request $request Request used to generate the response. |
| 348 | 348 | */ |
| 349 | - $result = apply_filters( 'rest_post_dispatch', rest_ensure_response( $result ), $this, $request ); |
|
| 349 | + $result = apply_filters('rest_post_dispatch', rest_ensure_response($result), $this, $request); |
|
| 350 | 350 | |
| 351 | 351 | // Wrap the response in an envelope if asked for. |
| 352 | - if ( isset( $_GET['_envelope'] ) ) { |
|
| 353 | - $result = $this->envelope_response( $result, isset( $_GET['_embed'] ) ); |
|
| 352 | + if (isset($_GET['_envelope'])) { |
|
| 353 | + $result = $this->envelope_response($result, isset($_GET['_embed'])); |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | // Send extra data from response objects. |
| 357 | 357 | $headers = $result->get_headers(); |
| 358 | - $this->send_headers( $headers ); |
|
| 358 | + $this->send_headers($headers); |
|
| 359 | 359 | |
| 360 | 360 | $code = $result->get_status(); |
| 361 | - $this->set_status( $code ); |
|
| 361 | + $this->set_status($code); |
|
| 362 | 362 | |
| 363 | 363 | /** |
| 364 | 364 | * Filter whether the request has already been served. |
@@ -374,29 +374,29 @@ discard block |
||
| 374 | 374 | * @param WP_REST_Request $request Request used to generate the response. |
| 375 | 375 | * @param WP_REST_Server $this Server instance. |
| 376 | 376 | */ |
| 377 | - $served = apply_filters( 'rest_pre_serve_request', false, $result, $request, $this ); |
|
| 377 | + $served = apply_filters('rest_pre_serve_request', false, $result, $request, $this); |
|
| 378 | 378 | |
| 379 | - if ( ! $served ) { |
|
| 380 | - if ( 'HEAD' === $request->get_method() ) { |
|
| 379 | + if ( ! $served) { |
|
| 380 | + if ('HEAD' === $request->get_method()) { |
|
| 381 | 381 | return null; |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | // Embed links inside the request. |
| 385 | - $result = $this->response_to_data( $result, isset( $_GET['_embed'] ) ); |
|
| 385 | + $result = $this->response_to_data($result, isset($_GET['_embed'])); |
|
| 386 | 386 | |
| 387 | - $result = wp_json_encode( $result ); |
|
| 387 | + $result = wp_json_encode($result); |
|
| 388 | 388 | |
| 389 | 389 | $json_error_message = $this->get_json_last_error(); |
| 390 | - if ( $json_error_message ) { |
|
| 391 | - $json_error_obj = new WP_Error( 'rest_encode_error', $json_error_message, array( 'status' => 500 ) ); |
|
| 392 | - $result = $this->error_to_response( $json_error_obj ); |
|
| 393 | - $result = wp_json_encode( $result->data[0] ); |
|
| 390 | + if ($json_error_message) { |
|
| 391 | + $json_error_obj = new WP_Error('rest_encode_error', $json_error_message, array('status' => 500)); |
|
| 392 | + $result = $this->error_to_response($json_error_obj); |
|
| 393 | + $result = wp_json_encode($result->data[0]); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | - if ( $jsonp_callback ) { |
|
| 396 | + if ($jsonp_callback) { |
|
| 397 | 397 | // Prepend '/**/' to mitigate possible JSONP Flash attacks |
| 398 | 398 | // http://miki.it/blog/2014/7/8/abusing-jsonp-with-rosetta-flash/ |
| 399 | - echo '/**/' . $jsonp_callback . '(' . $result . ')'; |
|
| 399 | + echo '/**/'.$jsonp_callback.'('.$result.')'; |
|
| 400 | 400 | } else { |
| 401 | 401 | echo $result; |
| 402 | 402 | } |
@@ -419,20 +419,20 @@ discard block |
||
| 419 | 419 | * @type array [$_embedded] Embeddeds. |
| 420 | 420 | * } |
| 421 | 421 | */ |
| 422 | - public function response_to_data( $response, $embed ) { |
|
| 422 | + public function response_to_data($response, $embed) { |
|
| 423 | 423 | $data = $response->get_data(); |
| 424 | - $links = $this->get_response_links( $response ); |
|
| 424 | + $links = $this->get_response_links($response); |
|
| 425 | 425 | |
| 426 | - if ( ! empty( $links ) ) { |
|
| 426 | + if ( ! empty($links)) { |
|
| 427 | 427 | // Convert links to part of the data. |
| 428 | 428 | $data['_links'] = $links; |
| 429 | 429 | } |
| 430 | - if ( $embed ) { |
|
| 430 | + if ($embed) { |
|
| 431 | 431 | // Determine if this is a numeric array. |
| 432 | - if ( wp_is_numeric_array( $data ) ) { |
|
| 433 | - $data = array_map( array( $this, 'embed_links' ), $data ); |
|
| 432 | + if (wp_is_numeric_array($data)) { |
|
| 433 | + $data = array_map(array($this, 'embed_links'), $data); |
|
| 434 | 434 | } else { |
| 435 | - $data = $this->embed_links( $data ); |
|
| 435 | + $data = $this->embed_links($data); |
|
| 436 | 436 | } |
| 437 | 437 | } |
| 438 | 438 | |
@@ -452,10 +452,10 @@ discard block |
||
| 452 | 452 | * @param WP_REST_Response $response Response to extract links from. |
| 453 | 453 | * @return array Map of link relation to list of link hashes. |
| 454 | 454 | */ |
| 455 | - public static function get_response_links( $response ) { |
|
| 455 | + public static function get_response_links($response) { |
|
| 456 | 456 | $links = $response->get_links(); |
| 457 | 457 | |
| 458 | - if ( empty( $links ) ) { |
|
| 458 | + if (empty($links)) { |
|
| 459 | 459 | return array(); |
| 460 | 460 | } |
| 461 | 461 | |
@@ -464,37 +464,37 @@ discard block |
||
| 464 | 464 | $curies = $response->get_curies(); |
| 465 | 465 | $used_curies = array(); |
| 466 | 466 | |
| 467 | - foreach ( $links as $rel => $items ) { |
|
| 467 | + foreach ($links as $rel => $items) { |
|
| 468 | 468 | |
| 469 | 469 | // Convert $rel URIs to their compact versions if they exist. |
| 470 | - foreach ( $curies as $curie ) { |
|
| 471 | - $href_prefix = substr( $curie['href'], 0, strpos( $curie['href'], '{rel}' ) ); |
|
| 472 | - if ( strpos( $rel, $href_prefix ) !== 0 ) { |
|
| 470 | + foreach ($curies as $curie) { |
|
| 471 | + $href_prefix = substr($curie['href'], 0, strpos($curie['href'], '{rel}')); |
|
| 472 | + if (strpos($rel, $href_prefix) !== 0) { |
|
| 473 | 473 | continue; |
| 474 | 474 | } |
| 475 | - $used_curies[ $curie['name'] ] = $curie; |
|
| 475 | + $used_curies[$curie['name']] = $curie; |
|
| 476 | 476 | |
| 477 | 477 | // Relation now changes from '$uri' to '$curie:$relation' |
| 478 | - $rel_regex = str_replace( '\{rel\}', '([\w]+)', preg_quote( $curie['href'], '!' ) ); |
|
| 479 | - preg_match( '!' . $rel_regex . '!', $rel, $matches ); |
|
| 480 | - if ( $matches ) { |
|
| 481 | - $rel = $curie['name'] . ':' . $matches[1]; |
|
| 478 | + $rel_regex = str_replace('\{rel\}', '([\w]+)', preg_quote($curie['href'], '!')); |
|
| 479 | + preg_match('!'.$rel_regex.'!', $rel, $matches); |
|
| 480 | + if ($matches) { |
|
| 481 | + $rel = $curie['name'].':'.$matches[1]; |
|
| 482 | 482 | } |
| 483 | 483 | break; |
| 484 | 484 | } |
| 485 | 485 | |
| 486 | - $data[ $rel ] = array(); |
|
| 486 | + $data[$rel] = array(); |
|
| 487 | 487 | |
| 488 | - foreach ( $items as $item ) { |
|
| 488 | + foreach ($items as $item) { |
|
| 489 | 489 | $attributes = $item['attributes']; |
| 490 | 490 | $attributes['href'] = $item['href']; |
| 491 | - $data[ $rel ][] = $attributes; |
|
| 491 | + $data[$rel][] = $attributes; |
|
| 492 | 492 | } |
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | // Push the curies onto the start of the links array. |
| 496 | - if ( $used_curies ) { |
|
| 497 | - $data = array_merge( array( 'curies' => array_values( $used_curies ) ), $data ); |
|
| 496 | + if ($used_curies) { |
|
| 497 | + $data = array_merge(array('curies' => array_values($used_curies)), $data); |
|
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | return $data; |
@@ -514,57 +514,57 @@ discard block |
||
| 514 | 514 | * @type array [$_embedded] Embeddeds. |
| 515 | 515 | * } |
| 516 | 516 | */ |
| 517 | - protected function embed_links( $data ) { |
|
| 518 | - if ( empty( $data['_links'] ) ) { |
|
| 517 | + protected function embed_links($data) { |
|
| 518 | + if (empty($data['_links'])) { |
|
| 519 | 519 | return $data; |
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | $embedded = array(); |
| 523 | 523 | |
| 524 | - foreach ( $data['_links'] as $rel => $links ) { |
|
| 524 | + foreach ($data['_links'] as $rel => $links) { |
|
| 525 | 525 | // Ignore links to self, for obvious reasons. |
| 526 | - if ( 'self' === $rel ) { |
|
| 526 | + if ('self' === $rel) { |
|
| 527 | 527 | continue; |
| 528 | 528 | } |
| 529 | 529 | |
| 530 | 530 | $embeds = array(); |
| 531 | 531 | |
| 532 | - foreach ( $links as $item ) { |
|
| 532 | + foreach ($links as $item) { |
|
| 533 | 533 | // Determine if the link is embeddable. |
| 534 | - if ( empty( $item['embeddable'] ) ) { |
|
| 534 | + if (empty($item['embeddable'])) { |
|
| 535 | 535 | // Ensure we keep the same order. |
| 536 | 536 | $embeds[] = array(); |
| 537 | 537 | continue; |
| 538 | 538 | } |
| 539 | 539 | |
| 540 | 540 | // Run through our internal routing and serve. |
| 541 | - $request = WP_REST_Request::from_url( $item['href'] ); |
|
| 542 | - if ( ! $request ) { |
|
| 541 | + $request = WP_REST_Request::from_url($item['href']); |
|
| 542 | + if ( ! $request) { |
|
| 543 | 543 | $embeds[] = array(); |
| 544 | 544 | continue; |
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | // Embedded resources get passed context=embed. |
| 548 | - if ( empty( $request['context'] ) ) { |
|
| 548 | + if (empty($request['context'])) { |
|
| 549 | 549 | $request['context'] = 'embed'; |
| 550 | 550 | } |
| 551 | 551 | |
| 552 | - $response = $this->dispatch( $request ); |
|
| 552 | + $response = $this->dispatch($request); |
|
| 553 | 553 | |
| 554 | 554 | /** This filter is documented in wp-includes/rest-api/class-wp-rest-server.php */ |
| 555 | - $response = apply_filters( 'rest_post_dispatch', rest_ensure_response( $response ), $this, $request ); |
|
| 555 | + $response = apply_filters('rest_post_dispatch', rest_ensure_response($response), $this, $request); |
|
| 556 | 556 | |
| 557 | - $embeds[] = $this->response_to_data( $response, false ); |
|
| 557 | + $embeds[] = $this->response_to_data($response, false); |
|
| 558 | 558 | } |
| 559 | 559 | |
| 560 | 560 | // Determine if any real links were found. |
| 561 | - $has_links = count( array_filter( $embeds ) ); |
|
| 562 | - if ( $has_links ) { |
|
| 563 | - $embedded[ $rel ] = $embeds; |
|
| 561 | + $has_links = count(array_filter($embeds)); |
|
| 562 | + if ($has_links) { |
|
| 563 | + $embedded[$rel] = $embeds; |
|
| 564 | 564 | } |
| 565 | 565 | } |
| 566 | 566 | |
| 567 | - if ( ! empty( $embedded ) ) { |
|
| 567 | + if ( ! empty($embedded)) { |
|
| 568 | 568 | $data['_embedded'] = $embedded; |
| 569 | 569 | } |
| 570 | 570 | |
@@ -585,9 +585,9 @@ discard block |
||
| 585 | 585 | * @param bool $embed Whether links should be embedded. |
| 586 | 586 | * @return WP_REST_Response New response with wrapped data |
| 587 | 587 | */ |
| 588 | - public function envelope_response( $response, $embed ) { |
|
| 588 | + public function envelope_response($response, $embed) { |
|
| 589 | 589 | $envelope = array( |
| 590 | - 'body' => $this->response_to_data( $response, $embed ), |
|
| 590 | + 'body' => $this->response_to_data($response, $embed), |
|
| 591 | 591 | 'status' => $response->get_status(), |
| 592 | 592 | 'headers' => $response->get_headers(), |
| 593 | 593 | ); |
@@ -600,10 +600,10 @@ discard block |
||
| 600 | 600 | * @param array $envelope Envelope data. |
| 601 | 601 | * @param WP_REST_Response $response Original response data. |
| 602 | 602 | */ |
| 603 | - $envelope = apply_filters( 'rest_envelope_response', $envelope, $response ); |
|
| 603 | + $envelope = apply_filters('rest_envelope_response', $envelope, $response); |
|
| 604 | 604 | |
| 605 | 605 | // Ensure it's still a response and return. |
| 606 | - return rest_ensure_response( $envelope ); |
|
| 606 | + return rest_ensure_response($envelope); |
|
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | /** |
@@ -618,14 +618,14 @@ discard block |
||
| 618 | 618 | * @param bool $override Optional. Whether the route should be overriden if it already exists. |
| 619 | 619 | * Default false. |
| 620 | 620 | */ |
| 621 | - public function register_route( $namespace, $route, $route_args, $override = false ) { |
|
| 622 | - if ( ! isset( $this->namespaces[ $namespace ] ) ) { |
|
| 623 | - $this->namespaces[ $namespace ] = array(); |
|
| 621 | + public function register_route($namespace, $route, $route_args, $override = false) { |
|
| 622 | + if ( ! isset($this->namespaces[$namespace])) { |
|
| 623 | + $this->namespaces[$namespace] = array(); |
|
| 624 | 624 | |
| 625 | - $this->register_route( $namespace, '/' . $namespace, array( |
|
| 625 | + $this->register_route($namespace, '/'.$namespace, array( |
|
| 626 | 626 | array( |
| 627 | 627 | 'methods' => self::READABLE, |
| 628 | - 'callback' => array( $this, 'get_namespace_index' ), |
|
| 628 | + 'callback' => array($this, 'get_namespace_index'), |
|
| 629 | 629 | 'args' => array( |
| 630 | 630 | 'namespace' => array( |
| 631 | 631 | 'default' => $namespace, |
@@ -635,17 +635,17 @@ discard block |
||
| 635 | 635 | ), |
| 636 | 636 | ), |
| 637 | 637 | ), |
| 638 | - ) ); |
|
| 638 | + )); |
|
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | // Associative to avoid double-registration. |
| 642 | - $this->namespaces[ $namespace ][ $route ] = true; |
|
| 642 | + $this->namespaces[$namespace][$route] = true; |
|
| 643 | 643 | $route_args['namespace'] = $namespace; |
| 644 | 644 | |
| 645 | - if ( $override || empty( $this->endpoints[ $route ] ) ) { |
|
| 646 | - $this->endpoints[ $route ] = $route_args; |
|
| 645 | + if ($override || empty($this->endpoints[$route])) { |
|
| 646 | + $this->endpoints[$route] = $route_args; |
|
| 647 | 647 | } else { |
| 648 | - $this->endpoints[ $route ] = array_merge( $this->endpoints[ $route ], $route_args ); |
|
| 648 | + $this->endpoints[$route] = array_merge($this->endpoints[$route], $route_args); |
|
| 649 | 649 | } |
| 650 | 650 | } |
| 651 | 651 | |
@@ -682,7 +682,7 @@ discard block |
||
| 682 | 682 | * `'/path/regex' => array( $callback, $bitmask )` or |
| 683 | 683 | * `'/path/regex' => array( array( $callback, $bitmask ). |
| 684 | 684 | */ |
| 685 | - $endpoints = apply_filters( 'rest_endpoints', $this->endpoints ); |
|
| 685 | + $endpoints = apply_filters('rest_endpoints', $this->endpoints); |
|
| 686 | 686 | |
| 687 | 687 | // Normalise the endpoints. |
| 688 | 688 | $defaults = array( |
@@ -693,32 +693,32 @@ discard block |
||
| 693 | 693 | 'args' => array(), |
| 694 | 694 | ); |
| 695 | 695 | |
| 696 | - foreach ( $endpoints as $route => &$handlers ) { |
|
| 696 | + foreach ($endpoints as $route => &$handlers) { |
|
| 697 | 697 | |
| 698 | - if ( isset( $handlers['callback'] ) ) { |
|
| 698 | + if (isset($handlers['callback'])) { |
|
| 699 | 699 | // Single endpoint, add one deeper. |
| 700 | - $handlers = array( $handlers ); |
|
| 700 | + $handlers = array($handlers); |
|
| 701 | 701 | } |
| 702 | 702 | |
| 703 | - if ( ! isset( $this->route_options[ $route ] ) ) { |
|
| 704 | - $this->route_options[ $route ] = array(); |
|
| 703 | + if ( ! isset($this->route_options[$route])) { |
|
| 704 | + $this->route_options[$route] = array(); |
|
| 705 | 705 | } |
| 706 | 706 | |
| 707 | - foreach ( $handlers as $key => &$handler ) { |
|
| 707 | + foreach ($handlers as $key => &$handler) { |
|
| 708 | 708 | |
| 709 | - if ( ! is_numeric( $key ) ) { |
|
| 709 | + if ( ! is_numeric($key)) { |
|
| 710 | 710 | // Route option, move it to the options. |
| 711 | - $this->route_options[ $route ][ $key ] = $handler; |
|
| 712 | - unset( $handlers[ $key ] ); |
|
| 711 | + $this->route_options[$route][$key] = $handler; |
|
| 712 | + unset($handlers[$key]); |
|
| 713 | 713 | continue; |
| 714 | 714 | } |
| 715 | 715 | |
| 716 | - $handler = wp_parse_args( $handler, $defaults ); |
|
| 716 | + $handler = wp_parse_args($handler, $defaults); |
|
| 717 | 717 | |
| 718 | 718 | // Allow comma-separated HTTP methods. |
| 719 | - if ( is_string( $handler['methods'] ) ) { |
|
| 720 | - $methods = explode( ',', $handler['methods'] ); |
|
| 721 | - } else if ( is_array( $handler['methods'] ) ) { |
|
| 719 | + if (is_string($handler['methods'])) { |
|
| 720 | + $methods = explode(',', $handler['methods']); |
|
| 721 | + } else if (is_array($handler['methods'])) { |
|
| 722 | 722 | $methods = $handler['methods']; |
| 723 | 723 | } else { |
| 724 | 724 | $methods = array(); |
@@ -726,9 +726,9 @@ discard block |
||
| 726 | 726 | |
| 727 | 727 | $handler['methods'] = array(); |
| 728 | 728 | |
| 729 | - foreach ( $methods as $method ) { |
|
| 730 | - $method = strtoupper( trim( $method ) ); |
|
| 731 | - $handler['methods'][ $method ] = true; |
|
| 729 | + foreach ($methods as $method) { |
|
| 730 | + $method = strtoupper(trim($method)); |
|
| 731 | + $handler['methods'][$method] = true; |
|
| 732 | 732 | } |
| 733 | 733 | } |
| 734 | 734 | } |
@@ -744,7 +744,7 @@ discard block |
||
| 744 | 744 | * @return array List of registered namespaces. |
| 745 | 745 | */ |
| 746 | 746 | public function get_namespaces() { |
| 747 | - return array_keys( $this->namespaces ); |
|
| 747 | + return array_keys($this->namespaces); |
|
| 748 | 748 | } |
| 749 | 749 | |
| 750 | 750 | /** |
@@ -756,12 +756,12 @@ discard block |
||
| 756 | 756 | * @param string $route Route pattern to fetch options for. |
| 757 | 757 | * @return array|null Data as an associative array if found, or null if not found. |
| 758 | 758 | */ |
| 759 | - public function get_route_options( $route ) { |
|
| 760 | - if ( ! isset( $this->route_options[ $route ] ) ) { |
|
| 759 | + public function get_route_options($route) { |
|
| 760 | + if ( ! isset($this->route_options[$route])) { |
|
| 761 | 761 | return null; |
| 762 | 762 | } |
| 763 | 763 | |
| 764 | - return $this->route_options[ $route ]; |
|
| 764 | + return $this->route_options[$route]; |
|
| 765 | 765 | } |
| 766 | 766 | |
| 767 | 767 | /** |
@@ -773,7 +773,7 @@ discard block |
||
| 773 | 773 | * @param WP_REST_Request $request Request to attempt dispatching. |
| 774 | 774 | * @return WP_REST_Response Response returned by the callback. |
| 775 | 775 | */ |
| 776 | - public function dispatch( $request ) { |
|
| 776 | + public function dispatch($request) { |
|
| 777 | 777 | /** |
| 778 | 778 | * Filter the pre-calculated result of a REST dispatch request. |
| 779 | 779 | * |
@@ -787,78 +787,78 @@ discard block |
||
| 787 | 787 | * @param WP_REST_Server $this Server instance. |
| 788 | 788 | * @param WP_REST_Request $request Request used to generate the response. |
| 789 | 789 | */ |
| 790 | - $result = apply_filters( 'rest_pre_dispatch', null, $this, $request ); |
|
| 790 | + $result = apply_filters('rest_pre_dispatch', null, $this, $request); |
|
| 791 | 791 | |
| 792 | - if ( ! empty( $result ) ) { |
|
| 792 | + if ( ! empty($result)) { |
|
| 793 | 793 | return $result; |
| 794 | 794 | } |
| 795 | 795 | |
| 796 | 796 | $method = $request->get_method(); |
| 797 | 797 | $path = $request->get_route(); |
| 798 | 798 | |
| 799 | - foreach ( $this->get_routes() as $route => $handlers ) { |
|
| 800 | - $match = preg_match( '@^' . $route . '$@i', $path, $args ); |
|
| 799 | + foreach ($this->get_routes() as $route => $handlers) { |
|
| 800 | + $match = preg_match('@^'.$route.'$@i', $path, $args); |
|
| 801 | 801 | |
| 802 | - if ( ! $match ) { |
|
| 802 | + if ( ! $match) { |
|
| 803 | 803 | continue; |
| 804 | 804 | } |
| 805 | 805 | |
| 806 | - foreach ( $handlers as $handler ) { |
|
| 807 | - $callback = $handler['callback']; |
|
| 806 | + foreach ($handlers as $handler) { |
|
| 807 | + $callback = $handler['callback']; |
|
| 808 | 808 | $response = null; |
| 809 | 809 | |
| 810 | 810 | // Fallback to GET method if no HEAD method is registered. |
| 811 | 811 | $checked_method = $method; |
| 812 | - if ( 'HEAD' === $method && empty( $handler['methods']['HEAD'] ) ) { |
|
| 812 | + if ('HEAD' === $method && empty($handler['methods']['HEAD'])) { |
|
| 813 | 813 | $checked_method = 'GET'; |
| 814 | 814 | } |
| 815 | - if ( empty( $handler['methods'][ $checked_method ] ) ) { |
|
| 815 | + if (empty($handler['methods'][$checked_method])) { |
|
| 816 | 816 | continue; |
| 817 | 817 | } |
| 818 | 818 | |
| 819 | - if ( ! is_callable( $callback ) ) { |
|
| 820 | - $response = new WP_Error( 'rest_invalid_handler', __( 'The handler for the route is invalid' ), array( 'status' => 500 ) ); |
|
| 819 | + if ( ! is_callable($callback)) { |
|
| 820 | + $response = new WP_Error('rest_invalid_handler', __('The handler for the route is invalid'), array('status' => 500)); |
|
| 821 | 821 | } |
| 822 | 822 | |
| 823 | - if ( ! is_wp_error( $response ) ) { |
|
| 823 | + if ( ! is_wp_error($response)) { |
|
| 824 | 824 | // Remove the redundant preg_match argument. |
| 825 | - unset( $args[0] ); |
|
| 825 | + unset($args[0]); |
|
| 826 | 826 | |
| 827 | - $request->set_url_params( $args ); |
|
| 828 | - $request->set_attributes( $handler ); |
|
| 827 | + $request->set_url_params($args); |
|
| 828 | + $request->set_attributes($handler); |
|
| 829 | 829 | |
| 830 | 830 | $request->sanitize_params(); |
| 831 | 831 | |
| 832 | 832 | $defaults = array(); |
| 833 | 833 | |
| 834 | - foreach ( $handler['args'] as $arg => $options ) { |
|
| 835 | - if ( isset( $options['default'] ) ) { |
|
| 836 | - $defaults[ $arg ] = $options['default']; |
|
| 834 | + foreach ($handler['args'] as $arg => $options) { |
|
| 835 | + if (isset($options['default'])) { |
|
| 836 | + $defaults[$arg] = $options['default']; |
|
| 837 | 837 | } |
| 838 | 838 | } |
| 839 | 839 | |
| 840 | - $request->set_default_params( $defaults ); |
|
| 840 | + $request->set_default_params($defaults); |
|
| 841 | 841 | |
| 842 | 842 | $check_required = $request->has_valid_params(); |
| 843 | - if ( is_wp_error( $check_required ) ) { |
|
| 843 | + if (is_wp_error($check_required)) { |
|
| 844 | 844 | $response = $check_required; |
| 845 | 845 | } |
| 846 | 846 | } |
| 847 | 847 | |
| 848 | - if ( ! is_wp_error( $response ) ) { |
|
| 848 | + if ( ! is_wp_error($response)) { |
|
| 849 | 849 | // Check permission specified on the route. |
| 850 | - if ( ! empty( $handler['permission_callback'] ) ) { |
|
| 851 | - $permission = call_user_func( $handler['permission_callback'], $request ); |
|
| 850 | + if ( ! empty($handler['permission_callback'])) { |
|
| 851 | + $permission = call_user_func($handler['permission_callback'], $request); |
|
| 852 | 852 | |
| 853 | - if ( is_wp_error( $permission ) ) { |
|
| 853 | + if (is_wp_error($permission)) { |
|
| 854 | 854 | $response = $permission; |
| 855 | - } else if ( false === $permission || null === $permission ) { |
|
| 856 | - $response = new WP_Error( 'rest_forbidden', __( "You don't have permission to do this." ), array( 'status' => 403 ) ); |
|
| 855 | + } else if (false === $permission || null === $permission) { |
|
| 856 | + $response = new WP_Error('rest_forbidden', __("You don't have permission to do this."), array('status' => 403)); |
|
| 857 | 857 | } |
| 858 | 858 | } |
| 859 | 859 | } |
| 860 | 860 | |
| 861 | - if ( ! is_wp_error( $response ) ) { |
|
| 861 | + if ( ! is_wp_error($response)) { |
|
| 862 | 862 | /** |
| 863 | 863 | * Filter the REST dispatch request result. |
| 864 | 864 | * |
@@ -872,30 +872,30 @@ discard block |
||
| 872 | 872 | * @param string $route Route matched for the request. |
| 873 | 873 | * @param array $handler Route handler used for the request. |
| 874 | 874 | */ |
| 875 | - $dispatch_result = apply_filters( 'rest_dispatch_request', null, $request, $route, $handler ); |
|
| 875 | + $dispatch_result = apply_filters('rest_dispatch_request', null, $request, $route, $handler); |
|
| 876 | 876 | |
| 877 | 877 | // Allow plugins to halt the request via this filter. |
| 878 | - if ( null !== $dispatch_result ) { |
|
| 878 | + if (null !== $dispatch_result) { |
|
| 879 | 879 | $response = $dispatch_result; |
| 880 | 880 | } else { |
| 881 | - $response = call_user_func( $callback, $request ); |
|
| 881 | + $response = call_user_func($callback, $request); |
|
| 882 | 882 | } |
| 883 | 883 | } |
| 884 | 884 | |
| 885 | - if ( is_wp_error( $response ) ) { |
|
| 886 | - $response = $this->error_to_response( $response ); |
|
| 885 | + if (is_wp_error($response)) { |
|
| 886 | + $response = $this->error_to_response($response); |
|
| 887 | 887 | } else { |
| 888 | - $response = rest_ensure_response( $response ); |
|
| 888 | + $response = rest_ensure_response($response); |
|
| 889 | 889 | } |
| 890 | 890 | |
| 891 | - $response->set_matched_route( $route ); |
|
| 892 | - $response->set_matched_handler( $handler ); |
|
| 891 | + $response->set_matched_route($route); |
|
| 892 | + $response->set_matched_handler($handler); |
|
| 893 | 893 | |
| 894 | 894 | return $response; |
| 895 | 895 | } |
| 896 | 896 | } |
| 897 | 897 | |
| 898 | - return $this->error_to_response( new WP_Error( 'rest_no_route', __( 'No route was found matching the URL and request method' ), array( 'status' => 404 ) ) ); |
|
| 898 | + return $this->error_to_response(new WP_Error('rest_no_route', __('No route was found matching the URL and request method'), array('status' => 404))); |
|
| 899 | 899 | } |
| 900 | 900 | |
| 901 | 901 | /** |
@@ -911,13 +911,13 @@ discard block |
||
| 911 | 911 | */ |
| 912 | 912 | protected function get_json_last_error() { |
| 913 | 913 | // See https://core.trac.wordpress.org/ticket/27799. |
| 914 | - if ( ! function_exists( 'json_last_error' ) ) { |
|
| 914 | + if ( ! function_exists('json_last_error')) { |
|
| 915 | 915 | return false; |
| 916 | 916 | } |
| 917 | 917 | |
| 918 | 918 | $last_error_code = json_last_error(); |
| 919 | 919 | |
| 920 | - if ( ( defined( 'JSON_ERROR_NONE' ) && JSON_ERROR_NONE === $last_error_code ) || empty( $last_error_code ) ) { |
|
| 920 | + if ((defined('JSON_ERROR_NONE') && JSON_ERROR_NONE === $last_error_code) || empty($last_error_code)) { |
|
| 921 | 921 | return false; |
| 922 | 922 | } |
| 923 | 923 | |
@@ -939,20 +939,20 @@ discard block |
||
| 939 | 939 | * } |
| 940 | 940 | * @return array Index entity |
| 941 | 941 | */ |
| 942 | - public function get_index( $request ) { |
|
| 942 | + public function get_index($request) { |
|
| 943 | 943 | // General site data. |
| 944 | 944 | $available = array( |
| 945 | - 'name' => get_option( 'blogname' ), |
|
| 946 | - 'description' => get_option( 'blogdescription' ), |
|
| 947 | - 'url' => get_option( 'siteurl' ), |
|
| 948 | - 'namespaces' => array_keys( $this->namespaces ), |
|
| 945 | + 'name' => get_option('blogname'), |
|
| 946 | + 'description' => get_option('blogdescription'), |
|
| 947 | + 'url' => get_option('siteurl'), |
|
| 948 | + 'namespaces' => array_keys($this->namespaces), |
|
| 949 | 949 | 'authentication' => array(), |
| 950 | - 'routes' => $this->get_data_for_routes( $this->get_routes(), $request['context'] ), |
|
| 950 | + 'routes' => $this->get_data_for_routes($this->get_routes(), $request['context']), |
|
| 951 | 951 | ); |
| 952 | 952 | |
| 953 | - $response = new WP_REST_Response( $available ); |
|
| 953 | + $response = new WP_REST_Response($available); |
|
| 954 | 954 | |
| 955 | - $response->add_link( 'help', 'http://v2.wp-api.org/' ); |
|
| 955 | + $response->add_link('help', 'http://v2.wp-api.org/'); |
|
| 956 | 956 | |
| 957 | 957 | /** |
| 958 | 958 | * Filter the API root index data. |
@@ -965,7 +965,7 @@ discard block |
||
| 965 | 965 | * |
| 966 | 966 | * @param WP_REST_Response $response Response data. |
| 967 | 967 | */ |
| 968 | - return apply_filters( 'rest_index', $response ); |
|
| 968 | + return apply_filters('rest_index', $response); |
|
| 969 | 969 | } |
| 970 | 970 | |
| 971 | 971 | /** |
@@ -978,24 +978,24 @@ discard block |
||
| 978 | 978 | * @return WP_REST_Response|WP_Error WP_REST_Response instance if the index was found, |
| 979 | 979 | * WP_Error if the namespace isn't set. |
| 980 | 980 | */ |
| 981 | - public function get_namespace_index( $request ) { |
|
| 981 | + public function get_namespace_index($request) { |
|
| 982 | 982 | $namespace = $request['namespace']; |
| 983 | 983 | |
| 984 | - if ( ! isset( $this->namespaces[ $namespace ] ) ) { |
|
| 985 | - return new WP_Error( 'rest_invalid_namespace', __( 'The specified namespace could not be found.' ), array( 'status' => 404 ) ); |
|
| 984 | + if ( ! isset($this->namespaces[$namespace])) { |
|
| 985 | + return new WP_Error('rest_invalid_namespace', __('The specified namespace could not be found.'), array('status' => 404)); |
|
| 986 | 986 | } |
| 987 | 987 | |
| 988 | - $routes = $this->namespaces[ $namespace ]; |
|
| 989 | - $endpoints = array_intersect_key( $this->get_routes(), $routes ); |
|
| 988 | + $routes = $this->namespaces[$namespace]; |
|
| 989 | + $endpoints = array_intersect_key($this->get_routes(), $routes); |
|
| 990 | 990 | |
| 991 | 991 | $data = array( |
| 992 | 992 | 'namespace' => $namespace, |
| 993 | - 'routes' => $this->get_data_for_routes( $endpoints, $request['context'] ), |
|
| 993 | + 'routes' => $this->get_data_for_routes($endpoints, $request['context']), |
|
| 994 | 994 | ); |
| 995 | - $response = rest_ensure_response( $data ); |
|
| 995 | + $response = rest_ensure_response($data); |
|
| 996 | 996 | |
| 997 | 997 | // Link to the root index. |
| 998 | - $response->add_link( 'up', rest_url( '/' ) ); |
|
| 998 | + $response->add_link('up', rest_url('/')); |
|
| 999 | 999 | |
| 1000 | 1000 | /** |
| 1001 | 1001 | * Filter the namespace index data. |
@@ -1008,7 +1008,7 @@ discard block |
||
| 1008 | 1008 | * @param WP_REST_Response $response Response data. |
| 1009 | 1009 | * @param WP_REST_Request $request Request data. The namespace is passed as the 'namespace' parameter. |
| 1010 | 1010 | */ |
| 1011 | - return apply_filters( 'rest_namespace_index', $response, $request ); |
|
| 1011 | + return apply_filters('rest_namespace_index', $response, $request); |
|
| 1012 | 1012 | } |
| 1013 | 1013 | |
| 1014 | 1014 | /** |
@@ -1021,13 +1021,13 @@ discard block |
||
| 1021 | 1021 | * @param string $context Optional. Context for data. Accepts 'view' or 'help'. Default 'view'. |
| 1022 | 1022 | * @return array Route data to expose in indexes. |
| 1023 | 1023 | */ |
| 1024 | - public function get_data_for_routes( $routes, $context = 'view' ) { |
|
| 1024 | + public function get_data_for_routes($routes, $context = 'view') { |
|
| 1025 | 1025 | $available = array(); |
| 1026 | 1026 | |
| 1027 | 1027 | // Find the available routes. |
| 1028 | - foreach ( $routes as $route => $callbacks ) { |
|
| 1029 | - $data = $this->get_data_for_route( $route, $callbacks, $context ); |
|
| 1030 | - if ( empty( $data ) ) { |
|
| 1028 | + foreach ($routes as $route => $callbacks) { |
|
| 1029 | + $data = $this->get_data_for_route($route, $callbacks, $context); |
|
| 1030 | + if (empty($data)) { |
|
| 1031 | 1031 | continue; |
| 1032 | 1032 | } |
| 1033 | 1033 | |
@@ -1038,7 +1038,7 @@ discard block |
||
| 1038 | 1038 | * |
| 1039 | 1039 | * @param WP_REST_Request $request Request data. The namespace is passed as the 'namespace' parameter. |
| 1040 | 1040 | */ |
| 1041 | - $available[ $route ] = apply_filters( 'rest_endpoints_description', $data ); |
|
| 1041 | + $available[$route] = apply_filters('rest_endpoints_description', $data); |
|
| 1042 | 1042 | } |
| 1043 | 1043 | |
| 1044 | 1044 | /** |
@@ -1053,7 +1053,7 @@ discard block |
||
| 1053 | 1053 | * @param array $available Map of route to route data. |
| 1054 | 1054 | * @param array $routes Internal route data as an associative array. |
| 1055 | 1055 | */ |
| 1056 | - return apply_filters( 'rest_route_data', $available, $routes ); |
|
| 1056 | + return apply_filters('rest_route_data', $available, $routes); |
|
| 1057 | 1057 | } |
| 1058 | 1058 | |
| 1059 | 1059 | /** |
@@ -1067,68 +1067,68 @@ discard block |
||
| 1067 | 1067 | * @param string $context Optional. Context for the data. Accepts 'view' or 'help'. Default 'view'. |
| 1068 | 1068 | * @return array|null Data for the route, or null if no publicly-visible data. |
| 1069 | 1069 | */ |
| 1070 | - public function get_data_for_route( $route, $callbacks, $context = 'view' ) { |
|
| 1070 | + public function get_data_for_route($route, $callbacks, $context = 'view') { |
|
| 1071 | 1071 | $data = array( |
| 1072 | 1072 | 'namespace' => '', |
| 1073 | 1073 | 'methods' => array(), |
| 1074 | 1074 | 'endpoints' => array(), |
| 1075 | 1075 | ); |
| 1076 | 1076 | |
| 1077 | - if ( isset( $this->route_options[ $route ] ) ) { |
|
| 1078 | - $options = $this->route_options[ $route ]; |
|
| 1077 | + if (isset($this->route_options[$route])) { |
|
| 1078 | + $options = $this->route_options[$route]; |
|
| 1079 | 1079 | |
| 1080 | - if ( isset( $options['namespace'] ) ) { |
|
| 1080 | + if (isset($options['namespace'])) { |
|
| 1081 | 1081 | $data['namespace'] = $options['namespace']; |
| 1082 | 1082 | } |
| 1083 | 1083 | |
| 1084 | - if ( isset( $options['schema'] ) && 'help' === $context ) { |
|
| 1085 | - $data['schema'] = call_user_func( $options['schema'] ); |
|
| 1084 | + if (isset($options['schema']) && 'help' === $context) { |
|
| 1085 | + $data['schema'] = call_user_func($options['schema']); |
|
| 1086 | 1086 | } |
| 1087 | 1087 | } |
| 1088 | 1088 | |
| 1089 | - $route = preg_replace( '#\(\?P<(\w+?)>.*?\)#', '{$1}', $route ); |
|
| 1089 | + $route = preg_replace('#\(\?P<(\w+?)>.*?\)#', '{$1}', $route); |
|
| 1090 | 1090 | |
| 1091 | - foreach ( $callbacks as $callback ) { |
|
| 1091 | + foreach ($callbacks as $callback) { |
|
| 1092 | 1092 | // Skip to the next route if any callback is hidden. |
| 1093 | - if ( empty( $callback['show_in_index'] ) ) { |
|
| 1093 | + if (empty($callback['show_in_index'])) { |
|
| 1094 | 1094 | continue; |
| 1095 | 1095 | } |
| 1096 | 1096 | |
| 1097 | - $data['methods'] = array_merge( $data['methods'], array_keys( $callback['methods'] ) ); |
|
| 1097 | + $data['methods'] = array_merge($data['methods'], array_keys($callback['methods'])); |
|
| 1098 | 1098 | $endpoint_data = array( |
| 1099 | - 'methods' => array_keys( $callback['methods'] ), |
|
| 1099 | + 'methods' => array_keys($callback['methods']), |
|
| 1100 | 1100 | ); |
| 1101 | 1101 | |
| 1102 | - if ( isset( $callback['args'] ) ) { |
|
| 1102 | + if (isset($callback['args'])) { |
|
| 1103 | 1103 | $endpoint_data['args'] = array(); |
| 1104 | - foreach ( $callback['args'] as $key => $opts ) { |
|
| 1104 | + foreach ($callback['args'] as $key => $opts) { |
|
| 1105 | 1105 | $arg_data = array( |
| 1106 | - 'required' => ! empty( $opts['required'] ), |
|
| 1106 | + 'required' => ! empty($opts['required']), |
|
| 1107 | 1107 | ); |
| 1108 | - if ( isset( $opts['default'] ) ) { |
|
| 1108 | + if (isset($opts['default'])) { |
|
| 1109 | 1109 | $arg_data['default'] = $opts['default']; |
| 1110 | 1110 | } |
| 1111 | - if ( isset( $opts['enum'] ) ) { |
|
| 1111 | + if (isset($opts['enum'])) { |
|
| 1112 | 1112 | $arg_data['enum'] = $opts['enum']; |
| 1113 | 1113 | } |
| 1114 | - if ( isset( $opts['description'] ) ) { |
|
| 1114 | + if (isset($opts['description'])) { |
|
| 1115 | 1115 | $arg_data['description'] = $opts['description']; |
| 1116 | 1116 | } |
| 1117 | - $endpoint_data['args'][ $key ] = $arg_data; |
|
| 1117 | + $endpoint_data['args'][$key] = $arg_data; |
|
| 1118 | 1118 | } |
| 1119 | 1119 | } |
| 1120 | 1120 | |
| 1121 | 1121 | $data['endpoints'][] = $endpoint_data; |
| 1122 | 1122 | |
| 1123 | 1123 | // For non-variable routes, generate links. |
| 1124 | - if ( strpos( $route, '{' ) === false ) { |
|
| 1124 | + if (strpos($route, '{') === false) { |
|
| 1125 | 1125 | $data['_links'] = array( |
| 1126 | - 'self' => rest_url( $route ), |
|
| 1126 | + 'self' => rest_url($route), |
|
| 1127 | 1127 | ); |
| 1128 | 1128 | } |
| 1129 | 1129 | } |
| 1130 | 1130 | |
| 1131 | - if ( empty( $data['methods'] ) ) { |
|
| 1131 | + if (empty($data['methods'])) { |
|
| 1132 | 1132 | // No methods supported, hide the route. |
| 1133 | 1133 | return null; |
| 1134 | 1134 | } |
@@ -1144,8 +1144,8 @@ discard block |
||
| 1144 | 1144 | * |
| 1145 | 1145 | * @param int $code HTTP status. |
| 1146 | 1146 | */ |
| 1147 | - protected function set_status( $code ) { |
|
| 1148 | - status_header( $code ); |
|
| 1147 | + protected function set_status($code) { |
|
| 1148 | + status_header($code); |
|
| 1149 | 1149 | } |
| 1150 | 1150 | |
| 1151 | 1151 | /** |
@@ -1157,7 +1157,7 @@ discard block |
||
| 1157 | 1157 | * @param string $key Header key. |
| 1158 | 1158 | * @param string $value Header value. |
| 1159 | 1159 | */ |
| 1160 | - public function send_header( $key, $value ) { |
|
| 1160 | + public function send_header($key, $value) { |
|
| 1161 | 1161 | /* |
| 1162 | 1162 | * Sanitize as per RFC2616 (Section 4.2): |
| 1163 | 1163 | * |
@@ -1165,8 +1165,8 @@ discard block |
||
| 1165 | 1165 | * single SP before interpreting the field value or forwarding the |
| 1166 | 1166 | * message downstream. |
| 1167 | 1167 | */ |
| 1168 | - $value = preg_replace( '/\s+/', ' ', $value ); |
|
| 1169 | - header( sprintf( '%s: %s', $key, $value ) ); |
|
| 1168 | + $value = preg_replace('/\s+/', ' ', $value); |
|
| 1169 | + header(sprintf('%s: %s', $key, $value)); |
|
| 1170 | 1170 | } |
| 1171 | 1171 | |
| 1172 | 1172 | /** |
@@ -1177,9 +1177,9 @@ discard block |
||
| 1177 | 1177 | * |
| 1178 | 1178 | * @param array $headers Map of header name to header value. |
| 1179 | 1179 | */ |
| 1180 | - public function send_headers( $headers ) { |
|
| 1181 | - foreach ( $headers as $key => $value ) { |
|
| 1182 | - $this->send_header( $key, $value ); |
|
| 1180 | + public function send_headers($headers) { |
|
| 1181 | + foreach ($headers as $key => $value) { |
|
| 1182 | + $this->send_header($key, $value); |
|
| 1183 | 1183 | } |
| 1184 | 1184 | } |
| 1185 | 1185 | |
@@ -1200,8 +1200,8 @@ discard block |
||
| 1200 | 1200 | * A bug in PHP < 5.2.2 makes $HTTP_RAW_POST_DATA not set by default, |
| 1201 | 1201 | * but we can do it ourself. |
| 1202 | 1202 | */ |
| 1203 | - if ( ! isset( $HTTP_RAW_POST_DATA ) ) { |
|
| 1204 | - $HTTP_RAW_POST_DATA = file_get_contents( 'php://input' ); |
|
| 1203 | + if ( ! isset($HTTP_RAW_POST_DATA)) { |
|
| 1204 | + $HTTP_RAW_POST_DATA = file_get_contents('php://input'); |
|
| 1205 | 1205 | } |
| 1206 | 1206 | |
| 1207 | 1207 | return $HTTP_RAW_POST_DATA; |
@@ -1216,17 +1216,17 @@ discard block |
||
| 1216 | 1216 | * @param array $server Associative array similar to `$_SERVER`. |
| 1217 | 1217 | * @return array Headers extracted from the input. |
| 1218 | 1218 | */ |
| 1219 | - public function get_headers( $server ) { |
|
| 1219 | + public function get_headers($server) { |
|
| 1220 | 1220 | $headers = array(); |
| 1221 | 1221 | |
| 1222 | 1222 | // CONTENT_* headers are not prefixed with HTTP_. |
| 1223 | - $additional = array( 'CONTENT_LENGTH' => true, 'CONTENT_MD5' => true, 'CONTENT_TYPE' => true ); |
|
| 1223 | + $additional = array('CONTENT_LENGTH' => true, 'CONTENT_MD5' => true, 'CONTENT_TYPE' => true); |
|
| 1224 | 1224 | |
| 1225 | - foreach ( $server as $key => $value ) { |
|
| 1226 | - if ( strpos( $key, 'HTTP_' ) === 0 ) { |
|
| 1227 | - $headers[ substr( $key, 5 ) ] = $value; |
|
| 1228 | - } elseif ( isset( $additional[ $key ] ) ) { |
|
| 1229 | - $headers[ $key ] = $value; |
|
| 1225 | + foreach ($server as $key => $value) { |
|
| 1226 | + if (strpos($key, 'HTTP_') === 0) { |
|
| 1227 | + $headers[substr($key, 5)] = $value; |
|
| 1228 | + } elseif (isset($additional[$key])) { |
|
| 1229 | + $headers[$key] = $value; |
|
| 1230 | 1230 | } |
| 1231 | 1231 | } |
| 1232 | 1232 | |
@@ -734,7 +734,7 @@ discard block |
||
| 734 | 734 | * |
| 735 | 735 | * @param int $user_id User ID. |
| 736 | 736 | * @param string $meta_key Metadata name. |
| 737 | - * @param mixed $meta_value Metadata value. |
|
| 737 | + * @param string $meta_value Metadata value. |
|
| 738 | 738 | * @param bool $unique Optional, default is false. Whether the same key should not be added. |
| 739 | 739 | * @return int|false Meta ID on success, false on failure. |
| 740 | 740 | */ |
@@ -1211,7 +1211,7 @@ discard block |
||
| 1211 | 1211 | * @since 3.0.0 |
| 1212 | 1212 | * |
| 1213 | 1213 | * @param object|WP_User $user User object to be cached |
| 1214 | - * @return bool|null Returns false on failure. |
|
| 1214 | + * @return false|null Returns false on failure. |
|
| 1215 | 1215 | */ |
| 1216 | 1216 | function update_user_caches( $user ) { |
| 1217 | 1217 | if ( $user instanceof WP_User ) { |
@@ -1,10 +1,10 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Core User API |
|
| 4 | - * |
|
| 5 | - * @package WordPress |
|
| 6 | - * @subpackage Users |
|
| 7 | - */ |
|
| 3 | + * Core User API |
|
| 4 | + * |
|
| 5 | + * @package WordPress |
|
| 6 | + * @subpackage Users |
|
| 7 | + */ |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Authenticates and logs a user in with 'remember' capability. |
@@ -65,13 +65,13 @@ discard block |
||
| 65 | 65 | * |
| 66 | 66 | * @param bool $secure_cookie Whether to use a secure sign-on cookie. |
| 67 | 67 | * @param array $credentials { |
| 68 | - * Array of entered sign-on data. |
|
| 69 | - * |
|
| 70 | - * @type string $user_login Username. |
|
| 71 | - * @type string $user_password Password entered. |
|
| 68 | + * Array of entered sign-on data. |
|
| 69 | + * |
|
| 70 | + * @type string $user_login Username. |
|
| 71 | + * @type string $user_password Password entered. |
|
| 72 | 72 | * @type bool $remember Whether to 'remember' the user. Increases the time |
| 73 | 73 | * that the cookie will be kept. Default false. |
| 74 | - * } |
|
| 74 | + * } |
|
| 75 | 75 | */ |
| 76 | 76 | $secure_cookie = apply_filters( 'secure_signon_cookie', $secure_cookie, $credentials ); |
| 77 | 77 | |
@@ -1163,7 +1163,7 @@ discard block |
||
| 1163 | 1163 | * |
| 1164 | 1164 | * The dynamic portion of the hook name, `$field`, refers to the prefixed user |
| 1165 | 1165 | * field being filtered, such as 'user_login', 'user_email', 'first_name', etc. |
| 1166 | - * |
|
| 1166 | + * |
|
| 1167 | 1167 | * @since 2.9.0 |
| 1168 | 1168 | * |
| 1169 | 1169 | * @param mixed $value Value of the prefixed user field. |
@@ -1604,16 +1604,16 @@ discard block |
||
| 1604 | 1604 | $user = new WP_User( $user_id ); |
| 1605 | 1605 | |
| 1606 | 1606 | /** |
| 1607 | - * Filter a user's meta values and keys before the user is created or updated. |
|
| 1608 | - * |
|
| 1609 | - * Does not include contact methods. These are added using `wp_get_user_contact_methods( $user )`. |
|
| 1610 | - * |
|
| 1611 | - * @since 4.4.0 |
|
| 1612 | - * |
|
| 1613 | - * @param array $meta { |
|
| 1614 | - * Default meta values and keys for the user. |
|
| 1615 | - * |
|
| 1616 | - * @type string $nickname The user's nickname. Default is the user's username. |
|
| 1607 | + * Filter a user's meta values and keys before the user is created or updated. |
|
| 1608 | + * |
|
| 1609 | + * Does not include contact methods. These are added using `wp_get_user_contact_methods( $user )`. |
|
| 1610 | + * |
|
| 1611 | + * @since 4.4.0 |
|
| 1612 | + * |
|
| 1613 | + * @param array $meta { |
|
| 1614 | + * Default meta values and keys for the user. |
|
| 1615 | + * |
|
| 1616 | + * @type string $nickname The user's nickname. Default is the user's username. |
|
| 1617 | 1617 | * @type string $first_name The user's first name. |
| 1618 | 1618 | * @type string $last_name The user's last name. |
| 1619 | 1619 | * @type string $description The user's description. |
@@ -1624,10 +1624,10 @@ discard block |
||
| 1624 | 1624 | * not forced. |
| 1625 | 1625 | * @type bool $show_admin_bar_front Whether to show the admin bar on the front end for the user. |
| 1626 | 1626 | * Default true. |
| 1627 | - * } |
|
| 1627 | + * } |
|
| 1628 | 1628 | * @param WP_User $user User object. |
| 1629 | 1629 | * @param bool $update Whether the user is being updated rather than created. |
| 1630 | - */ |
|
| 1630 | + */ |
|
| 1631 | 1631 | $meta = apply_filters( 'insert_user_meta', $meta, $user, $update ); |
| 1632 | 1632 | |
| 1633 | 1633 | // Update user meta. |
@@ -1962,7 +1962,7 @@ discard block |
||
| 1962 | 1962 | * @since 2.9.0 |
| 1963 | 1963 | * |
| 1964 | 1964 | * @param array $methods Array of contact methods and their labels. |
| 1965 | - * @param WP_User $user WP_User object. |
|
| 1965 | + * @param WP_User $user WP_User object. |
|
| 1966 | 1966 | */ |
| 1967 | 1967 | return apply_filters( 'user_contactmethods', $methods, $user ); |
| 1968 | 1968 | } |
@@ -25,17 +25,17 @@ discard block |
||
| 25 | 25 | * @param string|bool $secure_cookie Optional. Whether to use secure cookie. |
| 26 | 26 | * @return WP_User|WP_Error WP_User on success, WP_Error on failure. |
| 27 | 27 | */ |
| 28 | -function wp_signon( $credentials = array(), $secure_cookie = '' ) { |
|
| 29 | - if ( empty($credentials) ) { |
|
| 30 | - if ( ! empty($_POST['log']) ) |
|
| 28 | +function wp_signon($credentials = array(), $secure_cookie = '') { |
|
| 29 | + if (empty($credentials)) { |
|
| 30 | + if ( ! empty($_POST['log'])) |
|
| 31 | 31 | $credentials['user_login'] = $_POST['log']; |
| 32 | - if ( ! empty($_POST['pwd']) ) |
|
| 32 | + if ( ! empty($_POST['pwd'])) |
|
| 33 | 33 | $credentials['user_password'] = $_POST['pwd']; |
| 34 | - if ( ! empty($_POST['rememberme']) ) |
|
| 34 | + if ( ! empty($_POST['rememberme'])) |
|
| 35 | 35 | $credentials['remember'] = $_POST['rememberme']; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - if ( !empty($credentials['remember']) ) |
|
| 38 | + if ( ! empty($credentials['remember'])) |
|
| 39 | 39 | $credentials['remember'] = true; |
| 40 | 40 | else |
| 41 | 41 | $credentials['remember'] = false; |
@@ -53,9 +53,9 @@ discard block |
||
| 53 | 53 | * @param string $user_login Username, passed by reference. |
| 54 | 54 | * @param string $user_password User password, passed by reference. |
| 55 | 55 | */ |
| 56 | - do_action_ref_array( 'wp_authenticate', array( &$credentials['user_login'], &$credentials['user_password'] ) ); |
|
| 56 | + do_action_ref_array('wp_authenticate', array(&$credentials['user_login'], &$credentials['user_password'])); |
|
| 57 | 57 | |
| 58 | - if ( '' === $secure_cookie ) |
|
| 58 | + if ('' === $secure_cookie) |
|
| 59 | 59 | $secure_cookie = is_ssl(); |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * that the cookie will be kept. Default false. |
| 74 | 74 | * } |
| 75 | 75 | */ |
| 76 | - $secure_cookie = apply_filters( 'secure_signon_cookie', $secure_cookie, $credentials ); |
|
| 76 | + $secure_cookie = apply_filters('secure_signon_cookie', $secure_cookie, $credentials); |
|
| 77 | 77 | |
| 78 | 78 | global $auth_secure_cookie; // XXX ugly hack to pass this to wp_authenticate_cookie |
| 79 | 79 | $auth_secure_cookie = $secure_cookie; |
@@ -82,8 +82,8 @@ discard block |
||
| 82 | 82 | |
| 83 | 83 | $user = wp_authenticate($credentials['user_login'], $credentials['user_password']); |
| 84 | 84 | |
| 85 | - if ( is_wp_error($user) ) { |
|
| 86 | - if ( $user->get_error_codes() == array('empty_username', 'empty_password') ) { |
|
| 85 | + if (is_wp_error($user)) { |
|
| 86 | + if ($user->get_error_codes() == array('empty_username', 'empty_password')) { |
|
| 87 | 87 | $user = new WP_Error('', ''); |
| 88 | 88 | } |
| 89 | 89 | |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | * @param string $user_login Username. |
| 100 | 100 | * @param WP_User $user WP_User object of the logged-in user. |
| 101 | 101 | */ |
| 102 | - do_action( 'wp_login', $user->user_login, $user ); |
|
| 102 | + do_action('wp_login', $user->user_login, $user); |
|
| 103 | 103 | return $user; |
| 104 | 104 | } |
| 105 | 105 | |
@@ -114,20 +114,20 @@ discard block |
||
| 114 | 114 | * @return WP_User|WP_Error WP_User on success, WP_Error on failure. |
| 115 | 115 | */ |
| 116 | 116 | function wp_authenticate_username_password($user, $username, $password) { |
| 117 | - if ( $user instanceof WP_User ) { |
|
| 117 | + if ($user instanceof WP_User) { |
|
| 118 | 118 | return $user; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - if ( empty($username) || empty($password) ) { |
|
| 122 | - if ( is_wp_error( $user ) ) |
|
| 121 | + if (empty($username) || empty($password)) { |
|
| 122 | + if (is_wp_error($user)) |
|
| 123 | 123 | return $user; |
| 124 | 124 | |
| 125 | 125 | $error = new WP_Error(); |
| 126 | 126 | |
| 127 | - if ( empty($username) ) |
|
| 127 | + if (empty($username)) |
|
| 128 | 128 | $error->add('empty_username', __('<strong>ERROR</strong>: The username field is empty.')); |
| 129 | 129 | |
| 130 | - if ( empty($password) ) |
|
| 130 | + if (empty($password)) |
|
| 131 | 131 | $error->add('empty_password', __('<strong>ERROR</strong>: The password field is empty.')); |
| 132 | 132 | |
| 133 | 133 | return $error; |
@@ -135,11 +135,11 @@ discard block |
||
| 135 | 135 | |
| 136 | 136 | $user = get_user_by('login', $username); |
| 137 | 137 | |
| 138 | - if ( !$user ) { |
|
| 139 | - return new WP_Error( 'invalid_username', |
|
| 140 | - __( '<strong>ERROR</strong>: Invalid username.' ) . |
|
| 141 | - ' <a href="' . wp_lostpassword_url() . '">' . |
|
| 142 | - __( 'Lost your password?' ) . |
|
| 138 | + if ( ! $user) { |
|
| 139 | + return new WP_Error('invalid_username', |
|
| 140 | + __('<strong>ERROR</strong>: Invalid username.'). |
|
| 141 | + ' <a href="'.wp_lostpassword_url().'">'. |
|
| 142 | + __('Lost your password?'). |
|
| 143 | 143 | '</a>' |
| 144 | 144 | ); |
| 145 | 145 | } |
@@ -153,19 +153,19 @@ discard block |
||
| 153 | 153 | * callback failed authentication. |
| 154 | 154 | * @param string $password Password to check against the user. |
| 155 | 155 | */ |
| 156 | - $user = apply_filters( 'wp_authenticate_user', $user, $password ); |
|
| 157 | - if ( is_wp_error($user) ) |
|
| 156 | + $user = apply_filters('wp_authenticate_user', $user, $password); |
|
| 157 | + if (is_wp_error($user)) |
|
| 158 | 158 | return $user; |
| 159 | 159 | |
| 160 | - if ( ! wp_check_password( $password, $user->user_pass, $user->ID ) ) { |
|
| 161 | - return new WP_Error( 'incorrect_password', |
|
| 160 | + if ( ! wp_check_password($password, $user->user_pass, $user->ID)) { |
|
| 161 | + return new WP_Error('incorrect_password', |
|
| 162 | 162 | sprintf( |
| 163 | 163 | /* translators: %s: user name */ |
| 164 | - __( '<strong>ERROR</strong>: The password you entered for the username %s is incorrect.' ), |
|
| 165 | - '<strong>' . $username . '</strong>' |
|
| 166 | - ) . |
|
| 167 | - ' <a href="' . wp_lostpassword_url() . '">' . |
|
| 168 | - __( 'Lost your password?' ) . |
|
| 164 | + __('<strong>ERROR</strong>: The password you entered for the username %s is incorrect.'), |
|
| 165 | + '<strong>'.$username.'</strong>' |
|
| 166 | + ). |
|
| 167 | + ' <a href="'.wp_lostpassword_url().'">'. |
|
| 168 | + __('Lost your password?'). |
|
| 169 | 169 | '</a>' |
| 170 | 170 | ); |
| 171 | 171 | } |
@@ -184,60 +184,60 @@ discard block |
||
| 184 | 184 | * @param string $password Password for authentication. |
| 185 | 185 | * @return WP_User|WP_Error WP_User on success, WP_Error on failure. |
| 186 | 186 | */ |
| 187 | -function wp_authenticate_email_password( $user, $email, $password ) { |
|
| 188 | - if ( $user instanceof WP_User ) { |
|
| 187 | +function wp_authenticate_email_password($user, $email, $password) { |
|
| 188 | + if ($user instanceof WP_User) { |
|
| 189 | 189 | return $user; |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - if ( empty( $email ) || empty( $password ) ) { |
|
| 193 | - if ( is_wp_error( $user ) ) { |
|
| 192 | + if (empty($email) || empty($password)) { |
|
| 193 | + if (is_wp_error($user)) { |
|
| 194 | 194 | return $user; |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | $error = new WP_Error(); |
| 198 | 198 | |
| 199 | - if ( empty( $email ) ) { |
|
| 200 | - $error->add( 'empty_username', __( '<strong>ERROR</strong>: The email field is empty.' ) ); // Uses 'empty_username' for back-compat with wp_signon() |
|
| 199 | + if (empty($email)) { |
|
| 200 | + $error->add('empty_username', __('<strong>ERROR</strong>: The email field is empty.')); // Uses 'empty_username' for back-compat with wp_signon() |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | - if ( empty( $password ) ) { |
|
| 204 | - $error->add( 'empty_password', __( '<strong>ERROR</strong>: The password field is empty.' ) ); |
|
| 203 | + if (empty($password)) { |
|
| 204 | + $error->add('empty_password', __('<strong>ERROR</strong>: The password field is empty.')); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | return $error; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - if ( ! is_email( $email ) ) { |
|
| 210 | + if ( ! is_email($email)) { |
|
| 211 | 211 | return $user; |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - $user = get_user_by( 'email', $email ); |
|
| 214 | + $user = get_user_by('email', $email); |
|
| 215 | 215 | |
| 216 | - if ( ! $user ) { |
|
| 217 | - return new WP_Error( 'invalid_email', |
|
| 218 | - __( '<strong>ERROR</strong>: Invalid email address.' ) . |
|
| 219 | - ' <a href="' . wp_lostpassword_url() . '">' . |
|
| 220 | - __( 'Lost your password?' ) . |
|
| 216 | + if ( ! $user) { |
|
| 217 | + return new WP_Error('invalid_email', |
|
| 218 | + __('<strong>ERROR</strong>: Invalid email address.'). |
|
| 219 | + ' <a href="'.wp_lostpassword_url().'">'. |
|
| 220 | + __('Lost your password?'). |
|
| 221 | 221 | '</a>' |
| 222 | 222 | ); |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | /** This filter is documented in wp-includes/user.php */ |
| 226 | - $user = apply_filters( 'wp_authenticate_user', $user, $password ); |
|
| 226 | + $user = apply_filters('wp_authenticate_user', $user, $password); |
|
| 227 | 227 | |
| 228 | - if ( is_wp_error( $user ) ) { |
|
| 228 | + if (is_wp_error($user)) { |
|
| 229 | 229 | return $user; |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - if ( ! wp_check_password( $password, $user->user_pass, $user->ID ) ) { |
|
| 233 | - return new WP_Error( 'incorrect_password', |
|
| 232 | + if ( ! wp_check_password($password, $user->user_pass, $user->ID)) { |
|
| 233 | + return new WP_Error('incorrect_password', |
|
| 234 | 234 | sprintf( |
| 235 | 235 | /* translators: %s: email address */ |
| 236 | - __( '<strong>ERROR</strong>: The password you entered for the email address %s is incorrect.' ), |
|
| 237 | - '<strong>' . $email . '</strong>' |
|
| 238 | - ) . |
|
| 239 | - ' <a href="' . wp_lostpassword_url() . '">' . |
|
| 240 | - __( 'Lost your password?' ) . |
|
| 236 | + __('<strong>ERROR</strong>: The password you entered for the email address %s is incorrect.'), |
|
| 237 | + '<strong>'.$email.'</strong>' |
|
| 238 | + ). |
|
| 239 | + ' <a href="'.wp_lostpassword_url().'">'. |
|
| 240 | + __('Lost your password?'). |
|
| 241 | 241 | '</a>' |
| 242 | 242 | ); |
| 243 | 243 | } |
@@ -258,23 +258,23 @@ discard block |
||
| 258 | 258 | * @return WP_User|WP_Error WP_User on success, WP_Error on failure. |
| 259 | 259 | */ |
| 260 | 260 | function wp_authenticate_cookie($user, $username, $password) { |
| 261 | - if ( $user instanceof WP_User ) { |
|
| 261 | + if ($user instanceof WP_User) { |
|
| 262 | 262 | return $user; |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | - if ( empty($username) && empty($password) ) { |
|
| 265 | + if (empty($username) && empty($password)) { |
|
| 266 | 266 | $user_id = wp_validate_auth_cookie(); |
| 267 | - if ( $user_id ) |
|
| 267 | + if ($user_id) |
|
| 268 | 268 | return new WP_User($user_id); |
| 269 | 269 | |
| 270 | 270 | global $auth_secure_cookie; |
| 271 | 271 | |
| 272 | - if ( $auth_secure_cookie ) |
|
| 272 | + if ($auth_secure_cookie) |
|
| 273 | 273 | $auth_cookie = SECURE_AUTH_COOKIE; |
| 274 | 274 | else |
| 275 | 275 | $auth_cookie = AUTH_COOKIE; |
| 276 | 276 | |
| 277 | - if ( !empty($_COOKIE[$auth_cookie]) ) |
|
| 277 | + if ( ! empty($_COOKIE[$auth_cookie])) |
|
| 278 | 278 | return new WP_Error('expired_session', __('Please log in again.')); |
| 279 | 279 | |
| 280 | 280 | // If the cookie is not set, be silent. |
@@ -292,8 +292,8 @@ discard block |
||
| 292 | 292 | * @param WP_User|WP_Error|null $user WP_User or WP_Error object from a previous callback. Default null. |
| 293 | 293 | * @return WP_User|WP_Error WP_User on success, WP_Error if the user is considered a spammer. |
| 294 | 294 | */ |
| 295 | -function wp_authenticate_spam_check( $user ) { |
|
| 296 | - if ( $user instanceof WP_User && is_multisite() ) { |
|
| 295 | +function wp_authenticate_spam_check($user) { |
|
| 296 | + if ($user instanceof WP_User && is_multisite()) { |
|
| 297 | 297 | /** |
| 298 | 298 | * Filter whether the user has been marked as a spammer. |
| 299 | 299 | * |
@@ -302,10 +302,10 @@ discard block |
||
| 302 | 302 | * @param bool $spammed Whether the user is considered a spammer. |
| 303 | 303 | * @param WP_User $user User to check against. |
| 304 | 304 | */ |
| 305 | - $spammed = apply_filters( 'check_is_user_spammed', is_user_spammy(), $user ); |
|
| 305 | + $spammed = apply_filters('check_is_user_spammed', is_user_spammy(), $user); |
|
| 306 | 306 | |
| 307 | - if ( $spammed ) |
|
| 308 | - return new WP_Error( 'spammer_account', __( '<strong>ERROR</strong>: Your account has been marked as a spammer.' ) ); |
|
| 307 | + if ($spammed) |
|
| 308 | + return new WP_Error('spammer_account', __('<strong>ERROR</strong>: Your account has been marked as a spammer.')); |
|
| 309 | 309 | } |
| 310 | 310 | return $user; |
| 311 | 311 | } |
@@ -325,16 +325,16 @@ discard block |
||
| 325 | 325 | * @return int|false User ID if validated, false otherwise. If a user ID from |
| 326 | 326 | * an earlier filter callback is received, that value is returned. |
| 327 | 327 | */ |
| 328 | -function wp_validate_logged_in_cookie( $user_id ) { |
|
| 329 | - if ( $user_id ) { |
|
| 328 | +function wp_validate_logged_in_cookie($user_id) { |
|
| 329 | + if ($user_id) { |
|
| 330 | 330 | return $user_id; |
| 331 | 331 | } |
| 332 | 332 | |
| 333 | - if ( is_blog_admin() || is_network_admin() || empty( $_COOKIE[LOGGED_IN_COOKIE] ) ) { |
|
| 333 | + if (is_blog_admin() || is_network_admin() || empty($_COOKIE[LOGGED_IN_COOKIE])) { |
|
| 334 | 334 | return false; |
| 335 | 335 | } |
| 336 | 336 | |
| 337 | - return wp_validate_auth_cookie( $_COOKIE[LOGGED_IN_COOKIE], 'logged_in' ); |
|
| 337 | + return wp_validate_auth_cookie($_COOKIE[LOGGED_IN_COOKIE], 'logged_in'); |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | /** |
@@ -352,12 +352,12 @@ discard block |
||
| 352 | 352 | * @param bool $public_only Optional. Whether to only return counts for public posts. Default false. |
| 353 | 353 | * @return string Number of posts the user has written in this post type. |
| 354 | 354 | */ |
| 355 | -function count_user_posts( $userid, $post_type = 'post', $public_only = false ) { |
|
| 355 | +function count_user_posts($userid, $post_type = 'post', $public_only = false) { |
|
| 356 | 356 | global $wpdb; |
| 357 | 357 | |
| 358 | - $where = get_posts_by_author_sql( $post_type, true, $userid, $public_only ); |
|
| 358 | + $where = get_posts_by_author_sql($post_type, true, $userid, $public_only); |
|
| 359 | 359 | |
| 360 | - $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" ); |
|
| 360 | + $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts $where"); |
|
| 361 | 361 | |
| 362 | 362 | /** |
| 363 | 363 | * Filter the number of posts a user has written. |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | * @param string|array $post_type Single post type or array of post types to count the number of posts for. |
| 372 | 372 | * @param bool $public_only Whether to limit counted posts to public posts. |
| 373 | 373 | */ |
| 374 | - return apply_filters( 'get_usernumposts', $count, $userid, $post_type, $public_only ); |
|
| 374 | + return apply_filters('get_usernumposts', $count, $userid, $post_type, $public_only); |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | /** |
@@ -386,24 +386,24 @@ discard block |
||
| 386 | 386 | * @param bool $public_only Optional. Only return counts for public posts. Defaults to false. |
| 387 | 387 | * @return array Amount of posts each user has written. |
| 388 | 388 | */ |
| 389 | -function count_many_users_posts( $users, $post_type = 'post', $public_only = false ) { |
|
| 389 | +function count_many_users_posts($users, $post_type = 'post', $public_only = false) { |
|
| 390 | 390 | global $wpdb; |
| 391 | 391 | |
| 392 | 392 | $count = array(); |
| 393 | - if ( empty( $users ) || ! is_array( $users ) ) |
|
| 393 | + if (empty($users) || ! is_array($users)) |
|
| 394 | 394 | return $count; |
| 395 | 395 | |
| 396 | - $userlist = implode( ',', array_map( 'absint', $users ) ); |
|
| 397 | - $where = get_posts_by_author_sql( $post_type, true, null, $public_only ); |
|
| 396 | + $userlist = implode(',', array_map('absint', $users)); |
|
| 397 | + $where = get_posts_by_author_sql($post_type, true, null, $public_only); |
|
| 398 | 398 | |
| 399 | - $result = $wpdb->get_results( "SELECT post_author, COUNT(*) FROM $wpdb->posts $where AND post_author IN ($userlist) GROUP BY post_author", ARRAY_N ); |
|
| 400 | - foreach ( $result as $row ) { |
|
| 401 | - $count[ $row[0] ] = $row[1]; |
|
| 399 | + $result = $wpdb->get_results("SELECT post_author, COUNT(*) FROM $wpdb->posts $where AND post_author IN ($userlist) GROUP BY post_author", ARRAY_N); |
|
| 400 | + foreach ($result as $row) { |
|
| 401 | + $count[$row[0]] = $row[1]; |
|
| 402 | 402 | } |
| 403 | 403 | |
| 404 | - foreach ( $users as $id ) { |
|
| 405 | - if ( ! isset( $count[ $id ] ) ) |
|
| 406 | - $count[ $id ] = 0; |
|
| 404 | + foreach ($users as $id) { |
|
| 405 | + if ( ! isset($count[$id])) |
|
| 406 | + $count[$id] = 0; |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | return $count; |
@@ -421,10 +421,10 @@ discard block |
||
| 421 | 421 | * @return int The current user's ID |
| 422 | 422 | */ |
| 423 | 423 | function get_current_user_id() { |
| 424 | - if ( ! function_exists( 'wp_get_current_user' ) ) |
|
| 424 | + if ( ! function_exists('wp_get_current_user')) |
|
| 425 | 425 | return 0; |
| 426 | 426 | $user = wp_get_current_user(); |
| 427 | - return ( isset( $user->ID ) ? (int) $user->ID : 0 ); |
|
| 427 | + return (isset($user->ID) ? (int) $user->ID : 0); |
|
| 428 | 428 | } |
| 429 | 429 | |
| 430 | 430 | /** |
@@ -446,23 +446,23 @@ discard block |
||
| 446 | 446 | * @param string $deprecated Use get_option() to check for an option in the options table. |
| 447 | 447 | * @return mixed User option value on success, false on failure. |
| 448 | 448 | */ |
| 449 | -function get_user_option( $option, $user = 0, $deprecated = '' ) { |
|
| 449 | +function get_user_option($option, $user = 0, $deprecated = '') { |
|
| 450 | 450 | global $wpdb; |
| 451 | 451 | |
| 452 | - if ( !empty( $deprecated ) ) |
|
| 453 | - _deprecated_argument( __FUNCTION__, '3.0' ); |
|
| 452 | + if ( ! empty($deprecated)) |
|
| 453 | + _deprecated_argument(__FUNCTION__, '3.0'); |
|
| 454 | 454 | |
| 455 | - if ( empty( $user ) ) |
|
| 455 | + if (empty($user)) |
|
| 456 | 456 | $user = get_current_user_id(); |
| 457 | 457 | |
| 458 | - if ( ! $user = get_userdata( $user ) ) |
|
| 458 | + if ( ! $user = get_userdata($user)) |
|
| 459 | 459 | return false; |
| 460 | 460 | |
| 461 | 461 | $prefix = $wpdb->get_blog_prefix(); |
| 462 | - if ( $user->has_prop( $prefix . $option ) ) // Blog specific |
|
| 463 | - $result = $user->get( $prefix . $option ); |
|
| 464 | - elseif ( $user->has_prop( $option ) ) // User specific and cross-blog |
|
| 465 | - $result = $user->get( $option ); |
|
| 462 | + if ($user->has_prop($prefix.$option)) // Blog specific |
|
| 463 | + $result = $user->get($prefix.$option); |
|
| 464 | + elseif ($user->has_prop($option)) // User specific and cross-blog |
|
| 465 | + $result = $user->get($option); |
|
| 466 | 466 | else |
| 467 | 467 | $result = false; |
| 468 | 468 | |
@@ -477,7 +477,7 @@ discard block |
||
| 477 | 477 | * @param string $option Name of the option being retrieved. |
| 478 | 478 | * @param WP_User $user WP_User object of the user whose option is being retrieved. |
| 479 | 479 | */ |
| 480 | - return apply_filters( "get_user_option_{$option}", $result, $option, $user ); |
|
| 480 | + return apply_filters("get_user_option_{$option}", $result, $option, $user); |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | /** |
@@ -501,13 +501,13 @@ discard block |
||
| 501 | 501 | * @return int|bool User meta ID if the option didn't exist, true on successful update, |
| 502 | 502 | * false on failure. |
| 503 | 503 | */ |
| 504 | -function update_user_option( $user_id, $option_name, $newvalue, $global = false ) { |
|
| 504 | +function update_user_option($user_id, $option_name, $newvalue, $global = false) { |
|
| 505 | 505 | global $wpdb; |
| 506 | 506 | |
| 507 | - if ( !$global ) |
|
| 508 | - $option_name = $wpdb->get_blog_prefix() . $option_name; |
|
| 507 | + if ( ! $global) |
|
| 508 | + $option_name = $wpdb->get_blog_prefix().$option_name; |
|
| 509 | 509 | |
| 510 | - return update_user_meta( $user_id, $option_name, $newvalue ); |
|
| 510 | + return update_user_meta($user_id, $option_name, $newvalue); |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | /** |
@@ -527,12 +527,12 @@ discard block |
||
| 527 | 527 | * Default false (blog specific). |
| 528 | 528 | * @return bool True on success, false on failure. |
| 529 | 529 | */ |
| 530 | -function delete_user_option( $user_id, $option_name, $global = false ) { |
|
| 530 | +function delete_user_option($user_id, $option_name, $global = false) { |
|
| 531 | 531 | global $wpdb; |
| 532 | 532 | |
| 533 | - if ( !$global ) |
|
| 534 | - $option_name = $wpdb->get_blog_prefix() . $option_name; |
|
| 535 | - return delete_user_meta( $user_id, $option_name ); |
|
| 533 | + if ( ! $global) |
|
| 534 | + $option_name = $wpdb->get_blog_prefix().$option_name; |
|
| 535 | + return delete_user_meta($user_id, $option_name); |
|
| 536 | 536 | } |
| 537 | 537 | |
| 538 | 538 | /** |
@@ -546,9 +546,9 @@ discard block |
||
| 546 | 546 | * for more information on accepted arguments. |
| 547 | 547 | * @return array List of users. |
| 548 | 548 | */ |
| 549 | -function get_users( $args = array() ) { |
|
| 549 | +function get_users($args = array()) { |
|
| 550 | 550 | |
| 551 | - $args = wp_parse_args( $args ); |
|
| 551 | + $args = wp_parse_args($args); |
|
| 552 | 552 | $args['count_total'] = false; |
| 553 | 553 | |
| 554 | 554 | $user_search = new WP_User_Query($args); |
@@ -569,40 +569,40 @@ discard block |
||
| 569 | 569 | * @return array A list of the user's blogs. An empty array if the user doesn't exist |
| 570 | 570 | * or belongs to no blogs. |
| 571 | 571 | */ |
| 572 | -function get_blogs_of_user( $user_id, $all = false ) { |
|
| 572 | +function get_blogs_of_user($user_id, $all = false) { |
|
| 573 | 573 | global $wpdb; |
| 574 | 574 | |
| 575 | 575 | $user_id = (int) $user_id; |
| 576 | 576 | |
| 577 | 577 | // Logged out users can't have blogs |
| 578 | - if ( empty( $user_id ) ) |
|
| 578 | + if (empty($user_id)) |
|
| 579 | 579 | return array(); |
| 580 | 580 | |
| 581 | - $keys = get_user_meta( $user_id ); |
|
| 582 | - if ( empty( $keys ) ) |
|
| 581 | + $keys = get_user_meta($user_id); |
|
| 582 | + if (empty($keys)) |
|
| 583 | 583 | return array(); |
| 584 | 584 | |
| 585 | - if ( ! is_multisite() ) { |
|
| 585 | + if ( ! is_multisite()) { |
|
| 586 | 586 | $blog_id = get_current_blog_id(); |
| 587 | - $blogs = array( $blog_id => new stdClass ); |
|
| 588 | - $blogs[ $blog_id ]->userblog_id = $blog_id; |
|
| 589 | - $blogs[ $blog_id ]->blogname = get_option('blogname'); |
|
| 590 | - $blogs[ $blog_id ]->domain = ''; |
|
| 591 | - $blogs[ $blog_id ]->path = ''; |
|
| 592 | - $blogs[ $blog_id ]->site_id = 1; |
|
| 593 | - $blogs[ $blog_id ]->siteurl = get_option('siteurl'); |
|
| 594 | - $blogs[ $blog_id ]->archived = 0; |
|
| 595 | - $blogs[ $blog_id ]->spam = 0; |
|
| 596 | - $blogs[ $blog_id ]->deleted = 0; |
|
| 587 | + $blogs = array($blog_id => new stdClass); |
|
| 588 | + $blogs[$blog_id]->userblog_id = $blog_id; |
|
| 589 | + $blogs[$blog_id]->blogname = get_option('blogname'); |
|
| 590 | + $blogs[$blog_id]->domain = ''; |
|
| 591 | + $blogs[$blog_id]->path = ''; |
|
| 592 | + $blogs[$blog_id]->site_id = 1; |
|
| 593 | + $blogs[$blog_id]->siteurl = get_option('siteurl'); |
|
| 594 | + $blogs[$blog_id]->archived = 0; |
|
| 595 | + $blogs[$blog_id]->spam = 0; |
|
| 596 | + $blogs[$blog_id]->deleted = 0; |
|
| 597 | 597 | return $blogs; |
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | $blogs = array(); |
| 601 | 601 | |
| 602 | - if ( isset( $keys[ $wpdb->base_prefix . 'capabilities' ] ) && defined( 'MULTISITE' ) ) { |
|
| 603 | - $blog = get_blog_details( 1 ); |
|
| 604 | - if ( $blog && isset( $blog->domain ) && ( $all || ( ! $blog->archived && ! $blog->spam && ! $blog->deleted ) ) ) { |
|
| 605 | - $blogs[ 1 ] = (object) array( |
|
| 602 | + if (isset($keys[$wpdb->base_prefix.'capabilities']) && defined('MULTISITE')) { |
|
| 603 | + $blog = get_blog_details(1); |
|
| 604 | + if ($blog && isset($blog->domain) && ($all || ( ! $blog->archived && ! $blog->spam && ! $blog->deleted))) { |
|
| 605 | + $blogs[1] = (object) array( |
|
| 606 | 606 | 'userblog_id' => 1, |
| 607 | 607 | 'blogname' => $blog->blogname, |
| 608 | 608 | 'domain' => $blog->domain, |
@@ -615,24 +615,24 @@ discard block |
||
| 615 | 615 | 'deleted' => $blog->deleted, |
| 616 | 616 | ); |
| 617 | 617 | } |
| 618 | - unset( $keys[ $wpdb->base_prefix . 'capabilities' ] ); |
|
| 618 | + unset($keys[$wpdb->base_prefix.'capabilities']); |
|
| 619 | 619 | } |
| 620 | 620 | |
| 621 | - $keys = array_keys( $keys ); |
|
| 621 | + $keys = array_keys($keys); |
|
| 622 | 622 | |
| 623 | - foreach ( $keys as $key ) { |
|
| 624 | - if ( 'capabilities' !== substr( $key, -12 ) ) |
|
| 623 | + foreach ($keys as $key) { |
|
| 624 | + if ('capabilities' !== substr($key, -12)) |
|
| 625 | 625 | continue; |
| 626 | - if ( $wpdb->base_prefix && 0 !== strpos( $key, $wpdb->base_prefix ) ) |
|
| 626 | + if ($wpdb->base_prefix && 0 !== strpos($key, $wpdb->base_prefix)) |
|
| 627 | 627 | continue; |
| 628 | - $blog_id = str_replace( array( $wpdb->base_prefix, '_capabilities' ), '', $key ); |
|
| 629 | - if ( ! is_numeric( $blog_id ) ) |
|
| 628 | + $blog_id = str_replace(array($wpdb->base_prefix, '_capabilities'), '', $key); |
|
| 629 | + if ( ! is_numeric($blog_id)) |
|
| 630 | 630 | continue; |
| 631 | 631 | |
| 632 | 632 | $blog_id = (int) $blog_id; |
| 633 | - $blog = get_blog_details( $blog_id ); |
|
| 634 | - if ( $blog && isset( $blog->domain ) && ( $all || ( ! $blog->archived && ! $blog->spam && ! $blog->deleted ) ) ) { |
|
| 635 | - $blogs[ $blog_id ] = (object) array( |
|
| 633 | + $blog = get_blog_details($blog_id); |
|
| 634 | + if ($blog && isset($blog->domain) && ($all || ( ! $blog->archived && ! $blog->spam && ! $blog->deleted))) { |
|
| 635 | + $blogs[$blog_id] = (object) array( |
|
| 636 | 636 | 'userblog_id' => $blog_id, |
| 637 | 637 | 'blogname' => $blog->blogname, |
| 638 | 638 | 'domain' => $blog->domain, |
@@ -657,7 +657,7 @@ discard block |
||
| 657 | 657 | * @param bool $all Whether the returned blogs array should contain all blogs, including |
| 658 | 658 | * those marked 'deleted', 'archived', or 'spam'. Default false. |
| 659 | 659 | */ |
| 660 | - return apply_filters( 'get_blogs_of_user', $blogs, $user_id, $all ); |
|
| 660 | + return apply_filters('get_blogs_of_user', $blogs, $user_id, $all); |
|
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | /** |
@@ -669,55 +669,55 @@ discard block |
||
| 669 | 669 | * @param int $blog_id Optional. ID of the blog to check. Defaults to the current site. |
| 670 | 670 | * @return bool |
| 671 | 671 | */ |
| 672 | -function is_user_member_of_blog( $user_id = 0, $blog_id = 0 ) { |
|
| 672 | +function is_user_member_of_blog($user_id = 0, $blog_id = 0) { |
|
| 673 | 673 | global $wpdb; |
| 674 | 674 | |
| 675 | 675 | $user_id = (int) $user_id; |
| 676 | 676 | $blog_id = (int) $blog_id; |
| 677 | 677 | |
| 678 | - if ( empty( $user_id ) ) { |
|
| 678 | + if (empty($user_id)) { |
|
| 679 | 679 | $user_id = get_current_user_id(); |
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | // Technically not needed, but does save calls to get_blog_details and get_user_meta |
| 683 | 683 | // in the event that the function is called when a user isn't logged in |
| 684 | - if ( empty( $user_id ) ) { |
|
| 684 | + if (empty($user_id)) { |
|
| 685 | 685 | return false; |
| 686 | 686 | } else { |
| 687 | - $user = get_userdata( $user_id ); |
|
| 688 | - if ( ! $user instanceof WP_User ) { |
|
| 687 | + $user = get_userdata($user_id); |
|
| 688 | + if ( ! $user instanceof WP_User) { |
|
| 689 | 689 | return false; |
| 690 | 690 | } |
| 691 | 691 | } |
| 692 | 692 | |
| 693 | - if ( ! is_multisite() ) { |
|
| 693 | + if ( ! is_multisite()) { |
|
| 694 | 694 | return true; |
| 695 | 695 | } |
| 696 | 696 | |
| 697 | - if ( empty( $blog_id ) ) { |
|
| 697 | + if (empty($blog_id)) { |
|
| 698 | 698 | $blog_id = get_current_blog_id(); |
| 699 | 699 | } |
| 700 | 700 | |
| 701 | - $blog = get_blog_details( $blog_id ); |
|
| 701 | + $blog = get_blog_details($blog_id); |
|
| 702 | 702 | |
| 703 | - if ( ! $blog || ! isset( $blog->domain ) || $blog->archived || $blog->spam || $blog->deleted ) { |
|
| 703 | + if ( ! $blog || ! isset($blog->domain) || $blog->archived || $blog->spam || $blog->deleted) { |
|
| 704 | 704 | return false; |
| 705 | 705 | } |
| 706 | 706 | |
| 707 | - $keys = get_user_meta( $user_id ); |
|
| 708 | - if ( empty( $keys ) ) { |
|
| 707 | + $keys = get_user_meta($user_id); |
|
| 708 | + if (empty($keys)) { |
|
| 709 | 709 | return false; |
| 710 | 710 | } |
| 711 | 711 | |
| 712 | 712 | // no underscore before capabilities in $base_capabilities_key |
| 713 | - $base_capabilities_key = $wpdb->base_prefix . 'capabilities'; |
|
| 714 | - $site_capabilities_key = $wpdb->base_prefix . $blog_id . '_capabilities'; |
|
| 713 | + $base_capabilities_key = $wpdb->base_prefix.'capabilities'; |
|
| 714 | + $site_capabilities_key = $wpdb->base_prefix.$blog_id.'_capabilities'; |
|
| 715 | 715 | |
| 716 | - if ( isset( $keys[ $base_capabilities_key ] ) && $blog_id == 1 ) { |
|
| 716 | + if (isset($keys[$base_capabilities_key]) && $blog_id == 1) { |
|
| 717 | 717 | return true; |
| 718 | 718 | } |
| 719 | 719 | |
| 720 | - if ( isset( $keys[ $site_capabilities_key ] ) ) { |
|
| 720 | + if (isset($keys[$site_capabilities_key])) { |
|
| 721 | 721 | return true; |
| 722 | 722 | } |
| 723 | 723 | |
@@ -821,24 +821,24 @@ discard block |
||
| 821 | 821 | $blog_prefix = $wpdb->get_blog_prefix($id); |
| 822 | 822 | $result = array(); |
| 823 | 823 | |
| 824 | - if ( 'time' == $strategy ) { |
|
| 824 | + if ('time' == $strategy) { |
|
| 825 | 825 | $avail_roles = wp_roles()->get_names(); |
| 826 | 826 | |
| 827 | 827 | // Build a CPU-intensive query that will return concise information. |
| 828 | 828 | $select_count = array(); |
| 829 | - foreach ( $avail_roles as $this_role => $name ) { |
|
| 830 | - $select_count[] = $wpdb->prepare( "COUNT(NULLIF(`meta_value` LIKE %s, false))", '%' . $wpdb->esc_like( '"' . $this_role . '"' ) . '%'); |
|
| 829 | + foreach ($avail_roles as $this_role => $name) { |
|
| 830 | + $select_count[] = $wpdb->prepare("COUNT(NULLIF(`meta_value` LIKE %s, false))", '%'.$wpdb->esc_like('"'.$this_role.'"').'%'); |
|
| 831 | 831 | } |
| 832 | 832 | $select_count[] = "COUNT(NULLIF(`meta_value` = 'a:0:{}', false))"; |
| 833 | 833 | $select_count = implode(', ', $select_count); |
| 834 | 834 | |
| 835 | 835 | // Add the meta_value index to the selection list, then run the query. |
| 836 | - $row = $wpdb->get_row( "SELECT $select_count, COUNT(*) FROM $wpdb->usermeta WHERE meta_key = '{$blog_prefix}capabilities'", ARRAY_N ); |
|
| 836 | + $row = $wpdb->get_row("SELECT $select_count, COUNT(*) FROM $wpdb->usermeta WHERE meta_key = '{$blog_prefix}capabilities'", ARRAY_N); |
|
| 837 | 837 | |
| 838 | 838 | // Run the previous loop again to associate results with role names. |
| 839 | 839 | $col = 0; |
| 840 | 840 | $role_counts = array(); |
| 841 | - foreach ( $avail_roles as $this_role => $name ) { |
|
| 841 | + foreach ($avail_roles as $this_role => $name) { |
|
| 842 | 842 | $count = (int) $row[$col++]; |
| 843 | 843 | if ($count > 0) { |
| 844 | 844 | $role_counts[$this_role] = $count; |
@@ -851,23 +851,23 @@ discard block |
||
| 851 | 851 | $total_users = (int) $row[$col]; |
| 852 | 852 | |
| 853 | 853 | $result['total_users'] = $total_users; |
| 854 | - $result['avail_roles'] =& $role_counts; |
|
| 854 | + $result['avail_roles'] = & $role_counts; |
|
| 855 | 855 | } else { |
| 856 | 856 | $avail_roles = array( |
| 857 | 857 | 'none' => 0, |
| 858 | 858 | ); |
| 859 | 859 | |
| 860 | - $users_of_blog = $wpdb->get_col( "SELECT meta_value FROM $wpdb->usermeta WHERE meta_key = '{$blog_prefix}capabilities'" ); |
|
| 860 | + $users_of_blog = $wpdb->get_col("SELECT meta_value FROM $wpdb->usermeta WHERE meta_key = '{$blog_prefix}capabilities'"); |
|
| 861 | 861 | |
| 862 | - foreach ( $users_of_blog as $caps_meta ) { |
|
| 862 | + foreach ($users_of_blog as $caps_meta) { |
|
| 863 | 863 | $b_roles = maybe_unserialize($caps_meta); |
| 864 | - if ( ! is_array( $b_roles ) ) |
|
| 864 | + if ( ! is_array($b_roles)) |
|
| 865 | 865 | continue; |
| 866 | - if ( empty( $b_roles ) ) { |
|
| 866 | + if (empty($b_roles)) { |
|
| 867 | 867 | $avail_roles['none']++; |
| 868 | 868 | } |
| 869 | - foreach ( $b_roles as $b_role => $val ) { |
|
| 870 | - if ( isset($avail_roles[$b_role]) ) { |
|
| 869 | + foreach ($b_roles as $b_role => $val) { |
|
| 870 | + if (isset($avail_roles[$b_role])) { |
|
| 871 | 871 | $avail_roles[$b_role]++; |
| 872 | 872 | } else { |
| 873 | 873 | $avail_roles[$b_role] = 1; |
@@ -875,11 +875,11 @@ discard block |
||
| 875 | 875 | } |
| 876 | 876 | } |
| 877 | 877 | |
| 878 | - $result['total_users'] = count( $users_of_blog ); |
|
| 879 | - $result['avail_roles'] =& $avail_roles; |
|
| 878 | + $result['total_users'] = count($users_of_blog); |
|
| 879 | + $result['avail_roles'] = & $avail_roles; |
|
| 880 | 880 | } |
| 881 | 881 | |
| 882 | - if ( is_multisite() ) { |
|
| 882 | + if (is_multisite()) { |
|
| 883 | 883 | $result['avail_roles']['none'] = 0; |
| 884 | 884 | } |
| 885 | 885 | |
@@ -910,11 +910,11 @@ discard block |
||
| 910 | 910 | function setup_userdata($for_user_id = '') { |
| 911 | 911 | global $user_login, $userdata, $user_level, $user_ID, $user_email, $user_url, $user_identity; |
| 912 | 912 | |
| 913 | - if ( '' == $for_user_id ) |
|
| 913 | + if ('' == $for_user_id) |
|
| 914 | 914 | $for_user_id = get_current_user_id(); |
| 915 | - $user = get_userdata( $for_user_id ); |
|
| 915 | + $user = get_userdata($for_user_id); |
|
| 916 | 916 | |
| 917 | - if ( ! $user ) { |
|
| 917 | + if ( ! $user) { |
|
| 918 | 918 | $user_ID = 0; |
| 919 | 919 | $user_level = 0; |
| 920 | 920 | $userdata = null; |
@@ -988,7 +988,7 @@ discard block |
||
| 988 | 988 | * } |
| 989 | 989 | * @return string String of HTML content. |
| 990 | 990 | */ |
| 991 | -function wp_dropdown_users( $args = '' ) { |
|
| 991 | +function wp_dropdown_users($args = '') { |
|
| 992 | 992 | $defaults = array( |
| 993 | 993 | 'show_option_all' => '', 'show_option_none' => '', 'hide_if_only_one_author' => '', |
| 994 | 994 | 'orderby' => 'display_name', 'order' => 'ASC', |
@@ -999,16 +999,16 @@ discard block |
||
| 999 | 999 | 'option_none_value' => -1 |
| 1000 | 1000 | ); |
| 1001 | 1001 | |
| 1002 | - $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0; |
|
| 1002 | + $defaults['selected'] = is_author() ? get_query_var('author') : 0; |
|
| 1003 | 1003 | |
| 1004 | - $r = wp_parse_args( $args, $defaults ); |
|
| 1004 | + $r = wp_parse_args($args, $defaults); |
|
| 1005 | 1005 | |
| 1006 | - $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) ); |
|
| 1006 | + $query_args = wp_array_slice_assoc($r, array('blog_id', 'include', 'exclude', 'orderby', 'order', 'who')); |
|
| 1007 | 1007 | |
| 1008 | - $fields = array( 'ID', 'user_login' ); |
|
| 1008 | + $fields = array('ID', 'user_login'); |
|
| 1009 | 1009 | |
| 1010 | - $show = ! empty( $r['show'] ) ? $r['show'] : 'display_name'; |
|
| 1011 | - if ( 'display_name_with_login' === $show ) { |
|
| 1010 | + $show = ! empty($r['show']) ? $r['show'] : 'display_name'; |
|
| 1011 | + if ('display_name_with_login' === $show) { |
|
| 1012 | 1012 | $fields[] = 'display_name'; |
| 1013 | 1013 | } else { |
| 1014 | 1014 | $fields[] = $show; |
@@ -1028,56 +1028,56 @@ discard block |
||
| 1028 | 1028 | * @param array $query_args The query arguments for wp_dropdown_users(). |
| 1029 | 1029 | * @param array $r The default arguments for wp_dropdown_users(). |
| 1030 | 1030 | */ |
| 1031 | - $query_args = apply_filters( 'wp_dropdown_users_args', $query_args, $r ); |
|
| 1031 | + $query_args = apply_filters('wp_dropdown_users_args', $query_args, $r); |
|
| 1032 | 1032 | |
| 1033 | - $users = get_users( $query_args ); |
|
| 1033 | + $users = get_users($query_args); |
|
| 1034 | 1034 | |
| 1035 | 1035 | $output = ''; |
| 1036 | - if ( ! empty( $users ) && ( empty( $r['hide_if_only_one_author'] ) || count( $users ) > 1 ) ) { |
|
| 1037 | - $name = esc_attr( $r['name'] ); |
|
| 1038 | - if ( $r['multi'] && ! $r['id'] ) { |
|
| 1036 | + if ( ! empty($users) && (empty($r['hide_if_only_one_author']) || count($users) > 1)) { |
|
| 1037 | + $name = esc_attr($r['name']); |
|
| 1038 | + if ($r['multi'] && ! $r['id']) { |
|
| 1039 | 1039 | $id = ''; |
| 1040 | 1040 | } else { |
| 1041 | - $id = $r['id'] ? " id='" . esc_attr( $r['id'] ) . "'" : " id='$name'"; |
|
| 1041 | + $id = $r['id'] ? " id='".esc_attr($r['id'])."'" : " id='$name'"; |
|
| 1042 | 1042 | } |
| 1043 | - $output = "<select name='{$name}'{$id} class='" . $r['class'] . "'>\n"; |
|
| 1043 | + $output = "<select name='{$name}'{$id} class='".$r['class']."'>\n"; |
|
| 1044 | 1044 | |
| 1045 | - if ( $show_option_all ) { |
|
| 1045 | + if ($show_option_all) { |
|
| 1046 | 1046 | $output .= "\t<option value='0'>$show_option_all</option>\n"; |
| 1047 | 1047 | } |
| 1048 | 1048 | |
| 1049 | - if ( $show_option_none ) { |
|
| 1050 | - $_selected = selected( $option_none_value, $r['selected'], false ); |
|
| 1051 | - $output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$_selected>$show_option_none</option>\n"; |
|
| 1049 | + if ($show_option_none) { |
|
| 1050 | + $_selected = selected($option_none_value, $r['selected'], false); |
|
| 1051 | + $output .= "\t<option value='".esc_attr($option_none_value)."'$_selected>$show_option_none</option>\n"; |
|
| 1052 | 1052 | } |
| 1053 | 1053 | |
| 1054 | - if ( $r['include_selected'] && ( $r['selected'] > 0 ) ) { |
|
| 1054 | + if ($r['include_selected'] && ($r['selected'] > 0)) { |
|
| 1055 | 1055 | $found_selected = false; |
| 1056 | 1056 | $r['selected'] = (int) $r['selected']; |
| 1057 | - foreach ( (array) $users as $user ) { |
|
| 1057 | + foreach ((array) $users as $user) { |
|
| 1058 | 1058 | $user->ID = (int) $user->ID; |
| 1059 | - if ( $user->ID === $r['selected'] ) { |
|
| 1059 | + if ($user->ID === $r['selected']) { |
|
| 1060 | 1060 | $found_selected = true; |
| 1061 | 1061 | } |
| 1062 | 1062 | } |
| 1063 | 1063 | |
| 1064 | - if ( ! $found_selected ) { |
|
| 1065 | - $users[] = get_userdata( $r['selected'] ); |
|
| 1064 | + if ( ! $found_selected) { |
|
| 1065 | + $users[] = get_userdata($r['selected']); |
|
| 1066 | 1066 | } |
| 1067 | 1067 | } |
| 1068 | 1068 | |
| 1069 | - foreach ( (array) $users as $user ) { |
|
| 1070 | - if ( 'display_name_with_login' === $show ) { |
|
| 1069 | + foreach ((array) $users as $user) { |
|
| 1070 | + if ('display_name_with_login' === $show) { |
|
| 1071 | 1071 | /* translators: 1: display name, 2: user_login */ |
| 1072 | - $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_login ); |
|
| 1073 | - } elseif ( ! empty( $user->$show ) ) { |
|
| 1072 | + $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_login); |
|
| 1073 | + } elseif ( ! empty($user->$show)) { |
|
| 1074 | 1074 | $display = $user->$show; |
| 1075 | 1075 | } else { |
| 1076 | - $display = '(' . $user->user_login . ')'; |
|
| 1076 | + $display = '('.$user->user_login.')'; |
|
| 1077 | 1077 | } |
| 1078 | 1078 | |
| 1079 | - $_selected = selected( $user->ID, $r['selected'], false ); |
|
| 1080 | - $output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n"; |
|
| 1079 | + $_selected = selected($user->ID, $r['selected'], false); |
|
| 1080 | + $output .= "\t<option value='$user->ID'$_selected>".esc_html($display)."</option>\n"; |
|
| 1081 | 1081 | } |
| 1082 | 1082 | |
| 1083 | 1083 | $output .= "</select>"; |
@@ -1090,9 +1090,9 @@ discard block |
||
| 1090 | 1090 | * |
| 1091 | 1091 | * @param string $output HTML output generated by wp_dropdown_users(). |
| 1092 | 1092 | */ |
| 1093 | - $html = apply_filters( 'wp_dropdown_users', $output ); |
|
| 1093 | + $html = apply_filters('wp_dropdown_users', $output); |
|
| 1094 | 1094 | |
| 1095 | - if ( $r['echo'] ) { |
|
| 1095 | + if ($r['echo']) { |
|
| 1096 | 1096 | echo $html; |
| 1097 | 1097 | } |
| 1098 | 1098 | return $html; |
@@ -1116,22 +1116,22 @@ discard block |
||
| 1116 | 1116 | */ |
| 1117 | 1117 | function sanitize_user_field($field, $value, $user_id, $context) { |
| 1118 | 1118 | $int_fields = array('ID'); |
| 1119 | - if ( in_array($field, $int_fields) ) |
|
| 1119 | + if (in_array($field, $int_fields)) |
|
| 1120 | 1120 | $value = (int) $value; |
| 1121 | 1121 | |
| 1122 | - if ( 'raw' == $context ) |
|
| 1122 | + if ('raw' == $context) |
|
| 1123 | 1123 | return $value; |
| 1124 | 1124 | |
| 1125 | - if ( !is_string($value) && !is_numeric($value) ) |
|
| 1125 | + if ( ! is_string($value) && ! is_numeric($value)) |
|
| 1126 | 1126 | return $value; |
| 1127 | 1127 | |
| 1128 | - $prefixed = false !== strpos( $field, 'user_' ); |
|
| 1128 | + $prefixed = false !== strpos($field, 'user_'); |
|
| 1129 | 1129 | |
| 1130 | - if ( 'edit' == $context ) { |
|
| 1131 | - if ( $prefixed ) { |
|
| 1130 | + if ('edit' == $context) { |
|
| 1131 | + if ($prefixed) { |
|
| 1132 | 1132 | |
| 1133 | 1133 | /** This filter is documented in wp-includes/post.php */ |
| 1134 | - $value = apply_filters( "edit_{$field}", $value, $user_id ); |
|
| 1134 | + $value = apply_filters("edit_{$field}", $value, $user_id); |
|
| 1135 | 1135 | } else { |
| 1136 | 1136 | |
| 1137 | 1137 | /** |
@@ -1145,17 +1145,17 @@ discard block |
||
| 1145 | 1145 | * @param mixed $value Value of the prefixed user field. |
| 1146 | 1146 | * @param int $user_id User ID. |
| 1147 | 1147 | */ |
| 1148 | - $value = apply_filters( "edit_user_{$field}", $value, $user_id ); |
|
| 1148 | + $value = apply_filters("edit_user_{$field}", $value, $user_id); |
|
| 1149 | 1149 | } |
| 1150 | 1150 | |
| 1151 | - if ( 'description' == $field ) |
|
| 1152 | - $value = esc_html( $value ); // textarea_escaped? |
|
| 1151 | + if ('description' == $field) |
|
| 1152 | + $value = esc_html($value); // textarea_escaped? |
|
| 1153 | 1153 | else |
| 1154 | 1154 | $value = esc_attr($value); |
| 1155 | - } elseif ( 'db' == $context ) { |
|
| 1156 | - if ( $prefixed ) { |
|
| 1155 | + } elseif ('db' == $context) { |
|
| 1156 | + if ($prefixed) { |
|
| 1157 | 1157 | /** This filter is documented in wp-includes/post.php */ |
| 1158 | - $value = apply_filters( "pre_{$field}", $value ); |
|
| 1158 | + $value = apply_filters("pre_{$field}", $value); |
|
| 1159 | 1159 | } else { |
| 1160 | 1160 | |
| 1161 | 1161 | /** |
@@ -1168,14 +1168,14 @@ discard block |
||
| 1168 | 1168 | * |
| 1169 | 1169 | * @param mixed $value Value of the prefixed user field. |
| 1170 | 1170 | */ |
| 1171 | - $value = apply_filters( "pre_user_{$field}", $value ); |
|
| 1171 | + $value = apply_filters("pre_user_{$field}", $value); |
|
| 1172 | 1172 | } |
| 1173 | 1173 | } else { |
| 1174 | 1174 | // Use display filters by default. |
| 1175 | - if ( $prefixed ) { |
|
| 1175 | + if ($prefixed) { |
|
| 1176 | 1176 | |
| 1177 | 1177 | /** This filter is documented in wp-includes/post.php */ |
| 1178 | - $value = apply_filters( $field, $value, $user_id, $context ); |
|
| 1178 | + $value = apply_filters($field, $value, $user_id, $context); |
|
| 1179 | 1179 | } else { |
| 1180 | 1180 | |
| 1181 | 1181 | /** |
@@ -1190,17 +1190,17 @@ discard block |
||
| 1190 | 1190 | * @param int $user_id User ID. |
| 1191 | 1191 | * @param string $context The context to filter within. |
| 1192 | 1192 | */ |
| 1193 | - $value = apply_filters( "user_{$field}", $value, $user_id, $context ); |
|
| 1193 | + $value = apply_filters("user_{$field}", $value, $user_id, $context); |
|
| 1194 | 1194 | } |
| 1195 | 1195 | } |
| 1196 | 1196 | |
| 1197 | - if ( 'user_url' == $field ) |
|
| 1197 | + if ('user_url' == $field) |
|
| 1198 | 1198 | $value = esc_url($value); |
| 1199 | 1199 | |
| 1200 | - if ( 'attribute' == $context ) { |
|
| 1201 | - $value = esc_attr( $value ); |
|
| 1202 | - } elseif ( 'js' == $context ) { |
|
| 1203 | - $value = esc_js( $value ); |
|
| 1200 | + if ('attribute' == $context) { |
|
| 1201 | + $value = esc_attr($value); |
|
| 1202 | + } elseif ('js' == $context) { |
|
| 1203 | + $value = esc_js($value); |
|
| 1204 | 1204 | } |
| 1205 | 1205 | return $value; |
| 1206 | 1206 | } |
@@ -1213,9 +1213,9 @@ discard block |
||
| 1213 | 1213 | * @param object|WP_User $user User object to be cached |
| 1214 | 1214 | * @return bool|null Returns false on failure. |
| 1215 | 1215 | */ |
| 1216 | -function update_user_caches( $user ) { |
|
| 1217 | - if ( $user instanceof WP_User ) { |
|
| 1218 | - if ( ! $user->exists() ) { |
|
| 1216 | +function update_user_caches($user) { |
|
| 1217 | + if ($user instanceof WP_User) { |
|
| 1218 | + if ( ! $user->exists()) { |
|
| 1219 | 1219 | return false; |
| 1220 | 1220 | } |
| 1221 | 1221 | |
@@ -1236,17 +1236,17 @@ discard block |
||
| 1236 | 1236 | * |
| 1237 | 1237 | * @param WP_User|int $user User object or ID to be cleaned from the cache |
| 1238 | 1238 | */ |
| 1239 | -function clean_user_cache( $user ) { |
|
| 1240 | - if ( is_numeric( $user ) ) |
|
| 1241 | - $user = new WP_User( $user ); |
|
| 1239 | +function clean_user_cache($user) { |
|
| 1240 | + if (is_numeric($user)) |
|
| 1241 | + $user = new WP_User($user); |
|
| 1242 | 1242 | |
| 1243 | - if ( ! $user->exists() ) |
|
| 1243 | + if ( ! $user->exists()) |
|
| 1244 | 1244 | return; |
| 1245 | 1245 | |
| 1246 | - wp_cache_delete( $user->ID, 'users' ); |
|
| 1247 | - wp_cache_delete( $user->user_login, 'userlogins' ); |
|
| 1248 | - wp_cache_delete( $user->user_email, 'useremail' ); |
|
| 1249 | - wp_cache_delete( $user->user_nicename, 'userslugs' ); |
|
| 1246 | + wp_cache_delete($user->ID, 'users'); |
|
| 1247 | + wp_cache_delete($user->user_login, 'userlogins'); |
|
| 1248 | + wp_cache_delete($user->user_email, 'useremail'); |
|
| 1249 | + wp_cache_delete($user->user_nicename, 'userslugs'); |
|
| 1250 | 1250 | |
| 1251 | 1251 | /** |
| 1252 | 1252 | * Fires immediately after the given user's cache is cleaned. |
@@ -1256,7 +1256,7 @@ discard block |
||
| 1256 | 1256 | * @param int $user_id User ID. |
| 1257 | 1257 | * @param WP_User $user User object. |
| 1258 | 1258 | */ |
| 1259 | - do_action( 'clean_user_cache', $user->ID, $user ); |
|
| 1259 | + do_action('clean_user_cache', $user->ID, $user); |
|
| 1260 | 1260 | } |
| 1261 | 1261 | |
| 1262 | 1262 | /** |
@@ -1267,8 +1267,8 @@ discard block |
||
| 1267 | 1267 | * @param string $username Username. |
| 1268 | 1268 | * @return int|false The user's ID on success, and false on failure. |
| 1269 | 1269 | */ |
| 1270 | -function username_exists( $username ) { |
|
| 1271 | - if ( $user = get_user_by( 'login', $username ) ) { |
|
| 1270 | +function username_exists($username) { |
|
| 1271 | + if ($user = get_user_by('login', $username)) { |
|
| 1272 | 1272 | return $user->ID; |
| 1273 | 1273 | } |
| 1274 | 1274 | return false; |
@@ -1282,8 +1282,8 @@ discard block |
||
| 1282 | 1282 | * @param string $email Email. |
| 1283 | 1283 | * @return int|false The user's ID on success, and false on failure. |
| 1284 | 1284 | */ |
| 1285 | -function email_exists( $email ) { |
|
| 1286 | - if ( $user = get_user_by( 'email', $email) ) { |
|
| 1285 | +function email_exists($email) { |
|
| 1286 | + if ($user = get_user_by('email', $email)) { |
|
| 1287 | 1287 | return $user->ID; |
| 1288 | 1288 | } |
| 1289 | 1289 | return false; |
@@ -1298,9 +1298,9 @@ discard block |
||
| 1298 | 1298 | * @param string $username Username. |
| 1299 | 1299 | * @return bool Whether username given is valid |
| 1300 | 1300 | */ |
| 1301 | -function validate_username( $username ) { |
|
| 1302 | - $sanitized = sanitize_user( $username, true ); |
|
| 1303 | - $valid = ( $sanitized == $username && ! empty( $sanitized ) ); |
|
| 1301 | +function validate_username($username) { |
|
| 1302 | + $sanitized = sanitize_user($username, true); |
|
| 1303 | + $valid = ($sanitized == $username && ! empty($sanitized)); |
|
| 1304 | 1304 | |
| 1305 | 1305 | /** |
| 1306 | 1306 | * Filter whether the provided username is valid or not. |
@@ -1310,7 +1310,7 @@ discard block |
||
| 1310 | 1310 | * @param bool $valid Whether given username is valid. |
| 1311 | 1311 | * @param string $username Username to check. |
| 1312 | 1312 | */ |
| 1313 | - return apply_filters( 'validate_username', $valid, $username ); |
|
| 1313 | + return apply_filters('validate_username', $valid, $username); |
|
| 1314 | 1314 | } |
| 1315 | 1315 | |
| 1316 | 1316 | /** |
@@ -1363,34 +1363,34 @@ discard block |
||
| 1363 | 1363 | * @return int|WP_Error The newly created user's ID or a WP_Error object if the user could not |
| 1364 | 1364 | * be created. |
| 1365 | 1365 | */ |
| 1366 | -function wp_insert_user( $userdata ) { |
|
| 1366 | +function wp_insert_user($userdata) { |
|
| 1367 | 1367 | global $wpdb; |
| 1368 | 1368 | |
| 1369 | - if ( $userdata instanceof stdClass ) { |
|
| 1370 | - $userdata = get_object_vars( $userdata ); |
|
| 1371 | - } elseif ( $userdata instanceof WP_User ) { |
|
| 1369 | + if ($userdata instanceof stdClass) { |
|
| 1370 | + $userdata = get_object_vars($userdata); |
|
| 1371 | + } elseif ($userdata instanceof WP_User) { |
|
| 1372 | 1372 | $userdata = $userdata->to_array(); |
| 1373 | 1373 | } |
| 1374 | 1374 | |
| 1375 | 1375 | // Are we updating or creating? |
| 1376 | - if ( ! empty( $userdata['ID'] ) ) { |
|
| 1376 | + if ( ! empty($userdata['ID'])) { |
|
| 1377 | 1377 | $ID = (int) $userdata['ID']; |
| 1378 | 1378 | $update = true; |
| 1379 | - $old_user_data = get_userdata( $ID ); |
|
| 1379 | + $old_user_data = get_userdata($ID); |
|
| 1380 | 1380 | |
| 1381 | - if ( ! $old_user_data ) { |
|
| 1382 | - return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) ); |
|
| 1381 | + if ( ! $old_user_data) { |
|
| 1382 | + return new WP_Error('invalid_user_id', __('Invalid user ID.')); |
|
| 1383 | 1383 | } |
| 1384 | 1384 | |
| 1385 | 1385 | // hashed in wp_update_user(), plaintext if called directly |
| 1386 | - $user_pass = ! empty( $userdata['user_pass'] ) ? $userdata['user_pass'] : $old_user_data->user_pass; |
|
| 1386 | + $user_pass = ! empty($userdata['user_pass']) ? $userdata['user_pass'] : $old_user_data->user_pass; |
|
| 1387 | 1387 | } else { |
| 1388 | 1388 | $update = false; |
| 1389 | 1389 | // Hash the password |
| 1390 | - $user_pass = wp_hash_password( $userdata['user_pass'] ); |
|
| 1390 | + $user_pass = wp_hash_password($userdata['user_pass']); |
|
| 1391 | 1391 | } |
| 1392 | 1392 | |
| 1393 | - $sanitized_user_login = sanitize_user( $userdata['user_login'], true ); |
|
| 1393 | + $sanitized_user_login = sanitize_user($userdata['user_login'], true); |
|
| 1394 | 1394 | |
| 1395 | 1395 | /** |
| 1396 | 1396 | * Filter a username after it has been sanitized. |
@@ -1401,20 +1401,20 @@ discard block |
||
| 1401 | 1401 | * |
| 1402 | 1402 | * @param string $sanitized_user_login Username after it has been sanitized. |
| 1403 | 1403 | */ |
| 1404 | - $pre_user_login = apply_filters( 'pre_user_login', $sanitized_user_login ); |
|
| 1404 | + $pre_user_login = apply_filters('pre_user_login', $sanitized_user_login); |
|
| 1405 | 1405 | |
| 1406 | 1406 | //Remove any non-printable chars from the login string to see if we have ended up with an empty username |
| 1407 | - $user_login = trim( $pre_user_login ); |
|
| 1407 | + $user_login = trim($pre_user_login); |
|
| 1408 | 1408 | |
| 1409 | 1409 | // user_login must be between 0 and 60 characters. |
| 1410 | - if ( empty( $user_login ) ) { |
|
| 1411 | - return new WP_Error('empty_user_login', __('Cannot create a user with an empty login name.') ); |
|
| 1412 | - } elseif ( mb_strlen( $user_login ) > 60 ) { |
|
| 1413 | - return new WP_Error( 'user_login_too_long', __( 'Username may not be longer than 60 characters.' ) ); |
|
| 1410 | + if (empty($user_login)) { |
|
| 1411 | + return new WP_Error('empty_user_login', __('Cannot create a user with an empty login name.')); |
|
| 1412 | + } elseif (mb_strlen($user_login) > 60) { |
|
| 1413 | + return new WP_Error('user_login_too_long', __('Username may not be longer than 60 characters.')); |
|
| 1414 | 1414 | } |
| 1415 | 1415 | |
| 1416 | - if ( ! $update && username_exists( $user_login ) ) { |
|
| 1417 | - return new WP_Error( 'existing_user_login', __( 'Sorry, that username already exists!' ) ); |
|
| 1416 | + if ( ! $update && username_exists($user_login)) { |
|
| 1417 | + return new WP_Error('existing_user_login', __('Sorry, that username already exists!')); |
|
| 1418 | 1418 | } |
| 1419 | 1419 | |
| 1420 | 1420 | /** |
@@ -1424,26 +1424,26 @@ discard block |
||
| 1424 | 1424 | * |
| 1425 | 1425 | * @param array $usernames Array of blacklisted usernames. |
| 1426 | 1426 | */ |
| 1427 | - $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
|
| 1427 | + $illegal_logins = (array) apply_filters('illegal_user_logins', array()); |
|
| 1428 | 1428 | |
| 1429 | - if ( in_array( strtolower( $user_login ), array_map( 'strtolower', $illegal_logins ) ) ) { |
|
| 1430 | - return new WP_Error( 'invalid_username', __( 'Sorry, that username is not allowed.' ) ); |
|
| 1429 | + if (in_array(strtolower($user_login), array_map('strtolower', $illegal_logins))) { |
|
| 1430 | + return new WP_Error('invalid_username', __('Sorry, that username is not allowed.')); |
|
| 1431 | 1431 | } |
| 1432 | 1432 | |
| 1433 | 1433 | /* |
| 1434 | 1434 | * If a nicename is provided, remove unsafe user characters before using it. |
| 1435 | 1435 | * Otherwise build a nicename from the user_login. |
| 1436 | 1436 | */ |
| 1437 | - if ( ! empty( $userdata['user_nicename'] ) ) { |
|
| 1438 | - $user_nicename = sanitize_user( $userdata['user_nicename'], true ); |
|
| 1439 | - if ( mb_strlen( $user_nicename ) > 50 ) { |
|
| 1440 | - return new WP_Error( 'user_nicename_too_long', __( 'Nicename may not be longer than 50 characters.' ) ); |
|
| 1437 | + if ( ! empty($userdata['user_nicename'])) { |
|
| 1438 | + $user_nicename = sanitize_user($userdata['user_nicename'], true); |
|
| 1439 | + if (mb_strlen($user_nicename) > 50) { |
|
| 1440 | + return new WP_Error('user_nicename_too_long', __('Nicename may not be longer than 50 characters.')); |
|
| 1441 | 1441 | } |
| 1442 | 1442 | } else { |
| 1443 | - $user_nicename = mb_substr( $user_login, 0, 50 ); |
|
| 1443 | + $user_nicename = mb_substr($user_login, 0, 50); |
|
| 1444 | 1444 | } |
| 1445 | 1445 | |
| 1446 | - $user_nicename = sanitize_title( $user_nicename ); |
|
| 1446 | + $user_nicename = sanitize_title($user_nicename); |
|
| 1447 | 1447 | |
| 1448 | 1448 | // Store values to save in user meta. |
| 1449 | 1449 | $meta = array(); |
@@ -1455,9 +1455,9 @@ discard block |
||
| 1455 | 1455 | * |
| 1456 | 1456 | * @param string $user_nicename The user's nicename. |
| 1457 | 1457 | */ |
| 1458 | - $user_nicename = apply_filters( 'pre_user_nicename', $user_nicename ); |
|
| 1458 | + $user_nicename = apply_filters('pre_user_nicename', $user_nicename); |
|
| 1459 | 1459 | |
| 1460 | - $raw_user_url = empty( $userdata['user_url'] ) ? '' : $userdata['user_url']; |
|
| 1460 | + $raw_user_url = empty($userdata['user_url']) ? '' : $userdata['user_url']; |
|
| 1461 | 1461 | |
| 1462 | 1462 | /** |
| 1463 | 1463 | * Filter a user's URL before the user is created or updated. |
@@ -1466,9 +1466,9 @@ discard block |
||
| 1466 | 1466 | * |
| 1467 | 1467 | * @param string $raw_user_url The user's URL. |
| 1468 | 1468 | */ |
| 1469 | - $user_url = apply_filters( 'pre_user_url', $raw_user_url ); |
|
| 1469 | + $user_url = apply_filters('pre_user_url', $raw_user_url); |
|
| 1470 | 1470 | |
| 1471 | - $raw_user_email = empty( $userdata['user_email'] ) ? '' : $userdata['user_email']; |
|
| 1471 | + $raw_user_email = empty($userdata['user_email']) ? '' : $userdata['user_email']; |
|
| 1472 | 1472 | |
| 1473 | 1473 | /** |
| 1474 | 1474 | * Filter a user's email before the user is created or updated. |
@@ -1477,20 +1477,20 @@ discard block |
||
| 1477 | 1477 | * |
| 1478 | 1478 | * @param string $raw_user_email The user's email. |
| 1479 | 1479 | */ |
| 1480 | - $user_email = apply_filters( 'pre_user_email', $raw_user_email ); |
|
| 1480 | + $user_email = apply_filters('pre_user_email', $raw_user_email); |
|
| 1481 | 1481 | |
| 1482 | 1482 | /* |
| 1483 | 1483 | * If there is no update, just check for `email_exists`. If there is an update, |
| 1484 | 1484 | * check if current email and new email are the same, or not, and check `email_exists` |
| 1485 | 1485 | * accordingly. |
| 1486 | 1486 | */ |
| 1487 | - if ( ( ! $update || ( ! empty( $old_user_data ) && 0 !== strcasecmp( $user_email, $old_user_data->user_email ) ) ) |
|
| 1488 | - && ! defined( 'WP_IMPORTING' ) |
|
| 1489 | - && email_exists( $user_email ) |
|
| 1487 | + if (( ! $update || ( ! empty($old_user_data) && 0 !== strcasecmp($user_email, $old_user_data->user_email))) |
|
| 1488 | + && ! defined('WP_IMPORTING') |
|
| 1489 | + && email_exists($user_email) |
|
| 1490 | 1490 | ) { |
| 1491 | - return new WP_Error( 'existing_user_email', __( 'Sorry, that email address is already used!' ) ); |
|
| 1491 | + return new WP_Error('existing_user_email', __('Sorry, that email address is already used!')); |
|
| 1492 | 1492 | } |
| 1493 | - $nickname = empty( $userdata['nickname'] ) ? $user_login : $userdata['nickname']; |
|
| 1493 | + $nickname = empty($userdata['nickname']) ? $user_login : $userdata['nickname']; |
|
| 1494 | 1494 | |
| 1495 | 1495 | /** |
| 1496 | 1496 | * Filter a user's nickname before the user is created or updated. |
@@ -1499,9 +1499,9 @@ discard block |
||
| 1499 | 1499 | * |
| 1500 | 1500 | * @param string $nickname The user's nickname. |
| 1501 | 1501 | */ |
| 1502 | - $meta['nickname'] = apply_filters( 'pre_user_nickname', $nickname ); |
|
| 1502 | + $meta['nickname'] = apply_filters('pre_user_nickname', $nickname); |
|
| 1503 | 1503 | |
| 1504 | - $first_name = empty( $userdata['first_name'] ) ? '' : $userdata['first_name']; |
|
| 1504 | + $first_name = empty($userdata['first_name']) ? '' : $userdata['first_name']; |
|
| 1505 | 1505 | |
| 1506 | 1506 | /** |
| 1507 | 1507 | * Filter a user's first name before the user is created or updated. |
@@ -1510,9 +1510,9 @@ discard block |
||
| 1510 | 1510 | * |
| 1511 | 1511 | * @param string $first_name The user's first name. |
| 1512 | 1512 | */ |
| 1513 | - $meta['first_name'] = apply_filters( 'pre_user_first_name', $first_name ); |
|
| 1513 | + $meta['first_name'] = apply_filters('pre_user_first_name', $first_name); |
|
| 1514 | 1514 | |
| 1515 | - $last_name = empty( $userdata['last_name'] ) ? '' : $userdata['last_name']; |
|
| 1515 | + $last_name = empty($userdata['last_name']) ? '' : $userdata['last_name']; |
|
| 1516 | 1516 | |
| 1517 | 1517 | /** |
| 1518 | 1518 | * Filter a user's last name before the user is created or updated. |
@@ -1521,17 +1521,17 @@ discard block |
||
| 1521 | 1521 | * |
| 1522 | 1522 | * @param string $last_name The user's last name. |
| 1523 | 1523 | */ |
| 1524 | - $meta['last_name'] = apply_filters( 'pre_user_last_name', $last_name ); |
|
| 1524 | + $meta['last_name'] = apply_filters('pre_user_last_name', $last_name); |
|
| 1525 | 1525 | |
| 1526 | - if ( empty( $userdata['display_name'] ) ) { |
|
| 1527 | - if ( $update ) { |
|
| 1526 | + if (empty($userdata['display_name'])) { |
|
| 1527 | + if ($update) { |
|
| 1528 | 1528 | $display_name = $user_login; |
| 1529 | - } elseif ( $meta['first_name'] && $meta['last_name'] ) { |
|
| 1529 | + } elseif ($meta['first_name'] && $meta['last_name']) { |
|
| 1530 | 1530 | /* translators: 1: first name, 2: last name */ |
| 1531 | - $display_name = sprintf( _x( '%1$s %2$s', 'Display name based on first name and last name' ), $meta['first_name'], $meta['last_name'] ); |
|
| 1532 | - } elseif ( $meta['first_name'] ) { |
|
| 1531 | + $display_name = sprintf(_x('%1$s %2$s', 'Display name based on first name and last name'), $meta['first_name'], $meta['last_name']); |
|
| 1532 | + } elseif ($meta['first_name']) { |
|
| 1533 | 1533 | $display_name = $meta['first_name']; |
| 1534 | - } elseif ( $meta['last_name'] ) { |
|
| 1534 | + } elseif ($meta['last_name']) { |
|
| 1535 | 1535 | $display_name = $meta['last_name']; |
| 1536 | 1536 | } else { |
| 1537 | 1537 | $display_name = $user_login; |
@@ -1547,9 +1547,9 @@ discard block |
||
| 1547 | 1547 | * |
| 1548 | 1548 | * @param string $display_name The user's display name. |
| 1549 | 1549 | */ |
| 1550 | - $display_name = apply_filters( 'pre_user_display_name', $display_name ); |
|
| 1550 | + $display_name = apply_filters('pre_user_display_name', $display_name); |
|
| 1551 | 1551 | |
| 1552 | - $description = empty( $userdata['description'] ) ? '' : $userdata['description']; |
|
| 1552 | + $description = empty($userdata['description']) ? '' : $userdata['description']; |
|
| 1553 | 1553 | |
| 1554 | 1554 | /** |
| 1555 | 1555 | * Filter a user's description before the user is created or updated. |
@@ -1558,50 +1558,50 @@ discard block |
||
| 1558 | 1558 | * |
| 1559 | 1559 | * @param string $description The user's description. |
| 1560 | 1560 | */ |
| 1561 | - $meta['description'] = apply_filters( 'pre_user_description', $description ); |
|
| 1561 | + $meta['description'] = apply_filters('pre_user_description', $description); |
|
| 1562 | 1562 | |
| 1563 | - $meta['rich_editing'] = empty( $userdata['rich_editing'] ) ? 'true' : $userdata['rich_editing']; |
|
| 1563 | + $meta['rich_editing'] = empty($userdata['rich_editing']) ? 'true' : $userdata['rich_editing']; |
|
| 1564 | 1564 | |
| 1565 | - $meta['comment_shortcuts'] = empty( $userdata['comment_shortcuts'] ) || 'false' === $userdata['comment_shortcuts'] ? 'false' : 'true'; |
|
| 1565 | + $meta['comment_shortcuts'] = empty($userdata['comment_shortcuts']) || 'false' === $userdata['comment_shortcuts'] ? 'false' : 'true'; |
|
| 1566 | 1566 | |
| 1567 | - $admin_color = empty( $userdata['admin_color'] ) ? 'fresh' : $userdata['admin_color']; |
|
| 1568 | - $meta['admin_color'] = preg_replace( '|[^a-z0-9 _.\-@]|i', '', $admin_color ); |
|
| 1567 | + $admin_color = empty($userdata['admin_color']) ? 'fresh' : $userdata['admin_color']; |
|
| 1568 | + $meta['admin_color'] = preg_replace('|[^a-z0-9 _.\-@]|i', '', $admin_color); |
|
| 1569 | 1569 | |
| 1570 | - $meta['use_ssl'] = empty( $userdata['use_ssl'] ) ? 0 : $userdata['use_ssl']; |
|
| 1570 | + $meta['use_ssl'] = empty($userdata['use_ssl']) ? 0 : $userdata['use_ssl']; |
|
| 1571 | 1571 | |
| 1572 | - $user_registered = empty( $userdata['user_registered'] ) ? gmdate( 'Y-m-d H:i:s' ) : $userdata['user_registered']; |
|
| 1572 | + $user_registered = empty($userdata['user_registered']) ? gmdate('Y-m-d H:i:s') : $userdata['user_registered']; |
|
| 1573 | 1573 | |
| 1574 | - $meta['show_admin_bar_front'] = empty( $userdata['show_admin_bar_front'] ) ? 'true' : $userdata['show_admin_bar_front']; |
|
| 1574 | + $meta['show_admin_bar_front'] = empty($userdata['show_admin_bar_front']) ? 'true' : $userdata['show_admin_bar_front']; |
|
| 1575 | 1575 | |
| 1576 | - $user_nicename_check = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1" , $user_nicename, $user_login)); |
|
| 1576 | + $user_nicename_check = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1", $user_nicename, $user_login)); |
|
| 1577 | 1577 | |
| 1578 | - if ( $user_nicename_check ) { |
|
| 1578 | + if ($user_nicename_check) { |
|
| 1579 | 1579 | $suffix = 2; |
| 1580 | 1580 | while ($user_nicename_check) { |
| 1581 | 1581 | // user_nicename allows 50 chars. Subtract one for a hyphen, plus the length of the suffix. |
| 1582 | - $base_length = 49 - mb_strlen( $suffix ); |
|
| 1583 | - $alt_user_nicename = mb_substr( $user_nicename, 0, $base_length ) . "-$suffix"; |
|
| 1584 | - $user_nicename_check = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1" , $alt_user_nicename, $user_login)); |
|
| 1582 | + $base_length = 49 - mb_strlen($suffix); |
|
| 1583 | + $alt_user_nicename = mb_substr($user_nicename, 0, $base_length)."-$suffix"; |
|
| 1584 | + $user_nicename_check = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1", $alt_user_nicename, $user_login)); |
|
| 1585 | 1585 | $suffix++; |
| 1586 | 1586 | } |
| 1587 | 1587 | $user_nicename = $alt_user_nicename; |
| 1588 | 1588 | } |
| 1589 | 1589 | |
| 1590 | - $compacted = compact( 'user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered' ); |
|
| 1591 | - $data = wp_unslash( $compacted ); |
|
| 1590 | + $compacted = compact('user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered'); |
|
| 1591 | + $data = wp_unslash($compacted); |
|
| 1592 | 1592 | |
| 1593 | - if ( $update ) { |
|
| 1594 | - if ( $user_email !== $old_user_data->user_email ) { |
|
| 1593 | + if ($update) { |
|
| 1594 | + if ($user_email !== $old_user_data->user_email) { |
|
| 1595 | 1595 | $data['user_activation_key'] = ''; |
| 1596 | 1596 | } |
| 1597 | - $wpdb->update( $wpdb->users, $data, compact( 'ID' ) ); |
|
| 1597 | + $wpdb->update($wpdb->users, $data, compact('ID')); |
|
| 1598 | 1598 | $user_id = (int) $ID; |
| 1599 | 1599 | } else { |
| 1600 | - $wpdb->insert( $wpdb->users, $data + compact( 'user_login' ) ); |
|
| 1600 | + $wpdb->insert($wpdb->users, $data + compact('user_login')); |
|
| 1601 | 1601 | $user_id = (int) $wpdb->insert_id; |
| 1602 | 1602 | } |
| 1603 | 1603 | |
| 1604 | - $user = new WP_User( $user_id ); |
|
| 1604 | + $user = new WP_User($user_id); |
|
| 1605 | 1605 | |
| 1606 | 1606 | /** |
| 1607 | 1607 | * Filter a user's meta values and keys before the user is created or updated. |
@@ -1628,28 +1628,28 @@ discard block |
||
| 1628 | 1628 | * @param WP_User $user User object. |
| 1629 | 1629 | * @param bool $update Whether the user is being updated rather than created. |
| 1630 | 1630 | */ |
| 1631 | - $meta = apply_filters( 'insert_user_meta', $meta, $user, $update ); |
|
| 1631 | + $meta = apply_filters('insert_user_meta', $meta, $user, $update); |
|
| 1632 | 1632 | |
| 1633 | 1633 | // Update user meta. |
| 1634 | - foreach ( $meta as $key => $value ) { |
|
| 1635 | - update_user_meta( $user_id, $key, $value ); |
|
| 1634 | + foreach ($meta as $key => $value) { |
|
| 1635 | + update_user_meta($user_id, $key, $value); |
|
| 1636 | 1636 | } |
| 1637 | 1637 | |
| 1638 | - foreach ( wp_get_user_contact_methods( $user ) as $key => $value ) { |
|
| 1639 | - if ( isset( $userdata[ $key ] ) ) { |
|
| 1640 | - update_user_meta( $user_id, $key, $userdata[ $key ] ); |
|
| 1638 | + foreach (wp_get_user_contact_methods($user) as $key => $value) { |
|
| 1639 | + if (isset($userdata[$key])) { |
|
| 1640 | + update_user_meta($user_id, $key, $userdata[$key]); |
|
| 1641 | 1641 | } |
| 1642 | 1642 | } |
| 1643 | 1643 | |
| 1644 | - if ( isset( $userdata['role'] ) ) { |
|
| 1645 | - $user->set_role( $userdata['role'] ); |
|
| 1646 | - } elseif ( ! $update ) { |
|
| 1644 | + if (isset($userdata['role'])) { |
|
| 1645 | + $user->set_role($userdata['role']); |
|
| 1646 | + } elseif ( ! $update) { |
|
| 1647 | 1647 | $user->set_role(get_option('default_role')); |
| 1648 | 1648 | } |
| 1649 | - wp_cache_delete( $user_id, 'users' ); |
|
| 1650 | - wp_cache_delete( $user_login, 'userlogins' ); |
|
| 1649 | + wp_cache_delete($user_id, 'users'); |
|
| 1650 | + wp_cache_delete($user_login, 'userlogins'); |
|
| 1651 | 1651 | |
| 1652 | - if ( $update ) { |
|
| 1652 | + if ($update) { |
|
| 1653 | 1653 | /** |
| 1654 | 1654 | * Fires immediately after an existing user is updated. |
| 1655 | 1655 | * |
@@ -1658,7 +1658,7 @@ discard block |
||
| 1658 | 1658 | * @param int $user_id User ID. |
| 1659 | 1659 | * @param object $old_user_data Object containing user's data prior to update. |
| 1660 | 1660 | */ |
| 1661 | - do_action( 'profile_update', $user_id, $old_user_data ); |
|
| 1661 | + do_action('profile_update', $user_id, $old_user_data); |
|
| 1662 | 1662 | } else { |
| 1663 | 1663 | /** |
| 1664 | 1664 | * Fires immediately after a new user is registered. |
@@ -1667,7 +1667,7 @@ discard block |
||
| 1667 | 1667 | * |
| 1668 | 1668 | * @param int $user_id User ID. |
| 1669 | 1669 | */ |
| 1670 | - do_action( 'user_register', $user_id ); |
|
| 1670 | + do_action('user_register', $user_id); |
|
| 1671 | 1671 | } |
| 1672 | 1672 | |
| 1673 | 1673 | return $user_id; |
@@ -1690,37 +1690,37 @@ discard block |
||
| 1690 | 1690 | * @return int|WP_Error The updated user's ID or a WP_Error object if the user could not be updated. |
| 1691 | 1691 | */ |
| 1692 | 1692 | function wp_update_user($userdata) { |
| 1693 | - if ( $userdata instanceof stdClass ) { |
|
| 1694 | - $userdata = get_object_vars( $userdata ); |
|
| 1695 | - } elseif ( $userdata instanceof WP_User ) { |
|
| 1693 | + if ($userdata instanceof stdClass) { |
|
| 1694 | + $userdata = get_object_vars($userdata); |
|
| 1695 | + } elseif ($userdata instanceof WP_User) { |
|
| 1696 | 1696 | $userdata = $userdata->to_array(); |
| 1697 | 1697 | } |
| 1698 | 1698 | |
| 1699 | - $ID = isset( $userdata['ID'] ) ? (int) $userdata['ID'] : 0; |
|
| 1700 | - if ( ! $ID ) { |
|
| 1701 | - return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) ); |
|
| 1699 | + $ID = isset($userdata['ID']) ? (int) $userdata['ID'] : 0; |
|
| 1700 | + if ( ! $ID) { |
|
| 1701 | + return new WP_Error('invalid_user_id', __('Invalid user ID.')); |
|
| 1702 | 1702 | } |
| 1703 | 1703 | |
| 1704 | 1704 | // First, get all of the original fields |
| 1705 | - $user_obj = get_userdata( $ID ); |
|
| 1706 | - if ( ! $user_obj ) { |
|
| 1707 | - return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) ); |
|
| 1705 | + $user_obj = get_userdata($ID); |
|
| 1706 | + if ( ! $user_obj) { |
|
| 1707 | + return new WP_Error('invalid_user_id', __('Invalid user ID.')); |
|
| 1708 | 1708 | } |
| 1709 | 1709 | |
| 1710 | 1710 | $user = $user_obj->to_array(); |
| 1711 | 1711 | |
| 1712 | 1712 | // Add additional custom fields |
| 1713 | - foreach ( _get_additional_user_keys( $user_obj ) as $key ) { |
|
| 1714 | - $user[ $key ] = get_user_meta( $ID, $key, true ); |
|
| 1713 | + foreach (_get_additional_user_keys($user_obj) as $key) { |
|
| 1714 | + $user[$key] = get_user_meta($ID, $key, true); |
|
| 1715 | 1715 | } |
| 1716 | 1716 | |
| 1717 | 1717 | // Escape data pulled from DB. |
| 1718 | - $user = add_magic_quotes( $user ); |
|
| 1718 | + $user = add_magic_quotes($user); |
|
| 1719 | 1719 | |
| 1720 | - if ( ! empty( $userdata['user_pass'] ) && $userdata['user_pass'] !== $user_obj->user_pass ) { |
|
| 1720 | + if ( ! empty($userdata['user_pass']) && $userdata['user_pass'] !== $user_obj->user_pass) { |
|
| 1721 | 1721 | // If password is changing, hash it now |
| 1722 | 1722 | $plaintext_pass = $userdata['user_pass']; |
| 1723 | - $userdata['user_pass'] = wp_hash_password( $userdata['user_pass'] ); |
|
| 1723 | + $userdata['user_pass'] = wp_hash_password($userdata['user_pass']); |
|
| 1724 | 1724 | |
| 1725 | 1725 | /** |
| 1726 | 1726 | * Filter whether to send the password change email. |
@@ -1734,10 +1734,10 @@ discard block |
||
| 1734 | 1734 | * @param array $userdata The updated user array. |
| 1735 | 1735 | * |
| 1736 | 1736 | */ |
| 1737 | - $send_password_change_email = apply_filters( 'send_password_change_email', true, $user, $userdata ); |
|
| 1737 | + $send_password_change_email = apply_filters('send_password_change_email', true, $user, $userdata); |
|
| 1738 | 1738 | } |
| 1739 | 1739 | |
| 1740 | - if ( isset( $userdata['user_email'] ) && $user['user_email'] !== $userdata['user_email'] ) { |
|
| 1740 | + if (isset($userdata['user_email']) && $user['user_email'] !== $userdata['user_email']) { |
|
| 1741 | 1741 | /** |
| 1742 | 1742 | * Filter whether to send the email change email. |
| 1743 | 1743 | * |
@@ -1750,24 +1750,24 @@ discard block |
||
| 1750 | 1750 | * @param array $userdata The updated user array. |
| 1751 | 1751 | * |
| 1752 | 1752 | */ |
| 1753 | - $send_email_change_email = apply_filters( 'send_email_change_email', true, $user, $userdata ); |
|
| 1753 | + $send_email_change_email = apply_filters('send_email_change_email', true, $user, $userdata); |
|
| 1754 | 1754 | } |
| 1755 | 1755 | |
| 1756 | - wp_cache_delete( $user['user_email'], 'useremail' ); |
|
| 1757 | - wp_cache_delete( $user['user_nicename'], 'userslugs' ); |
|
| 1756 | + wp_cache_delete($user['user_email'], 'useremail'); |
|
| 1757 | + wp_cache_delete($user['user_nicename'], 'userslugs'); |
|
| 1758 | 1758 | |
| 1759 | 1759 | // Merge old and new fields with new fields overwriting old ones. |
| 1760 | - $userdata = array_merge( $user, $userdata ); |
|
| 1761 | - $user_id = wp_insert_user( $userdata ); |
|
| 1760 | + $userdata = array_merge($user, $userdata); |
|
| 1761 | + $user_id = wp_insert_user($userdata); |
|
| 1762 | 1762 | |
| 1763 | - if ( ! is_wp_error( $user_id ) ) { |
|
| 1763 | + if ( ! is_wp_error($user_id)) { |
|
| 1764 | 1764 | |
| 1765 | - $blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
|
| 1765 | + $blog_name = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); |
|
| 1766 | 1766 | |
| 1767 | - if ( ! empty( $send_password_change_email ) ) { |
|
| 1767 | + if ( ! empty($send_password_change_email)) { |
|
| 1768 | 1768 | |
| 1769 | 1769 | /* translators: Do not translate USERNAME, ADMIN_EMAIL, EMAIL, SITENAME, SITEURL: those are placeholders. */ |
| 1770 | - $pass_change_text = __( 'Hi ###USERNAME###, |
|
| 1770 | + $pass_change_text = __('Hi ###USERNAME###, |
|
| 1771 | 1771 | |
| 1772 | 1772 | This notice confirms that your password was changed on ###SITENAME###. |
| 1773 | 1773 | |
@@ -1782,7 +1782,7 @@ discard block |
||
| 1782 | 1782 | |
| 1783 | 1783 | $pass_change_email = array( |
| 1784 | 1784 | 'to' => $user['user_email'], |
| 1785 | - 'subject' => __( '[%s] Notice of Password Change' ), |
|
| 1785 | + 'subject' => __('[%s] Notice of Password Change'), |
|
| 1786 | 1786 | 'message' => $pass_change_text, |
| 1787 | 1787 | 'headers' => '', |
| 1788 | 1788 | ); |
@@ -1809,20 +1809,20 @@ discard block |
||
| 1809 | 1809 | * @param array $userdata The updated user array. |
| 1810 | 1810 | * |
| 1811 | 1811 | */ |
| 1812 | - $pass_change_email = apply_filters( 'password_change_email', $pass_change_email, $user, $userdata ); |
|
| 1812 | + $pass_change_email = apply_filters('password_change_email', $pass_change_email, $user, $userdata); |
|
| 1813 | 1813 | |
| 1814 | - $pass_change_email['message'] = str_replace( '###USERNAME###', $user['user_login'], $pass_change_email['message'] ); |
|
| 1815 | - $pass_change_email['message'] = str_replace( '###ADMIN_EMAIL###', get_option( 'admin_email' ), $pass_change_email['message'] ); |
|
| 1816 | - $pass_change_email['message'] = str_replace( '###EMAIL###', $user['user_email'], $pass_change_email['message'] ); |
|
| 1817 | - $pass_change_email['message'] = str_replace( '###SITENAME###', $blog_name, $pass_change_email['message'] ); |
|
| 1818 | - $pass_change_email['message'] = str_replace( '###SITEURL###', home_url(), $pass_change_email['message'] ); |
|
| 1814 | + $pass_change_email['message'] = str_replace('###USERNAME###', $user['user_login'], $pass_change_email['message']); |
|
| 1815 | + $pass_change_email['message'] = str_replace('###ADMIN_EMAIL###', get_option('admin_email'), $pass_change_email['message']); |
|
| 1816 | + $pass_change_email['message'] = str_replace('###EMAIL###', $user['user_email'], $pass_change_email['message']); |
|
| 1817 | + $pass_change_email['message'] = str_replace('###SITENAME###', $blog_name, $pass_change_email['message']); |
|
| 1818 | + $pass_change_email['message'] = str_replace('###SITEURL###', home_url(), $pass_change_email['message']); |
|
| 1819 | 1819 | |
| 1820 | - wp_mail( $pass_change_email['to'], sprintf( $pass_change_email['subject'], $blog_name ), $pass_change_email['message'], $pass_change_email['headers'] ); |
|
| 1820 | + wp_mail($pass_change_email['to'], sprintf($pass_change_email['subject'], $blog_name), $pass_change_email['message'], $pass_change_email['headers']); |
|
| 1821 | 1821 | } |
| 1822 | 1822 | |
| 1823 | - if ( ! empty( $send_email_change_email ) ) { |
|
| 1823 | + if ( ! empty($send_email_change_email)) { |
|
| 1824 | 1824 | /* translators: Do not translate USERNAME, ADMIN_EMAIL, EMAIL, SITENAME, SITEURL: those are placeholders. */ |
| 1825 | - $email_change_text = __( 'Hi ###USERNAME###, |
|
| 1825 | + $email_change_text = __('Hi ###USERNAME###, |
|
| 1826 | 1826 | |
| 1827 | 1827 | This notice confirms that your email was changed on ###SITENAME###. |
| 1828 | 1828 | |
@@ -1837,7 +1837,7 @@ discard block |
||
| 1837 | 1837 | |
| 1838 | 1838 | $email_change_email = array( |
| 1839 | 1839 | 'to' => $user['user_email'], |
| 1840 | - 'subject' => __( '[%s] Notice of Email Change' ), |
|
| 1840 | + 'subject' => __('[%s] Notice of Email Change'), |
|
| 1841 | 1841 | 'message' => $email_change_text, |
| 1842 | 1842 | 'headers' => '', |
| 1843 | 1843 | ); |
@@ -1863,32 +1863,32 @@ discard block |
||
| 1863 | 1863 | * @param array $user The original user array. |
| 1864 | 1864 | * @param array $userdata The updated user array. |
| 1865 | 1865 | */ |
| 1866 | - $email_change_email = apply_filters( 'email_change_email', $email_change_email, $user, $userdata ); |
|
| 1866 | + $email_change_email = apply_filters('email_change_email', $email_change_email, $user, $userdata); |
|
| 1867 | 1867 | |
| 1868 | - $email_change_email['message'] = str_replace( '###USERNAME###', $user['user_login'], $email_change_email['message'] ); |
|
| 1869 | - $email_change_email['message'] = str_replace( '###ADMIN_EMAIL###', get_option( 'admin_email' ), $email_change_email['message'] ); |
|
| 1870 | - $email_change_email['message'] = str_replace( '###EMAIL###', $user['user_email'], $email_change_email['message'] ); |
|
| 1871 | - $email_change_email['message'] = str_replace( '###SITENAME###', $blog_name, $email_change_email['message'] ); |
|
| 1872 | - $email_change_email['message'] = str_replace( '###SITEURL###', home_url(), $email_change_email['message'] ); |
|
| 1868 | + $email_change_email['message'] = str_replace('###USERNAME###', $user['user_login'], $email_change_email['message']); |
|
| 1869 | + $email_change_email['message'] = str_replace('###ADMIN_EMAIL###', get_option('admin_email'), $email_change_email['message']); |
|
| 1870 | + $email_change_email['message'] = str_replace('###EMAIL###', $user['user_email'], $email_change_email['message']); |
|
| 1871 | + $email_change_email['message'] = str_replace('###SITENAME###', $blog_name, $email_change_email['message']); |
|
| 1872 | + $email_change_email['message'] = str_replace('###SITEURL###', home_url(), $email_change_email['message']); |
|
| 1873 | 1873 | |
| 1874 | - wp_mail( $email_change_email['to'], sprintf( $email_change_email['subject'], $blog_name ), $email_change_email['message'], $email_change_email['headers'] ); |
|
| 1874 | + wp_mail($email_change_email['to'], sprintf($email_change_email['subject'], $blog_name), $email_change_email['message'], $email_change_email['headers']); |
|
| 1875 | 1875 | } |
| 1876 | 1876 | } |
| 1877 | 1877 | |
| 1878 | 1878 | // Update the cookies if the password changed. |
| 1879 | 1879 | $current_user = wp_get_current_user(); |
| 1880 | - if ( $current_user->ID == $ID ) { |
|
| 1881 | - if ( isset($plaintext_pass) ) { |
|
| 1880 | + if ($current_user->ID == $ID) { |
|
| 1881 | + if (isset($plaintext_pass)) { |
|
| 1882 | 1882 | wp_clear_auth_cookie(); |
| 1883 | 1883 | |
| 1884 | 1884 | // Here we calculate the expiration length of the current auth cookie and compare it to the default expiration. |
| 1885 | 1885 | // If it's greater than this, then we know the user checked 'Remember Me' when they logged in. |
| 1886 | - $logged_in_cookie = wp_parse_auth_cookie( '', 'logged_in' ); |
|
| 1886 | + $logged_in_cookie = wp_parse_auth_cookie('', 'logged_in'); |
|
| 1887 | 1887 | /** This filter is documented in wp-includes/pluggable.php */ |
| 1888 | - $default_cookie_life = apply_filters( 'auth_cookie_expiration', ( 2 * DAY_IN_SECONDS ), $ID, false ); |
|
| 1889 | - $remember = ( ( $logged_in_cookie['expiration'] - time() ) > $default_cookie_life ); |
|
| 1888 | + $default_cookie_life = apply_filters('auth_cookie_expiration', (2 * DAY_IN_SECONDS), $ID, false); |
|
| 1889 | + $remember = (($logged_in_cookie['expiration'] - time()) > $default_cookie_life); |
|
| 1890 | 1890 | |
| 1891 | - wp_set_auth_cookie( $ID, $remember ); |
|
| 1891 | + wp_set_auth_cookie($ID, $remember); |
|
| 1892 | 1892 | } |
| 1893 | 1893 | } |
| 1894 | 1894 | |
@@ -1911,8 +1911,8 @@ discard block |
||
| 1911 | 1911 | * be created. |
| 1912 | 1912 | */ |
| 1913 | 1913 | function wp_create_user($username, $password, $email = '') { |
| 1914 | - $user_login = wp_slash( $username ); |
|
| 1915 | - $user_email = wp_slash( $email ); |
|
| 1914 | + $user_login = wp_slash($username); |
|
| 1915 | + $user_email = wp_slash($email); |
|
| 1916 | 1916 | $user_pass = $password; |
| 1917 | 1917 | |
| 1918 | 1918 | $userdata = compact('user_login', 'user_email', 'user_pass'); |
@@ -1931,9 +1931,9 @@ discard block |
||
| 1931 | 1931 | * @param WP_User $user WP_User instance. |
| 1932 | 1932 | * @return array List of user keys to be populated in wp_update_user(). |
| 1933 | 1933 | */ |
| 1934 | -function _get_additional_user_keys( $user ) { |
|
| 1935 | - $keys = array( 'first_name', 'last_name', 'nickname', 'description', 'rich_editing', 'comment_shortcuts', 'admin_color', 'use_ssl', 'show_admin_bar_front' ); |
|
| 1936 | - return array_merge( $keys, array_keys( wp_get_user_contact_methods( $user ) ) ); |
|
| 1934 | +function _get_additional_user_keys($user) { |
|
| 1935 | + $keys = array('first_name', 'last_name', 'nickname', 'description', 'rich_editing', 'comment_shortcuts', 'admin_color', 'use_ssl', 'show_admin_bar_front'); |
|
| 1936 | + return array_merge($keys, array_keys(wp_get_user_contact_methods($user))); |
|
| 1937 | 1937 | } |
| 1938 | 1938 | |
| 1939 | 1939 | /** |
@@ -1946,13 +1946,13 @@ discard block |
||
| 1946 | 1946 | * @param WP_User $user Optional. WP_User object. |
| 1947 | 1947 | * @return array Array of contact methods and their labels. |
| 1948 | 1948 | */ |
| 1949 | -function wp_get_user_contact_methods( $user = null ) { |
|
| 1949 | +function wp_get_user_contact_methods($user = null) { |
|
| 1950 | 1950 | $methods = array(); |
| 1951 | - if ( get_site_option( 'initial_db_version' ) < 23588 ) { |
|
| 1951 | + if (get_site_option('initial_db_version') < 23588) { |
|
| 1952 | 1952 | $methods = array( |
| 1953 | - 'aim' => __( 'AIM' ), |
|
| 1954 | - 'yim' => __( 'Yahoo IM' ), |
|
| 1955 | - 'jabber' => __( 'Jabber / Google Talk' ) |
|
| 1953 | + 'aim' => __('AIM'), |
|
| 1954 | + 'yim' => __('Yahoo IM'), |
|
| 1955 | + 'jabber' => __('Jabber / Google Talk') |
|
| 1956 | 1956 | ); |
| 1957 | 1957 | } |
| 1958 | 1958 | |
@@ -1964,7 +1964,7 @@ discard block |
||
| 1964 | 1964 | * @param array $methods Array of contact methods and their labels. |
| 1965 | 1965 | * @param WP_User $user WP_User object. |
| 1966 | 1966 | */ |
| 1967 | - return apply_filters( 'user_contactmethods', $methods, $user ); |
|
| 1967 | + return apply_filters('user_contactmethods', $methods, $user); |
|
| 1968 | 1968 | } |
| 1969 | 1969 | |
| 1970 | 1970 | /** |
@@ -1978,8 +1978,8 @@ discard block |
||
| 1978 | 1978 | * @param WP_User $user Optional. WP_User object. Default null. |
| 1979 | 1979 | * @return array Array of contact methods and their labels. |
| 1980 | 1980 | */ |
| 1981 | -function _wp_get_user_contactmethods( $user = null ) { |
|
| 1982 | - return wp_get_user_contact_methods( $user ); |
|
| 1981 | +function _wp_get_user_contactmethods($user = null) { |
|
| 1982 | + return wp_get_user_contact_methods($user); |
|
| 1983 | 1983 | } |
| 1984 | 1984 | |
| 1985 | 1985 | /** |
@@ -1990,7 +1990,7 @@ discard block |
||
| 1990 | 1990 | * @return string The password hint text. |
| 1991 | 1991 | */ |
| 1992 | 1992 | function wp_get_password_hint() { |
| 1993 | - $hint = __( 'Hint: The password should be at least twelve characters long. To make it stronger, use upper and lower case letters, numbers, and symbols like ! " ? $ % ^ & ).' ); |
|
| 1993 | + $hint = __('Hint: The password should be at least twelve characters long. To make it stronger, use upper and lower case letters, numbers, and symbols like ! " ? $ % ^ & ).'); |
|
| 1994 | 1994 | |
| 1995 | 1995 | /** |
| 1996 | 1996 | * Filter the text describing the site's password complexity policy. |
@@ -1999,7 +1999,7 @@ discard block |
||
| 1999 | 1999 | * |
| 2000 | 2000 | * @param string $hint The password hint text. |
| 2001 | 2001 | */ |
| 2002 | - return apply_filters( 'password_hint', $hint ); |
|
| 2002 | + return apply_filters('password_hint', $hint); |
|
| 2003 | 2003 | } |
| 2004 | 2004 | |
| 2005 | 2005 | /** |
@@ -2014,7 +2014,7 @@ discard block |
||
| 2014 | 2014 | * |
| 2015 | 2015 | * @return string|WP_Error Password reset key on success. WP_Error on error. |
| 2016 | 2016 | */ |
| 2017 | -function get_password_reset_key( $user ) { |
|
| 2017 | +function get_password_reset_key($user) { |
|
| 2018 | 2018 | global $wpdb, $wp_hasher; |
| 2019 | 2019 | |
| 2020 | 2020 | /** |
@@ -2025,7 +2025,7 @@ discard block |
||
| 2025 | 2025 | * |
| 2026 | 2026 | * @param string $user_login The user login name. |
| 2027 | 2027 | */ |
| 2028 | - do_action( 'retreive_password', $user->user_login ); |
|
| 2028 | + do_action('retreive_password', $user->user_login); |
|
| 2029 | 2029 | |
| 2030 | 2030 | /** |
| 2031 | 2031 | * Fires before a new password is retrieved. |
@@ -2034,7 +2034,7 @@ discard block |
||
| 2034 | 2034 | * |
| 2035 | 2035 | * @param string $user_login The user login name. |
| 2036 | 2036 | */ |
| 2037 | - do_action( 'retrieve_password', $user->user_login ); |
|
| 2037 | + do_action('retrieve_password', $user->user_login); |
|
| 2038 | 2038 | |
| 2039 | 2039 | /** |
| 2040 | 2040 | * Filter whether to allow a password to be reset. |
@@ -2044,16 +2044,16 @@ discard block |
||
| 2044 | 2044 | * @param bool $allow Whether to allow the password to be reset. Default true. |
| 2045 | 2045 | * @param int $user_data->ID The ID of the user attempting to reset a password. |
| 2046 | 2046 | */ |
| 2047 | - $allow = apply_filters( 'allow_password_reset', true, $user->ID ); |
|
| 2047 | + $allow = apply_filters('allow_password_reset', true, $user->ID); |
|
| 2048 | 2048 | |
| 2049 | - if ( ! $allow ) { |
|
| 2050 | - return new WP_Error( 'no_password_reset', __( 'Password reset is not allowed for this user' ) ); |
|
| 2051 | - } elseif ( is_wp_error( $allow ) ) { |
|
| 2049 | + if ( ! $allow) { |
|
| 2050 | + return new WP_Error('no_password_reset', __('Password reset is not allowed for this user')); |
|
| 2051 | + } elseif (is_wp_error($allow)) { |
|
| 2052 | 2052 | return $allow; |
| 2053 | 2053 | } |
| 2054 | 2054 | |
| 2055 | 2055 | // Generate something random for a password reset key. |
| 2056 | - $key = wp_generate_password( 20, false ); |
|
| 2056 | + $key = wp_generate_password(20, false); |
|
| 2057 | 2057 | |
| 2058 | 2058 | /** |
| 2059 | 2059 | * Fires when a password reset key is generated. |
@@ -2063,17 +2063,17 @@ discard block |
||
| 2063 | 2063 | * @param string $user_login The username for the user. |
| 2064 | 2064 | * @param string $key The generated password reset key. |
| 2065 | 2065 | */ |
| 2066 | - do_action( 'retrieve_password_key', $user->user_login, $key ); |
|
| 2066 | + do_action('retrieve_password_key', $user->user_login, $key); |
|
| 2067 | 2067 | |
| 2068 | 2068 | // Now insert the key, hashed, into the DB. |
| 2069 | - if ( empty( $wp_hasher ) ) { |
|
| 2070 | - require_once ABSPATH . WPINC . '/class-phpass.php'; |
|
| 2071 | - $wp_hasher = new PasswordHash( 8, true ); |
|
| 2069 | + if (empty($wp_hasher)) { |
|
| 2070 | + require_once ABSPATH.WPINC.'/class-phpass.php'; |
|
| 2071 | + $wp_hasher = new PasswordHash(8, true); |
|
| 2072 | 2072 | } |
| 2073 | - $hashed = time() . ':' . $wp_hasher->HashPassword( $key ); |
|
| 2074 | - $key_saved = $wpdb->update( $wpdb->users, array( 'user_activation_key' => $hashed ), array( 'user_login' => $user->user_login ) ); |
|
| 2075 | - if ( false === $key_saved ) { |
|
| 2076 | - return new WP_Error( 'no_password_key_update', __( 'Could not save password reset key to database.' ) ); |
|
| 2073 | + $hashed = time().':'.$wp_hasher->HashPassword($key); |
|
| 2074 | + $key_saved = $wpdb->update($wpdb->users, array('user_activation_key' => $hashed), array('user_login' => $user->user_login)); |
|
| 2075 | + if (false === $key_saved) { |
|
| 2076 | + return new WP_Error('no_password_key_update', __('Could not save password reset key to database.')); |
|
| 2077 | 2077 | } |
| 2078 | 2078 | |
| 2079 | 2079 | return $key; |
@@ -2101,19 +2101,19 @@ discard block |
||
| 2101 | 2101 | |
| 2102 | 2102 | $key = preg_replace('/[^a-z0-9]/i', '', $key); |
| 2103 | 2103 | |
| 2104 | - if ( empty( $key ) || !is_string( $key ) ) |
|
| 2104 | + if (empty($key) || ! is_string($key)) |
|
| 2105 | 2105 | return new WP_Error('invalid_key', __('Invalid key')); |
| 2106 | 2106 | |
| 2107 | - if ( empty($login) || !is_string($login) ) |
|
| 2107 | + if (empty($login) || ! is_string($login)) |
|
| 2108 | 2108 | return new WP_Error('invalid_key', __('Invalid key')); |
| 2109 | 2109 | |
| 2110 | - $row = $wpdb->get_row( $wpdb->prepare( "SELECT ID, user_activation_key FROM $wpdb->users WHERE user_login = %s", $login ) ); |
|
| 2111 | - if ( ! $row ) |
|
| 2110 | + $row = $wpdb->get_row($wpdb->prepare("SELECT ID, user_activation_key FROM $wpdb->users WHERE user_login = %s", $login)); |
|
| 2111 | + if ( ! $row) |
|
| 2112 | 2112 | return new WP_Error('invalid_key', __('Invalid key')); |
| 2113 | 2113 | |
| 2114 | - if ( empty( $wp_hasher ) ) { |
|
| 2115 | - require_once ABSPATH . WPINC . '/class-phpass.php'; |
|
| 2116 | - $wp_hasher = new PasswordHash( 8, true ); |
|
| 2114 | + if (empty($wp_hasher)) { |
|
| 2115 | + require_once ABSPATH.WPINC.'/class-phpass.php'; |
|
| 2116 | + $wp_hasher = new PasswordHash(8, true); |
|
| 2117 | 2117 | } |
| 2118 | 2118 | |
| 2119 | 2119 | /** |
@@ -2123,31 +2123,31 @@ discard block |
||
| 2123 | 2123 | * |
| 2124 | 2124 | * @param int $expiration The expiration time in seconds. |
| 2125 | 2125 | */ |
| 2126 | - $expiration_duration = apply_filters( 'password_reset_expiration', DAY_IN_SECONDS ); |
|
| 2126 | + $expiration_duration = apply_filters('password_reset_expiration', DAY_IN_SECONDS); |
|
| 2127 | 2127 | |
| 2128 | - if ( false !== strpos( $row->user_activation_key, ':' ) ) { |
|
| 2129 | - list( $pass_request_time, $pass_key ) = explode( ':', $row->user_activation_key, 2 ); |
|
| 2128 | + if (false !== strpos($row->user_activation_key, ':')) { |
|
| 2129 | + list($pass_request_time, $pass_key) = explode(':', $row->user_activation_key, 2); |
|
| 2130 | 2130 | $expiration_time = $pass_request_time + $expiration_duration; |
| 2131 | 2131 | } else { |
| 2132 | 2132 | $pass_key = $row->user_activation_key; |
| 2133 | 2133 | $expiration_time = false; |
| 2134 | 2134 | } |
| 2135 | 2135 | |
| 2136 | - if ( ! $pass_key ) { |
|
| 2137 | - return new WP_Error( 'invalid_key', __( 'Invalid key' ) ); |
|
| 2136 | + if ( ! $pass_key) { |
|
| 2137 | + return new WP_Error('invalid_key', __('Invalid key')); |
|
| 2138 | 2138 | } |
| 2139 | 2139 | |
| 2140 | - $hash_is_correct = $wp_hasher->CheckPassword( $key, $pass_key ); |
|
| 2140 | + $hash_is_correct = $wp_hasher->CheckPassword($key, $pass_key); |
|
| 2141 | 2141 | |
| 2142 | - if ( $hash_is_correct && $expiration_time && time() < $expiration_time ) { |
|
| 2143 | - return get_userdata( $row->ID ); |
|
| 2144 | - } elseif ( $hash_is_correct && $expiration_time ) { |
|
| 2142 | + if ($hash_is_correct && $expiration_time && time() < $expiration_time) { |
|
| 2143 | + return get_userdata($row->ID); |
|
| 2144 | + } elseif ($hash_is_correct && $expiration_time) { |
|
| 2145 | 2145 | // Key has an expiration time that's passed |
| 2146 | - return new WP_Error( 'expired_key', __( 'Invalid key' ) ); |
|
| 2146 | + return new WP_Error('expired_key', __('Invalid key')); |
|
| 2147 | 2147 | } |
| 2148 | 2148 | |
| 2149 | - if ( hash_equals( $row->user_activation_key, $key ) || ( $hash_is_correct && ! $expiration_time ) ) { |
|
| 2150 | - $return = new WP_Error( 'expired_key', __( 'Invalid key' ) ); |
|
| 2149 | + if (hash_equals($row->user_activation_key, $key) || ($hash_is_correct && ! $expiration_time)) { |
|
| 2150 | + $return = new WP_Error('expired_key', __('Invalid key')); |
|
| 2151 | 2151 | $user_id = $row->ID; |
| 2152 | 2152 | |
| 2153 | 2153 | /** |
@@ -2161,10 +2161,10 @@ discard block |
||
| 2161 | 2161 | * Return a WP_User object to validate the key. |
| 2162 | 2162 | * @param int $user_id The matched user ID. |
| 2163 | 2163 | */ |
| 2164 | - return apply_filters( 'password_reset_key_expired', $return, $user_id ); |
|
| 2164 | + return apply_filters('password_reset_key_expired', $return, $user_id); |
|
| 2165 | 2165 | } |
| 2166 | 2166 | |
| 2167 | - return new WP_Error( 'invalid_key', __( 'Invalid key' ) ); |
|
| 2167 | + return new WP_Error('invalid_key', __('Invalid key')); |
|
| 2168 | 2168 | } |
| 2169 | 2169 | |
| 2170 | 2170 | /** |
@@ -2175,7 +2175,7 @@ discard block |
||
| 2175 | 2175 | * @param object $user The user |
| 2176 | 2176 | * @param string $new_pass New password for the user in plaintext |
| 2177 | 2177 | */ |
| 2178 | -function reset_password( $user, $new_pass ) { |
|
| 2178 | +function reset_password($user, $new_pass) { |
|
| 2179 | 2179 | /** |
| 2180 | 2180 | * Fires before the user's password is reset. |
| 2181 | 2181 | * |
@@ -2184,10 +2184,10 @@ discard block |
||
| 2184 | 2184 | * @param object $user The user. |
| 2185 | 2185 | * @param string $new_pass New user password. |
| 2186 | 2186 | */ |
| 2187 | - do_action( 'password_reset', $user, $new_pass ); |
|
| 2187 | + do_action('password_reset', $user, $new_pass); |
|
| 2188 | 2188 | |
| 2189 | - wp_set_password( $new_pass, $user->ID ); |
|
| 2190 | - update_user_option( $user->ID, 'default_password_nag', false, true ); |
|
| 2189 | + wp_set_password($new_pass, $user->ID); |
|
| 2190 | + update_user_option($user->ID, 'default_password_nag', false, true); |
|
| 2191 | 2191 | |
| 2192 | 2192 | /** |
| 2193 | 2193 | * Fires after the user's password is reset. |
@@ -2197,7 +2197,7 @@ discard block |
||
| 2197 | 2197 | * @param object $user The user. |
| 2198 | 2198 | * @param string $new_pass New user password. |
| 2199 | 2199 | */ |
| 2200 | - do_action( 'after_password_reset', $user, $new_pass ); |
|
| 2200 | + do_action('after_password_reset', $user, $new_pass); |
|
| 2201 | 2201 | } |
| 2202 | 2202 | |
| 2203 | 2203 | /** |
@@ -2209,10 +2209,10 @@ discard block |
||
| 2209 | 2209 | * @param string $user_email User's email address to send password and add |
| 2210 | 2210 | * @return int|WP_Error Either user's ID or error on failure. |
| 2211 | 2211 | */ |
| 2212 | -function register_new_user( $user_login, $user_email ) { |
|
| 2212 | +function register_new_user($user_login, $user_email) { |
|
| 2213 | 2213 | $errors = new WP_Error(); |
| 2214 | 2214 | |
| 2215 | - $sanitized_user_login = sanitize_user( $user_login ); |
|
| 2215 | + $sanitized_user_login = sanitize_user($user_login); |
|
| 2216 | 2216 | /** |
| 2217 | 2217 | * Filter the email address of a user being registered. |
| 2218 | 2218 | * |
@@ -2220,33 +2220,33 @@ discard block |
||
| 2220 | 2220 | * |
| 2221 | 2221 | * @param string $user_email The email address of the new user. |
| 2222 | 2222 | */ |
| 2223 | - $user_email = apply_filters( 'user_registration_email', $user_email ); |
|
| 2223 | + $user_email = apply_filters('user_registration_email', $user_email); |
|
| 2224 | 2224 | |
| 2225 | 2225 | // Check the username |
| 2226 | - if ( $sanitized_user_login == '' ) { |
|
| 2227 | - $errors->add( 'empty_username', __( '<strong>ERROR</strong>: Please enter a username.' ) ); |
|
| 2228 | - } elseif ( ! validate_username( $user_login ) ) { |
|
| 2229 | - $errors->add( 'invalid_username', __( '<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.' ) ); |
|
| 2226 | + if ($sanitized_user_login == '') { |
|
| 2227 | + $errors->add('empty_username', __('<strong>ERROR</strong>: Please enter a username.')); |
|
| 2228 | + } elseif ( ! validate_username($user_login)) { |
|
| 2229 | + $errors->add('invalid_username', __('<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.')); |
|
| 2230 | 2230 | $sanitized_user_login = ''; |
| 2231 | - } elseif ( username_exists( $sanitized_user_login ) ) { |
|
| 2232 | - $errors->add( 'username_exists', __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.' ) ); |
|
| 2231 | + } elseif (username_exists($sanitized_user_login)) { |
|
| 2232 | + $errors->add('username_exists', __('<strong>ERROR</strong>: This username is already registered. Please choose another one.')); |
|
| 2233 | 2233 | |
| 2234 | 2234 | } else { |
| 2235 | 2235 | /** This filter is documented in wp-includes/user.php */ |
| 2236 | - $illegal_user_logins = array_map( 'strtolower', (array) apply_filters( 'illegal_user_logins', array() ) ); |
|
| 2237 | - if ( in_array( strtolower( $sanitized_user_login ), $illegal_user_logins ) ) { |
|
| 2238 | - $errors->add( 'invalid_username', __( '<strong>ERROR</strong>: Sorry, that username is not allowed.' ) ); |
|
| 2236 | + $illegal_user_logins = array_map('strtolower', (array) apply_filters('illegal_user_logins', array())); |
|
| 2237 | + if (in_array(strtolower($sanitized_user_login), $illegal_user_logins)) { |
|
| 2238 | + $errors->add('invalid_username', __('<strong>ERROR</strong>: Sorry, that username is not allowed.')); |
|
| 2239 | 2239 | } |
| 2240 | 2240 | } |
| 2241 | 2241 | |
| 2242 | 2242 | // Check the email address |
| 2243 | - if ( $user_email == '' ) { |
|
| 2244 | - $errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please type your email address.' ) ); |
|
| 2245 | - } elseif ( ! is_email( $user_email ) ) { |
|
| 2246 | - $errors->add( 'invalid_email', __( '<strong>ERROR</strong>: The email address isn’t correct.' ) ); |
|
| 2243 | + if ($user_email == '') { |
|
| 2244 | + $errors->add('empty_email', __('<strong>ERROR</strong>: Please type your email address.')); |
|
| 2245 | + } elseif ( ! is_email($user_email)) { |
|
| 2246 | + $errors->add('invalid_email', __('<strong>ERROR</strong>: The email address isn’t correct.')); |
|
| 2247 | 2247 | $user_email = ''; |
| 2248 | - } elseif ( email_exists( $user_email ) ) { |
|
| 2249 | - $errors->add( 'email_exists', __( '<strong>ERROR</strong>: This email is already registered, please choose another one.' ) ); |
|
| 2248 | + } elseif (email_exists($user_email)) { |
|
| 2249 | + $errors->add('email_exists', __('<strong>ERROR</strong>: This email is already registered, please choose another one.')); |
|
| 2250 | 2250 | } |
| 2251 | 2251 | |
| 2252 | 2252 | /** |
@@ -2260,7 +2260,7 @@ discard block |
||
| 2260 | 2260 | * e.g., an empty field, an invalid username or email, |
| 2261 | 2261 | * or an existing username or email. |
| 2262 | 2262 | */ |
| 2263 | - do_action( 'register_post', $sanitized_user_login, $user_email, $errors ); |
|
| 2263 | + do_action('register_post', $sanitized_user_login, $user_email, $errors); |
|
| 2264 | 2264 | |
| 2265 | 2265 | /** |
| 2266 | 2266 | * Filter the errors encountered when a new user is being registered. |
@@ -2278,19 +2278,19 @@ discard block |
||
| 2278 | 2278 | * @param string $sanitized_user_login User's username after it has been sanitized. |
| 2279 | 2279 | * @param string $user_email User's email. |
| 2280 | 2280 | */ |
| 2281 | - $errors = apply_filters( 'registration_errors', $errors, $sanitized_user_login, $user_email ); |
|
| 2281 | + $errors = apply_filters('registration_errors', $errors, $sanitized_user_login, $user_email); |
|
| 2282 | 2282 | |
| 2283 | - if ( $errors->get_error_code() ) |
|
| 2283 | + if ($errors->get_error_code()) |
|
| 2284 | 2284 | return $errors; |
| 2285 | 2285 | |
| 2286 | - $user_pass = wp_generate_password( 12, false ); |
|
| 2287 | - $user_id = wp_create_user( $sanitized_user_login, $user_pass, $user_email ); |
|
| 2288 | - if ( ! $user_id || is_wp_error( $user_id ) ) { |
|
| 2289 | - $errors->add( 'registerfail', sprintf( __( '<strong>ERROR</strong>: Couldn’t register you… please contact the <a href="mailto:%s">webmaster</a> !' ), get_option( 'admin_email' ) ) ); |
|
| 2286 | + $user_pass = wp_generate_password(12, false); |
|
| 2287 | + $user_id = wp_create_user($sanitized_user_login, $user_pass, $user_email); |
|
| 2288 | + if ( ! $user_id || is_wp_error($user_id)) { |
|
| 2289 | + $errors->add('registerfail', sprintf(__('<strong>ERROR</strong>: Couldn’t register you… please contact the <a href="mailto:%s">webmaster</a> !'), get_option('admin_email'))); |
|
| 2290 | 2290 | return $errors; |
| 2291 | 2291 | } |
| 2292 | 2292 | |
| 2293 | - update_user_option( $user_id, 'default_password_nag', true, true ); //Set up the Password change nag. |
|
| 2293 | + update_user_option($user_id, 'default_password_nag', true, true); //Set up the Password change nag. |
|
| 2294 | 2294 | |
| 2295 | 2295 | /** |
| 2296 | 2296 | * Fires after a new user registration has been recorded. |
@@ -2299,7 +2299,7 @@ discard block |
||
| 2299 | 2299 | * |
| 2300 | 2300 | * @param int $user_id ID of the newly registered user. |
| 2301 | 2301 | */ |
| 2302 | - do_action( 'register_new_user', $user_id ); |
|
| 2302 | + do_action('register_new_user', $user_id); |
|
| 2303 | 2303 | |
| 2304 | 2304 | return $user_id; |
| 2305 | 2305 | } |
@@ -2315,8 +2315,8 @@ discard block |
||
| 2315 | 2315 | * @param string $notify Optional. Type of notification that should happen. Accepts 'admin' or an empty string |
| 2316 | 2316 | * (admin only), or 'both' (admin and user). Default 'both'. |
| 2317 | 2317 | */ |
| 2318 | -function wp_send_new_user_notifications( $user_id, $notify = 'both' ) { |
|
| 2319 | - wp_new_user_notification( $user_id, null, $notify ); |
|
| 2318 | +function wp_send_new_user_notifications($user_id, $notify = 'both') { |
|
| 2319 | + wp_new_user_notification($user_id, null, $notify); |
|
| 2320 | 2320 | } |
| 2321 | 2321 | |
| 2322 | 2322 | /** |
@@ -2327,8 +2327,8 @@ discard block |
||
| 2327 | 2327 | * @return string Token. |
| 2328 | 2328 | */ |
| 2329 | 2329 | function wp_get_session_token() { |
| 2330 | - $cookie = wp_parse_auth_cookie( '', 'logged_in' ); |
|
| 2331 | - return ! empty( $cookie['token'] ) ? $cookie['token'] : ''; |
|
| 2330 | + $cookie = wp_parse_auth_cookie('', 'logged_in'); |
|
| 2331 | + return ! empty($cookie['token']) ? $cookie['token'] : ''; |
|
| 2332 | 2332 | } |
| 2333 | 2333 | |
| 2334 | 2334 | /** |
@@ -2338,7 +2338,7 @@ discard block |
||
| 2338 | 2338 | * @return array Array of sessions. |
| 2339 | 2339 | */ |
| 2340 | 2340 | function wp_get_all_sessions() { |
| 2341 | - $manager = WP_Session_Tokens::get_instance( get_current_user_id() ); |
|
| 2341 | + $manager = WP_Session_Tokens::get_instance(get_current_user_id()); |
|
| 2342 | 2342 | return $manager->get_all(); |
| 2343 | 2343 | } |
| 2344 | 2344 | |
@@ -2349,9 +2349,9 @@ discard block |
||
| 2349 | 2349 | */ |
| 2350 | 2350 | function wp_destroy_current_session() { |
| 2351 | 2351 | $token = wp_get_session_token(); |
| 2352 | - if ( $token ) { |
|
| 2353 | - $manager = WP_Session_Tokens::get_instance( get_current_user_id() ); |
|
| 2354 | - $manager->destroy( $token ); |
|
| 2352 | + if ($token) { |
|
| 2353 | + $manager = WP_Session_Tokens::get_instance(get_current_user_id()); |
|
| 2354 | + $manager->destroy($token); |
|
| 2355 | 2355 | } |
| 2356 | 2356 | } |
| 2357 | 2357 | |
@@ -2362,9 +2362,9 @@ discard block |
||
| 2362 | 2362 | */ |
| 2363 | 2363 | function wp_destroy_other_sessions() { |
| 2364 | 2364 | $token = wp_get_session_token(); |
| 2365 | - if ( $token ) { |
|
| 2366 | - $manager = WP_Session_Tokens::get_instance( get_current_user_id() ); |
|
| 2367 | - $manager->destroy_others( $token ); |
|
| 2365 | + if ($token) { |
|
| 2366 | + $manager = WP_Session_Tokens::get_instance(get_current_user_id()); |
|
| 2367 | + $manager->destroy_others($token); |
|
| 2368 | 2368 | } |
| 2369 | 2369 | } |
| 2370 | 2370 | |
@@ -2374,7 +2374,7 @@ discard block |
||
| 2374 | 2374 | * @since 4.0.0 |
| 2375 | 2375 | */ |
| 2376 | 2376 | function wp_destroy_all_sessions() { |
| 2377 | - $manager = WP_Session_Tokens::get_instance( get_current_user_id() ); |
|
| 2377 | + $manager = WP_Session_Tokens::get_instance(get_current_user_id()); |
|
| 2378 | 2378 | $manager->destroy_all(); |
| 2379 | 2379 | } |
| 2380 | 2380 | |
@@ -2390,19 +2390,19 @@ discard block |
||
| 2390 | 2390 | function wp_get_users_with_no_role() { |
| 2391 | 2391 | global $wpdb; |
| 2392 | 2392 | |
| 2393 | - if ( is_multisite() ) { |
|
| 2393 | + if (is_multisite()) { |
|
| 2394 | 2394 | return array(); |
| 2395 | 2395 | } |
| 2396 | 2396 | |
| 2397 | 2397 | $prefix = $wpdb->get_blog_prefix(); |
| 2398 | - $regex = implode( '|', wp_roles()->get_names() ); |
|
| 2399 | - $regex = preg_replace( '/[^a-zA-Z_\|-]/', '', $regex ); |
|
| 2400 | - $users = $wpdb->get_col( $wpdb->prepare( " |
|
| 2398 | + $regex = implode('|', wp_roles()->get_names()); |
|
| 2399 | + $regex = preg_replace('/[^a-zA-Z_\|-]/', '', $regex); |
|
| 2400 | + $users = $wpdb->get_col($wpdb->prepare(" |
|
| 2401 | 2401 | SELECT user_id |
| 2402 | 2402 | FROM $wpdb->usermeta |
| 2403 | 2403 | WHERE meta_key = '{$prefix}capabilities' |
| 2404 | 2404 | AND meta_value NOT REGEXP %s |
| 2405 | - ", $regex ) ); |
|
| 2405 | + ", $regex)); |
|
| 2406 | 2406 | |
| 2407 | 2407 | return $users; |
| 2408 | 2408 | } |
@@ -2429,27 +2429,27 @@ discard block |
||
| 2429 | 2429 | function _wp_get_current_user() { |
| 2430 | 2430 | global $current_user; |
| 2431 | 2431 | |
| 2432 | - if ( ! empty( $current_user ) ) { |
|
| 2433 | - if ( $current_user instanceof WP_User ) { |
|
| 2432 | + if ( ! empty($current_user)) { |
|
| 2433 | + if ($current_user instanceof WP_User) { |
|
| 2434 | 2434 | return $current_user; |
| 2435 | 2435 | } |
| 2436 | 2436 | |
| 2437 | 2437 | // Upgrade stdClass to WP_User |
| 2438 | - if ( is_object( $current_user ) && isset( $current_user->ID ) ) { |
|
| 2438 | + if (is_object($current_user) && isset($current_user->ID)) { |
|
| 2439 | 2439 | $cur_id = $current_user->ID; |
| 2440 | 2440 | $current_user = null; |
| 2441 | - wp_set_current_user( $cur_id ); |
|
| 2441 | + wp_set_current_user($cur_id); |
|
| 2442 | 2442 | return $current_user; |
| 2443 | 2443 | } |
| 2444 | 2444 | |
| 2445 | 2445 | // $current_user has a junk value. Force to WP_User with ID 0. |
| 2446 | 2446 | $current_user = null; |
| 2447 | - wp_set_current_user( 0 ); |
|
| 2447 | + wp_set_current_user(0); |
|
| 2448 | 2448 | return $current_user; |
| 2449 | 2449 | } |
| 2450 | 2450 | |
| 2451 | - if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST ) { |
|
| 2452 | - wp_set_current_user( 0 ); |
|
| 2451 | + if (defined('XMLRPC_REQUEST') && XMLRPC_REQUEST) { |
|
| 2452 | + wp_set_current_user(0); |
|
| 2453 | 2453 | return $current_user; |
| 2454 | 2454 | } |
| 2455 | 2455 | |
@@ -2466,13 +2466,13 @@ discard block |
||
| 2466 | 2466 | * |
| 2467 | 2467 | * @param int|bool $user_id User ID if one has been determined, false otherwise. |
| 2468 | 2468 | */ |
| 2469 | - $user_id = apply_filters( 'determine_current_user', false ); |
|
| 2470 | - if ( ! $user_id ) { |
|
| 2471 | - wp_set_current_user( 0 ); |
|
| 2469 | + $user_id = apply_filters('determine_current_user', false); |
|
| 2470 | + if ( ! $user_id) { |
|
| 2471 | + wp_set_current_user(0); |
|
| 2472 | 2472 | return $current_user; |
| 2473 | 2473 | } |
| 2474 | 2474 | |
| 2475 | - wp_set_current_user( $user_id ); |
|
| 2475 | + wp_set_current_user($user_id); |
|
| 2476 | 2476 | |
| 2477 | 2477 | return $current_user; |
| 2478 | 2478 | } |
@@ -27,18 +27,22 @@ discard block |
||
| 27 | 27 | */ |
| 28 | 28 | function wp_signon( $credentials = array(), $secure_cookie = '' ) { |
| 29 | 29 | if ( empty($credentials) ) { |
| 30 | - if ( ! empty($_POST['log']) ) |
|
| 31 | - $credentials['user_login'] = $_POST['log']; |
|
| 32 | - if ( ! empty($_POST['pwd']) ) |
|
| 33 | - $credentials['user_password'] = $_POST['pwd']; |
|
| 34 | - if ( ! empty($_POST['rememberme']) ) |
|
| 35 | - $credentials['remember'] = $_POST['rememberme']; |
|
| 30 | + if ( ! empty($_POST['log']) ) { |
|
| 31 | + $credentials['user_login'] = $_POST['log']; |
|
| 32 | + } |
|
| 33 | + if ( ! empty($_POST['pwd']) ) { |
|
| 34 | + $credentials['user_password'] = $_POST['pwd']; |
|
| 35 | + } |
|
| 36 | + if ( ! empty($_POST['rememberme']) ) { |
|
| 37 | + $credentials['remember'] = $_POST['rememberme']; |
|
| 38 | + } |
|
| 36 | 39 | } |
| 37 | 40 | |
| 38 | - if ( !empty($credentials['remember']) ) |
|
| 39 | - $credentials['remember'] = true; |
|
| 40 | - else |
|
| 41 | - $credentials['remember'] = false; |
|
| 41 | + if ( !empty($credentials['remember']) ) { |
|
| 42 | + $credentials['remember'] = true; |
|
| 43 | + } else { |
|
| 44 | + $credentials['remember'] = false; |
|
| 45 | + } |
|
| 42 | 46 | |
| 43 | 47 | /** |
| 44 | 48 | * Fires before the user is authenticated. |
@@ -55,8 +59,9 @@ discard block |
||
| 55 | 59 | */ |
| 56 | 60 | do_action_ref_array( 'wp_authenticate', array( &$credentials['user_login'], &$credentials['user_password'] ) ); |
| 57 | 61 | |
| 58 | - if ( '' === $secure_cookie ) |
|
| 59 | - $secure_cookie = is_ssl(); |
|
| 62 | + if ( '' === $secure_cookie ) { |
|
| 63 | + $secure_cookie = is_ssl(); |
|
| 64 | + } |
|
| 60 | 65 | |
| 61 | 66 | /** |
| 62 | 67 | * Filter whether to use a secure sign-on cookie. |
@@ -119,16 +124,19 @@ discard block |
||
| 119 | 124 | } |
| 120 | 125 | |
| 121 | 126 | if ( empty($username) || empty($password) ) { |
| 122 | - if ( is_wp_error( $user ) ) |
|
| 123 | - return $user; |
|
| 127 | + if ( is_wp_error( $user ) ) { |
|
| 128 | + return $user; |
|
| 129 | + } |
|
| 124 | 130 | |
| 125 | 131 | $error = new WP_Error(); |
| 126 | 132 | |
| 127 | - if ( empty($username) ) |
|
| 128 | - $error->add('empty_username', __('<strong>ERROR</strong>: The username field is empty.')); |
|
| 133 | + if ( empty($username) ) { |
|
| 134 | + $error->add('empty_username', __('<strong>ERROR</strong>: The username field is empty.')); |
|
| 135 | + } |
|
| 129 | 136 | |
| 130 | - if ( empty($password) ) |
|
| 131 | - $error->add('empty_password', __('<strong>ERROR</strong>: The password field is empty.')); |
|
| 137 | + if ( empty($password) ) { |
|
| 138 | + $error->add('empty_password', __('<strong>ERROR</strong>: The password field is empty.')); |
|
| 139 | + } |
|
| 132 | 140 | |
| 133 | 141 | return $error; |
| 134 | 142 | } |
@@ -154,8 +162,9 @@ discard block |
||
| 154 | 162 | * @param string $password Password to check against the user. |
| 155 | 163 | */ |
| 156 | 164 | $user = apply_filters( 'wp_authenticate_user', $user, $password ); |
| 157 | - if ( is_wp_error($user) ) |
|
| 158 | - return $user; |
|
| 165 | + if ( is_wp_error($user) ) { |
|
| 166 | + return $user; |
|
| 167 | + } |
|
| 159 | 168 | |
| 160 | 169 | if ( ! wp_check_password( $password, $user->user_pass, $user->ID ) ) { |
| 161 | 170 | return new WP_Error( 'incorrect_password', |
@@ -264,18 +273,21 @@ discard block |
||
| 264 | 273 | |
| 265 | 274 | if ( empty($username) && empty($password) ) { |
| 266 | 275 | $user_id = wp_validate_auth_cookie(); |
| 267 | - if ( $user_id ) |
|
| 268 | - return new WP_User($user_id); |
|
| 276 | + if ( $user_id ) { |
|
| 277 | + return new WP_User($user_id); |
|
| 278 | + } |
|
| 269 | 279 | |
| 270 | 280 | global $auth_secure_cookie; |
| 271 | 281 | |
| 272 | - if ( $auth_secure_cookie ) |
|
| 273 | - $auth_cookie = SECURE_AUTH_COOKIE; |
|
| 274 | - else |
|
| 275 | - $auth_cookie = AUTH_COOKIE; |
|
| 282 | + if ( $auth_secure_cookie ) { |
|
| 283 | + $auth_cookie = SECURE_AUTH_COOKIE; |
|
| 284 | + } else { |
|
| 285 | + $auth_cookie = AUTH_COOKIE; |
|
| 286 | + } |
|
| 276 | 287 | |
| 277 | - if ( !empty($_COOKIE[$auth_cookie]) ) |
|
| 278 | - return new WP_Error('expired_session', __('Please log in again.')); |
|
| 288 | + if ( !empty($_COOKIE[$auth_cookie]) ) { |
|
| 289 | + return new WP_Error('expired_session', __('Please log in again.')); |
|
| 290 | + } |
|
| 279 | 291 | |
| 280 | 292 | // If the cookie is not set, be silent. |
| 281 | 293 | } |
@@ -304,8 +316,9 @@ discard block |
||
| 304 | 316 | */ |
| 305 | 317 | $spammed = apply_filters( 'check_is_user_spammed', is_user_spammy(), $user ); |
| 306 | 318 | |
| 307 | - if ( $spammed ) |
|
| 308 | - return new WP_Error( 'spammer_account', __( '<strong>ERROR</strong>: Your account has been marked as a spammer.' ) ); |
|
| 319 | + if ( $spammed ) { |
|
| 320 | + return new WP_Error( 'spammer_account', __( '<strong>ERROR</strong>: Your account has been marked as a spammer.' ) ); |
|
| 321 | + } |
|
| 309 | 322 | } |
| 310 | 323 | return $user; |
| 311 | 324 | } |
@@ -390,8 +403,9 @@ discard block |
||
| 390 | 403 | global $wpdb; |
| 391 | 404 | |
| 392 | 405 | $count = array(); |
| 393 | - if ( empty( $users ) || ! is_array( $users ) ) |
|
| 394 | - return $count; |
|
| 406 | + if ( empty( $users ) || ! is_array( $users ) ) { |
|
| 407 | + return $count; |
|
| 408 | + } |
|
| 395 | 409 | |
| 396 | 410 | $userlist = implode( ',', array_map( 'absint', $users ) ); |
| 397 | 411 | $where = get_posts_by_author_sql( $post_type, true, null, $public_only ); |
@@ -402,8 +416,9 @@ discard block |
||
| 402 | 416 | } |
| 403 | 417 | |
| 404 | 418 | foreach ( $users as $id ) { |
| 405 | - if ( ! isset( $count[ $id ] ) ) |
|
| 406 | - $count[ $id ] = 0; |
|
| 419 | + if ( ! isset( $count[ $id ] ) ) { |
|
| 420 | + $count[ $id ] = 0; |
|
| 421 | + } |
|
| 407 | 422 | } |
| 408 | 423 | |
| 409 | 424 | return $count; |
@@ -421,8 +436,9 @@ discard block |
||
| 421 | 436 | * @return int The current user's ID |
| 422 | 437 | */ |
| 423 | 438 | function get_current_user_id() { |
| 424 | - if ( ! function_exists( 'wp_get_current_user' ) ) |
|
| 425 | - return 0; |
|
| 439 | + if ( ! function_exists( 'wp_get_current_user' ) ) { |
|
| 440 | + return 0; |
|
| 441 | + } |
|
| 426 | 442 | $user = wp_get_current_user(); |
| 427 | 443 | return ( isset( $user->ID ) ? (int) $user->ID : 0 ); |
| 428 | 444 | } |
@@ -449,22 +465,28 @@ discard block |
||
| 449 | 465 | function get_user_option( $option, $user = 0, $deprecated = '' ) { |
| 450 | 466 | global $wpdb; |
| 451 | 467 | |
| 452 | - if ( !empty( $deprecated ) ) |
|
| 453 | - _deprecated_argument( __FUNCTION__, '3.0' ); |
|
| 468 | + if ( !empty( $deprecated ) ) { |
|
| 469 | + _deprecated_argument( __FUNCTION__, '3.0' ); |
|
| 470 | + } |
|
| 454 | 471 | |
| 455 | - if ( empty( $user ) ) |
|
| 456 | - $user = get_current_user_id(); |
|
| 472 | + if ( empty( $user ) ) { |
|
| 473 | + $user = get_current_user_id(); |
|
| 474 | + } |
|
| 457 | 475 | |
| 458 | - if ( ! $user = get_userdata( $user ) ) |
|
| 459 | - return false; |
|
| 476 | + if ( ! $user = get_userdata( $user ) ) { |
|
| 477 | + return false; |
|
| 478 | + } |
|
| 460 | 479 | |
| 461 | 480 | $prefix = $wpdb->get_blog_prefix(); |
| 462 | - if ( $user->has_prop( $prefix . $option ) ) // Blog specific |
|
| 481 | + if ( $user->has_prop( $prefix . $option ) ) { |
|
| 482 | + // Blog specific |
|
| 463 | 483 | $result = $user->get( $prefix . $option ); |
| 464 | - elseif ( $user->has_prop( $option ) ) // User specific and cross-blog |
|
| 484 | + } elseif ( $user->has_prop( $option ) ) { |
|
| 485 | + // User specific and cross-blog |
|
| 465 | 486 | $result = $user->get( $option ); |
| 466 | - else |
|
| 467 | - $result = false; |
|
| 487 | + } else { |
|
| 488 | + $result = false; |
|
| 489 | + } |
|
| 468 | 490 | |
| 469 | 491 | /** |
| 470 | 492 | * Filter a specific user option value. |
@@ -504,8 +526,9 @@ discard block |
||
| 504 | 526 | function update_user_option( $user_id, $option_name, $newvalue, $global = false ) { |
| 505 | 527 | global $wpdb; |
| 506 | 528 | |
| 507 | - if ( !$global ) |
|
| 508 | - $option_name = $wpdb->get_blog_prefix() . $option_name; |
|
| 529 | + if ( !$global ) { |
|
| 530 | + $option_name = $wpdb->get_blog_prefix() . $option_name; |
|
| 531 | + } |
|
| 509 | 532 | |
| 510 | 533 | return update_user_meta( $user_id, $option_name, $newvalue ); |
| 511 | 534 | } |
@@ -530,8 +553,9 @@ discard block |
||
| 530 | 553 | function delete_user_option( $user_id, $option_name, $global = false ) { |
| 531 | 554 | global $wpdb; |
| 532 | 555 | |
| 533 | - if ( !$global ) |
|
| 534 | - $option_name = $wpdb->get_blog_prefix() . $option_name; |
|
| 556 | + if ( !$global ) { |
|
| 557 | + $option_name = $wpdb->get_blog_prefix() . $option_name; |
|
| 558 | + } |
|
| 535 | 559 | return delete_user_meta( $user_id, $option_name ); |
| 536 | 560 | } |
| 537 | 561 | |
@@ -575,12 +599,14 @@ discard block |
||
| 575 | 599 | $user_id = (int) $user_id; |
| 576 | 600 | |
| 577 | 601 | // Logged out users can't have blogs |
| 578 | - if ( empty( $user_id ) ) |
|
| 579 | - return array(); |
|
| 602 | + if ( empty( $user_id ) ) { |
|
| 603 | + return array(); |
|
| 604 | + } |
|
| 580 | 605 | |
| 581 | 606 | $keys = get_user_meta( $user_id ); |
| 582 | - if ( empty( $keys ) ) |
|
| 583 | - return array(); |
|
| 607 | + if ( empty( $keys ) ) { |
|
| 608 | + return array(); |
|
| 609 | + } |
|
| 584 | 610 | |
| 585 | 611 | if ( ! is_multisite() ) { |
| 586 | 612 | $blog_id = get_current_blog_id(); |
@@ -621,13 +647,16 @@ discard block |
||
| 621 | 647 | $keys = array_keys( $keys ); |
| 622 | 648 | |
| 623 | 649 | foreach ( $keys as $key ) { |
| 624 | - if ( 'capabilities' !== substr( $key, -12 ) ) |
|
| 625 | - continue; |
|
| 626 | - if ( $wpdb->base_prefix && 0 !== strpos( $key, $wpdb->base_prefix ) ) |
|
| 627 | - continue; |
|
| 650 | + if ( 'capabilities' !== substr( $key, -12 ) ) { |
|
| 651 | + continue; |
|
| 652 | + } |
|
| 653 | + if ( $wpdb->base_prefix && 0 !== strpos( $key, $wpdb->base_prefix ) ) { |
|
| 654 | + continue; |
|
| 655 | + } |
|
| 628 | 656 | $blog_id = str_replace( array( $wpdb->base_prefix, '_capabilities' ), '', $key ); |
| 629 | - if ( ! is_numeric( $blog_id ) ) |
|
| 630 | - continue; |
|
| 657 | + if ( ! is_numeric( $blog_id ) ) { |
|
| 658 | + continue; |
|
| 659 | + } |
|
| 631 | 660 | |
| 632 | 661 | $blog_id = (int) $blog_id; |
| 633 | 662 | $blog = get_blog_details( $blog_id ); |
@@ -861,8 +890,9 @@ discard block |
||
| 861 | 890 | |
| 862 | 891 | foreach ( $users_of_blog as $caps_meta ) { |
| 863 | 892 | $b_roles = maybe_unserialize($caps_meta); |
| 864 | - if ( ! is_array( $b_roles ) ) |
|
| 865 | - continue; |
|
| 893 | + if ( ! is_array( $b_roles ) ) { |
|
| 894 | + continue; |
|
| 895 | + } |
|
| 866 | 896 | if ( empty( $b_roles ) ) { |
| 867 | 897 | $avail_roles['none']++; |
| 868 | 898 | } |
@@ -910,8 +940,9 @@ discard block |
||
| 910 | 940 | function setup_userdata($for_user_id = '') { |
| 911 | 941 | global $user_login, $userdata, $user_level, $user_ID, $user_email, $user_url, $user_identity; |
| 912 | 942 | |
| 913 | - if ( '' == $for_user_id ) |
|
| 914 | - $for_user_id = get_current_user_id(); |
|
| 943 | + if ( '' == $for_user_id ) { |
|
| 944 | + $for_user_id = get_current_user_id(); |
|
| 945 | + } |
|
| 915 | 946 | $user = get_userdata( $for_user_id ); |
| 916 | 947 | |
| 917 | 948 | if ( ! $user ) { |
@@ -1116,14 +1147,17 @@ discard block |
||
| 1116 | 1147 | */ |
| 1117 | 1148 | function sanitize_user_field($field, $value, $user_id, $context) { |
| 1118 | 1149 | $int_fields = array('ID'); |
| 1119 | - if ( in_array($field, $int_fields) ) |
|
| 1120 | - $value = (int) $value; |
|
| 1150 | + if ( in_array($field, $int_fields) ) { |
|
| 1151 | + $value = (int) $value; |
|
| 1152 | + } |
|
| 1121 | 1153 | |
| 1122 | - if ( 'raw' == $context ) |
|
| 1123 | - return $value; |
|
| 1154 | + if ( 'raw' == $context ) { |
|
| 1155 | + return $value; |
|
| 1156 | + } |
|
| 1124 | 1157 | |
| 1125 | - if ( !is_string($value) && !is_numeric($value) ) |
|
| 1126 | - return $value; |
|
| 1158 | + if ( !is_string($value) && !is_numeric($value) ) { |
|
| 1159 | + return $value; |
|
| 1160 | + } |
|
| 1127 | 1161 | |
| 1128 | 1162 | $prefixed = false !== strpos( $field, 'user_' ); |
| 1129 | 1163 | |
@@ -1148,10 +1182,13 @@ discard block |
||
| 1148 | 1182 | $value = apply_filters( "edit_user_{$field}", $value, $user_id ); |
| 1149 | 1183 | } |
| 1150 | 1184 | |
| 1151 | - if ( 'description' == $field ) |
|
| 1152 | - $value = esc_html( $value ); // textarea_escaped? |
|
| 1153 | - else |
|
| 1154 | - $value = esc_attr($value); |
|
| 1185 | + if ( 'description' == $field ) { |
|
| 1186 | + $value = esc_html( $value ); |
|
| 1187 | + } |
|
| 1188 | + // textarea_escaped? |
|
| 1189 | + else { |
|
| 1190 | + $value = esc_attr($value); |
|
| 1191 | + } |
|
| 1155 | 1192 | } elseif ( 'db' == $context ) { |
| 1156 | 1193 | if ( $prefixed ) { |
| 1157 | 1194 | /** This filter is documented in wp-includes/post.php */ |
@@ -1194,8 +1231,9 @@ discard block |
||
| 1194 | 1231 | } |
| 1195 | 1232 | } |
| 1196 | 1233 | |
| 1197 | - if ( 'user_url' == $field ) |
|
| 1198 | - $value = esc_url($value); |
|
| 1234 | + if ( 'user_url' == $field ) { |
|
| 1235 | + $value = esc_url($value); |
|
| 1236 | + } |
|
| 1199 | 1237 | |
| 1200 | 1238 | if ( 'attribute' == $context ) { |
| 1201 | 1239 | $value = esc_attr( $value ); |
@@ -1237,11 +1275,13 @@ discard block |
||
| 1237 | 1275 | * @param WP_User|int $user User object or ID to be cleaned from the cache |
| 1238 | 1276 | */ |
| 1239 | 1277 | function clean_user_cache( $user ) { |
| 1240 | - if ( is_numeric( $user ) ) |
|
| 1241 | - $user = new WP_User( $user ); |
|
| 1278 | + if ( is_numeric( $user ) ) { |
|
| 1279 | + $user = new WP_User( $user ); |
|
| 1280 | + } |
|
| 1242 | 1281 | |
| 1243 | - if ( ! $user->exists() ) |
|
| 1244 | - return; |
|
| 1282 | + if ( ! $user->exists() ) { |
|
| 1283 | + return; |
|
| 1284 | + } |
|
| 1245 | 1285 | |
| 1246 | 1286 | wp_cache_delete( $user->ID, 'users' ); |
| 1247 | 1287 | wp_cache_delete( $user->user_login, 'userlogins' ); |
@@ -2101,15 +2141,18 @@ discard block |
||
| 2101 | 2141 | |
| 2102 | 2142 | $key = preg_replace('/[^a-z0-9]/i', '', $key); |
| 2103 | 2143 | |
| 2104 | - if ( empty( $key ) || !is_string( $key ) ) |
|
| 2105 | - return new WP_Error('invalid_key', __('Invalid key')); |
|
| 2144 | + if ( empty( $key ) || !is_string( $key ) ) { |
|
| 2145 | + return new WP_Error('invalid_key', __('Invalid key')); |
|
| 2146 | + } |
|
| 2106 | 2147 | |
| 2107 | - if ( empty($login) || !is_string($login) ) |
|
| 2108 | - return new WP_Error('invalid_key', __('Invalid key')); |
|
| 2148 | + if ( empty($login) || !is_string($login) ) { |
|
| 2149 | + return new WP_Error('invalid_key', __('Invalid key')); |
|
| 2150 | + } |
|
| 2109 | 2151 | |
| 2110 | 2152 | $row = $wpdb->get_row( $wpdb->prepare( "SELECT ID, user_activation_key FROM $wpdb->users WHERE user_login = %s", $login ) ); |
| 2111 | - if ( ! $row ) |
|
| 2112 | - return new WP_Error('invalid_key', __('Invalid key')); |
|
| 2153 | + if ( ! $row ) { |
|
| 2154 | + return new WP_Error('invalid_key', __('Invalid key')); |
|
| 2155 | + } |
|
| 2113 | 2156 | |
| 2114 | 2157 | if ( empty( $wp_hasher ) ) { |
| 2115 | 2158 | require_once ABSPATH . WPINC . '/class-phpass.php'; |
@@ -2280,8 +2323,9 @@ discard block |
||
| 2280 | 2323 | */ |
| 2281 | 2324 | $errors = apply_filters( 'registration_errors', $errors, $sanitized_user_login, $user_email ); |
| 2282 | 2325 | |
| 2283 | - if ( $errors->get_error_code() ) |
|
| 2284 | - return $errors; |
|
| 2326 | + if ( $errors->get_error_code() ) { |
|
| 2327 | + return $errors; |
|
| 2328 | + } |
|
| 2285 | 2329 | |
| 2286 | 2330 | $user_pass = wp_generate_password( 12, false ); |
| 2287 | 2331 | $user_id = wp_create_user( $sanitized_user_login, $user_pass, $user_email ); |
@@ -663,7 +663,7 @@ discard block |
||
| 663 | 663 | * |
| 664 | 664 | * @see wpdb::__construct() |
| 665 | 665 | * @since 2.0.8 |
| 666 | - * @return true |
|
| 666 | + * @return boolean |
|
| 667 | 667 | */ |
| 668 | 668 | public function __destruct() { |
| 669 | 669 | return true; |
@@ -1239,8 +1239,6 @@ discard block |
||
| 1239 | 1239 | * @param array|mixed $args The array of variables to substitute into the query's placeholders if being called like |
| 1240 | 1240 | * {@link http://php.net/vsprintf vsprintf()}, or the first variable to substitute into the query's placeholders if |
| 1241 | 1241 | * being called like {@link http://php.net/sprintf sprintf()}. |
| 1242 | - * @param mixed $args,... further variables to substitute into the query's placeholders if being called like |
|
| 1243 | - * {@link http://php.net/sprintf sprintf()}. |
|
| 1244 | 1242 | * @return string|void Sanitized query string, if there is a query to prepare. |
| 1245 | 1243 | */ |
| 1246 | 1244 | public function prepare( $query, $args ) { |
@@ -1449,7 +1447,7 @@ discard block |
||
| 1449 | 1447 | * @since 3.9.0 $allow_bail parameter added. |
| 1450 | 1448 | * |
| 1451 | 1449 | * @param bool $allow_bail Optional. Allows the function to bail. Default true. |
| 1452 | - * @return bool True with a successful connection, false on failure. |
|
| 1450 | + * @return boolean|null True with a successful connection, false on failure. |
|
| 1453 | 1451 | */ |
| 1454 | 1452 | public function db_connect( $allow_bail = true ) { |
| 1455 | 1453 | $this->is_mysql = true; |
@@ -3052,7 +3050,7 @@ discard block |
||
| 3052 | 3050 | * |
| 3053 | 3051 | * @since 1.5.0 |
| 3054 | 3052 | * |
| 3055 | - * @return true |
|
| 3053 | + * @return boolean |
|
| 3056 | 3054 | */ |
| 3057 | 3055 | public function timer_start() { |
| 3058 | 3056 | $this->time_start = microtime( true ); |
@@ -3186,7 +3184,7 @@ discard block |
||
| 3186 | 3184 | * @param string $db_cap The feature to check for. Accepts 'collation', |
| 3187 | 3185 | * 'group_concat', 'subqueries', 'set_charset', |
| 3188 | 3186 | * or 'utf8mb4'. |
| 3189 | - * @return int|false Whether the database feature is supported, false otherwise. |
|
| 3187 | + * @return boolean Whether the database feature is supported, false otherwise. |
|
| 3190 | 3188 | */ |
| 3191 | 3189 | public function has_cap( $db_cap ) { |
| 3192 | 3190 | $version = $this->db_version(); |
@@ -3242,7 +3240,7 @@ discard block |
||
| 3242 | 3240 | * |
| 3243 | 3241 | * @since 2.7.0 |
| 3244 | 3242 | * |
| 3245 | - * @return null|string Null on failure, version number on success. |
|
| 3243 | + * @return string Null on failure, version number on success. |
|
| 3246 | 3244 | */ |
| 3247 | 3245 | public function db_version() { |
| 3248 | 3246 | if ( $this->use_mysqli ) { |
@@ -12,28 +12,28 @@ discard block |
||
| 12 | 12 | /** |
| 13 | 13 | * @since 0.71 |
| 14 | 14 | */ |
| 15 | -define( 'EZSQL_VERSION', 'WP1.25' ); |
|
| 15 | +define('EZSQL_VERSION', 'WP1.25'); |
|
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | 18 | * @since 0.71 |
| 19 | 19 | */ |
| 20 | -define( 'OBJECT', 'OBJECT' ); |
|
| 21 | -define( 'object', 'OBJECT' ); // Back compat. |
|
| 20 | +define('OBJECT', 'OBJECT'); |
|
| 21 | +define('object', 'OBJECT'); // Back compat. |
|
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | 24 | * @since 2.5.0 |
| 25 | 25 | */ |
| 26 | -define( 'OBJECT_K', 'OBJECT_K' ); |
|
| 26 | +define('OBJECT_K', 'OBJECT_K'); |
|
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * @since 0.71 |
| 30 | 30 | */ |
| 31 | -define( 'ARRAY_A', 'ARRAY_A' ); |
|
| 31 | +define('ARRAY_A', 'ARRAY_A'); |
|
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * @since 0.71 |
| 35 | 35 | */ |
| 36 | -define( 'ARRAY_N', 'ARRAY_N' ); |
|
| 36 | +define('ARRAY_N', 'ARRAY_N'); |
|
| 37 | 37 | |
| 38 | 38 | /** |
| 39 | 39 | * WordPress Database Access Abstraction Object |
@@ -265,8 +265,8 @@ discard block |
||
| 265 | 265 | * @see wpdb::tables() |
| 266 | 266 | * @var array |
| 267 | 267 | */ |
| 268 | - var $tables = array( 'posts', 'comments', 'links', 'options', 'postmeta', |
|
| 269 | - 'terms', 'term_taxonomy', 'term_relationships', 'termmeta', 'commentmeta' ); |
|
| 268 | + var $tables = array('posts', 'comments', 'links', 'options', 'postmeta', |
|
| 269 | + 'terms', 'term_taxonomy', 'term_relationships', 'termmeta', 'commentmeta'); |
|
| 270 | 270 | |
| 271 | 271 | /** |
| 272 | 272 | * List of deprecated WordPress tables |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | * @see wpdb::tables() |
| 279 | 279 | * @var array |
| 280 | 280 | */ |
| 281 | - var $old_tables = array( 'categories', 'post2cat', 'link2cat' ); |
|
| 281 | + var $old_tables = array('categories', 'post2cat', 'link2cat'); |
|
| 282 | 282 | |
| 283 | 283 | /** |
| 284 | 284 | * List of WordPress global tables |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | * @see wpdb::tables() |
| 289 | 289 | * @var array |
| 290 | 290 | */ |
| 291 | - var $global_tables = array( 'users', 'usermeta' ); |
|
| 291 | + var $global_tables = array('users', 'usermeta'); |
|
| 292 | 292 | |
| 293 | 293 | /** |
| 294 | 294 | * List of Multisite global tables |
@@ -298,8 +298,8 @@ discard block |
||
| 298 | 298 | * @see wpdb::tables() |
| 299 | 299 | * @var array |
| 300 | 300 | */ |
| 301 | - var $ms_global_tables = array( 'blogs', 'signups', 'site', 'sitemeta', |
|
| 302 | - 'sitecategories', 'registration_log', 'blog_versions' ); |
|
| 301 | + var $ms_global_tables = array('blogs', 'signups', 'site', 'sitemeta', |
|
| 302 | + 'sitecategories', 'registration_log', 'blog_versions'); |
|
| 303 | 303 | |
| 304 | 304 | /** |
| 305 | 305 | * WordPress Comments table |
@@ -585,8 +585,8 @@ discard block |
||
| 585 | 585 | * @access protected |
| 586 | 586 | * @var array |
| 587 | 587 | */ |
| 588 | - protected $incompatible_modes = array( 'NO_ZERO_DATE', 'ONLY_FULL_GROUP_BY', |
|
| 589 | - 'STRICT_TRANS_TABLES', 'STRICT_ALL_TABLES', 'TRADITIONAL' ); |
|
| 588 | + protected $incompatible_modes = array('NO_ZERO_DATE', 'ONLY_FULL_GROUP_BY', |
|
| 589 | + 'STRICT_TRANS_TABLES', 'STRICT_ALL_TABLES', 'TRADITIONAL'); |
|
| 590 | 590 | |
| 591 | 591 | /** |
| 592 | 592 | * Whether to use mysqli over mysql. |
@@ -623,10 +623,10 @@ discard block |
||
| 623 | 623 | * @param string $dbname MySQL database name |
| 624 | 624 | * @param string $dbhost MySQL database host |
| 625 | 625 | */ |
| 626 | - public function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) { |
|
| 627 | - register_shutdown_function( array( $this, '__destruct' ) ); |
|
| 626 | + public function __construct($dbuser, $dbpassword, $dbname, $dbhost) { |
|
| 627 | + register_shutdown_function(array($this, '__destruct')); |
|
| 628 | 628 | |
| 629 | - if ( WP_DEBUG && WP_DEBUG_DISPLAY ) |
|
| 629 | + if (WP_DEBUG && WP_DEBUG_DISPLAY) |
|
| 630 | 630 | $this->show_errors(); |
| 631 | 631 | |
| 632 | 632 | /* Use ext/mysqli if it exists and: |
@@ -635,12 +635,12 @@ discard block |
||
| 635 | 635 | * - We are running PHP 5.5 or greater, or |
| 636 | 636 | * - ext/mysql is not loaded. |
| 637 | 637 | */ |
| 638 | - if ( function_exists( 'mysqli_connect' ) ) { |
|
| 639 | - if ( defined( 'WP_USE_EXT_MYSQL' ) ) { |
|
| 638 | + if (function_exists('mysqli_connect')) { |
|
| 639 | + if (defined('WP_USE_EXT_MYSQL')) { |
|
| 640 | 640 | $this->use_mysqli = ! WP_USE_EXT_MYSQL; |
| 641 | - } elseif ( version_compare( phpversion(), '5.5', '>=' ) || ! function_exists( 'mysql_connect' ) ) { |
|
| 641 | + } elseif (version_compare(phpversion(), '5.5', '>=') || ! function_exists('mysql_connect')) { |
|
| 642 | 642 | $this->use_mysqli = true; |
| 643 | - } elseif ( false !== strpos( $GLOBALS['wp_version'], '-' ) ) { |
|
| 643 | + } elseif (false !== strpos($GLOBALS['wp_version'], '-')) { |
|
| 644 | 644 | $this->use_mysqli = true; |
| 645 | 645 | } |
| 646 | 646 | } |
@@ -651,7 +651,7 @@ discard block |
||
| 651 | 651 | $this->dbhost = $dbhost; |
| 652 | 652 | |
| 653 | 653 | // wp-config.php creation will manually connect when ready. |
| 654 | - if ( defined( 'WP_SETUP_CONFIG' ) ) { |
|
| 654 | + if (defined('WP_SETUP_CONFIG')) { |
|
| 655 | 655 | return; |
| 656 | 656 | } |
| 657 | 657 | |
@@ -677,8 +677,8 @@ discard block |
||
| 677 | 677 | * @param string $name The private member to get, and optionally process |
| 678 | 678 | * @return mixed The private member |
| 679 | 679 | */ |
| 680 | - public function __get( $name ) { |
|
| 681 | - if ( 'col_info' === $name ) |
|
| 680 | + public function __get($name) { |
|
| 681 | + if ('col_info' === $name) |
|
| 682 | 682 | $this->load_col_info(); |
| 683 | 683 | |
| 684 | 684 | return $this->$name; |
@@ -692,13 +692,13 @@ discard block |
||
| 692 | 692 | * @param string $name The private member to set |
| 693 | 693 | * @param mixed $value The value to set |
| 694 | 694 | */ |
| 695 | - public function __set( $name, $value ) { |
|
| 695 | + public function __set($name, $value) { |
|
| 696 | 696 | $protected_members = array( |
| 697 | 697 | 'col_meta', |
| 698 | 698 | 'table_charset', |
| 699 | 699 | 'check_current_query', |
| 700 | 700 | ); |
| 701 | - if ( in_array( $name, $protected_members, true ) ) { |
|
| 701 | + if (in_array($name, $protected_members, true)) { |
|
| 702 | 702 | return; |
| 703 | 703 | } |
| 704 | 704 | $this->$name = $value; |
@@ -713,8 +713,8 @@ discard block |
||
| 713 | 713 | * |
| 714 | 714 | * @return bool If the member is set or not |
| 715 | 715 | */ |
| 716 | - public function __isset( $name ) { |
|
| 717 | - return isset( $this->$name ); |
|
| 716 | + public function __isset($name) { |
|
| 717 | + return isset($this->$name); |
|
| 718 | 718 | } |
| 719 | 719 | |
| 720 | 720 | /** |
@@ -724,8 +724,8 @@ discard block |
||
| 724 | 724 | * |
| 725 | 725 | * @param string $name The private member to unset |
| 726 | 726 | */ |
| 727 | - public function __unset( $name ) { |
|
| 728 | - unset( $this->$name ); |
|
| 727 | + public function __unset($name) { |
|
| 728 | + unset($this->$name); |
|
| 729 | 729 | } |
| 730 | 730 | |
| 731 | 731 | /** |
@@ -734,30 +734,30 @@ discard block |
||
| 734 | 734 | * @since 3.1.0 |
| 735 | 735 | */ |
| 736 | 736 | public function init_charset() { |
| 737 | - if ( function_exists('is_multisite') && is_multisite() ) { |
|
| 737 | + if (function_exists('is_multisite') && is_multisite()) { |
|
| 738 | 738 | $this->charset = 'utf8'; |
| 739 | - if ( defined( 'DB_COLLATE' ) && DB_COLLATE ) { |
|
| 739 | + if (defined('DB_COLLATE') && DB_COLLATE) { |
|
| 740 | 740 | $this->collate = DB_COLLATE; |
| 741 | 741 | } else { |
| 742 | 742 | $this->collate = 'utf8_general_ci'; |
| 743 | 743 | } |
| 744 | - } elseif ( defined( 'DB_COLLATE' ) ) { |
|
| 744 | + } elseif (defined('DB_COLLATE')) { |
|
| 745 | 745 | $this->collate = DB_COLLATE; |
| 746 | 746 | } |
| 747 | 747 | |
| 748 | - if ( defined( 'DB_CHARSET' ) ) { |
|
| 748 | + if (defined('DB_CHARSET')) { |
|
| 749 | 749 | $this->charset = DB_CHARSET; |
| 750 | 750 | } |
| 751 | 751 | |
| 752 | - if ( ( $this->use_mysqli && ! ( $this->dbh instanceof mysqli ) ) || empty( $this->dbh ) ) { |
|
| 752 | + if (($this->use_mysqli && ! ($this->dbh instanceof mysqli)) || empty($this->dbh)) { |
|
| 753 | 753 | return; |
| 754 | 754 | } |
| 755 | 755 | |
| 756 | - if ( 'utf8' === $this->charset && $this->has_cap( 'utf8mb4' ) ) { |
|
| 756 | + if ('utf8' === $this->charset && $this->has_cap('utf8mb4')) { |
|
| 757 | 757 | $this->charset = 'utf8mb4'; |
| 758 | 758 | } |
| 759 | 759 | |
| 760 | - if ( 'utf8mb4' === $this->charset && ( ! $this->collate || stripos( $this->collate, 'utf8_' ) === 0 ) ) { |
|
| 760 | + if ('utf8mb4' === $this->charset && ( ! $this->collate || stripos($this->collate, 'utf8_') === 0)) { |
|
| 761 | 761 | $this->collate = 'utf8mb4_unicode_ci'; |
| 762 | 762 | } |
| 763 | 763 | } |
@@ -771,29 +771,29 @@ discard block |
||
| 771 | 771 | * @param string $charset Optional. The character set. Default null. |
| 772 | 772 | * @param string $collate Optional. The collation. Default null. |
| 773 | 773 | */ |
| 774 | - public function set_charset( $dbh, $charset = null, $collate = null ) { |
|
| 775 | - if ( ! isset( $charset ) ) |
|
| 774 | + public function set_charset($dbh, $charset = null, $collate = null) { |
|
| 775 | + if ( ! isset($charset)) |
|
| 776 | 776 | $charset = $this->charset; |
| 777 | - if ( ! isset( $collate ) ) |
|
| 777 | + if ( ! isset($collate)) |
|
| 778 | 778 | $collate = $this->collate; |
| 779 | - if ( $this->has_cap( 'collation' ) && ! empty( $charset ) ) { |
|
| 780 | - if ( $this->use_mysqli ) { |
|
| 781 | - if ( function_exists( 'mysqli_set_charset' ) && $this->has_cap( 'set_charset' ) ) { |
|
| 782 | - mysqli_set_charset( $dbh, $charset ); |
|
| 779 | + if ($this->has_cap('collation') && ! empty($charset)) { |
|
| 780 | + if ($this->use_mysqli) { |
|
| 781 | + if (function_exists('mysqli_set_charset') && $this->has_cap('set_charset')) { |
|
| 782 | + mysqli_set_charset($dbh, $charset); |
|
| 783 | 783 | } else { |
| 784 | - $query = $this->prepare( 'SET NAMES %s', $charset ); |
|
| 785 | - if ( ! empty( $collate ) ) |
|
| 786 | - $query .= $this->prepare( ' COLLATE %s', $collate ); |
|
| 787 | - mysqli_query( $dbh, $query ); |
|
| 784 | + $query = $this->prepare('SET NAMES %s', $charset); |
|
| 785 | + if ( ! empty($collate)) |
|
| 786 | + $query .= $this->prepare(' COLLATE %s', $collate); |
|
| 787 | + mysqli_query($dbh, $query); |
|
| 788 | 788 | } |
| 789 | 789 | } else { |
| 790 | - if ( function_exists( 'mysql_set_charset' ) && $this->has_cap( 'set_charset' ) ) { |
|
| 791 | - mysql_set_charset( $charset, $dbh ); |
|
| 790 | + if (function_exists('mysql_set_charset') && $this->has_cap('set_charset')) { |
|
| 791 | + mysql_set_charset($charset, $dbh); |
|
| 792 | 792 | } else { |
| 793 | - $query = $this->prepare( 'SET NAMES %s', $charset ); |
|
| 794 | - if ( ! empty( $collate ) ) |
|
| 795 | - $query .= $this->prepare( ' COLLATE %s', $collate ); |
|
| 796 | - mysql_query( $query, $dbh ); |
|
| 793 | + $query = $this->prepare('SET NAMES %s', $charset); |
|
| 794 | + if ( ! empty($collate)) |
|
| 795 | + $query .= $this->prepare(' COLLATE %s', $collate); |
|
| 796 | + mysql_query($query, $dbh); |
|
| 797 | 797 | } |
| 798 | 798 | } |
| 799 | 799 | } |
@@ -809,36 +809,36 @@ discard block |
||
| 809 | 809 | * |
| 810 | 810 | * @param array $modes Optional. A list of SQL modes to set. |
| 811 | 811 | */ |
| 812 | - public function set_sql_mode( $modes = array() ) { |
|
| 813 | - if ( empty( $modes ) ) { |
|
| 814 | - if ( $this->use_mysqli ) { |
|
| 815 | - $res = mysqli_query( $this->dbh, 'SELECT @@SESSION.sql_mode' ); |
|
| 812 | + public function set_sql_mode($modes = array()) { |
|
| 813 | + if (empty($modes)) { |
|
| 814 | + if ($this->use_mysqli) { |
|
| 815 | + $res = mysqli_query($this->dbh, 'SELECT @@SESSION.sql_mode'); |
|
| 816 | 816 | } else { |
| 817 | - $res = mysql_query( 'SELECT @@SESSION.sql_mode', $this->dbh ); |
|
| 817 | + $res = mysql_query('SELECT @@SESSION.sql_mode', $this->dbh); |
|
| 818 | 818 | } |
| 819 | 819 | |
| 820 | - if ( empty( $res ) ) { |
|
| 820 | + if (empty($res)) { |
|
| 821 | 821 | return; |
| 822 | 822 | } |
| 823 | 823 | |
| 824 | - if ( $this->use_mysqli ) { |
|
| 825 | - $modes_array = mysqli_fetch_array( $res ); |
|
| 826 | - if ( empty( $modes_array[0] ) ) { |
|
| 824 | + if ($this->use_mysqli) { |
|
| 825 | + $modes_array = mysqli_fetch_array($res); |
|
| 826 | + if (empty($modes_array[0])) { |
|
| 827 | 827 | return; |
| 828 | 828 | } |
| 829 | 829 | $modes_str = $modes_array[0]; |
| 830 | 830 | } else { |
| 831 | - $modes_str = mysql_result( $res, 0 ); |
|
| 831 | + $modes_str = mysql_result($res, 0); |
|
| 832 | 832 | } |
| 833 | 833 | |
| 834 | - if ( empty( $modes_str ) ) { |
|
| 834 | + if (empty($modes_str)) { |
|
| 835 | 835 | return; |
| 836 | 836 | } |
| 837 | 837 | |
| 838 | - $modes = explode( ',', $modes_str ); |
|
| 838 | + $modes = explode(',', $modes_str); |
|
| 839 | 839 | } |
| 840 | 840 | |
| 841 | - $modes = array_change_key_case( $modes, CASE_UPPER ); |
|
| 841 | + $modes = array_change_key_case($modes, CASE_UPPER); |
|
| 842 | 842 | |
| 843 | 843 | /** |
| 844 | 844 | * Filter the list of incompatible SQL modes to exclude. |
@@ -847,20 +847,20 @@ discard block |
||
| 847 | 847 | * |
| 848 | 848 | * @param array $incompatible_modes An array of incompatible modes. |
| 849 | 849 | */ |
| 850 | - $incompatible_modes = (array) apply_filters( 'incompatible_sql_modes', $this->incompatible_modes ); |
|
| 850 | + $incompatible_modes = (array) apply_filters('incompatible_sql_modes', $this->incompatible_modes); |
|
| 851 | 851 | |
| 852 | - foreach ( $modes as $i => $mode ) { |
|
| 853 | - if ( in_array( $mode, $incompatible_modes ) ) { |
|
| 854 | - unset( $modes[ $i ] ); |
|
| 852 | + foreach ($modes as $i => $mode) { |
|
| 853 | + if (in_array($mode, $incompatible_modes)) { |
|
| 854 | + unset($modes[$i]); |
|
| 855 | 855 | } |
| 856 | 856 | } |
| 857 | 857 | |
| 858 | - $modes_str = implode( ',', $modes ); |
|
| 858 | + $modes_str = implode(',', $modes); |
|
| 859 | 859 | |
| 860 | - if ( $this->use_mysqli ) { |
|
| 861 | - mysqli_query( $this->dbh, "SET SESSION sql_mode='$modes_str'" ); |
|
| 860 | + if ($this->use_mysqli) { |
|
| 861 | + mysqli_query($this->dbh, "SET SESSION sql_mode='$modes_str'"); |
|
| 862 | 862 | } else { |
| 863 | - mysql_query( "SET SESSION sql_mode='$modes_str'", $this->dbh ); |
|
| 863 | + mysql_query("SET SESSION sql_mode='$modes_str'", $this->dbh); |
|
| 864 | 864 | } |
| 865 | 865 | } |
| 866 | 866 | |
@@ -873,31 +873,31 @@ discard block |
||
| 873 | 873 | * @param bool $set_table_names Optional. Whether the table names, e.g. wpdb::$posts, should be updated or not. |
| 874 | 874 | * @return string|WP_Error Old prefix or WP_Error on error |
| 875 | 875 | */ |
| 876 | - public function set_prefix( $prefix, $set_table_names = true ) { |
|
| 876 | + public function set_prefix($prefix, $set_table_names = true) { |
|
| 877 | 877 | |
| 878 | - if ( preg_match( '|[^a-z0-9_]|i', $prefix ) ) |
|
| 879 | - return new WP_Error('invalid_db_prefix', 'Invalid database prefix' ); |
|
| 878 | + if (preg_match('|[^a-z0-9_]|i', $prefix)) |
|
| 879 | + return new WP_Error('invalid_db_prefix', 'Invalid database prefix'); |
|
| 880 | 880 | |
| 881 | 881 | $old_prefix = is_multisite() ? '' : $prefix; |
| 882 | 882 | |
| 883 | - if ( isset( $this->base_prefix ) ) |
|
| 883 | + if (isset($this->base_prefix)) |
|
| 884 | 884 | $old_prefix = $this->base_prefix; |
| 885 | 885 | |
| 886 | 886 | $this->base_prefix = $prefix; |
| 887 | 887 | |
| 888 | - if ( $set_table_names ) { |
|
| 889 | - foreach ( $this->tables( 'global' ) as $table => $prefixed_table ) |
|
| 888 | + if ($set_table_names) { |
|
| 889 | + foreach ($this->tables('global') as $table => $prefixed_table) |
|
| 890 | 890 | $this->$table = $prefixed_table; |
| 891 | 891 | |
| 892 | - if ( is_multisite() && empty( $this->blogid ) ) |
|
| 892 | + if (is_multisite() && empty($this->blogid)) |
|
| 893 | 893 | return $old_prefix; |
| 894 | 894 | |
| 895 | 895 | $this->prefix = $this->get_blog_prefix(); |
| 896 | 896 | |
| 897 | - foreach ( $this->tables( 'blog' ) as $table => $prefixed_table ) |
|
| 897 | + foreach ($this->tables('blog') as $table => $prefixed_table) |
|
| 898 | 898 | $this->$table = $prefixed_table; |
| 899 | 899 | |
| 900 | - foreach ( $this->tables( 'old' ) as $table => $prefixed_table ) |
|
| 900 | + foreach ($this->tables('old') as $table => $prefixed_table) |
|
| 901 | 901 | $this->$table = $prefixed_table; |
| 902 | 902 | } |
| 903 | 903 | return $old_prefix; |
@@ -913,8 +913,8 @@ discard block |
||
| 913 | 913 | * @param int $site_id Optional. |
| 914 | 914 | * @return int previous blog id |
| 915 | 915 | */ |
| 916 | - public function set_blog_id( $blog_id, $site_id = 0 ) { |
|
| 917 | - if ( ! empty( $site_id ) ) |
|
| 916 | + public function set_blog_id($blog_id, $site_id = 0) { |
|
| 917 | + if ( ! empty($site_id)) |
|
| 918 | 918 | $this->siteid = $site_id; |
| 919 | 919 | |
| 920 | 920 | $old_blog_id = $this->blogid; |
@@ -922,10 +922,10 @@ discard block |
||
| 922 | 922 | |
| 923 | 923 | $this->prefix = $this->get_blog_prefix(); |
| 924 | 924 | |
| 925 | - foreach ( $this->tables( 'blog' ) as $table => $prefixed_table ) |
|
| 925 | + foreach ($this->tables('blog') as $table => $prefixed_table) |
|
| 926 | 926 | $this->$table = $prefixed_table; |
| 927 | 927 | |
| 928 | - foreach ( $this->tables( 'old' ) as $table => $prefixed_table ) |
|
| 928 | + foreach ($this->tables('old') as $table => $prefixed_table) |
|
| 929 | 929 | $this->$table = $prefixed_table; |
| 930 | 930 | |
| 931 | 931 | return $old_blog_id; |
@@ -938,15 +938,15 @@ discard block |
||
| 938 | 938 | * @param int $blog_id Optional. |
| 939 | 939 | * @return string Blog prefix. |
| 940 | 940 | */ |
| 941 | - public function get_blog_prefix( $blog_id = null ) { |
|
| 942 | - if ( is_multisite() ) { |
|
| 943 | - if ( null === $blog_id ) |
|
| 941 | + public function get_blog_prefix($blog_id = null) { |
|
| 942 | + if (is_multisite()) { |
|
| 943 | + if (null === $blog_id) |
|
| 944 | 944 | $blog_id = $this->blogid; |
| 945 | 945 | $blog_id = (int) $blog_id; |
| 946 | - if ( defined( 'MULTISITE' ) && ( 0 == $blog_id || 1 == $blog_id ) ) |
|
| 946 | + if (defined('MULTISITE') && (0 == $blog_id || 1 == $blog_id)) |
|
| 947 | 947 | return $this->base_prefix; |
| 948 | 948 | else |
| 949 | - return $this->base_prefix . $blog_id . '_'; |
|
| 949 | + return $this->base_prefix.$blog_id.'_'; |
|
| 950 | 950 | } else { |
| 951 | 951 | return $this->base_prefix; |
| 952 | 952 | } |
@@ -979,20 +979,20 @@ discard block |
||
| 979 | 979 | * @param int $blog_id Optional. The blog_id to prefix. Defaults to wpdb::$blogid. Used only when prefix is requested. |
| 980 | 980 | * @return array Table names. When a prefix is requested, the key is the unprefixed table name. |
| 981 | 981 | */ |
| 982 | - public function tables( $scope = 'all', $prefix = true, $blog_id = 0 ) { |
|
| 983 | - switch ( $scope ) { |
|
| 982 | + public function tables($scope = 'all', $prefix = true, $blog_id = 0) { |
|
| 983 | + switch ($scope) { |
|
| 984 | 984 | case 'all' : |
| 985 | - $tables = array_merge( $this->global_tables, $this->tables ); |
|
| 986 | - if ( is_multisite() ) |
|
| 987 | - $tables = array_merge( $tables, $this->ms_global_tables ); |
|
| 985 | + $tables = array_merge($this->global_tables, $this->tables); |
|
| 986 | + if (is_multisite()) |
|
| 987 | + $tables = array_merge($tables, $this->ms_global_tables); |
|
| 988 | 988 | break; |
| 989 | 989 | case 'blog' : |
| 990 | 990 | $tables = $this->tables; |
| 991 | 991 | break; |
| 992 | 992 | case 'global' : |
| 993 | 993 | $tables = $this->global_tables; |
| 994 | - if ( is_multisite() ) |
|
| 995 | - $tables = array_merge( $tables, $this->ms_global_tables ); |
|
| 994 | + if (is_multisite()) |
|
| 995 | + $tables = array_merge($tables, $this->ms_global_tables); |
|
| 996 | 996 | break; |
| 997 | 997 | case 'ms_global' : |
| 998 | 998 | $tables = $this->ms_global_tables; |
@@ -1004,24 +1004,24 @@ discard block |
||
| 1004 | 1004 | return array(); |
| 1005 | 1005 | } |
| 1006 | 1006 | |
| 1007 | - if ( $prefix ) { |
|
| 1008 | - if ( ! $blog_id ) |
|
| 1007 | + if ($prefix) { |
|
| 1008 | + if ( ! $blog_id) |
|
| 1009 | 1009 | $blog_id = $this->blogid; |
| 1010 | - $blog_prefix = $this->get_blog_prefix( $blog_id ); |
|
| 1010 | + $blog_prefix = $this->get_blog_prefix($blog_id); |
|
| 1011 | 1011 | $base_prefix = $this->base_prefix; |
| 1012 | - $global_tables = array_merge( $this->global_tables, $this->ms_global_tables ); |
|
| 1013 | - foreach ( $tables as $k => $table ) { |
|
| 1014 | - if ( in_array( $table, $global_tables ) ) |
|
| 1015 | - $tables[ $table ] = $base_prefix . $table; |
|
| 1012 | + $global_tables = array_merge($this->global_tables, $this->ms_global_tables); |
|
| 1013 | + foreach ($tables as $k => $table) { |
|
| 1014 | + if (in_array($table, $global_tables)) |
|
| 1015 | + $tables[$table] = $base_prefix.$table; |
|
| 1016 | 1016 | else |
| 1017 | - $tables[ $table ] = $blog_prefix . $table; |
|
| 1018 | - unset( $tables[ $k ] ); |
|
| 1017 | + $tables[$table] = $blog_prefix.$table; |
|
| 1018 | + unset($tables[$k]); |
|
| 1019 | 1019 | } |
| 1020 | 1020 | |
| 1021 | - if ( isset( $tables['users'] ) && defined( 'CUSTOM_USER_TABLE' ) ) |
|
| 1021 | + if (isset($tables['users']) && defined('CUSTOM_USER_TABLE')) |
|
| 1022 | 1022 | $tables['users'] = CUSTOM_USER_TABLE; |
| 1023 | 1023 | |
| 1024 | - if ( isset( $tables['usermeta'] ) && defined( 'CUSTOM_USER_META_TABLE' ) ) |
|
| 1024 | + if (isset($tables['usermeta']) && defined('CUSTOM_USER_META_TABLE')) |
|
| 1025 | 1025 | $tables['usermeta'] = CUSTOM_USER_META_TABLE; |
| 1026 | 1026 | } |
| 1027 | 1027 | |
@@ -1039,53 +1039,53 @@ discard block |
||
| 1039 | 1039 | * @param string $db MySQL database name |
| 1040 | 1040 | * @param resource|null $dbh Optional link identifier. |
| 1041 | 1041 | */ |
| 1042 | - public function select( $db, $dbh = null ) { |
|
| 1043 | - if ( is_null($dbh) ) |
|
| 1042 | + public function select($db, $dbh = null) { |
|
| 1043 | + if (is_null($dbh)) |
|
| 1044 | 1044 | $dbh = $this->dbh; |
| 1045 | 1045 | |
| 1046 | - if ( $this->use_mysqli ) { |
|
| 1047 | - $success = mysqli_select_db( $dbh, $db ); |
|
| 1046 | + if ($this->use_mysqli) { |
|
| 1047 | + $success = mysqli_select_db($dbh, $db); |
|
| 1048 | 1048 | } else { |
| 1049 | - $success = mysql_select_db( $db, $dbh ); |
|
| 1049 | + $success = mysql_select_db($db, $dbh); |
|
| 1050 | 1050 | } |
| 1051 | - if ( ! $success ) { |
|
| 1051 | + if ( ! $success) { |
|
| 1052 | 1052 | $this->ready = false; |
| 1053 | - if ( ! did_action( 'template_redirect' ) ) { |
|
| 1053 | + if ( ! did_action('template_redirect')) { |
|
| 1054 | 1054 | wp_load_translations_early(); |
| 1055 | 1055 | |
| 1056 | - $message = '<h1>' . __( 'Can’t select database' ) . "</h1>\n"; |
|
| 1056 | + $message = '<h1>'.__('Can’t select database')."</h1>\n"; |
|
| 1057 | 1057 | |
| 1058 | - $message .= '<p>' . sprintf( |
|
| 1058 | + $message .= '<p>'.sprintf( |
|
| 1059 | 1059 | /* translators: %s: database name */ |
| 1060 | - __( 'We were able to connect to the database server (which means your username and password is okay) but not able to select the %s database.' ), |
|
| 1061 | - '<code>' . htmlspecialchars( $db, ENT_QUOTES ) . '</code>' |
|
| 1062 | - ) . "</p>\n"; |
|
| 1060 | + __('We were able to connect to the database server (which means your username and password is okay) but not able to select the %s database.'), |
|
| 1061 | + '<code>'.htmlspecialchars($db, ENT_QUOTES).'</code>' |
|
| 1062 | + )."</p>\n"; |
|
| 1063 | 1063 | |
| 1064 | 1064 | $message .= "<ul>\n"; |
| 1065 | - $message .= '<li>' . __( 'Are you sure it exists?' ) . "</li>\n"; |
|
| 1065 | + $message .= '<li>'.__('Are you sure it exists?')."</li>\n"; |
|
| 1066 | 1066 | |
| 1067 | - $message .= '<li>' . sprintf( |
|
| 1067 | + $message .= '<li>'.sprintf( |
|
| 1068 | 1068 | /* translators: 1: database user, 2: database name */ |
| 1069 | - __( 'Does the user %1$s have permission to use the %2$s database?' ), |
|
| 1070 | - '<code>' . htmlspecialchars( $this->dbuser, ENT_QUOTES ) . '</code>', |
|
| 1071 | - '<code>' . htmlspecialchars( $db, ENT_QUOTES ) . '</code>' |
|
| 1072 | - ) . "</li>\n"; |
|
| 1069 | + __('Does the user %1$s have permission to use the %2$s database?'), |
|
| 1070 | + '<code>'.htmlspecialchars($this->dbuser, ENT_QUOTES).'</code>', |
|
| 1071 | + '<code>'.htmlspecialchars($db, ENT_QUOTES).'</code>' |
|
| 1072 | + )."</li>\n"; |
|
| 1073 | 1073 | |
| 1074 | - $message .= '<li>' . sprintf( |
|
| 1074 | + $message .= '<li>'.sprintf( |
|
| 1075 | 1075 | /* translators: %s: database name */ |
| 1076 | - __( 'On some systems the name of your database is prefixed with your username, so it would be like <code>username_%1$s</code>. Could that be the problem?' ), |
|
| 1077 | - htmlspecialchars( $db, ENT_QUOTES ) |
|
| 1078 | - ). "</li>\n"; |
|
| 1076 | + __('On some systems the name of your database is prefixed with your username, so it would be like <code>username_%1$s</code>. Could that be the problem?'), |
|
| 1077 | + htmlspecialchars($db, ENT_QUOTES) |
|
| 1078 | + )."</li>\n"; |
|
| 1079 | 1079 | |
| 1080 | 1080 | $message .= "</ul>\n"; |
| 1081 | 1081 | |
| 1082 | - $message .= '<p>' . sprintf( |
|
| 1082 | + $message .= '<p>'.sprintf( |
|
| 1083 | 1083 | /* translators: %s: support forums URL */ |
| 1084 | - __( 'If you don’t know how to set up a database you should <strong>contact your host</strong>. If all else fails you may find help at the <a href="%s">WordPress Support Forums</a>.' ), |
|
| 1085 | - __( 'https://wordpress.org/support/' ) |
|
| 1086 | - ) . "</p>\n"; |
|
| 1084 | + __('If you don’t know how to set up a database you should <strong>contact your host</strong>. If all else fails you may find help at the <a href="%s">WordPress Support Forums</a>.'), |
|
| 1085 | + __('https://wordpress.org/support/') |
|
| 1086 | + )."</p>\n"; |
|
| 1087 | 1087 | |
| 1088 | - $this->bail( $message, 'db_select_fail' ); |
|
| 1088 | + $this->bail($message, 'db_select_fail'); |
|
| 1089 | 1089 | } |
| 1090 | 1090 | } |
| 1091 | 1091 | } |
@@ -1104,10 +1104,10 @@ discard block |
||
| 1104 | 1104 | * @param string $string |
| 1105 | 1105 | * @return string |
| 1106 | 1106 | */ |
| 1107 | - function _weak_escape( $string ) { |
|
| 1108 | - if ( func_num_args() === 1 && function_exists( '_deprecated_function' ) ) |
|
| 1109 | - _deprecated_function( __METHOD__, '3.6', 'wpdb::prepare() or esc_sql()' ); |
|
| 1110 | - return addslashes( $string ); |
|
| 1107 | + function _weak_escape($string) { |
|
| 1108 | + if (func_num_args() === 1 && function_exists('_deprecated_function')) |
|
| 1109 | + _deprecated_function(__METHOD__, '3.6', 'wpdb::prepare() or esc_sql()'); |
|
| 1110 | + return addslashes($string); |
|
| 1111 | 1111 | } |
| 1112 | 1112 | |
| 1113 | 1113 | /** |
@@ -1121,23 +1121,23 @@ discard block |
||
| 1121 | 1121 | * @param string $string to escape |
| 1122 | 1122 | * @return string escaped |
| 1123 | 1123 | */ |
| 1124 | - function _real_escape( $string ) { |
|
| 1125 | - if ( $this->dbh ) { |
|
| 1126 | - if ( $this->use_mysqli ) { |
|
| 1127 | - return mysqli_real_escape_string( $this->dbh, $string ); |
|
| 1124 | + function _real_escape($string) { |
|
| 1125 | + if ($this->dbh) { |
|
| 1126 | + if ($this->use_mysqli) { |
|
| 1127 | + return mysqli_real_escape_string($this->dbh, $string); |
|
| 1128 | 1128 | } else { |
| 1129 | - return mysql_real_escape_string( $string, $this->dbh ); |
|
| 1129 | + return mysql_real_escape_string($string, $this->dbh); |
|
| 1130 | 1130 | } |
| 1131 | 1131 | } |
| 1132 | 1132 | |
| 1133 | - $class = get_class( $this ); |
|
| 1134 | - if ( function_exists( '__' ) ) { |
|
| 1133 | + $class = get_class($this); |
|
| 1134 | + if (function_exists('__')) { |
|
| 1135 | 1135 | /* translators: %s: database access abstraction class, usually wpdb or a class extending wpdb */ |
| 1136 | - _doing_it_wrong( $class, sprintf( __( '%s must set a database connection for use with escaping.' ), $class ), E_USER_NOTICE ); |
|
| 1136 | + _doing_it_wrong($class, sprintf(__('%s must set a database connection for use with escaping.'), $class), E_USER_NOTICE); |
|
| 1137 | 1137 | } else { |
| 1138 | - _doing_it_wrong( $class, sprintf( '%s must set a database connection for use with escaping.', $class ), E_USER_NOTICE ); |
|
| 1138 | + _doing_it_wrong($class, sprintf('%s must set a database connection for use with escaping.', $class), E_USER_NOTICE); |
|
| 1139 | 1139 | } |
| 1140 | - return addslashes( $string ); |
|
| 1140 | + return addslashes($string); |
|
| 1141 | 1141 | } |
| 1142 | 1142 | |
| 1143 | 1143 | /** |
@@ -1150,16 +1150,16 @@ discard block |
||
| 1150 | 1150 | * @param string|array $data |
| 1151 | 1151 | * @return string|array escaped |
| 1152 | 1152 | */ |
| 1153 | - function _escape( $data ) { |
|
| 1154 | - if ( is_array( $data ) ) { |
|
| 1155 | - foreach ( $data as $k => $v ) { |
|
| 1156 | - if ( is_array($v) ) |
|
| 1157 | - $data[$k] = $this->_escape( $v ); |
|
| 1153 | + function _escape($data) { |
|
| 1154 | + if (is_array($data)) { |
|
| 1155 | + foreach ($data as $k => $v) { |
|
| 1156 | + if (is_array($v)) |
|
| 1157 | + $data[$k] = $this->_escape($v); |
|
| 1158 | 1158 | else |
| 1159 | - $data[$k] = $this->_real_escape( $v ); |
|
| 1159 | + $data[$k] = $this->_real_escape($v); |
|
| 1160 | 1160 | } |
| 1161 | 1161 | } else { |
| 1162 | - $data = $this->_real_escape( $data ); |
|
| 1162 | + $data = $this->_real_escape($data); |
|
| 1163 | 1163 | } |
| 1164 | 1164 | |
| 1165 | 1165 | return $data; |
@@ -1178,18 +1178,18 @@ discard block |
||
| 1178 | 1178 | * @param mixed $data |
| 1179 | 1179 | * @return mixed |
| 1180 | 1180 | */ |
| 1181 | - public function escape( $data ) { |
|
| 1182 | - if ( func_num_args() === 1 && function_exists( '_deprecated_function' ) ) |
|
| 1183 | - _deprecated_function( __METHOD__, '3.6', 'wpdb::prepare() or esc_sql()' ); |
|
| 1184 | - if ( is_array( $data ) ) { |
|
| 1185 | - foreach ( $data as $k => $v ) { |
|
| 1186 | - if ( is_array( $v ) ) |
|
| 1187 | - $data[$k] = $this->escape( $v, 'recursive' ); |
|
| 1181 | + public function escape($data) { |
|
| 1182 | + if (func_num_args() === 1 && function_exists('_deprecated_function')) |
|
| 1183 | + _deprecated_function(__METHOD__, '3.6', 'wpdb::prepare() or esc_sql()'); |
|
| 1184 | + if (is_array($data)) { |
|
| 1185 | + foreach ($data as $k => $v) { |
|
| 1186 | + if (is_array($v)) |
|
| 1187 | + $data[$k] = $this->escape($v, 'recursive'); |
|
| 1188 | 1188 | else |
| 1189 | - $data[$k] = $this->_weak_escape( $v, 'internal' ); |
|
| 1189 | + $data[$k] = $this->_weak_escape($v, 'internal'); |
|
| 1190 | 1190 | } |
| 1191 | 1191 | } else { |
| 1192 | - $data = $this->_weak_escape( $data, 'internal' ); |
|
| 1192 | + $data = $this->_weak_escape($data, 'internal'); |
|
| 1193 | 1193 | } |
| 1194 | 1194 | |
| 1195 | 1195 | return $data; |
@@ -1204,9 +1204,9 @@ discard block |
||
| 1204 | 1204 | * |
| 1205 | 1205 | * @param string $string to escape |
| 1206 | 1206 | */ |
| 1207 | - public function escape_by_ref( &$string ) { |
|
| 1208 | - if ( ! is_float( $string ) ) |
|
| 1209 | - $string = $this->_real_escape( $string ); |
|
| 1207 | + public function escape_by_ref(&$string) { |
|
| 1208 | + if ( ! is_float($string)) |
|
| 1209 | + $string = $this->_real_escape($string); |
|
| 1210 | 1210 | } |
| 1211 | 1211 | |
| 1212 | 1212 | /** |
@@ -1243,26 +1243,26 @@ discard block |
||
| 1243 | 1243 | * {@link http://php.net/sprintf sprintf()}. |
| 1244 | 1244 | * @return string|void Sanitized query string, if there is a query to prepare. |
| 1245 | 1245 | */ |
| 1246 | - public function prepare( $query, $args ) { |
|
| 1247 | - if ( is_null( $query ) ) |
|
| 1246 | + public function prepare($query, $args) { |
|
| 1247 | + if (is_null($query)) |
|
| 1248 | 1248 | return; |
| 1249 | 1249 | |
| 1250 | 1250 | // This is not meant to be foolproof -- but it will catch obviously incorrect usage. |
| 1251 | - if ( strpos( $query, '%' ) === false ) { |
|
| 1252 | - _doing_it_wrong( 'wpdb::prepare', sprintf( __( 'The query argument of %s must have a placeholder.' ), 'wpdb::prepare()' ), '3.9' ); |
|
| 1251 | + if (strpos($query, '%') === false) { |
|
| 1252 | + _doing_it_wrong('wpdb::prepare', sprintf(__('The query argument of %s must have a placeholder.'), 'wpdb::prepare()'), '3.9'); |
|
| 1253 | 1253 | } |
| 1254 | 1254 | |
| 1255 | 1255 | $args = func_get_args(); |
| 1256 | - array_shift( $args ); |
|
| 1256 | + array_shift($args); |
|
| 1257 | 1257 | // If args were passed as an array (as in vsprintf), move them up |
| 1258 | - if ( isset( $args[0] ) && is_array($args[0]) ) |
|
| 1258 | + if (isset($args[0]) && is_array($args[0])) |
|
| 1259 | 1259 | $args = $args[0]; |
| 1260 | - $query = str_replace( "'%s'", '%s', $query ); // in case someone mistakenly already singlequoted it |
|
| 1261 | - $query = str_replace( '"%s"', '%s', $query ); // doublequote unquoting |
|
| 1262 | - $query = preg_replace( '|(?<!%)%f|' , '%F', $query ); // Force floats to be locale unaware |
|
| 1263 | - $query = preg_replace( '|(?<!%)%s|', "'%s'", $query ); // quote the strings, avoiding escaped strings like %%s |
|
| 1264 | - array_walk( $args, array( $this, 'escape_by_ref' ) ); |
|
| 1265 | - return @vsprintf( $query, $args ); |
|
| 1260 | + $query = str_replace("'%s'", '%s', $query); // in case someone mistakenly already singlequoted it |
|
| 1261 | + $query = str_replace('"%s"', '%s', $query); // doublequote unquoting |
|
| 1262 | + $query = preg_replace('|(?<!%)%f|', '%F', $query); // Force floats to be locale unaware |
|
| 1263 | + $query = preg_replace('|(?<!%)%s|', "'%s'", $query); // quote the strings, avoiding escaped strings like %%s |
|
| 1264 | + array_walk($args, array($this, 'escape_by_ref')); |
|
| 1265 | + return @vsprintf($query, $args); |
|
| 1266 | 1266 | } |
| 1267 | 1267 | |
| 1268 | 1268 | /** |
@@ -1287,8 +1287,8 @@ discard block |
||
| 1287 | 1287 | * @return string Text in the form of a LIKE phrase. The output is not SQL safe. Call $wpdb::prepare() |
| 1288 | 1288 | * or real_escape next. |
| 1289 | 1289 | */ |
| 1290 | - public function esc_like( $text ) { |
|
| 1291 | - return addcslashes( $text, '_%\\' ); |
|
| 1290 | + public function esc_like($text) { |
|
| 1291 | + return addcslashes($text, '_%\\'); |
|
| 1292 | 1292 | } |
| 1293 | 1293 | |
| 1294 | 1294 | /** |
@@ -1300,56 +1300,56 @@ discard block |
||
| 1300 | 1300 | * @param string $str The error to display |
| 1301 | 1301 | * @return false|void False if the showing of errors is disabled. |
| 1302 | 1302 | */ |
| 1303 | - public function print_error( $str = '' ) { |
|
| 1303 | + public function print_error($str = '') { |
|
| 1304 | 1304 | global $EZSQL_ERROR; |
| 1305 | 1305 | |
| 1306 | - if ( !$str ) { |
|
| 1307 | - if ( $this->use_mysqli ) { |
|
| 1308 | - $str = mysqli_error( $this->dbh ); |
|
| 1306 | + if ( ! $str) { |
|
| 1307 | + if ($this->use_mysqli) { |
|
| 1308 | + $str = mysqli_error($this->dbh); |
|
| 1309 | 1309 | } else { |
| 1310 | - $str = mysql_error( $this->dbh ); |
|
| 1310 | + $str = mysql_error($this->dbh); |
|
| 1311 | 1311 | } |
| 1312 | 1312 | } |
| 1313 | - $EZSQL_ERROR[] = array( 'query' => $this->last_query, 'error_str' => $str ); |
|
| 1313 | + $EZSQL_ERROR[] = array('query' => $this->last_query, 'error_str' => $str); |
|
| 1314 | 1314 | |
| 1315 | - if ( $this->suppress_errors ) |
|
| 1315 | + if ($this->suppress_errors) |
|
| 1316 | 1316 | return false; |
| 1317 | 1317 | |
| 1318 | 1318 | wp_load_translations_early(); |
| 1319 | 1319 | |
| 1320 | - if ( $caller = $this->get_caller() ) |
|
| 1321 | - $error_str = sprintf( __( 'WordPress database error %1$s for query %2$s made by %3$s' ), $str, $this->last_query, $caller ); |
|
| 1320 | + if ($caller = $this->get_caller()) |
|
| 1321 | + $error_str = sprintf(__('WordPress database error %1$s for query %2$s made by %3$s'), $str, $this->last_query, $caller); |
|
| 1322 | 1322 | else |
| 1323 | - $error_str = sprintf( __( 'WordPress database error %1$s for query %2$s' ), $str, $this->last_query ); |
|
| 1323 | + $error_str = sprintf(__('WordPress database error %1$s for query %2$s'), $str, $this->last_query); |
|
| 1324 | 1324 | |
| 1325 | - error_log( $error_str ); |
|
| 1325 | + error_log($error_str); |
|
| 1326 | 1326 | |
| 1327 | 1327 | // Are we showing errors? |
| 1328 | - if ( ! $this->show_errors ) |
|
| 1328 | + if ( ! $this->show_errors) |
|
| 1329 | 1329 | return false; |
| 1330 | 1330 | |
| 1331 | 1331 | // If there is an error then take note of it |
| 1332 | - if ( is_multisite() ) { |
|
| 1332 | + if (is_multisite()) { |
|
| 1333 | 1333 | $msg = sprintf( |
| 1334 | 1334 | "%s [%s]\n%s\n", |
| 1335 | - __( 'WordPress database error:' ), |
|
| 1335 | + __('WordPress database error:'), |
|
| 1336 | 1336 | $str, |
| 1337 | 1337 | $this->last_query |
| 1338 | 1338 | ); |
| 1339 | 1339 | |
| 1340 | - if ( defined( 'ERRORLOGFILE' ) ) { |
|
| 1341 | - error_log( $msg, 3, ERRORLOGFILE ); |
|
| 1340 | + if (defined('ERRORLOGFILE')) { |
|
| 1341 | + error_log($msg, 3, ERRORLOGFILE); |
|
| 1342 | 1342 | } |
| 1343 | - if ( defined( 'DIEONDBERROR' ) ) { |
|
| 1344 | - wp_die( $msg ); |
|
| 1343 | + if (defined('DIEONDBERROR')) { |
|
| 1344 | + wp_die($msg); |
|
| 1345 | 1345 | } |
| 1346 | 1346 | } else { |
| 1347 | - $str = htmlspecialchars( $str, ENT_QUOTES ); |
|
| 1348 | - $query = htmlspecialchars( $this->last_query, ENT_QUOTES ); |
|
| 1347 | + $str = htmlspecialchars($str, ENT_QUOTES); |
|
| 1348 | + $query = htmlspecialchars($this->last_query, ENT_QUOTES); |
|
| 1349 | 1349 | |
| 1350 | 1350 | printf( |
| 1351 | 1351 | '<div id="error"><p class="wpdberror"><strong>%s</strong> [%s]<br /><code>%s</code></p></div>', |
| 1352 | - __( 'WordPress database error:' ), |
|
| 1352 | + __('WordPress database error:'), |
|
| 1353 | 1353 | $str, |
| 1354 | 1354 | $query |
| 1355 | 1355 | ); |
@@ -1370,7 +1370,7 @@ discard block |
||
| 1370 | 1370 | * @param bool $show Whether to show or hide errors |
| 1371 | 1371 | * @return bool Old value for showing errors. |
| 1372 | 1372 | */ |
| 1373 | - public function show_errors( $show = true ) { |
|
| 1373 | + public function show_errors($show = true) { |
|
| 1374 | 1374 | $errors = $this->show_errors; |
| 1375 | 1375 | $this->show_errors = $show; |
| 1376 | 1376 | return $errors; |
@@ -1403,7 +1403,7 @@ discard block |
||
| 1403 | 1403 | * @param bool $suppress Optional. New value. Defaults to true. |
| 1404 | 1404 | * @return bool Old value |
| 1405 | 1405 | */ |
| 1406 | - public function suppress_errors( $suppress = true ) { |
|
| 1406 | + public function suppress_errors($suppress = true) { |
|
| 1407 | 1407 | $errors = $this->suppress_errors; |
| 1408 | 1408 | $this->suppress_errors = (bool) $suppress; |
| 1409 | 1409 | return $errors; |
@@ -1421,21 +1421,21 @@ discard block |
||
| 1421 | 1421 | $this->rows_affected = $this->num_rows = 0; |
| 1422 | 1422 | $this->last_error = ''; |
| 1423 | 1423 | |
| 1424 | - if ( $this->use_mysqli && $this->result instanceof mysqli_result ) { |
|
| 1425 | - mysqli_free_result( $this->result ); |
|
| 1424 | + if ($this->use_mysqli && $this->result instanceof mysqli_result) { |
|
| 1425 | + mysqli_free_result($this->result); |
|
| 1426 | 1426 | $this->result = null; |
| 1427 | 1427 | |
| 1428 | 1428 | // Sanity check before using the handle |
| 1429 | - if ( empty( $this->dbh ) || !( $this->dbh instanceof mysqli ) ) { |
|
| 1429 | + if (empty($this->dbh) || ! ($this->dbh instanceof mysqli)) { |
|
| 1430 | 1430 | return; |
| 1431 | 1431 | } |
| 1432 | 1432 | |
| 1433 | 1433 | // Clear out any results from a multi-query |
| 1434 | - while ( mysqli_more_results( $this->dbh ) ) { |
|
| 1435 | - mysqli_next_result( $this->dbh ); |
|
| 1434 | + while (mysqli_more_results($this->dbh)) { |
|
| 1435 | + mysqli_next_result($this->dbh); |
|
| 1436 | 1436 | } |
| 1437 | - } elseif ( is_resource( $this->result ) ) { |
|
| 1438 | - mysql_free_result( $this->result ); |
|
| 1437 | + } elseif (is_resource($this->result)) { |
|
| 1438 | + mysql_free_result($this->result); |
|
| 1439 | 1439 | } |
| 1440 | 1440 | } |
| 1441 | 1441 | |
@@ -1451,17 +1451,17 @@ discard block |
||
| 1451 | 1451 | * @param bool $allow_bail Optional. Allows the function to bail. Default true. |
| 1452 | 1452 | * @return bool True with a successful connection, false on failure. |
| 1453 | 1453 | */ |
| 1454 | - public function db_connect( $allow_bail = true ) { |
|
| 1454 | + public function db_connect($allow_bail = true) { |
|
| 1455 | 1455 | $this->is_mysql = true; |
| 1456 | 1456 | |
| 1457 | 1457 | /* |
| 1458 | 1458 | * Deprecated in 3.9+ when using MySQLi. No equivalent |
| 1459 | 1459 | * $new_link parameter exists for mysqli_* functions. |
| 1460 | 1460 | */ |
| 1461 | - $new_link = defined( 'MYSQL_NEW_LINK' ) ? MYSQL_NEW_LINK : true; |
|
| 1462 | - $client_flags = defined( 'MYSQL_CLIENT_FLAGS' ) ? MYSQL_CLIENT_FLAGS : 0; |
|
| 1461 | + $new_link = defined('MYSQL_NEW_LINK') ? MYSQL_NEW_LINK : true; |
|
| 1462 | + $client_flags = defined('MYSQL_CLIENT_FLAGS') ? MYSQL_CLIENT_FLAGS : 0; |
|
| 1463 | 1463 | |
| 1464 | - if ( $this->use_mysqli ) { |
|
| 1464 | + if ($this->use_mysqli) { |
|
| 1465 | 1465 | $this->dbh = mysqli_init(); |
| 1466 | 1466 | |
| 1467 | 1467 | // mysqli_real_connect doesn't support the host param including a port or socket |
@@ -1469,24 +1469,24 @@ discard block |
||
| 1469 | 1469 | $port = null; |
| 1470 | 1470 | $socket = null; |
| 1471 | 1471 | $host = $this->dbhost; |
| 1472 | - $port_or_socket = strstr( $host, ':' ); |
|
| 1473 | - if ( ! empty( $port_or_socket ) ) { |
|
| 1474 | - $host = substr( $host, 0, strpos( $host, ':' ) ); |
|
| 1475 | - $port_or_socket = substr( $port_or_socket, 1 ); |
|
| 1476 | - if ( 0 !== strpos( $port_or_socket, '/' ) ) { |
|
| 1477 | - $port = intval( $port_or_socket ); |
|
| 1478 | - $maybe_socket = strstr( $port_or_socket, ':' ); |
|
| 1479 | - if ( ! empty( $maybe_socket ) ) { |
|
| 1480 | - $socket = substr( $maybe_socket, 1 ); |
|
| 1472 | + $port_or_socket = strstr($host, ':'); |
|
| 1473 | + if ( ! empty($port_or_socket)) { |
|
| 1474 | + $host = substr($host, 0, strpos($host, ':')); |
|
| 1475 | + $port_or_socket = substr($port_or_socket, 1); |
|
| 1476 | + if (0 !== strpos($port_or_socket, '/')) { |
|
| 1477 | + $port = intval($port_or_socket); |
|
| 1478 | + $maybe_socket = strstr($port_or_socket, ':'); |
|
| 1479 | + if ( ! empty($maybe_socket)) { |
|
| 1480 | + $socket = substr($maybe_socket, 1); |
|
| 1481 | 1481 | } |
| 1482 | 1482 | } else { |
| 1483 | 1483 | $socket = $port_or_socket; |
| 1484 | 1484 | } |
| 1485 | 1485 | } |
| 1486 | 1486 | |
| 1487 | - mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags ); |
|
| 1487 | + mysqli_real_connect($this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags); |
|
| 1488 | 1488 | |
| 1489 | - if ( $this->dbh->connect_errno ) { |
|
| 1489 | + if ($this->dbh->connect_errno) { |
|
| 1490 | 1490 | $this->dbh = null; |
| 1491 | 1491 | |
| 1492 | 1492 | /* It's possible ext/mysqli is misconfigured. Fall back to ext/mysql if: |
@@ -1496,68 +1496,68 @@ discard block |
||
| 1496 | 1496 | */ |
| 1497 | 1497 | $attempt_fallback = true; |
| 1498 | 1498 | |
| 1499 | - if ( $this->has_connected ) { |
|
| 1499 | + if ($this->has_connected) { |
|
| 1500 | 1500 | $attempt_fallback = false; |
| 1501 | - } elseif ( defined( 'WP_USE_EXT_MYSQL' ) && ! WP_USE_EXT_MYSQL ) { |
|
| 1501 | + } elseif (defined('WP_USE_EXT_MYSQL') && ! WP_USE_EXT_MYSQL) { |
|
| 1502 | 1502 | $attempt_fallback = false; |
| 1503 | - } elseif ( ! function_exists( 'mysql_connect' ) ) { |
|
| 1503 | + } elseif ( ! function_exists('mysql_connect')) { |
|
| 1504 | 1504 | $attempt_fallback = false; |
| 1505 | 1505 | } |
| 1506 | 1506 | |
| 1507 | - if ( $attempt_fallback ) { |
|
| 1507 | + if ($attempt_fallback) { |
|
| 1508 | 1508 | $this->use_mysqli = false; |
| 1509 | - return $this->db_connect( $allow_bail ); |
|
| 1509 | + return $this->db_connect($allow_bail); |
|
| 1510 | 1510 | } |
| 1511 | 1511 | } |
| 1512 | 1512 | } else { |
| 1513 | - $this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags ); |
|
| 1513 | + $this->dbh = mysql_connect($this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags); |
|
| 1514 | 1514 | } |
| 1515 | 1515 | |
| 1516 | - if ( ! $this->dbh && $allow_bail ) { |
|
| 1516 | + if ( ! $this->dbh && $allow_bail) { |
|
| 1517 | 1517 | wp_load_translations_early(); |
| 1518 | 1518 | |
| 1519 | 1519 | // Load custom DB error template, if present. |
| 1520 | - if ( file_exists( WP_CONTENT_DIR . '/db-error.php' ) ) { |
|
| 1521 | - require_once( WP_CONTENT_DIR . '/db-error.php' ); |
|
| 1520 | + if (file_exists(WP_CONTENT_DIR.'/db-error.php')) { |
|
| 1521 | + require_once(WP_CONTENT_DIR.'/db-error.php'); |
|
| 1522 | 1522 | die(); |
| 1523 | 1523 | } |
| 1524 | 1524 | |
| 1525 | - $message = '<h1>' . __( 'Error establishing a database connection' ) . "</h1>\n"; |
|
| 1525 | + $message = '<h1>'.__('Error establishing a database connection')."</h1>\n"; |
|
| 1526 | 1526 | |
| 1527 | - $message .= '<p>' . sprintf( |
|
| 1527 | + $message .= '<p>'.sprintf( |
|
| 1528 | 1528 | /* translators: 1: wp-config.php. 2: database host */ |
| 1529 | - __( 'This either means that the username and password information in your %1$s file is incorrect or we can’t contact the database server at %2$s. This could mean your host’s database server is down.' ), |
|
| 1529 | + __('This either means that the username and password information in your %1$s file is incorrect or we can’t contact the database server at %2$s. This could mean your host’s database server is down.'), |
|
| 1530 | 1530 | '<code>wp-config.php</code>', |
| 1531 | - '<code>' . htmlspecialchars( $this->dbhost, ENT_QUOTES ) . '</code>' |
|
| 1532 | - ) . "</p>\n"; |
|
| 1531 | + '<code>'.htmlspecialchars($this->dbhost, ENT_QUOTES).'</code>' |
|
| 1532 | + )."</p>\n"; |
|
| 1533 | 1533 | |
| 1534 | 1534 | $message .= "<ul>\n"; |
| 1535 | - $message .= '<li>' . __( 'Are you sure you have the correct username and password?' ) . "</li>\n"; |
|
| 1536 | - $message .= '<li>' . __( 'Are you sure that you have typed the correct hostname?' ) . "</li>\n"; |
|
| 1537 | - $message .= '<li>' . __( 'Are you sure that the database server is running?' ) . "</li>\n"; |
|
| 1535 | + $message .= '<li>'.__('Are you sure you have the correct username and password?')."</li>\n"; |
|
| 1536 | + $message .= '<li>'.__('Are you sure that you have typed the correct hostname?')."</li>\n"; |
|
| 1537 | + $message .= '<li>'.__('Are you sure that the database server is running?')."</li>\n"; |
|
| 1538 | 1538 | $message .= "</ul>\n"; |
| 1539 | 1539 | |
| 1540 | - $message .= '<p>' . sprintf( |
|
| 1540 | + $message .= '<p>'.sprintf( |
|
| 1541 | 1541 | /* translators: %s: support forums URL */ |
| 1542 | - __( 'If you’re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href="%s">WordPress Support Forums</a>.' ), |
|
| 1543 | - __( 'https://wordpress.org/support/' ) |
|
| 1544 | - ) . "</p>\n"; |
|
| 1542 | + __('If you’re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href="%s">WordPress Support Forums</a>.'), |
|
| 1543 | + __('https://wordpress.org/support/') |
|
| 1544 | + )."</p>\n"; |
|
| 1545 | 1545 | |
| 1546 | - $this->bail( $message, 'db_connect_fail' ); |
|
| 1546 | + $this->bail($message, 'db_connect_fail'); |
|
| 1547 | 1547 | |
| 1548 | 1548 | return false; |
| 1549 | - } elseif ( $this->dbh ) { |
|
| 1550 | - if ( ! $this->has_connected ) { |
|
| 1549 | + } elseif ($this->dbh) { |
|
| 1550 | + if ( ! $this->has_connected) { |
|
| 1551 | 1551 | $this->init_charset(); |
| 1552 | 1552 | } |
| 1553 | 1553 | |
| 1554 | 1554 | $this->has_connected = true; |
| 1555 | 1555 | |
| 1556 | - $this->set_charset( $this->dbh ); |
|
| 1556 | + $this->set_charset($this->dbh); |
|
| 1557 | 1557 | |
| 1558 | 1558 | $this->ready = true; |
| 1559 | 1559 | $this->set_sql_mode(); |
| 1560 | - $this->select( $this->dbname, $this->dbh ); |
|
| 1560 | + $this->select($this->dbname, $this->dbh); |
|
| 1561 | 1561 | |
| 1562 | 1562 | return true; |
| 1563 | 1563 | } |
@@ -1579,13 +1579,13 @@ discard block |
||
| 1579 | 1579 | * @param bool $allow_bail Optional. Allows the function to bail. Default true. |
| 1580 | 1580 | * @return bool|void True if the connection is up. |
| 1581 | 1581 | */ |
| 1582 | - public function check_connection( $allow_bail = true ) { |
|
| 1583 | - if ( $this->use_mysqli ) { |
|
| 1584 | - if ( ! empty( $this->dbh ) && mysqli_ping( $this->dbh ) ) { |
|
| 1582 | + public function check_connection($allow_bail = true) { |
|
| 1583 | + if ($this->use_mysqli) { |
|
| 1584 | + if ( ! empty($this->dbh) && mysqli_ping($this->dbh)) { |
|
| 1585 | 1585 | return true; |
| 1586 | 1586 | } |
| 1587 | 1587 | } else { |
| 1588 | - if ( ! empty( $this->dbh ) && mysql_ping( $this->dbh ) ) { |
|
| 1588 | + if ( ! empty($this->dbh) && mysql_ping($this->dbh)) { |
|
| 1589 | 1589 | return true; |
| 1590 | 1590 | } |
| 1591 | 1591 | } |
@@ -1593,62 +1593,62 @@ discard block |
||
| 1593 | 1593 | $error_reporting = false; |
| 1594 | 1594 | |
| 1595 | 1595 | // Disable warnings, as we don't want to see a multitude of "unable to connect" messages |
| 1596 | - if ( WP_DEBUG ) { |
|
| 1596 | + if (WP_DEBUG) { |
|
| 1597 | 1597 | $error_reporting = error_reporting(); |
| 1598 | - error_reporting( $error_reporting & ~E_WARNING ); |
|
| 1598 | + error_reporting($error_reporting & ~E_WARNING); |
|
| 1599 | 1599 | } |
| 1600 | 1600 | |
| 1601 | - for ( $tries = 1; $tries <= $this->reconnect_retries; $tries++ ) { |
|
| 1601 | + for ($tries = 1; $tries <= $this->reconnect_retries; $tries++) { |
|
| 1602 | 1602 | // On the last try, re-enable warnings. We want to see a single instance of the |
| 1603 | 1603 | // "unable to connect" message on the bail() screen, if it appears. |
| 1604 | - if ( $this->reconnect_retries === $tries && WP_DEBUG ) { |
|
| 1605 | - error_reporting( $error_reporting ); |
|
| 1604 | + if ($this->reconnect_retries === $tries && WP_DEBUG) { |
|
| 1605 | + error_reporting($error_reporting); |
|
| 1606 | 1606 | } |
| 1607 | 1607 | |
| 1608 | - if ( $this->db_connect( false ) ) { |
|
| 1609 | - if ( $error_reporting ) { |
|
| 1610 | - error_reporting( $error_reporting ); |
|
| 1608 | + if ($this->db_connect(false)) { |
|
| 1609 | + if ($error_reporting) { |
|
| 1610 | + error_reporting($error_reporting); |
|
| 1611 | 1611 | } |
| 1612 | 1612 | |
| 1613 | 1613 | return true; |
| 1614 | 1614 | } |
| 1615 | 1615 | |
| 1616 | - sleep( 1 ); |
|
| 1616 | + sleep(1); |
|
| 1617 | 1617 | } |
| 1618 | 1618 | |
| 1619 | 1619 | // If template_redirect has already happened, it's too late for wp_die()/dead_db(). |
| 1620 | 1620 | // Let's just return and hope for the best. |
| 1621 | - if ( did_action( 'template_redirect' ) ) { |
|
| 1621 | + if (did_action('template_redirect')) { |
|
| 1622 | 1622 | return false; |
| 1623 | 1623 | } |
| 1624 | 1624 | |
| 1625 | - if ( ! $allow_bail ) { |
|
| 1625 | + if ( ! $allow_bail) { |
|
| 1626 | 1626 | return false; |
| 1627 | 1627 | } |
| 1628 | 1628 | |
| 1629 | 1629 | wp_load_translations_early(); |
| 1630 | 1630 | |
| 1631 | - $message = '<h1>' . __( 'Error reconnecting to the database' ) . "</h1>\n"; |
|
| 1631 | + $message = '<h1>'.__('Error reconnecting to the database')."</h1>\n"; |
|
| 1632 | 1632 | |
| 1633 | - $message .= '<p>' . sprintf( |
|
| 1633 | + $message .= '<p>'.sprintf( |
|
| 1634 | 1634 | /* translators: %s: database host */ |
| 1635 | - __( 'This means that we lost contact with the database server at %s. This could mean your host’s database server is down.' ), |
|
| 1636 | - '<code>' . htmlspecialchars( $this->dbhost, ENT_QUOTES ) . '</code>' |
|
| 1637 | - ) . "</p>\n"; |
|
| 1635 | + __('This means that we lost contact with the database server at %s. This could mean your host’s database server is down.'), |
|
| 1636 | + '<code>'.htmlspecialchars($this->dbhost, ENT_QUOTES).'</code>' |
|
| 1637 | + )."</p>\n"; |
|
| 1638 | 1638 | |
| 1639 | 1639 | $message .= "<ul>\n"; |
| 1640 | - $message .= '<li>' . __( 'Are you sure that the database server is running?' ) . "</li>\n"; |
|
| 1641 | - $message .= '<li>' . __( 'Are you sure that the database server is not under particularly heavy load?' ) . "</li>\n"; |
|
| 1640 | + $message .= '<li>'.__('Are you sure that the database server is running?')."</li>\n"; |
|
| 1641 | + $message .= '<li>'.__('Are you sure that the database server is not under particularly heavy load?')."</li>\n"; |
|
| 1642 | 1642 | $message .= "</ul>\n"; |
| 1643 | 1643 | |
| 1644 | - $message .= '<p>' . sprintf( |
|
| 1644 | + $message .= '<p>'.sprintf( |
|
| 1645 | 1645 | /* translators: %s: support forums URL */ |
| 1646 | - __( 'If you’re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href="%s">WordPress Support Forums</a>.' ), |
|
| 1647 | - __( 'https://wordpress.org/support/' ) |
|
| 1648 | - ) . "</p>\n"; |
|
| 1646 | + __('If you’re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href="%s">WordPress Support Forums</a>.'), |
|
| 1647 | + __('https://wordpress.org/support/') |
|
| 1648 | + )."</p>\n"; |
|
| 1649 | 1649 | |
| 1650 | 1650 | // We weren't able to reconnect, so we better bail. |
| 1651 | - $this->bail( $message, 'db_connect_fail' ); |
|
| 1651 | + $this->bail($message, 'db_connect_fail'); |
|
| 1652 | 1652 | |
| 1653 | 1653 | // Call dead_db() if bail didn't die, because this database is no more. It has ceased to be (at least temporarily). |
| 1654 | 1654 | dead_db(); |
@@ -1664,8 +1664,8 @@ discard block |
||
| 1664 | 1664 | * @param string $query Database query |
| 1665 | 1665 | * @return int|false Number of rows affected/selected or false on error |
| 1666 | 1666 | */ |
| 1667 | - public function query( $query ) { |
|
| 1668 | - if ( ! $this->ready ) { |
|
| 1667 | + public function query($query) { |
|
| 1668 | + if ( ! $this->ready) { |
|
| 1669 | 1669 | $this->check_current_query = true; |
| 1670 | 1670 | return false; |
| 1671 | 1671 | } |
@@ -1680,7 +1680,7 @@ discard block |
||
| 1680 | 1680 | * |
| 1681 | 1681 | * @param string $query Database query. |
| 1682 | 1682 | */ |
| 1683 | - $query = apply_filters( 'query', $query ); |
|
| 1683 | + $query = apply_filters('query', $query); |
|
| 1684 | 1684 | |
| 1685 | 1685 | $this->flush(); |
| 1686 | 1686 | |
@@ -1688,12 +1688,12 @@ discard block |
||
| 1688 | 1688 | $this->func_call = "\$db->query(\"$query\")"; |
| 1689 | 1689 | |
| 1690 | 1690 | // If we're writing to the database, make sure the query will write safely. |
| 1691 | - if ( $this->check_current_query && ! $this->check_ascii( $query ) ) { |
|
| 1692 | - $stripped_query = $this->strip_invalid_text_from_query( $query ); |
|
| 1691 | + if ($this->check_current_query && ! $this->check_ascii($query)) { |
|
| 1692 | + $stripped_query = $this->strip_invalid_text_from_query($query); |
|
| 1693 | 1693 | // strip_invalid_text_from_query() can perform queries, so we need |
| 1694 | 1694 | // to flush again, just to make sure everything is clear. |
| 1695 | 1695 | $this->flush(); |
| 1696 | - if ( $stripped_query !== $query ) { |
|
| 1696 | + if ($stripped_query !== $query) { |
|
| 1697 | 1697 | $this->insert_id = 0; |
| 1698 | 1698 | return false; |
| 1699 | 1699 | } |
@@ -1704,21 +1704,21 @@ discard block |
||
| 1704 | 1704 | // Keep track of the last query for debug.. |
| 1705 | 1705 | $this->last_query = $query; |
| 1706 | 1706 | |
| 1707 | - $this->_do_query( $query ); |
|
| 1707 | + $this->_do_query($query); |
|
| 1708 | 1708 | |
| 1709 | 1709 | // MySQL server has gone away, try to reconnect |
| 1710 | 1710 | $mysql_errno = 0; |
| 1711 | - if ( ! empty( $this->dbh ) ) { |
|
| 1712 | - if ( $this->use_mysqli ) { |
|
| 1713 | - $mysql_errno = mysqli_errno( $this->dbh ); |
|
| 1711 | + if ( ! empty($this->dbh)) { |
|
| 1712 | + if ($this->use_mysqli) { |
|
| 1713 | + $mysql_errno = mysqli_errno($this->dbh); |
|
| 1714 | 1714 | } else { |
| 1715 | - $mysql_errno = mysql_errno( $this->dbh ); |
|
| 1715 | + $mysql_errno = mysql_errno($this->dbh); |
|
| 1716 | 1716 | } |
| 1717 | 1717 | } |
| 1718 | 1718 | |
| 1719 | - if ( empty( $this->dbh ) || 2006 == $mysql_errno ) { |
|
| 1720 | - if ( $this->check_connection() ) { |
|
| 1721 | - $this->_do_query( $query ); |
|
| 1719 | + if (empty($this->dbh) || 2006 == $mysql_errno) { |
|
| 1720 | + if ($this->check_connection()) { |
|
| 1721 | + $this->_do_query($query); |
|
| 1722 | 1722 | } else { |
| 1723 | 1723 | $this->insert_id = 0; |
| 1724 | 1724 | return false; |
@@ -1726,48 +1726,48 @@ discard block |
||
| 1726 | 1726 | } |
| 1727 | 1727 | |
| 1728 | 1728 | // If there is an error then take note of it.. |
| 1729 | - if ( $this->use_mysqli ) { |
|
| 1730 | - $this->last_error = mysqli_error( $this->dbh ); |
|
| 1729 | + if ($this->use_mysqli) { |
|
| 1730 | + $this->last_error = mysqli_error($this->dbh); |
|
| 1731 | 1731 | } else { |
| 1732 | - $this->last_error = mysql_error( $this->dbh ); |
|
| 1732 | + $this->last_error = mysql_error($this->dbh); |
|
| 1733 | 1733 | } |
| 1734 | 1734 | |
| 1735 | - if ( $this->last_error ) { |
|
| 1735 | + if ($this->last_error) { |
|
| 1736 | 1736 | // Clear insert_id on a subsequent failed insert. |
| 1737 | - if ( $this->insert_id && preg_match( '/^\s*(insert|replace)\s/i', $query ) ) |
|
| 1737 | + if ($this->insert_id && preg_match('/^\s*(insert|replace)\s/i', $query)) |
|
| 1738 | 1738 | $this->insert_id = 0; |
| 1739 | 1739 | |
| 1740 | 1740 | $this->print_error(); |
| 1741 | 1741 | return false; |
| 1742 | 1742 | } |
| 1743 | 1743 | |
| 1744 | - if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) { |
|
| 1744 | + if (preg_match('/^\s*(create|alter|truncate|drop)\s/i', $query)) { |
|
| 1745 | 1745 | $return_val = $this->result; |
| 1746 | - } elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) { |
|
| 1747 | - if ( $this->use_mysqli ) { |
|
| 1748 | - $this->rows_affected = mysqli_affected_rows( $this->dbh ); |
|
| 1746 | + } elseif (preg_match('/^\s*(insert|delete|update|replace)\s/i', $query)) { |
|
| 1747 | + if ($this->use_mysqli) { |
|
| 1748 | + $this->rows_affected = mysqli_affected_rows($this->dbh); |
|
| 1749 | 1749 | } else { |
| 1750 | - $this->rows_affected = mysql_affected_rows( $this->dbh ); |
|
| 1750 | + $this->rows_affected = mysql_affected_rows($this->dbh); |
|
| 1751 | 1751 | } |
| 1752 | 1752 | // Take note of the insert_id |
| 1753 | - if ( preg_match( '/^\s*(insert|replace)\s/i', $query ) ) { |
|
| 1754 | - if ( $this->use_mysqli ) { |
|
| 1755 | - $this->insert_id = mysqli_insert_id( $this->dbh ); |
|
| 1753 | + if (preg_match('/^\s*(insert|replace)\s/i', $query)) { |
|
| 1754 | + if ($this->use_mysqli) { |
|
| 1755 | + $this->insert_id = mysqli_insert_id($this->dbh); |
|
| 1756 | 1756 | } else { |
| 1757 | - $this->insert_id = mysql_insert_id( $this->dbh ); |
|
| 1757 | + $this->insert_id = mysql_insert_id($this->dbh); |
|
| 1758 | 1758 | } |
| 1759 | 1759 | } |
| 1760 | 1760 | // Return number of rows affected |
| 1761 | 1761 | $return_val = $this->rows_affected; |
| 1762 | 1762 | } else { |
| 1763 | 1763 | $num_rows = 0; |
| 1764 | - if ( $this->use_mysqli && $this->result instanceof mysqli_result ) { |
|
| 1765 | - while ( $row = mysqli_fetch_object( $this->result ) ) { |
|
| 1764 | + if ($this->use_mysqli && $this->result instanceof mysqli_result) { |
|
| 1765 | + while ($row = mysqli_fetch_object($this->result)) { |
|
| 1766 | 1766 | $this->last_result[$num_rows] = $row; |
| 1767 | 1767 | $num_rows++; |
| 1768 | 1768 | } |
| 1769 | - } elseif ( is_resource( $this->result ) ) { |
|
| 1770 | - while ( $row = mysql_fetch_object( $this->result ) ) { |
|
| 1769 | + } elseif (is_resource($this->result)) { |
|
| 1770 | + while ($row = mysql_fetch_object($this->result)) { |
|
| 1771 | 1771 | $this->last_result[$num_rows] = $row; |
| 1772 | 1772 | $num_rows++; |
| 1773 | 1773 | } |
@@ -1792,20 +1792,20 @@ discard block |
||
| 1792 | 1792 | * |
| 1793 | 1793 | * @param string $query The query to run. |
| 1794 | 1794 | */ |
| 1795 | - private function _do_query( $query ) { |
|
| 1796 | - if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) { |
|
| 1795 | + private function _do_query($query) { |
|
| 1796 | + if (defined('SAVEQUERIES') && SAVEQUERIES) { |
|
| 1797 | 1797 | $this->timer_start(); |
| 1798 | 1798 | } |
| 1799 | 1799 | |
| 1800 | - if ( ! empty( $this->dbh ) && $this->use_mysqli ) { |
|
| 1801 | - $this->result = mysqli_query( $this->dbh, $query ); |
|
| 1802 | - } elseif ( ! empty( $this->dbh ) ) { |
|
| 1803 | - $this->result = mysql_query( $query, $this->dbh ); |
|
| 1800 | + if ( ! empty($this->dbh) && $this->use_mysqli) { |
|
| 1801 | + $this->result = mysqli_query($this->dbh, $query); |
|
| 1802 | + } elseif ( ! empty($this->dbh)) { |
|
| 1803 | + $this->result = mysql_query($query, $this->dbh); |
|
| 1804 | 1804 | } |
| 1805 | 1805 | $this->num_queries++; |
| 1806 | 1806 | |
| 1807 | - if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) { |
|
| 1808 | - $this->queries[] = array( $query, $this->timer_stop(), $this->get_caller() ); |
|
| 1807 | + if (defined('SAVEQUERIES') && SAVEQUERIES) { |
|
| 1808 | + $this->queries[] = array($query, $this->timer_stop(), $this->get_caller()); |
|
| 1809 | 1809 | } |
| 1810 | 1810 | } |
| 1811 | 1811 | |
@@ -1830,8 +1830,8 @@ discard block |
||
| 1830 | 1830 | * If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types. |
| 1831 | 1831 | * @return int|false The number of rows inserted, or false on error. |
| 1832 | 1832 | */ |
| 1833 | - public function insert( $table, $data, $format = null ) { |
|
| 1834 | - return $this->_insert_replace_helper( $table, $data, $format, 'INSERT' ); |
|
| 1833 | + public function insert($table, $data, $format = null) { |
|
| 1834 | + return $this->_insert_replace_helper($table, $data, $format, 'INSERT'); |
|
| 1835 | 1835 | } |
| 1836 | 1836 | |
| 1837 | 1837 | /** |
@@ -1855,8 +1855,8 @@ discard block |
||
| 1855 | 1855 | * If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types. |
| 1856 | 1856 | * @return int|false The number of rows affected, or false on error. |
| 1857 | 1857 | */ |
| 1858 | - public function replace( $table, $data, $format = null ) { |
|
| 1859 | - return $this->_insert_replace_helper( $table, $data, $format, 'REPLACE' ); |
|
| 1858 | + public function replace($table, $data, $format = null) { |
|
| 1859 | + return $this->_insert_replace_helper($table, $data, $format, 'REPLACE'); |
|
| 1860 | 1860 | } |
| 1861 | 1861 | |
| 1862 | 1862 | /** |
@@ -1881,21 +1881,21 @@ discard block |
||
| 1881 | 1881 | * @param string $type Optional. What type of operation is this? INSERT or REPLACE. Defaults to INSERT. |
| 1882 | 1882 | * @return int|false The number of rows affected, or false on error. |
| 1883 | 1883 | */ |
| 1884 | - function _insert_replace_helper( $table, $data, $format = null, $type = 'INSERT' ) { |
|
| 1884 | + function _insert_replace_helper($table, $data, $format = null, $type = 'INSERT') { |
|
| 1885 | 1885 | $this->insert_id = 0; |
| 1886 | 1886 | |
| 1887 | - if ( ! in_array( strtoupper( $type ), array( 'REPLACE', 'INSERT' ) ) ) { |
|
| 1887 | + if ( ! in_array(strtoupper($type), array('REPLACE', 'INSERT'))) { |
|
| 1888 | 1888 | return false; |
| 1889 | 1889 | } |
| 1890 | 1890 | |
| 1891 | - $data = $this->process_fields( $table, $data, $format ); |
|
| 1892 | - if ( false === $data ) { |
|
| 1891 | + $data = $this->process_fields($table, $data, $format); |
|
| 1892 | + if (false === $data) { |
|
| 1893 | 1893 | return false; |
| 1894 | 1894 | } |
| 1895 | 1895 | |
| 1896 | 1896 | $formats = $values = array(); |
| 1897 | - foreach ( $data as $value ) { |
|
| 1898 | - if ( is_null( $value['value'] ) ) { |
|
| 1897 | + foreach ($data as $value) { |
|
| 1898 | + if (is_null($value['value'])) { |
|
| 1899 | 1899 | $formats[] = 'NULL'; |
| 1900 | 1900 | continue; |
| 1901 | 1901 | } |
@@ -1904,13 +1904,13 @@ discard block |
||
| 1904 | 1904 | $values[] = $value['value']; |
| 1905 | 1905 | } |
| 1906 | 1906 | |
| 1907 | - $fields = '`' . implode( '`, `', array_keys( $data ) ) . '`'; |
|
| 1908 | - $formats = implode( ', ', $formats ); |
|
| 1907 | + $fields = '`'.implode('`, `', array_keys($data)).'`'; |
|
| 1908 | + $formats = implode(', ', $formats); |
|
| 1909 | 1909 | |
| 1910 | 1910 | $sql = "$type INTO `$table` ($fields) VALUES ($formats)"; |
| 1911 | 1911 | |
| 1912 | 1912 | $this->check_current_query = false; |
| 1913 | - return $this->query( $this->prepare( $sql, $values ) ); |
|
| 1913 | + return $this->query($this->prepare($sql, $values)); |
|
| 1914 | 1914 | } |
| 1915 | 1915 | |
| 1916 | 1916 | /** |
@@ -1943,47 +1943,47 @@ discard block |
||
| 1943 | 1943 | * If omitted, all values in $where will be treated as strings. |
| 1944 | 1944 | * @return int|false The number of rows updated, or false on error. |
| 1945 | 1945 | */ |
| 1946 | - public function update( $table, $data, $where, $format = null, $where_format = null ) { |
|
| 1947 | - if ( ! is_array( $data ) || ! is_array( $where ) ) { |
|
| 1946 | + public function update($table, $data, $where, $format = null, $where_format = null) { |
|
| 1947 | + if ( ! is_array($data) || ! is_array($where)) { |
|
| 1948 | 1948 | return false; |
| 1949 | 1949 | } |
| 1950 | 1950 | |
| 1951 | - $data = $this->process_fields( $table, $data, $format ); |
|
| 1952 | - if ( false === $data ) { |
|
| 1951 | + $data = $this->process_fields($table, $data, $format); |
|
| 1952 | + if (false === $data) { |
|
| 1953 | 1953 | return false; |
| 1954 | 1954 | } |
| 1955 | - $where = $this->process_fields( $table, $where, $where_format ); |
|
| 1956 | - if ( false === $where ) { |
|
| 1955 | + $where = $this->process_fields($table, $where, $where_format); |
|
| 1956 | + if (false === $where) { |
|
| 1957 | 1957 | return false; |
| 1958 | 1958 | } |
| 1959 | 1959 | |
| 1960 | 1960 | $fields = $conditions = $values = array(); |
| 1961 | - foreach ( $data as $field => $value ) { |
|
| 1962 | - if ( is_null( $value['value'] ) ) { |
|
| 1961 | + foreach ($data as $field => $value) { |
|
| 1962 | + if (is_null($value['value'])) { |
|
| 1963 | 1963 | $fields[] = "`$field` = NULL"; |
| 1964 | 1964 | continue; |
| 1965 | 1965 | } |
| 1966 | 1966 | |
| 1967 | - $fields[] = "`$field` = " . $value['format']; |
|
| 1967 | + $fields[] = "`$field` = ".$value['format']; |
|
| 1968 | 1968 | $values[] = $value['value']; |
| 1969 | 1969 | } |
| 1970 | - foreach ( $where as $field => $value ) { |
|
| 1971 | - if ( is_null( $value['value'] ) ) { |
|
| 1970 | + foreach ($where as $field => $value) { |
|
| 1971 | + if (is_null($value['value'])) { |
|
| 1972 | 1972 | $conditions[] = "`$field` IS NULL"; |
| 1973 | 1973 | continue; |
| 1974 | 1974 | } |
| 1975 | 1975 | |
| 1976 | - $conditions[] = "`$field` = " . $value['format']; |
|
| 1976 | + $conditions[] = "`$field` = ".$value['format']; |
|
| 1977 | 1977 | $values[] = $value['value']; |
| 1978 | 1978 | } |
| 1979 | 1979 | |
| 1980 | - $fields = implode( ', ', $fields ); |
|
| 1981 | - $conditions = implode( ' AND ', $conditions ); |
|
| 1980 | + $fields = implode(', ', $fields); |
|
| 1981 | + $conditions = implode(' AND ', $conditions); |
|
| 1982 | 1982 | |
| 1983 | 1983 | $sql = "UPDATE `$table` SET $fields WHERE $conditions"; |
| 1984 | 1984 | |
| 1985 | 1985 | $this->check_current_query = false; |
| 1986 | - return $this->query( $this->prepare( $sql, $values ) ); |
|
| 1986 | + return $this->query($this->prepare($sql, $values)); |
|
| 1987 | 1987 | } |
| 1988 | 1988 | |
| 1989 | 1989 | /** |
@@ -2008,33 +2008,33 @@ discard block |
||
| 2008 | 2008 | * If omitted, all values in $where will be treated as strings unless otherwise specified in wpdb::$field_types. |
| 2009 | 2009 | * @return int|false The number of rows updated, or false on error. |
| 2010 | 2010 | */ |
| 2011 | - public function delete( $table, $where, $where_format = null ) { |
|
| 2012 | - if ( ! is_array( $where ) ) { |
|
| 2011 | + public function delete($table, $where, $where_format = null) { |
|
| 2012 | + if ( ! is_array($where)) { |
|
| 2013 | 2013 | return false; |
| 2014 | 2014 | } |
| 2015 | 2015 | |
| 2016 | - $where = $this->process_fields( $table, $where, $where_format ); |
|
| 2017 | - if ( false === $where ) { |
|
| 2016 | + $where = $this->process_fields($table, $where, $where_format); |
|
| 2017 | + if (false === $where) { |
|
| 2018 | 2018 | return false; |
| 2019 | 2019 | } |
| 2020 | 2020 | |
| 2021 | 2021 | $conditions = $values = array(); |
| 2022 | - foreach ( $where as $field => $value ) { |
|
| 2023 | - if ( is_null( $value['value'] ) ) { |
|
| 2022 | + foreach ($where as $field => $value) { |
|
| 2023 | + if (is_null($value['value'])) { |
|
| 2024 | 2024 | $conditions[] = "`$field` IS NULL"; |
| 2025 | 2025 | continue; |
| 2026 | 2026 | } |
| 2027 | 2027 | |
| 2028 | - $conditions[] = "`$field` = " . $value['format']; |
|
| 2028 | + $conditions[] = "`$field` = ".$value['format']; |
|
| 2029 | 2029 | $values[] = $value['value']; |
| 2030 | 2030 | } |
| 2031 | 2031 | |
| 2032 | - $conditions = implode( ' AND ', $conditions ); |
|
| 2032 | + $conditions = implode(' AND ', $conditions); |
|
| 2033 | 2033 | |
| 2034 | 2034 | $sql = "DELETE FROM `$table` WHERE $conditions"; |
| 2035 | 2035 | |
| 2036 | 2036 | $this->check_current_query = false; |
| 2037 | - return $this->query( $this->prepare( $sql, $values ) ); |
|
| 2037 | + return $this->query($this->prepare($sql, $values)); |
|
| 2038 | 2038 | } |
| 2039 | 2039 | |
| 2040 | 2040 | /** |
@@ -2055,25 +2055,25 @@ discard block |
||
| 2055 | 2055 | * @return array|false Returns an array of fields that contain paired values |
| 2056 | 2056 | * and formats. Returns false for invalid values. |
| 2057 | 2057 | */ |
| 2058 | - protected function process_fields( $table, $data, $format ) { |
|
| 2059 | - $data = $this->process_field_formats( $data, $format ); |
|
| 2060 | - if ( false === $data ) { |
|
| 2058 | + protected function process_fields($table, $data, $format) { |
|
| 2059 | + $data = $this->process_field_formats($data, $format); |
|
| 2060 | + if (false === $data) { |
|
| 2061 | 2061 | return false; |
| 2062 | 2062 | } |
| 2063 | 2063 | |
| 2064 | - $data = $this->process_field_charsets( $data, $table ); |
|
| 2065 | - if ( false === $data ) { |
|
| 2064 | + $data = $this->process_field_charsets($data, $table); |
|
| 2065 | + if (false === $data) { |
|
| 2066 | 2066 | return false; |
| 2067 | 2067 | } |
| 2068 | 2068 | |
| 2069 | - $data = $this->process_field_lengths( $data, $table ); |
|
| 2070 | - if ( false === $data ) { |
|
| 2069 | + $data = $this->process_field_lengths($data, $table); |
|
| 2070 | + if (false === $data) { |
|
| 2071 | 2071 | return false; |
| 2072 | 2072 | } |
| 2073 | 2073 | |
| 2074 | - $converted_data = $this->strip_invalid_text( $data ); |
|
| 2074 | + $converted_data = $this->strip_invalid_text($data); |
|
| 2075 | 2075 | |
| 2076 | - if ( $data !== $converted_data ) { |
|
| 2076 | + if ($data !== $converted_data) { |
|
| 2077 | 2077 | return false; |
| 2078 | 2078 | } |
| 2079 | 2079 | |
@@ -2091,25 +2091,25 @@ discard block |
||
| 2091 | 2091 | * @return array Array, keyed by field names with values being an array |
| 2092 | 2092 | * of 'value' and 'format' keys. |
| 2093 | 2093 | */ |
| 2094 | - protected function process_field_formats( $data, $format ) { |
|
| 2094 | + protected function process_field_formats($data, $format) { |
|
| 2095 | 2095 | $formats = $original_formats = (array) $format; |
| 2096 | 2096 | |
| 2097 | - foreach ( $data as $field => $value ) { |
|
| 2097 | + foreach ($data as $field => $value) { |
|
| 2098 | 2098 | $value = array( |
| 2099 | 2099 | 'value' => $value, |
| 2100 | 2100 | 'format' => '%s', |
| 2101 | 2101 | ); |
| 2102 | 2102 | |
| 2103 | - if ( ! empty( $format ) ) { |
|
| 2104 | - $value['format'] = array_shift( $formats ); |
|
| 2105 | - if ( ! $value['format'] ) { |
|
| 2106 | - $value['format'] = reset( $original_formats ); |
|
| 2103 | + if ( ! empty($format)) { |
|
| 2104 | + $value['format'] = array_shift($formats); |
|
| 2105 | + if ( ! $value['format']) { |
|
| 2106 | + $value['format'] = reset($original_formats); |
|
| 2107 | 2107 | } |
| 2108 | - } elseif ( isset( $this->field_types[ $field ] ) ) { |
|
| 2109 | - $value['format'] = $this->field_types[ $field ]; |
|
| 2108 | + } elseif (isset($this->field_types[$field])) { |
|
| 2109 | + $value['format'] = $this->field_types[$field]; |
|
| 2110 | 2110 | } |
| 2111 | 2111 | |
| 2112 | - $data[ $field ] = $value; |
|
| 2112 | + $data[$field] = $value; |
|
| 2113 | 2113 | } |
| 2114 | 2114 | |
| 2115 | 2115 | return $data; |
@@ -2126,22 +2126,22 @@ discard block |
||
| 2126 | 2126 | * @param string $table Table name. |
| 2127 | 2127 | * @return array|false The same array as $data with additional 'charset' keys. |
| 2128 | 2128 | */ |
| 2129 | - protected function process_field_charsets( $data, $table ) { |
|
| 2130 | - foreach ( $data as $field => $value ) { |
|
| 2131 | - if ( '%d' === $value['format'] || '%f' === $value['format'] ) { |
|
| 2129 | + protected function process_field_charsets($data, $table) { |
|
| 2130 | + foreach ($data as $field => $value) { |
|
| 2131 | + if ('%d' === $value['format'] || '%f' === $value['format']) { |
|
| 2132 | 2132 | /* |
| 2133 | 2133 | * We can skip this field if we know it isn't a string. |
| 2134 | 2134 | * This checks %d/%f versus ! %s because its sprintf() could take more. |
| 2135 | 2135 | */ |
| 2136 | 2136 | $value['charset'] = false; |
| 2137 | 2137 | } else { |
| 2138 | - $value['charset'] = $this->get_col_charset( $table, $field ); |
|
| 2139 | - if ( is_wp_error( $value['charset'] ) ) { |
|
| 2138 | + $value['charset'] = $this->get_col_charset($table, $field); |
|
| 2139 | + if (is_wp_error($value['charset'])) { |
|
| 2140 | 2140 | return false; |
| 2141 | 2141 | } |
| 2142 | 2142 | } |
| 2143 | 2143 | |
| 2144 | - $data[ $field ] = $value; |
|
| 2144 | + $data[$field] = $value; |
|
| 2145 | 2145 | } |
| 2146 | 2146 | |
| 2147 | 2147 | return $data; |
@@ -2158,22 +2158,22 @@ discard block |
||
| 2158 | 2158 | * @return array|false The same array as $data with additional 'length' keys, or false if |
| 2159 | 2159 | * any of the values were too long for their corresponding field. |
| 2160 | 2160 | */ |
| 2161 | - protected function process_field_lengths( $data, $table ) { |
|
| 2162 | - foreach ( $data as $field => $value ) { |
|
| 2163 | - if ( '%d' === $value['format'] || '%f' === $value['format'] ) { |
|
| 2161 | + protected function process_field_lengths($data, $table) { |
|
| 2162 | + foreach ($data as $field => $value) { |
|
| 2163 | + if ('%d' === $value['format'] || '%f' === $value['format']) { |
|
| 2164 | 2164 | /* |
| 2165 | 2165 | * We can skip this field if we know it isn't a string. |
| 2166 | 2166 | * This checks %d/%f versus ! %s because its sprintf() could take more. |
| 2167 | 2167 | */ |
| 2168 | 2168 | $value['length'] = false; |
| 2169 | 2169 | } else { |
| 2170 | - $value['length'] = $this->get_col_length( $table, $field ); |
|
| 2171 | - if ( is_wp_error( $value['length'] ) ) { |
|
| 2170 | + $value['length'] = $this->get_col_length($table, $field); |
|
| 2171 | + if (is_wp_error($value['length'])) { |
|
| 2172 | 2172 | return false; |
| 2173 | 2173 | } |
| 2174 | 2174 | } |
| 2175 | 2175 | |
| 2176 | - $data[ $field ] = $value; |
|
| 2176 | + $data[$field] = $value; |
|
| 2177 | 2177 | } |
| 2178 | 2178 | |
| 2179 | 2179 | return $data; |
@@ -2193,24 +2193,24 @@ discard block |
||
| 2193 | 2193 | * @param int $y Optional. Row of value to return. Indexed from 0. |
| 2194 | 2194 | * @return string|null Database query result (as string), or null on failure |
| 2195 | 2195 | */ |
| 2196 | - public function get_var( $query = null, $x = 0, $y = 0 ) { |
|
| 2196 | + public function get_var($query = null, $x = 0, $y = 0) { |
|
| 2197 | 2197 | $this->func_call = "\$db->get_var(\"$query\", $x, $y)"; |
| 2198 | 2198 | |
| 2199 | - if ( $this->check_current_query && $this->check_safe_collation( $query ) ) { |
|
| 2199 | + if ($this->check_current_query && $this->check_safe_collation($query)) { |
|
| 2200 | 2200 | $this->check_current_query = false; |
| 2201 | 2201 | } |
| 2202 | 2202 | |
| 2203 | - if ( $query ) { |
|
| 2204 | - $this->query( $query ); |
|
| 2203 | + if ($query) { |
|
| 2204 | + $this->query($query); |
|
| 2205 | 2205 | } |
| 2206 | 2206 | |
| 2207 | 2207 | // Extract var out of cached results based x,y vals |
| 2208 | - if ( !empty( $this->last_result[$y] ) ) { |
|
| 2209 | - $values = array_values( get_object_vars( $this->last_result[$y] ) ); |
|
| 2208 | + if ( ! empty($this->last_result[$y])) { |
|
| 2209 | + $values = array_values(get_object_vars($this->last_result[$y])); |
|
| 2210 | 2210 | } |
| 2211 | 2211 | |
| 2212 | 2212 | // If there is a value return it else return null |
| 2213 | - return ( isset( $values[$x] ) && $values[$x] !== '' ) ? $values[$x] : null; |
|
| 2213 | + return (isset($values[$x]) && $values[$x] !== '') ? $values[$x] : null; |
|
| 2214 | 2214 | } |
| 2215 | 2215 | |
| 2216 | 2216 | /** |
@@ -2228,33 +2228,33 @@ discard block |
||
| 2228 | 2228 | * @param int $y Optional. Row to return. Indexed from 0. |
| 2229 | 2229 | * @return array|object|null|void Database query result in format specified by $output or null on failure |
| 2230 | 2230 | */ |
| 2231 | - public function get_row( $query = null, $output = OBJECT, $y = 0 ) { |
|
| 2231 | + public function get_row($query = null, $output = OBJECT, $y = 0) { |
|
| 2232 | 2232 | $this->func_call = "\$db->get_row(\"$query\",$output,$y)"; |
| 2233 | 2233 | |
| 2234 | - if ( $this->check_current_query && $this->check_safe_collation( $query ) ) { |
|
| 2234 | + if ($this->check_current_query && $this->check_safe_collation($query)) { |
|
| 2235 | 2235 | $this->check_current_query = false; |
| 2236 | 2236 | } |
| 2237 | 2237 | |
| 2238 | - if ( $query ) { |
|
| 2239 | - $this->query( $query ); |
|
| 2238 | + if ($query) { |
|
| 2239 | + $this->query($query); |
|
| 2240 | 2240 | } else { |
| 2241 | 2241 | return null; |
| 2242 | 2242 | } |
| 2243 | 2243 | |
| 2244 | - if ( !isset( $this->last_result[$y] ) ) |
|
| 2244 | + if ( ! isset($this->last_result[$y])) |
|
| 2245 | 2245 | return null; |
| 2246 | 2246 | |
| 2247 | - if ( $output == OBJECT ) { |
|
| 2247 | + if ($output == OBJECT) { |
|
| 2248 | 2248 | return $this->last_result[$y] ? $this->last_result[$y] : null; |
| 2249 | - } elseif ( $output == ARRAY_A ) { |
|
| 2250 | - return $this->last_result[$y] ? get_object_vars( $this->last_result[$y] ) : null; |
|
| 2251 | - } elseif ( $output == ARRAY_N ) { |
|
| 2252 | - return $this->last_result[$y] ? array_values( get_object_vars( $this->last_result[$y] ) ) : null; |
|
| 2253 | - } elseif ( strtoupper( $output ) === OBJECT ) { |
|
| 2249 | + } elseif ($output == ARRAY_A) { |
|
| 2250 | + return $this->last_result[$y] ? get_object_vars($this->last_result[$y]) : null; |
|
| 2251 | + } elseif ($output == ARRAY_N) { |
|
| 2252 | + return $this->last_result[$y] ? array_values(get_object_vars($this->last_result[$y])) : null; |
|
| 2253 | + } elseif (strtoupper($output) === OBJECT) { |
|
| 2254 | 2254 | // Back compat for OBJECT being previously case insensitive. |
| 2255 | 2255 | return $this->last_result[$y] ? $this->last_result[$y] : null; |
| 2256 | 2256 | } else { |
| 2257 | - $this->print_error( " \$db->get_row(string query, output type, int offset) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N" ); |
|
| 2257 | + $this->print_error(" \$db->get_row(string query, output type, int offset) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N"); |
|
| 2258 | 2258 | } |
| 2259 | 2259 | } |
| 2260 | 2260 | |
@@ -2271,19 +2271,19 @@ discard block |
||
| 2271 | 2271 | * @param int $x Optional. Column to return. Indexed from 0. |
| 2272 | 2272 | * @return array Database query result. Array indexed from 0 by SQL result row number. |
| 2273 | 2273 | */ |
| 2274 | - public function get_col( $query = null , $x = 0 ) { |
|
| 2275 | - if ( $this->check_current_query && $this->check_safe_collation( $query ) ) { |
|
| 2274 | + public function get_col($query = null, $x = 0) { |
|
| 2275 | + if ($this->check_current_query && $this->check_safe_collation($query)) { |
|
| 2276 | 2276 | $this->check_current_query = false; |
| 2277 | 2277 | } |
| 2278 | 2278 | |
| 2279 | - if ( $query ) { |
|
| 2280 | - $this->query( $query ); |
|
| 2279 | + if ($query) { |
|
| 2280 | + $this->query($query); |
|
| 2281 | 2281 | } |
| 2282 | 2282 | |
| 2283 | 2283 | $new_array = array(); |
| 2284 | 2284 | // Extract the column values |
| 2285 | - for ( $i = 0, $j = count( $this->last_result ); $i < $j; $i++ ) { |
|
| 2286 | - $new_array[$i] = $this->get_var( null, $x, $i ); |
|
| 2285 | + for ($i = 0, $j = count($this->last_result); $i < $j; $i++) { |
|
| 2286 | + $new_array[$i] = $this->get_var(null, $x, $i); |
|
| 2287 | 2287 | } |
| 2288 | 2288 | return $new_array; |
| 2289 | 2289 | } |
@@ -2303,48 +2303,48 @@ discard block |
||
| 2303 | 2303 | * Duplicate keys are discarded. |
| 2304 | 2304 | * @return array|object|null Database query results |
| 2305 | 2305 | */ |
| 2306 | - public function get_results( $query = null, $output = OBJECT ) { |
|
| 2306 | + public function get_results($query = null, $output = OBJECT) { |
|
| 2307 | 2307 | $this->func_call = "\$db->get_results(\"$query\", $output)"; |
| 2308 | 2308 | |
| 2309 | - if ( $this->check_current_query && $this->check_safe_collation( $query ) ) { |
|
| 2309 | + if ($this->check_current_query && $this->check_safe_collation($query)) { |
|
| 2310 | 2310 | $this->check_current_query = false; |
| 2311 | 2311 | } |
| 2312 | 2312 | |
| 2313 | - if ( $query ) { |
|
| 2314 | - $this->query( $query ); |
|
| 2313 | + if ($query) { |
|
| 2314 | + $this->query($query); |
|
| 2315 | 2315 | } else { |
| 2316 | 2316 | return null; |
| 2317 | 2317 | } |
| 2318 | 2318 | |
| 2319 | 2319 | $new_array = array(); |
| 2320 | - if ( $output == OBJECT ) { |
|
| 2320 | + if ($output == OBJECT) { |
|
| 2321 | 2321 | // Return an integer-keyed array of row objects |
| 2322 | 2322 | return $this->last_result; |
| 2323 | - } elseif ( $output == OBJECT_K ) { |
|
| 2323 | + } elseif ($output == OBJECT_K) { |
|
| 2324 | 2324 | // Return an array of row objects with keys from column 1 |
| 2325 | 2325 | // (Duplicates are discarded) |
| 2326 | - foreach ( $this->last_result as $row ) { |
|
| 2327 | - $var_by_ref = get_object_vars( $row ); |
|
| 2328 | - $key = array_shift( $var_by_ref ); |
|
| 2329 | - if ( ! isset( $new_array[ $key ] ) ) |
|
| 2330 | - $new_array[ $key ] = $row; |
|
| 2326 | + foreach ($this->last_result as $row) { |
|
| 2327 | + $var_by_ref = get_object_vars($row); |
|
| 2328 | + $key = array_shift($var_by_ref); |
|
| 2329 | + if ( ! isset($new_array[$key])) |
|
| 2330 | + $new_array[$key] = $row; |
|
| 2331 | 2331 | } |
| 2332 | 2332 | return $new_array; |
| 2333 | - } elseif ( $output == ARRAY_A || $output == ARRAY_N ) { |
|
| 2333 | + } elseif ($output == ARRAY_A || $output == ARRAY_N) { |
|
| 2334 | 2334 | // Return an integer-keyed array of... |
| 2335 | - if ( $this->last_result ) { |
|
| 2336 | - foreach ( (array) $this->last_result as $row ) { |
|
| 2337 | - if ( $output == ARRAY_N ) { |
|
| 2335 | + if ($this->last_result) { |
|
| 2336 | + foreach ((array) $this->last_result as $row) { |
|
| 2337 | + if ($output == ARRAY_N) { |
|
| 2338 | 2338 | // ...integer-keyed row arrays |
| 2339 | - $new_array[] = array_values( get_object_vars( $row ) ); |
|
| 2339 | + $new_array[] = array_values(get_object_vars($row)); |
|
| 2340 | 2340 | } else { |
| 2341 | 2341 | // ...column name-keyed row arrays |
| 2342 | - $new_array[] = get_object_vars( $row ); |
|
| 2342 | + $new_array[] = get_object_vars($row); |
|
| 2343 | 2343 | } |
| 2344 | 2344 | } |
| 2345 | 2345 | } |
| 2346 | 2346 | return $new_array; |
| 2347 | - } elseif ( strtoupper( $output ) === OBJECT ) { |
|
| 2347 | + } elseif (strtoupper($output) === OBJECT) { |
|
| 2348 | 2348 | // Back compat for OBJECT being previously case insensitive. |
| 2349 | 2349 | return $this->last_result; |
| 2350 | 2350 | } |
@@ -2360,8 +2360,8 @@ discard block |
||
| 2360 | 2360 | * @param string $table Table name. |
| 2361 | 2361 | * @return string|WP_Error Table character set, WP_Error object if it couldn't be found. |
| 2362 | 2362 | */ |
| 2363 | - protected function get_table_charset( $table ) { |
|
| 2364 | - $tablekey = strtolower( $table ); |
|
| 2363 | + protected function get_table_charset($table) { |
|
| 2364 | + $tablekey = strtolower($table); |
|
| 2365 | 2365 | |
| 2366 | 2366 | /** |
| 2367 | 2367 | * Filter the table charset value before the DB is checked. |
@@ -2374,72 +2374,72 @@ discard block |
||
| 2374 | 2374 | * @param string $charset The character set to use. Default null. |
| 2375 | 2375 | * @param string $table The name of the table being checked. |
| 2376 | 2376 | */ |
| 2377 | - $charset = apply_filters( 'pre_get_table_charset', null, $table ); |
|
| 2378 | - if ( null !== $charset ) { |
|
| 2377 | + $charset = apply_filters('pre_get_table_charset', null, $table); |
|
| 2378 | + if (null !== $charset) { |
|
| 2379 | 2379 | return $charset; |
| 2380 | 2380 | } |
| 2381 | 2381 | |
| 2382 | - if ( isset( $this->table_charset[ $tablekey ] ) ) { |
|
| 2383 | - return $this->table_charset[ $tablekey ]; |
|
| 2382 | + if (isset($this->table_charset[$tablekey])) { |
|
| 2383 | + return $this->table_charset[$tablekey]; |
|
| 2384 | 2384 | } |
| 2385 | 2385 | |
| 2386 | 2386 | $charsets = $columns = array(); |
| 2387 | 2387 | |
| 2388 | - $table_parts = explode( '.', $table ); |
|
| 2389 | - $table = '`' . implode( '`.`', $table_parts ) . '`'; |
|
| 2390 | - $results = $this->get_results( "SHOW FULL COLUMNS FROM $table" ); |
|
| 2391 | - if ( ! $results ) { |
|
| 2392 | - return new WP_Error( 'wpdb_get_table_charset_failure' ); |
|
| 2388 | + $table_parts = explode('.', $table); |
|
| 2389 | + $table = '`'.implode('`.`', $table_parts).'`'; |
|
| 2390 | + $results = $this->get_results("SHOW FULL COLUMNS FROM $table"); |
|
| 2391 | + if ( ! $results) { |
|
| 2392 | + return new WP_Error('wpdb_get_table_charset_failure'); |
|
| 2393 | 2393 | } |
| 2394 | 2394 | |
| 2395 | - foreach ( $results as $column ) { |
|
| 2396 | - $columns[ strtolower( $column->Field ) ] = $column; |
|
| 2395 | + foreach ($results as $column) { |
|
| 2396 | + $columns[strtolower($column->Field)] = $column; |
|
| 2397 | 2397 | } |
| 2398 | 2398 | |
| 2399 | - $this->col_meta[ $tablekey ] = $columns; |
|
| 2399 | + $this->col_meta[$tablekey] = $columns; |
|
| 2400 | 2400 | |
| 2401 | - foreach ( $columns as $column ) { |
|
| 2402 | - if ( ! empty( $column->Collation ) ) { |
|
| 2403 | - list( $charset ) = explode( '_', $column->Collation ); |
|
| 2401 | + foreach ($columns as $column) { |
|
| 2402 | + if ( ! empty($column->Collation)) { |
|
| 2403 | + list($charset) = explode('_', $column->Collation); |
|
| 2404 | 2404 | |
| 2405 | 2405 | // If the current connection can't support utf8mb4 characters, let's only send 3-byte utf8 characters. |
| 2406 | - if ( 'utf8mb4' === $charset && ! $this->has_cap( 'utf8mb4' ) ) { |
|
| 2406 | + if ('utf8mb4' === $charset && ! $this->has_cap('utf8mb4')) { |
|
| 2407 | 2407 | $charset = 'utf8'; |
| 2408 | 2408 | } |
| 2409 | 2409 | |
| 2410 | - $charsets[ strtolower( $charset ) ] = true; |
|
| 2410 | + $charsets[strtolower($charset)] = true; |
|
| 2411 | 2411 | } |
| 2412 | 2412 | |
| 2413 | - list( $type ) = explode( '(', $column->Type ); |
|
| 2413 | + list($type) = explode('(', $column->Type); |
|
| 2414 | 2414 | |
| 2415 | 2415 | // A binary/blob means the whole query gets treated like this. |
| 2416 | - if ( in_array( strtoupper( $type ), array( 'BINARY', 'VARBINARY', 'TINYBLOB', 'MEDIUMBLOB', 'BLOB', 'LONGBLOB' ) ) ) { |
|
| 2417 | - $this->table_charset[ $tablekey ] = 'binary'; |
|
| 2416 | + if (in_array(strtoupper($type), array('BINARY', 'VARBINARY', 'TINYBLOB', 'MEDIUMBLOB', 'BLOB', 'LONGBLOB'))) { |
|
| 2417 | + $this->table_charset[$tablekey] = 'binary'; |
|
| 2418 | 2418 | return 'binary'; |
| 2419 | 2419 | } |
| 2420 | 2420 | } |
| 2421 | 2421 | |
| 2422 | 2422 | // utf8mb3 is an alias for utf8. |
| 2423 | - if ( isset( $charsets['utf8mb3'] ) ) { |
|
| 2423 | + if (isset($charsets['utf8mb3'])) { |
|
| 2424 | 2424 | $charsets['utf8'] = true; |
| 2425 | - unset( $charsets['utf8mb3'] ); |
|
| 2425 | + unset($charsets['utf8mb3']); |
|
| 2426 | 2426 | } |
| 2427 | 2427 | |
| 2428 | 2428 | // Check if we have more than one charset in play. |
| 2429 | - $count = count( $charsets ); |
|
| 2430 | - if ( 1 === $count ) { |
|
| 2431 | - $charset = key( $charsets ); |
|
| 2432 | - } elseif ( 0 === $count ) { |
|
| 2429 | + $count = count($charsets); |
|
| 2430 | + if (1 === $count) { |
|
| 2431 | + $charset = key($charsets); |
|
| 2432 | + } elseif (0 === $count) { |
|
| 2433 | 2433 | // No charsets, assume this table can store whatever. |
| 2434 | 2434 | $charset = false; |
| 2435 | 2435 | } else { |
| 2436 | 2436 | // More than one charset. Remove latin1 if present and recalculate. |
| 2437 | - unset( $charsets['latin1'] ); |
|
| 2438 | - $count = count( $charsets ); |
|
| 2439 | - if ( 1 === $count ) { |
|
| 2437 | + unset($charsets['latin1']); |
|
| 2438 | + $count = count($charsets); |
|
| 2439 | + if (1 === $count) { |
|
| 2440 | 2440 | // Only one charset (besides latin1). |
| 2441 | - $charset = key( $charsets ); |
|
| 2442 | - } elseif ( 2 === $count && isset( $charsets['utf8'], $charsets['utf8mb4'] ) ) { |
|
| 2441 | + $charset = key($charsets); |
|
| 2442 | + } elseif (2 === $count && isset($charsets['utf8'], $charsets['utf8mb4'])) { |
|
| 2443 | 2443 | // Two charsets, but they're utf8 and utf8mb4, use utf8. |
| 2444 | 2444 | $charset = 'utf8'; |
| 2445 | 2445 | } else { |
@@ -2448,7 +2448,7 @@ discard block |
||
| 2448 | 2448 | } |
| 2449 | 2449 | } |
| 2450 | 2450 | |
| 2451 | - $this->table_charset[ $tablekey ] = $charset; |
|
| 2451 | + $this->table_charset[$tablekey] = $charset; |
|
| 2452 | 2452 | return $charset; |
| 2453 | 2453 | } |
| 2454 | 2454 | |
@@ -2463,9 +2463,9 @@ discard block |
||
| 2463 | 2463 | * @return string|false|WP_Error Column character set as a string. False if the column has no |
| 2464 | 2464 | * character set. WP_Error object if there was an error. |
| 2465 | 2465 | */ |
| 2466 | - public function get_col_charset( $table, $column ) { |
|
| 2467 | - $tablekey = strtolower( $table ); |
|
| 2468 | - $columnkey = strtolower( $column ); |
|
| 2466 | + public function get_col_charset($table, $column) { |
|
| 2467 | + $tablekey = strtolower($table); |
|
| 2468 | + $columnkey = strtolower($column); |
|
| 2469 | 2469 | |
| 2470 | 2470 | /** |
| 2471 | 2471 | * Filter the column charset value before the DB is checked. |
@@ -2479,40 +2479,40 @@ discard block |
||
| 2479 | 2479 | * @param string $table The name of the table being checked. |
| 2480 | 2480 | * @param string $column The name of the column being checked. |
| 2481 | 2481 | */ |
| 2482 | - $charset = apply_filters( 'pre_get_col_charset', null, $table, $column ); |
|
| 2483 | - if ( null !== $charset ) { |
|
| 2482 | + $charset = apply_filters('pre_get_col_charset', null, $table, $column); |
|
| 2483 | + if (null !== $charset) { |
|
| 2484 | 2484 | return $charset; |
| 2485 | 2485 | } |
| 2486 | 2486 | |
| 2487 | 2487 | // Skip this entirely if this isn't a MySQL database. |
| 2488 | - if ( empty( $this->is_mysql ) ) { |
|
| 2488 | + if (empty($this->is_mysql)) { |
|
| 2489 | 2489 | return false; |
| 2490 | 2490 | } |
| 2491 | 2491 | |
| 2492 | - if ( empty( $this->table_charset[ $tablekey ] ) ) { |
|
| 2492 | + if (empty($this->table_charset[$tablekey])) { |
|
| 2493 | 2493 | // This primes column information for us. |
| 2494 | - $table_charset = $this->get_table_charset( $table ); |
|
| 2495 | - if ( is_wp_error( $table_charset ) ) { |
|
| 2494 | + $table_charset = $this->get_table_charset($table); |
|
| 2495 | + if (is_wp_error($table_charset)) { |
|
| 2496 | 2496 | return $table_charset; |
| 2497 | 2497 | } |
| 2498 | 2498 | } |
| 2499 | 2499 | |
| 2500 | 2500 | // If still no column information, return the table charset. |
| 2501 | - if ( empty( $this->col_meta[ $tablekey ] ) ) { |
|
| 2502 | - return $this->table_charset[ $tablekey ]; |
|
| 2501 | + if (empty($this->col_meta[$tablekey])) { |
|
| 2502 | + return $this->table_charset[$tablekey]; |
|
| 2503 | 2503 | } |
| 2504 | 2504 | |
| 2505 | 2505 | // If this column doesn't exist, return the table charset. |
| 2506 | - if ( empty( $this->col_meta[ $tablekey ][ $columnkey ] ) ) { |
|
| 2507 | - return $this->table_charset[ $tablekey ]; |
|
| 2506 | + if (empty($this->col_meta[$tablekey][$columnkey])) { |
|
| 2507 | + return $this->table_charset[$tablekey]; |
|
| 2508 | 2508 | } |
| 2509 | 2509 | |
| 2510 | 2510 | // Return false when it's not a string column. |
| 2511 | - if ( empty( $this->col_meta[ $tablekey ][ $columnkey ]->Collation ) ) { |
|
| 2511 | + if (empty($this->col_meta[$tablekey][$columnkey]->Collation)) { |
|
| 2512 | 2512 | return false; |
| 2513 | 2513 | } |
| 2514 | 2514 | |
| 2515 | - list( $charset ) = explode( '_', $this->col_meta[ $tablekey ][ $columnkey ]->Collation ); |
|
| 2515 | + list($charset) = explode('_', $this->col_meta[$tablekey][$columnkey]->Collation); |
|
| 2516 | 2516 | return $charset; |
| 2517 | 2517 | } |
| 2518 | 2518 | |
@@ -2529,37 +2529,37 @@ discard block |
||
| 2529 | 2529 | * false if the column has no length (for example, numeric column) |
| 2530 | 2530 | * WP_Error object if there was an error. |
| 2531 | 2531 | */ |
| 2532 | - public function get_col_length( $table, $column ) { |
|
| 2533 | - $tablekey = strtolower( $table ); |
|
| 2534 | - $columnkey = strtolower( $column ); |
|
| 2532 | + public function get_col_length($table, $column) { |
|
| 2533 | + $tablekey = strtolower($table); |
|
| 2534 | + $columnkey = strtolower($column); |
|
| 2535 | 2535 | |
| 2536 | 2536 | // Skip this entirely if this isn't a MySQL database. |
| 2537 | - if ( empty( $this->is_mysql ) ) { |
|
| 2537 | + if (empty($this->is_mysql)) { |
|
| 2538 | 2538 | return false; |
| 2539 | 2539 | } |
| 2540 | 2540 | |
| 2541 | - if ( empty( $this->col_meta[ $tablekey ] ) ) { |
|
| 2541 | + if (empty($this->col_meta[$tablekey])) { |
|
| 2542 | 2542 | // This primes column information for us. |
| 2543 | - $table_charset = $this->get_table_charset( $table ); |
|
| 2544 | - if ( is_wp_error( $table_charset ) ) { |
|
| 2543 | + $table_charset = $this->get_table_charset($table); |
|
| 2544 | + if (is_wp_error($table_charset)) { |
|
| 2545 | 2545 | return $table_charset; |
| 2546 | 2546 | } |
| 2547 | 2547 | } |
| 2548 | 2548 | |
| 2549 | - if ( empty( $this->col_meta[ $tablekey ][ $columnkey ] ) ) { |
|
| 2549 | + if (empty($this->col_meta[$tablekey][$columnkey])) { |
|
| 2550 | 2550 | return false; |
| 2551 | 2551 | } |
| 2552 | 2552 | |
| 2553 | - $typeinfo = explode( '(', $this->col_meta[ $tablekey ][ $columnkey ]->Type ); |
|
| 2553 | + $typeinfo = explode('(', $this->col_meta[$tablekey][$columnkey]->Type); |
|
| 2554 | 2554 | |
| 2555 | - $type = strtolower( $typeinfo[0] ); |
|
| 2556 | - if ( ! empty( $typeinfo[1] ) ) { |
|
| 2557 | - $length = trim( $typeinfo[1], ')' ); |
|
| 2555 | + $type = strtolower($typeinfo[0]); |
|
| 2556 | + if ( ! empty($typeinfo[1])) { |
|
| 2557 | + $length = trim($typeinfo[1], ')'); |
|
| 2558 | 2558 | } else { |
| 2559 | 2559 | $length = false; |
| 2560 | 2560 | } |
| 2561 | 2561 | |
| 2562 | - switch( $type ) { |
|
| 2562 | + switch ($type) { |
|
| 2563 | 2563 | case 'char': |
| 2564 | 2564 | case 'varchar': |
| 2565 | 2565 | return array( |
@@ -2578,21 +2578,21 @@ discard block |
||
| 2578 | 2578 | case 'tinytext': |
| 2579 | 2579 | return array( |
| 2580 | 2580 | 'type' => 'byte', |
| 2581 | - 'length' => 255, // 2^8 - 1 |
|
| 2581 | + 'length' => 255, // 2^8 - 1 |
|
| 2582 | 2582 | ); |
| 2583 | 2583 | |
| 2584 | 2584 | case 'blob': |
| 2585 | 2585 | case 'text': |
| 2586 | 2586 | return array( |
| 2587 | 2587 | 'type' => 'byte', |
| 2588 | - 'length' => 65535, // 2^16 - 1 |
|
| 2588 | + 'length' => 65535, // 2^16 - 1 |
|
| 2589 | 2589 | ); |
| 2590 | 2590 | |
| 2591 | 2591 | case 'mediumblob': |
| 2592 | 2592 | case 'mediumtext': |
| 2593 | 2593 | return array( |
| 2594 | 2594 | 'type' => 'byte', |
| 2595 | - 'length' => 16777215, // 2^24 - 1 |
|
| 2595 | + 'length' => 16777215, // 2^24 - 1 |
|
| 2596 | 2596 | ); |
| 2597 | 2597 | |
| 2598 | 2598 | case 'longblob': |
@@ -2619,12 +2619,12 @@ discard block |
||
| 2619 | 2619 | * @param string $string String to check. |
| 2620 | 2620 | * @return bool True if ASCII, false if not. |
| 2621 | 2621 | */ |
| 2622 | - protected function check_ascii( $string ) { |
|
| 2623 | - if ( function_exists( 'mb_check_encoding' ) ) { |
|
| 2624 | - if ( mb_check_encoding( $string, 'ASCII' ) ) { |
|
| 2622 | + protected function check_ascii($string) { |
|
| 2623 | + if (function_exists('mb_check_encoding')) { |
|
| 2624 | + if (mb_check_encoding($string, 'ASCII')) { |
|
| 2625 | 2625 | return true; |
| 2626 | 2626 | } |
| 2627 | - } elseif ( ! preg_match( '/[^\x00-\x7F]/', $string ) ) { |
|
| 2627 | + } elseif ( ! preg_match('/[^\x00-\x7F]/', $string)) { |
|
| 2628 | 2628 | return true; |
| 2629 | 2629 | } |
| 2630 | 2630 | |
@@ -2640,48 +2640,48 @@ discard block |
||
| 2640 | 2640 | * @param string $query The query to check. |
| 2641 | 2641 | * @return bool True if the collation is safe, false if it isn't. |
| 2642 | 2642 | */ |
| 2643 | - protected function check_safe_collation( $query ) { |
|
| 2644 | - if ( $this->checking_collation ) { |
|
| 2643 | + protected function check_safe_collation($query) { |
|
| 2644 | + if ($this->checking_collation) { |
|
| 2645 | 2645 | return true; |
| 2646 | 2646 | } |
| 2647 | 2647 | |
| 2648 | 2648 | // We don't need to check the collation for queries that don't read data. |
| 2649 | - $query = ltrim( $query, "\r\n\t (" ); |
|
| 2650 | - if ( preg_match( '/^(?:SHOW|DESCRIBE|DESC|EXPLAIN|CREATE)\s/i', $query ) ) { |
|
| 2649 | + $query = ltrim($query, "\r\n\t ("); |
|
| 2650 | + if (preg_match('/^(?:SHOW|DESCRIBE|DESC|EXPLAIN|CREATE)\s/i', $query)) { |
|
| 2651 | 2651 | return true; |
| 2652 | 2652 | } |
| 2653 | 2653 | |
| 2654 | 2654 | // All-ASCII queries don't need extra checking. |
| 2655 | - if ( $this->check_ascii( $query ) ) { |
|
| 2655 | + if ($this->check_ascii($query)) { |
|
| 2656 | 2656 | return true; |
| 2657 | 2657 | } |
| 2658 | 2658 | |
| 2659 | - $table = $this->get_table_from_query( $query ); |
|
| 2660 | - if ( ! $table ) { |
|
| 2659 | + $table = $this->get_table_from_query($query); |
|
| 2660 | + if ( ! $table) { |
|
| 2661 | 2661 | return false; |
| 2662 | 2662 | } |
| 2663 | 2663 | |
| 2664 | 2664 | $this->checking_collation = true; |
| 2665 | - $collation = $this->get_table_charset( $table ); |
|
| 2665 | + $collation = $this->get_table_charset($table); |
|
| 2666 | 2666 | $this->checking_collation = false; |
| 2667 | 2667 | |
| 2668 | 2668 | // Tables with no collation, or latin1 only, don't need extra checking. |
| 2669 | - if ( false === $collation || 'latin1' === $collation ) { |
|
| 2669 | + if (false === $collation || 'latin1' === $collation) { |
|
| 2670 | 2670 | return true; |
| 2671 | 2671 | } |
| 2672 | 2672 | |
| 2673 | - $table = strtolower( $table ); |
|
| 2674 | - if ( empty( $this->col_meta[ $table ] ) ) { |
|
| 2673 | + $table = strtolower($table); |
|
| 2674 | + if (empty($this->col_meta[$table])) { |
|
| 2675 | 2675 | return false; |
| 2676 | 2676 | } |
| 2677 | 2677 | |
| 2678 | 2678 | // If any of the columns don't have one of these collations, it needs more sanity checking. |
| 2679 | - foreach ( $this->col_meta[ $table ] as $col ) { |
|
| 2680 | - if ( empty( $col->Collation ) ) { |
|
| 2679 | + foreach ($this->col_meta[$table] as $col) { |
|
| 2680 | + if (empty($col->Collation)) { |
|
| 2681 | 2681 | continue; |
| 2682 | 2682 | } |
| 2683 | 2683 | |
| 2684 | - if ( ! in_array( $col->Collation, array( 'utf8_general_ci', 'utf8_bin', 'utf8mb4_general_ci', 'utf8mb4_bin' ), true ) ) { |
|
| 2684 | + if ( ! in_array($col->Collation, array('utf8_general_ci', 'utf8_bin', 'utf8mb4_general_ci', 'utf8mb4_bin'), true)) { |
|
| 2685 | 2685 | return false; |
| 2686 | 2686 | } |
| 2687 | 2687 | } |
@@ -2703,13 +2703,13 @@ discard block |
||
| 2703 | 2703 | * such as 'field' are retained in each value array. If we cannot |
| 2704 | 2704 | * remove invalid characters, a WP_Error object is returned. |
| 2705 | 2705 | */ |
| 2706 | - protected function strip_invalid_text( $data ) { |
|
| 2706 | + protected function strip_invalid_text($data) { |
|
| 2707 | 2707 | $db_check_string = false; |
| 2708 | 2708 | |
| 2709 | - foreach ( $data as &$value ) { |
|
| 2709 | + foreach ($data as &$value) { |
|
| 2710 | 2710 | $charset = $value['charset']; |
| 2711 | 2711 | |
| 2712 | - if ( is_array( $value['length'] ) ) { |
|
| 2712 | + if (is_array($value['length'])) { |
|
| 2713 | 2713 | $length = $value['length']['length']; |
| 2714 | 2714 | $truncate_by_byte_length = 'byte' === $value['length']['type']; |
| 2715 | 2715 | } else { |
@@ -2721,12 +2721,12 @@ discard block |
||
| 2721 | 2721 | } |
| 2722 | 2722 | |
| 2723 | 2723 | // There's no charset to work with. |
| 2724 | - if ( false === $charset ) { |
|
| 2724 | + if (false === $charset) { |
|
| 2725 | 2725 | continue; |
| 2726 | 2726 | } |
| 2727 | 2727 | |
| 2728 | 2728 | // Column isn't a string. |
| 2729 | - if ( ! is_string( $value['value'] ) ) { |
|
| 2729 | + if ( ! is_string($value['value'])) { |
|
| 2730 | 2730 | continue; |
| 2731 | 2731 | } |
| 2732 | 2732 | |
@@ -2736,26 +2736,26 @@ discard block |
||
| 2736 | 2736 | 'latin1' === $charset |
| 2737 | 2737 | || |
| 2738 | 2738 | // ASCII is always OK. |
| 2739 | - ( ! isset( $value['ascii'] ) && $this->check_ascii( $value['value'] ) ) |
|
| 2739 | + ( ! isset($value['ascii']) && $this->check_ascii($value['value'])) |
|
| 2740 | 2740 | ) { |
| 2741 | 2741 | $truncate_by_byte_length = true; |
| 2742 | 2742 | $needs_validation = false; |
| 2743 | 2743 | } |
| 2744 | 2744 | |
| 2745 | - if ( $truncate_by_byte_length ) { |
|
| 2745 | + if ($truncate_by_byte_length) { |
|
| 2746 | 2746 | mbstring_binary_safe_encoding(); |
| 2747 | - if ( false !== $length && strlen( $value['value'] ) > $length ) { |
|
| 2748 | - $value['value'] = substr( $value['value'], 0, $length ); |
|
| 2747 | + if (false !== $length && strlen($value['value']) > $length) { |
|
| 2748 | + $value['value'] = substr($value['value'], 0, $length); |
|
| 2749 | 2749 | } |
| 2750 | 2750 | reset_mbstring_encoding(); |
| 2751 | 2751 | |
| 2752 | - if ( ! $needs_validation ) { |
|
| 2752 | + if ( ! $needs_validation) { |
|
| 2753 | 2753 | continue; |
| 2754 | 2754 | } |
| 2755 | 2755 | } |
| 2756 | 2756 | |
| 2757 | 2757 | // utf8 can be handled by regex, which is a bunch faster than a DB lookup. |
| 2758 | - if ( ( 'utf8' === $charset || 'utf8mb3' === $charset || 'utf8mb4' === $charset ) && function_exists( 'mb_strlen' ) ) { |
|
| 2758 | + if (('utf8' === $charset || 'utf8mb3' === $charset || 'utf8mb4' === $charset) && function_exists('mb_strlen')) { |
|
| 2759 | 2759 | $regex = '/ |
| 2760 | 2760 | ( |
| 2761 | 2761 | (?: [\x00-\x7F] # single-byte sequences 0xxxxxxx |
@@ -2765,7 +2765,7 @@ discard block |
||
| 2765 | 2765 | | \xED[\x80-\x9F][\x80-\xBF] |
| 2766 | 2766 | | [\xEE-\xEF][\x80-\xBF]{2}'; |
| 2767 | 2767 | |
| 2768 | - if ( 'utf8mb4' === $charset ) { |
|
| 2768 | + if ('utf8mb4' === $charset) { |
|
| 2769 | 2769 | $regex .= ' |
| 2770 | 2770 | | \xF0[\x90-\xBF][\x80-\xBF]{2} # four-byte sequences 11110xxx 10xxxxxx * 3 |
| 2771 | 2771 | | [\xF1-\xF3][\x80-\xBF]{3} |
@@ -2777,11 +2777,11 @@ discard block |
||
| 2777 | 2777 | ) |
| 2778 | 2778 | | . # anything else |
| 2779 | 2779 | /x'; |
| 2780 | - $value['value'] = preg_replace( $regex, '$1', $value['value'] ); |
|
| 2780 | + $value['value'] = preg_replace($regex, '$1', $value['value']); |
|
| 2781 | 2781 | |
| 2782 | 2782 | |
| 2783 | - if ( false !== $length && mb_strlen( $value['value'], 'UTF-8' ) > $length ) { |
|
| 2784 | - $value['value'] = mb_substr( $value['value'], 0, $length, 'UTF-8' ); |
|
| 2783 | + if (false !== $length && mb_strlen($value['value'], 'UTF-8') > $length) { |
|
| 2784 | + $value['value'] = mb_substr($value['value'], 0, $length, 'UTF-8'); |
|
| 2785 | 2785 | } |
| 2786 | 2786 | continue; |
| 2787 | 2787 | } |
@@ -2789,59 +2789,59 @@ discard block |
||
| 2789 | 2789 | // We couldn't use any local conversions, send it to the DB. |
| 2790 | 2790 | $value['db'] = $db_check_string = true; |
| 2791 | 2791 | } |
| 2792 | - unset( $value ); // Remove by reference. |
|
| 2792 | + unset($value); // Remove by reference. |
|
| 2793 | 2793 | |
| 2794 | - if ( $db_check_string ) { |
|
| 2794 | + if ($db_check_string) { |
|
| 2795 | 2795 | $queries = array(); |
| 2796 | - foreach ( $data as $col => $value ) { |
|
| 2797 | - if ( ! empty( $value['db'] ) ) { |
|
| 2796 | + foreach ($data as $col => $value) { |
|
| 2797 | + if ( ! empty($value['db'])) { |
|
| 2798 | 2798 | // We're going to need to truncate by characters or bytes, depending on the length value we have. |
| 2799 | - if ( 'byte' === $value['length']['type'] ) { |
|
| 2799 | + if ('byte' === $value['length']['type']) { |
|
| 2800 | 2800 | // Using binary causes LEFT() to truncate by bytes. |
| 2801 | 2801 | $charset = 'binary'; |
| 2802 | 2802 | } else { |
| 2803 | 2803 | $charset = $value['charset']; |
| 2804 | 2804 | } |
| 2805 | 2805 | |
| 2806 | - if ( $this->charset ) { |
|
| 2806 | + if ($this->charset) { |
|
| 2807 | 2807 | $connection_charset = $this->charset; |
| 2808 | 2808 | } else { |
| 2809 | - if ( $this->use_mysqli ) { |
|
| 2810 | - $connection_charset = mysqli_character_set_name( $this->dbh ); |
|
| 2809 | + if ($this->use_mysqli) { |
|
| 2810 | + $connection_charset = mysqli_character_set_name($this->dbh); |
|
| 2811 | 2811 | } else { |
| 2812 | 2812 | $connection_charset = mysql_client_encoding(); |
| 2813 | 2813 | } |
| 2814 | 2814 | } |
| 2815 | 2815 | |
| 2816 | - if ( is_array( $value['length'] ) ) { |
|
| 2817 | - $queries[ $col ] = $this->prepare( "CONVERT( LEFT( CONVERT( %s USING $charset ), %.0f ) USING $connection_charset )", $value['value'], $value['length']['length'] ); |
|
| 2818 | - } else if ( 'binary' !== $charset ) { |
|
| 2816 | + if (is_array($value['length'])) { |
|
| 2817 | + $queries[$col] = $this->prepare("CONVERT( LEFT( CONVERT( %s USING $charset ), %.0f ) USING $connection_charset )", $value['value'], $value['length']['length']); |
|
| 2818 | + } else if ('binary' !== $charset) { |
|
| 2819 | 2819 | // If we don't have a length, there's no need to convert binary - it will always return the same result. |
| 2820 | - $queries[ $col ] = $this->prepare( "CONVERT( CONVERT( %s USING $charset ) USING $connection_charset )", $value['value'] ); |
|
| 2820 | + $queries[$col] = $this->prepare("CONVERT( CONVERT( %s USING $charset ) USING $connection_charset )", $value['value']); |
|
| 2821 | 2821 | } |
| 2822 | 2822 | |
| 2823 | - unset( $data[ $col ]['db'] ); |
|
| 2823 | + unset($data[$col]['db']); |
|
| 2824 | 2824 | } |
| 2825 | 2825 | } |
| 2826 | 2826 | |
| 2827 | 2827 | $sql = array(); |
| 2828 | - foreach ( $queries as $column => $query ) { |
|
| 2829 | - if ( ! $query ) { |
|
| 2828 | + foreach ($queries as $column => $query) { |
|
| 2829 | + if ( ! $query) { |
|
| 2830 | 2830 | continue; |
| 2831 | 2831 | } |
| 2832 | 2832 | |
| 2833 | - $sql[] = $query . " AS x_$column"; |
|
| 2833 | + $sql[] = $query." AS x_$column"; |
|
| 2834 | 2834 | } |
| 2835 | 2835 | |
| 2836 | 2836 | $this->check_current_query = false; |
| 2837 | - $row = $this->get_row( "SELECT " . implode( ', ', $sql ), ARRAY_A ); |
|
| 2838 | - if ( ! $row ) { |
|
| 2839 | - return new WP_Error( 'wpdb_strip_invalid_text_failure' ); |
|
| 2837 | + $row = $this->get_row("SELECT ".implode(', ', $sql), ARRAY_A); |
|
| 2838 | + if ( ! $row) { |
|
| 2839 | + return new WP_Error('wpdb_strip_invalid_text_failure'); |
|
| 2840 | 2840 | } |
| 2841 | 2841 | |
| 2842 | - foreach ( array_keys( $data ) as $column ) { |
|
| 2843 | - if ( isset( $row["x_$column"] ) ) { |
|
| 2844 | - $data[ $column ]['value'] = $row["x_$column"]; |
|
| 2842 | + foreach (array_keys($data) as $column) { |
|
| 2843 | + if (isset($row["x_$column"])) { |
|
| 2844 | + $data[$column]['value'] = $row["x_$column"]; |
|
| 2845 | 2845 | } |
| 2846 | 2846 | } |
| 2847 | 2847 | } |
@@ -2858,22 +2858,22 @@ discard block |
||
| 2858 | 2858 | * @param string $query Query to convert. |
| 2859 | 2859 | * @return string|WP_Error The converted query, or a WP_Error object if the conversion fails. |
| 2860 | 2860 | */ |
| 2861 | - protected function strip_invalid_text_from_query( $query ) { |
|
| 2861 | + protected function strip_invalid_text_from_query($query) { |
|
| 2862 | 2862 | // We don't need to check the collation for queries that don't read data. |
| 2863 | - $trimmed_query = ltrim( $query, "\r\n\t (" ); |
|
| 2864 | - if ( preg_match( '/^(?:SHOW|DESCRIBE|DESC|EXPLAIN|CREATE)\s/i', $trimmed_query ) ) { |
|
| 2863 | + $trimmed_query = ltrim($query, "\r\n\t ("); |
|
| 2864 | + if (preg_match('/^(?:SHOW|DESCRIBE|DESC|EXPLAIN|CREATE)\s/i', $trimmed_query)) { |
|
| 2865 | 2865 | return $query; |
| 2866 | 2866 | } |
| 2867 | 2867 | |
| 2868 | - $table = $this->get_table_from_query( $query ); |
|
| 2869 | - if ( $table ) { |
|
| 2870 | - $charset = $this->get_table_charset( $table ); |
|
| 2871 | - if ( is_wp_error( $charset ) ) { |
|
| 2868 | + $table = $this->get_table_from_query($query); |
|
| 2869 | + if ($table) { |
|
| 2870 | + $charset = $this->get_table_charset($table); |
|
| 2871 | + if (is_wp_error($charset)) { |
|
| 2872 | 2872 | return $charset; |
| 2873 | 2873 | } |
| 2874 | 2874 | |
| 2875 | 2875 | // We can't reliably strip text from tables containing binary/blob columns |
| 2876 | - if ( 'binary' === $charset ) { |
|
| 2876 | + if ('binary' === $charset) { |
|
| 2877 | 2877 | return $query; |
| 2878 | 2878 | } |
| 2879 | 2879 | } else { |
@@ -2887,8 +2887,8 @@ discard block |
||
| 2887 | 2887 | 'length' => false, |
| 2888 | 2888 | ); |
| 2889 | 2889 | |
| 2890 | - $data = $this->strip_invalid_text( array( $data ) ); |
|
| 2891 | - if ( is_wp_error( $data ) ) { |
|
| 2890 | + $data = $this->strip_invalid_text(array($data)); |
|
| 2891 | + if (is_wp_error($data)) { |
|
| 2892 | 2892 | return $data; |
| 2893 | 2893 | } |
| 2894 | 2894 | |
@@ -2906,16 +2906,16 @@ discard block |
||
| 2906 | 2906 | * @param string $value The text to check. |
| 2907 | 2907 | * @return string|WP_Error The converted string, or a WP_Error object if the conversion fails. |
| 2908 | 2908 | */ |
| 2909 | - public function strip_invalid_text_for_column( $table, $column, $value ) { |
|
| 2910 | - if ( ! is_string( $value ) ) { |
|
| 2909 | + public function strip_invalid_text_for_column($table, $column, $value) { |
|
| 2910 | + if ( ! is_string($value)) { |
|
| 2911 | 2911 | return $value; |
| 2912 | 2912 | } |
| 2913 | 2913 | |
| 2914 | - $charset = $this->get_col_charset( $table, $column ); |
|
| 2915 | - if ( ! $charset ) { |
|
| 2914 | + $charset = $this->get_col_charset($table, $column); |
|
| 2915 | + if ( ! $charset) { |
|
| 2916 | 2916 | // Not a string column. |
| 2917 | 2917 | return $value; |
| 2918 | - } elseif ( is_wp_error( $charset ) ) { |
|
| 2918 | + } elseif (is_wp_error($charset)) { |
|
| 2919 | 2919 | // Bail on real errors. |
| 2920 | 2920 | return $charset; |
| 2921 | 2921 | } |
@@ -2924,16 +2924,16 @@ discard block |
||
| 2924 | 2924 | $column => array( |
| 2925 | 2925 | 'value' => $value, |
| 2926 | 2926 | 'charset' => $charset, |
| 2927 | - 'length' => $this->get_col_length( $table, $column ), |
|
| 2927 | + 'length' => $this->get_col_length($table, $column), |
|
| 2928 | 2928 | ) |
| 2929 | 2929 | ); |
| 2930 | 2930 | |
| 2931 | - $data = $this->strip_invalid_text( $data ); |
|
| 2932 | - if ( is_wp_error( $data ) ) { |
|
| 2931 | + $data = $this->strip_invalid_text($data); |
|
| 2932 | + if (is_wp_error($data)) { |
|
| 2933 | 2933 | return $data; |
| 2934 | 2934 | } |
| 2935 | 2935 | |
| 2936 | - return $data[ $column ]['value']; |
|
| 2936 | + return $data[$column]['value']; |
|
| 2937 | 2937 | } |
| 2938 | 2938 | |
| 2939 | 2939 | /** |
@@ -2945,37 +2945,37 @@ discard block |
||
| 2945 | 2945 | * @param string $query The query to search. |
| 2946 | 2946 | * @return string|false $table The table name found, or false if a table couldn't be found. |
| 2947 | 2947 | */ |
| 2948 | - protected function get_table_from_query( $query ) { |
|
| 2948 | + protected function get_table_from_query($query) { |
|
| 2949 | 2949 | // Remove characters that can legally trail the table name. |
| 2950 | - $query = rtrim( $query, ';/-#' ); |
|
| 2950 | + $query = rtrim($query, ';/-#'); |
|
| 2951 | 2951 | |
| 2952 | 2952 | // Allow (select...) union [...] style queries. Use the first query's table name. |
| 2953 | - $query = ltrim( $query, "\r\n\t (" ); |
|
| 2953 | + $query = ltrim($query, "\r\n\t ("); |
|
| 2954 | 2954 | |
| 2955 | 2955 | // Strip everything between parentheses except nested selects. |
| 2956 | - $query = preg_replace( '/\((?!\s*select)[^(]*?\)/is', '()', $query ); |
|
| 2956 | + $query = preg_replace('/\((?!\s*select)[^(]*?\)/is', '()', $query); |
|
| 2957 | 2957 | |
| 2958 | 2958 | // Quickly match most common queries. |
| 2959 | - if ( preg_match( '/^\s*(?:' |
|
| 2959 | + if (preg_match('/^\s*(?:' |
|
| 2960 | 2960 | . 'SELECT.*?\s+FROM' |
| 2961 | 2961 | . '|INSERT(?:\s+LOW_PRIORITY|\s+DELAYED|\s+HIGH_PRIORITY)?(?:\s+IGNORE)?(?:\s+INTO)?' |
| 2962 | 2962 | . '|REPLACE(?:\s+LOW_PRIORITY|\s+DELAYED)?(?:\s+INTO)?' |
| 2963 | 2963 | . '|UPDATE(?:\s+LOW_PRIORITY)?(?:\s+IGNORE)?' |
| 2964 | 2964 | . '|DELETE(?:\s+LOW_PRIORITY|\s+QUICK|\s+IGNORE)*(?:\s+FROM)?' |
| 2965 | - . ')\s+((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)/is', $query, $maybe ) ) { |
|
| 2966 | - return str_replace( '`', '', $maybe[1] ); |
|
| 2965 | + . ')\s+((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)/is', $query, $maybe)) { |
|
| 2966 | + return str_replace('`', '', $maybe[1]); |
|
| 2967 | 2967 | } |
| 2968 | 2968 | |
| 2969 | 2969 | // SHOW TABLE STATUS and SHOW TABLES |
| 2970 | - if ( preg_match( '/^\s*(?:' |
|
| 2970 | + if (preg_match('/^\s*(?:' |
|
| 2971 | 2971 | . 'SHOW\s+TABLE\s+STATUS.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)' |
| 2972 | 2972 | . '|SHOW\s+(?:FULL\s+)?TABLES.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)' |
| 2973 | - . ')\W((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)\W/is', $query, $maybe ) ) { |
|
| 2974 | - return str_replace( '`', '', $maybe[1] ); |
|
| 2973 | + . ')\W((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)\W/is', $query, $maybe)) { |
|
| 2974 | + return str_replace('`', '', $maybe[1]); |
|
| 2975 | 2975 | } |
| 2976 | 2976 | |
| 2977 | 2977 | // Big pattern for the rest of the table-related queries. |
| 2978 | - if ( preg_match( '/^\s*(?:' |
|
| 2978 | + if (preg_match('/^\s*(?:' |
|
| 2979 | 2979 | . '(?:EXPLAIN\s+(?:EXTENDED\s+)?)?SELECT.*?\s+FROM' |
| 2980 | 2980 | . '|DESCRIBE|DESC|EXPLAIN|HANDLER' |
| 2981 | 2981 | . '|(?:LOCK|UNLOCK)\s+TABLE(?:S)?' |
@@ -2989,8 +2989,8 @@ discard block |
||
| 2989 | 2989 | . '|LOAD\s+DATA.*INFILE.*INTO\s+TABLE' |
| 2990 | 2990 | . '|(?:GRANT|REVOKE).*ON\s+TABLE' |
| 2991 | 2991 | . '|SHOW\s+(?:.*FROM|.*TABLE)' |
| 2992 | - . ')\s+\(*\s*((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)\s*\)*/is', $query, $maybe ) ) { |
|
| 2993 | - return str_replace( '`', '', $maybe[1] ); |
|
| 2992 | + . ')\s+\(*\s*((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)\s*\)*/is', $query, $maybe)) { |
|
| 2993 | + return str_replace('`', '', $maybe[1]); |
|
| 2994 | 2994 | } |
| 2995 | 2995 | |
| 2996 | 2996 | return false; |
@@ -3004,18 +3004,18 @@ discard block |
||
| 3004 | 3004 | * @access protected |
| 3005 | 3005 | */ |
| 3006 | 3006 | protected function load_col_info() { |
| 3007 | - if ( $this->col_info ) |
|
| 3007 | + if ($this->col_info) |
|
| 3008 | 3008 | return; |
| 3009 | 3009 | |
| 3010 | - if ( $this->use_mysqli ) { |
|
| 3011 | - $num_fields = mysqli_num_fields( $this->result ); |
|
| 3012 | - for ( $i = 0; $i < $num_fields; $i++ ) { |
|
| 3013 | - $this->col_info[ $i ] = mysqli_fetch_field( $this->result ); |
|
| 3010 | + if ($this->use_mysqli) { |
|
| 3011 | + $num_fields = mysqli_num_fields($this->result); |
|
| 3012 | + for ($i = 0; $i < $num_fields; $i++) { |
|
| 3013 | + $this->col_info[$i] = mysqli_fetch_field($this->result); |
|
| 3014 | 3014 | } |
| 3015 | 3015 | } else { |
| 3016 | - $num_fields = mysql_num_fields( $this->result ); |
|
| 3017 | - for ( $i = 0; $i < $num_fields; $i++ ) { |
|
| 3018 | - $this->col_info[ $i ] = mysql_fetch_field( $this->result, $i ); |
|
| 3016 | + $num_fields = mysql_num_fields($this->result); |
|
| 3017 | + for ($i = 0; $i < $num_fields; $i++) { |
|
| 3018 | + $this->col_info[$i] = mysql_fetch_field($this->result, $i); |
|
| 3019 | 3019 | } |
| 3020 | 3020 | } |
| 3021 | 3021 | } |
@@ -3029,14 +3029,14 @@ discard block |
||
| 3029 | 3029 | * @param int $col_offset Optional. 0: col name. 1: which table the col's in. 2: col's max length. 3: if the col is numeric. 4: col's type |
| 3030 | 3030 | * @return mixed Column Results |
| 3031 | 3031 | */ |
| 3032 | - public function get_col_info( $info_type = 'name', $col_offset = -1 ) { |
|
| 3032 | + public function get_col_info($info_type = 'name', $col_offset = -1) { |
|
| 3033 | 3033 | $this->load_col_info(); |
| 3034 | 3034 | |
| 3035 | - if ( $this->col_info ) { |
|
| 3036 | - if ( $col_offset == -1 ) { |
|
| 3035 | + if ($this->col_info) { |
|
| 3036 | + if ($col_offset == -1) { |
|
| 3037 | 3037 | $i = 0; |
| 3038 | 3038 | $new_array = array(); |
| 3039 | - foreach ( (array) $this->col_info as $col ) { |
|
| 3039 | + foreach ((array) $this->col_info as $col) { |
|
| 3040 | 3040 | $new_array[$i] = $col->{$info_type}; |
| 3041 | 3041 | $i++; |
| 3042 | 3042 | } |
@@ -3055,7 +3055,7 @@ discard block |
||
| 3055 | 3055 | * @return true |
| 3056 | 3056 | */ |
| 3057 | 3057 | public function timer_start() { |
| 3058 | - $this->time_start = microtime( true ); |
|
| 3058 | + $this->time_start = microtime(true); |
|
| 3059 | 3059 | return true; |
| 3060 | 3060 | } |
| 3061 | 3061 | |
@@ -3067,7 +3067,7 @@ discard block |
||
| 3067 | 3067 | * @return float Total time spent on the query, in seconds |
| 3068 | 3068 | */ |
| 3069 | 3069 | public function timer_stop() { |
| 3070 | - return ( microtime( true ) - $this->time_start ); |
|
| 3070 | + return (microtime(true) - $this->time_start); |
|
| 3071 | 3071 | } |
| 3072 | 3072 | |
| 3073 | 3073 | /** |
@@ -3081,9 +3081,9 @@ discard block |
||
| 3081 | 3081 | * @param string $error_code Optional. A Computer readable string to identify the error. |
| 3082 | 3082 | * @return false|void |
| 3083 | 3083 | */ |
| 3084 | - public function bail( $message, $error_code = '500' ) { |
|
| 3085 | - if ( !$this->show_errors ) { |
|
| 3086 | - if ( class_exists( 'WP_Error', false ) ) { |
|
| 3084 | + public function bail($message, $error_code = '500') { |
|
| 3085 | + if ( ! $this->show_errors) { |
|
| 3086 | + if (class_exists('WP_Error', false)) { |
|
| 3087 | 3087 | $this->error = new WP_Error($error_code, $message); |
| 3088 | 3088 | } else { |
| 3089 | 3089 | $this->error = $message; |
@@ -3104,17 +3104,17 @@ discard block |
||
| 3104 | 3104 | * or the connection doesn't exist. |
| 3105 | 3105 | */ |
| 3106 | 3106 | public function close() { |
| 3107 | - if ( ! $this->dbh ) { |
|
| 3107 | + if ( ! $this->dbh) { |
|
| 3108 | 3108 | return false; |
| 3109 | 3109 | } |
| 3110 | 3110 | |
| 3111 | - if ( $this->use_mysqli ) { |
|
| 3112 | - $closed = mysqli_close( $this->dbh ); |
|
| 3111 | + if ($this->use_mysqli) { |
|
| 3112 | + $closed = mysqli_close($this->dbh); |
|
| 3113 | 3113 | } else { |
| 3114 | - $closed = mysql_close( $this->dbh ); |
|
| 3114 | + $closed = mysql_close($this->dbh); |
|
| 3115 | 3115 | } |
| 3116 | 3116 | |
| 3117 | - if ( $closed ) { |
|
| 3117 | + if ($closed) { |
|
| 3118 | 3118 | $this->dbh = null; |
| 3119 | 3119 | $this->ready = false; |
| 3120 | 3120 | $this->has_connected = false; |
@@ -3136,8 +3136,8 @@ discard block |
||
| 3136 | 3136 | public function check_database_version() { |
| 3137 | 3137 | global $wp_version, $required_mysql_version; |
| 3138 | 3138 | // Make sure the server has the required MySQL version |
| 3139 | - if ( version_compare($this->db_version(), $required_mysql_version, '<') ) |
|
| 3140 | - return new WP_Error('database_version', sprintf( __( '<strong>ERROR</strong>: WordPress %1$s requires MySQL %2$s or higher' ), $wp_version, $required_mysql_version )); |
|
| 3139 | + if (version_compare($this->db_version(), $required_mysql_version, '<')) |
|
| 3140 | + return new WP_Error('database_version', sprintf(__('<strong>ERROR</strong>: WordPress %1$s requires MySQL %2$s or higher'), $wp_version, $required_mysql_version)); |
|
| 3141 | 3141 | } |
| 3142 | 3142 | |
| 3143 | 3143 | /** |
@@ -3153,8 +3153,8 @@ discard block |
||
| 3153 | 3153 | * @return bool True if collation is supported, false if version does not |
| 3154 | 3154 | */ |
| 3155 | 3155 | public function supports_collation() { |
| 3156 | - _deprecated_function( __FUNCTION__, '3.5', 'wpdb::has_cap( \'collation\' )' ); |
|
| 3157 | - return $this->has_cap( 'collation' ); |
|
| 3156 | + _deprecated_function(__FUNCTION__, '3.5', 'wpdb::has_cap( \'collation\' )'); |
|
| 3157 | + return $this->has_cap('collation'); |
|
| 3158 | 3158 | } |
| 3159 | 3159 | |
| 3160 | 3160 | /** |
@@ -3167,9 +3167,9 @@ discard block |
||
| 3167 | 3167 | public function get_charset_collate() { |
| 3168 | 3168 | $charset_collate = ''; |
| 3169 | 3169 | |
| 3170 | - if ( ! empty( $this->charset ) ) |
|
| 3170 | + if ( ! empty($this->charset)) |
|
| 3171 | 3171 | $charset_collate = "DEFAULT CHARACTER SET $this->charset"; |
| 3172 | - if ( ! empty( $this->collate ) ) |
|
| 3172 | + if ( ! empty($this->collate)) |
|
| 3173 | 3173 | $charset_collate .= " COLLATE $this->collate"; |
| 3174 | 3174 | |
| 3175 | 3175 | return $charset_collate; |
@@ -3188,21 +3188,21 @@ discard block |
||
| 3188 | 3188 | * or 'utf8mb4'. |
| 3189 | 3189 | * @return int|false Whether the database feature is supported, false otherwise. |
| 3190 | 3190 | */ |
| 3191 | - public function has_cap( $db_cap ) { |
|
| 3191 | + public function has_cap($db_cap) { |
|
| 3192 | 3192 | $version = $this->db_version(); |
| 3193 | 3193 | |
| 3194 | - switch ( strtolower( $db_cap ) ) { |
|
| 3194 | + switch (strtolower($db_cap)) { |
|
| 3195 | 3195 | case 'collation' : // @since 2.5.0 |
| 3196 | 3196 | case 'group_concat' : // @since 2.7.0 |
| 3197 | 3197 | case 'subqueries' : // @since 2.7.0 |
| 3198 | - return version_compare( $version, '4.1', '>=' ); |
|
| 3198 | + return version_compare($version, '4.1', '>='); |
|
| 3199 | 3199 | case 'set_charset' : |
| 3200 | - return version_compare( $version, '5.0.7', '>=' ); |
|
| 3200 | + return version_compare($version, '5.0.7', '>='); |
|
| 3201 | 3201 | case 'utf8mb4' : // @since 4.1.0 |
| 3202 | - if ( version_compare( $version, '5.5.3', '<' ) ) { |
|
| 3202 | + if (version_compare($version, '5.5.3', '<')) { |
|
| 3203 | 3203 | return false; |
| 3204 | 3204 | } |
| 3205 | - if ( $this->use_mysqli ) { |
|
| 3205 | + if ($this->use_mysqli) { |
|
| 3206 | 3206 | $client_version = mysqli_get_client_info(); |
| 3207 | 3207 | } else { |
| 3208 | 3208 | $client_version = mysql_get_client_info(); |
@@ -3212,11 +3212,11 @@ discard block |
||
| 3212 | 3212 | * libmysql has supported utf8mb4 since 5.5.3, same as the MySQL server. |
| 3213 | 3213 | * mysqlnd has supported utf8mb4 since 5.0.9. |
| 3214 | 3214 | */ |
| 3215 | - if ( false !== strpos( $client_version, 'mysqlnd' ) ) { |
|
| 3216 | - $client_version = preg_replace( '/^\D+([\d.]+).*/', '$1', $client_version ); |
|
| 3217 | - return version_compare( $client_version, '5.0.9', '>=' ); |
|
| 3215 | + if (false !== strpos($client_version, 'mysqlnd')) { |
|
| 3216 | + $client_version = preg_replace('/^\D+([\d.]+).*/', '$1', $client_version); |
|
| 3217 | + return version_compare($client_version, '5.0.9', '>='); |
|
| 3218 | 3218 | } else { |
| 3219 | - return version_compare( $client_version, '5.5.3', '>=' ); |
|
| 3219 | + return version_compare($client_version, '5.5.3', '>='); |
|
| 3220 | 3220 | } |
| 3221 | 3221 | } |
| 3222 | 3222 | |
@@ -3234,7 +3234,7 @@ discard block |
||
| 3234 | 3234 | * @return string|array The name of the calling function |
| 3235 | 3235 | */ |
| 3236 | 3236 | public function get_caller() { |
| 3237 | - return wp_debug_backtrace_summary( __CLASS__ ); |
|
| 3237 | + return wp_debug_backtrace_summary(__CLASS__); |
|
| 3238 | 3238 | } |
| 3239 | 3239 | |
| 3240 | 3240 | /** |
@@ -3245,11 +3245,11 @@ discard block |
||
| 3245 | 3245 | * @return null|string Null on failure, version number on success. |
| 3246 | 3246 | */ |
| 3247 | 3247 | public function db_version() { |
| 3248 | - if ( $this->use_mysqli ) { |
|
| 3249 | - $server_info = mysqli_get_server_info( $this->dbh ); |
|
| 3248 | + if ($this->use_mysqli) { |
|
| 3249 | + $server_info = mysqli_get_server_info($this->dbh); |
|
| 3250 | 3250 | } else { |
| 3251 | - $server_info = mysql_get_server_info( $this->dbh ); |
|
| 3251 | + $server_info = mysql_get_server_info($this->dbh); |
|
| 3252 | 3252 | } |
| 3253 | - return preg_replace( '/[^0-9.].*/', '', $server_info ); |
|
| 3253 | + return preg_replace('/[^0-9.].*/', '', $server_info); |
|
| 3254 | 3254 | } |
| 3255 | 3255 | } |
@@ -626,8 +626,9 @@ discard block |
||
| 626 | 626 | public function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) { |
| 627 | 627 | register_shutdown_function( array( $this, '__destruct' ) ); |
| 628 | 628 | |
| 629 | - if ( WP_DEBUG && WP_DEBUG_DISPLAY ) |
|
| 630 | - $this->show_errors(); |
|
| 629 | + if ( WP_DEBUG && WP_DEBUG_DISPLAY ) { |
|
| 630 | + $this->show_errors(); |
|
| 631 | + } |
|
| 631 | 632 | |
| 632 | 633 | /* Use ext/mysqli if it exists and: |
| 633 | 634 | * - WP_USE_EXT_MYSQL is defined as false, or |
@@ -678,8 +679,9 @@ discard block |
||
| 678 | 679 | * @return mixed The private member |
| 679 | 680 | */ |
| 680 | 681 | public function __get( $name ) { |
| 681 | - if ( 'col_info' === $name ) |
|
| 682 | - $this->load_col_info(); |
|
| 682 | + if ( 'col_info' === $name ) { |
|
| 683 | + $this->load_col_info(); |
|
| 684 | + } |
|
| 683 | 685 | |
| 684 | 686 | return $this->$name; |
| 685 | 687 | } |
@@ -772,18 +774,21 @@ discard block |
||
| 772 | 774 | * @param string $collate Optional. The collation. Default null. |
| 773 | 775 | */ |
| 774 | 776 | public function set_charset( $dbh, $charset = null, $collate = null ) { |
| 775 | - if ( ! isset( $charset ) ) |
|
| 776 | - $charset = $this->charset; |
|
| 777 | - if ( ! isset( $collate ) ) |
|
| 778 | - $collate = $this->collate; |
|
| 777 | + if ( ! isset( $charset ) ) { |
|
| 778 | + $charset = $this->charset; |
|
| 779 | + } |
|
| 780 | + if ( ! isset( $collate ) ) { |
|
| 781 | + $collate = $this->collate; |
|
| 782 | + } |
|
| 779 | 783 | if ( $this->has_cap( 'collation' ) && ! empty( $charset ) ) { |
| 780 | 784 | if ( $this->use_mysqli ) { |
| 781 | 785 | if ( function_exists( 'mysqli_set_charset' ) && $this->has_cap( 'set_charset' ) ) { |
| 782 | 786 | mysqli_set_charset( $dbh, $charset ); |
| 783 | 787 | } else { |
| 784 | 788 | $query = $this->prepare( 'SET NAMES %s', $charset ); |
| 785 | - if ( ! empty( $collate ) ) |
|
| 786 | - $query .= $this->prepare( ' COLLATE %s', $collate ); |
|
| 789 | + if ( ! empty( $collate ) ) { |
|
| 790 | + $query .= $this->prepare( ' COLLATE %s', $collate ); |
|
| 791 | + } |
|
| 787 | 792 | mysqli_query( $dbh, $query ); |
| 788 | 793 | } |
| 789 | 794 | } else { |
@@ -791,8 +796,9 @@ discard block |
||
| 791 | 796 | mysql_set_charset( $charset, $dbh ); |
| 792 | 797 | } else { |
| 793 | 798 | $query = $this->prepare( 'SET NAMES %s', $charset ); |
| 794 | - if ( ! empty( $collate ) ) |
|
| 795 | - $query .= $this->prepare( ' COLLATE %s', $collate ); |
|
| 799 | + if ( ! empty( $collate ) ) { |
|
| 800 | + $query .= $this->prepare( ' COLLATE %s', $collate ); |
|
| 801 | + } |
|
| 796 | 802 | mysql_query( $query, $dbh ); |
| 797 | 803 | } |
| 798 | 804 | } |
@@ -875,30 +881,36 @@ discard block |
||
| 875 | 881 | */ |
| 876 | 882 | public function set_prefix( $prefix, $set_table_names = true ) { |
| 877 | 883 | |
| 878 | - if ( preg_match( '|[^a-z0-9_]|i', $prefix ) ) |
|
| 879 | - return new WP_Error('invalid_db_prefix', 'Invalid database prefix' ); |
|
| 884 | + if ( preg_match( '|[^a-z0-9_]|i', $prefix ) ) { |
|
| 885 | + return new WP_Error('invalid_db_prefix', 'Invalid database prefix' ); |
|
| 886 | + } |
|
| 880 | 887 | |
| 881 | 888 | $old_prefix = is_multisite() ? '' : $prefix; |
| 882 | 889 | |
| 883 | - if ( isset( $this->base_prefix ) ) |
|
| 884 | - $old_prefix = $this->base_prefix; |
|
| 890 | + if ( isset( $this->base_prefix ) ) { |
|
| 891 | + $old_prefix = $this->base_prefix; |
|
| 892 | + } |
|
| 885 | 893 | |
| 886 | 894 | $this->base_prefix = $prefix; |
| 887 | 895 | |
| 888 | 896 | if ( $set_table_names ) { |
| 889 | - foreach ( $this->tables( 'global' ) as $table => $prefixed_table ) |
|
| 890 | - $this->$table = $prefixed_table; |
|
| 897 | + foreach ( $this->tables( 'global' ) as $table => $prefixed_table ) { |
|
| 898 | + $this->$table = $prefixed_table; |
|
| 899 | + } |
|
| 891 | 900 | |
| 892 | - if ( is_multisite() && empty( $this->blogid ) ) |
|
| 893 | - return $old_prefix; |
|
| 901 | + if ( is_multisite() && empty( $this->blogid ) ) { |
|
| 902 | + return $old_prefix; |
|
| 903 | + } |
|
| 894 | 904 | |
| 895 | 905 | $this->prefix = $this->get_blog_prefix(); |
| 896 | 906 | |
| 897 | - foreach ( $this->tables( 'blog' ) as $table => $prefixed_table ) |
|
| 898 | - $this->$table = $prefixed_table; |
|
| 907 | + foreach ( $this->tables( 'blog' ) as $table => $prefixed_table ) { |
|
| 908 | + $this->$table = $prefixed_table; |
|
| 909 | + } |
|
| 899 | 910 | |
| 900 | - foreach ( $this->tables( 'old' ) as $table => $prefixed_table ) |
|
| 901 | - $this->$table = $prefixed_table; |
|
| 911 | + foreach ( $this->tables( 'old' ) as $table => $prefixed_table ) { |
|
| 912 | + $this->$table = $prefixed_table; |
|
| 913 | + } |
|
| 902 | 914 | } |
| 903 | 915 | return $old_prefix; |
| 904 | 916 | } |
@@ -914,19 +926,22 @@ discard block |
||
| 914 | 926 | * @return int previous blog id |
| 915 | 927 | */ |
| 916 | 928 | public function set_blog_id( $blog_id, $site_id = 0 ) { |
| 917 | - if ( ! empty( $site_id ) ) |
|
| 918 | - $this->siteid = $site_id; |
|
| 929 | + if ( ! empty( $site_id ) ) { |
|
| 930 | + $this->siteid = $site_id; |
|
| 931 | + } |
|
| 919 | 932 | |
| 920 | 933 | $old_blog_id = $this->blogid; |
| 921 | 934 | $this->blogid = $blog_id; |
| 922 | 935 | |
| 923 | 936 | $this->prefix = $this->get_blog_prefix(); |
| 924 | 937 | |
| 925 | - foreach ( $this->tables( 'blog' ) as $table => $prefixed_table ) |
|
| 926 | - $this->$table = $prefixed_table; |
|
| 938 | + foreach ( $this->tables( 'blog' ) as $table => $prefixed_table ) { |
|
| 939 | + $this->$table = $prefixed_table; |
|
| 940 | + } |
|
| 927 | 941 | |
| 928 | - foreach ( $this->tables( 'old' ) as $table => $prefixed_table ) |
|
| 929 | - $this->$table = $prefixed_table; |
|
| 942 | + foreach ( $this->tables( 'old' ) as $table => $prefixed_table ) { |
|
| 943 | + $this->$table = $prefixed_table; |
|
| 944 | + } |
|
| 930 | 945 | |
| 931 | 946 | return $old_blog_id; |
| 932 | 947 | } |
@@ -940,13 +955,15 @@ discard block |
||
| 940 | 955 | */ |
| 941 | 956 | public function get_blog_prefix( $blog_id = null ) { |
| 942 | 957 | if ( is_multisite() ) { |
| 943 | - if ( null === $blog_id ) |
|
| 944 | - $blog_id = $this->blogid; |
|
| 958 | + if ( null === $blog_id ) { |
|
| 959 | + $blog_id = $this->blogid; |
|
| 960 | + } |
|
| 945 | 961 | $blog_id = (int) $blog_id; |
| 946 | - if ( defined( 'MULTISITE' ) && ( 0 == $blog_id || 1 == $blog_id ) ) |
|
| 947 | - return $this->base_prefix; |
|
| 948 | - else |
|
| 949 | - return $this->base_prefix . $blog_id . '_'; |
|
| 962 | + if ( defined( 'MULTISITE' ) && ( 0 == $blog_id || 1 == $blog_id ) ) { |
|
| 963 | + return $this->base_prefix; |
|
| 964 | + } else { |
|
| 965 | + return $this->base_prefix . $blog_id . '_'; |
|
| 966 | + } |
|
| 950 | 967 | } else { |
| 951 | 968 | return $this->base_prefix; |
| 952 | 969 | } |
@@ -983,16 +1000,18 @@ discard block |
||
| 983 | 1000 | switch ( $scope ) { |
| 984 | 1001 | case 'all' : |
| 985 | 1002 | $tables = array_merge( $this->global_tables, $this->tables ); |
| 986 | - if ( is_multisite() ) |
|
| 987 | - $tables = array_merge( $tables, $this->ms_global_tables ); |
|
| 1003 | + if ( is_multisite() ) { |
|
| 1004 | + $tables = array_merge( $tables, $this->ms_global_tables ); |
|
| 1005 | + } |
|
| 988 | 1006 | break; |
| 989 | 1007 | case 'blog' : |
| 990 | 1008 | $tables = $this->tables; |
| 991 | 1009 | break; |
| 992 | 1010 | case 'global' : |
| 993 | 1011 | $tables = $this->global_tables; |
| 994 | - if ( is_multisite() ) |
|
| 995 | - $tables = array_merge( $tables, $this->ms_global_tables ); |
|
| 1012 | + if ( is_multisite() ) { |
|
| 1013 | + $tables = array_merge( $tables, $this->ms_global_tables ); |
|
| 1014 | + } |
|
| 996 | 1015 | break; |
| 997 | 1016 | case 'ms_global' : |
| 998 | 1017 | $tables = $this->ms_global_tables; |
@@ -1005,24 +1024,28 @@ discard block |
||
| 1005 | 1024 | } |
| 1006 | 1025 | |
| 1007 | 1026 | if ( $prefix ) { |
| 1008 | - if ( ! $blog_id ) |
|
| 1009 | - $blog_id = $this->blogid; |
|
| 1027 | + if ( ! $blog_id ) { |
|
| 1028 | + $blog_id = $this->blogid; |
|
| 1029 | + } |
|
| 1010 | 1030 | $blog_prefix = $this->get_blog_prefix( $blog_id ); |
| 1011 | 1031 | $base_prefix = $this->base_prefix; |
| 1012 | 1032 | $global_tables = array_merge( $this->global_tables, $this->ms_global_tables ); |
| 1013 | 1033 | foreach ( $tables as $k => $table ) { |
| 1014 | - if ( in_array( $table, $global_tables ) ) |
|
| 1015 | - $tables[ $table ] = $base_prefix . $table; |
|
| 1016 | - else |
|
| 1017 | - $tables[ $table ] = $blog_prefix . $table; |
|
| 1034 | + if ( in_array( $table, $global_tables ) ) { |
|
| 1035 | + $tables[ $table ] = $base_prefix . $table; |
|
| 1036 | + } else { |
|
| 1037 | + $tables[ $table ] = $blog_prefix . $table; |
|
| 1038 | + } |
|
| 1018 | 1039 | unset( $tables[ $k ] ); |
| 1019 | 1040 | } |
| 1020 | 1041 | |
| 1021 | - if ( isset( $tables['users'] ) && defined( 'CUSTOM_USER_TABLE' ) ) |
|
| 1022 | - $tables['users'] = CUSTOM_USER_TABLE; |
|
| 1042 | + if ( isset( $tables['users'] ) && defined( 'CUSTOM_USER_TABLE' ) ) { |
|
| 1043 | + $tables['users'] = CUSTOM_USER_TABLE; |
|
| 1044 | + } |
|
| 1023 | 1045 | |
| 1024 | - if ( isset( $tables['usermeta'] ) && defined( 'CUSTOM_USER_META_TABLE' ) ) |
|
| 1025 | - $tables['usermeta'] = CUSTOM_USER_META_TABLE; |
|
| 1046 | + if ( isset( $tables['usermeta'] ) && defined( 'CUSTOM_USER_META_TABLE' ) ) { |
|
| 1047 | + $tables['usermeta'] = CUSTOM_USER_META_TABLE; |
|
| 1048 | + } |
|
| 1026 | 1049 | } |
| 1027 | 1050 | |
| 1028 | 1051 | return $tables; |
@@ -1040,8 +1063,9 @@ discard block |
||
| 1040 | 1063 | * @param resource|null $dbh Optional link identifier. |
| 1041 | 1064 | */ |
| 1042 | 1065 | public function select( $db, $dbh = null ) { |
| 1043 | - if ( is_null($dbh) ) |
|
| 1044 | - $dbh = $this->dbh; |
|
| 1066 | + if ( is_null($dbh) ) { |
|
| 1067 | + $dbh = $this->dbh; |
|
| 1068 | + } |
|
| 1045 | 1069 | |
| 1046 | 1070 | if ( $this->use_mysqli ) { |
| 1047 | 1071 | $success = mysqli_select_db( $dbh, $db ); |
@@ -1105,8 +1129,9 @@ discard block |
||
| 1105 | 1129 | * @return string |
| 1106 | 1130 | */ |
| 1107 | 1131 | function _weak_escape( $string ) { |
| 1108 | - if ( func_num_args() === 1 && function_exists( '_deprecated_function' ) ) |
|
| 1109 | - _deprecated_function( __METHOD__, '3.6', 'wpdb::prepare() or esc_sql()' ); |
|
| 1132 | + if ( func_num_args() === 1 && function_exists( '_deprecated_function' ) ) { |
|
| 1133 | + _deprecated_function( __METHOD__, '3.6', 'wpdb::prepare() or esc_sql()' ); |
|
| 1134 | + } |
|
| 1110 | 1135 | return addslashes( $string ); |
| 1111 | 1136 | } |
| 1112 | 1137 | |
@@ -1153,10 +1178,11 @@ discard block |
||
| 1153 | 1178 | function _escape( $data ) { |
| 1154 | 1179 | if ( is_array( $data ) ) { |
| 1155 | 1180 | foreach ( $data as $k => $v ) { |
| 1156 | - if ( is_array($v) ) |
|
| 1157 | - $data[$k] = $this->_escape( $v ); |
|
| 1158 | - else |
|
| 1159 | - $data[$k] = $this->_real_escape( $v ); |
|
| 1181 | + if ( is_array($v) ) { |
|
| 1182 | + $data[$k] = $this->_escape( $v ); |
|
| 1183 | + } else { |
|
| 1184 | + $data[$k] = $this->_real_escape( $v ); |
|
| 1185 | + } |
|
| 1160 | 1186 | } |
| 1161 | 1187 | } else { |
| 1162 | 1188 | $data = $this->_real_escape( $data ); |
@@ -1179,14 +1205,16 @@ discard block |
||
| 1179 | 1205 | * @return mixed |
| 1180 | 1206 | */ |
| 1181 | 1207 | public function escape( $data ) { |
| 1182 | - if ( func_num_args() === 1 && function_exists( '_deprecated_function' ) ) |
|
| 1183 | - _deprecated_function( __METHOD__, '3.6', 'wpdb::prepare() or esc_sql()' ); |
|
| 1208 | + if ( func_num_args() === 1 && function_exists( '_deprecated_function' ) ) { |
|
| 1209 | + _deprecated_function( __METHOD__, '3.6', 'wpdb::prepare() or esc_sql()' ); |
|
| 1210 | + } |
|
| 1184 | 1211 | if ( is_array( $data ) ) { |
| 1185 | 1212 | foreach ( $data as $k => $v ) { |
| 1186 | - if ( is_array( $v ) ) |
|
| 1187 | - $data[$k] = $this->escape( $v, 'recursive' ); |
|
| 1188 | - else |
|
| 1189 | - $data[$k] = $this->_weak_escape( $v, 'internal' ); |
|
| 1213 | + if ( is_array( $v ) ) { |
|
| 1214 | + $data[$k] = $this->escape( $v, 'recursive' ); |
|
| 1215 | + } else { |
|
| 1216 | + $data[$k] = $this->_weak_escape( $v, 'internal' ); |
|
| 1217 | + } |
|
| 1190 | 1218 | } |
| 1191 | 1219 | } else { |
| 1192 | 1220 | $data = $this->_weak_escape( $data, 'internal' ); |
@@ -1205,8 +1233,9 @@ discard block |
||
| 1205 | 1233 | * @param string $string to escape |
| 1206 | 1234 | */ |
| 1207 | 1235 | public function escape_by_ref( &$string ) { |
| 1208 | - if ( ! is_float( $string ) ) |
|
| 1209 | - $string = $this->_real_escape( $string ); |
|
| 1236 | + if ( ! is_float( $string ) ) { |
|
| 1237 | + $string = $this->_real_escape( $string ); |
|
| 1238 | + } |
|
| 1210 | 1239 | } |
| 1211 | 1240 | |
| 1212 | 1241 | /** |
@@ -1244,8 +1273,9 @@ discard block |
||
| 1244 | 1273 | * @return string|void Sanitized query string, if there is a query to prepare. |
| 1245 | 1274 | */ |
| 1246 | 1275 | public function prepare( $query, $args ) { |
| 1247 | - if ( is_null( $query ) ) |
|
| 1248 | - return; |
|
| 1276 | + if ( is_null( $query ) ) { |
|
| 1277 | + return; |
|
| 1278 | + } |
|
| 1249 | 1279 | |
| 1250 | 1280 | // This is not meant to be foolproof -- but it will catch obviously incorrect usage. |
| 1251 | 1281 | if ( strpos( $query, '%' ) === false ) { |
@@ -1255,8 +1285,9 @@ discard block |
||
| 1255 | 1285 | $args = func_get_args(); |
| 1256 | 1286 | array_shift( $args ); |
| 1257 | 1287 | // If args were passed as an array (as in vsprintf), move them up |
| 1258 | - if ( isset( $args[0] ) && is_array($args[0]) ) |
|
| 1259 | - $args = $args[0]; |
|
| 1288 | + if ( isset( $args[0] ) && is_array($args[0]) ) { |
|
| 1289 | + $args = $args[0]; |
|
| 1290 | + } |
|
| 1260 | 1291 | $query = str_replace( "'%s'", '%s', $query ); // in case someone mistakenly already singlequoted it |
| 1261 | 1292 | $query = str_replace( '"%s"', '%s', $query ); // doublequote unquoting |
| 1262 | 1293 | $query = preg_replace( '|(?<!%)%f|' , '%F', $query ); // Force floats to be locale unaware |
@@ -1312,21 +1343,24 @@ discard block |
||
| 1312 | 1343 | } |
| 1313 | 1344 | $EZSQL_ERROR[] = array( 'query' => $this->last_query, 'error_str' => $str ); |
| 1314 | 1345 | |
| 1315 | - if ( $this->suppress_errors ) |
|
| 1316 | - return false; |
|
| 1346 | + if ( $this->suppress_errors ) { |
|
| 1347 | + return false; |
|
| 1348 | + } |
|
| 1317 | 1349 | |
| 1318 | 1350 | wp_load_translations_early(); |
| 1319 | 1351 | |
| 1320 | - if ( $caller = $this->get_caller() ) |
|
| 1321 | - $error_str = sprintf( __( 'WordPress database error %1$s for query %2$s made by %3$s' ), $str, $this->last_query, $caller ); |
|
| 1322 | - else |
|
| 1323 | - $error_str = sprintf( __( 'WordPress database error %1$s for query %2$s' ), $str, $this->last_query ); |
|
| 1352 | + if ( $caller = $this->get_caller() ) { |
|
| 1353 | + $error_str = sprintf( __( 'WordPress database error %1$s for query %2$s made by %3$s' ), $str, $this->last_query, $caller ); |
|
| 1354 | + } else { |
|
| 1355 | + $error_str = sprintf( __( 'WordPress database error %1$s for query %2$s' ), $str, $this->last_query ); |
|
| 1356 | + } |
|
| 1324 | 1357 | |
| 1325 | 1358 | error_log( $error_str ); |
| 1326 | 1359 | |
| 1327 | 1360 | // Are we showing errors? |
| 1328 | - if ( ! $this->show_errors ) |
|
| 1329 | - return false; |
|
| 1361 | + if ( ! $this->show_errors ) { |
|
| 1362 | + return false; |
|
| 1363 | + } |
|
| 1330 | 1364 | |
| 1331 | 1365 | // If there is an error then take note of it |
| 1332 | 1366 | if ( is_multisite() ) { |
@@ -1734,8 +1768,9 @@ discard block |
||
| 1734 | 1768 | |
| 1735 | 1769 | if ( $this->last_error ) { |
| 1736 | 1770 | // Clear insert_id on a subsequent failed insert. |
| 1737 | - if ( $this->insert_id && preg_match( '/^\s*(insert|replace)\s/i', $query ) ) |
|
| 1738 | - $this->insert_id = 0; |
|
| 1771 | + if ( $this->insert_id && preg_match( '/^\s*(insert|replace)\s/i', $query ) ) { |
|
| 1772 | + $this->insert_id = 0; |
|
| 1773 | + } |
|
| 1739 | 1774 | |
| 1740 | 1775 | $this->print_error(); |
| 1741 | 1776 | return false; |
@@ -2241,8 +2276,9 @@ discard block |
||
| 2241 | 2276 | return null; |
| 2242 | 2277 | } |
| 2243 | 2278 | |
| 2244 | - if ( !isset( $this->last_result[$y] ) ) |
|
| 2245 | - return null; |
|
| 2279 | + if ( !isset( $this->last_result[$y] ) ) { |
|
| 2280 | + return null; |
|
| 2281 | + } |
|
| 2246 | 2282 | |
| 2247 | 2283 | if ( $output == OBJECT ) { |
| 2248 | 2284 | return $this->last_result[$y] ? $this->last_result[$y] : null; |
@@ -2326,8 +2362,9 @@ discard block |
||
| 2326 | 2362 | foreach ( $this->last_result as $row ) { |
| 2327 | 2363 | $var_by_ref = get_object_vars( $row ); |
| 2328 | 2364 | $key = array_shift( $var_by_ref ); |
| 2329 | - if ( ! isset( $new_array[ $key ] ) ) |
|
| 2330 | - $new_array[ $key ] = $row; |
|
| 2365 | + if ( ! isset( $new_array[ $key ] ) ) { |
|
| 2366 | + $new_array[ $key ] = $row; |
|
| 2367 | + } |
|
| 2331 | 2368 | } |
| 2332 | 2369 | return $new_array; |
| 2333 | 2370 | } elseif ( $output == ARRAY_A || $output == ARRAY_N ) { |
@@ -3004,8 +3041,9 @@ discard block |
||
| 3004 | 3041 | * @access protected |
| 3005 | 3042 | */ |
| 3006 | 3043 | protected function load_col_info() { |
| 3007 | - if ( $this->col_info ) |
|
| 3008 | - return; |
|
| 3044 | + if ( $this->col_info ) { |
|
| 3045 | + return; |
|
| 3046 | + } |
|
| 3009 | 3047 | |
| 3010 | 3048 | if ( $this->use_mysqli ) { |
| 3011 | 3049 | $num_fields = mysqli_num_fields( $this->result ); |
@@ -3136,8 +3174,9 @@ discard block |
||
| 3136 | 3174 | public function check_database_version() { |
| 3137 | 3175 | global $wp_version, $required_mysql_version; |
| 3138 | 3176 | // Make sure the server has the required MySQL version |
| 3139 | - if ( version_compare($this->db_version(), $required_mysql_version, '<') ) |
|
| 3140 | - return new WP_Error('database_version', sprintf( __( '<strong>ERROR</strong>: WordPress %1$s requires MySQL %2$s or higher' ), $wp_version, $required_mysql_version )); |
|
| 3177 | + if ( version_compare($this->db_version(), $required_mysql_version, '<') ) { |
|
| 3178 | + return new WP_Error('database_version', sprintf( __( '<strong>ERROR</strong>: WordPress %1$s requires MySQL %2$s or higher' ), $wp_version, $required_mysql_version )); |
|
| 3179 | + } |
|
| 3141 | 3180 | } |
| 3142 | 3181 | |
| 3143 | 3182 | /** |
@@ -3167,10 +3206,12 @@ discard block |
||
| 3167 | 3206 | public function get_charset_collate() { |
| 3168 | 3207 | $charset_collate = ''; |
| 3169 | 3208 | |
| 3170 | - if ( ! empty( $this->charset ) ) |
|
| 3171 | - $charset_collate = "DEFAULT CHARACTER SET $this->charset"; |
|
| 3172 | - if ( ! empty( $this->collate ) ) |
|
| 3173 | - $charset_collate .= " COLLATE $this->collate"; |
|
| 3209 | + if ( ! empty( $this->charset ) ) { |
|
| 3210 | + $charset_collate = "DEFAULT CHARACTER SET $this->charset"; |
|
| 3211 | + } |
|
| 3212 | + if ( ! empty( $this->collate ) ) { |
|
| 3213 | + $charset_collate .= " COLLATE $this->collate"; |
|
| 3214 | + } |
|
| 3174 | 3215 | |
| 3175 | 3216 | return $charset_collate; |
| 3176 | 3217 | } |
@@ -1,13 +1,13 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * The template for displaying the footer |
|
| 4 | - * |
|
| 5 | - * Contains footer content and the closing of the #main and #page div elements. |
|
| 6 | - * |
|
| 7 | - * @package WordPress |
|
| 8 | - * @subpackage Twenty_Thirteen |
|
| 9 | - * @since Twenty Thirteen 1.0 |
|
| 10 | - */ |
|
| 3 | + * The template for displaying the footer |
|
| 4 | + * |
|
| 5 | + * Contains footer content and the closing of the #main and #page div elements. |
|
| 6 | + * |
|
| 7 | + * @package WordPress |
|
| 8 | + * @subpackage Twenty_Thirteen |
|
| 9 | + * @since Twenty Thirteen 1.0 |
|
| 10 | + */ |
|
| 11 | 11 | ?> |
| 12 | 12 | |
| 13 | 13 | </div><!-- #main --> |
@@ -12,11 +12,11 @@ |
||
| 12 | 12 | |
| 13 | 13 | </div><!-- #main --> |
| 14 | 14 | <footer id="colophon" class="site-footer" role="contentinfo"> |
| 15 | - <?php get_sidebar( 'main' ); ?> |
|
| 15 | + <?php get_sidebar('main'); ?> |
|
| 16 | 16 | |
| 17 | 17 | <div class="site-info"> |
| 18 | - <?php do_action( 'twentythirteen_credits' ); ?> |
|
| 19 | - <a href="<?php echo esc_url( __( 'https://wordpress.org/', 'twentythirteen' ) ); ?>"><?php printf( __( 'Proudly powered by %s', 'twentythirteen' ), 'WordPress' ); ?></a> |
|
| 18 | + <?php do_action('twentythirteen_credits'); ?> |
|
| 19 | + <a href="<?php echo esc_url(__('https://wordpress.org/', 'twentythirteen')); ?>"><?php printf(__('Proudly powered by %s', 'twentythirteen'), 'WordPress'); ?></a> |
|
| 20 | 20 | </div><!-- .site-info --> |
| 21 | 21 | </footer><!-- #colophon --> |
| 22 | 22 | </div><!-- #page --> |
@@ -30,18 +30,18 @@ discard block |
||
| 30 | 30 | * |
| 31 | 31 | * @since Twenty Fifteen 1.0 |
| 32 | 32 | */ |
| 33 | -if ( ! isset( $content_width ) ) { |
|
| 33 | +if ( ! isset($content_width)) { |
|
| 34 | 34 | $content_width = 660; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | 38 | * Twenty Fifteen only works in WordPress 4.1 or later. |
| 39 | 39 | */ |
| 40 | -if ( version_compare( $GLOBALS['wp_version'], '4.1-alpha', '<' ) ) { |
|
| 41 | - require get_template_directory() . '/inc/back-compat.php'; |
|
| 40 | +if (version_compare($GLOBALS['wp_version'], '4.1-alpha', '<')) { |
|
| 41 | + require get_template_directory().'/inc/back-compat.php'; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | -if ( ! function_exists( 'twentyfifteen_setup' ) ) : |
|
| 44 | +if ( ! function_exists('twentyfifteen_setup')) : |
|
| 45 | 45 | /** |
| 46 | 46 | * Sets up theme defaults and registers support for various WordPress features. |
| 47 | 47 | * |
@@ -59,10 +59,10 @@ discard block |
||
| 59 | 59 | * If you're building a theme based on twentyfifteen, use a find and replace |
| 60 | 60 | * to change 'twentyfifteen' to the name of your theme in all the template files |
| 61 | 61 | */ |
| 62 | - load_theme_textdomain( 'twentyfifteen', get_template_directory() . '/languages' ); |
|
| 62 | + load_theme_textdomain('twentyfifteen', get_template_directory().'/languages'); |
|
| 63 | 63 | |
| 64 | 64 | // Add default posts and comments RSS feed links to head. |
| 65 | - add_theme_support( 'automatic-feed-links' ); |
|
| 65 | + add_theme_support('automatic-feed-links'); |
|
| 66 | 66 | |
| 67 | 67 | /* |
| 68 | 68 | * Let WordPress manage the document title. |
@@ -70,64 +70,64 @@ discard block |
||
| 70 | 70 | * hard-coded <title> tag in the document head, and expect WordPress to |
| 71 | 71 | * provide it for us. |
| 72 | 72 | */ |
| 73 | - add_theme_support( 'title-tag' ); |
|
| 73 | + add_theme_support('title-tag'); |
|
| 74 | 74 | |
| 75 | 75 | /* |
| 76 | 76 | * Enable support for Post Thumbnails on posts and pages. |
| 77 | 77 | * |
| 78 | 78 | * See: https://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails |
| 79 | 79 | */ |
| 80 | - add_theme_support( 'post-thumbnails' ); |
|
| 81 | - set_post_thumbnail_size( 825, 510, true ); |
|
| 80 | + add_theme_support('post-thumbnails'); |
|
| 81 | + set_post_thumbnail_size(825, 510, true); |
|
| 82 | 82 | |
| 83 | 83 | // This theme uses wp_nav_menu() in two locations. |
| 84 | - register_nav_menus( array( |
|
| 85 | - 'primary' => __( 'Primary Menu', 'twentyfifteen' ), |
|
| 86 | - 'social' => __( 'Social Links Menu', 'twentyfifteen' ), |
|
| 87 | - ) ); |
|
| 84 | + register_nav_menus(array( |
|
| 85 | + 'primary' => __('Primary Menu', 'twentyfifteen'), |
|
| 86 | + 'social' => __('Social Links Menu', 'twentyfifteen'), |
|
| 87 | + )); |
|
| 88 | 88 | |
| 89 | 89 | /* |
| 90 | 90 | * Switch default core markup for search form, comment form, and comments |
| 91 | 91 | * to output valid HTML5. |
| 92 | 92 | */ |
| 93 | - add_theme_support( 'html5', array( |
|
| 93 | + add_theme_support('html5', array( |
|
| 94 | 94 | 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption' |
| 95 | - ) ); |
|
| 95 | + )); |
|
| 96 | 96 | |
| 97 | 97 | /* |
| 98 | 98 | * Enable support for Post Formats. |
| 99 | 99 | * |
| 100 | 100 | * See: https://codex.wordpress.org/Post_Formats |
| 101 | 101 | */ |
| 102 | - add_theme_support( 'post-formats', array( |
|
| 102 | + add_theme_support('post-formats', array( |
|
| 103 | 103 | 'aside', 'image', 'video', 'quote', 'link', 'gallery', 'status', 'audio', 'chat' |
| 104 | - ) ); |
|
| 104 | + )); |
|
| 105 | 105 | |
| 106 | 106 | /* |
| 107 | 107 | * Enable support for custom logo. |
| 108 | 108 | * |
| 109 | 109 | * @since Twenty Fifteen 1.5 |
| 110 | 110 | */ |
| 111 | - add_image_size( 'twentyfifteen-logo', 248, 248 ); |
|
| 112 | - add_theme_support( 'custom-logo', array( 'size' => 'twentyfifteen-logo' ) ); |
|
| 111 | + add_image_size('twentyfifteen-logo', 248, 248); |
|
| 112 | + add_theme_support('custom-logo', array('size' => 'twentyfifteen-logo')); |
|
| 113 | 113 | |
| 114 | 114 | $color_scheme = twentyfifteen_get_color_scheme(); |
| 115 | - $default_color = trim( $color_scheme[0], '#' ); |
|
| 115 | + $default_color = trim($color_scheme[0], '#'); |
|
| 116 | 116 | |
| 117 | 117 | // Setup the WordPress core custom background feature. |
| 118 | - add_theme_support( 'custom-background', apply_filters( 'twentyfifteen_custom_background_args', array( |
|
| 118 | + add_theme_support('custom-background', apply_filters('twentyfifteen_custom_background_args', array( |
|
| 119 | 119 | 'default-color' => $default_color, |
| 120 | 120 | 'default-attachment' => 'fixed', |
| 121 | - ) ) ); |
|
| 121 | + ))); |
|
| 122 | 122 | |
| 123 | 123 | /* |
| 124 | 124 | * This theme styles the visual editor to resemble the theme style, |
| 125 | 125 | * specifically font, colors, icons, and column width. |
| 126 | 126 | */ |
| 127 | - add_editor_style( array( 'css/editor-style.css', 'genericons/genericons.css', twentyfifteen_fonts_url() ) ); |
|
| 127 | + add_editor_style(array('css/editor-style.css', 'genericons/genericons.css', twentyfifteen_fonts_url())); |
|
| 128 | 128 | } |
| 129 | 129 | endif; // twentyfifteen_setup |
| 130 | -add_action( 'after_setup_theme', 'twentyfifteen_setup' ); |
|
| 130 | +add_action('after_setup_theme', 'twentyfifteen_setup'); |
|
| 131 | 131 | |
| 132 | 132 | /** |
| 133 | 133 | * Register widget area. |
@@ -137,19 +137,19 @@ discard block |
||
| 137 | 137 | * @link https://codex.wordpress.org/Function_Reference/register_sidebar |
| 138 | 138 | */ |
| 139 | 139 | function twentyfifteen_widgets_init() { |
| 140 | - register_sidebar( array( |
|
| 141 | - 'name' => __( 'Widget Area', 'twentyfifteen' ), |
|
| 140 | + register_sidebar(array( |
|
| 141 | + 'name' => __('Widget Area', 'twentyfifteen'), |
|
| 142 | 142 | 'id' => 'sidebar-1', |
| 143 | - 'description' => __( 'Add widgets here to appear in your sidebar.', 'twentyfifteen' ), |
|
| 143 | + 'description' => __('Add widgets here to appear in your sidebar.', 'twentyfifteen'), |
|
| 144 | 144 | 'before_widget' => '<aside id="%1$s" class="widget %2$s">', |
| 145 | 145 | 'after_widget' => '</aside>', |
| 146 | 146 | 'before_title' => '<h2 class="widget-title">', |
| 147 | 147 | 'after_title' => '</h2>', |
| 148 | - ) ); |
|
| 148 | + )); |
|
| 149 | 149 | } |
| 150 | -add_action( 'widgets_init', 'twentyfifteen_widgets_init' ); |
|
| 150 | +add_action('widgets_init', 'twentyfifteen_widgets_init'); |
|
| 151 | 151 | |
| 152 | -if ( ! function_exists( 'twentyfifteen_fonts_url' ) ) : |
|
| 152 | +if ( ! function_exists('twentyfifteen_fonts_url')) : |
|
| 153 | 153 | /** |
| 154 | 154 | * Register Google fonts for Twenty Fifteen. |
| 155 | 155 | * |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | * Translators: If there are characters in your language that are not supported |
| 167 | 167 | * by Noto Sans, translate this to 'off'. Do not translate into your own language. |
| 168 | 168 | */ |
| 169 | - if ( 'off' !== _x( 'on', 'Noto Sans font: on or off', 'twentyfifteen' ) ) { |
|
| 169 | + if ('off' !== _x('on', 'Noto Sans font: on or off', 'twentyfifteen')) { |
|
| 170 | 170 | $fonts[] = 'Noto Sans:400italic,700italic,400,700'; |
| 171 | 171 | } |
| 172 | 172 | |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | * Translators: If there are characters in your language that are not supported |
| 175 | 175 | * by Noto Serif, translate this to 'off'. Do not translate into your own language. |
| 176 | 176 | */ |
| 177 | - if ( 'off' !== _x( 'on', 'Noto Serif font: on or off', 'twentyfifteen' ) ) { |
|
| 177 | + if ('off' !== _x('on', 'Noto Serif font: on or off', 'twentyfifteen')) { |
|
| 178 | 178 | $fonts[] = 'Noto Serif:400italic,700italic,400,700'; |
| 179 | 179 | } |
| 180 | 180 | |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | * Translators: If there are characters in your language that are not supported |
| 183 | 183 | * by Inconsolata, translate this to 'off'. Do not translate into your own language. |
| 184 | 184 | */ |
| 185 | - if ( 'off' !== _x( 'on', 'Inconsolata font: on or off', 'twentyfifteen' ) ) { |
|
| 185 | + if ('off' !== _x('on', 'Inconsolata font: on or off', 'twentyfifteen')) { |
|
| 186 | 186 | $fonts[] = 'Inconsolata:400,700'; |
| 187 | 187 | } |
| 188 | 188 | |
@@ -190,23 +190,23 @@ discard block |
||
| 190 | 190 | * Translators: To add an additional character subset specific to your language, |
| 191 | 191 | * translate this to 'greek', 'cyrillic', 'devanagari' or 'vietnamese'. Do not translate into your own language. |
| 192 | 192 | */ |
| 193 | - $subset = _x( 'no-subset', 'Add new subset (greek, cyrillic, devanagari, vietnamese)', 'twentyfifteen' ); |
|
| 193 | + $subset = _x('no-subset', 'Add new subset (greek, cyrillic, devanagari, vietnamese)', 'twentyfifteen'); |
|
| 194 | 194 | |
| 195 | - if ( 'cyrillic' == $subset ) { |
|
| 195 | + if ('cyrillic' == $subset) { |
|
| 196 | 196 | $subsets .= ',cyrillic,cyrillic-ext'; |
| 197 | - } elseif ( 'greek' == $subset ) { |
|
| 197 | + } elseif ('greek' == $subset) { |
|
| 198 | 198 | $subsets .= ',greek,greek-ext'; |
| 199 | - } elseif ( 'devanagari' == $subset ) { |
|
| 199 | + } elseif ('devanagari' == $subset) { |
|
| 200 | 200 | $subsets .= ',devanagari'; |
| 201 | - } elseif ( 'vietnamese' == $subset ) { |
|
| 201 | + } elseif ('vietnamese' == $subset) { |
|
| 202 | 202 | $subsets .= ',vietnamese'; |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | - if ( $fonts ) { |
|
| 206 | - $fonts_url = add_query_arg( array( |
|
| 207 | - 'family' => urlencode( implode( '|', $fonts ) ), |
|
| 208 | - 'subset' => urlencode( $subsets ), |
|
| 209 | - ), 'https://fonts.googleapis.com/css' ); |
|
| 205 | + if ($fonts) { |
|
| 206 | + $fonts_url = add_query_arg(array( |
|
| 207 | + 'family' => urlencode(implode('|', $fonts)), |
|
| 208 | + 'subset' => urlencode($subsets), |
|
| 209 | + ), 'https://fonts.googleapis.com/css'); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | return $fonts_url; |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | function twentyfifteen_javascript_detection() { |
| 224 | 224 | echo "<script>(function(html){html.className = html.className.replace(/\bno-js\b/,'js')})(document.documentElement);</script>\n"; |
| 225 | 225 | } |
| 226 | -add_action( 'wp_head', 'twentyfifteen_javascript_detection', 0 ); |
|
| 226 | +add_action('wp_head', 'twentyfifteen_javascript_detection', 0); |
|
| 227 | 227 | |
| 228 | 228 | /** |
| 229 | 229 | * Enqueue scripts and styles. |
@@ -232,39 +232,39 @@ discard block |
||
| 232 | 232 | */ |
| 233 | 233 | function twentyfifteen_scripts() { |
| 234 | 234 | // Add custom fonts, used in the main stylesheet. |
| 235 | - wp_enqueue_style( 'twentyfifteen-fonts', twentyfifteen_fonts_url(), array(), null ); |
|
| 235 | + wp_enqueue_style('twentyfifteen-fonts', twentyfifteen_fonts_url(), array(), null); |
|
| 236 | 236 | |
| 237 | 237 | // Add Genericons, used in the main stylesheet. |
| 238 | - wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.2' ); |
|
| 238 | + wp_enqueue_style('genericons', get_template_directory_uri().'/genericons/genericons.css', array(), '3.2'); |
|
| 239 | 239 | |
| 240 | 240 | // Load our main stylesheet. |
| 241 | - wp_enqueue_style( 'twentyfifteen-style', get_stylesheet_uri() ); |
|
| 241 | + wp_enqueue_style('twentyfifteen-style', get_stylesheet_uri()); |
|
| 242 | 242 | |
| 243 | 243 | // Load the Internet Explorer specific stylesheet. |
| 244 | - wp_enqueue_style( 'twentyfifteen-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentyfifteen-style' ), '20141010' ); |
|
| 245 | - wp_style_add_data( 'twentyfifteen-ie', 'conditional', 'lt IE 9' ); |
|
| 244 | + wp_enqueue_style('twentyfifteen-ie', get_template_directory_uri().'/css/ie.css', array('twentyfifteen-style'), '20141010'); |
|
| 245 | + wp_style_add_data('twentyfifteen-ie', 'conditional', 'lt IE 9'); |
|
| 246 | 246 | |
| 247 | 247 | // Load the Internet Explorer 7 specific stylesheet. |
| 248 | - wp_enqueue_style( 'twentyfifteen-ie7', get_template_directory_uri() . '/css/ie7.css', array( 'twentyfifteen-style' ), '20141010' ); |
|
| 249 | - wp_style_add_data( 'twentyfifteen-ie7', 'conditional', 'lt IE 8' ); |
|
| 248 | + wp_enqueue_style('twentyfifteen-ie7', get_template_directory_uri().'/css/ie7.css', array('twentyfifteen-style'), '20141010'); |
|
| 249 | + wp_style_add_data('twentyfifteen-ie7', 'conditional', 'lt IE 8'); |
|
| 250 | 250 | |
| 251 | - wp_enqueue_script( 'twentyfifteen-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20141010', true ); |
|
| 251 | + wp_enqueue_script('twentyfifteen-skip-link-focus-fix', get_template_directory_uri().'/js/skip-link-focus-fix.js', array(), '20141010', true); |
|
| 252 | 252 | |
| 253 | - if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { |
|
| 254 | - wp_enqueue_script( 'comment-reply' ); |
|
| 253 | + if (is_singular() && comments_open() && get_option('thread_comments')) { |
|
| 254 | + wp_enqueue_script('comment-reply'); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - if ( is_singular() && wp_attachment_is_image() ) { |
|
| 258 | - wp_enqueue_script( 'twentyfifteen-keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array( 'jquery' ), '20141010' ); |
|
| 257 | + if (is_singular() && wp_attachment_is_image()) { |
|
| 258 | + wp_enqueue_script('twentyfifteen-keyboard-image-navigation', get_template_directory_uri().'/js/keyboard-image-navigation.js', array('jquery'), '20141010'); |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - wp_enqueue_script( 'twentyfifteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20150330', true ); |
|
| 262 | - wp_localize_script( 'twentyfifteen-script', 'screenReaderText', array( |
|
| 263 | - 'expand' => '<span class="screen-reader-text">' . __( 'expand child menu', 'twentyfifteen' ) . '</span>', |
|
| 264 | - 'collapse' => '<span class="screen-reader-text">' . __( 'collapse child menu', 'twentyfifteen' ) . '</span>', |
|
| 265 | - ) ); |
|
| 261 | + wp_enqueue_script('twentyfifteen-script', get_template_directory_uri().'/js/functions.js', array('jquery'), '20150330', true); |
|
| 262 | + wp_localize_script('twentyfifteen-script', 'screenReaderText', array( |
|
| 263 | + 'expand' => '<span class="screen-reader-text">'.__('expand child menu', 'twentyfifteen').'</span>', |
|
| 264 | + 'collapse' => '<span class="screen-reader-text">'.__('collapse child menu', 'twentyfifteen').'</span>', |
|
| 265 | + )); |
|
| 266 | 266 | } |
| 267 | -add_action( 'wp_enqueue_scripts', 'twentyfifteen_scripts' ); |
|
| 267 | +add_action('wp_enqueue_scripts', 'twentyfifteen_scripts'); |
|
| 268 | 268 | |
| 269 | 269 | /** |
| 270 | 270 | * Add featured image as background image to post navigation elements. |
@@ -274,39 +274,39 @@ discard block |
||
| 274 | 274 | * @see wp_add_inline_style() |
| 275 | 275 | */ |
| 276 | 276 | function twentyfifteen_post_nav_background() { |
| 277 | - if ( ! is_single() ) { |
|
| 277 | + if ( ! is_single()) { |
|
| 278 | 278 | return; |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | - $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true ); |
|
| 282 | - $next = get_adjacent_post( false, '', false ); |
|
| 281 | + $previous = (is_attachment()) ? get_post(get_post()->post_parent) : get_adjacent_post(false, '', true); |
|
| 282 | + $next = get_adjacent_post(false, '', false); |
|
| 283 | 283 | $css = ''; |
| 284 | 284 | |
| 285 | - if ( is_attachment() && 'attachment' == $previous->post_type ) { |
|
| 285 | + if (is_attachment() && 'attachment' == $previous->post_type) { |
|
| 286 | 286 | return; |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | - if ( $previous && has_post_thumbnail( $previous->ID ) ) { |
|
| 290 | - $prevthumb = wp_get_attachment_image_src( get_post_thumbnail_id( $previous->ID ), 'post-thumbnail' ); |
|
| 289 | + if ($previous && has_post_thumbnail($previous->ID)) { |
|
| 290 | + $prevthumb = wp_get_attachment_image_src(get_post_thumbnail_id($previous->ID), 'post-thumbnail'); |
|
| 291 | 291 | $css .= ' |
| 292 | - .post-navigation .nav-previous { background-image: url(' . esc_url( $prevthumb[0] ) . '); } |
|
| 292 | + .post-navigation .nav-previous { background-image: url(' . esc_url($prevthumb[0]).'); } |
|
| 293 | 293 | .post-navigation .nav-previous .post-title, .post-navigation .nav-previous a:hover .post-title, .post-navigation .nav-previous .meta-nav { color: #fff; } |
| 294 | 294 | .post-navigation .nav-previous a:before { background-color: rgba(0, 0, 0, 0.4); } |
| 295 | 295 | '; |
| 296 | 296 | } |
| 297 | 297 | |
| 298 | - if ( $next && has_post_thumbnail( $next->ID ) ) { |
|
| 299 | - $nextthumb = wp_get_attachment_image_src( get_post_thumbnail_id( $next->ID ), 'post-thumbnail' ); |
|
| 298 | + if ($next && has_post_thumbnail($next->ID)) { |
|
| 299 | + $nextthumb = wp_get_attachment_image_src(get_post_thumbnail_id($next->ID), 'post-thumbnail'); |
|
| 300 | 300 | $css .= ' |
| 301 | - .post-navigation .nav-next { background-image: url(' . esc_url( $nextthumb[0] ) . '); border-top: 0; } |
|
| 301 | + .post-navigation .nav-next { background-image: url(' . esc_url($nextthumb[0]).'); border-top: 0; } |
|
| 302 | 302 | .post-navigation .nav-next .post-title, .post-navigation .nav-next a:hover .post-title, .post-navigation .nav-next .meta-nav { color: #fff; } |
| 303 | 303 | .post-navigation .nav-next a:before { background-color: rgba(0, 0, 0, 0.4); } |
| 304 | 304 | '; |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | - wp_add_inline_style( 'twentyfifteen-style', $css ); |
|
| 307 | + wp_add_inline_style('twentyfifteen-style', $css); |
|
| 308 | 308 | } |
| 309 | -add_action( 'wp_enqueue_scripts', 'twentyfifteen_post_nav_background' ); |
|
| 309 | +add_action('wp_enqueue_scripts', 'twentyfifteen_post_nav_background'); |
|
| 310 | 310 | |
| 311 | 311 | /** |
| 312 | 312 | * Display descriptions in main navigation. |
@@ -319,14 +319,14 @@ discard block |
||
| 319 | 319 | * @param array $args wp_nav_menu() arguments. |
| 320 | 320 | * @return string Menu item with possible description. |
| 321 | 321 | */ |
| 322 | -function twentyfifteen_nav_description( $item_output, $item, $depth, $args ) { |
|
| 323 | - if ( 'primary' == $args->theme_location && $item->description ) { |
|
| 324 | - $item_output = str_replace( $args->link_after . '</a>', '<div class="menu-item-description">' . $item->description . '</div>' . $args->link_after . '</a>', $item_output ); |
|
| 322 | +function twentyfifteen_nav_description($item_output, $item, $depth, $args) { |
|
| 323 | + if ('primary' == $args->theme_location && $item->description) { |
|
| 324 | + $item_output = str_replace($args->link_after.'</a>', '<div class="menu-item-description">'.$item->description.'</div>'.$args->link_after.'</a>', $item_output); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | return $item_output; |
| 328 | 328 | } |
| 329 | -add_filter( 'walker_nav_menu_start_el', 'twentyfifteen_nav_description', 10, 4 ); |
|
| 329 | +add_filter('walker_nav_menu_start_el', 'twentyfifteen_nav_description', 10, 4); |
|
| 330 | 330 | |
| 331 | 331 | /** |
| 332 | 332 | * Add a `screen-reader-text` class to the search form's submit button. |
@@ -336,28 +336,28 @@ discard block |
||
| 336 | 336 | * @param string $html Search form HTML. |
| 337 | 337 | * @return string Modified search form HTML. |
| 338 | 338 | */ |
| 339 | -function twentyfifteen_search_form_modify( $html ) { |
|
| 340 | - return str_replace( 'class="search-submit"', 'class="search-submit screen-reader-text"', $html ); |
|
| 339 | +function twentyfifteen_search_form_modify($html) { |
|
| 340 | + return str_replace('class="search-submit"', 'class="search-submit screen-reader-text"', $html); |
|
| 341 | 341 | } |
| 342 | -add_filter( 'get_search_form', 'twentyfifteen_search_form_modify' ); |
|
| 342 | +add_filter('get_search_form', 'twentyfifteen_search_form_modify'); |
|
| 343 | 343 | |
| 344 | 344 | /** |
| 345 | 345 | * Implement the Custom Header feature. |
| 346 | 346 | * |
| 347 | 347 | * @since Twenty Fifteen 1.0 |
| 348 | 348 | */ |
| 349 | -require get_template_directory() . '/inc/custom-header.php'; |
|
| 349 | +require get_template_directory().'/inc/custom-header.php'; |
|
| 350 | 350 | |
| 351 | 351 | /** |
| 352 | 352 | * Custom template tags for this theme. |
| 353 | 353 | * |
| 354 | 354 | * @since Twenty Fifteen 1.0 |
| 355 | 355 | */ |
| 356 | -require get_template_directory() . '/inc/template-tags.php'; |
|
| 356 | +require get_template_directory().'/inc/template-tags.php'; |
|
| 357 | 357 | |
| 358 | 358 | /** |
| 359 | 359 | * Customizer additions. |
| 360 | 360 | * |
| 361 | 361 | * @since Twenty Fifteen 1.0 |
| 362 | 362 | */ |
| 363 | -require get_template_directory() . '/inc/customizer.php'; |
|
| 363 | +require get_template_directory().'/inc/customizer.php'; |
|
@@ -1,13 +1,13 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Custom template tags for Twenty Fifteen |
|
| 4 | - * |
|
| 5 | - * Eventually, some of the functionality here could be replaced by core features. |
|
| 6 | - * |
|
| 7 | - * @package WordPress |
|
| 8 | - * @subpackage Twenty_Fifteen |
|
| 9 | - * @since Twenty Fifteen 1.0 |
|
| 10 | - */ |
|
| 3 | + * Custom template tags for Twenty Fifteen |
|
| 4 | + * |
|
| 5 | + * Eventually, some of the functionality here could be replaced by core features. |
|
| 6 | + * |
|
| 7 | + * @package WordPress |
|
| 8 | + * @subpackage Twenty_Fifteen |
|
| 9 | + * @since Twenty Fifteen 1.0 |
|
| 10 | + */ |
|
| 11 | 11 | |
| 12 | 12 | if ( ! function_exists( 'twentyfifteen_comment_nav' ) ) : |
| 13 | 13 | /** |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | * @since Twenty Fifteen 1.0 |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | -if ( ! function_exists( 'twentyfifteen_comment_nav' ) ) : |
|
| 12 | +if ( ! function_exists('twentyfifteen_comment_nav')) : |
|
| 13 | 13 | /** |
| 14 | 14 | * Display navigation to next/previous comments when applicable. |
| 15 | 15 | * |
@@ -17,18 +17,18 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | function twentyfifteen_comment_nav() { |
| 19 | 19 | // Are there comments to navigate through? |
| 20 | - if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : |
|
| 20 | + if (get_comment_pages_count() > 1 && get_option('page_comments')) : |
|
| 21 | 21 | ?> |
| 22 | 22 | <nav class="navigation comment-navigation" role="navigation"> |
| 23 | - <h2 class="screen-reader-text"><?php _e( 'Comment navigation', 'twentyfifteen' ); ?></h2> |
|
| 23 | + <h2 class="screen-reader-text"><?php _e('Comment navigation', 'twentyfifteen'); ?></h2> |
|
| 24 | 24 | <div class="nav-links"> |
| 25 | 25 | <?php |
| 26 | - if ( $prev_link = get_previous_comments_link( __( 'Older Comments', 'twentyfifteen' ) ) ) : |
|
| 27 | - printf( '<div class="nav-previous">%s</div>', $prev_link ); |
|
| 26 | + if ($prev_link = get_previous_comments_link(__('Older Comments', 'twentyfifteen'))) : |
|
| 27 | + printf('<div class="nav-previous">%s</div>', $prev_link); |
|
| 28 | 28 | endif; |
| 29 | 29 | |
| 30 | - if ( $next_link = get_next_comments_link( __( 'Newer Comments', 'twentyfifteen' ) ) ) : |
|
| 31 | - printf( '<div class="nav-next">%s</div>', $next_link ); |
|
| 30 | + if ($next_link = get_next_comments_link(__('Newer Comments', 'twentyfifteen'))) : |
|
| 31 | + printf('<div class="nav-next">%s</div>', $next_link); |
|
| 32 | 32 | endif; |
| 33 | 33 | ?> |
| 34 | 34 | </div><!-- .nav-links --> |
@@ -38,89 +38,89 @@ discard block |
||
| 38 | 38 | } |
| 39 | 39 | endif; |
| 40 | 40 | |
| 41 | -if ( ! function_exists( 'twentyfifteen_entry_meta' ) ) : |
|
| 41 | +if ( ! function_exists('twentyfifteen_entry_meta')) : |
|
| 42 | 42 | /** |
| 43 | 43 | * Prints HTML with meta information for the categories, tags. |
| 44 | 44 | * |
| 45 | 45 | * @since Twenty Fifteen 1.0 |
| 46 | 46 | */ |
| 47 | 47 | function twentyfifteen_entry_meta() { |
| 48 | - if ( is_sticky() && is_home() && ! is_paged() ) { |
|
| 49 | - printf( '<span class="sticky-post">%s</span>', __( 'Featured', 'twentyfifteen' ) ); |
|
| 48 | + if (is_sticky() && is_home() && ! is_paged()) { |
|
| 49 | + printf('<span class="sticky-post">%s</span>', __('Featured', 'twentyfifteen')); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | $format = get_post_format(); |
| 53 | - if ( current_theme_supports( 'post-formats', $format ) ) { |
|
| 54 | - printf( '<span class="entry-format">%1$s<a href="%2$s">%3$s</a></span>', |
|
| 55 | - sprintf( '<span class="screen-reader-text">%s </span>', _x( 'Format', 'Used before post format.', 'twentyfifteen' ) ), |
|
| 56 | - esc_url( get_post_format_link( $format ) ), |
|
| 57 | - get_post_format_string( $format ) |
|
| 53 | + if (current_theme_supports('post-formats', $format)) { |
|
| 54 | + printf('<span class="entry-format">%1$s<a href="%2$s">%3$s</a></span>', |
|
| 55 | + sprintf('<span class="screen-reader-text">%s </span>', _x('Format', 'Used before post format.', 'twentyfifteen')), |
|
| 56 | + esc_url(get_post_format_link($format)), |
|
| 57 | + get_post_format_string($format) |
|
| 58 | 58 | ); |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - if ( in_array( get_post_type(), array( 'post', 'attachment' ) ) ) { |
|
| 61 | + if (in_array(get_post_type(), array('post', 'attachment'))) { |
|
| 62 | 62 | $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>'; |
| 63 | 63 | |
| 64 | - if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) { |
|
| 64 | + if (get_the_time('U') !== get_the_modified_time('U')) { |
|
| 65 | 65 | $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>'; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - $time_string = sprintf( $time_string, |
|
| 69 | - esc_attr( get_the_date( 'c' ) ), |
|
| 68 | + $time_string = sprintf($time_string, |
|
| 69 | + esc_attr(get_the_date('c')), |
|
| 70 | 70 | get_the_date(), |
| 71 | - esc_attr( get_the_modified_date( 'c' ) ), |
|
| 71 | + esc_attr(get_the_modified_date('c')), |
|
| 72 | 72 | get_the_modified_date() |
| 73 | 73 | ); |
| 74 | 74 | |
| 75 | - printf( '<span class="posted-on"><span class="screen-reader-text">%1$s </span><a href="%2$s" rel="bookmark">%3$s</a></span>', |
|
| 76 | - _x( 'Posted on', 'Used before publish date.', 'twentyfifteen' ), |
|
| 77 | - esc_url( get_permalink() ), |
|
| 75 | + printf('<span class="posted-on"><span class="screen-reader-text">%1$s </span><a href="%2$s" rel="bookmark">%3$s</a></span>', |
|
| 76 | + _x('Posted on', 'Used before publish date.', 'twentyfifteen'), |
|
| 77 | + esc_url(get_permalink()), |
|
| 78 | 78 | $time_string |
| 79 | 79 | ); |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - if ( 'post' == get_post_type() ) { |
|
| 83 | - if ( is_singular() || is_multi_author() ) { |
|
| 84 | - printf( '<span class="byline"><span class="author vcard"><span class="screen-reader-text">%1$s </span><a class="url fn n" href="%2$s">%3$s</a></span></span>', |
|
| 85 | - _x( 'Author', 'Used before post author name.', 'twentyfifteen' ), |
|
| 86 | - esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), |
|
| 82 | + if ('post' == get_post_type()) { |
|
| 83 | + if (is_singular() || is_multi_author()) { |
|
| 84 | + printf('<span class="byline"><span class="author vcard"><span class="screen-reader-text">%1$s </span><a class="url fn n" href="%2$s">%3$s</a></span></span>', |
|
| 85 | + _x('Author', 'Used before post author name.', 'twentyfifteen'), |
|
| 86 | + esc_url(get_author_posts_url(get_the_author_meta('ID'))), |
|
| 87 | 87 | get_the_author() |
| 88 | 88 | ); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - $categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfifteen' ) ); |
|
| 92 | - if ( $categories_list && twentyfifteen_categorized_blog() ) { |
|
| 93 | - printf( '<span class="cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>', |
|
| 94 | - _x( 'Categories', 'Used before category names.', 'twentyfifteen' ), |
|
| 91 | + $categories_list = get_the_category_list(_x(', ', 'Used between list items, there is a space after the comma.', 'twentyfifteen')); |
|
| 92 | + if ($categories_list && twentyfifteen_categorized_blog()) { |
|
| 93 | + printf('<span class="cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>', |
|
| 94 | + _x('Categories', 'Used before category names.', 'twentyfifteen'), |
|
| 95 | 95 | $categories_list |
| 96 | 96 | ); |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - $tags_list = get_the_tag_list( '', _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfifteen' ) ); |
|
| 100 | - if ( $tags_list ) { |
|
| 101 | - printf( '<span class="tags-links"><span class="screen-reader-text">%1$s </span>%2$s</span>', |
|
| 102 | - _x( 'Tags', 'Used before tag names.', 'twentyfifteen' ), |
|
| 99 | + $tags_list = get_the_tag_list('', _x(', ', 'Used between list items, there is a space after the comma.', 'twentyfifteen')); |
|
| 100 | + if ($tags_list) { |
|
| 101 | + printf('<span class="tags-links"><span class="screen-reader-text">%1$s </span>%2$s</span>', |
|
| 102 | + _x('Tags', 'Used before tag names.', 'twentyfifteen'), |
|
| 103 | 103 | $tags_list |
| 104 | 104 | ); |
| 105 | 105 | } |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - if ( is_attachment() && wp_attachment_is_image() ) { |
|
| 108 | + if (is_attachment() && wp_attachment_is_image()) { |
|
| 109 | 109 | // Retrieve attachment metadata. |
| 110 | 110 | $metadata = wp_get_attachment_metadata(); |
| 111 | 111 | |
| 112 | - printf( '<span class="full-size-link"><span class="screen-reader-text">%1$s </span><a href="%2$s">%3$s × %4$s</a></span>', |
|
| 113 | - _x( 'Full size', 'Used before full size attachment link.', 'twentyfifteen' ), |
|
| 114 | - esc_url( wp_get_attachment_url() ), |
|
| 112 | + printf('<span class="full-size-link"><span class="screen-reader-text">%1$s </span><a href="%2$s">%3$s × %4$s</a></span>', |
|
| 113 | + _x('Full size', 'Used before full size attachment link.', 'twentyfifteen'), |
|
| 114 | + esc_url(wp_get_attachment_url()), |
|
| 115 | 115 | $metadata['width'], |
| 116 | 116 | $metadata['height'] |
| 117 | 117 | ); |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) { |
|
| 120 | + if ( ! is_single() && ! post_password_required() && (comments_open() || get_comments_number())) { |
|
| 121 | 121 | echo '<span class="comments-link">'; |
| 122 | 122 | /* translators: %s: post title */ |
| 123 | - comments_popup_link( sprintf( __( 'Leave a comment<span class="screen-reader-text"> on %s</span>', 'twentyfifteen' ), get_the_title() ) ); |
|
| 123 | + comments_popup_link(sprintf(__('Leave a comment<span class="screen-reader-text"> on %s</span>', 'twentyfifteen'), get_the_title())); |
|
| 124 | 124 | echo '</span>'; |
| 125 | 125 | } |
| 126 | 126 | } |
@@ -134,23 +134,23 @@ discard block |
||
| 134 | 134 | * @return bool True of there is more than one category, false otherwise. |
| 135 | 135 | */ |
| 136 | 136 | function twentyfifteen_categorized_blog() { |
| 137 | - if ( false === ( $all_the_cool_cats = get_transient( 'twentyfifteen_categories' ) ) ) { |
|
| 137 | + if (false === ($all_the_cool_cats = get_transient('twentyfifteen_categories'))) { |
|
| 138 | 138 | // Create an array of all the categories that are attached to posts. |
| 139 | - $all_the_cool_cats = get_categories( array( |
|
| 139 | + $all_the_cool_cats = get_categories(array( |
|
| 140 | 140 | 'fields' => 'ids', |
| 141 | 141 | 'hide_empty' => 1, |
| 142 | 142 | |
| 143 | 143 | // We only need to know if there is more than one category. |
| 144 | 144 | 'number' => 2, |
| 145 | - ) ); |
|
| 145 | + )); |
|
| 146 | 146 | |
| 147 | 147 | // Count the number of categories that are attached to the posts. |
| 148 | - $all_the_cool_cats = count( $all_the_cool_cats ); |
|
| 148 | + $all_the_cool_cats = count($all_the_cool_cats); |
|
| 149 | 149 | |
| 150 | - set_transient( 'twentyfifteen_categories', $all_the_cool_cats ); |
|
| 150 | + set_transient('twentyfifteen_categories', $all_the_cool_cats); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - if ( $all_the_cool_cats > 1 ) { |
|
| 153 | + if ($all_the_cool_cats > 1) { |
|
| 154 | 154 | // This blog has more than 1 category so twentyfifteen_categorized_blog should return true. |
| 155 | 155 | return true; |
| 156 | 156 | } else { |
@@ -166,12 +166,12 @@ discard block |
||
| 166 | 166 | */ |
| 167 | 167 | function twentyfifteen_category_transient_flusher() { |
| 168 | 168 | // Like, beat it. Dig? |
| 169 | - delete_transient( 'twentyfifteen_categories' ); |
|
| 169 | + delete_transient('twentyfifteen_categories'); |
|
| 170 | 170 | } |
| 171 | -add_action( 'edit_category', 'twentyfifteen_category_transient_flusher' ); |
|
| 172 | -add_action( 'save_post', 'twentyfifteen_category_transient_flusher' ); |
|
| 171 | +add_action('edit_category', 'twentyfifteen_category_transient_flusher'); |
|
| 172 | +add_action('save_post', 'twentyfifteen_category_transient_flusher'); |
|
| 173 | 173 | |
| 174 | -if ( ! function_exists( 'twentyfifteen_post_thumbnail' ) ) : |
|
| 174 | +if ( ! function_exists('twentyfifteen_post_thumbnail')) : |
|
| 175 | 175 | /** |
| 176 | 176 | * Display an optional post thumbnail. |
| 177 | 177 | * |
@@ -181,11 +181,11 @@ discard block |
||
| 181 | 181 | * @since Twenty Fifteen 1.0 |
| 182 | 182 | */ |
| 183 | 183 | function twentyfifteen_post_thumbnail() { |
| 184 | - if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) { |
|
| 184 | + if (post_password_required() || is_attachment() || ! has_post_thumbnail()) { |
|
| 185 | 185 | return; |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - if ( is_singular() ) : |
|
| 188 | + if (is_singular()) : |
|
| 189 | 189 | ?> |
| 190 | 190 | |
| 191 | 191 | <div class="post-thumbnail"> |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | |
| 197 | 197 | <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true"> |
| 198 | 198 | <?php |
| 199 | - the_post_thumbnail( 'post-thumbnail', array( 'alt' => get_the_title() ) ); |
|
| 199 | + the_post_thumbnail('post-thumbnail', array('alt' => get_the_title())); |
|
| 200 | 200 | ?> |
| 201 | 201 | </a> |
| 202 | 202 | |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | } |
| 205 | 205 | endif; |
| 206 | 206 | |
| 207 | -if ( ! function_exists( 'twentyfifteen_get_link_url' ) ) : |
|
| 207 | +if ( ! function_exists('twentyfifteen_get_link_url')) : |
|
| 208 | 208 | /** |
| 209 | 209 | * Return the post URL. |
| 210 | 210 | * |
@@ -217,13 +217,13 @@ discard block |
||
| 217 | 217 | * @return string The Link format URL. |
| 218 | 218 | */ |
| 219 | 219 | function twentyfifteen_get_link_url() { |
| 220 | - $has_url = get_url_in_content( get_the_content() ); |
|
| 220 | + $has_url = get_url_in_content(get_the_content()); |
|
| 221 | 221 | |
| 222 | - return $has_url ? $has_url : apply_filters( 'the_permalink', get_permalink() ); |
|
| 222 | + return $has_url ? $has_url : apply_filters('the_permalink', get_permalink()); |
|
| 223 | 223 | } |
| 224 | 224 | endif; |
| 225 | 225 | |
| 226 | -if ( ! function_exists( 'twentyfifteen_excerpt_more' ) && ! is_admin() ) : |
|
| 226 | +if ( ! function_exists('twentyfifteen_excerpt_more') && ! is_admin()) : |
|
| 227 | 227 | /** |
| 228 | 228 | * Replaces "[...]" (appended to automatically generated excerpts) with ... and a 'Continue reading' link. |
| 229 | 229 | * |
@@ -231,18 +231,18 @@ discard block |
||
| 231 | 231 | * |
| 232 | 232 | * @return string 'Continue reading' link prepended with an ellipsis. |
| 233 | 233 | */ |
| 234 | -function twentyfifteen_excerpt_more( $more ) { |
|
| 235 | - $link = sprintf( '<a href="%1$s" class="more-link">%2$s</a>', |
|
| 236 | - esc_url( get_permalink( get_the_ID() ) ), |
|
| 234 | +function twentyfifteen_excerpt_more($more) { |
|
| 235 | + $link = sprintf('<a href="%1$s" class="more-link">%2$s</a>', |
|
| 236 | + esc_url(get_permalink(get_the_ID())), |
|
| 237 | 237 | /* translators: %s: Name of current post */ |
| 238 | - sprintf( __( 'Continue reading %s', 'twentyfifteen' ), '<span class="screen-reader-text">' . get_the_title( get_the_ID() ) . '</span>' ) |
|
| 238 | + sprintf(__('Continue reading %s', 'twentyfifteen'), '<span class="screen-reader-text">'.get_the_title(get_the_ID()).'</span>') |
|
| 239 | 239 | ); |
| 240 | - return ' … ' . $link; |
|
| 240 | + return ' … '.$link; |
|
| 241 | 241 | } |
| 242 | -add_filter( 'excerpt_more', 'twentyfifteen_excerpt_more' ); |
|
| 242 | +add_filter('excerpt_more', 'twentyfifteen_excerpt_more'); |
|
| 243 | 243 | endif; |
| 244 | 244 | |
| 245 | -if ( ! function_exists( 'twentyfifteen_the_custom_logo' ) ) : |
|
| 245 | +if ( ! function_exists('twentyfifteen_the_custom_logo')) : |
|
| 246 | 246 | /** |
| 247 | 247 | * Displays the optional custom logo. |
| 248 | 248 | * |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | * @since Twenty Fifteen 1.5 |
| 252 | 252 | */ |
| 253 | 253 | function twentyfifteen_the_custom_logo() { |
| 254 | - if ( function_exists( 'the_custom_logo' ) ) { |
|
| 254 | + if (function_exists('the_custom_logo')) { |
|
| 255 | 255 | the_custom_logo(); |
| 256 | 256 | } |
| 257 | 257 | } |