@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * @global wpdb $wpdb |
| 63 | 63 | * |
| 64 | 64 | * @param int $user_id The unique ID of the user |
| 65 | - * @return object|void The blog object |
|
| 65 | + * @return string The blog object |
|
| 66 | 66 | */ |
| 67 | 67 | function get_active_blog_for_user( $user_id ) { |
| 68 | 68 | global $wpdb; |
@@ -806,7 +806,7 @@ discard block |
||
| 806 | 806 | * @param string $user The user's login name. |
| 807 | 807 | * @param string $user_email The user's email address. |
| 808 | 808 | * @param string $key The activation key created in wpmu_signup_blog() |
| 809 | - * @param array $meta By default, contains the requested privacy setting and lang_id. |
|
| 809 | + * @param string $meta By default, contains the requested privacy setting and lang_id. |
|
| 810 | 810 | * @return bool |
| 811 | 811 | */ |
| 812 | 812 | function wpmu_signup_blog_notification( $domain, $path, $title, $user, $user_email, $key, $meta = array() ) { |
@@ -909,7 +909,7 @@ discard block |
||
| 909 | 909 | * @param string $user The user's login name. |
| 910 | 910 | * @param string $user_email The user's email address. |
| 911 | 911 | * @param string $key The activation key created in wpmu_signup_user() |
| 912 | - * @param array $meta By default, an empty array. |
|
| 912 | + * @param string $meta By default, an empty array. |
|
| 913 | 913 | * @return bool |
| 914 | 914 | */ |
| 915 | 915 | function wpmu_signup_user_notification( $user, $user_email, $key, $meta = array() ) { |
@@ -2161,7 +2161,7 @@ discard block |
||
| 2161 | 2161 | * |
| 2162 | 2162 | * @staticvar bool $forced_content |
| 2163 | 2163 | * |
| 2164 | - * @param bool $force |
|
| 2164 | + * @param string|boolean $force |
|
| 2165 | 2165 | * @return bool True if forced, false if not forced. |
| 2166 | 2166 | */ |
| 2167 | 2167 | function force_ssl_content( $force = '' ) { |
@@ -1,11 +1,11 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Multisite WordPress API |
|
| 4 | - * |
|
| 5 | - * @package WordPress |
|
| 6 | - * @subpackage Multisite |
|
| 7 | - * @since 3.0.0 |
|
| 8 | - */ |
|
| 3 | + * Multisite WordPress API |
|
| 4 | + * |
|
| 5 | + * @package WordPress |
|
| 6 | + * @subpackage Multisite |
|
| 7 | + * @since 3.0.0 |
|
| 8 | + */ |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * Gets the network's site and user counts. |
@@ -1552,7 +1552,7 @@ discard block |
||
| 1552 | 1552 | $current_site = get_current_site(); |
| 1553 | 1553 | |
| 1554 | 1554 | /** |
| 1555 | - * Filter whether to bypass the welcome email after user activation. |
|
| 1555 | + * Filter whether to bypass the welcome email after user activation. |
|
| 1556 | 1556 | * |
| 1557 | 1557 | * Returning false disables the welcome email. |
| 1558 | 1558 | * |
@@ -2063,7 +2063,7 @@ discard block |
||
| 2063 | 2063 | * @return bool |
| 2064 | 2064 | */ |
| 2065 | 2065 | function is_user_spammy( $user = null ) { |
| 2066 | - if ( ! ( $user instanceof WP_User ) ) { |
|
| 2066 | + if ( ! ( $user instanceof WP_User ) ) { |
|
| 2067 | 2067 | if ( $user ) { |
| 2068 | 2068 | $user = get_user_by( 'login', $user ); |
| 2069 | 2069 | } else { |
@@ -34,16 +34,16 @@ discard block |
||
| 34 | 34 | * @param string $path Optional. Site path. |
| 35 | 35 | * @return array|false The network admins |
| 36 | 36 | */ |
| 37 | -function get_admin_users_for_domain( $sitedomain = '', $path = '' ) { |
|
| 37 | +function get_admin_users_for_domain($sitedomain = '', $path = '') { |
|
| 38 | 38 | global $wpdb; |
| 39 | 39 | |
| 40 | - if ( ! $sitedomain ) |
|
| 40 | + if ( ! $sitedomain) |
|
| 41 | 41 | $site_id = $wpdb->siteid; |
| 42 | 42 | else |
| 43 | - $site_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path ) ); |
|
| 43 | + $site_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path)); |
|
| 44 | 44 | |
| 45 | - if ( $site_id ) |
|
| 46 | - return $wpdb->get_results( $wpdb->prepare( "SELECT u.ID, u.user_login, u.user_pass FROM $wpdb->users AS u, $wpdb->sitemeta AS sm WHERE sm.meta_key = 'admin_user_id' AND u.ID = sm.meta_value AND sm.site_id = %d", $site_id ), ARRAY_A ); |
|
| 45 | + if ($site_id) |
|
| 46 | + return $wpdb->get_results($wpdb->prepare("SELECT u.ID, u.user_login, u.user_pass FROM $wpdb->users AS u, $wpdb->sitemeta AS sm WHERE sm.meta_key = 'admin_user_id' AND u.ID = sm.meta_value AND sm.site_id = %d", $site_id), ARRAY_A); |
|
| 47 | 47 | |
| 48 | 48 | return false; |
| 49 | 49 | } |
@@ -64,45 +64,45 @@ discard block |
||
| 64 | 64 | * @param int $user_id The unique ID of the user |
| 65 | 65 | * @return object|void The blog object |
| 66 | 66 | */ |
| 67 | -function get_active_blog_for_user( $user_id ) { |
|
| 67 | +function get_active_blog_for_user($user_id) { |
|
| 68 | 68 | global $wpdb; |
| 69 | - $blogs = get_blogs_of_user( $user_id ); |
|
| 70 | - if ( empty( $blogs ) ) |
|
| 69 | + $blogs = get_blogs_of_user($user_id); |
|
| 70 | + if (empty($blogs)) |
|
| 71 | 71 | return; |
| 72 | 72 | |
| 73 | - if ( !is_multisite() ) |
|
| 73 | + if ( ! is_multisite()) |
|
| 74 | 74 | return $blogs[$wpdb->blogid]; |
| 75 | 75 | |
| 76 | - $primary_blog = get_user_meta( $user_id, 'primary_blog', true ); |
|
| 76 | + $primary_blog = get_user_meta($user_id, 'primary_blog', true); |
|
| 77 | 77 | $first_blog = current($blogs); |
| 78 | - if ( false !== $primary_blog ) { |
|
| 79 | - if ( ! isset( $blogs[ $primary_blog ] ) ) { |
|
| 80 | - update_user_meta( $user_id, 'primary_blog', $first_blog->userblog_id ); |
|
| 81 | - $primary = get_blog_details( $first_blog->userblog_id ); |
|
| 78 | + if (false !== $primary_blog) { |
|
| 79 | + if ( ! isset($blogs[$primary_blog])) { |
|
| 80 | + update_user_meta($user_id, 'primary_blog', $first_blog->userblog_id); |
|
| 81 | + $primary = get_blog_details($first_blog->userblog_id); |
|
| 82 | 82 | } else { |
| 83 | - $primary = get_blog_details( $primary_blog ); |
|
| 83 | + $primary = get_blog_details($primary_blog); |
|
| 84 | 84 | } |
| 85 | 85 | } else { |
| 86 | 86 | //TODO Review this call to add_user_to_blog too - to get here the user must have a role on this blog? |
| 87 | - add_user_to_blog( $first_blog->userblog_id, $user_id, 'subscriber' ); |
|
| 88 | - update_user_meta( $user_id, 'primary_blog', $first_blog->userblog_id ); |
|
| 87 | + add_user_to_blog($first_blog->userblog_id, $user_id, 'subscriber'); |
|
| 88 | + update_user_meta($user_id, 'primary_blog', $first_blog->userblog_id); |
|
| 89 | 89 | $primary = $first_blog; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - if ( ( ! is_object( $primary ) ) || ( $primary->archived == 1 || $primary->spam == 1 || $primary->deleted == 1 ) ) { |
|
| 93 | - $blogs = get_blogs_of_user( $user_id, true ); // if a user's primary blog is shut down, check their other blogs. |
|
| 92 | + if (( ! is_object($primary)) || ($primary->archived == 1 || $primary->spam == 1 || $primary->deleted == 1)) { |
|
| 93 | + $blogs = get_blogs_of_user($user_id, true); // if a user's primary blog is shut down, check their other blogs. |
|
| 94 | 94 | $ret = false; |
| 95 | - if ( is_array( $blogs ) && count( $blogs ) > 0 ) { |
|
| 96 | - foreach ( (array) $blogs as $blog_id => $blog ) { |
|
| 97 | - if ( $blog->site_id != $wpdb->siteid ) |
|
| 95 | + if (is_array($blogs) && count($blogs) > 0) { |
|
| 96 | + foreach ((array) $blogs as $blog_id => $blog) { |
|
| 97 | + if ($blog->site_id != $wpdb->siteid) |
|
| 98 | 98 | continue; |
| 99 | - $details = get_blog_details( $blog_id ); |
|
| 100 | - if ( is_object( $details ) && $details->archived == 0 && $details->spam == 0 && $details->deleted == 0 ) { |
|
| 99 | + $details = get_blog_details($blog_id); |
|
| 100 | + if (is_object($details) && $details->archived == 0 && $details->spam == 0 && $details->deleted == 0) { |
|
| 101 | 101 | $ret = $blog; |
| 102 | - if ( get_user_meta( $user_id , 'primary_blog', true ) != $blog_id ) |
|
| 103 | - update_user_meta( $user_id, 'primary_blog', $blog_id ); |
|
| 104 | - if ( !get_user_meta($user_id , 'source_domain', true) ) |
|
| 105 | - update_user_meta( $user_id, 'source_domain', $blog->domain ); |
|
| 102 | + if (get_user_meta($user_id, 'primary_blog', true) != $blog_id) |
|
| 103 | + update_user_meta($user_id, 'primary_blog', $blog_id); |
|
| 104 | + if ( ! get_user_meta($user_id, 'source_domain', true)) |
|
| 105 | + update_user_meta($user_id, 'source_domain', $blog->domain); |
|
| 106 | 106 | break; |
| 107 | 107 | } |
| 108 | 108 | } |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | * @return int |
| 126 | 126 | */ |
| 127 | 127 | function get_user_count() { |
| 128 | - return get_site_option( 'user_count' ); |
|
| 128 | + return get_site_option('user_count'); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -138,11 +138,11 @@ discard block |
||
| 138 | 138 | * @param int $network_id Deprecated, not supported. |
| 139 | 139 | * @return int |
| 140 | 140 | */ |
| 141 | -function get_blog_count( $network_id = 0 ) { |
|
| 142 | - if ( func_num_args() ) |
|
| 143 | - _deprecated_argument( __FUNCTION__, '3.1' ); |
|
| 141 | +function get_blog_count($network_id = 0) { |
|
| 142 | + if (func_num_args()) |
|
| 143 | + _deprecated_argument(__FUNCTION__, '3.1'); |
|
| 144 | 144 | |
| 145 | - return get_site_option( 'blog_count' ); |
|
| 145 | + return get_site_option('blog_count'); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | /** |
@@ -154,9 +154,9 @@ discard block |
||
| 154 | 154 | * @param int $post_id ID of the post you're looking for. |
| 155 | 155 | * @return WP_Post|null WP_Post on success or null on failure |
| 156 | 156 | */ |
| 157 | -function get_blog_post( $blog_id, $post_id ) { |
|
| 158 | - switch_to_blog( $blog_id ); |
|
| 159 | - $post = get_post( $post_id ); |
|
| 157 | +function get_blog_post($blog_id, $post_id) { |
|
| 158 | + switch_to_blog($blog_id); |
|
| 159 | + $post = get_post($post_id); |
|
| 160 | 160 | restore_current_blog(); |
| 161 | 161 | |
| 162 | 162 | return $post; |
@@ -175,17 +175,17 @@ discard block |
||
| 175 | 175 | * @param string $role The role you want the user to have |
| 176 | 176 | * @return true|WP_Error |
| 177 | 177 | */ |
| 178 | -function add_user_to_blog( $blog_id, $user_id, $role ) { |
|
| 178 | +function add_user_to_blog($blog_id, $user_id, $role) { |
|
| 179 | 179 | switch_to_blog($blog_id); |
| 180 | 180 | |
| 181 | - $user = get_userdata( $user_id ); |
|
| 181 | + $user = get_userdata($user_id); |
|
| 182 | 182 | |
| 183 | - if ( ! $user ) { |
|
| 183 | + if ( ! $user) { |
|
| 184 | 184 | restore_current_blog(); |
| 185 | - return new WP_Error( 'user_does_not_exist', __( 'The requested user does not exist.' ) ); |
|
| 185 | + return new WP_Error('user_does_not_exist', __('The requested user does not exist.')); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - if ( !get_user_meta($user_id, 'primary_blog', true) ) { |
|
| 188 | + if ( ! get_user_meta($user_id, 'primary_blog', true)) { |
|
| 189 | 189 | update_user_meta($user_id, 'primary_blog', $blog_id); |
| 190 | 190 | $details = get_blog_details($blog_id); |
| 191 | 191 | update_user_meta($user_id, 'source_domain', $details->domain); |
@@ -202,9 +202,9 @@ discard block |
||
| 202 | 202 | * @param string $role User role. |
| 203 | 203 | * @param int $blog_id Blog ID. |
| 204 | 204 | */ |
| 205 | - do_action( 'add_user_to_blog', $user_id, $role, $blog_id ); |
|
| 206 | - wp_cache_delete( $user_id, 'users' ); |
|
| 207 | - wp_cache_delete( $blog_id . '_user_count', 'blog-details' ); |
|
| 205 | + do_action('add_user_to_blog', $user_id, $role, $blog_id); |
|
| 206 | + wp_cache_delete($user_id, 'users'); |
|
| 207 | + wp_cache_delete($blog_id.'_user_count', 'blog-details'); |
|
| 208 | 208 | restore_current_blog(); |
| 209 | 209 | return true; |
| 210 | 210 | } |
@@ -239,17 +239,17 @@ discard block |
||
| 239 | 239 | * @param int $user_id User ID. |
| 240 | 240 | * @param int $blog_id Blog ID. |
| 241 | 241 | */ |
| 242 | - do_action( 'remove_user_from_blog', $user_id, $blog_id ); |
|
| 242 | + do_action('remove_user_from_blog', $user_id, $blog_id); |
|
| 243 | 243 | |
| 244 | 244 | // If being removed from the primary blog, set a new primary if the user is assigned |
| 245 | 245 | // to multiple blogs. |
| 246 | 246 | $primary_blog = get_user_meta($user_id, 'primary_blog', true); |
| 247 | - if ( $primary_blog == $blog_id ) { |
|
| 247 | + if ($primary_blog == $blog_id) { |
|
| 248 | 248 | $new_id = ''; |
| 249 | 249 | $new_domain = ''; |
| 250 | 250 | $blogs = get_blogs_of_user($user_id); |
| 251 | - foreach ( (array) $blogs as $blog ) { |
|
| 252 | - if ( $blog->userblog_id == $blog_id ) |
|
| 251 | + foreach ((array) $blogs as $blog) { |
|
| 252 | + if ($blog->userblog_id == $blog_id) |
|
| 253 | 253 | continue; |
| 254 | 254 | $new_id = $blog->userblog_id; |
| 255 | 255 | $new_domain = $blog->domain; |
@@ -261,8 +261,8 @@ discard block |
||
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | // wp_revoke_user($user_id); |
| 264 | - $user = get_userdata( $user_id ); |
|
| 265 | - if ( ! $user ) { |
|
| 264 | + $user = get_userdata($user_id); |
|
| 265 | + if ( ! $user) { |
|
| 266 | 266 | restore_current_blog(); |
| 267 | 267 | return new WP_Error('user_does_not_exist', __('That user does not exist.')); |
| 268 | 268 | } |
@@ -270,24 +270,24 @@ discard block |
||
| 270 | 270 | $user->remove_all_caps(); |
| 271 | 271 | |
| 272 | 272 | $blogs = get_blogs_of_user($user_id); |
| 273 | - if ( count($blogs) == 0 ) { |
|
| 273 | + if (count($blogs) == 0) { |
|
| 274 | 274 | update_user_meta($user_id, 'primary_blog', ''); |
| 275 | 275 | update_user_meta($user_id, 'source_domain', ''); |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | - if ( $reassign != '' ) { |
|
| 278 | + if ($reassign != '') { |
|
| 279 | 279 | $reassign = (int) $reassign; |
| 280 | - $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $user_id ) ); |
|
| 281 | - $link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $user_id ) ); |
|
| 280 | + $post_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_author = %d", $user_id)); |
|
| 281 | + $link_ids = $wpdb->get_col($wpdb->prepare("SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $user_id)); |
|
| 282 | 282 | |
| 283 | - if ( ! empty( $post_ids ) ) { |
|
| 284 | - $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_author = %d WHERE post_author = %d", $reassign, $user_id ) ); |
|
| 285 | - array_walk( $post_ids, 'clean_post_cache' ); |
|
| 283 | + if ( ! empty($post_ids)) { |
|
| 284 | + $wpdb->query($wpdb->prepare("UPDATE $wpdb->posts SET post_author = %d WHERE post_author = %d", $reassign, $user_id)); |
|
| 285 | + array_walk($post_ids, 'clean_post_cache'); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | - if ( ! empty( $link_ids ) ) { |
|
| 289 | - $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->links SET link_owner = %d WHERE link_owner = %d", $reassign, $user_id ) ); |
|
| 290 | - array_walk( $link_ids, 'clean_bookmark_cache' ); |
|
| 288 | + if ( ! empty($link_ids)) { |
|
| 289 | + $wpdb->query($wpdb->prepare("UPDATE $wpdb->links SET link_owner = %d WHERE link_owner = %d", $reassign, $user_id)); |
|
| 290 | + array_walk($link_ids, 'clean_bookmark_cache'); |
|
| 291 | 291 | } |
| 292 | 292 | } |
| 293 | 293 | |
@@ -307,20 +307,20 @@ discard block |
||
| 307 | 307 | * @param int $site_id Optional. Defaults to 1. |
| 308 | 308 | * @return string|int The ID of the newly created blog |
| 309 | 309 | */ |
| 310 | -function create_empty_blog( $domain, $path, $weblog_title, $site_id = 1 ) { |
|
| 311 | - if ( empty($path) ) |
|
| 310 | +function create_empty_blog($domain, $path, $weblog_title, $site_id = 1) { |
|
| 311 | + if (empty($path)) |
|
| 312 | 312 | $path = '/'; |
| 313 | 313 | |
| 314 | 314 | // Check if the domain has been used already. We should return an error message. |
| 315 | - if ( domain_exists($domain, $path, $site_id) ) |
|
| 316 | - return __( '<strong>ERROR</strong>: Site URL already taken.' ); |
|
| 315 | + if (domain_exists($domain, $path, $site_id)) |
|
| 316 | + return __('<strong>ERROR</strong>: Site URL already taken.'); |
|
| 317 | 317 | |
| 318 | 318 | // Need to back up wpdb table names, and create a new wp_blogs entry for new blog. |
| 319 | 319 | // Need to get blog_id from wp_blogs, and create new table names. |
| 320 | 320 | // Must restore table names at the end of function. |
| 321 | 321 | |
| 322 | - if ( ! $blog_id = insert_blog($domain, $path, $site_id) ) |
|
| 323 | - return __( '<strong>ERROR</strong>: problem creating site entry.' ); |
|
| 322 | + if ( ! $blog_id = insert_blog($domain, $path, $site_id)) |
|
| 323 | + return __('<strong>ERROR</strong>: problem creating site entry.'); |
|
| 324 | 324 | |
| 325 | 325 | switch_to_blog($blog_id); |
| 326 | 326 | install_blog($blog_id); |
@@ -338,9 +338,9 @@ discard block |
||
| 338 | 338 | * @param int $post_id ID of the desired post. |
| 339 | 339 | * @return string The post's permalink |
| 340 | 340 | */ |
| 341 | -function get_blog_permalink( $blog_id, $post_id ) { |
|
| 342 | - switch_to_blog( $blog_id ); |
|
| 343 | - $link = get_permalink( $post_id ); |
|
| 341 | +function get_blog_permalink($blog_id, $post_id) { |
|
| 342 | + switch_to_blog($blog_id); |
|
| 343 | + $link = get_permalink($post_id); |
|
| 344 | 344 | restore_current_blog(); |
| 345 | 345 | |
| 346 | 346 | return $link; |
@@ -362,26 +362,26 @@ discard block |
||
| 362 | 362 | * @param string $path Optional. Not required for subdomain installations. |
| 363 | 363 | * @return int 0 if no blog found, otherwise the ID of the matching blog |
| 364 | 364 | */ |
| 365 | -function get_blog_id_from_url( $domain, $path = '/' ) { |
|
| 365 | +function get_blog_id_from_url($domain, $path = '/') { |
|
| 366 | 366 | global $wpdb; |
| 367 | 367 | |
| 368 | - $domain = strtolower( $domain ); |
|
| 369 | - $path = strtolower( $path ); |
|
| 370 | - $id = wp_cache_get( md5( $domain . $path ), 'blog-id-cache' ); |
|
| 368 | + $domain = strtolower($domain); |
|
| 369 | + $path = strtolower($path); |
|
| 370 | + $id = wp_cache_get(md5($domain.$path), 'blog-id-cache'); |
|
| 371 | 371 | |
| 372 | - if ( $id == -1 ) // blog does not exist |
|
| 372 | + if ($id == -1) // blog does not exist |
|
| 373 | 373 | return 0; |
| 374 | - elseif ( $id ) |
|
| 374 | + elseif ($id) |
|
| 375 | 375 | return (int) $id; |
| 376 | 376 | |
| 377 | - $id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s and path = %s /* get_blog_id_from_url */", $domain, $path ) ); |
|
| 377 | + $id = $wpdb->get_var($wpdb->prepare("SELECT blog_id FROM $wpdb->blogs WHERE domain = %s and path = %s /* get_blog_id_from_url */", $domain, $path)); |
|
| 378 | 378 | |
| 379 | - if ( ! $id ) { |
|
| 380 | - wp_cache_set( md5( $domain . $path ), -1, 'blog-id-cache' ); |
|
| 379 | + if ( ! $id) { |
|
| 380 | + wp_cache_set(md5($domain.$path), -1, 'blog-id-cache'); |
|
| 381 | 381 | return 0; |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | - wp_cache_set( md5( $domain . $path ), $id, 'blog-id-cache' ); |
|
| 384 | + wp_cache_set(md5($domain.$path), $id, 'blog-id-cache'); |
|
| 385 | 385 | |
| 386 | 386 | return $id; |
| 387 | 387 | } |
@@ -401,30 +401,30 @@ discard block |
||
| 401 | 401 | * @param string $user_email The email provided by the user at registration. |
| 402 | 402 | * @return bool Returns true when the email address is banned. |
| 403 | 403 | */ |
| 404 | -function is_email_address_unsafe( $user_email ) { |
|
| 405 | - $banned_names = get_site_option( 'banned_email_domains' ); |
|
| 406 | - if ( $banned_names && ! is_array( $banned_names ) ) |
|
| 407 | - $banned_names = explode( "\n", $banned_names ); |
|
| 404 | +function is_email_address_unsafe($user_email) { |
|
| 405 | + $banned_names = get_site_option('banned_email_domains'); |
|
| 406 | + if ($banned_names && ! is_array($banned_names)) |
|
| 407 | + $banned_names = explode("\n", $banned_names); |
|
| 408 | 408 | |
| 409 | 409 | $is_email_address_unsafe = false; |
| 410 | 410 | |
| 411 | - if ( $banned_names && is_array( $banned_names ) ) { |
|
| 412 | - $banned_names = array_map( 'strtolower', $banned_names ); |
|
| 413 | - $normalized_email = strtolower( $user_email ); |
|
| 411 | + if ($banned_names && is_array($banned_names)) { |
|
| 412 | + $banned_names = array_map('strtolower', $banned_names); |
|
| 413 | + $normalized_email = strtolower($user_email); |
|
| 414 | 414 | |
| 415 | - list( $email_local_part, $email_domain ) = explode( '@', $normalized_email ); |
|
| 415 | + list($email_local_part, $email_domain) = explode('@', $normalized_email); |
|
| 416 | 416 | |
| 417 | - foreach ( $banned_names as $banned_domain ) { |
|
| 418 | - if ( ! $banned_domain ) |
|
| 417 | + foreach ($banned_names as $banned_domain) { |
|
| 418 | + if ( ! $banned_domain) |
|
| 419 | 419 | continue; |
| 420 | 420 | |
| 421 | - if ( $email_domain == $banned_domain ) { |
|
| 421 | + if ($email_domain == $banned_domain) { |
|
| 422 | 422 | $is_email_address_unsafe = true; |
| 423 | 423 | break; |
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | $dotted_domain = ".$banned_domain"; |
| 427 | - if ( $dotted_domain === substr( $normalized_email, -strlen( $dotted_domain ) ) ) { |
|
| 427 | + if ($dotted_domain === substr($normalized_email, -strlen($dotted_domain))) { |
|
| 428 | 428 | $is_email_address_unsafe = true; |
| 429 | 429 | break; |
| 430 | 430 | } |
@@ -439,7 +439,7 @@ discard block |
||
| 439 | 439 | * @param bool $is_email_address_unsafe Whether the email address is "unsafe". Default false. |
| 440 | 440 | * @param string $user_email User email address. |
| 441 | 441 | */ |
| 442 | - return apply_filters( 'is_email_address_unsafe', $is_email_address_unsafe, $user_email ); |
|
| 442 | + return apply_filters('is_email_address_unsafe', $is_email_address_unsafe, $user_email); |
|
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | /** |
@@ -468,81 +468,81 @@ discard block |
||
| 468 | 468 | $errors = new WP_Error(); |
| 469 | 469 | |
| 470 | 470 | $orig_username = $user_name; |
| 471 | - $user_name = preg_replace( '/\s+/', '', sanitize_user( $user_name, true ) ); |
|
| 471 | + $user_name = preg_replace('/\s+/', '', sanitize_user($user_name, true)); |
|
| 472 | 472 | |
| 473 | - if ( $user_name != $orig_username || preg_match( '/[^a-z0-9]/', $user_name ) ) { |
|
| 474 | - $errors->add( 'user_name', __( 'Only lowercase letters (a-z) and numbers are allowed.' ) ); |
|
| 473 | + if ($user_name != $orig_username || preg_match('/[^a-z0-9]/', $user_name)) { |
|
| 474 | + $errors->add('user_name', __('Only lowercase letters (a-z) and numbers are allowed.')); |
|
| 475 | 475 | $user_name = $orig_username; |
| 476 | 476 | } |
| 477 | 477 | |
| 478 | - $user_email = sanitize_email( $user_email ); |
|
| 478 | + $user_email = sanitize_email($user_email); |
|
| 479 | 479 | |
| 480 | - if ( empty( $user_name ) ) |
|
| 481 | - $errors->add('user_name', __( 'Please enter a username.' ) ); |
|
| 480 | + if (empty($user_name)) |
|
| 481 | + $errors->add('user_name', __('Please enter a username.')); |
|
| 482 | 482 | |
| 483 | - $illegal_names = get_site_option( 'illegal_names' ); |
|
| 484 | - if ( ! is_array( $illegal_names ) ) { |
|
| 485 | - $illegal_names = array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator' ); |
|
| 486 | - add_site_option( 'illegal_names', $illegal_names ); |
|
| 483 | + $illegal_names = get_site_option('illegal_names'); |
|
| 484 | + if ( ! is_array($illegal_names)) { |
|
| 485 | + $illegal_names = array('www', 'web', 'root', 'admin', 'main', 'invite', 'administrator'); |
|
| 486 | + add_site_option('illegal_names', $illegal_names); |
|
| 487 | 487 | } |
| 488 | - if ( in_array( $user_name, $illegal_names ) ) |
|
| 489 | - $errors->add('user_name', __( 'That username is not allowed.' ) ); |
|
| 488 | + if (in_array($user_name, $illegal_names)) |
|
| 489 | + $errors->add('user_name', __('That username is not allowed.')); |
|
| 490 | 490 | |
| 491 | - if ( is_email_address_unsafe( $user_email ) ) |
|
| 492 | - $errors->add('user_email', __('You cannot use that email address to signup. We are having problems with them blocking some of our email. Please use another email provider.')); |
|
| 491 | + if (is_email_address_unsafe($user_email)) |
|
| 492 | + $errors->add('user_email', __('You cannot use that email address to signup. We are having problems with them blocking some of our email. Please use another email provider.')); |
|
| 493 | 493 | |
| 494 | - if ( strlen( $user_name ) < 4 ) |
|
| 495 | - $errors->add('user_name', __( 'Username must be at least 4 characters.' ) ); |
|
| 494 | + if (strlen($user_name) < 4) |
|
| 495 | + $errors->add('user_name', __('Username must be at least 4 characters.')); |
|
| 496 | 496 | |
| 497 | - if ( strlen( $user_name ) > 60 ) { |
|
| 498 | - $errors->add( 'user_name', __( 'Username may not be longer than 60 characters.' ) ); |
|
| 497 | + if (strlen($user_name) > 60) { |
|
| 498 | + $errors->add('user_name', __('Username may not be longer than 60 characters.')); |
|
| 499 | 499 | } |
| 500 | 500 | |
| 501 | - if ( strpos( $user_name, '_' ) !== false ) |
|
| 502 | - $errors->add( 'user_name', __( 'Sorry, usernames may not contain the character “_”!' ) ); |
|
| 501 | + if (strpos($user_name, '_') !== false) |
|
| 502 | + $errors->add('user_name', __('Sorry, usernames may not contain the character “_”!')); |
|
| 503 | 503 | |
| 504 | 504 | // all numeric? |
| 505 | - if ( preg_match( '/^[0-9]*$/', $user_name ) ) |
|
| 505 | + if (preg_match('/^[0-9]*$/', $user_name)) |
|
| 506 | 506 | $errors->add('user_name', __('Sorry, usernames must have letters too!')); |
| 507 | 507 | |
| 508 | - if ( !is_email( $user_email ) ) |
|
| 509 | - $errors->add('user_email', __( 'Please enter a valid email address.' ) ); |
|
| 508 | + if ( ! is_email($user_email)) |
|
| 509 | + $errors->add('user_email', __('Please enter a valid email address.')); |
|
| 510 | 510 | |
| 511 | - $limited_email_domains = get_site_option( 'limited_email_domains' ); |
|
| 512 | - if ( is_array( $limited_email_domains ) && ! empty( $limited_email_domains ) ) { |
|
| 513 | - $emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) ); |
|
| 514 | - if ( ! in_array( $emaildomain, $limited_email_domains ) ) { |
|
| 511 | + $limited_email_domains = get_site_option('limited_email_domains'); |
|
| 512 | + if (is_array($limited_email_domains) && ! empty($limited_email_domains)) { |
|
| 513 | + $emaildomain = substr($user_email, 1 + strpos($user_email, '@')); |
|
| 514 | + if ( ! in_array($emaildomain, $limited_email_domains)) { |
|
| 515 | 515 | $errors->add('user_email', __('Sorry, that email address is not allowed!')); |
| 516 | 516 | } |
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | // Check if the username has been used already. |
| 520 | - if ( username_exists($user_name) ) |
|
| 521 | - $errors->add( 'user_name', __( 'Sorry, that username already exists!' ) ); |
|
| 520 | + if (username_exists($user_name)) |
|
| 521 | + $errors->add('user_name', __('Sorry, that username already exists!')); |
|
| 522 | 522 | |
| 523 | 523 | // Check if the email address has been used already. |
| 524 | - if ( email_exists($user_email) ) |
|
| 525 | - $errors->add( 'user_email', __( 'Sorry, that email address is already used!' ) ); |
|
| 524 | + if (email_exists($user_email)) |
|
| 525 | + $errors->add('user_email', __('Sorry, that email address is already used!')); |
|
| 526 | 526 | |
| 527 | 527 | // Has someone already signed up for this username? |
| 528 | - $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE user_login = %s", $user_name) ); |
|
| 529 | - if ( $signup != null ) { |
|
| 530 | - $registered_at = mysql2date('U', $signup->registered); |
|
| 531 | - $now = current_time( 'timestamp', true ); |
|
| 528 | + $signup = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->signups WHERE user_login = %s", $user_name)); |
|
| 529 | + if ($signup != null) { |
|
| 530 | + $registered_at = mysql2date('U', $signup->registered); |
|
| 531 | + $now = current_time('timestamp', true); |
|
| 532 | 532 | $diff = $now - $registered_at; |
| 533 | 533 | // If registered more than two days ago, cancel registration and let this signup go through. |
| 534 | - if ( $diff > 2 * DAY_IN_SECONDS ) |
|
| 535 | - $wpdb->delete( $wpdb->signups, array( 'user_login' => $user_name ) ); |
|
| 534 | + if ($diff > 2 * DAY_IN_SECONDS) |
|
| 535 | + $wpdb->delete($wpdb->signups, array('user_login' => $user_name)); |
|
| 536 | 536 | else |
| 537 | 537 | $errors->add('user_name', __('That username is currently reserved but may be available in a couple of days.')); |
| 538 | 538 | } |
| 539 | 539 | |
| 540 | - $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE user_email = %s", $user_email) ); |
|
| 541 | - if ( $signup != null ) { |
|
| 542 | - $diff = current_time( 'timestamp', true ) - mysql2date('U', $signup->registered); |
|
| 540 | + $signup = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->signups WHERE user_email = %s", $user_email)); |
|
| 541 | + if ($signup != null) { |
|
| 542 | + $diff = current_time('timestamp', true) - mysql2date('U', $signup->registered); |
|
| 543 | 543 | // If registered more than two days ago, cancel registration and let this signup go through. |
| 544 | - if ( $diff > 2 * DAY_IN_SECONDS ) |
|
| 545 | - $wpdb->delete( $wpdb->signups, array( 'user_email' => $user_email ) ); |
|
| 544 | + if ($diff > 2 * DAY_IN_SECONDS) |
|
| 545 | + $wpdb->delete($wpdb->signups, array('user_email' => $user_email)); |
|
| 546 | 546 | else |
| 547 | 547 | $errors->add('user_email', __('That email address has already been used. Please check your inbox for an activation email. It will become available in a couple of days if you do nothing.')); |
| 548 | 548 | } |
@@ -566,7 +566,7 @@ discard block |
||
| 566 | 566 | * @type WP_Error $errors WP_Error object containing any errors found. |
| 567 | 567 | * } |
| 568 | 568 | */ |
| 569 | - return apply_filters( 'wpmu_validate_user_signup', $result ); |
|
| 569 | + return apply_filters('wpmu_validate_user_signup', $result); |
|
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | /** |
@@ -592,27 +592,27 @@ discard block |
||
| 592 | 592 | * @param string $blog_title The blog title provided by the user. |
| 593 | 593 | * @return array Contains the new site data and error messages. |
| 594 | 594 | */ |
| 595 | -function wpmu_validate_blog_signup( $blogname, $blog_title, $user = '' ) { |
|
| 595 | +function wpmu_validate_blog_signup($blogname, $blog_title, $user = '') { |
|
| 596 | 596 | global $wpdb, $domain; |
| 597 | 597 | |
| 598 | 598 | $current_site = get_current_site(); |
| 599 | 599 | $base = $current_site->path; |
| 600 | 600 | |
| 601 | - $blog_title = strip_tags( $blog_title ); |
|
| 602 | - $blog_title = substr( $blog_title, 0, 50 ); |
|
| 601 | + $blog_title = strip_tags($blog_title); |
|
| 602 | + $blog_title = substr($blog_title, 0, 50); |
|
| 603 | 603 | |
| 604 | 604 | $errors = new WP_Error(); |
| 605 | - $illegal_names = get_site_option( 'illegal_names' ); |
|
| 606 | - if ( $illegal_names == false ) { |
|
| 607 | - $illegal_names = array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator' ); |
|
| 608 | - add_site_option( 'illegal_names', $illegal_names ); |
|
| 605 | + $illegal_names = get_site_option('illegal_names'); |
|
| 606 | + if ($illegal_names == false) { |
|
| 607 | + $illegal_names = array('www', 'web', 'root', 'admin', 'main', 'invite', 'administrator'); |
|
| 608 | + add_site_option('illegal_names', $illegal_names); |
|
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | /* |
| 612 | 612 | * On sub dir installs, some names are so illegal, only a filter can |
| 613 | 613 | * spring them from jail. |
| 614 | 614 | */ |
| 615 | - if ( ! is_subdomain_install() ) { |
|
| 615 | + if ( ! is_subdomain_install()) { |
|
| 616 | 616 | $illegal_names = array_merge( |
| 617 | 617 | $illegal_names, |
| 618 | 618 | /** |
@@ -622,31 +622,31 @@ discard block |
||
| 622 | 622 | * |
| 623 | 623 | * @param array $subdirectory_reserved_names Array of reserved names. |
| 624 | 624 | */ |
| 625 | - apply_filters( 'subdirectory_reserved_names', array( 'page', 'comments', 'blog', 'files', 'feed' ) ) |
|
| 625 | + apply_filters('subdirectory_reserved_names', array('page', 'comments', 'blog', 'files', 'feed')) |
|
| 626 | 626 | ); |
| 627 | 627 | } |
| 628 | 628 | |
| 629 | - if ( empty( $blogname ) ) |
|
| 630 | - $errors->add('blogname', __( 'Please enter a site name.' ) ); |
|
| 629 | + if (empty($blogname)) |
|
| 630 | + $errors->add('blogname', __('Please enter a site name.')); |
|
| 631 | 631 | |
| 632 | - if ( preg_match( '/[^a-z0-9]+/', $blogname ) ) |
|
| 633 | - $errors->add('blogname', __( 'Only lowercase letters (a-z) and numbers are allowed.' ) ); |
|
| 632 | + if (preg_match('/[^a-z0-9]+/', $blogname)) |
|
| 633 | + $errors->add('blogname', __('Only lowercase letters (a-z) and numbers are allowed.')); |
|
| 634 | 634 | |
| 635 | - if ( in_array( $blogname, $illegal_names ) ) |
|
| 636 | - $errors->add('blogname', __( 'That name is not allowed.' ) ); |
|
| 635 | + if (in_array($blogname, $illegal_names)) |
|
| 636 | + $errors->add('blogname', __('That name is not allowed.')); |
|
| 637 | 637 | |
| 638 | - if ( strlen( $blogname ) < 4 && !is_super_admin() ) |
|
| 639 | - $errors->add('blogname', __( 'Site name must be at least 4 characters.' ) ); |
|
| 638 | + if (strlen($blogname) < 4 && ! is_super_admin()) |
|
| 639 | + $errors->add('blogname', __('Site name must be at least 4 characters.')); |
|
| 640 | 640 | |
| 641 | - if ( strpos( $blogname, '_' ) !== false ) |
|
| 642 | - $errors->add( 'blogname', __( 'Sorry, site names may not contain the character “_”!' ) ); |
|
| 641 | + if (strpos($blogname, '_') !== false) |
|
| 642 | + $errors->add('blogname', __('Sorry, site names may not contain the character “_”!')); |
|
| 643 | 643 | |
| 644 | 644 | // do not allow users to create a blog that conflicts with a page on the main blog. |
| 645 | - if ( !is_subdomain_install() && $wpdb->get_var( $wpdb->prepare( "SELECT post_name FROM " . $wpdb->get_blog_prefix( $current_site->blog_id ) . "posts WHERE post_type = 'page' AND post_name = %s", $blogname ) ) ) |
|
| 646 | - $errors->add( 'blogname', __( 'Sorry, you may not use that site name.' ) ); |
|
| 645 | + if ( ! is_subdomain_install() && $wpdb->get_var($wpdb->prepare("SELECT post_name FROM ".$wpdb->get_blog_prefix($current_site->blog_id)."posts WHERE post_type = 'page' AND post_name = %s", $blogname))) |
|
| 646 | + $errors->add('blogname', __('Sorry, you may not use that site name.')); |
|
| 647 | 647 | |
| 648 | 648 | // all numeric? |
| 649 | - if ( preg_match( '/^[0-9]*$/', $blogname ) ) |
|
| 649 | + if (preg_match('/^[0-9]*$/', $blogname)) |
|
| 650 | 650 | $errors->add('blogname', __('Sorry, site names must have letters too!')); |
| 651 | 651 | |
| 652 | 652 | /** |
@@ -659,36 +659,36 @@ discard block |
||
| 659 | 659 | * |
| 660 | 660 | * @param string $blogname Site name. |
| 661 | 661 | */ |
| 662 | - $blogname = apply_filters( 'newblogname', $blogname ); |
|
| 662 | + $blogname = apply_filters('newblogname', $blogname); |
|
| 663 | 663 | |
| 664 | - $blog_title = wp_unslash( $blog_title ); |
|
| 664 | + $blog_title = wp_unslash($blog_title); |
|
| 665 | 665 | |
| 666 | - if ( empty( $blog_title ) ) |
|
| 667 | - $errors->add('blog_title', __( 'Please enter a site title.' ) ); |
|
| 666 | + if (empty($blog_title)) |
|
| 667 | + $errors->add('blog_title', __('Please enter a site title.')); |
|
| 668 | 668 | |
| 669 | 669 | // Check if the domain/path has been used already. |
| 670 | - if ( is_subdomain_install() ) { |
|
| 671 | - $mydomain = $blogname . '.' . preg_replace( '|^www\.|', '', $domain ); |
|
| 670 | + if (is_subdomain_install()) { |
|
| 671 | + $mydomain = $blogname.'.'.preg_replace('|^www\.|', '', $domain); |
|
| 672 | 672 | $path = $base; |
| 673 | 673 | } else { |
| 674 | 674 | $mydomain = "$domain"; |
| 675 | 675 | $path = $base.$blogname.'/'; |
| 676 | 676 | } |
| 677 | - if ( domain_exists($mydomain, $path, $current_site->id) ) |
|
| 678 | - $errors->add( 'blogname', __( 'Sorry, that site already exists!' ) ); |
|
| 677 | + if (domain_exists($mydomain, $path, $current_site->id)) |
|
| 678 | + $errors->add('blogname', __('Sorry, that site already exists!')); |
|
| 679 | 679 | |
| 680 | - if ( username_exists( $blogname ) ) { |
|
| 681 | - if ( ! is_object( $user ) || ( is_object($user) && ( $user->user_login != $blogname ) ) ) |
|
| 682 | - $errors->add( 'blogname', __( 'Sorry, that site is reserved!' ) ); |
|
| 680 | + if (username_exists($blogname)) { |
|
| 681 | + if ( ! is_object($user) || (is_object($user) && ($user->user_login != $blogname))) |
|
| 682 | + $errors->add('blogname', __('Sorry, that site is reserved!')); |
|
| 683 | 683 | } |
| 684 | 684 | |
| 685 | 685 | // Has someone already signed up for this domain? |
| 686 | - $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE domain = %s AND path = %s", $mydomain, $path) ); // TODO: Check email too? |
|
| 687 | - if ( ! empty($signup) ) { |
|
| 688 | - $diff = current_time( 'timestamp', true ) - mysql2date('U', $signup->registered); |
|
| 686 | + $signup = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->signups WHERE domain = %s AND path = %s", $mydomain, $path)); // TODO: Check email too? |
|
| 687 | + if ( ! empty($signup)) { |
|
| 688 | + $diff = current_time('timestamp', true) - mysql2date('U', $signup->registered); |
|
| 689 | 689 | // If registered more than two days ago, cancel registration and let this signup go through. |
| 690 | - if ( $diff > 2 * DAY_IN_SECONDS ) |
|
| 691 | - $wpdb->delete( $wpdb->signups, array( 'domain' => $mydomain , 'path' => $path ) ); |
|
| 690 | + if ($diff > 2 * DAY_IN_SECONDS) |
|
| 691 | + $wpdb->delete($wpdb->signups, array('domain' => $mydomain, 'path' => $path)); |
|
| 692 | 692 | else |
| 693 | 693 | $errors->add('blogname', __('That site is currently reserved but may be available in a couple days.')); |
| 694 | 694 | } |
@@ -711,7 +711,7 @@ discard block |
||
| 711 | 711 | * @type WP_Error $errors WP_Error containing any errors found. |
| 712 | 712 | * } |
| 713 | 713 | */ |
| 714 | - return apply_filters( 'wpmu_validate_blog_signup', $result ); |
|
| 714 | + return apply_filters('wpmu_validate_blog_signup', $result); |
|
| 715 | 715 | } |
| 716 | 716 | |
| 717 | 717 | /** |
@@ -728,13 +728,13 @@ discard block |
||
| 728 | 728 | * @param string $user_email The user's email address. |
| 729 | 729 | * @param array $meta By default, contains the requested privacy setting and lang_id. |
| 730 | 730 | */ |
| 731 | -function wpmu_signup_blog( $domain, $path, $title, $user, $user_email, $meta = array() ) { |
|
| 731 | +function wpmu_signup_blog($domain, $path, $title, $user, $user_email, $meta = array()) { |
|
| 732 | 732 | global $wpdb; |
| 733 | 733 | |
| 734 | - $key = substr( md5( time() . rand() . $domain ), 0, 16 ); |
|
| 734 | + $key = substr(md5(time().rand().$domain), 0, 16); |
|
| 735 | 735 | $meta = serialize($meta); |
| 736 | 736 | |
| 737 | - $wpdb->insert( $wpdb->signups, array( |
|
| 737 | + $wpdb->insert($wpdb->signups, array( |
|
| 738 | 738 | 'domain' => $domain, |
| 739 | 739 | 'path' => $path, |
| 740 | 740 | 'title' => $title, |
@@ -743,7 +743,7 @@ discard block |
||
| 743 | 743 | 'registered' => current_time('mysql', true), |
| 744 | 744 | 'activation_key' => $key, |
| 745 | 745 | 'meta' => $meta |
| 746 | - ) ); |
|
| 746 | + )); |
|
| 747 | 747 | |
| 748 | 748 | wpmu_signup_blog_notification($domain, $path, $title, $user, $user_email, $key, $meta); |
| 749 | 749 | } |
@@ -762,16 +762,16 @@ discard block |
||
| 762 | 762 | * @param string $user_email The user's email address. |
| 763 | 763 | * @param array $meta By default, this is an empty array. |
| 764 | 764 | */ |
| 765 | -function wpmu_signup_user( $user, $user_email, $meta = array() ) { |
|
| 765 | +function wpmu_signup_user($user, $user_email, $meta = array()) { |
|
| 766 | 766 | global $wpdb; |
| 767 | 767 | |
| 768 | 768 | // Format data |
| 769 | - $user = preg_replace( '/\s+/', '', sanitize_user( $user, true ) ); |
|
| 770 | - $user_email = sanitize_email( $user_email ); |
|
| 771 | - $key = substr( md5( time() . rand() . $user_email ), 0, 16 ); |
|
| 769 | + $user = preg_replace('/\s+/', '', sanitize_user($user, true)); |
|
| 770 | + $user_email = sanitize_email($user_email); |
|
| 771 | + $key = substr(md5(time().rand().$user_email), 0, 16); |
|
| 772 | 772 | $meta = serialize($meta); |
| 773 | 773 | |
| 774 | - $wpdb->insert( $wpdb->signups, array( |
|
| 774 | + $wpdb->insert($wpdb->signups, array( |
|
| 775 | 775 | 'domain' => '', |
| 776 | 776 | 'path' => '', |
| 777 | 777 | 'title' => '', |
@@ -780,7 +780,7 @@ discard block |
||
| 780 | 780 | 'registered' => current_time('mysql', true), |
| 781 | 781 | 'activation_key' => $key, |
| 782 | 782 | 'meta' => $meta |
| 783 | - ) ); |
|
| 783 | + )); |
|
| 784 | 784 | |
| 785 | 785 | wpmu_signup_user_notification($user, $user_email, $key, $meta); |
| 786 | 786 | } |
@@ -809,7 +809,7 @@ discard block |
||
| 809 | 809 | * @param array $meta By default, contains the requested privacy setting and lang_id. |
| 810 | 810 | * @return bool |
| 811 | 811 | */ |
| 812 | -function wpmu_signup_blog_notification( $domain, $path, $title, $user, $user_email, $key, $meta = array() ) { |
|
| 812 | +function wpmu_signup_blog_notification($domain, $path, $title, $user, $user_email, $key, $meta = array()) { |
|
| 813 | 813 | /** |
| 814 | 814 | * Filter whether to bypass the new site email notification. |
| 815 | 815 | * |
@@ -823,22 +823,22 @@ discard block |
||
| 823 | 823 | * @param string $key Activation key created in wpmu_signup_blog(). |
| 824 | 824 | * @param array $meta By default, contains the requested privacy setting and lang_id. |
| 825 | 825 | */ |
| 826 | - if ( ! apply_filters( 'wpmu_signup_blog_notification', $domain, $path, $title, $user, $user_email, $key, $meta ) ) { |
|
| 826 | + if ( ! apply_filters('wpmu_signup_blog_notification', $domain, $path, $title, $user, $user_email, $key, $meta)) { |
|
| 827 | 827 | return false; |
| 828 | 828 | } |
| 829 | 829 | |
| 830 | 830 | // Send email with activation link. |
| 831 | - if ( !is_subdomain_install() || get_current_site()->id != 1 ) |
|
| 831 | + if ( ! is_subdomain_install() || get_current_site()->id != 1) |
|
| 832 | 832 | $activate_url = network_site_url("wp-activate.php?key=$key"); |
| 833 | 833 | else |
| 834 | 834 | $activate_url = "http://{$domain}{$path}wp-activate.php?key=$key"; // @todo use *_url() API |
| 835 | 835 | |
| 836 | 836 | $activate_url = esc_url($activate_url); |
| 837 | - $admin_email = get_site_option( 'admin_email' ); |
|
| 838 | - if ( $admin_email == '' ) |
|
| 839 | - $admin_email = 'support@' . $_SERVER['SERVER_NAME']; |
|
| 840 | - $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) ); |
|
| 841 | - $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; |
|
| 837 | + $admin_email = get_site_option('admin_email'); |
|
| 838 | + if ($admin_email == '') |
|
| 839 | + $admin_email = 'support@'.$_SERVER['SERVER_NAME']; |
|
| 840 | + $from_name = get_site_option('site_name') == '' ? 'WordPress' : esc_html(get_site_option('site_name')); |
|
| 841 | + $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n"."Content-Type: text/plain; charset=\"".get_option('blog_charset')."\"\n"; |
|
| 842 | 842 | $message = sprintf( |
| 843 | 843 | /** |
| 844 | 844 | * Filter the message content of the new blog notification email. |
@@ -856,12 +856,12 @@ discard block |
||
| 856 | 856 | * @param string $key Activation key created in wpmu_signup_blog(). |
| 857 | 857 | * @param array $meta By default, contains the requested privacy setting and lang_id. |
| 858 | 858 | */ |
| 859 | - apply_filters( 'wpmu_signup_blog_notification_email', |
|
| 860 | - __( "To activate your blog, please click the following link:\n\n%s\n\nAfter you activate, you will receive *another email* with your login.\n\nAfter you activate, you can visit your site here:\n\n%s" ), |
|
| 859 | + apply_filters('wpmu_signup_blog_notification_email', |
|
| 860 | + __("To activate your blog, please click the following link:\n\n%s\n\nAfter you activate, you will receive *another email* with your login.\n\nAfter you activate, you can visit your site here:\n\n%s"), |
|
| 861 | 861 | $domain, $path, $title, $user, $user_email, $key, $meta |
| 862 | 862 | ), |
| 863 | 863 | $activate_url, |
| 864 | - esc_url( "http://{$domain}{$path}" ), |
|
| 864 | + esc_url("http://{$domain}{$path}"), |
|
| 865 | 865 | $key |
| 866 | 866 | ); |
| 867 | 867 | // TODO: Don't hard code activation link. |
@@ -880,14 +880,14 @@ discard block |
||
| 880 | 880 | * @param string $key Activation key created in wpmu_signup_blog(). |
| 881 | 881 | * @param array $meta By default, contains the requested privacy setting and lang_id. |
| 882 | 882 | */ |
| 883 | - apply_filters( 'wpmu_signup_blog_notification_subject', |
|
| 884 | - __( '[%1$s] Activate %2$s' ), |
|
| 883 | + apply_filters('wpmu_signup_blog_notification_subject', |
|
| 884 | + __('[%1$s] Activate %2$s'), |
|
| 885 | 885 | $domain, $path, $title, $user, $user_email, $key, $meta |
| 886 | 886 | ), |
| 887 | 887 | $from_name, |
| 888 | - esc_url( 'http://' . $domain . $path ) |
|
| 888 | + esc_url('http://'.$domain.$path) |
|
| 889 | 889 | ); |
| 890 | - wp_mail( $user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); |
|
| 890 | + wp_mail($user_email, wp_specialchars_decode($subject), $message, $message_headers); |
|
| 891 | 891 | return true; |
| 892 | 892 | } |
| 893 | 893 | |
@@ -912,7 +912,7 @@ discard block |
||
| 912 | 912 | * @param array $meta By default, an empty array. |
| 913 | 913 | * @return bool |
| 914 | 914 | */ |
| 915 | -function wpmu_signup_user_notification( $user, $user_email, $key, $meta = array() ) { |
|
| 915 | +function wpmu_signup_user_notification($user, $user_email, $key, $meta = array()) { |
|
| 916 | 916 | /** |
| 917 | 917 | * Filter whether to bypass the email notification for new user sign-up. |
| 918 | 918 | * |
@@ -923,15 +923,15 @@ discard block |
||
| 923 | 923 | * @param string $key Activation key created in wpmu_signup_user(). |
| 924 | 924 | * @param array $meta Signup meta data. |
| 925 | 925 | */ |
| 926 | - if ( ! apply_filters( 'wpmu_signup_user_notification', $user, $user_email, $key, $meta ) ) |
|
| 926 | + if ( ! apply_filters('wpmu_signup_user_notification', $user, $user_email, $key, $meta)) |
|
| 927 | 927 | return false; |
| 928 | 928 | |
| 929 | 929 | // Send email with activation link. |
| 930 | - $admin_email = get_site_option( 'admin_email' ); |
|
| 931 | - if ( $admin_email == '' ) |
|
| 932 | - $admin_email = 'support@' . $_SERVER['SERVER_NAME']; |
|
| 933 | - $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) ); |
|
| 934 | - $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; |
|
| 930 | + $admin_email = get_site_option('admin_email'); |
|
| 931 | + if ($admin_email == '') |
|
| 932 | + $admin_email = 'support@'.$_SERVER['SERVER_NAME']; |
|
| 933 | + $from_name = get_site_option('site_name') == '' ? 'WordPress' : esc_html(get_site_option('site_name')); |
|
| 934 | + $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n"."Content-Type: text/plain; charset=\"".get_option('blog_charset')."\"\n"; |
|
| 935 | 935 | $message = sprintf( |
| 936 | 936 | /** |
| 937 | 937 | * Filter the content of the notification email for new user sign-up. |
@@ -946,11 +946,11 @@ discard block |
||
| 946 | 946 | * @param string $key Activation key created in wpmu_signup_user(). |
| 947 | 947 | * @param array $meta Signup meta data. |
| 948 | 948 | */ |
| 949 | - apply_filters( 'wpmu_signup_user_notification_email', |
|
| 950 | - __( "To activate your user, please click the following link:\n\n%s\n\nAfter you activate, you will receive *another email* with your login." ), |
|
| 949 | + apply_filters('wpmu_signup_user_notification_email', |
|
| 950 | + __("To activate your user, please click the following link:\n\n%s\n\nAfter you activate, you will receive *another email* with your login."), |
|
| 951 | 951 | $user, $user_email, $key, $meta |
| 952 | 952 | ), |
| 953 | - site_url( "wp-activate.php?key=$key" ) |
|
| 953 | + site_url("wp-activate.php?key=$key") |
|
| 954 | 954 | ); |
| 955 | 955 | // TODO: Don't hard code activation link. |
| 956 | 956 | $subject = sprintf( |
@@ -965,14 +965,14 @@ discard block |
||
| 965 | 965 | * @param string $key Activation key created in wpmu_signup_user(). |
| 966 | 966 | * @param array $meta Signup meta data. |
| 967 | 967 | */ |
| 968 | - apply_filters( 'wpmu_signup_user_notification_subject', |
|
| 969 | - __( '[%1$s] Activate %2$s' ), |
|
| 968 | + apply_filters('wpmu_signup_user_notification_subject', |
|
| 969 | + __('[%1$s] Activate %2$s'), |
|
| 970 | 970 | $user, $user_email, $key, $meta |
| 971 | 971 | ), |
| 972 | 972 | $from_name, |
| 973 | 973 | $user |
| 974 | 974 | ); |
| 975 | - wp_mail( $user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); |
|
| 975 | + wp_mail($user_email, wp_specialchars_decode($subject), $message, $message_headers); |
|
| 976 | 976 | return true; |
| 977 | 977 | } |
| 978 | 978 | |
@@ -994,40 +994,40 @@ discard block |
||
| 994 | 994 | function wpmu_activate_signup($key) { |
| 995 | 995 | global $wpdb; |
| 996 | 996 | |
| 997 | - $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE activation_key = %s", $key) ); |
|
| 997 | + $signup = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->signups WHERE activation_key = %s", $key)); |
|
| 998 | 998 | |
| 999 | - if ( empty( $signup ) ) |
|
| 1000 | - return new WP_Error( 'invalid_key', __( 'Invalid activation key.' ) ); |
|
| 999 | + if (empty($signup)) |
|
| 1000 | + return new WP_Error('invalid_key', __('Invalid activation key.')); |
|
| 1001 | 1001 | |
| 1002 | - if ( $signup->active ) { |
|
| 1003 | - if ( empty( $signup->domain ) ) |
|
| 1004 | - return new WP_Error( 'already_active', __( 'The user is already active.' ), $signup ); |
|
| 1002 | + if ($signup->active) { |
|
| 1003 | + if (empty($signup->domain)) |
|
| 1004 | + return new WP_Error('already_active', __('The user is already active.'), $signup); |
|
| 1005 | 1005 | else |
| 1006 | - return new WP_Error( 'already_active', __( 'The site is already active.' ), $signup ); |
|
| 1006 | + return new WP_Error('already_active', __('The site is already active.'), $signup); |
|
| 1007 | 1007 | } |
| 1008 | 1008 | |
| 1009 | 1009 | $meta = maybe_unserialize($signup->meta); |
| 1010 | - $password = wp_generate_password( 12, false ); |
|
| 1010 | + $password = wp_generate_password(12, false); |
|
| 1011 | 1011 | |
| 1012 | 1012 | $user_id = username_exists($signup->user_login); |
| 1013 | 1013 | |
| 1014 | - if ( ! $user_id ) |
|
| 1014 | + if ( ! $user_id) |
|
| 1015 | 1015 | $user_id = wpmu_create_user($signup->user_login, $password, $signup->user_email); |
| 1016 | 1016 | else |
| 1017 | 1017 | $user_already_exists = true; |
| 1018 | 1018 | |
| 1019 | - if ( ! $user_id ) |
|
| 1019 | + if ( ! $user_id) |
|
| 1020 | 1020 | return new WP_Error('create_user', __('Could not create user'), $signup); |
| 1021 | 1021 | |
| 1022 | 1022 | $now = current_time('mysql', true); |
| 1023 | 1023 | |
| 1024 | - if ( empty($signup->domain) ) { |
|
| 1025 | - $wpdb->update( $wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key) ); |
|
| 1024 | + if (empty($signup->domain)) { |
|
| 1025 | + $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key)); |
|
| 1026 | 1026 | |
| 1027 | - if ( isset( $user_already_exists ) ) |
|
| 1028 | - return new WP_Error( 'user_already_exists', __( 'That username is already activated.' ), $signup); |
|
| 1027 | + if (isset($user_already_exists)) |
|
| 1028 | + return new WP_Error('user_already_exists', __('That username is already activated.'), $signup); |
|
| 1029 | 1029 | |
| 1030 | - wpmu_welcome_user_notification( $user_id, $password, $meta ); |
|
| 1030 | + wpmu_welcome_user_notification($user_id, $password, $meta); |
|
| 1031 | 1031 | /** |
| 1032 | 1032 | * Fires immediately after a new user is activated. |
| 1033 | 1033 | * |
@@ -1037,24 +1037,24 @@ discard block |
||
| 1037 | 1037 | * @param int $password User password. |
| 1038 | 1038 | * @param array $meta Signup meta data. |
| 1039 | 1039 | */ |
| 1040 | - do_action( 'wpmu_activate_user', $user_id, $password, $meta ); |
|
| 1041 | - return array( 'user_id' => $user_id, 'password' => $password, 'meta' => $meta ); |
|
| 1040 | + do_action('wpmu_activate_user', $user_id, $password, $meta); |
|
| 1041 | + return array('user_id' => $user_id, 'password' => $password, 'meta' => $meta); |
|
| 1042 | 1042 | } |
| 1043 | 1043 | |
| 1044 | - $blog_id = wpmu_create_blog( $signup->domain, $signup->path, $signup->title, $user_id, $meta, $wpdb->siteid ); |
|
| 1044 | + $blog_id = wpmu_create_blog($signup->domain, $signup->path, $signup->title, $user_id, $meta, $wpdb->siteid); |
|
| 1045 | 1045 | |
| 1046 | 1046 | // TODO: What to do if we create a user but cannot create a blog? |
| 1047 | - if ( is_wp_error($blog_id) ) { |
|
| 1047 | + if (is_wp_error($blog_id)) { |
|
| 1048 | 1048 | // If blog is taken, that means a previous attempt to activate this blog failed in between creating the blog and |
| 1049 | 1049 | // setting the activation flag. Let's just set the active flag and instruct the user to reset their password. |
| 1050 | - if ( 'blog_taken' == $blog_id->get_error_code() ) { |
|
| 1051 | - $blog_id->add_data( $signup ); |
|
| 1052 | - $wpdb->update( $wpdb->signups, array( 'active' => 1, 'activated' => $now ), array( 'activation_key' => $key ) ); |
|
| 1050 | + if ('blog_taken' == $blog_id->get_error_code()) { |
|
| 1051 | + $blog_id->add_data($signup); |
|
| 1052 | + $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key)); |
|
| 1053 | 1053 | } |
| 1054 | 1054 | return $blog_id; |
| 1055 | 1055 | } |
| 1056 | 1056 | |
| 1057 | - $wpdb->update( $wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key) ); |
|
| 1057 | + $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key)); |
|
| 1058 | 1058 | wpmu_welcome_notification($blog_id, $user_id, $password, $signup->title, $meta); |
| 1059 | 1059 | /** |
| 1060 | 1060 | * Fires immediately after a site is activated. |
@@ -1067,7 +1067,7 @@ discard block |
||
| 1067 | 1067 | * @param string $signup_title Site title. |
| 1068 | 1068 | * @param array $meta Signup meta data. |
| 1069 | 1069 | */ |
| 1070 | - do_action( 'wpmu_activate_blog', $blog_id, $user_id, $password, $signup->title, $meta ); |
|
| 1070 | + do_action('wpmu_activate_blog', $blog_id, $user_id, $password, $signup->title, $meta); |
|
| 1071 | 1071 | |
| 1072 | 1072 | return array('blog_id' => $blog_id, 'user_id' => $user_id, 'password' => $password, 'title' => $signup->title, 'meta' => $meta); |
| 1073 | 1073 | } |
@@ -1087,16 +1087,16 @@ discard block |
||
| 1087 | 1087 | * @param string $email The new user's email address. |
| 1088 | 1088 | * @return int|false Returns false on failure, or int $user_id on success |
| 1089 | 1089 | */ |
| 1090 | -function wpmu_create_user( $user_name, $password, $email ) { |
|
| 1091 | - $user_name = preg_replace( '/\s+/', '', sanitize_user( $user_name, true ) ); |
|
| 1090 | +function wpmu_create_user($user_name, $password, $email) { |
|
| 1091 | + $user_name = preg_replace('/\s+/', '', sanitize_user($user_name, true)); |
|
| 1092 | 1092 | |
| 1093 | - $user_id = wp_create_user( $user_name, $password, $email ); |
|
| 1094 | - if ( is_wp_error( $user_id ) ) |
|
| 1093 | + $user_id = wp_create_user($user_name, $password, $email); |
|
| 1094 | + if (is_wp_error($user_id)) |
|
| 1095 | 1095 | return false; |
| 1096 | 1096 | |
| 1097 | 1097 | // Newly created users have no roles or caps until they are added to a blog. |
| 1098 | - delete_user_option( $user_id, 'capabilities' ); |
|
| 1099 | - delete_user_option( $user_id, 'user_level' ); |
|
| 1098 | + delete_user_option($user_id, 'capabilities'); |
|
| 1099 | + delete_user_option($user_id, 'user_level'); |
|
| 1100 | 1100 | |
| 1101 | 1101 | /** |
| 1102 | 1102 | * Fires immediately after a new user is created. |
@@ -1105,7 +1105,7 @@ discard block |
||
| 1105 | 1105 | * |
| 1106 | 1106 | * @param int $user_id User ID. |
| 1107 | 1107 | */ |
| 1108 | - do_action( 'wpmu_new_user', $user_id ); |
|
| 1108 | + do_action('wpmu_new_user', $user_id); |
|
| 1109 | 1109 | |
| 1110 | 1110 | return $user_id; |
| 1111 | 1111 | } |
@@ -1132,29 +1132,29 @@ discard block |
||
| 1132 | 1132 | * @param int $site_id Optional. Only relevant on multi-network installs. |
| 1133 | 1133 | * @return int|WP_Error Returns WP_Error object on failure, int $blog_id on success |
| 1134 | 1134 | */ |
| 1135 | -function wpmu_create_blog( $domain, $path, $title, $user_id, $meta = array(), $site_id = 1 ) { |
|
| 1136 | - $defaults = array( 'public' => 0 ); |
|
| 1137 | - $meta = wp_parse_args( $meta, $defaults ); |
|
| 1135 | +function wpmu_create_blog($domain, $path, $title, $user_id, $meta = array(), $site_id = 1) { |
|
| 1136 | + $defaults = array('public' => 0); |
|
| 1137 | + $meta = wp_parse_args($meta, $defaults); |
|
| 1138 | 1138 | |
| 1139 | - $domain = preg_replace( '/\s+/', '', sanitize_user( $domain, true ) ); |
|
| 1139 | + $domain = preg_replace('/\s+/', '', sanitize_user($domain, true)); |
|
| 1140 | 1140 | |
| 1141 | - if ( is_subdomain_install() ) |
|
| 1142 | - $domain = str_replace( '@', '', $domain ); |
|
| 1141 | + if (is_subdomain_install()) |
|
| 1142 | + $domain = str_replace('@', '', $domain); |
|
| 1143 | 1143 | |
| 1144 | - $title = strip_tags( $title ); |
|
| 1144 | + $title = strip_tags($title); |
|
| 1145 | 1145 | $user_id = (int) $user_id; |
| 1146 | 1146 | |
| 1147 | - if ( empty($path) ) |
|
| 1147 | + if (empty($path)) |
|
| 1148 | 1148 | $path = '/'; |
| 1149 | 1149 | |
| 1150 | 1150 | // Check if the domain has been used already. We should return an error message. |
| 1151 | - if ( domain_exists($domain, $path, $site_id) ) |
|
| 1152 | - return new WP_Error( 'blog_taken', __( 'Sorry, that site already exists!' ) ); |
|
| 1151 | + if (domain_exists($domain, $path, $site_id)) |
|
| 1152 | + return new WP_Error('blog_taken', __('Sorry, that site already exists!')); |
|
| 1153 | 1153 | |
| 1154 | - if ( !defined('WP_INSTALLING') ) |
|
| 1155 | - define( 'WP_INSTALLING', true ); |
|
| 1154 | + if ( ! defined('WP_INSTALLING')) |
|
| 1155 | + define('WP_INSTALLING', true); |
|
| 1156 | 1156 | |
| 1157 | - if ( ! $blog_id = insert_blog($domain, $path, $site_id) ) |
|
| 1157 | + if ( ! $blog_id = insert_blog($domain, $path, $site_id)) |
|
| 1158 | 1158 | return new WP_Error('insert_blog', __('Could not create site.')); |
| 1159 | 1159 | |
| 1160 | 1160 | switch_to_blog($blog_id); |
@@ -1163,18 +1163,18 @@ discard block |
||
| 1163 | 1163 | |
| 1164 | 1164 | add_user_to_blog($blog_id, $user_id, 'administrator'); |
| 1165 | 1165 | |
| 1166 | - foreach ( $meta as $key => $value ) { |
|
| 1167 | - if ( in_array( $key, array( 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id' ) ) ) |
|
| 1168 | - update_blog_status( $blog_id, $key, $value ); |
|
| 1166 | + foreach ($meta as $key => $value) { |
|
| 1167 | + if (in_array($key, array('public', 'archived', 'mature', 'spam', 'deleted', 'lang_id'))) |
|
| 1168 | + update_blog_status($blog_id, $key, $value); |
|
| 1169 | 1169 | else |
| 1170 | - update_option( $key, $value ); |
|
| 1170 | + update_option($key, $value); |
|
| 1171 | 1171 | } |
| 1172 | 1172 | |
| 1173 | - add_option( 'WPLANG', get_site_option( 'WPLANG' ) ); |
|
| 1174 | - update_option( 'blog_public', (int) $meta['public'] ); |
|
| 1173 | + add_option('WPLANG', get_site_option('WPLANG')); |
|
| 1174 | + update_option('blog_public', (int) $meta['public']); |
|
| 1175 | 1175 | |
| 1176 | - if ( ! is_super_admin( $user_id ) && ! get_user_meta( $user_id, 'primary_blog', true ) ) |
|
| 1177 | - update_user_meta( $user_id, 'primary_blog', $blog_id ); |
|
| 1176 | + if ( ! is_super_admin($user_id) && ! get_user_meta($user_id, 'primary_blog', true)) |
|
| 1177 | + update_user_meta($user_id, 'primary_blog', $blog_id); |
|
| 1178 | 1178 | |
| 1179 | 1179 | restore_current_blog(); |
| 1180 | 1180 | /** |
@@ -1189,7 +1189,7 @@ discard block |
||
| 1189 | 1189 | * @param int $site_id Site ID. Only relevant on multi-network installs. |
| 1190 | 1190 | * @param array $meta Meta data. Used to set initial site options. |
| 1191 | 1191 | */ |
| 1192 | - do_action( 'wpmu_new_blog', $blog_id, $user_id, $domain, $path, $site_id, $meta ); |
|
| 1192 | + do_action('wpmu_new_blog', $blog_id, $user_id, $domain, $path, $site_id, $meta); |
|
| 1193 | 1193 | |
| 1194 | 1194 | return $blog_id; |
| 1195 | 1195 | } |
@@ -1205,26 +1205,26 @@ discard block |
||
| 1205 | 1205 | * @param int $blog_id The new site's ID. |
| 1206 | 1206 | * @return bool |
| 1207 | 1207 | */ |
| 1208 | -function newblog_notify_siteadmin( $blog_id, $deprecated = '' ) { |
|
| 1209 | - if ( get_site_option( 'registrationnotification' ) != 'yes' ) |
|
| 1208 | +function newblog_notify_siteadmin($blog_id, $deprecated = '') { |
|
| 1209 | + if (get_site_option('registrationnotification') != 'yes') |
|
| 1210 | 1210 | return false; |
| 1211 | 1211 | |
| 1212 | - $email = get_site_option( 'admin_email' ); |
|
| 1213 | - if ( is_email($email) == false ) |
|
| 1212 | + $email = get_site_option('admin_email'); |
|
| 1213 | + if (is_email($email) == false) |
|
| 1214 | 1214 | return false; |
| 1215 | 1215 | |
| 1216 | 1216 | $options_site_url = esc_url(network_admin_url('settings.php')); |
| 1217 | 1217 | |
| 1218 | - switch_to_blog( $blog_id ); |
|
| 1219 | - $blogname = get_option( 'blogname' ); |
|
| 1218 | + switch_to_blog($blog_id); |
|
| 1219 | + $blogname = get_option('blogname'); |
|
| 1220 | 1220 | $siteurl = site_url(); |
| 1221 | 1221 | restore_current_blog(); |
| 1222 | 1222 | |
| 1223 | - $msg = sprintf( __( 'New Site: %1$s |
|
| 1223 | + $msg = sprintf(__('New Site: %1$s |
|
| 1224 | 1224 | URL: %2$s |
| 1225 | 1225 | Remote IP: %3$s |
| 1226 | 1226 | |
| 1227 | -Disable these notifications: %4$s' ), $blogname, $siteurl, wp_unslash( $_SERVER['REMOTE_ADDR'] ), $options_site_url); |
|
| 1227 | +Disable these notifications: %4$s' ), $blogname, $siteurl, wp_unslash($_SERVER['REMOTE_ADDR']), $options_site_url); |
|
| 1228 | 1228 | /** |
| 1229 | 1229 | * Filter the message body of the new site activation email sent |
| 1230 | 1230 | * to the network administrator. |
@@ -1233,9 +1233,9 @@ discard block |
||
| 1233 | 1233 | * |
| 1234 | 1234 | * @param string $msg Email body. |
| 1235 | 1235 | */ |
| 1236 | - $msg = apply_filters( 'newblog_notify_siteadmin', $msg ); |
|
| 1236 | + $msg = apply_filters('newblog_notify_siteadmin', $msg); |
|
| 1237 | 1237 | |
| 1238 | - wp_mail( $email, sprintf( __( 'New Site Registration: %s' ), $siteurl ), $msg ); |
|
| 1238 | + wp_mail($email, sprintf(__('New Site Registration: %s'), $siteurl), $msg); |
|
| 1239 | 1239 | return true; |
| 1240 | 1240 | } |
| 1241 | 1241 | |
@@ -1250,22 +1250,22 @@ discard block |
||
| 1250 | 1250 | * @param int $user_id The new user's ID. |
| 1251 | 1251 | * @return bool |
| 1252 | 1252 | */ |
| 1253 | -function newuser_notify_siteadmin( $user_id ) { |
|
| 1254 | - if ( get_site_option( 'registrationnotification' ) != 'yes' ) |
|
| 1253 | +function newuser_notify_siteadmin($user_id) { |
|
| 1254 | + if (get_site_option('registrationnotification') != 'yes') |
|
| 1255 | 1255 | return false; |
| 1256 | 1256 | |
| 1257 | - $email = get_site_option( 'admin_email' ); |
|
| 1257 | + $email = get_site_option('admin_email'); |
|
| 1258 | 1258 | |
| 1259 | - if ( is_email($email) == false ) |
|
| 1259 | + if (is_email($email) == false) |
|
| 1260 | 1260 | return false; |
| 1261 | 1261 | |
| 1262 | - $user = get_userdata( $user_id ); |
|
| 1262 | + $user = get_userdata($user_id); |
|
| 1263 | 1263 | |
| 1264 | 1264 | $options_site_url = esc_url(network_admin_url('settings.php')); |
| 1265 | 1265 | $msg = sprintf(__('New User: %1$s |
| 1266 | 1266 | Remote IP: %2$s |
| 1267 | 1267 | |
| 1268 | -Disable these notifications: %3$s'), $user->user_login, wp_unslash( $_SERVER['REMOTE_ADDR'] ), $options_site_url); |
|
| 1268 | +Disable these notifications: %3$s'), $user->user_login, wp_unslash($_SERVER['REMOTE_ADDR']), $options_site_url); |
|
| 1269 | 1269 | |
| 1270 | 1270 | /** |
| 1271 | 1271 | * Filter the message body of the new user activation email sent |
@@ -1276,8 +1276,8 @@ discard block |
||
| 1276 | 1276 | * @param string $msg Email body. |
| 1277 | 1277 | * @param WP_User $user WP_User instance of the new user. |
| 1278 | 1278 | */ |
| 1279 | - $msg = apply_filters( 'newuser_notify_siteadmin', $msg, $user ); |
|
| 1280 | - wp_mail( $email, sprintf(__('New User Registration: %s'), $user->user_login), $msg ); |
|
| 1279 | + $msg = apply_filters('newuser_notify_siteadmin', $msg, $user); |
|
| 1280 | + wp_mail($email, sprintf(__('New User Registration: %s'), $user->user_login), $msg); |
|
| 1281 | 1281 | return true; |
| 1282 | 1282 | } |
| 1283 | 1283 | |
@@ -1298,8 +1298,8 @@ discard block |
||
| 1298 | 1298 | */ |
| 1299 | 1299 | function domain_exists($domain, $path, $site_id = 1) { |
| 1300 | 1300 | global $wpdb; |
| 1301 | - $path = trailingslashit( $path ); |
|
| 1302 | - $result = $wpdb->get_var( $wpdb->prepare("SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s AND site_id = %d", $domain, $path, $site_id) ); |
|
| 1301 | + $path = trailingslashit($path); |
|
| 1302 | + $result = $wpdb->get_var($wpdb->prepare("SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s AND site_id = %d", $domain, $path, $site_id)); |
|
| 1303 | 1303 | |
| 1304 | 1304 | /** |
| 1305 | 1305 | * Filter whether a blogname is taken. |
@@ -1311,7 +1311,7 @@ discard block |
||
| 1311 | 1311 | * @param string $path Path to be checked. |
| 1312 | 1312 | * @param int $site_id Site ID. Relevant only on multi-network installs. |
| 1313 | 1313 | */ |
| 1314 | - return apply_filters( 'domain_exists', $result, $domain, $path, $site_id ); |
|
| 1314 | + return apply_filters('domain_exists', $result, $domain, $path, $site_id); |
|
| 1315 | 1315 | } |
| 1316 | 1316 | |
| 1317 | 1317 | /** |
@@ -1335,12 +1335,12 @@ discard block |
||
| 1335 | 1335 | $path = trailingslashit($path); |
| 1336 | 1336 | $site_id = (int) $site_id; |
| 1337 | 1337 | |
| 1338 | - $result = $wpdb->insert( $wpdb->blogs, array('site_id' => $site_id, 'domain' => $domain, 'path' => $path, 'registered' => current_time('mysql')) ); |
|
| 1339 | - if ( ! $result ) |
|
| 1338 | + $result = $wpdb->insert($wpdb->blogs, array('site_id' => $site_id, 'domain' => $domain, 'path' => $path, 'registered' => current_time('mysql'))); |
|
| 1339 | + if ( ! $result) |
|
| 1340 | 1340 | return false; |
| 1341 | 1341 | |
| 1342 | 1342 | $blog_id = $wpdb->insert_id; |
| 1343 | - refresh_blog_details( $blog_id ); |
|
| 1343 | + refresh_blog_details($blog_id); |
|
| 1344 | 1344 | |
| 1345 | 1345 | wp_maybe_update_network_site_counts(); |
| 1346 | 1346 | |
@@ -1362,46 +1362,46 @@ discard block |
||
| 1362 | 1362 | * @param int $blog_id The value returned by insert_blog(). |
| 1363 | 1363 | * @param string $blog_title The title of the new site. |
| 1364 | 1364 | */ |
| 1365 | -function install_blog( $blog_id, $blog_title = '' ) { |
|
| 1365 | +function install_blog($blog_id, $blog_title = '') { |
|
| 1366 | 1366 | global $wpdb, $wp_roles; |
| 1367 | 1367 | |
| 1368 | 1368 | // Cast for security |
| 1369 | 1369 | $blog_id = (int) $blog_id; |
| 1370 | 1370 | |
| 1371 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
| 1371 | + require_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
|
| 1372 | 1372 | |
| 1373 | 1373 | $suppress = $wpdb->suppress_errors(); |
| 1374 | - if ( $wpdb->get_results( "DESCRIBE {$wpdb->posts}" ) ) |
|
| 1375 | - die( '<h1>' . __( 'Already Installed' ) . '</h1><p>' . __( 'You appear to have already installed WordPress. To reinstall please clear your old database tables first.' ) . '</p></body></html>' ); |
|
| 1376 | - $wpdb->suppress_errors( $suppress ); |
|
| 1374 | + if ($wpdb->get_results("DESCRIBE {$wpdb->posts}")) |
|
| 1375 | + die('<h1>'.__('Already Installed').'</h1><p>'.__('You appear to have already installed WordPress. To reinstall please clear your old database tables first.').'</p></body></html>'); |
|
| 1376 | + $wpdb->suppress_errors($suppress); |
|
| 1377 | 1377 | |
| 1378 | - $url = get_blogaddress_by_id( $blog_id ); |
|
| 1378 | + $url = get_blogaddress_by_id($blog_id); |
|
| 1379 | 1379 | |
| 1380 | 1380 | // Set everything up |
| 1381 | - make_db_current_silent( 'blog' ); |
|
| 1381 | + make_db_current_silent('blog'); |
|
| 1382 | 1382 | populate_options(); |
| 1383 | 1383 | populate_roles(); |
| 1384 | 1384 | |
| 1385 | 1385 | // populate_roles() clears previous role definitions so we start over. |
| 1386 | 1386 | $wp_roles = new WP_Roles(); |
| 1387 | 1387 | |
| 1388 | - $url = untrailingslashit( $url ); |
|
| 1388 | + $url = untrailingslashit($url); |
|
| 1389 | 1389 | |
| 1390 | - update_option( 'siteurl', $url ); |
|
| 1391 | - update_option( 'home', $url ); |
|
| 1390 | + update_option('siteurl', $url); |
|
| 1391 | + update_option('home', $url); |
|
| 1392 | 1392 | |
| 1393 | - if ( get_site_option( 'ms_files_rewriting' ) ) |
|
| 1394 | - update_option( 'upload_path', UPLOADBLOGSDIR . "/$blog_id/files" ); |
|
| 1393 | + if (get_site_option('ms_files_rewriting')) |
|
| 1394 | + update_option('upload_path', UPLOADBLOGSDIR."/$blog_id/files"); |
|
| 1395 | 1395 | else |
| 1396 | - update_option( 'upload_path', get_blog_option( get_current_site()->blog_id, 'upload_path' ) ); |
|
| 1396 | + update_option('upload_path', get_blog_option(get_current_site()->blog_id, 'upload_path')); |
|
| 1397 | 1397 | |
| 1398 | - update_option( 'blogname', wp_unslash( $blog_title ) ); |
|
| 1399 | - update_option( 'admin_email', '' ); |
|
| 1398 | + update_option('blogname', wp_unslash($blog_title)); |
|
| 1399 | + update_option('admin_email', ''); |
|
| 1400 | 1400 | |
| 1401 | 1401 | // remove all perms |
| 1402 | 1402 | $table_prefix = $wpdb->get_blog_prefix(); |
| 1403 | - delete_metadata( 'user', 0, $table_prefix . 'user_level', null, true ); // delete all |
|
| 1404 | - delete_metadata( 'user', 0, $table_prefix . 'capabilities', null, true ); // delete all |
|
| 1403 | + delete_metadata('user', 0, $table_prefix.'user_level', null, true); // delete all |
|
| 1404 | + delete_metadata('user', 0, $table_prefix.'capabilities', null, true); // delete all |
|
| 1405 | 1405 | } |
| 1406 | 1406 | |
| 1407 | 1407 | /** |
@@ -1421,13 +1421,13 @@ discard block |
||
| 1421 | 1421 | function install_blog_defaults($blog_id, $user_id) { |
| 1422 | 1422 | global $wpdb; |
| 1423 | 1423 | |
| 1424 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
| 1424 | + require_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
|
| 1425 | 1425 | |
| 1426 | 1426 | $suppress = $wpdb->suppress_errors(); |
| 1427 | 1427 | |
| 1428 | 1428 | wp_install_defaults($user_id); |
| 1429 | 1429 | |
| 1430 | - $wpdb->suppress_errors( $suppress ); |
|
| 1430 | + $wpdb->suppress_errors($suppress); |
|
| 1431 | 1431 | } |
| 1432 | 1432 | |
| 1433 | 1433 | /** |
@@ -1447,7 +1447,7 @@ discard block |
||
| 1447 | 1447 | * @param array $meta Optional. Not used in the default function, but is passed along to hooks for customization. |
| 1448 | 1448 | * @return bool |
| 1449 | 1449 | */ |
| 1450 | -function wpmu_welcome_notification( $blog_id, $user_id, $password, $title, $meta = array() ) { |
|
| 1450 | +function wpmu_welcome_notification($blog_id, $user_id, $password, $title, $meta = array()) { |
|
| 1451 | 1451 | $current_site = get_current_site(); |
| 1452 | 1452 | |
| 1453 | 1453 | /** |
@@ -1463,13 +1463,13 @@ discard block |
||
| 1463 | 1463 | * @param string $title Site title. |
| 1464 | 1464 | * @param array $meta Signup meta data. |
| 1465 | 1465 | */ |
| 1466 | - if ( ! apply_filters( 'wpmu_welcome_notification', $blog_id, $user_id, $password, $title, $meta ) ) |
|
| 1466 | + if ( ! apply_filters('wpmu_welcome_notification', $blog_id, $user_id, $password, $title, $meta)) |
|
| 1467 | 1467 | return false; |
| 1468 | 1468 | |
| 1469 | - $welcome_email = get_site_option( 'welcome_email' ); |
|
| 1470 | - if ( $welcome_email == false ) { |
|
| 1469 | + $welcome_email = get_site_option('welcome_email'); |
|
| 1470 | + if ($welcome_email == false) { |
|
| 1471 | 1471 | /* translators: Do not translate USERNAME, SITE_NAME, BLOG_URL, PASSWORD: those are placeholders. */ |
| 1472 | - $welcome_email = __( 'Howdy USERNAME, |
|
| 1472 | + $welcome_email = __('Howdy USERNAME, |
|
| 1473 | 1473 | |
| 1474 | 1474 | Your new SITE_NAME site has been successfully set up at: |
| 1475 | 1475 | BLOG_URL |
@@ -1486,13 +1486,13 @@ discard block |
||
| 1486 | 1486 | } |
| 1487 | 1487 | |
| 1488 | 1488 | $url = get_blogaddress_by_id($blog_id); |
| 1489 | - $user = get_userdata( $user_id ); |
|
| 1489 | + $user = get_userdata($user_id); |
|
| 1490 | 1490 | |
| 1491 | - $welcome_email = str_replace( 'SITE_NAME', $current_site->site_name, $welcome_email ); |
|
| 1492 | - $welcome_email = str_replace( 'BLOG_TITLE', $title, $welcome_email ); |
|
| 1493 | - $welcome_email = str_replace( 'BLOG_URL', $url, $welcome_email ); |
|
| 1494 | - $welcome_email = str_replace( 'USERNAME', $user->user_login, $welcome_email ); |
|
| 1495 | - $welcome_email = str_replace( 'PASSWORD', $password, $welcome_email ); |
|
| 1491 | + $welcome_email = str_replace('SITE_NAME', $current_site->site_name, $welcome_email); |
|
| 1492 | + $welcome_email = str_replace('BLOG_TITLE', $title, $welcome_email); |
|
| 1493 | + $welcome_email = str_replace('BLOG_URL', $url, $welcome_email); |
|
| 1494 | + $welcome_email = str_replace('USERNAME', $user->user_login, $welcome_email); |
|
| 1495 | + $welcome_email = str_replace('PASSWORD', $password, $welcome_email); |
|
| 1496 | 1496 | |
| 1497 | 1497 | /** |
| 1498 | 1498 | * Filter the content of the welcome email after site activation. |
@@ -1508,17 +1508,17 @@ discard block |
||
| 1508 | 1508 | * @param string $title Site title. |
| 1509 | 1509 | * @param array $meta Signup meta data. |
| 1510 | 1510 | */ |
| 1511 | - $welcome_email = apply_filters( 'update_welcome_email', $welcome_email, $blog_id, $user_id, $password, $title, $meta ); |
|
| 1512 | - $admin_email = get_site_option( 'admin_email' ); |
|
| 1511 | + $welcome_email = apply_filters('update_welcome_email', $welcome_email, $blog_id, $user_id, $password, $title, $meta); |
|
| 1512 | + $admin_email = get_site_option('admin_email'); |
|
| 1513 | 1513 | |
| 1514 | - if ( $admin_email == '' ) |
|
| 1515 | - $admin_email = 'support@' . $_SERVER['SERVER_NAME']; |
|
| 1514 | + if ($admin_email == '') |
|
| 1515 | + $admin_email = 'support@'.$_SERVER['SERVER_NAME']; |
|
| 1516 | 1516 | |
| 1517 | - $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) ); |
|
| 1518 | - $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; |
|
| 1517 | + $from_name = get_site_option('site_name') == '' ? 'WordPress' : esc_html(get_site_option('site_name')); |
|
| 1518 | + $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n"."Content-Type: text/plain; charset=\"".get_option('blog_charset')."\"\n"; |
|
| 1519 | 1519 | $message = $welcome_email; |
| 1520 | 1520 | |
| 1521 | - if ( empty( $current_site->site_name ) ) |
|
| 1521 | + if (empty($current_site->site_name)) |
|
| 1522 | 1522 | $current_site->site_name = 'WordPress'; |
| 1523 | 1523 | |
| 1524 | 1524 | /** |
@@ -1528,8 +1528,8 @@ discard block |
||
| 1528 | 1528 | * |
| 1529 | 1529 | * @param string $subject Subject of the email. |
| 1530 | 1530 | */ |
| 1531 | - $subject = apply_filters( 'update_welcome_subject', sprintf( __( 'New %1$s Site: %2$s' ), $current_site->site_name, wp_unslash( $title ) ) ); |
|
| 1532 | - wp_mail( $user->user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); |
|
| 1531 | + $subject = apply_filters('update_welcome_subject', sprintf(__('New %1$s Site: %2$s'), $current_site->site_name, wp_unslash($title))); |
|
| 1532 | + wp_mail($user->user_email, wp_specialchars_decode($subject), $message, $message_headers); |
|
| 1533 | 1533 | return true; |
| 1534 | 1534 | } |
| 1535 | 1535 | |
@@ -1548,7 +1548,7 @@ discard block |
||
| 1548 | 1548 | * @param array $meta Optional. Not used in the default function, but is passed along to hooks for customization. |
| 1549 | 1549 | * @return bool |
| 1550 | 1550 | */ |
| 1551 | -function wpmu_welcome_user_notification( $user_id, $password, $meta = array() ) { |
|
| 1551 | +function wpmu_welcome_user_notification($user_id, $password, $meta = array()) { |
|
| 1552 | 1552 | $current_site = get_current_site(); |
| 1553 | 1553 | |
| 1554 | 1554 | /** |
@@ -1562,12 +1562,12 @@ discard block |
||
| 1562 | 1562 | * @param string $password User password. |
| 1563 | 1563 | * @param array $meta Signup meta data. |
| 1564 | 1564 | */ |
| 1565 | - if ( ! apply_filters( 'wpmu_welcome_user_notification', $user_id, $password, $meta ) ) |
|
| 1565 | + if ( ! apply_filters('wpmu_welcome_user_notification', $user_id, $password, $meta)) |
|
| 1566 | 1566 | return false; |
| 1567 | 1567 | |
| 1568 | - $welcome_email = get_site_option( 'welcome_user_email' ); |
|
| 1568 | + $welcome_email = get_site_option('welcome_user_email'); |
|
| 1569 | 1569 | |
| 1570 | - $user = get_userdata( $user_id ); |
|
| 1570 | + $user = get_userdata($user_id); |
|
| 1571 | 1571 | |
| 1572 | 1572 | /** |
| 1573 | 1573 | * Filter the content of the welcome email after user activation. |
@@ -1581,22 +1581,22 @@ discard block |
||
| 1581 | 1581 | * @param string $password User password. |
| 1582 | 1582 | * @param array $meta Signup meta data. |
| 1583 | 1583 | */ |
| 1584 | - $welcome_email = apply_filters( 'update_welcome_user_email', $welcome_email, $user_id, $password, $meta ); |
|
| 1585 | - $welcome_email = str_replace( 'SITE_NAME', $current_site->site_name, $welcome_email ); |
|
| 1586 | - $welcome_email = str_replace( 'USERNAME', $user->user_login, $welcome_email ); |
|
| 1587 | - $welcome_email = str_replace( 'PASSWORD', $password, $welcome_email ); |
|
| 1588 | - $welcome_email = str_replace( 'LOGINLINK', wp_login_url(), $welcome_email ); |
|
| 1584 | + $welcome_email = apply_filters('update_welcome_user_email', $welcome_email, $user_id, $password, $meta); |
|
| 1585 | + $welcome_email = str_replace('SITE_NAME', $current_site->site_name, $welcome_email); |
|
| 1586 | + $welcome_email = str_replace('USERNAME', $user->user_login, $welcome_email); |
|
| 1587 | + $welcome_email = str_replace('PASSWORD', $password, $welcome_email); |
|
| 1588 | + $welcome_email = str_replace('LOGINLINK', wp_login_url(), $welcome_email); |
|
| 1589 | 1589 | |
| 1590 | - $admin_email = get_site_option( 'admin_email' ); |
|
| 1590 | + $admin_email = get_site_option('admin_email'); |
|
| 1591 | 1591 | |
| 1592 | - if ( $admin_email == '' ) |
|
| 1593 | - $admin_email = 'support@' . $_SERVER['SERVER_NAME']; |
|
| 1592 | + if ($admin_email == '') |
|
| 1593 | + $admin_email = 'support@'.$_SERVER['SERVER_NAME']; |
|
| 1594 | 1594 | |
| 1595 | - $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) ); |
|
| 1596 | - $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; |
|
| 1595 | + $from_name = get_site_option('site_name') == '' ? 'WordPress' : esc_html(get_site_option('site_name')); |
|
| 1596 | + $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n"."Content-Type: text/plain; charset=\"".get_option('blog_charset')."\"\n"; |
|
| 1597 | 1597 | $message = $welcome_email; |
| 1598 | 1598 | |
| 1599 | - if ( empty( $current_site->site_name ) ) |
|
| 1599 | + if (empty($current_site->site_name)) |
|
| 1600 | 1600 | $current_site->site_name = 'WordPress'; |
| 1601 | 1601 | |
| 1602 | 1602 | /** |
@@ -1606,8 +1606,8 @@ discard block |
||
| 1606 | 1606 | * |
| 1607 | 1607 | * @param string $subject Subject of the email. |
| 1608 | 1608 | */ |
| 1609 | - $subject = apply_filters( 'update_welcome_user_subject', sprintf( __( 'New %1$s User: %2$s' ), $current_site->site_name, $user->user_login) ); |
|
| 1610 | - wp_mail( $user->user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); |
|
| 1609 | + $subject = apply_filters('update_welcome_user_subject', sprintf(__('New %1$s User: %2$s'), $current_site->site_name, $user->user_login)); |
|
| 1610 | + wp_mail($user->user_email, wp_specialchars_decode($subject), $message, $message_headers); |
|
| 1611 | 1611 | return true; |
| 1612 | 1612 | } |
| 1613 | 1613 | |
@@ -1643,26 +1643,26 @@ discard block |
||
| 1643 | 1643 | * @param int $user_id |
| 1644 | 1644 | * @return array Contains the blog_id, post_id, post_date_gmt, and post_gmt_ts |
| 1645 | 1645 | */ |
| 1646 | -function get_most_recent_post_of_user( $user_id ) { |
|
| 1646 | +function get_most_recent_post_of_user($user_id) { |
|
| 1647 | 1647 | global $wpdb; |
| 1648 | 1648 | |
| 1649 | - $user_blogs = get_blogs_of_user( (int) $user_id ); |
|
| 1649 | + $user_blogs = get_blogs_of_user((int) $user_id); |
|
| 1650 | 1650 | $most_recent_post = array(); |
| 1651 | 1651 | |
| 1652 | 1652 | // Walk through each blog and get the most recent post |
| 1653 | 1653 | // published by $user_id |
| 1654 | - foreach ( (array) $user_blogs as $blog ) { |
|
| 1655 | - $prefix = $wpdb->get_blog_prefix( $blog->userblog_id ); |
|
| 1656 | - $recent_post = $wpdb->get_row( $wpdb->prepare("SELECT ID, post_date_gmt FROM {$prefix}posts WHERE post_author = %d AND post_type = 'post' AND post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1", $user_id ), ARRAY_A); |
|
| 1654 | + foreach ((array) $user_blogs as $blog) { |
|
| 1655 | + $prefix = $wpdb->get_blog_prefix($blog->userblog_id); |
|
| 1656 | + $recent_post = $wpdb->get_row($wpdb->prepare("SELECT ID, post_date_gmt FROM {$prefix}posts WHERE post_author = %d AND post_type = 'post' AND post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1", $user_id), ARRAY_A); |
|
| 1657 | 1657 | |
| 1658 | 1658 | // Make sure we found a post |
| 1659 | - if ( isset($recent_post['ID']) ) { |
|
| 1659 | + if (isset($recent_post['ID'])) { |
|
| 1660 | 1660 | $post_gmt_ts = strtotime($recent_post['post_date_gmt']); |
| 1661 | 1661 | |
| 1662 | 1662 | // If this is the first post checked or if this post is |
| 1663 | 1663 | // newer than the current recent post, make it the new |
| 1664 | 1664 | // most recent post. |
| 1665 | - if ( !isset($most_recent_post['post_gmt_ts']) || ( $post_gmt_ts > $most_recent_post['post_gmt_ts'] ) ) { |
|
| 1665 | + if ( ! isset($most_recent_post['post_gmt_ts']) || ($post_gmt_ts > $most_recent_post['post_gmt_ts'])) { |
|
| 1666 | 1666 | $most_recent_post = array( |
| 1667 | 1667 | 'blog_id' => $blog->userblog_id, |
| 1668 | 1668 | 'post_id' => $recent_post['ID'], |
@@ -1689,24 +1689,24 @@ discard block |
||
| 1689 | 1689 | * @param string $directory Full path of a directory. |
| 1690 | 1690 | * @return int Size of the directory in MB. |
| 1691 | 1691 | */ |
| 1692 | -function get_dirsize( $directory ) { |
|
| 1693 | - $dirsize = get_transient( 'dirsize_cache' ); |
|
| 1694 | - if ( is_array( $dirsize ) && isset( $dirsize[ $directory ][ 'size' ] ) ) |
|
| 1695 | - return $dirsize[ $directory ][ 'size' ]; |
|
| 1692 | +function get_dirsize($directory) { |
|
| 1693 | + $dirsize = get_transient('dirsize_cache'); |
|
| 1694 | + if (is_array($dirsize) && isset($dirsize[$directory]['size'])) |
|
| 1695 | + return $dirsize[$directory]['size']; |
|
| 1696 | 1696 | |
| 1697 | - if ( ! is_array( $dirsize ) ) |
|
| 1697 | + if ( ! is_array($dirsize)) |
|
| 1698 | 1698 | $dirsize = array(); |
| 1699 | 1699 | |
| 1700 | 1700 | // Exclude individual site directories from the total when checking the main site, |
| 1701 | 1701 | // as they are subdirectories and should not be counted. |
| 1702 | - if ( is_main_site() ) { |
|
| 1703 | - $dirsize[ $directory ][ 'size' ] = recurse_dirsize( $directory, $directory . '/sites' ); |
|
| 1702 | + if (is_main_site()) { |
|
| 1703 | + $dirsize[$directory]['size'] = recurse_dirsize($directory, $directory.'/sites'); |
|
| 1704 | 1704 | } else { |
| 1705 | - $dirsize[ $directory ][ 'size' ] = recurse_dirsize( $directory ); |
|
| 1705 | + $dirsize[$directory]['size'] = recurse_dirsize($directory); |
|
| 1706 | 1706 | } |
| 1707 | 1707 | |
| 1708 | - set_transient( 'dirsize_cache', $dirsize, HOUR_IN_SECONDS ); |
|
| 1709 | - return $dirsize[ $directory ][ 'size' ]; |
|
| 1708 | + set_transient('dirsize_cache', $dirsize, HOUR_IN_SECONDS); |
|
| 1709 | + return $dirsize[$directory]['size']; |
|
| 1710 | 1710 | } |
| 1711 | 1711 | |
| 1712 | 1712 | /** |
@@ -1722,23 +1722,23 @@ discard block |
||
| 1722 | 1722 | * @param string $exclude Optional. Full path of a subdirectory to exclude from the total. |
| 1723 | 1723 | * @return int|false Size in MB if a valid directory. False if not. |
| 1724 | 1724 | */ |
| 1725 | -function recurse_dirsize( $directory, $exclude = null ) { |
|
| 1725 | +function recurse_dirsize($directory, $exclude = null) { |
|
| 1726 | 1726 | $size = 0; |
| 1727 | 1727 | |
| 1728 | - $directory = untrailingslashit( $directory ); |
|
| 1728 | + $directory = untrailingslashit($directory); |
|
| 1729 | 1729 | |
| 1730 | - if ( ! file_exists( $directory ) || ! is_dir( $directory ) || ! is_readable( $directory ) || $directory === $exclude ) { |
|
| 1730 | + if ( ! file_exists($directory) || ! is_dir($directory) || ! is_readable($directory) || $directory === $exclude) { |
|
| 1731 | 1731 | return false; |
| 1732 | 1732 | } |
| 1733 | 1733 | |
| 1734 | 1734 | if ($handle = opendir($directory)) { |
| 1735 | - while(($file = readdir($handle)) !== false) { |
|
| 1735 | + while (($file = readdir($handle)) !== false) { |
|
| 1736 | 1736 | $path = $directory.'/'.$file; |
| 1737 | 1737 | if ($file != '.' && $file != '..') { |
| 1738 | 1738 | if (is_file($path)) { |
| 1739 | 1739 | $size += filesize($path); |
| 1740 | 1740 | } elseif (is_dir($path)) { |
| 1741 | - $handlesize = recurse_dirsize( $path, $exclude ); |
|
| 1741 | + $handlesize = recurse_dirsize($path, $exclude); |
|
| 1742 | 1742 | if ($handlesize > 0) |
| 1743 | 1743 | $size += $handlesize; |
| 1744 | 1744 | } |
@@ -1763,12 +1763,12 @@ discard block |
||
| 1763 | 1763 | * @param array $mimes |
| 1764 | 1764 | * @return array |
| 1765 | 1765 | */ |
| 1766 | -function check_upload_mimes( $mimes ) { |
|
| 1767 | - $site_exts = explode( ' ', get_site_option( 'upload_filetypes', 'jpg jpeg png gif' ) ); |
|
| 1766 | +function check_upload_mimes($mimes) { |
|
| 1767 | + $site_exts = explode(' ', get_site_option('upload_filetypes', 'jpg jpeg png gif')); |
|
| 1768 | 1768 | $site_mimes = array(); |
| 1769 | - foreach ( $site_exts as $ext ) { |
|
| 1770 | - foreach ( $mimes as $ext_pattern => $mime ) { |
|
| 1771 | - if ( $ext != '' && strpos( $ext_pattern, $ext ) !== false ) |
|
| 1769 | + foreach ($site_exts as $ext) { |
|
| 1770 | + foreach ($mimes as $ext_pattern => $mime) { |
|
| 1771 | + if ($ext != '' && strpos($ext_pattern, $ext) !== false) |
|
| 1772 | 1772 | $site_mimes[$ext_pattern] = $mime; |
| 1773 | 1773 | } |
| 1774 | 1774 | } |
@@ -1787,9 +1787,9 @@ discard block |
||
| 1787 | 1787 | * |
| 1788 | 1788 | * @global wpdb $wpdb |
| 1789 | 1789 | */ |
| 1790 | -function update_posts_count( $deprecated = '' ) { |
|
| 1790 | +function update_posts_count($deprecated = '') { |
|
| 1791 | 1791 | global $wpdb; |
| 1792 | - update_option( 'post_count', (int) $wpdb->get_var( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_status = 'publish' and post_type = 'post'" ) ); |
|
| 1792 | + update_option('post_count', (int) $wpdb->get_var("SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_status = 'publish' and post_type = 'post'")); |
|
| 1793 | 1793 | } |
| 1794 | 1794 | |
| 1795 | 1795 | /** |
@@ -1802,11 +1802,11 @@ discard block |
||
| 1802 | 1802 | * @param int $blog_id |
| 1803 | 1803 | * @param int $user_id |
| 1804 | 1804 | */ |
| 1805 | -function wpmu_log_new_registrations( $blog_id, $user_id ) { |
|
| 1805 | +function wpmu_log_new_registrations($blog_id, $user_id) { |
|
| 1806 | 1806 | global $wpdb; |
| 1807 | - $user = get_userdata( (int) $user_id ); |
|
| 1808 | - if ( $user ) |
|
| 1809 | - $wpdb->insert( $wpdb->registration_log, array('email' => $user->user_email, 'IP' => preg_replace( '/[^0-9., ]/', '', wp_unslash( $_SERVER['REMOTE_ADDR'] ) ), 'blog_id' => $blog_id, 'date_registered' => current_time('mysql')) ); |
|
| 1807 | + $user = get_userdata((int) $user_id); |
|
| 1808 | + if ($user) |
|
| 1809 | + $wpdb->insert($wpdb->registration_log, array('email' => $user->user_email, 'IP' => preg_replace('/[^0-9., ]/', '', wp_unslash($_SERVER['REMOTE_ADDR'])), 'blog_id' => $blog_id, 'date_registered' => current_time('mysql'))); |
|
| 1810 | 1810 | } |
| 1811 | 1811 | |
| 1812 | 1812 | /** |
@@ -1822,61 +1822,61 @@ discard block |
||
| 1822 | 1822 | * @param int $term_id An ID for a term on the current blog. |
| 1823 | 1823 | * @return int An ID from the global terms table mapped from $term_id. |
| 1824 | 1824 | */ |
| 1825 | -function global_terms( $term_id, $deprecated = '' ) { |
|
| 1825 | +function global_terms($term_id, $deprecated = '') { |
|
| 1826 | 1826 | global $wpdb; |
| 1827 | 1827 | static $global_terms_recurse = null; |
| 1828 | 1828 | |
| 1829 | - if ( !global_terms_enabled() ) |
|
| 1829 | + if ( ! global_terms_enabled()) |
|
| 1830 | 1830 | return $term_id; |
| 1831 | 1831 | |
| 1832 | 1832 | // prevent a race condition |
| 1833 | 1833 | $recurse_start = false; |
| 1834 | - if ( $global_terms_recurse === null ) { |
|
| 1834 | + if ($global_terms_recurse === null) { |
|
| 1835 | 1835 | $recurse_start = true; |
| 1836 | 1836 | $global_terms_recurse = 1; |
| 1837 | - } elseif ( 10 < $global_terms_recurse++ ) { |
|
| 1837 | + } elseif (10 < $global_terms_recurse++) { |
|
| 1838 | 1838 | return $term_id; |
| 1839 | 1839 | } |
| 1840 | 1840 | |
| 1841 | - $term_id = intval( $term_id ); |
|
| 1842 | - $c = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->terms WHERE term_id = %d", $term_id ) ); |
|
| 1841 | + $term_id = intval($term_id); |
|
| 1842 | + $c = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->terms WHERE term_id = %d", $term_id)); |
|
| 1843 | 1843 | |
| 1844 | - $global_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM $wpdb->sitecategories WHERE category_nicename = %s", $c->slug ) ); |
|
| 1845 | - if ( $global_id == null ) { |
|
| 1846 | - $used_global_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM $wpdb->sitecategories WHERE cat_ID = %d", $c->term_id ) ); |
|
| 1847 | - if ( null == $used_global_id ) { |
|
| 1848 | - $wpdb->insert( $wpdb->sitecategories, array( 'cat_ID' => $term_id, 'cat_name' => $c->name, 'category_nicename' => $c->slug ) ); |
|
| 1844 | + $global_id = $wpdb->get_var($wpdb->prepare("SELECT cat_ID FROM $wpdb->sitecategories WHERE category_nicename = %s", $c->slug)); |
|
| 1845 | + if ($global_id == null) { |
|
| 1846 | + $used_global_id = $wpdb->get_var($wpdb->prepare("SELECT cat_ID FROM $wpdb->sitecategories WHERE cat_ID = %d", $c->term_id)); |
|
| 1847 | + if (null == $used_global_id) { |
|
| 1848 | + $wpdb->insert($wpdb->sitecategories, array('cat_ID' => $term_id, 'cat_name' => $c->name, 'category_nicename' => $c->slug)); |
|
| 1849 | 1849 | $global_id = $wpdb->insert_id; |
| 1850 | - if ( empty( $global_id ) ) |
|
| 1850 | + if (empty($global_id)) |
|
| 1851 | 1851 | return $term_id; |
| 1852 | 1852 | } else { |
| 1853 | - $max_global_id = $wpdb->get_var( "SELECT MAX(cat_ID) FROM $wpdb->sitecategories" ); |
|
| 1854 | - $max_local_id = $wpdb->get_var( "SELECT MAX(term_id) FROM $wpdb->terms" ); |
|
| 1855 | - $new_global_id = max( $max_global_id, $max_local_id ) + mt_rand( 100, 400 ); |
|
| 1856 | - $wpdb->insert( $wpdb->sitecategories, array( 'cat_ID' => $new_global_id, 'cat_name' => $c->name, 'category_nicename' => $c->slug ) ); |
|
| 1853 | + $max_global_id = $wpdb->get_var("SELECT MAX(cat_ID) FROM $wpdb->sitecategories"); |
|
| 1854 | + $max_local_id = $wpdb->get_var("SELECT MAX(term_id) FROM $wpdb->terms"); |
|
| 1855 | + $new_global_id = max($max_global_id, $max_local_id) + mt_rand(100, 400); |
|
| 1856 | + $wpdb->insert($wpdb->sitecategories, array('cat_ID' => $new_global_id, 'cat_name' => $c->name, 'category_nicename' => $c->slug)); |
|
| 1857 | 1857 | $global_id = $wpdb->insert_id; |
| 1858 | 1858 | } |
| 1859 | - } elseif ( $global_id != $term_id ) { |
|
| 1860 | - $local_id = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms WHERE term_id = %d", $global_id ) ); |
|
| 1861 | - if ( null != $local_id ) { |
|
| 1862 | - global_terms( $local_id ); |
|
| 1863 | - if ( 10 < $global_terms_recurse ) { |
|
| 1859 | + } elseif ($global_id != $term_id) { |
|
| 1860 | + $local_id = $wpdb->get_var($wpdb->prepare("SELECT term_id FROM $wpdb->terms WHERE term_id = %d", $global_id)); |
|
| 1861 | + if (null != $local_id) { |
|
| 1862 | + global_terms($local_id); |
|
| 1863 | + if (10 < $global_terms_recurse) { |
|
| 1864 | 1864 | $global_id = $term_id; |
| 1865 | 1865 | } |
| 1866 | 1866 | } |
| 1867 | 1867 | } |
| 1868 | 1868 | |
| 1869 | - if ( $global_id != $term_id ) { |
|
| 1870 | - if ( get_option( 'default_category' ) == $term_id ) |
|
| 1871 | - update_option( 'default_category', $global_id ); |
|
| 1869 | + if ($global_id != $term_id) { |
|
| 1870 | + if (get_option('default_category') == $term_id) |
|
| 1871 | + update_option('default_category', $global_id); |
|
| 1872 | 1872 | |
| 1873 | - $wpdb->update( $wpdb->terms, array('term_id' => $global_id), array('term_id' => $term_id) ); |
|
| 1874 | - $wpdb->update( $wpdb->term_taxonomy, array('term_id' => $global_id), array('term_id' => $term_id) ); |
|
| 1875 | - $wpdb->update( $wpdb->term_taxonomy, array('parent' => $global_id), array('parent' => $term_id) ); |
|
| 1873 | + $wpdb->update($wpdb->terms, array('term_id' => $global_id), array('term_id' => $term_id)); |
|
| 1874 | + $wpdb->update($wpdb->term_taxonomy, array('term_id' => $global_id), array('term_id' => $term_id)); |
|
| 1875 | + $wpdb->update($wpdb->term_taxonomy, array('parent' => $global_id), array('parent' => $term_id)); |
|
| 1876 | 1876 | |
| 1877 | 1877 | clean_term_cache($term_id); |
| 1878 | 1878 | } |
| 1879 | - if ( $recurse_start ) |
|
| 1879 | + if ($recurse_start) |
|
| 1880 | 1880 | $global_terms_recurse = null; |
| 1881 | 1881 | |
| 1882 | 1882 | return $global_id; |
@@ -1890,8 +1890,8 @@ discard block |
||
| 1890 | 1890 | * |
| 1891 | 1891 | * @return array The current site's domain |
| 1892 | 1892 | */ |
| 1893 | -function redirect_this_site( $deprecated = '' ) { |
|
| 1894 | - return array( get_current_site()->domain ); |
|
| 1893 | +function redirect_this_site($deprecated = '') { |
|
| 1894 | + return array(get_current_site()->domain); |
|
| 1895 | 1895 | } |
| 1896 | 1896 | |
| 1897 | 1897 | /** |
@@ -1902,12 +1902,12 @@ discard block |
||
| 1902 | 1902 | * @param array $upload |
| 1903 | 1903 | * @return string|array If the upload is under the size limit, $upload is returned. Otherwise returns an error message. |
| 1904 | 1904 | */ |
| 1905 | -function upload_is_file_too_big( $upload ) { |
|
| 1906 | - if ( ! is_array( $upload ) || defined( 'WP_IMPORTING' ) || get_site_option( 'upload_space_check_disabled' ) ) |
|
| 1905 | +function upload_is_file_too_big($upload) { |
|
| 1906 | + if ( ! is_array($upload) || defined('WP_IMPORTING') || get_site_option('upload_space_check_disabled')) |
|
| 1907 | 1907 | return $upload; |
| 1908 | 1908 | |
| 1909 | - if ( strlen( $upload['bits'] ) > ( 1024 * get_site_option( 'fileupload_maxk', 1500 ) ) ) |
|
| 1910 | - return sprintf( __( 'This file is too big. Files must be less than %d KB in size.' ) . '<br />', get_site_option( 'fileupload_maxk', 1500 )); |
|
| 1909 | + if (strlen($upload['bits']) > (1024 * get_site_option('fileupload_maxk', 1500))) |
|
| 1910 | + return sprintf(__('This file is too big. Files must be less than %d KB in size.').'<br />', get_site_option('fileupload_maxk', 1500)); |
|
| 1911 | 1911 | |
| 1912 | 1912 | return $upload; |
| 1913 | 1913 | } |
@@ -1920,7 +1920,7 @@ discard block |
||
| 1920 | 1920 | function signup_nonce_fields() { |
| 1921 | 1921 | $id = mt_rand(); |
| 1922 | 1922 | echo "<input type='hidden' name='signup_form_id' value='{$id}' />"; |
| 1923 | - wp_nonce_field('signup_form_' . $id, '_signup_form', false); |
|
| 1923 | + wp_nonce_field('signup_form_'.$id, '_signup_form', false); |
|
| 1924 | 1924 | } |
| 1925 | 1925 | |
| 1926 | 1926 | /** |
@@ -1931,12 +1931,12 @@ discard block |
||
| 1931 | 1931 | * @param array $result |
| 1932 | 1932 | * @return array |
| 1933 | 1933 | */ |
| 1934 | -function signup_nonce_check( $result ) { |
|
| 1935 | - if ( !strpos( $_SERVER[ 'PHP_SELF' ], 'wp-signup.php' ) ) |
|
| 1934 | +function signup_nonce_check($result) { |
|
| 1935 | + if ( ! strpos($_SERVER['PHP_SELF'], 'wp-signup.php')) |
|
| 1936 | 1936 | return $result; |
| 1937 | 1937 | |
| 1938 | - if ( wp_create_nonce('signup_form_' . $_POST[ 'signup_form_id' ]) != $_POST['_signup_form'] ) |
|
| 1939 | - wp_die( __( 'Please try again.' ) ); |
|
| 1938 | + if (wp_create_nonce('signup_form_'.$_POST['signup_form_id']) != $_POST['_signup_form']) |
|
| 1939 | + wp_die(__('Please try again.')); |
|
| 1940 | 1940 | |
| 1941 | 1941 | return $result; |
| 1942 | 1942 | } |
@@ -1956,10 +1956,10 @@ discard block |
||
| 1956 | 1956 | * |
| 1957 | 1957 | * @param string $no_blog_redirect The redirect URL defined in NOBLOGREDIRECT. |
| 1958 | 1958 | */ |
| 1959 | - if ( is_main_site() && is_404() && defined( 'NOBLOGREDIRECT' ) && ( $destination = apply_filters( 'blog_redirect_404', NOBLOGREDIRECT ) ) ) { |
|
| 1960 | - if ( $destination == '%siteurl%' ) |
|
| 1959 | + if (is_main_site() && is_404() && defined('NOBLOGREDIRECT') && ($destination = apply_filters('blog_redirect_404', NOBLOGREDIRECT))) { |
|
| 1960 | + if ($destination == '%siteurl%') |
|
| 1961 | 1961 | $destination = network_home_url(); |
| 1962 | - wp_redirect( $destination ); |
|
| 1962 | + wp_redirect($destination); |
|
| 1963 | 1963 | exit(); |
| 1964 | 1964 | } |
| 1965 | 1965 | } |
@@ -1974,23 +1974,23 @@ discard block |
||
| 1974 | 1974 | * @since MU |
| 1975 | 1975 | */ |
| 1976 | 1976 | function maybe_add_existing_user_to_blog() { |
| 1977 | - if ( false === strpos( $_SERVER[ 'REQUEST_URI' ], '/newbloguser/' ) ) |
|
| 1977 | + if (false === strpos($_SERVER['REQUEST_URI'], '/newbloguser/')) |
|
| 1978 | 1978 | return; |
| 1979 | 1979 | |
| 1980 | - $parts = explode( '/', $_SERVER[ 'REQUEST_URI' ] ); |
|
| 1981 | - $key = array_pop( $parts ); |
|
| 1980 | + $parts = explode('/', $_SERVER['REQUEST_URI']); |
|
| 1981 | + $key = array_pop($parts); |
|
| 1982 | 1982 | |
| 1983 | - if ( $key == '' ) |
|
| 1984 | - $key = array_pop( $parts ); |
|
| 1983 | + if ($key == '') |
|
| 1984 | + $key = array_pop($parts); |
|
| 1985 | 1985 | |
| 1986 | - $details = get_option( 'new_user_' . $key ); |
|
| 1987 | - if ( !empty( $details ) ) |
|
| 1988 | - delete_option( 'new_user_' . $key ); |
|
| 1986 | + $details = get_option('new_user_'.$key); |
|
| 1987 | + if ( ! empty($details)) |
|
| 1988 | + delete_option('new_user_'.$key); |
|
| 1989 | 1989 | |
| 1990 | - if ( empty( $details ) || is_wp_error( add_existing_user_to_blog( $details ) ) ) |
|
| 1991 | - wp_die( sprintf(__('An error occurred adding you to this site. Back to the <a href="%s">homepage</a>.'), home_url() ) ); |
|
| 1990 | + if (empty($details) || is_wp_error(add_existing_user_to_blog($details))) |
|
| 1991 | + wp_die(sprintf(__('An error occurred adding you to this site. Back to the <a href="%s">homepage</a>.'), home_url())); |
|
| 1992 | 1992 | |
| 1993 | - wp_die( sprintf( __( 'You have been added to this site. Please visit the <a href="%s">homepage</a> or <a href="%s">log in</a> using your username and password.' ), home_url(), admin_url() ), __( 'WordPress › Success' ), array( 'response' => 200 ) ); |
|
| 1993 | + wp_die(sprintf(__('You have been added to this site. Please visit the <a href="%s">homepage</a> or <a href="%s">log in</a> using your username and password.'), home_url(), admin_url()), __('WordPress › Success'), array('response' => 200)); |
|
| 1994 | 1994 | } |
| 1995 | 1995 | |
| 1996 | 1996 | /** |
@@ -2003,11 +2003,11 @@ discard block |
||
| 2003 | 2003 | * @param array $details |
| 2004 | 2004 | * @return true|WP_Error|void |
| 2005 | 2005 | */ |
| 2006 | -function add_existing_user_to_blog( $details = false ) { |
|
| 2006 | +function add_existing_user_to_blog($details = false) { |
|
| 2007 | 2007 | global $blog_id; |
| 2008 | 2008 | |
| 2009 | - if ( is_array( $details ) ) { |
|
| 2010 | - $result = add_user_to_blog( $blog_id, $details[ 'user_id' ], $details[ 'role' ] ); |
|
| 2009 | + if (is_array($details)) { |
|
| 2010 | + $result = add_user_to_blog($blog_id, $details['user_id'], $details['role']); |
|
| 2011 | 2011 | /** |
| 2012 | 2012 | * Fires immediately after an existing user is added to a site. |
| 2013 | 2013 | * |
@@ -2016,7 +2016,7 @@ discard block |
||
| 2016 | 2016 | * @param int $user_id User ID. |
| 2017 | 2017 | * @param mixed $result True on success or a WP_Error object if the user doesn't exist. |
| 2018 | 2018 | */ |
| 2019 | - do_action( 'added_existing_user', $details['user_id'], $result ); |
|
| 2019 | + do_action('added_existing_user', $details['user_id'], $result); |
|
| 2020 | 2020 | return $result; |
| 2021 | 2021 | } |
| 2022 | 2022 | } |
@@ -2034,13 +2034,13 @@ discard block |
||
| 2034 | 2034 | * @param mixed $password Ignored. |
| 2035 | 2035 | * @param array $meta |
| 2036 | 2036 | */ |
| 2037 | -function add_new_user_to_blog( $user_id, $password, $meta ) { |
|
| 2038 | - if ( !empty( $meta[ 'add_to_blog' ] ) ) { |
|
| 2039 | - $blog_id = $meta[ 'add_to_blog' ]; |
|
| 2040 | - $role = $meta[ 'new_role' ]; |
|
| 2037 | +function add_new_user_to_blog($user_id, $password, $meta) { |
|
| 2038 | + if ( ! empty($meta['add_to_blog'])) { |
|
| 2039 | + $blog_id = $meta['add_to_blog']; |
|
| 2040 | + $role = $meta['new_role']; |
|
| 2041 | 2041 | remove_user_from_blog($user_id, get_current_site()->blog_id); // remove user from main blog. |
| 2042 | - add_user_to_blog( $blog_id, $user_id, $role ); |
|
| 2043 | - update_user_meta( $user_id, 'primary_blog', $blog_id ); |
|
| 2042 | + add_user_to_blog($blog_id, $user_id, $role); |
|
| 2043 | + update_user_meta($user_id, 'primary_blog', $blog_id); |
|
| 2044 | 2044 | } |
| 2045 | 2045 | } |
| 2046 | 2046 | |
@@ -2049,7 +2049,7 @@ discard block |
||
| 2049 | 2049 | * |
| 2050 | 2050 | * @since MU |
| 2051 | 2051 | */ |
| 2052 | -function fix_phpmailer_messageid( $phpmailer ) { |
|
| 2052 | +function fix_phpmailer_messageid($phpmailer) { |
|
| 2053 | 2053 | $phpmailer->Hostname = get_current_site()->domain; |
| 2054 | 2054 | } |
| 2055 | 2055 | |
@@ -2062,16 +2062,16 @@ discard block |
||
| 2062 | 2062 | * or user login name as a string. |
| 2063 | 2063 | * @return bool |
| 2064 | 2064 | */ |
| 2065 | -function is_user_spammy( $user = null ) { |
|
| 2066 | - if ( ! ( $user instanceof WP_User ) ) { |
|
| 2067 | - if ( $user ) { |
|
| 2068 | - $user = get_user_by( 'login', $user ); |
|
| 2065 | +function is_user_spammy($user = null) { |
|
| 2066 | + if ( ! ($user instanceof WP_User)) { |
|
| 2067 | + if ($user) { |
|
| 2068 | + $user = get_user_by('login', $user); |
|
| 2069 | 2069 | } else { |
| 2070 | 2070 | $user = wp_get_current_user(); |
| 2071 | 2071 | } |
| 2072 | 2072 | } |
| 2073 | 2073 | |
| 2074 | - return $user && isset( $user->spam ) && 1 == $user->spam; |
|
| 2074 | + return $user && isset($user->spam) && 1 == $user->spam; |
|
| 2075 | 2075 | } |
| 2076 | 2076 | |
| 2077 | 2077 | /** |
@@ -2084,8 +2084,8 @@ discard block |
||
| 2084 | 2084 | * @param int $old_value |
| 2085 | 2085 | * @param int $value The new public value |
| 2086 | 2086 | */ |
| 2087 | -function update_blog_public( $old_value, $value ) { |
|
| 2088 | - update_blog_status( get_current_blog_id(), 'public', (int) $value ); |
|
| 2087 | +function update_blog_public($old_value, $value) { |
|
| 2088 | + update_blog_status(get_current_blog_id(), 'public', (int) $value); |
|
| 2089 | 2089 | } |
| 2090 | 2090 | |
| 2091 | 2091 | /** |
@@ -2100,16 +2100,16 @@ discard block |
||
| 2100 | 2100 | * @param int $blog_id Optional. Defaults to current blog. |
| 2101 | 2101 | * @return bool |
| 2102 | 2102 | */ |
| 2103 | -function is_user_option_local( $key, $user_id = 0, $blog_id = 0 ) { |
|
| 2103 | +function is_user_option_local($key, $user_id = 0, $blog_id = 0) { |
|
| 2104 | 2104 | global $wpdb; |
| 2105 | 2105 | |
| 2106 | 2106 | $current_user = wp_get_current_user(); |
| 2107 | - if ( $blog_id == 0 ) { |
|
| 2107 | + if ($blog_id == 0) { |
|
| 2108 | 2108 | $blog_id = $wpdb->blogid; |
| 2109 | 2109 | } |
| 2110 | - $local_key = $wpdb->get_blog_prefix( $blog_id ) . $key; |
|
| 2110 | + $local_key = $wpdb->get_blog_prefix($blog_id).$key; |
|
| 2111 | 2111 | |
| 2112 | - return isset( $current_user->$local_key ); |
|
| 2112 | + return isset($current_user->$local_key); |
|
| 2113 | 2113 | } |
| 2114 | 2114 | |
| 2115 | 2115 | /** |
@@ -2121,7 +2121,7 @@ discard block |
||
| 2121 | 2121 | */ |
| 2122 | 2122 | function users_can_register_signup_filter() { |
| 2123 | 2123 | $registration = get_site_option('registration'); |
| 2124 | - return ( $registration == 'all' || $registration == 'user' ); |
|
| 2124 | + return ($registration == 'all' || $registration == 'user'); |
|
| 2125 | 2125 | } |
| 2126 | 2126 | |
| 2127 | 2127 | /** |
@@ -2132,12 +2132,12 @@ discard block |
||
| 2132 | 2132 | * @param string $text |
| 2133 | 2133 | * @return string |
| 2134 | 2134 | */ |
| 2135 | -function welcome_user_msg_filter( $text ) { |
|
| 2136 | - if ( !$text ) { |
|
| 2137 | - remove_filter( 'site_option_welcome_user_email', 'welcome_user_msg_filter' ); |
|
| 2135 | +function welcome_user_msg_filter($text) { |
|
| 2136 | + if ( ! $text) { |
|
| 2137 | + remove_filter('site_option_welcome_user_email', 'welcome_user_msg_filter'); |
|
| 2138 | 2138 | |
| 2139 | 2139 | /* translators: Do not translate USERNAME, PASSWORD, LOGINLINK, SITE_NAME: those are placeholders. */ |
| 2140 | - $text = __( 'Howdy USERNAME, |
|
| 2140 | + $text = __('Howdy USERNAME, |
|
| 2141 | 2141 | |
| 2142 | 2142 | Your new account is set up. |
| 2143 | 2143 | |
@@ -2149,7 +2149,7 @@ discard block |
||
| 2149 | 2149 | Thanks! |
| 2150 | 2150 | |
| 2151 | 2151 | --The Team @ SITE_NAME' ); |
| 2152 | - update_site_option( 'welcome_user_email', $text ); |
|
| 2152 | + update_site_option('welcome_user_email', $text); |
|
| 2153 | 2153 | } |
| 2154 | 2154 | return $text; |
| 2155 | 2155 | } |
@@ -2164,10 +2164,10 @@ discard block |
||
| 2164 | 2164 | * @param bool $force |
| 2165 | 2165 | * @return bool True if forced, false if not forced. |
| 2166 | 2166 | */ |
| 2167 | -function force_ssl_content( $force = '' ) { |
|
| 2167 | +function force_ssl_content($force = '') { |
|
| 2168 | 2168 | static $forced_content = false; |
| 2169 | 2169 | |
| 2170 | - if ( '' != $force ) { |
|
| 2170 | + if ('' != $force) { |
|
| 2171 | 2171 | $old_forced = $forced_content; |
| 2172 | 2172 | $forced_content = $force; |
| 2173 | 2173 | return $old_forced; |
@@ -2186,12 +2186,12 @@ discard block |
||
| 2186 | 2186 | * @param string URL |
| 2187 | 2187 | * @return string URL with https as the scheme |
| 2188 | 2188 | */ |
| 2189 | -function filter_SSL( $url ) { |
|
| 2190 | - if ( ! is_string( $url ) ) |
|
| 2191 | - return get_bloginfo( 'url' ); // Return home blog url with proper scheme |
|
| 2189 | +function filter_SSL($url) { |
|
| 2190 | + if ( ! is_string($url)) |
|
| 2191 | + return get_bloginfo('url'); // Return home blog url with proper scheme |
|
| 2192 | 2192 | |
| 2193 | - if ( force_ssl_content() && is_ssl() ) |
|
| 2194 | - $url = set_url_scheme( $url, 'https' ); |
|
| 2193 | + if (force_ssl_content() && is_ssl()) |
|
| 2194 | + $url = set_url_scheme($url, 'https'); |
|
| 2195 | 2195 | |
| 2196 | 2196 | return $url; |
| 2197 | 2197 | } |
@@ -2202,10 +2202,10 @@ discard block |
||
| 2202 | 2202 | * @since 3.1.0 |
| 2203 | 2203 | */ |
| 2204 | 2204 | function wp_schedule_update_network_counts() { |
| 2205 | - if ( !is_main_site() ) |
|
| 2205 | + if ( ! is_main_site()) |
|
| 2206 | 2206 | return; |
| 2207 | 2207 | |
| 2208 | - if ( !wp_next_scheduled('update_network_counts') && !defined('WP_INSTALLING') ) |
|
| 2208 | + if ( ! wp_next_scheduled('update_network_counts') && ! defined('WP_INSTALLING')) |
|
| 2209 | 2209 | wp_schedule_event(time(), 'twicedaily', 'update_network_counts'); |
| 2210 | 2210 | } |
| 2211 | 2211 | |
@@ -2228,7 +2228,7 @@ discard block |
||
| 2228 | 2228 | * @since 3.7.0 |
| 2229 | 2229 | */ |
| 2230 | 2230 | function wp_maybe_update_network_site_counts() { |
| 2231 | - $is_small_network = ! wp_is_large_network( 'sites' ); |
|
| 2231 | + $is_small_network = ! wp_is_large_network('sites'); |
|
| 2232 | 2232 | |
| 2233 | 2233 | /** |
| 2234 | 2234 | * Filter whether to update network site or user counts when a new site is created. |
@@ -2240,7 +2240,7 @@ discard block |
||
| 2240 | 2240 | * @param bool $small_network Whether the network is considered small. |
| 2241 | 2241 | * @param string $context Context. Either 'users' or 'sites'. |
| 2242 | 2242 | */ |
| 2243 | - if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'sites' ) ) |
|
| 2243 | + if ( ! apply_filters('enable_live_network_counts', $is_small_network, 'sites')) |
|
| 2244 | 2244 | return; |
| 2245 | 2245 | |
| 2246 | 2246 | wp_update_network_site_counts(); |
@@ -2255,10 +2255,10 @@ discard block |
||
| 2255 | 2255 | * @since 3.7.0 |
| 2256 | 2256 | */ |
| 2257 | 2257 | function wp_maybe_update_network_user_counts() { |
| 2258 | - $is_small_network = ! wp_is_large_network( 'users' ); |
|
| 2258 | + $is_small_network = ! wp_is_large_network('users'); |
|
| 2259 | 2259 | |
| 2260 | 2260 | /** This filter is documented in wp-includes/ms-functions.php */ |
| 2261 | - if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'users' ) ) |
|
| 2261 | + if ( ! apply_filters('enable_live_network_counts', $is_small_network, 'users')) |
|
| 2262 | 2262 | return; |
| 2263 | 2263 | |
| 2264 | 2264 | wp_update_network_user_counts(); |
@@ -2274,8 +2274,8 @@ discard block |
||
| 2274 | 2274 | function wp_update_network_site_counts() { |
| 2275 | 2275 | global $wpdb; |
| 2276 | 2276 | |
| 2277 | - $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(blog_id) as c FROM $wpdb->blogs WHERE site_id = %d AND spam = '0' AND deleted = '0' and archived = '0'", $wpdb->siteid) ); |
|
| 2278 | - update_site_option( 'blog_count', $count ); |
|
| 2277 | + $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(blog_id) as c FROM $wpdb->blogs WHERE site_id = %d AND spam = '0' AND deleted = '0' and archived = '0'", $wpdb->siteid)); |
|
| 2278 | + update_site_option('blog_count', $count); |
|
| 2279 | 2279 | } |
| 2280 | 2280 | |
| 2281 | 2281 | /** |
@@ -2288,8 +2288,8 @@ discard block |
||
| 2288 | 2288 | function wp_update_network_user_counts() { |
| 2289 | 2289 | global $wpdb; |
| 2290 | 2290 | |
| 2291 | - $count = $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'" ); |
|
| 2292 | - update_site_option( 'user_count', $count ); |
|
| 2291 | + $count = $wpdb->get_var("SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'"); |
|
| 2292 | + update_site_option('user_count', $count); |
|
| 2293 | 2293 | } |
| 2294 | 2294 | |
| 2295 | 2295 | /** |
@@ -2307,10 +2307,10 @@ discard block |
||
| 2307 | 2307 | * |
| 2308 | 2308 | * @param int|bool $space_used The amount of used space, in megabytes. Default false. |
| 2309 | 2309 | */ |
| 2310 | - $space_used = apply_filters( 'pre_get_space_used', false ); |
|
| 2311 | - if ( false === $space_used ) { |
|
| 2310 | + $space_used = apply_filters('pre_get_space_used', false); |
|
| 2311 | + if (false === $space_used) { |
|
| 2312 | 2312 | $upload_dir = wp_upload_dir(); |
| 2313 | - $space_used = get_dirsize( $upload_dir['basedir'] ) / 1024 / 1024; |
|
| 2313 | + $space_used = get_dirsize($upload_dir['basedir']) / 1024 / 1024; |
|
| 2314 | 2314 | } |
| 2315 | 2315 | |
| 2316 | 2316 | return $space_used; |
@@ -2324,12 +2324,12 @@ discard block |
||
| 2324 | 2324 | * @return int Quota in megabytes |
| 2325 | 2325 | */ |
| 2326 | 2326 | function get_space_allowed() { |
| 2327 | - $space_allowed = get_option( 'blog_upload_space' ); |
|
| 2327 | + $space_allowed = get_option('blog_upload_space'); |
|
| 2328 | 2328 | |
| 2329 | - if ( ! is_numeric( $space_allowed ) ) |
|
| 2330 | - $space_allowed = get_site_option( 'blog_upload_space' ); |
|
| 2329 | + if ( ! is_numeric($space_allowed)) |
|
| 2330 | + $space_allowed = get_site_option('blog_upload_space'); |
|
| 2331 | 2331 | |
| 2332 | - if ( empty( $space_allowed ) || ! is_numeric( $space_allowed ) ) |
|
| 2332 | + if (empty($space_allowed) || ! is_numeric($space_allowed)) |
|
| 2333 | 2333 | $space_allowed = 100; |
| 2334 | 2334 | |
| 2335 | 2335 | /** |
@@ -2339,7 +2339,7 @@ discard block |
||
| 2339 | 2339 | * |
| 2340 | 2340 | * @param int $space_allowed Upload quota in megabytes for the current blog. |
| 2341 | 2341 | */ |
| 2342 | - return apply_filters( 'get_space_allowed', $space_allowed ); |
|
| 2342 | + return apply_filters('get_space_allowed', $space_allowed); |
|
| 2343 | 2343 | } |
| 2344 | 2344 | |
| 2345 | 2345 | /** |
@@ -2351,12 +2351,12 @@ discard block |
||
| 2351 | 2351 | */ |
| 2352 | 2352 | function get_upload_space_available() { |
| 2353 | 2353 | $space_allowed = get_space_allowed() * 1024 * 1024; |
| 2354 | - if ( get_site_option( 'upload_space_check_disabled' ) ) |
|
| 2354 | + if (get_site_option('upload_space_check_disabled')) |
|
| 2355 | 2355 | return $space_allowed; |
| 2356 | 2356 | |
| 2357 | 2357 | $space_used = get_space_used() * 1024 * 1024; |
| 2358 | 2358 | |
| 2359 | - if ( ( $space_allowed - $space_used ) <= 0 ) |
|
| 2359 | + if (($space_allowed - $space_used) <= 0) |
|
| 2360 | 2360 | return 0; |
| 2361 | 2361 | |
| 2362 | 2362 | return $space_allowed - $space_used; |
@@ -2369,7 +2369,7 @@ discard block |
||
| 2369 | 2369 | * @return bool True if space is available, false otherwise. |
| 2370 | 2370 | */ |
| 2371 | 2371 | function is_upload_space_available() { |
| 2372 | - if ( get_site_option( 'upload_space_check_disabled' ) ) |
|
| 2372 | + if (get_site_option('upload_space_check_disabled')) |
|
| 2373 | 2373 | return true; |
| 2374 | 2374 | |
| 2375 | 2375 | return (bool) get_upload_space_available(); |
@@ -2380,12 +2380,12 @@ discard block |
||
| 2380 | 2380 | * |
| 2381 | 2381 | * @return int of upload size limit in bytes |
| 2382 | 2382 | */ |
| 2383 | -function upload_size_limit_filter( $size ) { |
|
| 2384 | - $fileupload_maxk = 1024 * get_site_option( 'fileupload_maxk', 1500 ); |
|
| 2385 | - if ( get_site_option( 'upload_space_check_disabled' ) ) |
|
| 2386 | - return min( $size, $fileupload_maxk ); |
|
| 2383 | +function upload_size_limit_filter($size) { |
|
| 2384 | + $fileupload_maxk = 1024 * get_site_option('fileupload_maxk', 1500); |
|
| 2385 | + if (get_site_option('upload_space_check_disabled')) |
|
| 2386 | + return min($size, $fileupload_maxk); |
|
| 2387 | 2387 | |
| 2388 | - return min( $size, $fileupload_maxk, get_upload_space_available() ); |
|
| 2388 | + return min($size, $fileupload_maxk, get_upload_space_available()); |
|
| 2389 | 2389 | } |
| 2390 | 2390 | |
| 2391 | 2391 | /** |
@@ -2398,8 +2398,8 @@ discard block |
||
| 2398 | 2398 | * @param string $using 'sites or 'users'. Default is 'sites'. |
| 2399 | 2399 | * @return bool True if the network meets the criteria for large. False otherwise. |
| 2400 | 2400 | */ |
| 2401 | -function wp_is_large_network( $using = 'sites' ) { |
|
| 2402 | - if ( 'users' == $using ) { |
|
| 2401 | +function wp_is_large_network($using = 'sites') { |
|
| 2402 | + if ('users' == $using) { |
|
| 2403 | 2403 | $count = get_user_count(); |
| 2404 | 2404 | /** |
| 2405 | 2405 | * Filter whether the network is considered large. |
@@ -2410,12 +2410,12 @@ discard block |
||
| 2410 | 2410 | * @param string $component The component to count. Accepts 'users', or 'sites'. |
| 2411 | 2411 | * @param int $count The count of items for the component. |
| 2412 | 2412 | */ |
| 2413 | - return apply_filters( 'wp_is_large_network', $count > 10000, 'users', $count ); |
|
| 2413 | + return apply_filters('wp_is_large_network', $count > 10000, 'users', $count); |
|
| 2414 | 2414 | } |
| 2415 | 2415 | |
| 2416 | 2416 | $count = get_blog_count(); |
| 2417 | 2417 | /** This filter is documented in wp-includes/ms-functions.php */ |
| 2418 | - return apply_filters( 'wp_is_large_network', $count > 10000, 'sites', $count ); |
|
| 2418 | + return apply_filters('wp_is_large_network', $count > 10000, 'sites', $count); |
|
| 2419 | 2419 | } |
| 2420 | 2420 | |
| 2421 | 2421 | |
@@ -2444,10 +2444,10 @@ discard block |
||
| 2444 | 2444 | * site domain and path, dates registered and modified, and the language ID. Also, boolean |
| 2445 | 2445 | * values for whether the site is public, archived, mature, spam, and/or deleted. |
| 2446 | 2446 | */ |
| 2447 | -function wp_get_sites( $args = array() ) { |
|
| 2447 | +function wp_get_sites($args = array()) { |
|
| 2448 | 2448 | global $wpdb; |
| 2449 | 2449 | |
| 2450 | - if ( wp_is_large_network() ) |
|
| 2450 | + if (wp_is_large_network()) |
|
| 2451 | 2451 | return array(); |
| 2452 | 2452 | |
| 2453 | 2453 | $defaults = array( |
@@ -2461,38 +2461,38 @@ discard block |
||
| 2461 | 2461 | 'offset' => 0, |
| 2462 | 2462 | ); |
| 2463 | 2463 | |
| 2464 | - $args = wp_parse_args( $args, $defaults ); |
|
| 2464 | + $args = wp_parse_args($args, $defaults); |
|
| 2465 | 2465 | |
| 2466 | 2466 | $query = "SELECT * FROM $wpdb->blogs WHERE 1=1 "; |
| 2467 | 2467 | |
| 2468 | - if ( isset( $args['network_id'] ) && ( is_array( $args['network_id'] ) || is_numeric( $args['network_id'] ) ) ) { |
|
| 2469 | - $network_ids = implode( ',', wp_parse_id_list( $args['network_id'] ) ); |
|
| 2468 | + if (isset($args['network_id']) && (is_array($args['network_id']) || is_numeric($args['network_id']))) { |
|
| 2469 | + $network_ids = implode(',', wp_parse_id_list($args['network_id'])); |
|
| 2470 | 2470 | $query .= "AND site_id IN ($network_ids) "; |
| 2471 | 2471 | } |
| 2472 | 2472 | |
| 2473 | - if ( isset( $args['public'] ) ) |
|
| 2474 | - $query .= $wpdb->prepare( "AND public = %d ", $args['public'] ); |
|
| 2473 | + if (isset($args['public'])) |
|
| 2474 | + $query .= $wpdb->prepare("AND public = %d ", $args['public']); |
|
| 2475 | 2475 | |
| 2476 | - if ( isset( $args['archived'] ) ) |
|
| 2477 | - $query .= $wpdb->prepare( "AND archived = %d ", $args['archived'] ); |
|
| 2476 | + if (isset($args['archived'])) |
|
| 2477 | + $query .= $wpdb->prepare("AND archived = %d ", $args['archived']); |
|
| 2478 | 2478 | |
| 2479 | - if ( isset( $args['mature'] ) ) |
|
| 2480 | - $query .= $wpdb->prepare( "AND mature = %d ", $args['mature'] ); |
|
| 2479 | + if (isset($args['mature'])) |
|
| 2480 | + $query .= $wpdb->prepare("AND mature = %d ", $args['mature']); |
|
| 2481 | 2481 | |
| 2482 | - if ( isset( $args['spam'] ) ) |
|
| 2483 | - $query .= $wpdb->prepare( "AND spam = %d ", $args['spam'] ); |
|
| 2482 | + if (isset($args['spam'])) |
|
| 2483 | + $query .= $wpdb->prepare("AND spam = %d ", $args['spam']); |
|
| 2484 | 2484 | |
| 2485 | - if ( isset( $args['deleted'] ) ) |
|
| 2486 | - $query .= $wpdb->prepare( "AND deleted = %d ", $args['deleted'] ); |
|
| 2485 | + if (isset($args['deleted'])) |
|
| 2486 | + $query .= $wpdb->prepare("AND deleted = %d ", $args['deleted']); |
|
| 2487 | 2487 | |
| 2488 | - if ( isset( $args['limit'] ) && $args['limit'] ) { |
|
| 2489 | - if ( isset( $args['offset'] ) && $args['offset'] ) |
|
| 2490 | - $query .= $wpdb->prepare( "LIMIT %d , %d ", $args['offset'], $args['limit'] ); |
|
| 2488 | + if (isset($args['limit']) && $args['limit']) { |
|
| 2489 | + if (isset($args['offset']) && $args['offset']) |
|
| 2490 | + $query .= $wpdb->prepare("LIMIT %d , %d ", $args['offset'], $args['limit']); |
|
| 2491 | 2491 | else |
| 2492 | - $query .= $wpdb->prepare( "LIMIT %d ", $args['limit'] ); |
|
| 2492 | + $query .= $wpdb->prepare("LIMIT %d ", $args['limit']); |
|
| 2493 | 2493 | } |
| 2494 | 2494 | |
| 2495 | - $site_results = $wpdb->get_results( $query, ARRAY_A ); |
|
| 2495 | + $site_results = $wpdb->get_results($query, ARRAY_A); |
|
| 2496 | 2496 | |
| 2497 | 2497 | return $site_results; |
| 2498 | 2498 | } |
@@ -37,13 +37,15 @@ discard block |
||
| 37 | 37 | function get_admin_users_for_domain( $sitedomain = '', $path = '' ) { |
| 38 | 38 | global $wpdb; |
| 39 | 39 | |
| 40 | - if ( ! $sitedomain ) |
|
| 41 | - $site_id = $wpdb->siteid; |
|
| 42 | - else |
|
| 43 | - $site_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path ) ); |
|
| 40 | + if ( ! $sitedomain ) { |
|
| 41 | + $site_id = $wpdb->siteid; |
|
| 42 | + } else { |
|
| 43 | + $site_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path ) ); |
|
| 44 | + } |
|
| 44 | 45 | |
| 45 | - if ( $site_id ) |
|
| 46 | - return $wpdb->get_results( $wpdb->prepare( "SELECT u.ID, u.user_login, u.user_pass FROM $wpdb->users AS u, $wpdb->sitemeta AS sm WHERE sm.meta_key = 'admin_user_id' AND u.ID = sm.meta_value AND sm.site_id = %d", $site_id ), ARRAY_A ); |
|
| 46 | + if ( $site_id ) { |
|
| 47 | + return $wpdb->get_results( $wpdb->prepare( "SELECT u.ID, u.user_login, u.user_pass FROM $wpdb->users AS u, $wpdb->sitemeta AS sm WHERE sm.meta_key = 'admin_user_id' AND u.ID = sm.meta_value AND sm.site_id = %d", $site_id ), ARRAY_A ); |
|
| 48 | + } |
|
| 47 | 49 | |
| 48 | 50 | return false; |
| 49 | 51 | } |
@@ -67,11 +69,13 @@ discard block |
||
| 67 | 69 | function get_active_blog_for_user( $user_id ) { |
| 68 | 70 | global $wpdb; |
| 69 | 71 | $blogs = get_blogs_of_user( $user_id ); |
| 70 | - if ( empty( $blogs ) ) |
|
| 71 | - return; |
|
| 72 | + if ( empty( $blogs ) ) { |
|
| 73 | + return; |
|
| 74 | + } |
|
| 72 | 75 | |
| 73 | - if ( !is_multisite() ) |
|
| 74 | - return $blogs[$wpdb->blogid]; |
|
| 76 | + if ( !is_multisite() ) { |
|
| 77 | + return $blogs[$wpdb->blogid]; |
|
| 78 | + } |
|
| 75 | 79 | |
| 76 | 80 | $primary_blog = get_user_meta( $user_id, 'primary_blog', true ); |
| 77 | 81 | $first_blog = current($blogs); |
@@ -94,15 +98,18 @@ discard block |
||
| 94 | 98 | $ret = false; |
| 95 | 99 | if ( is_array( $blogs ) && count( $blogs ) > 0 ) { |
| 96 | 100 | foreach ( (array) $blogs as $blog_id => $blog ) { |
| 97 | - if ( $blog->site_id != $wpdb->siteid ) |
|
| 98 | - continue; |
|
| 101 | + if ( $blog->site_id != $wpdb->siteid ) { |
|
| 102 | + continue; |
|
| 103 | + } |
|
| 99 | 104 | $details = get_blog_details( $blog_id ); |
| 100 | 105 | if ( is_object( $details ) && $details->archived == 0 && $details->spam == 0 && $details->deleted == 0 ) { |
| 101 | 106 | $ret = $blog; |
| 102 | - if ( get_user_meta( $user_id , 'primary_blog', true ) != $blog_id ) |
|
| 103 | - update_user_meta( $user_id, 'primary_blog', $blog_id ); |
|
| 104 | - if ( !get_user_meta($user_id , 'source_domain', true) ) |
|
| 105 | - update_user_meta( $user_id, 'source_domain', $blog->domain ); |
|
| 107 | + if ( get_user_meta( $user_id , 'primary_blog', true ) != $blog_id ) { |
|
| 108 | + update_user_meta( $user_id, 'primary_blog', $blog_id ); |
|
| 109 | + } |
|
| 110 | + if ( !get_user_meta($user_id , 'source_domain', true) ) { |
|
| 111 | + update_user_meta( $user_id, 'source_domain', $blog->domain ); |
|
| 112 | + } |
|
| 106 | 113 | break; |
| 107 | 114 | } |
| 108 | 115 | } |
@@ -139,8 +146,9 @@ discard block |
||
| 139 | 146 | * @return int |
| 140 | 147 | */ |
| 141 | 148 | function get_blog_count( $network_id = 0 ) { |
| 142 | - if ( func_num_args() ) |
|
| 143 | - _deprecated_argument( __FUNCTION__, '3.1' ); |
|
| 149 | + if ( func_num_args() ) { |
|
| 150 | + _deprecated_argument( __FUNCTION__, '3.1' ); |
|
| 151 | + } |
|
| 144 | 152 | |
| 145 | 153 | return get_site_option( 'blog_count' ); |
| 146 | 154 | } |
@@ -249,8 +257,9 @@ discard block |
||
| 249 | 257 | $new_domain = ''; |
| 250 | 258 | $blogs = get_blogs_of_user($user_id); |
| 251 | 259 | foreach ( (array) $blogs as $blog ) { |
| 252 | - if ( $blog->userblog_id == $blog_id ) |
|
| 253 | - continue; |
|
| 260 | + if ( $blog->userblog_id == $blog_id ) { |
|
| 261 | + continue; |
|
| 262 | + } |
|
| 254 | 263 | $new_id = $blog->userblog_id; |
| 255 | 264 | $new_domain = $blog->domain; |
| 256 | 265 | break; |
@@ -308,19 +317,22 @@ discard block |
||
| 308 | 317 | * @return string|int The ID of the newly created blog |
| 309 | 318 | */ |
| 310 | 319 | function create_empty_blog( $domain, $path, $weblog_title, $site_id = 1 ) { |
| 311 | - if ( empty($path) ) |
|
| 312 | - $path = '/'; |
|
| 320 | + if ( empty($path) ) { |
|
| 321 | + $path = '/'; |
|
| 322 | + } |
|
| 313 | 323 | |
| 314 | 324 | // Check if the domain has been used already. We should return an error message. |
| 315 | - if ( domain_exists($domain, $path, $site_id) ) |
|
| 316 | - return __( '<strong>ERROR</strong>: Site URL already taken.' ); |
|
| 325 | + if ( domain_exists($domain, $path, $site_id) ) { |
|
| 326 | + return __( '<strong>ERROR</strong>: Site URL already taken.' ); |
|
| 327 | + } |
|
| 317 | 328 | |
| 318 | 329 | // Need to back up wpdb table names, and create a new wp_blogs entry for new blog. |
| 319 | 330 | // Need to get blog_id from wp_blogs, and create new table names. |
| 320 | 331 | // Must restore table names at the end of function. |
| 321 | 332 | |
| 322 | - if ( ! $blog_id = insert_blog($domain, $path, $site_id) ) |
|
| 323 | - return __( '<strong>ERROR</strong>: problem creating site entry.' ); |
|
| 333 | + if ( ! $blog_id = insert_blog($domain, $path, $site_id) ) { |
|
| 334 | + return __( '<strong>ERROR</strong>: problem creating site entry.' ); |
|
| 335 | + } |
|
| 324 | 336 | |
| 325 | 337 | switch_to_blog($blog_id); |
| 326 | 338 | install_blog($blog_id); |
@@ -369,10 +381,12 @@ discard block |
||
| 369 | 381 | $path = strtolower( $path ); |
| 370 | 382 | $id = wp_cache_get( md5( $domain . $path ), 'blog-id-cache' ); |
| 371 | 383 | |
| 372 | - if ( $id == -1 ) // blog does not exist |
|
| 384 | + if ( $id == -1 ) { |
|
| 385 | + // blog does not exist |
|
| 373 | 386 | return 0; |
| 374 | - elseif ( $id ) |
|
| 375 | - return (int) $id; |
|
| 387 | + } elseif ( $id ) { |
|
| 388 | + return (int) $id; |
|
| 389 | + } |
|
| 376 | 390 | |
| 377 | 391 | $id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s and path = %s /* get_blog_id_from_url */", $domain, $path ) ); |
| 378 | 392 | |
@@ -403,8 +417,9 @@ discard block |
||
| 403 | 417 | */ |
| 404 | 418 | function is_email_address_unsafe( $user_email ) { |
| 405 | 419 | $banned_names = get_site_option( 'banned_email_domains' ); |
| 406 | - if ( $banned_names && ! is_array( $banned_names ) ) |
|
| 407 | - $banned_names = explode( "\n", $banned_names ); |
|
| 420 | + if ( $banned_names && ! is_array( $banned_names ) ) { |
|
| 421 | + $banned_names = explode( "\n", $banned_names ); |
|
| 422 | + } |
|
| 408 | 423 | |
| 409 | 424 | $is_email_address_unsafe = false; |
| 410 | 425 | |
@@ -415,8 +430,9 @@ discard block |
||
| 415 | 430 | list( $email_local_part, $email_domain ) = explode( '@', $normalized_email ); |
| 416 | 431 | |
| 417 | 432 | foreach ( $banned_names as $banned_domain ) { |
| 418 | - if ( ! $banned_domain ) |
|
| 419 | - continue; |
|
| 433 | + if ( ! $banned_domain ) { |
|
| 434 | + continue; |
|
| 435 | + } |
|
| 420 | 436 | |
| 421 | 437 | if ( $email_domain == $banned_domain ) { |
| 422 | 438 | $is_email_address_unsafe = true; |
@@ -477,36 +493,43 @@ discard block |
||
| 477 | 493 | |
| 478 | 494 | $user_email = sanitize_email( $user_email ); |
| 479 | 495 | |
| 480 | - if ( empty( $user_name ) ) |
|
| 481 | - $errors->add('user_name', __( 'Please enter a username.' ) ); |
|
| 496 | + if ( empty( $user_name ) ) { |
|
| 497 | + $errors->add('user_name', __( 'Please enter a username.' ) ); |
|
| 498 | + } |
|
| 482 | 499 | |
| 483 | 500 | $illegal_names = get_site_option( 'illegal_names' ); |
| 484 | 501 | if ( ! is_array( $illegal_names ) ) { |
| 485 | 502 | $illegal_names = array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator' ); |
| 486 | 503 | add_site_option( 'illegal_names', $illegal_names ); |
| 487 | 504 | } |
| 488 | - if ( in_array( $user_name, $illegal_names ) ) |
|
| 489 | - $errors->add('user_name', __( 'That username is not allowed.' ) ); |
|
| 505 | + if ( in_array( $user_name, $illegal_names ) ) { |
|
| 506 | + $errors->add('user_name', __( 'That username is not allowed.' ) ); |
|
| 507 | + } |
|
| 490 | 508 | |
| 491 | - if ( is_email_address_unsafe( $user_email ) ) |
|
| 492 | - $errors->add('user_email', __('You cannot use that email address to signup. We are having problems with them blocking some of our email. Please use another email provider.')); |
|
| 509 | + if ( is_email_address_unsafe( $user_email ) ) { |
|
| 510 | + $errors->add('user_email', __('You cannot use that email address to signup. We are having problems with them blocking some of our email. Please use another email provider.')); |
|
| 511 | + } |
|
| 493 | 512 | |
| 494 | - if ( strlen( $user_name ) < 4 ) |
|
| 495 | - $errors->add('user_name', __( 'Username must be at least 4 characters.' ) ); |
|
| 513 | + if ( strlen( $user_name ) < 4 ) { |
|
| 514 | + $errors->add('user_name', __( 'Username must be at least 4 characters.' ) ); |
|
| 515 | + } |
|
| 496 | 516 | |
| 497 | 517 | if ( strlen( $user_name ) > 60 ) { |
| 498 | 518 | $errors->add( 'user_name', __( 'Username may not be longer than 60 characters.' ) ); |
| 499 | 519 | } |
| 500 | 520 | |
| 501 | - if ( strpos( $user_name, '_' ) !== false ) |
|
| 502 | - $errors->add( 'user_name', __( 'Sorry, usernames may not contain the character “_”!' ) ); |
|
| 521 | + if ( strpos( $user_name, '_' ) !== false ) { |
|
| 522 | + $errors->add( 'user_name', __( 'Sorry, usernames may not contain the character “_”!' ) ); |
|
| 523 | + } |
|
| 503 | 524 | |
| 504 | 525 | // all numeric? |
| 505 | - if ( preg_match( '/^[0-9]*$/', $user_name ) ) |
|
| 506 | - $errors->add('user_name', __('Sorry, usernames must have letters too!')); |
|
| 526 | + if ( preg_match( '/^[0-9]*$/', $user_name ) ) { |
|
| 527 | + $errors->add('user_name', __('Sorry, usernames must have letters too!')); |
|
| 528 | + } |
|
| 507 | 529 | |
| 508 | - if ( !is_email( $user_email ) ) |
|
| 509 | - $errors->add('user_email', __( 'Please enter a valid email address.' ) ); |
|
| 530 | + if ( !is_email( $user_email ) ) { |
|
| 531 | + $errors->add('user_email', __( 'Please enter a valid email address.' ) ); |
|
| 532 | + } |
|
| 510 | 533 | |
| 511 | 534 | $limited_email_domains = get_site_option( 'limited_email_domains' ); |
| 512 | 535 | if ( is_array( $limited_email_domains ) && ! empty( $limited_email_domains ) ) { |
@@ -517,12 +540,14 @@ discard block |
||
| 517 | 540 | } |
| 518 | 541 | |
| 519 | 542 | // Check if the username has been used already. |
| 520 | - if ( username_exists($user_name) ) |
|
| 521 | - $errors->add( 'user_name', __( 'Sorry, that username already exists!' ) ); |
|
| 543 | + if ( username_exists($user_name) ) { |
|
| 544 | + $errors->add( 'user_name', __( 'Sorry, that username already exists!' ) ); |
|
| 545 | + } |
|
| 522 | 546 | |
| 523 | 547 | // Check if the email address has been used already. |
| 524 | - if ( email_exists($user_email) ) |
|
| 525 | - $errors->add( 'user_email', __( 'Sorry, that email address is already used!' ) ); |
|
| 548 | + if ( email_exists($user_email) ) { |
|
| 549 | + $errors->add( 'user_email', __( 'Sorry, that email address is already used!' ) ); |
|
| 550 | + } |
|
| 526 | 551 | |
| 527 | 552 | // Has someone already signed up for this username? |
| 528 | 553 | $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE user_login = %s", $user_name) ); |
@@ -531,20 +556,22 @@ discard block |
||
| 531 | 556 | $now = current_time( 'timestamp', true ); |
| 532 | 557 | $diff = $now - $registered_at; |
| 533 | 558 | // If registered more than two days ago, cancel registration and let this signup go through. |
| 534 | - if ( $diff > 2 * DAY_IN_SECONDS ) |
|
| 535 | - $wpdb->delete( $wpdb->signups, array( 'user_login' => $user_name ) ); |
|
| 536 | - else |
|
| 537 | - $errors->add('user_name', __('That username is currently reserved but may be available in a couple of days.')); |
|
| 559 | + if ( $diff > 2 * DAY_IN_SECONDS ) { |
|
| 560 | + $wpdb->delete( $wpdb->signups, array( 'user_login' => $user_name ) ); |
|
| 561 | + } else { |
|
| 562 | + $errors->add('user_name', __('That username is currently reserved but may be available in a couple of days.')); |
|
| 563 | + } |
|
| 538 | 564 | } |
| 539 | 565 | |
| 540 | 566 | $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE user_email = %s", $user_email) ); |
| 541 | 567 | if ( $signup != null ) { |
| 542 | 568 | $diff = current_time( 'timestamp', true ) - mysql2date('U', $signup->registered); |
| 543 | 569 | // If registered more than two days ago, cancel registration and let this signup go through. |
| 544 | - if ( $diff > 2 * DAY_IN_SECONDS ) |
|
| 545 | - $wpdb->delete( $wpdb->signups, array( 'user_email' => $user_email ) ); |
|
| 546 | - else |
|
| 547 | - $errors->add('user_email', __('That email address has already been used. Please check your inbox for an activation email. It will become available in a couple of days if you do nothing.')); |
|
| 570 | + if ( $diff > 2 * DAY_IN_SECONDS ) { |
|
| 571 | + $wpdb->delete( $wpdb->signups, array( 'user_email' => $user_email ) ); |
|
| 572 | + } else { |
|
| 573 | + $errors->add('user_email', __('That email address has already been used. Please check your inbox for an activation email. It will become available in a couple of days if you do nothing.')); |
|
| 574 | + } |
|
| 548 | 575 | } |
| 549 | 576 | |
| 550 | 577 | $result = array('user_name' => $user_name, 'orig_username' => $orig_username, 'user_email' => $user_email, 'errors' => $errors); |
@@ -626,28 +653,35 @@ discard block |
||
| 626 | 653 | ); |
| 627 | 654 | } |
| 628 | 655 | |
| 629 | - if ( empty( $blogname ) ) |
|
| 630 | - $errors->add('blogname', __( 'Please enter a site name.' ) ); |
|
| 656 | + if ( empty( $blogname ) ) { |
|
| 657 | + $errors->add('blogname', __( 'Please enter a site name.' ) ); |
|
| 658 | + } |
|
| 631 | 659 | |
| 632 | - if ( preg_match( '/[^a-z0-9]+/', $blogname ) ) |
|
| 633 | - $errors->add('blogname', __( 'Only lowercase letters (a-z) and numbers are allowed.' ) ); |
|
| 660 | + if ( preg_match( '/[^a-z0-9]+/', $blogname ) ) { |
|
| 661 | + $errors->add('blogname', __( 'Only lowercase letters (a-z) and numbers are allowed.' ) ); |
|
| 662 | + } |
|
| 634 | 663 | |
| 635 | - if ( in_array( $blogname, $illegal_names ) ) |
|
| 636 | - $errors->add('blogname', __( 'That name is not allowed.' ) ); |
|
| 664 | + if ( in_array( $blogname, $illegal_names ) ) { |
|
| 665 | + $errors->add('blogname', __( 'That name is not allowed.' ) ); |
|
| 666 | + } |
|
| 637 | 667 | |
| 638 | - if ( strlen( $blogname ) < 4 && !is_super_admin() ) |
|
| 639 | - $errors->add('blogname', __( 'Site name must be at least 4 characters.' ) ); |
|
| 668 | + if ( strlen( $blogname ) < 4 && !is_super_admin() ) { |
|
| 669 | + $errors->add('blogname', __( 'Site name must be at least 4 characters.' ) ); |
|
| 670 | + } |
|
| 640 | 671 | |
| 641 | - if ( strpos( $blogname, '_' ) !== false ) |
|
| 642 | - $errors->add( 'blogname', __( 'Sorry, site names may not contain the character “_”!' ) ); |
|
| 672 | + if ( strpos( $blogname, '_' ) !== false ) { |
|
| 673 | + $errors->add( 'blogname', __( 'Sorry, site names may not contain the character “_”!' ) ); |
|
| 674 | + } |
|
| 643 | 675 | |
| 644 | 676 | // do not allow users to create a blog that conflicts with a page on the main blog. |
| 645 | - if ( !is_subdomain_install() && $wpdb->get_var( $wpdb->prepare( "SELECT post_name FROM " . $wpdb->get_blog_prefix( $current_site->blog_id ) . "posts WHERE post_type = 'page' AND post_name = %s", $blogname ) ) ) |
|
| 646 | - $errors->add( 'blogname', __( 'Sorry, you may not use that site name.' ) ); |
|
| 677 | + if ( !is_subdomain_install() && $wpdb->get_var( $wpdb->prepare( "SELECT post_name FROM " . $wpdb->get_blog_prefix( $current_site->blog_id ) . "posts WHERE post_type = 'page' AND post_name = %s", $blogname ) ) ) { |
|
| 678 | + $errors->add( 'blogname', __( 'Sorry, you may not use that site name.' ) ); |
|
| 679 | + } |
|
| 647 | 680 | |
| 648 | 681 | // all numeric? |
| 649 | - if ( preg_match( '/^[0-9]*$/', $blogname ) ) |
|
| 650 | - $errors->add('blogname', __('Sorry, site names must have letters too!')); |
|
| 682 | + if ( preg_match( '/^[0-9]*$/', $blogname ) ) { |
|
| 683 | + $errors->add('blogname', __('Sorry, site names must have letters too!')); |
|
| 684 | + } |
|
| 651 | 685 | |
| 652 | 686 | /** |
| 653 | 687 | * Filter the new site name during registration. |
@@ -663,8 +697,9 @@ discard block |
||
| 663 | 697 | |
| 664 | 698 | $blog_title = wp_unslash( $blog_title ); |
| 665 | 699 | |
| 666 | - if ( empty( $blog_title ) ) |
|
| 667 | - $errors->add('blog_title', __( 'Please enter a site title.' ) ); |
|
| 700 | + if ( empty( $blog_title ) ) { |
|
| 701 | + $errors->add('blog_title', __( 'Please enter a site title.' ) ); |
|
| 702 | + } |
|
| 668 | 703 | |
| 669 | 704 | // Check if the domain/path has been used already. |
| 670 | 705 | if ( is_subdomain_install() ) { |
@@ -674,12 +709,14 @@ discard block |
||
| 674 | 709 | $mydomain = "$domain"; |
| 675 | 710 | $path = $base.$blogname.'/'; |
| 676 | 711 | } |
| 677 | - if ( domain_exists($mydomain, $path, $current_site->id) ) |
|
| 678 | - $errors->add( 'blogname', __( 'Sorry, that site already exists!' ) ); |
|
| 712 | + if ( domain_exists($mydomain, $path, $current_site->id) ) { |
|
| 713 | + $errors->add( 'blogname', __( 'Sorry, that site already exists!' ) ); |
|
| 714 | + } |
|
| 679 | 715 | |
| 680 | 716 | if ( username_exists( $blogname ) ) { |
| 681 | - if ( ! is_object( $user ) || ( is_object($user) && ( $user->user_login != $blogname ) ) ) |
|
| 682 | - $errors->add( 'blogname', __( 'Sorry, that site is reserved!' ) ); |
|
| 717 | + if ( ! is_object( $user ) || ( is_object($user) && ( $user->user_login != $blogname ) ) ) { |
|
| 718 | + $errors->add( 'blogname', __( 'Sorry, that site is reserved!' ) ); |
|
| 719 | + } |
|
| 683 | 720 | } |
| 684 | 721 | |
| 685 | 722 | // Has someone already signed up for this domain? |
@@ -687,10 +724,11 @@ discard block |
||
| 687 | 724 | if ( ! empty($signup) ) { |
| 688 | 725 | $diff = current_time( 'timestamp', true ) - mysql2date('U', $signup->registered); |
| 689 | 726 | // If registered more than two days ago, cancel registration and let this signup go through. |
| 690 | - if ( $diff > 2 * DAY_IN_SECONDS ) |
|
| 691 | - $wpdb->delete( $wpdb->signups, array( 'domain' => $mydomain , 'path' => $path ) ); |
|
| 692 | - else |
|
| 693 | - $errors->add('blogname', __('That site is currently reserved but may be available in a couple days.')); |
|
| 727 | + if ( $diff > 2 * DAY_IN_SECONDS ) { |
|
| 728 | + $wpdb->delete( $wpdb->signups, array( 'domain' => $mydomain , 'path' => $path ) ); |
|
| 729 | + } else { |
|
| 730 | + $errors->add('blogname', __('That site is currently reserved but may be available in a couple days.')); |
|
| 731 | + } |
|
| 694 | 732 | } |
| 695 | 733 | |
| 696 | 734 | $result = array('domain' => $mydomain, 'path' => $path, 'blogname' => $blogname, 'blog_title' => $blog_title, 'user' => $user, 'errors' => $errors); |
@@ -828,15 +866,18 @@ discard block |
||
| 828 | 866 | } |
| 829 | 867 | |
| 830 | 868 | // Send email with activation link. |
| 831 | - if ( !is_subdomain_install() || get_current_site()->id != 1 ) |
|
| 832 | - $activate_url = network_site_url("wp-activate.php?key=$key"); |
|
| 833 | - else |
|
| 834 | - $activate_url = "http://{$domain}{$path}wp-activate.php?key=$key"; // @todo use *_url() API |
|
| 869 | + if ( !is_subdomain_install() || get_current_site()->id != 1 ) { |
|
| 870 | + $activate_url = network_site_url("wp-activate.php?key=$key"); |
|
| 871 | + } else { |
|
| 872 | + $activate_url = "http://{$domain}{$path}wp-activate.php?key=$key"; |
|
| 873 | + } |
|
| 874 | + // @todo use *_url() API |
|
| 835 | 875 | |
| 836 | 876 | $activate_url = esc_url($activate_url); |
| 837 | 877 | $admin_email = get_site_option( 'admin_email' ); |
| 838 | - if ( $admin_email == '' ) |
|
| 839 | - $admin_email = 'support@' . $_SERVER['SERVER_NAME']; |
|
| 878 | + if ( $admin_email == '' ) { |
|
| 879 | + $admin_email = 'support@' . $_SERVER['SERVER_NAME']; |
|
| 880 | + } |
|
| 840 | 881 | $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) ); |
| 841 | 882 | $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; |
| 842 | 883 | $message = sprintf( |
@@ -923,13 +964,15 @@ discard block |
||
| 923 | 964 | * @param string $key Activation key created in wpmu_signup_user(). |
| 924 | 965 | * @param array $meta Signup meta data. |
| 925 | 966 | */ |
| 926 | - if ( ! apply_filters( 'wpmu_signup_user_notification', $user, $user_email, $key, $meta ) ) |
|
| 927 | - return false; |
|
| 967 | + if ( ! apply_filters( 'wpmu_signup_user_notification', $user, $user_email, $key, $meta ) ) { |
|
| 968 | + return false; |
|
| 969 | + } |
|
| 928 | 970 | |
| 929 | 971 | // Send email with activation link. |
| 930 | 972 | $admin_email = get_site_option( 'admin_email' ); |
| 931 | - if ( $admin_email == '' ) |
|
| 932 | - $admin_email = 'support@' . $_SERVER['SERVER_NAME']; |
|
| 973 | + if ( $admin_email == '' ) { |
|
| 974 | + $admin_email = 'support@' . $_SERVER['SERVER_NAME']; |
|
| 975 | + } |
|
| 933 | 976 | $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) ); |
| 934 | 977 | $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; |
| 935 | 978 | $message = sprintf( |
@@ -996,14 +1039,16 @@ discard block |
||
| 996 | 1039 | |
| 997 | 1040 | $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE activation_key = %s", $key) ); |
| 998 | 1041 | |
| 999 | - if ( empty( $signup ) ) |
|
| 1000 | - return new WP_Error( 'invalid_key', __( 'Invalid activation key.' ) ); |
|
| 1042 | + if ( empty( $signup ) ) { |
|
| 1043 | + return new WP_Error( 'invalid_key', __( 'Invalid activation key.' ) ); |
|
| 1044 | + } |
|
| 1001 | 1045 | |
| 1002 | 1046 | if ( $signup->active ) { |
| 1003 | - if ( empty( $signup->domain ) ) |
|
| 1004 | - return new WP_Error( 'already_active', __( 'The user is already active.' ), $signup ); |
|
| 1005 | - else |
|
| 1006 | - return new WP_Error( 'already_active', __( 'The site is already active.' ), $signup ); |
|
| 1047 | + if ( empty( $signup->domain ) ) { |
|
| 1048 | + return new WP_Error( 'already_active', __( 'The user is already active.' ), $signup ); |
|
| 1049 | + } else { |
|
| 1050 | + return new WP_Error( 'already_active', __( 'The site is already active.' ), $signup ); |
|
| 1051 | + } |
|
| 1007 | 1052 | } |
| 1008 | 1053 | |
| 1009 | 1054 | $meta = maybe_unserialize($signup->meta); |
@@ -1011,21 +1056,24 @@ discard block |
||
| 1011 | 1056 | |
| 1012 | 1057 | $user_id = username_exists($signup->user_login); |
| 1013 | 1058 | |
| 1014 | - if ( ! $user_id ) |
|
| 1015 | - $user_id = wpmu_create_user($signup->user_login, $password, $signup->user_email); |
|
| 1016 | - else |
|
| 1017 | - $user_already_exists = true; |
|
| 1059 | + if ( ! $user_id ) { |
|
| 1060 | + $user_id = wpmu_create_user($signup->user_login, $password, $signup->user_email); |
|
| 1061 | + } else { |
|
| 1062 | + $user_already_exists = true; |
|
| 1063 | + } |
|
| 1018 | 1064 | |
| 1019 | - if ( ! $user_id ) |
|
| 1020 | - return new WP_Error('create_user', __('Could not create user'), $signup); |
|
| 1065 | + if ( ! $user_id ) { |
|
| 1066 | + return new WP_Error('create_user', __('Could not create user'), $signup); |
|
| 1067 | + } |
|
| 1021 | 1068 | |
| 1022 | 1069 | $now = current_time('mysql', true); |
| 1023 | 1070 | |
| 1024 | 1071 | if ( empty($signup->domain) ) { |
| 1025 | 1072 | $wpdb->update( $wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key) ); |
| 1026 | 1073 | |
| 1027 | - if ( isset( $user_already_exists ) ) |
|
| 1028 | - return new WP_Error( 'user_already_exists', __( 'That username is already activated.' ), $signup); |
|
| 1074 | + if ( isset( $user_already_exists ) ) { |
|
| 1075 | + return new WP_Error( 'user_already_exists', __( 'That username is already activated.' ), $signup); |
|
| 1076 | + } |
|
| 1029 | 1077 | |
| 1030 | 1078 | wpmu_welcome_user_notification( $user_id, $password, $meta ); |
| 1031 | 1079 | /** |
@@ -1091,8 +1139,9 @@ discard block |
||
| 1091 | 1139 | $user_name = preg_replace( '/\s+/', '', sanitize_user( $user_name, true ) ); |
| 1092 | 1140 | |
| 1093 | 1141 | $user_id = wp_create_user( $user_name, $password, $email ); |
| 1094 | - if ( is_wp_error( $user_id ) ) |
|
| 1095 | - return false; |
|
| 1142 | + if ( is_wp_error( $user_id ) ) { |
|
| 1143 | + return false; |
|
| 1144 | + } |
|
| 1096 | 1145 | |
| 1097 | 1146 | // Newly created users have no roles or caps until they are added to a blog. |
| 1098 | 1147 | delete_user_option( $user_id, 'capabilities' ); |
@@ -1138,24 +1187,29 @@ discard block |
||
| 1138 | 1187 | |
| 1139 | 1188 | $domain = preg_replace( '/\s+/', '', sanitize_user( $domain, true ) ); |
| 1140 | 1189 | |
| 1141 | - if ( is_subdomain_install() ) |
|
| 1142 | - $domain = str_replace( '@', '', $domain ); |
|
| 1190 | + if ( is_subdomain_install() ) { |
|
| 1191 | + $domain = str_replace( '@', '', $domain ); |
|
| 1192 | + } |
|
| 1143 | 1193 | |
| 1144 | 1194 | $title = strip_tags( $title ); |
| 1145 | 1195 | $user_id = (int) $user_id; |
| 1146 | 1196 | |
| 1147 | - if ( empty($path) ) |
|
| 1148 | - $path = '/'; |
|
| 1197 | + if ( empty($path) ) { |
|
| 1198 | + $path = '/'; |
|
| 1199 | + } |
|
| 1149 | 1200 | |
| 1150 | 1201 | // Check if the domain has been used already. We should return an error message. |
| 1151 | - if ( domain_exists($domain, $path, $site_id) ) |
|
| 1152 | - return new WP_Error( 'blog_taken', __( 'Sorry, that site already exists!' ) ); |
|
| 1202 | + if ( domain_exists($domain, $path, $site_id) ) { |
|
| 1203 | + return new WP_Error( 'blog_taken', __( 'Sorry, that site already exists!' ) ); |
|
| 1204 | + } |
|
| 1153 | 1205 | |
| 1154 | - if ( !defined('WP_INSTALLING') ) |
|
| 1155 | - define( 'WP_INSTALLING', true ); |
|
| 1206 | + if ( !defined('WP_INSTALLING') ) { |
|
| 1207 | + define( 'WP_INSTALLING', true ); |
|
| 1208 | + } |
|
| 1156 | 1209 | |
| 1157 | - if ( ! $blog_id = insert_blog($domain, $path, $site_id) ) |
|
| 1158 | - return new WP_Error('insert_blog', __('Could not create site.')); |
|
| 1210 | + if ( ! $blog_id = insert_blog($domain, $path, $site_id) ) { |
|
| 1211 | + return new WP_Error('insert_blog', __('Could not create site.')); |
|
| 1212 | + } |
|
| 1159 | 1213 | |
| 1160 | 1214 | switch_to_blog($blog_id); |
| 1161 | 1215 | install_blog($blog_id, $title); |
@@ -1164,17 +1218,19 @@ discard block |
||
| 1164 | 1218 | add_user_to_blog($blog_id, $user_id, 'administrator'); |
| 1165 | 1219 | |
| 1166 | 1220 | foreach ( $meta as $key => $value ) { |
| 1167 | - if ( in_array( $key, array( 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id' ) ) ) |
|
| 1168 | - update_blog_status( $blog_id, $key, $value ); |
|
| 1169 | - else |
|
| 1170 | - update_option( $key, $value ); |
|
| 1221 | + if ( in_array( $key, array( 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id' ) ) ) { |
|
| 1222 | + update_blog_status( $blog_id, $key, $value ); |
|
| 1223 | + } else { |
|
| 1224 | + update_option( $key, $value ); |
|
| 1225 | + } |
|
| 1171 | 1226 | } |
| 1172 | 1227 | |
| 1173 | 1228 | add_option( 'WPLANG', get_site_option( 'WPLANG' ) ); |
| 1174 | 1229 | update_option( 'blog_public', (int) $meta['public'] ); |
| 1175 | 1230 | |
| 1176 | - if ( ! is_super_admin( $user_id ) && ! get_user_meta( $user_id, 'primary_blog', true ) ) |
|
| 1177 | - update_user_meta( $user_id, 'primary_blog', $blog_id ); |
|
| 1231 | + if ( ! is_super_admin( $user_id ) && ! get_user_meta( $user_id, 'primary_blog', true ) ) { |
|
| 1232 | + update_user_meta( $user_id, 'primary_blog', $blog_id ); |
|
| 1233 | + } |
|
| 1178 | 1234 | |
| 1179 | 1235 | restore_current_blog(); |
| 1180 | 1236 | /** |
@@ -1206,12 +1262,14 @@ discard block |
||
| 1206 | 1262 | * @return bool |
| 1207 | 1263 | */ |
| 1208 | 1264 | function newblog_notify_siteadmin( $blog_id, $deprecated = '' ) { |
| 1209 | - if ( get_site_option( 'registrationnotification' ) != 'yes' ) |
|
| 1210 | - return false; |
|
| 1265 | + if ( get_site_option( 'registrationnotification' ) != 'yes' ) { |
|
| 1266 | + return false; |
|
| 1267 | + } |
|
| 1211 | 1268 | |
| 1212 | 1269 | $email = get_site_option( 'admin_email' ); |
| 1213 | - if ( is_email($email) == false ) |
|
| 1214 | - return false; |
|
| 1270 | + if ( is_email($email) == false ) { |
|
| 1271 | + return false; |
|
| 1272 | + } |
|
| 1215 | 1273 | |
| 1216 | 1274 | $options_site_url = esc_url(network_admin_url('settings.php')); |
| 1217 | 1275 | |
@@ -1251,13 +1309,15 @@ discard block |
||
| 1251 | 1309 | * @return bool |
| 1252 | 1310 | */ |
| 1253 | 1311 | function newuser_notify_siteadmin( $user_id ) { |
| 1254 | - if ( get_site_option( 'registrationnotification' ) != 'yes' ) |
|
| 1255 | - return false; |
|
| 1312 | + if ( get_site_option( 'registrationnotification' ) != 'yes' ) { |
|
| 1313 | + return false; |
|
| 1314 | + } |
|
| 1256 | 1315 | |
| 1257 | 1316 | $email = get_site_option( 'admin_email' ); |
| 1258 | 1317 | |
| 1259 | - if ( is_email($email) == false ) |
|
| 1260 | - return false; |
|
| 1318 | + if ( is_email($email) == false ) { |
|
| 1319 | + return false; |
|
| 1320 | + } |
|
| 1261 | 1321 | |
| 1262 | 1322 | $user = get_userdata( $user_id ); |
| 1263 | 1323 | |
@@ -1336,8 +1396,9 @@ discard block |
||
| 1336 | 1396 | $site_id = (int) $site_id; |
| 1337 | 1397 | |
| 1338 | 1398 | $result = $wpdb->insert( $wpdb->blogs, array('site_id' => $site_id, 'domain' => $domain, 'path' => $path, 'registered' => current_time('mysql')) ); |
| 1339 | - if ( ! $result ) |
|
| 1340 | - return false; |
|
| 1399 | + if ( ! $result ) { |
|
| 1400 | + return false; |
|
| 1401 | + } |
|
| 1341 | 1402 | |
| 1342 | 1403 | $blog_id = $wpdb->insert_id; |
| 1343 | 1404 | refresh_blog_details( $blog_id ); |
@@ -1371,8 +1432,9 @@ discard block |
||
| 1371 | 1432 | require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| 1372 | 1433 | |
| 1373 | 1434 | $suppress = $wpdb->suppress_errors(); |
| 1374 | - if ( $wpdb->get_results( "DESCRIBE {$wpdb->posts}" ) ) |
|
| 1375 | - die( '<h1>' . __( 'Already Installed' ) . '</h1><p>' . __( 'You appear to have already installed WordPress. To reinstall please clear your old database tables first.' ) . '</p></body></html>' ); |
|
| 1435 | + if ( $wpdb->get_results( "DESCRIBE {$wpdb->posts}" ) ) { |
|
| 1436 | + die( '<h1>' . __( 'Already Installed' ) . '</h1><p>' . __( 'You appear to have already installed WordPress. To reinstall please clear your old database tables first.' ) . '</p></body></html>' ); |
|
| 1437 | + } |
|
| 1376 | 1438 | $wpdb->suppress_errors( $suppress ); |
| 1377 | 1439 | |
| 1378 | 1440 | $url = get_blogaddress_by_id( $blog_id ); |
@@ -1390,10 +1452,11 @@ discard block |
||
| 1390 | 1452 | update_option( 'siteurl', $url ); |
| 1391 | 1453 | update_option( 'home', $url ); |
| 1392 | 1454 | |
| 1393 | - if ( get_site_option( 'ms_files_rewriting' ) ) |
|
| 1394 | - update_option( 'upload_path', UPLOADBLOGSDIR . "/$blog_id/files" ); |
|
| 1395 | - else |
|
| 1396 | - update_option( 'upload_path', get_blog_option( get_current_site()->blog_id, 'upload_path' ) ); |
|
| 1455 | + if ( get_site_option( 'ms_files_rewriting' ) ) { |
|
| 1456 | + update_option( 'upload_path', UPLOADBLOGSDIR . "/$blog_id/files" ); |
|
| 1457 | + } else { |
|
| 1458 | + update_option( 'upload_path', get_blog_option( get_current_site()->blog_id, 'upload_path' ) ); |
|
| 1459 | + } |
|
| 1397 | 1460 | |
| 1398 | 1461 | update_option( 'blogname', wp_unslash( $blog_title ) ); |
| 1399 | 1462 | update_option( 'admin_email', '' ); |
@@ -1463,8 +1526,9 @@ discard block |
||
| 1463 | 1526 | * @param string $title Site title. |
| 1464 | 1527 | * @param array $meta Signup meta data. |
| 1465 | 1528 | */ |
| 1466 | - if ( ! apply_filters( 'wpmu_welcome_notification', $blog_id, $user_id, $password, $title, $meta ) ) |
|
| 1467 | - return false; |
|
| 1529 | + if ( ! apply_filters( 'wpmu_welcome_notification', $blog_id, $user_id, $password, $title, $meta ) ) { |
|
| 1530 | + return false; |
|
| 1531 | + } |
|
| 1468 | 1532 | |
| 1469 | 1533 | $welcome_email = get_site_option( 'welcome_email' ); |
| 1470 | 1534 | if ( $welcome_email == false ) { |
@@ -1511,15 +1575,17 @@ discard block |
||
| 1511 | 1575 | $welcome_email = apply_filters( 'update_welcome_email', $welcome_email, $blog_id, $user_id, $password, $title, $meta ); |
| 1512 | 1576 | $admin_email = get_site_option( 'admin_email' ); |
| 1513 | 1577 | |
| 1514 | - if ( $admin_email == '' ) |
|
| 1515 | - $admin_email = 'support@' . $_SERVER['SERVER_NAME']; |
|
| 1578 | + if ( $admin_email == '' ) { |
|
| 1579 | + $admin_email = 'support@' . $_SERVER['SERVER_NAME']; |
|
| 1580 | + } |
|
| 1516 | 1581 | |
| 1517 | 1582 | $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) ); |
| 1518 | 1583 | $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; |
| 1519 | 1584 | $message = $welcome_email; |
| 1520 | 1585 | |
| 1521 | - if ( empty( $current_site->site_name ) ) |
|
| 1522 | - $current_site->site_name = 'WordPress'; |
|
| 1586 | + if ( empty( $current_site->site_name ) ) { |
|
| 1587 | + $current_site->site_name = 'WordPress'; |
|
| 1588 | + } |
|
| 1523 | 1589 | |
| 1524 | 1590 | /** |
| 1525 | 1591 | * Filter the subject of the welcome email after site activation. |
@@ -1562,8 +1628,9 @@ discard block |
||
| 1562 | 1628 | * @param string $password User password. |
| 1563 | 1629 | * @param array $meta Signup meta data. |
| 1564 | 1630 | */ |
| 1565 | - if ( ! apply_filters( 'wpmu_welcome_user_notification', $user_id, $password, $meta ) ) |
|
| 1566 | - return false; |
|
| 1631 | + if ( ! apply_filters( 'wpmu_welcome_user_notification', $user_id, $password, $meta ) ) { |
|
| 1632 | + return false; |
|
| 1633 | + } |
|
| 1567 | 1634 | |
| 1568 | 1635 | $welcome_email = get_site_option( 'welcome_user_email' ); |
| 1569 | 1636 | |
@@ -1589,15 +1656,17 @@ discard block |
||
| 1589 | 1656 | |
| 1590 | 1657 | $admin_email = get_site_option( 'admin_email' ); |
| 1591 | 1658 | |
| 1592 | - if ( $admin_email == '' ) |
|
| 1593 | - $admin_email = 'support@' . $_SERVER['SERVER_NAME']; |
|
| 1659 | + if ( $admin_email == '' ) { |
|
| 1660 | + $admin_email = 'support@' . $_SERVER['SERVER_NAME']; |
|
| 1661 | + } |
|
| 1594 | 1662 | |
| 1595 | 1663 | $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) ); |
| 1596 | 1664 | $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; |
| 1597 | 1665 | $message = $welcome_email; |
| 1598 | 1666 | |
| 1599 | - if ( empty( $current_site->site_name ) ) |
|
| 1600 | - $current_site->site_name = 'WordPress'; |
|
| 1667 | + if ( empty( $current_site->site_name ) ) { |
|
| 1668 | + $current_site->site_name = 'WordPress'; |
|
| 1669 | + } |
|
| 1601 | 1670 | |
| 1602 | 1671 | /** |
| 1603 | 1672 | * Filter the subject of the welcome email after user activation. |
@@ -1691,11 +1760,13 @@ discard block |
||
| 1691 | 1760 | */ |
| 1692 | 1761 | function get_dirsize( $directory ) { |
| 1693 | 1762 | $dirsize = get_transient( 'dirsize_cache' ); |
| 1694 | - if ( is_array( $dirsize ) && isset( $dirsize[ $directory ][ 'size' ] ) ) |
|
| 1695 | - return $dirsize[ $directory ][ 'size' ]; |
|
| 1763 | + if ( is_array( $dirsize ) && isset( $dirsize[ $directory ][ 'size' ] ) ) { |
|
| 1764 | + return $dirsize[ $directory ][ 'size' ]; |
|
| 1765 | + } |
|
| 1696 | 1766 | |
| 1697 | - if ( ! is_array( $dirsize ) ) |
|
| 1698 | - $dirsize = array(); |
|
| 1767 | + if ( ! is_array( $dirsize ) ) { |
|
| 1768 | + $dirsize = array(); |
|
| 1769 | + } |
|
| 1699 | 1770 | |
| 1700 | 1771 | // Exclude individual site directories from the total when checking the main site, |
| 1701 | 1772 | // as they are subdirectories and should not be counted. |
@@ -1739,8 +1810,9 @@ discard block |
||
| 1739 | 1810 | $size += filesize($path); |
| 1740 | 1811 | } elseif (is_dir($path)) { |
| 1741 | 1812 | $handlesize = recurse_dirsize( $path, $exclude ); |
| 1742 | - if ($handlesize > 0) |
|
| 1743 | - $size += $handlesize; |
|
| 1813 | + if ($handlesize > 0) { |
|
| 1814 | + $size += $handlesize; |
|
| 1815 | + } |
|
| 1744 | 1816 | } |
| 1745 | 1817 | } |
| 1746 | 1818 | } |
@@ -1768,8 +1840,9 @@ discard block |
||
| 1768 | 1840 | $site_mimes = array(); |
| 1769 | 1841 | foreach ( $site_exts as $ext ) { |
| 1770 | 1842 | foreach ( $mimes as $ext_pattern => $mime ) { |
| 1771 | - if ( $ext != '' && strpos( $ext_pattern, $ext ) !== false ) |
|
| 1772 | - $site_mimes[$ext_pattern] = $mime; |
|
| 1843 | + if ( $ext != '' && strpos( $ext_pattern, $ext ) !== false ) { |
|
| 1844 | + $site_mimes[$ext_pattern] = $mime; |
|
| 1845 | + } |
|
| 1773 | 1846 | } |
| 1774 | 1847 | } |
| 1775 | 1848 | return $site_mimes; |
@@ -1805,9 +1878,10 @@ discard block |
||
| 1805 | 1878 | function wpmu_log_new_registrations( $blog_id, $user_id ) { |
| 1806 | 1879 | global $wpdb; |
| 1807 | 1880 | $user = get_userdata( (int) $user_id ); |
| 1808 | - if ( $user ) |
|
| 1809 | - $wpdb->insert( $wpdb->registration_log, array('email' => $user->user_email, 'IP' => preg_replace( '/[^0-9., ]/', '', wp_unslash( $_SERVER['REMOTE_ADDR'] ) ), 'blog_id' => $blog_id, 'date_registered' => current_time('mysql')) ); |
|
| 1810 | -} |
|
| 1881 | + if ( $user ) { |
|
| 1882 | + $wpdb->insert( $wpdb->registration_log, array('email' => $user->user_email, 'IP' => preg_replace( '/[^0-9., ]/', '', wp_unslash( $_SERVER['REMOTE_ADDR'] ) ), 'blog_id' => $blog_id, 'date_registered' => current_time('mysql')) ); |
|
| 1883 | + } |
|
| 1884 | + } |
|
| 1811 | 1885 | |
| 1812 | 1886 | /** |
| 1813 | 1887 | * Maintains a canonical list of terms by syncing terms created for each blog with the global terms table. |
@@ -1826,8 +1900,9 @@ discard block |
||
| 1826 | 1900 | global $wpdb; |
| 1827 | 1901 | static $global_terms_recurse = null; |
| 1828 | 1902 | |
| 1829 | - if ( !global_terms_enabled() ) |
|
| 1830 | - return $term_id; |
|
| 1903 | + if ( !global_terms_enabled() ) { |
|
| 1904 | + return $term_id; |
|
| 1905 | + } |
|
| 1831 | 1906 | |
| 1832 | 1907 | // prevent a race condition |
| 1833 | 1908 | $recurse_start = false; |
@@ -1847,8 +1922,9 @@ discard block |
||
| 1847 | 1922 | if ( null == $used_global_id ) { |
| 1848 | 1923 | $wpdb->insert( $wpdb->sitecategories, array( 'cat_ID' => $term_id, 'cat_name' => $c->name, 'category_nicename' => $c->slug ) ); |
| 1849 | 1924 | $global_id = $wpdb->insert_id; |
| 1850 | - if ( empty( $global_id ) ) |
|
| 1851 | - return $term_id; |
|
| 1925 | + if ( empty( $global_id ) ) { |
|
| 1926 | + return $term_id; |
|
| 1927 | + } |
|
| 1852 | 1928 | } else { |
| 1853 | 1929 | $max_global_id = $wpdb->get_var( "SELECT MAX(cat_ID) FROM $wpdb->sitecategories" ); |
| 1854 | 1930 | $max_local_id = $wpdb->get_var( "SELECT MAX(term_id) FROM $wpdb->terms" ); |
@@ -1867,8 +1943,9 @@ discard block |
||
| 1867 | 1943 | } |
| 1868 | 1944 | |
| 1869 | 1945 | if ( $global_id != $term_id ) { |
| 1870 | - if ( get_option( 'default_category' ) == $term_id ) |
|
| 1871 | - update_option( 'default_category', $global_id ); |
|
| 1946 | + if ( get_option( 'default_category' ) == $term_id ) { |
|
| 1947 | + update_option( 'default_category', $global_id ); |
|
| 1948 | + } |
|
| 1872 | 1949 | |
| 1873 | 1950 | $wpdb->update( $wpdb->terms, array('term_id' => $global_id), array('term_id' => $term_id) ); |
| 1874 | 1951 | $wpdb->update( $wpdb->term_taxonomy, array('term_id' => $global_id), array('term_id' => $term_id) ); |
@@ -1876,8 +1953,9 @@ discard block |
||
| 1876 | 1953 | |
| 1877 | 1954 | clean_term_cache($term_id); |
| 1878 | 1955 | } |
| 1879 | - if ( $recurse_start ) |
|
| 1880 | - $global_terms_recurse = null; |
|
| 1956 | + if ( $recurse_start ) { |
|
| 1957 | + $global_terms_recurse = null; |
|
| 1958 | + } |
|
| 1881 | 1959 | |
| 1882 | 1960 | return $global_id; |
| 1883 | 1961 | } |
@@ -1903,11 +1981,13 @@ discard block |
||
| 1903 | 1981 | * @return string|array If the upload is under the size limit, $upload is returned. Otherwise returns an error message. |
| 1904 | 1982 | */ |
| 1905 | 1983 | function upload_is_file_too_big( $upload ) { |
| 1906 | - if ( ! is_array( $upload ) || defined( 'WP_IMPORTING' ) || get_site_option( 'upload_space_check_disabled' ) ) |
|
| 1907 | - return $upload; |
|
| 1984 | + if ( ! is_array( $upload ) || defined( 'WP_IMPORTING' ) || get_site_option( 'upload_space_check_disabled' ) ) { |
|
| 1985 | + return $upload; |
|
| 1986 | + } |
|
| 1908 | 1987 | |
| 1909 | - if ( strlen( $upload['bits'] ) > ( 1024 * get_site_option( 'fileupload_maxk', 1500 ) ) ) |
|
| 1910 | - return sprintf( __( 'This file is too big. Files must be less than %d KB in size.' ) . '<br />', get_site_option( 'fileupload_maxk', 1500 )); |
|
| 1988 | + if ( strlen( $upload['bits'] ) > ( 1024 * get_site_option( 'fileupload_maxk', 1500 ) ) ) { |
|
| 1989 | + return sprintf( __( 'This file is too big. Files must be less than %d KB in size.' ) . '<br />', get_site_option( 'fileupload_maxk', 1500 )); |
|
| 1990 | + } |
|
| 1911 | 1991 | |
| 1912 | 1992 | return $upload; |
| 1913 | 1993 | } |
@@ -1932,11 +2012,13 @@ discard block |
||
| 1932 | 2012 | * @return array |
| 1933 | 2013 | */ |
| 1934 | 2014 | function signup_nonce_check( $result ) { |
| 1935 | - if ( !strpos( $_SERVER[ 'PHP_SELF' ], 'wp-signup.php' ) ) |
|
| 1936 | - return $result; |
|
| 2015 | + if ( !strpos( $_SERVER[ 'PHP_SELF' ], 'wp-signup.php' ) ) { |
|
| 2016 | + return $result; |
|
| 2017 | + } |
|
| 1937 | 2018 | |
| 1938 | - if ( wp_create_nonce('signup_form_' . $_POST[ 'signup_form_id' ]) != $_POST['_signup_form'] ) |
|
| 1939 | - wp_die( __( 'Please try again.' ) ); |
|
| 2019 | + if ( wp_create_nonce('signup_form_' . $_POST[ 'signup_form_id' ]) != $_POST['_signup_form'] ) { |
|
| 2020 | + wp_die( __( 'Please try again.' ) ); |
|
| 2021 | + } |
|
| 1940 | 2022 | |
| 1941 | 2023 | return $result; |
| 1942 | 2024 | } |
@@ -1957,8 +2039,9 @@ discard block |
||
| 1957 | 2039 | * @param string $no_blog_redirect The redirect URL defined in NOBLOGREDIRECT. |
| 1958 | 2040 | */ |
| 1959 | 2041 | if ( is_main_site() && is_404() && defined( 'NOBLOGREDIRECT' ) && ( $destination = apply_filters( 'blog_redirect_404', NOBLOGREDIRECT ) ) ) { |
| 1960 | - if ( $destination == '%siteurl%' ) |
|
| 1961 | - $destination = network_home_url(); |
|
| 2042 | + if ( $destination == '%siteurl%' ) { |
|
| 2043 | + $destination = network_home_url(); |
|
| 2044 | + } |
|
| 1962 | 2045 | wp_redirect( $destination ); |
| 1963 | 2046 | exit(); |
| 1964 | 2047 | } |
@@ -1974,21 +2057,25 @@ discard block |
||
| 1974 | 2057 | * @since MU |
| 1975 | 2058 | */ |
| 1976 | 2059 | function maybe_add_existing_user_to_blog() { |
| 1977 | - if ( false === strpos( $_SERVER[ 'REQUEST_URI' ], '/newbloguser/' ) ) |
|
| 1978 | - return; |
|
| 2060 | + if ( false === strpos( $_SERVER[ 'REQUEST_URI' ], '/newbloguser/' ) ) { |
|
| 2061 | + return; |
|
| 2062 | + } |
|
| 1979 | 2063 | |
| 1980 | 2064 | $parts = explode( '/', $_SERVER[ 'REQUEST_URI' ] ); |
| 1981 | 2065 | $key = array_pop( $parts ); |
| 1982 | 2066 | |
| 1983 | - if ( $key == '' ) |
|
| 1984 | - $key = array_pop( $parts ); |
|
| 2067 | + if ( $key == '' ) { |
|
| 2068 | + $key = array_pop( $parts ); |
|
| 2069 | + } |
|
| 1985 | 2070 | |
| 1986 | 2071 | $details = get_option( 'new_user_' . $key ); |
| 1987 | - if ( !empty( $details ) ) |
|
| 1988 | - delete_option( 'new_user_' . $key ); |
|
| 2072 | + if ( !empty( $details ) ) { |
|
| 2073 | + delete_option( 'new_user_' . $key ); |
|
| 2074 | + } |
|
| 1989 | 2075 | |
| 1990 | - if ( empty( $details ) || is_wp_error( add_existing_user_to_blog( $details ) ) ) |
|
| 1991 | - wp_die( sprintf(__('An error occurred adding you to this site. Back to the <a href="%s">homepage</a>.'), home_url() ) ); |
|
| 2076 | + if ( empty( $details ) || is_wp_error( add_existing_user_to_blog( $details ) ) ) { |
|
| 2077 | + wp_die( sprintf(__('An error occurred adding you to this site. Back to the <a href="%s">homepage</a>.'), home_url() ) ); |
|
| 2078 | + } |
|
| 1992 | 2079 | |
| 1993 | 2080 | wp_die( sprintf( __( 'You have been added to this site. Please visit the <a href="%s">homepage</a> or <a href="%s">log in</a> using your username and password.' ), home_url(), admin_url() ), __( 'WordPress › Success' ), array( 'response' => 200 ) ); |
| 1994 | 2081 | } |
@@ -2187,11 +2274,14 @@ discard block |
||
| 2187 | 2274 | * @return string URL with https as the scheme |
| 2188 | 2275 | */ |
| 2189 | 2276 | function filter_SSL( $url ) { |
| 2190 | - if ( ! is_string( $url ) ) |
|
| 2191 | - return get_bloginfo( 'url' ); // Return home blog url with proper scheme |
|
| 2277 | + if ( ! is_string( $url ) ) { |
|
| 2278 | + return get_bloginfo( 'url' ); |
|
| 2279 | + } |
|
| 2280 | + // Return home blog url with proper scheme |
|
| 2192 | 2281 | |
| 2193 | - if ( force_ssl_content() && is_ssl() ) |
|
| 2194 | - $url = set_url_scheme( $url, 'https' ); |
|
| 2282 | + if ( force_ssl_content() && is_ssl() ) { |
|
| 2283 | + $url = set_url_scheme( $url, 'https' ); |
|
| 2284 | + } |
|
| 2195 | 2285 | |
| 2196 | 2286 | return $url; |
| 2197 | 2287 | } |
@@ -2202,12 +2292,14 @@ discard block |
||
| 2202 | 2292 | * @since 3.1.0 |
| 2203 | 2293 | */ |
| 2204 | 2294 | function wp_schedule_update_network_counts() { |
| 2205 | - if ( !is_main_site() ) |
|
| 2206 | - return; |
|
| 2295 | + if ( !is_main_site() ) { |
|
| 2296 | + return; |
|
| 2297 | + } |
|
| 2207 | 2298 | |
| 2208 | - if ( !wp_next_scheduled('update_network_counts') && !defined('WP_INSTALLING') ) |
|
| 2209 | - wp_schedule_event(time(), 'twicedaily', 'update_network_counts'); |
|
| 2210 | -} |
|
| 2299 | + if ( !wp_next_scheduled('update_network_counts') && !defined('WP_INSTALLING') ) { |
|
| 2300 | + wp_schedule_event(time(), 'twicedaily', 'update_network_counts'); |
|
| 2301 | + } |
|
| 2302 | + } |
|
| 2211 | 2303 | |
| 2212 | 2304 | /** |
| 2213 | 2305 | * Update the network-wide counts for the current network. |
@@ -2240,8 +2332,9 @@ discard block |
||
| 2240 | 2332 | * @param bool $small_network Whether the network is considered small. |
| 2241 | 2333 | * @param string $context Context. Either 'users' or 'sites'. |
| 2242 | 2334 | */ |
| 2243 | - if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'sites' ) ) |
|
| 2244 | - return; |
|
| 2335 | + if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'sites' ) ) { |
|
| 2336 | + return; |
|
| 2337 | + } |
|
| 2245 | 2338 | |
| 2246 | 2339 | wp_update_network_site_counts(); |
| 2247 | 2340 | } |
@@ -2258,8 +2351,9 @@ discard block |
||
| 2258 | 2351 | $is_small_network = ! wp_is_large_network( 'users' ); |
| 2259 | 2352 | |
| 2260 | 2353 | /** This filter is documented in wp-includes/ms-functions.php */ |
| 2261 | - if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'users' ) ) |
|
| 2262 | - return; |
|
| 2354 | + if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'users' ) ) { |
|
| 2355 | + return; |
|
| 2356 | + } |
|
| 2263 | 2357 | |
| 2264 | 2358 | wp_update_network_user_counts(); |
| 2265 | 2359 | } |
@@ -2326,11 +2420,13 @@ discard block |
||
| 2326 | 2420 | function get_space_allowed() { |
| 2327 | 2421 | $space_allowed = get_option( 'blog_upload_space' ); |
| 2328 | 2422 | |
| 2329 | - if ( ! is_numeric( $space_allowed ) ) |
|
| 2330 | - $space_allowed = get_site_option( 'blog_upload_space' ); |
|
| 2423 | + if ( ! is_numeric( $space_allowed ) ) { |
|
| 2424 | + $space_allowed = get_site_option( 'blog_upload_space' ); |
|
| 2425 | + } |
|
| 2331 | 2426 | |
| 2332 | - if ( empty( $space_allowed ) || ! is_numeric( $space_allowed ) ) |
|
| 2333 | - $space_allowed = 100; |
|
| 2427 | + if ( empty( $space_allowed ) || ! is_numeric( $space_allowed ) ) { |
|
| 2428 | + $space_allowed = 100; |
|
| 2429 | + } |
|
| 2334 | 2430 | |
| 2335 | 2431 | /** |
| 2336 | 2432 | * Filter the upload quota for the current site. |
@@ -2351,13 +2447,15 @@ discard block |
||
| 2351 | 2447 | */ |
| 2352 | 2448 | function get_upload_space_available() { |
| 2353 | 2449 | $space_allowed = get_space_allowed() * 1024 * 1024; |
| 2354 | - if ( get_site_option( 'upload_space_check_disabled' ) ) |
|
| 2355 | - return $space_allowed; |
|
| 2450 | + if ( get_site_option( 'upload_space_check_disabled' ) ) { |
|
| 2451 | + return $space_allowed; |
|
| 2452 | + } |
|
| 2356 | 2453 | |
| 2357 | 2454 | $space_used = get_space_used() * 1024 * 1024; |
| 2358 | 2455 | |
| 2359 | - if ( ( $space_allowed - $space_used ) <= 0 ) |
|
| 2360 | - return 0; |
|
| 2456 | + if ( ( $space_allowed - $space_used ) <= 0 ) { |
|
| 2457 | + return 0; |
|
| 2458 | + } |
|
| 2361 | 2459 | |
| 2362 | 2460 | return $space_allowed - $space_used; |
| 2363 | 2461 | } |
@@ -2369,8 +2467,9 @@ discard block |
||
| 2369 | 2467 | * @return bool True if space is available, false otherwise. |
| 2370 | 2468 | */ |
| 2371 | 2469 | function is_upload_space_available() { |
| 2372 | - if ( get_site_option( 'upload_space_check_disabled' ) ) |
|
| 2373 | - return true; |
|
| 2470 | + if ( get_site_option( 'upload_space_check_disabled' ) ) { |
|
| 2471 | + return true; |
|
| 2472 | + } |
|
| 2374 | 2473 | |
| 2375 | 2474 | return (bool) get_upload_space_available(); |
| 2376 | 2475 | } |
@@ -2382,8 +2481,9 @@ discard block |
||
| 2382 | 2481 | */ |
| 2383 | 2482 | function upload_size_limit_filter( $size ) { |
| 2384 | 2483 | $fileupload_maxk = 1024 * get_site_option( 'fileupload_maxk', 1500 ); |
| 2385 | - if ( get_site_option( 'upload_space_check_disabled' ) ) |
|
| 2386 | - return min( $size, $fileupload_maxk ); |
|
| 2484 | + if ( get_site_option( 'upload_space_check_disabled' ) ) { |
|
| 2485 | + return min( $size, $fileupload_maxk ); |
|
| 2486 | + } |
|
| 2387 | 2487 | |
| 2388 | 2488 | return min( $size, $fileupload_maxk, get_upload_space_available() ); |
| 2389 | 2489 | } |
@@ -2447,8 +2547,9 @@ discard block |
||
| 2447 | 2547 | function wp_get_sites( $args = array() ) { |
| 2448 | 2548 | global $wpdb; |
| 2449 | 2549 | |
| 2450 | - if ( wp_is_large_network() ) |
|
| 2451 | - return array(); |
|
| 2550 | + if ( wp_is_large_network() ) { |
|
| 2551 | + return array(); |
|
| 2552 | + } |
|
| 2452 | 2553 | |
| 2453 | 2554 | $defaults = array( |
| 2454 | 2555 | 'network_id' => $wpdb->siteid, |
@@ -2470,26 +2571,32 @@ discard block |
||
| 2470 | 2571 | $query .= "AND site_id IN ($network_ids) "; |
| 2471 | 2572 | } |
| 2472 | 2573 | |
| 2473 | - if ( isset( $args['public'] ) ) |
|
| 2474 | - $query .= $wpdb->prepare( "AND public = %d ", $args['public'] ); |
|
| 2574 | + if ( isset( $args['public'] ) ) { |
|
| 2575 | + $query .= $wpdb->prepare( "AND public = %d ", $args['public'] ); |
|
| 2576 | + } |
|
| 2475 | 2577 | |
| 2476 | - if ( isset( $args['archived'] ) ) |
|
| 2477 | - $query .= $wpdb->prepare( "AND archived = %d ", $args['archived'] ); |
|
| 2578 | + if ( isset( $args['archived'] ) ) { |
|
| 2579 | + $query .= $wpdb->prepare( "AND archived = %d ", $args['archived'] ); |
|
| 2580 | + } |
|
| 2478 | 2581 | |
| 2479 | - if ( isset( $args['mature'] ) ) |
|
| 2480 | - $query .= $wpdb->prepare( "AND mature = %d ", $args['mature'] ); |
|
| 2582 | + if ( isset( $args['mature'] ) ) { |
|
| 2583 | + $query .= $wpdb->prepare( "AND mature = %d ", $args['mature'] ); |
|
| 2584 | + } |
|
| 2481 | 2585 | |
| 2482 | - if ( isset( $args['spam'] ) ) |
|
| 2483 | - $query .= $wpdb->prepare( "AND spam = %d ", $args['spam'] ); |
|
| 2586 | + if ( isset( $args['spam'] ) ) { |
|
| 2587 | + $query .= $wpdb->prepare( "AND spam = %d ", $args['spam'] ); |
|
| 2588 | + } |
|
| 2484 | 2589 | |
| 2485 | - if ( isset( $args['deleted'] ) ) |
|
| 2486 | - $query .= $wpdb->prepare( "AND deleted = %d ", $args['deleted'] ); |
|
| 2590 | + if ( isset( $args['deleted'] ) ) { |
|
| 2591 | + $query .= $wpdb->prepare( "AND deleted = %d ", $args['deleted'] ); |
|
| 2592 | + } |
|
| 2487 | 2593 | |
| 2488 | 2594 | if ( isset( $args['limit'] ) && $args['limit'] ) { |
| 2489 | - if ( isset( $args['offset'] ) && $args['offset'] ) |
|
| 2490 | - $query .= $wpdb->prepare( "LIMIT %d , %d ", $args['offset'], $args['limit'] ); |
|
| 2491 | - else |
|
| 2492 | - $query .= $wpdb->prepare( "LIMIT %d ", $args['limit'] ); |
|
| 2595 | + if ( isset( $args['offset'] ) && $args['offset'] ) { |
|
| 2596 | + $query .= $wpdb->prepare( "LIMIT %d , %d ", $args['offset'], $args['limit'] ); |
|
| 2597 | + } else { |
|
| 2598 | + $query .= $wpdb->prepare( "LIMIT %d ", $args['limit'] ); |
|
| 2599 | + } |
|
| 2493 | 2600 | } |
| 2494 | 2601 | |
| 2495 | 2602 | $site_results = $wpdb->get_results( $query, ARRAY_A ); |
@@ -65,7 +65,7 @@ |
||
| 65 | 65 | * |
| 66 | 66 | * @since 3.0.0 |
| 67 | 67 | * |
| 68 | - * @return true|string Returns true on success, or drop-in file to include. |
|
| 68 | + * @return boolean|string Returns true on success, or drop-in file to include. |
|
| 69 | 69 | */ |
| 70 | 70 | function ms_site_check() { |
| 71 | 71 | $blog = get_blog_details(); |
@@ -1,12 +1,12 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * These functions are needed to load Multisite. |
|
| 4 | - * |
|
| 5 | - * @since 3.0.0 |
|
| 6 | - * |
|
| 7 | - * @package WordPress |
|
| 8 | - * @subpackage Multisite |
|
| 9 | - */ |
|
| 3 | + * These functions are needed to load Multisite. |
|
| 4 | + * |
|
| 5 | + * @since 3.0.0 |
|
| 6 | + * |
|
| 7 | + * @package WordPress |
|
| 8 | + * @subpackage Multisite |
|
| 9 | + */ |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * Whether a subdomain configuration is enabled. |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * @since 3.0.0 |
| 77 | 77 | * |
| 78 | 78 | * @param bool null Whether to skip the blog status check. Default null. |
| 79 | - */ |
|
| 79 | + */ |
|
| 80 | 80 | $check = apply_filters( 'ms_site_check', null ); |
| 81 | 81 | if ( null !== $check ) |
| 82 | 82 | return true; |
@@ -16,10 +16,10 @@ discard block |
||
| 16 | 16 | * @return bool True if subdomain configuration is enabled, false otherwise. |
| 17 | 17 | */ |
| 18 | 18 | function is_subdomain_install() { |
| 19 | - if ( defined('SUBDOMAIN_INSTALL') ) |
|
| 19 | + if (defined('SUBDOMAIN_INSTALL')) |
|
| 20 | 20 | return SUBDOMAIN_INSTALL; |
| 21 | 21 | |
| 22 | - return ( defined( 'VHOST' ) && VHOST == 'yes' ); |
|
| 22 | + return (defined('VHOST') && VHOST == 'yes'); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /** |
@@ -34,20 +34,20 @@ discard block |
||
| 34 | 34 | * @return array Files to include. |
| 35 | 35 | */ |
| 36 | 36 | function wp_get_active_network_plugins() { |
| 37 | - $active_plugins = (array) get_site_option( 'active_sitewide_plugins', array() ); |
|
| 38 | - if ( empty( $active_plugins ) ) |
|
| 37 | + $active_plugins = (array) get_site_option('active_sitewide_plugins', array()); |
|
| 38 | + if (empty($active_plugins)) |
|
| 39 | 39 | return array(); |
| 40 | 40 | |
| 41 | 41 | $plugins = array(); |
| 42 | - $active_plugins = array_keys( $active_plugins ); |
|
| 43 | - sort( $active_plugins ); |
|
| 42 | + $active_plugins = array_keys($active_plugins); |
|
| 43 | + sort($active_plugins); |
|
| 44 | 44 | |
| 45 | - foreach ( $active_plugins as $plugin ) { |
|
| 46 | - if ( ! validate_file( $plugin ) // $plugin must validate as file |
|
| 47 | - && '.php' == substr( $plugin, -4 ) // $plugin must end with '.php' |
|
| 48 | - && file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist |
|
| 45 | + foreach ($active_plugins as $plugin) { |
|
| 46 | + if ( ! validate_file($plugin) // $plugin must validate as file |
|
| 47 | + && '.php' == substr($plugin, -4) // $plugin must end with '.php' |
|
| 48 | + && file_exists(WP_PLUGIN_DIR.'/'.$plugin) // $plugin must exist |
|
| 49 | 49 | ) |
| 50 | - $plugins[] = WP_PLUGIN_DIR . '/' . $plugin; |
|
| 50 | + $plugins[] = WP_PLUGIN_DIR.'/'.$plugin; |
|
| 51 | 51 | } |
| 52 | 52 | return $plugins; |
| 53 | 53 | } |
@@ -77,33 +77,33 @@ discard block |
||
| 77 | 77 | * |
| 78 | 78 | * @param bool null Whether to skip the blog status check. Default null. |
| 79 | 79 | */ |
| 80 | - $check = apply_filters( 'ms_site_check', null ); |
|
| 81 | - if ( null !== $check ) |
|
| 80 | + $check = apply_filters('ms_site_check', null); |
|
| 81 | + if (null !== $check) |
|
| 82 | 82 | return true; |
| 83 | 83 | |
| 84 | 84 | // Allow super admins to see blocked sites |
| 85 | - if ( is_super_admin() ) |
|
| 85 | + if (is_super_admin()) |
|
| 86 | 86 | return true; |
| 87 | 87 | |
| 88 | - if ( '1' == $blog->deleted ) { |
|
| 89 | - if ( file_exists( WP_CONTENT_DIR . '/blog-deleted.php' ) ) |
|
| 90 | - return WP_CONTENT_DIR . '/blog-deleted.php'; |
|
| 88 | + if ('1' == $blog->deleted) { |
|
| 89 | + if (file_exists(WP_CONTENT_DIR.'/blog-deleted.php')) |
|
| 90 | + return WP_CONTENT_DIR.'/blog-deleted.php'; |
|
| 91 | 91 | else |
| 92 | - wp_die( __( 'This site is no longer available.' ), '', array( 'response' => 410 ) ); |
|
| 92 | + wp_die(__('This site is no longer available.'), '', array('response' => 410)); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - if ( '2' == $blog->deleted ) { |
|
| 96 | - if ( file_exists( WP_CONTENT_DIR . '/blog-inactive.php' ) ) |
|
| 97 | - return WP_CONTENT_DIR . '/blog-inactive.php'; |
|
| 95 | + if ('2' == $blog->deleted) { |
|
| 96 | + if (file_exists(WP_CONTENT_DIR.'/blog-inactive.php')) |
|
| 97 | + return WP_CONTENT_DIR.'/blog-inactive.php'; |
|
| 98 | 98 | else |
| 99 | - wp_die( sprintf( __( 'This site has not been activated yet. If you are having problems activating your site, please contact <a href="mailto:%1$s">%1$s</a>.' ), str_replace( '@', ' AT ', get_site_option( 'admin_email', 'support@' . get_current_site()->domain ) ) ) ); |
|
| 99 | + wp_die(sprintf(__('This site has not been activated yet. If you are having problems activating your site, please contact <a href="mailto:%1$s">%1$s</a>.'), str_replace('@', ' AT ', get_site_option('admin_email', 'support@'.get_current_site()->domain)))); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - if ( $blog->archived == '1' || $blog->spam == '1' ) { |
|
| 103 | - if ( file_exists( WP_CONTENT_DIR . '/blog-suspended.php' ) ) |
|
| 104 | - return WP_CONTENT_DIR . '/blog-suspended.php'; |
|
| 102 | + if ($blog->archived == '1' || $blog->spam == '1') { |
|
| 103 | + if (file_exists(WP_CONTENT_DIR.'/blog-suspended.php')) |
|
| 104 | + return WP_CONTENT_DIR.'/blog-suspended.php'; |
|
| 105 | 105 | else |
| 106 | - wp_die( __( 'This site has been archived or suspended.' ), '', array( 'response' => 410 ) ); |
|
| 106 | + wp_die(__('This site has been archived or suspended.'), '', array('response' => 410)); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | return true; |
@@ -121,19 +121,19 @@ discard block |
||
| 121 | 121 | * @param int|null $segments Path segments to use. Defaults to null, or the full path. |
| 122 | 122 | * @return object|false Network object if successful. False when no network is found. |
| 123 | 123 | */ |
| 124 | -function get_network_by_path( $domain, $path, $segments = null ) { |
|
| 124 | +function get_network_by_path($domain, $path, $segments = null) { |
|
| 125 | 125 | global $wpdb; |
| 126 | 126 | |
| 127 | - $domains = array( $domain ); |
|
| 128 | - $pieces = explode( '.', $domain ); |
|
| 127 | + $domains = array($domain); |
|
| 128 | + $pieces = explode('.', $domain); |
|
| 129 | 129 | |
| 130 | 130 | /* |
| 131 | 131 | * It's possible one domain to search is 'com', but it might as well |
| 132 | 132 | * be 'localhost' or some other locally mapped domain. |
| 133 | 133 | */ |
| 134 | - while ( array_shift( $pieces ) ) { |
|
| 135 | - if ( $pieces ) { |
|
| 136 | - $domains[] = implode( '.', $pieces ); |
|
| 134 | + while (array_shift($pieces)) { |
|
| 135 | + if ($pieces) { |
|
| 136 | + $domains[] = implode('.', $pieces); |
|
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | |
@@ -147,17 +147,17 @@ discard block |
||
| 147 | 147 | * depending on the setup, so this is best done per-install. |
| 148 | 148 | */ |
| 149 | 149 | $using_paths = true; |
| 150 | - if ( wp_using_ext_object_cache() ) { |
|
| 151 | - $using_paths = wp_cache_get( 'networks_have_paths', 'site-options' ); |
|
| 152 | - if ( false === $using_paths ) { |
|
| 153 | - $using_paths = (bool) $wpdb->get_var( "SELECT id FROM $wpdb->site WHERE path <> '/' LIMIT 1" ); |
|
| 154 | - wp_cache_add( 'networks_have_paths', (int) $using_paths, 'site-options' ); |
|
| 150 | + if (wp_using_ext_object_cache()) { |
|
| 151 | + $using_paths = wp_cache_get('networks_have_paths', 'site-options'); |
|
| 152 | + if (false === $using_paths) { |
|
| 153 | + $using_paths = (bool) $wpdb->get_var("SELECT id FROM $wpdb->site WHERE path <> '/' LIMIT 1"); |
|
| 154 | + wp_cache_add('networks_have_paths', (int) $using_paths, 'site-options'); |
|
| 155 | 155 | } |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | $paths = array(); |
| 159 | - if ( $using_paths ) { |
|
| 160 | - $path_segments = array_filter( explode( '/', trim( $path, "/" ) ) ); |
|
| 159 | + if ($using_paths) { |
|
| 160 | + $path_segments = array_filter(explode('/', trim($path, "/"))); |
|
| 161 | 161 | |
| 162 | 162 | /** |
| 163 | 163 | * Filter the number of path segments to consider when searching for a site. |
@@ -170,15 +170,15 @@ discard block |
||
| 170 | 170 | * @param string $domain The requested domain. |
| 171 | 171 | * @param string $path The requested path, in full. |
| 172 | 172 | */ |
| 173 | - $segments = apply_filters( 'network_by_path_segments_count', $segments, $domain, $path ); |
|
| 173 | + $segments = apply_filters('network_by_path_segments_count', $segments, $domain, $path); |
|
| 174 | 174 | |
| 175 | - if ( null !== $segments && count($path_segments ) > $segments ) { |
|
| 176 | - $path_segments = array_slice( $path_segments, 0, $segments ); |
|
| 175 | + if (null !== $segments && count($path_segments) > $segments) { |
|
| 176 | + $path_segments = array_slice($path_segments, 0, $segments); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | - while ( count( $path_segments ) ) { |
|
| 180 | - $paths[] = '/' . implode( '/', $path_segments ) . '/'; |
|
| 181 | - array_pop( $path_segments ); |
|
| 179 | + while (count($path_segments)) { |
|
| 180 | + $paths[] = '/'.implode('/', $path_segments).'/'; |
|
| 181 | + array_pop($path_segments); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | $paths[] = '/'; |
@@ -203,29 +203,29 @@ discard block |
||
| 203 | 203 | * Default null, meaning the entire path was to be consulted. |
| 204 | 204 | * @param array $paths The paths to search for, based on $path and $segments. |
| 205 | 205 | */ |
| 206 | - $pre = apply_filters( 'pre_get_network_by_path', null, $domain, $path, $segments, $paths ); |
|
| 207 | - if ( null !== $pre ) { |
|
| 206 | + $pre = apply_filters('pre_get_network_by_path', null, $domain, $path, $segments, $paths); |
|
| 207 | + if (null !== $pre) { |
|
| 208 | 208 | return $pre; |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | // @todo Consider additional optimization routes, perhaps as an opt-in for plugins. |
| 212 | 212 | // We already have paths covered. What about how far domains should be drilled down (including www)? |
| 213 | 213 | |
| 214 | - $search_domains = "'" . implode( "', '", $wpdb->_escape( $domains ) ) . "'"; |
|
| 214 | + $search_domains = "'".implode("', '", $wpdb->_escape($domains))."'"; |
|
| 215 | 215 | |
| 216 | - if ( ! $using_paths ) { |
|
| 217 | - $network = $wpdb->get_row( "SELECT id, domain, path FROM $wpdb->site |
|
| 218 | - WHERE domain IN ($search_domains) ORDER BY CHAR_LENGTH(domain) DESC LIMIT 1" ); |
|
| 219 | - if ( $network ) { |
|
| 220 | - return wp_get_network( $network ); |
|
| 216 | + if ( ! $using_paths) { |
|
| 217 | + $network = $wpdb->get_row("SELECT id, domain, path FROM $wpdb->site |
|
| 218 | + WHERE domain IN ($search_domains) ORDER BY CHAR_LENGTH(domain) DESC LIMIT 1"); |
|
| 219 | + if ($network) { |
|
| 220 | + return wp_get_network($network); |
|
| 221 | 221 | } |
| 222 | 222 | return false; |
| 223 | 223 | |
| 224 | 224 | } else { |
| 225 | - $search_paths = "'" . implode( "', '", $wpdb->_escape( $paths ) ) . "'"; |
|
| 226 | - $networks = $wpdb->get_results( "SELECT id, domain, path FROM $wpdb->site |
|
| 225 | + $search_paths = "'".implode("', '", $wpdb->_escape($paths))."'"; |
|
| 226 | + $networks = $wpdb->get_results("SELECT id, domain, path FROM $wpdb->site |
|
| 227 | 227 | WHERE domain IN ($search_domains) AND path IN ($search_paths) |
| 228 | - ORDER BY CHAR_LENGTH(domain) DESC, CHAR_LENGTH(path) DESC" ); |
|
| 228 | + ORDER BY CHAR_LENGTH(domain) DESC, CHAR_LENGTH(path) DESC"); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /* |
@@ -234,21 +234,21 @@ discard block |
||
| 234 | 234 | * a network with the path of / will suffice. |
| 235 | 235 | */ |
| 236 | 236 | $found = false; |
| 237 | - foreach ( $networks as $network ) { |
|
| 238 | - if ( $network->domain === $domain || "www.$network->domain" === $domain ) { |
|
| 239 | - if ( in_array( $network->path, $paths, true ) ) { |
|
| 237 | + foreach ($networks as $network) { |
|
| 238 | + if ($network->domain === $domain || "www.$network->domain" === $domain) { |
|
| 239 | + if (in_array($network->path, $paths, true)) { |
|
| 240 | 240 | $found = true; |
| 241 | 241 | break; |
| 242 | 242 | } |
| 243 | 243 | } |
| 244 | - if ( $network->path === '/' ) { |
|
| 244 | + if ($network->path === '/') { |
|
| 245 | 245 | $found = true; |
| 246 | 246 | break; |
| 247 | 247 | } |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | - if ( $found ) { |
|
| 251 | - return wp_get_network( $network ); |
|
| 250 | + if ($found) { |
|
| 251 | + return wp_get_network($network); |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | return false; |
@@ -264,12 +264,12 @@ discard block |
||
| 264 | 264 | * @param object|int $network The network's database row or ID. |
| 265 | 265 | * @return object|false Object containing network information if found, false if not. |
| 266 | 266 | */ |
| 267 | -function wp_get_network( $network ) { |
|
| 267 | +function wp_get_network($network) { |
|
| 268 | 268 | global $wpdb; |
| 269 | 269 | |
| 270 | - if ( ! is_object( $network ) ) { |
|
| 271 | - $network = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->site WHERE id = %d", $network ) ); |
|
| 272 | - if ( ! $network ) { |
|
| 270 | + if ( ! is_object($network)) { |
|
| 271 | + $network = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->site WHERE id = %d", $network)); |
|
| 272 | + if ( ! $network) { |
|
| 273 | 273 | return false; |
| 274 | 274 | } |
| 275 | 275 | } |
@@ -289,10 +289,10 @@ discard block |
||
| 289 | 289 | * @param int|null $segments Path segments to use. Defaults to null, or the full path. |
| 290 | 290 | * @return object|false Site object if successful. False when no site is found. |
| 291 | 291 | */ |
| 292 | -function get_site_by_path( $domain, $path, $segments = null ) { |
|
| 292 | +function get_site_by_path($domain, $path, $segments = null) { |
|
| 293 | 293 | global $wpdb; |
| 294 | 294 | |
| 295 | - $path_segments = array_filter( explode( '/', trim( $path, '/' ) ) ); |
|
| 295 | + $path_segments = array_filter(explode('/', trim($path, '/'))); |
|
| 296 | 296 | |
| 297 | 297 | /** |
| 298 | 298 | * Filter the number of path segments to consider when searching for a site. |
@@ -305,17 +305,17 @@ discard block |
||
| 305 | 305 | * @param string $domain The requested domain. |
| 306 | 306 | * @param string $path The requested path, in full. |
| 307 | 307 | */ |
| 308 | - $segments = apply_filters( 'site_by_path_segments_count', $segments, $domain, $path ); |
|
| 308 | + $segments = apply_filters('site_by_path_segments_count', $segments, $domain, $path); |
|
| 309 | 309 | |
| 310 | - if ( null !== $segments && count( $path_segments ) > $segments ) { |
|
| 311 | - $path_segments = array_slice( $path_segments, 0, $segments ); |
|
| 310 | + if (null !== $segments && count($path_segments) > $segments) { |
|
| 311 | + $path_segments = array_slice($path_segments, 0, $segments); |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | $paths = array(); |
| 315 | 315 | |
| 316 | - while ( count( $path_segments ) ) { |
|
| 317 | - $paths[] = '/' . implode( '/', $path_segments ) . '/'; |
|
| 318 | - array_pop( $path_segments ); |
|
| 316 | + while (count($path_segments)) { |
|
| 317 | + $paths[] = '/'.implode('/', $path_segments).'/'; |
|
| 318 | + array_pop($path_segments); |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | $paths[] = '/'; |
@@ -339,8 +339,8 @@ discard block |
||
| 339 | 339 | * Default null, meaning the entire path was to be consulted. |
| 340 | 340 | * @param array $paths The paths to search for, based on $path and $segments. |
| 341 | 341 | */ |
| 342 | - $pre = apply_filters( 'pre_get_site_by_path', null, $domain, $path, $segments, $paths ); |
|
| 343 | - if ( null !== $pre ) { |
|
| 342 | + $pre = apply_filters('pre_get_site_by_path', null, $domain, $path, $segments, $paths); |
|
| 343 | + if (null !== $pre) { |
|
| 344 | 344 | return $pre; |
| 345 | 345 | } |
| 346 | 346 | |
@@ -355,31 +355,31 @@ discard block |
||
| 355 | 355 | |
| 356 | 356 | // Either www or non-www is supported, not both. If a www domain is requested, |
| 357 | 357 | // query for both to provide the proper redirect. |
| 358 | - $domains = array( $domain ); |
|
| 359 | - if ( 'www.' === substr( $domain, 0, 4 ) ) { |
|
| 360 | - $domains[] = substr( $domain, 4 ); |
|
| 361 | - $search_domains = "'" . implode( "', '", $wpdb->_escape( $domains ) ) . "'"; |
|
| 358 | + $domains = array($domain); |
|
| 359 | + if ('www.' === substr($domain, 0, 4)) { |
|
| 360 | + $domains[] = substr($domain, 4); |
|
| 361 | + $search_domains = "'".implode("', '", $wpdb->_escape($domains))."'"; |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | - if ( count( $paths ) > 1 ) { |
|
| 365 | - $search_paths = "'" . implode( "', '", $wpdb->_escape( $paths ) ) . "'"; |
|
| 364 | + if (count($paths) > 1) { |
|
| 365 | + $search_paths = "'".implode("', '", $wpdb->_escape($paths))."'"; |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | - if ( count( $domains ) > 1 && count( $paths ) > 1 ) { |
|
| 369 | - $site = $wpdb->get_row( "SELECT * FROM $wpdb->blogs WHERE domain IN ($search_domains) AND path IN ($search_paths) ORDER BY CHAR_LENGTH(domain) DESC, CHAR_LENGTH(path) DESC LIMIT 1" ); |
|
| 370 | - } elseif ( count( $domains ) > 1 ) { |
|
| 371 | - $sql = $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE path = %s", $paths[0] ); |
|
| 368 | + if (count($domains) > 1 && count($paths) > 1) { |
|
| 369 | + $site = $wpdb->get_row("SELECT * FROM $wpdb->blogs WHERE domain IN ($search_domains) AND path IN ($search_paths) ORDER BY CHAR_LENGTH(domain) DESC, CHAR_LENGTH(path) DESC LIMIT 1"); |
|
| 370 | + } elseif (count($domains) > 1) { |
|
| 371 | + $sql = $wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE path = %s", $paths[0]); |
|
| 372 | 372 | $sql .= " AND domain IN ($search_domains) ORDER BY CHAR_LENGTH(domain) DESC LIMIT 1"; |
| 373 | - $site = $wpdb->get_row( $sql ); |
|
| 374 | - } elseif ( count( $paths ) > 1 ) { |
|
| 375 | - $sql = $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s", $domains[0] ); |
|
| 373 | + $site = $wpdb->get_row($sql); |
|
| 374 | + } elseif (count($paths) > 1) { |
|
| 375 | + $sql = $wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE domain = %s", $domains[0]); |
|
| 376 | 376 | $sql .= " AND path IN ($search_paths) ORDER BY CHAR_LENGTH(path) DESC LIMIT 1"; |
| 377 | - $site = $wpdb->get_row( $sql ); |
|
| 377 | + $site = $wpdb->get_row($sql); |
|
| 378 | 378 | } else { |
| 379 | - $site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $domains[0], $paths[0] ) ); |
|
| 379 | + $site = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $domains[0], $paths[0])); |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | - if ( $site ) { |
|
| 382 | + if ($site) { |
|
| 383 | 383 | // @todo get_blog_details() |
| 384 | 384 | return $site; |
| 385 | 385 | } |
@@ -402,44 +402,44 @@ discard block |
||
| 402 | 402 | function ms_not_installed() { |
| 403 | 403 | global $wpdb, $domain, $path; |
| 404 | 404 | |
| 405 | - if ( ! is_admin() ) { |
|
| 405 | + if ( ! is_admin()) { |
|
| 406 | 406 | dead_db(); |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | wp_load_translations_early(); |
| 410 | 410 | |
| 411 | - $title = __( 'Error establishing a database connection' ); |
|
| 411 | + $title = __('Error establishing a database connection'); |
|
| 412 | 412 | |
| 413 | - $msg = '<h1>' . $title . '</h1>'; |
|
| 414 | - $msg .= '<p>' . __( 'If your site does not display, please contact the owner of this network.' ) . ''; |
|
| 415 | - $msg .= ' ' . __( 'If you are the owner of this network please check that MySQL is running properly and all tables are error free.' ) . '</p>'; |
|
| 416 | - $query = $wpdb->prepare( "SHOW TABLES LIKE %s", $wpdb->esc_like( $wpdb->site ) ); |
|
| 417 | - if ( ! $wpdb->get_var( $query ) ) { |
|
| 418 | - $msg .= '<p>' . sprintf( |
|
| 413 | + $msg = '<h1>'.$title.'</h1>'; |
|
| 414 | + $msg .= '<p>'.__('If your site does not display, please contact the owner of this network.').''; |
|
| 415 | + $msg .= ' '.__('If you are the owner of this network please check that MySQL is running properly and all tables are error free.').'</p>'; |
|
| 416 | + $query = $wpdb->prepare("SHOW TABLES LIKE %s", $wpdb->esc_like($wpdb->site)); |
|
| 417 | + if ( ! $wpdb->get_var($query)) { |
|
| 418 | + $msg .= '<p>'.sprintf( |
|
| 419 | 419 | /* translators: %s: table name */ |
| 420 | - __( '<strong>Database tables are missing.</strong> This means that MySQL is not running, WordPress was not installed properly, or someone deleted %s. You really should look at your database now.' ), |
|
| 421 | - '<code>' . $wpdb->site . '</code>' |
|
| 422 | - ) . '</p>'; |
|
| 420 | + __('<strong>Database tables are missing.</strong> This means that MySQL is not running, WordPress was not installed properly, or someone deleted %s. You really should look at your database now.'), |
|
| 421 | + '<code>'.$wpdb->site.'</code>' |
|
| 422 | + ).'</p>'; |
|
| 423 | 423 | } else { |
| 424 | - $msg .= '<p>' . sprintf( |
|
| 424 | + $msg .= '<p>'.sprintf( |
|
| 425 | 425 | /* translators: 1: site url, 2: table name, 3: database name */ |
| 426 | - __( '<strong>Could not find site %1$s.</strong> Searched for table %2$s in database %3$s. Is that right?' ), |
|
| 427 | - '<code>' . rtrim( $domain . $path, '/' ) . '</code>', |
|
| 428 | - '<code>' . $wpdb->blogs . '</code>', |
|
| 429 | - '<code>' . DB_NAME . '</code>' |
|
| 430 | - ) . '</p>'; |
|
| 426 | + __('<strong>Could not find site %1$s.</strong> Searched for table %2$s in database %3$s. Is that right?'), |
|
| 427 | + '<code>'.rtrim($domain.$path, '/').'</code>', |
|
| 428 | + '<code>'.$wpdb->blogs.'</code>', |
|
| 429 | + '<code>'.DB_NAME.'</code>' |
|
| 430 | + ).'</p>'; |
|
| 431 | 431 | } |
| 432 | - $msg .= '<p><strong>' . __( 'What do I do now?' ) . '</strong> '; |
|
| 433 | - $msg .= __( 'Read the <a target="_blank" href="https://codex.wordpress.org/Debugging_a_WordPress_Network">bug report</a> page. Some of the guidelines there may help you figure out what went wrong.' ); |
|
| 434 | - $msg .= ' ' . __( 'If you’re still stuck with this message, then check that your database contains the following tables:' ) . '</p><ul>'; |
|
| 435 | - foreach ( $wpdb->tables('global') as $t => $table ) { |
|
| 436 | - if ( 'sitecategories' == $t ) |
|
| 432 | + $msg .= '<p><strong>'.__('What do I do now?').'</strong> '; |
|
| 433 | + $msg .= __('Read the <a target="_blank" href="https://codex.wordpress.org/Debugging_a_WordPress_Network">bug report</a> page. Some of the guidelines there may help you figure out what went wrong.'); |
|
| 434 | + $msg .= ' '.__('If you’re still stuck with this message, then check that your database contains the following tables:').'</p><ul>'; |
|
| 435 | + foreach ($wpdb->tables('global') as $t => $table) { |
|
| 436 | + if ('sitecategories' == $t) |
|
| 437 | 437 | continue; |
| 438 | - $msg .= '<li>' . $table . '</li>'; |
|
| 438 | + $msg .= '<li>'.$table.'</li>'; |
|
| 439 | 439 | } |
| 440 | 440 | $msg .= '</ul>'; |
| 441 | 441 | |
| 442 | - wp_die( $msg, $title, array( 'response' => 500 ) ); |
|
| 442 | + wp_die($msg, $title, array('response' => 500)); |
|
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | /** |
@@ -455,8 +455,8 @@ discard block |
||
| 455 | 455 | * @param object $current_site |
| 456 | 456 | * @return object |
| 457 | 457 | */ |
| 458 | -function get_current_site_name( $current_site ) { |
|
| 459 | - _deprecated_function( __FUNCTION__, '3.9', 'get_current_site()' ); |
|
| 458 | +function get_current_site_name($current_site) { |
|
| 459 | + _deprecated_function(__FUNCTION__, '3.9', 'get_current_site()'); |
|
| 460 | 460 | return $current_site; |
| 461 | 461 | } |
| 462 | 462 | |
@@ -476,6 +476,6 @@ discard block |
||
| 476 | 476 | */ |
| 477 | 477 | function wpmu_current_site() { |
| 478 | 478 | global $current_site; |
| 479 | - _deprecated_function( __FUNCTION__, '3.9' ); |
|
| 479 | + _deprecated_function(__FUNCTION__, '3.9'); |
|
| 480 | 480 | return $current_site; |
| 481 | 481 | } |
@@ -16,8 +16,9 @@ discard block |
||
| 16 | 16 | * @return bool True if subdomain configuration is enabled, false otherwise. |
| 17 | 17 | */ |
| 18 | 18 | function is_subdomain_install() { |
| 19 | - if ( defined('SUBDOMAIN_INSTALL') ) |
|
| 20 | - return SUBDOMAIN_INSTALL; |
|
| 19 | + if ( defined('SUBDOMAIN_INSTALL') ) { |
|
| 20 | + return SUBDOMAIN_INSTALL; |
|
| 21 | + } |
|
| 21 | 22 | |
| 22 | 23 | return ( defined( 'VHOST' ) && VHOST == 'yes' ); |
| 23 | 24 | } |
@@ -35,8 +36,9 @@ discard block |
||
| 35 | 36 | */ |
| 36 | 37 | function wp_get_active_network_plugins() { |
| 37 | 38 | $active_plugins = (array) get_site_option( 'active_sitewide_plugins', array() ); |
| 38 | - if ( empty( $active_plugins ) ) |
|
| 39 | - return array(); |
|
| 39 | + if ( empty( $active_plugins ) ) { |
|
| 40 | + return array(); |
|
| 41 | + } |
|
| 40 | 42 | |
| 41 | 43 | $plugins = array(); |
| 42 | 44 | $active_plugins = array_keys( $active_plugins ); |
@@ -46,8 +48,9 @@ discard block |
||
| 46 | 48 | if ( ! validate_file( $plugin ) // $plugin must validate as file |
| 47 | 49 | && '.php' == substr( $plugin, -4 ) // $plugin must end with '.php' |
| 48 | 50 | && file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist |
| 49 | - ) |
|
| 50 | - $plugins[] = WP_PLUGIN_DIR . '/' . $plugin; |
|
| 51 | + ) { |
|
| 52 | + $plugins[] = WP_PLUGIN_DIR . '/' . $plugin; |
|
| 53 | + } |
|
| 51 | 54 | } |
| 52 | 55 | return $plugins; |
| 53 | 56 | } |
@@ -78,32 +81,37 @@ discard block |
||
| 78 | 81 | * @param bool null Whether to skip the blog status check. Default null. |
| 79 | 82 | */ |
| 80 | 83 | $check = apply_filters( 'ms_site_check', null ); |
| 81 | - if ( null !== $check ) |
|
| 82 | - return true; |
|
| 84 | + if ( null !== $check ) { |
|
| 85 | + return true; |
|
| 86 | + } |
|
| 83 | 87 | |
| 84 | 88 | // Allow super admins to see blocked sites |
| 85 | - if ( is_super_admin() ) |
|
| 86 | - return true; |
|
| 89 | + if ( is_super_admin() ) { |
|
| 90 | + return true; |
|
| 91 | + } |
|
| 87 | 92 | |
| 88 | 93 | if ( '1' == $blog->deleted ) { |
| 89 | - if ( file_exists( WP_CONTENT_DIR . '/blog-deleted.php' ) ) |
|
| 90 | - return WP_CONTENT_DIR . '/blog-deleted.php'; |
|
| 91 | - else |
|
| 92 | - wp_die( __( 'This site is no longer available.' ), '', array( 'response' => 410 ) ); |
|
| 94 | + if ( file_exists( WP_CONTENT_DIR . '/blog-deleted.php' ) ) { |
|
| 95 | + return WP_CONTENT_DIR . '/blog-deleted.php'; |
|
| 96 | + } else { |
|
| 97 | + wp_die( __( 'This site is no longer available.' ), '', array( 'response' => 410 ) ); |
|
| 98 | + } |
|
| 93 | 99 | } |
| 94 | 100 | |
| 95 | 101 | if ( '2' == $blog->deleted ) { |
| 96 | - if ( file_exists( WP_CONTENT_DIR . '/blog-inactive.php' ) ) |
|
| 97 | - return WP_CONTENT_DIR . '/blog-inactive.php'; |
|
| 98 | - else |
|
| 99 | - wp_die( sprintf( __( 'This site has not been activated yet. If you are having problems activating your site, please contact <a href="mailto:%1$s">%1$s</a>.' ), str_replace( '@', ' AT ', get_site_option( 'admin_email', 'support@' . get_current_site()->domain ) ) ) ); |
|
| 102 | + if ( file_exists( WP_CONTENT_DIR . '/blog-inactive.php' ) ) { |
|
| 103 | + return WP_CONTENT_DIR . '/blog-inactive.php'; |
|
| 104 | + } else { |
|
| 105 | + wp_die( sprintf( __( 'This site has not been activated yet. If you are having problems activating your site, please contact <a href="mailto:%1$s">%1$s</a>.' ), str_replace( '@', ' AT ', get_site_option( 'admin_email', 'support@' . get_current_site()->domain ) ) ) ); |
|
| 106 | + } |
|
| 100 | 107 | } |
| 101 | 108 | |
| 102 | 109 | if ( $blog->archived == '1' || $blog->spam == '1' ) { |
| 103 | - if ( file_exists( WP_CONTENT_DIR . '/blog-suspended.php' ) ) |
|
| 104 | - return WP_CONTENT_DIR . '/blog-suspended.php'; |
|
| 105 | - else |
|
| 106 | - wp_die( __( 'This site has been archived or suspended.' ), '', array( 'response' => 410 ) ); |
|
| 110 | + if ( file_exists( WP_CONTENT_DIR . '/blog-suspended.php' ) ) { |
|
| 111 | + return WP_CONTENT_DIR . '/blog-suspended.php'; |
|
| 112 | + } else { |
|
| 113 | + wp_die( __( 'This site has been archived or suspended.' ), '', array( 'response' => 410 ) ); |
|
| 114 | + } |
|
| 107 | 115 | } |
| 108 | 116 | |
| 109 | 117 | return true; |
@@ -433,8 +441,9 @@ discard block |
||
| 433 | 441 | $msg .= __( 'Read the <a target="_blank" href="https://codex.wordpress.org/Debugging_a_WordPress_Network">bug report</a> page. Some of the guidelines there may help you figure out what went wrong.' ); |
| 434 | 442 | $msg .= ' ' . __( 'If you’re still stuck with this message, then check that your database contains the following tables:' ) . '</p><ul>'; |
| 435 | 443 | foreach ( $wpdb->tables('global') as $t => $table ) { |
| 436 | - if ( 'sitecategories' == $t ) |
|
| 437 | - continue; |
|
| 444 | + if ( 'sitecategories' == $t ) { |
|
| 445 | + continue; |
|
| 446 | + } |
|
| 438 | 447 | $msg .= '<li>' . $table . '</li>'; |
| 439 | 448 | } |
| 440 | 449 | $msg .= '</ul>'; |
@@ -1078,7 +1078,7 @@ discard block |
||
| 1078 | 1078 | * |
| 1079 | 1079 | * @since 1.2.0 |
| 1080 | 1080 | * |
| 1081 | - * @param int|string $action Action nonce. |
|
| 1081 | + * @param integer $action Action nonce. |
|
| 1082 | 1082 | * @param string $query_arg Optional. Key to check for nonce in `$_REQUEST` (since 2.5). |
| 1083 | 1083 | * Default '_wpnonce'. |
| 1084 | 1084 | * @return false|int False if the nonce is invalid, 1 if the nonce is valid and generated between |
@@ -1118,7 +1118,7 @@ discard block |
||
| 1118 | 1118 | * |
| 1119 | 1119 | * @since 2.0.3 |
| 1120 | 1120 | * |
| 1121 | - * @param int|string $action Action nonce. |
|
| 1121 | + * @param integer $action Action nonce. |
|
| 1122 | 1122 | * @param false|string $query_arg Optional. Key to check for the nonce in `$_REQUEST` (since 2.5). If false, |
| 1123 | 1123 | * `$_REQUEST` values will be evaluated for '_ajax_nonce', and '_wpnonce' |
| 1124 | 1124 | * (in that order). Default false. |
@@ -1546,7 +1546,7 @@ discard block |
||
| 1546 | 1546 | * @global wpdb $wpdb WordPress database abstraction object. |
| 1547 | 1547 | * |
| 1548 | 1548 | * @param int $comment_id Comment ID |
| 1549 | - * @return true Always returns true |
|
| 1549 | + * @return boolean Always returns true |
|
| 1550 | 1550 | */ |
| 1551 | 1551 | function wp_notify_moderator($comment_id) { |
| 1552 | 1552 | global $wpdb; |
@@ -1772,7 +1772,7 @@ discard block |
||
| 1772 | 1772 | * @since 2.0.3 |
| 1773 | 1773 | * |
| 1774 | 1774 | * @param string $nonce Nonce that was used in the form to verify |
| 1775 | - * @param string|int $action Should give context to what is taking place and be the same when nonce was created. |
|
| 1775 | + * @param integer $action Should give context to what is taking place and be the same when nonce was created. |
|
| 1776 | 1776 | * @return false|int False if the nonce is invalid, 1 if the nonce is valid and generated between |
| 1777 | 1777 | * 0-12 hours ago, 2 if the nonce is valid and generated between 12-24 hours ago. |
| 1778 | 1778 | */ |
@@ -1822,7 +1822,7 @@ discard block |
||
| 1822 | 1822 | * |
| 1823 | 1823 | * @since 2.0.3 |
| 1824 | 1824 | * |
| 1825 | - * @param string|int $action Scalar value to add context to the nonce. |
|
| 1825 | + * @param integer $action Scalar value to add context to the nonce. |
|
| 1826 | 1826 | * @return string The token. |
| 1827 | 1827 | */ |
| 1828 | 1828 | function wp_create_nonce($action = -1) { |
@@ -1,10 +1,10 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * These functions can be replaced via plugins. If plugins do not redefine these |
|
| 4 | - * functions, then these will be used instead. |
|
| 5 | - * |
|
| 6 | - * @package WordPress |
|
| 7 | - */ |
|
| 3 | + * These functions can be replaced via plugins. If plugins do not redefine these |
|
| 4 | + * functions, then these will be used instead. |
|
| 5 | + * |
|
| 6 | + * @package WordPress |
|
| 7 | + */ |
|
| 8 | 8 | |
| 9 | 9 | if ( !function_exists('wp_set_current_user') ) : |
| 10 | 10 | /** |
@@ -801,7 +801,7 @@ discard block |
||
| 801 | 801 | $cookie_name = AUTH_COOKIE; |
| 802 | 802 | $scheme = 'auth'; |
| 803 | 803 | } |
| 804 | - } |
|
| 804 | + } |
|
| 805 | 805 | |
| 806 | 806 | if ( empty($_COOKIE[$cookie_name]) ) |
| 807 | 807 | return false; |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @package WordPress |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -if ( !function_exists('wp_set_current_user') ) : |
|
| 9 | +if ( ! function_exists('wp_set_current_user')) : |
|
| 10 | 10 | /** |
| 11 | 11 | * Changes the current user by ID or name. |
| 12 | 12 | * |
@@ -26,25 +26,25 @@ discard block |
||
| 26 | 26 | function wp_set_current_user($id, $name = '') { |
| 27 | 27 | global $current_user; |
| 28 | 28 | |
| 29 | - if ( isset( $current_user ) && ( $current_user instanceof WP_User ) && ( $id == $current_user->ID ) ) |
|
| 29 | + if (isset($current_user) && ($current_user instanceof WP_User) && ($id == $current_user->ID)) |
|
| 30 | 30 | return $current_user; |
| 31 | 31 | |
| 32 | - $current_user = new WP_User( $id, $name ); |
|
| 32 | + $current_user = new WP_User($id, $name); |
|
| 33 | 33 | |
| 34 | - setup_userdata( $current_user->ID ); |
|
| 34 | + setup_userdata($current_user->ID); |
|
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * Fires after the current user is set. |
| 38 | 38 | * |
| 39 | 39 | * @since 2.0.1 |
| 40 | 40 | */ |
| 41 | - do_action( 'set_current_user' ); |
|
| 41 | + do_action('set_current_user'); |
|
| 42 | 42 | |
| 43 | 43 | return $current_user; |
| 44 | 44 | } |
| 45 | 45 | endif; |
| 46 | 46 | |
| 47 | -if ( !function_exists('wp_get_current_user') ) : |
|
| 47 | +if ( ! function_exists('wp_get_current_user')) : |
|
| 48 | 48 | /** |
| 49 | 49 | * Retrieve the current user object. |
| 50 | 50 | * |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | } |
| 64 | 64 | endif; |
| 65 | 65 | |
| 66 | -if ( !function_exists('get_currentuserinfo') ) : |
|
| 66 | +if ( ! function_exists('get_currentuserinfo')) : |
|
| 67 | 67 | /** |
| 68 | 68 | * Populate global variables with information about the currently logged in user. |
| 69 | 69 | * |
@@ -80,26 +80,26 @@ discard block |
||
| 80 | 80 | function get_currentuserinfo() { |
| 81 | 81 | global $current_user; |
| 82 | 82 | |
| 83 | - if ( ! empty( $current_user ) ) { |
|
| 84 | - if ( $current_user instanceof WP_User ) |
|
| 83 | + if ( ! empty($current_user)) { |
|
| 84 | + if ($current_user instanceof WP_User) |
|
| 85 | 85 | return; |
| 86 | 86 | |
| 87 | 87 | // Upgrade stdClass to WP_User |
| 88 | - if ( is_object( $current_user ) && isset( $current_user->ID ) ) { |
|
| 88 | + if (is_object($current_user) && isset($current_user->ID)) { |
|
| 89 | 89 | $cur_id = $current_user->ID; |
| 90 | 90 | $current_user = null; |
| 91 | - wp_set_current_user( $cur_id ); |
|
| 91 | + wp_set_current_user($cur_id); |
|
| 92 | 92 | return; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | // $current_user has a junk value. Force to WP_User with ID 0. |
| 96 | 96 | $current_user = null; |
| 97 | - wp_set_current_user( 0 ); |
|
| 97 | + wp_set_current_user(0); |
|
| 98 | 98 | return false; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST ) { |
|
| 102 | - wp_set_current_user( 0 ); |
|
| 101 | + if (defined('XMLRPC_REQUEST') && XMLRPC_REQUEST) { |
|
| 102 | + wp_set_current_user(0); |
|
| 103 | 103 | return false; |
| 104 | 104 | } |
| 105 | 105 | |
@@ -116,17 +116,17 @@ discard block |
||
| 116 | 116 | * |
| 117 | 117 | * @param int|bool $user_id User ID if one has been determined, false otherwise. |
| 118 | 118 | */ |
| 119 | - $user_id = apply_filters( 'determine_current_user', false ); |
|
| 120 | - if ( ! $user_id ) { |
|
| 121 | - wp_set_current_user( 0 ); |
|
| 119 | + $user_id = apply_filters('determine_current_user', false); |
|
| 120 | + if ( ! $user_id) { |
|
| 121 | + wp_set_current_user(0); |
|
| 122 | 122 | return false; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - wp_set_current_user( $user_id ); |
|
| 125 | + wp_set_current_user($user_id); |
|
| 126 | 126 | } |
| 127 | 127 | endif; |
| 128 | 128 | |
| 129 | -if ( !function_exists('get_userdata') ) : |
|
| 129 | +if ( ! function_exists('get_userdata')) : |
|
| 130 | 130 | /** |
| 131 | 131 | * Retrieve user info by user ID. |
| 132 | 132 | * |
@@ -135,12 +135,12 @@ discard block |
||
| 135 | 135 | * @param int $user_id User ID |
| 136 | 136 | * @return WP_User|false WP_User object on success, false on failure. |
| 137 | 137 | */ |
| 138 | -function get_userdata( $user_id ) { |
|
| 139 | - return get_user_by( 'id', $user_id ); |
|
| 138 | +function get_userdata($user_id) { |
|
| 139 | + return get_user_by('id', $user_id); |
|
| 140 | 140 | } |
| 141 | 141 | endif; |
| 142 | 142 | |
| 143 | -if ( !function_exists('get_user_by') ) : |
|
| 143 | +if ( ! function_exists('get_user_by')) : |
|
| 144 | 144 | /** |
| 145 | 145 | * Retrieve user info by a given field |
| 146 | 146 | * |
@@ -150,20 +150,20 @@ discard block |
||
| 150 | 150 | * @param int|string $value A value for $field. A user ID, slug, email address, or login name. |
| 151 | 151 | * @return WP_User|false WP_User object on success, false on failure. |
| 152 | 152 | */ |
| 153 | -function get_user_by( $field, $value ) { |
|
| 154 | - $userdata = WP_User::get_data_by( $field, $value ); |
|
| 153 | +function get_user_by($field, $value) { |
|
| 154 | + $userdata = WP_User::get_data_by($field, $value); |
|
| 155 | 155 | |
| 156 | - if ( !$userdata ) |
|
| 156 | + if ( ! $userdata) |
|
| 157 | 157 | return false; |
| 158 | 158 | |
| 159 | 159 | $user = new WP_User; |
| 160 | - $user->init( $userdata ); |
|
| 160 | + $user->init($userdata); |
|
| 161 | 161 | |
| 162 | 162 | return $user; |
| 163 | 163 | } |
| 164 | 164 | endif; |
| 165 | 165 | |
| 166 | -if ( !function_exists('cache_users') ) : |
|
| 166 | +if ( ! function_exists('cache_users')) : |
|
| 167 | 167 | /** |
| 168 | 168 | * Retrieve info for user lists to prevent multiple queries by get_userdata() |
| 169 | 169 | * |
@@ -173,28 +173,28 @@ discard block |
||
| 173 | 173 | * |
| 174 | 174 | * @param array $user_ids User ID numbers list |
| 175 | 175 | */ |
| 176 | -function cache_users( $user_ids ) { |
|
| 176 | +function cache_users($user_ids) { |
|
| 177 | 177 | global $wpdb; |
| 178 | 178 | |
| 179 | - $clean = _get_non_cached_ids( $user_ids, 'users' ); |
|
| 179 | + $clean = _get_non_cached_ids($user_ids, 'users'); |
|
| 180 | 180 | |
| 181 | - if ( empty( $clean ) ) |
|
| 181 | + if (empty($clean)) |
|
| 182 | 182 | return; |
| 183 | 183 | |
| 184 | - $list = implode( ',', $clean ); |
|
| 184 | + $list = implode(',', $clean); |
|
| 185 | 185 | |
| 186 | - $users = $wpdb->get_results( "SELECT * FROM $wpdb->users WHERE ID IN ($list)" ); |
|
| 186 | + $users = $wpdb->get_results("SELECT * FROM $wpdb->users WHERE ID IN ($list)"); |
|
| 187 | 187 | |
| 188 | 188 | $ids = array(); |
| 189 | - foreach ( $users as $user ) { |
|
| 190 | - update_user_caches( $user ); |
|
| 189 | + foreach ($users as $user) { |
|
| 190 | + update_user_caches($user); |
|
| 191 | 191 | $ids[] = $user->ID; |
| 192 | 192 | } |
| 193 | - update_meta_cache( 'user', $ids ); |
|
| 193 | + update_meta_cache('user', $ids); |
|
| 194 | 194 | } |
| 195 | 195 | endif; |
| 196 | 196 | |
| 197 | -if ( !function_exists( 'wp_mail' ) ) : |
|
| 197 | +if ( ! function_exists('wp_mail')) : |
|
| 198 | 198 | /** |
| 199 | 199 | * Send mail, similar to PHP's mail |
| 200 | 200 | * |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | * @param string|array $attachments Optional. Files to attach. |
| 226 | 226 | * @return bool Whether the email contents were sent successfully. |
| 227 | 227 | */ |
| 228 | -function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) { |
|
| 228 | +function wp_mail($to, $subject, $message, $headers = '', $attachments = array()) { |
|
| 229 | 229 | // Compact the input, apply the filters, and extract them back out |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -236,48 +236,48 @@ discard block |
||
| 236 | 236 | * @param array $args A compacted array of wp_mail() arguments, including the "to" email, |
| 237 | 237 | * subject, message, headers, and attachments values. |
| 238 | 238 | */ |
| 239 | - $atts = apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ); |
|
| 239 | + $atts = apply_filters('wp_mail', compact('to', 'subject', 'message', 'headers', 'attachments')); |
|
| 240 | 240 | |
| 241 | - if ( isset( $atts['to'] ) ) { |
|
| 241 | + if (isset($atts['to'])) { |
|
| 242 | 242 | $to = $atts['to']; |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | - if ( isset( $atts['subject'] ) ) { |
|
| 245 | + if (isset($atts['subject'])) { |
|
| 246 | 246 | $subject = $atts['subject']; |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - if ( isset( $atts['message'] ) ) { |
|
| 249 | + if (isset($atts['message'])) { |
|
| 250 | 250 | $message = $atts['message']; |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | - if ( isset( $atts['headers'] ) ) { |
|
| 253 | + if (isset($atts['headers'])) { |
|
| 254 | 254 | $headers = $atts['headers']; |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - if ( isset( $atts['attachments'] ) ) { |
|
| 257 | + if (isset($atts['attachments'])) { |
|
| 258 | 258 | $attachments = $atts['attachments']; |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - if ( ! is_array( $attachments ) ) { |
|
| 262 | - $attachments = explode( "\n", str_replace( "\r\n", "\n", $attachments ) ); |
|
| 261 | + if ( ! is_array($attachments)) { |
|
| 262 | + $attachments = explode("\n", str_replace("\r\n", "\n", $attachments)); |
|
| 263 | 263 | } |
| 264 | 264 | global $phpmailer; |
| 265 | 265 | |
| 266 | 266 | // (Re)create it, if it's gone missing |
| 267 | - if ( ! ( $phpmailer instanceof PHPMailer ) ) { |
|
| 268 | - require_once ABSPATH . WPINC . '/class-phpmailer.php'; |
|
| 269 | - require_once ABSPATH . WPINC . '/class-smtp.php'; |
|
| 270 | - $phpmailer = new PHPMailer( true ); |
|
| 267 | + if ( ! ($phpmailer instanceof PHPMailer)) { |
|
| 268 | + require_once ABSPATH.WPINC.'/class-phpmailer.php'; |
|
| 269 | + require_once ABSPATH.WPINC.'/class-smtp.php'; |
|
| 270 | + $phpmailer = new PHPMailer(true); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | // Headers |
| 274 | - if ( empty( $headers ) ) { |
|
| 274 | + if (empty($headers)) { |
|
| 275 | 275 | $headers = array(); |
| 276 | 276 | } else { |
| 277 | - if ( !is_array( $headers ) ) { |
|
| 277 | + if ( ! is_array($headers)) { |
|
| 278 | 278 | // Explode the headers out, so this function can take both |
| 279 | 279 | // string headers and an array of headers. |
| 280 | - $tempheaders = explode( "\n", str_replace( "\r\n", "\n", $headers ) ); |
|
| 280 | + $tempheaders = explode("\n", str_replace("\r\n", "\n", $headers)); |
|
| 281 | 281 | } else { |
| 282 | 282 | $tempheaders = $headers; |
| 283 | 283 | } |
@@ -286,69 +286,69 @@ discard block |
||
| 286 | 286 | $bcc = array(); |
| 287 | 287 | |
| 288 | 288 | // If it's actually got contents |
| 289 | - if ( !empty( $tempheaders ) ) { |
|
| 289 | + if ( ! empty($tempheaders)) { |
|
| 290 | 290 | // Iterate through the raw headers |
| 291 | - foreach ( (array) $tempheaders as $header ) { |
|
| 292 | - if ( strpos($header, ':') === false ) { |
|
| 293 | - if ( false !== stripos( $header, 'boundary=' ) ) { |
|
| 294 | - $parts = preg_split('/boundary=/i', trim( $header ) ); |
|
| 295 | - $boundary = trim( str_replace( array( "'", '"' ), '', $parts[1] ) ); |
|
| 291 | + foreach ((array) $tempheaders as $header) { |
|
| 292 | + if (strpos($header, ':') === false) { |
|
| 293 | + if (false !== stripos($header, 'boundary=')) { |
|
| 294 | + $parts = preg_split('/boundary=/i', trim($header)); |
|
| 295 | + $boundary = trim(str_replace(array("'", '"'), '', $parts[1])); |
|
| 296 | 296 | } |
| 297 | 297 | continue; |
| 298 | 298 | } |
| 299 | 299 | // Explode them out |
| 300 | - list( $name, $content ) = explode( ':', trim( $header ), 2 ); |
|
| 300 | + list($name, $content) = explode(':', trim($header), 2); |
|
| 301 | 301 | |
| 302 | 302 | // Cleanup crew |
| 303 | - $name = trim( $name ); |
|
| 304 | - $content = trim( $content ); |
|
| 303 | + $name = trim($name); |
|
| 304 | + $content = trim($content); |
|
| 305 | 305 | |
| 306 | - switch ( strtolower( $name ) ) { |
|
| 306 | + switch (strtolower($name)) { |
|
| 307 | 307 | // Mainly for legacy -- process a From: header if it's there |
| 308 | 308 | case 'from': |
| 309 | - $bracket_pos = strpos( $content, '<' ); |
|
| 310 | - if ( $bracket_pos !== false ) { |
|
| 309 | + $bracket_pos = strpos($content, '<'); |
|
| 310 | + if ($bracket_pos !== false) { |
|
| 311 | 311 | // Text before the bracketed email is the "From" name. |
| 312 | - if ( $bracket_pos > 0 ) { |
|
| 313 | - $from_name = substr( $content, 0, $bracket_pos - 1 ); |
|
| 314 | - $from_name = str_replace( '"', '', $from_name ); |
|
| 315 | - $from_name = trim( $from_name ); |
|
| 312 | + if ($bracket_pos > 0) { |
|
| 313 | + $from_name = substr($content, 0, $bracket_pos - 1); |
|
| 314 | + $from_name = str_replace('"', '', $from_name); |
|
| 315 | + $from_name = trim($from_name); |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | - $from_email = substr( $content, $bracket_pos + 1 ); |
|
| 319 | - $from_email = str_replace( '>', '', $from_email ); |
|
| 320 | - $from_email = trim( $from_email ); |
|
| 318 | + $from_email = substr($content, $bracket_pos + 1); |
|
| 319 | + $from_email = str_replace('>', '', $from_email); |
|
| 320 | + $from_email = trim($from_email); |
|
| 321 | 321 | |
| 322 | 322 | // Avoid setting an empty $from_email. |
| 323 | - } elseif ( '' !== trim( $content ) ) { |
|
| 324 | - $from_email = trim( $content ); |
|
| 323 | + } elseif ('' !== trim($content)) { |
|
| 324 | + $from_email = trim($content); |
|
| 325 | 325 | } |
| 326 | 326 | break; |
| 327 | 327 | case 'content-type': |
| 328 | - if ( strpos( $content, ';' ) !== false ) { |
|
| 329 | - list( $type, $charset_content ) = explode( ';', $content ); |
|
| 330 | - $content_type = trim( $type ); |
|
| 331 | - if ( false !== stripos( $charset_content, 'charset=' ) ) { |
|
| 332 | - $charset = trim( str_replace( array( 'charset=', '"' ), '', $charset_content ) ); |
|
| 333 | - } elseif ( false !== stripos( $charset_content, 'boundary=' ) ) { |
|
| 334 | - $boundary = trim( str_replace( array( 'BOUNDARY=', 'boundary=', '"' ), '', $charset_content ) ); |
|
| 328 | + if (strpos($content, ';') !== false) { |
|
| 329 | + list($type, $charset_content) = explode(';', $content); |
|
| 330 | + $content_type = trim($type); |
|
| 331 | + if (false !== stripos($charset_content, 'charset=')) { |
|
| 332 | + $charset = trim(str_replace(array('charset=', '"'), '', $charset_content)); |
|
| 333 | + } elseif (false !== stripos($charset_content, 'boundary=')) { |
|
| 334 | + $boundary = trim(str_replace(array('BOUNDARY=', 'boundary=', '"'), '', $charset_content)); |
|
| 335 | 335 | $charset = ''; |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | // Avoid setting an empty $content_type. |
| 339 | - } elseif ( '' !== trim( $content ) ) { |
|
| 340 | - $content_type = trim( $content ); |
|
| 339 | + } elseif ('' !== trim($content)) { |
|
| 340 | + $content_type = trim($content); |
|
| 341 | 341 | } |
| 342 | 342 | break; |
| 343 | 343 | case 'cc': |
| 344 | - $cc = array_merge( (array) $cc, explode( ',', $content ) ); |
|
| 344 | + $cc = array_merge((array) $cc, explode(',', $content)); |
|
| 345 | 345 | break; |
| 346 | 346 | case 'bcc': |
| 347 | - $bcc = array_merge( (array) $bcc, explode( ',', $content ) ); |
|
| 347 | + $bcc = array_merge((array) $bcc, explode(',', $content)); |
|
| 348 | 348 | break; |
| 349 | 349 | default: |
| 350 | 350 | // Add it to our grand headers array |
| 351 | - $headers[trim( $name )] = trim( $content ); |
|
| 351 | + $headers[trim($name)] = trim($content); |
|
| 352 | 352 | break; |
| 353 | 353 | } |
| 354 | 354 | } |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | |
| 364 | 364 | // From email and name |
| 365 | 365 | // If we don't have a name from the input headers |
| 366 | - if ( !isset( $from_name ) ) |
|
| 366 | + if ( ! isset($from_name)) |
|
| 367 | 367 | $from_name = 'WordPress'; |
| 368 | 368 | |
| 369 | 369 | /* If we don't have an email from the input headers default to wordpress@$sitename |
@@ -373,14 +373,14 @@ discard block |
||
| 373 | 373 | * https://core.trac.wordpress.org/ticket/5007. |
| 374 | 374 | */ |
| 375 | 375 | |
| 376 | - if ( !isset( $from_email ) ) { |
|
| 376 | + if ( ! isset($from_email)) { |
|
| 377 | 377 | // Get the site domain and get rid of www. |
| 378 | - $sitename = strtolower( $_SERVER['SERVER_NAME'] ); |
|
| 379 | - if ( substr( $sitename, 0, 4 ) == 'www.' ) { |
|
| 380 | - $sitename = substr( $sitename, 4 ); |
|
| 378 | + $sitename = strtolower($_SERVER['SERVER_NAME']); |
|
| 379 | + if (substr($sitename, 0, 4) == 'www.') { |
|
| 380 | + $sitename = substr($sitename, 4); |
|
| 381 | 381 | } |
| 382 | 382 | |
| 383 | - $from_email = 'wordpress@' . $sitename; |
|
| 383 | + $from_email = 'wordpress@'.$sitename; |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | /** |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | * |
| 391 | 391 | * @param string $from_email Email address to send from. |
| 392 | 392 | */ |
| 393 | - $phpmailer->From = apply_filters( 'wp_mail_from', $from_email ); |
|
| 393 | + $phpmailer->From = apply_filters('wp_mail_from', $from_email); |
|
| 394 | 394 | |
| 395 | 395 | /** |
| 396 | 396 | * Filter the name to associate with the "from" email address. |
@@ -399,24 +399,24 @@ discard block |
||
| 399 | 399 | * |
| 400 | 400 | * @param string $from_name Name associated with the "from" email address. |
| 401 | 401 | */ |
| 402 | - $phpmailer->FromName = apply_filters( 'wp_mail_from_name', $from_name ); |
|
| 402 | + $phpmailer->FromName = apply_filters('wp_mail_from_name', $from_name); |
|
| 403 | 403 | |
| 404 | 404 | // Set destination addresses |
| 405 | - if ( !is_array( $to ) ) |
|
| 406 | - $to = explode( ',', $to ); |
|
| 405 | + if ( ! is_array($to)) |
|
| 406 | + $to = explode(',', $to); |
|
| 407 | 407 | |
| 408 | - foreach ( (array) $to as $recipient ) { |
|
| 408 | + foreach ((array) $to as $recipient) { |
|
| 409 | 409 | try { |
| 410 | 410 | // Break $recipient into name and address parts if in the format "Foo <[email protected]>" |
| 411 | 411 | $recipient_name = ''; |
| 412 | - if ( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) { |
|
| 413 | - if ( count( $matches ) == 3 ) { |
|
| 412 | + if (preg_match('/(.*)<(.+)>/', $recipient, $matches)) { |
|
| 413 | + if (count($matches) == 3) { |
|
| 414 | 414 | $recipient_name = $matches[1]; |
| 415 | 415 | $recipient = $matches[2]; |
| 416 | 416 | } |
| 417 | 417 | } |
| 418 | - $phpmailer->AddAddress( $recipient, $recipient_name); |
|
| 419 | - } catch ( phpmailerException $e ) { |
|
| 418 | + $phpmailer->AddAddress($recipient, $recipient_name); |
|
| 419 | + } catch (phpmailerException $e) { |
|
| 420 | 420 | continue; |
| 421 | 421 | } |
| 422 | 422 | } |
@@ -426,37 +426,37 @@ discard block |
||
| 426 | 426 | $phpmailer->Body = $message; |
| 427 | 427 | |
| 428 | 428 | // Add any CC and BCC recipients |
| 429 | - if ( !empty( $cc ) ) { |
|
| 430 | - foreach ( (array) $cc as $recipient ) { |
|
| 429 | + if ( ! empty($cc)) { |
|
| 430 | + foreach ((array) $cc as $recipient) { |
|
| 431 | 431 | try { |
| 432 | 432 | // Break $recipient into name and address parts if in the format "Foo <[email protected]>" |
| 433 | 433 | $recipient_name = ''; |
| 434 | - if ( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) { |
|
| 435 | - if ( count( $matches ) == 3 ) { |
|
| 434 | + if (preg_match('/(.*)<(.+)>/', $recipient, $matches)) { |
|
| 435 | + if (count($matches) == 3) { |
|
| 436 | 436 | $recipient_name = $matches[1]; |
| 437 | 437 | $recipient = $matches[2]; |
| 438 | 438 | } |
| 439 | 439 | } |
| 440 | - $phpmailer->AddCc( $recipient, $recipient_name ); |
|
| 441 | - } catch ( phpmailerException $e ) { |
|
| 440 | + $phpmailer->AddCc($recipient, $recipient_name); |
|
| 441 | + } catch (phpmailerException $e) { |
|
| 442 | 442 | continue; |
| 443 | 443 | } |
| 444 | 444 | } |
| 445 | 445 | } |
| 446 | 446 | |
| 447 | - if ( !empty( $bcc ) ) { |
|
| 448 | - foreach ( (array) $bcc as $recipient) { |
|
| 447 | + if ( ! empty($bcc)) { |
|
| 448 | + foreach ((array) $bcc as $recipient) { |
|
| 449 | 449 | try { |
| 450 | 450 | // Break $recipient into name and address parts if in the format "Foo <[email protected]>" |
| 451 | 451 | $recipient_name = ''; |
| 452 | - if ( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) { |
|
| 453 | - if ( count( $matches ) == 3 ) { |
|
| 452 | + if (preg_match('/(.*)<(.+)>/', $recipient, $matches)) { |
|
| 453 | + if (count($matches) == 3) { |
|
| 454 | 454 | $recipient_name = $matches[1]; |
| 455 | 455 | $recipient = $matches[2]; |
| 456 | 456 | } |
| 457 | 457 | } |
| 458 | - $phpmailer->AddBcc( $recipient, $recipient_name ); |
|
| 459 | - } catch ( phpmailerException $e ) { |
|
| 458 | + $phpmailer->AddBcc($recipient, $recipient_name); |
|
| 459 | + } catch (phpmailerException $e) { |
|
| 460 | 460 | continue; |
| 461 | 461 | } |
| 462 | 462 | } |
@@ -467,7 +467,7 @@ discard block |
||
| 467 | 467 | |
| 468 | 468 | // Set Content-Type and charset |
| 469 | 469 | // If we don't have a content-type from the input headers |
| 470 | - if ( !isset( $content_type ) ) |
|
| 470 | + if ( ! isset($content_type)) |
|
| 471 | 471 | $content_type = 'text/plain'; |
| 472 | 472 | |
| 473 | 473 | /** |
@@ -477,17 +477,17 @@ discard block |
||
| 477 | 477 | * |
| 478 | 478 | * @param string $content_type Default wp_mail() content type. |
| 479 | 479 | */ |
| 480 | - $content_type = apply_filters( 'wp_mail_content_type', $content_type ); |
|
| 480 | + $content_type = apply_filters('wp_mail_content_type', $content_type); |
|
| 481 | 481 | |
| 482 | 482 | $phpmailer->ContentType = $content_type; |
| 483 | 483 | |
| 484 | 484 | // Set whether it's plaintext, depending on $content_type |
| 485 | - if ( 'text/html' == $content_type ) |
|
| 486 | - $phpmailer->IsHTML( true ); |
|
| 485 | + if ('text/html' == $content_type) |
|
| 486 | + $phpmailer->IsHTML(true); |
|
| 487 | 487 | |
| 488 | 488 | // If we don't have a charset from the input headers |
| 489 | - if ( !isset( $charset ) ) |
|
| 490 | - $charset = get_bloginfo( 'charset' ); |
|
| 489 | + if ( ! isset($charset)) |
|
| 490 | + $charset = get_bloginfo('charset'); |
|
| 491 | 491 | |
| 492 | 492 | // Set the content-type and charset |
| 493 | 493 | |
@@ -498,23 +498,23 @@ discard block |
||
| 498 | 498 | * |
| 499 | 499 | * @param string $charset Default email charset. |
| 500 | 500 | */ |
| 501 | - $phpmailer->CharSet = apply_filters( 'wp_mail_charset', $charset ); |
|
| 501 | + $phpmailer->CharSet = apply_filters('wp_mail_charset', $charset); |
|
| 502 | 502 | |
| 503 | 503 | // Set custom headers |
| 504 | - if ( !empty( $headers ) ) { |
|
| 505 | - foreach( (array) $headers as $name => $content ) { |
|
| 506 | - $phpmailer->AddCustomHeader( sprintf( '%1$s: %2$s', $name, $content ) ); |
|
| 504 | + if ( ! empty($headers)) { |
|
| 505 | + foreach ((array) $headers as $name => $content) { |
|
| 506 | + $phpmailer->AddCustomHeader(sprintf('%1$s: %2$s', $name, $content)); |
|
| 507 | 507 | } |
| 508 | 508 | |
| 509 | - if ( false !== stripos( $content_type, 'multipart' ) && ! empty($boundary) ) |
|
| 510 | - $phpmailer->AddCustomHeader( sprintf( "Content-Type: %s;\n\t boundary=\"%s\"", $content_type, $boundary ) ); |
|
| 509 | + if (false !== stripos($content_type, 'multipart') && ! empty($boundary)) |
|
| 510 | + $phpmailer->AddCustomHeader(sprintf("Content-Type: %s;\n\t boundary=\"%s\"", $content_type, $boundary)); |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | - if ( !empty( $attachments ) ) { |
|
| 514 | - foreach ( $attachments as $attachment ) { |
|
| 513 | + if ( ! empty($attachments)) { |
|
| 514 | + foreach ($attachments as $attachment) { |
|
| 515 | 515 | try { |
| 516 | 516 | $phpmailer->AddAttachment($attachment); |
| 517 | - } catch ( phpmailerException $e ) { |
|
| 517 | + } catch (phpmailerException $e) { |
|
| 518 | 518 | continue; |
| 519 | 519 | } |
| 520 | 520 | } |
@@ -527,18 +527,18 @@ discard block |
||
| 527 | 527 | * |
| 528 | 528 | * @param PHPMailer &$phpmailer The PHPMailer instance, passed by reference. |
| 529 | 529 | */ |
| 530 | - do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) ); |
|
| 530 | + do_action_ref_array('phpmailer_init', array(&$phpmailer)); |
|
| 531 | 531 | |
| 532 | 532 | // Send! |
| 533 | 533 | try { |
| 534 | 534 | return $phpmailer->Send(); |
| 535 | - } catch ( phpmailerException $e ) { |
|
| 535 | + } catch (phpmailerException $e) { |
|
| 536 | 536 | return false; |
| 537 | 537 | } |
| 538 | 538 | } |
| 539 | 539 | endif; |
| 540 | 540 | |
| 541 | -if ( !function_exists('wp_authenticate') ) : |
|
| 541 | +if ( ! function_exists('wp_authenticate')) : |
|
| 542 | 542 | /** |
| 543 | 543 | * Checks a user's login information and logs them in if it checks out. |
| 544 | 544 | * |
@@ -564,9 +564,9 @@ discard block |
||
| 564 | 564 | * @param string $username User login. |
| 565 | 565 | * @param string $password User password |
| 566 | 566 | */ |
| 567 | - $user = apply_filters( 'authenticate', null, $username, $password ); |
|
| 567 | + $user = apply_filters('authenticate', null, $username, $password); |
|
| 568 | 568 | |
| 569 | - if ( $user == null ) { |
|
| 569 | + if ($user == null) { |
|
| 570 | 570 | // TODO what should the error message be? (Or would these even happen?) |
| 571 | 571 | // Only needed if all authentication handlers fail to return anything. |
| 572 | 572 | $user = new WP_Error('authentication_failed', __('<strong>ERROR</strong>: Invalid username or incorrect password.')); |
@@ -574,7 +574,7 @@ discard block |
||
| 574 | 574 | |
| 575 | 575 | $ignore_codes = array('empty_username', 'empty_password'); |
| 576 | 576 | |
| 577 | - if (is_wp_error($user) && !in_array($user->get_error_code(), $ignore_codes) ) { |
|
| 577 | + if (is_wp_error($user) && ! in_array($user->get_error_code(), $ignore_codes)) { |
|
| 578 | 578 | /** |
| 579 | 579 | * Fires after a user login has failed. |
| 580 | 580 | * |
@@ -582,14 +582,14 @@ discard block |
||
| 582 | 582 | * |
| 583 | 583 | * @param string $username User login. |
| 584 | 584 | */ |
| 585 | - do_action( 'wp_login_failed', $username ); |
|
| 585 | + do_action('wp_login_failed', $username); |
|
| 586 | 586 | } |
| 587 | 587 | |
| 588 | 588 | return $user; |
| 589 | 589 | } |
| 590 | 590 | endif; |
| 591 | 591 | |
| 592 | -if ( !function_exists('wp_logout') ) : |
|
| 592 | +if ( ! function_exists('wp_logout')) : |
|
| 593 | 593 | /** |
| 594 | 594 | * Log the current user out. |
| 595 | 595 | * |
@@ -604,11 +604,11 @@ discard block |
||
| 604 | 604 | * |
| 605 | 605 | * @since 1.5.0 |
| 606 | 606 | */ |
| 607 | - do_action( 'wp_logout' ); |
|
| 607 | + do_action('wp_logout'); |
|
| 608 | 608 | } |
| 609 | 609 | endif; |
| 610 | 610 | |
| 611 | -if ( !function_exists('wp_validate_auth_cookie') ) : |
|
| 611 | +if ( ! function_exists('wp_validate_auth_cookie')) : |
|
| 612 | 612 | /** |
| 613 | 613 | * Validates authentication cookie. |
| 614 | 614 | * |
@@ -627,7 +627,7 @@ discard block |
||
| 627 | 627 | * @return false|int False if invalid cookie, User ID if valid. |
| 628 | 628 | */ |
| 629 | 629 | function wp_validate_auth_cookie($cookie = '', $scheme = '') { |
| 630 | - if ( ! $cookie_elements = wp_parse_auth_cookie($cookie, $scheme) ) { |
|
| 630 | + if ( ! $cookie_elements = wp_parse_auth_cookie($cookie, $scheme)) { |
|
| 631 | 631 | /** |
| 632 | 632 | * Fires if an authentication cookie is malformed. |
| 633 | 633 | * |
@@ -637,7 +637,7 @@ discard block |
||
| 637 | 637 | * @param string $scheme Authentication scheme. Values include 'auth', 'secure_auth', |
| 638 | 638 | * or 'logged_in'. |
| 639 | 639 | */ |
| 640 | - do_action( 'auth_cookie_malformed', $cookie, $scheme ); |
|
| 640 | + do_action('auth_cookie_malformed', $cookie, $scheme); |
|
| 641 | 641 | return false; |
| 642 | 642 | } |
| 643 | 643 | |
@@ -648,12 +648,12 @@ discard block |
||
| 648 | 648 | $expired = $expiration = $cookie_elements['expiration']; |
| 649 | 649 | |
| 650 | 650 | // Allow a grace period for POST and AJAX requests |
| 651 | - if ( defined('DOING_AJAX') || 'POST' == $_SERVER['REQUEST_METHOD'] ) { |
|
| 651 | + if (defined('DOING_AJAX') || 'POST' == $_SERVER['REQUEST_METHOD']) { |
|
| 652 | 652 | $expired += HOUR_IN_SECONDS; |
| 653 | 653 | } |
| 654 | 654 | |
| 655 | 655 | // Quick check to see if an honest cookie has expired |
| 656 | - if ( $expired < time() ) { |
|
| 656 | + if ($expired < time()) { |
|
| 657 | 657 | /** |
| 658 | 658 | * Fires once an authentication cookie has expired. |
| 659 | 659 | * |
@@ -661,12 +661,12 @@ discard block |
||
| 661 | 661 | * |
| 662 | 662 | * @param array $cookie_elements An array of data for the authentication cookie. |
| 663 | 663 | */ |
| 664 | - do_action( 'auth_cookie_expired', $cookie_elements ); |
|
| 664 | + do_action('auth_cookie_expired', $cookie_elements); |
|
| 665 | 665 | return false; |
| 666 | 666 | } |
| 667 | 667 | |
| 668 | 668 | $user = get_user_by('login', $username); |
| 669 | - if ( ! $user ) { |
|
| 669 | + if ( ! $user) { |
|
| 670 | 670 | /** |
| 671 | 671 | * Fires if a bad username is entered in the user authentication process. |
| 672 | 672 | * |
@@ -674,19 +674,19 @@ discard block |
||
| 674 | 674 | * |
| 675 | 675 | * @param array $cookie_elements An array of data for the authentication cookie. |
| 676 | 676 | */ |
| 677 | - do_action( 'auth_cookie_bad_username', $cookie_elements ); |
|
| 677 | + do_action('auth_cookie_bad_username', $cookie_elements); |
|
| 678 | 678 | return false; |
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | $pass_frag = substr($user->user_pass, 8, 4); |
| 682 | 682 | |
| 683 | - $key = wp_hash( $username . '|' . $pass_frag . '|' . $expiration . '|' . $token, $scheme ); |
|
| 683 | + $key = wp_hash($username.'|'.$pass_frag.'|'.$expiration.'|'.$token, $scheme); |
|
| 684 | 684 | |
| 685 | 685 | // If ext/hash is not present, compat.php's hash_hmac() does not support sha256. |
| 686 | - $algo = function_exists( 'hash' ) ? 'sha256' : 'sha1'; |
|
| 687 | - $hash = hash_hmac( $algo, $username . '|' . $expiration . '|' . $token, $key ); |
|
| 686 | + $algo = function_exists('hash') ? 'sha256' : 'sha1'; |
|
| 687 | + $hash = hash_hmac($algo, $username.'|'.$expiration.'|'.$token, $key); |
|
| 688 | 688 | |
| 689 | - if ( ! hash_equals( $hash, $hmac ) ) { |
|
| 689 | + if ( ! hash_equals($hash, $hmac)) { |
|
| 690 | 690 | /** |
| 691 | 691 | * Fires if a bad authentication cookie hash is encountered. |
| 692 | 692 | * |
@@ -694,18 +694,18 @@ discard block |
||
| 694 | 694 | * |
| 695 | 695 | * @param array $cookie_elements An array of data for the authentication cookie. |
| 696 | 696 | */ |
| 697 | - do_action( 'auth_cookie_bad_hash', $cookie_elements ); |
|
| 697 | + do_action('auth_cookie_bad_hash', $cookie_elements); |
|
| 698 | 698 | return false; |
| 699 | 699 | } |
| 700 | 700 | |
| 701 | - $manager = WP_Session_Tokens::get_instance( $user->ID ); |
|
| 702 | - if ( ! $manager->verify( $token ) ) { |
|
| 703 | - do_action( 'auth_cookie_bad_session_token', $cookie_elements ); |
|
| 701 | + $manager = WP_Session_Tokens::get_instance($user->ID); |
|
| 702 | + if ( ! $manager->verify($token)) { |
|
| 703 | + do_action('auth_cookie_bad_session_token', $cookie_elements); |
|
| 704 | 704 | return false; |
| 705 | 705 | } |
| 706 | 706 | |
| 707 | 707 | // AJAX/POST grace period set above |
| 708 | - if ( $expiration < time() ) { |
|
| 708 | + if ($expiration < time()) { |
|
| 709 | 709 | $GLOBALS['login_grace_period'] = 1; |
| 710 | 710 | } |
| 711 | 711 | |
@@ -717,13 +717,13 @@ discard block |
||
| 717 | 717 | * @param array $cookie_elements An array of data for the authentication cookie. |
| 718 | 718 | * @param WP_User $user User object. |
| 719 | 719 | */ |
| 720 | - do_action( 'auth_cookie_valid', $cookie_elements, $user ); |
|
| 720 | + do_action('auth_cookie_valid', $cookie_elements, $user); |
|
| 721 | 721 | |
| 722 | 722 | return $user->ID; |
| 723 | 723 | } |
| 724 | 724 | endif; |
| 725 | 725 | |
| 726 | -if ( !function_exists('wp_generate_auth_cookie') ) : |
|
| 726 | +if ( ! function_exists('wp_generate_auth_cookie')) : |
|
| 727 | 727 | /** |
| 728 | 728 | * Generate authentication cookie contents. |
| 729 | 729 | * |
@@ -735,26 +735,26 @@ discard block |
||
| 735 | 735 | * @param string $token User's session token to use for this cookie |
| 736 | 736 | * @return string Authentication cookie contents. Empty string if user does not exist. |
| 737 | 737 | */ |
| 738 | -function wp_generate_auth_cookie( $user_id, $expiration, $scheme = 'auth', $token = '' ) { |
|
| 738 | +function wp_generate_auth_cookie($user_id, $expiration, $scheme = 'auth', $token = '') { |
|
| 739 | 739 | $user = get_userdata($user_id); |
| 740 | - if ( ! $user ) { |
|
| 740 | + if ( ! $user) { |
|
| 741 | 741 | return ''; |
| 742 | 742 | } |
| 743 | 743 | |
| 744 | - if ( ! $token ) { |
|
| 745 | - $manager = WP_Session_Tokens::get_instance( $user_id ); |
|
| 746 | - $token = $manager->create( $expiration ); |
|
| 744 | + if ( ! $token) { |
|
| 745 | + $manager = WP_Session_Tokens::get_instance($user_id); |
|
| 746 | + $token = $manager->create($expiration); |
|
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | $pass_frag = substr($user->user_pass, 8, 4); |
| 750 | 750 | |
| 751 | - $key = wp_hash( $user->user_login . '|' . $pass_frag . '|' . $expiration . '|' . $token, $scheme ); |
|
| 751 | + $key = wp_hash($user->user_login.'|'.$pass_frag.'|'.$expiration.'|'.$token, $scheme); |
|
| 752 | 752 | |
| 753 | 753 | // If ext/hash is not present, compat.php's hash_hmac() does not support sha256. |
| 754 | - $algo = function_exists( 'hash' ) ? 'sha256' : 'sha1'; |
|
| 755 | - $hash = hash_hmac( $algo, $user->user_login . '|' . $expiration . '|' . $token, $key ); |
|
| 754 | + $algo = function_exists('hash') ? 'sha256' : 'sha1'; |
|
| 755 | + $hash = hash_hmac($algo, $user->user_login.'|'.$expiration.'|'.$token, $key); |
|
| 756 | 756 | |
| 757 | - $cookie = $user->user_login . '|' . $expiration . '|' . $token . '|' . $hash; |
|
| 757 | + $cookie = $user->user_login.'|'.$expiration.'|'.$token.'|'.$hash; |
|
| 758 | 758 | |
| 759 | 759 | /** |
| 760 | 760 | * Filter the authentication cookie. |
@@ -767,11 +767,11 @@ discard block |
||
| 767 | 767 | * @param string $scheme Cookie scheme used. Accepts 'auth', 'secure_auth', or 'logged_in'. |
| 768 | 768 | * @param string $token User's session token used. |
| 769 | 769 | */ |
| 770 | - return apply_filters( 'auth_cookie', $cookie, $user_id, $expiration, $scheme, $token ); |
|
| 770 | + return apply_filters('auth_cookie', $cookie, $user_id, $expiration, $scheme, $token); |
|
| 771 | 771 | } |
| 772 | 772 | endif; |
| 773 | 773 | |
| 774 | -if ( !function_exists('wp_parse_auth_cookie') ) : |
|
| 774 | +if ( ! function_exists('wp_parse_auth_cookie')) : |
|
| 775 | 775 | /** |
| 776 | 776 | * Parse a cookie into its components |
| 777 | 777 | * |
@@ -782,8 +782,8 @@ discard block |
||
| 782 | 782 | * @return array|false Authentication cookie components |
| 783 | 783 | */ |
| 784 | 784 | function wp_parse_auth_cookie($cookie = '', $scheme = '') { |
| 785 | - if ( empty($cookie) ) { |
|
| 786 | - switch ($scheme){ |
|
| 785 | + if (empty($cookie)) { |
|
| 786 | + switch ($scheme) { |
|
| 787 | 787 | case 'auth': |
| 788 | 788 | $cookie_name = AUTH_COOKIE; |
| 789 | 789 | break; |
@@ -794,7 +794,7 @@ discard block |
||
| 794 | 794 | $cookie_name = LOGGED_IN_COOKIE; |
| 795 | 795 | break; |
| 796 | 796 | default: |
| 797 | - if ( is_ssl() ) { |
|
| 797 | + if (is_ssl()) { |
|
| 798 | 798 | $cookie_name = SECURE_AUTH_COOKIE; |
| 799 | 799 | $scheme = 'secure_auth'; |
| 800 | 800 | } else { |
@@ -803,23 +803,23 @@ discard block |
||
| 803 | 803 | } |
| 804 | 804 | } |
| 805 | 805 | |
| 806 | - if ( empty($_COOKIE[$cookie_name]) ) |
|
| 806 | + if (empty($_COOKIE[$cookie_name])) |
|
| 807 | 807 | return false; |
| 808 | 808 | $cookie = $_COOKIE[$cookie_name]; |
| 809 | 809 | } |
| 810 | 810 | |
| 811 | 811 | $cookie_elements = explode('|', $cookie); |
| 812 | - if ( count( $cookie_elements ) !== 4 ) { |
|
| 812 | + if (count($cookie_elements) !== 4) { |
|
| 813 | 813 | return false; |
| 814 | 814 | } |
| 815 | 815 | |
| 816 | - list( $username, $expiration, $token, $hmac ) = $cookie_elements; |
|
| 816 | + list($username, $expiration, $token, $hmac) = $cookie_elements; |
|
| 817 | 817 | |
| 818 | - return compact( 'username', 'expiration', 'token', 'hmac', 'scheme' ); |
|
| 818 | + return compact('username', 'expiration', 'token', 'hmac', 'scheme'); |
|
| 819 | 819 | } |
| 820 | 820 | endif; |
| 821 | 821 | |
| 822 | -if ( !function_exists('wp_set_auth_cookie') ) : |
|
| 822 | +if ( ! function_exists('wp_set_auth_cookie')) : |
|
| 823 | 823 | /** |
| 824 | 824 | * Sets the authentication cookies based on user ID. |
| 825 | 825 | * |
@@ -836,8 +836,8 @@ discard block |
||
| 836 | 836 | * Default is_ssl(). |
| 837 | 837 | * @param string $token Optional. User's session token to use for this cookie. |
| 838 | 838 | */ |
| 839 | -function wp_set_auth_cookie( $user_id, $remember = false, $secure = '', $token = '' ) { |
|
| 840 | - if ( $remember ) { |
|
| 839 | +function wp_set_auth_cookie($user_id, $remember = false, $secure = '', $token = '') { |
|
| 840 | + if ($remember) { |
|
| 841 | 841 | /** |
| 842 | 842 | * Filter the duration of the authentication cookie expiration period. |
| 843 | 843 | * |
@@ -847,25 +847,25 @@ discard block |
||
| 847 | 847 | * @param int $user_id User ID. |
| 848 | 848 | * @param bool $remember Whether to remember the user login. Default false. |
| 849 | 849 | */ |
| 850 | - $expiration = time() + apply_filters( 'auth_cookie_expiration', 14 * DAY_IN_SECONDS, $user_id, $remember ); |
|
| 850 | + $expiration = time() + apply_filters('auth_cookie_expiration', 14 * DAY_IN_SECONDS, $user_id, $remember); |
|
| 851 | 851 | |
| 852 | 852 | /* |
| 853 | 853 | * Ensure the browser will continue to send the cookie after the expiration time is reached. |
| 854 | 854 | * Needed for the login grace period in wp_validate_auth_cookie(). |
| 855 | 855 | */ |
| 856 | - $expire = $expiration + ( 12 * HOUR_IN_SECONDS ); |
|
| 856 | + $expire = $expiration + (12 * HOUR_IN_SECONDS); |
|
| 857 | 857 | } else { |
| 858 | 858 | /** This filter is documented in wp-includes/pluggable.php */ |
| 859 | - $expiration = time() + apply_filters( 'auth_cookie_expiration', 2 * DAY_IN_SECONDS, $user_id, $remember ); |
|
| 859 | + $expiration = time() + apply_filters('auth_cookie_expiration', 2 * DAY_IN_SECONDS, $user_id, $remember); |
|
| 860 | 860 | $expire = 0; |
| 861 | 861 | } |
| 862 | 862 | |
| 863 | - if ( '' === $secure ) { |
|
| 863 | + if ('' === $secure) { |
|
| 864 | 864 | $secure = is_ssl(); |
| 865 | 865 | } |
| 866 | 866 | |
| 867 | 867 | // Frontend cookie is secure when the auth cookie is secure and the site's home URL is forced HTTPS. |
| 868 | - $secure_logged_in_cookie = $secure && 'https' === parse_url( get_option( 'home' ), PHP_URL_SCHEME ); |
|
| 868 | + $secure_logged_in_cookie = $secure && 'https' === parse_url(get_option('home'), PHP_URL_SCHEME); |
|
| 869 | 869 | |
| 870 | 870 | /** |
| 871 | 871 | * Filter whether the connection is secure. |
@@ -875,7 +875,7 @@ discard block |
||
| 875 | 875 | * @param bool $secure Whether the connection is secure. |
| 876 | 876 | * @param int $user_id User ID. |
| 877 | 877 | */ |
| 878 | - $secure = apply_filters( 'secure_auth_cookie', $secure, $user_id ); |
|
| 878 | + $secure = apply_filters('secure_auth_cookie', $secure, $user_id); |
|
| 879 | 879 | |
| 880 | 880 | /** |
| 881 | 881 | * Filter whether to use a secure cookie when logged-in. |
@@ -886,9 +886,9 @@ discard block |
||
| 886 | 886 | * @param int $user_id User ID. |
| 887 | 887 | * @param bool $secure Whether the connection is secure. |
| 888 | 888 | */ |
| 889 | - $secure_logged_in_cookie = apply_filters( 'secure_logged_in_cookie', $secure_logged_in_cookie, $user_id, $secure ); |
|
| 889 | + $secure_logged_in_cookie = apply_filters('secure_logged_in_cookie', $secure_logged_in_cookie, $user_id, $secure); |
|
| 890 | 890 | |
| 891 | - if ( $secure ) { |
|
| 891 | + if ($secure) { |
|
| 892 | 892 | $auth_cookie_name = SECURE_AUTH_COOKIE; |
| 893 | 893 | $scheme = 'secure_auth'; |
| 894 | 894 | } else { |
@@ -896,13 +896,13 @@ discard block |
||
| 896 | 896 | $scheme = 'auth'; |
| 897 | 897 | } |
| 898 | 898 | |
| 899 | - if ( '' === $token ) { |
|
| 900 | - $manager = WP_Session_Tokens::get_instance( $user_id ); |
|
| 901 | - $token = $manager->create( $expiration ); |
|
| 899 | + if ('' === $token) { |
|
| 900 | + $manager = WP_Session_Tokens::get_instance($user_id); |
|
| 901 | + $token = $manager->create($expiration); |
|
| 902 | 902 | } |
| 903 | 903 | |
| 904 | - $auth_cookie = wp_generate_auth_cookie( $user_id, $expiration, $scheme, $token ); |
|
| 905 | - $logged_in_cookie = wp_generate_auth_cookie( $user_id, $expiration, 'logged_in', $token ); |
|
| 904 | + $auth_cookie = wp_generate_auth_cookie($user_id, $expiration, $scheme, $token); |
|
| 905 | + $logged_in_cookie = wp_generate_auth_cookie($user_id, $expiration, 'logged_in', $token); |
|
| 906 | 906 | |
| 907 | 907 | /** |
| 908 | 908 | * Fires immediately before the authentication cookie is set. |
@@ -916,7 +916,7 @@ discard block |
||
| 916 | 916 | * @param int $user_id User ID. |
| 917 | 917 | * @param string $scheme Authentication scheme. Values include 'auth', 'secure_auth', or 'logged_in'. |
| 918 | 918 | */ |
| 919 | - do_action( 'set_auth_cookie', $auth_cookie, $expire, $expiration, $user_id, $scheme ); |
|
| 919 | + do_action('set_auth_cookie', $auth_cookie, $expire, $expiration, $user_id, $scheme); |
|
| 920 | 920 | |
| 921 | 921 | /** |
| 922 | 922 | * Fires immediately before the secure authentication cookie is set. |
@@ -930,17 +930,17 @@ discard block |
||
| 930 | 930 | * @param int $user_id User ID. |
| 931 | 931 | * @param string $scheme Authentication scheme. Default 'logged_in'. |
| 932 | 932 | */ |
| 933 | - do_action( 'set_logged_in_cookie', $logged_in_cookie, $expire, $expiration, $user_id, 'logged_in' ); |
|
| 933 | + do_action('set_logged_in_cookie', $logged_in_cookie, $expire, $expiration, $user_id, 'logged_in'); |
|
| 934 | 934 | |
| 935 | 935 | setcookie($auth_cookie_name, $auth_cookie, $expire, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN, $secure, true); |
| 936 | 936 | setcookie($auth_cookie_name, $auth_cookie, $expire, ADMIN_COOKIE_PATH, COOKIE_DOMAIN, $secure, true); |
| 937 | 937 | setcookie(LOGGED_IN_COOKIE, $logged_in_cookie, $expire, COOKIEPATH, COOKIE_DOMAIN, $secure_logged_in_cookie, true); |
| 938 | - if ( COOKIEPATH != SITECOOKIEPATH ) |
|
| 938 | + if (COOKIEPATH != SITECOOKIEPATH) |
|
| 939 | 939 | setcookie(LOGGED_IN_COOKIE, $logged_in_cookie, $expire, SITECOOKIEPATH, COOKIE_DOMAIN, $secure_logged_in_cookie, true); |
| 940 | 940 | } |
| 941 | 941 | endif; |
| 942 | 942 | |
| 943 | -if ( !function_exists('wp_clear_auth_cookie') ) : |
|
| 943 | +if ( ! function_exists('wp_clear_auth_cookie')) : |
|
| 944 | 944 | /** |
| 945 | 945 | * Removes all of the cookies associated with authentication. |
| 946 | 946 | * |
@@ -952,30 +952,30 @@ discard block |
||
| 952 | 952 | * |
| 953 | 953 | * @since 2.7.0 |
| 954 | 954 | */ |
| 955 | - do_action( 'clear_auth_cookie' ); |
|
| 955 | + do_action('clear_auth_cookie'); |
|
| 956 | 956 | |
| 957 | - setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, ADMIN_COOKIE_PATH, COOKIE_DOMAIN ); |
|
| 958 | - setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, ADMIN_COOKIE_PATH, COOKIE_DOMAIN ); |
|
| 959 | - setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN ); |
|
| 960 | - setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN ); |
|
| 961 | - setcookie( LOGGED_IN_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN ); |
|
| 962 | - setcookie( LOGGED_IN_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN ); |
|
| 957 | + setcookie(AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, ADMIN_COOKIE_PATH, COOKIE_DOMAIN); |
|
| 958 | + setcookie(SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, ADMIN_COOKIE_PATH, COOKIE_DOMAIN); |
|
| 959 | + setcookie(AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN); |
|
| 960 | + setcookie(SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN); |
|
| 961 | + setcookie(LOGGED_IN_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN); |
|
| 962 | + setcookie(LOGGED_IN_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN); |
|
| 963 | 963 | |
| 964 | 964 | // Old cookies |
| 965 | - setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN ); |
|
| 966 | - setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN ); |
|
| 967 | - setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN ); |
|
| 968 | - setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN ); |
|
| 965 | + setcookie(AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN); |
|
| 966 | + setcookie(AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN); |
|
| 967 | + setcookie(SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN); |
|
| 968 | + setcookie(SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN); |
|
| 969 | 969 | |
| 970 | 970 | // Even older cookies |
| 971 | - setcookie( USER_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN ); |
|
| 972 | - setcookie( PASS_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN ); |
|
| 973 | - setcookie( USER_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN ); |
|
| 974 | - setcookie( PASS_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN ); |
|
| 971 | + setcookie(USER_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN); |
|
| 972 | + setcookie(PASS_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN); |
|
| 973 | + setcookie(USER_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN); |
|
| 974 | + setcookie(PASS_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN); |
|
| 975 | 975 | } |
| 976 | 976 | endif; |
| 977 | 977 | |
| 978 | -if ( !function_exists('is_user_logged_in') ) : |
|
| 978 | +if ( ! function_exists('is_user_logged_in')) : |
|
| 979 | 979 | /** |
| 980 | 980 | * Checks if the current visitor is a logged in user. |
| 981 | 981 | * |
@@ -990,7 +990,7 @@ discard block |
||
| 990 | 990 | } |
| 991 | 991 | endif; |
| 992 | 992 | |
| 993 | -if ( !function_exists('auth_redirect') ) : |
|
| 993 | +if ( ! function_exists('auth_redirect')) : |
|
| 994 | 994 | /** |
| 995 | 995 | * Checks if a user is logged in, if not it redirects them to the login page. |
| 996 | 996 | * |
@@ -999,7 +999,7 @@ discard block |
||
| 999 | 999 | function auth_redirect() { |
| 1000 | 1000 | // Checks if a user is logged in, if not redirects them to the login page |
| 1001 | 1001 | |
| 1002 | - $secure = ( is_ssl() || force_ssl_admin() ); |
|
| 1002 | + $secure = (is_ssl() || force_ssl_admin()); |
|
| 1003 | 1003 | |
| 1004 | 1004 | /** |
| 1005 | 1005 | * Filter whether to use a secure authentication redirect. |
@@ -1008,20 +1008,20 @@ discard block |
||
| 1008 | 1008 | * |
| 1009 | 1009 | * @param bool $secure Whether to use a secure authentication redirect. Default false. |
| 1010 | 1010 | */ |
| 1011 | - $secure = apply_filters( 'secure_auth_redirect', $secure ); |
|
| 1011 | + $secure = apply_filters('secure_auth_redirect', $secure); |
|
| 1012 | 1012 | |
| 1013 | 1013 | // If https is required and request is http, redirect |
| 1014 | - if ( $secure && !is_ssl() && false !== strpos($_SERVER['REQUEST_URI'], 'wp-admin') ) { |
|
| 1015 | - if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) { |
|
| 1016 | - wp_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) ); |
|
| 1014 | + if ($secure && ! is_ssl() && false !== strpos($_SERVER['REQUEST_URI'], 'wp-admin')) { |
|
| 1015 | + if (0 === strpos($_SERVER['REQUEST_URI'], 'http')) { |
|
| 1016 | + wp_redirect(set_url_scheme($_SERVER['REQUEST_URI'], 'https')); |
|
| 1017 | 1017 | exit(); |
| 1018 | 1018 | } else { |
| 1019 | - wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); |
|
| 1019 | + wp_redirect('https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); |
|
| 1020 | 1020 | exit(); |
| 1021 | 1021 | } |
| 1022 | 1022 | } |
| 1023 | 1023 | |
| 1024 | - if ( is_user_admin() ) { |
|
| 1024 | + if (is_user_admin()) { |
|
| 1025 | 1025 | $scheme = 'logged_in'; |
| 1026 | 1026 | } else { |
| 1027 | 1027 | /** |
@@ -1031,10 +1031,10 @@ discard block |
||
| 1031 | 1031 | * |
| 1032 | 1032 | * @param string $scheme Authentication redirect scheme. Default empty. |
| 1033 | 1033 | */ |
| 1034 | - $scheme = apply_filters( 'auth_redirect_scheme', '' ); |
|
| 1034 | + $scheme = apply_filters('auth_redirect_scheme', ''); |
|
| 1035 | 1035 | } |
| 1036 | 1036 | |
| 1037 | - if ( $user_id = wp_validate_auth_cookie( '', $scheme) ) { |
|
| 1037 | + if ($user_id = wp_validate_auth_cookie('', $scheme)) { |
|
| 1038 | 1038 | /** |
| 1039 | 1039 | * Fires before the authentication redirect. |
| 1040 | 1040 | * |
@@ -1042,26 +1042,26 @@ discard block |
||
| 1042 | 1042 | * |
| 1043 | 1043 | * @param int $user_id User ID. |
| 1044 | 1044 | */ |
| 1045 | - do_action( 'auth_redirect', $user_id ); |
|
| 1045 | + do_action('auth_redirect', $user_id); |
|
| 1046 | 1046 | |
| 1047 | 1047 | // If the user wants ssl but the session is not ssl, redirect. |
| 1048 | - if ( !$secure && get_user_option('use_ssl', $user_id) && false !== strpos($_SERVER['REQUEST_URI'], 'wp-admin') ) { |
|
| 1049 | - if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) { |
|
| 1050 | - wp_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) ); |
|
| 1048 | + if ( ! $secure && get_user_option('use_ssl', $user_id) && false !== strpos($_SERVER['REQUEST_URI'], 'wp-admin')) { |
|
| 1049 | + if (0 === strpos($_SERVER['REQUEST_URI'], 'http')) { |
|
| 1050 | + wp_redirect(set_url_scheme($_SERVER['REQUEST_URI'], 'https')); |
|
| 1051 | 1051 | exit(); |
| 1052 | 1052 | } else { |
| 1053 | - wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); |
|
| 1053 | + wp_redirect('https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); |
|
| 1054 | 1054 | exit(); |
| 1055 | 1055 | } |
| 1056 | 1056 | } |
| 1057 | 1057 | |
| 1058 | - return; // The cookie is good so we're done |
|
| 1058 | + return; // The cookie is good so we're done |
|
| 1059 | 1059 | } |
| 1060 | 1060 | |
| 1061 | 1061 | // The cookie is no good so force login |
| 1062 | 1062 | nocache_headers(); |
| 1063 | 1063 | |
| 1064 | - $redirect = ( strpos( $_SERVER['REQUEST_URI'], '/options.php' ) && wp_get_referer() ) ? wp_get_referer() : set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); |
|
| 1064 | + $redirect = (strpos($_SERVER['REQUEST_URI'], '/options.php') && wp_get_referer()) ? wp_get_referer() : set_url_scheme('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); |
|
| 1065 | 1065 | |
| 1066 | 1066 | $login_url = wp_login_url($redirect, true); |
| 1067 | 1067 | |
@@ -1070,7 +1070,7 @@ discard block |
||
| 1070 | 1070 | } |
| 1071 | 1071 | endif; |
| 1072 | 1072 | |
| 1073 | -if ( !function_exists('check_admin_referer') ) : |
|
| 1073 | +if ( ! function_exists('check_admin_referer')) : |
|
| 1074 | 1074 | /** |
| 1075 | 1075 | * Makes sure that a user was referred from another admin page. |
| 1076 | 1076 | * |
@@ -1084,9 +1084,9 @@ discard block |
||
| 1084 | 1084 | * @return false|int False if the nonce is invalid, 1 if the nonce is valid and generated between |
| 1085 | 1085 | * 0-12 hours ago, 2 if the nonce is valid and generated between 12-24 hours ago. |
| 1086 | 1086 | */ |
| 1087 | -function check_admin_referer( $action = -1, $query_arg = '_wpnonce' ) { |
|
| 1087 | +function check_admin_referer($action = -1, $query_arg = '_wpnonce') { |
|
| 1088 | 1088 | if ( -1 == $action ) |
| 1089 | - _doing_it_wrong( __FUNCTION__, __( 'You should specify a nonce action to be verified by using the first parameter.' ), '3.2' ); |
|
| 1089 | + _doing_it_wrong(__FUNCTION__, __('You should specify a nonce action to be verified by using the first parameter.'), '3.2'); |
|
| 1090 | 1090 | |
| 1091 | 1091 | $adminurl = strtolower(admin_url()); |
| 1092 | 1092 | $referer = strtolower(wp_get_referer()); |
@@ -1101,10 +1101,10 @@ discard block |
||
| 1101 | 1101 | * @param false|int $result False if the nonce is invalid, 1 if the nonce is valid and generated between |
| 1102 | 1102 | * 0-12 hours ago, 2 if the nonce is valid and generated between 12-24 hours ago. |
| 1103 | 1103 | */ |
| 1104 | - do_action( 'check_admin_referer', $action, $result ); |
|
| 1104 | + do_action('check_admin_referer', $action, $result); |
|
| 1105 | 1105 | |
| 1106 | - if ( ! $result && ! ( -1 == $action && strpos( $referer, $adminurl ) === 0 ) ) { |
|
| 1107 | - wp_nonce_ays( $action ); |
|
| 1106 | + if ( ! $result && ! ( -1 == $action && strpos($referer, $adminurl) === 0 )) { |
|
| 1107 | + wp_nonce_ays($action); |
|
| 1108 | 1108 | die(); |
| 1109 | 1109 | } |
| 1110 | 1110 | |
@@ -1112,7 +1112,7 @@ discard block |
||
| 1112 | 1112 | } |
| 1113 | 1113 | endif; |
| 1114 | 1114 | |
| 1115 | -if ( !function_exists('check_ajax_referer') ) : |
|
| 1115 | +if ( ! function_exists('check_ajax_referer')) : |
|
| 1116 | 1116 | /** |
| 1117 | 1117 | * Verifies the AJAX request to prevent processing requests external of the blog. |
| 1118 | 1118 | * |
@@ -1127,23 +1127,23 @@ discard block |
||
| 1127 | 1127 | * @return false|int False if the nonce is invalid, 1 if the nonce is valid and generated between |
| 1128 | 1128 | * 0-12 hours ago, 2 if the nonce is valid and generated between 12-24 hours ago. |
| 1129 | 1129 | */ |
| 1130 | -function check_ajax_referer( $action = -1, $query_arg = false, $die = true ) { |
|
| 1130 | +function check_ajax_referer($action = -1, $query_arg = false, $die = true) { |
|
| 1131 | 1131 | $nonce = ''; |
| 1132 | 1132 | |
| 1133 | - if ( $query_arg && isset( $_REQUEST[ $query_arg ] ) ) |
|
| 1134 | - $nonce = $_REQUEST[ $query_arg ]; |
|
| 1135 | - elseif ( isset( $_REQUEST['_ajax_nonce'] ) ) |
|
| 1133 | + if ($query_arg && isset($_REQUEST[$query_arg])) |
|
| 1134 | + $nonce = $_REQUEST[$query_arg]; |
|
| 1135 | + elseif (isset($_REQUEST['_ajax_nonce'])) |
|
| 1136 | 1136 | $nonce = $_REQUEST['_ajax_nonce']; |
| 1137 | - elseif ( isset( $_REQUEST['_wpnonce'] ) ) |
|
| 1137 | + elseif (isset($_REQUEST['_wpnonce'])) |
|
| 1138 | 1138 | $nonce = $_REQUEST['_wpnonce']; |
| 1139 | 1139 | |
| 1140 | - $result = wp_verify_nonce( $nonce, $action ); |
|
| 1140 | + $result = wp_verify_nonce($nonce, $action); |
|
| 1141 | 1141 | |
| 1142 | - if ( $die && false === $result ) { |
|
| 1143 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) |
|
| 1142 | + if ($die && false === $result) { |
|
| 1143 | + if (defined('DOING_AJAX') && DOING_AJAX) |
|
| 1144 | 1144 | wp_die( -1 ); |
| 1145 | 1145 | else |
| 1146 | - die( '-1' ); |
|
| 1146 | + die('-1'); |
|
| 1147 | 1147 | } |
| 1148 | 1148 | |
| 1149 | 1149 | /** |
@@ -1155,13 +1155,13 @@ discard block |
||
| 1155 | 1155 | * @param false|int $result False if the nonce is invalid, 1 if the nonce is valid and generated between |
| 1156 | 1156 | * 0-12 hours ago, 2 if the nonce is valid and generated between 12-24 hours ago. |
| 1157 | 1157 | */ |
| 1158 | - do_action( 'check_ajax_referer', $action, $result ); |
|
| 1158 | + do_action('check_ajax_referer', $action, $result); |
|
| 1159 | 1159 | |
| 1160 | 1160 | return $result; |
| 1161 | 1161 | } |
| 1162 | 1162 | endif; |
| 1163 | 1163 | |
| 1164 | -if ( !function_exists('wp_redirect') ) : |
|
| 1164 | +if ( ! function_exists('wp_redirect')) : |
|
| 1165 | 1165 | /** |
| 1166 | 1166 | * Redirects to another page. |
| 1167 | 1167 | * |
@@ -1184,7 +1184,7 @@ discard block |
||
| 1184 | 1184 | * @param string $location The path to redirect to. |
| 1185 | 1185 | * @param int $status Status code to use. |
| 1186 | 1186 | */ |
| 1187 | - $location = apply_filters( 'wp_redirect', $location, $status ); |
|
| 1187 | + $location = apply_filters('wp_redirect', $location, $status); |
|
| 1188 | 1188 | |
| 1189 | 1189 | /** |
| 1190 | 1190 | * Filter the redirect status code. |
@@ -1194,14 +1194,14 @@ discard block |
||
| 1194 | 1194 | * @param int $status Status code to use. |
| 1195 | 1195 | * @param string $location The path to redirect to. |
| 1196 | 1196 | */ |
| 1197 | - $status = apply_filters( 'wp_redirect_status', $status, $location ); |
|
| 1197 | + $status = apply_filters('wp_redirect_status', $status, $location); |
|
| 1198 | 1198 | |
| 1199 | - if ( ! $location ) |
|
| 1199 | + if ( ! $location) |
|
| 1200 | 1200 | return false; |
| 1201 | 1201 | |
| 1202 | 1202 | $location = wp_sanitize_redirect($location); |
| 1203 | 1203 | |
| 1204 | - if ( !$is_IIS && PHP_SAPI != 'cgi-fcgi' ) |
|
| 1204 | + if ( ! $is_IIS && PHP_SAPI != 'cgi-fcgi') |
|
| 1205 | 1205 | status_header($status); // This causes problems on IIS and some FastCGI setups |
| 1206 | 1206 | |
| 1207 | 1207 | header("Location: $location", true, $status); |
@@ -1210,7 +1210,7 @@ discard block |
||
| 1210 | 1210 | } |
| 1211 | 1211 | endif; |
| 1212 | 1212 | |
| 1213 | -if ( !function_exists('wp_sanitize_redirect') ) : |
|
| 1213 | +if ( ! function_exists('wp_sanitize_redirect')) : |
|
| 1214 | 1214 | /** |
| 1215 | 1215 | * Sanitizes a URL for use in a redirect. |
| 1216 | 1216 | * |
@@ -1231,13 +1231,13 @@ discard block |
||
| 1231 | 1231 | | \xF4[\x80-\x8F][\x80-\xBF]{2} |
| 1232 | 1232 | ){1,40} # ...one or more times |
| 1233 | 1233 | )/x'; |
| 1234 | - $location = preg_replace_callback( $regex, '_wp_sanitize_utf8_in_redirect', $location ); |
|
| 1234 | + $location = preg_replace_callback($regex, '_wp_sanitize_utf8_in_redirect', $location); |
|
| 1235 | 1235 | $location = preg_replace('|[^a-z0-9-~+_.?#=&;,/:%!*\[\]()]|i', '', $location); |
| 1236 | 1236 | $location = wp_kses_no_null($location); |
| 1237 | 1237 | |
| 1238 | 1238 | // remove %0d and %0a from location |
| 1239 | 1239 | $strip = array('%0d', '%0a', '%0D', '%0A'); |
| 1240 | - return _deep_replace( $strip, $location ); |
|
| 1240 | + return _deep_replace($strip, $location); |
|
| 1241 | 1241 | } |
| 1242 | 1242 | |
| 1243 | 1243 | /** |
@@ -1249,12 +1249,12 @@ discard block |
||
| 1249 | 1249 | * |
| 1250 | 1250 | * @see wp_sanitize_redirect() |
| 1251 | 1251 | */ |
| 1252 | -function _wp_sanitize_utf8_in_redirect( $matches ) { |
|
| 1253 | - return urlencode( $matches[0] ); |
|
| 1252 | +function _wp_sanitize_utf8_in_redirect($matches) { |
|
| 1253 | + return urlencode($matches[0]); |
|
| 1254 | 1254 | } |
| 1255 | 1255 | endif; |
| 1256 | 1256 | |
| 1257 | -if ( !function_exists('wp_safe_redirect') ) : |
|
| 1257 | +if ( ! function_exists('wp_safe_redirect')) : |
|
| 1258 | 1258 | /** |
| 1259 | 1259 | * Performs a safe (local) redirect, using wp_redirect(). |
| 1260 | 1260 | * |
@@ -1281,13 +1281,13 @@ discard block |
||
| 1281 | 1281 | * @param string $fallback_url The fallback URL to use by default. |
| 1282 | 1282 | * @param int $status The redirect status. |
| 1283 | 1283 | */ |
| 1284 | - $location = wp_validate_redirect( $location, apply_filters( 'wp_safe_redirect_fallback', admin_url(), $status ) ); |
|
| 1284 | + $location = wp_validate_redirect($location, apply_filters('wp_safe_redirect_fallback', admin_url(), $status)); |
|
| 1285 | 1285 | |
| 1286 | 1286 | wp_redirect($location, $status); |
| 1287 | 1287 | } |
| 1288 | 1288 | endif; |
| 1289 | 1289 | |
| 1290 | -if ( !function_exists('wp_validate_redirect') ) : |
|
| 1290 | +if ( ! function_exists('wp_validate_redirect')) : |
|
| 1291 | 1291 | /** |
| 1292 | 1292 | * Validates a URL for use in a redirect. |
| 1293 | 1293 | * |
@@ -1304,26 +1304,26 @@ discard block |
||
| 1304 | 1304 | * @return string redirect-sanitized URL |
| 1305 | 1305 | **/ |
| 1306 | 1306 | function wp_validate_redirect($location, $default = '') { |
| 1307 | - $location = trim( $location ); |
|
| 1307 | + $location = trim($location); |
|
| 1308 | 1308 | // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//' |
| 1309 | - if ( substr($location, 0, 2) == '//' ) |
|
| 1310 | - $location = 'http:' . $location; |
|
| 1309 | + if (substr($location, 0, 2) == '//') |
|
| 1310 | + $location = 'http:'.$location; |
|
| 1311 | 1311 | |
| 1312 | 1312 | // In php 5 parse_url may fail if the URL query part contains http://, bug #38143 |
| 1313 | - $test = ( $cut = strpos($location, '?') ) ? substr( $location, 0, $cut ) : $location; |
|
| 1313 | + $test = ($cut = strpos($location, '?')) ? substr($location, 0, $cut) : $location; |
|
| 1314 | 1314 | |
| 1315 | - $lp = parse_url($test); |
|
| 1315 | + $lp = parse_url($test); |
|
| 1316 | 1316 | |
| 1317 | 1317 | // Give up if malformed URL |
| 1318 | - if ( false === $lp ) |
|
| 1318 | + if (false === $lp) |
|
| 1319 | 1319 | return $default; |
| 1320 | 1320 | |
| 1321 | 1321 | // Allow only http and https schemes. No data:, etc. |
| 1322 | - if ( isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme']) ) |
|
| 1322 | + if (isset($lp['scheme']) && ! ('http' == $lp['scheme'] || 'https' == $lp['scheme'])) |
|
| 1323 | 1323 | return $default; |
| 1324 | 1324 | |
| 1325 | 1325 | // Reject if scheme is set but host is not. This catches urls like https:host.com for which parse_url does not set the host field. |
| 1326 | - if ( isset($lp['scheme']) && !isset($lp['host']) ) |
|
| 1326 | + if (isset($lp['scheme']) && ! isset($lp['host'])) |
|
| 1327 | 1327 | return $default; |
| 1328 | 1328 | |
| 1329 | 1329 | $wpp = parse_url(home_url()); |
@@ -1336,16 +1336,16 @@ discard block |
||
| 1336 | 1336 | * @param array $hosts An array of allowed hosts. |
| 1337 | 1337 | * @param bool|string $host The parsed host; empty if not isset. |
| 1338 | 1338 | */ |
| 1339 | - $allowed_hosts = (array) apply_filters( 'allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '' ); |
|
| 1339 | + $allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : ''); |
|
| 1340 | 1340 | |
| 1341 | - if ( isset($lp['host']) && ( !in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host'])) ) |
|
| 1341 | + if (isset($lp['host']) && ( ! in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host']))) |
|
| 1342 | 1342 | $location = $default; |
| 1343 | 1343 | |
| 1344 | 1344 | return $location; |
| 1345 | 1345 | } |
| 1346 | 1346 | endif; |
| 1347 | 1347 | |
| 1348 | -if ( ! function_exists('wp_notify_postauthor') ) : |
|
| 1348 | +if ( ! function_exists('wp_notify_postauthor')) : |
|
| 1349 | 1349 | /** |
| 1350 | 1350 | * Notify an author (and/or others) of a comment/trackback/pingback on a post. |
| 1351 | 1351 | * |
@@ -1355,21 +1355,21 @@ discard block |
||
| 1355 | 1355 | * @param string $deprecated Not used |
| 1356 | 1356 | * @return bool True on completion. False if no email addresses were specified. |
| 1357 | 1357 | */ |
| 1358 | -function wp_notify_postauthor( $comment_id, $deprecated = null ) { |
|
| 1359 | - if ( null !== $deprecated ) { |
|
| 1360 | - _deprecated_argument( __FUNCTION__, '3.8' ); |
|
| 1358 | +function wp_notify_postauthor($comment_id, $deprecated = null) { |
|
| 1359 | + if (null !== $deprecated) { |
|
| 1360 | + _deprecated_argument(__FUNCTION__, '3.8'); |
|
| 1361 | 1361 | } |
| 1362 | 1362 | |
| 1363 | - $comment = get_comment( $comment_id ); |
|
| 1364 | - if ( empty( $comment ) ) |
|
| 1363 | + $comment = get_comment($comment_id); |
|
| 1364 | + if (empty($comment)) |
|
| 1365 | 1365 | return false; |
| 1366 | 1366 | |
| 1367 | - $post = get_post( $comment->comment_post_ID ); |
|
| 1368 | - $author = get_userdata( $post->post_author ); |
|
| 1367 | + $post = get_post($comment->comment_post_ID); |
|
| 1368 | + $author = get_userdata($post->post_author); |
|
| 1369 | 1369 | |
| 1370 | 1370 | // Who to notify? By default, just the post author, but others can be added. |
| 1371 | 1371 | $emails = array(); |
| 1372 | - if ( $author ) { |
|
| 1372 | + if ($author) { |
|
| 1373 | 1373 | $emails[] = $author->user_email; |
| 1374 | 1374 | } |
| 1375 | 1375 | |
@@ -1384,16 +1384,16 @@ discard block |
||
| 1384 | 1384 | * @param array $emails An array of email addresses to receive a comment notification. |
| 1385 | 1385 | * @param int $comment_id The comment ID. |
| 1386 | 1386 | */ |
| 1387 | - $emails = apply_filters( 'comment_notification_recipients', $emails, $comment_id ); |
|
| 1388 | - $emails = array_filter( $emails ); |
|
| 1387 | + $emails = apply_filters('comment_notification_recipients', $emails, $comment_id); |
|
| 1388 | + $emails = array_filter($emails); |
|
| 1389 | 1389 | |
| 1390 | 1390 | // If there are no addresses to send the comment to, bail. |
| 1391 | - if ( ! count( $emails ) ) { |
|
| 1391 | + if ( ! count($emails)) { |
|
| 1392 | 1392 | return false; |
| 1393 | 1393 | } |
| 1394 | 1394 | |
| 1395 | 1395 | // Facilitate unsetting below without knowing the keys. |
| 1396 | - $emails = array_flip( $emails ); |
|
| 1396 | + $emails = array_flip($emails); |
|
| 1397 | 1397 | |
| 1398 | 1398 | /** |
| 1399 | 1399 | * Filter whether to notify comment authors of their comments on their own posts. |
@@ -1407,28 +1407,28 @@ discard block |
||
| 1407 | 1407 | * Default false. |
| 1408 | 1408 | * @param int $comment_id The comment ID. |
| 1409 | 1409 | */ |
| 1410 | - $notify_author = apply_filters( 'comment_notification_notify_author', false, $comment_id ); |
|
| 1410 | + $notify_author = apply_filters('comment_notification_notify_author', false, $comment_id); |
|
| 1411 | 1411 | |
| 1412 | 1412 | // The comment was left by the author |
| 1413 | - if ( $author && ! $notify_author && $comment->user_id == $post->post_author ) { |
|
| 1414 | - unset( $emails[ $author->user_email ] ); |
|
| 1413 | + if ($author && ! $notify_author && $comment->user_id == $post->post_author) { |
|
| 1414 | + unset($emails[$author->user_email]); |
|
| 1415 | 1415 | } |
| 1416 | 1416 | |
| 1417 | 1417 | // The author moderated a comment on their own post |
| 1418 | - if ( $author && ! $notify_author && $post->post_author == get_current_user_id() ) { |
|
| 1419 | - unset( $emails[ $author->user_email ] ); |
|
| 1418 | + if ($author && ! $notify_author && $post->post_author == get_current_user_id()) { |
|
| 1419 | + unset($emails[$author->user_email]); |
|
| 1420 | 1420 | } |
| 1421 | 1421 | |
| 1422 | 1422 | // The post author is no longer a member of the blog |
| 1423 | - if ( $author && ! $notify_author && ! user_can( $post->post_author, 'read_post', $post->ID ) ) { |
|
| 1424 | - unset( $emails[ $author->user_email ] ); |
|
| 1423 | + if ($author && ! $notify_author && ! user_can($post->post_author, 'read_post', $post->ID)) { |
|
| 1424 | + unset($emails[$author->user_email]); |
|
| 1425 | 1425 | } |
| 1426 | 1426 | |
| 1427 | 1427 | // If there's no email to send the comment to, bail, otherwise flip array back around for use below |
| 1428 | - if ( ! count( $emails ) ) { |
|
| 1428 | + if ( ! count($emails)) { |
|
| 1429 | 1429 | return false; |
| 1430 | 1430 | } else { |
| 1431 | - $emails = array_flip( $emails ); |
|
| 1431 | + $emails = array_flip($emails); |
|
| 1432 | 1432 | } |
| 1433 | 1433 | |
| 1434 | 1434 | $comment_author_domain = @gethostbyaddr($comment->comment_author_IP); |
@@ -1437,67 +1437,67 @@ discard block |
||
| 1437 | 1437 | // we want to reverse this for the plain text arena of emails. |
| 1438 | 1438 | $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); |
| 1439 | 1439 | |
| 1440 | - switch ( $comment->comment_type ) { |
|
| 1440 | + switch ($comment->comment_type) { |
|
| 1441 | 1441 | case 'trackback': |
| 1442 | - $notify_message = sprintf( __( 'New trackback on your post "%s"' ), $post->post_title ) . "\r\n"; |
|
| 1442 | + $notify_message = sprintf(__('New trackback on your post "%s"'), $post->post_title)."\r\n"; |
|
| 1443 | 1443 | /* translators: 1: website name, 2: website IP, 3: website hostname */ |
| 1444 | - $notify_message .= sprintf( __('Website: %1$s (IP: %2$s, %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
|
| 1445 | - $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; |
|
| 1446 | - $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment->comment_content ) . "\r\n\r\n"; |
|
| 1447 | - $notify_message .= __( 'You can see all trackbacks on this post here:' ) . "\r\n"; |
|
| 1444 | + $notify_message .= sprintf(__('Website: %1$s (IP: %2$s, %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain)."\r\n"; |
|
| 1445 | + $notify_message .= sprintf(__('URL: %s'), $comment->comment_author_url)."\r\n"; |
|
| 1446 | + $notify_message .= sprintf(__('Comment: %s'), "\r\n".$comment->comment_content)."\r\n\r\n"; |
|
| 1447 | + $notify_message .= __('You can see all trackbacks on this post here:')."\r\n"; |
|
| 1448 | 1448 | /* translators: 1: blog name, 2: post title */ |
| 1449 | - $subject = sprintf( __('[%1$s] Trackback: "%2$s"'), $blogname, $post->post_title ); |
|
| 1449 | + $subject = sprintf(__('[%1$s] Trackback: "%2$s"'), $blogname, $post->post_title); |
|
| 1450 | 1450 | break; |
| 1451 | 1451 | case 'pingback': |
| 1452 | - $notify_message = sprintf( __( 'New pingback on your post "%s"' ), $post->post_title ) . "\r\n"; |
|
| 1452 | + $notify_message = sprintf(__('New pingback on your post "%s"'), $post->post_title)."\r\n"; |
|
| 1453 | 1453 | /* translators: 1: website name, 2: website IP, 3: website hostname */ |
| 1454 | - $notify_message .= sprintf( __('Website: %1$s (IP: %2$s, %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
|
| 1455 | - $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; |
|
| 1456 | - $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment->comment_content ) . "\r\n\r\n"; |
|
| 1457 | - $notify_message .= __( 'You can see all pingbacks on this post here:' ) . "\r\n"; |
|
| 1454 | + $notify_message .= sprintf(__('Website: %1$s (IP: %2$s, %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain)."\r\n"; |
|
| 1455 | + $notify_message .= sprintf(__('URL: %s'), $comment->comment_author_url)."\r\n"; |
|
| 1456 | + $notify_message .= sprintf(__('Comment: %s'), "\r\n".$comment->comment_content)."\r\n\r\n"; |
|
| 1457 | + $notify_message .= __('You can see all pingbacks on this post here:')."\r\n"; |
|
| 1458 | 1458 | /* translators: 1: blog name, 2: post title */ |
| 1459 | - $subject = sprintf( __('[%1$s] Pingback: "%2$s"'), $blogname, $post->post_title ); |
|
| 1459 | + $subject = sprintf(__('[%1$s] Pingback: "%2$s"'), $blogname, $post->post_title); |
|
| 1460 | 1460 | break; |
| 1461 | 1461 | default: // Comments |
| 1462 | - $notify_message = sprintf( __( 'New comment on your post "%s"' ), $post->post_title ) . "\r\n"; |
|
| 1462 | + $notify_message = sprintf(__('New comment on your post "%s"'), $post->post_title)."\r\n"; |
|
| 1463 | 1463 | /* translators: 1: comment author, 2: author IP, 3: author domain */ |
| 1464 | - $notify_message .= sprintf( __( 'Author: %1$s (IP: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
|
| 1465 | - $notify_message .= sprintf( __( 'E-mail: %s' ), $comment->comment_author_email ) . "\r\n"; |
|
| 1466 | - $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; |
|
| 1467 | - $notify_message .= sprintf( __('Comment: %s' ), "\r\n" . $comment->comment_content ) . "\r\n\r\n"; |
|
| 1468 | - $notify_message .= __( 'You can see all comments on this post here:' ) . "\r\n"; |
|
| 1464 | + $notify_message .= sprintf(__('Author: %1$s (IP: %2$s, %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain)."\r\n"; |
|
| 1465 | + $notify_message .= sprintf(__('E-mail: %s'), $comment->comment_author_email)."\r\n"; |
|
| 1466 | + $notify_message .= sprintf(__('URL: %s'), $comment->comment_author_url)."\r\n"; |
|
| 1467 | + $notify_message .= sprintf(__('Comment: %s'), "\r\n".$comment->comment_content)."\r\n\r\n"; |
|
| 1468 | + $notify_message .= __('You can see all comments on this post here:')."\r\n"; |
|
| 1469 | 1469 | /* translators: 1: blog name, 2: post title */ |
| 1470 | - $subject = sprintf( __('[%1$s] Comment: "%2$s"'), $blogname, $post->post_title ); |
|
| 1470 | + $subject = sprintf(__('[%1$s] Comment: "%2$s"'), $blogname, $post->post_title); |
|
| 1471 | 1471 | break; |
| 1472 | 1472 | } |
| 1473 | - $notify_message .= get_permalink($comment->comment_post_ID) . "#comments\r\n\r\n"; |
|
| 1474 | - $notify_message .= sprintf( __('Permalink: %s'), get_comment_link( $comment_id ) ) . "\r\n"; |
|
| 1473 | + $notify_message .= get_permalink($comment->comment_post_ID)."#comments\r\n\r\n"; |
|
| 1474 | + $notify_message .= sprintf(__('Permalink: %s'), get_comment_link($comment_id))."\r\n"; |
|
| 1475 | 1475 | |
| 1476 | - if ( user_can( $post->post_author, 'edit_comment', $comment_id ) ) { |
|
| 1477 | - if ( EMPTY_TRASH_DAYS ) |
|
| 1478 | - $notify_message .= sprintf( __('Trash it: %s'), admin_url("comment.php?action=trash&c=$comment_id") ) . "\r\n"; |
|
| 1476 | + if (user_can($post->post_author, 'edit_comment', $comment_id)) { |
|
| 1477 | + if (EMPTY_TRASH_DAYS) |
|
| 1478 | + $notify_message .= sprintf(__('Trash it: %s'), admin_url("comment.php?action=trash&c=$comment_id"))."\r\n"; |
|
| 1479 | 1479 | else |
| 1480 | - $notify_message .= sprintf( __('Delete it: %s'), admin_url("comment.php?action=delete&c=$comment_id") ) . "\r\n"; |
|
| 1481 | - $notify_message .= sprintf( __('Spam it: %s'), admin_url("comment.php?action=spam&c=$comment_id") ) . "\r\n"; |
|
| 1480 | + $notify_message .= sprintf(__('Delete it: %s'), admin_url("comment.php?action=delete&c=$comment_id"))."\r\n"; |
|
| 1481 | + $notify_message .= sprintf(__('Spam it: %s'), admin_url("comment.php?action=spam&c=$comment_id"))."\r\n"; |
|
| 1482 | 1482 | } |
| 1483 | 1483 | |
| 1484 | - $wp_email = 'wordpress@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])); |
|
| 1484 | + $wp_email = 'wordpress@'.preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])); |
|
| 1485 | 1485 | |
| 1486 | - if ( '' == $comment->comment_author ) { |
|
| 1486 | + if ('' == $comment->comment_author) { |
|
| 1487 | 1487 | $from = "From: \"$blogname\" <$wp_email>"; |
| 1488 | - if ( '' != $comment->comment_author_email ) |
|
| 1488 | + if ('' != $comment->comment_author_email) |
|
| 1489 | 1489 | $reply_to = "Reply-To: $comment->comment_author_email"; |
| 1490 | 1490 | } else { |
| 1491 | 1491 | $from = "From: \"$comment->comment_author\" <$wp_email>"; |
| 1492 | - if ( '' != $comment->comment_author_email ) |
|
| 1492 | + if ('' != $comment->comment_author_email) |
|
| 1493 | 1493 | $reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>"; |
| 1494 | 1494 | } |
| 1495 | 1495 | |
| 1496 | 1496 | $message_headers = "$from\n" |
| 1497 | - . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; |
|
| 1497 | + . "Content-Type: text/plain; charset=\"".get_option('blog_charset')."\"\n"; |
|
| 1498 | 1498 | |
| 1499 | - if ( isset($reply_to) ) |
|
| 1500 | - $message_headers .= $reply_to . "\n"; |
|
| 1499 | + if (isset($reply_to)) |
|
| 1500 | + $message_headers .= $reply_to."\n"; |
|
| 1501 | 1501 | |
| 1502 | 1502 | /** |
| 1503 | 1503 | * Filter the comment notification email text. |
@@ -1507,7 +1507,7 @@ discard block |
||
| 1507 | 1507 | * @param string $notify_message The comment notification email text. |
| 1508 | 1508 | * @param int $comment_id Comment ID. |
| 1509 | 1509 | */ |
| 1510 | - $notify_message = apply_filters( 'comment_notification_text', $notify_message, $comment_id ); |
|
| 1510 | + $notify_message = apply_filters('comment_notification_text', $notify_message, $comment_id); |
|
| 1511 | 1511 | |
| 1512 | 1512 | /** |
| 1513 | 1513 | * Filter the comment notification email subject. |
@@ -1517,7 +1517,7 @@ discard block |
||
| 1517 | 1517 | * @param string $subject The comment notification email subject. |
| 1518 | 1518 | * @param int $comment_id Comment ID. |
| 1519 | 1519 | */ |
| 1520 | - $subject = apply_filters( 'comment_notification_subject', $subject, $comment_id ); |
|
| 1520 | + $subject = apply_filters('comment_notification_subject', $subject, $comment_id); |
|
| 1521 | 1521 | |
| 1522 | 1522 | /** |
| 1523 | 1523 | * Filter the comment notification email headers. |
@@ -1527,17 +1527,17 @@ discard block |
||
| 1527 | 1527 | * @param string $message_headers Headers for the comment notification email. |
| 1528 | 1528 | * @param int $comment_id Comment ID. |
| 1529 | 1529 | */ |
| 1530 | - $message_headers = apply_filters( 'comment_notification_headers', $message_headers, $comment_id ); |
|
| 1530 | + $message_headers = apply_filters('comment_notification_headers', $message_headers, $comment_id); |
|
| 1531 | 1531 | |
| 1532 | - foreach ( $emails as $email ) { |
|
| 1533 | - @wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers ); |
|
| 1532 | + foreach ($emails as $email) { |
|
| 1533 | + @wp_mail($email, wp_specialchars_decode($subject), $notify_message, $message_headers); |
|
| 1534 | 1534 | } |
| 1535 | 1535 | |
| 1536 | 1536 | return true; |
| 1537 | 1537 | } |
| 1538 | 1538 | endif; |
| 1539 | 1539 | |
| 1540 | -if ( !function_exists('wp_notify_moderator') ) : |
|
| 1540 | +if ( ! function_exists('wp_notify_moderator')) : |
|
| 1541 | 1541 | /** |
| 1542 | 1542 | * Notifies the moderator of the blog about a new comment that is awaiting approval. |
| 1543 | 1543 | * |
@@ -1551,16 +1551,16 @@ discard block |
||
| 1551 | 1551 | function wp_notify_moderator($comment_id) { |
| 1552 | 1552 | global $wpdb; |
| 1553 | 1553 | |
| 1554 | - if ( 0 == get_option( 'moderation_notify' ) ) |
|
| 1554 | + if (0 == get_option('moderation_notify')) |
|
| 1555 | 1555 | return true; |
| 1556 | 1556 | |
| 1557 | 1557 | $comment = get_comment($comment_id); |
| 1558 | 1558 | $post = get_post($comment->comment_post_ID); |
| 1559 | - $user = get_userdata( $post->post_author ); |
|
| 1559 | + $user = get_userdata($post->post_author); |
|
| 1560 | 1560 | // Send to the administration and to the post author if the author can modify the comment. |
| 1561 | - $emails = array( get_option( 'admin_email' ) ); |
|
| 1562 | - if ( $user && user_can( $user->ID, 'edit_comment', $comment_id ) && ! empty( $user->user_email ) ) { |
|
| 1563 | - if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) ) |
|
| 1561 | + $emails = array(get_option('admin_email')); |
|
| 1562 | + if ($user && user_can($user->ID, 'edit_comment', $comment_id) && ! empty($user->user_email)) { |
|
| 1563 | + if (0 !== strcasecmp($user->user_email, get_option('admin_email'))) |
|
| 1564 | 1564 | $emails[] = $user->user_email; |
| 1565 | 1565 | } |
| 1566 | 1566 | |
@@ -1571,45 +1571,45 @@ discard block |
||
| 1571 | 1571 | // we want to reverse this for the plain text arena of emails. |
| 1572 | 1572 | $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); |
| 1573 | 1573 | |
| 1574 | - switch ( $comment->comment_type ) { |
|
| 1574 | + switch ($comment->comment_type) { |
|
| 1575 | 1575 | case 'trackback': |
| 1576 | - $notify_message = sprintf( __('A new trackback on the post "%s" is waiting for your approval'), $post->post_title ) . "\r\n"; |
|
| 1577 | - $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n"; |
|
| 1576 | + $notify_message = sprintf(__('A new trackback on the post "%s" is waiting for your approval'), $post->post_title)."\r\n"; |
|
| 1577 | + $notify_message .= get_permalink($comment->comment_post_ID)."\r\n\r\n"; |
|
| 1578 | 1578 | /* translators: 1: website name, 2: website IP, 3: website hostname */ |
| 1579 | - $notify_message .= sprintf( __( 'Website: %1$s (IP: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
|
| 1580 | - $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; |
|
| 1581 | - $notify_message .= __('Trackback excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n"; |
|
| 1579 | + $notify_message .= sprintf(__('Website: %1$s (IP: %2$s, %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain)."\r\n"; |
|
| 1580 | + $notify_message .= sprintf(__('URL: %s'), $comment->comment_author_url)."\r\n"; |
|
| 1581 | + $notify_message .= __('Trackback excerpt: ')."\r\n".$comment->comment_content."\r\n\r\n"; |
|
| 1582 | 1582 | break; |
| 1583 | 1583 | case 'pingback': |
| 1584 | - $notify_message = sprintf( __('A new pingback on the post "%s" is waiting for your approval'), $post->post_title ) . "\r\n"; |
|
| 1585 | - $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n"; |
|
| 1584 | + $notify_message = sprintf(__('A new pingback on the post "%s" is waiting for your approval'), $post->post_title)."\r\n"; |
|
| 1585 | + $notify_message .= get_permalink($comment->comment_post_ID)."\r\n\r\n"; |
|
| 1586 | 1586 | /* translators: 1: website name, 2: website IP, 3: website hostname */ |
| 1587 | - $notify_message .= sprintf( __( 'Website: %1$s (IP: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
|
| 1588 | - $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; |
|
| 1589 | - $notify_message .= __('Pingback excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n"; |
|
| 1587 | + $notify_message .= sprintf(__('Website: %1$s (IP: %2$s, %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain)."\r\n"; |
|
| 1588 | + $notify_message .= sprintf(__('URL: %s'), $comment->comment_author_url)."\r\n"; |
|
| 1589 | + $notify_message .= __('Pingback excerpt: ')."\r\n".$comment->comment_content."\r\n\r\n"; |
|
| 1590 | 1590 | break; |
| 1591 | 1591 | default: // Comments |
| 1592 | - $notify_message = sprintf( __('A new comment on the post "%s" is waiting for your approval'), $post->post_title ) . "\r\n"; |
|
| 1593 | - $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n"; |
|
| 1594 | - $notify_message .= sprintf( __( 'Author: %1$s (IP: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
|
| 1595 | - $notify_message .= sprintf( __( 'E-mail: %s' ), $comment->comment_author_email ) . "\r\n"; |
|
| 1596 | - $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; |
|
| 1597 | - $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment->comment_content ) . "\r\n\r\n"; |
|
| 1592 | + $notify_message = sprintf(__('A new comment on the post "%s" is waiting for your approval'), $post->post_title)."\r\n"; |
|
| 1593 | + $notify_message .= get_permalink($comment->comment_post_ID)."\r\n\r\n"; |
|
| 1594 | + $notify_message .= sprintf(__('Author: %1$s (IP: %2$s, %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain)."\r\n"; |
|
| 1595 | + $notify_message .= sprintf(__('E-mail: %s'), $comment->comment_author_email)."\r\n"; |
|
| 1596 | + $notify_message .= sprintf(__('URL: %s'), $comment->comment_author_url)."\r\n"; |
|
| 1597 | + $notify_message .= sprintf(__('Comment: %s'), "\r\n".$comment->comment_content)."\r\n\r\n"; |
|
| 1598 | 1598 | break; |
| 1599 | 1599 | } |
| 1600 | 1600 | |
| 1601 | - $notify_message .= sprintf( __('Approve it: %s'), admin_url("comment.php?action=approve&c=$comment_id") ) . "\r\n"; |
|
| 1602 | - if ( EMPTY_TRASH_DAYS ) |
|
| 1603 | - $notify_message .= sprintf( __('Trash it: %s'), admin_url("comment.php?action=trash&c=$comment_id") ) . "\r\n"; |
|
| 1601 | + $notify_message .= sprintf(__('Approve it: %s'), admin_url("comment.php?action=approve&c=$comment_id"))."\r\n"; |
|
| 1602 | + if (EMPTY_TRASH_DAYS) |
|
| 1603 | + $notify_message .= sprintf(__('Trash it: %s'), admin_url("comment.php?action=trash&c=$comment_id"))."\r\n"; |
|
| 1604 | 1604 | else |
| 1605 | - $notify_message .= sprintf( __('Delete it: %s'), admin_url("comment.php?action=delete&c=$comment_id") ) . "\r\n"; |
|
| 1606 | - $notify_message .= sprintf( __('Spam it: %s'), admin_url("comment.php?action=spam&c=$comment_id") ) . "\r\n"; |
|
| 1605 | + $notify_message .= sprintf(__('Delete it: %s'), admin_url("comment.php?action=delete&c=$comment_id"))."\r\n"; |
|
| 1606 | + $notify_message .= sprintf(__('Spam it: %s'), admin_url("comment.php?action=spam&c=$comment_id"))."\r\n"; |
|
| 1607 | 1607 | |
| 1608 | - $notify_message .= sprintf( _n('Currently %s comment is waiting for approval. Please visit the moderation panel:', |
|
| 1609 | - 'Currently %s comments are waiting for approval. Please visit the moderation panel:', $comments_waiting), number_format_i18n($comments_waiting) ) . "\r\n"; |
|
| 1610 | - $notify_message .= admin_url("edit-comments.php?comment_status=moderated") . "\r\n"; |
|
| 1608 | + $notify_message .= sprintf(_n('Currently %s comment is waiting for approval. Please visit the moderation panel:', |
|
| 1609 | + 'Currently %s comments are waiting for approval. Please visit the moderation panel:', $comments_waiting), number_format_i18n($comments_waiting))."\r\n"; |
|
| 1610 | + $notify_message .= admin_url("edit-comments.php?comment_status=moderated")."\r\n"; |
|
| 1611 | 1611 | |
| 1612 | - $subject = sprintf( __('[%1$s] Please moderate: "%2$s"'), $blogname, $post->post_title ); |
|
| 1612 | + $subject = sprintf(__('[%1$s] Please moderate: "%2$s"'), $blogname, $post->post_title); |
|
| 1613 | 1613 | $message_headers = ''; |
| 1614 | 1614 | |
| 1615 | 1615 | /** |
@@ -1620,7 +1620,7 @@ discard block |
||
| 1620 | 1620 | * @param array $emails List of email addresses to notify for comment moderation. |
| 1621 | 1621 | * @param int $comment_id Comment ID. |
| 1622 | 1622 | */ |
| 1623 | - $emails = apply_filters( 'comment_moderation_recipients', $emails, $comment_id ); |
|
| 1623 | + $emails = apply_filters('comment_moderation_recipients', $emails, $comment_id); |
|
| 1624 | 1624 | |
| 1625 | 1625 | /** |
| 1626 | 1626 | * Filter the comment moderation email text. |
@@ -1630,7 +1630,7 @@ discard block |
||
| 1630 | 1630 | * @param string $notify_message Text of the comment moderation email. |
| 1631 | 1631 | * @param int $comment_id Comment ID. |
| 1632 | 1632 | */ |
| 1633 | - $notify_message = apply_filters( 'comment_moderation_text', $notify_message, $comment_id ); |
|
| 1633 | + $notify_message = apply_filters('comment_moderation_text', $notify_message, $comment_id); |
|
| 1634 | 1634 | |
| 1635 | 1635 | /** |
| 1636 | 1636 | * Filter the comment moderation email subject. |
@@ -1640,7 +1640,7 @@ discard block |
||
| 1640 | 1640 | * @param string $subject Subject of the comment moderation email. |
| 1641 | 1641 | * @param int $comment_id Comment ID. |
| 1642 | 1642 | */ |
| 1643 | - $subject = apply_filters( 'comment_moderation_subject', $subject, $comment_id ); |
|
| 1643 | + $subject = apply_filters('comment_moderation_subject', $subject, $comment_id); |
|
| 1644 | 1644 | |
| 1645 | 1645 | /** |
| 1646 | 1646 | * Filter the comment moderation email headers. |
@@ -1650,17 +1650,17 @@ discard block |
||
| 1650 | 1650 | * @param string $message_headers Headers for the comment moderation email. |
| 1651 | 1651 | * @param int $comment_id Comment ID. |
| 1652 | 1652 | */ |
| 1653 | - $message_headers = apply_filters( 'comment_moderation_headers', $message_headers, $comment_id ); |
|
| 1653 | + $message_headers = apply_filters('comment_moderation_headers', $message_headers, $comment_id); |
|
| 1654 | 1654 | |
| 1655 | - foreach ( $emails as $email ) { |
|
| 1656 | - @wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers ); |
|
| 1655 | + foreach ($emails as $email) { |
|
| 1656 | + @wp_mail($email, wp_specialchars_decode($subject), $notify_message, $message_headers); |
|
| 1657 | 1657 | } |
| 1658 | 1658 | |
| 1659 | 1659 | return true; |
| 1660 | 1660 | } |
| 1661 | 1661 | endif; |
| 1662 | 1662 | |
| 1663 | -if ( !function_exists('wp_password_change_notification') ) : |
|
| 1663 | +if ( ! function_exists('wp_password_change_notification')) : |
|
| 1664 | 1664 | /** |
| 1665 | 1665 | * Notify the blog admin of a user changing password, normally via email. |
| 1666 | 1666 | * |
@@ -1671,8 +1671,8 @@ discard block |
||
| 1671 | 1671 | function wp_password_change_notification(&$user) { |
| 1672 | 1672 | // send a copy of password change notification to the admin |
| 1673 | 1673 | // but check to see if it's the admin whose password we're changing, and skip this |
| 1674 | - if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) ) { |
|
| 1675 | - $message = sprintf(__('Password Lost and Changed for user: %s'), $user->user_login) . "\r\n"; |
|
| 1674 | + if (0 !== strcasecmp($user->user_email, get_option('admin_email'))) { |
|
| 1675 | + $message = sprintf(__('Password Lost and Changed for user: %s'), $user->user_login)."\r\n"; |
|
| 1676 | 1676 | // The blogname option is escaped with esc_html on the way into the database in sanitize_option |
| 1677 | 1677 | // we want to reverse this for the plain text arena of emails. |
| 1678 | 1678 | $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); |
@@ -1681,7 +1681,7 @@ discard block |
||
| 1681 | 1681 | } |
| 1682 | 1682 | endif; |
| 1683 | 1683 | |
| 1684 | -if ( !function_exists('wp_new_user_notification') ) : |
|
| 1684 | +if ( ! function_exists('wp_new_user_notification')) : |
|
| 1685 | 1685 | /** |
| 1686 | 1686 | * Email login credentials to a newly-registered user. |
| 1687 | 1687 | * |
@@ -1695,49 +1695,49 @@ discard block |
||
| 1695 | 1695 | * string (admin only), or 'both' (admin and user). The empty string value was kept |
| 1696 | 1696 | * for backward-compatibility purposes with the renamed parameter. Default empty. |
| 1697 | 1697 | */ |
| 1698 | -function wp_new_user_notification( $user_id, $notify = '' ) { |
|
| 1698 | +function wp_new_user_notification($user_id, $notify = '') { |
|
| 1699 | 1699 | global $wpdb; |
| 1700 | - $user = get_userdata( $user_id ); |
|
| 1700 | + $user = get_userdata($user_id); |
|
| 1701 | 1701 | |
| 1702 | 1702 | // The blogname option is escaped with esc_html on the way into the database in sanitize_option |
| 1703 | 1703 | // we want to reverse this for the plain text arena of emails. |
| 1704 | 1704 | $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); |
| 1705 | 1705 | |
| 1706 | - $message = sprintf(__('New user registration on your site %s:'), $blogname) . "\r\n\r\n"; |
|
| 1707 | - $message .= sprintf(__('Username: %s'), $user->user_login) . "\r\n\r\n"; |
|
| 1708 | - $message .= sprintf(__('E-mail: %s'), $user->user_email) . "\r\n"; |
|
| 1706 | + $message = sprintf(__('New user registration on your site %s:'), $blogname)."\r\n\r\n"; |
|
| 1707 | + $message .= sprintf(__('Username: %s'), $user->user_login)."\r\n\r\n"; |
|
| 1708 | + $message .= sprintf(__('E-mail: %s'), $user->user_email)."\r\n"; |
|
| 1709 | 1709 | |
| 1710 | 1710 | @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), $blogname), $message); |
| 1711 | 1711 | |
| 1712 | - if ( 'admin' === $notify || empty( $notify ) ) { |
|
| 1712 | + if ('admin' === $notify || empty($notify)) { |
|
| 1713 | 1713 | return; |
| 1714 | 1714 | } |
| 1715 | 1715 | |
| 1716 | 1716 | // Generate something random for a password reset key. |
| 1717 | - $key = wp_generate_password( 20, false ); |
|
| 1717 | + $key = wp_generate_password(20, false); |
|
| 1718 | 1718 | |
| 1719 | 1719 | /** This action is documented in wp-login.php */ |
| 1720 | - do_action( 'retrieve_password_key', $user->user_login, $key ); |
|
| 1720 | + do_action('retrieve_password_key', $user->user_login, $key); |
|
| 1721 | 1721 | |
| 1722 | 1722 | // Now insert the key, hashed, into the DB. |
| 1723 | - if ( empty( $wp_hasher ) ) { |
|
| 1724 | - require_once ABSPATH . WPINC . '/class-phpass.php'; |
|
| 1725 | - $wp_hasher = new PasswordHash( 8, true ); |
|
| 1723 | + if (empty($wp_hasher)) { |
|
| 1724 | + require_once ABSPATH.WPINC.'/class-phpass.php'; |
|
| 1725 | + $wp_hasher = new PasswordHash(8, true); |
|
| 1726 | 1726 | } |
| 1727 | - $hashed = time() . ':' . $wp_hasher->HashPassword( $key ); |
|
| 1728 | - $wpdb->update( $wpdb->users, array( 'user_activation_key' => $hashed ), array( 'user_login' => $user->user_login ) ); |
|
| 1727 | + $hashed = time().':'.$wp_hasher->HashPassword($key); |
|
| 1728 | + $wpdb->update($wpdb->users, array('user_activation_key' => $hashed), array('user_login' => $user->user_login)); |
|
| 1729 | 1729 | |
| 1730 | - $message = sprintf(__('Username: %s'), $user->user_login) . "\r\n\r\n"; |
|
| 1731 | - $message .= __('To set your password, visit the following address:') . "\r\n\r\n"; |
|
| 1732 | - $message .= '<' . network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user->user_login), 'login') . ">\r\n\r\n"; |
|
| 1730 | + $message = sprintf(__('Username: %s'), $user->user_login)."\r\n\r\n"; |
|
| 1731 | + $message .= __('To set your password, visit the following address:')."\r\n\r\n"; |
|
| 1732 | + $message .= '<'.network_site_url("wp-login.php?action=rp&key=$key&login=".rawurlencode($user->user_login), 'login').">\r\n\r\n"; |
|
| 1733 | 1733 | |
| 1734 | - $message .= wp_login_url() . "\r\n"; |
|
| 1734 | + $message .= wp_login_url()."\r\n"; |
|
| 1735 | 1735 | |
| 1736 | 1736 | wp_mail($user->user_email, sprintf(__('[%s] Your username and password info'), $blogname), $message); |
| 1737 | 1737 | } |
| 1738 | 1738 | endif; |
| 1739 | 1739 | |
| 1740 | -if ( !function_exists('wp_nonce_tick') ) : |
|
| 1740 | +if ( ! function_exists('wp_nonce_tick')) : |
|
| 1741 | 1741 | /** |
| 1742 | 1742 | * Get the time-dependent variable for nonce creation. |
| 1743 | 1743 | * |
@@ -1756,13 +1756,13 @@ discard block |
||
| 1756 | 1756 | * |
| 1757 | 1757 | * @param int $lifespan Lifespan of nonces in seconds. Default 86,400 seconds, or one day. |
| 1758 | 1758 | */ |
| 1759 | - $nonce_life = apply_filters( 'nonce_life', DAY_IN_SECONDS ); |
|
| 1759 | + $nonce_life = apply_filters('nonce_life', DAY_IN_SECONDS); |
|
| 1760 | 1760 | |
| 1761 | - return ceil(time() / ( $nonce_life / 2 )); |
|
| 1761 | + return ceil(time() / ($nonce_life / 2)); |
|
| 1762 | 1762 | } |
| 1763 | 1763 | endif; |
| 1764 | 1764 | |
| 1765 | -if ( !function_exists('wp_verify_nonce') ) : |
|
| 1765 | +if ( ! function_exists('wp_verify_nonce')) : |
|
| 1766 | 1766 | /** |
| 1767 | 1767 | * Verify that correct nonce was used with time limit. |
| 1768 | 1768 | * |
@@ -1776,11 +1776,11 @@ discard block |
||
| 1776 | 1776 | * @return false|int False if the nonce is invalid, 1 if the nonce is valid and generated between |
| 1777 | 1777 | * 0-12 hours ago, 2 if the nonce is valid and generated between 12-24 hours ago. |
| 1778 | 1778 | */ |
| 1779 | -function wp_verify_nonce( $nonce, $action = -1 ) { |
|
| 1779 | +function wp_verify_nonce($nonce, $action = -1) { |
|
| 1780 | 1780 | $nonce = (string) $nonce; |
| 1781 | 1781 | $user = wp_get_current_user(); |
| 1782 | 1782 | $uid = (int) $user->ID; |
| 1783 | - if ( ! $uid ) { |
|
| 1783 | + if ( ! $uid) { |
|
| 1784 | 1784 | /** |
| 1785 | 1785 | * Filter whether the user who generated the nonce is logged out. |
| 1786 | 1786 | * |
@@ -1789,10 +1789,10 @@ discard block |
||
| 1789 | 1789 | * @param int $uid ID of the nonce-owning user. |
| 1790 | 1790 | * @param string $action The nonce action. |
| 1791 | 1791 | */ |
| 1792 | - $uid = apply_filters( 'nonce_user_logged_out', $uid, $action ); |
|
| 1792 | + $uid = apply_filters('nonce_user_logged_out', $uid, $action); |
|
| 1793 | 1793 | } |
| 1794 | 1794 | |
| 1795 | - if ( empty( $nonce ) ) { |
|
| 1795 | + if (empty($nonce)) { |
|
| 1796 | 1796 | return false; |
| 1797 | 1797 | } |
| 1798 | 1798 | |
@@ -1800,14 +1800,14 @@ discard block |
||
| 1800 | 1800 | $i = wp_nonce_tick(); |
| 1801 | 1801 | |
| 1802 | 1802 | // Nonce generated 0-12 hours ago |
| 1803 | - $expected = substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce'), -12, 10 ); |
|
| 1804 | - if ( hash_equals( $expected, $nonce ) ) { |
|
| 1803 | + $expected = substr(wp_hash($i.'|'.$action.'|'.$uid.'|'.$token, 'nonce'), -12, 10); |
|
| 1804 | + if (hash_equals($expected, $nonce)) { |
|
| 1805 | 1805 | return 1; |
| 1806 | 1806 | } |
| 1807 | 1807 | |
| 1808 | 1808 | // Nonce generated 12-24 hours ago |
| 1809 | - $expected = substr( wp_hash( ( $i - 1 ) . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 ); |
|
| 1810 | - if ( hash_equals( $expected, $nonce ) ) { |
|
| 1809 | + $expected = substr(wp_hash(($i - 1).'|'.$action.'|'.$uid.'|'.$token, 'nonce'), -12, 10); |
|
| 1810 | + if (hash_equals($expected, $nonce)) { |
|
| 1811 | 1811 | return 2; |
| 1812 | 1812 | } |
| 1813 | 1813 | |
@@ -1816,7 +1816,7 @@ discard block |
||
| 1816 | 1816 | } |
| 1817 | 1817 | endif; |
| 1818 | 1818 | |
| 1819 | -if ( !function_exists('wp_create_nonce') ) : |
|
| 1819 | +if ( ! function_exists('wp_create_nonce')) : |
|
| 1820 | 1820 | /** |
| 1821 | 1821 | * Creates a cryptographic token tied to a specific action, user, and window of time. |
| 1822 | 1822 | * |
@@ -1828,19 +1828,19 @@ discard block |
||
| 1828 | 1828 | function wp_create_nonce($action = -1) { |
| 1829 | 1829 | $user = wp_get_current_user(); |
| 1830 | 1830 | $uid = (int) $user->ID; |
| 1831 | - if ( ! $uid ) { |
|
| 1831 | + if ( ! $uid) { |
|
| 1832 | 1832 | /** This filter is documented in wp-includes/pluggable.php */ |
| 1833 | - $uid = apply_filters( 'nonce_user_logged_out', $uid, $action ); |
|
| 1833 | + $uid = apply_filters('nonce_user_logged_out', $uid, $action); |
|
| 1834 | 1834 | } |
| 1835 | 1835 | |
| 1836 | 1836 | $token = wp_get_session_token(); |
| 1837 | 1837 | $i = wp_nonce_tick(); |
| 1838 | 1838 | |
| 1839 | - return substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 ); |
|
| 1839 | + return substr(wp_hash($i.'|'.$action.'|'.$uid.'|'.$token, 'nonce'), -12, 10); |
|
| 1840 | 1840 | } |
| 1841 | 1841 | endif; |
| 1842 | 1842 | |
| 1843 | -if ( !function_exists('wp_salt') ) : |
|
| 1843 | +if ( ! function_exists('wp_salt')) : |
|
| 1844 | 1844 | /** |
| 1845 | 1845 | * Get salt to add to hashes. |
| 1846 | 1846 | * |
@@ -1876,9 +1876,9 @@ discard block |
||
| 1876 | 1876 | * @param string $scheme Authentication scheme (auth, secure_auth, logged_in, nonce) |
| 1877 | 1877 | * @return string Salt value |
| 1878 | 1878 | */ |
| 1879 | -function wp_salt( $scheme = 'auth' ) { |
|
| 1879 | +function wp_salt($scheme = 'auth') { |
|
| 1880 | 1880 | static $cached_salts = array(); |
| 1881 | - if ( isset( $cached_salts[ $scheme ] ) ) { |
|
| 1881 | + if (isset($cached_salts[$scheme])) { |
|
| 1882 | 1882 | /** |
| 1883 | 1883 | * Filter the WordPress salt. |
| 1884 | 1884 | * |
@@ -1888,19 +1888,19 @@ discard block |
||
| 1888 | 1888 | * @param string $scheme Authentication scheme. Values include 'auth', |
| 1889 | 1889 | * 'secure_auth', 'logged_in', and 'nonce'. |
| 1890 | 1890 | */ |
| 1891 | - return apply_filters( 'salt', $cached_salts[ $scheme ], $scheme ); |
|
| 1891 | + return apply_filters('salt', $cached_salts[$scheme], $scheme); |
|
| 1892 | 1892 | } |
| 1893 | 1893 | |
| 1894 | 1894 | static $duplicated_keys; |
| 1895 | - if ( null === $duplicated_keys ) { |
|
| 1896 | - $duplicated_keys = array( 'put your unique phrase here' => true ); |
|
| 1897 | - foreach ( array( 'AUTH', 'SECURE_AUTH', 'LOGGED_IN', 'NONCE', 'SECRET' ) as $first ) { |
|
| 1898 | - foreach ( array( 'KEY', 'SALT' ) as $second ) { |
|
| 1899 | - if ( ! defined( "{$first}_{$second}" ) ) { |
|
| 1895 | + if (null === $duplicated_keys) { |
|
| 1896 | + $duplicated_keys = array('put your unique phrase here' => true); |
|
| 1897 | + foreach (array('AUTH', 'SECURE_AUTH', 'LOGGED_IN', 'NONCE', 'SECRET') as $first) { |
|
| 1898 | + foreach (array('KEY', 'SALT') as $second) { |
|
| 1899 | + if ( ! defined("{$first}_{$second}")) { |
|
| 1900 | 1900 | continue; |
| 1901 | 1901 | } |
| 1902 | - $value = constant( "{$first}_{$second}" ); |
|
| 1903 | - $duplicated_keys[ $value ] = isset( $duplicated_keys[ $value ] ); |
|
| 1902 | + $value = constant("{$first}_{$second}"); |
|
| 1903 | + $duplicated_keys[$value] = isset($duplicated_keys[$value]); |
|
| 1904 | 1904 | } |
| 1905 | 1905 | } |
| 1906 | 1906 | } |
@@ -1909,45 +1909,45 @@ discard block |
||
| 1909 | 1909 | 'key' => '', |
| 1910 | 1910 | 'salt' => '' |
| 1911 | 1911 | ); |
| 1912 | - if ( defined( 'SECRET_KEY' ) && SECRET_KEY && empty( $duplicated_keys[ SECRET_KEY ] ) ) { |
|
| 1912 | + if (defined('SECRET_KEY') && SECRET_KEY && empty($duplicated_keys[SECRET_KEY])) { |
|
| 1913 | 1913 | $values['key'] = SECRET_KEY; |
| 1914 | 1914 | } |
| 1915 | - if ( 'auth' == $scheme && defined( 'SECRET_SALT' ) && SECRET_SALT && empty( $duplicated_keys[ SECRET_SALT ] ) ) { |
|
| 1915 | + if ('auth' == $scheme && defined('SECRET_SALT') && SECRET_SALT && empty($duplicated_keys[SECRET_SALT])) { |
|
| 1916 | 1916 | $values['salt'] = SECRET_SALT; |
| 1917 | 1917 | } |
| 1918 | 1918 | |
| 1919 | - if ( in_array( $scheme, array( 'auth', 'secure_auth', 'logged_in', 'nonce' ) ) ) { |
|
| 1920 | - foreach ( array( 'key', 'salt' ) as $type ) { |
|
| 1921 | - $const = strtoupper( "{$scheme}_{$type}" ); |
|
| 1922 | - if ( defined( $const ) && constant( $const ) && empty( $duplicated_keys[ constant( $const ) ] ) ) { |
|
| 1923 | - $values[ $type ] = constant( $const ); |
|
| 1924 | - } elseif ( ! $values[ $type ] ) { |
|
| 1925 | - $values[ $type ] = get_site_option( "{$scheme}_{$type}" ); |
|
| 1926 | - if ( ! $values[ $type ] ) { |
|
| 1927 | - $values[ $type ] = wp_generate_password( 64, true, true ); |
|
| 1928 | - update_site_option( "{$scheme}_{$type}", $values[ $type ] ); |
|
| 1919 | + if (in_array($scheme, array('auth', 'secure_auth', 'logged_in', 'nonce'))) { |
|
| 1920 | + foreach (array('key', 'salt') as $type) { |
|
| 1921 | + $const = strtoupper("{$scheme}_{$type}"); |
|
| 1922 | + if (defined($const) && constant($const) && empty($duplicated_keys[constant($const)])) { |
|
| 1923 | + $values[$type] = constant($const); |
|
| 1924 | + } elseif ( ! $values[$type]) { |
|
| 1925 | + $values[$type] = get_site_option("{$scheme}_{$type}"); |
|
| 1926 | + if ( ! $values[$type]) { |
|
| 1927 | + $values[$type] = wp_generate_password(64, true, true); |
|
| 1928 | + update_site_option("{$scheme}_{$type}", $values[$type]); |
|
| 1929 | 1929 | } |
| 1930 | 1930 | } |
| 1931 | 1931 | } |
| 1932 | 1932 | } else { |
| 1933 | - if ( ! $values['key'] ) { |
|
| 1934 | - $values['key'] = get_site_option( 'secret_key' ); |
|
| 1935 | - if ( ! $values['key'] ) { |
|
| 1936 | - $values['key'] = wp_generate_password( 64, true, true ); |
|
| 1937 | - update_site_option( 'secret_key', $values['key'] ); |
|
| 1933 | + if ( ! $values['key']) { |
|
| 1934 | + $values['key'] = get_site_option('secret_key'); |
|
| 1935 | + if ( ! $values['key']) { |
|
| 1936 | + $values['key'] = wp_generate_password(64, true, true); |
|
| 1937 | + update_site_option('secret_key', $values['key']); |
|
| 1938 | 1938 | } |
| 1939 | 1939 | } |
| 1940 | - $values['salt'] = hash_hmac( 'md5', $scheme, $values['key'] ); |
|
| 1940 | + $values['salt'] = hash_hmac('md5', $scheme, $values['key']); |
|
| 1941 | 1941 | } |
| 1942 | 1942 | |
| 1943 | - $cached_salts[ $scheme ] = $values['key'] . $values['salt']; |
|
| 1943 | + $cached_salts[$scheme] = $values['key'].$values['salt']; |
|
| 1944 | 1944 | |
| 1945 | 1945 | /** This filter is documented in wp-includes/pluggable.php */ |
| 1946 | - return apply_filters( 'salt', $cached_salts[ $scheme ], $scheme ); |
|
| 1946 | + return apply_filters('salt', $cached_salts[$scheme], $scheme); |
|
| 1947 | 1947 | } |
| 1948 | 1948 | endif; |
| 1949 | 1949 | |
| 1950 | -if ( !function_exists('wp_hash') ) : |
|
| 1950 | +if ( ! function_exists('wp_hash')) : |
|
| 1951 | 1951 | /** |
| 1952 | 1952 | * Get hash of given string. |
| 1953 | 1953 | * |
@@ -1963,7 +1963,7 @@ discard block |
||
| 1963 | 1963 | } |
| 1964 | 1964 | endif; |
| 1965 | 1965 | |
| 1966 | -if ( !function_exists('wp_hash_password') ) : |
|
| 1966 | +if ( ! function_exists('wp_hash_password')) : |
|
| 1967 | 1967 | /** |
| 1968 | 1968 | * Create a hash (encrypt) of a plain text password. |
| 1969 | 1969 | * |
@@ -1980,17 +1980,17 @@ discard block |
||
| 1980 | 1980 | function wp_hash_password($password) { |
| 1981 | 1981 | global $wp_hasher; |
| 1982 | 1982 | |
| 1983 | - if ( empty($wp_hasher) ) { |
|
| 1984 | - require_once( ABSPATH . WPINC . '/class-phpass.php'); |
|
| 1983 | + if (empty($wp_hasher)) { |
|
| 1984 | + require_once(ABSPATH.WPINC.'/class-phpass.php'); |
|
| 1985 | 1985 | // By default, use the portable hash from phpass |
| 1986 | 1986 | $wp_hasher = new PasswordHash(8, true); |
| 1987 | 1987 | } |
| 1988 | 1988 | |
| 1989 | - return $wp_hasher->HashPassword( trim( $password ) ); |
|
| 1989 | + return $wp_hasher->HashPassword(trim($password)); |
|
| 1990 | 1990 | } |
| 1991 | 1991 | endif; |
| 1992 | 1992 | |
| 1993 | -if ( !function_exists('wp_check_password') ) : |
|
| 1993 | +if ( ! function_exists('wp_check_password')) : |
|
| 1994 | 1994 | /** |
| 1995 | 1995 | * Checks the plaintext password against the encrypted Password. |
| 1996 | 1996 | * |
@@ -2016,9 +2016,9 @@ discard block |
||
| 2016 | 2016 | global $wp_hasher; |
| 2017 | 2017 | |
| 2018 | 2018 | // If the hash is still md5... |
| 2019 | - if ( strlen($hash) <= 32 ) { |
|
| 2020 | - $check = hash_equals( $hash, md5( $password ) ); |
|
| 2021 | - if ( $check && $user_id ) { |
|
| 2019 | + if (strlen($hash) <= 32) { |
|
| 2020 | + $check = hash_equals($hash, md5($password)); |
|
| 2021 | + if ($check && $user_id) { |
|
| 2022 | 2022 | // Rehash using new hash. |
| 2023 | 2023 | wp_set_password($password, $user_id); |
| 2024 | 2024 | $hash = wp_hash_password($password); |
@@ -2034,13 +2034,13 @@ discard block |
||
| 2034 | 2034 | * @param string $hash The hashed password. |
| 2035 | 2035 | * @param int $user_id User ID. |
| 2036 | 2036 | */ |
| 2037 | - return apply_filters( 'check_password', $check, $password, $hash, $user_id ); |
|
| 2037 | + return apply_filters('check_password', $check, $password, $hash, $user_id); |
|
| 2038 | 2038 | } |
| 2039 | 2039 | |
| 2040 | 2040 | // If the stored hash is longer than an MD5, presume the |
| 2041 | 2041 | // new style phpass portable hash. |
| 2042 | - if ( empty($wp_hasher) ) { |
|
| 2043 | - require_once( ABSPATH . WPINC . '/class-phpass.php'); |
|
| 2042 | + if (empty($wp_hasher)) { |
|
| 2043 | + require_once(ABSPATH.WPINC.'/class-phpass.php'); |
|
| 2044 | 2044 | // By default, use the portable hash from phpass |
| 2045 | 2045 | $wp_hasher = new PasswordHash(8, true); |
| 2046 | 2046 | } |
@@ -2048,11 +2048,11 @@ discard block |
||
| 2048 | 2048 | $check = $wp_hasher->CheckPassword($password, $hash); |
| 2049 | 2049 | |
| 2050 | 2050 | /** This filter is documented in wp-includes/pluggable.php */ |
| 2051 | - return apply_filters( 'check_password', $check, $password, $hash, $user_id ); |
|
| 2051 | + return apply_filters('check_password', $check, $password, $hash, $user_id); |
|
| 2052 | 2052 | } |
| 2053 | 2053 | endif; |
| 2054 | 2054 | |
| 2055 | -if ( !function_exists('wp_generate_password') ) : |
|
| 2055 | +if ( ! function_exists('wp_generate_password')) : |
|
| 2056 | 2056 | /** |
| 2057 | 2057 | * Generates a random password drawn from the defined set of characters. |
| 2058 | 2058 | * |
@@ -2065,15 +2065,15 @@ discard block |
||
| 2065 | 2065 | * Used when generating secret keys and salts. Default false. |
| 2066 | 2066 | * @return string The random password. |
| 2067 | 2067 | */ |
| 2068 | -function wp_generate_password( $length = 12, $special_chars = true, $extra_special_chars = false ) { |
|
| 2068 | +function wp_generate_password($length = 12, $special_chars = true, $extra_special_chars = false) { |
|
| 2069 | 2069 | $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; |
| 2070 | - if ( $special_chars ) |
|
| 2070 | + if ($special_chars) |
|
| 2071 | 2071 | $chars .= '!@#$%^&*()'; |
| 2072 | - if ( $extra_special_chars ) |
|
| 2072 | + if ($extra_special_chars) |
|
| 2073 | 2073 | $chars .= '-_ []{}<>~`+=,.;:/?|'; |
| 2074 | 2074 | |
| 2075 | 2075 | $password = ''; |
| 2076 | - for ( $i = 0; $i < $length; $i++ ) { |
|
| 2076 | + for ($i = 0; $i < $length; $i++) { |
|
| 2077 | 2077 | $password .= substr($chars, wp_rand(0, strlen($chars) - 1), 1); |
| 2078 | 2078 | } |
| 2079 | 2079 | |
@@ -2084,11 +2084,11 @@ discard block |
||
| 2084 | 2084 | * |
| 2085 | 2085 | * @param string $password The generated password. |
| 2086 | 2086 | */ |
| 2087 | - return apply_filters( 'random_password', $password ); |
|
| 2087 | + return apply_filters('random_password', $password); |
|
| 2088 | 2088 | } |
| 2089 | 2089 | endif; |
| 2090 | 2090 | |
| 2091 | -if ( !function_exists('wp_rand') ) : |
|
| 2091 | +if ( ! function_exists('wp_rand')) : |
|
| 2092 | 2092 | /** |
| 2093 | 2093 | * Generates a random number |
| 2094 | 2094 | * |
@@ -2101,22 +2101,22 @@ discard block |
||
| 2101 | 2101 | * @param int $max Upper limit for the generated number |
| 2102 | 2102 | * @return int A random number between min and max |
| 2103 | 2103 | */ |
| 2104 | -function wp_rand( $min = 0, $max = 0 ) { |
|
| 2104 | +function wp_rand($min = 0, $max = 0) { |
|
| 2105 | 2105 | global $rnd_value; |
| 2106 | 2106 | |
| 2107 | 2107 | // Reset $rnd_value after 14 uses |
| 2108 | 2108 | // 32(md5) + 40(sha1) + 40(sha1) / 8 = 14 random numbers from $rnd_value |
| 2109 | - if ( strlen($rnd_value) < 8 ) { |
|
| 2110 | - if ( defined( 'WP_SETUP_CONFIG' ) ) |
|
| 2109 | + if (strlen($rnd_value) < 8) { |
|
| 2110 | + if (defined('WP_SETUP_CONFIG')) |
|
| 2111 | 2111 | static $seed = ''; |
| 2112 | 2112 | else |
| 2113 | 2113 | $seed = get_transient('random_seed'); |
| 2114 | - $rnd_value = md5( uniqid(microtime() . mt_rand(), true ) . $seed ); |
|
| 2114 | + $rnd_value = md5(uniqid(microtime().mt_rand(), true).$seed); |
|
| 2115 | 2115 | $rnd_value .= sha1($rnd_value); |
| 2116 | - $rnd_value .= sha1($rnd_value . $seed); |
|
| 2117 | - $seed = md5($seed . $rnd_value); |
|
| 2118 | - if ( ! defined( 'WP_SETUP_CONFIG' ) && ! defined( 'WP_INSTALLING' ) ) { |
|
| 2119 | - set_transient( 'random_seed', $seed ); |
|
| 2116 | + $rnd_value .= sha1($rnd_value.$seed); |
|
| 2117 | + $seed = md5($seed.$rnd_value); |
|
| 2118 | + if ( ! defined('WP_SETUP_CONFIG') && ! defined('WP_INSTALLING')) { |
|
| 2119 | + set_transient('random_seed', $seed); |
|
| 2120 | 2120 | } |
| 2121 | 2121 | } |
| 2122 | 2122 | |
@@ -2132,14 +2132,14 @@ discard block |
||
| 2132 | 2132 | $max_random_number = 3000000000 === 2147483647 ? (float) "4294967295" : 4294967295; // 4294967295 = 0xffffffff |
| 2133 | 2133 | |
| 2134 | 2134 | // Reduce the value to be within the min - max range |
| 2135 | - if ( $max != 0 ) |
|
| 2136 | - $value = $min + ( $max - $min + 1 ) * $value / ( $max_random_number + 1 ); |
|
| 2135 | + if ($max != 0) |
|
| 2136 | + $value = $min + ($max - $min + 1) * $value / ($max_random_number + 1); |
|
| 2137 | 2137 | |
| 2138 | 2138 | return abs(intval($value)); |
| 2139 | 2139 | } |
| 2140 | 2140 | endif; |
| 2141 | 2141 | |
| 2142 | -if ( !function_exists('wp_set_password') ) : |
|
| 2142 | +if ( ! function_exists('wp_set_password')) : |
|
| 2143 | 2143 | /** |
| 2144 | 2144 | * Updates the user's password with a new encrypted one. |
| 2145 | 2145 | * |
@@ -2157,17 +2157,17 @@ discard block |
||
| 2157 | 2157 | * @param string $password The plaintext new user password |
| 2158 | 2158 | * @param int $user_id User ID |
| 2159 | 2159 | */ |
| 2160 | -function wp_set_password( $password, $user_id ) { |
|
| 2160 | +function wp_set_password($password, $user_id) { |
|
| 2161 | 2161 | global $wpdb; |
| 2162 | 2162 | |
| 2163 | - $hash = wp_hash_password( $password ); |
|
| 2164 | - $wpdb->update($wpdb->users, array('user_pass' => $hash, 'user_activation_key' => ''), array('ID' => $user_id) ); |
|
| 2163 | + $hash = wp_hash_password($password); |
|
| 2164 | + $wpdb->update($wpdb->users, array('user_pass' => $hash, 'user_activation_key' => ''), array('ID' => $user_id)); |
|
| 2165 | 2165 | |
| 2166 | 2166 | wp_cache_delete($user_id, 'users'); |
| 2167 | 2167 | } |
| 2168 | 2168 | endif; |
| 2169 | 2169 | |
| 2170 | -if ( !function_exists( 'get_avatar' ) ) : |
|
| 2170 | +if ( ! function_exists('get_avatar')) : |
|
| 2171 | 2171 | /** |
| 2172 | 2172 | * Retrieve the avatar `<img>` tag for a user, email address, MD5 hash, comment, or post. |
| 2173 | 2173 | * |
@@ -2202,15 +2202,15 @@ discard block |
||
| 2202 | 2202 | * } |
| 2203 | 2203 | * @return false|string `<img>` tag for the user's avatar. False on failure. |
| 2204 | 2204 | */ |
| 2205 | -function get_avatar( $id_or_email, $size = 96, $default = '', $alt = '', $args = null ) { |
|
| 2205 | +function get_avatar($id_or_email, $size = 96, $default = '', $alt = '', $args = null) { |
|
| 2206 | 2206 | $defaults = array( |
| 2207 | 2207 | // get_avatar_data() args. |
| 2208 | 2208 | 'size' => 96, |
| 2209 | 2209 | 'height' => null, |
| 2210 | 2210 | 'width' => null, |
| 2211 | - 'default' => get_option( 'avatar_default', 'mystery' ), |
|
| 2211 | + 'default' => get_option('avatar_default', 'mystery'), |
|
| 2212 | 2212 | 'force_default' => false, |
| 2213 | - 'rating' => get_option( 'avatar_rating' ), |
|
| 2213 | + 'rating' => get_option('avatar_rating'), |
|
| 2214 | 2214 | 'scheme' => null, |
| 2215 | 2215 | 'alt' => '', |
| 2216 | 2216 | 'class' => null, |
@@ -2218,7 +2218,7 @@ discard block |
||
| 2218 | 2218 | 'extra_attr' => '', |
| 2219 | 2219 | ); |
| 2220 | 2220 | |
| 2221 | - if ( empty( $args ) ) { |
|
| 2221 | + if (empty($args)) { |
|
| 2222 | 2222 | $args = array(); |
| 2223 | 2223 | } |
| 2224 | 2224 | |
@@ -2226,12 +2226,12 @@ discard block |
||
| 2226 | 2226 | $args['default'] = $default; |
| 2227 | 2227 | $args['alt'] = $alt; |
| 2228 | 2228 | |
| 2229 | - $args = wp_parse_args( $args, $defaults ); |
|
| 2229 | + $args = wp_parse_args($args, $defaults); |
|
| 2230 | 2230 | |
| 2231 | - if ( empty( $args['height'] ) ) { |
|
| 2231 | + if (empty($args['height'])) { |
|
| 2232 | 2232 | $args['height'] = $args['size']; |
| 2233 | 2233 | } |
| 2234 | - if ( empty( $args['width'] ) ) { |
|
| 2234 | + if (empty($args['width'])) { |
|
| 2235 | 2235 | $args['width'] = $args['size']; |
| 2236 | 2236 | } |
| 2237 | 2237 | |
@@ -2247,36 +2247,36 @@ discard block |
||
| 2247 | 2247 | * @param int|object|string $id_or_email A user ID, email address, or comment object. |
| 2248 | 2248 | * @param array $args Arguments passed to get_avatar_url(), after processing. |
| 2249 | 2249 | */ |
| 2250 | - $avatar = apply_filters( 'pre_get_avatar', null, $id_or_email, $args ); |
|
| 2250 | + $avatar = apply_filters('pre_get_avatar', null, $id_or_email, $args); |
|
| 2251 | 2251 | |
| 2252 | - if ( ! is_null( $avatar ) ) { |
|
| 2252 | + if ( ! is_null($avatar)) { |
|
| 2253 | 2253 | /** This filter is documented in wp-includes/pluggable.php */ |
| 2254 | - return apply_filters( 'get_avatar', $avatar, $id_or_email, $args['size'], $args['default'], $args['alt'], $args ); |
|
| 2254 | + return apply_filters('get_avatar', $avatar, $id_or_email, $args['size'], $args['default'], $args['alt'], $args); |
|
| 2255 | 2255 | } |
| 2256 | 2256 | |
| 2257 | - if ( ! $args['force_display'] && ! get_option( 'show_avatars' ) ) { |
|
| 2257 | + if ( ! $args['force_display'] && ! get_option('show_avatars')) { |
|
| 2258 | 2258 | return false; |
| 2259 | 2259 | } |
| 2260 | 2260 | |
| 2261 | - $url2x = get_avatar_url( $id_or_email, array_merge( $args, array( 'size' => $args['size'] * 2 ) ) ); |
|
| 2261 | + $url2x = get_avatar_url($id_or_email, array_merge($args, array('size' => $args['size'] * 2))); |
|
| 2262 | 2262 | |
| 2263 | - $args = get_avatar_data( $id_or_email, $args ); |
|
| 2263 | + $args = get_avatar_data($id_or_email, $args); |
|
| 2264 | 2264 | |
| 2265 | 2265 | $url = $args['url']; |
| 2266 | 2266 | |
| 2267 | - if ( ! $url || is_wp_error( $url ) ) { |
|
| 2267 | + if ( ! $url || is_wp_error($url)) { |
|
| 2268 | 2268 | return false; |
| 2269 | 2269 | } |
| 2270 | 2270 | |
| 2271 | - $class = array( 'avatar', 'avatar-' . (int) $args['size'], 'photo' ); |
|
| 2271 | + $class = array('avatar', 'avatar-'.(int) $args['size'], 'photo'); |
|
| 2272 | 2272 | |
| 2273 | - if ( ! $args['found_avatar'] || $args['force_default'] ) { |
|
| 2273 | + if ( ! $args['found_avatar'] || $args['force_default']) { |
|
| 2274 | 2274 | $class[] = 'avatar-default'; |
| 2275 | 2275 | } |
| 2276 | 2276 | |
| 2277 | - if ( $args['class'] ) { |
|
| 2278 | - if ( is_array( $args['class'] ) ) { |
|
| 2279 | - $class = array_merge( $class, $args['class'] ); |
|
| 2277 | + if ($args['class']) { |
|
| 2278 | + if (is_array($args['class'])) { |
|
| 2279 | + $class = array_merge($class, $args['class']); |
|
| 2280 | 2280 | } else { |
| 2281 | 2281 | $class[] = $args['class']; |
| 2282 | 2282 | } |
@@ -2284,10 +2284,10 @@ discard block |
||
| 2284 | 2284 | |
| 2285 | 2285 | $avatar = sprintf( |
| 2286 | 2286 | "<img alt='%s' src='%s' srcset='%s' class='%s' height='%d' width='%d' %s/>", |
| 2287 | - esc_attr( $args['alt'] ), |
|
| 2288 | - esc_url( $url ), |
|
| 2289 | - esc_attr( "$url2x 2x" ), |
|
| 2290 | - esc_attr( join( ' ', $class ) ), |
|
| 2287 | + esc_attr($args['alt']), |
|
| 2288 | + esc_url($url), |
|
| 2289 | + esc_attr("$url2x 2x"), |
|
| 2290 | + esc_attr(join(' ', $class)), |
|
| 2291 | 2291 | (int) $args['height'], |
| 2292 | 2292 | (int) $args['width'], |
| 2293 | 2293 | $args['extra_attr'] |
@@ -2306,11 +2306,11 @@ discard block |
||
| 2306 | 2306 | * Default empty. |
| 2307 | 2307 | * @param array $args Arguments passed to get_avatar_data(), after processing. |
| 2308 | 2308 | */ |
| 2309 | - return apply_filters( 'get_avatar', $avatar, $id_or_email, $args['size'], $args['default'], $args['alt'], $args ); |
|
| 2309 | + return apply_filters('get_avatar', $avatar, $id_or_email, $args['size'], $args['default'], $args['alt'], $args); |
|
| 2310 | 2310 | } |
| 2311 | 2311 | endif; |
| 2312 | 2312 | |
| 2313 | -if ( !function_exists( 'wp_text_diff' ) ) : |
|
| 2313 | +if ( ! function_exists('wp_text_diff')) : |
|
| 2314 | 2314 | /** |
| 2315 | 2315 | * Displays a human readable HTML representation of the difference between two strings. |
| 2316 | 2316 | * |
@@ -2338,12 +2338,12 @@ discard block |
||
| 2338 | 2338 | * @param string|array $args Optional. Change 'title', 'title_left', and 'title_right' defaults. |
| 2339 | 2339 | * @return string Empty string if strings are equivalent or HTML with differences. |
| 2340 | 2340 | */ |
| 2341 | -function wp_text_diff( $left_string, $right_string, $args = null ) { |
|
| 2342 | - $defaults = array( 'title' => '', 'title_left' => '', 'title_right' => '' ); |
|
| 2343 | - $args = wp_parse_args( $args, $defaults ); |
|
| 2341 | +function wp_text_diff($left_string, $right_string, $args = null) { |
|
| 2342 | + $defaults = array('title' => '', 'title_left' => '', 'title_right' => ''); |
|
| 2343 | + $args = wp_parse_args($args, $defaults); |
|
| 2344 | 2344 | |
| 2345 | - if ( !class_exists( 'WP_Text_Diff_Renderer_Table' ) ) |
|
| 2346 | - require( ABSPATH . WPINC . '/wp-diff.php' ); |
|
| 2345 | + if ( ! class_exists('WP_Text_Diff_Renderer_Table')) |
|
| 2346 | + require(ABSPATH.WPINC.'/wp-diff.php'); |
|
| 2347 | 2347 | |
| 2348 | 2348 | $left_string = normalize_whitespace($left_string); |
| 2349 | 2349 | $right_string = normalize_whitespace($right_string); |
@@ -2351,31 +2351,31 @@ discard block |
||
| 2351 | 2351 | $left_lines = explode("\n", $left_string); |
| 2352 | 2352 | $right_lines = explode("\n", $right_string); |
| 2353 | 2353 | $text_diff = new Text_Diff($left_lines, $right_lines); |
| 2354 | - $renderer = new WP_Text_Diff_Renderer_Table( $args ); |
|
| 2354 | + $renderer = new WP_Text_Diff_Renderer_Table($args); |
|
| 2355 | 2355 | $diff = $renderer->render($text_diff); |
| 2356 | 2356 | |
| 2357 | - if ( !$diff ) |
|
| 2357 | + if ( ! $diff) |
|
| 2358 | 2358 | return ''; |
| 2359 | 2359 | |
| 2360 | - $r = "<table class='diff'>\n"; |
|
| 2360 | + $r = "<table class='diff'>\n"; |
|
| 2361 | 2361 | |
| 2362 | - if ( ! empty( $args[ 'show_split_view' ] ) ) { |
|
| 2362 | + if ( ! empty($args['show_split_view'])) { |
|
| 2363 | 2363 | $r .= "<col class='content diffsplit left' /><col class='content diffsplit middle' /><col class='content diffsplit right' />"; |
| 2364 | 2364 | } else { |
| 2365 | 2365 | $r .= "<col class='content' />"; |
| 2366 | 2366 | } |
| 2367 | 2367 | |
| 2368 | - if ( $args['title'] || $args['title_left'] || $args['title_right'] ) |
|
| 2368 | + if ($args['title'] || $args['title_left'] || $args['title_right']) |
|
| 2369 | 2369 | $r .= "<thead>"; |
| 2370 | - if ( $args['title'] ) |
|
| 2370 | + if ($args['title']) |
|
| 2371 | 2371 | $r .= "<tr class='diff-title'><th colspan='4'>$args[title]</th></tr>\n"; |
| 2372 | - if ( $args['title_left'] || $args['title_right'] ) { |
|
| 2372 | + if ($args['title_left'] || $args['title_right']) { |
|
| 2373 | 2373 | $r .= "<tr class='diff-sub-title'>\n"; |
| 2374 | 2374 | $r .= "\t<td></td><th>$args[title_left]</th>\n"; |
| 2375 | 2375 | $r .= "\t<td></td><th>$args[title_right]</th>\n"; |
| 2376 | 2376 | $r .= "</tr>\n"; |
| 2377 | 2377 | } |
| 2378 | - if ( $args['title'] || $args['title_left'] || $args['title_right'] ) |
|
| 2378 | + if ($args['title'] || $args['title_left'] || $args['title_right']) |
|
| 2379 | 2379 | $r .= "</thead>\n"; |
| 2380 | 2380 | |
| 2381 | 2381 | $r .= "<tbody>\n$diff\n</tbody>\n"; |
@@ -26,8 +26,9 @@ discard block |
||
| 26 | 26 | function wp_set_current_user($id, $name = '') { |
| 27 | 27 | global $current_user; |
| 28 | 28 | |
| 29 | - if ( isset( $current_user ) && ( $current_user instanceof WP_User ) && ( $id == $current_user->ID ) ) |
|
| 30 | - return $current_user; |
|
| 29 | + if ( isset( $current_user ) && ( $current_user instanceof WP_User ) && ( $id == $current_user->ID ) ) { |
|
| 30 | + return $current_user; |
|
| 31 | + } |
|
| 31 | 32 | |
| 32 | 33 | $current_user = new WP_User( $id, $name ); |
| 33 | 34 | |
@@ -81,8 +82,9 @@ discard block |
||
| 81 | 82 | global $current_user; |
| 82 | 83 | |
| 83 | 84 | if ( ! empty( $current_user ) ) { |
| 84 | - if ( $current_user instanceof WP_User ) |
|
| 85 | - return; |
|
| 85 | + if ( $current_user instanceof WP_User ) { |
|
| 86 | + return; |
|
| 87 | + } |
|
| 86 | 88 | |
| 87 | 89 | // Upgrade stdClass to WP_User |
| 88 | 90 | if ( is_object( $current_user ) && isset( $current_user->ID ) ) { |
@@ -153,8 +155,9 @@ discard block |
||
| 153 | 155 | function get_user_by( $field, $value ) { |
| 154 | 156 | $userdata = WP_User::get_data_by( $field, $value ); |
| 155 | 157 | |
| 156 | - if ( !$userdata ) |
|
| 157 | - return false; |
|
| 158 | + if ( !$userdata ) { |
|
| 159 | + return false; |
|
| 160 | + } |
|
| 158 | 161 | |
| 159 | 162 | $user = new WP_User; |
| 160 | 163 | $user->init( $userdata ); |
@@ -178,8 +181,9 @@ discard block |
||
| 178 | 181 | |
| 179 | 182 | $clean = _get_non_cached_ids( $user_ids, 'users' ); |
| 180 | 183 | |
| 181 | - if ( empty( $clean ) ) |
|
| 182 | - return; |
|
| 184 | + if ( empty( $clean ) ) { |
|
| 185 | + return; |
|
| 186 | + } |
|
| 183 | 187 | |
| 184 | 188 | $list = implode( ',', $clean ); |
| 185 | 189 | |
@@ -363,8 +367,9 @@ discard block |
||
| 363 | 367 | |
| 364 | 368 | // From email and name |
| 365 | 369 | // If we don't have a name from the input headers |
| 366 | - if ( !isset( $from_name ) ) |
|
| 367 | - $from_name = 'WordPress'; |
|
| 370 | + if ( !isset( $from_name ) ) { |
|
| 371 | + $from_name = 'WordPress'; |
|
| 372 | + } |
|
| 368 | 373 | |
| 369 | 374 | /* If we don't have an email from the input headers default to wordpress@$sitename |
| 370 | 375 | * Some hosts will block outgoing mail from this address if it doesn't exist but |
@@ -402,8 +407,9 @@ discard block |
||
| 402 | 407 | $phpmailer->FromName = apply_filters( 'wp_mail_from_name', $from_name ); |
| 403 | 408 | |
| 404 | 409 | // Set destination addresses |
| 405 | - if ( !is_array( $to ) ) |
|
| 406 | - $to = explode( ',', $to ); |
|
| 410 | + if ( !is_array( $to ) ) { |
|
| 411 | + $to = explode( ',', $to ); |
|
| 412 | + } |
|
| 407 | 413 | |
| 408 | 414 | foreach ( (array) $to as $recipient ) { |
| 409 | 415 | try { |
@@ -467,8 +473,9 @@ discard block |
||
| 467 | 473 | |
| 468 | 474 | // Set Content-Type and charset |
| 469 | 475 | // If we don't have a content-type from the input headers |
| 470 | - if ( !isset( $content_type ) ) |
|
| 471 | - $content_type = 'text/plain'; |
|
| 476 | + if ( !isset( $content_type ) ) { |
|
| 477 | + $content_type = 'text/plain'; |
|
| 478 | + } |
|
| 472 | 479 | |
| 473 | 480 | /** |
| 474 | 481 | * Filter the wp_mail() content type. |
@@ -482,12 +489,14 @@ discard block |
||
| 482 | 489 | $phpmailer->ContentType = $content_type; |
| 483 | 490 | |
| 484 | 491 | // Set whether it's plaintext, depending on $content_type |
| 485 | - if ( 'text/html' == $content_type ) |
|
| 486 | - $phpmailer->IsHTML( true ); |
|
| 492 | + if ( 'text/html' == $content_type ) { |
|
| 493 | + $phpmailer->IsHTML( true ); |
|
| 494 | + } |
|
| 487 | 495 | |
| 488 | 496 | // If we don't have a charset from the input headers |
| 489 | - if ( !isset( $charset ) ) |
|
| 490 | - $charset = get_bloginfo( 'charset' ); |
|
| 497 | + if ( !isset( $charset ) ) { |
|
| 498 | + $charset = get_bloginfo( 'charset' ); |
|
| 499 | + } |
|
| 491 | 500 | |
| 492 | 501 | // Set the content-type and charset |
| 493 | 502 | |
@@ -506,8 +515,9 @@ discard block |
||
| 506 | 515 | $phpmailer->AddCustomHeader( sprintf( '%1$s: %2$s', $name, $content ) ); |
| 507 | 516 | } |
| 508 | 517 | |
| 509 | - if ( false !== stripos( $content_type, 'multipart' ) && ! empty($boundary) ) |
|
| 510 | - $phpmailer->AddCustomHeader( sprintf( "Content-Type: %s;\n\t boundary=\"%s\"", $content_type, $boundary ) ); |
|
| 518 | + if ( false !== stripos( $content_type, 'multipart' ) && ! empty($boundary) ) { |
|
| 519 | + $phpmailer->AddCustomHeader( sprintf( "Content-Type: %s;\n\t boundary=\"%s\"", $content_type, $boundary ) ); |
|
| 520 | + } |
|
| 511 | 521 | } |
| 512 | 522 | |
| 513 | 523 | if ( !empty( $attachments ) ) { |
@@ -803,8 +813,9 @@ discard block |
||
| 803 | 813 | } |
| 804 | 814 | } |
| 805 | 815 | |
| 806 | - if ( empty($_COOKIE[$cookie_name]) ) |
|
| 807 | - return false; |
|
| 816 | + if ( empty($_COOKIE[$cookie_name]) ) { |
|
| 817 | + return false; |
|
| 818 | + } |
|
| 808 | 819 | $cookie = $_COOKIE[$cookie_name]; |
| 809 | 820 | } |
| 810 | 821 | |
@@ -935,9 +946,10 @@ discard block |
||
| 935 | 946 | setcookie($auth_cookie_name, $auth_cookie, $expire, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN, $secure, true); |
| 936 | 947 | setcookie($auth_cookie_name, $auth_cookie, $expire, ADMIN_COOKIE_PATH, COOKIE_DOMAIN, $secure, true); |
| 937 | 948 | setcookie(LOGGED_IN_COOKIE, $logged_in_cookie, $expire, COOKIEPATH, COOKIE_DOMAIN, $secure_logged_in_cookie, true); |
| 938 | - if ( COOKIEPATH != SITECOOKIEPATH ) |
|
| 939 | - setcookie(LOGGED_IN_COOKIE, $logged_in_cookie, $expire, SITECOOKIEPATH, COOKIE_DOMAIN, $secure_logged_in_cookie, true); |
|
| 940 | -} |
|
| 949 | + if ( COOKIEPATH != SITECOOKIEPATH ) { |
|
| 950 | + setcookie(LOGGED_IN_COOKIE, $logged_in_cookie, $expire, SITECOOKIEPATH, COOKIE_DOMAIN, $secure_logged_in_cookie, true); |
|
| 951 | + } |
|
| 952 | + } |
|
| 941 | 953 | endif; |
| 942 | 954 | |
| 943 | 955 | if ( !function_exists('wp_clear_auth_cookie') ) : |
@@ -1085,8 +1097,9 @@ discard block |
||
| 1085 | 1097 | * 0-12 hours ago, 2 if the nonce is valid and generated between 12-24 hours ago. |
| 1086 | 1098 | */ |
| 1087 | 1099 | function check_admin_referer( $action = -1, $query_arg = '_wpnonce' ) { |
| 1088 | - if ( -1 == $action ) |
|
| 1089 | - _doing_it_wrong( __FUNCTION__, __( 'You should specify a nonce action to be verified by using the first parameter.' ), '3.2' ); |
|
| 1100 | + if ( -1 == $action ) { |
|
| 1101 | + _doing_it_wrong( __FUNCTION__, __( 'You should specify a nonce action to be verified by using the first parameter.' ), '3.2' ); |
|
| 1102 | + } |
|
| 1090 | 1103 | |
| 1091 | 1104 | $adminurl = strtolower(admin_url()); |
| 1092 | 1105 | $referer = strtolower(wp_get_referer()); |
@@ -1130,20 +1143,22 @@ discard block |
||
| 1130 | 1143 | function check_ajax_referer( $action = -1, $query_arg = false, $die = true ) { |
| 1131 | 1144 | $nonce = ''; |
| 1132 | 1145 | |
| 1133 | - if ( $query_arg && isset( $_REQUEST[ $query_arg ] ) ) |
|
| 1134 | - $nonce = $_REQUEST[ $query_arg ]; |
|
| 1135 | - elseif ( isset( $_REQUEST['_ajax_nonce'] ) ) |
|
| 1136 | - $nonce = $_REQUEST['_ajax_nonce']; |
|
| 1137 | - elseif ( isset( $_REQUEST['_wpnonce'] ) ) |
|
| 1138 | - $nonce = $_REQUEST['_wpnonce']; |
|
| 1146 | + if ( $query_arg && isset( $_REQUEST[ $query_arg ] ) ) { |
|
| 1147 | + $nonce = $_REQUEST[ $query_arg ]; |
|
| 1148 | + } elseif ( isset( $_REQUEST['_ajax_nonce'] ) ) { |
|
| 1149 | + $nonce = $_REQUEST['_ajax_nonce']; |
|
| 1150 | + } elseif ( isset( $_REQUEST['_wpnonce'] ) ) { |
|
| 1151 | + $nonce = $_REQUEST['_wpnonce']; |
|
| 1152 | + } |
|
| 1139 | 1153 | |
| 1140 | 1154 | $result = wp_verify_nonce( $nonce, $action ); |
| 1141 | 1155 | |
| 1142 | 1156 | if ( $die && false === $result ) { |
| 1143 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) |
|
| 1144 | - wp_die( -1 ); |
|
| 1145 | - else |
|
| 1146 | - die( '-1' ); |
|
| 1157 | + if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
| 1158 | + wp_die( -1 ); |
|
| 1159 | + } else { |
|
| 1160 | + die( '-1' ); |
|
| 1161 | + } |
|
| 1147 | 1162 | } |
| 1148 | 1163 | |
| 1149 | 1164 | /** |
@@ -1196,13 +1211,16 @@ discard block |
||
| 1196 | 1211 | */ |
| 1197 | 1212 | $status = apply_filters( 'wp_redirect_status', $status, $location ); |
| 1198 | 1213 | |
| 1199 | - if ( ! $location ) |
|
| 1200 | - return false; |
|
| 1214 | + if ( ! $location ) { |
|
| 1215 | + return false; |
|
| 1216 | + } |
|
| 1201 | 1217 | |
| 1202 | 1218 | $location = wp_sanitize_redirect($location); |
| 1203 | 1219 | |
| 1204 | - if ( !$is_IIS && PHP_SAPI != 'cgi-fcgi' ) |
|
| 1205 | - status_header($status); // This causes problems on IIS and some FastCGI setups |
|
| 1220 | + if ( !$is_IIS && PHP_SAPI != 'cgi-fcgi' ) { |
|
| 1221 | + status_header($status); |
|
| 1222 | + } |
|
| 1223 | + // This causes problems on IIS and some FastCGI setups |
|
| 1206 | 1224 | |
| 1207 | 1225 | header("Location: $location", true, $status); |
| 1208 | 1226 | |
@@ -1306,8 +1324,9 @@ discard block |
||
| 1306 | 1324 | function wp_validate_redirect($location, $default = '') { |
| 1307 | 1325 | $location = trim( $location ); |
| 1308 | 1326 | // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//' |
| 1309 | - if ( substr($location, 0, 2) == '//' ) |
|
| 1310 | - $location = 'http:' . $location; |
|
| 1327 | + if ( substr($location, 0, 2) == '//' ) { |
|
| 1328 | + $location = 'http:' . $location; |
|
| 1329 | + } |
|
| 1311 | 1330 | |
| 1312 | 1331 | // In php 5 parse_url may fail if the URL query part contains http://, bug #38143 |
| 1313 | 1332 | $test = ( $cut = strpos($location, '?') ) ? substr( $location, 0, $cut ) : $location; |
@@ -1315,16 +1334,19 @@ discard block |
||
| 1315 | 1334 | $lp = parse_url($test); |
| 1316 | 1335 | |
| 1317 | 1336 | // Give up if malformed URL |
| 1318 | - if ( false === $lp ) |
|
| 1319 | - return $default; |
|
| 1337 | + if ( false === $lp ) { |
|
| 1338 | + return $default; |
|
| 1339 | + } |
|
| 1320 | 1340 | |
| 1321 | 1341 | // Allow only http and https schemes. No data:, etc. |
| 1322 | - if ( isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme']) ) |
|
| 1323 | - return $default; |
|
| 1342 | + if ( isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme']) ) { |
|
| 1343 | + return $default; |
|
| 1344 | + } |
|
| 1324 | 1345 | |
| 1325 | 1346 | // Reject if scheme is set but host is not. This catches urls like https:host.com for which parse_url does not set the host field. |
| 1326 | - if ( isset($lp['scheme']) && !isset($lp['host']) ) |
|
| 1327 | - return $default; |
|
| 1347 | + if ( isset($lp['scheme']) && !isset($lp['host']) ) { |
|
| 1348 | + return $default; |
|
| 1349 | + } |
|
| 1328 | 1350 | |
| 1329 | 1351 | $wpp = parse_url(home_url()); |
| 1330 | 1352 | |
@@ -1338,8 +1360,9 @@ discard block |
||
| 1338 | 1360 | */ |
| 1339 | 1361 | $allowed_hosts = (array) apply_filters( 'allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '' ); |
| 1340 | 1362 | |
| 1341 | - if ( isset($lp['host']) && ( !in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host'])) ) |
|
| 1342 | - $location = $default; |
|
| 1363 | + if ( isset($lp['host']) && ( !in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host'])) ) { |
|
| 1364 | + $location = $default; |
|
| 1365 | + } |
|
| 1343 | 1366 | |
| 1344 | 1367 | return $location; |
| 1345 | 1368 | } |
@@ -1361,8 +1384,9 @@ discard block |
||
| 1361 | 1384 | } |
| 1362 | 1385 | |
| 1363 | 1386 | $comment = get_comment( $comment_id ); |
| 1364 | - if ( empty( $comment ) ) |
|
| 1365 | - return false; |
|
| 1387 | + if ( empty( $comment ) ) { |
|
| 1388 | + return false; |
|
| 1389 | + } |
|
| 1366 | 1390 | |
| 1367 | 1391 | $post = get_post( $comment->comment_post_ID ); |
| 1368 | 1392 | $author = get_userdata( $post->post_author ); |
@@ -1474,10 +1498,11 @@ discard block |
||
| 1474 | 1498 | $notify_message .= sprintf( __('Permalink: %s'), get_comment_link( $comment_id ) ) . "\r\n"; |
| 1475 | 1499 | |
| 1476 | 1500 | if ( user_can( $post->post_author, 'edit_comment', $comment_id ) ) { |
| 1477 | - if ( EMPTY_TRASH_DAYS ) |
|
| 1478 | - $notify_message .= sprintf( __('Trash it: %s'), admin_url("comment.php?action=trash&c=$comment_id") ) . "\r\n"; |
|
| 1479 | - else |
|
| 1480 | - $notify_message .= sprintf( __('Delete it: %s'), admin_url("comment.php?action=delete&c=$comment_id") ) . "\r\n"; |
|
| 1501 | + if ( EMPTY_TRASH_DAYS ) { |
|
| 1502 | + $notify_message .= sprintf( __('Trash it: %s'), admin_url("comment.php?action=trash&c=$comment_id") ) . "\r\n"; |
|
| 1503 | + } else { |
|
| 1504 | + $notify_message .= sprintf( __('Delete it: %s'), admin_url("comment.php?action=delete&c=$comment_id") ) . "\r\n"; |
|
| 1505 | + } |
|
| 1481 | 1506 | $notify_message .= sprintf( __('Spam it: %s'), admin_url("comment.php?action=spam&c=$comment_id") ) . "\r\n"; |
| 1482 | 1507 | } |
| 1483 | 1508 | |
@@ -1485,19 +1510,22 @@ discard block |
||
| 1485 | 1510 | |
| 1486 | 1511 | if ( '' == $comment->comment_author ) { |
| 1487 | 1512 | $from = "From: \"$blogname\" <$wp_email>"; |
| 1488 | - if ( '' != $comment->comment_author_email ) |
|
| 1489 | - $reply_to = "Reply-To: $comment->comment_author_email"; |
|
| 1513 | + if ( '' != $comment->comment_author_email ) { |
|
| 1514 | + $reply_to = "Reply-To: $comment->comment_author_email"; |
|
| 1515 | + } |
|
| 1490 | 1516 | } else { |
| 1491 | 1517 | $from = "From: \"$comment->comment_author\" <$wp_email>"; |
| 1492 | - if ( '' != $comment->comment_author_email ) |
|
| 1493 | - $reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>"; |
|
| 1518 | + if ( '' != $comment->comment_author_email ) { |
|
| 1519 | + $reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>"; |
|
| 1520 | + } |
|
| 1494 | 1521 | } |
| 1495 | 1522 | |
| 1496 | 1523 | $message_headers = "$from\n" |
| 1497 | 1524 | . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; |
| 1498 | 1525 | |
| 1499 | - if ( isset($reply_to) ) |
|
| 1500 | - $message_headers .= $reply_to . "\n"; |
|
| 1526 | + if ( isset($reply_to) ) { |
|
| 1527 | + $message_headers .= $reply_to . "\n"; |
|
| 1528 | + } |
|
| 1501 | 1529 | |
| 1502 | 1530 | /** |
| 1503 | 1531 | * Filter the comment notification email text. |
@@ -1551,8 +1579,9 @@ discard block |
||
| 1551 | 1579 | function wp_notify_moderator($comment_id) { |
| 1552 | 1580 | global $wpdb; |
| 1553 | 1581 | |
| 1554 | - if ( 0 == get_option( 'moderation_notify' ) ) |
|
| 1555 | - return true; |
|
| 1582 | + if ( 0 == get_option( 'moderation_notify' ) ) { |
|
| 1583 | + return true; |
|
| 1584 | + } |
|
| 1556 | 1585 | |
| 1557 | 1586 | $comment = get_comment($comment_id); |
| 1558 | 1587 | $post = get_post($comment->comment_post_ID); |
@@ -1560,8 +1589,9 @@ discard block |
||
| 1560 | 1589 | // Send to the administration and to the post author if the author can modify the comment. |
| 1561 | 1590 | $emails = array( get_option( 'admin_email' ) ); |
| 1562 | 1591 | if ( $user && user_can( $user->ID, 'edit_comment', $comment_id ) && ! empty( $user->user_email ) ) { |
| 1563 | - if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) ) |
|
| 1564 | - $emails[] = $user->user_email; |
|
| 1592 | + if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) ) { |
|
| 1593 | + $emails[] = $user->user_email; |
|
| 1594 | + } |
|
| 1565 | 1595 | } |
| 1566 | 1596 | |
| 1567 | 1597 | $comment_author_domain = @gethostbyaddr($comment->comment_author_IP); |
@@ -1599,10 +1629,11 @@ discard block |
||
| 1599 | 1629 | } |
| 1600 | 1630 | |
| 1601 | 1631 | $notify_message .= sprintf( __('Approve it: %s'), admin_url("comment.php?action=approve&c=$comment_id") ) . "\r\n"; |
| 1602 | - if ( EMPTY_TRASH_DAYS ) |
|
| 1603 | - $notify_message .= sprintf( __('Trash it: %s'), admin_url("comment.php?action=trash&c=$comment_id") ) . "\r\n"; |
|
| 1604 | - else |
|
| 1605 | - $notify_message .= sprintf( __('Delete it: %s'), admin_url("comment.php?action=delete&c=$comment_id") ) . "\r\n"; |
|
| 1632 | + if ( EMPTY_TRASH_DAYS ) { |
|
| 1633 | + $notify_message .= sprintf( __('Trash it: %s'), admin_url("comment.php?action=trash&c=$comment_id") ) . "\r\n"; |
|
| 1634 | + } else { |
|
| 1635 | + $notify_message .= sprintf( __('Delete it: %s'), admin_url("comment.php?action=delete&c=$comment_id") ) . "\r\n"; |
|
| 1636 | + } |
|
| 1606 | 1637 | $notify_message .= sprintf( __('Spam it: %s'), admin_url("comment.php?action=spam&c=$comment_id") ) . "\r\n"; |
| 1607 | 1638 | |
| 1608 | 1639 | $notify_message .= sprintf( _n('Currently %s comment is waiting for approval. Please visit the moderation panel:', |
@@ -2067,10 +2098,12 @@ discard block |
||
| 2067 | 2098 | */ |
| 2068 | 2099 | function wp_generate_password( $length = 12, $special_chars = true, $extra_special_chars = false ) { |
| 2069 | 2100 | $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; |
| 2070 | - if ( $special_chars ) |
|
| 2071 | - $chars .= '!@#$%^&*()'; |
|
| 2072 | - if ( $extra_special_chars ) |
|
| 2073 | - $chars .= '-_ []{}<>~`+=,.;:/?|'; |
|
| 2101 | + if ( $special_chars ) { |
|
| 2102 | + $chars .= '!@#$%^&*()'; |
|
| 2103 | + } |
|
| 2104 | + if ( $extra_special_chars ) { |
|
| 2105 | + $chars .= '-_ []{}<>~`+=,.;:/?|'; |
|
| 2106 | + } |
|
| 2074 | 2107 | |
| 2075 | 2108 | $password = ''; |
| 2076 | 2109 | for ( $i = 0; $i < $length; $i++ ) { |
@@ -2107,10 +2140,11 @@ discard block |
||
| 2107 | 2140 | // Reset $rnd_value after 14 uses |
| 2108 | 2141 | // 32(md5) + 40(sha1) + 40(sha1) / 8 = 14 random numbers from $rnd_value |
| 2109 | 2142 | if ( strlen($rnd_value) < 8 ) { |
| 2110 | - if ( defined( 'WP_SETUP_CONFIG' ) ) |
|
| 2111 | - static $seed = ''; |
|
| 2112 | - else |
|
| 2113 | - $seed = get_transient('random_seed'); |
|
| 2143 | + if ( defined( 'WP_SETUP_CONFIG' ) ) { |
|
| 2144 | + static $seed = ''; |
|
| 2145 | + } else { |
|
| 2146 | + $seed = get_transient('random_seed'); |
|
| 2147 | + } |
|
| 2114 | 2148 | $rnd_value = md5( uniqid(microtime() . mt_rand(), true ) . $seed ); |
| 2115 | 2149 | $rnd_value .= sha1($rnd_value); |
| 2116 | 2150 | $rnd_value .= sha1($rnd_value . $seed); |
@@ -2132,8 +2166,9 @@ discard block |
||
| 2132 | 2166 | $max_random_number = 3000000000 === 2147483647 ? (float) "4294967295" : 4294967295; // 4294967295 = 0xffffffff |
| 2133 | 2167 | |
| 2134 | 2168 | // Reduce the value to be within the min - max range |
| 2135 | - if ( $max != 0 ) |
|
| 2136 | - $value = $min + ( $max - $min + 1 ) * $value / ( $max_random_number + 1 ); |
|
| 2169 | + if ( $max != 0 ) { |
|
| 2170 | + $value = $min + ( $max - $min + 1 ) * $value / ( $max_random_number + 1 ); |
|
| 2171 | + } |
|
| 2137 | 2172 | |
| 2138 | 2173 | return abs(intval($value)); |
| 2139 | 2174 | } |
@@ -2342,8 +2377,9 @@ discard block |
||
| 2342 | 2377 | $defaults = array( 'title' => '', 'title_left' => '', 'title_right' => '' ); |
| 2343 | 2378 | $args = wp_parse_args( $args, $defaults ); |
| 2344 | 2379 | |
| 2345 | - if ( !class_exists( 'WP_Text_Diff_Renderer_Table' ) ) |
|
| 2346 | - require( ABSPATH . WPINC . '/wp-diff.php' ); |
|
| 2380 | + if ( !class_exists( 'WP_Text_Diff_Renderer_Table' ) ) { |
|
| 2381 | + require( ABSPATH . WPINC . '/wp-diff.php' ); |
|
| 2382 | + } |
|
| 2347 | 2383 | |
| 2348 | 2384 | $left_string = normalize_whitespace($left_string); |
| 2349 | 2385 | $right_string = normalize_whitespace($right_string); |
@@ -2354,8 +2390,9 @@ discard block |
||
| 2354 | 2390 | $renderer = new WP_Text_Diff_Renderer_Table( $args ); |
| 2355 | 2391 | $diff = $renderer->render($text_diff); |
| 2356 | 2392 | |
| 2357 | - if ( !$diff ) |
|
| 2358 | - return ''; |
|
| 2393 | + if ( !$diff ) { |
|
| 2394 | + return ''; |
|
| 2395 | + } |
|
| 2359 | 2396 | |
| 2360 | 2397 | $r = "<table class='diff'>\n"; |
| 2361 | 2398 | |
@@ -2365,18 +2402,21 @@ discard block |
||
| 2365 | 2402 | $r .= "<col class='content' />"; |
| 2366 | 2403 | } |
| 2367 | 2404 | |
| 2368 | - if ( $args['title'] || $args['title_left'] || $args['title_right'] ) |
|
| 2369 | - $r .= "<thead>"; |
|
| 2370 | - if ( $args['title'] ) |
|
| 2371 | - $r .= "<tr class='diff-title'><th colspan='4'>$args[title]</th></tr>\n"; |
|
| 2405 | + if ( $args['title'] || $args['title_left'] || $args['title_right'] ) { |
|
| 2406 | + $r .= "<thead>"; |
|
| 2407 | + } |
|
| 2408 | + if ( $args['title'] ) { |
|
| 2409 | + $r .= "<tr class='diff-title'><th colspan='4'>$args[title]</th></tr>\n"; |
|
| 2410 | + } |
|
| 2372 | 2411 | if ( $args['title_left'] || $args['title_right'] ) { |
| 2373 | 2412 | $r .= "<tr class='diff-sub-title'>\n"; |
| 2374 | 2413 | $r .= "\t<td></td><th>$args[title_left]</th>\n"; |
| 2375 | 2414 | $r .= "\t<td></td><th>$args[title_right]</th>\n"; |
| 2376 | 2415 | $r .= "</tr>\n"; |
| 2377 | 2416 | } |
| 2378 | - if ( $args['title'] || $args['title_left'] || $args['title_right'] ) |
|
| 2379 | - $r .= "</thead>\n"; |
|
| 2417 | + if ( $args['title'] || $args['title_left'] || $args['title_right'] ) { |
|
| 2418 | + $r .= "</thead>\n"; |
|
| 2419 | + } |
|
| 2380 | 2420 | |
| 2381 | 2421 | $r .= "<tbody>\n$diff\n</tbody>\n"; |
| 2382 | 2422 | $r .= "</table>"; |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * and functions with the same priority are executed |
| 77 | 77 | * in the order in which they were added to the action. |
| 78 | 78 | * @param int $accepted_args Optional. The number of arguments the function accepts. Default 1. |
| 79 | - * @return true |
|
| 79 | + * @return boolean |
|
| 80 | 80 | */ |
| 81 | 81 | function add_filter( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) { |
| 82 | 82 | global $wp_filter, $merged_filters; |
@@ -171,7 +171,6 @@ discard block |
||
| 171 | 171 | * |
| 172 | 172 | * @param string $tag The name of the filter hook. |
| 173 | 173 | * @param mixed $value The value on which the filters hooked to `$tag` are applied on. |
| 174 | - * @param mixed $var Additional variables passed to the functions hooked to `$tag`. |
|
| 175 | 174 | * @return mixed The filtered value after all hooked functions are applied to it. |
| 176 | 175 | */ |
| 177 | 176 | function apply_filters( $tag, $value ) { |
@@ -325,7 +324,7 @@ discard block |
||
| 325 | 324 | * |
| 326 | 325 | * @param string $tag The filter to remove hooks from. |
| 327 | 326 | * @param int|bool $priority Optional. The priority number to remove. Default false. |
| 328 | - * @return true True when finished. |
|
| 327 | + * @return boolean True when finished. |
|
| 329 | 328 | */ |
| 330 | 329 | function remove_all_filters( $tag, $priority = false ) { |
| 331 | 330 | global $wp_filter, $merged_filters; |
@@ -430,7 +429,7 @@ discard block |
||
| 430 | 429 | * and functions with the same priority are executed |
| 431 | 430 | * in the order in which they were added to the action. |
| 432 | 431 | * @param int $accepted_args Optional. The number of arguments the function accepts. Default 1. |
| 433 | - * @return true Will always return true. |
|
| 432 | + * @return boolean Will always return true. |
|
| 434 | 433 | */ |
| 435 | 434 | function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) { |
| 436 | 435 | return add_filter($tag, $function_to_add, $priority, $accepted_args); |
@@ -628,7 +627,7 @@ discard block |
||
| 628 | 627 | * |
| 629 | 628 | * @param string $tag The action to remove hooks from. |
| 630 | 629 | * @param int|bool $priority The priority number to remove them from. Default false. |
| 631 | - * @return true True when finished. |
|
| 630 | + * @return boolean True when finished. |
|
| 632 | 631 | */ |
| 633 | 632 | function remove_all_actions($tag, $priority = false) { |
| 634 | 633 | return remove_all_filters($tag, $priority); |
@@ -22,16 +22,16 @@ discard block |
||
| 22 | 22 | // Initialize the filter globals. |
| 23 | 23 | global $wp_filter, $wp_actions, $merged_filters, $wp_current_filter; |
| 24 | 24 | |
| 25 | -if ( ! isset( $wp_filter ) ) |
|
| 25 | +if ( ! isset($wp_filter)) |
|
| 26 | 26 | $wp_filter = array(); |
| 27 | 27 | |
| 28 | -if ( ! isset( $wp_actions ) ) |
|
| 28 | +if ( ! isset($wp_actions)) |
|
| 29 | 29 | $wp_actions = array(); |
| 30 | 30 | |
| 31 | -if ( ! isset( $merged_filters ) ) |
|
| 31 | +if ( ! isset($merged_filters)) |
|
| 32 | 32 | $merged_filters = array(); |
| 33 | 33 | |
| 34 | -if ( ! isset( $wp_current_filter ) ) |
|
| 34 | +if ( ! isset($wp_current_filter)) |
|
| 35 | 35 | $wp_current_filter = array(); |
| 36 | 36 | |
| 37 | 37 | /** |
@@ -78,12 +78,12 @@ discard block |
||
| 78 | 78 | * @param int $accepted_args Optional. The number of arguments the function accepts. Default 1. |
| 79 | 79 | * @return true |
| 80 | 80 | */ |
| 81 | -function add_filter( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) { |
|
| 81 | +function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) { |
|
| 82 | 82 | global $wp_filter, $merged_filters; |
| 83 | 83 | |
| 84 | 84 | $idx = _wp_filter_build_unique_id($tag, $function_to_add, $priority); |
| 85 | 85 | $wp_filter[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args); |
| 86 | - unset( $merged_filters[ $tag ] ); |
|
| 86 | + unset($merged_filters[$tag]); |
|
| 87 | 87 | return true; |
| 88 | 88 | } |
| 89 | 89 | |
@@ -107,31 +107,31 @@ discard block |
||
| 107 | 107 | // Don't reset the internal array pointer |
| 108 | 108 | $wp_filter = $GLOBALS['wp_filter']; |
| 109 | 109 | |
| 110 | - $has = ! empty( $wp_filter[ $tag ] ); |
|
| 110 | + $has = ! empty($wp_filter[$tag]); |
|
| 111 | 111 | |
| 112 | 112 | // Make sure at least one priority has a filter callback |
| 113 | - if ( $has ) { |
|
| 113 | + if ($has) { |
|
| 114 | 114 | $exists = false; |
| 115 | - foreach ( $wp_filter[ $tag ] as $callbacks ) { |
|
| 116 | - if ( ! empty( $callbacks ) ) { |
|
| 115 | + foreach ($wp_filter[$tag] as $callbacks) { |
|
| 116 | + if ( ! empty($callbacks)) { |
|
| 117 | 117 | $exists = true; |
| 118 | 118 | break; |
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - if ( ! $exists ) { |
|
| 122 | + if ( ! $exists) { |
|
| 123 | 123 | $has = false; |
| 124 | 124 | } |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - if ( false === $function_to_check || false === $has ) |
|
| 127 | + if (false === $function_to_check || false === $has) |
|
| 128 | 128 | return $has; |
| 129 | 129 | |
| 130 | - if ( !$idx = _wp_filter_build_unique_id($tag, $function_to_check, false) ) |
|
| 130 | + if ( ! $idx = _wp_filter_build_unique_id($tag, $function_to_check, false)) |
|
| 131 | 131 | return false; |
| 132 | 132 | |
| 133 | - foreach ( (array) array_keys($wp_filter[$tag]) as $priority ) { |
|
| 134 | - if ( isset($wp_filter[$tag][$priority][$idx]) ) |
|
| 133 | + foreach ((array) array_keys($wp_filter[$tag]) as $priority) { |
|
| 134 | + if (isset($wp_filter[$tag][$priority][$idx])) |
|
| 135 | 135 | return $priority; |
| 136 | 136 | } |
| 137 | 137 | |
@@ -174,48 +174,48 @@ discard block |
||
| 174 | 174 | * @param mixed $var Additional variables passed to the functions hooked to `$tag`. |
| 175 | 175 | * @return mixed The filtered value after all hooked functions are applied to it. |
| 176 | 176 | */ |
| 177 | -function apply_filters( $tag, $value ) { |
|
| 177 | +function apply_filters($tag, $value) { |
|
| 178 | 178 | global $wp_filter, $merged_filters, $wp_current_filter; |
| 179 | 179 | |
| 180 | 180 | $args = array(); |
| 181 | 181 | |
| 182 | 182 | // Do 'all' actions first. |
| 183 | - if ( isset($wp_filter['all']) ) { |
|
| 183 | + if (isset($wp_filter['all'])) { |
|
| 184 | 184 | $wp_current_filter[] = $tag; |
| 185 | 185 | $args = func_get_args(); |
| 186 | 186 | _wp_call_all_hook($args); |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - if ( !isset($wp_filter[$tag]) ) { |
|
| 190 | - if ( isset($wp_filter['all']) ) |
|
| 189 | + if ( ! isset($wp_filter[$tag])) { |
|
| 190 | + if (isset($wp_filter['all'])) |
|
| 191 | 191 | array_pop($wp_current_filter); |
| 192 | 192 | return $value; |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - if ( !isset($wp_filter['all']) ) |
|
| 195 | + if ( ! isset($wp_filter['all'])) |
|
| 196 | 196 | $wp_current_filter[] = $tag; |
| 197 | 197 | |
| 198 | 198 | // Sort. |
| 199 | - if ( !isset( $merged_filters[ $tag ] ) ) { |
|
| 199 | + if ( ! isset($merged_filters[$tag])) { |
|
| 200 | 200 | ksort($wp_filter[$tag]); |
| 201 | - $merged_filters[ $tag ] = true; |
|
| 201 | + $merged_filters[$tag] = true; |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - reset( $wp_filter[ $tag ] ); |
|
| 204 | + reset($wp_filter[$tag]); |
|
| 205 | 205 | |
| 206 | - if ( empty($args) ) |
|
| 206 | + if (empty($args)) |
|
| 207 | 207 | $args = func_get_args(); |
| 208 | 208 | |
| 209 | 209 | do { |
| 210 | - foreach( (array) current($wp_filter[$tag]) as $the_ ) |
|
| 211 | - if ( !is_null($the_['function']) ){ |
|
| 210 | + foreach ((array) current($wp_filter[$tag]) as $the_) |
|
| 211 | + if ( ! is_null($the_['function'])) { |
|
| 212 | 212 | $args[1] = $value; |
| 213 | 213 | $value = call_user_func_array($the_['function'], array_slice($args, 1, (int) $the_['accepted_args'])); |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - } while ( next($wp_filter[$tag]) !== false ); |
|
| 216 | + } while (next($wp_filter[$tag]) !== false); |
|
| 217 | 217 | |
| 218 | - array_pop( $wp_current_filter ); |
|
| 218 | + array_pop($wp_current_filter); |
|
| 219 | 219 | |
| 220 | 220 | return $value; |
| 221 | 221 | } |
@@ -240,37 +240,37 @@ discard block |
||
| 240 | 240 | global $wp_filter, $merged_filters, $wp_current_filter; |
| 241 | 241 | |
| 242 | 242 | // Do 'all' actions first |
| 243 | - if ( isset($wp_filter['all']) ) { |
|
| 243 | + if (isset($wp_filter['all'])) { |
|
| 244 | 244 | $wp_current_filter[] = $tag; |
| 245 | 245 | $all_args = func_get_args(); |
| 246 | 246 | _wp_call_all_hook($all_args); |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - if ( !isset($wp_filter[$tag]) ) { |
|
| 250 | - if ( isset($wp_filter['all']) ) |
|
| 249 | + if ( ! isset($wp_filter[$tag])) { |
|
| 250 | + if (isset($wp_filter['all'])) |
|
| 251 | 251 | array_pop($wp_current_filter); |
| 252 | 252 | return $args[0]; |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | - if ( !isset($wp_filter['all']) ) |
|
| 255 | + if ( ! isset($wp_filter['all'])) |
|
| 256 | 256 | $wp_current_filter[] = $tag; |
| 257 | 257 | |
| 258 | 258 | // Sort |
| 259 | - if ( !isset( $merged_filters[ $tag ] ) ) { |
|
| 259 | + if ( ! isset($merged_filters[$tag])) { |
|
| 260 | 260 | ksort($wp_filter[$tag]); |
| 261 | - $merged_filters[ $tag ] = true; |
|
| 261 | + $merged_filters[$tag] = true; |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | - reset( $wp_filter[ $tag ] ); |
|
| 264 | + reset($wp_filter[$tag]); |
|
| 265 | 265 | |
| 266 | 266 | do { |
| 267 | - foreach( (array) current($wp_filter[$tag]) as $the_ ) |
|
| 268 | - if ( !is_null($the_['function']) ) |
|
| 267 | + foreach ((array) current($wp_filter[$tag]) as $the_) |
|
| 268 | + if ( ! is_null($the_['function'])) |
|
| 269 | 269 | $args[0] = call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args'])); |
| 270 | 270 | |
| 271 | - } while ( next($wp_filter[$tag]) !== false ); |
|
| 271 | + } while (next($wp_filter[$tag]) !== false); |
|
| 272 | 272 | |
| 273 | - array_pop( $wp_current_filter ); |
|
| 273 | + array_pop($wp_current_filter); |
|
| 274 | 274 | |
| 275 | 275 | return $args[0]; |
| 276 | 276 | } |
@@ -296,20 +296,20 @@ discard block |
||
| 296 | 296 | * @param int $priority Optional. The priority of the function. Default 10. |
| 297 | 297 | * @return bool Whether the function existed before it was removed. |
| 298 | 298 | */ |
| 299 | -function remove_filter( $tag, $function_to_remove, $priority = 10 ) { |
|
| 300 | - $function_to_remove = _wp_filter_build_unique_id( $tag, $function_to_remove, $priority ); |
|
| 299 | +function remove_filter($tag, $function_to_remove, $priority = 10) { |
|
| 300 | + $function_to_remove = _wp_filter_build_unique_id($tag, $function_to_remove, $priority); |
|
| 301 | 301 | |
| 302 | - $r = isset( $GLOBALS['wp_filter'][ $tag ][ $priority ][ $function_to_remove ] ); |
|
| 302 | + $r = isset($GLOBALS['wp_filter'][$tag][$priority][$function_to_remove]); |
|
| 303 | 303 | |
| 304 | - if ( true === $r ) { |
|
| 305 | - unset( $GLOBALS['wp_filter'][ $tag ][ $priority ][ $function_to_remove ] ); |
|
| 306 | - if ( empty( $GLOBALS['wp_filter'][ $tag ][ $priority ] ) ) { |
|
| 307 | - unset( $GLOBALS['wp_filter'][ $tag ][ $priority ] ); |
|
| 304 | + if (true === $r) { |
|
| 305 | + unset($GLOBALS['wp_filter'][$tag][$priority][$function_to_remove]); |
|
| 306 | + if (empty($GLOBALS['wp_filter'][$tag][$priority])) { |
|
| 307 | + unset($GLOBALS['wp_filter'][$tag][$priority]); |
|
| 308 | 308 | } |
| 309 | - if ( empty( $GLOBALS['wp_filter'][ $tag ] ) ) { |
|
| 310 | - $GLOBALS['wp_filter'][ $tag ] = array(); |
|
| 309 | + if (empty($GLOBALS['wp_filter'][$tag])) { |
|
| 310 | + $GLOBALS['wp_filter'][$tag] = array(); |
|
| 311 | 311 | } |
| 312 | - unset( $GLOBALS['merged_filters'][ $tag ] ); |
|
| 312 | + unset($GLOBALS['merged_filters'][$tag]); |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | return $r; |
@@ -327,18 +327,18 @@ discard block |
||
| 327 | 327 | * @param int|bool $priority Optional. The priority number to remove. Default false. |
| 328 | 328 | * @return true True when finished. |
| 329 | 329 | */ |
| 330 | -function remove_all_filters( $tag, $priority = false ) { |
|
| 330 | +function remove_all_filters($tag, $priority = false) { |
|
| 331 | 331 | global $wp_filter, $merged_filters; |
| 332 | 332 | |
| 333 | - if ( isset( $wp_filter[ $tag ]) ) { |
|
| 334 | - if ( false === $priority ) { |
|
| 335 | - $wp_filter[ $tag ] = array(); |
|
| 336 | - } elseif ( isset( $wp_filter[ $tag ][ $priority ] ) ) { |
|
| 337 | - $wp_filter[ $tag ][ $priority ] = array(); |
|
| 333 | + if (isset($wp_filter[$tag])) { |
|
| 334 | + if (false === $priority) { |
|
| 335 | + $wp_filter[$tag] = array(); |
|
| 336 | + } elseif (isset($wp_filter[$tag][$priority])) { |
|
| 337 | + $wp_filter[$tag][$priority] = array(); |
|
| 338 | 338 | } |
| 339 | 339 | } |
| 340 | 340 | |
| 341 | - unset( $merged_filters[ $tag ] ); |
|
| 341 | + unset($merged_filters[$tag]); |
|
| 342 | 342 | |
| 343 | 343 | return true; |
| 344 | 344 | } |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | */ |
| 355 | 355 | function current_filter() { |
| 356 | 356 | global $wp_current_filter; |
| 357 | - return end( $wp_current_filter ); |
|
| 357 | + return end($wp_current_filter); |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | /** |
@@ -389,14 +389,14 @@ discard block |
||
| 389 | 389 | * checks if any filter is currently being run. |
| 390 | 390 | * @return bool Whether the filter is currently in the stack. |
| 391 | 391 | */ |
| 392 | -function doing_filter( $filter = null ) { |
|
| 392 | +function doing_filter($filter = null) { |
|
| 393 | 393 | global $wp_current_filter; |
| 394 | 394 | |
| 395 | - if ( null === $filter ) { |
|
| 396 | - return ! empty( $wp_current_filter ); |
|
| 395 | + if (null === $filter) { |
|
| 396 | + return ! empty($wp_current_filter); |
|
| 397 | 397 | } |
| 398 | 398 | |
| 399 | - return in_array( $filter, $wp_current_filter ); |
|
| 399 | + return in_array($filter, $wp_current_filter); |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | /** |
@@ -408,8 +408,8 @@ discard block |
||
| 408 | 408 | * if any action is currently being run. |
| 409 | 409 | * @return bool Whether the action is currently in the stack. |
| 410 | 410 | */ |
| 411 | -function doing_action( $action = null ) { |
|
| 412 | - return doing_filter( $action ); |
|
| 411 | +function doing_action($action = null) { |
|
| 412 | + return doing_filter($action); |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | /** |
@@ -460,49 +460,49 @@ discard block |
||
| 460 | 460 | function do_action($tag, $arg = '') { |
| 461 | 461 | global $wp_filter, $wp_actions, $merged_filters, $wp_current_filter; |
| 462 | 462 | |
| 463 | - if ( ! isset($wp_actions[$tag]) ) |
|
| 463 | + if ( ! isset($wp_actions[$tag])) |
|
| 464 | 464 | $wp_actions[$tag] = 1; |
| 465 | 465 | else |
| 466 | 466 | ++$wp_actions[$tag]; |
| 467 | 467 | |
| 468 | 468 | // Do 'all' actions first |
| 469 | - if ( isset($wp_filter['all']) ) { |
|
| 469 | + if (isset($wp_filter['all'])) { |
|
| 470 | 470 | $wp_current_filter[] = $tag; |
| 471 | 471 | $all_args = func_get_args(); |
| 472 | 472 | _wp_call_all_hook($all_args); |
| 473 | 473 | } |
| 474 | 474 | |
| 475 | - if ( !isset($wp_filter[$tag]) ) { |
|
| 476 | - if ( isset($wp_filter['all']) ) |
|
| 475 | + if ( ! isset($wp_filter[$tag])) { |
|
| 476 | + if (isset($wp_filter['all'])) |
|
| 477 | 477 | array_pop($wp_current_filter); |
| 478 | 478 | return; |
| 479 | 479 | } |
| 480 | 480 | |
| 481 | - if ( !isset($wp_filter['all']) ) |
|
| 481 | + if ( ! isset($wp_filter['all'])) |
|
| 482 | 482 | $wp_current_filter[] = $tag; |
| 483 | 483 | |
| 484 | 484 | $args = array(); |
| 485 | - if ( is_array($arg) && 1 == count($arg) && isset($arg[0]) && is_object($arg[0]) ) // array(&$this) |
|
| 486 | - $args[] =& $arg[0]; |
|
| 485 | + if (is_array($arg) && 1 == count($arg) && isset($arg[0]) && is_object($arg[0])) // array(&$this) |
|
| 486 | + $args[] = & $arg[0]; |
|
| 487 | 487 | else |
| 488 | 488 | $args[] = $arg; |
| 489 | - for ( $a = 2, $num = func_num_args(); $a < $num; $a++ ) |
|
| 489 | + for ($a = 2, $num = func_num_args(); $a < $num; $a++) |
|
| 490 | 490 | $args[] = func_get_arg($a); |
| 491 | 491 | |
| 492 | 492 | // Sort |
| 493 | - if ( !isset( $merged_filters[ $tag ] ) ) { |
|
| 493 | + if ( ! isset($merged_filters[$tag])) { |
|
| 494 | 494 | ksort($wp_filter[$tag]); |
| 495 | - $merged_filters[ $tag ] = true; |
|
| 495 | + $merged_filters[$tag] = true; |
|
| 496 | 496 | } |
| 497 | 497 | |
| 498 | - reset( $wp_filter[ $tag ] ); |
|
| 498 | + reset($wp_filter[$tag]); |
|
| 499 | 499 | |
| 500 | 500 | do { |
| 501 | - foreach ( (array) current($wp_filter[$tag]) as $the_ ) |
|
| 502 | - if ( !is_null($the_['function']) ) |
|
| 501 | + foreach ((array) current($wp_filter[$tag]) as $the_) |
|
| 502 | + if ( ! is_null($the_['function'])) |
|
| 503 | 503 | call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args'])); |
| 504 | 504 | |
| 505 | - } while ( next($wp_filter[$tag]) !== false ); |
|
| 505 | + } while (next($wp_filter[$tag]) !== false); |
|
| 506 | 506 | |
| 507 | 507 | array_pop($wp_current_filter); |
| 508 | 508 | } |
@@ -520,7 +520,7 @@ discard block |
||
| 520 | 520 | function did_action($tag) { |
| 521 | 521 | global $wp_actions; |
| 522 | 522 | |
| 523 | - if ( ! isset( $wp_actions[ $tag ] ) ) |
|
| 523 | + if ( ! isset($wp_actions[$tag])) |
|
| 524 | 524 | return 0; |
| 525 | 525 | |
| 526 | 526 | return $wp_actions[$tag]; |
@@ -544,41 +544,41 @@ discard block |
||
| 544 | 544 | function do_action_ref_array($tag, $args) { |
| 545 | 545 | global $wp_filter, $wp_actions, $merged_filters, $wp_current_filter; |
| 546 | 546 | |
| 547 | - if ( ! isset($wp_actions[$tag]) ) |
|
| 547 | + if ( ! isset($wp_actions[$tag])) |
|
| 548 | 548 | $wp_actions[$tag] = 1; |
| 549 | 549 | else |
| 550 | 550 | ++$wp_actions[$tag]; |
| 551 | 551 | |
| 552 | 552 | // Do 'all' actions first |
| 553 | - if ( isset($wp_filter['all']) ) { |
|
| 553 | + if (isset($wp_filter['all'])) { |
|
| 554 | 554 | $wp_current_filter[] = $tag; |
| 555 | 555 | $all_args = func_get_args(); |
| 556 | 556 | _wp_call_all_hook($all_args); |
| 557 | 557 | } |
| 558 | 558 | |
| 559 | - if ( !isset($wp_filter[$tag]) ) { |
|
| 560 | - if ( isset($wp_filter['all']) ) |
|
| 559 | + if ( ! isset($wp_filter[$tag])) { |
|
| 560 | + if (isset($wp_filter['all'])) |
|
| 561 | 561 | array_pop($wp_current_filter); |
| 562 | 562 | return; |
| 563 | 563 | } |
| 564 | 564 | |
| 565 | - if ( !isset($wp_filter['all']) ) |
|
| 565 | + if ( ! isset($wp_filter['all'])) |
|
| 566 | 566 | $wp_current_filter[] = $tag; |
| 567 | 567 | |
| 568 | 568 | // Sort |
| 569 | - if ( !isset( $merged_filters[ $tag ] ) ) { |
|
| 569 | + if ( ! isset($merged_filters[$tag])) { |
|
| 570 | 570 | ksort($wp_filter[$tag]); |
| 571 | - $merged_filters[ $tag ] = true; |
|
| 571 | + $merged_filters[$tag] = true; |
|
| 572 | 572 | } |
| 573 | 573 | |
| 574 | - reset( $wp_filter[ $tag ] ); |
|
| 574 | + reset($wp_filter[$tag]); |
|
| 575 | 575 | |
| 576 | 576 | do { |
| 577 | - foreach( (array) current($wp_filter[$tag]) as $the_ ) |
|
| 578 | - if ( !is_null($the_['function']) ) |
|
| 577 | + foreach ((array) current($wp_filter[$tag]) as $the_) |
|
| 578 | + if ( ! is_null($the_['function'])) |
|
| 579 | 579 | call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args'])); |
| 580 | 580 | |
| 581 | - } while ( next($wp_filter[$tag]) !== false ); |
|
| 581 | + } while (next($wp_filter[$tag]) !== false); |
|
| 582 | 582 | |
| 583 | 583 | array_pop($wp_current_filter); |
| 584 | 584 | } |
@@ -617,8 +617,8 @@ discard block |
||
| 617 | 617 | * @param int $priority Optional. The priority of the function. Default 10. |
| 618 | 618 | * @return bool Whether the function is removed. |
| 619 | 619 | */ |
| 620 | -function remove_action( $tag, $function_to_remove, $priority = 10 ) { |
|
| 621 | - return remove_filter( $tag, $function_to_remove, $priority ); |
|
| 620 | +function remove_action($tag, $function_to_remove, $priority = 10) { |
|
| 621 | + return remove_filter($tag, $function_to_remove, $priority); |
|
| 622 | 622 | } |
| 623 | 623 | |
| 624 | 624 | /** |
@@ -650,20 +650,20 @@ discard block |
||
| 650 | 650 | * @param string $file The filename of plugin. |
| 651 | 651 | * @return string The name of a plugin. |
| 652 | 652 | */ |
| 653 | -function plugin_basename( $file ) { |
|
| 653 | +function plugin_basename($file) { |
|
| 654 | 654 | global $wp_plugin_paths; |
| 655 | 655 | |
| 656 | - foreach ( $wp_plugin_paths as $dir => $realdir ) { |
|
| 657 | - if ( strpos( $file, $realdir ) === 0 ) { |
|
| 658 | - $file = $dir . substr( $file, strlen( $realdir ) ); |
|
| 656 | + foreach ($wp_plugin_paths as $dir => $realdir) { |
|
| 657 | + if (strpos($file, $realdir) === 0) { |
|
| 658 | + $file = $dir.substr($file, strlen($realdir)); |
|
| 659 | 659 | } |
| 660 | 660 | } |
| 661 | 661 | |
| 662 | - $file = wp_normalize_path( $file ); |
|
| 663 | - $plugin_dir = wp_normalize_path( WP_PLUGIN_DIR ); |
|
| 664 | - $mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR ); |
|
| 662 | + $file = wp_normalize_path($file); |
|
| 663 | + $plugin_dir = wp_normalize_path(WP_PLUGIN_DIR); |
|
| 664 | + $mu_plugin_dir = wp_normalize_path(WPMU_PLUGIN_DIR); |
|
| 665 | 665 | |
| 666 | - $file = preg_replace('#^' . preg_quote($plugin_dir, '#') . '/|^' . preg_quote($mu_plugin_dir, '#') . '/#','',$file); // get relative path from plugins dir |
|
| 666 | + $file = preg_replace('#^'.preg_quote($plugin_dir, '#').'/|^'.preg_quote($mu_plugin_dir, '#').'/#', '', $file); // get relative path from plugins dir |
|
| 667 | 667 | $file = trim($file, '/'); |
| 668 | 668 | return $file; |
| 669 | 669 | } |
@@ -685,25 +685,25 @@ discard block |
||
| 685 | 685 | * @param string $file Known path to the file. |
| 686 | 686 | * @return bool Whether the path was able to be registered. |
| 687 | 687 | */ |
| 688 | -function wp_register_plugin_realpath( $file ) { |
|
| 688 | +function wp_register_plugin_realpath($file) { |
|
| 689 | 689 | global $wp_plugin_paths; |
| 690 | 690 | |
| 691 | 691 | // Normalize, but store as static to avoid recalculation of a constant value |
| 692 | 692 | static $wp_plugin_path = null, $wpmu_plugin_path = null; |
| 693 | - if ( ! isset( $wp_plugin_path ) ) { |
|
| 694 | - $wp_plugin_path = wp_normalize_path( WP_PLUGIN_DIR ); |
|
| 695 | - $wpmu_plugin_path = wp_normalize_path( WPMU_PLUGIN_DIR ); |
|
| 693 | + if ( ! isset($wp_plugin_path)) { |
|
| 694 | + $wp_plugin_path = wp_normalize_path(WP_PLUGIN_DIR); |
|
| 695 | + $wpmu_plugin_path = wp_normalize_path(WPMU_PLUGIN_DIR); |
|
| 696 | 696 | } |
| 697 | 697 | |
| 698 | - $plugin_path = wp_normalize_path( dirname( $file ) ); |
|
| 699 | - $plugin_realpath = wp_normalize_path( dirname( realpath( $file ) ) ); |
|
| 698 | + $plugin_path = wp_normalize_path(dirname($file)); |
|
| 699 | + $plugin_realpath = wp_normalize_path(dirname(realpath($file))); |
|
| 700 | 700 | |
| 701 | - if ( $plugin_path === $wp_plugin_path || $plugin_path === $wpmu_plugin_path ) { |
|
| 701 | + if ($plugin_path === $wp_plugin_path || $plugin_path === $wpmu_plugin_path) { |
|
| 702 | 702 | return false; |
| 703 | 703 | } |
| 704 | 704 | |
| 705 | - if ( $plugin_path !== $plugin_realpath ) { |
|
| 706 | - $wp_plugin_paths[ $plugin_path ] = $plugin_realpath; |
|
| 705 | + if ($plugin_path !== $plugin_realpath) { |
|
| 706 | + $wp_plugin_paths[$plugin_path] = $plugin_realpath; |
|
| 707 | 707 | } |
| 708 | 708 | |
| 709 | 709 | return true; |
@@ -717,8 +717,8 @@ discard block |
||
| 717 | 717 | * @param string $file The filename of the plugin (__FILE__). |
| 718 | 718 | * @return string the filesystem path of the directory that contains the plugin. |
| 719 | 719 | */ |
| 720 | -function plugin_dir_path( $file ) { |
|
| 721 | - return trailingslashit( dirname( $file ) ); |
|
| 720 | +function plugin_dir_path($file) { |
|
| 721 | + return trailingslashit(dirname($file)); |
|
| 722 | 722 | } |
| 723 | 723 | |
| 724 | 724 | /** |
@@ -729,8 +729,8 @@ discard block |
||
| 729 | 729 | * @param string $file The filename of the plugin (__FILE__). |
| 730 | 730 | * @return string the URL path of the directory that contains the plugin. |
| 731 | 731 | */ |
| 732 | -function plugin_dir_url( $file ) { |
|
| 733 | - return trailingslashit( plugins_url( '', $file ) ); |
|
| 732 | +function plugin_dir_url($file) { |
|
| 733 | + return trailingslashit(plugins_url('', $file)); |
|
| 734 | 734 | } |
| 735 | 735 | |
| 736 | 736 | /** |
@@ -753,7 +753,7 @@ discard block |
||
| 753 | 753 | */ |
| 754 | 754 | function register_activation_hook($file, $function) { |
| 755 | 755 | $file = plugin_basename($file); |
| 756 | - add_action('activate_' . $file, $function); |
|
| 756 | + add_action('activate_'.$file, $function); |
|
| 757 | 757 | } |
| 758 | 758 | |
| 759 | 759 | /** |
@@ -776,7 +776,7 @@ discard block |
||
| 776 | 776 | */ |
| 777 | 777 | function register_deactivation_hook($file, $function) { |
| 778 | 778 | $file = plugin_basename($file); |
| 779 | - add_action('deactivate_' . $file, $function); |
|
| 779 | + add_action('deactivate_'.$file, $function); |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | /** |
@@ -805,9 +805,9 @@ discard block |
||
| 805 | 805 | * @param callback $callback The callback to run when the hook is called. Must be |
| 806 | 806 | * a static method or function. |
| 807 | 807 | */ |
| 808 | -function register_uninstall_hook( $file, $callback ) { |
|
| 809 | - if ( is_array( $callback ) && is_object( $callback[0] ) ) { |
|
| 810 | - _doing_it_wrong( __FUNCTION__, __( 'Only a static class method or function can be used in an uninstall hook.' ), '3.1' ); |
|
| 808 | +function register_uninstall_hook($file, $callback) { |
|
| 809 | + if (is_array($callback) && is_object($callback[0])) { |
|
| 810 | + _doing_it_wrong(__FUNCTION__, __('Only a static class method or function can be used in an uninstall hook.'), '3.1'); |
|
| 811 | 811 | return; |
| 812 | 812 | } |
| 813 | 813 | |
@@ -843,13 +843,13 @@ discard block |
||
| 843 | 843 | function _wp_call_all_hook($args) { |
| 844 | 844 | global $wp_filter; |
| 845 | 845 | |
| 846 | - reset( $wp_filter['all'] ); |
|
| 846 | + reset($wp_filter['all']); |
|
| 847 | 847 | do { |
| 848 | - foreach( (array) current($wp_filter['all']) as $the_ ) |
|
| 849 | - if ( !is_null($the_['function']) ) |
|
| 848 | + foreach ((array) current($wp_filter['all']) as $the_) |
|
| 849 | + if ( ! is_null($the_['function'])) |
|
| 850 | 850 | call_user_func_array($the_['function'], $args); |
| 851 | 851 | |
| 852 | - } while ( next($wp_filter['all']) !== false ); |
|
| 852 | + } while (next($wp_filter['all']) !== false); |
|
| 853 | 853 | } |
| 854 | 854 | |
| 855 | 855 | /** |
@@ -890,26 +890,26 @@ discard block |
||
| 890 | 890 | global $wp_filter; |
| 891 | 891 | static $filter_id_count = 0; |
| 892 | 892 | |
| 893 | - if ( is_string($function) ) |
|
| 893 | + if (is_string($function)) |
|
| 894 | 894 | return $function; |
| 895 | 895 | |
| 896 | - if ( is_object($function) ) { |
|
| 896 | + if (is_object($function)) { |
|
| 897 | 897 | // Closures are currently implemented as objects |
| 898 | - $function = array( $function, '' ); |
|
| 898 | + $function = array($function, ''); |
|
| 899 | 899 | } else { |
| 900 | 900 | $function = (array) $function; |
| 901 | 901 | } |
| 902 | 902 | |
| 903 | - if (is_object($function[0]) ) { |
|
| 903 | + if (is_object($function[0])) { |
|
| 904 | 904 | // Object Class Calling |
| 905 | - if ( function_exists('spl_object_hash') ) { |
|
| 906 | - return spl_object_hash($function[0]) . $function[1]; |
|
| 905 | + if (function_exists('spl_object_hash')) { |
|
| 906 | + return spl_object_hash($function[0]).$function[1]; |
|
| 907 | 907 | } else { |
| 908 | 908 | $obj_idx = get_class($function[0]).$function[1]; |
| 909 | - if ( !isset($function[0]->wp_filter_id) ) { |
|
| 910 | - if ( false === $priority ) |
|
| 909 | + if ( ! isset($function[0]->wp_filter_id)) { |
|
| 910 | + if (false === $priority) |
|
| 911 | 911 | return false; |
| 912 | - $obj_idx .= isset($wp_filter[$tag][$priority]) ? count((array)$wp_filter[$tag][$priority]) : $filter_id_count; |
|
| 912 | + $obj_idx .= isset($wp_filter[$tag][$priority]) ? count((array) $wp_filter[$tag][$priority]) : $filter_id_count; |
|
| 913 | 913 | $function[0]->wp_filter_id = $filter_id_count; |
| 914 | 914 | ++$filter_id_count; |
| 915 | 915 | } else { |
@@ -918,8 +918,8 @@ discard block |
||
| 918 | 918 | |
| 919 | 919 | return $obj_idx; |
| 920 | 920 | } |
| 921 | - } elseif ( is_string( $function[0] ) ) { |
|
| 921 | + } elseif (is_string($function[0])) { |
|
| 922 | 922 | // Static Calling |
| 923 | - return $function[0] . '::' . $function[1]; |
|
| 923 | + return $function[0].'::'.$function[1]; |
|
| 924 | 924 | } |
| 925 | 925 | } |
@@ -22,17 +22,21 @@ discard block |
||
| 22 | 22 | // Initialize the filter globals. |
| 23 | 23 | global $wp_filter, $wp_actions, $merged_filters, $wp_current_filter; |
| 24 | 24 | |
| 25 | -if ( ! isset( $wp_filter ) ) |
|
| 25 | +if ( ! isset( $wp_filter ) ) { |
|
| 26 | 26 | $wp_filter = array(); |
| 27 | +} |
|
| 27 | 28 | |
| 28 | -if ( ! isset( $wp_actions ) ) |
|
| 29 | +if ( ! isset( $wp_actions ) ) { |
|
| 29 | 30 | $wp_actions = array(); |
| 31 | +} |
|
| 30 | 32 | |
| 31 | -if ( ! isset( $merged_filters ) ) |
|
| 33 | +if ( ! isset( $merged_filters ) ) { |
|
| 32 | 34 | $merged_filters = array(); |
| 35 | +} |
|
| 33 | 36 | |
| 34 | -if ( ! isset( $wp_current_filter ) ) |
|
| 37 | +if ( ! isset( $wp_current_filter ) ) { |
|
| 35 | 38 | $wp_current_filter = array(); |
| 39 | +} |
|
| 36 | 40 | |
| 37 | 41 | /** |
| 38 | 42 | * Hook a function or method to a specific filter action. |
@@ -124,15 +128,18 @@ discard block |
||
| 124 | 128 | } |
| 125 | 129 | } |
| 126 | 130 | |
| 127 | - if ( false === $function_to_check || false === $has ) |
|
| 128 | - return $has; |
|
| 131 | + if ( false === $function_to_check || false === $has ) { |
|
| 132 | + return $has; |
|
| 133 | + } |
|
| 129 | 134 | |
| 130 | - if ( !$idx = _wp_filter_build_unique_id($tag, $function_to_check, false) ) |
|
| 131 | - return false; |
|
| 135 | + if ( !$idx = _wp_filter_build_unique_id($tag, $function_to_check, false) ) { |
|
| 136 | + return false; |
|
| 137 | + } |
|
| 132 | 138 | |
| 133 | 139 | foreach ( (array) array_keys($wp_filter[$tag]) as $priority ) { |
| 134 | - if ( isset($wp_filter[$tag][$priority][$idx]) ) |
|
| 135 | - return $priority; |
|
| 140 | + if ( isset($wp_filter[$tag][$priority][$idx]) ) { |
|
| 141 | + return $priority; |
|
| 142 | + } |
|
| 136 | 143 | } |
| 137 | 144 | |
| 138 | 145 | return false; |
@@ -187,13 +194,15 @@ discard block |
||
| 187 | 194 | } |
| 188 | 195 | |
| 189 | 196 | if ( !isset($wp_filter[$tag]) ) { |
| 190 | - if ( isset($wp_filter['all']) ) |
|
| 191 | - array_pop($wp_current_filter); |
|
| 197 | + if ( isset($wp_filter['all']) ) { |
|
| 198 | + array_pop($wp_current_filter); |
|
| 199 | + } |
|
| 192 | 200 | return $value; |
| 193 | 201 | } |
| 194 | 202 | |
| 195 | - if ( !isset($wp_filter['all']) ) |
|
| 196 | - $wp_current_filter[] = $tag; |
|
| 203 | + if ( !isset($wp_filter['all']) ) { |
|
| 204 | + $wp_current_filter[] = $tag; |
|
| 205 | + } |
|
| 197 | 206 | |
| 198 | 207 | // Sort. |
| 199 | 208 | if ( !isset( $merged_filters[ $tag ] ) ) { |
@@ -203,13 +212,15 @@ discard block |
||
| 203 | 212 | |
| 204 | 213 | reset( $wp_filter[ $tag ] ); |
| 205 | 214 | |
| 206 | - if ( empty($args) ) |
|
| 207 | - $args = func_get_args(); |
|
| 215 | + if ( empty($args) ) { |
|
| 216 | + $args = func_get_args(); |
|
| 217 | + } |
|
| 208 | 218 | |
| 209 | 219 | do { |
| 210 | - foreach( (array) current($wp_filter[$tag]) as $the_ ) |
|
| 211 | - if ( !is_null($the_['function']) ){ |
|
| 220 | + foreach( (array) current($wp_filter[$tag]) as $the_ ) { |
|
| 221 | + if ( !is_null($the_['function']) ){ |
|
| 212 | 222 | $args[1] = $value; |
| 223 | + } |
|
| 213 | 224 | $value = call_user_func_array($the_['function'], array_slice($args, 1, (int) $the_['accepted_args'])); |
| 214 | 225 | } |
| 215 | 226 | |
@@ -247,13 +258,15 @@ discard block |
||
| 247 | 258 | } |
| 248 | 259 | |
| 249 | 260 | if ( !isset($wp_filter[$tag]) ) { |
| 250 | - if ( isset($wp_filter['all']) ) |
|
| 251 | - array_pop($wp_current_filter); |
|
| 261 | + if ( isset($wp_filter['all']) ) { |
|
| 262 | + array_pop($wp_current_filter); |
|
| 263 | + } |
|
| 252 | 264 | return $args[0]; |
| 253 | 265 | } |
| 254 | 266 | |
| 255 | - if ( !isset($wp_filter['all']) ) |
|
| 256 | - $wp_current_filter[] = $tag; |
|
| 267 | + if ( !isset($wp_filter['all']) ) { |
|
| 268 | + $wp_current_filter[] = $tag; |
|
| 269 | + } |
|
| 257 | 270 | |
| 258 | 271 | // Sort |
| 259 | 272 | if ( !isset( $merged_filters[ $tag ] ) ) { |
@@ -264,9 +277,10 @@ discard block |
||
| 264 | 277 | reset( $wp_filter[ $tag ] ); |
| 265 | 278 | |
| 266 | 279 | do { |
| 267 | - foreach( (array) current($wp_filter[$tag]) as $the_ ) |
|
| 268 | - if ( !is_null($the_['function']) ) |
|
| 280 | + foreach( (array) current($wp_filter[$tag]) as $the_ ) { |
|
| 281 | + if ( !is_null($the_['function']) ) |
|
| 269 | 282 | $args[0] = call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args'])); |
| 283 | + } |
|
| 270 | 284 | |
| 271 | 285 | } while ( next($wp_filter[$tag]) !== false ); |
| 272 | 286 | |
@@ -460,10 +474,11 @@ discard block |
||
| 460 | 474 | function do_action($tag, $arg = '') { |
| 461 | 475 | global $wp_filter, $wp_actions, $merged_filters, $wp_current_filter; |
| 462 | 476 | |
| 463 | - if ( ! isset($wp_actions[$tag]) ) |
|
| 464 | - $wp_actions[$tag] = 1; |
|
| 465 | - else |
|
| 466 | - ++$wp_actions[$tag]; |
|
| 477 | + if ( ! isset($wp_actions[$tag]) ) { |
|
| 478 | + $wp_actions[$tag] = 1; |
|
| 479 | + } else { |
|
| 480 | + ++$wp_actions[$tag]; |
|
| 481 | + } |
|
| 467 | 482 | |
| 468 | 483 | // Do 'all' actions first |
| 469 | 484 | if ( isset($wp_filter['all']) ) { |
@@ -473,21 +488,26 @@ discard block |
||
| 473 | 488 | } |
| 474 | 489 | |
| 475 | 490 | if ( !isset($wp_filter[$tag]) ) { |
| 476 | - if ( isset($wp_filter['all']) ) |
|
| 477 | - array_pop($wp_current_filter); |
|
| 491 | + if ( isset($wp_filter['all']) ) { |
|
| 492 | + array_pop($wp_current_filter); |
|
| 493 | + } |
|
| 478 | 494 | return; |
| 479 | 495 | } |
| 480 | 496 | |
| 481 | - if ( !isset($wp_filter['all']) ) |
|
| 482 | - $wp_current_filter[] = $tag; |
|
| 497 | + if ( !isset($wp_filter['all']) ) { |
|
| 498 | + $wp_current_filter[] = $tag; |
|
| 499 | + } |
|
| 483 | 500 | |
| 484 | 501 | $args = array(); |
| 485 | - if ( is_array($arg) && 1 == count($arg) && isset($arg[0]) && is_object($arg[0]) ) // array(&$this) |
|
| 502 | + if ( is_array($arg) && 1 == count($arg) && isset($arg[0]) && is_object($arg[0]) ) { |
|
| 503 | + // array(&$this) |
|
| 486 | 504 | $args[] =& $arg[0]; |
| 487 | - else |
|
| 488 | - $args[] = $arg; |
|
| 489 | - for ( $a = 2, $num = func_num_args(); $a < $num; $a++ ) |
|
| 490 | - $args[] = func_get_arg($a); |
|
| 505 | + } else { |
|
| 506 | + $args[] = $arg; |
|
| 507 | + } |
|
| 508 | + for ( $a = 2, $num = func_num_args(); $a < $num; $a++ ) { |
|
| 509 | + $args[] = func_get_arg($a); |
|
| 510 | + } |
|
| 491 | 511 | |
| 492 | 512 | // Sort |
| 493 | 513 | if ( !isset( $merged_filters[ $tag ] ) ) { |
@@ -498,9 +518,10 @@ discard block |
||
| 498 | 518 | reset( $wp_filter[ $tag ] ); |
| 499 | 519 | |
| 500 | 520 | do { |
| 501 | - foreach ( (array) current($wp_filter[$tag]) as $the_ ) |
|
| 502 | - if ( !is_null($the_['function']) ) |
|
| 521 | + foreach ( (array) current($wp_filter[$tag]) as $the_ ) { |
|
| 522 | + if ( !is_null($the_['function']) ) |
|
| 503 | 523 | call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args'])); |
| 524 | + } |
|
| 504 | 525 | |
| 505 | 526 | } while ( next($wp_filter[$tag]) !== false ); |
| 506 | 527 | |
@@ -520,8 +541,9 @@ discard block |
||
| 520 | 541 | function did_action($tag) { |
| 521 | 542 | global $wp_actions; |
| 522 | 543 | |
| 523 | - if ( ! isset( $wp_actions[ $tag ] ) ) |
|
| 524 | - return 0; |
|
| 544 | + if ( ! isset( $wp_actions[ $tag ] ) ) { |
|
| 545 | + return 0; |
|
| 546 | + } |
|
| 525 | 547 | |
| 526 | 548 | return $wp_actions[$tag]; |
| 527 | 549 | } |
@@ -544,10 +566,11 @@ discard block |
||
| 544 | 566 | function do_action_ref_array($tag, $args) { |
| 545 | 567 | global $wp_filter, $wp_actions, $merged_filters, $wp_current_filter; |
| 546 | 568 | |
| 547 | - if ( ! isset($wp_actions[$tag]) ) |
|
| 548 | - $wp_actions[$tag] = 1; |
|
| 549 | - else |
|
| 550 | - ++$wp_actions[$tag]; |
|
| 569 | + if ( ! isset($wp_actions[$tag]) ) { |
|
| 570 | + $wp_actions[$tag] = 1; |
|
| 571 | + } else { |
|
| 572 | + ++$wp_actions[$tag]; |
|
| 573 | + } |
|
| 551 | 574 | |
| 552 | 575 | // Do 'all' actions first |
| 553 | 576 | if ( isset($wp_filter['all']) ) { |
@@ -557,13 +580,15 @@ discard block |
||
| 557 | 580 | } |
| 558 | 581 | |
| 559 | 582 | if ( !isset($wp_filter[$tag]) ) { |
| 560 | - if ( isset($wp_filter['all']) ) |
|
| 561 | - array_pop($wp_current_filter); |
|
| 583 | + if ( isset($wp_filter['all']) ) { |
|
| 584 | + array_pop($wp_current_filter); |
|
| 585 | + } |
|
| 562 | 586 | return; |
| 563 | 587 | } |
| 564 | 588 | |
| 565 | - if ( !isset($wp_filter['all']) ) |
|
| 566 | - $wp_current_filter[] = $tag; |
|
| 589 | + if ( !isset($wp_filter['all']) ) { |
|
| 590 | + $wp_current_filter[] = $tag; |
|
| 591 | + } |
|
| 567 | 592 | |
| 568 | 593 | // Sort |
| 569 | 594 | if ( !isset( $merged_filters[ $tag ] ) ) { |
@@ -574,9 +599,10 @@ discard block |
||
| 574 | 599 | reset( $wp_filter[ $tag ] ); |
| 575 | 600 | |
| 576 | 601 | do { |
| 577 | - foreach( (array) current($wp_filter[$tag]) as $the_ ) |
|
| 578 | - if ( !is_null($the_['function']) ) |
|
| 602 | + foreach( (array) current($wp_filter[$tag]) as $the_ ) { |
|
| 603 | + if ( !is_null($the_['function']) ) |
|
| 579 | 604 | call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args'])); |
| 605 | + } |
|
| 580 | 606 | |
| 581 | 607 | } while ( next($wp_filter[$tag]) !== false ); |
| 582 | 608 | |
@@ -845,9 +871,10 @@ discard block |
||
| 845 | 871 | |
| 846 | 872 | reset( $wp_filter['all'] ); |
| 847 | 873 | do { |
| 848 | - foreach( (array) current($wp_filter['all']) as $the_ ) |
|
| 849 | - if ( !is_null($the_['function']) ) |
|
| 874 | + foreach( (array) current($wp_filter['all']) as $the_ ) { |
|
| 875 | + if ( !is_null($the_['function']) ) |
|
| 850 | 876 | call_user_func_array($the_['function'], $args); |
| 877 | + } |
|
| 851 | 878 | |
| 852 | 879 | } while ( next($wp_filter['all']) !== false ); |
| 853 | 880 | } |
@@ -890,8 +917,9 @@ discard block |
||
| 890 | 917 | global $wp_filter; |
| 891 | 918 | static $filter_id_count = 0; |
| 892 | 919 | |
| 893 | - if ( is_string($function) ) |
|
| 894 | - return $function; |
|
| 920 | + if ( is_string($function) ) { |
|
| 921 | + return $function; |
|
| 922 | + } |
|
| 895 | 923 | |
| 896 | 924 | if ( is_object($function) ) { |
| 897 | 925 | // Closures are currently implemented as objects |
@@ -907,8 +935,9 @@ discard block |
||
| 907 | 935 | } else { |
| 908 | 936 | $obj_idx = get_class($function[0]).$function[1]; |
| 909 | 937 | if ( !isset($function[0]->wp_filter_id) ) { |
| 910 | - if ( false === $priority ) |
|
| 911 | - return false; |
|
| 938 | + if ( false === $priority ) { |
|
| 939 | + return false; |
|
| 940 | + } |
|
| 912 | 941 | $obj_idx .= isset($wp_filter[$tag][$priority]) ? count((array)$wp_filter[$tag][$priority]) : $filter_id_count; |
| 913 | 942 | $function[0]->wp_filter_id = $filter_id_count; |
| 914 | 943 | ++$filter_id_count; |
@@ -68,7 +68,7 @@ |
||
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | 70 | * @param resource $fh |
| 71 | - * @return true |
|
| 71 | + * @return boolean |
|
| 72 | 72 | */ |
| 73 | 73 | function export_to_file_handle($fh) { |
| 74 | 74 | $entries = array_filter( $this->entries, array( $this, 'is_entry_good_for_export' ) ); |
@@ -1,11 +1,11 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Class for working with MO files |
|
| 4 | - * |
|
| 5 | - * @version $Id: mo.php 718 2012-10-31 00:32:02Z nbachiyski $ |
|
| 6 | - * @package pomo |
|
| 7 | - * @subpackage mo |
|
| 8 | - */ |
|
| 3 | + * Class for working with MO files |
|
| 4 | + * |
|
| 5 | + * @version $Id: mo.php 718 2012-10-31 00:32:02Z nbachiyski $ |
|
| 6 | + * @package pomo |
|
| 7 | + * @subpackage mo |
|
| 8 | + */ |
|
| 9 | 9 | |
| 10 | 10 | require_once dirname(__FILE__) . '/translations.php'; |
| 11 | 11 | require_once dirname(__FILE__) . '/streams.php'; |
@@ -7,10 +7,10 @@ discard block |
||
| 7 | 7 | * @subpackage mo |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -require_once dirname(__FILE__) . '/translations.php'; |
|
| 11 | -require_once dirname(__FILE__) . '/streams.php'; |
|
| 10 | +require_once dirname(__FILE__).'/translations.php'; |
|
| 11 | +require_once dirname(__FILE__).'/streams.php'; |
|
| 12 | 12 | |
| 13 | -if ( !class_exists( 'MO' ) ): |
|
| 13 | +if ( ! class_exists('MO')): |
|
| 14 | 14 | class MO extends Gettext_Translations { |
| 15 | 15 | |
| 16 | 16 | var $_nplurals = 2; |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | function import_from_file($filename) { |
| 24 | 24 | $reader = new POMO_FileReader($filename); |
| 25 | - if (!$reader->is_resource()) |
|
| 25 | + if ( ! $reader->is_resource()) |
|
| 26 | 26 | return false; |
| 27 | 27 | return $this->import_from_reader($reader); |
| 28 | 28 | } |
@@ -33,8 +33,8 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | function export_to_file($filename) { |
| 35 | 35 | $fh = fopen($filename, 'wb'); |
| 36 | - if ( !$fh ) return false; |
|
| 37 | - $res = $this->export_to_file_handle( $fh ); |
|
| 36 | + if ( ! $fh) return false; |
|
| 37 | + $res = $this->export_to_file_handle($fh); |
|
| 38 | 38 | fclose($fh); |
| 39 | 39 | return $res; |
| 40 | 40 | } |
@@ -44,22 +44,22 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | function export() { |
| 46 | 46 | $tmp_fh = fopen("php://temp", 'r+'); |
| 47 | - if ( !$tmp_fh ) return false; |
|
| 48 | - $this->export_to_file_handle( $tmp_fh ); |
|
| 49 | - rewind( $tmp_fh ); |
|
| 50 | - return stream_get_contents( $tmp_fh ); |
|
| 47 | + if ( ! $tmp_fh) return false; |
|
| 48 | + $this->export_to_file_handle($tmp_fh); |
|
| 49 | + rewind($tmp_fh); |
|
| 50 | + return stream_get_contents($tmp_fh); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | 54 | * @param Translation_Entry $entry |
| 55 | 55 | * @return bool |
| 56 | 56 | */ |
| 57 | - function is_entry_good_for_export( $entry ) { |
|
| 58 | - if ( empty( $entry->translations ) ) { |
|
| 57 | + function is_entry_good_for_export($entry) { |
|
| 58 | + if (empty($entry->translations)) { |
|
| 59 | 59 | return false; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - if ( !array_filter( $entry->translations ) ) { |
|
| 62 | + if ( ! array_filter($entry->translations)) { |
|
| 63 | 63 | return false; |
| 64 | 64 | } |
| 65 | 65 | |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | * @return true |
| 72 | 72 | */ |
| 73 | 73 | function export_to_file_handle($fh) { |
| 74 | - $entries = array_filter( $this->entries, array( $this, 'is_entry_good_for_export' ) ); |
|
| 74 | + $entries = array_filter($this->entries, array($this, 'is_entry_good_for_export')); |
|
| 75 | 75 | ksort($entries); |
| 76 | 76 | $magic = 0x950412de; |
| 77 | 77 | $revision = 0; |
@@ -92,8 +92,8 @@ discard block |
||
| 92 | 92 | |
| 93 | 93 | $reader = new POMO_Reader(); |
| 94 | 94 | |
| 95 | - foreach($entries as $entry) { |
|
| 96 | - $originals_table .= $this->export_original($entry) . chr(0); |
|
| 95 | + foreach ($entries as $entry) { |
|
| 96 | + $originals_table .= $this->export_original($entry).chr(0); |
|
| 97 | 97 | $length = $reader->strlen($this->export_original($entry)); |
| 98 | 98 | fwrite($fh, pack('VV', $length, $current_addr)); |
| 99 | 99 | $current_addr += $length + 1; // account for the NULL byte after |
@@ -102,10 +102,10 @@ discard block |
||
| 102 | 102 | $exported_headers = $this->export_headers(); |
| 103 | 103 | fwrite($fh, pack('VV', $reader->strlen($exported_headers), $current_addr)); |
| 104 | 104 | $current_addr += strlen($exported_headers) + 1; |
| 105 | - $translations_table = $exported_headers . chr(0); |
|
| 105 | + $translations_table = $exported_headers.chr(0); |
|
| 106 | 106 | |
| 107 | - foreach($entries as $entry) { |
|
| 108 | - $translations_table .= $this->export_translations($entry) . chr(0); |
|
| 107 | + foreach ($entries as $entry) { |
|
| 108 | + $translations_table .= $this->export_translations($entry).chr(0); |
|
| 109 | 109 | $length = $reader->strlen($this->export_translations($entry)); |
| 110 | 110 | fwrite($fh, pack('VV', $length, $current_addr)); |
| 111 | 111 | $current_addr += $length + 1; |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | //TODO: warnings for control characters |
| 125 | 125 | $exported = $entry->singular; |
| 126 | 126 | if ($entry->is_plural) $exported .= chr(0).$entry->plural; |
| 127 | - if (!is_null($entry->context)) $exported = $entry->context . chr(4) . $exported; |
|
| 127 | + if ( ! is_null($entry->context)) $exported = $entry->context.chr(4).$exported; |
|
| 128 | 128 | return $exported; |
| 129 | 129 | } |
| 130 | 130 | |
@@ -142,8 +142,8 @@ discard block |
||
| 142 | 142 | */ |
| 143 | 143 | function export_headers() { |
| 144 | 144 | $exported = ''; |
| 145 | - foreach($this->headers as $header => $value) { |
|
| 146 | - $exported.= "$header: $value\n"; |
|
| 145 | + foreach ($this->headers as $header => $value) { |
|
| 146 | + $exported .= "$header: $value\n"; |
|
| 147 | 147 | } |
| 148 | 148 | return $exported; |
| 149 | 149 | } |
@@ -156,10 +156,10 @@ discard block |
||
| 156 | 156 | // The magic is 0x950412de |
| 157 | 157 | |
| 158 | 158 | // bug in PHP 5.0.2, see https://savannah.nongnu.org/bugs/?func=detailitem&item_id=10565 |
| 159 | - $magic_little = (int) - 1794895138; |
|
| 159 | + $magic_little = (int) -1794895138; |
|
| 160 | 160 | $magic_little_64 = (int) 2500072158; |
| 161 | 161 | // 0xde120495 |
| 162 | - $magic_big = ((int) - 569244523) & 0xFFFFFFFF; |
|
| 162 | + $magic_big = ((int) -569244523) & 0xFFFFFFFF; |
|
| 163 | 163 | if ($magic_little == $magic || $magic_little_64 == $magic) { |
| 164 | 164 | return 'little'; |
| 165 | 165 | } else if ($magic_big == $magic) { |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | } |
| 180 | 180 | $reader->setEndian($endian_string); |
| 181 | 181 | |
| 182 | - $endian = ('big' == $endian_string)? 'N' : 'V'; |
|
| 182 | + $endian = ('big' == $endian_string) ? 'N' : 'V'; |
|
| 183 | 183 | |
| 184 | 184 | $header = $reader->read(24); |
| 185 | 185 | if ($reader->strlen($header) != 24) |
@@ -187,42 +187,42 @@ discard block |
||
| 187 | 187 | |
| 188 | 188 | // parse header |
| 189 | 189 | $header = unpack("{$endian}revision/{$endian}total/{$endian}originals_lenghts_addr/{$endian}translations_lenghts_addr/{$endian}hash_length/{$endian}hash_addr", $header); |
| 190 | - if (!is_array($header)) |
|
| 190 | + if ( ! is_array($header)) |
|
| 191 | 191 | return false; |
| 192 | 192 | |
| 193 | 193 | // support revision 0 of MO format specs, only |
| 194 | - if ( $header['revision'] != 0 ) { |
|
| 194 | + if ($header['revision'] != 0) { |
|
| 195 | 195 | return false; |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | // seek to data blocks |
| 199 | - $reader->seekto( $header['originals_lenghts_addr'] ); |
|
| 199 | + $reader->seekto($header['originals_lenghts_addr']); |
|
| 200 | 200 | |
| 201 | 201 | // read originals' indices |
| 202 | 202 | $originals_lengths_length = $header['translations_lenghts_addr'] - $header['originals_lenghts_addr']; |
| 203 | - if ( $originals_lengths_length != $header['total'] * 8 ) { |
|
| 203 | + if ($originals_lengths_length != $header['total'] * 8) { |
|
| 204 | 204 | return false; |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | $originals = $reader->read($originals_lengths_length); |
| 208 | - if ( $reader->strlen( $originals ) != $originals_lengths_length ) { |
|
| 208 | + if ($reader->strlen($originals) != $originals_lengths_length) { |
|
| 209 | 209 | return false; |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | // read translations' indices |
| 213 | 213 | $translations_lenghts_length = $header['hash_addr'] - $header['translations_lenghts_addr']; |
| 214 | - if ( $translations_lenghts_length != $header['total'] * 8 ) { |
|
| 214 | + if ($translations_lenghts_length != $header['total'] * 8) { |
|
| 215 | 215 | return false; |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | $translations = $reader->read($translations_lenghts_length); |
| 219 | - if ( $reader->strlen( $translations ) != $translations_lenghts_length ) { |
|
| 219 | + if ($reader->strlen($translations) != $translations_lenghts_length) { |
|
| 220 | 220 | return false; |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | // transform raw data into set of indices |
| 224 | - $originals = $reader->str_split( $originals, 8 ); |
|
| 225 | - $translations = $reader->str_split( $translations, 8 ); |
|
| 224 | + $originals = $reader->str_split($originals, 8); |
|
| 225 | + $translations = $reader->str_split($translations, 8); |
|
| 226 | 226 | |
| 227 | 227 | // skip hash table |
| 228 | 228 | $strings_addr = $header['hash_addr'] + $header['hash_length'] * 4; |
@@ -232,17 +232,17 @@ discard block |
||
| 232 | 232 | $strings = $reader->read_all(); |
| 233 | 233 | $reader->close(); |
| 234 | 234 | |
| 235 | - for ( $i = 0; $i < $header['total']; $i++ ) { |
|
| 236 | - $o = unpack( "{$endian}length/{$endian}pos", $originals[$i] ); |
|
| 237 | - $t = unpack( "{$endian}length/{$endian}pos", $translations[$i] ); |
|
| 238 | - if ( !$o || !$t ) return false; |
|
| 235 | + for ($i = 0; $i < $header['total']; $i++) { |
|
| 236 | + $o = unpack("{$endian}length/{$endian}pos", $originals[$i]); |
|
| 237 | + $t = unpack("{$endian}length/{$endian}pos", $translations[$i]); |
|
| 238 | + if ( ! $o || ! $t) return false; |
|
| 239 | 239 | |
| 240 | 240 | // adjust offset due to reading strings to separate space before |
| 241 | 241 | $o['pos'] -= $strings_addr; |
| 242 | 242 | $t['pos'] -= $strings_addr; |
| 243 | 243 | |
| 244 | - $original = $reader->substr( $strings, $o['pos'], $o['length'] ); |
|
| 245 | - $translation = $reader->substr( $strings, $t['pos'], $t['length'] ); |
|
| 244 | + $original = $reader->substr($strings, $o['pos'], $o['length']); |
|
| 245 | + $translation = $reader->substr($strings, $t['pos'], $t['length']); |
|
| 246 | 246 | |
| 247 | 247 | if ('' === $original) { |
| 248 | 248 | $this->set_headers($this->make_headers($translation)); |
@@ -22,8 +22,9 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | function import_from_file($filename) { |
| 24 | 24 | $reader = new POMO_FileReader($filename); |
| 25 | - if (!$reader->is_resource()) |
|
| 26 | - return false; |
|
| 25 | + if (!$reader->is_resource()) { |
|
| 26 | + return false; |
|
| 27 | + } |
|
| 27 | 28 | return $this->import_from_reader($reader); |
| 28 | 29 | } |
| 29 | 30 | |
@@ -33,7 +34,9 @@ discard block |
||
| 33 | 34 | */ |
| 34 | 35 | function export_to_file($filename) { |
| 35 | 36 | $fh = fopen($filename, 'wb'); |
| 36 | - if ( !$fh ) return false; |
|
| 37 | + if ( !$fh ) { |
|
| 38 | + return false; |
|
| 39 | + } |
|
| 37 | 40 | $res = $this->export_to_file_handle( $fh ); |
| 38 | 41 | fclose($fh); |
| 39 | 42 | return $res; |
@@ -44,7 +47,9 @@ discard block |
||
| 44 | 47 | */ |
| 45 | 48 | function export() { |
| 46 | 49 | $tmp_fh = fopen("php://temp", 'r+'); |
| 47 | - if ( !$tmp_fh ) return false; |
|
| 50 | + if ( !$tmp_fh ) { |
|
| 51 | + return false; |
|
| 52 | + } |
|
| 48 | 53 | $this->export_to_file_handle( $tmp_fh ); |
| 49 | 54 | rewind( $tmp_fh ); |
| 50 | 55 | return stream_get_contents( $tmp_fh ); |
@@ -123,8 +128,12 @@ discard block |
||
| 123 | 128 | function export_original($entry) { |
| 124 | 129 | //TODO: warnings for control characters |
| 125 | 130 | $exported = $entry->singular; |
| 126 | - if ($entry->is_plural) $exported .= chr(0).$entry->plural; |
|
| 127 | - if (!is_null($entry->context)) $exported = $entry->context . chr(4) . $exported; |
|
| 131 | + if ($entry->is_plural) { |
|
| 132 | + $exported .= chr(0).$entry->plural; |
|
| 133 | + } |
|
| 134 | + if (!is_null($entry->context)) { |
|
| 135 | + $exported = $entry->context . chr(4) . $exported; |
|
| 136 | + } |
|
| 128 | 137 | return $exported; |
| 129 | 138 | } |
| 130 | 139 | |
@@ -182,13 +191,15 @@ discard block |
||
| 182 | 191 | $endian = ('big' == $endian_string)? 'N' : 'V'; |
| 183 | 192 | |
| 184 | 193 | $header = $reader->read(24); |
| 185 | - if ($reader->strlen($header) != 24) |
|
| 186 | - return false; |
|
| 194 | + if ($reader->strlen($header) != 24) { |
|
| 195 | + return false; |
|
| 196 | + } |
|
| 187 | 197 | |
| 188 | 198 | // parse header |
| 189 | 199 | $header = unpack("{$endian}revision/{$endian}total/{$endian}originals_lenghts_addr/{$endian}translations_lenghts_addr/{$endian}hash_length/{$endian}hash_addr", $header); |
| 190 | - if (!is_array($header)) |
|
| 191 | - return false; |
|
| 200 | + if (!is_array($header)) { |
|
| 201 | + return false; |
|
| 202 | + } |
|
| 192 | 203 | |
| 193 | 204 | // support revision 0 of MO format specs, only |
| 194 | 205 | if ( $header['revision'] != 0 ) { |
@@ -235,7 +246,9 @@ discard block |
||
| 235 | 246 | for ( $i = 0; $i < $header['total']; $i++ ) { |
| 236 | 247 | $o = unpack( "{$endian}length/{$endian}pos", $originals[$i] ); |
| 237 | 248 | $t = unpack( "{$endian}length/{$endian}pos", $translations[$i] ); |
| 238 | - if ( !$o || !$t ) return false; |
|
| 249 | + if ( !$o || !$t ) { |
|
| 250 | + return false; |
|
| 251 | + } |
|
| 239 | 252 | |
| 240 | 253 | // adjust offset due to reading strings to separate space before |
| 241 | 254 | $o['pos'] -= $strings_addr; |
@@ -85,6 +85,7 @@ discard block |
||
| 85 | 85 | * Text to include as a comment before the start of the PO contents |
| 86 | 86 | * |
| 87 | 87 | * Doesn't need to include # in the beginning of lines, these are added automatically |
| 88 | + * @param string $text |
|
| 88 | 89 | */ |
| 89 | 90 | function set_comment_before_headers( $text ) { |
| 90 | 91 | $this->comments_before_headers = $text; |
@@ -190,6 +191,7 @@ discard block |
||
| 190 | 191 | * |
| 191 | 192 | * @static |
| 192 | 193 | * @param Translation_Entry &$entry the entry to convert to po string |
| 194 | + * @param Translation_Entry $entry |
|
| 193 | 195 | * @return false|string PO-style formatted string for the entry or |
| 194 | 196 | * false if the entry is empty |
| 195 | 197 | */ |
@@ -358,7 +360,7 @@ discard block |
||
| 358 | 360 | * |
| 359 | 361 | * @param resource $f |
| 360 | 362 | * @param string $action |
| 361 | - * @return boolean |
|
| 363 | + * @return boolean|string |
|
| 362 | 364 | */ |
| 363 | 365 | function read_line($f, $action = 'read') { |
| 364 | 366 | static $last_line = ''; |
@@ -398,7 +400,7 @@ discard block |
||
| 398 | 400 | |
| 399 | 401 | /** |
| 400 | 402 | * @param string $s |
| 401 | - * @return sring |
|
| 403 | + * @return string |
|
| 402 | 404 | */ |
| 403 | 405 | function trim_quotes($s) { |
| 404 | 406 | if ( substr($s, 0, 1) == '"') $s = substr($s, 1); |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | * @subpackage po |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -require_once dirname(__FILE__) . '/translations.php'; |
|
| 10 | +require_once dirname(__FILE__).'/translations.php'; |
|
| 11 | 11 | |
| 12 | 12 | define('PO_MAX_LINE_LEN', 79); |
| 13 | 13 | |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | /** |
| 17 | 17 | * Routines for working with PO files |
| 18 | 18 | */ |
| 19 | -if ( !class_exists( 'PO' ) ): |
|
| 19 | +if ( ! class_exists('PO')): |
|
| 20 | 20 | class PO extends Gettext_Translations { |
| 21 | 21 | |
| 22 | 22 | var $comments_before_headers = ''; |
@@ -28,8 +28,8 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | function export_headers() { |
| 30 | 30 | $header_string = ''; |
| 31 | - foreach($this->headers as $header => $value) { |
|
| 32 | - $header_string.= "$header: $value\n"; |
|
| 31 | + foreach ($this->headers as $header => $value) { |
|
| 32 | + $header_string .= "$header: $value\n"; |
|
| 33 | 33 | } |
| 34 | 34 | $poified = PO::poify($header_string); |
| 35 | 35 | if ($this->comments_before_headers) |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | * |
| 87 | 87 | * Doesn't need to include # in the beginning of lines, these are added automatically |
| 88 | 88 | */ |
| 89 | - function set_comment_before_headers( $text ) { |
|
| 89 | + function set_comment_before_headers($text) { |
|
| 90 | 90 | $this->comments_before_headers = $text; |
| 91 | 91 | } |
| 92 | 92 | |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | $po = $quote.implode("${slash}n$quote$newline$quote", explode($newline, $string)).$quote; |
| 114 | 114 | // add empty string on first line for readbility |
| 115 | 115 | if (false !== strpos($string, $newline) && |
| 116 | - (substr_count($string, $newline) > 1 || !($newline === substr($string, -strlen($newline))))) { |
|
| 116 | + (substr_count($string, $newline) > 1 || ! ($newline === substr($string, -strlen($newline))))) { |
|
| 117 | 117 | $po = "$quote$quote$newline$po"; |
| 118 | 118 | } |
| 119 | 119 | // remove empty strings |
@@ -134,18 +134,18 @@ discard block |
||
| 134 | 134 | $lines = array_map(array('PO', 'trim_quotes'), $lines); |
| 135 | 135 | $unpoified = ''; |
| 136 | 136 | $previous_is_backslash = false; |
| 137 | - foreach($lines as $line) { |
|
| 137 | + foreach ($lines as $line) { |
|
| 138 | 138 | preg_match_all('/./u', $line, $chars); |
| 139 | 139 | $chars = $chars[0]; |
| 140 | - foreach($chars as $char) { |
|
| 141 | - if (!$previous_is_backslash) { |
|
| 140 | + foreach ($chars as $char) { |
|
| 141 | + if ( ! $previous_is_backslash) { |
|
| 142 | 142 | if ('\\' == $char) |
| 143 | 143 | $previous_is_backslash = true; |
| 144 | 144 | else |
| 145 | 145 | $unpoified .= $char; |
| 146 | 146 | } else { |
| 147 | 147 | $previous_is_backslash = false; |
| 148 | - $unpoified .= isset($escapes[$char])? $escapes[$char] : $char; |
|
| 148 | + $unpoified .= isset($escapes[$char]) ? $escapes[$char] : $char; |
|
| 149 | 149 | } |
| 150 | 150 | } |
| 151 | 151 | } |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | * @param string $char character to denote a special PO comment, |
| 181 | 181 | * like :, default is a space |
| 182 | 182 | */ |
| 183 | - function comment_block($text, $char=' ') { |
|
| 183 | + function comment_block($text, $char = ' ') { |
|
| 184 | 184 | $text = wordwrap($text, PO_MAX_LINE_LEN - 3); |
| 185 | 185 | return PO::prepend_each_line($text, "#$char "); |
| 186 | 186 | } |
@@ -196,19 +196,19 @@ discard block |
||
| 196 | 196 | function export_entry(&$entry) { |
| 197 | 197 | if (is_null($entry->singular)) return false; |
| 198 | 198 | $po = array(); |
| 199 | - if (!empty($entry->translator_comments)) $po[] = PO::comment_block($entry->translator_comments); |
|
| 200 | - if (!empty($entry->extracted_comments)) $po[] = PO::comment_block($entry->extracted_comments, '.'); |
|
| 201 | - if (!empty($entry->references)) $po[] = PO::comment_block(implode(' ', $entry->references), ':'); |
|
| 202 | - if (!empty($entry->flags)) $po[] = PO::comment_block(implode(", ", $entry->flags), ','); |
|
| 203 | - if (!is_null($entry->context)) $po[] = 'msgctxt '.PO::poify($entry->context); |
|
| 199 | + if ( ! empty($entry->translator_comments)) $po[] = PO::comment_block($entry->translator_comments); |
|
| 200 | + if ( ! empty($entry->extracted_comments)) $po[] = PO::comment_block($entry->extracted_comments, '.'); |
|
| 201 | + if ( ! empty($entry->references)) $po[] = PO::comment_block(implode(' ', $entry->references), ':'); |
|
| 202 | + if ( ! empty($entry->flags)) $po[] = PO::comment_block(implode(", ", $entry->flags), ','); |
|
| 203 | + if ( ! is_null($entry->context)) $po[] = 'msgctxt '.PO::poify($entry->context); |
|
| 204 | 204 | $po[] = 'msgid '.PO::poify($entry->singular); |
| 205 | - if (!$entry->is_plural) { |
|
| 206 | - $translation = empty($entry->translations)? '' : $entry->translations[0]; |
|
| 205 | + if ( ! $entry->is_plural) { |
|
| 206 | + $translation = empty($entry->translations) ? '' : $entry->translations[0]; |
|
| 207 | 207 | $po[] = 'msgstr '.PO::poify($translation); |
| 208 | 208 | } else { |
| 209 | 209 | $po[] = 'msgid_plural '.PO::poify($entry->plural); |
| 210 | - $translations = empty($entry->translations)? array('', '') : $entry->translations; |
|
| 211 | - foreach($translations as $i => $translation) { |
|
| 210 | + $translations = empty($entry->translations) ? array('', '') : $entry->translations; |
|
| 211 | + foreach ($translations as $i => $translation) { |
|
| 212 | 212 | $po[] = "msgstr[$i] ".PO::poify($translation); |
| 213 | 213 | } |
| 214 | 214 | } |
@@ -221,11 +221,11 @@ discard block |
||
| 221 | 221 | */ |
| 222 | 222 | function import_from_file($filename) { |
| 223 | 223 | $f = fopen($filename, 'r'); |
| 224 | - if (!$f) return false; |
|
| 224 | + if ( ! $f) return false; |
|
| 225 | 225 | $lineno = 0; |
| 226 | 226 | while (true) { |
| 227 | 227 | $res = $this->read_entry($f, $lineno); |
| 228 | - if (!$res) break; |
|
| 228 | + if ( ! $res) break; |
|
| 229 | 229 | if ($res['entry']->singular == '') { |
| 230 | 230 | $this->set_headers($this->make_headers($res['entry']->translations[0])); |
| 231 | 231 | } else { |
@@ -233,10 +233,10 @@ discard block |
||
| 233 | 233 | } |
| 234 | 234 | } |
| 235 | 235 | PO::read_line($f, 'clear'); |
| 236 | - if ( false === $res ) { |
|
| 236 | + if (false === $res) { |
|
| 237 | 237 | return false; |
| 238 | 238 | } |
| 239 | - if ( ! $this->headers && ! $this->entries ) { |
|
| 239 | + if ( ! $this->headers && ! $this->entries) { |
|
| 240 | 240 | return false; |
| 241 | 241 | } |
| 242 | 242 | return true; |
@@ -257,11 +257,11 @@ discard block |
||
| 257 | 257 | while (true) { |
| 258 | 258 | $lineno++; |
| 259 | 259 | $line = PO::read_line($f); |
| 260 | - if (!$line) { |
|
| 260 | + if ( ! $line) { |
|
| 261 | 261 | if (feof($f)) { |
| 262 | 262 | if ($is_final($context)) |
| 263 | 263 | break; |
| 264 | - elseif (!$context) // we haven't read a line and eof came |
|
| 264 | + elseif ( ! $context) // we haven't read a line and eof came |
|
| 265 | 265 | return null; |
| 266 | 266 | else |
| 267 | 267 | return false; |
@@ -371,8 +371,8 @@ discard block |
||
| 371 | 371 | $use_last_line = true; |
| 372 | 372 | return true; |
| 373 | 373 | } |
| 374 | - $line = $use_last_line? $last_line : fgets($f); |
|
| 375 | - $line = ( "\r\n" == substr( $line, -2 ) ) ? rtrim( $line, "\r\n" ) . "\n" : $line; |
|
| 374 | + $line = $use_last_line ? $last_line : fgets($f); |
|
| 375 | + $line = ("\r\n" == substr($line, -2)) ? rtrim($line, "\r\n")."\n" : $line; |
|
| 376 | 376 | $last_line = $line; |
| 377 | 377 | $use_last_line = false; |
| 378 | 378 | return $line; |
@@ -388,11 +388,11 @@ discard block |
||
| 388 | 388 | if ('#:' == $first_two) { |
| 389 | 389 | $entry->references = array_merge($entry->references, preg_split('/\s+/', $comment)); |
| 390 | 390 | } elseif ('#.' == $first_two) { |
| 391 | - $entry->extracted_comments = trim($entry->extracted_comments . "\n" . $comment); |
|
| 391 | + $entry->extracted_comments = trim($entry->extracted_comments."\n".$comment); |
|
| 392 | 392 | } elseif ('#,' == $first_two) { |
| 393 | 393 | $entry->flags = array_merge($entry->flags, preg_split('/,\s*/', $comment)); |
| 394 | 394 | } else { |
| 395 | - $entry->translator_comments = trim($entry->translator_comments . "\n" . $comment); |
|
| 395 | + $entry->translator_comments = trim($entry->translator_comments."\n".$comment); |
|
| 396 | 396 | } |
| 397 | 397 | } |
| 398 | 398 | |
@@ -401,8 +401,8 @@ discard block |
||
| 401 | 401 | * @return sring |
| 402 | 402 | */ |
| 403 | 403 | function trim_quotes($s) { |
| 404 | - if ( substr($s, 0, 1) == '"') $s = substr($s, 1); |
|
| 405 | - if ( substr($s, -1, 1) == '"') $s = substr($s, 0, -1); |
|
| 404 | + if (substr($s, 0, 1) == '"') $s = substr($s, 1); |
|
| 405 | + if (substr($s, -1, 1) == '"') $s = substr($s, 0, -1); |
|
| 406 | 406 | return $s; |
| 407 | 407 | } |
| 408 | 408 | } |
@@ -32,10 +32,11 @@ discard block |
||
| 32 | 32 | $header_string.= "$header: $value\n"; |
| 33 | 33 | } |
| 34 | 34 | $poified = PO::poify($header_string); |
| 35 | - if ($this->comments_before_headers) |
|
| 36 | - $before_headers = $this->prepend_each_line(rtrim($this->comments_before_headers)."\n", '# '); |
|
| 37 | - else |
|
| 38 | - $before_headers = ''; |
|
| 35 | + if ($this->comments_before_headers) { |
|
| 36 | + $before_headers = $this->prepend_each_line(rtrim($this->comments_before_headers)."\n", '# '); |
|
| 37 | + } else { |
|
| 38 | + $before_headers = ''; |
|
| 39 | + } |
|
| 39 | 40 | return rtrim("{$before_headers}msgid \"\"\nmsgstr $poified"); |
| 40 | 41 | } |
| 41 | 42 | |
@@ -74,10 +75,14 @@ discard block |
||
| 74 | 75 | */ |
| 75 | 76 | function export_to_file($filename, $include_headers = true) { |
| 76 | 77 | $fh = fopen($filename, 'w'); |
| 77 | - if (false === $fh) return false; |
|
| 78 | + if (false === $fh) { |
|
| 79 | + return false; |
|
| 80 | + } |
|
| 78 | 81 | $export = $this->export($include_headers); |
| 79 | 82 | $res = fwrite($fh, $export); |
| 80 | - if (false === $res) return false; |
|
| 83 | + if (false === $res) { |
|
| 84 | + return false; |
|
| 85 | + } |
|
| 81 | 86 | return fclose($fh); |
| 82 | 87 | } |
| 83 | 88 | |
@@ -139,10 +144,11 @@ discard block |
||
| 139 | 144 | $chars = $chars[0]; |
| 140 | 145 | foreach($chars as $char) { |
| 141 | 146 | if (!$previous_is_backslash) { |
| 142 | - if ('\\' == $char) |
|
| 143 | - $previous_is_backslash = true; |
|
| 144 | - else |
|
| 145 | - $unpoified .= $char; |
|
| 147 | + if ('\\' == $char) { |
|
| 148 | + $previous_is_backslash = true; |
|
| 149 | + } else { |
|
| 150 | + $unpoified .= $char; |
|
| 151 | + } |
|
| 146 | 152 | } else { |
| 147 | 153 | $previous_is_backslash = false; |
| 148 | 154 | $unpoified .= isset($escapes[$char])? $escapes[$char] : $char; |
@@ -164,10 +170,14 @@ discard block |
||
| 164 | 170 | $php_with = var_export($with, true); |
| 165 | 171 | $lines = explode("\n", $string); |
| 166 | 172 | // do not prepend the string on the last empty line, artefact by explode |
| 167 | - if ("\n" == substr($string, -1)) unset($lines[count($lines) - 1]); |
|
| 173 | + if ("\n" == substr($string, -1)) { |
|
| 174 | + unset($lines[count($lines) - 1]); |
|
| 175 | + } |
|
| 168 | 176 | $res = implode("\n", array_map(create_function('$x', "return $php_with.\$x;"), $lines)); |
| 169 | 177 | // give back the empty line, we ignored above |
| 170 | - if ("\n" == substr($string, -1)) $res .= "\n"; |
|
| 178 | + if ("\n" == substr($string, -1)) { |
|
| 179 | + $res .= "\n"; |
|
| 180 | + } |
|
| 171 | 181 | return $res; |
| 172 | 182 | } |
| 173 | 183 | |
@@ -194,13 +204,25 @@ discard block |
||
| 194 | 204 | * false if the entry is empty |
| 195 | 205 | */ |
| 196 | 206 | function export_entry(&$entry) { |
| 197 | - if (is_null($entry->singular)) return false; |
|
| 207 | + if (is_null($entry->singular)) { |
|
| 208 | + return false; |
|
| 209 | + } |
|
| 198 | 210 | $po = array(); |
| 199 | - if (!empty($entry->translator_comments)) $po[] = PO::comment_block($entry->translator_comments); |
|
| 200 | - if (!empty($entry->extracted_comments)) $po[] = PO::comment_block($entry->extracted_comments, '.'); |
|
| 201 | - if (!empty($entry->references)) $po[] = PO::comment_block(implode(' ', $entry->references), ':'); |
|
| 202 | - if (!empty($entry->flags)) $po[] = PO::comment_block(implode(", ", $entry->flags), ','); |
|
| 203 | - if (!is_null($entry->context)) $po[] = 'msgctxt '.PO::poify($entry->context); |
|
| 211 | + if (!empty($entry->translator_comments)) { |
|
| 212 | + $po[] = PO::comment_block($entry->translator_comments); |
|
| 213 | + } |
|
| 214 | + if (!empty($entry->extracted_comments)) { |
|
| 215 | + $po[] = PO::comment_block($entry->extracted_comments, '.'); |
|
| 216 | + } |
|
| 217 | + if (!empty($entry->references)) { |
|
| 218 | + $po[] = PO::comment_block(implode(' ', $entry->references), ':'); |
|
| 219 | + } |
|
| 220 | + if (!empty($entry->flags)) { |
|
| 221 | + $po[] = PO::comment_block(implode(", ", $entry->flags), ','); |
|
| 222 | + } |
|
| 223 | + if (!is_null($entry->context)) { |
|
| 224 | + $po[] = 'msgctxt '.PO::poify($entry->context); |
|
| 225 | + } |
|
| 204 | 226 | $po[] = 'msgid '.PO::poify($entry->singular); |
| 205 | 227 | if (!$entry->is_plural) { |
| 206 | 228 | $translation = empty($entry->translations)? '' : $entry->translations[0]; |
@@ -221,11 +243,15 @@ discard block |
||
| 221 | 243 | */ |
| 222 | 244 | function import_from_file($filename) { |
| 223 | 245 | $f = fopen($filename, 'r'); |
| 224 | - if (!$f) return false; |
|
| 246 | + if (!$f) { |
|
| 247 | + return false; |
|
| 248 | + } |
|
| 225 | 249 | $lineno = 0; |
| 226 | 250 | while (true) { |
| 227 | 251 | $res = $this->read_entry($f, $lineno); |
| 228 | - if (!$res) break; |
|
| 252 | + if (!$res) { |
|
| 253 | + break; |
|
| 254 | + } |
|
| 229 | 255 | if ($res['entry']->singular == '') { |
| 230 | 256 | $this->set_headers($this->make_headers($res['entry']->translations[0])); |
| 231 | 257 | } else { |
@@ -259,17 +285,21 @@ discard block |
||
| 259 | 285 | $line = PO::read_line($f); |
| 260 | 286 | if (!$line) { |
| 261 | 287 | if (feof($f)) { |
| 262 | - if ($is_final($context)) |
|
| 263 | - break; |
|
| 264 | - elseif (!$context) // we haven't read a line and eof came |
|
| 288 | + if ($is_final($context)) { |
|
| 289 | + break; |
|
| 290 | + } elseif (!$context) { |
|
| 291 | + // we haven't read a line and eof came |
|
| 265 | 292 | return null; |
| 266 | - else |
|
| 267 | - return false; |
|
| 293 | + } else { |
|
| 294 | + return false; |
|
| 295 | + } |
|
| 268 | 296 | } else { |
| 269 | 297 | return false; |
| 270 | 298 | } |
| 271 | 299 | } |
| 272 | - if ($line == "\n") continue; |
|
| 300 | + if ($line == "\n") { |
|
| 301 | + continue; |
|
| 302 | + } |
|
| 273 | 303 | $line = trim($line); |
| 274 | 304 | if (preg_match('/^#/', $line, $m)) { |
| 275 | 305 | // the comment is the start of a new entry |
@@ -401,8 +431,12 @@ discard block |
||
| 401 | 431 | * @return sring |
| 402 | 432 | */ |
| 403 | 433 | function trim_quotes($s) { |
| 404 | - if ( substr($s, 0, 1) == '"') $s = substr($s, 1); |
|
| 405 | - if ( substr($s, -1, 1) == '"') $s = substr($s, 0, -1); |
|
| 434 | + if ( substr($s, 0, 1) == '"') { |
|
| 435 | + $s = substr($s, 1); |
|
| 436 | + } |
|
| 437 | + if ( substr($s, -1, 1) == '"') { |
|
| 438 | + $s = substr($s, 0, -1); |
|
| 439 | + } |
|
| 406 | 440 | return $s; |
| 407 | 441 | } |
| 408 | 442 | } |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | /** |
| 33 | 33 | * Sets the endianness of the file. |
| 34 | 34 | * |
| 35 | - * @param $endian string 'big' or 'little' |
|
| 35 | + * @param string $endian string 'big' or 'little' |
|
| 36 | 36 | */ |
| 37 | 37 | function setEndian($endian) { |
| 38 | 38 | $this->endian = $endian; |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | /** |
| 42 | 42 | * Reads a 32bit Integer from the Stream |
| 43 | 43 | * |
| 44 | - * @return mixed The integer, corresponding to the next 32 bits from |
|
| 44 | + * @return integer The integer, corresponding to the next 32 bits from |
|
| 45 | 45 | * the stream of false if there are not enough bytes or on error |
| 46 | 46 | */ |
| 47 | 47 | function readint32() { |
@@ -119,14 +119,14 @@ discard block |
||
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
| 122 | - * @return true |
|
| 122 | + * @return boolean |
|
| 123 | 123 | */ |
| 124 | 124 | function is_resource() { |
| 125 | 125 | return true; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | /** |
| 129 | - * @return true |
|
| 129 | + * @return boolean |
|
| 130 | 130 | */ |
| 131 | 131 | function close() { |
| 132 | 132 | return true; |
@@ -1,12 +1,12 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Classes, which help reading streams of data from files. |
|
| 4 | - * Based on the classes from Danilo Segan <[email protected]> |
|
| 5 | - * |
|
| 6 | - * @version $Id: streams.php 718 2012-10-31 00:32:02Z nbachiyski $ |
|
| 7 | - * @package pomo |
|
| 8 | - * @subpackage streams |
|
| 9 | - */ |
|
| 3 | + * Classes, which help reading streams of data from files. |
|
| 4 | + * Based on the classes from Danilo Segan <[email protected]> |
|
| 5 | + * |
|
| 6 | + * @version $Id: streams.php 718 2012-10-31 00:32:02Z nbachiyski $ |
|
| 7 | + * @package pomo |
|
| 8 | + * @subpackage streams |
|
| 9 | + */ |
|
| 10 | 10 | |
| 11 | 11 | if ( !class_exists( 'POMO_Reader' ) ): |
| 12 | 12 | class POMO_Reader { |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | * @subpackage streams |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -if ( !class_exists( 'POMO_Reader' ) ): |
|
| 11 | +if ( ! class_exists('POMO_Reader')): |
|
| 12 | 12 | class POMO_Reader { |
| 13 | 13 | |
| 14 | 14 | var $endian = 'little'; |
@@ -48,9 +48,9 @@ discard block |
||
| 48 | 48 | $bytes = $this->read(4); |
| 49 | 49 | if (4 != $this->strlen($bytes)) |
| 50 | 50 | return false; |
| 51 | - $endian_letter = ('big' == $this->endian)? 'N' : 'V'; |
|
| 51 | + $endian_letter = ('big' == $this->endian) ? 'N' : 'V'; |
|
| 52 | 52 | $int = unpack($endian_letter, $bytes); |
| 53 | - return reset( $int ); |
|
| 53 | + return reset($int); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -62,9 +62,9 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | function readint32array($count) { |
| 64 | 64 | $bytes = $this->read(4 * $count); |
| 65 | - if (4*$count != $this->strlen($bytes)) |
|
| 65 | + if (4 * $count != $this->strlen($bytes)) |
|
| 66 | 66 | return false; |
| 67 | - $endian_letter = ('big' == $this->endian)? 'N' : 'V'; |
|
| 67 | + $endian_letter = ('big' == $this->endian) ? 'N' : 'V'; |
|
| 68 | 68 | return unpack($endian_letter.$count, $bytes); |
| 69 | 69 | } |
| 70 | 70 | |
@@ -100,14 +100,14 @@ discard block |
||
| 100 | 100 | * @return array |
| 101 | 101 | */ |
| 102 | 102 | function str_split($string, $chunk_size) { |
| 103 | - if (!function_exists('str_split')) { |
|
| 103 | + if ( ! function_exists('str_split')) { |
|
| 104 | 104 | $length = $this->strlen($string); |
| 105 | 105 | $out = array(); |
| 106 | 106 | for ($i = 0; $i < $length; $i += $chunk_size) |
| 107 | 107 | $out[] = $this->substr($string, $i, $chunk_size); |
| 108 | 108 | return $out; |
| 109 | 109 | } else { |
| 110 | - return str_split( $string, $chunk_size ); |
|
| 110 | + return str_split($string, $chunk_size); |
|
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | |
@@ -134,13 +134,13 @@ discard block |
||
| 134 | 134 | } |
| 135 | 135 | endif; |
| 136 | 136 | |
| 137 | -if ( !class_exists( 'POMO_FileReader' ) ): |
|
| 137 | +if ( ! class_exists('POMO_FileReader')): |
|
| 138 | 138 | class POMO_FileReader extends POMO_Reader { |
| 139 | 139 | |
| 140 | 140 | /** |
| 141 | 141 | * @param string $filename |
| 142 | 142 | */ |
| 143 | - function __construct( $filename ) { |
|
| 143 | + function __construct($filename) { |
|
| 144 | 144 | parent::POMO_Reader(); |
| 145 | 145 | $this->_f = fopen($filename, 'rb'); |
| 146 | 146 | } |
@@ -148,8 +148,8 @@ discard block |
||
| 148 | 148 | /** |
| 149 | 149 | * PHP4 constructor. |
| 150 | 150 | */ |
| 151 | - public function POMO_FileReader( $filename ) { |
|
| 152 | - self::__construct( $filename ); |
|
| 151 | + public function POMO_FileReader($filename) { |
|
| 152 | + self::__construct($filename); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
@@ -197,14 +197,14 @@ discard block |
||
| 197 | 197 | */ |
| 198 | 198 | function read_all() { |
| 199 | 199 | $all = ''; |
| 200 | - while ( !$this->feof() ) |
|
| 200 | + while ( ! $this->feof()) |
|
| 201 | 201 | $all .= $this->read(4096); |
| 202 | 202 | return $all; |
| 203 | 203 | } |
| 204 | 204 | } |
| 205 | 205 | endif; |
| 206 | 206 | |
| 207 | -if ( !class_exists( 'POMO_StringReader' ) ): |
|
| 207 | +if ( ! class_exists('POMO_StringReader')): |
|
| 208 | 208 | /** |
| 209 | 209 | * Provides file-like methods for manipulating a string instead |
| 210 | 210 | * of a physical file. |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | /** |
| 217 | 217 | * PHP5 constructor. |
| 218 | 218 | */ |
| 219 | - function __construct( $str = '' ) { |
|
| 219 | + function __construct($str = '') { |
|
| 220 | 220 | parent::POMO_Reader(); |
| 221 | 221 | $this->_str = $str; |
| 222 | 222 | $this->_pos = 0; |
@@ -225,8 +225,8 @@ discard block |
||
| 225 | 225 | /** |
| 226 | 226 | * PHP4 constructor. |
| 227 | 227 | */ |
| 228 | - public function POMO_StringReader( $str = '' ) { |
|
| 229 | - self::__construct( $str ); |
|
| 228 | + public function POMO_StringReader($str = '') { |
|
| 229 | + self::__construct($str); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | } |
| 268 | 268 | endif; |
| 269 | 269 | |
| 270 | -if ( !class_exists( 'POMO_CachedFileReader' ) ): |
|
| 270 | +if ( ! class_exists('POMO_CachedFileReader')): |
|
| 271 | 271 | /** |
| 272 | 272 | * Reads the contents of the file in the beginning. |
| 273 | 273 | */ |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | /** |
| 276 | 276 | * PHP5 constructor. |
| 277 | 277 | */ |
| 278 | - function __construct( $filename ) { |
|
| 278 | + function __construct($filename) { |
|
| 279 | 279 | parent::POMO_StringReader(); |
| 280 | 280 | $this->_str = file_get_contents($filename); |
| 281 | 281 | if (false === $this->_str) |
@@ -286,13 +286,13 @@ discard block |
||
| 286 | 286 | /** |
| 287 | 287 | * PHP4 constructor. |
| 288 | 288 | */ |
| 289 | - public function POMO_CachedFileReader( $filename ) { |
|
| 290 | - self::__construct( $filename ); |
|
| 289 | + public function POMO_CachedFileReader($filename) { |
|
| 290 | + self::__construct($filename); |
|
| 291 | 291 | } |
| 292 | 292 | } |
| 293 | 293 | endif; |
| 294 | 294 | |
| 295 | -if ( !class_exists( 'POMO_CachedIntFileReader' ) ): |
|
| 295 | +if ( ! class_exists('POMO_CachedIntFileReader')): |
|
| 296 | 296 | /** |
| 297 | 297 | * Reads the contents of the file in the beginning. |
| 298 | 298 | */ |
@@ -300,15 +300,15 @@ discard block |
||
| 300 | 300 | /** |
| 301 | 301 | * PHP5 constructor. |
| 302 | 302 | */ |
| 303 | - public function __construct( $filename ) { |
|
| 303 | + public function __construct($filename) { |
|
| 304 | 304 | parent::POMO_CachedFileReader($filename); |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /** |
| 308 | 308 | * PHP4 constructor. |
| 309 | 309 | */ |
| 310 | - function POMO_CachedIntFileReader( $filename ) { |
|
| 311 | - self::__construct( $filename ); |
|
| 310 | + function POMO_CachedIntFileReader($filename) { |
|
| 311 | + self::__construct($filename); |
|
| 312 | 312 | } |
| 313 | 313 | } |
| 314 | 314 | endif; |
@@ -46,8 +46,9 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | function readint32() { |
| 48 | 48 | $bytes = $this->read(4); |
| 49 | - if (4 != $this->strlen($bytes)) |
|
| 50 | - return false; |
|
| 49 | + if (4 != $this->strlen($bytes)) { |
|
| 50 | + return false; |
|
| 51 | + } |
|
| 51 | 52 | $endian_letter = ('big' == $this->endian)? 'N' : 'V'; |
| 52 | 53 | $int = unpack($endian_letter, $bytes); |
| 53 | 54 | return reset( $int ); |
@@ -62,8 +63,9 @@ discard block |
||
| 62 | 63 | */ |
| 63 | 64 | function readint32array($count) { |
| 64 | 65 | $bytes = $this->read(4 * $count); |
| 65 | - if (4*$count != $this->strlen($bytes)) |
|
| 66 | - return false; |
|
| 66 | + if (4*$count != $this->strlen($bytes)) { |
|
| 67 | + return false; |
|
| 68 | + } |
|
| 67 | 69 | $endian_letter = ('big' == $this->endian)? 'N' : 'V'; |
| 68 | 70 | return unpack($endian_letter.$count, $bytes); |
| 69 | 71 | } |
@@ -103,8 +105,9 @@ discard block |
||
| 103 | 105 | if (!function_exists('str_split')) { |
| 104 | 106 | $length = $this->strlen($string); |
| 105 | 107 | $out = array(); |
| 106 | - for ($i = 0; $i < $length; $i += $chunk_size) |
|
| 107 | - $out[] = $this->substr($string, $i, $chunk_size); |
|
| 108 | + for ($i = 0; $i < $length; $i += $chunk_size) { |
|
| 109 | + $out[] = $this->substr($string, $i, $chunk_size); |
|
| 110 | + } |
|
| 108 | 111 | return $out; |
| 109 | 112 | } else { |
| 110 | 113 | return str_split( $string, $chunk_size ); |
@@ -197,8 +200,9 @@ discard block |
||
| 197 | 200 | */ |
| 198 | 201 | function read_all() { |
| 199 | 202 | $all = ''; |
| 200 | - while ( !$this->feof() ) |
|
| 201 | - $all .= $this->read(4096); |
|
| 203 | + while ( !$this->feof() ) { |
|
| 204 | + $all .= $this->read(4096); |
|
| 205 | + } |
|
| 202 | 206 | return $all; |
| 203 | 207 | } |
| 204 | 208 | } |
@@ -236,7 +240,9 @@ discard block |
||
| 236 | 240 | function read($bytes) { |
| 237 | 241 | $data = $this->substr($this->_str, $this->_pos, $bytes); |
| 238 | 242 | $this->_pos += $bytes; |
| 239 | - if ($this->strlen($this->_str) < $this->_pos) $this->_pos = $this->strlen($this->_str); |
|
| 243 | + if ($this->strlen($this->_str) < $this->_pos) { |
|
| 244 | + $this->_pos = $this->strlen($this->_str); |
|
| 245 | + } |
|
| 240 | 246 | return $data; |
| 241 | 247 | } |
| 242 | 248 | |
@@ -246,7 +252,9 @@ discard block |
||
| 246 | 252 | */ |
| 247 | 253 | function seekto($pos) { |
| 248 | 254 | $this->_pos = $pos; |
| 249 | - if ($this->strlen($this->_str) < $this->_pos) $this->_pos = $this->strlen($this->_str); |
|
| 255 | + if ($this->strlen($this->_str) < $this->_pos) { |
|
| 256 | + $this->_pos = $this->strlen($this->_str); |
|
| 257 | + } |
|
| 250 | 258 | return $this->_pos; |
| 251 | 259 | } |
| 252 | 260 | |
@@ -278,8 +286,9 @@ discard block |
||
| 278 | 286 | function __construct( $filename ) { |
| 279 | 287 | parent::POMO_StringReader(); |
| 280 | 288 | $this->_str = file_get_contents($filename); |
| 281 | - if (false === $this->_str) |
|
| 282 | - return false; |
|
| 289 | + if (false === $this->_str) { |
|
| 290 | + return false; |
|
| 291 | + } |
|
| 283 | 292 | $this->_pos = 0; |
| 284 | 293 | } |
| 285 | 294 | |
@@ -18,6 +18,7 @@ discard block |
||
| 18 | 18 | * Add entry to the PO structure |
| 19 | 19 | * |
| 20 | 20 | * @param array|Translation_Entry &$entry |
| 21 | + * @param Translation_Entry $entry |
|
| 21 | 22 | * @return bool true on success, false if the entry doesn't have a key |
| 22 | 23 | */ |
| 23 | 24 | function add_entry($entry) { |
@@ -72,6 +73,7 @@ discard block |
||
| 72 | 73 | |
| 73 | 74 | /** |
| 74 | 75 | * @param string $header |
| 76 | + * @return string |
|
| 75 | 77 | */ |
| 76 | 78 | function get_header($header) { |
| 77 | 79 | return isset($this->headers[$header])? $this->headers[$header] : false; |
@@ -150,7 +152,7 @@ discard block |
||
| 150 | 152 | } |
| 151 | 153 | |
| 152 | 154 | /** |
| 153 | - * @param object $other |
|
| 155 | + * @param Translations $other |
|
| 154 | 156 | */ |
| 155 | 157 | function merge_originals_with(&$other) { |
| 156 | 158 | foreach( $other->entries as $entry ) { |
@@ -326,7 +328,7 @@ discard block |
||
| 326 | 328 | /** |
| 327 | 329 | * |
| 328 | 330 | * @param int $count |
| 329 | - * @return bool |
|
| 331 | + * @return integer |
|
| 330 | 332 | */ |
| 331 | 333 | function select_plural_form($count) { |
| 332 | 334 | return 1 == $count? 0 : 1; |
@@ -7,9 +7,9 @@ discard block |
||
| 7 | 7 | * @subpackage translations |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -require_once dirname(__FILE__) . '/entry.php'; |
|
| 10 | +require_once dirname(__FILE__).'/entry.php'; |
|
| 11 | 11 | |
| 12 | -if ( !class_exists( 'Translations' ) ): |
|
| 12 | +if ( ! class_exists('Translations')): |
|
| 13 | 13 | class Translations { |
| 14 | 14 | var $entries = array(); |
| 15 | 15 | var $headers = array(); |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | * @param array $headers |
| 66 | 66 | */ |
| 67 | 67 | function set_headers($headers) { |
| 68 | - foreach($headers as $header => $value) { |
|
| 68 | + foreach ($headers as $header => $value) { |
|
| 69 | 69 | $this->set_header($header, $value); |
| 70 | 70 | } |
| 71 | 71 | } |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | * @param string $header |
| 75 | 75 | */ |
| 76 | 76 | function get_header($header) { |
| 77 | - return isset($this->headers[$header])? $this->headers[$header] : false; |
|
| 77 | + return isset($this->headers[$header]) ? $this->headers[$header] : false; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | function translate_entry(&$entry) { |
| 84 | 84 | $key = $entry->key(); |
| 85 | - return isset($this->entries[$key])? $this->entries[$key] : false; |
|
| 85 | + return isset($this->entries[$key]) ? $this->entries[$key] : false; |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
@@ -90,10 +90,10 @@ discard block |
||
| 90 | 90 | * @param string $context |
| 91 | 91 | * @return string |
| 92 | 92 | */ |
| 93 | - function translate($singular, $context=null) { |
|
| 93 | + function translate($singular, $context = null) { |
|
| 94 | 94 | $entry = new Translation_Entry(array('singular' => $singular, 'context' => $context)); |
| 95 | 95 | $translated = $this->translate_entry($entry); |
| 96 | - return ($translated && !empty($translated->translations))? $translated->translations[0] : $singular; |
|
| 96 | + return ($translated && ! empty($translated->translations)) ? $translated->translations[0] : $singular; |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | /** |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | * @param integer $count number of items |
| 109 | 109 | */ |
| 110 | 110 | function select_plural_form($count) { |
| 111 | - return 1 == $count? 0 : 1; |
|
| 111 | + return 1 == $count ? 0 : 1; |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | isset($translated->translations[$index])) |
| 135 | 135 | return $translated->translations[$index]; |
| 136 | 136 | else |
| 137 | - return 1 == $count? $singular : $plural; |
|
| 137 | + return 1 == $count ? $singular : $plural; |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * @return void |
| 145 | 145 | **/ |
| 146 | 146 | function merge_with(&$other) { |
| 147 | - foreach( $other->entries as $entry ) { |
|
| 147 | + foreach ($other->entries as $entry) { |
|
| 148 | 148 | $this->entries[$entry->key()] = $entry; |
| 149 | 149 | } |
| 150 | 150 | } |
@@ -153,8 +153,8 @@ discard block |
||
| 153 | 153 | * @param object $other |
| 154 | 154 | */ |
| 155 | 155 | function merge_originals_with(&$other) { |
| 156 | - foreach( $other->entries as $entry ) { |
|
| 157 | - if ( !isset( $this->entries[$entry->key()] ) ) |
|
| 156 | + foreach ($other->entries as $entry) { |
|
| 157 | + if ( ! isset($this->entries[$entry->key()])) |
|
| 158 | 158 | $this->entries[$entry->key()] = $entry; |
| 159 | 159 | else |
| 160 | 160 | $this->entries[$entry->key()]->merge_with($entry); |
@@ -172,8 +172,8 @@ discard block |
||
| 172 | 172 | * @param int $count |
| 173 | 173 | */ |
| 174 | 174 | function gettext_select_plural_form($count) { |
| 175 | - if (!isset($this->_gettext_select_plural_form) || is_null($this->_gettext_select_plural_form)) { |
|
| 176 | - list( $nplurals, $expression ) = $this->nplurals_and_expression_from_header($this->get_header('Plural-Forms')); |
|
| 175 | + if ( ! isset($this->_gettext_select_plural_form) || is_null($this->_gettext_select_plural_form)) { |
|
| 176 | + list($nplurals, $expression) = $this->nplurals_and_expression_from_header($this->get_header('Plural-Forms')); |
|
| 177 | 177 | $this->_nplurals = $nplurals; |
| 178 | 178 | $this->_gettext_select_plural_form = $this->make_plural_form_function($nplurals, $expression); |
| 179 | 179 | } |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | */ |
| 187 | 187 | function nplurals_and_expression_from_header($header) { |
| 188 | 188 | if (preg_match('/^\s*nplurals\s*=\s*(\d+)\s*;\s+plural\s*=\s*(.+)$/', $header, $matches)) { |
| 189 | - $nplurals = (int)$matches[1]; |
|
| 189 | + $nplurals = (int) $matches[1]; |
|
| 190 | 190 | $expression = trim($this->parenthesize_plural_exression($matches[2])); |
| 191 | 191 | return array($nplurals, $expression); |
| 192 | 192 | } else { |
@@ -230,8 +230,8 @@ discard block |
||
| 230 | 230 | $res .= ') : ('; |
| 231 | 231 | break; |
| 232 | 232 | case ';': |
| 233 | - $res .= str_repeat(')', $depth) . ';'; |
|
| 234 | - $depth= 0; |
|
| 233 | + $res .= str_repeat(')', $depth).';'; |
|
| 234 | + $depth = 0; |
|
| 235 | 235 | break; |
| 236 | 236 | default: |
| 237 | 237 | $res .= $char; |
@@ -249,9 +249,9 @@ discard block |
||
| 249 | 249 | // sometimes \ns are used instead of real new lines |
| 250 | 250 | $translation = str_replace('\n', "\n", $translation); |
| 251 | 251 | $lines = explode("\n", $translation); |
| 252 | - foreach($lines as $line) { |
|
| 252 | + foreach ($lines as $line) { |
|
| 253 | 253 | $parts = explode(':', $line, 2); |
| 254 | - if (!isset($parts[1])) continue; |
|
| 254 | + if ( ! isset($parts[1])) continue; |
|
| 255 | 255 | $headers[trim($parts[0])] = trim($parts[1]); |
| 256 | 256 | } |
| 257 | 257 | return $headers; |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | function set_header($header, $value) { |
| 265 | 265 | parent::set_header($header, $value); |
| 266 | 266 | if ('Plural-Forms' == $header) { |
| 267 | - list( $nplurals, $expression ) = $this->nplurals_and_expression_from_header($this->get_header('Plural-Forms')); |
|
| 267 | + list($nplurals, $expression) = $this->nplurals_and_expression_from_header($this->get_header('Plural-Forms')); |
|
| 268 | 268 | $this->_nplurals = $nplurals; |
| 269 | 269 | $this->_gettext_select_plural_form = $this->make_plural_form_function($nplurals, $expression); |
| 270 | 270 | } |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | } |
| 273 | 273 | endif; |
| 274 | 274 | |
| 275 | -if ( !class_exists( 'NOOP_Translations' ) ): |
|
| 275 | +if ( ! class_exists('NOOP_Translations')): |
|
| 276 | 276 | /** |
| 277 | 277 | * Provides the same interface as Translations, but doesn't do anything |
| 278 | 278 | */ |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | * @param string $singular |
| 320 | 320 | * @param string $context |
| 321 | 321 | */ |
| 322 | - function translate($singular, $context=null) { |
|
| 322 | + function translate($singular, $context = null) { |
|
| 323 | 323 | return $singular; |
| 324 | 324 | } |
| 325 | 325 | |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | * @return bool |
| 330 | 330 | */ |
| 331 | 331 | function select_plural_form($count) { |
| 332 | - return 1 == $count? 0 : 1; |
|
| 332 | + return 1 == $count ? 0 : 1; |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | /** |
@@ -346,7 +346,7 @@ discard block |
||
| 346 | 346 | * @param string $context |
| 347 | 347 | */ |
| 348 | 348 | function translate_plural($singular, $plural, $count, $context = null) { |
| 349 | - return 1 == $count? $singular : $plural; |
|
| 349 | + return 1 == $count ? $singular : $plural; |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | /** |
@@ -25,7 +25,9 @@ discard block |
||
| 25 | 25 | $entry = new Translation_Entry($entry); |
| 26 | 26 | } |
| 27 | 27 | $key = $entry->key(); |
| 28 | - if (false === $key) return false; |
|
| 28 | + if (false === $key) { |
|
| 29 | + return false; |
|
| 30 | + } |
|
| 29 | 31 | $this->entries[$key] = &$entry; |
| 30 | 32 | return true; |
| 31 | 33 | } |
@@ -39,11 +41,14 @@ discard block |
||
| 39 | 41 | $entry = new Translation_Entry($entry); |
| 40 | 42 | } |
| 41 | 43 | $key = $entry->key(); |
| 42 | - if (false === $key) return false; |
|
| 43 | - if (isset($this->entries[$key])) |
|
| 44 | - $this->entries[$key]->merge_with($entry); |
|
| 45 | - else |
|
| 46 | - $this->entries[$key] = &$entry; |
|
| 44 | + if (false === $key) { |
|
| 45 | + return false; |
|
| 46 | + } |
|
| 47 | + if (isset($this->entries[$key])) { |
|
| 48 | + $this->entries[$key]->merge_with($entry); |
|
| 49 | + } else { |
|
| 50 | + $this->entries[$key] = &$entry; |
|
| 51 | + } |
|
| 47 | 52 | return true; |
| 48 | 53 | } |
| 49 | 54 | |
@@ -131,10 +136,11 @@ discard block |
||
| 131 | 136 | $total_plural_forms = $this->get_plural_forms_count(); |
| 132 | 137 | if ($translated && 0 <= $index && $index < $total_plural_forms && |
| 133 | 138 | is_array($translated->translations) && |
| 134 | - isset($translated->translations[$index])) |
|
| 135 | - return $translated->translations[$index]; |
|
| 136 | - else |
|
| 137 | - return 1 == $count? $singular : $plural; |
|
| 139 | + isset($translated->translations[$index])) { |
|
| 140 | + return $translated->translations[$index]; |
|
| 141 | + } else { |
|
| 142 | + return 1 == $count? $singular : $plural; |
|
| 143 | + } |
|
| 138 | 144 | } |
| 139 | 145 | |
| 140 | 146 | /** |
@@ -154,10 +160,11 @@ discard block |
||
| 154 | 160 | */ |
| 155 | 161 | function merge_originals_with(&$other) { |
| 156 | 162 | foreach( $other->entries as $entry ) { |
| 157 | - if ( !isset( $this->entries[$entry->key()] ) ) |
|
| 158 | - $this->entries[$entry->key()] = $entry; |
|
| 159 | - else |
|
| 160 | - $this->entries[$entry->key()]->merge_with($entry); |
|
| 163 | + if ( !isset( $this->entries[$entry->key()] ) ) { |
|
| 164 | + $this->entries[$entry->key()] = $entry; |
|
| 165 | + } else { |
|
| 166 | + $this->entries[$entry->key()]->merge_with($entry); |
|
| 167 | + } |
|
| 161 | 168 | } |
| 162 | 169 | } |
| 163 | 170 | } |
@@ -251,7 +258,9 @@ discard block |
||
| 251 | 258 | $lines = explode("\n", $translation); |
| 252 | 259 | foreach($lines as $line) { |
| 253 | 260 | $parts = explode(':', $line, 2); |
| 254 | - if (!isset($parts[1])) continue; |
|
| 261 | + if (!isset($parts[1])) { |
|
| 262 | + continue; |
|
| 263 | + } |
|
| 255 | 264 | $headers[trim($parts[0])] = trim($parts[1]); |
| 256 | 265 | } |
| 257 | 266 | return $headers; |
@@ -135,7 +135,7 @@ |
||
| 135 | 135 | * @since 3.1.0 |
| 136 | 136 | * |
| 137 | 137 | * @param string $format The post format slug. |
| 138 | - * @return string|WP_Error|false The post format term link. |
|
| 138 | + * @return string The post format term link. |
|
| 139 | 139 | */ |
| 140 | 140 | function get_post_format_link( $format ) { |
| 141 | 141 | $term = get_term_by('slug', 'post-format-' . $format, 'post_format' ); |
@@ -1,10 +1,10 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Post format functions. |
|
| 4 | - * |
|
| 5 | - * @package WordPress |
|
| 6 | - * @subpackage Post |
|
| 7 | - */ |
|
| 3 | + * Post format functions. |
|
| 4 | + * |
|
| 5 | + * @package WordPress |
|
| 6 | + * @subpackage Post |
|
| 7 | + */ |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Retrieve the format slug for a post |
@@ -14,21 +14,21 @@ discard block |
||
| 14 | 14 | * @param int|object|null $post Post ID or post object. Optional, default is the current post from the loop. |
| 15 | 15 | * @return string|false The format if successful. False otherwise. |
| 16 | 16 | */ |
| 17 | -function get_post_format( $post = null ) { |
|
| 18 | - if ( ! $post = get_post( $post ) ) |
|
| 17 | +function get_post_format($post = null) { |
|
| 18 | + if ( ! $post = get_post($post)) |
|
| 19 | 19 | return false; |
| 20 | 20 | |
| 21 | - if ( ! post_type_supports( $post->post_type, 'post-formats' ) ) |
|
| 21 | + if ( ! post_type_supports($post->post_type, 'post-formats')) |
|
| 22 | 22 | return false; |
| 23 | 23 | |
| 24 | - $_format = get_the_terms( $post->ID, 'post_format' ); |
|
| 24 | + $_format = get_the_terms($post->ID, 'post_format'); |
|
| 25 | 25 | |
| 26 | - if ( empty( $_format ) ) |
|
| 26 | + if (empty($_format)) |
|
| 27 | 27 | return false; |
| 28 | 28 | |
| 29 | - $format = reset( $_format ); |
|
| 29 | + $format = reset($_format); |
|
| 30 | 30 | |
| 31 | - return str_replace('post-format-', '', $format->slug ); |
|
| 31 | + return str_replace('post-format-', '', $format->slug); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -40,16 +40,16 @@ discard block |
||
| 40 | 40 | * @param object|int|null $post Optional. The post to check. If not supplied, defaults to the current post if used in the loop. |
| 41 | 41 | * @return bool True if the post has any of the given formats (or any format, if no format specified), false otherwise. |
| 42 | 42 | */ |
| 43 | -function has_post_format( $format = array(), $post = null ) { |
|
| 43 | +function has_post_format($format = array(), $post = null) { |
|
| 44 | 44 | $prefixed = array(); |
| 45 | 45 | |
| 46 | - if ( $format ) { |
|
| 47 | - foreach ( (array) $format as $single ) { |
|
| 48 | - $prefixed[] = 'post-format-' . sanitize_key( $single ); |
|
| 46 | + if ($format) { |
|
| 47 | + foreach ((array) $format as $single) { |
|
| 48 | + $prefixed[] = 'post-format-'.sanitize_key($single); |
|
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - return has_term( $prefixed, 'post_format', $post ); |
|
| 52 | + return has_term($prefixed, 'post_format', $post); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** |
@@ -61,21 +61,21 @@ discard block |
||
| 61 | 61 | * @param string $format A format to assign. Use an empty string or array to remove all formats from the post. |
| 62 | 62 | * @return array|WP_Error|false WP_Error on error. Array of affected term IDs on success. |
| 63 | 63 | */ |
| 64 | -function set_post_format( $post, $format ) { |
|
| 65 | - $post = get_post( $post ); |
|
| 64 | +function set_post_format($post, $format) { |
|
| 65 | + $post = get_post($post); |
|
| 66 | 66 | |
| 67 | - if ( empty( $post ) ) |
|
| 68 | - return new WP_Error( 'invalid_post', __( 'Invalid post.' ) ); |
|
| 67 | + if (empty($post)) |
|
| 68 | + return new WP_Error('invalid_post', __('Invalid post.')); |
|
| 69 | 69 | |
| 70 | - if ( ! empty( $format ) ) { |
|
| 71 | - $format = sanitize_key( $format ); |
|
| 72 | - if ( 'standard' === $format || ! in_array( $format, get_post_format_slugs() ) ) |
|
| 70 | + if ( ! empty($format)) { |
|
| 71 | + $format = sanitize_key($format); |
|
| 72 | + if ('standard' === $format || ! in_array($format, get_post_format_slugs())) |
|
| 73 | 73 | $format = ''; |
| 74 | 74 | else |
| 75 | - $format = 'post-format-' . $format; |
|
| 75 | + $format = 'post-format-'.$format; |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - return wp_set_post_terms( $post->ID, $format, 'post_format' ); |
|
| 78 | + return wp_set_post_terms($post->ID, $format, 'post_format'); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -87,16 +87,16 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | function get_post_format_strings() { |
| 89 | 89 | $strings = array( |
| 90 | - 'standard' => _x( 'Standard', 'Post format' ), // Special case. any value that evals to false will be considered standard |
|
| 91 | - 'aside' => _x( 'Aside', 'Post format' ), |
|
| 92 | - 'chat' => _x( 'Chat', 'Post format' ), |
|
| 93 | - 'gallery' => _x( 'Gallery', 'Post format' ), |
|
| 94 | - 'link' => _x( 'Link', 'Post format' ), |
|
| 95 | - 'image' => _x( 'Image', 'Post format' ), |
|
| 96 | - 'quote' => _x( 'Quote', 'Post format' ), |
|
| 97 | - 'status' => _x( 'Status', 'Post format' ), |
|
| 98 | - 'video' => _x( 'Video', 'Post format' ), |
|
| 99 | - 'audio' => _x( 'Audio', 'Post format' ), |
|
| 90 | + 'standard' => _x('Standard', 'Post format'), // Special case. any value that evals to false will be considered standard |
|
| 91 | + 'aside' => _x('Aside', 'Post format'), |
|
| 92 | + 'chat' => _x('Chat', 'Post format'), |
|
| 93 | + 'gallery' => _x('Gallery', 'Post format'), |
|
| 94 | + 'link' => _x('Link', 'Post format'), |
|
| 95 | + 'image' => _x('Image', 'Post format'), |
|
| 96 | + 'quote' => _x('Quote', 'Post format'), |
|
| 97 | + 'status' => _x('Status', 'Post format'), |
|
| 98 | + 'video' => _x('Video', 'Post format'), |
|
| 99 | + 'audio' => _x('Audio', 'Post format'), |
|
| 100 | 100 | ); |
| 101 | 101 | return $strings; |
| 102 | 102 | } |
@@ -109,8 +109,8 @@ discard block |
||
| 109 | 109 | * @return array The array of post format slugs. |
| 110 | 110 | */ |
| 111 | 111 | function get_post_format_slugs() { |
| 112 | - $slugs = array_keys( get_post_format_strings() ); |
|
| 113 | - return array_combine( $slugs, $slugs ); |
|
| 112 | + $slugs = array_keys(get_post_format_strings()); |
|
| 113 | + return array_combine($slugs, $slugs); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -121,12 +121,12 @@ discard block |
||
| 121 | 121 | * @param string $slug A post format slug. |
| 122 | 122 | * @return string The translated post format name. |
| 123 | 123 | */ |
| 124 | -function get_post_format_string( $slug ) { |
|
| 124 | +function get_post_format_string($slug) { |
|
| 125 | 125 | $strings = get_post_format_strings(); |
| 126 | - if ( !$slug ) |
|
| 126 | + if ( ! $slug) |
|
| 127 | 127 | return $strings['standard']; |
| 128 | 128 | else |
| 129 | - return ( isset( $strings[$slug] ) ) ? $strings[$slug] : ''; |
|
| 129 | + return (isset($strings[$slug])) ? $strings[$slug] : ''; |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
@@ -137,11 +137,11 @@ discard block |
||
| 137 | 137 | * @param string $format The post format slug. |
| 138 | 138 | * @return string|WP_Error|false The post format term link. |
| 139 | 139 | */ |
| 140 | -function get_post_format_link( $format ) { |
|
| 141 | - $term = get_term_by('slug', 'post-format-' . $format, 'post_format' ); |
|
| 142 | - if ( ! $term || is_wp_error( $term ) ) |
|
| 140 | +function get_post_format_link($format) { |
|
| 141 | + $term = get_term_by('slug', 'post-format-'.$format, 'post_format'); |
|
| 142 | + if ( ! $term || is_wp_error($term)) |
|
| 143 | 143 | return false; |
| 144 | - return get_term_link( $term ); |
|
| 144 | + return get_term_link($term); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /** |
@@ -153,14 +153,14 @@ discard block |
||
| 153 | 153 | * @param array $qvs |
| 154 | 154 | * @return array |
| 155 | 155 | */ |
| 156 | -function _post_format_request( $qvs ) { |
|
| 157 | - if ( ! isset( $qvs['post_format'] ) ) |
|
| 156 | +function _post_format_request($qvs) { |
|
| 157 | + if ( ! isset($qvs['post_format'])) |
|
| 158 | 158 | return $qvs; |
| 159 | 159 | $slugs = get_post_format_slugs(); |
| 160 | - if ( isset( $slugs[ $qvs['post_format'] ] ) ) |
|
| 161 | - $qvs['post_format'] = 'post-format-' . $slugs[ $qvs['post_format'] ]; |
|
| 162 | - $tax = get_taxonomy( 'post_format' ); |
|
| 163 | - if ( ! is_admin() ) |
|
| 160 | + if (isset($slugs[$qvs['post_format']])) |
|
| 161 | + $qvs['post_format'] = 'post-format-'.$slugs[$qvs['post_format']]; |
|
| 162 | + $tax = get_taxonomy('post_format'); |
|
| 163 | + if ( ! is_admin()) |
|
| 164 | 164 | $qvs['post_type'] = $tax->object_type; |
| 165 | 165 | return $qvs; |
| 166 | 166 | } |
@@ -178,16 +178,16 @@ discard block |
||
| 178 | 178 | * @param string $taxonomy |
| 179 | 179 | * @return string |
| 180 | 180 | */ |
| 181 | -function _post_format_link( $link, $term, $taxonomy ) { |
|
| 181 | +function _post_format_link($link, $term, $taxonomy) { |
|
| 182 | 182 | global $wp_rewrite; |
| 183 | - if ( 'post_format' != $taxonomy ) { |
|
| 183 | + if ('post_format' != $taxonomy) { |
|
| 184 | 184 | return $link; |
| 185 | 185 | } |
| 186 | - if ( $wp_rewrite->get_extra_permastruct( $taxonomy ) ) { |
|
| 187 | - return str_replace( "/{$term->slug}", '/' . str_replace( 'post-format-', '', $term->slug ), $link ); |
|
| 186 | + if ($wp_rewrite->get_extra_permastruct($taxonomy)) { |
|
| 187 | + return str_replace("/{$term->slug}", '/'.str_replace('post-format-', '', $term->slug), $link); |
|
| 188 | 188 | } else { |
| 189 | - $link = remove_query_arg( 'post_format', $link ); |
|
| 190 | - return add_query_arg( 'post_format', str_replace( 'post-format-', '', $term->slug ), $link ); |
|
| 189 | + $link = remove_query_arg('post_format', $link); |
|
| 190 | + return add_query_arg('post_format', str_replace('post-format-', '', $term->slug), $link); |
|
| 191 | 191 | } |
| 192 | 192 | } |
| 193 | 193 | |
@@ -200,9 +200,9 @@ discard block |
||
| 200 | 200 | * @param object $term |
| 201 | 201 | * @return object |
| 202 | 202 | */ |
| 203 | -function _post_format_get_term( $term ) { |
|
| 204 | - if ( isset( $term->slug ) ) { |
|
| 205 | - $term->name = get_post_format_string( str_replace( 'post-format-', '', $term->slug ) ); |
|
| 203 | +function _post_format_get_term($term) { |
|
| 204 | + if (isset($term->slug)) { |
|
| 205 | + $term->name = get_post_format_string(str_replace('post-format-', '', $term->slug)); |
|
| 206 | 206 | } |
| 207 | 207 | return $term; |
| 208 | 208 | } |
@@ -218,16 +218,16 @@ discard block |
||
| 218 | 218 | * @param array $args |
| 219 | 219 | * @return array |
| 220 | 220 | */ |
| 221 | -function _post_format_get_terms( $terms, $taxonomies, $args ) { |
|
| 222 | - if ( in_array( 'post_format', (array) $taxonomies ) ) { |
|
| 223 | - if ( isset( $args['fields'] ) && 'names' == $args['fields'] ) { |
|
| 224 | - foreach( $terms as $order => $name ) { |
|
| 225 | - $terms[$order] = get_post_format_string( str_replace( 'post-format-', '', $name ) ); |
|
| 221 | +function _post_format_get_terms($terms, $taxonomies, $args) { |
|
| 222 | + if (in_array('post_format', (array) $taxonomies)) { |
|
| 223 | + if (isset($args['fields']) && 'names' == $args['fields']) { |
|
| 224 | + foreach ($terms as $order => $name) { |
|
| 225 | + $terms[$order] = get_post_format_string(str_replace('post-format-', '', $name)); |
|
| 226 | 226 | } |
| 227 | 227 | } else { |
| 228 | - foreach ( (array) $terms as $order => $term ) { |
|
| 229 | - if ( isset( $term->taxonomy ) && 'post_format' == $term->taxonomy ) { |
|
| 230 | - $terms[$order]->name = get_post_format_string( str_replace( 'post-format-', '', $term->slug ) ); |
|
| 228 | + foreach ((array) $terms as $order => $term) { |
|
| 229 | + if (isset($term->taxonomy) && 'post_format' == $term->taxonomy) { |
|
| 230 | + $terms[$order]->name = get_post_format_string(str_replace('post-format-', '', $term->slug)); |
|
| 231 | 231 | } |
| 232 | 232 | } |
| 233 | 233 | } |
@@ -244,10 +244,10 @@ discard block |
||
| 244 | 244 | * @param array $terms |
| 245 | 245 | * @return array |
| 246 | 246 | */ |
| 247 | -function _post_format_wp_get_object_terms( $terms ) { |
|
| 248 | - foreach ( (array) $terms as $order => $term ) { |
|
| 249 | - if ( isset( $term->taxonomy ) && 'post_format' == $term->taxonomy ) { |
|
| 250 | - $terms[$order]->name = get_post_format_string( str_replace( 'post-format-', '', $term->slug ) ); |
|
| 247 | +function _post_format_wp_get_object_terms($terms) { |
|
| 248 | + foreach ((array) $terms as $order => $term) { |
|
| 249 | + if (isset($term->taxonomy) && 'post_format' == $term->taxonomy) { |
|
| 250 | + $terms[$order]->name = get_post_format_string(str_replace('post-format-', '', $term->slug)); |
|
| 251 | 251 | } |
| 252 | 252 | } |
| 253 | 253 | return $terms; |
@@ -15,16 +15,19 @@ discard block |
||
| 15 | 15 | * @return string|false The format if successful. False otherwise. |
| 16 | 16 | */ |
| 17 | 17 | function get_post_format( $post = null ) { |
| 18 | - if ( ! $post = get_post( $post ) ) |
|
| 19 | - return false; |
|
| 18 | + if ( ! $post = get_post( $post ) ) { |
|
| 19 | + return false; |
|
| 20 | + } |
|
| 20 | 21 | |
| 21 | - if ( ! post_type_supports( $post->post_type, 'post-formats' ) ) |
|
| 22 | - return false; |
|
| 22 | + if ( ! post_type_supports( $post->post_type, 'post-formats' ) ) { |
|
| 23 | + return false; |
|
| 24 | + } |
|
| 23 | 25 | |
| 24 | 26 | $_format = get_the_terms( $post->ID, 'post_format' ); |
| 25 | 27 | |
| 26 | - if ( empty( $_format ) ) |
|
| 27 | - return false; |
|
| 28 | + if ( empty( $_format ) ) { |
|
| 29 | + return false; |
|
| 30 | + } |
|
| 28 | 31 | |
| 29 | 32 | $format = reset( $_format ); |
| 30 | 33 | |
@@ -64,15 +67,17 @@ discard block |
||
| 64 | 67 | function set_post_format( $post, $format ) { |
| 65 | 68 | $post = get_post( $post ); |
| 66 | 69 | |
| 67 | - if ( empty( $post ) ) |
|
| 68 | - return new WP_Error( 'invalid_post', __( 'Invalid post.' ) ); |
|
| 70 | + if ( empty( $post ) ) { |
|
| 71 | + return new WP_Error( 'invalid_post', __( 'Invalid post.' ) ); |
|
| 72 | + } |
|
| 69 | 73 | |
| 70 | 74 | if ( ! empty( $format ) ) { |
| 71 | 75 | $format = sanitize_key( $format ); |
| 72 | - if ( 'standard' === $format || ! in_array( $format, get_post_format_slugs() ) ) |
|
| 73 | - $format = ''; |
|
| 74 | - else |
|
| 75 | - $format = 'post-format-' . $format; |
|
| 76 | + if ( 'standard' === $format || ! in_array( $format, get_post_format_slugs() ) ) { |
|
| 77 | + $format = ''; |
|
| 78 | + } else { |
|
| 79 | + $format = 'post-format-' . $format; |
|
| 80 | + } |
|
| 76 | 81 | } |
| 77 | 82 | |
| 78 | 83 | return wp_set_post_terms( $post->ID, $format, 'post_format' ); |
@@ -123,11 +128,12 @@ discard block |
||
| 123 | 128 | */ |
| 124 | 129 | function get_post_format_string( $slug ) { |
| 125 | 130 | $strings = get_post_format_strings(); |
| 126 | - if ( !$slug ) |
|
| 127 | - return $strings['standard']; |
|
| 128 | - else |
|
| 129 | - return ( isset( $strings[$slug] ) ) ? $strings[$slug] : ''; |
|
| 130 | -} |
|
| 131 | + if ( !$slug ) { |
|
| 132 | + return $strings['standard']; |
|
| 133 | + } else { |
|
| 134 | + return ( isset( $strings[$slug] ) ) ? $strings[$slug] : ''; |
|
| 135 | + } |
|
| 136 | + } |
|
| 131 | 137 | |
| 132 | 138 | /** |
| 133 | 139 | * Returns a link to a post format index. |
@@ -139,8 +145,9 @@ discard block |
||
| 139 | 145 | */ |
| 140 | 146 | function get_post_format_link( $format ) { |
| 141 | 147 | $term = get_term_by('slug', 'post-format-' . $format, 'post_format' ); |
| 142 | - if ( ! $term || is_wp_error( $term ) ) |
|
| 143 | - return false; |
|
| 148 | + if ( ! $term || is_wp_error( $term ) ) { |
|
| 149 | + return false; |
|
| 150 | + } |
|
| 144 | 151 | return get_term_link( $term ); |
| 145 | 152 | } |
| 146 | 153 | |
@@ -154,14 +161,17 @@ discard block |
||
| 154 | 161 | * @return array |
| 155 | 162 | */ |
| 156 | 163 | function _post_format_request( $qvs ) { |
| 157 | - if ( ! isset( $qvs['post_format'] ) ) |
|
| 158 | - return $qvs; |
|
| 164 | + if ( ! isset( $qvs['post_format'] ) ) { |
|
| 165 | + return $qvs; |
|
| 166 | + } |
|
| 159 | 167 | $slugs = get_post_format_slugs(); |
| 160 | - if ( isset( $slugs[ $qvs['post_format'] ] ) ) |
|
| 161 | - $qvs['post_format'] = 'post-format-' . $slugs[ $qvs['post_format'] ]; |
|
| 168 | + if ( isset( $slugs[ $qvs['post_format'] ] ) ) { |
|
| 169 | + $qvs['post_format'] = 'post-format-' . $slugs[ $qvs['post_format'] ]; |
|
| 170 | + } |
|
| 162 | 171 | $tax = get_taxonomy( 'post_format' ); |
| 163 | - if ( ! is_admin() ) |
|
| 164 | - $qvs['post_type'] = $tax->object_type; |
|
| 172 | + if ( ! is_admin() ) { |
|
| 173 | + $qvs['post_type'] = $tax->object_type; |
|
| 174 | + } |
|
| 165 | 175 | return $qvs; |
| 166 | 176 | } |
| 167 | 177 | |