@@ -21,13 +21,13 @@ discard block |
||
| 21 | 21 | * @param string $name |
| 22 | 22 | * @return string|array|void |
| 23 | 23 | */ |
| 24 | - public function __get( $name ) { |
|
| 25 | - switch ( $name ) { |
|
| 24 | + public function __get($name) { |
|
| 25 | + switch ($name) { |
|
| 26 | 26 | case 'proto' : |
| 27 | 27 | return is_ssl() ? 'https://' : 'http://'; |
| 28 | 28 | |
| 29 | 29 | case 'menu' : |
| 30 | - _deprecated_argument( 'WP_Admin_Bar', '3.3.0', 'Modify admin bar nodes with WP_Admin_Bar::get_node(), WP_Admin_Bar::add_node(), and WP_Admin_Bar::remove_node(), not the <code>menu</code> property.' ); |
|
| 30 | + _deprecated_argument('WP_Admin_Bar', '3.3.0', 'Modify admin bar nodes with WP_Admin_Bar::get_node(), WP_Admin_Bar::add_node(), and WP_Admin_Bar::remove_node(), not the <code>menu</code> property.'); |
|
| 31 | 31 | return array(); // Sorry, folks. |
| 32 | 32 | } |
| 33 | 33 | } |
@@ -38,61 +38,61 @@ discard block |
||
| 38 | 38 | public function initialize() { |
| 39 | 39 | $this->user = new stdClass; |
| 40 | 40 | |
| 41 | - if ( is_user_logged_in() ) { |
|
| 41 | + if (is_user_logged_in()) { |
|
| 42 | 42 | /* Populate settings we need for the menu based on the current user. */ |
| 43 | - $this->user->blogs = get_blogs_of_user( get_current_user_id() ); |
|
| 44 | - if ( is_multisite() ) { |
|
| 45 | - $this->user->active_blog = get_active_blog_for_user( get_current_user_id() ); |
|
| 46 | - $this->user->domain = empty( $this->user->active_blog ) ? user_admin_url() : trailingslashit( get_home_url( $this->user->active_blog->blog_id ) ); |
|
| 43 | + $this->user->blogs = get_blogs_of_user(get_current_user_id()); |
|
| 44 | + if (is_multisite()) { |
|
| 45 | + $this->user->active_blog = get_active_blog_for_user(get_current_user_id()); |
|
| 46 | + $this->user->domain = empty($this->user->active_blog) ? user_admin_url() : trailingslashit(get_home_url($this->user->active_blog->blog_id)); |
|
| 47 | 47 | $this->user->account_domain = $this->user->domain; |
| 48 | 48 | } else { |
| 49 | 49 | $this->user->active_blog = $this->user->blogs[get_current_blog_id()]; |
| 50 | - $this->user->domain = trailingslashit( home_url() ); |
|
| 50 | + $this->user->domain = trailingslashit(home_url()); |
|
| 51 | 51 | $this->user->account_domain = $this->user->domain; |
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - add_action( 'wp_head', 'wp_admin_bar_header' ); |
|
| 55 | + add_action('wp_head', 'wp_admin_bar_header'); |
|
| 56 | 56 | |
| 57 | - add_action( 'admin_head', 'wp_admin_bar_header' ); |
|
| 57 | + add_action('admin_head', 'wp_admin_bar_header'); |
|
| 58 | 58 | |
| 59 | - if ( current_theme_supports( 'admin-bar' ) ) { |
|
| 59 | + if (current_theme_supports('admin-bar')) { |
|
| 60 | 60 | /** |
| 61 | 61 | * To remove the default padding styles from WordPress for the Toolbar, use the following code: |
| 62 | 62 | * add_theme_support( 'admin-bar', array( 'callback' => '__return_false' ) ); |
| 63 | 63 | */ |
| 64 | - $admin_bar_args = get_theme_support( 'admin-bar' ); |
|
| 64 | + $admin_bar_args = get_theme_support('admin-bar'); |
|
| 65 | 65 | $header_callback = $admin_bar_args[0]['callback']; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - if ( empty($header_callback) ) |
|
| 68 | + if (empty($header_callback)) |
|
| 69 | 69 | $header_callback = '_admin_bar_bump_cb'; |
| 70 | 70 | |
| 71 | 71 | add_action('wp_head', $header_callback); |
| 72 | 72 | |
| 73 | - wp_enqueue_script( 'admin-bar' ); |
|
| 74 | - wp_enqueue_style( 'admin-bar' ); |
|
| 73 | + wp_enqueue_script('admin-bar'); |
|
| 74 | + wp_enqueue_style('admin-bar'); |
|
| 75 | 75 | |
| 76 | 76 | /** |
| 77 | 77 | * Fires after WP_Admin_Bar is initialized. |
| 78 | 78 | * |
| 79 | 79 | * @since 3.1.0 |
| 80 | 80 | */ |
| 81 | - do_action( 'admin_bar_init' ); |
|
| 81 | + do_action('admin_bar_init'); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | /** |
| 85 | 85 | * @param array $node |
| 86 | 86 | */ |
| 87 | - public function add_menu( $node ) { |
|
| 88 | - $this->add_node( $node ); |
|
| 87 | + public function add_menu($node) { |
|
| 88 | + $this->add_node($node); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
| 92 | 92 | * @param string $id |
| 93 | 93 | */ |
| 94 | - public function remove_menu( $id ) { |
|
| 95 | - $this->remove_node( $id ); |
|
| 94 | + public function remove_menu($id) { |
|
| 95 | + $this->remove_node($id); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -114,22 +114,22 @@ discard block |
||
| 114 | 114 | * 'onclick', 'target', 'title', 'tabindex'. Default empty. |
| 115 | 115 | * } |
| 116 | 116 | */ |
| 117 | - public function add_node( $args ) { |
|
| 117 | + public function add_node($args) { |
|
| 118 | 118 | // Shim for old method signature: add_node( $parent_id, $menu_obj, $args ) |
| 119 | - if ( func_num_args() >= 3 && is_string( func_get_arg(0) ) ) |
|
| 120 | - $args = array_merge( array( 'parent' => func_get_arg(0) ), func_get_arg(2) ); |
|
| 119 | + if (func_num_args() >= 3 && is_string(func_get_arg(0))) |
|
| 120 | + $args = array_merge(array('parent' => func_get_arg(0)), func_get_arg(2)); |
|
| 121 | 121 | |
| 122 | - if ( is_object( $args ) ) |
|
| 123 | - $args = get_object_vars( $args ); |
|
| 122 | + if (is_object($args)) |
|
| 123 | + $args = get_object_vars($args); |
|
| 124 | 124 | |
| 125 | 125 | // Ensure we have a valid title. |
| 126 | - if ( empty( $args['id'] ) ) { |
|
| 127 | - if ( empty( $args['title'] ) ) |
|
| 126 | + if (empty($args['id'])) { |
|
| 127 | + if (empty($args['title'])) |
|
| 128 | 128 | return; |
| 129 | 129 | |
| 130 | - _doing_it_wrong( __METHOD__, __( 'The menu ID should not be empty.' ), '3.3.0' ); |
|
| 130 | + _doing_it_wrong(__METHOD__, __('The menu ID should not be empty.'), '3.3.0'); |
|
| 131 | 131 | // Deprecated: Generate an ID from the title. |
| 132 | - $args['id'] = esc_attr( sanitize_title( trim( $args['title'] ) ) ); |
|
| 132 | + $args['id'] = esc_attr(sanitize_title(trim($args['title']))); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | $defaults = array( |
@@ -142,34 +142,34 @@ discard block |
||
| 142 | 142 | ); |
| 143 | 143 | |
| 144 | 144 | // If the node already exists, keep any data that isn't provided. |
| 145 | - if ( $maybe_defaults = $this->get_node( $args['id'] ) ) |
|
| 146 | - $defaults = get_object_vars( $maybe_defaults ); |
|
| 145 | + if ($maybe_defaults = $this->get_node($args['id'])) |
|
| 146 | + $defaults = get_object_vars($maybe_defaults); |
|
| 147 | 147 | |
| 148 | 148 | // Do the same for 'meta' items. |
| 149 | - if ( ! empty( $defaults['meta'] ) && ! empty( $args['meta'] ) ) |
|
| 150 | - $args['meta'] = wp_parse_args( $args['meta'], $defaults['meta'] ); |
|
| 149 | + if ( ! empty($defaults['meta']) && ! empty($args['meta'])) |
|
| 150 | + $args['meta'] = wp_parse_args($args['meta'], $defaults['meta']); |
|
| 151 | 151 | |
| 152 | - $args = wp_parse_args( $args, $defaults ); |
|
| 152 | + $args = wp_parse_args($args, $defaults); |
|
| 153 | 153 | |
| 154 | 154 | $back_compat_parents = array( |
| 155 | - 'my-account-with-avatar' => array( 'my-account', '3.3' ), |
|
| 156 | - 'my-blogs' => array( 'my-sites', '3.3' ), |
|
| 155 | + 'my-account-with-avatar' => array('my-account', '3.3'), |
|
| 156 | + 'my-blogs' => array('my-sites', '3.3'), |
|
| 157 | 157 | ); |
| 158 | 158 | |
| 159 | - if ( isset( $back_compat_parents[ $args['parent'] ] ) ) { |
|
| 160 | - list( $new_parent, $version ) = $back_compat_parents[ $args['parent'] ]; |
|
| 161 | - _deprecated_argument( __METHOD__, $version, sprintf( 'Use <code>%s</code> as the parent for the <code>%s</code> admin bar node instead of <code>%s</code>.', $new_parent, $args['id'], $args['parent'] ) ); |
|
| 159 | + if (isset($back_compat_parents[$args['parent']])) { |
|
| 160 | + list($new_parent, $version) = $back_compat_parents[$args['parent']]; |
|
| 161 | + _deprecated_argument(__METHOD__, $version, sprintf('Use <code>%s</code> as the parent for the <code>%s</code> admin bar node instead of <code>%s</code>.', $new_parent, $args['id'], $args['parent'])); |
|
| 162 | 162 | $args['parent'] = $new_parent; |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - $this->_set_node( $args ); |
|
| 165 | + $this->_set_node($args); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
| 169 | 169 | * @param array $args |
| 170 | 170 | */ |
| 171 | - final protected function _set_node( $args ) { |
|
| 172 | - $this->nodes[ $args['id'] ] = (object) $args; |
|
| 171 | + final protected function _set_node($args) { |
|
| 172 | + $this->nodes[$args['id']] = (object) $args; |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | /** |
@@ -178,8 +178,8 @@ discard block |
||
| 178 | 178 | * @param string $id |
| 179 | 179 | * @return object Node. |
| 180 | 180 | */ |
| 181 | - final public function get_node( $id ) { |
|
| 182 | - if ( $node = $this->_get_node( $id ) ) |
|
| 181 | + final public function get_node($id) { |
|
| 182 | + if ($node = $this->_get_node($id)) |
|
| 183 | 183 | return clone $node; |
| 184 | 184 | } |
| 185 | 185 | |
@@ -187,25 +187,25 @@ discard block |
||
| 187 | 187 | * @param string $id |
| 188 | 188 | * @return object|void |
| 189 | 189 | */ |
| 190 | - final protected function _get_node( $id ) { |
|
| 191 | - if ( $this->bound ) |
|
| 190 | + final protected function _get_node($id) { |
|
| 191 | + if ($this->bound) |
|
| 192 | 192 | return; |
| 193 | 193 | |
| 194 | - if ( empty( $id ) ) |
|
| 194 | + if (empty($id)) |
|
| 195 | 195 | $id = 'root'; |
| 196 | 196 | |
| 197 | - if ( isset( $this->nodes[ $id ] ) ) |
|
| 198 | - return $this->nodes[ $id ]; |
|
| 197 | + if (isset($this->nodes[$id])) |
|
| 198 | + return $this->nodes[$id]; |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | /** |
| 202 | 202 | * @return array|void |
| 203 | 203 | */ |
| 204 | 204 | final public function get_nodes() { |
| 205 | - if ( ! $nodes = $this->_get_nodes() ) |
|
| 205 | + if ( ! $nodes = $this->_get_nodes()) |
|
| 206 | 206 | return; |
| 207 | 207 | |
| 208 | - foreach ( $nodes as &$node ) { |
|
| 208 | + foreach ($nodes as &$node) { |
|
| 209 | 209 | $node = clone $node; |
| 210 | 210 | } |
| 211 | 211 | return $nodes; |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | * @return array|void |
| 216 | 216 | */ |
| 217 | 217 | final protected function _get_nodes() { |
| 218 | - if ( $this->bound ) |
|
| 218 | + if ($this->bound) |
|
| 219 | 219 | return; |
| 220 | 220 | |
| 221 | 221 | return $this->nodes; |
@@ -235,10 +235,10 @@ discard block |
||
| 235 | 235 | * 'class', 'onclick', 'target', and 'title'. |
| 236 | 236 | * } |
| 237 | 237 | */ |
| 238 | - final public function add_group( $args ) { |
|
| 238 | + final public function add_group($args) { |
|
| 239 | 239 | $args['group'] = true; |
| 240 | 240 | |
| 241 | - $this->add_node( $args ); |
|
| 241 | + $this->add_node($args); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
@@ -246,15 +246,15 @@ discard block |
||
| 246 | 246 | * |
| 247 | 247 | * @param string $id The ID of the item. |
| 248 | 248 | */ |
| 249 | - public function remove_node( $id ) { |
|
| 250 | - $this->_unset_node( $id ); |
|
| 249 | + public function remove_node($id) { |
|
| 250 | + $this->_unset_node($id); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
| 254 | 254 | * @param string $id |
| 255 | 255 | */ |
| 256 | - final protected function _unset_node( $id ) { |
|
| 257 | - unset( $this->nodes[ $id ] ); |
|
| 256 | + final protected function _unset_node($id) { |
|
| 257 | + unset($this->nodes[$id]); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | /** |
@@ -262,66 +262,66 @@ discard block |
||
| 262 | 262 | */ |
| 263 | 263 | public function render() { |
| 264 | 264 | $root = $this->_bind(); |
| 265 | - if ( $root ) |
|
| 266 | - $this->_render( $root ); |
|
| 265 | + if ($root) |
|
| 266 | + $this->_render($root); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | /** |
| 270 | 270 | * @return object|void |
| 271 | 271 | */ |
| 272 | 272 | final protected function _bind() { |
| 273 | - if ( $this->bound ) |
|
| 273 | + if ($this->bound) |
|
| 274 | 274 | return; |
| 275 | 275 | |
| 276 | 276 | // Add the root node. |
| 277 | 277 | // Clear it first, just in case. Don't mess with The Root. |
| 278 | - $this->remove_node( 'root' ); |
|
| 279 | - $this->add_node( array( |
|
| 278 | + $this->remove_node('root'); |
|
| 279 | + $this->add_node(array( |
|
| 280 | 280 | 'id' => 'root', |
| 281 | 281 | 'group' => false, |
| 282 | - ) ); |
|
| 282 | + )); |
|
| 283 | 283 | |
| 284 | 284 | // Normalize nodes: define internal 'children' and 'type' properties. |
| 285 | - foreach ( $this->_get_nodes() as $node ) { |
|
| 285 | + foreach ($this->_get_nodes() as $node) { |
|
| 286 | 286 | $node->children = array(); |
| 287 | - $node->type = ( $node->group ) ? 'group' : 'item'; |
|
| 288 | - unset( $node->group ); |
|
| 287 | + $node->type = ($node->group) ? 'group' : 'item'; |
|
| 288 | + unset($node->group); |
|
| 289 | 289 | |
| 290 | 290 | // The Root wants your orphans. No lonely items allowed. |
| 291 | - if ( ! $node->parent ) |
|
| 291 | + if ( ! $node->parent) |
|
| 292 | 292 | $node->parent = 'root'; |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | - foreach ( $this->_get_nodes() as $node ) { |
|
| 296 | - if ( 'root' == $node->id ) |
|
| 295 | + foreach ($this->_get_nodes() as $node) { |
|
| 296 | + if ('root' == $node->id) |
|
| 297 | 297 | continue; |
| 298 | 298 | |
| 299 | 299 | // Fetch the parent node. If it isn't registered, ignore the node. |
| 300 | - if ( ! $parent = $this->_get_node( $node->parent ) ) { |
|
| 300 | + if ( ! $parent = $this->_get_node($node->parent)) { |
|
| 301 | 301 | continue; |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | // Generate the group class (we distinguish between top level and other level groups). |
| 305 | - $group_class = ( $node->parent == 'root' ) ? 'ab-top-menu' : 'ab-submenu'; |
|
| 305 | + $group_class = ($node->parent == 'root') ? 'ab-top-menu' : 'ab-submenu'; |
|
| 306 | 306 | |
| 307 | - if ( $node->type == 'group' ) { |
|
| 308 | - if ( empty( $node->meta['class'] ) ) |
|
| 307 | + if ($node->type == 'group') { |
|
| 308 | + if (empty($node->meta['class'])) |
|
| 309 | 309 | $node->meta['class'] = $group_class; |
| 310 | 310 | else |
| 311 | - $node->meta['class'] .= ' ' . $group_class; |
|
| 311 | + $node->meta['class'] .= ' '.$group_class; |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | // Items in items aren't allowed. Wrap nested items in 'default' groups. |
| 315 | - if ( $parent->type == 'item' && $node->type == 'item' ) { |
|
| 316 | - $default_id = $parent->id . '-default'; |
|
| 317 | - $default = $this->_get_node( $default_id ); |
|
| 315 | + if ($parent->type == 'item' && $node->type == 'item') { |
|
| 316 | + $default_id = $parent->id.'-default'; |
|
| 317 | + $default = $this->_get_node($default_id); |
|
| 318 | 318 | |
| 319 | 319 | // The default group is added here to allow groups that are |
| 320 | 320 | // added before standard menu items to render first. |
| 321 | - if ( ! $default ) { |
|
| 321 | + if ( ! $default) { |
|
| 322 | 322 | // Use _set_node because add_node can be overloaded. |
| 323 | 323 | // Make sure to specify default settings for all properties. |
| 324 | - $this->_set_node( array( |
|
| 324 | + $this->_set_node(array( |
|
| 325 | 325 | 'id' => $default_id, |
| 326 | 326 | 'parent' => $parent->id, |
| 327 | 327 | 'type' => 'group', |
@@ -331,45 +331,45 @@ discard block |
||
| 331 | 331 | ), |
| 332 | 332 | 'title' => false, |
| 333 | 333 | 'href' => false, |
| 334 | - ) ); |
|
| 335 | - $default = $this->_get_node( $default_id ); |
|
| 334 | + )); |
|
| 335 | + $default = $this->_get_node($default_id); |
|
| 336 | 336 | $parent->children[] = $default; |
| 337 | 337 | } |
| 338 | 338 | $parent = $default; |
| 339 | 339 | |
| 340 | 340 | // Groups in groups aren't allowed. Add a special 'container' node. |
| 341 | 341 | // The container will invisibly wrap both groups. |
| 342 | - } elseif ( $parent->type == 'group' && $node->type == 'group' ) { |
|
| 343 | - $container_id = $parent->id . '-container'; |
|
| 344 | - $container = $this->_get_node( $container_id ); |
|
| 342 | + } elseif ($parent->type == 'group' && $node->type == 'group') { |
|
| 343 | + $container_id = $parent->id.'-container'; |
|
| 344 | + $container = $this->_get_node($container_id); |
|
| 345 | 345 | |
| 346 | 346 | // We need to create a container for this group, life is sad. |
| 347 | - if ( ! $container ) { |
|
| 347 | + if ( ! $container) { |
|
| 348 | 348 | // Use _set_node because add_node can be overloaded. |
| 349 | 349 | // Make sure to specify default settings for all properties. |
| 350 | - $this->_set_node( array( |
|
| 350 | + $this->_set_node(array( |
|
| 351 | 351 | 'id' => $container_id, |
| 352 | 352 | 'type' => 'container', |
| 353 | - 'children' => array( $parent ), |
|
| 353 | + 'children' => array($parent), |
|
| 354 | 354 | 'parent' => false, |
| 355 | 355 | 'title' => false, |
| 356 | 356 | 'href' => false, |
| 357 | 357 | 'meta' => array(), |
| 358 | - ) ); |
|
| 358 | + )); |
|
| 359 | 359 | |
| 360 | - $container = $this->_get_node( $container_id ); |
|
| 360 | + $container = $this->_get_node($container_id); |
|
| 361 | 361 | |
| 362 | 362 | // Link the container node if a grandparent node exists. |
| 363 | - $grandparent = $this->_get_node( $parent->parent ); |
|
| 363 | + $grandparent = $this->_get_node($parent->parent); |
|
| 364 | 364 | |
| 365 | - if ( $grandparent ) { |
|
| 365 | + if ($grandparent) { |
|
| 366 | 366 | $container->parent = $grandparent->id; |
| 367 | 367 | |
| 368 | - $index = array_search( $parent, $grandparent->children, true ); |
|
| 369 | - if ( $index === false ) |
|
| 368 | + $index = array_search($parent, $grandparent->children, true); |
|
| 369 | + if ($index === false) |
|
| 370 | 370 | $grandparent->children[] = $container; |
| 371 | 371 | else |
| 372 | - array_splice( $grandparent->children, $index, 1, array( $container ) ); |
|
| 372 | + array_splice($grandparent->children, $index, 1, array($container)); |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | $parent->parent = $container->id; |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | $parent->children[] = $node; |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | - $root = $this->_get_node( 'root' ); |
|
| 388 | + $root = $this->_get_node('root'); |
|
| 389 | 389 | $this->bound = true; |
| 390 | 390 | return $root; |
| 391 | 391 | } |
@@ -395,35 +395,35 @@ discard block |
||
| 395 | 395 | * @global bool $is_IE |
| 396 | 396 | * @param object $root |
| 397 | 397 | */ |
| 398 | - final protected function _render( $root ) { |
|
| 398 | + final protected function _render($root) { |
|
| 399 | 399 | global $is_IE; |
| 400 | 400 | |
| 401 | 401 | // Add browser classes. |
| 402 | 402 | // We have to do this here since admin bar shows on the front end. |
| 403 | 403 | $class = 'nojq nojs'; |
| 404 | - if ( $is_IE ) { |
|
| 405 | - if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 7' ) ) |
|
| 404 | + if ($is_IE) { |
|
| 405 | + if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7')) |
|
| 406 | 406 | $class .= ' ie7'; |
| 407 | - elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 8' ) ) |
|
| 407 | + elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 8')) |
|
| 408 | 408 | $class .= ' ie8'; |
| 409 | - elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 9' ) ) |
|
| 409 | + elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 9')) |
|
| 410 | 410 | $class .= ' ie9'; |
| 411 | - } elseif ( wp_is_mobile() ) { |
|
| 411 | + } elseif (wp_is_mobile()) { |
|
| 412 | 412 | $class .= ' mobile'; |
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | ?> |
| 416 | 416 | <div id="wpadminbar" class="<?php echo $class; ?>"> |
| 417 | - <?php if ( ! is_admin() ) { ?> |
|
| 418 | - <a class="screen-reader-shortcut" href="#wp-toolbar" tabindex="1"><?php _e( 'Skip to toolbar' ); ?></a> |
|
| 417 | + <?php if ( ! is_admin()) { ?> |
|
| 418 | + <a class="screen-reader-shortcut" href="#wp-toolbar" tabindex="1"><?php _e('Skip to toolbar'); ?></a> |
|
| 419 | 419 | <?php } ?> |
| 420 | - <div class="quicklinks" id="wp-toolbar" role="navigation" aria-label="<?php esc_attr_e( 'Toolbar' ); ?>" tabindex="0"> |
|
| 421 | - <?php foreach ( $root->children as $group ) { |
|
| 422 | - $this->_render_group( $group ); |
|
| 420 | + <div class="quicklinks" id="wp-toolbar" role="navigation" aria-label="<?php esc_attr_e('Toolbar'); ?>" tabindex="0"> |
|
| 421 | + <?php foreach ($root->children as $group) { |
|
| 422 | + $this->_render_group($group); |
|
| 423 | 423 | } ?> |
| 424 | 424 | </div> |
| 425 | - <?php if ( is_user_logged_in() ) : ?> |
|
| 426 | - <a class="screen-reader-shortcut" href="<?php echo esc_url( wp_logout_url() ); ?>"><?php _e('Log Out'); ?></a> |
|
| 425 | + <?php if (is_user_logged_in()) : ?> |
|
| 426 | + <a class="screen-reader-shortcut" href="<?php echo esc_url(wp_logout_url()); ?>"><?php _e('Log Out'); ?></a> |
|
| 427 | 427 | <?php endif; ?> |
| 428 | 428 | </div> |
| 429 | 429 | |
@@ -433,13 +433,13 @@ discard block |
||
| 433 | 433 | /** |
| 434 | 434 | * @param object $node |
| 435 | 435 | */ |
| 436 | - final protected function _render_container( $node ) { |
|
| 437 | - if ( $node->type != 'container' || empty( $node->children ) ) |
|
| 436 | + final protected function _render_container($node) { |
|
| 437 | + if ($node->type != 'container' || empty($node->children)) |
|
| 438 | 438 | return; |
| 439 | 439 | |
| 440 | - ?><div id="<?php echo esc_attr( 'wp-admin-bar-' . $node->id ); ?>" class="ab-group-container"><?php |
|
| 441 | - foreach ( $node->children as $group ) { |
|
| 442 | - $this->_render_group( $group ); |
|
| 440 | + ?><div id="<?php echo esc_attr('wp-admin-bar-'.$node->id); ?>" class="ab-group-container"><?php |
|
| 441 | + foreach ($node->children as $group) { |
|
| 442 | + $this->_render_group($group); |
|
| 443 | 443 | } |
| 444 | 444 | ?></div><?php |
| 445 | 445 | } |
@@ -447,22 +447,22 @@ discard block |
||
| 447 | 447 | /** |
| 448 | 448 | * @param object $node |
| 449 | 449 | */ |
| 450 | - final protected function _render_group( $node ) { |
|
| 451 | - if ( $node->type == 'container' ) { |
|
| 452 | - $this->_render_container( $node ); |
|
| 450 | + final protected function _render_group($node) { |
|
| 451 | + if ($node->type == 'container') { |
|
| 452 | + $this->_render_container($node); |
|
| 453 | 453 | return; |
| 454 | 454 | } |
| 455 | - if ( $node->type != 'group' || empty( $node->children ) ) |
|
| 455 | + if ($node->type != 'group' || empty($node->children)) |
|
| 456 | 456 | return; |
| 457 | 457 | |
| 458 | - if ( ! empty( $node->meta['class'] ) ) |
|
| 459 | - $class = ' class="' . esc_attr( trim( $node->meta['class'] ) ) . '"'; |
|
| 458 | + if ( ! empty($node->meta['class'])) |
|
| 459 | + $class = ' class="'.esc_attr(trim($node->meta['class'])).'"'; |
|
| 460 | 460 | else |
| 461 | 461 | $class = ''; |
| 462 | 462 | |
| 463 | - ?><ul id="<?php echo esc_attr( 'wp-admin-bar-' . $node->id ); ?>"<?php echo $class; ?>><?php |
|
| 464 | - foreach ( $node->children as $item ) { |
|
| 465 | - $this->_render_item( $item ); |
|
| 463 | + ?><ul id="<?php echo esc_attr('wp-admin-bar-'.$node->id); ?>"<?php echo $class; ?>><?php |
|
| 464 | + foreach ($node->children as $item) { |
|
| 465 | + $this->_render_item($item); |
|
| 466 | 466 | } |
| 467 | 467 | ?></ul><?php |
| 468 | 468 | } |
@@ -470,85 +470,85 @@ discard block |
||
| 470 | 470 | /** |
| 471 | 471 | * @param object $node |
| 472 | 472 | */ |
| 473 | - final protected function _render_item( $node ) { |
|
| 474 | - if ( $node->type != 'item' ) |
|
| 473 | + final protected function _render_item($node) { |
|
| 474 | + if ($node->type != 'item') |
|
| 475 | 475 | return; |
| 476 | 476 | |
| 477 | - $is_parent = ! empty( $node->children ); |
|
| 478 | - $has_link = ! empty( $node->href ); |
|
| 477 | + $is_parent = ! empty($node->children); |
|
| 478 | + $has_link = ! empty($node->href); |
|
| 479 | 479 | |
| 480 | 480 | // Allow only numeric values, then casted to integers, and allow a tabindex value of `0` for a11y. |
| 481 | - $tabindex = ( isset( $node->meta['tabindex'] ) && is_numeric( $node->meta['tabindex'] ) ) ? (int) $node->meta['tabindex'] : ''; |
|
| 482 | - $aria_attributes = ( '' !== $tabindex ) ? ' tabindex="' . $tabindex . '"' : ''; |
|
| 481 | + $tabindex = (isset($node->meta['tabindex']) && is_numeric($node->meta['tabindex'])) ? (int) $node->meta['tabindex'] : ''; |
|
| 482 | + $aria_attributes = ('' !== $tabindex) ? ' tabindex="'.$tabindex.'"' : ''; |
|
| 483 | 483 | |
| 484 | 484 | $menuclass = ''; |
| 485 | 485 | |
| 486 | - if ( $is_parent ) { |
|
| 486 | + if ($is_parent) { |
|
| 487 | 487 | $menuclass = 'menupop '; |
| 488 | 488 | $aria_attributes .= ' aria-haspopup="true"'; |
| 489 | 489 | } |
| 490 | 490 | |
| 491 | - if ( ! empty( $node->meta['class'] ) ) |
|
| 491 | + if ( ! empty($node->meta['class'])) |
|
| 492 | 492 | $menuclass .= $node->meta['class']; |
| 493 | 493 | |
| 494 | - if ( $menuclass ) |
|
| 495 | - $menuclass = ' class="' . esc_attr( trim( $menuclass ) ) . '"'; |
|
| 494 | + if ($menuclass) |
|
| 495 | + $menuclass = ' class="'.esc_attr(trim($menuclass)).'"'; |
|
| 496 | 496 | |
| 497 | 497 | ?> |
| 498 | 498 | |
| 499 | - <li id="<?php echo esc_attr( 'wp-admin-bar-' . $node->id ); ?>"<?php echo $menuclass; ?>><?php |
|
| 500 | - if ( $has_link ): |
|
| 501 | - ?><a class="ab-item"<?php echo $aria_attributes; ?> href="<?php echo esc_url( $node->href ) ?>"<?php |
|
| 502 | - if ( ! empty( $node->meta['onclick'] ) ) : |
|
| 503 | - ?> onclick="<?php echo esc_js( $node->meta['onclick'] ); ?>"<?php |
|
| 499 | + <li id="<?php echo esc_attr('wp-admin-bar-'.$node->id); ?>"<?php echo $menuclass; ?>><?php |
|
| 500 | + if ($has_link): |
|
| 501 | + ?><a class="ab-item"<?php echo $aria_attributes; ?> href="<?php echo esc_url($node->href) ?>"<?php |
|
| 502 | + if ( ! empty($node->meta['onclick'])) : |
|
| 503 | + ?> onclick="<?php echo esc_js($node->meta['onclick']); ?>"<?php |
|
| 504 | 504 | endif; |
| 505 | - if ( ! empty( $node->meta['target'] ) ) : |
|
| 506 | - ?> target="<?php echo esc_attr( $node->meta['target'] ); ?>"<?php |
|
| 505 | + if ( ! empty($node->meta['target'])) : |
|
| 506 | + ?> target="<?php echo esc_attr($node->meta['target']); ?>"<?php |
|
| 507 | 507 | endif; |
| 508 | - if ( ! empty( $node->meta['title'] ) ) : |
|
| 509 | - ?> title="<?php echo esc_attr( $node->meta['title'] ); ?>"<?php |
|
| 508 | + if ( ! empty($node->meta['title'])) : |
|
| 509 | + ?> title="<?php echo esc_attr($node->meta['title']); ?>"<?php |
|
| 510 | 510 | endif; |
| 511 | - if ( ! empty( $node->meta['rel'] ) ) : |
|
| 512 | - ?> rel="<?php echo esc_attr( $node->meta['rel'] ); ?>"<?php |
|
| 511 | + if ( ! empty($node->meta['rel'])) : |
|
| 512 | + ?> rel="<?php echo esc_attr($node->meta['rel']); ?>"<?php |
|
| 513 | 513 | endif; |
| 514 | - if ( ! empty( $node->meta['lang'] ) ) : |
|
| 515 | - ?> lang="<?php echo esc_attr( $node->meta['lang'] ); ?>"<?php |
|
| 514 | + if ( ! empty($node->meta['lang'])) : |
|
| 515 | + ?> lang="<?php echo esc_attr($node->meta['lang']); ?>"<?php |
|
| 516 | 516 | endif; |
| 517 | - if ( ! empty( $node->meta['dir'] ) ) : |
|
| 518 | - ?> dir="<?php echo esc_attr( $node->meta['dir'] ); ?>"<?php |
|
| 517 | + if ( ! empty($node->meta['dir'])) : |
|
| 518 | + ?> dir="<?php echo esc_attr($node->meta['dir']); ?>"<?php |
|
| 519 | 519 | endif; |
| 520 | 520 | ?>><?php |
| 521 | 521 | else: |
| 522 | 522 | ?><div class="ab-item ab-empty-item"<?php echo $aria_attributes; |
| 523 | - if ( ! empty( $node->meta['title'] ) ) : |
|
| 524 | - ?> title="<?php echo esc_attr( $node->meta['title'] ); ?>"<?php |
|
| 523 | + if ( ! empty($node->meta['title'])) : |
|
| 524 | + ?> title="<?php echo esc_attr($node->meta['title']); ?>"<?php |
|
| 525 | 525 | endif; |
| 526 | - if ( ! empty( $node->meta['lang'] ) ) : |
|
| 527 | - ?> lang="<?php echo esc_attr( $node->meta['lang'] ); ?>"<?php |
|
| 526 | + if ( ! empty($node->meta['lang'])) : |
|
| 527 | + ?> lang="<?php echo esc_attr($node->meta['lang']); ?>"<?php |
|
| 528 | 528 | endif; |
| 529 | - if ( ! empty( $node->meta['dir'] ) ) : |
|
| 530 | - ?> dir="<?php echo esc_attr( $node->meta['dir'] ); ?>"<?php |
|
| 529 | + if ( ! empty($node->meta['dir'])) : |
|
| 530 | + ?> dir="<?php echo esc_attr($node->meta['dir']); ?>"<?php |
|
| 531 | 531 | endif; |
| 532 | 532 | ?>><?php |
| 533 | 533 | endif; |
| 534 | 534 | |
| 535 | 535 | echo $node->title; |
| 536 | 536 | |
| 537 | - if ( $has_link ) : |
|
| 537 | + if ($has_link) : |
|
| 538 | 538 | ?></a><?php |
| 539 | 539 | else: |
| 540 | 540 | ?></div><?php |
| 541 | 541 | endif; |
| 542 | 542 | |
| 543 | - if ( $is_parent ) : |
|
| 543 | + if ($is_parent) : |
|
| 544 | 544 | ?><div class="ab-sub-wrapper"><?php |
| 545 | - foreach ( $node->children as $group ) { |
|
| 546 | - $this->_render_group( $group ); |
|
| 545 | + foreach ($node->children as $group) { |
|
| 546 | + $this->_render_group($group); |
|
| 547 | 547 | } |
| 548 | 548 | ?></div><?php |
| 549 | 549 | endif; |
| 550 | 550 | |
| 551 | - if ( ! empty( $node->meta['html'] ) ) |
|
| 551 | + if ( ! empty($node->meta['html'])) |
|
| 552 | 552 | echo $node->meta['html']; |
| 553 | 553 | |
| 554 | 554 | ?> |
@@ -559,9 +559,9 @@ discard block |
||
| 559 | 559 | * @param string $id Unused. |
| 560 | 560 | * @param object $node |
| 561 | 561 | */ |
| 562 | - public function recursive_render( $id, $node ) { |
|
| 563 | - _deprecated_function( __METHOD__, '3.3.0', 'WP_Admin_bar::render(), WP_Admin_Bar::_render_item()' ); |
|
| 564 | - $this->_render_item( $node ); |
|
| 562 | + public function recursive_render($id, $node) { |
|
| 563 | + _deprecated_function(__METHOD__, '3.3.0', 'WP_Admin_bar::render(), WP_Admin_Bar::_render_item()'); |
|
| 564 | + $this->_render_item($node); |
|
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | /** |
@@ -569,32 +569,32 @@ discard block |
||
| 569 | 569 | */ |
| 570 | 570 | public function add_menus() { |
| 571 | 571 | // User related, aligned right. |
| 572 | - add_action( 'admin_bar_menu', 'wp_admin_bar_my_account_menu', 0 ); |
|
| 573 | - add_action( 'admin_bar_menu', 'wp_admin_bar_search_menu', 4 ); |
|
| 574 | - add_action( 'admin_bar_menu', 'wp_admin_bar_my_account_item', 7 ); |
|
| 572 | + add_action('admin_bar_menu', 'wp_admin_bar_my_account_menu', 0); |
|
| 573 | + add_action('admin_bar_menu', 'wp_admin_bar_search_menu', 4); |
|
| 574 | + add_action('admin_bar_menu', 'wp_admin_bar_my_account_item', 7); |
|
| 575 | 575 | |
| 576 | 576 | // Site related. |
| 577 | - add_action( 'admin_bar_menu', 'wp_admin_bar_sidebar_toggle', 0 ); |
|
| 578 | - add_action( 'admin_bar_menu', 'wp_admin_bar_wp_menu', 10 ); |
|
| 579 | - add_action( 'admin_bar_menu', 'wp_admin_bar_my_sites_menu', 20 ); |
|
| 580 | - add_action( 'admin_bar_menu', 'wp_admin_bar_site_menu', 30 ); |
|
| 581 | - add_action( 'admin_bar_menu', 'wp_admin_bar_customize_menu', 40 ); |
|
| 582 | - add_action( 'admin_bar_menu', 'wp_admin_bar_updates_menu', 50 ); |
|
| 577 | + add_action('admin_bar_menu', 'wp_admin_bar_sidebar_toggle', 0); |
|
| 578 | + add_action('admin_bar_menu', 'wp_admin_bar_wp_menu', 10); |
|
| 579 | + add_action('admin_bar_menu', 'wp_admin_bar_my_sites_menu', 20); |
|
| 580 | + add_action('admin_bar_menu', 'wp_admin_bar_site_menu', 30); |
|
| 581 | + add_action('admin_bar_menu', 'wp_admin_bar_customize_menu', 40); |
|
| 582 | + add_action('admin_bar_menu', 'wp_admin_bar_updates_menu', 50); |
|
| 583 | 583 | |
| 584 | 584 | // Content related. |
| 585 | - if ( ! is_network_admin() && ! is_user_admin() ) { |
|
| 586 | - add_action( 'admin_bar_menu', 'wp_admin_bar_comments_menu', 60 ); |
|
| 587 | - add_action( 'admin_bar_menu', 'wp_admin_bar_new_content_menu', 70 ); |
|
| 585 | + if ( ! is_network_admin() && ! is_user_admin()) { |
|
| 586 | + add_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60); |
|
| 587 | + add_action('admin_bar_menu', 'wp_admin_bar_new_content_menu', 70); |
|
| 588 | 588 | } |
| 589 | - add_action( 'admin_bar_menu', 'wp_admin_bar_edit_menu', 80 ); |
|
| 589 | + add_action('admin_bar_menu', 'wp_admin_bar_edit_menu', 80); |
|
| 590 | 590 | |
| 591 | - add_action( 'admin_bar_menu', 'wp_admin_bar_add_secondary_groups', 200 ); |
|
| 591 | + add_action('admin_bar_menu', 'wp_admin_bar_add_secondary_groups', 200); |
|
| 592 | 592 | |
| 593 | 593 | /** |
| 594 | 594 | * Fires after menus are added to the menu bar. |
| 595 | 595 | * |
| 596 | 596 | * @since 3.1.0 |
| 597 | 597 | */ |
| 598 | - do_action( 'add_admin_bar_menus' ); |
|
| 598 | + do_action('add_admin_bar_menus'); |
|
| 599 | 599 | } |
| 600 | 600 | } |
@@ -8,6 +8,6 @@ |
||
| 8 | 8 | * @deprecated 4.5.0 Moved to wp-includes/theme-compat/embed.php |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -_deprecated_file( basename( __FILE__ ), '4.5.0', 'wp-includes/theme-compat/embed.php' ); |
|
| 11 | +_deprecated_file(basename(__FILE__), '4.5.0', 'wp-includes/theme-compat/embed.php'); |
|
| 12 | 12 | |
| 13 | -include( ABSPATH . WPINC . '/theme-compat/embed.php' ); |
|
| 13 | +include(ABSPATH.WPINC.'/theme-compat/embed.php'); |
|
@@ -38,39 +38,39 @@ discard block |
||
| 38 | 38 | * (like inserting into an editor). Default null. |
| 39 | 39 | * @return array Width and height of what the result image should resize to. |
| 40 | 40 | */ |
| 41 | -function image_constrain_size_for_editor( $width, $height, $size = 'medium', $context = null ) { |
|
| 41 | +function image_constrain_size_for_editor($width, $height, $size = 'medium', $context = null) { |
|
| 42 | 42 | global $content_width, $_wp_additional_image_sizes; |
| 43 | 43 | |
| 44 | - if ( ! $context ) |
|
| 44 | + if ( ! $context) |
|
| 45 | 45 | $context = is_admin() ? 'edit' : 'display'; |
| 46 | 46 | |
| 47 | - if ( is_array($size) ) { |
|
| 47 | + if (is_array($size)) { |
|
| 48 | 48 | $max_width = $size[0]; |
| 49 | 49 | $max_height = $size[1]; |
| 50 | 50 | } |
| 51 | - elseif ( $size == 'thumb' || $size == 'thumbnail' ) { |
|
| 51 | + elseif ($size == 'thumb' || $size == 'thumbnail') { |
|
| 52 | 52 | $max_width = intval(get_option('thumbnail_size_w')); |
| 53 | 53 | $max_height = intval(get_option('thumbnail_size_h')); |
| 54 | 54 | // last chance thumbnail size defaults |
| 55 | - if ( !$max_width && !$max_height ) { |
|
| 55 | + if ( ! $max_width && ! $max_height) { |
|
| 56 | 56 | $max_width = 128; |
| 57 | 57 | $max_height = 96; |
| 58 | 58 | } |
| 59 | 59 | } |
| 60 | - elseif ( $size == 'medium' ) { |
|
| 60 | + elseif ($size == 'medium') { |
|
| 61 | 61 | $max_width = intval(get_option('medium_size_w')); |
| 62 | 62 | $max_height = intval(get_option('medium_size_h')); |
| 63 | 63 | |
| 64 | 64 | } |
| 65 | - elseif ( $size == 'medium_large' ) { |
|
| 66 | - $max_width = intval( get_option( 'medium_large_size_w' ) ); |
|
| 67 | - $max_height = intval( get_option( 'medium_large_size_h' ) ); |
|
| 65 | + elseif ($size == 'medium_large') { |
|
| 66 | + $max_width = intval(get_option('medium_large_size_w')); |
|
| 67 | + $max_height = intval(get_option('medium_large_size_h')); |
|
| 68 | 68 | |
| 69 | - if ( intval( $content_width ) > 0 ) { |
|
| 70 | - $max_width = min( intval( $content_width ), $max_width ); |
|
| 69 | + if (intval($content_width) > 0) { |
|
| 70 | + $max_width = min(intval($content_width), $max_width); |
|
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | - elseif ( $size == 'large' ) { |
|
| 73 | + elseif ($size == 'large') { |
|
| 74 | 74 | /* |
| 75 | 75 | * We're inserting a large size image into the editor. If it's a really |
| 76 | 76 | * big image we'll scale it down to fit reasonably within the editor |
@@ -79,14 +79,14 @@ discard block |
||
| 79 | 79 | */ |
| 80 | 80 | $max_width = intval(get_option('large_size_w')); |
| 81 | 81 | $max_height = intval(get_option('large_size_h')); |
| 82 | - if ( intval($content_width) > 0 ) { |
|
| 83 | - $max_width = min( intval($content_width), $max_width ); |
|
| 82 | + if (intval($content_width) > 0) { |
|
| 83 | + $max_width = min(intval($content_width), $max_width); |
|
| 84 | 84 | } |
| 85 | - } elseif ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) && in_array( $size, array_keys( $_wp_additional_image_sizes ) ) ) { |
|
| 86 | - $max_width = intval( $_wp_additional_image_sizes[$size]['width'] ); |
|
| 87 | - $max_height = intval( $_wp_additional_image_sizes[$size]['height'] ); |
|
| 88 | - if ( intval($content_width) > 0 && 'edit' == $context ) // Only in admin. Assume that theme authors know what they're doing. |
|
| 89 | - $max_width = min( intval($content_width), $max_width ); |
|
| 85 | + } elseif (isset($_wp_additional_image_sizes) && count($_wp_additional_image_sizes) && in_array($size, array_keys($_wp_additional_image_sizes))) { |
|
| 86 | + $max_width = intval($_wp_additional_image_sizes[$size]['width']); |
|
| 87 | + $max_height = intval($_wp_additional_image_sizes[$size]['height']); |
|
| 88 | + if (intval($content_width) > 0 && 'edit' == $context) // Only in admin. Assume that theme authors know what they're doing. |
|
| 89 | + $max_width = min(intval($content_width), $max_width); |
|
| 90 | 90 | } |
| 91 | 91 | // $size == 'full' has no constraint |
| 92 | 92 | else { |
@@ -106,9 +106,9 @@ discard block |
||
| 106 | 106 | * Possible values are 'display' (like in a theme) |
| 107 | 107 | * or 'edit' (like inserting into an editor). |
| 108 | 108 | */ |
| 109 | - list( $max_width, $max_height ) = apply_filters( 'editor_max_image_size', array( $max_width, $max_height ), $size, $context ); |
|
| 109 | + list($max_width, $max_height) = apply_filters('editor_max_image_size', array($max_width, $max_height), $size, $context); |
|
| 110 | 110 | |
| 111 | - return wp_constrain_dimensions( $width, $height, $max_width, $max_height ); |
|
| 111 | + return wp_constrain_dimensions($width, $height, $max_width, $max_height); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | * @param int|string $height Image height in pixels. |
| 129 | 129 | * @return string HTML attributes for width and, or height. |
| 130 | 130 | */ |
| 131 | -function image_hwstring( $width, $height ) { |
|
| 131 | +function image_hwstring($width, $height) { |
|
| 132 | 132 | $out = ''; |
| 133 | 133 | if ($width) |
| 134 | 134 | $out .= 'width="'.intval($width).'" '; |
@@ -162,9 +162,9 @@ discard block |
||
| 162 | 162 | * @return false|array Array containing the image URL, width, height, and boolean for whether |
| 163 | 163 | * the image is an intermediate size. False on failure. |
| 164 | 164 | */ |
| 165 | -function image_downsize( $id, $size = 'medium' ) { |
|
| 165 | +function image_downsize($id, $size = 'medium') { |
|
| 166 | 166 | |
| 167 | - if ( !wp_attachment_is_image($id) ) |
|
| 167 | + if ( ! wp_attachment_is_image($id)) |
|
| 168 | 168 | return false; |
| 169 | 169 | |
| 170 | 170 | /** |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | * @param array|string $size Size of image. Image size or array of width and height values (in that order). |
| 181 | 181 | * Default 'medium'. |
| 182 | 182 | */ |
| 183 | - if ( $out = apply_filters( 'image_downsize', false, $id, $size ) ) { |
|
| 183 | + if ($out = apply_filters('image_downsize', false, $id, $size)) { |
|
| 184 | 184 | return $out; |
| 185 | 185 | } |
| 186 | 186 | |
@@ -191,32 +191,32 @@ discard block |
||
| 191 | 191 | $img_url_basename = wp_basename($img_url); |
| 192 | 192 | |
| 193 | 193 | // try for a new style intermediate size |
| 194 | - if ( $intermediate = image_get_intermediate_size($id, $size) ) { |
|
| 194 | + if ($intermediate = image_get_intermediate_size($id, $size)) { |
|
| 195 | 195 | $img_url = str_replace($img_url_basename, $intermediate['file'], $img_url); |
| 196 | 196 | $width = $intermediate['width']; |
| 197 | 197 | $height = $intermediate['height']; |
| 198 | 198 | $is_intermediate = true; |
| 199 | 199 | } |
| 200 | - elseif ( $size == 'thumbnail' ) { |
|
| 200 | + elseif ($size == 'thumbnail') { |
|
| 201 | 201 | // fall back to the old thumbnail |
| 202 | - if ( ($thumb_file = wp_get_attachment_thumb_file($id)) && $info = getimagesize($thumb_file) ) { |
|
| 202 | + if (($thumb_file = wp_get_attachment_thumb_file($id)) && $info = getimagesize($thumb_file)) { |
|
| 203 | 203 | $img_url = str_replace($img_url_basename, wp_basename($thumb_file), $img_url); |
| 204 | 204 | $width = $info[0]; |
| 205 | 205 | $height = $info[1]; |
| 206 | 206 | $is_intermediate = true; |
| 207 | 207 | } |
| 208 | 208 | } |
| 209 | - if ( !$width && !$height && isset( $meta['width'], $meta['height'] ) ) { |
|
| 209 | + if ( ! $width && ! $height && isset($meta['width'], $meta['height'])) { |
|
| 210 | 210 | // any other type: use the real image |
| 211 | 211 | $width = $meta['width']; |
| 212 | 212 | $height = $meta['height']; |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | - if ( $img_url) { |
|
| 215 | + if ($img_url) { |
|
| 216 | 216 | // we have the actual image size, but might need to further constrain it if content_width is narrower |
| 217 | - list( $width, $height ) = image_constrain_size_for_editor( $width, $height, $size ); |
|
| 217 | + list($width, $height) = image_constrain_size_for_editor($width, $height, $size); |
|
| 218 | 218 | |
| 219 | - return array( $img_url, $width, $height, $is_intermediate ); |
|
| 219 | + return array($img_url, $width, $height, $is_intermediate); |
|
| 220 | 220 | } |
| 221 | 221 | return false; |
| 222 | 222 | |
@@ -243,12 +243,12 @@ discard block |
||
| 243 | 243 | * @param bool|array $crop Optional. Whether to crop images to specified width and height or resize. |
| 244 | 244 | * An array can specify positioning of the crop area. Default false. |
| 245 | 245 | */ |
| 246 | -function add_image_size( $name, $width = 0, $height = 0, $crop = false ) { |
|
| 246 | +function add_image_size($name, $width = 0, $height = 0, $crop = false) { |
|
| 247 | 247 | global $_wp_additional_image_sizes; |
| 248 | 248 | |
| 249 | - $_wp_additional_image_sizes[ $name ] = array( |
|
| 250 | - 'width' => absint( $width ), |
|
| 251 | - 'height' => absint( $height ), |
|
| 249 | + $_wp_additional_image_sizes[$name] = array( |
|
| 250 | + 'width' => absint($width), |
|
| 251 | + 'height' => absint($height), |
|
| 252 | 252 | 'crop' => $crop, |
| 253 | 253 | ); |
| 254 | 254 | } |
@@ -263,10 +263,10 @@ discard block |
||
| 263 | 263 | * @param string $name The image size to check. |
| 264 | 264 | * @return bool True if the image size exists, false if not. |
| 265 | 265 | */ |
| 266 | -function has_image_size( $name ) { |
|
| 266 | +function has_image_size($name) { |
|
| 267 | 267 | global $_wp_additional_image_sizes; |
| 268 | 268 | |
| 269 | - return isset( $_wp_additional_image_sizes[ $name ] ); |
|
| 269 | + return isset($_wp_additional_image_sizes[$name]); |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | /** |
@@ -279,11 +279,11 @@ discard block |
||
| 279 | 279 | * @param string $name The image size to remove. |
| 280 | 280 | * @return bool True if the image size was successfully removed, false on failure. |
| 281 | 281 | */ |
| 282 | -function remove_image_size( $name ) { |
|
| 282 | +function remove_image_size($name) { |
|
| 283 | 283 | global $_wp_additional_image_sizes; |
| 284 | 284 | |
| 285 | - if ( isset( $_wp_additional_image_sizes[ $name ] ) ) { |
|
| 286 | - unset( $_wp_additional_image_sizes[ $name ] ); |
|
| 285 | + if (isset($_wp_additional_image_sizes[$name])) { |
|
| 286 | + unset($_wp_additional_image_sizes[$name]); |
|
| 287 | 287 | return true; |
| 288 | 288 | } |
| 289 | 289 | |
@@ -302,8 +302,8 @@ discard block |
||
| 302 | 302 | * @param bool|array $crop Optional. Whether to crop images to specified width and height or resize. |
| 303 | 303 | * An array can specify positioning of the crop area. Default false. |
| 304 | 304 | */ |
| 305 | -function set_post_thumbnail_size( $width = 0, $height = 0, $crop = false ) { |
|
| 306 | - add_image_size( 'post-thumbnail', $width, $height, $crop ); |
|
| 305 | +function set_post_thumbnail_size($width = 0, $height = 0, $crop = false) { |
|
| 306 | + add_image_size('post-thumbnail', $width, $height, $crop); |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | /** |
@@ -329,14 +329,14 @@ discard block |
||
| 329 | 329 | * (in that order). Default 'medium'. |
| 330 | 330 | * @return string HTML IMG element for given image attachment |
| 331 | 331 | */ |
| 332 | -function get_image_tag( $id, $alt, $title, $align, $size = 'medium' ) { |
|
| 332 | +function get_image_tag($id, $alt, $title, $align, $size = 'medium') { |
|
| 333 | 333 | |
| 334 | - list( $img_src, $width, $height ) = image_downsize($id, $size); |
|
| 334 | + list($img_src, $width, $height) = image_downsize($id, $size); |
|
| 335 | 335 | $hwstring = image_hwstring($width, $height); |
| 336 | 336 | |
| 337 | - $title = $title ? 'title="' . esc_attr( $title ) . '" ' : ''; |
|
| 337 | + $title = $title ? 'title="'.esc_attr($title).'" ' : ''; |
|
| 338 | 338 | |
| 339 | - $class = 'align' . esc_attr($align) .' size-' . esc_attr($size) . ' wp-image-' . $id; |
|
| 339 | + $class = 'align'.esc_attr($align).' size-'.esc_attr($size).' wp-image-'.$id; |
|
| 340 | 340 | |
| 341 | 341 | /** |
| 342 | 342 | * Filters the value of the attachment's image tag class attribute. |
@@ -349,9 +349,9 @@ discard block |
||
| 349 | 349 | * @param string|array $size Size of image. Image size or array of width and height values (in that order). |
| 350 | 350 | * Default 'medium'. |
| 351 | 351 | */ |
| 352 | - $class = apply_filters( 'get_image_tag_class', $class, $id, $align, $size ); |
|
| 352 | + $class = apply_filters('get_image_tag_class', $class, $id, $align, $size); |
|
| 353 | 353 | |
| 354 | - $html = '<img src="' . esc_attr($img_src) . '" alt="' . esc_attr($alt) . '" ' . $title . $hwstring . 'class="' . $class . '" />'; |
|
| 354 | + $html = '<img src="'.esc_attr($img_src).'" alt="'.esc_attr($alt).'" '.$title.$hwstring.'class="'.$class.'" />'; |
|
| 355 | 355 | |
| 356 | 356 | /** |
| 357 | 357 | * Filters the HTML content for the image tag. |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | * @param string|array $size Size of image. Image size or array of width and height values (in that order). |
| 367 | 367 | * Default 'medium'. |
| 368 | 368 | */ |
| 369 | - return apply_filters( 'get_image_tag', $html, $id, $alt, $title, $align, $size ); |
|
| 369 | + return apply_filters('get_image_tag', $html, $id, $alt, $title, $align, $size); |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | /** |
@@ -383,28 +383,28 @@ discard block |
||
| 383 | 383 | * @param int $max_height Optional. Max height in pixels to constrain to. Default 0. |
| 384 | 384 | * @return array First item is the width, the second item is the height. |
| 385 | 385 | */ |
| 386 | -function wp_constrain_dimensions( $current_width, $current_height, $max_width = 0, $max_height = 0 ) { |
|
| 387 | - if ( !$max_width && !$max_height ) |
|
| 388 | - return array( $current_width, $current_height ); |
|
| 386 | +function wp_constrain_dimensions($current_width, $current_height, $max_width = 0, $max_height = 0) { |
|
| 387 | + if ( ! $max_width && ! $max_height) |
|
| 388 | + return array($current_width, $current_height); |
|
| 389 | 389 | |
| 390 | 390 | $width_ratio = $height_ratio = 1.0; |
| 391 | 391 | $did_width = $did_height = false; |
| 392 | 392 | |
| 393 | - if ( $max_width > 0 && $current_width > 0 && $current_width > $max_width ) { |
|
| 393 | + if ($max_width > 0 && $current_width > 0 && $current_width > $max_width) { |
|
| 394 | 394 | $width_ratio = $max_width / $current_width; |
| 395 | 395 | $did_width = true; |
| 396 | 396 | } |
| 397 | 397 | |
| 398 | - if ( $max_height > 0 && $current_height > 0 && $current_height > $max_height ) { |
|
| 398 | + if ($max_height > 0 && $current_height > 0 && $current_height > $max_height) { |
|
| 399 | 399 | $height_ratio = $max_height / $current_height; |
| 400 | 400 | $did_height = true; |
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | // Calculate the larger/smaller ratios |
| 404 | - $smaller_ratio = min( $width_ratio, $height_ratio ); |
|
| 405 | - $larger_ratio = max( $width_ratio, $height_ratio ); |
|
| 404 | + $smaller_ratio = min($width_ratio, $height_ratio); |
|
| 405 | + $larger_ratio = max($width_ratio, $height_ratio); |
|
| 406 | 406 | |
| 407 | - if ( (int) round( $current_width * $larger_ratio ) > $max_width || (int) round( $current_height * $larger_ratio ) > $max_height ) { |
|
| 407 | + if ((int) round($current_width * $larger_ratio) > $max_width || (int) round($current_height * $larger_ratio) > $max_height) { |
|
| 408 | 408 | // The larger ratio is too big. It would result in an overflow. |
| 409 | 409 | $ratio = $smaller_ratio; |
| 410 | 410 | } else { |
@@ -413,20 +413,20 @@ discard block |
||
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | // Very small dimensions may result in 0, 1 should be the minimum. |
| 416 | - $w = max ( 1, (int) round( $current_width * $ratio ) ); |
|
| 417 | - $h = max ( 1, (int) round( $current_height * $ratio ) ); |
|
| 416 | + $w = max(1, (int) round($current_width * $ratio)); |
|
| 417 | + $h = max(1, (int) round($current_height * $ratio)); |
|
| 418 | 418 | |
| 419 | 419 | // Sometimes, due to rounding, we'll end up with a result like this: 465x700 in a 177x177 box is 117x176... a pixel short |
| 420 | 420 | // We also have issues with recursive calls resulting in an ever-changing result. Constraining to the result of a constraint should yield the original result. |
| 421 | 421 | // Thus we look for dimensions that are one pixel shy of the max value and bump them up |
| 422 | 422 | |
| 423 | 423 | // Note: $did_width means it is possible $smaller_ratio == $width_ratio. |
| 424 | - if ( $did_width && $w == $max_width - 1 ) { |
|
| 424 | + if ($did_width && $w == $max_width - 1) { |
|
| 425 | 425 | $w = $max_width; // Round it up |
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | // Note: $did_height means it is possible $smaller_ratio == $height_ratio. |
| 429 | - if ( $did_height && $h == $max_height - 1 ) { |
|
| 429 | + if ($did_height && $h == $max_height - 1) { |
|
| 430 | 430 | $h = $max_height; // Round it up |
| 431 | 431 | } |
| 432 | 432 | |
@@ -441,7 +441,7 @@ discard block |
||
| 441 | 441 | * @param int $max_width The maximum width permitted. |
| 442 | 442 | * @param int $max_height The maximum height permitted. |
| 443 | 443 | */ |
| 444 | - return apply_filters( 'wp_constrain_dimensions', array( $w, $h ), $current_width, $current_height, $max_width, $max_height ); |
|
| 444 | + return apply_filters('wp_constrain_dimensions', array($w, $h), $current_width, $current_height, $max_width, $max_height); |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | /** |
@@ -468,7 +468,7 @@ discard block |
||
| 468 | 468 | * An array can specify positioning of the crop area. Default false. |
| 469 | 469 | * @return false|array False on failure. Returned array matches parameters for `imagecopyresampled()`. |
| 470 | 470 | */ |
| 471 | -function image_resize_dimensions( $orig_w, $orig_h, $dest_w, $dest_h, $crop = false ) { |
|
| 471 | +function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = false) { |
|
| 472 | 472 | |
| 473 | 473 | if ($orig_w <= 0 || $orig_h <= 0) |
| 474 | 474 | return false; |
@@ -492,22 +492,22 @@ discard block |
||
| 492 | 492 | * @param bool|array $crop Whether to crop image to specified width and height or resize. |
| 493 | 493 | * An array can specify positioning of the crop area. Default false. |
| 494 | 494 | */ |
| 495 | - $output = apply_filters( 'image_resize_dimensions', null, $orig_w, $orig_h, $dest_w, $dest_h, $crop ); |
|
| 496 | - if ( null !== $output ) |
|
| 495 | + $output = apply_filters('image_resize_dimensions', null, $orig_w, $orig_h, $dest_w, $dest_h, $crop); |
|
| 496 | + if (null !== $output) |
|
| 497 | 497 | return $output; |
| 498 | 498 | |
| 499 | - if ( $crop ) { |
|
| 499 | + if ($crop) { |
|
| 500 | 500 | // crop the largest possible portion of the original image that we can size to $dest_w x $dest_h |
| 501 | 501 | $aspect_ratio = $orig_w / $orig_h; |
| 502 | 502 | $new_w = min($dest_w, $orig_w); |
| 503 | 503 | $new_h = min($dest_h, $orig_h); |
| 504 | 504 | |
| 505 | - if ( ! $new_w ) { |
|
| 506 | - $new_w = (int) round( $new_h * $aspect_ratio ); |
|
| 505 | + if ( ! $new_w) { |
|
| 506 | + $new_w = (int) round($new_h * $aspect_ratio); |
|
| 507 | 507 | } |
| 508 | 508 | |
| 509 | - if ( ! $new_h ) { |
|
| 510 | - $new_h = (int) round( $new_w / $aspect_ratio ); |
|
| 509 | + if ( ! $new_h) { |
|
| 510 | + $new_h = (int) round($new_w / $aspect_ratio); |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | $size_ratio = max($new_w / $orig_w, $new_h / $orig_h); |
@@ -515,26 +515,26 @@ discard block |
||
| 515 | 515 | $crop_w = round($new_w / $size_ratio); |
| 516 | 516 | $crop_h = round($new_h / $size_ratio); |
| 517 | 517 | |
| 518 | - if ( ! is_array( $crop ) || count( $crop ) !== 2 ) { |
|
| 519 | - $crop = array( 'center', 'center' ); |
|
| 518 | + if ( ! is_array($crop) || count($crop) !== 2) { |
|
| 519 | + $crop = array('center', 'center'); |
|
| 520 | 520 | } |
| 521 | 521 | |
| 522 | - list( $x, $y ) = $crop; |
|
| 522 | + list($x, $y) = $crop; |
|
| 523 | 523 | |
| 524 | - if ( 'left' === $x ) { |
|
| 524 | + if ('left' === $x) { |
|
| 525 | 525 | $s_x = 0; |
| 526 | - } elseif ( 'right' === $x ) { |
|
| 526 | + } elseif ('right' === $x) { |
|
| 527 | 527 | $s_x = $orig_w - $crop_w; |
| 528 | 528 | } else { |
| 529 | - $s_x = floor( ( $orig_w - $crop_w ) / 2 ); |
|
| 529 | + $s_x = floor(($orig_w - $crop_w) / 2); |
|
| 530 | 530 | } |
| 531 | 531 | |
| 532 | - if ( 'top' === $y ) { |
|
| 532 | + if ('top' === $y) { |
|
| 533 | 533 | $s_y = 0; |
| 534 | - } elseif ( 'bottom' === $y ) { |
|
| 534 | + } elseif ('bottom' === $y) { |
|
| 535 | 535 | $s_y = $orig_h - $crop_h; |
| 536 | 536 | } else { |
| 537 | - $s_y = floor( ( $orig_h - $crop_h ) / 2 ); |
|
| 537 | + $s_y = floor(($orig_h - $crop_h) / 2); |
|
| 538 | 538 | } |
| 539 | 539 | } else { |
| 540 | 540 | // don't crop, just resize using $dest_w x $dest_h as a maximum bounding box |
@@ -544,17 +544,17 @@ discard block |
||
| 544 | 544 | $s_x = 0; |
| 545 | 545 | $s_y = 0; |
| 546 | 546 | |
| 547 | - list( $new_w, $new_h ) = wp_constrain_dimensions( $orig_w, $orig_h, $dest_w, $dest_h ); |
|
| 547 | + list($new_w, $new_h) = wp_constrain_dimensions($orig_w, $orig_h, $dest_w, $dest_h); |
|
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | // if the resulting image would be the same size or larger we don't want to resize it |
| 551 | - if ( $new_w >= $orig_w && $new_h >= $orig_h && $dest_w != $orig_w && $dest_h != $orig_h ) { |
|
| 551 | + if ($new_w >= $orig_w && $new_h >= $orig_h && $dest_w != $orig_w && $dest_h != $orig_h) { |
|
| 552 | 552 | return false; |
| 553 | 553 | } |
| 554 | 554 | |
| 555 | 555 | // the return array matches the parameters to imagecopyresampled() |
| 556 | 556 | // int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h |
| 557 | - return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h ); |
|
| 557 | + return array(0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h); |
|
| 558 | 558 | |
| 559 | 559 | } |
| 560 | 560 | |
@@ -574,17 +574,17 @@ discard block |
||
| 574 | 574 | * Default false. |
| 575 | 575 | * @return false|array False, if no image was created. Metadata array on success. |
| 576 | 576 | */ |
| 577 | -function image_make_intermediate_size( $file, $width, $height, $crop = false ) { |
|
| 578 | - if ( $width || $height ) { |
|
| 579 | - $editor = wp_get_image_editor( $file ); |
|
| 577 | +function image_make_intermediate_size($file, $width, $height, $crop = false) { |
|
| 578 | + if ($width || $height) { |
|
| 579 | + $editor = wp_get_image_editor($file); |
|
| 580 | 580 | |
| 581 | - if ( is_wp_error( $editor ) || is_wp_error( $editor->resize( $width, $height, $crop ) ) ) |
|
| 581 | + if (is_wp_error($editor) || is_wp_error($editor->resize($width, $height, $crop))) |
|
| 582 | 582 | return false; |
| 583 | 583 | |
| 584 | 584 | $resized_file = $editor->save(); |
| 585 | 585 | |
| 586 | - if ( ! is_wp_error( $resized_file ) && $resized_file ) { |
|
| 587 | - unset( $resized_file['path'] ); |
|
| 586 | + if ( ! is_wp_error($resized_file) && $resized_file) { |
|
| 587 | + unset($resized_file['path']); |
|
| 588 | 588 | return $resized_file; |
| 589 | 589 | } |
| 590 | 590 | } |
@@ -602,21 +602,21 @@ discard block |
||
| 602 | 602 | * @param int $target_height Height of the second image in pixels. |
| 603 | 603 | * @return bool True if aspect ratios match within 1px. False if not. |
| 604 | 604 | */ |
| 605 | -function wp_image_matches_ratio( $source_width, $source_height, $target_width, $target_height ) { |
|
| 605 | +function wp_image_matches_ratio($source_width, $source_height, $target_width, $target_height) { |
|
| 606 | 606 | /* |
| 607 | 607 | * To test for varying crops, we constrain the dimensions of the larger image |
| 608 | 608 | * to the dimensions of the smaller image and see if they match. |
| 609 | 609 | */ |
| 610 | - if ( $source_width > $target_width ) { |
|
| 611 | - $constrained_size = wp_constrain_dimensions( $source_width, $source_height, $target_width ); |
|
| 612 | - $expected_size = array( $target_width, $target_height ); |
|
| 610 | + if ($source_width > $target_width) { |
|
| 611 | + $constrained_size = wp_constrain_dimensions($source_width, $source_height, $target_width); |
|
| 612 | + $expected_size = array($target_width, $target_height); |
|
| 613 | 613 | } else { |
| 614 | - $constrained_size = wp_constrain_dimensions( $target_width, $target_height, $source_width ); |
|
| 615 | - $expected_size = array( $source_width, $source_height ); |
|
| 614 | + $constrained_size = wp_constrain_dimensions($target_width, $target_height, $source_width); |
|
| 615 | + $expected_size = array($source_width, $source_height); |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | // If the image dimensions are within 1px of the expected size, we consider it a match. |
| 619 | - $matched = ( abs( $constrained_size[0] - $expected_size[0] ) <= 1 && abs( $constrained_size[1] - $expected_size[1] ) <= 1 ); |
|
| 619 | + $matched = (abs($constrained_size[0] - $expected_size[0]) <= 1 && abs($constrained_size[1] - $expected_size[1]) <= 1); |
|
| 620 | 620 | |
| 621 | 621 | return $matched; |
| 622 | 622 | } |
@@ -657,74 +657,74 @@ discard block |
||
| 657 | 657 | * @type string $url Image's URL. |
| 658 | 658 | * } |
| 659 | 659 | */ |
| 660 | -function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) { |
|
| 661 | - if ( ! $size || ! is_array( $imagedata = wp_get_attachment_metadata( $post_id ) ) || empty( $imagedata['sizes'] ) ) { |
|
| 660 | +function image_get_intermediate_size($post_id, $size = 'thumbnail') { |
|
| 661 | + if ( ! $size || ! is_array($imagedata = wp_get_attachment_metadata($post_id)) || empty($imagedata['sizes'])) { |
|
| 662 | 662 | return false; |
| 663 | 663 | } |
| 664 | 664 | |
| 665 | 665 | $data = array(); |
| 666 | 666 | |
| 667 | 667 | // Find the best match when '$size' is an array. |
| 668 | - if ( is_array( $size ) ) { |
|
| 668 | + if (is_array($size)) { |
|
| 669 | 669 | $candidates = array(); |
| 670 | 670 | |
| 671 | - foreach ( $imagedata['sizes'] as $_size => $data ) { |
|
| 671 | + foreach ($imagedata['sizes'] as $_size => $data) { |
|
| 672 | 672 | // If there's an exact match to an existing image size, short circuit. |
| 673 | - if ( $data['width'] == $size[0] && $data['height'] == $size[1] ) { |
|
| 674 | - $candidates[ $data['width'] * $data['height'] ] = $data; |
|
| 673 | + if ($data['width'] == $size[0] && $data['height'] == $size[1]) { |
|
| 674 | + $candidates[$data['width'] * $data['height']] = $data; |
|
| 675 | 675 | break; |
| 676 | 676 | } |
| 677 | 677 | |
| 678 | 678 | // If it's not an exact match, consider larger sizes with the same aspect ratio. |
| 679 | - if ( $data['width'] >= $size[0] && $data['height'] >= $size[1] ) { |
|
| 679 | + if ($data['width'] >= $size[0] && $data['height'] >= $size[1]) { |
|
| 680 | 680 | // If '0' is passed to either size, we test ratios against the original file. |
| 681 | - if ( 0 === $size[0] || 0 === $size[1] ) { |
|
| 682 | - $same_ratio = wp_image_matches_ratio( $data['width'], $data['height'], $imagedata['width'], $imagedata['height'] ); |
|
| 681 | + if (0 === $size[0] || 0 === $size[1]) { |
|
| 682 | + $same_ratio = wp_image_matches_ratio($data['width'], $data['height'], $imagedata['width'], $imagedata['height']); |
|
| 683 | 683 | } else { |
| 684 | - $same_ratio = wp_image_matches_ratio( $data['width'], $data['height'], $size[0], $size[1] ); |
|
| 684 | + $same_ratio = wp_image_matches_ratio($data['width'], $data['height'], $size[0], $size[1]); |
|
| 685 | 685 | } |
| 686 | 686 | |
| 687 | - if ( $same_ratio ) { |
|
| 688 | - $candidates[ $data['width'] * $data['height'] ] = $data; |
|
| 687 | + if ($same_ratio) { |
|
| 688 | + $candidates[$data['width'] * $data['height']] = $data; |
|
| 689 | 689 | } |
| 690 | 690 | } |
| 691 | 691 | } |
| 692 | 692 | |
| 693 | - if ( ! empty( $candidates ) ) { |
|
| 693 | + if ( ! empty($candidates)) { |
|
| 694 | 694 | // Sort the array by size if we have more than one candidate. |
| 695 | - if ( 1 < count( $candidates ) ) { |
|
| 696 | - ksort( $candidates ); |
|
| 695 | + if (1 < count($candidates)) { |
|
| 696 | + ksort($candidates); |
|
| 697 | 697 | } |
| 698 | 698 | |
| 699 | - $data = array_shift( $candidates ); |
|
| 699 | + $data = array_shift($candidates); |
|
| 700 | 700 | /* |
| 701 | 701 | * When the size requested is smaller than the thumbnail dimensions, we |
| 702 | 702 | * fall back to the thumbnail size to maintain backwards compatibility with |
| 703 | 703 | * pre 4.6 versions of WordPress. |
| 704 | 704 | */ |
| 705 | - } elseif ( ! empty( $imagedata['sizes']['thumbnail'] ) && $imagedata['sizes']['thumbnail']['width'] >= $size[0] && $imagedata['sizes']['thumbnail']['width'] >= $size[1] ) { |
|
| 705 | + } elseif ( ! empty($imagedata['sizes']['thumbnail']) && $imagedata['sizes']['thumbnail']['width'] >= $size[0] && $imagedata['sizes']['thumbnail']['width'] >= $size[1]) { |
|
| 706 | 706 | $data = $imagedata['sizes']['thumbnail']; |
| 707 | 707 | } else { |
| 708 | 708 | return false; |
| 709 | 709 | } |
| 710 | 710 | |
| 711 | 711 | // Constrain the width and height attributes to the requested values. |
| 712 | - list( $data['width'], $data['height'] ) = image_constrain_size_for_editor( $data['width'], $data['height'], $size ); |
|
| 712 | + list($data['width'], $data['height']) = image_constrain_size_for_editor($data['width'], $data['height'], $size); |
|
| 713 | 713 | |
| 714 | - } elseif ( ! empty( $imagedata['sizes'][ $size ] ) ) { |
|
| 715 | - $data = $imagedata['sizes'][ $size ]; |
|
| 714 | + } elseif ( ! empty($imagedata['sizes'][$size])) { |
|
| 715 | + $data = $imagedata['sizes'][$size]; |
|
| 716 | 716 | } |
| 717 | 717 | |
| 718 | 718 | // If we still don't have a match at this point, return false. |
| 719 | - if ( empty( $data ) ) { |
|
| 719 | + if (empty($data)) { |
|
| 720 | 720 | return false; |
| 721 | 721 | } |
| 722 | 722 | |
| 723 | 723 | // include the full filesystem path of the intermediate file |
| 724 | - if ( empty($data['path']) && !empty($data['file']) ) { |
|
| 724 | + if (empty($data['path']) && ! empty($data['file'])) { |
|
| 725 | 725 | $file_url = wp_get_attachment_url($post_id); |
| 726 | - $data['path'] = path_join( dirname($imagedata['file']), $data['file'] ); |
|
| 727 | - $data['url'] = path_join( dirname($file_url), $data['file'] ); |
|
| 726 | + $data['path'] = path_join(dirname($imagedata['file']), $data['file']); |
|
| 727 | + $data['url'] = path_join(dirname($file_url), $data['file']); |
|
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | /** |
@@ -740,7 +740,7 @@ discard block |
||
| 740 | 740 | * @param string|array $size Registered image size or flat array of initially-requested height and width |
| 741 | 741 | * dimensions (in that order). |
| 742 | 742 | */ |
| 743 | - return apply_filters( 'image_get_intermediate_size', $data, $post_id, $size ); |
|
| 743 | + return apply_filters('image_get_intermediate_size', $data, $post_id, $size); |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | 746 | /** |
@@ -755,8 +755,8 @@ discard block |
||
| 755 | 755 | function get_intermediate_image_sizes() { |
| 756 | 756 | global $_wp_additional_image_sizes; |
| 757 | 757 | $image_sizes = array('thumbnail', 'medium', 'medium_large', 'large'); // Standard sizes |
| 758 | - if ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) ) |
|
| 759 | - $image_sizes = array_merge( $image_sizes, array_keys( $_wp_additional_image_sizes ) ); |
|
| 758 | + if (isset($_wp_additional_image_sizes) && count($_wp_additional_image_sizes)) |
|
| 759 | + $image_sizes = array_merge($image_sizes, array_keys($_wp_additional_image_sizes)); |
|
| 760 | 760 | |
| 761 | 761 | /** |
| 762 | 762 | * Filters the list of intermediate image sizes. |
@@ -766,7 +766,7 @@ discard block |
||
| 766 | 766 | * @param array $image_sizes An array of intermediate image sizes. Defaults |
| 767 | 767 | * are 'thumbnail', 'medium', 'medium_large', 'large'. |
| 768 | 768 | */ |
| 769 | - return apply_filters( 'intermediate_image_sizes', $image_sizes ); |
|
| 769 | + return apply_filters('intermediate_image_sizes', $image_sizes); |
|
| 770 | 770 | } |
| 771 | 771 | |
| 772 | 772 | /** |
@@ -787,22 +787,22 @@ discard block |
||
| 787 | 787 | * @param bool $icon Optional. Whether the image should be treated as an icon. Default false. |
| 788 | 788 | * @return false|array Returns an array (url, width, height, is_intermediate), or false, if no image is available. |
| 789 | 789 | */ |
| 790 | -function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon = false ) { |
|
| 790 | +function wp_get_attachment_image_src($attachment_id, $size = 'thumbnail', $icon = false) { |
|
| 791 | 791 | // get a thumbnail or intermediate image if there is one |
| 792 | - $image = image_downsize( $attachment_id, $size ); |
|
| 793 | - if ( ! $image ) { |
|
| 792 | + $image = image_downsize($attachment_id, $size); |
|
| 793 | + if ( ! $image) { |
|
| 794 | 794 | $src = false; |
| 795 | 795 | |
| 796 | - if ( $icon && $src = wp_mime_type_icon( $attachment_id ) ) { |
|
| 796 | + if ($icon && $src = wp_mime_type_icon($attachment_id)) { |
|
| 797 | 797 | /** This filter is documented in wp-includes/post.php */ |
| 798 | - $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' ); |
|
| 798 | + $icon_dir = apply_filters('icon_dir', ABSPATH.WPINC.'/images/media'); |
|
| 799 | 799 | |
| 800 | - $src_file = $icon_dir . '/' . wp_basename( $src ); |
|
| 801 | - @list( $width, $height ) = getimagesize( $src_file ); |
|
| 800 | + $src_file = $icon_dir.'/'.wp_basename($src); |
|
| 801 | + @list($width, $height) = getimagesize($src_file); |
|
| 802 | 802 | } |
| 803 | 803 | |
| 804 | - if ( $src && $width && $height ) { |
|
| 805 | - $image = array( $src, $width, $height ); |
|
| 804 | + if ($src && $width && $height) { |
|
| 805 | + $image = array($src, $width, $height); |
|
| 806 | 806 | } |
| 807 | 807 | } |
| 808 | 808 | /** |
@@ -816,7 +816,7 @@ discard block |
||
| 816 | 816 | * (in that order). Default 'thumbnail'. |
| 817 | 817 | * @param bool $icon Whether the image should be treated as an icon. Default false. |
| 818 | 818 | */ |
| 819 | - return apply_filters( 'wp_get_attachment_image_src', $image, $attachment_id, $size, $icon ); |
|
| 819 | + return apply_filters('wp_get_attachment_image_src', $image, $attachment_id, $size, $icon); |
|
| 820 | 820 | } |
| 821 | 821 | |
| 822 | 822 | /** |
@@ -839,39 +839,39 @@ discard block |
||
| 839 | 839 | function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = false, $attr = '') { |
| 840 | 840 | $html = ''; |
| 841 | 841 | $image = wp_get_attachment_image_src($attachment_id, $size, $icon); |
| 842 | - if ( $image ) { |
|
| 842 | + if ($image) { |
|
| 843 | 843 | list($src, $width, $height) = $image; |
| 844 | 844 | $hwstring = image_hwstring($width, $height); |
| 845 | 845 | $size_class = $size; |
| 846 | - if ( is_array( $size_class ) ) { |
|
| 847 | - $size_class = join( 'x', $size_class ); |
|
| 846 | + if (is_array($size_class)) { |
|
| 847 | + $size_class = join('x', $size_class); |
|
| 848 | 848 | } |
| 849 | 849 | $attachment = get_post($attachment_id); |
| 850 | 850 | $default_attr = array( |
| 851 | 851 | 'src' => $src, |
| 852 | 852 | 'class' => "attachment-$size_class size-$size_class", |
| 853 | - 'alt' => trim(strip_tags( get_post_meta($attachment_id, '_wp_attachment_image_alt', true) )), // Use Alt field first |
|
| 853 | + 'alt' => trim(strip_tags(get_post_meta($attachment_id, '_wp_attachment_image_alt', true))), // Use Alt field first |
|
| 854 | 854 | ); |
| 855 | - if ( empty($default_attr['alt']) ) |
|
| 856 | - $default_attr['alt'] = trim(strip_tags( $attachment->post_excerpt )); // If not, Use the Caption |
|
| 857 | - if ( empty($default_attr['alt']) ) |
|
| 858 | - $default_attr['alt'] = trim(strip_tags( $attachment->post_title )); // Finally, use the title |
|
| 855 | + if (empty($default_attr['alt'])) |
|
| 856 | + $default_attr['alt'] = trim(strip_tags($attachment->post_excerpt)); // If not, Use the Caption |
|
| 857 | + if (empty($default_attr['alt'])) |
|
| 858 | + $default_attr['alt'] = trim(strip_tags($attachment->post_title)); // Finally, use the title |
|
| 859 | 859 | |
| 860 | - $attr = wp_parse_args( $attr, $default_attr ); |
|
| 860 | + $attr = wp_parse_args($attr, $default_attr); |
|
| 861 | 861 | |
| 862 | 862 | // Generate 'srcset' and 'sizes' if not already present. |
| 863 | - if ( empty( $attr['srcset'] ) ) { |
|
| 864 | - $image_meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true ); |
|
| 863 | + if (empty($attr['srcset'])) { |
|
| 864 | + $image_meta = get_post_meta($attachment_id, '_wp_attachment_metadata', true); |
|
| 865 | 865 | |
| 866 | - if ( is_array( $image_meta ) ) { |
|
| 867 | - $size_array = array( absint( $width ), absint( $height ) ); |
|
| 868 | - $srcset = wp_calculate_image_srcset( $size_array, $src, $image_meta, $attachment_id ); |
|
| 869 | - $sizes = wp_calculate_image_sizes( $size_array, $src, $image_meta, $attachment_id ); |
|
| 866 | + if (is_array($image_meta)) { |
|
| 867 | + $size_array = array(absint($width), absint($height)); |
|
| 868 | + $srcset = wp_calculate_image_srcset($size_array, $src, $image_meta, $attachment_id); |
|
| 869 | + $sizes = wp_calculate_image_sizes($size_array, $src, $image_meta, $attachment_id); |
|
| 870 | 870 | |
| 871 | - if ( $srcset && ( $sizes || ! empty( $attr['sizes'] ) ) ) { |
|
| 871 | + if ($srcset && ($sizes || ! empty($attr['sizes']))) { |
|
| 872 | 872 | $attr['srcset'] = $srcset; |
| 873 | 873 | |
| 874 | - if ( empty( $attr['sizes'] ) ) { |
|
| 874 | + if (empty($attr['sizes'])) { |
|
| 875 | 875 | $attr['sizes'] = $sizes; |
| 876 | 876 | } |
| 877 | 877 | } |
@@ -888,11 +888,11 @@ discard block |
||
| 888 | 888 | * @param string|array $size Requested size. Image size or array of width and height values |
| 889 | 889 | * (in that order). Default 'thumbnail'. |
| 890 | 890 | */ |
| 891 | - $attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment, $size ); |
|
| 892 | - $attr = array_map( 'esc_attr', $attr ); |
|
| 891 | + $attr = apply_filters('wp_get_attachment_image_attributes', $attr, $attachment, $size); |
|
| 892 | + $attr = array_map('esc_attr', $attr); |
|
| 893 | 893 | $html = rtrim("<img $hwstring"); |
| 894 | - foreach ( $attr as $name => $value ) { |
|
| 895 | - $html .= " $name=" . '"' . $value . '"'; |
|
| 894 | + foreach ($attr as $name => $value) { |
|
| 895 | + $html .= " $name=".'"'.$value.'"'; |
|
| 896 | 896 | } |
| 897 | 897 | $html .= ' />'; |
| 898 | 898 | } |
@@ -911,9 +911,9 @@ discard block |
||
| 911 | 911 | * @param bool $icon Optional. Whether the image should be treated as an icon. Default false. |
| 912 | 912 | * @return string|false Attachment URL or false if no image is available. |
| 913 | 913 | */ |
| 914 | -function wp_get_attachment_image_url( $attachment_id, $size = 'thumbnail', $icon = false ) { |
|
| 915 | - $image = wp_get_attachment_image_src( $attachment_id, $size, $icon ); |
|
| 916 | - return isset( $image['0'] ) ? $image['0'] : false; |
|
| 914 | +function wp_get_attachment_image_url($attachment_id, $size = 'thumbnail', $icon = false) { |
|
| 915 | + $image = wp_get_attachment_image_src($attachment_id, $size, $icon); |
|
| 916 | + return isset($image['0']) ? $image['0'] : false; |
|
| 917 | 917 | } |
| 918 | 918 | |
| 919 | 919 | /** |
@@ -925,17 +925,17 @@ discard block |
||
| 925 | 925 | * @param string $file Attachment file name. |
| 926 | 926 | * @return string Attachment path relative to the upload directory. |
| 927 | 927 | */ |
| 928 | -function _wp_get_attachment_relative_path( $file ) { |
|
| 929 | - $dirname = dirname( $file ); |
|
| 928 | +function _wp_get_attachment_relative_path($file) { |
|
| 929 | + $dirname = dirname($file); |
|
| 930 | 930 | |
| 931 | - if ( '.' === $dirname ) { |
|
| 931 | + if ('.' === $dirname) { |
|
| 932 | 932 | return ''; |
| 933 | 933 | } |
| 934 | 934 | |
| 935 | - if ( false !== strpos( $dirname, 'wp-content/uploads' ) ) { |
|
| 935 | + if (false !== strpos($dirname, 'wp-content/uploads')) { |
|
| 936 | 936 | // Get the directory name relative to the upload directory (back compat for pre-2.7 uploads) |
| 937 | - $dirname = substr( $dirname, strpos( $dirname, 'wp-content/uploads' ) + 18 ); |
|
| 938 | - $dirname = ltrim( $dirname, '/' ); |
|
| 937 | + $dirname = substr($dirname, strpos($dirname, 'wp-content/uploads') + 18); |
|
| 938 | + $dirname = ltrim($dirname, '/'); |
|
| 939 | 939 | } |
| 940 | 940 | |
| 941 | 941 | return $dirname; |
@@ -954,16 +954,16 @@ discard block |
||
| 954 | 954 | * @return array|bool Array of width and height values in pixels (in that order) |
| 955 | 955 | * or false if the size doesn't exist. |
| 956 | 956 | */ |
| 957 | -function _wp_get_image_size_from_meta( $size_name, $image_meta ) { |
|
| 958 | - if ( $size_name === 'full' ) { |
|
| 957 | +function _wp_get_image_size_from_meta($size_name, $image_meta) { |
|
| 958 | + if ($size_name === 'full') { |
|
| 959 | 959 | return array( |
| 960 | - absint( $image_meta['width'] ), |
|
| 961 | - absint( $image_meta['height'] ), |
|
| 960 | + absint($image_meta['width']), |
|
| 961 | + absint($image_meta['height']), |
|
| 962 | 962 | ); |
| 963 | - } elseif ( ! empty( $image_meta['sizes'][$size_name] ) ) { |
|
| 963 | + } elseif ( ! empty($image_meta['sizes'][$size_name])) { |
|
| 964 | 964 | return array( |
| 965 | - absint( $image_meta['sizes'][$size_name]['width'] ), |
|
| 966 | - absint( $image_meta['sizes'][$size_name]['height'] ), |
|
| 965 | + absint($image_meta['sizes'][$size_name]['width']), |
|
| 966 | + absint($image_meta['sizes'][$size_name]['height']), |
|
| 967 | 967 | ); |
| 968 | 968 | } |
| 969 | 969 | |
@@ -984,22 +984,22 @@ discard block |
||
| 984 | 984 | * Default null. |
| 985 | 985 | * @return string|bool A 'srcset' value string or false. |
| 986 | 986 | */ |
| 987 | -function wp_get_attachment_image_srcset( $attachment_id, $size = 'medium', $image_meta = null ) { |
|
| 988 | - if ( ! $image = wp_get_attachment_image_src( $attachment_id, $size ) ) { |
|
| 987 | +function wp_get_attachment_image_srcset($attachment_id, $size = 'medium', $image_meta = null) { |
|
| 988 | + if ( ! $image = wp_get_attachment_image_src($attachment_id, $size)) { |
|
| 989 | 989 | return false; |
| 990 | 990 | } |
| 991 | 991 | |
| 992 | - if ( ! is_array( $image_meta ) ) { |
|
| 993 | - $image_meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true ); |
|
| 992 | + if ( ! is_array($image_meta)) { |
|
| 993 | + $image_meta = get_post_meta($attachment_id, '_wp_attachment_metadata', true); |
|
| 994 | 994 | } |
| 995 | 995 | |
| 996 | 996 | $image_src = $image[0]; |
| 997 | 997 | $size_array = array( |
| 998 | - absint( $image[1] ), |
|
| 999 | - absint( $image[2] ) |
|
| 998 | + absint($image[1]), |
|
| 999 | + absint($image[2]) |
|
| 1000 | 1000 | ); |
| 1001 | 1001 | |
| 1002 | - return wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attachment_id ); |
|
| 1002 | + return wp_calculate_image_srcset($size_array, $image_src, $image_meta, $attachment_id); |
|
| 1003 | 1003 | } |
| 1004 | 1004 | |
| 1005 | 1005 | /** |
@@ -1013,7 +1013,7 @@ discard block |
||
| 1013 | 1013 | * @param int $attachment_id Optional. The image attachment ID to pass to the filter. Default 0. |
| 1014 | 1014 | * @return string|bool The 'srcset' attribute value. False on error or when only one source exists. |
| 1015 | 1015 | */ |
| 1016 | -function wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attachment_id = 0 ) { |
|
| 1016 | +function wp_calculate_image_srcset($size_array, $image_src, $image_meta, $attachment_id = 0) { |
|
| 1017 | 1017 | /** |
| 1018 | 1018 | * Let plugins pre-filter the image meta to be able to fix inconsistencies in the stored data. |
| 1019 | 1019 | * |
@@ -1022,9 +1022,9 @@ discard block |
||
| 1022 | 1022 | * @param string $image_src The 'src' of the image. |
| 1023 | 1023 | * @param int $attachment_id The image attachment ID or 0 if not supplied. |
| 1024 | 1024 | */ |
| 1025 | - $image_meta = apply_filters( 'wp_calculate_image_srcset_meta', $image_meta, $size_array, $image_src, $attachment_id ); |
|
| 1025 | + $image_meta = apply_filters('wp_calculate_image_srcset_meta', $image_meta, $size_array, $image_src, $attachment_id); |
|
| 1026 | 1026 | |
| 1027 | - if ( empty( $image_meta['sizes'] ) || ! isset( $image_meta['file'] ) || strlen( $image_meta['file'] ) < 4 ) { |
|
| 1027 | + if (empty($image_meta['sizes']) || ! isset($image_meta['file']) || strlen($image_meta['file']) < 4) { |
|
| 1028 | 1028 | return false; |
| 1029 | 1029 | } |
| 1030 | 1030 | |
@@ -1035,43 +1035,43 @@ discard block |
||
| 1035 | 1035 | $image_height = (int) $size_array[1]; |
| 1036 | 1036 | |
| 1037 | 1037 | // Bail early if error/no width. |
| 1038 | - if ( $image_width < 1 ) { |
|
| 1038 | + if ($image_width < 1) { |
|
| 1039 | 1039 | return false; |
| 1040 | 1040 | } |
| 1041 | 1041 | |
| 1042 | - $image_basename = wp_basename( $image_meta['file'] ); |
|
| 1042 | + $image_basename = wp_basename($image_meta['file']); |
|
| 1043 | 1043 | |
| 1044 | 1044 | /* |
| 1045 | 1045 | * WordPress flattens animated GIFs into one frame when generating intermediate sizes. |
| 1046 | 1046 | * To avoid hiding animation in user content, if src is a full size GIF, a srcset attribute is not generated. |
| 1047 | 1047 | * If src is an intermediate size GIF, the full size is excluded from srcset to keep a flattened GIF from becoming animated. |
| 1048 | 1048 | */ |
| 1049 | - if ( ! isset( $image_sizes['thumbnail']['mime-type'] ) || 'image/gif' !== $image_sizes['thumbnail']['mime-type'] ) { |
|
| 1049 | + if ( ! isset($image_sizes['thumbnail']['mime-type']) || 'image/gif' !== $image_sizes['thumbnail']['mime-type']) { |
|
| 1050 | 1050 | $image_sizes[] = array( |
| 1051 | 1051 | 'width' => $image_meta['width'], |
| 1052 | 1052 | 'height' => $image_meta['height'], |
| 1053 | 1053 | 'file' => $image_basename, |
| 1054 | 1054 | ); |
| 1055 | - } elseif ( strpos( $image_src, $image_meta['file'] ) ) { |
|
| 1055 | + } elseif (strpos($image_src, $image_meta['file'])) { |
|
| 1056 | 1056 | return false; |
| 1057 | 1057 | } |
| 1058 | 1058 | |
| 1059 | 1059 | // Retrieve the uploads sub-directory from the full size image. |
| 1060 | - $dirname = _wp_get_attachment_relative_path( $image_meta['file'] ); |
|
| 1060 | + $dirname = _wp_get_attachment_relative_path($image_meta['file']); |
|
| 1061 | 1061 | |
| 1062 | - if ( $dirname ) { |
|
| 1063 | - $dirname = trailingslashit( $dirname ); |
|
| 1062 | + if ($dirname) { |
|
| 1063 | + $dirname = trailingslashit($dirname); |
|
| 1064 | 1064 | } |
| 1065 | 1065 | |
| 1066 | 1066 | $upload_dir = wp_get_upload_dir(); |
| 1067 | - $image_baseurl = trailingslashit( $upload_dir['baseurl'] ) . $dirname; |
|
| 1067 | + $image_baseurl = trailingslashit($upload_dir['baseurl']).$dirname; |
|
| 1068 | 1068 | |
| 1069 | 1069 | /* |
| 1070 | 1070 | * If currently on HTTPS, prefer HTTPS URLs when we know they're supported by the domain |
| 1071 | 1071 | * (which is to say, when they share the domain name of the current request). |
| 1072 | 1072 | */ |
| 1073 | - if ( is_ssl() && 'https' !== substr( $image_baseurl, 0, 5 ) && parse_url( $image_baseurl, PHP_URL_HOST ) === $_SERVER['HTTP_HOST'] ) { |
|
| 1074 | - $image_baseurl = set_url_scheme( $image_baseurl, 'https' ); |
|
| 1073 | + if (is_ssl() && 'https' !== substr($image_baseurl, 0, 5) && parse_url($image_baseurl, PHP_URL_HOST) === $_SERVER['HTTP_HOST']) { |
|
| 1074 | + $image_baseurl = set_url_scheme($image_baseurl, 'https'); |
|
| 1075 | 1075 | } |
| 1076 | 1076 | |
| 1077 | 1077 | /* |
@@ -1079,7 +1079,7 @@ discard block |
||
| 1079 | 1079 | * contain a unique hash. Look for that hash and use it later to filter |
| 1080 | 1080 | * out images that are leftovers from previous versions. |
| 1081 | 1081 | */ |
| 1082 | - $image_edited = preg_match( '/-e[0-9]{13}/', wp_basename( $image_src ), $image_edit_hash ); |
|
| 1082 | + $image_edited = preg_match('/-e[0-9]{13}/', wp_basename($image_src), $image_edit_hash); |
|
| 1083 | 1083 | |
| 1084 | 1084 | /** |
| 1085 | 1085 | * Filters the maximum image width to be included in a 'srcset' attribute. |
@@ -1089,7 +1089,7 @@ discard block |
||
| 1089 | 1089 | * @param int $max_width The maximum image width to be included in the 'srcset'. Default '1600'. |
| 1090 | 1090 | * @param array $size_array Array of width and height values in pixels (in that order). |
| 1091 | 1091 | */ |
| 1092 | - $max_srcset_image_width = apply_filters( 'max_srcset_image_width', 1600, $size_array ); |
|
| 1092 | + $max_srcset_image_width = apply_filters('max_srcset_image_width', 1600, $size_array); |
|
| 1093 | 1093 | |
| 1094 | 1094 | // Array to hold URL candidates. |
| 1095 | 1095 | $sources = array(); |
@@ -1105,21 +1105,21 @@ discard block |
||
| 1105 | 1105 | * Loop through available images. Only use images that are resized |
| 1106 | 1106 | * versions of the same edit. |
| 1107 | 1107 | */ |
| 1108 | - foreach ( $image_sizes as $image ) { |
|
| 1108 | + foreach ($image_sizes as $image) { |
|
| 1109 | 1109 | $is_src = false; |
| 1110 | 1110 | |
| 1111 | 1111 | // Check if image meta isn't corrupted. |
| 1112 | - if ( ! is_array( $image ) ) { |
|
| 1112 | + if ( ! is_array($image)) { |
|
| 1113 | 1113 | continue; |
| 1114 | 1114 | } |
| 1115 | 1115 | |
| 1116 | 1116 | // If the file name is part of the `src`, we've confirmed a match. |
| 1117 | - if ( ! $src_matched && false !== strpos( $image_src, $dirname . $image['file'] ) ) { |
|
| 1117 | + if ( ! $src_matched && false !== strpos($image_src, $dirname.$image['file'])) { |
|
| 1118 | 1118 | $src_matched = $is_src = true; |
| 1119 | 1119 | } |
| 1120 | 1120 | |
| 1121 | 1121 | // Filter out images that are from previous edits. |
| 1122 | - if ( $image_edited && ! strpos( $image['file'], $image_edit_hash[0] ) ) { |
|
| 1122 | + if ($image_edited && ! strpos($image['file'], $image_edit_hash[0])) { |
|
| 1123 | 1123 | continue; |
| 1124 | 1124 | } |
| 1125 | 1125 | |
@@ -1127,24 +1127,24 @@ discard block |
||
| 1127 | 1127 | * Filters out images that are wider than '$max_srcset_image_width' unless |
| 1128 | 1128 | * that file is in the 'src' attribute. |
| 1129 | 1129 | */ |
| 1130 | - if ( $max_srcset_image_width && $image['width'] > $max_srcset_image_width && ! $is_src ) { |
|
| 1130 | + if ($max_srcset_image_width && $image['width'] > $max_srcset_image_width && ! $is_src) { |
|
| 1131 | 1131 | continue; |
| 1132 | 1132 | } |
| 1133 | 1133 | |
| 1134 | 1134 | // If the image dimensions are within 1px of the expected size, use it. |
| 1135 | - if ( wp_image_matches_ratio( $image_width, $image_height, $image['width'], $image['height'] ) ) { |
|
| 1135 | + if (wp_image_matches_ratio($image_width, $image_height, $image['width'], $image['height'])) { |
|
| 1136 | 1136 | // Add the URL, descriptor, and value to the sources array to be returned. |
| 1137 | 1137 | $source = array( |
| 1138 | - 'url' => $image_baseurl . $image['file'], |
|
| 1138 | + 'url' => $image_baseurl.$image['file'], |
|
| 1139 | 1139 | 'descriptor' => 'w', |
| 1140 | 1140 | 'value' => $image['width'], |
| 1141 | 1141 | ); |
| 1142 | 1142 | |
| 1143 | 1143 | // The 'src' image has to be the first in the 'srcset', because of a bug in iOS8. See #35030. |
| 1144 | - if ( $is_src ) { |
|
| 1145 | - $sources = array( $image['width'] => $source ) + $sources; |
|
| 1144 | + if ($is_src) { |
|
| 1145 | + $sources = array($image['width'] => $source) + $sources; |
|
| 1146 | 1146 | } else { |
| 1147 | - $sources[ $image['width'] ] = $source; |
|
| 1147 | + $sources[$image['width']] = $source; |
|
| 1148 | 1148 | } |
| 1149 | 1149 | } |
| 1150 | 1150 | } |
@@ -1170,20 +1170,20 @@ discard block |
||
| 1170 | 1170 | * @param array $image_meta The image meta data as returned by 'wp_get_attachment_metadata()'. |
| 1171 | 1171 | * @param int $attachment_id Image attachment ID or 0. |
| 1172 | 1172 | */ |
| 1173 | - $sources = apply_filters( 'wp_calculate_image_srcset', $sources, $size_array, $image_src, $image_meta, $attachment_id ); |
|
| 1173 | + $sources = apply_filters('wp_calculate_image_srcset', $sources, $size_array, $image_src, $image_meta, $attachment_id); |
|
| 1174 | 1174 | |
| 1175 | 1175 | // Only return a 'srcset' value if there is more than one source. |
| 1176 | - if ( ! $src_matched || count( $sources ) < 2 ) { |
|
| 1176 | + if ( ! $src_matched || count($sources) < 2) { |
|
| 1177 | 1177 | return false; |
| 1178 | 1178 | } |
| 1179 | 1179 | |
| 1180 | 1180 | $srcset = ''; |
| 1181 | 1181 | |
| 1182 | - foreach ( $sources as $source ) { |
|
| 1183 | - $srcset .= str_replace( ' ', '%20', $source['url'] ) . ' ' . $source['value'] . $source['descriptor'] . ', '; |
|
| 1182 | + foreach ($sources as $source) { |
|
| 1183 | + $srcset .= str_replace(' ', '%20', $source['url']).' '.$source['value'].$source['descriptor'].', '; |
|
| 1184 | 1184 | } |
| 1185 | 1185 | |
| 1186 | - return rtrim( $srcset, ', ' ); |
|
| 1186 | + return rtrim($srcset, ', '); |
|
| 1187 | 1187 | } |
| 1188 | 1188 | |
| 1189 | 1189 | /** |
@@ -1200,22 +1200,22 @@ discard block |
||
| 1200 | 1200 | * Default null. |
| 1201 | 1201 | * @return string|bool A valid source size value for use in a 'sizes' attribute or false. |
| 1202 | 1202 | */ |
| 1203 | -function wp_get_attachment_image_sizes( $attachment_id, $size = 'medium', $image_meta = null ) { |
|
| 1204 | - if ( ! $image = wp_get_attachment_image_src( $attachment_id, $size ) ) { |
|
| 1203 | +function wp_get_attachment_image_sizes($attachment_id, $size = 'medium', $image_meta = null) { |
|
| 1204 | + if ( ! $image = wp_get_attachment_image_src($attachment_id, $size)) { |
|
| 1205 | 1205 | return false; |
| 1206 | 1206 | } |
| 1207 | 1207 | |
| 1208 | - if ( ! is_array( $image_meta ) ) { |
|
| 1209 | - $image_meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true ); |
|
| 1208 | + if ( ! is_array($image_meta)) { |
|
| 1209 | + $image_meta = get_post_meta($attachment_id, '_wp_attachment_metadata', true); |
|
| 1210 | 1210 | } |
| 1211 | 1211 | |
| 1212 | 1212 | $image_src = $image[0]; |
| 1213 | 1213 | $size_array = array( |
| 1214 | - absint( $image[1] ), |
|
| 1215 | - absint( $image[2] ) |
|
| 1214 | + absint($image[1]), |
|
| 1215 | + absint($image[2]) |
|
| 1216 | 1216 | ); |
| 1217 | 1217 | |
| 1218 | - return wp_calculate_image_sizes( $size_array, $image_src, $image_meta, $attachment_id ); |
|
| 1218 | + return wp_calculate_image_sizes($size_array, $image_src, $image_meta, $attachment_id); |
|
| 1219 | 1219 | } |
| 1220 | 1220 | |
| 1221 | 1221 | /** |
@@ -1232,30 +1232,30 @@ discard block |
||
| 1232 | 1232 | * is needed when using the image size name as argument for `$size`. Default 0. |
| 1233 | 1233 | * @return string|bool A valid source size value for use in a 'sizes' attribute or false. |
| 1234 | 1234 | */ |
| 1235 | -function wp_calculate_image_sizes( $size, $image_src = null, $image_meta = null, $attachment_id = 0 ) { |
|
| 1235 | +function wp_calculate_image_sizes($size, $image_src = null, $image_meta = null, $attachment_id = 0) { |
|
| 1236 | 1236 | $width = 0; |
| 1237 | 1237 | |
| 1238 | - if ( is_array( $size ) ) { |
|
| 1239 | - $width = absint( $size[0] ); |
|
| 1240 | - } elseif ( is_string( $size ) ) { |
|
| 1241 | - if ( ! $image_meta && $attachment_id ) { |
|
| 1242 | - $image_meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true ); |
|
| 1238 | + if (is_array($size)) { |
|
| 1239 | + $width = absint($size[0]); |
|
| 1240 | + } elseif (is_string($size)) { |
|
| 1241 | + if ( ! $image_meta && $attachment_id) { |
|
| 1242 | + $image_meta = get_post_meta($attachment_id, '_wp_attachment_metadata', true); |
|
| 1243 | 1243 | } |
| 1244 | 1244 | |
| 1245 | - if ( is_array( $image_meta ) ) { |
|
| 1246 | - $size_array = _wp_get_image_size_from_meta( $size, $image_meta ); |
|
| 1247 | - if ( $size_array ) { |
|
| 1248 | - $width = absint( $size_array[0] ); |
|
| 1245 | + if (is_array($image_meta)) { |
|
| 1246 | + $size_array = _wp_get_image_size_from_meta($size, $image_meta); |
|
| 1247 | + if ($size_array) { |
|
| 1248 | + $width = absint($size_array[0]); |
|
| 1249 | 1249 | } |
| 1250 | 1250 | } |
| 1251 | 1251 | } |
| 1252 | 1252 | |
| 1253 | - if ( ! $width ) { |
|
| 1253 | + if ( ! $width) { |
|
| 1254 | 1254 | return false; |
| 1255 | 1255 | } |
| 1256 | 1256 | |
| 1257 | 1257 | // Setup the default 'sizes' attribute. |
| 1258 | - $sizes = sprintf( '(max-width: %1$dpx) 100vw, %1$dpx', $width ); |
|
| 1258 | + $sizes = sprintf('(max-width: %1$dpx) 100vw, %1$dpx', $width); |
|
| 1259 | 1259 | |
| 1260 | 1260 | /** |
| 1261 | 1261 | * Filters the output of 'wp_calculate_image_sizes()'. |
@@ -1269,7 +1269,7 @@ discard block |
||
| 1269 | 1269 | * @param array|null $image_meta The image meta data as returned by wp_get_attachment_metadata() or null. |
| 1270 | 1270 | * @param int $attachment_id Image attachment ID of the original image or 0. |
| 1271 | 1271 | */ |
| 1272 | - return apply_filters( 'wp_calculate_image_sizes', $sizes, $size, $image_src, $image_meta, $attachment_id ); |
|
| 1272 | + return apply_filters('wp_calculate_image_sizes', $sizes, $size, $image_src, $image_meta, $attachment_id); |
|
| 1273 | 1273 | } |
| 1274 | 1274 | |
| 1275 | 1275 | /** |
@@ -1282,40 +1282,40 @@ discard block |
||
| 1282 | 1282 | * @param string $content The raw post content to be filtered. |
| 1283 | 1283 | * @return string Converted content with 'srcset' and 'sizes' attributes added to images. |
| 1284 | 1284 | */ |
| 1285 | -function wp_make_content_images_responsive( $content ) { |
|
| 1286 | - if ( ! preg_match_all( '/<img [^>]+>/', $content, $matches ) ) { |
|
| 1285 | +function wp_make_content_images_responsive($content) { |
|
| 1286 | + if ( ! preg_match_all('/<img [^>]+>/', $content, $matches)) { |
|
| 1287 | 1287 | return $content; |
| 1288 | 1288 | } |
| 1289 | 1289 | |
| 1290 | 1290 | $selected_images = $attachment_ids = array(); |
| 1291 | 1291 | |
| 1292 | - foreach( $matches[0] as $image ) { |
|
| 1293 | - if ( false === strpos( $image, ' srcset=' ) && preg_match( '/wp-image-([0-9]+)/i', $image, $class_id ) && |
|
| 1294 | - ( $attachment_id = absint( $class_id[1] ) ) ) { |
|
| 1292 | + foreach ($matches[0] as $image) { |
|
| 1293 | + if (false === strpos($image, ' srcset=') && preg_match('/wp-image-([0-9]+)/i', $image, $class_id) && |
|
| 1294 | + ($attachment_id = absint($class_id[1]))) { |
|
| 1295 | 1295 | |
| 1296 | 1296 | /* |
| 1297 | 1297 | * If exactly the same image tag is used more than once, overwrite it. |
| 1298 | 1298 | * All identical tags will be replaced later with 'str_replace()'. |
| 1299 | 1299 | */ |
| 1300 | - $selected_images[ $image ] = $attachment_id; |
|
| 1300 | + $selected_images[$image] = $attachment_id; |
|
| 1301 | 1301 | // Overwrite the ID when the same image is included more than once. |
| 1302 | - $attachment_ids[ $attachment_id ] = true; |
|
| 1302 | + $attachment_ids[$attachment_id] = true; |
|
| 1303 | 1303 | } |
| 1304 | 1304 | } |
| 1305 | 1305 | |
| 1306 | - if ( count( $attachment_ids ) > 1 ) { |
|
| 1306 | + if (count($attachment_ids) > 1) { |
|
| 1307 | 1307 | /* |
| 1308 | 1308 | * Warm object cache for use with 'get_post_meta()'. |
| 1309 | 1309 | * |
| 1310 | 1310 | * To avoid making a database call for each image, a single query |
| 1311 | 1311 | * warms the object cache with the meta information for all images. |
| 1312 | 1312 | */ |
| 1313 | - update_meta_cache( 'post', array_keys( $attachment_ids ) ); |
|
| 1313 | + update_meta_cache('post', array_keys($attachment_ids)); |
|
| 1314 | 1314 | } |
| 1315 | 1315 | |
| 1316 | - foreach ( $selected_images as $image => $attachment_id ) { |
|
| 1317 | - $image_meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true ); |
|
| 1318 | - $content = str_replace( $image, wp_image_add_srcset_and_sizes( $image, $image_meta, $attachment_id ), $content ); |
|
| 1316 | + foreach ($selected_images as $image => $attachment_id) { |
|
| 1317 | + $image_meta = get_post_meta($attachment_id, '_wp_attachment_metadata', true); |
|
| 1318 | + $content = str_replace($image, wp_image_add_srcset_and_sizes($image, $image_meta, $attachment_id), $content); |
|
| 1319 | 1319 | } |
| 1320 | 1320 | |
| 1321 | 1321 | return $content; |
@@ -1334,43 +1334,43 @@ discard block |
||
| 1334 | 1334 | * @param int $attachment_id Image attachment ID. |
| 1335 | 1335 | * @return string Converted 'img' element with 'srcset' and 'sizes' attributes added. |
| 1336 | 1336 | */ |
| 1337 | -function wp_image_add_srcset_and_sizes( $image, $image_meta, $attachment_id ) { |
|
| 1337 | +function wp_image_add_srcset_and_sizes($image, $image_meta, $attachment_id) { |
|
| 1338 | 1338 | // Ensure the image meta exists. |
| 1339 | - if ( empty( $image_meta['sizes'] ) ) { |
|
| 1339 | + if (empty($image_meta['sizes'])) { |
|
| 1340 | 1340 | return $image; |
| 1341 | 1341 | } |
| 1342 | 1342 | |
| 1343 | - $image_src = preg_match( '/src="([^"]+)"/', $image, $match_src ) ? $match_src[1] : ''; |
|
| 1344 | - list( $image_src ) = explode( '?', $image_src ); |
|
| 1343 | + $image_src = preg_match('/src="([^"]+)"/', $image, $match_src) ? $match_src[1] : ''; |
|
| 1344 | + list($image_src) = explode('?', $image_src); |
|
| 1345 | 1345 | |
| 1346 | 1346 | // Return early if we couldn't get the image source. |
| 1347 | - if ( ! $image_src ) { |
|
| 1347 | + if ( ! $image_src) { |
|
| 1348 | 1348 | return $image; |
| 1349 | 1349 | } |
| 1350 | 1350 | |
| 1351 | 1351 | // Bail early if an image has been inserted and later edited. |
| 1352 | - if ( preg_match( '/-e[0-9]{13}/', $image_meta['file'], $img_edit_hash ) && |
|
| 1353 | - strpos( wp_basename( $image_src ), $img_edit_hash[0] ) === false ) { |
|
| 1352 | + if (preg_match('/-e[0-9]{13}/', $image_meta['file'], $img_edit_hash) && |
|
| 1353 | + strpos(wp_basename($image_src), $img_edit_hash[0]) === false) { |
|
| 1354 | 1354 | |
| 1355 | 1355 | return $image; |
| 1356 | 1356 | } |
| 1357 | 1357 | |
| 1358 | - $width = preg_match( '/ width="([0-9]+)"/', $image, $match_width ) ? (int) $match_width[1] : 0; |
|
| 1359 | - $height = preg_match( '/ height="([0-9]+)"/', $image, $match_height ) ? (int) $match_height[1] : 0; |
|
| 1358 | + $width = preg_match('/ width="([0-9]+)"/', $image, $match_width) ? (int) $match_width[1] : 0; |
|
| 1359 | + $height = preg_match('/ height="([0-9]+)"/', $image, $match_height) ? (int) $match_height[1] : 0; |
|
| 1360 | 1360 | |
| 1361 | - if ( ! $width || ! $height ) { |
|
| 1361 | + if ( ! $width || ! $height) { |
|
| 1362 | 1362 | /* |
| 1363 | 1363 | * If attempts to parse the size value failed, attempt to use the image meta data to match |
| 1364 | 1364 | * the image file name from 'src' against the available sizes for an attachment. |
| 1365 | 1365 | */ |
| 1366 | - $image_filename = wp_basename( $image_src ); |
|
| 1366 | + $image_filename = wp_basename($image_src); |
|
| 1367 | 1367 | |
| 1368 | - if ( $image_filename === wp_basename( $image_meta['file'] ) ) { |
|
| 1368 | + if ($image_filename === wp_basename($image_meta['file'])) { |
|
| 1369 | 1369 | $width = (int) $image_meta['width']; |
| 1370 | 1370 | $height = (int) $image_meta['height']; |
| 1371 | 1371 | } else { |
| 1372 | - foreach( $image_meta['sizes'] as $image_size_data ) { |
|
| 1373 | - if ( $image_filename === $image_size_data['file'] ) { |
|
| 1372 | + foreach ($image_meta['sizes'] as $image_size_data) { |
|
| 1373 | + if ($image_filename === $image_size_data['file']) { |
|
| 1374 | 1374 | $width = (int) $image_size_data['width']; |
| 1375 | 1375 | $height = (int) $image_size_data['height']; |
| 1376 | 1376 | break; |
@@ -1379,32 +1379,32 @@ discard block |
||
| 1379 | 1379 | } |
| 1380 | 1380 | } |
| 1381 | 1381 | |
| 1382 | - if ( ! $width || ! $height ) { |
|
| 1382 | + if ( ! $width || ! $height) { |
|
| 1383 | 1383 | return $image; |
| 1384 | 1384 | } |
| 1385 | 1385 | |
| 1386 | - $size_array = array( $width, $height ); |
|
| 1387 | - $srcset = wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attachment_id ); |
|
| 1386 | + $size_array = array($width, $height); |
|
| 1387 | + $srcset = wp_calculate_image_srcset($size_array, $image_src, $image_meta, $attachment_id); |
|
| 1388 | 1388 | |
| 1389 | - if ( $srcset ) { |
|
| 1389 | + if ($srcset) { |
|
| 1390 | 1390 | // Check if there is already a 'sizes' attribute. |
| 1391 | - $sizes = strpos( $image, ' sizes=' ); |
|
| 1391 | + $sizes = strpos($image, ' sizes='); |
|
| 1392 | 1392 | |
| 1393 | - if ( ! $sizes ) { |
|
| 1394 | - $sizes = wp_calculate_image_sizes( $size_array, $image_src, $image_meta, $attachment_id ); |
|
| 1393 | + if ( ! $sizes) { |
|
| 1394 | + $sizes = wp_calculate_image_sizes($size_array, $image_src, $image_meta, $attachment_id); |
|
| 1395 | 1395 | } |
| 1396 | 1396 | } |
| 1397 | 1397 | |
| 1398 | - if ( $srcset && $sizes ) { |
|
| 1398 | + if ($srcset && $sizes) { |
|
| 1399 | 1399 | // Format the 'srcset' and 'sizes' string and escape attributes. |
| 1400 | - $attr = sprintf( ' srcset="%s"', esc_attr( $srcset ) ); |
|
| 1400 | + $attr = sprintf(' srcset="%s"', esc_attr($srcset)); |
|
| 1401 | 1401 | |
| 1402 | - if ( is_string( $sizes ) ) { |
|
| 1403 | - $attr .= sprintf( ' sizes="%s"', esc_attr( $sizes ) ); |
|
| 1402 | + if (is_string($sizes)) { |
|
| 1403 | + $attr .= sprintf(' sizes="%s"', esc_attr($sizes)); |
|
| 1404 | 1404 | } |
| 1405 | 1405 | |
| 1406 | 1406 | // Add 'srcset' and 'sizes' attributes to the image markup. |
| 1407 | - $image = preg_replace( '/<img ([^>]+?)[\/ ]*>/', '<img $1' . $attr . ' />', $image ); |
|
| 1407 | + $image = preg_replace('/<img ([^>]+?)[\/ ]*>/', '<img $1'.$attr.' />', $image); |
|
| 1408 | 1408 | } |
| 1409 | 1409 | |
| 1410 | 1410 | return $image; |
@@ -1422,7 +1422,7 @@ discard block |
||
| 1422 | 1422 | * @param array $attr Thumbnail attributes including src, class, alt, title. |
| 1423 | 1423 | * @return array Modified array of attributes including the new 'wp-post-image' class. |
| 1424 | 1424 | */ |
| 1425 | -function _wp_post_thumbnail_class_filter( $attr ) { |
|
| 1425 | +function _wp_post_thumbnail_class_filter($attr) { |
|
| 1426 | 1426 | $attr['class'] .= ' wp-post-image'; |
| 1427 | 1427 | return $attr; |
| 1428 | 1428 | } |
@@ -1436,8 +1436,8 @@ discard block |
||
| 1436 | 1436 | * |
| 1437 | 1437 | * @param array $attr Thumbnail attributes including src, class, alt, title. |
| 1438 | 1438 | */ |
| 1439 | -function _wp_post_thumbnail_class_filter_add( $attr ) { |
|
| 1440 | - add_filter( 'wp_get_attachment_image_attributes', '_wp_post_thumbnail_class_filter' ); |
|
| 1439 | +function _wp_post_thumbnail_class_filter_add($attr) { |
|
| 1440 | + add_filter('wp_get_attachment_image_attributes', '_wp_post_thumbnail_class_filter'); |
|
| 1441 | 1441 | } |
| 1442 | 1442 | |
| 1443 | 1443 | /** |
@@ -1449,8 +1449,8 @@ discard block |
||
| 1449 | 1449 | * |
| 1450 | 1450 | * @param array $attr Thumbnail attributes including src, class, alt, title. |
| 1451 | 1451 | */ |
| 1452 | -function _wp_post_thumbnail_class_filter_remove( $attr ) { |
|
| 1453 | - remove_filter( 'wp_get_attachment_image_attributes', '_wp_post_thumbnail_class_filter' ); |
|
| 1452 | +function _wp_post_thumbnail_class_filter_remove($attr) { |
|
| 1453 | + remove_filter('wp_get_attachment_image_attributes', '_wp_post_thumbnail_class_filter'); |
|
| 1454 | 1454 | } |
| 1455 | 1455 | |
| 1456 | 1456 | add_shortcode('wp_caption', 'img_caption_shortcode'); |
@@ -1481,15 +1481,15 @@ discard block |
||
| 1481 | 1481 | * @param string $content Shortcode content. |
| 1482 | 1482 | * @return string HTML content to display the caption. |
| 1483 | 1483 | */ |
| 1484 | -function img_caption_shortcode( $attr, $content = null ) { |
|
| 1484 | +function img_caption_shortcode($attr, $content = null) { |
|
| 1485 | 1485 | // New-style shortcode with the caption inside the shortcode with the link and image tags. |
| 1486 | - if ( ! isset( $attr['caption'] ) ) { |
|
| 1487 | - if ( preg_match( '#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches ) ) { |
|
| 1486 | + if ( ! isset($attr['caption'])) { |
|
| 1487 | + if (preg_match('#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches)) { |
|
| 1488 | 1488 | $content = $matches[1]; |
| 1489 | - $attr['caption'] = trim( $matches[2] ); |
|
| 1489 | + $attr['caption'] = trim($matches[2]); |
|
| 1490 | 1490 | } |
| 1491 | - } elseif ( strpos( $attr['caption'], '<' ) !== false ) { |
|
| 1492 | - $attr['caption'] = wp_kses( $attr['caption'], 'post' ); |
|
| 1491 | + } elseif (strpos($attr['caption'], '<') !== false) { |
|
| 1492 | + $attr['caption'] = wp_kses($attr['caption'], 'post'); |
|
| 1493 | 1493 | } |
| 1494 | 1494 | |
| 1495 | 1495 | /** |
@@ -1506,30 +1506,30 @@ discard block |
||
| 1506 | 1506 | * @param array $attr Attributes of the caption shortcode. |
| 1507 | 1507 | * @param string $content The image element, possibly wrapped in a hyperlink. |
| 1508 | 1508 | */ |
| 1509 | - $output = apply_filters( 'img_caption_shortcode', '', $attr, $content ); |
|
| 1510 | - if ( $output != '' ) |
|
| 1509 | + $output = apply_filters('img_caption_shortcode', '', $attr, $content); |
|
| 1510 | + if ($output != '') |
|
| 1511 | 1511 | return $output; |
| 1512 | 1512 | |
| 1513 | - $atts = shortcode_atts( array( |
|
| 1513 | + $atts = shortcode_atts(array( |
|
| 1514 | 1514 | 'id' => '', |
| 1515 | 1515 | 'align' => 'alignnone', |
| 1516 | 1516 | 'width' => '', |
| 1517 | 1517 | 'caption' => '', |
| 1518 | 1518 | 'class' => '', |
| 1519 | - ), $attr, 'caption' ); |
|
| 1519 | + ), $attr, 'caption'); |
|
| 1520 | 1520 | |
| 1521 | 1521 | $atts['width'] = (int) $atts['width']; |
| 1522 | - if ( $atts['width'] < 1 || empty( $atts['caption'] ) ) |
|
| 1522 | + if ($atts['width'] < 1 || empty($atts['caption'])) |
|
| 1523 | 1523 | return $content; |
| 1524 | 1524 | |
| 1525 | - if ( ! empty( $atts['id'] ) ) |
|
| 1526 | - $atts['id'] = 'id="' . esc_attr( sanitize_html_class( $atts['id'] ) ) . '" '; |
|
| 1525 | + if ( ! empty($atts['id'])) |
|
| 1526 | + $atts['id'] = 'id="'.esc_attr(sanitize_html_class($atts['id'])).'" '; |
|
| 1527 | 1527 | |
| 1528 | - $class = trim( 'wp-caption ' . $atts['align'] . ' ' . $atts['class'] ); |
|
| 1528 | + $class = trim('wp-caption '.$atts['align'].' '.$atts['class']); |
|
| 1529 | 1529 | |
| 1530 | - $html5 = current_theme_supports( 'html5', 'caption' ); |
|
| 1530 | + $html5 = current_theme_supports('html5', 'caption'); |
|
| 1531 | 1531 | // HTML5 captions never added the extra 10px to the image width |
| 1532 | - $width = $html5 ? $atts['width'] : ( 10 + $atts['width'] ); |
|
| 1532 | + $width = $html5 ? $atts['width'] : (10 + $atts['width']); |
|
| 1533 | 1533 | |
| 1534 | 1534 | /** |
| 1535 | 1535 | * Filters the width of an image's caption. |
@@ -1546,19 +1546,19 @@ discard block |
||
| 1546 | 1546 | * @param array $atts Attributes of the caption shortcode. |
| 1547 | 1547 | * @param string $content The image element, possibly wrapped in a hyperlink. |
| 1548 | 1548 | */ |
| 1549 | - $caption_width = apply_filters( 'img_caption_shortcode_width', $width, $atts, $content ); |
|
| 1549 | + $caption_width = apply_filters('img_caption_shortcode_width', $width, $atts, $content); |
|
| 1550 | 1550 | |
| 1551 | 1551 | $style = ''; |
| 1552 | - if ( $caption_width ) |
|
| 1553 | - $style = 'style="width: ' . (int) $caption_width . 'px" '; |
|
| 1552 | + if ($caption_width) |
|
| 1553 | + $style = 'style="width: '.(int) $caption_width.'px" '; |
|
| 1554 | 1554 | |
| 1555 | 1555 | $html = ''; |
| 1556 | - if ( $html5 ) { |
|
| 1557 | - $html = '<figure ' . $atts['id'] . $style . 'class="' . esc_attr( $class ) . '">' |
|
| 1558 | - . do_shortcode( $content ) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption></figure>'; |
|
| 1556 | + if ($html5) { |
|
| 1557 | + $html = '<figure '.$atts['id'].$style.'class="'.esc_attr($class).'">' |
|
| 1558 | + . do_shortcode($content).'<figcaption class="wp-caption-text">'.$atts['caption'].'</figcaption></figure>'; |
|
| 1559 | 1559 | } else { |
| 1560 | - $html = '<div ' . $atts['id'] . $style . 'class="' . esc_attr( $class ) . '">' |
|
| 1561 | - . do_shortcode( $content ) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>'; |
|
| 1560 | + $html = '<div '.$atts['id'].$style.'class="'.esc_attr($class).'">' |
|
| 1561 | + . do_shortcode($content).'<p class="wp-caption-text">'.$atts['caption'].'</p></div>'; |
|
| 1562 | 1562 | } |
| 1563 | 1563 | |
| 1564 | 1564 | return $html; |
@@ -1600,15 +1600,15 @@ discard block |
||
| 1600 | 1600 | * } |
| 1601 | 1601 | * @return string HTML content to display gallery. |
| 1602 | 1602 | */ |
| 1603 | -function gallery_shortcode( $attr ) { |
|
| 1603 | +function gallery_shortcode($attr) { |
|
| 1604 | 1604 | $post = get_post(); |
| 1605 | 1605 | |
| 1606 | 1606 | static $instance = 0; |
| 1607 | 1607 | $instance++; |
| 1608 | 1608 | |
| 1609 | - if ( ! empty( $attr['ids'] ) ) { |
|
| 1609 | + if ( ! empty($attr['ids'])) { |
|
| 1610 | 1610 | // 'ids' is explicitly ordered, unless you specify otherwise. |
| 1611 | - if ( empty( $attr['orderby'] ) ) { |
|
| 1611 | + if (empty($attr['orderby'])) { |
|
| 1612 | 1612 | $attr['orderby'] = 'post__in'; |
| 1613 | 1613 | } |
| 1614 | 1614 | $attr['include'] = $attr['ids']; |
@@ -1629,69 +1629,69 @@ discard block |
||
| 1629 | 1629 | * @param array $attr Attributes of the gallery shortcode. |
| 1630 | 1630 | * @param int $instance Unique numeric ID of this gallery shortcode instance. |
| 1631 | 1631 | */ |
| 1632 | - $output = apply_filters( 'post_gallery', '', $attr, $instance ); |
|
| 1633 | - if ( $output != '' ) { |
|
| 1632 | + $output = apply_filters('post_gallery', '', $attr, $instance); |
|
| 1633 | + if ($output != '') { |
|
| 1634 | 1634 | return $output; |
| 1635 | 1635 | } |
| 1636 | 1636 | |
| 1637 | - $html5 = current_theme_supports( 'html5', 'gallery' ); |
|
| 1638 | - $atts = shortcode_atts( array( |
|
| 1637 | + $html5 = current_theme_supports('html5', 'gallery'); |
|
| 1638 | + $atts = shortcode_atts(array( |
|
| 1639 | 1639 | 'order' => 'ASC', |
| 1640 | 1640 | 'orderby' => 'menu_order ID', |
| 1641 | 1641 | 'id' => $post ? $post->ID : 0, |
| 1642 | - 'itemtag' => $html5 ? 'figure' : 'dl', |
|
| 1643 | - 'icontag' => $html5 ? 'div' : 'dt', |
|
| 1642 | + 'itemtag' => $html5 ? 'figure' : 'dl', |
|
| 1643 | + 'icontag' => $html5 ? 'div' : 'dt', |
|
| 1644 | 1644 | 'captiontag' => $html5 ? 'figcaption' : 'dd', |
| 1645 | 1645 | 'columns' => 3, |
| 1646 | 1646 | 'size' => 'thumbnail', |
| 1647 | 1647 | 'include' => '', |
| 1648 | 1648 | 'exclude' => '', |
| 1649 | 1649 | 'link' => '' |
| 1650 | - ), $attr, 'gallery' ); |
|
| 1650 | + ), $attr, 'gallery'); |
|
| 1651 | 1651 | |
| 1652 | - $id = intval( $atts['id'] ); |
|
| 1652 | + $id = intval($atts['id']); |
|
| 1653 | 1653 | |
| 1654 | - if ( ! empty( $atts['include'] ) ) { |
|
| 1655 | - $_attachments = get_posts( array( 'include' => $atts['include'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) ); |
|
| 1654 | + if ( ! empty($atts['include'])) { |
|
| 1655 | + $_attachments = get_posts(array('include' => $atts['include'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'])); |
|
| 1656 | 1656 | |
| 1657 | 1657 | $attachments = array(); |
| 1658 | - foreach ( $_attachments as $key => $val ) { |
|
| 1658 | + foreach ($_attachments as $key => $val) { |
|
| 1659 | 1659 | $attachments[$val->ID] = $_attachments[$key]; |
| 1660 | 1660 | } |
| 1661 | - } elseif ( ! empty( $atts['exclude'] ) ) { |
|
| 1662 | - $attachments = get_children( array( 'post_parent' => $id, 'exclude' => $atts['exclude'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) ); |
|
| 1661 | + } elseif ( ! empty($atts['exclude'])) { |
|
| 1662 | + $attachments = get_children(array('post_parent' => $id, 'exclude' => $atts['exclude'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'])); |
|
| 1663 | 1663 | } else { |
| 1664 | - $attachments = get_children( array( 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) ); |
|
| 1664 | + $attachments = get_children(array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'])); |
|
| 1665 | 1665 | } |
| 1666 | 1666 | |
| 1667 | - if ( empty( $attachments ) ) { |
|
| 1667 | + if (empty($attachments)) { |
|
| 1668 | 1668 | return ''; |
| 1669 | 1669 | } |
| 1670 | 1670 | |
| 1671 | - if ( is_feed() ) { |
|
| 1671 | + if (is_feed()) { |
|
| 1672 | 1672 | $output = "\n"; |
| 1673 | - foreach ( $attachments as $att_id => $attachment ) { |
|
| 1674 | - $output .= wp_get_attachment_link( $att_id, $atts['size'], true ) . "\n"; |
|
| 1673 | + foreach ($attachments as $att_id => $attachment) { |
|
| 1674 | + $output .= wp_get_attachment_link($att_id, $atts['size'], true)."\n"; |
|
| 1675 | 1675 | } |
| 1676 | 1676 | return $output; |
| 1677 | 1677 | } |
| 1678 | 1678 | |
| 1679 | - $itemtag = tag_escape( $atts['itemtag'] ); |
|
| 1680 | - $captiontag = tag_escape( $atts['captiontag'] ); |
|
| 1681 | - $icontag = tag_escape( $atts['icontag'] ); |
|
| 1682 | - $valid_tags = wp_kses_allowed_html( 'post' ); |
|
| 1683 | - if ( ! isset( $valid_tags[ $itemtag ] ) ) { |
|
| 1679 | + $itemtag = tag_escape($atts['itemtag']); |
|
| 1680 | + $captiontag = tag_escape($atts['captiontag']); |
|
| 1681 | + $icontag = tag_escape($atts['icontag']); |
|
| 1682 | + $valid_tags = wp_kses_allowed_html('post'); |
|
| 1683 | + if ( ! isset($valid_tags[$itemtag])) { |
|
| 1684 | 1684 | $itemtag = 'dl'; |
| 1685 | 1685 | } |
| 1686 | - if ( ! isset( $valid_tags[ $captiontag ] ) ) { |
|
| 1686 | + if ( ! isset($valid_tags[$captiontag])) { |
|
| 1687 | 1687 | $captiontag = 'dd'; |
| 1688 | 1688 | } |
| 1689 | - if ( ! isset( $valid_tags[ $icontag ] ) ) { |
|
| 1689 | + if ( ! isset($valid_tags[$icontag])) { |
|
| 1690 | 1690 | $icontag = 'dt'; |
| 1691 | 1691 | } |
| 1692 | 1692 | |
| 1693 | - $columns = intval( $atts['columns'] ); |
|
| 1694 | - $itemwidth = $columns > 0 ? floor(100/$columns) : 100; |
|
| 1693 | + $columns = intval($atts['columns']); |
|
| 1694 | + $itemwidth = $columns > 0 ? floor(100 / $columns) : 100; |
|
| 1695 | 1695 | $float = is_rtl() ? 'right' : 'left'; |
| 1696 | 1696 | |
| 1697 | 1697 | $selector = "gallery-{$instance}"; |
@@ -1707,7 +1707,7 @@ discard block |
||
| 1707 | 1707 | * Defaults to false if the theme supports HTML5 galleries. |
| 1708 | 1708 | * Otherwise, defaults to true. |
| 1709 | 1709 | */ |
| 1710 | - if ( apply_filters( 'use_default_gallery_style', ! $html5 ) ) { |
|
| 1710 | + if (apply_filters('use_default_gallery_style', ! $html5)) { |
|
| 1711 | 1711 | $gallery_style = " |
| 1712 | 1712 | <style type='text/css'> |
| 1713 | 1713 | #{$selector} { |
@@ -1729,7 +1729,7 @@ discard block |
||
| 1729 | 1729 | </style>\n\t\t"; |
| 1730 | 1730 | } |
| 1731 | 1731 | |
| 1732 | - $size_class = sanitize_html_class( $atts['size'] ); |
|
| 1732 | + $size_class = sanitize_html_class($atts['size']); |
|
| 1733 | 1733 | $gallery_div = "<div id='$selector' class='gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}'>"; |
| 1734 | 1734 | |
| 1735 | 1735 | /** |
@@ -1740,43 +1740,43 @@ discard block |
||
| 1740 | 1740 | * @param string $gallery_style Default CSS styles and opening HTML div container |
| 1741 | 1741 | * for the gallery shortcode output. |
| 1742 | 1742 | */ |
| 1743 | - $output = apply_filters( 'gallery_style', $gallery_style . $gallery_div ); |
|
| 1743 | + $output = apply_filters('gallery_style', $gallery_style.$gallery_div); |
|
| 1744 | 1744 | |
| 1745 | 1745 | $i = 0; |
| 1746 | - foreach ( $attachments as $id => $attachment ) { |
|
| 1746 | + foreach ($attachments as $id => $attachment) { |
|
| 1747 | 1747 | |
| 1748 | - $attr = ( trim( $attachment->post_excerpt ) ) ? array( 'aria-describedby' => "$selector-$id" ) : ''; |
|
| 1749 | - if ( ! empty( $atts['link'] ) && 'file' === $atts['link'] ) { |
|
| 1750 | - $image_output = wp_get_attachment_link( $id, $atts['size'], false, false, false, $attr ); |
|
| 1751 | - } elseif ( ! empty( $atts['link'] ) && 'none' === $atts['link'] ) { |
|
| 1752 | - $image_output = wp_get_attachment_image( $id, $atts['size'], false, $attr ); |
|
| 1748 | + $attr = (trim($attachment->post_excerpt)) ? array('aria-describedby' => "$selector-$id") : ''; |
|
| 1749 | + if ( ! empty($atts['link']) && 'file' === $atts['link']) { |
|
| 1750 | + $image_output = wp_get_attachment_link($id, $atts['size'], false, false, false, $attr); |
|
| 1751 | + } elseif ( ! empty($atts['link']) && 'none' === $atts['link']) { |
|
| 1752 | + $image_output = wp_get_attachment_image($id, $atts['size'], false, $attr); |
|
| 1753 | 1753 | } else { |
| 1754 | - $image_output = wp_get_attachment_link( $id, $atts['size'], true, false, false, $attr ); |
|
| 1754 | + $image_output = wp_get_attachment_link($id, $atts['size'], true, false, false, $attr); |
|
| 1755 | 1755 | } |
| 1756 | - $image_meta = wp_get_attachment_metadata( $id ); |
|
| 1756 | + $image_meta = wp_get_attachment_metadata($id); |
|
| 1757 | 1757 | |
| 1758 | 1758 | $orientation = ''; |
| 1759 | - if ( isset( $image_meta['height'], $image_meta['width'] ) ) { |
|
| 1760 | - $orientation = ( $image_meta['height'] > $image_meta['width'] ) ? 'portrait' : 'landscape'; |
|
| 1759 | + if (isset($image_meta['height'], $image_meta['width'])) { |
|
| 1760 | + $orientation = ($image_meta['height'] > $image_meta['width']) ? 'portrait' : 'landscape'; |
|
| 1761 | 1761 | } |
| 1762 | 1762 | $output .= "<{$itemtag} class='gallery-item'>"; |
| 1763 | 1763 | $output .= " |
| 1764 | 1764 | <{$icontag} class='gallery-icon {$orientation}'> |
| 1765 | 1765 | $image_output |
| 1766 | 1766 | </{$icontag}>"; |
| 1767 | - if ( $captiontag && trim($attachment->post_excerpt) ) { |
|
| 1767 | + if ($captiontag && trim($attachment->post_excerpt)) { |
|
| 1768 | 1768 | $output .= " |
| 1769 | 1769 | <{$captiontag} class='wp-caption-text gallery-caption' id='$selector-$id'> |
| 1770 | - " . wptexturize($attachment->post_excerpt) . " |
|
| 1770 | + ".wptexturize($attachment->post_excerpt)." |
|
| 1771 | 1771 | </{$captiontag}>"; |
| 1772 | 1772 | } |
| 1773 | 1773 | $output .= "</{$itemtag}>"; |
| 1774 | - if ( ! $html5 && $columns > 0 && ++$i % $columns == 0 ) { |
|
| 1774 | + if ( ! $html5 && $columns > 0 && ++$i % $columns == 0) { |
|
| 1775 | 1775 | $output .= '<br style="clear: both" />'; |
| 1776 | 1776 | } |
| 1777 | 1777 | } |
| 1778 | 1778 | |
| 1779 | - if ( ! $html5 && $columns > 0 && $i % $columns !== 0 ) { |
|
| 1779 | + if ( ! $html5 && $columns > 0 && $i % $columns !== 0) { |
|
| 1780 | 1780 | $output .= " |
| 1781 | 1781 | <br style='clear: both' />"; |
| 1782 | 1782 | } |
@@ -1801,7 +1801,7 @@ discard block |
||
| 1801 | 1801 | <div class="wp-playlist-caption"> |
| 1802 | 1802 | <span class="wp-playlist-item-meta wp-playlist-item-title"><?php |
| 1803 | 1803 | /* translators: playlist item title */ |
| 1804 | - printf( _x( '“%s”', 'playlist item title' ), '{{ data.title }}' ); |
|
| 1804 | + printf(_x('“%s”', 'playlist item title'), '{{ data.title }}'); |
|
| 1805 | 1805 | ?></span> |
| 1806 | 1806 | <# if ( data.meta.album ) { #><span class="wp-playlist-item-meta wp-playlist-item-album">{{ data.meta.album }}</span><# } #> |
| 1807 | 1807 | <# if ( data.meta.artist ) { #><span class="wp-playlist-item-meta wp-playlist-item-artist">{{ data.meta.artist }}</span><# } #> |
@@ -1816,7 +1816,7 @@ discard block |
||
| 1816 | 1816 | <# } else { #> |
| 1817 | 1817 | <span class="wp-playlist-item-title"><?php |
| 1818 | 1818 | /* translators: playlist item title */ |
| 1819 | - printf( _x( '“%s”', 'playlist item title' ), '{{{ data.title }}}' ); |
|
| 1819 | + printf(_x('“%s”', 'playlist item title'), '{{{ data.title }}}'); |
|
| 1820 | 1820 | ?></span> |
| 1821 | 1821 | <# if ( data.artists && data.meta.artist ) { #> |
| 1822 | 1822 | <span class="wp-playlist-item-artist"> — {{ data.meta.artist }}</span> |
@@ -1838,14 +1838,14 @@ discard block |
||
| 1838 | 1838 | * |
| 1839 | 1839 | * @param string $type Type of playlist. Accepts 'audio' or 'video'. |
| 1840 | 1840 | */ |
| 1841 | -function wp_playlist_scripts( $type ) { |
|
| 1842 | - wp_enqueue_style( 'wp-mediaelement' ); |
|
| 1843 | - wp_enqueue_script( 'wp-playlist' ); |
|
| 1841 | +function wp_playlist_scripts($type) { |
|
| 1842 | + wp_enqueue_style('wp-mediaelement'); |
|
| 1843 | + wp_enqueue_script('wp-playlist'); |
|
| 1844 | 1844 | ?> |
| 1845 | -<!--[if lt IE 9]><script>document.createElement('<?php echo esc_js( $type ) ?>');</script><![endif]--> |
|
| 1845 | +<!--[if lt IE 9]><script>document.createElement('<?php echo esc_js($type) ?>');</script><![endif]--> |
|
| 1846 | 1846 | <?php |
| 1847 | - add_action( 'wp_footer', 'wp_underscore_playlist_templates', 0 ); |
|
| 1848 | - add_action( 'admin_footer', 'wp_underscore_playlist_templates', 0 ); |
|
| 1847 | + add_action('wp_footer', 'wp_underscore_playlist_templates', 0); |
|
| 1848 | + add_action('admin_footer', 'wp_underscore_playlist_templates', 0); |
|
| 1849 | 1849 | } |
| 1850 | 1850 | |
| 1851 | 1851 | /** |
@@ -1885,16 +1885,16 @@ discard block |
||
| 1885 | 1885 | * |
| 1886 | 1886 | * @return string Playlist output. Empty string if the passed type is unsupported. |
| 1887 | 1887 | */ |
| 1888 | -function wp_playlist_shortcode( $attr ) { |
|
| 1888 | +function wp_playlist_shortcode($attr) { |
|
| 1889 | 1889 | global $content_width; |
| 1890 | 1890 | $post = get_post(); |
| 1891 | 1891 | |
| 1892 | 1892 | static $instance = 0; |
| 1893 | 1893 | $instance++; |
| 1894 | 1894 | |
| 1895 | - if ( ! empty( $attr['ids'] ) ) { |
|
| 1895 | + if ( ! empty($attr['ids'])) { |
|
| 1896 | 1896 | // 'ids' is explicitly ordered, unless you specify otherwise. |
| 1897 | - if ( empty( $attr['orderby'] ) ) { |
|
| 1897 | + if (empty($attr['orderby'])) { |
|
| 1898 | 1898 | $attr['orderby'] = 'post__in'; |
| 1899 | 1899 | } |
| 1900 | 1900 | $attr['include'] = $attr['ids']; |
@@ -1913,12 +1913,12 @@ discard block |
||
| 1913 | 1913 | * @param array $attr An array of shortcode attributes. |
| 1914 | 1914 | * @param int $instance Unique numeric ID of this playlist shortcode instance. |
| 1915 | 1915 | */ |
| 1916 | - $output = apply_filters( 'post_playlist', '', $attr, $instance ); |
|
| 1917 | - if ( $output != '' ) { |
|
| 1916 | + $output = apply_filters('post_playlist', '', $attr, $instance); |
|
| 1917 | + if ($output != '') { |
|
| 1918 | 1918 | return $output; |
| 1919 | 1919 | } |
| 1920 | 1920 | |
| 1921 | - $atts = shortcode_atts( array( |
|
| 1921 | + $atts = shortcode_atts(array( |
|
| 1922 | 1922 | 'type' => 'audio', |
| 1923 | 1923 | 'order' => 'ASC', |
| 1924 | 1924 | 'orderby' => 'menu_order ID', |
@@ -1930,11 +1930,11 @@ discard block |
||
| 1930 | 1930 | 'tracknumbers' => true, |
| 1931 | 1931 | 'images' => true, |
| 1932 | 1932 | 'artists' => true |
| 1933 | - ), $attr, 'playlist' ); |
|
| 1933 | + ), $attr, 'playlist'); |
|
| 1934 | 1934 | |
| 1935 | - $id = intval( $atts['id'] ); |
|
| 1935 | + $id = intval($atts['id']); |
|
| 1936 | 1936 | |
| 1937 | - if ( $atts['type'] !== 'audio' ) { |
|
| 1937 | + if ($atts['type'] !== 'audio') { |
|
| 1938 | 1938 | $atts['type'] = 'video'; |
| 1939 | 1939 | } |
| 1940 | 1940 | |
@@ -1946,31 +1946,31 @@ discard block |
||
| 1946 | 1946 | 'orderby' => $atts['orderby'] |
| 1947 | 1947 | ); |
| 1948 | 1948 | |
| 1949 | - if ( ! empty( $atts['include'] ) ) { |
|
| 1949 | + if ( ! empty($atts['include'])) { |
|
| 1950 | 1950 | $args['include'] = $atts['include']; |
| 1951 | - $_attachments = get_posts( $args ); |
|
| 1951 | + $_attachments = get_posts($args); |
|
| 1952 | 1952 | |
| 1953 | 1953 | $attachments = array(); |
| 1954 | - foreach ( $_attachments as $key => $val ) { |
|
| 1954 | + foreach ($_attachments as $key => $val) { |
|
| 1955 | 1955 | $attachments[$val->ID] = $_attachments[$key]; |
| 1956 | 1956 | } |
| 1957 | - } elseif ( ! empty( $atts['exclude'] ) ) { |
|
| 1957 | + } elseif ( ! empty($atts['exclude'])) { |
|
| 1958 | 1958 | $args['post_parent'] = $id; |
| 1959 | 1959 | $args['exclude'] = $atts['exclude']; |
| 1960 | - $attachments = get_children( $args ); |
|
| 1960 | + $attachments = get_children($args); |
|
| 1961 | 1961 | } else { |
| 1962 | 1962 | $args['post_parent'] = $id; |
| 1963 | - $attachments = get_children( $args ); |
|
| 1963 | + $attachments = get_children($args); |
|
| 1964 | 1964 | } |
| 1965 | 1965 | |
| 1966 | - if ( empty( $attachments ) ) { |
|
| 1966 | + if (empty($attachments)) { |
|
| 1967 | 1967 | return ''; |
| 1968 | 1968 | } |
| 1969 | 1969 | |
| 1970 | - if ( is_feed() ) { |
|
| 1970 | + if (is_feed()) { |
|
| 1971 | 1971 | $output = "\n"; |
| 1972 | - foreach ( $attachments as $att_id => $attachment ) { |
|
| 1973 | - $output .= wp_get_attachment_link( $att_id ) . "\n"; |
|
| 1972 | + foreach ($attachments as $att_id => $attachment) { |
|
| 1973 | + $output .= wp_get_attachment_link($att_id)."\n"; |
|
| 1974 | 1974 | } |
| 1975 | 1975 | return $output; |
| 1976 | 1976 | } |
@@ -1980,22 +1980,22 @@ discard block |
||
| 1980 | 1980 | $default_width = 640; |
| 1981 | 1981 | $default_height = 360; |
| 1982 | 1982 | |
| 1983 | - $theme_width = empty( $content_width ) ? $default_width : ( $content_width - $outer ); |
|
| 1984 | - $theme_height = empty( $content_width ) ? $default_height : round( ( $default_height * $theme_width ) / $default_width ); |
|
| 1983 | + $theme_width = empty($content_width) ? $default_width : ($content_width - $outer); |
|
| 1984 | + $theme_height = empty($content_width) ? $default_height : round(($default_height * $theme_width) / $default_width); |
|
| 1985 | 1985 | |
| 1986 | 1986 | $data = array( |
| 1987 | 1987 | 'type' => $atts['type'], |
| 1988 | 1988 | // don't pass strings to JSON, will be truthy in JS |
| 1989 | - 'tracklist' => wp_validate_boolean( $atts['tracklist'] ), |
|
| 1990 | - 'tracknumbers' => wp_validate_boolean( $atts['tracknumbers'] ), |
|
| 1991 | - 'images' => wp_validate_boolean( $atts['images'] ), |
|
| 1992 | - 'artists' => wp_validate_boolean( $atts['artists'] ), |
|
| 1989 | + 'tracklist' => wp_validate_boolean($atts['tracklist']), |
|
| 1990 | + 'tracknumbers' => wp_validate_boolean($atts['tracknumbers']), |
|
| 1991 | + 'images' => wp_validate_boolean($atts['images']), |
|
| 1992 | + 'artists' => wp_validate_boolean($atts['artists']), |
|
| 1993 | 1993 | ); |
| 1994 | 1994 | |
| 1995 | 1995 | $tracks = array(); |
| 1996 | - foreach ( $attachments as $attachment ) { |
|
| 1997 | - $url = wp_get_attachment_url( $attachment->ID ); |
|
| 1998 | - $ftype = wp_check_filetype( $url, wp_get_mime_types() ); |
|
| 1996 | + foreach ($attachments as $attachment) { |
|
| 1997 | + $url = wp_get_attachment_url($attachment->ID); |
|
| 1998 | + $ftype = wp_check_filetype($url, wp_get_mime_types()); |
|
| 1999 | 1999 | $track = array( |
| 2000 | 2000 | 'src' => $url, |
| 2001 | 2001 | 'type' => $ftype['type'], |
@@ -2005,27 +2005,27 @@ discard block |
||
| 2005 | 2005 | ); |
| 2006 | 2006 | |
| 2007 | 2007 | $track['meta'] = array(); |
| 2008 | - $meta = wp_get_attachment_metadata( $attachment->ID ); |
|
| 2009 | - if ( ! empty( $meta ) ) { |
|
| 2008 | + $meta = wp_get_attachment_metadata($attachment->ID); |
|
| 2009 | + if ( ! empty($meta)) { |
|
| 2010 | 2010 | |
| 2011 | - foreach ( wp_get_attachment_id3_keys( $attachment ) as $key => $label ) { |
|
| 2012 | - if ( ! empty( $meta[ $key ] ) ) { |
|
| 2013 | - $track['meta'][ $key ] = $meta[ $key ]; |
|
| 2011 | + foreach (wp_get_attachment_id3_keys($attachment) as $key => $label) { |
|
| 2012 | + if ( ! empty($meta[$key])) { |
|
| 2013 | + $track['meta'][$key] = $meta[$key]; |
|
| 2014 | 2014 | } |
| 2015 | 2015 | } |
| 2016 | 2016 | |
| 2017 | - if ( 'video' === $atts['type'] ) { |
|
| 2018 | - if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) { |
|
| 2017 | + if ('video' === $atts['type']) { |
|
| 2018 | + if ( ! empty($meta['width']) && ! empty($meta['height'])) { |
|
| 2019 | 2019 | $width = $meta['width']; |
| 2020 | 2020 | $height = $meta['height']; |
| 2021 | - $theme_height = round( ( $height * $theme_width ) / $width ); |
|
| 2021 | + $theme_height = round(($height * $theme_width) / $width); |
|
| 2022 | 2022 | } else { |
| 2023 | 2023 | $width = $default_width; |
| 2024 | 2024 | $height = $default_height; |
| 2025 | 2025 | } |
| 2026 | 2026 | |
| 2027 | 2027 | $track['dimensions'] = array( |
| 2028 | - 'original' => compact( 'width', 'height' ), |
|
| 2028 | + 'original' => compact('width', 'height'), |
|
| 2029 | 2029 | 'resized' => array( |
| 2030 | 2030 | 'width' => $theme_width, |
| 2031 | 2031 | 'height' => $theme_height |
@@ -2034,19 +2034,19 @@ discard block |
||
| 2034 | 2034 | } |
| 2035 | 2035 | } |
| 2036 | 2036 | |
| 2037 | - if ( $atts['images'] ) { |
|
| 2038 | - $thumb_id = get_post_thumbnail_id( $attachment->ID ); |
|
| 2039 | - if ( ! empty( $thumb_id ) ) { |
|
| 2040 | - list( $src, $width, $height ) = wp_get_attachment_image_src( $thumb_id, 'full' ); |
|
| 2041 | - $track['image'] = compact( 'src', 'width', 'height' ); |
|
| 2042 | - list( $src, $width, $height ) = wp_get_attachment_image_src( $thumb_id, 'thumbnail' ); |
|
| 2043 | - $track['thumb'] = compact( 'src', 'width', 'height' ); |
|
| 2037 | + if ($atts['images']) { |
|
| 2038 | + $thumb_id = get_post_thumbnail_id($attachment->ID); |
|
| 2039 | + if ( ! empty($thumb_id)) { |
|
| 2040 | + list($src, $width, $height) = wp_get_attachment_image_src($thumb_id, 'full'); |
|
| 2041 | + $track['image'] = compact('src', 'width', 'height'); |
|
| 2042 | + list($src, $width, $height) = wp_get_attachment_image_src($thumb_id, 'thumbnail'); |
|
| 2043 | + $track['thumb'] = compact('src', 'width', 'height'); |
|
| 2044 | 2044 | } else { |
| 2045 | - $src = wp_mime_type_icon( $attachment->ID ); |
|
| 2045 | + $src = wp_mime_type_icon($attachment->ID); |
|
| 2046 | 2046 | $width = 48; |
| 2047 | 2047 | $height = 64; |
| 2048 | - $track['image'] = compact( 'src', 'width', 'height' ); |
|
| 2049 | - $track['thumb'] = compact( 'src', 'width', 'height' ); |
|
| 2048 | + $track['image'] = compact('src', 'width', 'height'); |
|
| 2049 | + $track['thumb'] = compact('src', 'width', 'height'); |
|
| 2050 | 2050 | } |
| 2051 | 2051 | } |
| 2052 | 2052 | |
@@ -2054,12 +2054,12 @@ discard block |
||
| 2054 | 2054 | } |
| 2055 | 2055 | $data['tracks'] = $tracks; |
| 2056 | 2056 | |
| 2057 | - $safe_type = esc_attr( $atts['type'] ); |
|
| 2058 | - $safe_style = esc_attr( $atts['style'] ); |
|
| 2057 | + $safe_type = esc_attr($atts['type']); |
|
| 2058 | + $safe_style = esc_attr($atts['style']); |
|
| 2059 | 2059 | |
| 2060 | 2060 | ob_start(); |
| 2061 | 2061 | |
| 2062 | - if ( 1 === $instance ) { |
|
| 2062 | + if (1 === $instance) { |
|
| 2063 | 2063 | /** |
| 2064 | 2064 | * Prints and enqueues playlist scripts, styles, and JavaScript templates. |
| 2065 | 2065 | * |
@@ -2068,32 +2068,32 @@ discard block |
||
| 2068 | 2068 | * @param string $type Type of playlist. Possible values are 'audio' or 'video'. |
| 2069 | 2069 | * @param string $style The 'theme' for the playlist. Core provides 'light' and 'dark'. |
| 2070 | 2070 | */ |
| 2071 | - do_action( 'wp_playlist_scripts', $atts['type'], $atts['style'] ); |
|
| 2071 | + do_action('wp_playlist_scripts', $atts['type'], $atts['style']); |
|
| 2072 | 2072 | } ?> |
| 2073 | 2073 | <div class="wp-playlist wp-<?php echo $safe_type ?>-playlist wp-playlist-<?php echo $safe_style ?>"> |
| 2074 | - <?php if ( 'audio' === $atts['type'] ): ?> |
|
| 2074 | + <?php if ('audio' === $atts['type']): ?> |
|
| 2075 | 2075 | <div class="wp-playlist-current-item"></div> |
| 2076 | 2076 | <?php endif ?> |
| 2077 | 2077 | <<?php echo $safe_type ?> controls="controls" preload="none" width="<?php |
| 2078 | 2078 | echo (int) $theme_width; |
| 2079 | - ?>"<?php if ( 'video' === $safe_type ): |
|
| 2079 | + ?>"<?php if ('video' === $safe_type): |
|
| 2080 | 2080 | echo ' height="', (int) $theme_height, '"'; |
| 2081 | 2081 | endif; ?>></<?php echo $safe_type ?>> |
| 2082 | 2082 | <div class="wp-playlist-next"></div> |
| 2083 | 2083 | <div class="wp-playlist-prev"></div> |
| 2084 | 2084 | <noscript> |
| 2085 | 2085 | <ol><?php |
| 2086 | - foreach ( $attachments as $att_id => $attachment ) { |
|
| 2087 | - printf( '<li>%s</li>', wp_get_attachment_link( $att_id ) ); |
|
| 2086 | + foreach ($attachments as $att_id => $attachment) { |
|
| 2087 | + printf('<li>%s</li>', wp_get_attachment_link($att_id)); |
|
| 2088 | 2088 | } |
| 2089 | 2089 | ?></ol> |
| 2090 | 2090 | </noscript> |
| 2091 | - <script type="application/json" class="wp-playlist-script"><?php echo wp_json_encode( $data ) ?></script> |
|
| 2091 | + <script type="application/json" class="wp-playlist-script"><?php echo wp_json_encode($data) ?></script> |
|
| 2092 | 2092 | </div> |
| 2093 | 2093 | <?php |
| 2094 | 2094 | return ob_get_clean(); |
| 2095 | 2095 | } |
| 2096 | -add_shortcode( 'playlist', 'wp_playlist_shortcode' ); |
|
| 2096 | +add_shortcode('playlist', 'wp_playlist_shortcode'); |
|
| 2097 | 2097 | |
| 2098 | 2098 | /** |
| 2099 | 2099 | * Provides a No-JS Flash fallback as a last resort for audio / video. |
@@ -2103,7 +2103,7 @@ discard block |
||
| 2103 | 2103 | * @param string $url The media element URL. |
| 2104 | 2104 | * @return string Fallback HTML. |
| 2105 | 2105 | */ |
| 2106 | -function wp_mediaelement_fallback( $url ) { |
|
| 2106 | +function wp_mediaelement_fallback($url) { |
|
| 2107 | 2107 | /** |
| 2108 | 2108 | * Filters the Mediaelement fallback output for no-JS. |
| 2109 | 2109 | * |
@@ -2112,7 +2112,7 @@ discard block |
||
| 2112 | 2112 | * @param string $output Fallback output for no-JS. |
| 2113 | 2113 | * @param string $url Media file URL. |
| 2114 | 2114 | */ |
| 2115 | - return apply_filters( 'wp_mediaelement_fallback', sprintf( '<a href="%1$s">%1$s</a>', esc_url( $url ) ), $url ); |
|
| 2115 | + return apply_filters('wp_mediaelement_fallback', sprintf('<a href="%1$s">%1$s</a>', esc_url($url)), $url); |
|
| 2116 | 2116 | } |
| 2117 | 2117 | |
| 2118 | 2118 | /** |
@@ -2131,7 +2131,7 @@ discard block |
||
| 2131 | 2131 | * @param array $extensions An array of support audio formats. Defaults are |
| 2132 | 2132 | * 'mp3', 'ogg', 'wma', 'm4a', 'wav'. |
| 2133 | 2133 | */ |
| 2134 | - return apply_filters( 'wp_audio_extensions', array( 'mp3', 'ogg', 'wma', 'm4a', 'wav' ) ); |
|
| 2134 | + return apply_filters('wp_audio_extensions', array('mp3', 'ogg', 'wma', 'm4a', 'wav')); |
|
| 2135 | 2135 | } |
| 2136 | 2136 | |
| 2137 | 2137 | /** |
@@ -2143,19 +2143,19 @@ discard block |
||
| 2143 | 2143 | * @param string $context Optional. The context. Accepts 'edit', 'display'. Default 'display'. |
| 2144 | 2144 | * @return array Key/value pairs of field keys to labels. |
| 2145 | 2145 | */ |
| 2146 | -function wp_get_attachment_id3_keys( $attachment, $context = 'display' ) { |
|
| 2146 | +function wp_get_attachment_id3_keys($attachment, $context = 'display') { |
|
| 2147 | 2147 | $fields = array( |
| 2148 | - 'artist' => __( 'Artist' ), |
|
| 2149 | - 'album' => __( 'Album' ), |
|
| 2148 | + 'artist' => __('Artist'), |
|
| 2149 | + 'album' => __('Album'), |
|
| 2150 | 2150 | ); |
| 2151 | 2151 | |
| 2152 | - if ( 'display' === $context ) { |
|
| 2153 | - $fields['genre'] = __( 'Genre' ); |
|
| 2154 | - $fields['year'] = __( 'Year' ); |
|
| 2155 | - $fields['length_formatted'] = _x( 'Length', 'video or audio' ); |
|
| 2156 | - } elseif ( 'js' === $context ) { |
|
| 2157 | - $fields['bitrate'] = __( 'Bitrate' ); |
|
| 2158 | - $fields['bitrate_mode'] = __( 'Bitrate Mode' ); |
|
| 2152 | + if ('display' === $context) { |
|
| 2153 | + $fields['genre'] = __('Genre'); |
|
| 2154 | + $fields['year'] = __('Year'); |
|
| 2155 | + $fields['length_formatted'] = _x('Length', 'video or audio'); |
|
| 2156 | + } elseif ('js' === $context) { |
|
| 2157 | + $fields['bitrate'] = __('Bitrate'); |
|
| 2158 | + $fields['bitrate_mode'] = __('Bitrate Mode'); |
|
| 2159 | 2159 | } |
| 2160 | 2160 | |
| 2161 | 2161 | /** |
@@ -2167,7 +2167,7 @@ discard block |
||
| 2167 | 2167 | * @param WP_Post $attachment Attachment object. |
| 2168 | 2168 | * @param string $context The context. Accepts 'edit', 'display'. Default 'display'. |
| 2169 | 2169 | */ |
| 2170 | - return apply_filters( 'wp_get_attachment_id3_keys', $fields, $attachment, $context ); |
|
| 2170 | + return apply_filters('wp_get_attachment_id3_keys', $fields, $attachment, $context); |
|
| 2171 | 2171 | } |
| 2172 | 2172 | /** |
| 2173 | 2173 | * Builds the Audio shortcode output. |
@@ -2192,7 +2192,7 @@ discard block |
||
| 2192 | 2192 | * @param string $content Shortcode content. |
| 2193 | 2193 | * @return string|void HTML content to display audio. |
| 2194 | 2194 | */ |
| 2195 | -function wp_audio_shortcode( $attr, $content = '' ) { |
|
| 2195 | +function wp_audio_shortcode($attr, $content = '') { |
|
| 2196 | 2196 | $post_id = get_post() ? get_the_ID() : 0; |
| 2197 | 2197 | |
| 2198 | 2198 | static $instance = 0; |
@@ -2210,8 +2210,8 @@ discard block |
||
| 2210 | 2210 | * @param string $content Shortcode content. |
| 2211 | 2211 | * @param int $instance Unique numeric ID of this audio shortcode instance. |
| 2212 | 2212 | */ |
| 2213 | - $override = apply_filters( 'wp_audio_shortcode_override', '', $attr, $content, $instance ); |
|
| 2214 | - if ( '' !== $override ) { |
|
| 2213 | + $override = apply_filters('wp_audio_shortcode_override', '', $attr, $content, $instance); |
|
| 2214 | + if ('' !== $override) { |
|
| 2215 | 2215 | return $override; |
| 2216 | 2216 | } |
| 2217 | 2217 | |
@@ -2226,44 +2226,44 @@ discard block |
||
| 2226 | 2226 | 'class' => 'wp-audio-shortcode', |
| 2227 | 2227 | 'style' => 'width: 100%;' |
| 2228 | 2228 | ); |
| 2229 | - foreach ( $default_types as $type ) { |
|
| 2229 | + foreach ($default_types as $type) { |
|
| 2230 | 2230 | $defaults_atts[$type] = ''; |
| 2231 | 2231 | } |
| 2232 | 2232 | |
| 2233 | - $atts = shortcode_atts( $defaults_atts, $attr, 'audio' ); |
|
| 2233 | + $atts = shortcode_atts($defaults_atts, $attr, 'audio'); |
|
| 2234 | 2234 | |
| 2235 | 2235 | $primary = false; |
| 2236 | - if ( ! empty( $atts['src'] ) ) { |
|
| 2237 | - $type = wp_check_filetype( $atts['src'], wp_get_mime_types() ); |
|
| 2238 | - if ( ! in_array( strtolower( $type['ext'] ), $default_types ) ) { |
|
| 2239 | - return sprintf( '<a class="wp-embedded-audio" href="%s">%s</a>', esc_url( $atts['src'] ), esc_html( $atts['src'] ) ); |
|
| 2236 | + if ( ! empty($atts['src'])) { |
|
| 2237 | + $type = wp_check_filetype($atts['src'], wp_get_mime_types()); |
|
| 2238 | + if ( ! in_array(strtolower($type['ext']), $default_types)) { |
|
| 2239 | + return sprintf('<a class="wp-embedded-audio" href="%s">%s</a>', esc_url($atts['src']), esc_html($atts['src'])); |
|
| 2240 | 2240 | } |
| 2241 | 2241 | $primary = true; |
| 2242 | - array_unshift( $default_types, 'src' ); |
|
| 2242 | + array_unshift($default_types, 'src'); |
|
| 2243 | 2243 | } else { |
| 2244 | - foreach ( $default_types as $ext ) { |
|
| 2245 | - if ( ! empty( $atts[ $ext ] ) ) { |
|
| 2246 | - $type = wp_check_filetype( $atts[ $ext ], wp_get_mime_types() ); |
|
| 2247 | - if ( strtolower( $type['ext'] ) === $ext ) { |
|
| 2244 | + foreach ($default_types as $ext) { |
|
| 2245 | + if ( ! empty($atts[$ext])) { |
|
| 2246 | + $type = wp_check_filetype($atts[$ext], wp_get_mime_types()); |
|
| 2247 | + if (strtolower($type['ext']) === $ext) { |
|
| 2248 | 2248 | $primary = true; |
| 2249 | 2249 | } |
| 2250 | 2250 | } |
| 2251 | 2251 | } |
| 2252 | 2252 | } |
| 2253 | 2253 | |
| 2254 | - if ( ! $primary ) { |
|
| 2255 | - $audios = get_attached_media( 'audio', $post_id ); |
|
| 2256 | - if ( empty( $audios ) ) { |
|
| 2254 | + if ( ! $primary) { |
|
| 2255 | + $audios = get_attached_media('audio', $post_id); |
|
| 2256 | + if (empty($audios)) { |
|
| 2257 | 2257 | return; |
| 2258 | 2258 | } |
| 2259 | 2259 | |
| 2260 | - $audio = reset( $audios ); |
|
| 2261 | - $atts['src'] = wp_get_attachment_url( $audio->ID ); |
|
| 2262 | - if ( empty( $atts['src'] ) ) { |
|
| 2260 | + $audio = reset($audios); |
|
| 2261 | + $atts['src'] = wp_get_attachment_url($audio->ID); |
|
| 2262 | + if (empty($atts['src'])) { |
|
| 2263 | 2263 | return; |
| 2264 | 2264 | } |
| 2265 | 2265 | |
| 2266 | - array_unshift( $default_types, 'src' ); |
|
| 2266 | + array_unshift($default_types, 'src'); |
|
| 2267 | 2267 | } |
| 2268 | 2268 | |
| 2269 | 2269 | /** |
@@ -2273,10 +2273,10 @@ discard block |
||
| 2273 | 2273 | * |
| 2274 | 2274 | * @param string $library Media library used for the audio shortcode. |
| 2275 | 2275 | */ |
| 2276 | - $library = apply_filters( 'wp_audio_shortcode_library', 'mediaelement' ); |
|
| 2277 | - if ( 'mediaelement' === $library && did_action( 'init' ) ) { |
|
| 2278 | - wp_enqueue_style( 'wp-mediaelement' ); |
|
| 2279 | - wp_enqueue_script( 'wp-mediaelement' ); |
|
| 2276 | + $library = apply_filters('wp_audio_shortcode_library', 'mediaelement'); |
|
| 2277 | + if ('mediaelement' === $library && did_action('init')) { |
|
| 2278 | + wp_enqueue_style('wp-mediaelement'); |
|
| 2279 | + wp_enqueue_script('wp-mediaelement'); |
|
| 2280 | 2280 | } |
| 2281 | 2281 | |
| 2282 | 2282 | /** |
@@ -2286,50 +2286,50 @@ discard block |
||
| 2286 | 2286 | * |
| 2287 | 2287 | * @param string $class CSS class or list of space-separated classes. |
| 2288 | 2288 | */ |
| 2289 | - $atts['class'] = apply_filters( 'wp_audio_shortcode_class', $atts['class'] ); |
|
| 2289 | + $atts['class'] = apply_filters('wp_audio_shortcode_class', $atts['class']); |
|
| 2290 | 2290 | |
| 2291 | 2291 | $html_atts = array( |
| 2292 | 2292 | 'class' => $atts['class'], |
| 2293 | - 'id' => sprintf( 'audio-%d-%d', $post_id, $instance ), |
|
| 2294 | - 'loop' => wp_validate_boolean( $atts['loop'] ), |
|
| 2295 | - 'autoplay' => wp_validate_boolean( $atts['autoplay'] ), |
|
| 2293 | + 'id' => sprintf('audio-%d-%d', $post_id, $instance), |
|
| 2294 | + 'loop' => wp_validate_boolean($atts['loop']), |
|
| 2295 | + 'autoplay' => wp_validate_boolean($atts['autoplay']), |
|
| 2296 | 2296 | 'preload' => $atts['preload'], |
| 2297 | 2297 | 'style' => $atts['style'], |
| 2298 | 2298 | ); |
| 2299 | 2299 | |
| 2300 | 2300 | // These ones should just be omitted altogether if they are blank |
| 2301 | - foreach ( array( 'loop', 'autoplay', 'preload' ) as $a ) { |
|
| 2302 | - if ( empty( $html_atts[$a] ) ) { |
|
| 2303 | - unset( $html_atts[$a] ); |
|
| 2301 | + foreach (array('loop', 'autoplay', 'preload') as $a) { |
|
| 2302 | + if (empty($html_atts[$a])) { |
|
| 2303 | + unset($html_atts[$a]); |
|
| 2304 | 2304 | } |
| 2305 | 2305 | } |
| 2306 | 2306 | |
| 2307 | 2307 | $attr_strings = array(); |
| 2308 | - foreach ( $html_atts as $k => $v ) { |
|
| 2309 | - $attr_strings[] = $k . '="' . esc_attr( $v ) . '"'; |
|
| 2308 | + foreach ($html_atts as $k => $v) { |
|
| 2309 | + $attr_strings[] = $k.'="'.esc_attr($v).'"'; |
|
| 2310 | 2310 | } |
| 2311 | 2311 | |
| 2312 | 2312 | $html = ''; |
| 2313 | - if ( 'mediaelement' === $library && 1 === $instance ) { |
|
| 2313 | + if ('mediaelement' === $library && 1 === $instance) { |
|
| 2314 | 2314 | $html .= "<!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->\n"; |
| 2315 | 2315 | } |
| 2316 | - $html .= sprintf( '<audio %s controls="controls">', join( ' ', $attr_strings ) ); |
|
| 2316 | + $html .= sprintf('<audio %s controls="controls">', join(' ', $attr_strings)); |
|
| 2317 | 2317 | |
| 2318 | 2318 | $fileurl = ''; |
| 2319 | 2319 | $source = '<source type="%s" src="%s" />'; |
| 2320 | - foreach ( $default_types as $fallback ) { |
|
| 2321 | - if ( ! empty( $atts[ $fallback ] ) ) { |
|
| 2322 | - if ( empty( $fileurl ) ) { |
|
| 2323 | - $fileurl = $atts[ $fallback ]; |
|
| 2320 | + foreach ($default_types as $fallback) { |
|
| 2321 | + if ( ! empty($atts[$fallback])) { |
|
| 2322 | + if (empty($fileurl)) { |
|
| 2323 | + $fileurl = $atts[$fallback]; |
|
| 2324 | 2324 | } |
| 2325 | - $type = wp_check_filetype( $atts[ $fallback ], wp_get_mime_types() ); |
|
| 2326 | - $url = add_query_arg( '_', $instance, $atts[ $fallback ] ); |
|
| 2327 | - $html .= sprintf( $source, $type['type'], esc_url( $url ) ); |
|
| 2325 | + $type = wp_check_filetype($atts[$fallback], wp_get_mime_types()); |
|
| 2326 | + $url = add_query_arg('_', $instance, $atts[$fallback]); |
|
| 2327 | + $html .= sprintf($source, $type['type'], esc_url($url)); |
|
| 2328 | 2328 | } |
| 2329 | 2329 | } |
| 2330 | 2330 | |
| 2331 | - if ( 'mediaelement' === $library ) { |
|
| 2332 | - $html .= wp_mediaelement_fallback( $fileurl ); |
|
| 2331 | + if ('mediaelement' === $library) { |
|
| 2332 | + $html .= wp_mediaelement_fallback($fileurl); |
|
| 2333 | 2333 | } |
| 2334 | 2334 | $html .= '</audio>'; |
| 2335 | 2335 | |
@@ -2344,9 +2344,9 @@ discard block |
||
| 2344 | 2344 | * @param int $post_id Post ID. |
| 2345 | 2345 | * @param string $library Media library used for the audio shortcode. |
| 2346 | 2346 | */ |
| 2347 | - return apply_filters( 'wp_audio_shortcode', $html, $atts, $audio, $post_id, $library ); |
|
| 2347 | + return apply_filters('wp_audio_shortcode', $html, $atts, $audio, $post_id, $library); |
|
| 2348 | 2348 | } |
| 2349 | -add_shortcode( 'audio', 'wp_audio_shortcode' ); |
|
| 2349 | +add_shortcode('audio', 'wp_audio_shortcode'); |
|
| 2350 | 2350 | |
| 2351 | 2351 | /** |
| 2352 | 2352 | * Returns a filtered list of WP-supported video formats. |
@@ -2364,7 +2364,7 @@ discard block |
||
| 2364 | 2364 | * @param array $extensions An array of support video formats. Defaults are |
| 2365 | 2365 | * 'mp4', 'm4v', 'webm', 'ogv', 'wmv', 'flv'. |
| 2366 | 2366 | */ |
| 2367 | - return apply_filters( 'wp_video_extensions', array( 'mp4', 'm4v', 'webm', 'ogv', 'wmv', 'flv' ) ); |
|
| 2367 | + return apply_filters('wp_video_extensions', array('mp4', 'm4v', 'webm', 'ogv', 'wmv', 'flv')); |
|
| 2368 | 2368 | } |
| 2369 | 2369 | |
| 2370 | 2370 | /** |
@@ -2395,7 +2395,7 @@ discard block |
||
| 2395 | 2395 | * @param string $content Shortcode content. |
| 2396 | 2396 | * @return string|void HTML content to display video. |
| 2397 | 2397 | */ |
| 2398 | -function wp_video_shortcode( $attr, $content = '' ) { |
|
| 2398 | +function wp_video_shortcode($attr, $content = '') { |
|
| 2399 | 2399 | global $content_width; |
| 2400 | 2400 | $post_id = get_post() ? get_the_ID() : 0; |
| 2401 | 2401 | |
@@ -2417,8 +2417,8 @@ discard block |
||
| 2417 | 2417 | * @param string $content Video shortcode content. |
| 2418 | 2418 | * @param int $instance Unique numeric ID of this video shortcode instance. |
| 2419 | 2419 | */ |
| 2420 | - $override = apply_filters( 'wp_video_shortcode_override', '', $attr, $content, $instance ); |
|
| 2421 | - if ( '' !== $override ) { |
|
| 2420 | + $override = apply_filters('wp_video_shortcode_override', '', $attr, $content, $instance); |
|
| 2421 | + if ('' !== $override) { |
|
| 2422 | 2422 | return $override; |
| 2423 | 2423 | } |
| 2424 | 2424 | |
@@ -2436,22 +2436,22 @@ discard block |
||
| 2436 | 2436 | 'class' => 'wp-video-shortcode', |
| 2437 | 2437 | ); |
| 2438 | 2438 | |
| 2439 | - foreach ( $default_types as $type ) { |
|
| 2439 | + foreach ($default_types as $type) { |
|
| 2440 | 2440 | $defaults_atts[$type] = ''; |
| 2441 | 2441 | } |
| 2442 | 2442 | |
| 2443 | - $atts = shortcode_atts( $defaults_atts, $attr, 'video' ); |
|
| 2443 | + $atts = shortcode_atts($defaults_atts, $attr, 'video'); |
|
| 2444 | 2444 | |
| 2445 | - if ( is_admin() ) { |
|
| 2445 | + if (is_admin()) { |
|
| 2446 | 2446 | // shrink the video so it isn't huge in the admin |
| 2447 | - if ( $atts['width'] > $defaults_atts['width'] ) { |
|
| 2448 | - $atts['height'] = round( ( $atts['height'] * $defaults_atts['width'] ) / $atts['width'] ); |
|
| 2447 | + if ($atts['width'] > $defaults_atts['width']) { |
|
| 2448 | + $atts['height'] = round(($atts['height'] * $defaults_atts['width']) / $atts['width']); |
|
| 2449 | 2449 | $atts['width'] = $defaults_atts['width']; |
| 2450 | 2450 | } |
| 2451 | 2451 | } else { |
| 2452 | 2452 | // if the video is bigger than the theme |
| 2453 | - if ( ! empty( $content_width ) && $atts['width'] > $content_width ) { |
|
| 2454 | - $atts['height'] = round( ( $atts['height'] * $content_width ) / $atts['width'] ); |
|
| 2453 | + if ( ! empty($content_width) && $atts['width'] > $content_width) { |
|
| 2454 | + $atts['height'] = round(($atts['height'] * $content_width) / $atts['width']); |
|
| 2455 | 2455 | $atts['width'] = $content_width; |
| 2456 | 2456 | } |
| 2457 | 2457 | } |
@@ -2461,46 +2461,46 @@ discard block |
||
| 2461 | 2461 | $vimeo_pattern = '#^https?://(.+\.)?vimeo\.com/.*#'; |
| 2462 | 2462 | |
| 2463 | 2463 | $primary = false; |
| 2464 | - if ( ! empty( $atts['src'] ) ) { |
|
| 2465 | - $is_vimeo = ( preg_match( $vimeo_pattern, $atts['src'] ) ); |
|
| 2466 | - $is_youtube = ( preg_match( $yt_pattern, $atts['src'] ) ); |
|
| 2467 | - if ( ! $is_youtube && ! $is_vimeo ) { |
|
| 2468 | - $type = wp_check_filetype( $atts['src'], wp_get_mime_types() ); |
|
| 2469 | - if ( ! in_array( strtolower( $type['ext'] ), $default_types ) ) { |
|
| 2470 | - return sprintf( '<a class="wp-embedded-video" href="%s">%s</a>', esc_url( $atts['src'] ), esc_html( $atts['src'] ) ); |
|
| 2464 | + if ( ! empty($atts['src'])) { |
|
| 2465 | + $is_vimeo = (preg_match($vimeo_pattern, $atts['src'])); |
|
| 2466 | + $is_youtube = (preg_match($yt_pattern, $atts['src'])); |
|
| 2467 | + if ( ! $is_youtube && ! $is_vimeo) { |
|
| 2468 | + $type = wp_check_filetype($atts['src'], wp_get_mime_types()); |
|
| 2469 | + if ( ! in_array(strtolower($type['ext']), $default_types)) { |
|
| 2470 | + return sprintf('<a class="wp-embedded-video" href="%s">%s</a>', esc_url($atts['src']), esc_html($atts['src'])); |
|
| 2471 | 2471 | } |
| 2472 | 2472 | } |
| 2473 | 2473 | |
| 2474 | - if ( $is_vimeo ) { |
|
| 2475 | - wp_enqueue_script( 'froogaloop' ); |
|
| 2474 | + if ($is_vimeo) { |
|
| 2475 | + wp_enqueue_script('froogaloop'); |
|
| 2476 | 2476 | } |
| 2477 | 2477 | |
| 2478 | 2478 | $primary = true; |
| 2479 | - array_unshift( $default_types, 'src' ); |
|
| 2479 | + array_unshift($default_types, 'src'); |
|
| 2480 | 2480 | } else { |
| 2481 | - foreach ( $default_types as $ext ) { |
|
| 2482 | - if ( ! empty( $atts[ $ext ] ) ) { |
|
| 2483 | - $type = wp_check_filetype( $atts[ $ext ], wp_get_mime_types() ); |
|
| 2484 | - if ( strtolower( $type['ext'] ) === $ext ) { |
|
| 2481 | + foreach ($default_types as $ext) { |
|
| 2482 | + if ( ! empty($atts[$ext])) { |
|
| 2483 | + $type = wp_check_filetype($atts[$ext], wp_get_mime_types()); |
|
| 2484 | + if (strtolower($type['ext']) === $ext) { |
|
| 2485 | 2485 | $primary = true; |
| 2486 | 2486 | } |
| 2487 | 2487 | } |
| 2488 | 2488 | } |
| 2489 | 2489 | } |
| 2490 | 2490 | |
| 2491 | - if ( ! $primary ) { |
|
| 2492 | - $videos = get_attached_media( 'video', $post_id ); |
|
| 2493 | - if ( empty( $videos ) ) { |
|
| 2491 | + if ( ! $primary) { |
|
| 2492 | + $videos = get_attached_media('video', $post_id); |
|
| 2493 | + if (empty($videos)) { |
|
| 2494 | 2494 | return; |
| 2495 | 2495 | } |
| 2496 | 2496 | |
| 2497 | - $video = reset( $videos ); |
|
| 2498 | - $atts['src'] = wp_get_attachment_url( $video->ID ); |
|
| 2499 | - if ( empty( $atts['src'] ) ) { |
|
| 2497 | + $video = reset($videos); |
|
| 2498 | + $atts['src'] = wp_get_attachment_url($video->ID); |
|
| 2499 | + if (empty($atts['src'])) { |
|
| 2500 | 2500 | return; |
| 2501 | 2501 | } |
| 2502 | 2502 | |
| 2503 | - array_unshift( $default_types, 'src' ); |
|
| 2503 | + array_unshift($default_types, 'src'); |
|
| 2504 | 2504 | } |
| 2505 | 2505 | |
| 2506 | 2506 | /** |
@@ -2510,10 +2510,10 @@ discard block |
||
| 2510 | 2510 | * |
| 2511 | 2511 | * @param string $library Media library used for the video shortcode. |
| 2512 | 2512 | */ |
| 2513 | - $library = apply_filters( 'wp_video_shortcode_library', 'mediaelement' ); |
|
| 2514 | - if ( 'mediaelement' === $library && did_action( 'init' ) ) { |
|
| 2515 | - wp_enqueue_style( 'wp-mediaelement' ); |
|
| 2516 | - wp_enqueue_script( 'wp-mediaelement' ); |
|
| 2513 | + $library = apply_filters('wp_video_shortcode_library', 'mediaelement'); |
|
| 2514 | + if ('mediaelement' === $library && did_action('init')) { |
|
| 2515 | + wp_enqueue_style('wp-mediaelement'); |
|
| 2516 | + wp_enqueue_script('wp-mediaelement'); |
|
| 2517 | 2517 | } |
| 2518 | 2518 | |
| 2519 | 2519 | /** |
@@ -2523,73 +2523,73 @@ discard block |
||
| 2523 | 2523 | * |
| 2524 | 2524 | * @param string $class CSS class or list of space-separated classes. |
| 2525 | 2525 | */ |
| 2526 | - $atts['class'] = apply_filters( 'wp_video_shortcode_class', $atts['class'] ); |
|
| 2526 | + $atts['class'] = apply_filters('wp_video_shortcode_class', $atts['class']); |
|
| 2527 | 2527 | |
| 2528 | 2528 | $html_atts = array( |
| 2529 | 2529 | 'class' => $atts['class'], |
| 2530 | - 'id' => sprintf( 'video-%d-%d', $post_id, $instance ), |
|
| 2531 | - 'width' => absint( $atts['width'] ), |
|
| 2532 | - 'height' => absint( $atts['height'] ), |
|
| 2533 | - 'poster' => esc_url( $atts['poster'] ), |
|
| 2534 | - 'loop' => wp_validate_boolean( $atts['loop'] ), |
|
| 2535 | - 'autoplay' => wp_validate_boolean( $atts['autoplay'] ), |
|
| 2530 | + 'id' => sprintf('video-%d-%d', $post_id, $instance), |
|
| 2531 | + 'width' => absint($atts['width']), |
|
| 2532 | + 'height' => absint($atts['height']), |
|
| 2533 | + 'poster' => esc_url($atts['poster']), |
|
| 2534 | + 'loop' => wp_validate_boolean($atts['loop']), |
|
| 2535 | + 'autoplay' => wp_validate_boolean($atts['autoplay']), |
|
| 2536 | 2536 | 'preload' => $atts['preload'], |
| 2537 | 2537 | ); |
| 2538 | 2538 | |
| 2539 | 2539 | // These ones should just be omitted altogether if they are blank |
| 2540 | - foreach ( array( 'poster', 'loop', 'autoplay', 'preload' ) as $a ) { |
|
| 2541 | - if ( empty( $html_atts[$a] ) ) { |
|
| 2542 | - unset( $html_atts[$a] ); |
|
| 2540 | + foreach (array('poster', 'loop', 'autoplay', 'preload') as $a) { |
|
| 2541 | + if (empty($html_atts[$a])) { |
|
| 2542 | + unset($html_atts[$a]); |
|
| 2543 | 2543 | } |
| 2544 | 2544 | } |
| 2545 | 2545 | |
| 2546 | 2546 | $attr_strings = array(); |
| 2547 | - foreach ( $html_atts as $k => $v ) { |
|
| 2548 | - $attr_strings[] = $k . '="' . esc_attr( $v ) . '"'; |
|
| 2547 | + foreach ($html_atts as $k => $v) { |
|
| 2548 | + $attr_strings[] = $k.'="'.esc_attr($v).'"'; |
|
| 2549 | 2549 | } |
| 2550 | 2550 | |
| 2551 | 2551 | $html = ''; |
| 2552 | - if ( 'mediaelement' === $library && 1 === $instance ) { |
|
| 2552 | + if ('mediaelement' === $library && 1 === $instance) { |
|
| 2553 | 2553 | $html .= "<!--[if lt IE 9]><script>document.createElement('video');</script><![endif]-->\n"; |
| 2554 | 2554 | } |
| 2555 | - $html .= sprintf( '<video %s controls="controls">', join( ' ', $attr_strings ) ); |
|
| 2555 | + $html .= sprintf('<video %s controls="controls">', join(' ', $attr_strings)); |
|
| 2556 | 2556 | |
| 2557 | 2557 | $fileurl = ''; |
| 2558 | 2558 | $source = '<source type="%s" src="%s" />'; |
| 2559 | - foreach ( $default_types as $fallback ) { |
|
| 2560 | - if ( ! empty( $atts[ $fallback ] ) ) { |
|
| 2561 | - if ( empty( $fileurl ) ) { |
|
| 2562 | - $fileurl = $atts[ $fallback ]; |
|
| 2559 | + foreach ($default_types as $fallback) { |
|
| 2560 | + if ( ! empty($atts[$fallback])) { |
|
| 2561 | + if (empty($fileurl)) { |
|
| 2562 | + $fileurl = $atts[$fallback]; |
|
| 2563 | 2563 | } |
| 2564 | - if ( 'src' === $fallback && $is_youtube ) { |
|
| 2565 | - $type = array( 'type' => 'video/youtube' ); |
|
| 2566 | - } elseif ( 'src' === $fallback && $is_vimeo ) { |
|
| 2567 | - $type = array( 'type' => 'video/vimeo' ); |
|
| 2564 | + if ('src' === $fallback && $is_youtube) { |
|
| 2565 | + $type = array('type' => 'video/youtube'); |
|
| 2566 | + } elseif ('src' === $fallback && $is_vimeo) { |
|
| 2567 | + $type = array('type' => 'video/vimeo'); |
|
| 2568 | 2568 | } else { |
| 2569 | - $type = wp_check_filetype( $atts[ $fallback ], wp_get_mime_types() ); |
|
| 2569 | + $type = wp_check_filetype($atts[$fallback], wp_get_mime_types()); |
|
| 2570 | 2570 | } |
| 2571 | - $url = add_query_arg( '_', $instance, $atts[ $fallback ] ); |
|
| 2572 | - $html .= sprintf( $source, $type['type'], esc_url( $url ) ); |
|
| 2571 | + $url = add_query_arg('_', $instance, $atts[$fallback]); |
|
| 2572 | + $html .= sprintf($source, $type['type'], esc_url($url)); |
|
| 2573 | 2573 | } |
| 2574 | 2574 | } |
| 2575 | 2575 | |
| 2576 | - if ( ! empty( $content ) ) { |
|
| 2577 | - if ( false !== strpos( $content, "\n" ) ) { |
|
| 2578 | - $content = str_replace( array( "\r\n", "\n", "\t" ), '', $content ); |
|
| 2576 | + if ( ! empty($content)) { |
|
| 2577 | + if (false !== strpos($content, "\n")) { |
|
| 2578 | + $content = str_replace(array("\r\n", "\n", "\t"), '', $content); |
|
| 2579 | 2579 | } |
| 2580 | - $html .= trim( $content ); |
|
| 2580 | + $html .= trim($content); |
|
| 2581 | 2581 | } |
| 2582 | 2582 | |
| 2583 | - if ( 'mediaelement' === $library ) { |
|
| 2584 | - $html .= wp_mediaelement_fallback( $fileurl ); |
|
| 2583 | + if ('mediaelement' === $library) { |
|
| 2584 | + $html .= wp_mediaelement_fallback($fileurl); |
|
| 2585 | 2585 | } |
| 2586 | 2586 | $html .= '</video>'; |
| 2587 | 2587 | |
| 2588 | 2588 | $width_rule = ''; |
| 2589 | - if ( ! empty( $atts['width'] ) ) { |
|
| 2590 | - $width_rule = sprintf( 'width: %dpx; ', $atts['width'] ); |
|
| 2589 | + if ( ! empty($atts['width'])) { |
|
| 2590 | + $width_rule = sprintf('width: %dpx; ', $atts['width']); |
|
| 2591 | 2591 | } |
| 2592 | - $output = sprintf( '<div style="%s" class="wp-video">%s</div>', $width_rule, $html ); |
|
| 2592 | + $output = sprintf('<div style="%s" class="wp-video">%s</div>', $width_rule, $html); |
|
| 2593 | 2593 | |
| 2594 | 2594 | /** |
| 2595 | 2595 | * Filters the output of the video shortcode. |
@@ -2602,9 +2602,9 @@ discard block |
||
| 2602 | 2602 | * @param int $post_id Post ID. |
| 2603 | 2603 | * @param string $library Media library used for the video shortcode. |
| 2604 | 2604 | */ |
| 2605 | - return apply_filters( 'wp_video_shortcode', $output, $atts, $video, $post_id, $library ); |
|
| 2605 | + return apply_filters('wp_video_shortcode', $output, $atts, $video, $post_id, $library); |
|
| 2606 | 2606 | } |
| 2607 | -add_shortcode( 'video', 'wp_video_shortcode' ); |
|
| 2607 | +add_shortcode('video', 'wp_video_shortcode'); |
|
| 2608 | 2608 | |
| 2609 | 2609 | /** |
| 2610 | 2610 | * Displays previous image link that has the same post parent. |
@@ -2618,7 +2618,7 @@ discard block |
||
| 2618 | 2618 | * default to 'post_title' or `$text`. Default 'thumbnail'. |
| 2619 | 2619 | * @param string $text Optional. Link text. Default false. |
| 2620 | 2620 | */ |
| 2621 | -function previous_image_link( $size = 'thumbnail', $text = false ) { |
|
| 2621 | +function previous_image_link($size = 'thumbnail', $text = false) { |
|
| 2622 | 2622 | adjacent_image_link(true, $size, $text); |
| 2623 | 2623 | } |
| 2624 | 2624 | |
@@ -2634,7 +2634,7 @@ discard block |
||
| 2634 | 2634 | * default to 'post_title' or `$text`. Default 'thumbnail'. |
| 2635 | 2635 | * @param string $text Optional. Link text. Default false. |
| 2636 | 2636 | */ |
| 2637 | -function next_image_link( $size = 'thumbnail', $text = false ) { |
|
| 2637 | +function next_image_link($size = 'thumbnail', $text = false) { |
|
| 2638 | 2638 | adjacent_image_link(false, $size, $text); |
| 2639 | 2639 | } |
| 2640 | 2640 | |
@@ -2650,12 +2650,12 @@ discard block |
||
| 2650 | 2650 | * values in pixels (in that order). Default 'thumbnail'. |
| 2651 | 2651 | * @param bool $text Optional. Link text. Default false. |
| 2652 | 2652 | */ |
| 2653 | -function adjacent_image_link( $prev = true, $size = 'thumbnail', $text = false ) { |
|
| 2653 | +function adjacent_image_link($prev = true, $size = 'thumbnail', $text = false) { |
|
| 2654 | 2654 | $post = get_post(); |
| 2655 | - $attachments = array_values( get_children( array( 'post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) ) ); |
|
| 2655 | + $attachments = array_values(get_children(array('post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID'))); |
|
| 2656 | 2656 | |
| 2657 | - foreach ( $attachments as $k => $attachment ) { |
|
| 2658 | - if ( $attachment->ID == $post->ID ) { |
|
| 2657 | + foreach ($attachments as $k => $attachment) { |
|
| 2658 | + if ($attachment->ID == $post->ID) { |
|
| 2659 | 2659 | break; |
| 2660 | 2660 | } |
| 2661 | 2661 | } |
@@ -2663,12 +2663,12 @@ discard block |
||
| 2663 | 2663 | $output = ''; |
| 2664 | 2664 | $attachment_id = 0; |
| 2665 | 2665 | |
| 2666 | - if ( $attachments ) { |
|
| 2666 | + if ($attachments) { |
|
| 2667 | 2667 | $k = $prev ? $k - 1 : $k + 1; |
| 2668 | 2668 | |
| 2669 | - if ( isset( $attachments[ $k ] ) ) { |
|
| 2670 | - $attachment_id = $attachments[ $k ]->ID; |
|
| 2671 | - $output = wp_get_attachment_link( $attachment_id, $size, true, false, $text ); |
|
| 2669 | + if (isset($attachments[$k])) { |
|
| 2670 | + $attachment_id = $attachments[$k]->ID; |
|
| 2671 | + $output = wp_get_attachment_link($attachment_id, $size, true, false, $text); |
|
| 2672 | 2672 | } |
| 2673 | 2673 | } |
| 2674 | 2674 | |
@@ -2687,7 +2687,7 @@ discard block |
||
| 2687 | 2687 | * @param string $size Image size. |
| 2688 | 2688 | * @param string $text Link text. |
| 2689 | 2689 | */ |
| 2690 | - echo apply_filters( "{$adjacent}_image_link", $output, $attachment_id, $size, $text ); |
|
| 2690 | + echo apply_filters("{$adjacent}_image_link", $output, $attachment_id, $size, $text); |
|
| 2691 | 2691 | } |
| 2692 | 2692 | |
| 2693 | 2693 | /** |
@@ -2698,33 +2698,33 @@ discard block |
||
| 2698 | 2698 | * @param int|array|object $attachment Attachment ID, data array, or data object. |
| 2699 | 2699 | * @return array Empty array on failure. List of taxonomies on success. |
| 2700 | 2700 | */ |
| 2701 | -function get_attachment_taxonomies( $attachment ) { |
|
| 2702 | - if ( is_int( $attachment ) ) { |
|
| 2703 | - $attachment = get_post( $attachment ); |
|
| 2704 | - } elseif ( is_array( $attachment ) ) { |
|
| 2701 | +function get_attachment_taxonomies($attachment) { |
|
| 2702 | + if (is_int($attachment)) { |
|
| 2703 | + $attachment = get_post($attachment); |
|
| 2704 | + } elseif (is_array($attachment)) { |
|
| 2705 | 2705 | $attachment = (object) $attachment; |
| 2706 | 2706 | } |
| 2707 | - if ( ! is_object($attachment) ) |
|
| 2707 | + if ( ! is_object($attachment)) |
|
| 2708 | 2708 | return array(); |
| 2709 | 2709 | |
| 2710 | - $file = get_attached_file( $attachment->ID ); |
|
| 2711 | - $filename = basename( $file ); |
|
| 2710 | + $file = get_attached_file($attachment->ID); |
|
| 2711 | + $filename = basename($file); |
|
| 2712 | 2712 | |
| 2713 | 2713 | $objects = array('attachment'); |
| 2714 | 2714 | |
| 2715 | - if ( false !== strpos($filename, '.') ) |
|
| 2716 | - $objects[] = 'attachment:' . substr($filename, strrpos($filename, '.') + 1); |
|
| 2717 | - if ( !empty($attachment->post_mime_type) ) { |
|
| 2718 | - $objects[] = 'attachment:' . $attachment->post_mime_type; |
|
| 2719 | - if ( false !== strpos($attachment->post_mime_type, '/') ) |
|
| 2720 | - foreach ( explode('/', $attachment->post_mime_type) as $token ) |
|
| 2721 | - if ( !empty($token) ) |
|
| 2715 | + if (false !== strpos($filename, '.')) |
|
| 2716 | + $objects[] = 'attachment:'.substr($filename, strrpos($filename, '.') + 1); |
|
| 2717 | + if ( ! empty($attachment->post_mime_type)) { |
|
| 2718 | + $objects[] = 'attachment:'.$attachment->post_mime_type; |
|
| 2719 | + if (false !== strpos($attachment->post_mime_type, '/')) |
|
| 2720 | + foreach (explode('/', $attachment->post_mime_type) as $token) |
|
| 2721 | + if ( ! empty($token)) |
|
| 2722 | 2722 | $objects[] = "attachment:$token"; |
| 2723 | 2723 | } |
| 2724 | 2724 | |
| 2725 | 2725 | $taxonomies = array(); |
| 2726 | - foreach ( $objects as $object ) |
|
| 2727 | - if ( $taxes = get_object_taxonomies($object) ) |
|
| 2726 | + foreach ($objects as $object) |
|
| 2727 | + if ($taxes = get_object_taxonomies($object)) |
|
| 2728 | 2728 | $taxonomies = array_merge($taxonomies, $taxes); |
| 2729 | 2729 | |
| 2730 | 2730 | return array_unique($taxonomies); |
@@ -2743,15 +2743,15 @@ discard block |
||
| 2743 | 2743 | * Default 'names'. |
| 2744 | 2744 | * @return array The names of all taxonomy of $object_type. |
| 2745 | 2745 | */ |
| 2746 | -function get_taxonomies_for_attachments( $output = 'names' ) { |
|
| 2746 | +function get_taxonomies_for_attachments($output = 'names') { |
|
| 2747 | 2747 | $taxonomies = array(); |
| 2748 | - foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy ) { |
|
| 2749 | - foreach ( $taxonomy->object_type as $object_type ) { |
|
| 2750 | - if ( 'attachment' == $object_type || 0 === strpos( $object_type, 'attachment:' ) ) { |
|
| 2751 | - if ( 'names' == $output ) |
|
| 2748 | + foreach (get_taxonomies(array(), 'objects') as $taxonomy) { |
|
| 2749 | + foreach ($taxonomy->object_type as $object_type) { |
|
| 2750 | + if ('attachment' == $object_type || 0 === strpos($object_type, 'attachment:')) { |
|
| 2751 | + if ('names' == $output) |
|
| 2752 | 2752 | $taxonomies[] = $taxonomy->name; |
| 2753 | 2753 | else |
| 2754 | - $taxonomies[ $taxonomy->name ] = $taxonomy; |
|
| 2754 | + $taxonomies[$taxonomy->name] = $taxonomy; |
|
| 2755 | 2755 | break; |
| 2756 | 2756 | } |
| 2757 | 2757 | } |
@@ -2773,7 +2773,7 @@ discard block |
||
| 2773 | 2773 | */ |
| 2774 | 2774 | function wp_imagecreatetruecolor($width, $height) { |
| 2775 | 2775 | $img = imagecreatetruecolor($width, $height); |
| 2776 | - if ( is_resource($img) && function_exists('imagealphablending') && function_exists('imagesavealpha') ) { |
|
| 2776 | + if (is_resource($img) && function_exists('imagealphablending') && function_exists('imagesavealpha')) { |
|
| 2777 | 2777 | imagealphablending($img, false); |
| 2778 | 2778 | imagesavealpha($img, true); |
| 2779 | 2779 | } |
@@ -2793,13 +2793,13 @@ discard block |
||
| 2793 | 2793 | * @param int $max_height The maximum allowed height. |
| 2794 | 2794 | * @return array The maximum possible width and height based on the example ratio. |
| 2795 | 2795 | */ |
| 2796 | -function wp_expand_dimensions( $example_width, $example_height, $max_width, $max_height ) { |
|
| 2796 | +function wp_expand_dimensions($example_width, $example_height, $max_width, $max_height) { |
|
| 2797 | 2797 | $example_width = (int) $example_width; |
| 2798 | 2798 | $example_height = (int) $example_height; |
| 2799 | 2799 | $max_width = (int) $max_width; |
| 2800 | 2800 | $max_height = (int) $max_height; |
| 2801 | 2801 | |
| 2802 | - return wp_constrain_dimensions( $example_width * 1000000, $example_height * 1000000, $max_width, $max_height ); |
|
| 2802 | + return wp_constrain_dimensions($example_width * 1000000, $example_height * 1000000, $max_width, $max_height); |
|
| 2803 | 2803 | } |
| 2804 | 2804 | |
| 2805 | 2805 | /** |
@@ -2810,8 +2810,8 @@ discard block |
||
| 2810 | 2810 | * @return int Allowed upload size. |
| 2811 | 2811 | */ |
| 2812 | 2812 | function wp_max_upload_size() { |
| 2813 | - $u_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) ); |
|
| 2814 | - $p_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) ); |
|
| 2813 | + $u_bytes = wp_convert_hr_to_bytes(ini_get('upload_max_filesize')); |
|
| 2814 | + $p_bytes = wp_convert_hr_to_bytes(ini_get('post_max_size')); |
|
| 2815 | 2815 | |
| 2816 | 2816 | /** |
| 2817 | 2817 | * Filters the maximum upload size allowed in php.ini. |
@@ -2822,7 +2822,7 @@ discard block |
||
| 2822 | 2822 | * @param int $u_bytes Maximum upload filesize in bytes. |
| 2823 | 2823 | * @param int $p_bytes Maximum size of POST data in bytes. |
| 2824 | 2824 | */ |
| 2825 | - return apply_filters( 'upload_size_limit', min( $u_bytes, $p_bytes ), $u_bytes, $p_bytes ); |
|
| 2825 | + return apply_filters('upload_size_limit', min($u_bytes, $p_bytes), $u_bytes, $p_bytes); |
|
| 2826 | 2826 | } |
| 2827 | 2827 | |
| 2828 | 2828 | /** |
@@ -2836,31 +2836,31 @@ discard block |
||
| 2836 | 2836 | * @return WP_Image_Editor|WP_Error The WP_Image_Editor object if successful, an WP_Error |
| 2837 | 2837 | * object otherwise. |
| 2838 | 2838 | */ |
| 2839 | -function wp_get_image_editor( $path, $args = array() ) { |
|
| 2839 | +function wp_get_image_editor($path, $args = array()) { |
|
| 2840 | 2840 | $args['path'] = $path; |
| 2841 | 2841 | |
| 2842 | - if ( ! isset( $args['mime_type'] ) ) { |
|
| 2843 | - $file_info = wp_check_filetype( $args['path'] ); |
|
| 2842 | + if ( ! isset($args['mime_type'])) { |
|
| 2843 | + $file_info = wp_check_filetype($args['path']); |
|
| 2844 | 2844 | |
| 2845 | 2845 | // If $file_info['type'] is false, then we let the editor attempt to |
| 2846 | 2846 | // figure out the file type, rather than forcing a failure based on extension. |
| 2847 | - if ( isset( $file_info ) && $file_info['type'] ) |
|
| 2847 | + if (isset($file_info) && $file_info['type']) |
|
| 2848 | 2848 | $args['mime_type'] = $file_info['type']; |
| 2849 | 2849 | } |
| 2850 | 2850 | |
| 2851 | - $implementation = _wp_image_editor_choose( $args ); |
|
| 2851 | + $implementation = _wp_image_editor_choose($args); |
|
| 2852 | 2852 | |
| 2853 | - if ( $implementation ) { |
|
| 2854 | - $editor = new $implementation( $path ); |
|
| 2853 | + if ($implementation) { |
|
| 2854 | + $editor = new $implementation($path); |
|
| 2855 | 2855 | $loaded = $editor->load(); |
| 2856 | 2856 | |
| 2857 | - if ( is_wp_error( $loaded ) ) |
|
| 2857 | + if (is_wp_error($loaded)) |
|
| 2858 | 2858 | return $loaded; |
| 2859 | 2859 | |
| 2860 | 2860 | return $editor; |
| 2861 | 2861 | } |
| 2862 | 2862 | |
| 2863 | - return new WP_Error( 'image_no_editor', __('No editor could be selected.') ); |
|
| 2863 | + return new WP_Error('image_no_editor', __('No editor could be selected.')); |
|
| 2864 | 2864 | } |
| 2865 | 2865 | |
| 2866 | 2866 | /** |
@@ -2872,8 +2872,8 @@ discard block |
||
| 2872 | 2872 | * Default empty array. |
| 2873 | 2873 | * @return bool True if an eligible editor is found; false otherwise. |
| 2874 | 2874 | */ |
| 2875 | -function wp_image_editor_supports( $args = array() ) { |
|
| 2876 | - return (bool) _wp_image_editor_choose( $args ); |
|
| 2875 | +function wp_image_editor_supports($args = array()) { |
|
| 2876 | + return (bool) _wp_image_editor_choose($args); |
|
| 2877 | 2877 | } |
| 2878 | 2878 | |
| 2879 | 2879 | /** |
@@ -2886,10 +2886,10 @@ discard block |
||
| 2886 | 2886 | * @return string|false Class name for the first editor that claims to support the request. False if no |
| 2887 | 2887 | * editor claims to support the request. |
| 2888 | 2888 | */ |
| 2889 | -function _wp_image_editor_choose( $args = array() ) { |
|
| 2890 | - require_once ABSPATH . WPINC . '/class-wp-image-editor.php'; |
|
| 2891 | - require_once ABSPATH . WPINC . '/class-wp-image-editor-gd.php'; |
|
| 2892 | - require_once ABSPATH . WPINC . '/class-wp-image-editor-imagick.php'; |
|
| 2889 | +function _wp_image_editor_choose($args = array()) { |
|
| 2890 | + require_once ABSPATH.WPINC.'/class-wp-image-editor.php'; |
|
| 2891 | + require_once ABSPATH.WPINC.'/class-wp-image-editor-gd.php'; |
|
| 2892 | + require_once ABSPATH.WPINC.'/class-wp-image-editor-imagick.php'; |
|
| 2893 | 2893 | |
| 2894 | 2894 | /** |
| 2895 | 2895 | * Filters the list of image editing library classes. |
@@ -2899,21 +2899,21 @@ discard block |
||
| 2899 | 2899 | * @param array $image_editors List of available image editors. Defaults are |
| 2900 | 2900 | * 'WP_Image_Editor_Imagick', 'WP_Image_Editor_GD'. |
| 2901 | 2901 | */ |
| 2902 | - $implementations = apply_filters( 'wp_image_editors', array( 'WP_Image_Editor_Imagick', 'WP_Image_Editor_GD' ) ); |
|
| 2902 | + $implementations = apply_filters('wp_image_editors', array('WP_Image_Editor_Imagick', 'WP_Image_Editor_GD')); |
|
| 2903 | 2903 | |
| 2904 | - foreach ( $implementations as $implementation ) { |
|
| 2905 | - if ( ! call_user_func( array( $implementation, 'test' ), $args ) ) |
|
| 2904 | + foreach ($implementations as $implementation) { |
|
| 2905 | + if ( ! call_user_func(array($implementation, 'test'), $args)) |
|
| 2906 | 2906 | continue; |
| 2907 | 2907 | |
| 2908 | - if ( isset( $args['mime_type'] ) && |
|
| 2908 | + if (isset($args['mime_type']) && |
|
| 2909 | 2909 | ! call_user_func( |
| 2910 | - array( $implementation, 'supports_mime_type' ), |
|
| 2911 | - $args['mime_type'] ) ) { |
|
| 2910 | + array($implementation, 'supports_mime_type'), |
|
| 2911 | + $args['mime_type'] )) { |
|
| 2912 | 2912 | continue; |
| 2913 | 2913 | } |
| 2914 | 2914 | |
| 2915 | - if ( isset( $args['methods'] ) && |
|
| 2916 | - array_diff( $args['methods'], get_class_methods( $implementation ) ) ) { |
|
| 2915 | + if (isset($args['methods']) && |
|
| 2916 | + array_diff($args['methods'], get_class_methods($implementation))) { |
|
| 2917 | 2917 | continue; |
| 2918 | 2918 | } |
| 2919 | 2919 | |
@@ -2931,33 +2931,33 @@ discard block |
||
| 2931 | 2931 | function wp_plupload_default_settings() { |
| 2932 | 2932 | $wp_scripts = wp_scripts(); |
| 2933 | 2933 | |
| 2934 | - $data = $wp_scripts->get_data( 'wp-plupload', 'data' ); |
|
| 2935 | - if ( $data && false !== strpos( $data, '_wpPluploadSettings' ) ) |
|
| 2934 | + $data = $wp_scripts->get_data('wp-plupload', 'data'); |
|
| 2935 | + if ($data && false !== strpos($data, '_wpPluploadSettings')) |
|
| 2936 | 2936 | return; |
| 2937 | 2937 | |
| 2938 | 2938 | $max_upload_size = wp_max_upload_size(); |
| 2939 | - $allowed_extensions = array_keys( get_allowed_mime_types() ); |
|
| 2939 | + $allowed_extensions = array_keys(get_allowed_mime_types()); |
|
| 2940 | 2940 | $extensions = array(); |
| 2941 | - foreach ( $allowed_extensions as $extension ) { |
|
| 2942 | - $extensions = array_merge( $extensions, explode( '|', $extension ) ); |
|
| 2941 | + foreach ($allowed_extensions as $extension) { |
|
| 2942 | + $extensions = array_merge($extensions, explode('|', $extension)); |
|
| 2943 | 2943 | } |
| 2944 | 2944 | |
| 2945 | 2945 | $defaults = array( |
| 2946 | 2946 | 'runtimes' => 'html5,flash,silverlight,html4', |
| 2947 | 2947 | 'file_data_name' => 'async-upload', // key passed to $_FILE. |
| 2948 | - 'url' => admin_url( 'async-upload.php', 'relative' ), |
|
| 2949 | - 'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ), |
|
| 2950 | - 'silverlight_xap_url' => includes_url( 'js/plupload/plupload.silverlight.xap' ), |
|
| 2948 | + 'url' => admin_url('async-upload.php', 'relative'), |
|
| 2949 | + 'flash_swf_url' => includes_url('js/plupload/plupload.flash.swf'), |
|
| 2950 | + 'silverlight_xap_url' => includes_url('js/plupload/plupload.silverlight.xap'), |
|
| 2951 | 2951 | 'filters' => array( |
| 2952 | - 'max_file_size' => $max_upload_size . 'b', |
|
| 2953 | - 'mime_types' => array( array( 'extensions' => implode( ',', $extensions ) ) ), |
|
| 2952 | + 'max_file_size' => $max_upload_size.'b', |
|
| 2953 | + 'mime_types' => array(array('extensions' => implode(',', $extensions))), |
|
| 2954 | 2954 | ), |
| 2955 | 2955 | ); |
| 2956 | 2956 | |
| 2957 | 2957 | // Currently only iOS Safari supports multiple files uploading but iOS 7.x has a bug that prevents uploading of videos |
| 2958 | 2958 | // when enabled. See #29602. |
| 2959 | - if ( wp_is_mobile() && strpos( $_SERVER['HTTP_USER_AGENT'], 'OS 7_' ) !== false && |
|
| 2960 | - strpos( $_SERVER['HTTP_USER_AGENT'], 'like Mac OS X' ) !== false ) { |
|
| 2959 | + if (wp_is_mobile() && strpos($_SERVER['HTTP_USER_AGENT'], 'OS 7_') !== false && |
|
| 2960 | + strpos($_SERVER['HTTP_USER_AGENT'], 'like Mac OS X') !== false) { |
|
| 2961 | 2961 | |
| 2962 | 2962 | $defaults['multi_selection'] = false; |
| 2963 | 2963 | } |
@@ -2969,7 +2969,7 @@ discard block |
||
| 2969 | 2969 | * |
| 2970 | 2970 | * @param array $defaults Default Plupload settings array. |
| 2971 | 2971 | */ |
| 2972 | - $defaults = apply_filters( 'plupload_default_settings', $defaults ); |
|
| 2972 | + $defaults = apply_filters('plupload_default_settings', $defaults); |
|
| 2973 | 2973 | |
| 2974 | 2974 | $params = array( |
| 2975 | 2975 | 'action' => 'upload-attachment', |
@@ -2982,8 +2982,8 @@ discard block |
||
| 2982 | 2982 | * |
| 2983 | 2983 | * @param array $params Default Plupload parameters array. |
| 2984 | 2984 | */ |
| 2985 | - $params = apply_filters( 'plupload_default_params', $params ); |
|
| 2986 | - $params['_wpnonce'] = wp_create_nonce( 'media-form' ); |
|
| 2985 | + $params = apply_filters('plupload_default_params', $params); |
|
| 2986 | + $params['_wpnonce'] = wp_create_nonce('media-form'); |
|
| 2987 | 2987 | $defaults['multipart_params'] = $params; |
| 2988 | 2988 | |
| 2989 | 2989 | $settings = array( |
@@ -2995,12 +2995,12 @@ discard block |
||
| 2995 | 2995 | 'limitExceeded' => is_multisite() && ! is_upload_space_available() |
| 2996 | 2996 | ); |
| 2997 | 2997 | |
| 2998 | - $script = 'var _wpPluploadSettings = ' . wp_json_encode( $settings ) . ';'; |
|
| 2998 | + $script = 'var _wpPluploadSettings = '.wp_json_encode($settings).';'; |
|
| 2999 | 2999 | |
| 3000 | - if ( $data ) |
|
| 3000 | + if ($data) |
|
| 3001 | 3001 | $script = "$data\n$script"; |
| 3002 | 3002 | |
| 3003 | - $wp_scripts->add_data( 'wp-plupload', 'data', $script ); |
|
| 3003 | + $wp_scripts->add_data('wp-plupload', 'data', $script); |
|
| 3004 | 3004 | } |
| 3005 | 3005 | |
| 3006 | 3006 | /** |
@@ -3012,42 +3012,42 @@ discard block |
||
| 3012 | 3012 | * @param mixed $attachment Attachment ID or object. |
| 3013 | 3013 | * @return array|void Array of attachment details. |
| 3014 | 3014 | */ |
| 3015 | -function wp_prepare_attachment_for_js( $attachment ) { |
|
| 3016 | - if ( ! $attachment = get_post( $attachment ) ) |
|
| 3015 | +function wp_prepare_attachment_for_js($attachment) { |
|
| 3016 | + if ( ! $attachment = get_post($attachment)) |
|
| 3017 | 3017 | return; |
| 3018 | 3018 | |
| 3019 | - if ( 'attachment' != $attachment->post_type ) |
|
| 3019 | + if ('attachment' != $attachment->post_type) |
|
| 3020 | 3020 | return; |
| 3021 | 3021 | |
| 3022 | - $meta = wp_get_attachment_metadata( $attachment->ID ); |
|
| 3023 | - if ( false !== strpos( $attachment->post_mime_type, '/' ) ) |
|
| 3024 | - list( $type, $subtype ) = explode( '/', $attachment->post_mime_type ); |
|
| 3022 | + $meta = wp_get_attachment_metadata($attachment->ID); |
|
| 3023 | + if (false !== strpos($attachment->post_mime_type, '/')) |
|
| 3024 | + list($type, $subtype) = explode('/', $attachment->post_mime_type); |
|
| 3025 | 3025 | else |
| 3026 | - list( $type, $subtype ) = array( $attachment->post_mime_type, '' ); |
|
| 3026 | + list($type, $subtype) = array($attachment->post_mime_type, ''); |
|
| 3027 | 3027 | |
| 3028 | - $attachment_url = wp_get_attachment_url( $attachment->ID ); |
|
| 3028 | + $attachment_url = wp_get_attachment_url($attachment->ID); |
|
| 3029 | 3029 | |
| 3030 | 3030 | $response = array( |
| 3031 | 3031 | 'id' => $attachment->ID, |
| 3032 | 3032 | 'title' => $attachment->post_title, |
| 3033 | - 'filename' => wp_basename( get_attached_file( $attachment->ID ) ), |
|
| 3033 | + 'filename' => wp_basename(get_attached_file($attachment->ID)), |
|
| 3034 | 3034 | 'url' => $attachment_url, |
| 3035 | - 'link' => get_attachment_link( $attachment->ID ), |
|
| 3036 | - 'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ), |
|
| 3035 | + 'link' => get_attachment_link($attachment->ID), |
|
| 3036 | + 'alt' => get_post_meta($attachment->ID, '_wp_attachment_image_alt', true), |
|
| 3037 | 3037 | 'author' => $attachment->post_author, |
| 3038 | 3038 | 'description' => $attachment->post_content, |
| 3039 | 3039 | 'caption' => $attachment->post_excerpt, |
| 3040 | 3040 | 'name' => $attachment->post_name, |
| 3041 | 3041 | 'status' => $attachment->post_status, |
| 3042 | 3042 | 'uploadedTo' => $attachment->post_parent, |
| 3043 | - 'date' => strtotime( $attachment->post_date_gmt ) * 1000, |
|
| 3044 | - 'modified' => strtotime( $attachment->post_modified_gmt ) * 1000, |
|
| 3043 | + 'date' => strtotime($attachment->post_date_gmt) * 1000, |
|
| 3044 | + 'modified' => strtotime($attachment->post_modified_gmt) * 1000, |
|
| 3045 | 3045 | 'menuOrder' => $attachment->menu_order, |
| 3046 | 3046 | 'mime' => $attachment->post_mime_type, |
| 3047 | 3047 | 'type' => $type, |
| 3048 | 3048 | 'subtype' => $subtype, |
| 3049 | - 'icon' => wp_mime_type_icon( $attachment->ID ), |
|
| 3050 | - 'dateFormatted' => mysql2date( __( 'F j, Y' ), $attachment->post_date ), |
|
| 3049 | + 'icon' => wp_mime_type_icon($attachment->ID), |
|
| 3050 | + 'dateFormatted' => mysql2date(__('F j, Y'), $attachment->post_date), |
|
| 3051 | 3051 | 'nonces' => array( |
| 3052 | 3052 | 'update' => false, |
| 3053 | 3053 | 'delete' => false, |
@@ -3057,145 +3057,145 @@ discard block |
||
| 3057 | 3057 | 'meta' => false, |
| 3058 | 3058 | ); |
| 3059 | 3059 | |
| 3060 | - $author = new WP_User( $attachment->post_author ); |
|
| 3060 | + $author = new WP_User($attachment->post_author); |
|
| 3061 | 3061 | $response['authorName'] = $author->display_name; |
| 3062 | 3062 | |
| 3063 | - if ( $attachment->post_parent ) { |
|
| 3064 | - $post_parent = get_post( $attachment->post_parent ); |
|
| 3063 | + if ($attachment->post_parent) { |
|
| 3064 | + $post_parent = get_post($attachment->post_parent); |
|
| 3065 | 3065 | } else { |
| 3066 | 3066 | $post_parent = false; |
| 3067 | 3067 | } |
| 3068 | 3068 | |
| 3069 | - if ( $post_parent ) { |
|
| 3070 | - $parent_type = get_post_type_object( $post_parent->post_type ); |
|
| 3069 | + if ($post_parent) { |
|
| 3070 | + $parent_type = get_post_type_object($post_parent->post_type); |
|
| 3071 | 3071 | |
| 3072 | - if ( $parent_type && $parent_type->show_ui && current_user_can( 'edit_post', $attachment->post_parent ) ) { |
|
| 3073 | - $response['uploadedToLink'] = get_edit_post_link( $attachment->post_parent, 'raw' ); |
|
| 3072 | + if ($parent_type && $parent_type->show_ui && current_user_can('edit_post', $attachment->post_parent)) { |
|
| 3073 | + $response['uploadedToLink'] = get_edit_post_link($attachment->post_parent, 'raw'); |
|
| 3074 | 3074 | } |
| 3075 | 3075 | |
| 3076 | - if ( $parent_type && current_user_can( 'read_post', $attachment->post_parent ) ) { |
|
| 3077 | - $response['uploadedToTitle'] = $post_parent->post_title ? $post_parent->post_title : __( '(no title)' ); |
|
| 3076 | + if ($parent_type && current_user_can('read_post', $attachment->post_parent)) { |
|
| 3077 | + $response['uploadedToTitle'] = $post_parent->post_title ? $post_parent->post_title : __('(no title)'); |
|
| 3078 | 3078 | } |
| 3079 | 3079 | } |
| 3080 | 3080 | |
| 3081 | - $attached_file = get_attached_file( $attachment->ID ); |
|
| 3081 | + $attached_file = get_attached_file($attachment->ID); |
|
| 3082 | 3082 | |
| 3083 | - if ( isset( $meta['filesize'] ) ) { |
|
| 3083 | + if (isset($meta['filesize'])) { |
|
| 3084 | 3084 | $bytes = $meta['filesize']; |
| 3085 | - } elseif ( file_exists( $attached_file ) ) { |
|
| 3086 | - $bytes = filesize( $attached_file ); |
|
| 3085 | + } elseif (file_exists($attached_file)) { |
|
| 3086 | + $bytes = filesize($attached_file); |
|
| 3087 | 3087 | } else { |
| 3088 | 3088 | $bytes = ''; |
| 3089 | 3089 | } |
| 3090 | 3090 | |
| 3091 | - if ( $bytes ) { |
|
| 3091 | + if ($bytes) { |
|
| 3092 | 3092 | $response['filesizeInBytes'] = $bytes; |
| 3093 | - $response['filesizeHumanReadable'] = size_format( $bytes ); |
|
| 3093 | + $response['filesizeHumanReadable'] = size_format($bytes); |
|
| 3094 | 3094 | } |
| 3095 | 3095 | |
| 3096 | - if ( current_user_can( 'edit_post', $attachment->ID ) ) { |
|
| 3097 | - $response['nonces']['update'] = wp_create_nonce( 'update-post_' . $attachment->ID ); |
|
| 3098 | - $response['nonces']['edit'] = wp_create_nonce( 'image_editor-' . $attachment->ID ); |
|
| 3099 | - $response['editLink'] = get_edit_post_link( $attachment->ID, 'raw' ); |
|
| 3096 | + if (current_user_can('edit_post', $attachment->ID)) { |
|
| 3097 | + $response['nonces']['update'] = wp_create_nonce('update-post_'.$attachment->ID); |
|
| 3098 | + $response['nonces']['edit'] = wp_create_nonce('image_editor-'.$attachment->ID); |
|
| 3099 | + $response['editLink'] = get_edit_post_link($attachment->ID, 'raw'); |
|
| 3100 | 3100 | } |
| 3101 | 3101 | |
| 3102 | - if ( current_user_can( 'delete_post', $attachment->ID ) ) |
|
| 3103 | - $response['nonces']['delete'] = wp_create_nonce( 'delete-post_' . $attachment->ID ); |
|
| 3102 | + if (current_user_can('delete_post', $attachment->ID)) |
|
| 3103 | + $response['nonces']['delete'] = wp_create_nonce('delete-post_'.$attachment->ID); |
|
| 3104 | 3104 | |
| 3105 | - if ( $meta && 'image' === $type ) { |
|
| 3105 | + if ($meta && 'image' === $type) { |
|
| 3106 | 3106 | $sizes = array(); |
| 3107 | 3107 | |
| 3108 | 3108 | /** This filter is documented in wp-admin/includes/media.php */ |
| 3109 | - $possible_sizes = apply_filters( 'image_size_names_choose', array( |
|
| 3109 | + $possible_sizes = apply_filters('image_size_names_choose', array( |
|
| 3110 | 3110 | 'thumbnail' => __('Thumbnail'), |
| 3111 | 3111 | 'medium' => __('Medium'), |
| 3112 | 3112 | 'large' => __('Large'), |
| 3113 | 3113 | 'full' => __('Full Size'), |
| 3114 | - ) ); |
|
| 3115 | - unset( $possible_sizes['full'] ); |
|
| 3114 | + )); |
|
| 3115 | + unset($possible_sizes['full']); |
|
| 3116 | 3116 | |
| 3117 | 3117 | // Loop through all potential sizes that may be chosen. Try to do this with some efficiency. |
| 3118 | 3118 | // First: run the image_downsize filter. If it returns something, we can use its data. |
| 3119 | 3119 | // If the filter does not return something, then image_downsize() is just an expensive |
| 3120 | 3120 | // way to check the image metadata, which we do second. |
| 3121 | - foreach ( $possible_sizes as $size => $label ) { |
|
| 3121 | + foreach ($possible_sizes as $size => $label) { |
|
| 3122 | 3122 | |
| 3123 | 3123 | /** This filter is documented in wp-includes/media.php */ |
| 3124 | - if ( $downsize = apply_filters( 'image_downsize', false, $attachment->ID, $size ) ) { |
|
| 3125 | - if ( ! $downsize[3] ) |
|
| 3124 | + if ($downsize = apply_filters('image_downsize', false, $attachment->ID, $size)) { |
|
| 3125 | + if ( ! $downsize[3]) |
|
| 3126 | 3126 | continue; |
| 3127 | - $sizes[ $size ] = array( |
|
| 3127 | + $sizes[$size] = array( |
|
| 3128 | 3128 | 'height' => $downsize[2], |
| 3129 | 3129 | 'width' => $downsize[1], |
| 3130 | 3130 | 'url' => $downsize[0], |
| 3131 | 3131 | 'orientation' => $downsize[2] > $downsize[1] ? 'portrait' : 'landscape', |
| 3132 | 3132 | ); |
| 3133 | - } elseif ( isset( $meta['sizes'][ $size ] ) ) { |
|
| 3134 | - if ( ! isset( $base_url ) ) |
|
| 3135 | - $base_url = str_replace( wp_basename( $attachment_url ), '', $attachment_url ); |
|
| 3133 | + } elseif (isset($meta['sizes'][$size])) { |
|
| 3134 | + if ( ! isset($base_url)) |
|
| 3135 | + $base_url = str_replace(wp_basename($attachment_url), '', $attachment_url); |
|
| 3136 | 3136 | |
| 3137 | 3137 | // Nothing from the filter, so consult image metadata if we have it. |
| 3138 | - $size_meta = $meta['sizes'][ $size ]; |
|
| 3138 | + $size_meta = $meta['sizes'][$size]; |
|
| 3139 | 3139 | |
| 3140 | 3140 | // We have the actual image size, but might need to further constrain it if content_width is narrower. |
| 3141 | 3141 | // Thumbnail, medium, and full sizes are also checked against the site's height/width options. |
| 3142 | - list( $width, $height ) = image_constrain_size_for_editor( $size_meta['width'], $size_meta['height'], $size, 'edit' ); |
|
| 3142 | + list($width, $height) = image_constrain_size_for_editor($size_meta['width'], $size_meta['height'], $size, 'edit'); |
|
| 3143 | 3143 | |
| 3144 | - $sizes[ $size ] = array( |
|
| 3144 | + $sizes[$size] = array( |
|
| 3145 | 3145 | 'height' => $height, |
| 3146 | 3146 | 'width' => $width, |
| 3147 | - 'url' => $base_url . $size_meta['file'], |
|
| 3147 | + 'url' => $base_url.$size_meta['file'], |
|
| 3148 | 3148 | 'orientation' => $height > $width ? 'portrait' : 'landscape', |
| 3149 | 3149 | ); |
| 3150 | 3150 | } |
| 3151 | 3151 | } |
| 3152 | 3152 | |
| 3153 | - $sizes['full'] = array( 'url' => $attachment_url ); |
|
| 3153 | + $sizes['full'] = array('url' => $attachment_url); |
|
| 3154 | 3154 | |
| 3155 | - if ( isset( $meta['height'], $meta['width'] ) ) { |
|
| 3155 | + if (isset($meta['height'], $meta['width'])) { |
|
| 3156 | 3156 | $sizes['full']['height'] = $meta['height']; |
| 3157 | 3157 | $sizes['full']['width'] = $meta['width']; |
| 3158 | 3158 | $sizes['full']['orientation'] = $meta['height'] > $meta['width'] ? 'portrait' : 'landscape'; |
| 3159 | 3159 | } |
| 3160 | 3160 | |
| 3161 | - $response = array_merge( $response, array( 'sizes' => $sizes ), $sizes['full'] ); |
|
| 3162 | - } elseif ( $meta && 'video' === $type ) { |
|
| 3163 | - if ( isset( $meta['width'] ) ) |
|
| 3161 | + $response = array_merge($response, array('sizes' => $sizes), $sizes['full']); |
|
| 3162 | + } elseif ($meta && 'video' === $type) { |
|
| 3163 | + if (isset($meta['width'])) |
|
| 3164 | 3164 | $response['width'] = (int) $meta['width']; |
| 3165 | - if ( isset( $meta['height'] ) ) |
|
| 3165 | + if (isset($meta['height'])) |
|
| 3166 | 3166 | $response['height'] = (int) $meta['height']; |
| 3167 | 3167 | } |
| 3168 | 3168 | |
| 3169 | - if ( $meta && ( 'audio' === $type || 'video' === $type ) ) { |
|
| 3170 | - if ( isset( $meta['length_formatted'] ) ) |
|
| 3169 | + if ($meta && ('audio' === $type || 'video' === $type)) { |
|
| 3170 | + if (isset($meta['length_formatted'])) |
|
| 3171 | 3171 | $response['fileLength'] = $meta['length_formatted']; |
| 3172 | 3172 | |
| 3173 | 3173 | $response['meta'] = array(); |
| 3174 | - foreach ( wp_get_attachment_id3_keys( $attachment, 'js' ) as $key => $label ) { |
|
| 3175 | - $response['meta'][ $key ] = false; |
|
| 3174 | + foreach (wp_get_attachment_id3_keys($attachment, 'js') as $key => $label) { |
|
| 3175 | + $response['meta'][$key] = false; |
|
| 3176 | 3176 | |
| 3177 | - if ( ! empty( $meta[ $key ] ) ) { |
|
| 3178 | - $response['meta'][ $key ] = $meta[ $key ]; |
|
| 3177 | + if ( ! empty($meta[$key])) { |
|
| 3178 | + $response['meta'][$key] = $meta[$key]; |
|
| 3179 | 3179 | } |
| 3180 | 3180 | } |
| 3181 | 3181 | |
| 3182 | - $id = get_post_thumbnail_id( $attachment->ID ); |
|
| 3183 | - if ( ! empty( $id ) ) { |
|
| 3184 | - list( $src, $width, $height ) = wp_get_attachment_image_src( $id, 'full' ); |
|
| 3185 | - $response['image'] = compact( 'src', 'width', 'height' ); |
|
| 3186 | - list( $src, $width, $height ) = wp_get_attachment_image_src( $id, 'thumbnail' ); |
|
| 3187 | - $response['thumb'] = compact( 'src', 'width', 'height' ); |
|
| 3182 | + $id = get_post_thumbnail_id($attachment->ID); |
|
| 3183 | + if ( ! empty($id)) { |
|
| 3184 | + list($src, $width, $height) = wp_get_attachment_image_src($id, 'full'); |
|
| 3185 | + $response['image'] = compact('src', 'width', 'height'); |
|
| 3186 | + list($src, $width, $height) = wp_get_attachment_image_src($id, 'thumbnail'); |
|
| 3187 | + $response['thumb'] = compact('src', 'width', 'height'); |
|
| 3188 | 3188 | } else { |
| 3189 | - $src = wp_mime_type_icon( $attachment->ID ); |
|
| 3189 | + $src = wp_mime_type_icon($attachment->ID); |
|
| 3190 | 3190 | $width = 48; |
| 3191 | 3191 | $height = 64; |
| 3192 | - $response['image'] = compact( 'src', 'width', 'height' ); |
|
| 3193 | - $response['thumb'] = compact( 'src', 'width', 'height' ); |
|
| 3192 | + $response['image'] = compact('src', 'width', 'height'); |
|
| 3193 | + $response['thumb'] = compact('src', 'width', 'height'); |
|
| 3194 | 3194 | } |
| 3195 | 3195 | } |
| 3196 | 3196 | |
| 3197 | - if ( function_exists('get_compat_media_markup') ) |
|
| 3198 | - $response['compat'] = get_compat_media_markup( $attachment->ID, array( 'in_modal' => true ) ); |
|
| 3197 | + if (function_exists('get_compat_media_markup')) |
|
| 3198 | + $response['compat'] = get_compat_media_markup($attachment->ID, array('in_modal' => true)); |
|
| 3199 | 3199 | |
| 3200 | 3200 | /** |
| 3201 | 3201 | * Filters the attachment data prepared for JavaScript. |
@@ -3206,7 +3206,7 @@ discard block |
||
| 3206 | 3206 | * @param int|object $attachment Attachment ID or object. |
| 3207 | 3207 | * @param array $meta Array of attachment meta data. |
| 3208 | 3208 | */ |
| 3209 | - return apply_filters( 'wp_prepare_attachment_for_js', $response, $attachment, $meta ); |
|
| 3209 | + return apply_filters('wp_prepare_attachment_for_js', $response, $attachment, $meta); |
|
| 3210 | 3210 | } |
| 3211 | 3211 | |
| 3212 | 3212 | /** |
@@ -3225,9 +3225,9 @@ discard block |
||
| 3225 | 3225 | * @type int|WP_Post A post object or ID. |
| 3226 | 3226 | * } |
| 3227 | 3227 | */ |
| 3228 | -function wp_enqueue_media( $args = array() ) { |
|
| 3228 | +function wp_enqueue_media($args = array()) { |
|
| 3229 | 3229 | // Enqueue me just once per page, please. |
| 3230 | - if ( did_action( 'wp_enqueue_media' ) ) |
|
| 3230 | + if (did_action('wp_enqueue_media')) |
|
| 3231 | 3231 | return; |
| 3232 | 3232 | |
| 3233 | 3233 | global $content_width, $wpdb, $wp_locale; |
@@ -3235,7 +3235,7 @@ discard block |
||
| 3235 | 3235 | $defaults = array( |
| 3236 | 3236 | 'post' => null, |
| 3237 | 3237 | ); |
| 3238 | - $args = wp_parse_args( $args, $defaults ); |
|
| 3238 | + $args = wp_parse_args($args, $defaults); |
|
| 3239 | 3239 | |
| 3240 | 3240 | // We're going to pass the old thickbox media tabs to `media_upload_tabs` |
| 3241 | 3241 | // to ensure plugins will work. We will then unset those tabs. |
@@ -3248,67 +3248,67 @@ discard block |
||
| 3248 | 3248 | ); |
| 3249 | 3249 | |
| 3250 | 3250 | /** This filter is documented in wp-admin/includes/media.php */ |
| 3251 | - $tabs = apply_filters( 'media_upload_tabs', $tabs ); |
|
| 3252 | - unset( $tabs['type'], $tabs['type_url'], $tabs['gallery'], $tabs['library'] ); |
|
| 3251 | + $tabs = apply_filters('media_upload_tabs', $tabs); |
|
| 3252 | + unset($tabs['type'], $tabs['type_url'], $tabs['gallery'], $tabs['library']); |
|
| 3253 | 3253 | |
| 3254 | 3254 | $props = array( |
| 3255 | - 'link' => get_option( 'image_default_link_type' ), // db default is 'file' |
|
| 3256 | - 'align' => get_option( 'image_default_align' ), // empty default |
|
| 3257 | - 'size' => get_option( 'image_default_size' ), // empty default |
|
| 3255 | + 'link' => get_option('image_default_link_type'), // db default is 'file' |
|
| 3256 | + 'align' => get_option('image_default_align'), // empty default |
|
| 3257 | + 'size' => get_option('image_default_size'), // empty default |
|
| 3258 | 3258 | ); |
| 3259 | 3259 | |
| 3260 | - $exts = array_merge( wp_get_audio_extensions(), wp_get_video_extensions() ); |
|
| 3260 | + $exts = array_merge(wp_get_audio_extensions(), wp_get_video_extensions()); |
|
| 3261 | 3261 | $mimes = get_allowed_mime_types(); |
| 3262 | 3262 | $ext_mimes = array(); |
| 3263 | - foreach ( $exts as $ext ) { |
|
| 3264 | - foreach ( $mimes as $ext_preg => $mime_match ) { |
|
| 3265 | - if ( preg_match( '#' . $ext . '#i', $ext_preg ) ) { |
|
| 3266 | - $ext_mimes[ $ext ] = $mime_match; |
|
| 3263 | + foreach ($exts as $ext) { |
|
| 3264 | + foreach ($mimes as $ext_preg => $mime_match) { |
|
| 3265 | + if (preg_match('#'.$ext.'#i', $ext_preg)) { |
|
| 3266 | + $ext_mimes[$ext] = $mime_match; |
|
| 3267 | 3267 | break; |
| 3268 | 3268 | } |
| 3269 | 3269 | } |
| 3270 | 3270 | } |
| 3271 | 3271 | |
| 3272 | - $has_audio = $wpdb->get_var( " |
|
| 3272 | + $has_audio = $wpdb->get_var(" |
|
| 3273 | 3273 | SELECT ID |
| 3274 | 3274 | FROM $wpdb->posts |
| 3275 | 3275 | WHERE post_type = 'attachment' |
| 3276 | 3276 | AND post_mime_type LIKE 'audio%' |
| 3277 | 3277 | LIMIT 1 |
| 3278 | - " ); |
|
| 3279 | - $has_video = $wpdb->get_var( " |
|
| 3278 | + "); |
|
| 3279 | + $has_video = $wpdb->get_var(" |
|
| 3280 | 3280 | SELECT ID |
| 3281 | 3281 | FROM $wpdb->posts |
| 3282 | 3282 | WHERE post_type = 'attachment' |
| 3283 | 3283 | AND post_mime_type LIKE 'video%' |
| 3284 | 3284 | LIMIT 1 |
| 3285 | - " ); |
|
| 3286 | - $months = $wpdb->get_results( $wpdb->prepare( " |
|
| 3285 | + "); |
|
| 3286 | + $months = $wpdb->get_results($wpdb->prepare(" |
|
| 3287 | 3287 | SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month |
| 3288 | 3288 | FROM $wpdb->posts |
| 3289 | 3289 | WHERE post_type = %s |
| 3290 | 3290 | ORDER BY post_date DESC |
| 3291 | - ", 'attachment' ) ); |
|
| 3292 | - foreach ( $months as $month_year ) { |
|
| 3293 | - $month_year->text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month_year->month ), $month_year->year ); |
|
| 3291 | + ", 'attachment')); |
|
| 3292 | + foreach ($months as $month_year) { |
|
| 3293 | + $month_year->text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($month_year->month), $month_year->year); |
|
| 3294 | 3294 | } |
| 3295 | 3295 | |
| 3296 | 3296 | $settings = array( |
| 3297 | 3297 | 'tabs' => $tabs, |
| 3298 | - 'tabUrl' => add_query_arg( array( 'chromeless' => true ), admin_url('media-upload.php') ), |
|
| 3299 | - 'mimeTypes' => wp_list_pluck( get_post_mime_types(), 0 ), |
|
| 3298 | + 'tabUrl' => add_query_arg(array('chromeless' => true), admin_url('media-upload.php')), |
|
| 3299 | + 'mimeTypes' => wp_list_pluck(get_post_mime_types(), 0), |
|
| 3300 | 3300 | /** This filter is documented in wp-admin/includes/media.php */ |
| 3301 | - 'captions' => ! apply_filters( 'disable_captions', '' ), |
|
| 3301 | + 'captions' => ! apply_filters('disable_captions', ''), |
|
| 3302 | 3302 | 'nonce' => array( |
| 3303 | - 'sendToEditor' => wp_create_nonce( 'media-send-to-editor' ), |
|
| 3303 | + 'sendToEditor' => wp_create_nonce('media-send-to-editor'), |
|
| 3304 | 3304 | ), |
| 3305 | 3305 | 'post' => array( |
| 3306 | 3306 | 'id' => 0, |
| 3307 | 3307 | ), |
| 3308 | 3308 | 'defaultProps' => $props, |
| 3309 | 3309 | 'attachmentCounts' => array( |
| 3310 | - 'audio' => ( $has_audio ) ? 1 : 0, |
|
| 3311 | - 'video' => ( $has_video ) ? 1 : 0 |
|
| 3310 | + 'audio' => ($has_audio) ? 1 : 0, |
|
| 3311 | + 'video' => ($has_video) ? 1 : 0 |
|
| 3312 | 3312 | ), |
| 3313 | 3313 | 'embedExts' => $exts, |
| 3314 | 3314 | 'embedMimes' => $ext_mimes, |
@@ -3318,154 +3318,154 @@ discard block |
||
| 3318 | 3318 | ); |
| 3319 | 3319 | |
| 3320 | 3320 | $post = null; |
| 3321 | - if ( isset( $args['post'] ) ) { |
|
| 3322 | - $post = get_post( $args['post'] ); |
|
| 3321 | + if (isset($args['post'])) { |
|
| 3322 | + $post = get_post($args['post']); |
|
| 3323 | 3323 | $settings['post'] = array( |
| 3324 | 3324 | 'id' => $post->ID, |
| 3325 | - 'nonce' => wp_create_nonce( 'update-post_' . $post->ID ), |
|
| 3325 | + 'nonce' => wp_create_nonce('update-post_'.$post->ID), |
|
| 3326 | 3326 | ); |
| 3327 | 3327 | |
| 3328 | - $thumbnail_support = current_theme_supports( 'post-thumbnails', $post->post_type ) && post_type_supports( $post->post_type, 'thumbnail' ); |
|
| 3329 | - if ( ! $thumbnail_support && 'attachment' === $post->post_type && $post->post_mime_type ) { |
|
| 3330 | - if ( wp_attachment_is( 'audio', $post ) ) { |
|
| 3331 | - $thumbnail_support = post_type_supports( 'attachment:audio', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:audio' ); |
|
| 3332 | - } elseif ( wp_attachment_is( 'video', $post ) ) { |
|
| 3333 | - $thumbnail_support = post_type_supports( 'attachment:video', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:video' ); |
|
| 3328 | + $thumbnail_support = current_theme_supports('post-thumbnails', $post->post_type) && post_type_supports($post->post_type, 'thumbnail'); |
|
| 3329 | + if ( ! $thumbnail_support && 'attachment' === $post->post_type && $post->post_mime_type) { |
|
| 3330 | + if (wp_attachment_is('audio', $post)) { |
|
| 3331 | + $thumbnail_support = post_type_supports('attachment:audio', 'thumbnail') || current_theme_supports('post-thumbnails', 'attachment:audio'); |
|
| 3332 | + } elseif (wp_attachment_is('video', $post)) { |
|
| 3333 | + $thumbnail_support = post_type_supports('attachment:video', 'thumbnail') || current_theme_supports('post-thumbnails', 'attachment:video'); |
|
| 3334 | 3334 | } |
| 3335 | 3335 | } |
| 3336 | 3336 | |
| 3337 | - if ( $thumbnail_support ) { |
|
| 3338 | - $featured_image_id = get_post_meta( $post->ID, '_thumbnail_id', true ); |
|
| 3337 | + if ($thumbnail_support) { |
|
| 3338 | + $featured_image_id = get_post_meta($post->ID, '_thumbnail_id', true); |
|
| 3339 | 3339 | $settings['post']['featuredImageId'] = $featured_image_id ? $featured_image_id : -1; |
| 3340 | 3340 | } |
| 3341 | 3341 | } |
| 3342 | 3342 | |
| 3343 | - if ( $post ) { |
|
| 3344 | - $post_type_object = get_post_type_object( $post->post_type ); |
|
| 3343 | + if ($post) { |
|
| 3344 | + $post_type_object = get_post_type_object($post->post_type); |
|
| 3345 | 3345 | } else { |
| 3346 | - $post_type_object = get_post_type_object( 'post' ); |
|
| 3346 | + $post_type_object = get_post_type_object('post'); |
|
| 3347 | 3347 | } |
| 3348 | 3348 | |
| 3349 | 3349 | $strings = array( |
| 3350 | 3350 | // Generic |
| 3351 | - 'url' => __( 'URL' ), |
|
| 3352 | - 'addMedia' => __( 'Add Media' ), |
|
| 3353 | - 'search' => __( 'Search' ), |
|
| 3354 | - 'select' => __( 'Select' ), |
|
| 3355 | - 'cancel' => __( 'Cancel' ), |
|
| 3356 | - 'update' => __( 'Update' ), |
|
| 3357 | - 'replace' => __( 'Replace' ), |
|
| 3358 | - 'remove' => __( 'Remove' ), |
|
| 3359 | - 'back' => __( 'Back' ), |
|
| 3351 | + 'url' => __('URL'), |
|
| 3352 | + 'addMedia' => __('Add Media'), |
|
| 3353 | + 'search' => __('Search'), |
|
| 3354 | + 'select' => __('Select'), |
|
| 3355 | + 'cancel' => __('Cancel'), |
|
| 3356 | + 'update' => __('Update'), |
|
| 3357 | + 'replace' => __('Replace'), |
|
| 3358 | + 'remove' => __('Remove'), |
|
| 3359 | + 'back' => __('Back'), |
|
| 3360 | 3360 | /* translators: This is a would-be plural string used in the media manager. |
| 3361 | 3361 | If there is not a word you can use in your language to avoid issues with the |
| 3362 | 3362 | lack of plural support here, turn it into "selected: %d" then translate it. |
| 3363 | 3363 | */ |
| 3364 | - 'selected' => __( '%d selected' ), |
|
| 3365 | - 'dragInfo' => __( 'Drag and drop to reorder media files.' ), |
|
| 3364 | + 'selected' => __('%d selected'), |
|
| 3365 | + 'dragInfo' => __('Drag and drop to reorder media files.'), |
|
| 3366 | 3366 | |
| 3367 | 3367 | // Upload |
| 3368 | - 'uploadFilesTitle' => __( 'Upload Files' ), |
|
| 3369 | - 'uploadImagesTitle' => __( 'Upload Images' ), |
|
| 3368 | + 'uploadFilesTitle' => __('Upload Files'), |
|
| 3369 | + 'uploadImagesTitle' => __('Upload Images'), |
|
| 3370 | 3370 | |
| 3371 | 3371 | // Library |
| 3372 | - 'mediaLibraryTitle' => __( 'Media Library' ), |
|
| 3373 | - 'insertMediaTitle' => __( 'Insert Media' ), |
|
| 3374 | - 'createNewGallery' => __( 'Create a new gallery' ), |
|
| 3375 | - 'createNewPlaylist' => __( 'Create a new playlist' ), |
|
| 3376 | - 'createNewVideoPlaylist' => __( 'Create a new video playlist' ), |
|
| 3377 | - 'returnToLibrary' => __( '← Return to library' ), |
|
| 3378 | - 'allMediaItems' => __( 'All media items' ), |
|
| 3379 | - 'allDates' => __( 'All dates' ), |
|
| 3380 | - 'noItemsFound' => __( 'No items found.' ), |
|
| 3372 | + 'mediaLibraryTitle' => __('Media Library'), |
|
| 3373 | + 'insertMediaTitle' => __('Insert Media'), |
|
| 3374 | + 'createNewGallery' => __('Create a new gallery'), |
|
| 3375 | + 'createNewPlaylist' => __('Create a new playlist'), |
|
| 3376 | + 'createNewVideoPlaylist' => __('Create a new video playlist'), |
|
| 3377 | + 'returnToLibrary' => __('← Return to library'), |
|
| 3378 | + 'allMediaItems' => __('All media items'), |
|
| 3379 | + 'allDates' => __('All dates'), |
|
| 3380 | + 'noItemsFound' => __('No items found.'), |
|
| 3381 | 3381 | 'insertIntoPost' => $post_type_object->labels->insert_into_item, |
| 3382 | - 'unattached' => __( 'Unattached' ), |
|
| 3383 | - 'trash' => _x( 'Trash', 'noun' ), |
|
| 3382 | + 'unattached' => __('Unattached'), |
|
| 3383 | + 'trash' => _x('Trash', 'noun'), |
|
| 3384 | 3384 | 'uploadedToThisPost' => $post_type_object->labels->uploaded_to_this_item, |
| 3385 | - 'warnDelete' => __( "You are about to permanently delete this item.\n 'Cancel' to stop, 'OK' to delete." ), |
|
| 3386 | - 'warnBulkDelete' => __( "You are about to permanently delete these items.\n 'Cancel' to stop, 'OK' to delete." ), |
|
| 3387 | - 'warnBulkTrash' => __( "You are about to trash these items.\n 'Cancel' to stop, 'OK' to delete." ), |
|
| 3388 | - 'bulkSelect' => __( 'Bulk Select' ), |
|
| 3389 | - 'cancelSelection' => __( 'Cancel Selection' ), |
|
| 3390 | - 'trashSelected' => __( 'Trash Selected' ), |
|
| 3391 | - 'untrashSelected' => __( 'Untrash Selected' ), |
|
| 3392 | - 'deleteSelected' => __( 'Delete Selected' ), |
|
| 3393 | - 'deletePermanently' => __( 'Delete Permanently' ), |
|
| 3394 | - 'apply' => __( 'Apply' ), |
|
| 3395 | - 'filterByDate' => __( 'Filter by date' ), |
|
| 3396 | - 'filterByType' => __( 'Filter by type' ), |
|
| 3397 | - 'searchMediaLabel' => __( 'Search Media' ), |
|
| 3398 | - 'noMedia' => __( 'No media files found.' ), |
|
| 3385 | + 'warnDelete' => __("You are about to permanently delete this item.\n 'Cancel' to stop, 'OK' to delete."), |
|
| 3386 | + 'warnBulkDelete' => __("You are about to permanently delete these items.\n 'Cancel' to stop, 'OK' to delete."), |
|
| 3387 | + 'warnBulkTrash' => __("You are about to trash these items.\n 'Cancel' to stop, 'OK' to delete."), |
|
| 3388 | + 'bulkSelect' => __('Bulk Select'), |
|
| 3389 | + 'cancelSelection' => __('Cancel Selection'), |
|
| 3390 | + 'trashSelected' => __('Trash Selected'), |
|
| 3391 | + 'untrashSelected' => __('Untrash Selected'), |
|
| 3392 | + 'deleteSelected' => __('Delete Selected'), |
|
| 3393 | + 'deletePermanently' => __('Delete Permanently'), |
|
| 3394 | + 'apply' => __('Apply'), |
|
| 3395 | + 'filterByDate' => __('Filter by date'), |
|
| 3396 | + 'filterByType' => __('Filter by type'), |
|
| 3397 | + 'searchMediaLabel' => __('Search Media'), |
|
| 3398 | + 'noMedia' => __('No media files found.'), |
|
| 3399 | 3399 | |
| 3400 | 3400 | // Library Details |
| 3401 | - 'attachmentDetails' => __( 'Attachment Details' ), |
|
| 3401 | + 'attachmentDetails' => __('Attachment Details'), |
|
| 3402 | 3402 | |
| 3403 | 3403 | // From URL |
| 3404 | - 'insertFromUrlTitle' => __( 'Insert from URL' ), |
|
| 3404 | + 'insertFromUrlTitle' => __('Insert from URL'), |
|
| 3405 | 3405 | |
| 3406 | 3406 | // Featured Images |
| 3407 | 3407 | 'setFeaturedImageTitle' => $post_type_object->labels->featured_image, |
| 3408 | 3408 | 'setFeaturedImage' => $post_type_object->labels->set_featured_image, |
| 3409 | 3409 | |
| 3410 | 3410 | // Gallery |
| 3411 | - 'createGalleryTitle' => __( 'Create Gallery' ), |
|
| 3412 | - 'editGalleryTitle' => __( 'Edit Gallery' ), |
|
| 3413 | - 'cancelGalleryTitle' => __( '← Cancel Gallery' ), |
|
| 3414 | - 'insertGallery' => __( 'Insert gallery' ), |
|
| 3415 | - 'updateGallery' => __( 'Update gallery' ), |
|
| 3416 | - 'addToGallery' => __( 'Add to gallery' ), |
|
| 3417 | - 'addToGalleryTitle' => __( 'Add to Gallery' ), |
|
| 3418 | - 'reverseOrder' => __( 'Reverse order' ), |
|
| 3411 | + 'createGalleryTitle' => __('Create Gallery'), |
|
| 3412 | + 'editGalleryTitle' => __('Edit Gallery'), |
|
| 3413 | + 'cancelGalleryTitle' => __('← Cancel Gallery'), |
|
| 3414 | + 'insertGallery' => __('Insert gallery'), |
|
| 3415 | + 'updateGallery' => __('Update gallery'), |
|
| 3416 | + 'addToGallery' => __('Add to gallery'), |
|
| 3417 | + 'addToGalleryTitle' => __('Add to Gallery'), |
|
| 3418 | + 'reverseOrder' => __('Reverse order'), |
|
| 3419 | 3419 | |
| 3420 | 3420 | // Edit Image |
| 3421 | - 'imageDetailsTitle' => __( 'Image Details' ), |
|
| 3422 | - 'imageReplaceTitle' => __( 'Replace Image' ), |
|
| 3423 | - 'imageDetailsCancel' => __( 'Cancel Edit' ), |
|
| 3424 | - 'editImage' => __( 'Edit Image' ), |
|
| 3421 | + 'imageDetailsTitle' => __('Image Details'), |
|
| 3422 | + 'imageReplaceTitle' => __('Replace Image'), |
|
| 3423 | + 'imageDetailsCancel' => __('Cancel Edit'), |
|
| 3424 | + 'editImage' => __('Edit Image'), |
|
| 3425 | 3425 | |
| 3426 | 3426 | // Crop Image |
| 3427 | - 'chooseImage' => __( 'Choose Image' ), |
|
| 3428 | - 'selectAndCrop' => __( 'Select and Crop' ), |
|
| 3429 | - 'skipCropping' => __( 'Skip Cropping' ), |
|
| 3430 | - 'cropImage' => __( 'Crop Image' ), |
|
| 3431 | - 'cropYourImage' => __( 'Crop your image' ), |
|
| 3432 | - 'cropping' => __( 'Cropping…' ), |
|
| 3433 | - 'suggestedDimensions' => __( 'Suggested image dimensions:' ), |
|
| 3434 | - 'cropError' => __( 'There has been an error cropping your image.' ), |
|
| 3427 | + 'chooseImage' => __('Choose Image'), |
|
| 3428 | + 'selectAndCrop' => __('Select and Crop'), |
|
| 3429 | + 'skipCropping' => __('Skip Cropping'), |
|
| 3430 | + 'cropImage' => __('Crop Image'), |
|
| 3431 | + 'cropYourImage' => __('Crop your image'), |
|
| 3432 | + 'cropping' => __('Cropping…'), |
|
| 3433 | + 'suggestedDimensions' => __('Suggested image dimensions:'), |
|
| 3434 | + 'cropError' => __('There has been an error cropping your image.'), |
|
| 3435 | 3435 | |
| 3436 | 3436 | // Edit Audio |
| 3437 | - 'audioDetailsTitle' => __( 'Audio Details' ), |
|
| 3438 | - 'audioReplaceTitle' => __( 'Replace Audio' ), |
|
| 3439 | - 'audioAddSourceTitle' => __( 'Add Audio Source' ), |
|
| 3440 | - 'audioDetailsCancel' => __( 'Cancel Edit' ), |
|
| 3437 | + 'audioDetailsTitle' => __('Audio Details'), |
|
| 3438 | + 'audioReplaceTitle' => __('Replace Audio'), |
|
| 3439 | + 'audioAddSourceTitle' => __('Add Audio Source'), |
|
| 3440 | + 'audioDetailsCancel' => __('Cancel Edit'), |
|
| 3441 | 3441 | |
| 3442 | 3442 | // Edit Video |
| 3443 | - 'videoDetailsTitle' => __( 'Video Details' ), |
|
| 3444 | - 'videoReplaceTitle' => __( 'Replace Video' ), |
|
| 3445 | - 'videoAddSourceTitle' => __( 'Add Video Source' ), |
|
| 3446 | - 'videoDetailsCancel' => __( 'Cancel Edit' ), |
|
| 3447 | - 'videoSelectPosterImageTitle' => __( 'Select Poster Image' ), |
|
| 3448 | - 'videoAddTrackTitle' => __( 'Add Subtitles' ), |
|
| 3443 | + 'videoDetailsTitle' => __('Video Details'), |
|
| 3444 | + 'videoReplaceTitle' => __('Replace Video'), |
|
| 3445 | + 'videoAddSourceTitle' => __('Add Video Source'), |
|
| 3446 | + 'videoDetailsCancel' => __('Cancel Edit'), |
|
| 3447 | + 'videoSelectPosterImageTitle' => __('Select Poster Image'), |
|
| 3448 | + 'videoAddTrackTitle' => __('Add Subtitles'), |
|
| 3449 | 3449 | |
| 3450 | 3450 | // Playlist |
| 3451 | - 'playlistDragInfo' => __( 'Drag and drop to reorder tracks.' ), |
|
| 3452 | - 'createPlaylistTitle' => __( 'Create Audio Playlist' ), |
|
| 3453 | - 'editPlaylistTitle' => __( 'Edit Audio Playlist' ), |
|
| 3454 | - 'cancelPlaylistTitle' => __( '← Cancel Audio Playlist' ), |
|
| 3455 | - 'insertPlaylist' => __( 'Insert audio playlist' ), |
|
| 3456 | - 'updatePlaylist' => __( 'Update audio playlist' ), |
|
| 3457 | - 'addToPlaylist' => __( 'Add to audio playlist' ), |
|
| 3458 | - 'addToPlaylistTitle' => __( 'Add to Audio Playlist' ), |
|
| 3451 | + 'playlistDragInfo' => __('Drag and drop to reorder tracks.'), |
|
| 3452 | + 'createPlaylistTitle' => __('Create Audio Playlist'), |
|
| 3453 | + 'editPlaylistTitle' => __('Edit Audio Playlist'), |
|
| 3454 | + 'cancelPlaylistTitle' => __('← Cancel Audio Playlist'), |
|
| 3455 | + 'insertPlaylist' => __('Insert audio playlist'), |
|
| 3456 | + 'updatePlaylist' => __('Update audio playlist'), |
|
| 3457 | + 'addToPlaylist' => __('Add to audio playlist'), |
|
| 3458 | + 'addToPlaylistTitle' => __('Add to Audio Playlist'), |
|
| 3459 | 3459 | |
| 3460 | 3460 | // Video Playlist |
| 3461 | - 'videoPlaylistDragInfo' => __( 'Drag and drop to reorder videos.' ), |
|
| 3462 | - 'createVideoPlaylistTitle' => __( 'Create Video Playlist' ), |
|
| 3463 | - 'editVideoPlaylistTitle' => __( 'Edit Video Playlist' ), |
|
| 3464 | - 'cancelVideoPlaylistTitle' => __( '← Cancel Video Playlist' ), |
|
| 3465 | - 'insertVideoPlaylist' => __( 'Insert video playlist' ), |
|
| 3466 | - 'updateVideoPlaylist' => __( 'Update video playlist' ), |
|
| 3467 | - 'addToVideoPlaylist' => __( 'Add to video playlist' ), |
|
| 3468 | - 'addToVideoPlaylistTitle' => __( 'Add to Video Playlist' ), |
|
| 3461 | + 'videoPlaylistDragInfo' => __('Drag and drop to reorder videos.'), |
|
| 3462 | + 'createVideoPlaylistTitle' => __('Create Video Playlist'), |
|
| 3463 | + 'editVideoPlaylistTitle' => __('Edit Video Playlist'), |
|
| 3464 | + 'cancelVideoPlaylistTitle' => __('← Cancel Video Playlist'), |
|
| 3465 | + 'insertVideoPlaylist' => __('Insert video playlist'), |
|
| 3466 | + 'updateVideoPlaylist' => __('Update video playlist'), |
|
| 3467 | + 'addToVideoPlaylist' => __('Add to video playlist'), |
|
| 3468 | + 'addToVideoPlaylistTitle' => __('Add to Video Playlist'), |
|
| 3469 | 3469 | ); |
| 3470 | 3470 | |
| 3471 | 3471 | /** |
@@ -3476,7 +3476,7 @@ discard block |
||
| 3476 | 3476 | * @param array $settings List of media view settings. |
| 3477 | 3477 | * @param WP_Post $post Post object. |
| 3478 | 3478 | */ |
| 3479 | - $settings = apply_filters( 'media_view_settings', $settings, $post ); |
|
| 3479 | + $settings = apply_filters('media_view_settings', $settings, $post); |
|
| 3480 | 3480 | |
| 3481 | 3481 | /** |
| 3482 | 3482 | * Filters the media view strings. |
@@ -3486,35 +3486,35 @@ discard block |
||
| 3486 | 3486 | * @param array $strings List of media view strings. |
| 3487 | 3487 | * @param WP_Post $post Post object. |
| 3488 | 3488 | */ |
| 3489 | - $strings = apply_filters( 'media_view_strings', $strings, $post ); |
|
| 3489 | + $strings = apply_filters('media_view_strings', $strings, $post); |
|
| 3490 | 3490 | |
| 3491 | 3491 | $strings['settings'] = $settings; |
| 3492 | 3492 | |
| 3493 | 3493 | // Ensure we enqueue media-editor first, that way media-views is |
| 3494 | 3494 | // registered internally before we try to localize it. see #24724. |
| 3495 | - wp_enqueue_script( 'media-editor' ); |
|
| 3496 | - wp_localize_script( 'media-views', '_wpMediaViewsL10n', $strings ); |
|
| 3495 | + wp_enqueue_script('media-editor'); |
|
| 3496 | + wp_localize_script('media-views', '_wpMediaViewsL10n', $strings); |
|
| 3497 | 3497 | |
| 3498 | - wp_enqueue_script( 'media-audiovideo' ); |
|
| 3499 | - wp_enqueue_style( 'media-views' ); |
|
| 3500 | - if ( is_admin() ) { |
|
| 3501 | - wp_enqueue_script( 'mce-view' ); |
|
| 3502 | - wp_enqueue_script( 'image-edit' ); |
|
| 3498 | + wp_enqueue_script('media-audiovideo'); |
|
| 3499 | + wp_enqueue_style('media-views'); |
|
| 3500 | + if (is_admin()) { |
|
| 3501 | + wp_enqueue_script('mce-view'); |
|
| 3502 | + wp_enqueue_script('image-edit'); |
|
| 3503 | 3503 | } |
| 3504 | - wp_enqueue_style( 'imgareaselect' ); |
|
| 3504 | + wp_enqueue_style('imgareaselect'); |
|
| 3505 | 3505 | wp_plupload_default_settings(); |
| 3506 | 3506 | |
| 3507 | - require_once ABSPATH . WPINC . '/media-template.php'; |
|
| 3508 | - add_action( 'admin_footer', 'wp_print_media_templates' ); |
|
| 3509 | - add_action( 'wp_footer', 'wp_print_media_templates' ); |
|
| 3510 | - add_action( 'customize_controls_print_footer_scripts', 'wp_print_media_templates' ); |
|
| 3507 | + require_once ABSPATH.WPINC.'/media-template.php'; |
|
| 3508 | + add_action('admin_footer', 'wp_print_media_templates'); |
|
| 3509 | + add_action('wp_footer', 'wp_print_media_templates'); |
|
| 3510 | + add_action('customize_controls_print_footer_scripts', 'wp_print_media_templates'); |
|
| 3511 | 3511 | |
| 3512 | 3512 | /** |
| 3513 | 3513 | * Fires at the conclusion of wp_enqueue_media(). |
| 3514 | 3514 | * |
| 3515 | 3515 | * @since 3.5.0 |
| 3516 | 3516 | */ |
| 3517 | - do_action( 'wp_enqueue_media' ); |
|
| 3517 | + do_action('wp_enqueue_media'); |
|
| 3518 | 3518 | } |
| 3519 | 3519 | |
| 3520 | 3520 | /** |
@@ -3526,8 +3526,8 @@ discard block |
||
| 3526 | 3526 | * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. |
| 3527 | 3527 | * @return array Found attachments. |
| 3528 | 3528 | */ |
| 3529 | -function get_attached_media( $type, $post = 0 ) { |
|
| 3530 | - if ( ! $post = get_post( $post ) ) |
|
| 3529 | +function get_attached_media($type, $post = 0) { |
|
| 3530 | + if ( ! $post = get_post($post)) |
|
| 3531 | 3531 | return array(); |
| 3532 | 3532 | |
| 3533 | 3533 | $args = array( |
@@ -3548,9 +3548,9 @@ discard block |
||
| 3548 | 3548 | * @param string $type Mime type of the desired media. |
| 3549 | 3549 | * @param mixed $post Post ID or object. |
| 3550 | 3550 | */ |
| 3551 | - $args = apply_filters( 'get_attached_media_args', $args, $type, $post ); |
|
| 3551 | + $args = apply_filters('get_attached_media_args', $args, $type, $post); |
|
| 3552 | 3552 | |
| 3553 | - $children = get_children( $args ); |
|
| 3553 | + $children = get_children($args); |
|
| 3554 | 3554 | |
| 3555 | 3555 | /** |
| 3556 | 3556 | * Filters the list of media attached to the given post. |
@@ -3561,7 +3561,7 @@ discard block |
||
| 3561 | 3561 | * @param string $type Mime type of the media desired. |
| 3562 | 3562 | * @param mixed $post Post ID or object. |
| 3563 | 3563 | */ |
| 3564 | - return (array) apply_filters( 'get_attached_media', $children, $type, $post ); |
|
| 3564 | + return (array) apply_filters('get_attached_media', $children, $type, $post); |
|
| 3565 | 3565 | } |
| 3566 | 3566 | |
| 3567 | 3567 | /** |
@@ -3573,7 +3573,7 @@ discard block |
||
| 3573 | 3573 | * @param array $types An array of media types: 'audio', 'video', 'object', 'embed', or 'iframe'. |
| 3574 | 3574 | * @return array A list of found HTML media embeds. |
| 3575 | 3575 | */ |
| 3576 | -function get_media_embedded_in_content( $content, $types = null ) { |
|
| 3576 | +function get_media_embedded_in_content($content, $types = null) { |
|
| 3577 | 3577 | $html = array(); |
| 3578 | 3578 | |
| 3579 | 3579 | /** |
@@ -3584,20 +3584,20 @@ discard block |
||
| 3584 | 3584 | * @param array $allowed_media_types An array of allowed media types. Default media types are |
| 3585 | 3585 | * 'audio', 'video', 'object', 'embed', and 'iframe'. |
| 3586 | 3586 | */ |
| 3587 | - $allowed_media_types = apply_filters( 'media_embedded_in_content_allowed_types', array( 'audio', 'video', 'object', 'embed', 'iframe' ) ); |
|
| 3587 | + $allowed_media_types = apply_filters('media_embedded_in_content_allowed_types', array('audio', 'video', 'object', 'embed', 'iframe')); |
|
| 3588 | 3588 | |
| 3589 | - if ( ! empty( $types ) ) { |
|
| 3590 | - if ( ! is_array( $types ) ) { |
|
| 3591 | - $types = array( $types ); |
|
| 3589 | + if ( ! empty($types)) { |
|
| 3590 | + if ( ! is_array($types)) { |
|
| 3591 | + $types = array($types); |
|
| 3592 | 3592 | } |
| 3593 | 3593 | |
| 3594 | - $allowed_media_types = array_intersect( $allowed_media_types, $types ); |
|
| 3594 | + $allowed_media_types = array_intersect($allowed_media_types, $types); |
|
| 3595 | 3595 | } |
| 3596 | 3596 | |
| 3597 | - $tags = implode( '|', $allowed_media_types ); |
|
| 3597 | + $tags = implode('|', $allowed_media_types); |
|
| 3598 | 3598 | |
| 3599 | - if ( preg_match_all( '#<(?P<tag>' . $tags . ')[^<]*?(?:>[\s\S]*?<\/(?P=tag)>|\s*\/>)#', $content, $matches ) ) { |
|
| 3600 | - foreach ( $matches[0] as $match ) { |
|
| 3599 | + if (preg_match_all('#<(?P<tag>'.$tags.')[^<]*?(?:>[\s\S]*?<\/(?P=tag)>|\s*\/>)#', $content, $matches)) { |
|
| 3600 | + foreach ($matches[0] as $match) { |
|
| 3601 | 3601 | $html[] = $match; |
| 3602 | 3602 | } |
| 3603 | 3603 | } |
@@ -3615,31 +3615,31 @@ discard block |
||
| 3615 | 3615 | * @return array A list of arrays, each containing gallery data and srcs parsed |
| 3616 | 3616 | * from the expanded shortcode. |
| 3617 | 3617 | */ |
| 3618 | -function get_post_galleries( $post, $html = true ) { |
|
| 3619 | - if ( ! $post = get_post( $post ) ) |
|
| 3618 | +function get_post_galleries($post, $html = true) { |
|
| 3619 | + if ( ! $post = get_post($post)) |
|
| 3620 | 3620 | return array(); |
| 3621 | 3621 | |
| 3622 | - if ( ! has_shortcode( $post->post_content, 'gallery' ) ) |
|
| 3622 | + if ( ! has_shortcode($post->post_content, 'gallery')) |
|
| 3623 | 3623 | return array(); |
| 3624 | 3624 | |
| 3625 | 3625 | $galleries = array(); |
| 3626 | - if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $post->post_content, $matches, PREG_SET_ORDER ) ) { |
|
| 3627 | - foreach ( $matches as $shortcode ) { |
|
| 3628 | - if ( 'gallery' === $shortcode[2] ) { |
|
| 3626 | + if (preg_match_all('/'.get_shortcode_regex().'/s', $post->post_content, $matches, PREG_SET_ORDER)) { |
|
| 3627 | + foreach ($matches as $shortcode) { |
|
| 3628 | + if ('gallery' === $shortcode[2]) { |
|
| 3629 | 3629 | $srcs = array(); |
| 3630 | 3630 | |
| 3631 | - $gallery = do_shortcode_tag( $shortcode ); |
|
| 3632 | - if ( $html ) { |
|
| 3631 | + $gallery = do_shortcode_tag($shortcode); |
|
| 3632 | + if ($html) { |
|
| 3633 | 3633 | $galleries[] = $gallery; |
| 3634 | 3634 | } else { |
| 3635 | - preg_match_all( '#src=([\'"])(.+?)\1#is', $gallery, $src, PREG_SET_ORDER ); |
|
| 3636 | - if ( ! empty( $src ) ) { |
|
| 3637 | - foreach ( $src as $s ) |
|
| 3635 | + preg_match_all('#src=([\'"])(.+?)\1#is', $gallery, $src, PREG_SET_ORDER); |
|
| 3636 | + if ( ! empty($src)) { |
|
| 3637 | + foreach ($src as $s) |
|
| 3638 | 3638 | $srcs[] = $s[2]; |
| 3639 | 3639 | } |
| 3640 | 3640 | |
| 3641 | - $data = shortcode_parse_atts( $shortcode[3] ); |
|
| 3642 | - $data['src'] = array_values( array_unique( $srcs ) ); |
|
| 3641 | + $data = shortcode_parse_atts($shortcode[3]); |
|
| 3642 | + $data['src'] = array_values(array_unique($srcs)); |
|
| 3643 | 3643 | $galleries[] = $data; |
| 3644 | 3644 | } |
| 3645 | 3645 | } |
@@ -3654,7 +3654,7 @@ discard block |
||
| 3654 | 3654 | * @param array $galleries Associative array of all found post galleries. |
| 3655 | 3655 | * @param WP_Post $post Post object. |
| 3656 | 3656 | */ |
| 3657 | - return apply_filters( 'get_post_galleries', $galleries, $post ); |
|
| 3657 | + return apply_filters('get_post_galleries', $galleries, $post); |
|
| 3658 | 3658 | } |
| 3659 | 3659 | |
| 3660 | 3660 | /** |
@@ -3666,9 +3666,9 @@ discard block |
||
| 3666 | 3666 | * @param bool $html Optional. Whether to return HTML or data. Default is true. |
| 3667 | 3667 | * @return string|array Gallery data and srcs parsed from the expanded shortcode. |
| 3668 | 3668 | */ |
| 3669 | -function get_post_gallery( $post = 0, $html = true ) { |
|
| 3670 | - $galleries = get_post_galleries( $post, $html ); |
|
| 3671 | - $gallery = reset( $galleries ); |
|
| 3669 | +function get_post_gallery($post = 0, $html = true) { |
|
| 3670 | + $galleries = get_post_galleries($post, $html); |
|
| 3671 | + $gallery = reset($galleries); |
|
| 3672 | 3672 | |
| 3673 | 3673 | /** |
| 3674 | 3674 | * Filters the first-found post gallery. |
@@ -3679,7 +3679,7 @@ discard block |
||
| 3679 | 3679 | * @param int|WP_Post $post Post ID or object. |
| 3680 | 3680 | * @param array $galleries Associative array of all found post galleries. |
| 3681 | 3681 | */ |
| 3682 | - return apply_filters( 'get_post_gallery', $gallery, $post, $galleries ); |
|
| 3682 | + return apply_filters('get_post_gallery', $gallery, $post, $galleries); |
|
| 3683 | 3683 | } |
| 3684 | 3684 | |
| 3685 | 3685 | /** |
@@ -3693,9 +3693,9 @@ discard block |
||
| 3693 | 3693 | * @return array A list of lists, each containing image srcs parsed. |
| 3694 | 3694 | * from an expanded shortcode |
| 3695 | 3695 | */ |
| 3696 | -function get_post_galleries_images( $post = 0 ) { |
|
| 3697 | - $galleries = get_post_galleries( $post, false ); |
|
| 3698 | - return wp_list_pluck( $galleries, 'src' ); |
|
| 3696 | +function get_post_galleries_images($post = 0) { |
|
| 3697 | + $galleries = get_post_galleries($post, false); |
|
| 3698 | + return wp_list_pluck($galleries, 'src'); |
|
| 3699 | 3699 | } |
| 3700 | 3700 | |
| 3701 | 3701 | /** |
@@ -3708,9 +3708,9 @@ discard block |
||
| 3708 | 3708 | * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`. |
| 3709 | 3709 | * @return array A list of a gallery's image srcs in order. |
| 3710 | 3710 | */ |
| 3711 | -function get_post_gallery_images( $post = 0 ) { |
|
| 3712 | - $gallery = get_post_gallery( $post, false ); |
|
| 3713 | - return empty( $gallery['src'] ) ? array() : $gallery['src']; |
|
| 3711 | +function get_post_gallery_images($post = 0) { |
|
| 3712 | + $gallery = get_post_gallery($post, false); |
|
| 3713 | + return empty($gallery['src']) ? array() : $gallery['src']; |
|
| 3714 | 3714 | } |
| 3715 | 3715 | |
| 3716 | 3716 | /** |
@@ -3720,20 +3720,20 @@ discard block |
||
| 3720 | 3720 | * |
| 3721 | 3721 | * @param WP_Post $attachment Attachment object. |
| 3722 | 3722 | */ |
| 3723 | -function wp_maybe_generate_attachment_metadata( $attachment ) { |
|
| 3724 | - if ( empty( $attachment ) || ( empty( $attachment->ID ) || ! $attachment_id = (int) $attachment->ID ) ) { |
|
| 3723 | +function wp_maybe_generate_attachment_metadata($attachment) { |
|
| 3724 | + if (empty($attachment) || (empty($attachment->ID) || ! $attachment_id = (int) $attachment->ID)) { |
|
| 3725 | 3725 | return; |
| 3726 | 3726 | } |
| 3727 | 3727 | |
| 3728 | - $file = get_attached_file( $attachment_id ); |
|
| 3729 | - $meta = wp_get_attachment_metadata( $attachment_id ); |
|
| 3730 | - if ( empty( $meta ) && file_exists( $file ) ) { |
|
| 3731 | - $_meta = get_post_meta( $attachment_id ); |
|
| 3732 | - $regeneration_lock = 'wp_generating_att_' . $attachment_id; |
|
| 3733 | - if ( ! array_key_exists( '_wp_attachment_metadata', $_meta ) && ! get_transient( $regeneration_lock ) ) { |
|
| 3734 | - set_transient( $regeneration_lock, $file ); |
|
| 3735 | - wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) ); |
|
| 3736 | - delete_transient( $regeneration_lock ); |
|
| 3728 | + $file = get_attached_file($attachment_id); |
|
| 3729 | + $meta = wp_get_attachment_metadata($attachment_id); |
|
| 3730 | + if (empty($meta) && file_exists($file)) { |
|
| 3731 | + $_meta = get_post_meta($attachment_id); |
|
| 3732 | + $regeneration_lock = 'wp_generating_att_'.$attachment_id; |
|
| 3733 | + if ( ! array_key_exists('_wp_attachment_metadata', $_meta) && ! get_transient($regeneration_lock)) { |
|
| 3734 | + set_transient($regeneration_lock, $file); |
|
| 3735 | + wp_update_attachment_metadata($attachment_id, wp_generate_attachment_metadata($attachment_id, $file)); |
|
| 3736 | + delete_transient($regeneration_lock); |
|
| 3737 | 3737 | } |
| 3738 | 3738 | } |
| 3739 | 3739 | } |
@@ -3748,29 +3748,29 @@ discard block |
||
| 3748 | 3748 | * @param string $url The URL to resolve. |
| 3749 | 3749 | * @return int The found post ID, or 0 on failure. |
| 3750 | 3750 | */ |
| 3751 | -function attachment_url_to_postid( $url ) { |
|
| 3751 | +function attachment_url_to_postid($url) { |
|
| 3752 | 3752 | global $wpdb; |
| 3753 | 3753 | |
| 3754 | 3754 | $dir = wp_get_upload_dir(); |
| 3755 | 3755 | $path = $url; |
| 3756 | 3756 | |
| 3757 | - $site_url = parse_url( $dir['url'] ); |
|
| 3758 | - $image_path = parse_url( $path ); |
|
| 3757 | + $site_url = parse_url($dir['url']); |
|
| 3758 | + $image_path = parse_url($path); |
|
| 3759 | 3759 | |
| 3760 | 3760 | //force the protocols to match if needed |
| 3761 | - if ( isset( $image_path['scheme'] ) && ( $image_path['scheme'] !== $site_url['scheme'] ) ) { |
|
| 3762 | - $path = str_replace( $image_path['scheme'], $site_url['scheme'], $path ); |
|
| 3761 | + if (isset($image_path['scheme']) && ($image_path['scheme'] !== $site_url['scheme'])) { |
|
| 3762 | + $path = str_replace($image_path['scheme'], $site_url['scheme'], $path); |
|
| 3763 | 3763 | } |
| 3764 | 3764 | |
| 3765 | - if ( 0 === strpos( $path, $dir['baseurl'] . '/' ) ) { |
|
| 3766 | - $path = substr( $path, strlen( $dir['baseurl'] . '/' ) ); |
|
| 3765 | + if (0 === strpos($path, $dir['baseurl'].'/')) { |
|
| 3766 | + $path = substr($path, strlen($dir['baseurl'].'/')); |
|
| 3767 | 3767 | } |
| 3768 | 3768 | |
| 3769 | 3769 | $sql = $wpdb->prepare( |
| 3770 | 3770 | "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attached_file' AND meta_value = %s", |
| 3771 | 3771 | $path |
| 3772 | 3772 | ); |
| 3773 | - $post_id = $wpdb->get_var( $sql ); |
|
| 3773 | + $post_id = $wpdb->get_var($sql); |
|
| 3774 | 3774 | |
| 3775 | 3775 | /** |
| 3776 | 3776 | * Filters an attachment id found by URL. |
@@ -3780,7 +3780,7 @@ discard block |
||
| 3780 | 3780 | * @param int|null $post_id The post_id (if any) found by the function. |
| 3781 | 3781 | * @param string $url The URL being looked up. |
| 3782 | 3782 | */ |
| 3783 | - return (int) apply_filters( 'attachment_url_to_postid', $post_id, $url ); |
|
| 3783 | + return (int) apply_filters('attachment_url_to_postid', $post_id, $url); |
|
| 3784 | 3784 | } |
| 3785 | 3785 | |
| 3786 | 3786 | /** |
@@ -3793,9 +3793,9 @@ discard block |
||
| 3793 | 3793 | * @return array The relevant CSS file URLs. |
| 3794 | 3794 | */ |
| 3795 | 3795 | function wpview_media_sandbox_styles() { |
| 3796 | - $version = 'ver=' . $GLOBALS['wp_version']; |
|
| 3797 | - $mediaelement = includes_url( "js/mediaelement/mediaelementplayer.min.css?$version" ); |
|
| 3798 | - $wpmediaelement = includes_url( "js/mediaelement/wp-mediaelement.css?$version" ); |
|
| 3796 | + $version = 'ver='.$GLOBALS['wp_version']; |
|
| 3797 | + $mediaelement = includes_url("js/mediaelement/mediaelementplayer.min.css?$version"); |
|
| 3798 | + $wpmediaelement = includes_url("js/mediaelement/wp-mediaelement.css?$version"); |
|
| 3799 | 3799 | |
| 3800 | - return array( $mediaelement, $wpmediaelement ); |
|
| 3800 | + return array($mediaelement, $wpmediaelement); |
|
| 3801 | 3801 | } |
@@ -41,14 +41,14 @@ discard block |
||
| 41 | 41 | function image_constrain_size_for_editor( $width, $height, $size = 'medium', $context = null ) { |
| 42 | 42 | global $content_width, $_wp_additional_image_sizes; |
| 43 | 43 | |
| 44 | - if ( ! $context ) |
|
| 45 | - $context = is_admin() ? 'edit' : 'display'; |
|
| 44 | + if ( ! $context ) { |
|
| 45 | + $context = is_admin() ? 'edit' : 'display'; |
|
| 46 | + } |
|
| 46 | 47 | |
| 47 | 48 | if ( is_array($size) ) { |
| 48 | 49 | $max_width = $size[0]; |
| 49 | 50 | $max_height = $size[1]; |
| 50 | - } |
|
| 51 | - elseif ( $size == 'thumb' || $size == 'thumbnail' ) { |
|
| 51 | + } elseif ( $size == 'thumb' || $size == 'thumbnail' ) { |
|
| 52 | 52 | $max_width = intval(get_option('thumbnail_size_w')); |
| 53 | 53 | $max_height = intval(get_option('thumbnail_size_h')); |
| 54 | 54 | // last chance thumbnail size defaults |
@@ -56,21 +56,18 @@ discard block |
||
| 56 | 56 | $max_width = 128; |
| 57 | 57 | $max_height = 96; |
| 58 | 58 | } |
| 59 | - } |
|
| 60 | - elseif ( $size == 'medium' ) { |
|
| 59 | + } elseif ( $size == 'medium' ) { |
|
| 61 | 60 | $max_width = intval(get_option('medium_size_w')); |
| 62 | 61 | $max_height = intval(get_option('medium_size_h')); |
| 63 | 62 | |
| 64 | - } |
|
| 65 | - elseif ( $size == 'medium_large' ) { |
|
| 63 | + } elseif ( $size == 'medium_large' ) { |
|
| 66 | 64 | $max_width = intval( get_option( 'medium_large_size_w' ) ); |
| 67 | 65 | $max_height = intval( get_option( 'medium_large_size_h' ) ); |
| 68 | 66 | |
| 69 | 67 | if ( intval( $content_width ) > 0 ) { |
| 70 | 68 | $max_width = min( intval( $content_width ), $max_width ); |
| 71 | 69 | } |
| 72 | - } |
|
| 73 | - elseif ( $size == 'large' ) { |
|
| 70 | + } elseif ( $size == 'large' ) { |
|
| 74 | 71 | /* |
| 75 | 72 | * We're inserting a large size image into the editor. If it's a really |
| 76 | 73 | * big image we'll scale it down to fit reasonably within the editor |
@@ -85,8 +82,10 @@ discard block |
||
| 85 | 82 | } elseif ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) && in_array( $size, array_keys( $_wp_additional_image_sizes ) ) ) { |
| 86 | 83 | $max_width = intval( $_wp_additional_image_sizes[$size]['width'] ); |
| 87 | 84 | $max_height = intval( $_wp_additional_image_sizes[$size]['height'] ); |
| 88 | - if ( intval($content_width) > 0 && 'edit' == $context ) // Only in admin. Assume that theme authors know what they're doing. |
|
| 85 | + if ( intval($content_width) > 0 && 'edit' == $context ) { |
|
| 86 | + // Only in admin. Assume that theme authors know what they're doing. |
|
| 89 | 87 | $max_width = min( intval($content_width), $max_width ); |
| 88 | + } |
|
| 90 | 89 | } |
| 91 | 90 | // $size == 'full' has no constraint |
| 92 | 91 | else { |
@@ -130,10 +129,12 @@ discard block |
||
| 130 | 129 | */ |
| 131 | 130 | function image_hwstring( $width, $height ) { |
| 132 | 131 | $out = ''; |
| 133 | - if ($width) |
|
| 134 | - $out .= 'width="'.intval($width).'" '; |
|
| 135 | - if ($height) |
|
| 136 | - $out .= 'height="'.intval($height).'" '; |
|
| 132 | + if ($width) { |
|
| 133 | + $out .= 'width="'.intval($width).'" '; |
|
| 134 | + } |
|
| 135 | + if ($height) { |
|
| 136 | + $out .= 'height="'.intval($height).'" '; |
|
| 137 | + } |
|
| 137 | 138 | return $out; |
| 138 | 139 | } |
| 139 | 140 | |
@@ -164,8 +165,9 @@ discard block |
||
| 164 | 165 | */ |
| 165 | 166 | function image_downsize( $id, $size = 'medium' ) { |
| 166 | 167 | |
| 167 | - if ( !wp_attachment_is_image($id) ) |
|
| 168 | - return false; |
|
| 168 | + if ( !wp_attachment_is_image($id) ) { |
|
| 169 | + return false; |
|
| 170 | + } |
|
| 169 | 171 | |
| 170 | 172 | /** |
| 171 | 173 | * Filters whether to preempt the output of image_downsize(). |
@@ -196,8 +198,7 @@ discard block |
||
| 196 | 198 | $width = $intermediate['width']; |
| 197 | 199 | $height = $intermediate['height']; |
| 198 | 200 | $is_intermediate = true; |
| 199 | - } |
|
| 200 | - elseif ( $size == 'thumbnail' ) { |
|
| 201 | + } elseif ( $size == 'thumbnail' ) { |
|
| 201 | 202 | // fall back to the old thumbnail |
| 202 | 203 | if ( ($thumb_file = wp_get_attachment_thumb_file($id)) && $info = getimagesize($thumb_file) ) { |
| 203 | 204 | $img_url = str_replace($img_url_basename, wp_basename($thumb_file), $img_url); |
@@ -384,8 +385,9 @@ discard block |
||
| 384 | 385 | * @return array First item is the width, the second item is the height. |
| 385 | 386 | */ |
| 386 | 387 | function wp_constrain_dimensions( $current_width, $current_height, $max_width = 0, $max_height = 0 ) { |
| 387 | - if ( !$max_width && !$max_height ) |
|
| 388 | - return array( $current_width, $current_height ); |
|
| 388 | + if ( !$max_width && !$max_height ) { |
|
| 389 | + return array( $current_width, $current_height ); |
|
| 390 | + } |
|
| 389 | 391 | |
| 390 | 392 | $width_ratio = $height_ratio = 1.0; |
| 391 | 393 | $did_width = $did_height = false; |
@@ -470,11 +472,13 @@ discard block |
||
| 470 | 472 | */ |
| 471 | 473 | function image_resize_dimensions( $orig_w, $orig_h, $dest_w, $dest_h, $crop = false ) { |
| 472 | 474 | |
| 473 | - if ($orig_w <= 0 || $orig_h <= 0) |
|
| 474 | - return false; |
|
| 475 | + if ($orig_w <= 0 || $orig_h <= 0) { |
|
| 476 | + return false; |
|
| 477 | + } |
|
| 475 | 478 | // at least one of dest_w or dest_h must be specific |
| 476 | - if ($dest_w <= 0 && $dest_h <= 0) |
|
| 477 | - return false; |
|
| 479 | + if ($dest_w <= 0 && $dest_h <= 0) { |
|
| 480 | + return false; |
|
| 481 | + } |
|
| 478 | 482 | |
| 479 | 483 | /** |
| 480 | 484 | * Filters whether to preempt calculating the image resize dimensions. |
@@ -493,8 +497,9 @@ discard block |
||
| 493 | 497 | * An array can specify positioning of the crop area. Default false. |
| 494 | 498 | */ |
| 495 | 499 | $output = apply_filters( 'image_resize_dimensions', null, $orig_w, $orig_h, $dest_w, $dest_h, $crop ); |
| 496 | - if ( null !== $output ) |
|
| 497 | - return $output; |
|
| 500 | + if ( null !== $output ) { |
|
| 501 | + return $output; |
|
| 502 | + } |
|
| 498 | 503 | |
| 499 | 504 | if ( $crop ) { |
| 500 | 505 | // crop the largest possible portion of the original image that we can size to $dest_w x $dest_h |
@@ -578,8 +583,9 @@ discard block |
||
| 578 | 583 | if ( $width || $height ) { |
| 579 | 584 | $editor = wp_get_image_editor( $file ); |
| 580 | 585 | |
| 581 | - if ( is_wp_error( $editor ) || is_wp_error( $editor->resize( $width, $height, $crop ) ) ) |
|
| 582 | - return false; |
|
| 586 | + if ( is_wp_error( $editor ) || is_wp_error( $editor->resize( $width, $height, $crop ) ) ) { |
|
| 587 | + return false; |
|
| 588 | + } |
|
| 583 | 589 | |
| 584 | 590 | $resized_file = $editor->save(); |
| 585 | 591 | |
@@ -755,8 +761,9 @@ discard block |
||
| 755 | 761 | function get_intermediate_image_sizes() { |
| 756 | 762 | global $_wp_additional_image_sizes; |
| 757 | 763 | $image_sizes = array('thumbnail', 'medium', 'medium_large', 'large'); // Standard sizes |
| 758 | - if ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) ) |
|
| 759 | - $image_sizes = array_merge( $image_sizes, array_keys( $_wp_additional_image_sizes ) ); |
|
| 764 | + if ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) ) { |
|
| 765 | + $image_sizes = array_merge( $image_sizes, array_keys( $_wp_additional_image_sizes ) ); |
|
| 766 | + } |
|
| 760 | 767 | |
| 761 | 768 | /** |
| 762 | 769 | * Filters the list of intermediate image sizes. |
@@ -852,10 +859,14 @@ discard block |
||
| 852 | 859 | 'class' => "attachment-$size_class size-$size_class", |
| 853 | 860 | 'alt' => trim(strip_tags( get_post_meta($attachment_id, '_wp_attachment_image_alt', true) )), // Use Alt field first |
| 854 | 861 | ); |
| 855 | - if ( empty($default_attr['alt']) ) |
|
| 856 | - $default_attr['alt'] = trim(strip_tags( $attachment->post_excerpt )); // If not, Use the Caption |
|
| 857 | - if ( empty($default_attr['alt']) ) |
|
| 858 | - $default_attr['alt'] = trim(strip_tags( $attachment->post_title )); // Finally, use the title |
|
| 862 | + if ( empty($default_attr['alt']) ) { |
|
| 863 | + $default_attr['alt'] = trim(strip_tags( $attachment->post_excerpt )); |
|
| 864 | + } |
|
| 865 | + // If not, Use the Caption |
|
| 866 | + if ( empty($default_attr['alt']) ) { |
|
| 867 | + $default_attr['alt'] = trim(strip_tags( $attachment->post_title )); |
|
| 868 | + } |
|
| 869 | + // Finally, use the title |
|
| 859 | 870 | |
| 860 | 871 | $attr = wp_parse_args( $attr, $default_attr ); |
| 861 | 872 | |
@@ -1507,8 +1518,9 @@ discard block |
||
| 1507 | 1518 | * @param string $content The image element, possibly wrapped in a hyperlink. |
| 1508 | 1519 | */ |
| 1509 | 1520 | $output = apply_filters( 'img_caption_shortcode', '', $attr, $content ); |
| 1510 | - if ( $output != '' ) |
|
| 1511 | - return $output; |
|
| 1521 | + if ( $output != '' ) { |
|
| 1522 | + return $output; |
|
| 1523 | + } |
|
| 1512 | 1524 | |
| 1513 | 1525 | $atts = shortcode_atts( array( |
| 1514 | 1526 | 'id' => '', |
@@ -1519,11 +1531,13 @@ discard block |
||
| 1519 | 1531 | ), $attr, 'caption' ); |
| 1520 | 1532 | |
| 1521 | 1533 | $atts['width'] = (int) $atts['width']; |
| 1522 | - if ( $atts['width'] < 1 || empty( $atts['caption'] ) ) |
|
| 1523 | - return $content; |
|
| 1534 | + if ( $atts['width'] < 1 || empty( $atts['caption'] ) ) { |
|
| 1535 | + return $content; |
|
| 1536 | + } |
|
| 1524 | 1537 | |
| 1525 | - if ( ! empty( $atts['id'] ) ) |
|
| 1526 | - $atts['id'] = 'id="' . esc_attr( sanitize_html_class( $atts['id'] ) ) . '" '; |
|
| 1538 | + if ( ! empty( $atts['id'] ) ) { |
|
| 1539 | + $atts['id'] = 'id="' . esc_attr( sanitize_html_class( $atts['id'] ) ) . '" '; |
|
| 1540 | + } |
|
| 1527 | 1541 | |
| 1528 | 1542 | $class = trim( 'wp-caption ' . $atts['align'] . ' ' . $atts['class'] ); |
| 1529 | 1543 | |
@@ -1549,8 +1563,9 @@ discard block |
||
| 1549 | 1563 | $caption_width = apply_filters( 'img_caption_shortcode_width', $width, $atts, $content ); |
| 1550 | 1564 | |
| 1551 | 1565 | $style = ''; |
| 1552 | - if ( $caption_width ) |
|
| 1553 | - $style = 'style="width: ' . (int) $caption_width . 'px" '; |
|
| 1566 | + if ( $caption_width ) { |
|
| 1567 | + $style = 'style="width: ' . (int) $caption_width . 'px" '; |
|
| 1568 | + } |
|
| 1554 | 1569 | |
| 1555 | 1570 | $html = ''; |
| 1556 | 1571 | if ( $html5 ) { |
@@ -2704,28 +2719,32 @@ discard block |
||
| 2704 | 2719 | } elseif ( is_array( $attachment ) ) { |
| 2705 | 2720 | $attachment = (object) $attachment; |
| 2706 | 2721 | } |
| 2707 | - if ( ! is_object($attachment) ) |
|
| 2708 | - return array(); |
|
| 2722 | + if ( ! is_object($attachment) ) { |
|
| 2723 | + return array(); |
|
| 2724 | + } |
|
| 2709 | 2725 | |
| 2710 | 2726 | $file = get_attached_file( $attachment->ID ); |
| 2711 | 2727 | $filename = basename( $file ); |
| 2712 | 2728 | |
| 2713 | 2729 | $objects = array('attachment'); |
| 2714 | 2730 | |
| 2715 | - if ( false !== strpos($filename, '.') ) |
|
| 2716 | - $objects[] = 'attachment:' . substr($filename, strrpos($filename, '.') + 1); |
|
| 2731 | + if ( false !== strpos($filename, '.') ) { |
|
| 2732 | + $objects[] = 'attachment:' . substr($filename, strrpos($filename, '.') + 1); |
|
| 2733 | + } |
|
| 2717 | 2734 | if ( !empty($attachment->post_mime_type) ) { |
| 2718 | 2735 | $objects[] = 'attachment:' . $attachment->post_mime_type; |
| 2719 | - if ( false !== strpos($attachment->post_mime_type, '/') ) |
|
| 2720 | - foreach ( explode('/', $attachment->post_mime_type) as $token ) |
|
| 2736 | + if ( false !== strpos($attachment->post_mime_type, '/') ) { |
|
| 2737 | + foreach ( explode('/', $attachment->post_mime_type) as $token ) |
|
| 2721 | 2738 | if ( !empty($token) ) |
| 2722 | 2739 | $objects[] = "attachment:$token"; |
| 2740 | + } |
|
| 2723 | 2741 | } |
| 2724 | 2742 | |
| 2725 | 2743 | $taxonomies = array(); |
| 2726 | - foreach ( $objects as $object ) |
|
| 2727 | - if ( $taxes = get_object_taxonomies($object) ) |
|
| 2744 | + foreach ( $objects as $object ) { |
|
| 2745 | + if ( $taxes = get_object_taxonomies($object) ) |
|
| 2728 | 2746 | $taxonomies = array_merge($taxonomies, $taxes); |
| 2747 | + } |
|
| 2729 | 2748 | |
| 2730 | 2749 | return array_unique($taxonomies); |
| 2731 | 2750 | } |
@@ -2748,10 +2767,11 @@ discard block |
||
| 2748 | 2767 | foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy ) { |
| 2749 | 2768 | foreach ( $taxonomy->object_type as $object_type ) { |
| 2750 | 2769 | if ( 'attachment' == $object_type || 0 === strpos( $object_type, 'attachment:' ) ) { |
| 2751 | - if ( 'names' == $output ) |
|
| 2752 | - $taxonomies[] = $taxonomy->name; |
|
| 2753 | - else |
|
| 2754 | - $taxonomies[ $taxonomy->name ] = $taxonomy; |
|
| 2770 | + if ( 'names' == $output ) { |
|
| 2771 | + $taxonomies[] = $taxonomy->name; |
|
| 2772 | + } else { |
|
| 2773 | + $taxonomies[ $taxonomy->name ] = $taxonomy; |
|
| 2774 | + } |
|
| 2755 | 2775 | break; |
| 2756 | 2776 | } |
| 2757 | 2777 | } |
@@ -2844,8 +2864,9 @@ discard block |
||
| 2844 | 2864 | |
| 2845 | 2865 | // If $file_info['type'] is false, then we let the editor attempt to |
| 2846 | 2866 | // figure out the file type, rather than forcing a failure based on extension. |
| 2847 | - if ( isset( $file_info ) && $file_info['type'] ) |
|
| 2848 | - $args['mime_type'] = $file_info['type']; |
|
| 2867 | + if ( isset( $file_info ) && $file_info['type'] ) { |
|
| 2868 | + $args['mime_type'] = $file_info['type']; |
|
| 2869 | + } |
|
| 2849 | 2870 | } |
| 2850 | 2871 | |
| 2851 | 2872 | $implementation = _wp_image_editor_choose( $args ); |
@@ -2854,8 +2875,9 @@ discard block |
||
| 2854 | 2875 | $editor = new $implementation( $path ); |
| 2855 | 2876 | $loaded = $editor->load(); |
| 2856 | 2877 | |
| 2857 | - if ( is_wp_error( $loaded ) ) |
|
| 2858 | - return $loaded; |
|
| 2878 | + if ( is_wp_error( $loaded ) ) { |
|
| 2879 | + return $loaded; |
|
| 2880 | + } |
|
| 2859 | 2881 | |
| 2860 | 2882 | return $editor; |
| 2861 | 2883 | } |
@@ -2902,8 +2924,9 @@ discard block |
||
| 2902 | 2924 | $implementations = apply_filters( 'wp_image_editors', array( 'WP_Image_Editor_Imagick', 'WP_Image_Editor_GD' ) ); |
| 2903 | 2925 | |
| 2904 | 2926 | foreach ( $implementations as $implementation ) { |
| 2905 | - if ( ! call_user_func( array( $implementation, 'test' ), $args ) ) |
|
| 2906 | - continue; |
|
| 2927 | + if ( ! call_user_func( array( $implementation, 'test' ), $args ) ) { |
|
| 2928 | + continue; |
|
| 2929 | + } |
|
| 2907 | 2930 | |
| 2908 | 2931 | if ( isset( $args['mime_type'] ) && |
| 2909 | 2932 | ! call_user_func( |
@@ -2932,8 +2955,9 @@ discard block |
||
| 2932 | 2955 | $wp_scripts = wp_scripts(); |
| 2933 | 2956 | |
| 2934 | 2957 | $data = $wp_scripts->get_data( 'wp-plupload', 'data' ); |
| 2935 | - if ( $data && false !== strpos( $data, '_wpPluploadSettings' ) ) |
|
| 2936 | - return; |
|
| 2958 | + if ( $data && false !== strpos( $data, '_wpPluploadSettings' ) ) { |
|
| 2959 | + return; |
|
| 2960 | + } |
|
| 2937 | 2961 | |
| 2938 | 2962 | $max_upload_size = wp_max_upload_size(); |
| 2939 | 2963 | $allowed_extensions = array_keys( get_allowed_mime_types() ); |
@@ -2997,8 +3021,9 @@ discard block |
||
| 2997 | 3021 | |
| 2998 | 3022 | $script = 'var _wpPluploadSettings = ' . wp_json_encode( $settings ) . ';'; |
| 2999 | 3023 | |
| 3000 | - if ( $data ) |
|
| 3001 | - $script = "$data\n$script"; |
|
| 3024 | + if ( $data ) { |
|
| 3025 | + $script = "$data\n$script"; |
|
| 3026 | + } |
|
| 3002 | 3027 | |
| 3003 | 3028 | $wp_scripts->add_data( 'wp-plupload', 'data', $script ); |
| 3004 | 3029 | } |
@@ -3013,17 +3038,20 @@ discard block |
||
| 3013 | 3038 | * @return array|void Array of attachment details. |
| 3014 | 3039 | */ |
| 3015 | 3040 | function wp_prepare_attachment_for_js( $attachment ) { |
| 3016 | - if ( ! $attachment = get_post( $attachment ) ) |
|
| 3017 | - return; |
|
| 3041 | + if ( ! $attachment = get_post( $attachment ) ) { |
|
| 3042 | + return; |
|
| 3043 | + } |
|
| 3018 | 3044 | |
| 3019 | - if ( 'attachment' != $attachment->post_type ) |
|
| 3020 | - return; |
|
| 3045 | + if ( 'attachment' != $attachment->post_type ) { |
|
| 3046 | + return; |
|
| 3047 | + } |
|
| 3021 | 3048 | |
| 3022 | 3049 | $meta = wp_get_attachment_metadata( $attachment->ID ); |
| 3023 | - if ( false !== strpos( $attachment->post_mime_type, '/' ) ) |
|
| 3024 | - list( $type, $subtype ) = explode( '/', $attachment->post_mime_type ); |
|
| 3025 | - else |
|
| 3026 | - list( $type, $subtype ) = array( $attachment->post_mime_type, '' ); |
|
| 3050 | + if ( false !== strpos( $attachment->post_mime_type, '/' ) ) { |
|
| 3051 | + list( $type, $subtype ) = explode( '/', $attachment->post_mime_type ); |
|
| 3052 | + } else { |
|
| 3053 | + list( $type, $subtype ) = array( $attachment->post_mime_type, '' ); |
|
| 3054 | + } |
|
| 3027 | 3055 | |
| 3028 | 3056 | $attachment_url = wp_get_attachment_url( $attachment->ID ); |
| 3029 | 3057 | |
@@ -3099,8 +3127,9 @@ discard block |
||
| 3099 | 3127 | $response['editLink'] = get_edit_post_link( $attachment->ID, 'raw' ); |
| 3100 | 3128 | } |
| 3101 | 3129 | |
| 3102 | - if ( current_user_can( 'delete_post', $attachment->ID ) ) |
|
| 3103 | - $response['nonces']['delete'] = wp_create_nonce( 'delete-post_' . $attachment->ID ); |
|
| 3130 | + if ( current_user_can( 'delete_post', $attachment->ID ) ) { |
|
| 3131 | + $response['nonces']['delete'] = wp_create_nonce( 'delete-post_' . $attachment->ID ); |
|
| 3132 | + } |
|
| 3104 | 3133 | |
| 3105 | 3134 | if ( $meta && 'image' === $type ) { |
| 3106 | 3135 | $sizes = array(); |
@@ -3122,8 +3151,9 @@ discard block |
||
| 3122 | 3151 | |
| 3123 | 3152 | /** This filter is documented in wp-includes/media.php */ |
| 3124 | 3153 | if ( $downsize = apply_filters( 'image_downsize', false, $attachment->ID, $size ) ) { |
| 3125 | - if ( ! $downsize[3] ) |
|
| 3126 | - continue; |
|
| 3154 | + if ( ! $downsize[3] ) { |
|
| 3155 | + continue; |
|
| 3156 | + } |
|
| 3127 | 3157 | $sizes[ $size ] = array( |
| 3128 | 3158 | 'height' => $downsize[2], |
| 3129 | 3159 | 'width' => $downsize[1], |
@@ -3131,8 +3161,9 @@ discard block |
||
| 3131 | 3161 | 'orientation' => $downsize[2] > $downsize[1] ? 'portrait' : 'landscape', |
| 3132 | 3162 | ); |
| 3133 | 3163 | } elseif ( isset( $meta['sizes'][ $size ] ) ) { |
| 3134 | - if ( ! isset( $base_url ) ) |
|
| 3135 | - $base_url = str_replace( wp_basename( $attachment_url ), '', $attachment_url ); |
|
| 3164 | + if ( ! isset( $base_url ) ) { |
|
| 3165 | + $base_url = str_replace( wp_basename( $attachment_url ), '', $attachment_url ); |
|
| 3166 | + } |
|
| 3136 | 3167 | |
| 3137 | 3168 | // Nothing from the filter, so consult image metadata if we have it. |
| 3138 | 3169 | $size_meta = $meta['sizes'][ $size ]; |
@@ -3160,15 +3191,18 @@ discard block |
||
| 3160 | 3191 | |
| 3161 | 3192 | $response = array_merge( $response, array( 'sizes' => $sizes ), $sizes['full'] ); |
| 3162 | 3193 | } elseif ( $meta && 'video' === $type ) { |
| 3163 | - if ( isset( $meta['width'] ) ) |
|
| 3164 | - $response['width'] = (int) $meta['width']; |
|
| 3165 | - if ( isset( $meta['height'] ) ) |
|
| 3166 | - $response['height'] = (int) $meta['height']; |
|
| 3194 | + if ( isset( $meta['width'] ) ) { |
|
| 3195 | + $response['width'] = (int) $meta['width']; |
|
| 3196 | + } |
|
| 3197 | + if ( isset( $meta['height'] ) ) { |
|
| 3198 | + $response['height'] = (int) $meta['height']; |
|
| 3199 | + } |
|
| 3167 | 3200 | } |
| 3168 | 3201 | |
| 3169 | 3202 | if ( $meta && ( 'audio' === $type || 'video' === $type ) ) { |
| 3170 | - if ( isset( $meta['length_formatted'] ) ) |
|
| 3171 | - $response['fileLength'] = $meta['length_formatted']; |
|
| 3203 | + if ( isset( $meta['length_formatted'] ) ) { |
|
| 3204 | + $response['fileLength'] = $meta['length_formatted']; |
|
| 3205 | + } |
|
| 3172 | 3206 | |
| 3173 | 3207 | $response['meta'] = array(); |
| 3174 | 3208 | foreach ( wp_get_attachment_id3_keys( $attachment, 'js' ) as $key => $label ) { |
@@ -3194,8 +3228,9 @@ discard block |
||
| 3194 | 3228 | } |
| 3195 | 3229 | } |
| 3196 | 3230 | |
| 3197 | - if ( function_exists('get_compat_media_markup') ) |
|
| 3198 | - $response['compat'] = get_compat_media_markup( $attachment->ID, array( 'in_modal' => true ) ); |
|
| 3231 | + if ( function_exists('get_compat_media_markup') ) { |
|
| 3232 | + $response['compat'] = get_compat_media_markup( $attachment->ID, array( 'in_modal' => true ) ); |
|
| 3233 | + } |
|
| 3199 | 3234 | |
| 3200 | 3235 | /** |
| 3201 | 3236 | * Filters the attachment data prepared for JavaScript. |
@@ -3227,8 +3262,9 @@ discard block |
||
| 3227 | 3262 | */ |
| 3228 | 3263 | function wp_enqueue_media( $args = array() ) { |
| 3229 | 3264 | // Enqueue me just once per page, please. |
| 3230 | - if ( did_action( 'wp_enqueue_media' ) ) |
|
| 3231 | - return; |
|
| 3265 | + if ( did_action( 'wp_enqueue_media' ) ) { |
|
| 3266 | + return; |
|
| 3267 | + } |
|
| 3232 | 3268 | |
| 3233 | 3269 | global $content_width, $wpdb, $wp_locale; |
| 3234 | 3270 | |
@@ -3527,8 +3563,9 @@ discard block |
||
| 3527 | 3563 | * @return array Found attachments. |
| 3528 | 3564 | */ |
| 3529 | 3565 | function get_attached_media( $type, $post = 0 ) { |
| 3530 | - if ( ! $post = get_post( $post ) ) |
|
| 3531 | - return array(); |
|
| 3566 | + if ( ! $post = get_post( $post ) ) { |
|
| 3567 | + return array(); |
|
| 3568 | + } |
|
| 3532 | 3569 | |
| 3533 | 3570 | $args = array( |
| 3534 | 3571 | 'post_parent' => $post->ID, |
@@ -3616,11 +3653,13 @@ discard block |
||
| 3616 | 3653 | * from the expanded shortcode. |
| 3617 | 3654 | */ |
| 3618 | 3655 | function get_post_galleries( $post, $html = true ) { |
| 3619 | - if ( ! $post = get_post( $post ) ) |
|
| 3620 | - return array(); |
|
| 3656 | + if ( ! $post = get_post( $post ) ) { |
|
| 3657 | + return array(); |
|
| 3658 | + } |
|
| 3621 | 3659 | |
| 3622 | - if ( ! has_shortcode( $post->post_content, 'gallery' ) ) |
|
| 3623 | - return array(); |
|
| 3660 | + if ( ! has_shortcode( $post->post_content, 'gallery' ) ) { |
|
| 3661 | + return array(); |
|
| 3662 | + } |
|
| 3624 | 3663 | |
| 3625 | 3664 | $galleries = array(); |
| 3626 | 3665 | if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $post->post_content, $matches, PREG_SET_ORDER ) ) { |
@@ -3634,8 +3673,9 @@ discard block |
||
| 3634 | 3673 | } else { |
| 3635 | 3674 | preg_match_all( '#src=([\'"])(.+?)\1#is', $gallery, $src, PREG_SET_ORDER ); |
| 3636 | 3675 | if ( ! empty( $src ) ) { |
| 3637 | - foreach ( $src as $s ) |
|
| 3638 | - $srcs[] = $s[2]; |
|
| 3676 | + foreach ( $src as $s ) { |
|
| 3677 | + $srcs[] = $s[2]; |
|
| 3678 | + } |
|
| 3639 | 3679 | } |
| 3640 | 3680 | |
| 3641 | 3681 | $data = shortcode_parse_atts( $shortcode[3] ); |
@@ -142,8 +142,8 @@ discard block |
||
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | $file = str_replace('_', '/', $class); |
| 145 | - if (file_exists(dirname(__FILE__) . '/' . $file . '.php')) { |
|
| 146 | - require_once(dirname(__FILE__) . '/' . $file . '.php'); |
|
| 145 | + if (file_exists(dirname(__FILE__).'/'.$file.'.php')) { |
|
| 146 | + require_once(dirname(__FILE__).'/'.$file.'.php'); |
|
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | 149 | |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | |
| 201 | 201 | // Find us a working transport |
| 202 | 202 | foreach (self::$transports as $class) { |
| 203 | - if (!class_exists($class)) { |
|
| 203 | + if ( ! class_exists($class)) { |
|
| 204 | 204 | continue; |
| 205 | 205 | } |
| 206 | 206 | |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | |
| 365 | 365 | $options['hooks']->dispatch('requests.before_request', array(&$url, &$headers, &$data, &$type, &$options)); |
| 366 | 366 | |
| 367 | - if (!empty($options['transport'])) { |
|
| 367 | + if ( ! empty($options['transport'])) { |
|
| 368 | 368 | $transport = $options['transport']; |
| 369 | 369 | |
| 370 | 370 | if (is_string($options['transport'])) { |
@@ -427,24 +427,24 @@ discard block |
||
| 427 | 427 | public static function request_multiple($requests, $options = array()) { |
| 428 | 428 | $options = array_merge(self::get_default_options(true), $options); |
| 429 | 429 | |
| 430 | - if (!empty($options['hooks'])) { |
|
| 430 | + if ( ! empty($options['hooks'])) { |
|
| 431 | 431 | $options['hooks']->register('transport.internal.parse_response', array('Requests', 'parse_multiple')); |
| 432 | - if (!empty($options['complete'])) { |
|
| 432 | + if ( ! empty($options['complete'])) { |
|
| 433 | 433 | $options['hooks']->register('multiple.request.complete', $options['complete']); |
| 434 | 434 | } |
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | foreach ($requests as $id => &$request) { |
| 438 | - if (!isset($request['headers'])) { |
|
| 438 | + if ( ! isset($request['headers'])) { |
|
| 439 | 439 | $request['headers'] = array(); |
| 440 | 440 | } |
| 441 | - if (!isset($request['data'])) { |
|
| 441 | + if ( ! isset($request['data'])) { |
|
| 442 | 442 | $request['data'] = array(); |
| 443 | 443 | } |
| 444 | - if (!isset($request['type'])) { |
|
| 444 | + if ( ! isset($request['type'])) { |
|
| 445 | 445 | $request['type'] = self::GET; |
| 446 | 446 | } |
| 447 | - if (!isset($request['options'])) { |
|
| 447 | + if ( ! isset($request['options'])) { |
|
| 448 | 448 | $request['options'] = $options; |
| 449 | 449 | $request['options']['type'] = $request['type']; |
| 450 | 450 | } |
@@ -460,14 +460,14 @@ discard block |
||
| 460 | 460 | // Ensure we only hook in once |
| 461 | 461 | if ($request['options']['hooks'] !== $options['hooks']) { |
| 462 | 462 | $request['options']['hooks']->register('transport.internal.parse_response', array('Requests', 'parse_multiple')); |
| 463 | - if (!empty($request['options']['complete'])) { |
|
| 463 | + if ( ! empty($request['options']['complete'])) { |
|
| 464 | 464 | $request['options']['hooks']->register('multiple.request.complete', $request['options']['complete']); |
| 465 | 465 | } |
| 466 | 466 | } |
| 467 | 467 | } |
| 468 | 468 | unset($request); |
| 469 | 469 | |
| 470 | - if (!empty($options['transport'])) { |
|
| 470 | + if ( ! empty($options['transport'])) { |
|
| 471 | 471 | $transport = $options['transport']; |
| 472 | 472 | |
| 473 | 473 | if (is_string($options['transport'])) { |
@@ -503,7 +503,7 @@ discard block |
||
| 503 | 503 | $defaults = array( |
| 504 | 504 | 'timeout' => 10, |
| 505 | 505 | 'connect_timeout' => 10, |
| 506 | - 'useragent' => 'php-requests/' . self::VERSION, |
|
| 506 | + 'useragent' => 'php-requests/'.self::VERSION, |
|
| 507 | 507 | 'protocol_version' => 1.1, |
| 508 | 508 | 'redirected' => 0, |
| 509 | 509 | 'redirects' => 10, |
@@ -533,11 +533,11 @@ discard block |
||
| 533 | 533 | * @return string Default certificate path. |
| 534 | 534 | */ |
| 535 | 535 | public static function get_certificate_path() { |
| 536 | - if ( ! empty( Requests::$certificate_path ) ) { |
|
| 536 | + if ( ! empty(Requests::$certificate_path)) { |
|
| 537 | 537 | return Requests::$certificate_path; |
| 538 | 538 | } |
| 539 | 539 | |
| 540 | - return dirname(__FILE__) . '/Requests/Transport/cacert.pem'; |
|
| 540 | + return dirname(__FILE__).'/Requests/Transport/cacert.pem'; |
|
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | /** |
@@ -545,7 +545,7 @@ discard block |
||
| 545 | 545 | * |
| 546 | 546 | * @param string $path Certificate path, pointing to a PEM file. |
| 547 | 547 | */ |
| 548 | - public static function set_certificate_path( $path ) { |
|
| 548 | + public static function set_certificate_path($path) { |
|
| 549 | 549 | Requests::$certificate_path = $path; |
| 550 | 550 | } |
| 551 | 551 | |
@@ -560,7 +560,7 @@ discard block |
||
| 560 | 560 | * @return array $options |
| 561 | 561 | */ |
| 562 | 562 | protected static function set_defaults(&$url, &$headers, &$data, &$type, &$options) { |
| 563 | - if (!preg_match('/^http(s)?:\/\//i', $url, $matches)) { |
|
| 563 | + if ( ! preg_match('/^http(s)?:\/\//i', $url, $matches)) { |
|
| 564 | 564 | throw new Requests_Exception('Only HTTP(S) requests are handled.', 'nonhttp', $url); |
| 565 | 565 | } |
| 566 | 566 | |
@@ -601,7 +601,7 @@ discard block |
||
| 601 | 601 | // Massage the type to ensure we support it. |
| 602 | 602 | $type = strtoupper($type); |
| 603 | 603 | |
| 604 | - if (!isset($options['data_format'])) { |
|
| 604 | + if ( ! isset($options['data_format'])) { |
|
| 605 | 605 | if (in_array($type, array(self::HEAD, self::GET, self::DELETE))) { |
| 606 | 606 | $options['data_format'] = 'query'; |
| 607 | 607 | } |
@@ -627,14 +627,14 @@ discard block |
||
| 627 | 627 | */ |
| 628 | 628 | protected static function parse_response($headers, $url, $req_headers, $req_data, $options) { |
| 629 | 629 | $return = new Requests_Response(); |
| 630 | - if (!$options['blocking']) { |
|
| 630 | + if ( ! $options['blocking']) { |
|
| 631 | 631 | return $return; |
| 632 | 632 | } |
| 633 | 633 | |
| 634 | 634 | $return->raw = $headers; |
| 635 | 635 | $return->url = $url; |
| 636 | 636 | |
| 637 | - if (!$options['filename']) { |
|
| 637 | + if ( ! $options['filename']) { |
|
| 638 | 638 | if (($pos = strpos($headers, "\r\n\r\n")) === false) { |
| 639 | 639 | // Crap! |
| 640 | 640 | throw new Requests_Exception('Missing header/body separator', 'requests.no_crlf_separator'); |
@@ -749,7 +749,7 @@ discard block |
||
| 749 | 749 | * @return string Decoded body |
| 750 | 750 | */ |
| 751 | 751 | protected static function decode_chunked($data) { |
| 752 | - if (!preg_match('/^([0-9a-f]+)[^\r\n]*\r\n/i', trim($data))) { |
|
| 752 | + if ( ! preg_match('/^([0-9a-f]+)[^\r\n]*\r\n/i', trim($data))) { |
|
| 753 | 753 | return $data; |
| 754 | 754 | } |
| 755 | 755 | |
@@ -758,7 +758,7 @@ discard block |
||
| 758 | 758 | |
| 759 | 759 | while (true) { |
| 760 | 760 | $is_chunked = (bool) preg_match('/^([0-9a-f]+)[^\r\n]*\r\n/i', $encoded, $matches); |
| 761 | - if (!$is_chunked) { |
|
| 761 | + if ( ! $is_chunked) { |
|
| 762 | 762 | // Looks like it's not chunked after all |
| 763 | 763 | return $data; |
| 764 | 764 | } |
@@ -927,7 +927,7 @@ discard block |
||
| 927 | 927 | // between a compressed document, and a ZIP file |
| 928 | 928 | $zip_compressed_on_the_fly = (0x08 == (0x08 & $general_purpose_flag)); |
| 929 | 929 | |
| 930 | - if (!$zip_compressed_on_the_fly) { |
|
| 930 | + if ( ! $zip_compressed_on_the_fly) { |
|
| 931 | 931 | // Don't attempt to decode a compressed zip file |
| 932 | 932 | return $gzData; |
| 933 | 933 | } |
@@ -122,11 +122,11 @@ discard block |
||
| 122 | 122 | * theme mod or option name. |
| 123 | 123 | * @param array $args Setting arguments. |
| 124 | 124 | */ |
| 125 | - public function __construct( $manager, $id, $args = array() ) { |
|
| 126 | - $keys = array_keys( get_object_vars( $this ) ); |
|
| 127 | - foreach ( $keys as $key ) { |
|
| 128 | - if ( isset( $args[ $key ] ) ) { |
|
| 129 | - $this->$key = $args[ $key ]; |
|
| 125 | + public function __construct($manager, $id, $args = array()) { |
|
| 126 | + $keys = array_keys(get_object_vars($this)); |
|
| 127 | + foreach ($keys as $key) { |
|
| 128 | + if (isset($args[$key])) { |
|
| 129 | + $this->$key = $args[$key]; |
|
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | |
@@ -134,32 +134,32 @@ discard block |
||
| 134 | 134 | $this->id = $id; |
| 135 | 135 | |
| 136 | 136 | // Parse the ID for array keys. |
| 137 | - $this->id_data['keys'] = preg_split( '/\[/', str_replace( ']', '', $this->id ) ); |
|
| 138 | - $this->id_data['base'] = array_shift( $this->id_data['keys'] ); |
|
| 137 | + $this->id_data['keys'] = preg_split('/\[/', str_replace(']', '', $this->id)); |
|
| 138 | + $this->id_data['base'] = array_shift($this->id_data['keys']); |
|
| 139 | 139 | |
| 140 | 140 | // Rebuild the ID. |
| 141 | - $this->id = $this->id_data[ 'base' ]; |
|
| 142 | - if ( ! empty( $this->id_data[ 'keys' ] ) ) { |
|
| 143 | - $this->id .= '[' . implode( '][', $this->id_data['keys'] ) . ']'; |
|
| 141 | + $this->id = $this->id_data['base']; |
|
| 142 | + if ( ! empty($this->id_data['keys'])) { |
|
| 143 | + $this->id .= '['.implode('][', $this->id_data['keys']).']'; |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - if ( $this->validate_callback ) { |
|
| 147 | - add_filter( "customize_validate_{$this->id}", $this->validate_callback, 10, 3 ); |
|
| 146 | + if ($this->validate_callback) { |
|
| 147 | + add_filter("customize_validate_{$this->id}", $this->validate_callback, 10, 3); |
|
| 148 | 148 | } |
| 149 | - if ( $this->sanitize_callback ) { |
|
| 150 | - add_filter( "customize_sanitize_{$this->id}", $this->sanitize_callback, 10, 2 ); |
|
| 149 | + if ($this->sanitize_callback) { |
|
| 150 | + add_filter("customize_sanitize_{$this->id}", $this->sanitize_callback, 10, 2); |
|
| 151 | 151 | } |
| 152 | - if ( $this->sanitize_js_callback ) { |
|
| 153 | - add_filter( "customize_sanitize_js_{$this->id}", $this->sanitize_js_callback, 10, 2 ); |
|
| 152 | + if ($this->sanitize_js_callback) { |
|
| 153 | + add_filter("customize_sanitize_js_{$this->id}", $this->sanitize_js_callback, 10, 2); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - if ( 'option' === $this->type || 'theme_mod' === $this->type ) { |
|
| 156 | + if ('option' === $this->type || 'theme_mod' === $this->type) { |
|
| 157 | 157 | // Other setting types can opt-in to aggregate multidimensional explicitly. |
| 158 | 158 | $this->aggregate_multidimensional(); |
| 159 | 159 | |
| 160 | 160 | // Allow option settings to indicate whether they should be autoloaded. |
| 161 | - if ( 'option' === $this->type && isset( $args['autoload'] ) ) { |
|
| 162 | - self::$aggregated_multidimensionals[ $this->type ][ $this->id_data['base'] ]['autoload'] = $args['autoload']; |
|
| 161 | + if ('option' === $this->type && isset($args['autoload'])) { |
|
| 162 | + self::$aggregated_multidimensionals[$this->type][$this->id_data['base']]['autoload'] = $args['autoload']; |
|
| 163 | 163 | } |
| 164 | 164 | } |
| 165 | 165 | } |
@@ -192,20 +192,20 @@ discard block |
||
| 192 | 192 | */ |
| 193 | 193 | protected function aggregate_multidimensional() { |
| 194 | 194 | $id_base = $this->id_data['base']; |
| 195 | - if ( ! isset( self::$aggregated_multidimensionals[ $this->type ] ) ) { |
|
| 196 | - self::$aggregated_multidimensionals[ $this->type ] = array(); |
|
| 195 | + if ( ! isset(self::$aggregated_multidimensionals[$this->type])) { |
|
| 196 | + self::$aggregated_multidimensionals[$this->type] = array(); |
|
| 197 | 197 | } |
| 198 | - if ( ! isset( self::$aggregated_multidimensionals[ $this->type ][ $id_base ] ) ) { |
|
| 199 | - self::$aggregated_multidimensionals[ $this->type ][ $id_base ] = array( |
|
| 198 | + if ( ! isset(self::$aggregated_multidimensionals[$this->type][$id_base])) { |
|
| 199 | + self::$aggregated_multidimensionals[$this->type][$id_base] = array( |
|
| 200 | 200 | 'previewed_instances' => array(), // Calling preview() will add the $setting to the array. |
| 201 | 201 | 'preview_applied_instances' => array(), // Flags for which settings have had their values applied. |
| 202 | - 'root_value' => $this->get_root_value( array() ), // Root value for initial state, manipulated by preview and update calls. |
|
| 202 | + 'root_value' => $this->get_root_value(array()), // Root value for initial state, manipulated by preview and update calls. |
|
| 203 | 203 | ); |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - if ( ! empty( $this->id_data['keys'] ) ) { |
|
| 206 | + if ( ! empty($this->id_data['keys'])) { |
|
| 207 | 207 | // Note the preview-applied flag is cleared at priority 9 to ensure it is cleared before a deferred-preview runs. |
| 208 | - add_action( "customize_post_value_set_{$this->id}", array( $this, '_clear_aggregated_multidimensional_preview_applied_flag' ), 9 ); |
|
| 208 | + add_action("customize_post_value_set_{$this->id}", array($this, '_clear_aggregated_multidimensional_preview_applied_flag'), 9); |
|
| 209 | 209 | $this->is_multidimensional_aggregated = true; |
| 210 | 210 | } |
| 211 | 211 | } |
@@ -241,10 +241,10 @@ discard block |
||
| 241 | 241 | * @return bool If preview() has been called. |
| 242 | 242 | */ |
| 243 | 243 | public function is_current_blog_previewed() { |
| 244 | - if ( ! isset( $this->_previewed_blog_id ) ) { |
|
| 244 | + if ( ! isset($this->_previewed_blog_id)) { |
|
| 245 | 245 | return false; |
| 246 | 246 | } |
| 247 | - return ( get_current_blog_id() === $this->_previewed_blog_id ); |
|
| 247 | + return (get_current_blog_id() === $this->_previewed_blog_id); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | /** |
@@ -270,18 +270,18 @@ discard block |
||
| 270 | 270 | * @return bool False when preview short-circuits due no change needing to be previewed. |
| 271 | 271 | */ |
| 272 | 272 | public function preview() { |
| 273 | - if ( ! isset( $this->_previewed_blog_id ) ) { |
|
| 273 | + if ( ! isset($this->_previewed_blog_id)) { |
|
| 274 | 274 | $this->_previewed_blog_id = get_current_blog_id(); |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | // Prevent re-previewing an already-previewed setting. |
| 278 | - if ( $this->is_previewed ) { |
|
| 278 | + if ($this->is_previewed) { |
|
| 279 | 279 | return true; |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | $id_base = $this->id_data['base']; |
| 283 | - $is_multidimensional = ! empty( $this->id_data['keys'] ); |
|
| 284 | - $multidimensional_filter = array( $this, '_multidimensional_preview_filter' ); |
|
| 283 | + $is_multidimensional = ! empty($this->id_data['keys']); |
|
| 284 | + $multidimensional_filter = array($this, '_multidimensional_preview_filter'); |
|
| 285 | 285 | |
| 286 | 286 | /* |
| 287 | 287 | * Check if the setting has a pre-existing value (an isset check), |
@@ -290,53 +290,53 @@ discard block |
||
| 290 | 290 | * to be previewed. |
| 291 | 291 | */ |
| 292 | 292 | $undefined = new stdClass(); |
| 293 | - $needs_preview = ( $undefined !== $this->post_value( $undefined ) ); |
|
| 293 | + $needs_preview = ($undefined !== $this->post_value($undefined)); |
|
| 294 | 294 | $value = null; |
| 295 | 295 | |
| 296 | 296 | // Since no post value was defined, check if we have an initial value set. |
| 297 | - if ( ! $needs_preview ) { |
|
| 298 | - if ( $this->is_multidimensional_aggregated ) { |
|
| 299 | - $root = self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['root_value']; |
|
| 300 | - $value = $this->multidimensional_get( $root, $this->id_data['keys'], $undefined ); |
|
| 297 | + if ( ! $needs_preview) { |
|
| 298 | + if ($this->is_multidimensional_aggregated) { |
|
| 299 | + $root = self::$aggregated_multidimensionals[$this->type][$id_base]['root_value']; |
|
| 300 | + $value = $this->multidimensional_get($root, $this->id_data['keys'], $undefined); |
|
| 301 | 301 | } else { |
| 302 | 302 | $default = $this->default; |
| 303 | 303 | $this->default = $undefined; // Temporarily set default to undefined so we can detect if existing value is set. |
| 304 | 304 | $value = $this->value(); |
| 305 | 305 | $this->default = $default; |
| 306 | 306 | } |
| 307 | - $needs_preview = ( $undefined === $value ); // Because the default needs to be supplied. |
|
| 307 | + $needs_preview = ($undefined === $value); // Because the default needs to be supplied. |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | // If the setting does not need previewing now, defer to when it has a value to preview. |
| 311 | - if ( ! $needs_preview ) { |
|
| 312 | - if ( ! has_action( "customize_post_value_set_{$this->id}", array( $this, 'preview' ) ) ) { |
|
| 313 | - add_action( "customize_post_value_set_{$this->id}", array( $this, 'preview' ) ); |
|
| 311 | + if ( ! $needs_preview) { |
|
| 312 | + if ( ! has_action("customize_post_value_set_{$this->id}", array($this, 'preview'))) { |
|
| 313 | + add_action("customize_post_value_set_{$this->id}", array($this, 'preview')); |
|
| 314 | 314 | } |
| 315 | 315 | return false; |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | - switch ( $this->type ) { |
|
| 318 | + switch ($this->type) { |
|
| 319 | 319 | case 'theme_mod' : |
| 320 | - if ( ! $is_multidimensional ) { |
|
| 321 | - add_filter( "theme_mod_{$id_base}", array( $this, '_preview_filter' ) ); |
|
| 320 | + if ( ! $is_multidimensional) { |
|
| 321 | + add_filter("theme_mod_{$id_base}", array($this, '_preview_filter')); |
|
| 322 | 322 | } else { |
| 323 | - if ( empty( self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['previewed_instances'] ) ) { |
|
| 323 | + if (empty(self::$aggregated_multidimensionals[$this->type][$id_base]['previewed_instances'])) { |
|
| 324 | 324 | // Only add this filter once for this ID base. |
| 325 | - add_filter( "theme_mod_{$id_base}", $multidimensional_filter ); |
|
| 325 | + add_filter("theme_mod_{$id_base}", $multidimensional_filter); |
|
| 326 | 326 | } |
| 327 | - self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['previewed_instances'][ $this->id ] = $this; |
|
| 327 | + self::$aggregated_multidimensionals[$this->type][$id_base]['previewed_instances'][$this->id] = $this; |
|
| 328 | 328 | } |
| 329 | 329 | break; |
| 330 | 330 | case 'option' : |
| 331 | - if ( ! $is_multidimensional ) { |
|
| 332 | - add_filter( "pre_option_{$id_base}", array( $this, '_preview_filter' ) ); |
|
| 331 | + if ( ! $is_multidimensional) { |
|
| 332 | + add_filter("pre_option_{$id_base}", array($this, '_preview_filter')); |
|
| 333 | 333 | } else { |
| 334 | - if ( empty( self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['previewed_instances'] ) ) { |
|
| 334 | + if (empty(self::$aggregated_multidimensionals[$this->type][$id_base]['previewed_instances'])) { |
|
| 335 | 335 | // Only add these filters once for this ID base. |
| 336 | - add_filter( "option_{$id_base}", $multidimensional_filter ); |
|
| 337 | - add_filter( "default_option_{$id_base}", $multidimensional_filter ); |
|
| 336 | + add_filter("option_{$id_base}", $multidimensional_filter); |
|
| 337 | + add_filter("default_option_{$id_base}", $multidimensional_filter); |
|
| 338 | 338 | } |
| 339 | - self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['previewed_instances'][ $this->id ] = $this; |
|
| 339 | + self::$aggregated_multidimensionals[$this->type][$id_base]['previewed_instances'][$this->id] = $this; |
|
| 340 | 340 | } |
| 341 | 341 | break; |
| 342 | 342 | default : |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | * |
| 352 | 352 | * @param WP_Customize_Setting $this WP_Customize_Setting instance. |
| 353 | 353 | */ |
| 354 | - do_action( "customize_preview_{$this->id}", $this ); |
|
| 354 | + do_action("customize_preview_{$this->id}", $this); |
|
| 355 | 355 | |
| 356 | 356 | /** |
| 357 | 357 | * Fires when the WP_Customize_Setting::preview() method is called for settings |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | * |
| 364 | 364 | * @param WP_Customize_Setting $this WP_Customize_Setting instance. |
| 365 | 365 | */ |
| 366 | - do_action( "customize_preview_{$this->type}", $this ); |
|
| 366 | + do_action("customize_preview_{$this->type}", $this); |
|
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | $this->is_previewed = true; |
@@ -384,7 +384,7 @@ discard block |
||
| 384 | 384 | * @see WP_Customize_Setting::_multidimensional_preview_filter() |
| 385 | 385 | */ |
| 386 | 386 | final public function _clear_aggregated_multidimensional_preview_applied_flag() { |
| 387 | - unset( self::$aggregated_multidimensionals[ $this->type ][ $this->id_data['base'] ]['preview_applied_instances'][ $this->id ] ); |
|
| 387 | + unset(self::$aggregated_multidimensionals[$this->type][$this->id_data['base']]['preview_applied_instances'][$this->id]); |
|
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | /** |
@@ -399,14 +399,14 @@ discard block |
||
| 399 | 399 | * @param mixed $original Old value. |
| 400 | 400 | * @return mixed New or old value. |
| 401 | 401 | */ |
| 402 | - public function _preview_filter( $original ) { |
|
| 403 | - if ( ! $this->is_current_blog_previewed() ) { |
|
| 402 | + public function _preview_filter($original) { |
|
| 403 | + if ( ! $this->is_current_blog_previewed()) { |
|
| 404 | 404 | return $original; |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | $undefined = new stdClass(); // Symbol hack. |
| 408 | - $post_value = $this->post_value( $undefined ); |
|
| 409 | - if ( $undefined !== $post_value ) { |
|
| 408 | + $post_value = $this->post_value($undefined); |
|
| 409 | + if ($undefined !== $post_value) { |
|
| 410 | 410 | $value = $post_value; |
| 411 | 411 | } else { |
| 412 | 412 | /* |
@@ -432,35 +432,35 @@ discard block |
||
| 432 | 432 | * @param mixed $original Original root value. |
| 433 | 433 | * @return mixed New or old value. |
| 434 | 434 | */ |
| 435 | - final public function _multidimensional_preview_filter( $original ) { |
|
| 436 | - if ( ! $this->is_current_blog_previewed() ) { |
|
| 435 | + final public function _multidimensional_preview_filter($original) { |
|
| 436 | + if ( ! $this->is_current_blog_previewed()) { |
|
| 437 | 437 | return $original; |
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | $id_base = $this->id_data['base']; |
| 441 | 441 | |
| 442 | 442 | // If no settings have been previewed yet (which should not be the case, since $this is), just pass through the original value. |
| 443 | - if ( empty( self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['previewed_instances'] ) ) { |
|
| 443 | + if (empty(self::$aggregated_multidimensionals[$this->type][$id_base]['previewed_instances'])) { |
|
| 444 | 444 | return $original; |
| 445 | 445 | } |
| 446 | 446 | |
| 447 | - foreach ( self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['previewed_instances'] as $previewed_setting ) { |
|
| 447 | + foreach (self::$aggregated_multidimensionals[$this->type][$id_base]['previewed_instances'] as $previewed_setting) { |
|
| 448 | 448 | // Skip applying previewed value for any settings that have already been applied. |
| 449 | - if ( ! empty( self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['preview_applied_instances'][ $previewed_setting->id ] ) ) { |
|
| 449 | + if ( ! empty(self::$aggregated_multidimensionals[$this->type][$id_base]['preview_applied_instances'][$previewed_setting->id])) { |
|
| 450 | 450 | continue; |
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | // Do the replacements of the posted/default sub value into the root value. |
| 454 | - $value = $previewed_setting->post_value( $previewed_setting->default ); |
|
| 455 | - $root = self::$aggregated_multidimensionals[ $previewed_setting->type ][ $id_base ]['root_value']; |
|
| 456 | - $root = $previewed_setting->multidimensional_replace( $root, $previewed_setting->id_data['keys'], $value ); |
|
| 457 | - self::$aggregated_multidimensionals[ $previewed_setting->type ][ $id_base ]['root_value'] = $root; |
|
| 454 | + $value = $previewed_setting->post_value($previewed_setting->default); |
|
| 455 | + $root = self::$aggregated_multidimensionals[$previewed_setting->type][$id_base]['root_value']; |
|
| 456 | + $root = $previewed_setting->multidimensional_replace($root, $previewed_setting->id_data['keys'], $value); |
|
| 457 | + self::$aggregated_multidimensionals[$previewed_setting->type][$id_base]['root_value'] = $root; |
|
| 458 | 458 | |
| 459 | 459 | // Mark this setting having been applied so that it will be skipped when the filter is called again. |
| 460 | - self::$aggregated_multidimensionals[ $previewed_setting->type ][ $id_base ]['preview_applied_instances'][ $previewed_setting->id ] = true; |
|
| 460 | + self::$aggregated_multidimensionals[$previewed_setting->type][$id_base]['preview_applied_instances'][$previewed_setting->id] = true; |
|
| 461 | 461 | } |
| 462 | 462 | |
| 463 | - return self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['root_value']; |
|
| 463 | + return self::$aggregated_multidimensionals[$this->type][$id_base]['root_value']; |
|
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | /** |
@@ -476,7 +476,7 @@ discard block |
||
| 476 | 476 | final public function save() { |
| 477 | 477 | $value = $this->post_value(); |
| 478 | 478 | |
| 479 | - if ( ! $this->check_capabilities() || ! isset( $value ) ) { |
|
| 479 | + if ( ! $this->check_capabilities() || ! isset($value)) { |
|
| 480 | 480 | return false; |
| 481 | 481 | } |
| 482 | 482 | |
@@ -490,9 +490,9 @@ discard block |
||
| 490 | 490 | * |
| 491 | 491 | * @param WP_Customize_Setting $this WP_Customize_Setting instance. |
| 492 | 492 | */ |
| 493 | - do_action( 'customize_save_' . $this->id_data['base'], $this ); |
|
| 493 | + do_action('customize_save_'.$this->id_data['base'], $this); |
|
| 494 | 494 | |
| 495 | - $this->update( $value ); |
|
| 495 | + $this->update($value); |
|
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | /** |
@@ -503,8 +503,8 @@ discard block |
||
| 503 | 503 | * @param mixed $default A default value which is used as a fallback. Default is null. |
| 504 | 504 | * @return mixed The default value on failure, otherwise the sanitized and validated value. |
| 505 | 505 | */ |
| 506 | - final public function post_value( $default = null ) { |
|
| 507 | - return $this->manager->post_value( $this, $default ); |
|
| 506 | + final public function post_value($default = null) { |
|
| 507 | + return $this->manager->post_value($this, $default); |
|
| 508 | 508 | } |
| 509 | 509 | |
| 510 | 510 | /** |
@@ -515,7 +515,7 @@ discard block |
||
| 515 | 515 | * @param string|array $value The value to sanitize. |
| 516 | 516 | * @return string|array|null|WP_Error Sanitized value, or `null`/`WP_Error` if invalid. |
| 517 | 517 | */ |
| 518 | - public function sanitize( $value ) { |
|
| 518 | + public function sanitize($value) { |
|
| 519 | 519 | |
| 520 | 520 | /** |
| 521 | 521 | * Filters a Customize setting value in un-slashed form. |
@@ -525,7 +525,7 @@ discard block |
||
| 525 | 525 | * @param mixed $value Value of the setting. |
| 526 | 526 | * @param WP_Customize_Setting $this WP_Customize_Setting instance. |
| 527 | 527 | */ |
| 528 | - return apply_filters( "customize_sanitize_{$this->id}", $value, $this ); |
|
| 528 | + return apply_filters("customize_sanitize_{$this->id}", $value, $this); |
|
| 529 | 529 | } |
| 530 | 530 | |
| 531 | 531 | /** |
@@ -539,12 +539,12 @@ discard block |
||
| 539 | 539 | * @param mixed $value Value to validate. |
| 540 | 540 | * @return true|WP_Error True if the input was validated, otherwise WP_Error. |
| 541 | 541 | */ |
| 542 | - public function validate( $value ) { |
|
| 543 | - if ( is_wp_error( $value ) ) { |
|
| 542 | + public function validate($value) { |
|
| 543 | + if (is_wp_error($value)) { |
|
| 544 | 544 | return $value; |
| 545 | 545 | } |
| 546 | - if ( is_null( $value ) ) { |
|
| 547 | - return new WP_Error( 'invalid_value', __( 'Invalid value.' ) ); |
|
| 546 | + if (is_null($value)) { |
|
| 547 | + return new WP_Error('invalid_value', __('Invalid value.')); |
|
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | $validity = new WP_Error(); |
@@ -562,9 +562,9 @@ discard block |
||
| 562 | 562 | * @param mixed $value Value of the setting. |
| 563 | 563 | * @param WP_Customize_Setting $this WP_Customize_Setting instance. |
| 564 | 564 | */ |
| 565 | - $validity = apply_filters( "customize_validate_{$this->id}", $validity, $value, $this ); |
|
| 565 | + $validity = apply_filters("customize_validate_{$this->id}", $validity, $value, $this); |
|
| 566 | 566 | |
| 567 | - if ( is_wp_error( $validity ) && empty( $validity->errors ) ) { |
|
| 567 | + if (is_wp_error($validity) && empty($validity->errors)) { |
|
| 568 | 568 | $validity = true; |
| 569 | 569 | } |
| 570 | 570 | return $validity; |
@@ -579,12 +579,12 @@ discard block |
||
| 579 | 579 | * @param mixed $default Value to return if root does not exist. |
| 580 | 580 | * @return mixed |
| 581 | 581 | */ |
| 582 | - protected function get_root_value( $default = null ) { |
|
| 582 | + protected function get_root_value($default = null) { |
|
| 583 | 583 | $id_base = $this->id_data['base']; |
| 584 | - if ( 'option' === $this->type ) { |
|
| 585 | - return get_option( $id_base, $default ); |
|
| 586 | - } else if ( 'theme_mod' ) { |
|
| 587 | - return get_theme_mod( $id_base, $default ); |
|
| 584 | + if ('option' === $this->type) { |
|
| 585 | + return get_option($id_base, $default); |
|
| 586 | + } else if ('theme_mod') { |
|
| 587 | + return get_theme_mod($id_base, $default); |
|
| 588 | 588 | } else { |
| 589 | 589 | /* |
| 590 | 590 | * Any WP_Customize_Setting subclass implementing aggregate multidimensional |
@@ -604,16 +604,16 @@ discard block |
||
| 604 | 604 | * @param mixed $value Value to set as root of multidimensional setting. |
| 605 | 605 | * @return bool Whether the multidimensional root was updated successfully. |
| 606 | 606 | */ |
| 607 | - protected function set_root_value( $value ) { |
|
| 607 | + protected function set_root_value($value) { |
|
| 608 | 608 | $id_base = $this->id_data['base']; |
| 609 | - if ( 'option' === $this->type ) { |
|
| 609 | + if ('option' === $this->type) { |
|
| 610 | 610 | $autoload = true; |
| 611 | - if ( isset( self::$aggregated_multidimensionals[ $this->type ][ $this->id_data['base'] ]['autoload'] ) ) { |
|
| 612 | - $autoload = self::$aggregated_multidimensionals[ $this->type ][ $this->id_data['base'] ]['autoload']; |
|
| 611 | + if (isset(self::$aggregated_multidimensionals[$this->type][$this->id_data['base']]['autoload'])) { |
|
| 612 | + $autoload = self::$aggregated_multidimensionals[$this->type][$this->id_data['base']]['autoload']; |
|
| 613 | 613 | } |
| 614 | - return update_option( $id_base, $value, $autoload ); |
|
| 615 | - } else if ( 'theme_mod' ) { |
|
| 616 | - set_theme_mod( $id_base, $value ); |
|
| 614 | + return update_option($id_base, $value, $autoload); |
|
| 615 | + } else if ('theme_mod') { |
|
| 616 | + set_theme_mod($id_base, $value); |
|
| 617 | 617 | return true; |
| 618 | 618 | } else { |
| 619 | 619 | /* |
@@ -633,16 +633,16 @@ discard block |
||
| 633 | 633 | * @param mixed $value The value to update. |
| 634 | 634 | * @return bool The result of saving the value. |
| 635 | 635 | */ |
| 636 | - protected function update( $value ) { |
|
| 636 | + protected function update($value) { |
|
| 637 | 637 | $id_base = $this->id_data['base']; |
| 638 | - if ( 'option' === $this->type || 'theme_mod' === $this->type ) { |
|
| 639 | - if ( ! $this->is_multidimensional_aggregated ) { |
|
| 640 | - return $this->set_root_value( $value ); |
|
| 638 | + if ('option' === $this->type || 'theme_mod' === $this->type) { |
|
| 639 | + if ( ! $this->is_multidimensional_aggregated) { |
|
| 640 | + return $this->set_root_value($value); |
|
| 641 | 641 | } else { |
| 642 | - $root = self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['root_value']; |
|
| 643 | - $root = $this->multidimensional_replace( $root, $this->id_data['keys'], $value ); |
|
| 644 | - self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['root_value'] = $root; |
|
| 645 | - return $this->set_root_value( $root ); |
|
| 642 | + $root = self::$aggregated_multidimensionals[$this->type][$id_base]['root_value']; |
|
| 643 | + $root = $this->multidimensional_replace($root, $this->id_data['keys'], $value); |
|
| 644 | + self::$aggregated_multidimensionals[$this->type][$id_base]['root_value'] = $root; |
|
| 645 | + return $this->set_root_value($root); |
|
| 646 | 646 | } |
| 647 | 647 | } else { |
| 648 | 648 | /** |
@@ -656,9 +656,9 @@ discard block |
||
| 656 | 656 | * @param mixed $value Value of the setting. |
| 657 | 657 | * @param WP_Customize_Setting $this WP_Customize_Setting instance. |
| 658 | 658 | */ |
| 659 | - do_action( "customize_update_{$this->type}", $value, $this ); |
|
| 659 | + do_action("customize_update_{$this->type}", $value, $this); |
|
| 660 | 660 | |
| 661 | - return has_action( "customize_update_{$this->type}" ); |
|
| 661 | + return has_action("customize_update_{$this->type}"); |
|
| 662 | 662 | } |
| 663 | 663 | } |
| 664 | 664 | |
@@ -669,7 +669,7 @@ discard block |
||
| 669 | 669 | * @deprecated 4.4.0 Deprecated in favor of update() method. |
| 670 | 670 | */ |
| 671 | 671 | protected function _update_theme_mod() { |
| 672 | - _deprecated_function( __METHOD__, '4.4.0', __CLASS__ . '::update()' ); |
|
| 672 | + _deprecated_function(__METHOD__, '4.4.0', __CLASS__.'::update()'); |
|
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | /** |
@@ -679,7 +679,7 @@ discard block |
||
| 679 | 679 | * @deprecated 4.4.0 Deprecated in favor of update() method. |
| 680 | 680 | */ |
| 681 | 681 | protected function _update_option() { |
| 682 | - _deprecated_function( __METHOD__, '4.4.0', __CLASS__ . '::update()' ); |
|
| 682 | + _deprecated_function(__METHOD__, '4.4.0', __CLASS__.'::update()'); |
|
| 683 | 683 | } |
| 684 | 684 | |
| 685 | 685 | /** |
@@ -691,10 +691,10 @@ discard block |
||
| 691 | 691 | */ |
| 692 | 692 | public function value() { |
| 693 | 693 | $id_base = $this->id_data['base']; |
| 694 | - $is_core_type = ( 'option' === $this->type || 'theme_mod' === $this->type ); |
|
| 694 | + $is_core_type = ('option' === $this->type || 'theme_mod' === $this->type); |
|
| 695 | 695 | |
| 696 | - if ( ! $is_core_type && ! $this->is_multidimensional_aggregated ) { |
|
| 697 | - $value = $this->get_root_value( $this->default ); |
|
| 696 | + if ( ! $is_core_type && ! $this->is_multidimensional_aggregated) { |
|
| 697 | + $value = $this->get_root_value($this->default); |
|
| 698 | 698 | |
| 699 | 699 | /** |
| 700 | 700 | * Filters a Customize setting value not handled as a theme_mod or option. |
@@ -711,17 +711,17 @@ discard block |
||
| 711 | 711 | * @param mixed $default The setting default value. Default empty. |
| 712 | 712 | * @param WP_Customize_Setting $this The setting instance. |
| 713 | 713 | */ |
| 714 | - $value = apply_filters( "customize_value_{$id_base}", $value, $this ); |
|
| 715 | - } elseif ( $this->is_multidimensional_aggregated ) { |
|
| 716 | - $root_value = self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['root_value']; |
|
| 717 | - $value = $this->multidimensional_get( $root_value, $this->id_data['keys'], $this->default ); |
|
| 714 | + $value = apply_filters("customize_value_{$id_base}", $value, $this); |
|
| 715 | + } elseif ($this->is_multidimensional_aggregated) { |
|
| 716 | + $root_value = self::$aggregated_multidimensionals[$this->type][$id_base]['root_value']; |
|
| 717 | + $value = $this->multidimensional_get($root_value, $this->id_data['keys'], $this->default); |
|
| 718 | 718 | |
| 719 | 719 | // Ensure that the post value is used if the setting is previewed, since preview filters aren't applying on cached $root_value. |
| 720 | - if ( $this->is_previewed ) { |
|
| 721 | - $value = $this->post_value( $value ); |
|
| 720 | + if ($this->is_previewed) { |
|
| 721 | + $value = $this->post_value($value); |
|
| 722 | 722 | } |
| 723 | 723 | } else { |
| 724 | - $value = $this->get_root_value( $this->default ); |
|
| 724 | + $value = $this->get_root_value($this->default); |
|
| 725 | 725 | } |
| 726 | 726 | return $value; |
| 727 | 727 | } |
@@ -745,10 +745,10 @@ discard block |
||
| 745 | 745 | * @param mixed $value The setting value. |
| 746 | 746 | * @param WP_Customize_Setting $this WP_Customize_Setting instance. |
| 747 | 747 | */ |
| 748 | - $value = apply_filters( "customize_sanitize_js_{$this->id}", $this->value(), $this ); |
|
| 748 | + $value = apply_filters("customize_sanitize_js_{$this->id}", $this->value(), $this); |
|
| 749 | 749 | |
| 750 | - if ( is_string( $value ) ) |
|
| 751 | - return html_entity_decode( $value, ENT_QUOTES, 'UTF-8'); |
|
| 750 | + if (is_string($value)) |
|
| 751 | + return html_entity_decode($value, ENT_QUOTES, 'UTF-8'); |
|
| 752 | 752 | |
| 753 | 753 | return $value; |
| 754 | 754 | } |
@@ -778,10 +778,10 @@ discard block |
||
| 778 | 778 | * @return bool False if theme doesn't support the setting or user can't change setting, otherwise true. |
| 779 | 779 | */ |
| 780 | 780 | final public function check_capabilities() { |
| 781 | - if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) ) |
|
| 781 | + if ($this->capability && ! call_user_func_array('current_user_can', (array) $this->capability)) |
|
| 782 | 782 | return false; |
| 783 | 783 | |
| 784 | - if ( $this->theme_supports && ! call_user_func_array( 'current_theme_supports', (array) $this->theme_supports ) ) |
|
| 784 | + if ($this->theme_supports && ! call_user_func_array('current_theme_supports', (array) $this->theme_supports)) |
|
| 785 | 785 | return false; |
| 786 | 786 | |
| 787 | 787 | return true; |
@@ -797,37 +797,37 @@ discard block |
||
| 797 | 797 | * @param bool $create Default is false. |
| 798 | 798 | * @return array|void Keys are 'root', 'node', and 'key'. |
| 799 | 799 | */ |
| 800 | - final protected function multidimensional( &$root, $keys, $create = false ) { |
|
| 801 | - if ( $create && empty( $root ) ) |
|
| 800 | + final protected function multidimensional(&$root, $keys, $create = false) { |
|
| 801 | + if ($create && empty($root)) |
|
| 802 | 802 | $root = array(); |
| 803 | 803 | |
| 804 | - if ( ! isset( $root ) || empty( $keys ) ) |
|
| 804 | + if ( ! isset($root) || empty($keys)) |
|
| 805 | 805 | return; |
| 806 | 806 | |
| 807 | - $last = array_pop( $keys ); |
|
| 807 | + $last = array_pop($keys); |
|
| 808 | 808 | $node = &$root; |
| 809 | 809 | |
| 810 | - foreach ( $keys as $key ) { |
|
| 811 | - if ( $create && ! isset( $node[ $key ] ) ) |
|
| 812 | - $node[ $key ] = array(); |
|
| 810 | + foreach ($keys as $key) { |
|
| 811 | + if ($create && ! isset($node[$key])) |
|
| 812 | + $node[$key] = array(); |
|
| 813 | 813 | |
| 814 | - if ( ! is_array( $node ) || ! isset( $node[ $key ] ) ) |
|
| 814 | + if ( ! is_array($node) || ! isset($node[$key])) |
|
| 815 | 815 | return; |
| 816 | 816 | |
| 817 | - $node = &$node[ $key ]; |
|
| 817 | + $node = &$node[$key]; |
|
| 818 | 818 | } |
| 819 | 819 | |
| 820 | - if ( $create ) { |
|
| 821 | - if ( ! is_array( $node ) ) { |
|
| 820 | + if ($create) { |
|
| 821 | + if ( ! is_array($node)) { |
|
| 822 | 822 | // account for an array overriding a string or object value |
| 823 | 823 | $node = array(); |
| 824 | 824 | } |
| 825 | - if ( ! isset( $node[ $last ] ) ) { |
|
| 826 | - $node[ $last ] = array(); |
|
| 825 | + if ( ! isset($node[$last])) { |
|
| 826 | + $node[$last] = array(); |
|
| 827 | 827 | } |
| 828 | 828 | } |
| 829 | 829 | |
| 830 | - if ( ! isset( $node[ $last ] ) ) |
|
| 830 | + if ( ! isset($node[$last])) |
|
| 831 | 831 | return; |
| 832 | 832 | |
| 833 | 833 | return array( |
@@ -847,16 +847,16 @@ discard block |
||
| 847 | 847 | * @param mixed $value The value to update. |
| 848 | 848 | * @return mixed |
| 849 | 849 | */ |
| 850 | - final protected function multidimensional_replace( $root, $keys, $value ) { |
|
| 851 | - if ( ! isset( $value ) ) |
|
| 850 | + final protected function multidimensional_replace($root, $keys, $value) { |
|
| 851 | + if ( ! isset($value)) |
|
| 852 | 852 | return $root; |
| 853 | - elseif ( empty( $keys ) ) // If there are no keys, we're replacing the root. |
|
| 853 | + elseif (empty($keys)) // If there are no keys, we're replacing the root. |
|
| 854 | 854 | return $value; |
| 855 | 855 | |
| 856 | - $result = $this->multidimensional( $root, $keys, true ); |
|
| 856 | + $result = $this->multidimensional($root, $keys, true); |
|
| 857 | 857 | |
| 858 | - if ( isset( $result ) ) |
|
| 859 | - $result['node'][ $result['key'] ] = $value; |
|
| 858 | + if (isset($result)) |
|
| 859 | + $result['node'][$result['key']] = $value; |
|
| 860 | 860 | |
| 861 | 861 | return $root; |
| 862 | 862 | } |
@@ -871,12 +871,12 @@ discard block |
||
| 871 | 871 | * @param mixed $default A default value which is used as a fallback. Default is null. |
| 872 | 872 | * @return mixed The requested value or the default value. |
| 873 | 873 | */ |
| 874 | - final protected function multidimensional_get( $root, $keys, $default = null ) { |
|
| 875 | - if ( empty( $keys ) ) // If there are no keys, test the root. |
|
| 876 | - return isset( $root ) ? $root : $default; |
|
| 874 | + final protected function multidimensional_get($root, $keys, $default = null) { |
|
| 875 | + if (empty($keys)) // If there are no keys, test the root. |
|
| 876 | + return isset($root) ? $root : $default; |
|
| 877 | 877 | |
| 878 | - $result = $this->multidimensional( $root, $keys ); |
|
| 879 | - return isset( $result ) ? $result['node'][ $result['key'] ] : $default; |
|
| 878 | + $result = $this->multidimensional($root, $keys); |
|
| 879 | + return isset($result) ? $result['node'][$result['key']] : $default; |
|
| 880 | 880 | } |
| 881 | 881 | |
| 882 | 882 | /** |
@@ -888,23 +888,23 @@ discard block |
||
| 888 | 888 | * @param $keys |
| 889 | 889 | * @return bool True if value is set, false if not. |
| 890 | 890 | */ |
| 891 | - final protected function multidimensional_isset( $root, $keys ) { |
|
| 892 | - $result = $this->multidimensional_get( $root, $keys ); |
|
| 893 | - return isset( $result ); |
|
| 891 | + final protected function multidimensional_isset($root, $keys) { |
|
| 892 | + $result = $this->multidimensional_get($root, $keys); |
|
| 893 | + return isset($result); |
|
| 894 | 894 | } |
| 895 | 895 | } |
| 896 | 896 | |
| 897 | 897 | /** WP_Customize_Filter_Setting class */ |
| 898 | -require_once( ABSPATH . WPINC . '/customize/class-wp-customize-filter-setting.php' ); |
|
| 898 | +require_once(ABSPATH.WPINC.'/customize/class-wp-customize-filter-setting.php'); |
|
| 899 | 899 | |
| 900 | 900 | /** WP_Customize_Header_Image_Setting class */ |
| 901 | -require_once( ABSPATH . WPINC . '/customize/class-wp-customize-header-image-setting.php' ); |
|
| 901 | +require_once(ABSPATH.WPINC.'/customize/class-wp-customize-header-image-setting.php'); |
|
| 902 | 902 | |
| 903 | 903 | /** WP_Customize_Background_Image_Setting class */ |
| 904 | -require_once( ABSPATH . WPINC . '/customize/class-wp-customize-background-image-setting.php' ); |
|
| 904 | +require_once(ABSPATH.WPINC.'/customize/class-wp-customize-background-image-setting.php'); |
|
| 905 | 905 | |
| 906 | 906 | /** WP_Customize_Nav_Menu_Item_Setting class */ |
| 907 | -require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-item-setting.php' ); |
|
| 907 | +require_once(ABSPATH.WPINC.'/customize/class-wp-customize-nav-menu-item-setting.php'); |
|
| 908 | 908 | |
| 909 | 909 | /** WP_Customize_Nav_Menu_Setting class */ |
| 910 | -require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-setting.php' ); |
|
| 910 | +require_once(ABSPATH.WPINC.'/customize/class-wp-customize-nav-menu-setting.php'); |
|
@@ -24,20 +24,20 @@ discard block |
||
| 24 | 24 | * @param array $args Optional. Arguments to pass to the hook's callback function. |
| 25 | 25 | * @return false|void False when an event is not scheduled. |
| 26 | 26 | */ |
| 27 | -function wp_schedule_single_event( $timestamp, $hook, $args = array()) { |
|
| 27 | +function wp_schedule_single_event($timestamp, $hook, $args = array()) { |
|
| 28 | 28 | // Make sure timestamp is a positive integer |
| 29 | - if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) { |
|
| 29 | + if ( ! is_numeric($timestamp) || $timestamp <= 0) { |
|
| 30 | 30 | return false; |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | // Don't schedule a duplicate if there's already an identical event due within 10 minutes of it |
| 34 | 34 | $next = wp_next_scheduled($hook, $args); |
| 35 | - if ( $next && abs( $next - $timestamp ) <= 10 * MINUTE_IN_SECONDS ) { |
|
| 35 | + if ($next && abs($next - $timestamp) <= 10 * MINUTE_IN_SECONDS) { |
|
| 36 | 36 | return false; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | $crons = _get_cron_array(); |
| 40 | - $event = (object) array( 'hook' => $hook, 'timestamp' => $timestamp, 'schedule' => false, 'args' => $args ); |
|
| 40 | + $event = (object) array('hook' => $hook, 'timestamp' => $timestamp, 'schedule' => false, 'args' => $args); |
|
| 41 | 41 | /** |
| 42 | 42 | * Filters a single event before it is scheduled. |
| 43 | 43 | * |
@@ -45,17 +45,17 @@ discard block |
||
| 45 | 45 | * |
| 46 | 46 | * @param object $event An object containing an event's data. |
| 47 | 47 | */ |
| 48 | - $event = apply_filters( 'schedule_event', $event ); |
|
| 48 | + $event = apply_filters('schedule_event', $event); |
|
| 49 | 49 | |
| 50 | 50 | // A plugin disallowed this event |
| 51 | - if ( ! $event ) |
|
| 51 | + if ( ! $event) |
|
| 52 | 52 | return false; |
| 53 | 53 | |
| 54 | 54 | $key = md5(serialize($event->args)); |
| 55 | 55 | |
| 56 | - $crons[$event->timestamp][$event->hook][$key] = array( 'schedule' => $event->schedule, 'args' => $event->args ); |
|
| 57 | - uksort( $crons, "strnatcasecmp" ); |
|
| 58 | - _set_cron_array( $crons ); |
|
| 56 | + $crons[$event->timestamp][$event->hook][$key] = array('schedule' => $event->schedule, 'args' => $event->args); |
|
| 57 | + uksort($crons, "strnatcasecmp"); |
|
| 58 | + _set_cron_array($crons); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -78,31 +78,31 @@ discard block |
||
| 78 | 78 | * @param array $args Optional. Arguments to pass to the hook's callback function. |
| 79 | 79 | * @return false|void False when an event is not scheduled. |
| 80 | 80 | */ |
| 81 | -function wp_schedule_event( $timestamp, $recurrence, $hook, $args = array()) { |
|
| 81 | +function wp_schedule_event($timestamp, $recurrence, $hook, $args = array()) { |
|
| 82 | 82 | // Make sure timestamp is a positive integer |
| 83 | - if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) { |
|
| 83 | + if ( ! is_numeric($timestamp) || $timestamp <= 0) { |
|
| 84 | 84 | return false; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | $crons = _get_cron_array(); |
| 88 | 88 | $schedules = wp_get_schedules(); |
| 89 | 89 | |
| 90 | - if ( !isset( $schedules[$recurrence] ) ) |
|
| 90 | + if ( ! isset($schedules[$recurrence])) |
|
| 91 | 91 | return false; |
| 92 | 92 | |
| 93 | - $event = (object) array( 'hook' => $hook, 'timestamp' => $timestamp, 'schedule' => $recurrence, 'args' => $args, 'interval' => $schedules[$recurrence]['interval'] ); |
|
| 93 | + $event = (object) array('hook' => $hook, 'timestamp' => $timestamp, 'schedule' => $recurrence, 'args' => $args, 'interval' => $schedules[$recurrence]['interval']); |
|
| 94 | 94 | /** This filter is documented in wp-includes/cron.php */ |
| 95 | - $event = apply_filters( 'schedule_event', $event ); |
|
| 95 | + $event = apply_filters('schedule_event', $event); |
|
| 96 | 96 | |
| 97 | 97 | // A plugin disallowed this event |
| 98 | - if ( ! $event ) |
|
| 98 | + if ( ! $event) |
|
| 99 | 99 | return false; |
| 100 | 100 | |
| 101 | 101 | $key = md5(serialize($event->args)); |
| 102 | 102 | |
| 103 | - $crons[$event->timestamp][$event->hook][$key] = array( 'schedule' => $event->schedule, 'args' => $event->args, 'interval' => $event->interval ); |
|
| 104 | - uksort( $crons, "strnatcasecmp" ); |
|
| 105 | - _set_cron_array( $crons ); |
|
| 103 | + $crons[$event->timestamp][$event->hook][$key] = array('schedule' => $event->schedule, 'args' => $event->args, 'interval' => $event->interval); |
|
| 104 | + uksort($crons, "strnatcasecmp"); |
|
| 105 | + _set_cron_array($crons); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -116,39 +116,39 @@ discard block |
||
| 116 | 116 | * @param array $args Optional. Arguments to pass to the hook's callback function. |
| 117 | 117 | * @return false|void False when an event is not scheduled. |
| 118 | 118 | */ |
| 119 | -function wp_reschedule_event( $timestamp, $recurrence, $hook, $args = array() ) { |
|
| 119 | +function wp_reschedule_event($timestamp, $recurrence, $hook, $args = array()) { |
|
| 120 | 120 | // Make sure timestamp is a positive integer |
| 121 | - if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) { |
|
| 121 | + if ( ! is_numeric($timestamp) || $timestamp <= 0) { |
|
| 122 | 122 | return false; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | $crons = _get_cron_array(); |
| 126 | 126 | $schedules = wp_get_schedules(); |
| 127 | - $key = md5( serialize( $args ) ); |
|
| 127 | + $key = md5(serialize($args)); |
|
| 128 | 128 | $interval = 0; |
| 129 | 129 | |
| 130 | 130 | // First we try to get it from the schedule |
| 131 | - if ( isset( $schedules[ $recurrence ] ) ) { |
|
| 132 | - $interval = $schedules[ $recurrence ]['interval']; |
|
| 131 | + if (isset($schedules[$recurrence])) { |
|
| 132 | + $interval = $schedules[$recurrence]['interval']; |
|
| 133 | 133 | } |
| 134 | 134 | // Now we try to get it from the saved interval in case the schedule disappears |
| 135 | - if ( 0 == $interval ) { |
|
| 136 | - $interval = $crons[ $timestamp ][ $hook ][ $key ]['interval']; |
|
| 135 | + if (0 == $interval) { |
|
| 136 | + $interval = $crons[$timestamp][$hook][$key]['interval']; |
|
| 137 | 137 | } |
| 138 | 138 | // Now we assume something is wrong and fail to schedule |
| 139 | - if ( 0 == $interval ) { |
|
| 139 | + if (0 == $interval) { |
|
| 140 | 140 | return false; |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | $now = time(); |
| 144 | 144 | |
| 145 | - if ( $timestamp >= $now ) { |
|
| 145 | + if ($timestamp >= $now) { |
|
| 146 | 146 | $timestamp = $now + $interval; |
| 147 | 147 | } else { |
| 148 | - $timestamp = $now + ( $interval - ( ( $now - $timestamp ) % $interval ) ); |
|
| 148 | + $timestamp = $now + ($interval - (($now - $timestamp) % $interval)); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - wp_schedule_event( $timestamp, $recurrence, $hook, $args ); |
|
| 151 | + wp_schedule_event($timestamp, $recurrence, $hook, $args); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -167,20 +167,20 @@ discard block |
||
| 167 | 167 | * as those used when originally scheduling the event. |
| 168 | 168 | * @return false|void False when an event is not unscheduled. |
| 169 | 169 | */ |
| 170 | -function wp_unschedule_event( $timestamp, $hook, $args = array() ) { |
|
| 170 | +function wp_unschedule_event($timestamp, $hook, $args = array()) { |
|
| 171 | 171 | // Make sure timestamp is a positive integer |
| 172 | - if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) { |
|
| 172 | + if ( ! is_numeric($timestamp) || $timestamp <= 0) { |
|
| 173 | 173 | return false; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | $crons = _get_cron_array(); |
| 177 | 177 | $key = md5(serialize($args)); |
| 178 | - unset( $crons[$timestamp][$hook][$key] ); |
|
| 179 | - if ( empty($crons[$timestamp][$hook]) ) |
|
| 180 | - unset( $crons[$timestamp][$hook] ); |
|
| 181 | - if ( empty($crons[$timestamp]) ) |
|
| 182 | - unset( $crons[$timestamp] ); |
|
| 183 | - _set_cron_array( $crons ); |
|
| 178 | + unset($crons[$timestamp][$hook][$key]); |
|
| 179 | + if (empty($crons[$timestamp][$hook])) |
|
| 180 | + unset($crons[$timestamp][$hook]); |
|
| 181 | + if (empty($crons[$timestamp])) |
|
| 182 | + unset($crons[$timestamp]); |
|
| 183 | + _set_cron_array($crons); |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
@@ -191,25 +191,25 @@ discard block |
||
| 191 | 191 | * @param string $hook Action hook, the execution of which will be unscheduled. |
| 192 | 192 | * @param array $args Optional. Arguments that were to be pass to the hook's callback function. |
| 193 | 193 | */ |
| 194 | -function wp_clear_scheduled_hook( $hook, $args = array() ) { |
|
| 194 | +function wp_clear_scheduled_hook($hook, $args = array()) { |
|
| 195 | 195 | // Backward compatibility |
| 196 | 196 | // Previously this function took the arguments as discrete vars rather than an array like the rest of the API |
| 197 | - if ( !is_array($args) ) { |
|
| 198 | - _deprecated_argument( __FUNCTION__, '3.0.0', __('This argument has changed to an array to match the behavior of the other cron functions.') ); |
|
| 199 | - $args = array_slice( func_get_args(), 1 ); |
|
| 197 | + if ( ! is_array($args)) { |
|
| 198 | + _deprecated_argument(__FUNCTION__, '3.0.0', __('This argument has changed to an array to match the behavior of the other cron functions.')); |
|
| 199 | + $args = array_slice(func_get_args(), 1); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | // This logic duplicates wp_next_scheduled() |
| 203 | 203 | // It's required due to a scenario where wp_unschedule_event() fails due to update_option() failing, |
| 204 | 204 | // and, wp_next_scheduled() returns the same schedule in an infinite loop. |
| 205 | 205 | $crons = _get_cron_array(); |
| 206 | - if ( empty( $crons ) ) |
|
| 206 | + if (empty($crons)) |
|
| 207 | 207 | return; |
| 208 | 208 | |
| 209 | - $key = md5( serialize( $args ) ); |
|
| 210 | - foreach ( $crons as $timestamp => $cron ) { |
|
| 211 | - if ( isset( $cron[ $hook ][ $key ] ) ) { |
|
| 212 | - wp_unschedule_event( $timestamp, $hook, $args ); |
|
| 209 | + $key = md5(serialize($args)); |
|
| 210 | + foreach ($crons as $timestamp => $cron) { |
|
| 211 | + if (isset($cron[$hook][$key])) { |
|
| 212 | + wp_unschedule_event($timestamp, $hook, $args); |
|
| 213 | 213 | } |
| 214 | 214 | } |
| 215 | 215 | } |
@@ -223,13 +223,13 @@ discard block |
||
| 223 | 223 | * @param array $args Optional. Arguments to pass to the hook's callback function. |
| 224 | 224 | * @return false|int The UNIX timestamp of the next time the scheduled event will occur. |
| 225 | 225 | */ |
| 226 | -function wp_next_scheduled( $hook, $args = array() ) { |
|
| 226 | +function wp_next_scheduled($hook, $args = array()) { |
|
| 227 | 227 | $crons = _get_cron_array(); |
| 228 | 228 | $key = md5(serialize($args)); |
| 229 | - if ( empty($crons) ) |
|
| 229 | + if (empty($crons)) |
|
| 230 | 230 | return false; |
| 231 | - foreach ( $crons as $timestamp => $cron ) { |
|
| 232 | - if ( isset( $cron[$hook][$key] ) ) |
|
| 231 | + foreach ($crons as $timestamp => $cron) { |
|
| 232 | + if (isset($cron[$hook][$key])) |
|
| 233 | 233 | return $timestamp; |
| 234 | 234 | } |
| 235 | 235 | return false; |
@@ -242,11 +242,11 @@ discard block |
||
| 242 | 242 | * |
| 243 | 243 | * @param int $gmt_time Optional. Unix timestamp. Default 0 (current time is used). |
| 244 | 244 | */ |
| 245 | -function spawn_cron( $gmt_time = 0 ) { |
|
| 246 | - if ( ! $gmt_time ) |
|
| 247 | - $gmt_time = microtime( true ); |
|
| 245 | +function spawn_cron($gmt_time = 0) { |
|
| 246 | + if ( ! $gmt_time) |
|
| 247 | + $gmt_time = microtime(true); |
|
| 248 | 248 | |
| 249 | - if ( defined('DOING_CRON') || isset($_GET['doing_wp_cron']) ) |
|
| 249 | + if (defined('DOING_CRON') || isset($_GET['doing_wp_cron'])) |
|
| 250 | 250 | return; |
| 251 | 251 | |
| 252 | 252 | /* |
@@ -258,45 +258,45 @@ discard block |
||
| 258 | 258 | */ |
| 259 | 259 | $lock = get_transient('doing_cron'); |
| 260 | 260 | |
| 261 | - if ( $lock > $gmt_time + 10 * MINUTE_IN_SECONDS ) |
|
| 261 | + if ($lock > $gmt_time + 10 * MINUTE_IN_SECONDS) |
|
| 262 | 262 | $lock = 0; |
| 263 | 263 | |
| 264 | 264 | // don't run if another process is currently running it or more than once every 60 sec. |
| 265 | - if ( $lock + WP_CRON_LOCK_TIMEOUT > $gmt_time ) |
|
| 265 | + if ($lock + WP_CRON_LOCK_TIMEOUT > $gmt_time) |
|
| 266 | 266 | return; |
| 267 | 267 | |
| 268 | 268 | //sanity check |
| 269 | 269 | $crons = _get_cron_array(); |
| 270 | - if ( !is_array($crons) ) |
|
| 270 | + if ( ! is_array($crons)) |
|
| 271 | 271 | return; |
| 272 | 272 | |
| 273 | - $keys = array_keys( $crons ); |
|
| 274 | - if ( isset($keys[0]) && $keys[0] > $gmt_time ) |
|
| 273 | + $keys = array_keys($crons); |
|
| 274 | + if (isset($keys[0]) && $keys[0] > $gmt_time) |
|
| 275 | 275 | return; |
| 276 | 276 | |
| 277 | - if ( defined( 'ALTERNATE_WP_CRON' ) && ALTERNATE_WP_CRON ) { |
|
| 278 | - if ( 'GET' !== $_SERVER['REQUEST_METHOD'] || defined( 'DOING_AJAX' ) || defined( 'XMLRPC_REQUEST' ) ) { |
|
| 277 | + if (defined('ALTERNATE_WP_CRON') && ALTERNATE_WP_CRON) { |
|
| 278 | + if ('GET' !== $_SERVER['REQUEST_METHOD'] || defined('DOING_AJAX') || defined('XMLRPC_REQUEST')) { |
|
| 279 | 279 | return; |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | - $doing_wp_cron = sprintf( '%.22F', $gmt_time ); |
|
| 283 | - set_transient( 'doing_cron', $doing_wp_cron ); |
|
| 282 | + $doing_wp_cron = sprintf('%.22F', $gmt_time); |
|
| 283 | + set_transient('doing_cron', $doing_wp_cron); |
|
| 284 | 284 | |
| 285 | 285 | ob_start(); |
| 286 | - wp_redirect( add_query_arg( 'doing_wp_cron', $doing_wp_cron, wp_unslash( $_SERVER['REQUEST_URI'] ) ) ); |
|
| 286 | + wp_redirect(add_query_arg('doing_wp_cron', $doing_wp_cron, wp_unslash($_SERVER['REQUEST_URI']))); |
|
| 287 | 287 | echo ' '; |
| 288 | 288 | |
| 289 | 289 | // flush any buffers and send the headers |
| 290 | - while ( @ob_end_flush() ); |
|
| 290 | + while (@ob_end_flush()); |
|
| 291 | 291 | flush(); |
| 292 | 292 | |
| 293 | - WP_DEBUG ? include_once( ABSPATH . 'wp-cron.php' ) : @include_once( ABSPATH . 'wp-cron.php' ); |
|
| 293 | + WP_DEBUG ? include_once(ABSPATH.'wp-cron.php') : @include_once(ABSPATH.'wp-cron.php'); |
|
| 294 | 294 | return; |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | // Set the cron lock with the current unix timestamp, when the cron is being spawned. |
| 298 | - $doing_wp_cron = sprintf( '%.22F', $gmt_time ); |
|
| 299 | - set_transient( 'doing_cron', $doing_wp_cron ); |
|
| 298 | + $doing_wp_cron = sprintf('%.22F', $gmt_time); |
|
| 299 | + set_transient('doing_cron', $doing_wp_cron); |
|
| 300 | 300 | |
| 301 | 301 | /** |
| 302 | 302 | * Filters the cron request arguments. |
@@ -319,18 +319,18 @@ discard block |
||
| 319 | 319 | * } |
| 320 | 320 | * @param string $doing_wp_cron The unix timestamp of the cron lock. |
| 321 | 321 | */ |
| 322 | - $cron_request = apply_filters( 'cron_request', array( |
|
| 323 | - 'url' => add_query_arg( 'doing_wp_cron', $doing_wp_cron, site_url( 'wp-cron.php' ) ), |
|
| 322 | + $cron_request = apply_filters('cron_request', array( |
|
| 323 | + 'url' => add_query_arg('doing_wp_cron', $doing_wp_cron, site_url('wp-cron.php')), |
|
| 324 | 324 | 'key' => $doing_wp_cron, |
| 325 | 325 | 'args' => array( |
| 326 | 326 | 'timeout' => 0.01, |
| 327 | 327 | 'blocking' => false, |
| 328 | 328 | /** This filter is documented in wp-includes/class-wp-http-streams.php */ |
| 329 | - 'sslverify' => apply_filters( 'https_local_ssl_verify', false ) |
|
| 329 | + 'sslverify' => apply_filters('https_local_ssl_verify', false) |
|
| 330 | 330 | ) |
| 331 | - ), $doing_wp_cron ); |
|
| 331 | + ), $doing_wp_cron); |
|
| 332 | 332 | |
| 333 | - wp_remote_post( $cron_request['url'], $cron_request['args'] ); |
|
| 333 | + wp_remote_post($cron_request['url'], $cron_request['args']); |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | /** |
@@ -340,24 +340,24 @@ discard block |
||
| 340 | 340 | */ |
| 341 | 341 | function wp_cron() { |
| 342 | 342 | // Prevent infinite loops caused by lack of wp-cron.php |
| 343 | - if ( strpos($_SERVER['REQUEST_URI'], '/wp-cron.php') !== false || ( defined('DISABLE_WP_CRON') && DISABLE_WP_CRON ) ) |
|
| 343 | + if (strpos($_SERVER['REQUEST_URI'], '/wp-cron.php') !== false || (defined('DISABLE_WP_CRON') && DISABLE_WP_CRON)) |
|
| 344 | 344 | return; |
| 345 | 345 | |
| 346 | - if ( false === $crons = _get_cron_array() ) |
|
| 346 | + if (false === $crons = _get_cron_array()) |
|
| 347 | 347 | return; |
| 348 | 348 | |
| 349 | - $gmt_time = microtime( true ); |
|
| 350 | - $keys = array_keys( $crons ); |
|
| 351 | - if ( isset($keys[0]) && $keys[0] > $gmt_time ) |
|
| 349 | + $gmt_time = microtime(true); |
|
| 350 | + $keys = array_keys($crons); |
|
| 351 | + if (isset($keys[0]) && $keys[0] > $gmt_time) |
|
| 352 | 352 | return; |
| 353 | 353 | |
| 354 | 354 | $schedules = wp_get_schedules(); |
| 355 | - foreach ( $crons as $timestamp => $cronhooks ) { |
|
| 356 | - if ( $timestamp > $gmt_time ) break; |
|
| 357 | - foreach ( (array) $cronhooks as $hook => $args ) { |
|
| 358 | - if ( isset($schedules[$hook]['callback']) && !call_user_func( $schedules[$hook]['callback'] ) ) |
|
| 355 | + foreach ($crons as $timestamp => $cronhooks) { |
|
| 356 | + if ($timestamp > $gmt_time) break; |
|
| 357 | + foreach ((array) $cronhooks as $hook => $args) { |
|
| 358 | + if (isset($schedules[$hook]['callback']) && ! call_user_func($schedules[$hook]['callback'])) |
|
| 359 | 359 | continue; |
| 360 | - spawn_cron( $gmt_time ); |
|
| 360 | + spawn_cron($gmt_time); |
|
| 361 | 361 | break 2; |
| 362 | 362 | } |
| 363 | 363 | } |
@@ -395,9 +395,9 @@ discard block |
||
| 395 | 395 | */ |
| 396 | 396 | function wp_get_schedules() { |
| 397 | 397 | $schedules = array( |
| 398 | - 'hourly' => array( 'interval' => HOUR_IN_SECONDS, 'display' => __( 'Once Hourly' ) ), |
|
| 399 | - 'twicedaily' => array( 'interval' => 12 * HOUR_IN_SECONDS, 'display' => __( 'Twice Daily' ) ), |
|
| 400 | - 'daily' => array( 'interval' => DAY_IN_SECONDS, 'display' => __( 'Once Daily' ) ), |
|
| 398 | + 'hourly' => array('interval' => HOUR_IN_SECONDS, 'display' => __('Once Hourly')), |
|
| 399 | + 'twicedaily' => array('interval' => 12 * HOUR_IN_SECONDS, 'display' => __('Twice Daily')), |
|
| 400 | + 'daily' => array('interval' => DAY_IN_SECONDS, 'display' => __('Once Daily')), |
|
| 401 | 401 | ); |
| 402 | 402 | /** |
| 403 | 403 | * Filters the non-default cron schedules. |
@@ -406,7 +406,7 @@ discard block |
||
| 406 | 406 | * |
| 407 | 407 | * @param array $new_schedules An array of non-default cron schedules. Default empty. |
| 408 | 408 | */ |
| 409 | - return array_merge( apply_filters( 'cron_schedules', array() ), $schedules ); |
|
| 409 | + return array_merge(apply_filters('cron_schedules', array()), $schedules); |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** |
@@ -421,10 +421,10 @@ discard block |
||
| 421 | 421 | function wp_get_schedule($hook, $args = array()) { |
| 422 | 422 | $crons = _get_cron_array(); |
| 423 | 423 | $key = md5(serialize($args)); |
| 424 | - if ( empty($crons) ) |
|
| 424 | + if (empty($crons)) |
|
| 425 | 425 | return false; |
| 426 | - foreach ( $crons as $timestamp => $cron ) { |
|
| 427 | - if ( isset( $cron[$hook][$key] ) ) |
|
| 426 | + foreach ($crons as $timestamp => $cron) { |
|
| 427 | + if (isset($cron[$hook][$key])) |
|
| 428 | 428 | return $cron[$hook][$key]['schedule']; |
| 429 | 429 | } |
| 430 | 430 | return false; |
@@ -442,12 +442,12 @@ discard block |
||
| 442 | 442 | * |
| 443 | 443 | * @return false|array CRON info array. |
| 444 | 444 | */ |
| 445 | -function _get_cron_array() { |
|
| 445 | +function _get_cron_array() { |
|
| 446 | 446 | $cron = get_option('cron'); |
| 447 | - if ( ! is_array($cron) ) |
|
| 447 | + if ( ! is_array($cron)) |
|
| 448 | 448 | return false; |
| 449 | 449 | |
| 450 | - if ( !isset($cron['version']) ) |
|
| 450 | + if ( ! isset($cron['version'])) |
|
| 451 | 451 | $cron = _upgrade_cron_array($cron); |
| 452 | 452 | |
| 453 | 453 | unset($cron['version']); |
@@ -465,7 +465,7 @@ discard block |
||
| 465 | 465 | */ |
| 466 | 466 | function _set_cron_array($cron) { |
| 467 | 467 | $cron['version'] = 2; |
| 468 | - update_option( 'cron', $cron ); |
|
| 468 | + update_option('cron', $cron); |
|
| 469 | 469 | } |
| 470 | 470 | |
| 471 | 471 | /** |
@@ -480,19 +480,19 @@ discard block |
||
| 480 | 480 | * @return array An upgraded Cron info array. |
| 481 | 481 | */ |
| 482 | 482 | function _upgrade_cron_array($cron) { |
| 483 | - if ( isset($cron['version']) && 2 == $cron['version']) |
|
| 483 | + if (isset($cron['version']) && 2 == $cron['version']) |
|
| 484 | 484 | return $cron; |
| 485 | 485 | |
| 486 | 486 | $new_cron = array(); |
| 487 | 487 | |
| 488 | - foreach ( (array) $cron as $timestamp => $hooks) { |
|
| 489 | - foreach ( (array) $hooks as $hook => $args ) { |
|
| 488 | + foreach ((array) $cron as $timestamp => $hooks) { |
|
| 489 | + foreach ((array) $hooks as $hook => $args) { |
|
| 490 | 490 | $key = md5(serialize($args['args'])); |
| 491 | 491 | $new_cron[$timestamp][$hook][$key] = $args; |
| 492 | 492 | } |
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | $new_cron['version'] = 2; |
| 496 | - update_option( 'cron', $new_cron ); |
|
| 496 | + update_option('cron', $new_cron); |
|
| 497 | 497 | return $new_cron; |
| 498 | 498 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | function get_locale() { |
| 31 | 31 | global $locale, $wp_local_package; |
| 32 | 32 | |
| 33 | - if ( isset( $locale ) ) { |
|
| 33 | + if (isset($locale)) { |
|
| 34 | 34 | /** |
| 35 | 35 | * Filters WordPress install's locale ID. |
| 36 | 36 | * |
@@ -38,41 +38,41 @@ discard block |
||
| 38 | 38 | * |
| 39 | 39 | * @param string $locale The locale ID. |
| 40 | 40 | */ |
| 41 | - return apply_filters( 'locale', $locale ); |
|
| 41 | + return apply_filters('locale', $locale); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - if ( isset( $wp_local_package ) ) { |
|
| 44 | + if (isset($wp_local_package)) { |
|
| 45 | 45 | $locale = $wp_local_package; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | // WPLANG was defined in wp-config. |
| 49 | - if ( defined( 'WPLANG' ) ) { |
|
| 49 | + if (defined('WPLANG')) { |
|
| 50 | 50 | $locale = WPLANG; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | // If multisite, check options. |
| 54 | - if ( is_multisite() ) { |
|
| 54 | + if (is_multisite()) { |
|
| 55 | 55 | // Don't check blog option when installing. |
| 56 | - if ( wp_installing() || ( false === $ms_locale = get_option( 'WPLANG' ) ) ) { |
|
| 57 | - $ms_locale = get_site_option( 'WPLANG' ); |
|
| 56 | + if (wp_installing() || (false === $ms_locale = get_option('WPLANG'))) { |
|
| 57 | + $ms_locale = get_site_option('WPLANG'); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - if ( $ms_locale !== false ) { |
|
| 60 | + if ($ms_locale !== false) { |
|
| 61 | 61 | $locale = $ms_locale; |
| 62 | 62 | } |
| 63 | 63 | } else { |
| 64 | - $db_locale = get_option( 'WPLANG' ); |
|
| 65 | - if ( $db_locale !== false ) { |
|
| 64 | + $db_locale = get_option('WPLANG'); |
|
| 65 | + if ($db_locale !== false) { |
|
| 66 | 66 | $locale = $db_locale; |
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - if ( empty( $locale ) ) { |
|
| 70 | + if (empty($locale)) { |
|
| 71 | 71 | $locale = 'en_US'; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** This filter is documented in wp-includes/l10n.php */ |
| 75 | - return apply_filters( 'locale', $locale ); |
|
| 75 | + return apply_filters('locale', $locale); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -89,9 +89,9 @@ discard block |
||
| 89 | 89 | * Default 'default'. |
| 90 | 90 | * @return string Translated text |
| 91 | 91 | */ |
| 92 | -function translate( $text, $domain = 'default' ) { |
|
| 93 | - $translations = get_translations_for_domain( $domain ); |
|
| 94 | - $translations = $translations->translate( $text ); |
|
| 92 | +function translate($text, $domain = 'default') { |
|
| 93 | + $translations = get_translations_for_domain($domain); |
|
| 94 | + $translations = $translations->translate($text); |
|
| 95 | 95 | |
| 96 | 96 | /** |
| 97 | 97 | * Filters text with its translation. |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | * @param string $text Text to translate. |
| 103 | 103 | * @param string $domain Text domain. Unique identifier for retrieving translated strings. |
| 104 | 104 | */ |
| 105 | - return apply_filters( 'gettext', $translations, $text, $domain ); |
|
| 105 | + return apply_filters('gettext', $translations, $text, $domain); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -116,12 +116,12 @@ discard block |
||
| 116 | 116 | * @param string $string A pipe-delimited string. |
| 117 | 117 | * @return string Either $string or everything before the last pipe. |
| 118 | 118 | */ |
| 119 | -function before_last_bar( $string ) { |
|
| 120 | - $last_bar = strrpos( $string, '|' ); |
|
| 121 | - if ( false === $last_bar ) { |
|
| 119 | +function before_last_bar($string) { |
|
| 120 | + $last_bar = strrpos($string, '|'); |
|
| 121 | + if (false === $last_bar) { |
|
| 122 | 122 | return $string; |
| 123 | 123 | } else { |
| 124 | - return substr( $string, 0, $last_bar ); |
|
| 124 | + return substr($string, 0, $last_bar); |
|
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | |
@@ -141,9 +141,9 @@ discard block |
||
| 141 | 141 | * Default 'default'. |
| 142 | 142 | * @return string Translated text on success, original text on failure. |
| 143 | 143 | */ |
| 144 | -function translate_with_gettext_context( $text, $context, $domain = 'default' ) { |
|
| 145 | - $translations = get_translations_for_domain( $domain ); |
|
| 146 | - $translations = $translations->translate( $text, $context ); |
|
| 144 | +function translate_with_gettext_context($text, $context, $domain = 'default') { |
|
| 145 | + $translations = get_translations_for_domain($domain); |
|
| 146 | + $translations = $translations->translate($text, $context); |
|
| 147 | 147 | /** |
| 148 | 148 | * Filters text with its translation based on context information. |
| 149 | 149 | * |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * @param string $context Context information for the translators. |
| 155 | 155 | * @param string $domain Text domain. Unique identifier for retrieving translated strings. |
| 156 | 156 | */ |
| 157 | - return apply_filters( 'gettext_with_context', $translations, $text, $context, $domain ); |
|
| 157 | + return apply_filters('gettext_with_context', $translations, $text, $context, $domain); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -169,8 +169,8 @@ discard block |
||
| 169 | 169 | * Default 'default'. |
| 170 | 170 | * @return string Translated text. |
| 171 | 171 | */ |
| 172 | -function __( $text, $domain = 'default' ) { |
|
| 173 | - return translate( $text, $domain ); |
|
| 172 | +function __($text, $domain = 'default') { |
|
| 173 | + return translate($text, $domain); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
@@ -185,8 +185,8 @@ discard block |
||
| 185 | 185 | * Default 'default'. |
| 186 | 186 | * @return string Translated text on success, original text on failure. |
| 187 | 187 | */ |
| 188 | -function esc_attr__( $text, $domain = 'default' ) { |
|
| 189 | - return esc_attr( translate( $text, $domain ) ); |
|
| 188 | +function esc_attr__($text, $domain = 'default') { |
|
| 189 | + return esc_attr(translate($text, $domain)); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | /** |
@@ -201,8 +201,8 @@ discard block |
||
| 201 | 201 | * Default 'default'. |
| 202 | 202 | * @return string Translated text |
| 203 | 203 | */ |
| 204 | -function esc_html__( $text, $domain = 'default' ) { |
|
| 205 | - return esc_html( translate( $text, $domain ) ); |
|
| 204 | +function esc_html__($text, $domain = 'default') { |
|
| 205 | + return esc_html(translate($text, $domain)); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | /** |
@@ -214,8 +214,8 @@ discard block |
||
| 214 | 214 | * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. |
| 215 | 215 | * Default 'default'. |
| 216 | 216 | */ |
| 217 | -function _e( $text, $domain = 'default' ) { |
|
| 218 | - echo translate( $text, $domain ); |
|
| 217 | +function _e($text, $domain = 'default') { |
|
| 218 | + echo translate($text, $domain); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | /** |
@@ -227,8 +227,8 @@ discard block |
||
| 227 | 227 | * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. |
| 228 | 228 | * Default 'default'. |
| 229 | 229 | */ |
| 230 | -function esc_attr_e( $text, $domain = 'default' ) { |
|
| 231 | - echo esc_attr( translate( $text, $domain ) ); |
|
| 230 | +function esc_attr_e($text, $domain = 'default') { |
|
| 231 | + echo esc_attr(translate($text, $domain)); |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | /** |
@@ -240,8 +240,8 @@ discard block |
||
| 240 | 240 | * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. |
| 241 | 241 | * Default 'default'. |
| 242 | 242 | */ |
| 243 | -function esc_html_e( $text, $domain = 'default' ) { |
|
| 244 | - echo esc_html( translate( $text, $domain ) ); |
|
| 243 | +function esc_html_e($text, $domain = 'default') { |
|
| 244 | + echo esc_html(translate($text, $domain)); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | /** |
@@ -261,8 +261,8 @@ discard block |
||
| 261 | 261 | * Default 'default'. |
| 262 | 262 | * @return string Translated context string without pipe. |
| 263 | 263 | */ |
| 264 | -function _x( $text, $context, $domain = 'default' ) { |
|
| 265 | - return translate_with_gettext_context( $text, $context, $domain ); |
|
| 264 | +function _x($text, $context, $domain = 'default') { |
|
| 265 | + return translate_with_gettext_context($text, $context, $domain); |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | /** |
@@ -276,8 +276,8 @@ discard block |
||
| 276 | 276 | * Default 'default'. |
| 277 | 277 | * @return string Translated context string without pipe. |
| 278 | 278 | */ |
| 279 | -function _ex( $text, $context, $domain = 'default' ) { |
|
| 280 | - echo _x( $text, $context, $domain ); |
|
| 279 | +function _ex($text, $context, $domain = 'default') { |
|
| 280 | + echo _x($text, $context, $domain); |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | /** |
@@ -291,8 +291,8 @@ discard block |
||
| 291 | 291 | * Default 'default'. |
| 292 | 292 | * @return string Translated text |
| 293 | 293 | */ |
| 294 | -function esc_attr_x( $text, $context, $domain = 'default' ) { |
|
| 295 | - return esc_attr( translate_with_gettext_context( $text, $context, $domain ) ); |
|
| 294 | +function esc_attr_x($text, $context, $domain = 'default') { |
|
| 295 | + return esc_attr(translate_with_gettext_context($text, $context, $domain)); |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | /** |
@@ -306,8 +306,8 @@ discard block |
||
| 306 | 306 | * Default 'default'. |
| 307 | 307 | * @return string Translated text. |
| 308 | 308 | */ |
| 309 | -function esc_html_x( $text, $context, $domain = 'default' ) { |
|
| 310 | - return esc_html( translate_with_gettext_context( $text, $context, $domain ) ); |
|
| 309 | +function esc_html_x($text, $context, $domain = 'default') { |
|
| 310 | + return esc_html(translate_with_gettext_context($text, $context, $domain)); |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | /** |
@@ -329,9 +329,9 @@ discard block |
||
| 329 | 329 | * Default 'default'. |
| 330 | 330 | * @return string The translated singular or plural form. |
| 331 | 331 | */ |
| 332 | -function _n( $single, $plural, $number, $domain = 'default' ) { |
|
| 333 | - $translations = get_translations_for_domain( $domain ); |
|
| 334 | - $translation = $translations->translate_plural( $single, $plural, $number ); |
|
| 332 | +function _n($single, $plural, $number, $domain = 'default') { |
|
| 333 | + $translations = get_translations_for_domain($domain); |
|
| 334 | + $translation = $translations->translate_plural($single, $plural, $number); |
|
| 335 | 335 | |
| 336 | 336 | /** |
| 337 | 337 | * Filters the singular or plural form of a string. |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | * @param string $number The number to compare against to use either the singular or plural form. |
| 345 | 345 | * @param string $domain Text domain. Unique identifier for retrieving translated strings. |
| 346 | 346 | */ |
| 347 | - return apply_filters( 'ngettext', $translation, $single, $plural, $number, $domain ); |
|
| 347 | + return apply_filters('ngettext', $translation, $single, $plural, $number, $domain); |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | /** |
@@ -370,8 +370,8 @@ discard block |
||
| 370 | 370 | * @return string The translated singular or plural form. |
| 371 | 371 | */ |
| 372 | 372 | function _nx($single, $plural, $number, $context, $domain = 'default') { |
| 373 | - $translations = get_translations_for_domain( $domain ); |
|
| 374 | - $translation = $translations->translate_plural( $single, $plural, $number, $context ); |
|
| 373 | + $translations = get_translations_for_domain($domain); |
|
| 374 | + $translation = $translations->translate_plural($single, $plural, $number, $context); |
|
| 375 | 375 | |
| 376 | 376 | /** |
| 377 | 377 | * Filters the singular or plural form of a string with gettext context. |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | * @param string $context Context information for the translators. |
| 386 | 386 | * @param string $domain Text domain. Unique identifier for retrieving translated strings. |
| 387 | 387 | */ |
| 388 | - return apply_filters( 'ngettext_with_context', $translation, $single, $plural, $number, $context, $domain ); |
|
| 388 | + return apply_filters('ngettext_with_context', $translation, $single, $plural, $number, $context, $domain); |
|
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | /** |
@@ -421,8 +421,8 @@ discard block |
||
| 421 | 421 | * @type string $domain Text domain. |
| 422 | 422 | * } |
| 423 | 423 | */ |
| 424 | -function _n_noop( $singular, $plural, $domain = null ) { |
|
| 425 | - return array( 0 => $singular, 1 => $plural, 'singular' => $singular, 'plural' => $plural, 'context' => null, 'domain' => $domain ); |
|
| 424 | +function _n_noop($singular, $plural, $domain = null) { |
|
| 425 | + return array(0 => $singular, 1 => $plural, 'singular' => $singular, 'plural' => $plural, 'context' => null, 'domain' => $domain); |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | /** |
@@ -460,8 +460,8 @@ discard block |
||
| 460 | 460 | * @type string $domain Text domain. |
| 461 | 461 | * } |
| 462 | 462 | */ |
| 463 | -function _nx_noop( $singular, $plural, $context, $domain = null ) { |
|
| 464 | - return array( 0 => $singular, 1 => $plural, 2 => $context, 'singular' => $singular, 'plural' => $plural, 'context' => $context, 'domain' => $domain ); |
|
| 463 | +function _nx_noop($singular, $plural, $context, $domain = null) { |
|
| 464 | + return array(0 => $singular, 1 => $plural, 2 => $context, 'singular' => $singular, 'plural' => $plural, 'context' => $context, 'domain' => $domain); |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | /** |
@@ -488,14 +488,14 @@ discard block |
||
| 488 | 488 | * a text domain passed to _n_noop() or _nx_noop(), it will override this value. Default 'default'. |
| 489 | 489 | * @return string Either $single or $plural translated text. |
| 490 | 490 | */ |
| 491 | -function translate_nooped_plural( $nooped_plural, $count, $domain = 'default' ) { |
|
| 492 | - if ( $nooped_plural['domain'] ) |
|
| 491 | +function translate_nooped_plural($nooped_plural, $count, $domain = 'default') { |
|
| 492 | + if ($nooped_plural['domain']) |
|
| 493 | 493 | $domain = $nooped_plural['domain']; |
| 494 | 494 | |
| 495 | - if ( $nooped_plural['context'] ) |
|
| 496 | - return _nx( $nooped_plural['singular'], $nooped_plural['plural'], $count, $nooped_plural['context'], $domain ); |
|
| 495 | + if ($nooped_plural['context']) |
|
| 496 | + return _nx($nooped_plural['singular'], $nooped_plural['plural'], $count, $nooped_plural['context'], $domain); |
|
| 497 | 497 | else |
| 498 | - return _n( $nooped_plural['singular'], $nooped_plural['plural'], $count, $domain ); |
|
| 498 | + return _n($nooped_plural['singular'], $nooped_plural['plural'], $count, $domain); |
|
| 499 | 499 | } |
| 500 | 500 | |
| 501 | 501 | /** |
@@ -516,7 +516,7 @@ discard block |
||
| 516 | 516 | * @param string $mofile Path to the .mo file. |
| 517 | 517 | * @return bool True on success, false on failure. |
| 518 | 518 | */ |
| 519 | -function load_textdomain( $domain, $mofile ) { |
|
| 519 | +function load_textdomain($domain, $mofile) { |
|
| 520 | 520 | global $l10n, $l10n_unloaded; |
| 521 | 521 | |
| 522 | 522 | $l10n_unloaded = (array) $l10n_unloaded; |
@@ -530,10 +530,10 @@ discard block |
||
| 530 | 530 | * @param string $domain Text domain. Unique identifier for retrieving translated strings. |
| 531 | 531 | * @param string $mofile Path to the MO file. |
| 532 | 532 | */ |
| 533 | - $plugin_override = apply_filters( 'override_load_textdomain', false, $domain, $mofile ); |
|
| 533 | + $plugin_override = apply_filters('override_load_textdomain', false, $domain, $mofile); |
|
| 534 | 534 | |
| 535 | - if ( true == $plugin_override ) { |
|
| 536 | - unset( $l10n_unloaded[ $domain ] ); |
|
| 535 | + if (true == $plugin_override) { |
|
| 536 | + unset($l10n_unloaded[$domain]); |
|
| 537 | 537 | |
| 538 | 538 | return true; |
| 539 | 539 | } |
@@ -546,7 +546,7 @@ discard block |
||
| 546 | 546 | * @param string $domain Text domain. Unique identifier for retrieving translated strings. |
| 547 | 547 | * @param string $mofile Path to the .mo file. |
| 548 | 548 | */ |
| 549 | - do_action( 'load_textdomain', $domain, $mofile ); |
|
| 549 | + do_action('load_textdomain', $domain, $mofile); |
|
| 550 | 550 | |
| 551 | 551 | /** |
| 552 | 552 | * Filters MO file path for loading translations for a specific text domain. |
@@ -556,17 +556,17 @@ discard block |
||
| 556 | 556 | * @param string $mofile Path to the MO file. |
| 557 | 557 | * @param string $domain Text domain. Unique identifier for retrieving translated strings. |
| 558 | 558 | */ |
| 559 | - $mofile = apply_filters( 'load_textdomain_mofile', $mofile, $domain ); |
|
| 559 | + $mofile = apply_filters('load_textdomain_mofile', $mofile, $domain); |
|
| 560 | 560 | |
| 561 | - if ( !is_readable( $mofile ) ) return false; |
|
| 561 | + if ( ! is_readable($mofile)) return false; |
|
| 562 | 562 | |
| 563 | 563 | $mo = new MO(); |
| 564 | - if ( !$mo->import_from_file( $mofile ) ) return false; |
|
| 564 | + if ( ! $mo->import_from_file($mofile)) return false; |
|
| 565 | 565 | |
| 566 | - if ( isset( $l10n[$domain] ) ) |
|
| 567 | - $mo->merge_with( $l10n[$domain] ); |
|
| 566 | + if (isset($l10n[$domain])) |
|
| 567 | + $mo->merge_with($l10n[$domain]); |
|
| 568 | 568 | |
| 569 | - unset( $l10n_unloaded[ $domain ] ); |
|
| 569 | + unset($l10n_unloaded[$domain]); |
|
| 570 | 570 | |
| 571 | 571 | $l10n[$domain] = &$mo; |
| 572 | 572 | |
@@ -584,7 +584,7 @@ discard block |
||
| 584 | 584 | * @param string $domain Text domain. Unique identifier for retrieving translated strings. |
| 585 | 585 | * @return bool Whether textdomain was unloaded. |
| 586 | 586 | */ |
| 587 | -function unload_textdomain( $domain ) { |
|
| 587 | +function unload_textdomain($domain) { |
|
| 588 | 588 | global $l10n, $l10n_unloaded; |
| 589 | 589 | |
| 590 | 590 | $l10n_unloaded = (array) $l10n_unloaded; |
@@ -597,10 +597,10 @@ discard block |
||
| 597 | 597 | * @param bool $override Whether to override the text domain unloading. Default false. |
| 598 | 598 | * @param string $domain Text domain. Unique identifier for retrieving translated strings. |
| 599 | 599 | */ |
| 600 | - $plugin_override = apply_filters( 'override_unload_textdomain', false, $domain ); |
|
| 600 | + $plugin_override = apply_filters('override_unload_textdomain', false, $domain); |
|
| 601 | 601 | |
| 602 | - if ( $plugin_override ) { |
|
| 603 | - $l10n_unloaded[ $domain ] = true; |
|
| 602 | + if ($plugin_override) { |
|
| 603 | + $l10n_unloaded[$domain] = true; |
|
| 604 | 604 | |
| 605 | 605 | return true; |
| 606 | 606 | } |
@@ -612,12 +612,12 @@ discard block |
||
| 612 | 612 | * |
| 613 | 613 | * @param string $domain Text domain. Unique identifier for retrieving translated strings. |
| 614 | 614 | */ |
| 615 | - do_action( 'unload_textdomain', $domain ); |
|
| 615 | + do_action('unload_textdomain', $domain); |
|
| 616 | 616 | |
| 617 | - if ( isset( $l10n[$domain] ) ) { |
|
| 618 | - unset( $l10n[$domain] ); |
|
| 617 | + if (isset($l10n[$domain])) { |
|
| 618 | + unset($l10n[$domain]); |
|
| 619 | 619 | |
| 620 | - $l10n_unloaded[ $domain ] = true; |
|
| 620 | + $l10n_unloaded[$domain] = true; |
|
| 621 | 621 | |
| 622 | 622 | return true; |
| 623 | 623 | } |
@@ -638,27 +638,27 @@ discard block |
||
| 638 | 638 | * @param string $locale Optional. Locale to load. Default is the value of get_locale(). |
| 639 | 639 | * @return bool Whether the textdomain was loaded. |
| 640 | 640 | */ |
| 641 | -function load_default_textdomain( $locale = null ) { |
|
| 642 | - if ( null === $locale ) { |
|
| 641 | +function load_default_textdomain($locale = null) { |
|
| 642 | + if (null === $locale) { |
|
| 643 | 643 | $locale = get_locale(); |
| 644 | 644 | } |
| 645 | 645 | |
| 646 | 646 | // Unload previously loaded strings so we can switch translations. |
| 647 | - unload_textdomain( 'default' ); |
|
| 647 | + unload_textdomain('default'); |
|
| 648 | 648 | |
| 649 | - $return = load_textdomain( 'default', WP_LANG_DIR . "/$locale.mo" ); |
|
| 649 | + $return = load_textdomain('default', WP_LANG_DIR."/$locale.mo"); |
|
| 650 | 650 | |
| 651 | - if ( ( is_multisite() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) ) && ! file_exists( WP_LANG_DIR . "/admin-$locale.mo" ) ) { |
|
| 652 | - load_textdomain( 'default', WP_LANG_DIR . "/ms-$locale.mo" ); |
|
| 651 | + if ((is_multisite() || (defined('WP_INSTALLING_NETWORK') && WP_INSTALLING_NETWORK)) && ! file_exists(WP_LANG_DIR."/admin-$locale.mo")) { |
|
| 652 | + load_textdomain('default', WP_LANG_DIR."/ms-$locale.mo"); |
|
| 653 | 653 | return $return; |
| 654 | 654 | } |
| 655 | 655 | |
| 656 | - if ( is_admin() || wp_installing() || ( defined( 'WP_REPAIRING' ) && WP_REPAIRING ) ) { |
|
| 657 | - load_textdomain( 'default', WP_LANG_DIR . "/admin-$locale.mo" ); |
|
| 656 | + if (is_admin() || wp_installing() || (defined('WP_REPAIRING') && WP_REPAIRING)) { |
|
| 657 | + load_textdomain('default', WP_LANG_DIR."/admin-$locale.mo"); |
|
| 658 | 658 | } |
| 659 | 659 | |
| 660 | - if ( is_network_admin() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) ) |
|
| 661 | - load_textdomain( 'default', WP_LANG_DIR . "/admin-network-$locale.mo" ); |
|
| 660 | + if (is_network_admin() || (defined('WP_INSTALLING_NETWORK') && WP_INSTALLING_NETWORK)) |
|
| 661 | + load_textdomain('default', WP_LANG_DIR."/admin-network-$locale.mo"); |
|
| 662 | 662 | |
| 663 | 663 | return $return; |
| 664 | 664 | } |
@@ -679,7 +679,7 @@ discard block |
||
| 679 | 679 | * Default false. |
| 680 | 680 | * @return bool True when textdomain is successfully loaded, false otherwise. |
| 681 | 681 | */ |
| 682 | -function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path = false ) { |
|
| 682 | +function load_plugin_textdomain($domain, $deprecated = false, $plugin_rel_path = false) { |
|
| 683 | 683 | /** |
| 684 | 684 | * Filters a plugin's locale. |
| 685 | 685 | * |
@@ -688,25 +688,25 @@ discard block |
||
| 688 | 688 | * @param string $locale The plugin's current locale. |
| 689 | 689 | * @param string $domain Text domain. Unique identifier for retrieving translated strings. |
| 690 | 690 | */ |
| 691 | - $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); |
|
| 691 | + $locale = apply_filters('plugin_locale', get_locale(), $domain); |
|
| 692 | 692 | |
| 693 | - $mofile = $domain . '-' . $locale . '.mo'; |
|
| 693 | + $mofile = $domain.'-'.$locale.'.mo'; |
|
| 694 | 694 | |
| 695 | 695 | // Try to load from the languages directory first. |
| 696 | - if ( load_textdomain( $domain, WP_LANG_DIR . '/plugins/' . $mofile ) ) { |
|
| 696 | + if (load_textdomain($domain, WP_LANG_DIR.'/plugins/'.$mofile)) { |
|
| 697 | 697 | return true; |
| 698 | 698 | } |
| 699 | 699 | |
| 700 | - if ( false !== $plugin_rel_path ) { |
|
| 701 | - $path = WP_PLUGIN_DIR . '/' . trim( $plugin_rel_path, '/' ); |
|
| 702 | - } elseif ( false !== $deprecated ) { |
|
| 703 | - _deprecated_argument( __FUNCTION__, '2.7.0' ); |
|
| 704 | - $path = ABSPATH . trim( $deprecated, '/' ); |
|
| 700 | + if (false !== $plugin_rel_path) { |
|
| 701 | + $path = WP_PLUGIN_DIR.'/'.trim($plugin_rel_path, '/'); |
|
| 702 | + } elseif (false !== $deprecated) { |
|
| 703 | + _deprecated_argument(__FUNCTION__, '2.7.0'); |
|
| 704 | + $path = ABSPATH.trim($deprecated, '/'); |
|
| 705 | 705 | } else { |
| 706 | 706 | $path = WP_PLUGIN_DIR; |
| 707 | 707 | } |
| 708 | 708 | |
| 709 | - return load_textdomain( $domain, $path . '/' . $mofile ); |
|
| 709 | + return load_textdomain($domain, $path.'/'.$mofile); |
|
| 710 | 710 | } |
| 711 | 711 | |
| 712 | 712 | /** |
@@ -720,20 +720,20 @@ discard block |
||
| 720 | 720 | * file resides. Default empty string. |
| 721 | 721 | * @return bool True when textdomain is successfully loaded, false otherwise. |
| 722 | 722 | */ |
| 723 | -function load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' ) { |
|
| 723 | +function load_muplugin_textdomain($domain, $mu_plugin_rel_path = '') { |
|
| 724 | 724 | /** This filter is documented in wp-includes/l10n.php */ |
| 725 | - $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); |
|
| 725 | + $locale = apply_filters('plugin_locale', get_locale(), $domain); |
|
| 726 | 726 | |
| 727 | - $mofile = $domain . '-' . $locale . '.mo'; |
|
| 727 | + $mofile = $domain.'-'.$locale.'.mo'; |
|
| 728 | 728 | |
| 729 | 729 | // Try to load from the languages directory first. |
| 730 | - if ( load_textdomain( $domain, WP_LANG_DIR . '/plugins/' . $mofile ) ) { |
|
| 730 | + if (load_textdomain($domain, WP_LANG_DIR.'/plugins/'.$mofile)) { |
|
| 731 | 731 | return true; |
| 732 | 732 | } |
| 733 | 733 | |
| 734 | - $path = trailingslashit( WPMU_PLUGIN_DIR . '/' . ltrim( $mu_plugin_rel_path, '/' ) ); |
|
| 734 | + $path = trailingslashit(WPMU_PLUGIN_DIR.'/'.ltrim($mu_plugin_rel_path, '/')); |
|
| 735 | 735 | |
| 736 | - return load_textdomain( $domain, $path . '/' . $mofile ); |
|
| 736 | + return load_textdomain($domain, $path.'/'.$mofile); |
|
| 737 | 737 | } |
| 738 | 738 | |
| 739 | 739 | /** |
@@ -752,7 +752,7 @@ discard block |
||
| 752 | 752 | * Default false. |
| 753 | 753 | * @return bool True when textdomain is successfully loaded, false otherwise. |
| 754 | 754 | */ |
| 755 | -function load_theme_textdomain( $domain, $path = false ) { |
|
| 755 | +function load_theme_textdomain($domain, $path = false) { |
|
| 756 | 756 | /** |
| 757 | 757 | * Filters a theme's locale. |
| 758 | 758 | * |
@@ -761,20 +761,20 @@ discard block |
||
| 761 | 761 | * @param string $locale The theme's current locale. |
| 762 | 762 | * @param string $domain Text domain. Unique identifier for retrieving translated strings. |
| 763 | 763 | */ |
| 764 | - $locale = apply_filters( 'theme_locale', get_locale(), $domain ); |
|
| 764 | + $locale = apply_filters('theme_locale', get_locale(), $domain); |
|
| 765 | 765 | |
| 766 | - $mofile = $domain . '-' . $locale . '.mo'; |
|
| 766 | + $mofile = $domain.'-'.$locale.'.mo'; |
|
| 767 | 767 | |
| 768 | 768 | // Try to load from the languages directory first. |
| 769 | - if ( load_textdomain( $domain, WP_LANG_DIR . '/themes/' . $mofile ) ) { |
|
| 769 | + if (load_textdomain($domain, WP_LANG_DIR.'/themes/'.$mofile)) { |
|
| 770 | 770 | return true; |
| 771 | 771 | } |
| 772 | 772 | |
| 773 | - if ( ! $path ) { |
|
| 773 | + if ( ! $path) { |
|
| 774 | 774 | $path = get_template_directory(); |
| 775 | 775 | } |
| 776 | 776 | |
| 777 | - return load_textdomain( $domain, $path . '/' . $locale . '.mo' ); |
|
| 777 | + return load_textdomain($domain, $path.'/'.$locale.'.mo'); |
|
| 778 | 778 | } |
| 779 | 779 | |
| 780 | 780 | /** |
@@ -792,10 +792,10 @@ discard block |
||
| 792 | 792 | * Default false. |
| 793 | 793 | * @return bool True when the theme textdomain is successfully loaded, false otherwise. |
| 794 | 794 | */ |
| 795 | -function load_child_theme_textdomain( $domain, $path = false ) { |
|
| 796 | - if ( ! $path ) |
|
| 795 | +function load_child_theme_textdomain($domain, $path = false) { |
|
| 796 | + if ( ! $path) |
|
| 797 | 797 | $path = get_stylesheet_directory(); |
| 798 | - return load_theme_textdomain( $domain, $path ); |
|
| 798 | + return load_theme_textdomain($domain, $path); |
|
| 799 | 799 | } |
| 800 | 800 | |
| 801 | 801 | /** |
@@ -816,7 +816,7 @@ discard block |
||
| 816 | 816 | * @param string $domain Text domain. Unique identifier for retrieving translated strings. |
| 817 | 817 | * @return bool True when the textdomain is successfully loaded, false otherwise. |
| 818 | 818 | */ |
| 819 | -function _load_textdomain_just_in_time( $domain ) { |
|
| 819 | +function _load_textdomain_just_in_time($domain) { |
|
| 820 | 820 | global $l10n_unloaded; |
| 821 | 821 | |
| 822 | 822 | $l10n_unloaded = (array) $l10n_unloaded; |
@@ -824,20 +824,20 @@ discard block |
||
| 824 | 824 | static $cached_mofiles = null; |
| 825 | 825 | |
| 826 | 826 | // Short-circuit if domain is 'default' which is reserved for core. |
| 827 | - if ( 'default' === $domain || isset( $l10n_unloaded[ $domain ] ) ) { |
|
| 827 | + if ('default' === $domain || isset($l10n_unloaded[$domain])) { |
|
| 828 | 828 | return false; |
| 829 | 829 | } |
| 830 | 830 | |
| 831 | - if ( null === $cached_mofiles ) { |
|
| 831 | + if (null === $cached_mofiles) { |
|
| 832 | 832 | $cached_mofiles = array(); |
| 833 | 833 | |
| 834 | 834 | $locations = array( |
| 835 | - WP_LANG_DIR . '/plugins', |
|
| 836 | - WP_LANG_DIR . '/themes', |
|
| 835 | + WP_LANG_DIR.'/plugins', |
|
| 836 | + WP_LANG_DIR.'/themes', |
|
| 837 | 837 | ); |
| 838 | 838 | |
| 839 | - foreach ( $locations as $location ) { |
|
| 840 | - foreach ( get_available_languages( $location ) as $file ) { |
|
| 839 | + foreach ($locations as $location) { |
|
| 840 | + foreach (get_available_languages($location) as $file) { |
|
| 841 | 841 | $cached_mofiles[] = "{$location}/{$file}.mo"; |
| 842 | 842 | } |
| 843 | 843 | } |
@@ -846,12 +846,12 @@ discard block |
||
| 846 | 846 | $locale = get_locale(); |
| 847 | 847 | $mofile = "{$domain}-{$locale}.mo"; |
| 848 | 848 | |
| 849 | - if ( in_array( WP_LANG_DIR . '/plugins/' . $mofile, $cached_mofiles ) ) { |
|
| 850 | - return load_textdomain( $domain, WP_LANG_DIR . '/plugins/' . $mofile ); |
|
| 849 | + if (in_array(WP_LANG_DIR.'/plugins/'.$mofile, $cached_mofiles)) { |
|
| 850 | + return load_textdomain($domain, WP_LANG_DIR.'/plugins/'.$mofile); |
|
| 851 | 851 | } |
| 852 | 852 | |
| 853 | - if ( in_array( WP_LANG_DIR . '/themes/' . $mofile, $cached_mofiles ) ) { |
|
| 854 | - return load_textdomain( $domain, WP_LANG_DIR . '/themes/' . $mofile ); |
|
| 853 | + if (in_array(WP_LANG_DIR.'/themes/'.$mofile, $cached_mofiles)) { |
|
| 854 | + return load_textdomain($domain, WP_LANG_DIR.'/themes/'.$mofile); |
|
| 855 | 855 | } |
| 856 | 856 | |
| 857 | 857 | return false; |
@@ -869,14 +869,14 @@ discard block |
||
| 869 | 869 | * @param string $domain Text domain. Unique identifier for retrieving translated strings. |
| 870 | 870 | * @return Translations|NOOP_Translations A Translations instance. |
| 871 | 871 | */ |
| 872 | -function get_translations_for_domain( $domain ) { |
|
| 872 | +function get_translations_for_domain($domain) { |
|
| 873 | 873 | global $l10n; |
| 874 | - if ( isset( $l10n[ $domain ] ) || ( _load_textdomain_just_in_time( $domain ) && isset( $l10n[ $domain ] ) ) ) { |
|
| 875 | - return $l10n[ $domain ]; |
|
| 874 | + if (isset($l10n[$domain]) || (_load_textdomain_just_in_time($domain) && isset($l10n[$domain]))) { |
|
| 875 | + return $l10n[$domain]; |
|
| 876 | 876 | } |
| 877 | 877 | |
| 878 | 878 | static $noop_translations = null; |
| 879 | - if ( null === $noop_translations ) { |
|
| 879 | + if (null === $noop_translations) { |
|
| 880 | 880 | $noop_translations = new NOOP_Translations; |
| 881 | 881 | } |
| 882 | 882 | |
@@ -893,9 +893,9 @@ discard block |
||
| 893 | 893 | * @param string $domain Text domain. Unique identifier for retrieving translated strings. |
| 894 | 894 | * @return bool Whether there are translations. |
| 895 | 895 | */ |
| 896 | -function is_textdomain_loaded( $domain ) { |
|
| 896 | +function is_textdomain_loaded($domain) { |
|
| 897 | 897 | global $l10n; |
| 898 | - return isset( $l10n[ $domain ] ); |
|
| 898 | + return isset($l10n[$domain]); |
|
| 899 | 899 | } |
| 900 | 900 | |
| 901 | 901 | /** |
@@ -915,8 +915,8 @@ discard block |
||
| 915 | 915 | * @param string $name The role name. |
| 916 | 916 | * @return string Translated role name on success, original name on failure. |
| 917 | 917 | */ |
| 918 | -function translate_user_role( $name ) { |
|
| 919 | - return translate_with_gettext_context( before_last_bar($name), 'User role' ); |
|
| 918 | +function translate_user_role($name) { |
|
| 919 | + return translate_with_gettext_context(before_last_bar($name), 'User role'); |
|
| 920 | 920 | } |
| 921 | 921 | |
| 922 | 922 | /** |
@@ -930,15 +930,15 @@ discard block |
||
| 930 | 930 | * Default WP_LANG_DIR. |
| 931 | 931 | * @return array An array of language codes or an empty array if no languages are present. Language codes are formed by stripping the .mo extension from the language file names. |
| 932 | 932 | */ |
| 933 | -function get_available_languages( $dir = null ) { |
|
| 933 | +function get_available_languages($dir = null) { |
|
| 934 | 934 | $languages = array(); |
| 935 | 935 | |
| 936 | - $lang_files = glob( ( is_null( $dir) ? WP_LANG_DIR : $dir ) . '/*.mo' ); |
|
| 937 | - if ( $lang_files ) { |
|
| 938 | - foreach ( $lang_files as $lang_file ) { |
|
| 939 | - $lang_file = basename( $lang_file, '.mo' ); |
|
| 940 | - if ( 0 !== strpos( $lang_file, 'continents-cities' ) && 0 !== strpos( $lang_file, 'ms-' ) && |
|
| 941 | - 0 !== strpos( $lang_file, 'admin-' ) ) { |
|
| 936 | + $lang_files = glob((is_null($dir) ? WP_LANG_DIR : $dir).'/*.mo'); |
|
| 937 | + if ($lang_files) { |
|
| 938 | + foreach ($lang_files as $lang_file) { |
|
| 939 | + $lang_file = basename($lang_file, '.mo'); |
|
| 940 | + if (0 !== strpos($lang_file, 'continents-cities') && 0 !== strpos($lang_file, 'ms-') && |
|
| 941 | + 0 !== strpos($lang_file, 'admin-')) { |
|
| 942 | 942 | $languages[] = $lang_file; |
| 943 | 943 | } |
| 944 | 944 | } |
@@ -958,43 +958,43 @@ discard block |
||
| 958 | 958 | * @param string $type What to search for. Accepts 'plugins', 'themes', 'core'. |
| 959 | 959 | * @return array Array of language data. |
| 960 | 960 | */ |
| 961 | -function wp_get_installed_translations( $type ) { |
|
| 962 | - if ( $type !== 'themes' && $type !== 'plugins' && $type !== 'core' ) |
|
| 961 | +function wp_get_installed_translations($type) { |
|
| 962 | + if ($type !== 'themes' && $type !== 'plugins' && $type !== 'core') |
|
| 963 | 963 | return array(); |
| 964 | 964 | |
| 965 | 965 | $dir = 'core' === $type ? '' : "/$type"; |
| 966 | 966 | |
| 967 | - if ( ! is_dir( WP_LANG_DIR ) ) |
|
| 967 | + if ( ! is_dir(WP_LANG_DIR)) |
|
| 968 | 968 | return array(); |
| 969 | 969 | |
| 970 | - if ( $dir && ! is_dir( WP_LANG_DIR . $dir ) ) |
|
| 970 | + if ($dir && ! is_dir(WP_LANG_DIR.$dir)) |
|
| 971 | 971 | return array(); |
| 972 | 972 | |
| 973 | - $files = scandir( WP_LANG_DIR . $dir ); |
|
| 974 | - if ( ! $files ) |
|
| 973 | + $files = scandir(WP_LANG_DIR.$dir); |
|
| 974 | + if ( ! $files) |
|
| 975 | 975 | return array(); |
| 976 | 976 | |
| 977 | 977 | $language_data = array(); |
| 978 | 978 | |
| 979 | - foreach ( $files as $file ) { |
|
| 980 | - if ( '.' === $file[0] || is_dir( WP_LANG_DIR . "$dir/$file" ) ) { |
|
| 979 | + foreach ($files as $file) { |
|
| 980 | + if ('.' === $file[0] || is_dir(WP_LANG_DIR."$dir/$file")) { |
|
| 981 | 981 | continue; |
| 982 | 982 | } |
| 983 | - if ( substr( $file, -3 ) !== '.po' ) { |
|
| 983 | + if (substr($file, -3) !== '.po') { |
|
| 984 | 984 | continue; |
| 985 | 985 | } |
| 986 | - if ( ! preg_match( '/(?:(.+)-)?([a-z]{2,3}(?:_[A-Z]{2})?(?:_[a-z0-9]+)?).po/', $file, $match ) ) { |
|
| 986 | + if ( ! preg_match('/(?:(.+)-)?([a-z]{2,3}(?:_[A-Z]{2})?(?:_[a-z0-9]+)?).po/', $file, $match)) { |
|
| 987 | 987 | continue; |
| 988 | 988 | } |
| 989 | - if ( ! in_array( substr( $file, 0, -3 ) . '.mo', $files ) ) { |
|
| 989 | + if ( ! in_array(substr($file, 0, -3).'.mo', $files)) { |
|
| 990 | 990 | continue; |
| 991 | 991 | } |
| 992 | 992 | |
| 993 | - list( , $textdomain, $language ) = $match; |
|
| 994 | - if ( '' === $textdomain ) { |
|
| 993 | + list(, $textdomain, $language) = $match; |
|
| 994 | + if ('' === $textdomain) { |
|
| 995 | 995 | $textdomain = 'default'; |
| 996 | 996 | } |
| 997 | - $language_data[ $textdomain ][ $language ] = wp_get_pomo_file_data( WP_LANG_DIR . "$dir/$file" ); |
|
| 997 | + $language_data[$textdomain][$language] = wp_get_pomo_file_data(WP_LANG_DIR."$dir/$file"); |
|
| 998 | 998 | } |
| 999 | 999 | return $language_data; |
| 1000 | 1000 | } |
@@ -1007,16 +1007,16 @@ discard block |
||
| 1007 | 1007 | * @param string $po_file Path to PO file. |
| 1008 | 1008 | * @return array PO file headers. |
| 1009 | 1009 | */ |
| 1010 | -function wp_get_pomo_file_data( $po_file ) { |
|
| 1011 | - $headers = get_file_data( $po_file, array( |
|
| 1010 | +function wp_get_pomo_file_data($po_file) { |
|
| 1011 | + $headers = get_file_data($po_file, array( |
|
| 1012 | 1012 | 'POT-Creation-Date' => '"POT-Creation-Date', |
| 1013 | 1013 | 'PO-Revision-Date' => '"PO-Revision-Date', |
| 1014 | 1014 | 'Project-Id-Version' => '"Project-Id-Version', |
| 1015 | 1015 | 'X-Generator' => '"X-Generator', |
| 1016 | - ) ); |
|
| 1017 | - foreach ( $headers as $header => $value ) { |
|
| 1016 | + )); |
|
| 1017 | + foreach ($headers as $header => $value) { |
|
| 1018 | 1018 | // Remove possible contextual '\n' and closing double quote. |
| 1019 | - $headers[ $header ] = preg_replace( '~(\\\n)?"$~', '', $value ); |
|
| 1019 | + $headers[$header] = preg_replace('~(\\\n)?"$~', '', $value); |
|
| 1020 | 1020 | } |
| 1021 | 1021 | return $headers; |
| 1022 | 1022 | } |
@@ -1046,9 +1046,9 @@ discard block |
||
| 1046 | 1046 | * } |
| 1047 | 1047 | * @return string HTML content |
| 1048 | 1048 | */ |
| 1049 | -function wp_dropdown_languages( $args = array() ) { |
|
| 1049 | +function wp_dropdown_languages($args = array()) { |
|
| 1050 | 1050 | |
| 1051 | - $args = wp_parse_args( $args, array( |
|
| 1051 | + $args = wp_parse_args($args, array( |
|
| 1052 | 1052 | 'id' => '', |
| 1053 | 1053 | 'name' => '', |
| 1054 | 1054 | 'languages' => array(), |
@@ -1056,11 +1056,11 @@ discard block |
||
| 1056 | 1056 | 'selected' => '', |
| 1057 | 1057 | 'echo' => 1, |
| 1058 | 1058 | 'show_available_translations' => true, |
| 1059 | - ) ); |
|
| 1059 | + )); |
|
| 1060 | 1060 | |
| 1061 | 1061 | $translations = $args['translations']; |
| 1062 | - if ( empty( $translations ) ) { |
|
| 1063 | - require_once( ABSPATH . 'wp-admin/includes/translation-install.php' ); |
|
| 1062 | + if (empty($translations)) { |
|
| 1063 | + require_once(ABSPATH.'wp-admin/includes/translation-install.php'); |
|
| 1064 | 1064 | $translations = wp_get_available_translations(); |
| 1065 | 1065 | } |
| 1066 | 1066 | |
@@ -1069,17 +1069,17 @@ discard block |
||
| 1069 | 1069 | * $translations to get the native name. Fall back to locale. |
| 1070 | 1070 | */ |
| 1071 | 1071 | $languages = array(); |
| 1072 | - foreach ( $args['languages'] as $locale ) { |
|
| 1073 | - if ( isset( $translations[ $locale ] ) ) { |
|
| 1074 | - $translation = $translations[ $locale ]; |
|
| 1072 | + foreach ($args['languages'] as $locale) { |
|
| 1073 | + if (isset($translations[$locale])) { |
|
| 1074 | + $translation = $translations[$locale]; |
|
| 1075 | 1075 | $languages[] = array( |
| 1076 | 1076 | 'language' => $translation['language'], |
| 1077 | 1077 | 'native_name' => $translation['native_name'], |
| 1078 | - 'lang' => current( $translation['iso'] ), |
|
| 1078 | + 'lang' => current($translation['iso']), |
|
| 1079 | 1079 | ); |
| 1080 | 1080 | |
| 1081 | 1081 | // Remove installed language from available translations. |
| 1082 | - unset( $translations[ $locale ] ); |
|
| 1082 | + unset($translations[$locale]); |
|
| 1083 | 1083 | } else { |
| 1084 | 1084 | $languages[] = array( |
| 1085 | 1085 | 'language' => $locale, |
@@ -1089,51 +1089,51 @@ discard block |
||
| 1089 | 1089 | } |
| 1090 | 1090 | } |
| 1091 | 1091 | |
| 1092 | - $translations_available = ( ! empty( $translations ) && $args['show_available_translations'] ); |
|
| 1092 | + $translations_available = ( ! empty($translations) && $args['show_available_translations']); |
|
| 1093 | 1093 | |
| 1094 | - $output = sprintf( '<select name="%s" id="%s">', esc_attr( $args['name'] ), esc_attr( $args['id'] ) ); |
|
| 1094 | + $output = sprintf('<select name="%s" id="%s">', esc_attr($args['name']), esc_attr($args['id'])); |
|
| 1095 | 1095 | |
| 1096 | 1096 | // Holds the HTML markup. |
| 1097 | 1097 | $structure = array(); |
| 1098 | 1098 | |
| 1099 | 1099 | // List installed languages. |
| 1100 | - if ( $translations_available ) { |
|
| 1101 | - $structure[] = '<optgroup label="' . esc_attr_x( 'Installed', 'translations' ) . '">'; |
|
| 1100 | + if ($translations_available) { |
|
| 1101 | + $structure[] = '<optgroup label="'.esc_attr_x('Installed', 'translations').'">'; |
|
| 1102 | 1102 | } |
| 1103 | 1103 | $structure[] = '<option value="" lang="en" data-installed="1">English (United States)</option>'; |
| 1104 | - foreach ( $languages as $language ) { |
|
| 1104 | + foreach ($languages as $language) { |
|
| 1105 | 1105 | $structure[] = sprintf( |
| 1106 | 1106 | '<option value="%s" lang="%s"%s data-installed="1">%s</option>', |
| 1107 | - esc_attr( $language['language'] ), |
|
| 1108 | - esc_attr( $language['lang'] ), |
|
| 1109 | - selected( $language['language'], $args['selected'], false ), |
|
| 1110 | - esc_html( $language['native_name'] ) |
|
| 1107 | + esc_attr($language['language']), |
|
| 1108 | + esc_attr($language['lang']), |
|
| 1109 | + selected($language['language'], $args['selected'], false), |
|
| 1110 | + esc_html($language['native_name']) |
|
| 1111 | 1111 | ); |
| 1112 | 1112 | } |
| 1113 | - if ( $translations_available ) { |
|
| 1113 | + if ($translations_available) { |
|
| 1114 | 1114 | $structure[] = '</optgroup>'; |
| 1115 | 1115 | } |
| 1116 | 1116 | |
| 1117 | 1117 | // List available translations. |
| 1118 | - if ( $translations_available ) { |
|
| 1119 | - $structure[] = '<optgroup label="' . esc_attr_x( 'Available', 'translations' ) . '">'; |
|
| 1120 | - foreach ( $translations as $translation ) { |
|
| 1118 | + if ($translations_available) { |
|
| 1119 | + $structure[] = '<optgroup label="'.esc_attr_x('Available', 'translations').'">'; |
|
| 1120 | + foreach ($translations as $translation) { |
|
| 1121 | 1121 | $structure[] = sprintf( |
| 1122 | 1122 | '<option value="%s" lang="%s"%s>%s</option>', |
| 1123 | - esc_attr( $translation['language'] ), |
|
| 1124 | - esc_attr( current( $translation['iso'] ) ), |
|
| 1125 | - selected( $translation['language'], $args['selected'], false ), |
|
| 1126 | - esc_html( $translation['native_name'] ) |
|
| 1123 | + esc_attr($translation['language']), |
|
| 1124 | + esc_attr(current($translation['iso'])), |
|
| 1125 | + selected($translation['language'], $args['selected'], false), |
|
| 1126 | + esc_html($translation['native_name']) |
|
| 1127 | 1127 | ); |
| 1128 | 1128 | } |
| 1129 | 1129 | $structure[] = '</optgroup>'; |
| 1130 | 1130 | } |
| 1131 | 1131 | |
| 1132 | - $output .= join( "\n", $structure ); |
|
| 1132 | + $output .= join("\n", $structure); |
|
| 1133 | 1133 | |
| 1134 | 1134 | $output .= '</select>'; |
| 1135 | 1135 | |
| 1136 | - if ( $args['echo'] ) { |
|
| 1136 | + if ($args['echo']) { |
|
| 1137 | 1137 | echo $output; |
| 1138 | 1138 | } |
| 1139 | 1139 | |
@@ -198,19 +198,19 @@ discard block |
||
| 198 | 198 | * @param string $theme_root Theme root. |
| 199 | 199 | * @param WP_Error|void $_child If this theme is a parent theme, the child may be passed for validation purposes. |
| 200 | 200 | */ |
| 201 | - public function __construct( $theme_dir, $theme_root, $_child = null ) { |
|
| 201 | + public function __construct($theme_dir, $theme_root, $_child = null) { |
|
| 202 | 202 | global $wp_theme_directories; |
| 203 | 203 | |
| 204 | 204 | // Initialize caching on first run. |
| 205 | - if ( ! isset( self::$persistently_cache ) ) { |
|
| 205 | + if ( ! isset(self::$persistently_cache)) { |
|
| 206 | 206 | /** This action is documented in wp-includes/theme.php */ |
| 207 | - self::$persistently_cache = apply_filters( 'wp_cache_themes_persistently', false, 'WP_Theme' ); |
|
| 208 | - if ( self::$persistently_cache ) { |
|
| 209 | - wp_cache_add_global_groups( 'themes' ); |
|
| 210 | - if ( is_int( self::$persistently_cache ) ) |
|
| 207 | + self::$persistently_cache = apply_filters('wp_cache_themes_persistently', false, 'WP_Theme'); |
|
| 208 | + if (self::$persistently_cache) { |
|
| 209 | + wp_cache_add_global_groups('themes'); |
|
| 210 | + if (is_int(self::$persistently_cache)) |
|
| 211 | 211 | self::$cache_expiration = self::$persistently_cache; |
| 212 | 212 | } else { |
| 213 | - wp_cache_add_non_persistent_groups( 'themes' ); |
|
| 213 | + wp_cache_add_non_persistent_groups('themes'); |
|
| 214 | 214 | } |
| 215 | 215 | } |
| 216 | 216 | |
@@ -218,114 +218,114 @@ discard block |
||
| 218 | 218 | $this->stylesheet = $theme_dir; |
| 219 | 219 | |
| 220 | 220 | // Correct a situation where the theme is 'some-directory/some-theme' but 'some-directory' was passed in as part of the theme root instead. |
| 221 | - if ( ! in_array( $theme_root, (array) $wp_theme_directories ) && in_array( dirname( $theme_root ), (array) $wp_theme_directories ) ) { |
|
| 222 | - $this->stylesheet = basename( $this->theme_root ) . '/' . $this->stylesheet; |
|
| 223 | - $this->theme_root = dirname( $theme_root ); |
|
| 221 | + if ( ! in_array($theme_root, (array) $wp_theme_directories) && in_array(dirname($theme_root), (array) $wp_theme_directories)) { |
|
| 222 | + $this->stylesheet = basename($this->theme_root).'/'.$this->stylesheet; |
|
| 223 | + $this->theme_root = dirname($theme_root); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - $this->cache_hash = md5( $this->theme_root . '/' . $this->stylesheet ); |
|
| 227 | - $theme_file = $this->stylesheet . '/style.css'; |
|
| 226 | + $this->cache_hash = md5($this->theme_root.'/'.$this->stylesheet); |
|
| 227 | + $theme_file = $this->stylesheet.'/style.css'; |
|
| 228 | 228 | |
| 229 | - $cache = $this->cache_get( 'theme' ); |
|
| 229 | + $cache = $this->cache_get('theme'); |
|
| 230 | 230 | |
| 231 | - if ( is_array( $cache ) ) { |
|
| 232 | - foreach ( array( 'errors', 'headers', 'template' ) as $key ) { |
|
| 233 | - if ( isset( $cache[ $key ] ) ) |
|
| 234 | - $this->$key = $cache[ $key ]; |
|
| 231 | + if (is_array($cache)) { |
|
| 232 | + foreach (array('errors', 'headers', 'template') as $key) { |
|
| 233 | + if (isset($cache[$key])) |
|
| 234 | + $this->$key = $cache[$key]; |
|
| 235 | 235 | } |
| 236 | - if ( $this->errors ) |
|
| 236 | + if ($this->errors) |
|
| 237 | 237 | return; |
| 238 | - if ( isset( $cache['theme_root_template'] ) ) |
|
| 238 | + if (isset($cache['theme_root_template'])) |
|
| 239 | 239 | $theme_root_template = $cache['theme_root_template']; |
| 240 | - } elseif ( ! file_exists( $this->theme_root . '/' . $theme_file ) ) { |
|
| 240 | + } elseif ( ! file_exists($this->theme_root.'/'.$theme_file)) { |
|
| 241 | 241 | $this->headers['Name'] = $this->stylesheet; |
| 242 | - if ( ! file_exists( $this->theme_root . '/' . $this->stylesheet ) ) |
|
| 243 | - $this->errors = new WP_Error( 'theme_not_found', sprintf( __( 'The theme directory "%s" does not exist.' ), esc_html( $this->stylesheet ) ) ); |
|
| 242 | + if ( ! file_exists($this->theme_root.'/'.$this->stylesheet)) |
|
| 243 | + $this->errors = new WP_Error('theme_not_found', sprintf(__('The theme directory "%s" does not exist.'), esc_html($this->stylesheet))); |
|
| 244 | 244 | else |
| 245 | - $this->errors = new WP_Error( 'theme_no_stylesheet', __( 'Stylesheet is missing.' ) ); |
|
| 245 | + $this->errors = new WP_Error('theme_no_stylesheet', __('Stylesheet is missing.')); |
|
| 246 | 246 | $this->template = $this->stylesheet; |
| 247 | - $this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) ); |
|
| 248 | - if ( ! file_exists( $this->theme_root ) ) // Don't cache this one. |
|
| 249 | - $this->errors->add( 'theme_root_missing', __( 'ERROR: The themes directory is either empty or doesn’t exist. Please check your installation.' ) ); |
|
| 247 | + $this->cache_add('theme', array('headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template)); |
|
| 248 | + if ( ! file_exists($this->theme_root)) // Don't cache this one. |
|
| 249 | + $this->errors->add('theme_root_missing', __('ERROR: The themes directory is either empty or doesn’t exist. Please check your installation.')); |
|
| 250 | 250 | return; |
| 251 | - } elseif ( ! is_readable( $this->theme_root . '/' . $theme_file ) ) { |
|
| 251 | + } elseif ( ! is_readable($this->theme_root.'/'.$theme_file)) { |
|
| 252 | 252 | $this->headers['Name'] = $this->stylesheet; |
| 253 | - $this->errors = new WP_Error( 'theme_stylesheet_not_readable', __( 'Stylesheet is not readable.' ) ); |
|
| 253 | + $this->errors = new WP_Error('theme_stylesheet_not_readable', __('Stylesheet is not readable.')); |
|
| 254 | 254 | $this->template = $this->stylesheet; |
| 255 | - $this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) ); |
|
| 255 | + $this->cache_add('theme', array('headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template)); |
|
| 256 | 256 | return; |
| 257 | 257 | } else { |
| 258 | - $this->headers = get_file_data( $this->theme_root . '/' . $theme_file, self::$file_headers, 'theme' ); |
|
| 258 | + $this->headers = get_file_data($this->theme_root.'/'.$theme_file, self::$file_headers, 'theme'); |
|
| 259 | 259 | // Default themes always trump their pretenders. |
| 260 | 260 | // Properly identify default themes that are inside a directory within wp-content/themes. |
| 261 | - if ( $default_theme_slug = array_search( $this->headers['Name'], self::$default_themes ) ) { |
|
| 262 | - if ( basename( $this->stylesheet ) != $default_theme_slug ) |
|
| 263 | - $this->headers['Name'] .= '/' . $this->stylesheet; |
|
| 261 | + if ($default_theme_slug = array_search($this->headers['Name'], self::$default_themes)) { |
|
| 262 | + if (basename($this->stylesheet) != $default_theme_slug) |
|
| 263 | + $this->headers['Name'] .= '/'.$this->stylesheet; |
|
| 264 | 264 | } |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | // (If template is set from cache [and there are no errors], we know it's good.) |
| 268 | - if ( ! $this->template && ! ( $this->template = $this->headers['Template'] ) ) { |
|
| 268 | + if ( ! $this->template && ! ($this->template = $this->headers['Template'])) { |
|
| 269 | 269 | $this->template = $this->stylesheet; |
| 270 | - if ( ! file_exists( $this->theme_root . '/' . $this->stylesheet . '/index.php' ) ) { |
|
| 270 | + if ( ! file_exists($this->theme_root.'/'.$this->stylesheet.'/index.php')) { |
|
| 271 | 271 | $error_message = sprintf( |
| 272 | 272 | /* translators: 1: index.php, 2: Codex URL, 3: style.css */ |
| 273 | - __( 'Template is missing. Standalone themes need to have a %1$s template file. <a href="%2$s">Child themes</a> need to have a Template header in the %3$s stylesheet.' ), |
|
| 273 | + __('Template is missing. Standalone themes need to have a %1$s template file. <a href="%2$s">Child themes</a> need to have a Template header in the %3$s stylesheet.'), |
|
| 274 | 274 | '<code>index.php</code>', |
| 275 | - __( 'https://codex.wordpress.org/Child_Themes' ), |
|
| 275 | + __('https://codex.wordpress.org/Child_Themes'), |
|
| 276 | 276 | '<code>style.css</code>' |
| 277 | 277 | ); |
| 278 | - $this->errors = new WP_Error( 'theme_no_index', $error_message ); |
|
| 279 | - $this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) ); |
|
| 278 | + $this->errors = new WP_Error('theme_no_index', $error_message); |
|
| 279 | + $this->cache_add('theme', array('headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template)); |
|
| 280 | 280 | return; |
| 281 | 281 | } |
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | // If we got our data from cache, we can assume that 'template' is pointing to the right place. |
| 285 | - if ( ! is_array( $cache ) && $this->template != $this->stylesheet && ! file_exists( $this->theme_root . '/' . $this->template . '/index.php' ) ) { |
|
| 285 | + if ( ! is_array($cache) && $this->template != $this->stylesheet && ! file_exists($this->theme_root.'/'.$this->template.'/index.php')) { |
|
| 286 | 286 | // If we're in a directory of themes inside /themes, look for the parent nearby. |
| 287 | 287 | // wp-content/themes/directory-of-themes/* |
| 288 | - $parent_dir = dirname( $this->stylesheet ); |
|
| 289 | - if ( '.' != $parent_dir && file_exists( $this->theme_root . '/' . $parent_dir . '/' . $this->template . '/index.php' ) ) { |
|
| 290 | - $this->template = $parent_dir . '/' . $this->template; |
|
| 291 | - } elseif ( ( $directories = search_theme_directories() ) && isset( $directories[ $this->template ] ) ) { |
|
| 288 | + $parent_dir = dirname($this->stylesheet); |
|
| 289 | + if ('.' != $parent_dir && file_exists($this->theme_root.'/'.$parent_dir.'/'.$this->template.'/index.php')) { |
|
| 290 | + $this->template = $parent_dir.'/'.$this->template; |
|
| 291 | + } elseif (($directories = search_theme_directories()) && isset($directories[$this->template])) { |
|
| 292 | 292 | // Look for the template in the search_theme_directories() results, in case it is in another theme root. |
| 293 | 293 | // We don't look into directories of themes, just the theme root. |
| 294 | - $theme_root_template = $directories[ $this->template ]['theme_root']; |
|
| 294 | + $theme_root_template = $directories[$this->template]['theme_root']; |
|
| 295 | 295 | } else { |
| 296 | 296 | // Parent theme is missing. |
| 297 | - $this->errors = new WP_Error( 'theme_no_parent', sprintf( __( 'The parent theme is missing. Please install the "%s" parent theme.' ), esc_html( $this->template ) ) ); |
|
| 298 | - $this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) ); |
|
| 299 | - $this->parent = new WP_Theme( $this->template, $this->theme_root, $this ); |
|
| 297 | + $this->errors = new WP_Error('theme_no_parent', sprintf(__('The parent theme is missing. Please install the "%s" parent theme.'), esc_html($this->template))); |
|
| 298 | + $this->cache_add('theme', array('headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template)); |
|
| 299 | + $this->parent = new WP_Theme($this->template, $this->theme_root, $this); |
|
| 300 | 300 | return; |
| 301 | 301 | } |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | // Set the parent, if we're a child theme. |
| 305 | - if ( $this->template != $this->stylesheet ) { |
|
| 305 | + if ($this->template != $this->stylesheet) { |
|
| 306 | 306 | // If we are a parent, then there is a problem. Only two generations allowed! Cancel things out. |
| 307 | - if ( $_child instanceof WP_Theme && $_child->template == $this->stylesheet ) { |
|
| 307 | + if ($_child instanceof WP_Theme && $_child->template == $this->stylesheet) { |
|
| 308 | 308 | $_child->parent = null; |
| 309 | - $_child->errors = new WP_Error( 'theme_parent_invalid', sprintf( __( 'The "%s" theme is not a valid parent theme.' ), esc_html( $_child->template ) ) ); |
|
| 310 | - $_child->cache_add( 'theme', array( 'headers' => $_child->headers, 'errors' => $_child->errors, 'stylesheet' => $_child->stylesheet, 'template' => $_child->template ) ); |
|
| 309 | + $_child->errors = new WP_Error('theme_parent_invalid', sprintf(__('The "%s" theme is not a valid parent theme.'), esc_html($_child->template))); |
|
| 310 | + $_child->cache_add('theme', array('headers' => $_child->headers, 'errors' => $_child->errors, 'stylesheet' => $_child->stylesheet, 'template' => $_child->template)); |
|
| 311 | 311 | // The two themes actually reference each other with the Template header. |
| 312 | - if ( $_child->stylesheet == $this->template ) { |
|
| 313 | - $this->errors = new WP_Error( 'theme_parent_invalid', sprintf( __( 'The "%s" theme is not a valid parent theme.' ), esc_html( $this->template ) ) ); |
|
| 314 | - $this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) ); |
|
| 312 | + if ($_child->stylesheet == $this->template) { |
|
| 313 | + $this->errors = new WP_Error('theme_parent_invalid', sprintf(__('The "%s" theme is not a valid parent theme.'), esc_html($this->template))); |
|
| 314 | + $this->cache_add('theme', array('headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template)); |
|
| 315 | 315 | } |
| 316 | 316 | return; |
| 317 | 317 | } |
| 318 | 318 | // Set the parent. Pass the current instance so we can do the crazy checks above and assess errors. |
| 319 | - $this->parent = new WP_Theme( $this->template, isset( $theme_root_template ) ? $theme_root_template : $this->theme_root, $this ); |
|
| 319 | + $this->parent = new WP_Theme($this->template, isset($theme_root_template) ? $theme_root_template : $this->theme_root, $this); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | // We're good. If we didn't retrieve from cache, set it. |
| 323 | - if ( ! is_array( $cache ) ) { |
|
| 324 | - $cache = array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ); |
|
| 323 | + if ( ! is_array($cache)) { |
|
| 324 | + $cache = array('headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template); |
|
| 325 | 325 | // If the parent theme is in another root, we'll want to cache this. Avoids an entire branch of filesystem calls above. |
| 326 | - if ( isset( $theme_root_template ) ) |
|
| 326 | + if (isset($theme_root_template)) |
|
| 327 | 327 | $cache['theme_root_template'] = $theme_root_template; |
| 328 | - $this->cache_add( 'theme', $cache ); |
|
| 328 | + $this->cache_add('theme', $cache); |
|
| 329 | 329 | } |
| 330 | 330 | } |
| 331 | 331 | |
@@ -346,13 +346,13 @@ discard block |
||
| 346 | 346 | * @param string $offset Property to check if set. |
| 347 | 347 | * @return bool Whether the given property is set. |
| 348 | 348 | */ |
| 349 | - public function __isset( $offset ) { |
|
| 349 | + public function __isset($offset) { |
|
| 350 | 350 | static $properties = array( |
| 351 | 351 | 'name', 'title', 'version', 'parent_theme', 'template_dir', 'stylesheet_dir', 'template', 'stylesheet', |
| 352 | 352 | 'screenshot', 'description', 'author', 'tags', 'theme_root', 'theme_root_uri', |
| 353 | 353 | ); |
| 354 | 354 | |
| 355 | - return in_array( $offset, $properties ); |
|
| 355 | + return in_array($offset, $properties); |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | /** |
@@ -361,8 +361,8 @@ discard block |
||
| 361 | 361 | * @param string $offset Property to get. |
| 362 | 362 | * @return mixed Property value. |
| 363 | 363 | */ |
| 364 | - public function __get( $offset ) { |
|
| 365 | - switch ( $offset ) { |
|
| 364 | + public function __get($offset) { |
|
| 365 | + switch ($offset) { |
|
| 366 | 366 | case 'name' : |
| 367 | 367 | case 'title' : |
| 368 | 368 | return $this->get('Name'); |
@@ -379,21 +379,21 @@ discard block |
||
| 379 | 379 | case 'stylesheet' : |
| 380 | 380 | return $this->get_stylesheet(); |
| 381 | 381 | case 'screenshot' : |
| 382 | - return $this->get_screenshot( 'relative' ); |
|
| 382 | + return $this->get_screenshot('relative'); |
|
| 383 | 383 | // 'author' and 'description' did not previously return translated data. |
| 384 | 384 | case 'description' : |
| 385 | 385 | return $this->display('Description'); |
| 386 | 386 | case 'author' : |
| 387 | 387 | return $this->display('Author'); |
| 388 | 388 | case 'tags' : |
| 389 | - return $this->get( 'Tags' ); |
|
| 389 | + return $this->get('Tags'); |
|
| 390 | 390 | case 'theme_root' : |
| 391 | 391 | return $this->get_theme_root(); |
| 392 | 392 | case 'theme_root_uri' : |
| 393 | 393 | return $this->get_theme_root_uri(); |
| 394 | 394 | // For cases where the array was converted to an object. |
| 395 | 395 | default : |
| 396 | - return $this->offsetGet( $offset ); |
|
| 396 | + return $this->offsetGet($offset); |
|
| 397 | 397 | } |
| 398 | 398 | } |
| 399 | 399 | |
@@ -403,14 +403,14 @@ discard block |
||
| 403 | 403 | * @param mixed $offset |
| 404 | 404 | * @param mixed $value |
| 405 | 405 | */ |
| 406 | - public function offsetSet( $offset, $value ) {} |
|
| 406 | + public function offsetSet($offset, $value) {} |
|
| 407 | 407 | |
| 408 | 408 | /** |
| 409 | 409 | * Method to implement ArrayAccess for keys formerly returned by get_themes() |
| 410 | 410 | * |
| 411 | 411 | * @param mixed $offset |
| 412 | 412 | */ |
| 413 | - public function offsetUnset( $offset ) {} |
|
| 413 | + public function offsetUnset($offset) {} |
|
| 414 | 414 | |
| 415 | 415 | /** |
| 416 | 416 | * Method to implement ArrayAccess for keys formerly returned by get_themes() |
@@ -420,14 +420,14 @@ discard block |
||
| 420 | 420 | * @param mixed $offset |
| 421 | 421 | * @return bool |
| 422 | 422 | */ |
| 423 | - public function offsetExists( $offset ) { |
|
| 423 | + public function offsetExists($offset) { |
|
| 424 | 424 | static $keys = array( |
| 425 | 425 | 'Name', 'Version', 'Status', 'Title', 'Author', 'Author Name', 'Author URI', 'Description', |
| 426 | 426 | 'Template', 'Stylesheet', 'Template Files', 'Stylesheet Files', 'Template Dir', 'Stylesheet Dir', |
| 427 | 427 | 'Screenshot', 'Tags', 'Theme Root', 'Theme Root URI', 'Parent Theme', |
| 428 | 428 | ); |
| 429 | 429 | |
| 430 | - return in_array( $offset, $keys ); |
|
| 430 | + return in_array($offset, $keys); |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | /** |
@@ -443,8 +443,8 @@ discard block |
||
| 443 | 443 | * @param mixed $offset |
| 444 | 444 | * @return mixed |
| 445 | 445 | */ |
| 446 | - public function offsetGet( $offset ) { |
|
| 447 | - switch ( $offset ) { |
|
| 446 | + public function offsetGet($offset) { |
|
| 447 | + switch ($offset) { |
|
| 448 | 448 | case 'Name' : |
| 449 | 449 | case 'Title' : |
| 450 | 450 | /* |
@@ -453,30 +453,30 @@ discard block |
||
| 453 | 453 | */ |
| 454 | 454 | return $this->get('Name'); |
| 455 | 455 | case 'Author' : |
| 456 | - return $this->display( 'Author'); |
|
| 456 | + return $this->display('Author'); |
|
| 457 | 457 | case 'Author Name' : |
| 458 | - return $this->display( 'Author', false); |
|
| 458 | + return $this->display('Author', false); |
|
| 459 | 459 | case 'Author URI' : |
| 460 | 460 | return $this->display('AuthorURI'); |
| 461 | 461 | case 'Description' : |
| 462 | - return $this->display( 'Description'); |
|
| 462 | + return $this->display('Description'); |
|
| 463 | 463 | case 'Version' : |
| 464 | 464 | case 'Status' : |
| 465 | - return $this->get( $offset ); |
|
| 465 | + return $this->get($offset); |
|
| 466 | 466 | case 'Template' : |
| 467 | 467 | return $this->get_template(); |
| 468 | 468 | case 'Stylesheet' : |
| 469 | 469 | return $this->get_stylesheet(); |
| 470 | 470 | case 'Template Files' : |
| 471 | - return $this->get_files( 'php', 1, true ); |
|
| 471 | + return $this->get_files('php', 1, true); |
|
| 472 | 472 | case 'Stylesheet Files' : |
| 473 | - return $this->get_files( 'css', 0, false ); |
|
| 473 | + return $this->get_files('css', 0, false); |
|
| 474 | 474 | case 'Template Dir' : |
| 475 | 475 | return $this->get_template_directory(); |
| 476 | 476 | case 'Stylesheet Dir' : |
| 477 | 477 | return $this->get_stylesheet_directory(); |
| 478 | 478 | case 'Screenshot' : |
| 479 | - return $this->get_screenshot( 'relative' ); |
|
| 479 | + return $this->get_screenshot('relative'); |
|
| 480 | 480 | case 'Tags' : |
| 481 | 481 | return $this->get('Tags'); |
| 482 | 482 | case 'Theme Root' : |
@@ -499,7 +499,7 @@ discard block |
||
| 499 | 499 | * @return WP_Error|false WP_Error if there are errors, or false. |
| 500 | 500 | */ |
| 501 | 501 | public function errors() { |
| 502 | - return is_wp_error( $this->errors ) ? $this->errors : false; |
|
| 502 | + return is_wp_error($this->errors) ? $this->errors : false; |
|
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | /** |
@@ -514,7 +514,7 @@ discard block |
||
| 514 | 514 | * @return bool Whether the theme exists. |
| 515 | 515 | */ |
| 516 | 516 | public function exists() { |
| 517 | - return ! ( $this->errors() && in_array( 'theme_not_found', $this->errors()->get_error_codes() ) ); |
|
| 517 | + return ! ($this->errors() && in_array('theme_not_found', $this->errors()->get_error_codes())); |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | /** |
@@ -526,7 +526,7 @@ discard block |
||
| 526 | 526 | * @return WP_Theme|false Parent theme, or false if the current theme is not a child theme. |
| 527 | 527 | */ |
| 528 | 528 | public function parent() { |
| 529 | - return isset( $this->parent ) ? $this->parent : false; |
|
| 529 | + return isset($this->parent) ? $this->parent : false; |
|
| 530 | 530 | } |
| 531 | 531 | |
| 532 | 532 | /** |
@@ -541,8 +541,8 @@ discard block |
||
| 541 | 541 | * @param string $data Data to store |
| 542 | 542 | * @return bool Return value from wp_cache_add() |
| 543 | 543 | */ |
| 544 | - private function cache_add( $key, $data ) { |
|
| 545 | - return wp_cache_add( $key . '-' . $this->cache_hash, $data, 'themes', self::$cache_expiration ); |
|
| 544 | + private function cache_add($key, $data) { |
|
| 545 | + return wp_cache_add($key.'-'.$this->cache_hash, $data, 'themes', self::$cache_expiration); |
|
| 546 | 546 | } |
| 547 | 547 | |
| 548 | 548 | /** |
@@ -556,8 +556,8 @@ discard block |
||
| 556 | 556 | * @param string $key Type of data to retrieve (theme, screenshot, headers, page_templates) |
| 557 | 557 | * @return mixed Retrieved data |
| 558 | 558 | */ |
| 559 | - private function cache_get( $key ) { |
|
| 560 | - return wp_cache_get( $key . '-' . $this->cache_hash, 'themes' ); |
|
| 559 | + private function cache_get($key) { |
|
| 560 | + return wp_cache_get($key.'-'.$this->cache_hash, 'themes'); |
|
| 561 | 561 | } |
| 562 | 562 | |
| 563 | 563 | /** |
@@ -567,11 +567,11 @@ discard block |
||
| 567 | 567 | * @access public |
| 568 | 568 | */ |
| 569 | 569 | public function cache_delete() { |
| 570 | - foreach ( array( 'theme', 'screenshot', 'headers', 'page_templates' ) as $key ) |
|
| 571 | - wp_cache_delete( $key . '-' . $this->cache_hash, 'themes' ); |
|
| 570 | + foreach (array('theme', 'screenshot', 'headers', 'page_templates') as $key) |
|
| 571 | + wp_cache_delete($key.'-'.$this->cache_hash, 'themes'); |
|
| 572 | 572 | $this->template = $this->textdomain_loaded = $this->theme_root_uri = $this->parent = $this->errors = $this->headers_sanitized = $this->name_translated = null; |
| 573 | 573 | $this->headers = array(); |
| 574 | - $this->__construct( $this->stylesheet, $this->theme_root ); |
|
| 574 | + $this->__construct($this->stylesheet, $this->theme_root); |
|
| 575 | 575 | } |
| 576 | 576 | |
| 577 | 577 | /** |
@@ -591,29 +591,29 @@ discard block |
||
| 591 | 591 | * @param string $header Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags. |
| 592 | 592 | * @return string|false String on success, false on failure. |
| 593 | 593 | */ |
| 594 | - public function get( $header ) { |
|
| 595 | - if ( ! isset( $this->headers[ $header ] ) ) |
|
| 594 | + public function get($header) { |
|
| 595 | + if ( ! isset($this->headers[$header])) |
|
| 596 | 596 | return false; |
| 597 | 597 | |
| 598 | - if ( ! isset( $this->headers_sanitized ) ) { |
|
| 599 | - $this->headers_sanitized = $this->cache_get( 'headers' ); |
|
| 600 | - if ( ! is_array( $this->headers_sanitized ) ) |
|
| 598 | + if ( ! isset($this->headers_sanitized)) { |
|
| 599 | + $this->headers_sanitized = $this->cache_get('headers'); |
|
| 600 | + if ( ! is_array($this->headers_sanitized)) |
|
| 601 | 601 | $this->headers_sanitized = array(); |
| 602 | 602 | } |
| 603 | 603 | |
| 604 | - if ( isset( $this->headers_sanitized[ $header ] ) ) |
|
| 605 | - return $this->headers_sanitized[ $header ]; |
|
| 604 | + if (isset($this->headers_sanitized[$header])) |
|
| 605 | + return $this->headers_sanitized[$header]; |
|
| 606 | 606 | |
| 607 | 607 | // If themes are a persistent group, sanitize everything and cache it. One cache add is better than many cache sets. |
| 608 | - if ( self::$persistently_cache ) { |
|
| 609 | - foreach ( array_keys( $this->headers ) as $_header ) |
|
| 610 | - $this->headers_sanitized[ $_header ] = $this->sanitize_header( $_header, $this->headers[ $_header ] ); |
|
| 611 | - $this->cache_add( 'headers', $this->headers_sanitized ); |
|
| 608 | + if (self::$persistently_cache) { |
|
| 609 | + foreach (array_keys($this->headers) as $_header) |
|
| 610 | + $this->headers_sanitized[$_header] = $this->sanitize_header($_header, $this->headers[$_header]); |
|
| 611 | + $this->cache_add('headers', $this->headers_sanitized); |
|
| 612 | 612 | } else { |
| 613 | - $this->headers_sanitized[ $header ] = $this->sanitize_header( $header, $this->headers[ $header ] ); |
|
| 613 | + $this->headers_sanitized[$header] = $this->sanitize_header($header, $this->headers[$header]); |
|
| 614 | 614 | } |
| 615 | 615 | |
| 616 | - return $this->headers_sanitized[ $header ]; |
|
| 616 | + return $this->headers_sanitized[$header]; |
|
| 617 | 617 | } |
| 618 | 618 | |
| 619 | 619 | /** |
@@ -627,20 +627,20 @@ discard block |
||
| 627 | 627 | * @param bool $translate Optional. Whether to translate the header. Defaults to true. |
| 628 | 628 | * @return string|false Processed header, false on failure. |
| 629 | 629 | */ |
| 630 | - public function display( $header, $markup = true, $translate = true ) { |
|
| 631 | - $value = $this->get( $header ); |
|
| 632 | - if ( false === $value ) { |
|
| 630 | + public function display($header, $markup = true, $translate = true) { |
|
| 631 | + $value = $this->get($header); |
|
| 632 | + if (false === $value) { |
|
| 633 | 633 | return false; |
| 634 | 634 | } |
| 635 | 635 | |
| 636 | - if ( $translate && ( empty( $value ) || ! $this->load_textdomain() ) ) |
|
| 636 | + if ($translate && (empty($value) || ! $this->load_textdomain())) |
|
| 637 | 637 | $translate = false; |
| 638 | 638 | |
| 639 | - if ( $translate ) |
|
| 640 | - $value = $this->translate_header( $header, $value ); |
|
| 639 | + if ($translate) |
|
| 640 | + $value = $this->translate_header($header, $value); |
|
| 641 | 641 | |
| 642 | - if ( $markup ) |
|
| 643 | - $value = $this->markup_header( $header, $value, $translate ); |
|
| 642 | + if ($markup) |
|
| 643 | + $value = $this->markup_header($header, $value, $translate); |
|
| 644 | 644 | |
| 645 | 645 | return $value; |
| 646 | 646 | } |
@@ -658,46 +658,46 @@ discard block |
||
| 658 | 658 | * @param string $value Value to sanitize. |
| 659 | 659 | * @return mixed |
| 660 | 660 | */ |
| 661 | - private function sanitize_header( $header, $value ) { |
|
| 662 | - switch ( $header ) { |
|
| 661 | + private function sanitize_header($header, $value) { |
|
| 662 | + switch ($header) { |
|
| 663 | 663 | case 'Status' : |
| 664 | - if ( ! $value ) { |
|
| 664 | + if ( ! $value) { |
|
| 665 | 665 | $value = 'publish'; |
| 666 | 666 | break; |
| 667 | 667 | } |
| 668 | 668 | // Fall through otherwise. |
| 669 | 669 | case 'Name' : |
| 670 | 670 | static $header_tags = array( |
| 671 | - 'abbr' => array( 'title' => true ), |
|
| 672 | - 'acronym' => array( 'title' => true ), |
|
| 671 | + 'abbr' => array('title' => true), |
|
| 672 | + 'acronym' => array('title' => true), |
|
| 673 | 673 | 'code' => true, |
| 674 | 674 | 'em' => true, |
| 675 | 675 | 'strong' => true, |
| 676 | 676 | ); |
| 677 | - $value = wp_kses( $value, $header_tags ); |
|
| 677 | + $value = wp_kses($value, $header_tags); |
|
| 678 | 678 | break; |
| 679 | 679 | case 'Author' : |
| 680 | 680 | // There shouldn't be anchor tags in Author, but some themes like to be challenging. |
| 681 | 681 | case 'Description' : |
| 682 | 682 | static $header_tags_with_a = array( |
| 683 | - 'a' => array( 'href' => true, 'title' => true ), |
|
| 684 | - 'abbr' => array( 'title' => true ), |
|
| 685 | - 'acronym' => array( 'title' => true ), |
|
| 683 | + 'a' => array('href' => true, 'title' => true), |
|
| 684 | + 'abbr' => array('title' => true), |
|
| 685 | + 'acronym' => array('title' => true), |
|
| 686 | 686 | 'code' => true, |
| 687 | 687 | 'em' => true, |
| 688 | 688 | 'strong' => true, |
| 689 | 689 | ); |
| 690 | - $value = wp_kses( $value, $header_tags_with_a ); |
|
| 690 | + $value = wp_kses($value, $header_tags_with_a); |
|
| 691 | 691 | break; |
| 692 | 692 | case 'ThemeURI' : |
| 693 | 693 | case 'AuthorURI' : |
| 694 | - $value = esc_url_raw( $value ); |
|
| 694 | + $value = esc_url_raw($value); |
|
| 695 | 695 | break; |
| 696 | 696 | case 'Tags' : |
| 697 | - $value = array_filter( array_map( 'trim', explode( ',', strip_tags( $value ) ) ) ); |
|
| 697 | + $value = array_filter(array_map('trim', explode(',', strip_tags($value)))); |
|
| 698 | 698 | break; |
| 699 | 699 | case 'Version' : |
| 700 | - $value = strip_tags( $value ); |
|
| 700 | + $value = strip_tags($value); |
|
| 701 | 701 | break; |
| 702 | 702 | } |
| 703 | 703 | |
@@ -717,33 +717,33 @@ discard block |
||
| 717 | 717 | * @param string $translate Whether the header has been translated. |
| 718 | 718 | * @return string Value, marked up. |
| 719 | 719 | */ |
| 720 | - private function markup_header( $header, $value, $translate ) { |
|
| 721 | - switch ( $header ) { |
|
| 720 | + private function markup_header($header, $value, $translate) { |
|
| 721 | + switch ($header) { |
|
| 722 | 722 | case 'Name' : |
| 723 | - if ( empty( $value ) ) |
|
| 723 | + if (empty($value)) |
|
| 724 | 724 | $value = $this->get_stylesheet(); |
| 725 | 725 | break; |
| 726 | 726 | case 'Description' : |
| 727 | - $value = wptexturize( $value ); |
|
| 727 | + $value = wptexturize($value); |
|
| 728 | 728 | break; |
| 729 | 729 | case 'Author' : |
| 730 | - if ( $this->get('AuthorURI') ) { |
|
| 731 | - $value = sprintf( '<a href="%1$s">%2$s</a>', $this->display( 'AuthorURI', true, $translate ), $value ); |
|
| 732 | - } elseif ( ! $value ) { |
|
| 733 | - $value = __( 'Anonymous' ); |
|
| 730 | + if ($this->get('AuthorURI')) { |
|
| 731 | + $value = sprintf('<a href="%1$s">%2$s</a>', $this->display('AuthorURI', true, $translate), $value); |
|
| 732 | + } elseif ( ! $value) { |
|
| 733 | + $value = __('Anonymous'); |
|
| 734 | 734 | } |
| 735 | 735 | break; |
| 736 | 736 | case 'Tags' : |
| 737 | 737 | static $comma = null; |
| 738 | - if ( ! isset( $comma ) ) { |
|
| 738 | + if ( ! isset($comma)) { |
|
| 739 | 739 | /* translators: used between list items, there is a space after the comma */ |
| 740 | - $comma = __( ', ' ); |
|
| 740 | + $comma = __(', '); |
|
| 741 | 741 | } |
| 742 | - $value = implode( $comma, $value ); |
|
| 742 | + $value = implode($comma, $value); |
|
| 743 | 743 | break; |
| 744 | 744 | case 'ThemeURI' : |
| 745 | 745 | case 'AuthorURI' : |
| 746 | - $value = esc_url( $value ); |
|
| 746 | + $value = esc_url($value); |
|
| 747 | 747 | break; |
| 748 | 748 | } |
| 749 | 749 | |
@@ -762,51 +762,51 @@ discard block |
||
| 762 | 762 | * @param string $value Value to translate. |
| 763 | 763 | * @return string Translated value. |
| 764 | 764 | */ |
| 765 | - private function translate_header( $header, $value ) { |
|
| 766 | - switch ( $header ) { |
|
| 765 | + private function translate_header($header, $value) { |
|
| 766 | + switch ($header) { |
|
| 767 | 767 | case 'Name' : |
| 768 | 768 | // Cached for sorting reasons. |
| 769 | - if ( isset( $this->name_translated ) ) |
|
| 769 | + if (isset($this->name_translated)) |
|
| 770 | 770 | return $this->name_translated; |
| 771 | - $this->name_translated = translate( $value, $this->get('TextDomain' ) ); |
|
| 771 | + $this->name_translated = translate($value, $this->get('TextDomain')); |
|
| 772 | 772 | return $this->name_translated; |
| 773 | 773 | case 'Tags' : |
| 774 | - if ( empty( $value ) || ! function_exists( 'get_theme_feature_list' ) ) { |
|
| 774 | + if (empty($value) || ! function_exists('get_theme_feature_list')) { |
|
| 775 | 775 | return $value; |
| 776 | 776 | } |
| 777 | 777 | |
| 778 | 778 | static $tags_list; |
| 779 | - if ( ! isset( $tags_list ) ) { |
|
| 779 | + if ( ! isset($tags_list)) { |
|
| 780 | 780 | $tags_list = array( |
| 781 | 781 | // As of 4.6, deprecated tags which are only used to provide translation for older themes. |
| 782 | - 'black' => __( 'Black' ), 'blue' => __( 'Blue' ), 'brown' => __( 'Brown' ), |
|
| 783 | - 'gray' => __( 'Gray' ), 'green' => __( 'Green' ), 'orange' => __( 'Orange' ), |
|
| 784 | - 'pink' => __( 'Pink' ), 'purple' => __( 'Purple' ), 'red' => __( 'Red' ), |
|
| 785 | - 'silver' => __( 'Silver' ), 'tan' => __( 'Tan' ), 'white' => __( 'White' ), |
|
| 786 | - 'yellow' => __( 'Yellow' ), 'dark' => __( 'Dark' ), 'light' => __( 'Light' ), |
|
| 787 | - 'fixed-layout' => __( 'Fixed Layout' ), 'fluid-layout' => __( 'Fluid Layout' ), |
|
| 788 | - 'responsive-layout' => __( 'Responsive Layout' ), 'blavatar' => __( 'Blavatar' ), |
|
| 789 | - 'photoblogging' => __( 'Photoblogging' ), 'seasonal' => __( 'Seasonal' ), |
|
| 782 | + 'black' => __('Black'), 'blue' => __('Blue'), 'brown' => __('Brown'), |
|
| 783 | + 'gray' => __('Gray'), 'green' => __('Green'), 'orange' => __('Orange'), |
|
| 784 | + 'pink' => __('Pink'), 'purple' => __('Purple'), 'red' => __('Red'), |
|
| 785 | + 'silver' => __('Silver'), 'tan' => __('Tan'), 'white' => __('White'), |
|
| 786 | + 'yellow' => __('Yellow'), 'dark' => __('Dark'), 'light' => __('Light'), |
|
| 787 | + 'fixed-layout' => __('Fixed Layout'), 'fluid-layout' => __('Fluid Layout'), |
|
| 788 | + 'responsive-layout' => __('Responsive Layout'), 'blavatar' => __('Blavatar'), |
|
| 789 | + 'photoblogging' => __('Photoblogging'), 'seasonal' => __('Seasonal'), |
|
| 790 | 790 | ); |
| 791 | 791 | |
| 792 | - $feature_list = get_theme_feature_list( false ); // No API |
|
| 793 | - foreach ( $feature_list as $tags ) { |
|
| 792 | + $feature_list = get_theme_feature_list(false); // No API |
|
| 793 | + foreach ($feature_list as $tags) { |
|
| 794 | 794 | $tags_list += $tags; |
| 795 | 795 | } |
| 796 | 796 | } |
| 797 | 797 | |
| 798 | - foreach ( $value as &$tag ) { |
|
| 799 | - if ( isset( $tags_list[ $tag ] ) ) { |
|
| 800 | - $tag = $tags_list[ $tag ]; |
|
| 801 | - } elseif ( isset( self::$tag_map[ $tag ] ) ) { |
|
| 802 | - $tag = $tags_list[ self::$tag_map[ $tag ] ]; |
|
| 798 | + foreach ($value as &$tag) { |
|
| 799 | + if (isset($tags_list[$tag])) { |
|
| 800 | + $tag = $tags_list[$tag]; |
|
| 801 | + } elseif (isset(self::$tag_map[$tag])) { |
|
| 802 | + $tag = $tags_list[self::$tag_map[$tag]]; |
|
| 803 | 803 | } |
| 804 | 804 | } |
| 805 | 805 | |
| 806 | 806 | return $value; |
| 807 | 807 | |
| 808 | 808 | default : |
| 809 | - $value = translate( $value, $this->get('TextDomain') ); |
|
| 809 | + $value = translate($value, $this->get('TextDomain')); |
|
| 810 | 810 | } |
| 811 | 811 | return $value; |
| 812 | 812 | } |
@@ -853,10 +853,10 @@ discard block |
||
| 853 | 853 | * @return string Absolute path of the stylesheet directory. |
| 854 | 854 | */ |
| 855 | 855 | public function get_stylesheet_directory() { |
| 856 | - if ( $this->errors() && in_array( 'theme_root_missing', $this->errors()->get_error_codes() ) ) |
|
| 856 | + if ($this->errors() && in_array('theme_root_missing', $this->errors()->get_error_codes())) |
|
| 857 | 857 | return ''; |
| 858 | 858 | |
| 859 | - return $this->theme_root . '/' . $this->stylesheet; |
|
| 859 | + return $this->theme_root.'/'.$this->stylesheet; |
|
| 860 | 860 | } |
| 861 | 861 | |
| 862 | 862 | /** |
@@ -871,12 +871,12 @@ discard block |
||
| 871 | 871 | * @return string Absolute path of the template directory. |
| 872 | 872 | */ |
| 873 | 873 | public function get_template_directory() { |
| 874 | - if ( $this->parent() ) |
|
| 874 | + if ($this->parent()) |
|
| 875 | 875 | $theme_root = $this->parent()->theme_root; |
| 876 | 876 | else |
| 877 | 877 | $theme_root = $this->theme_root; |
| 878 | 878 | |
| 879 | - return $theme_root . '/' . $this->template; |
|
| 879 | + return $theme_root.'/'.$this->template; |
|
| 880 | 880 | } |
| 881 | 881 | |
| 882 | 882 | /** |
@@ -891,7 +891,7 @@ discard block |
||
| 891 | 891 | * @return string URL to the stylesheet directory. |
| 892 | 892 | */ |
| 893 | 893 | public function get_stylesheet_directory_uri() { |
| 894 | - return $this->get_theme_root_uri() . '/' . str_replace( '%2F', '/', rawurlencode( $this->stylesheet ) ); |
|
| 894 | + return $this->get_theme_root_uri().'/'.str_replace('%2F', '/', rawurlencode($this->stylesheet)); |
|
| 895 | 895 | } |
| 896 | 896 | |
| 897 | 897 | /** |
@@ -906,12 +906,12 @@ discard block |
||
| 906 | 906 | * @return string URL to the template directory. |
| 907 | 907 | */ |
| 908 | 908 | public function get_template_directory_uri() { |
| 909 | - if ( $this->parent() ) |
|
| 909 | + if ($this->parent()) |
|
| 910 | 910 | $theme_root_uri = $this->parent()->get_theme_root_uri(); |
| 911 | 911 | else |
| 912 | 912 | $theme_root_uri = $this->get_theme_root_uri(); |
| 913 | 913 | |
| 914 | - return $theme_root_uri . '/' . str_replace( '%2F', '/', rawurlencode( $this->template ) ); |
|
| 914 | + return $theme_root_uri.'/'.str_replace('%2F', '/', rawurlencode($this->template)); |
|
| 915 | 915 | } |
| 916 | 916 | |
| 917 | 917 | /** |
@@ -941,8 +941,8 @@ discard block |
||
| 941 | 941 | * @return string Theme root URI. |
| 942 | 942 | */ |
| 943 | 943 | public function get_theme_root_uri() { |
| 944 | - if ( ! isset( $this->theme_root_uri ) ) |
|
| 945 | - $this->theme_root_uri = get_theme_root_uri( $this->stylesheet, $this->theme_root ); |
|
| 944 | + if ( ! isset($this->theme_root_uri)) |
|
| 945 | + $this->theme_root_uri = get_theme_root_uri($this->stylesheet, $this->theme_root); |
|
| 946 | 946 | return $this->theme_root_uri; |
| 947 | 947 | } |
| 948 | 948 | |
@@ -960,26 +960,26 @@ discard block |
||
| 960 | 960 | * @param string $uri Type of URL to return, either 'relative' or an absolute URI. Defaults to absolute URI. |
| 961 | 961 | * @return string|false Screenshot file. False if the theme does not have a screenshot. |
| 962 | 962 | */ |
| 963 | - public function get_screenshot( $uri = 'uri' ) { |
|
| 964 | - $screenshot = $this->cache_get( 'screenshot' ); |
|
| 965 | - if ( $screenshot ) { |
|
| 966 | - if ( 'relative' == $uri ) |
|
| 963 | + public function get_screenshot($uri = 'uri') { |
|
| 964 | + $screenshot = $this->cache_get('screenshot'); |
|
| 965 | + if ($screenshot) { |
|
| 966 | + if ('relative' == $uri) |
|
| 967 | 967 | return $screenshot; |
| 968 | - return $this->get_stylesheet_directory_uri() . '/' . $screenshot; |
|
| 969 | - } elseif ( 0 === $screenshot ) { |
|
| 968 | + return $this->get_stylesheet_directory_uri().'/'.$screenshot; |
|
| 969 | + } elseif (0 === $screenshot) { |
|
| 970 | 970 | return false; |
| 971 | 971 | } |
| 972 | 972 | |
| 973 | - foreach ( array( 'png', 'gif', 'jpg', 'jpeg' ) as $ext ) { |
|
| 974 | - if ( file_exists( $this->get_stylesheet_directory() . "/screenshot.$ext" ) ) { |
|
| 975 | - $this->cache_add( 'screenshot', 'screenshot.' . $ext ); |
|
| 976 | - if ( 'relative' == $uri ) |
|
| 977 | - return 'screenshot.' . $ext; |
|
| 978 | - return $this->get_stylesheet_directory_uri() . '/' . 'screenshot.' . $ext; |
|
| 973 | + foreach (array('png', 'gif', 'jpg', 'jpeg') as $ext) { |
|
| 974 | + if (file_exists($this->get_stylesheet_directory()."/screenshot.$ext")) { |
|
| 975 | + $this->cache_add('screenshot', 'screenshot.'.$ext); |
|
| 976 | + if ('relative' == $uri) |
|
| 977 | + return 'screenshot.'.$ext; |
|
| 978 | + return $this->get_stylesheet_directory_uri().'/'.'screenshot.'.$ext; |
|
| 979 | 979 | } |
| 980 | 980 | } |
| 981 | 981 | |
| 982 | - $this->cache_add( 'screenshot', 0 ); |
|
| 982 | + $this->cache_add('screenshot', 0); |
|
| 983 | 983 | return false; |
| 984 | 984 | } |
| 985 | 985 | |
@@ -995,11 +995,11 @@ discard block |
||
| 995 | 995 | * @return array Array of files, keyed by the path to the file relative to the theme's directory, with the values |
| 996 | 996 | * being absolute paths. |
| 997 | 997 | */ |
| 998 | - public function get_files( $type = null, $depth = 0, $search_parent = false ) { |
|
| 999 | - $files = (array) self::scandir( $this->get_stylesheet_directory(), $type, $depth ); |
|
| 998 | + public function get_files($type = null, $depth = 0, $search_parent = false) { |
|
| 999 | + $files = (array) self::scandir($this->get_stylesheet_directory(), $type, $depth); |
|
| 1000 | 1000 | |
| 1001 | - if ( $search_parent && $this->parent() ) |
|
| 1002 | - $files += (array) self::scandir( $this->get_template_directory(), $type, $depth ); |
|
| 1001 | + if ($search_parent && $this->parent()) |
|
| 1002 | + $files += (array) self::scandir($this->get_template_directory(), $type, $depth); |
|
| 1003 | 1003 | |
| 1004 | 1004 | return $files; |
| 1005 | 1005 | } |
@@ -1013,35 +1013,35 @@ discard block |
||
| 1013 | 1013 | * @param WP_Post|null $post Optional. The post being edited, provided for context. |
| 1014 | 1014 | * @return array Array of page templates, keyed by filename, with the value of the translated header name. |
| 1015 | 1015 | */ |
| 1016 | - public function get_page_templates( $post = null ) { |
|
| 1016 | + public function get_page_templates($post = null) { |
|
| 1017 | 1017 | // If you screw up your current theme and we invalidate your parent, most things still work. Let it slide. |
| 1018 | - if ( $this->errors() && $this->errors()->get_error_codes() !== array( 'theme_parent_invalid' ) ) |
|
| 1018 | + if ($this->errors() && $this->errors()->get_error_codes() !== array('theme_parent_invalid')) |
|
| 1019 | 1019 | return array(); |
| 1020 | 1020 | |
| 1021 | - $page_templates = $this->cache_get( 'page_templates' ); |
|
| 1021 | + $page_templates = $this->cache_get('page_templates'); |
|
| 1022 | 1022 | |
| 1023 | - if ( ! is_array( $page_templates ) ) { |
|
| 1023 | + if ( ! is_array($page_templates)) { |
|
| 1024 | 1024 | $page_templates = array(); |
| 1025 | 1025 | |
| 1026 | - $files = (array) $this->get_files( 'php', 1 ); |
|
| 1026 | + $files = (array) $this->get_files('php', 1); |
|
| 1027 | 1027 | |
| 1028 | - foreach ( $files as $file => $full_path ) { |
|
| 1029 | - if ( ! preg_match( '|Template Name:(.*)$|mi', file_get_contents( $full_path ), $header ) ) |
|
| 1028 | + foreach ($files as $file => $full_path) { |
|
| 1029 | + if ( ! preg_match('|Template Name:(.*)$|mi', file_get_contents($full_path), $header)) |
|
| 1030 | 1030 | continue; |
| 1031 | - $page_templates[ $file ] = _cleanup_header_comment( $header[1] ); |
|
| 1031 | + $page_templates[$file] = _cleanup_header_comment($header[1]); |
|
| 1032 | 1032 | } |
| 1033 | 1033 | |
| 1034 | - $this->cache_add( 'page_templates', $page_templates ); |
|
| 1034 | + $this->cache_add('page_templates', $page_templates); |
|
| 1035 | 1035 | } |
| 1036 | 1036 | |
| 1037 | - if ( $this->load_textdomain() ) { |
|
| 1038 | - foreach ( $page_templates as &$page_template ) { |
|
| 1039 | - $page_template = $this->translate_header( 'Template Name', $page_template ); |
|
| 1037 | + if ($this->load_textdomain()) { |
|
| 1038 | + foreach ($page_templates as &$page_template) { |
|
| 1039 | + $page_template = $this->translate_header('Template Name', $page_template); |
|
| 1040 | 1040 | } |
| 1041 | 1041 | } |
| 1042 | 1042 | |
| 1043 | - if ( $this->parent() ) |
|
| 1044 | - $page_templates += $this->parent()->get_page_templates( $post ); |
|
| 1043 | + if ($this->parent()) |
|
| 1044 | + $page_templates += $this->parent()->get_page_templates($post); |
|
| 1045 | 1045 | |
| 1046 | 1046 | /** |
| 1047 | 1047 | * Filters list of page templates for a theme. |
@@ -1054,7 +1054,7 @@ discard block |
||
| 1054 | 1054 | * @param WP_Theme $this The theme object. |
| 1055 | 1055 | * @param WP_Post|null $post The post being edited, provided for context, or null. |
| 1056 | 1056 | */ |
| 1057 | - return (array) apply_filters( 'theme_page_templates', $page_templates, $this, $post ); |
|
| 1057 | + return (array) apply_filters('theme_page_templates', $page_templates, $this, $post); |
|
| 1058 | 1058 | } |
| 1059 | 1059 | |
| 1060 | 1060 | /** |
@@ -1076,32 +1076,32 @@ discard block |
||
| 1076 | 1076 | * @return array|false Array of files, keyed by the path to the file relative to the `$path` directory prepended |
| 1077 | 1077 | * with `$relative_path`, with the values being absolute paths. False otherwise. |
| 1078 | 1078 | */ |
| 1079 | - private static function scandir( $path, $extensions = null, $depth = 0, $relative_path = '' ) { |
|
| 1080 | - if ( ! is_dir( $path ) ) |
|
| 1079 | + private static function scandir($path, $extensions = null, $depth = 0, $relative_path = '') { |
|
| 1080 | + if ( ! is_dir($path)) |
|
| 1081 | 1081 | return false; |
| 1082 | 1082 | |
| 1083 | - if ( $extensions ) { |
|
| 1083 | + if ($extensions) { |
|
| 1084 | 1084 | $extensions = (array) $extensions; |
| 1085 | - $_extensions = implode( '|', $extensions ); |
|
| 1085 | + $_extensions = implode('|', $extensions); |
|
| 1086 | 1086 | } |
| 1087 | 1087 | |
| 1088 | - $relative_path = trailingslashit( $relative_path ); |
|
| 1089 | - if ( '/' == $relative_path ) |
|
| 1088 | + $relative_path = trailingslashit($relative_path); |
|
| 1089 | + if ('/' == $relative_path) |
|
| 1090 | 1090 | $relative_path = ''; |
| 1091 | 1091 | |
| 1092 | - $results = scandir( $path ); |
|
| 1092 | + $results = scandir($path); |
|
| 1093 | 1093 | $files = array(); |
| 1094 | 1094 | |
| 1095 | - foreach ( $results as $result ) { |
|
| 1096 | - if ( '.' == $result[0] ) |
|
| 1095 | + foreach ($results as $result) { |
|
| 1096 | + if ('.' == $result[0]) |
|
| 1097 | 1097 | continue; |
| 1098 | - if ( is_dir( $path . '/' . $result ) ) { |
|
| 1099 | - if ( ! $depth || 'CVS' == $result ) |
|
| 1098 | + if (is_dir($path.'/'.$result)) { |
|
| 1099 | + if ( ! $depth || 'CVS' == $result) |
|
| 1100 | 1100 | continue; |
| 1101 | - $found = self::scandir( $path . '/' . $result, $extensions, $depth - 1 , $relative_path . $result ); |
|
| 1102 | - $files = array_merge_recursive( $files, $found ); |
|
| 1103 | - } elseif ( ! $extensions || preg_match( '~\.(' . $_extensions . ')$~', $result ) ) { |
|
| 1104 | - $files[ $relative_path . $result ] = $path . '/' . $result; |
|
| 1101 | + $found = self::scandir($path.'/'.$result, $extensions, $depth - 1, $relative_path.$result); |
|
| 1102 | + $files = array_merge_recursive($files, $found); |
|
| 1103 | + } elseif ( ! $extensions || preg_match('~\.('.$_extensions.')$~', $result)) { |
|
| 1104 | + $files[$relative_path.$result] = $path.'/'.$result; |
|
| 1105 | 1105 | } |
| 1106 | 1106 | } |
| 1107 | 1107 | |
@@ -1121,27 +1121,27 @@ discard block |
||
| 1121 | 1121 | * False if no textdomain was specified in the file headers, or if the domain could not be loaded. |
| 1122 | 1122 | */ |
| 1123 | 1123 | public function load_textdomain() { |
| 1124 | - if ( isset( $this->textdomain_loaded ) ) |
|
| 1124 | + if (isset($this->textdomain_loaded)) |
|
| 1125 | 1125 | return $this->textdomain_loaded; |
| 1126 | 1126 | |
| 1127 | 1127 | $textdomain = $this->get('TextDomain'); |
| 1128 | - if ( ! $textdomain ) { |
|
| 1128 | + if ( ! $textdomain) { |
|
| 1129 | 1129 | $this->textdomain_loaded = false; |
| 1130 | 1130 | return false; |
| 1131 | 1131 | } |
| 1132 | 1132 | |
| 1133 | - if ( is_textdomain_loaded( $textdomain ) ) { |
|
| 1133 | + if (is_textdomain_loaded($textdomain)) { |
|
| 1134 | 1134 | $this->textdomain_loaded = true; |
| 1135 | 1135 | return true; |
| 1136 | 1136 | } |
| 1137 | 1137 | |
| 1138 | 1138 | $path = $this->get_stylesheet_directory(); |
| 1139 | - if ( $domainpath = $this->get('DomainPath') ) |
|
| 1139 | + if ($domainpath = $this->get('DomainPath')) |
|
| 1140 | 1140 | $path .= $domainpath; |
| 1141 | 1141 | else |
| 1142 | 1142 | $path .= '/languages'; |
| 1143 | 1143 | |
| 1144 | - $this->textdomain_loaded = load_theme_textdomain( $textdomain, $path ); |
|
| 1144 | + $this->textdomain_loaded = load_theme_textdomain($textdomain, $path); |
|
| 1145 | 1145 | return $this->textdomain_loaded; |
| 1146 | 1146 | } |
| 1147 | 1147 | |
@@ -1156,19 +1156,19 @@ discard block |
||
| 1156 | 1156 | * @param int $blog_id Optional. Ignored if only network-wide settings are checked. Defaults to current site. |
| 1157 | 1157 | * @return bool Whether the theme is allowed for the network. Returns true in single-site. |
| 1158 | 1158 | */ |
| 1159 | - public function is_allowed( $check = 'both', $blog_id = null ) { |
|
| 1160 | - if ( ! is_multisite() ) |
|
| 1159 | + public function is_allowed($check = 'both', $blog_id = null) { |
|
| 1160 | + if ( ! is_multisite()) |
|
| 1161 | 1161 | return true; |
| 1162 | 1162 | |
| 1163 | - if ( 'both' == $check || 'network' == $check ) { |
|
| 1163 | + if ('both' == $check || 'network' == $check) { |
|
| 1164 | 1164 | $allowed = self::get_allowed_on_network(); |
| 1165 | - if ( ! empty( $allowed[ $this->get_stylesheet() ] ) ) |
|
| 1165 | + if ( ! empty($allowed[$this->get_stylesheet()])) |
|
| 1166 | 1166 | return true; |
| 1167 | 1167 | } |
| 1168 | 1168 | |
| 1169 | - if ( 'both' == $check || 'site' == $check ) { |
|
| 1170 | - $allowed = self::get_allowed_on_site( $blog_id ); |
|
| 1171 | - if ( ! empty( $allowed[ $this->get_stylesheet() ] ) ) |
|
| 1169 | + if ('both' == $check || 'site' == $check) { |
|
| 1170 | + $allowed = self::get_allowed_on_site($blog_id); |
|
| 1171 | + if ( ! empty($allowed[$this->get_stylesheet()])) |
|
| 1172 | 1172 | return true; |
| 1173 | 1173 | } |
| 1174 | 1174 | |
@@ -1183,9 +1183,9 @@ discard block |
||
| 1183 | 1183 | * @return WP_Theme|false Object, or false if no theme is installed, which would be bad. |
| 1184 | 1184 | */ |
| 1185 | 1185 | public static function get_core_default_theme() { |
| 1186 | - foreach ( array_reverse( self::$default_themes ) as $slug => $name ) { |
|
| 1187 | - $theme = wp_get_theme( $slug ); |
|
| 1188 | - if ( $theme->exists() ) { |
|
| 1186 | + foreach (array_reverse(self::$default_themes) as $slug => $name) { |
|
| 1187 | + $theme = wp_get_theme($slug); |
|
| 1188 | + if ($theme->exists()) { |
|
| 1189 | 1189 | return $theme; |
| 1190 | 1190 | } |
| 1191 | 1191 | } |
@@ -1203,7 +1203,7 @@ discard block |
||
| 1203 | 1203 | * @param int $blog_id Optional. ID of the site. Defaults to the current site. |
| 1204 | 1204 | * @return array Array of stylesheet names. |
| 1205 | 1205 | */ |
| 1206 | - public static function get_allowed( $blog_id = null ) { |
|
| 1206 | + public static function get_allowed($blog_id = null) { |
|
| 1207 | 1207 | /** |
| 1208 | 1208 | * Filters the array of themes allowed on the network. |
| 1209 | 1209 | * |
@@ -1215,8 +1215,8 @@ discard block |
||
| 1215 | 1215 | * @param array $allowed_themes An array of theme stylesheet names. |
| 1216 | 1216 | * @param int $blog_id ID of the site. |
| 1217 | 1217 | */ |
| 1218 | - $network = (array) apply_filters( 'network_allowed_themes', self::get_allowed_on_network(), $blog_id ); |
|
| 1219 | - return $network + self::get_allowed_on_site( $blog_id ); |
|
| 1218 | + $network = (array) apply_filters('network_allowed_themes', self::get_allowed_on_network(), $blog_id); |
|
| 1219 | + return $network + self::get_allowed_on_site($blog_id); |
|
| 1220 | 1220 | } |
| 1221 | 1221 | |
| 1222 | 1222 | /** |
@@ -1233,8 +1233,8 @@ discard block |
||
| 1233 | 1233 | */ |
| 1234 | 1234 | public static function get_allowed_on_network() { |
| 1235 | 1235 | static $allowed_themes; |
| 1236 | - if ( ! isset( $allowed_themes ) ) { |
|
| 1237 | - $allowed_themes = (array) get_site_option( 'allowedthemes' ); |
|
| 1236 | + if ( ! isset($allowed_themes)) { |
|
| 1237 | + $allowed_themes = (array) get_site_option('allowedthemes'); |
|
| 1238 | 1238 | } |
| 1239 | 1239 | |
| 1240 | 1240 | /** |
@@ -1244,7 +1244,7 @@ discard block |
||
| 1244 | 1244 | * |
| 1245 | 1245 | * @param array $allowed_themes An array of theme stylesheet names. |
| 1246 | 1246 | */ |
| 1247 | - $allowed_themes = apply_filters( 'allowed_themes', $allowed_themes ); |
|
| 1247 | + $allowed_themes = apply_filters('allowed_themes', $allowed_themes); |
|
| 1248 | 1248 | |
| 1249 | 1249 | return $allowed_themes; |
| 1250 | 1250 | } |
@@ -1262,13 +1262,13 @@ discard block |
||
| 1262 | 1262 | * @param int $blog_id Optional. ID of the site. Defaults to the current site. |
| 1263 | 1263 | * @return array Array of stylesheet names. |
| 1264 | 1264 | */ |
| 1265 | - public static function get_allowed_on_site( $blog_id = null ) { |
|
| 1265 | + public static function get_allowed_on_site($blog_id = null) { |
|
| 1266 | 1266 | static $allowed_themes = array(); |
| 1267 | 1267 | |
| 1268 | - if ( ! $blog_id || ! is_multisite() ) |
|
| 1268 | + if ( ! $blog_id || ! is_multisite()) |
|
| 1269 | 1269 | $blog_id = get_current_blog_id(); |
| 1270 | 1270 | |
| 1271 | - if ( isset( $allowed_themes[ $blog_id ] ) ) { |
|
| 1271 | + if (isset($allowed_themes[$blog_id])) { |
|
| 1272 | 1272 | /** |
| 1273 | 1273 | * Filters the array of themes allowed on the site. |
| 1274 | 1274 | * |
@@ -1277,57 +1277,57 @@ discard block |
||
| 1277 | 1277 | * @param array $allowed_themes An array of theme stylesheet names. |
| 1278 | 1278 | * @param int $blog_id ID of the site. Defaults to current site. |
| 1279 | 1279 | */ |
| 1280 | - return (array) apply_filters( 'site_allowed_themes', $allowed_themes[ $blog_id ], $blog_id ); |
|
| 1280 | + return (array) apply_filters('site_allowed_themes', $allowed_themes[$blog_id], $blog_id); |
|
| 1281 | 1281 | } |
| 1282 | 1282 | |
| 1283 | 1283 | $current = $blog_id == get_current_blog_id(); |
| 1284 | 1284 | |
| 1285 | - if ( $current ) { |
|
| 1286 | - $allowed_themes[ $blog_id ] = get_option( 'allowedthemes' ); |
|
| 1285 | + if ($current) { |
|
| 1286 | + $allowed_themes[$blog_id] = get_option('allowedthemes'); |
|
| 1287 | 1287 | } else { |
| 1288 | - switch_to_blog( $blog_id ); |
|
| 1289 | - $allowed_themes[ $blog_id ] = get_option( 'allowedthemes' ); |
|
| 1288 | + switch_to_blog($blog_id); |
|
| 1289 | + $allowed_themes[$blog_id] = get_option('allowedthemes'); |
|
| 1290 | 1290 | restore_current_blog(); |
| 1291 | 1291 | } |
| 1292 | 1292 | |
| 1293 | 1293 | // This is all super old MU back compat joy. |
| 1294 | 1294 | // 'allowedthemes' keys things by stylesheet. 'allowed_themes' keyed things by name. |
| 1295 | - if ( false === $allowed_themes[ $blog_id ] ) { |
|
| 1296 | - if ( $current ) { |
|
| 1297 | - $allowed_themes[ $blog_id ] = get_option( 'allowed_themes' ); |
|
| 1295 | + if (false === $allowed_themes[$blog_id]) { |
|
| 1296 | + if ($current) { |
|
| 1297 | + $allowed_themes[$blog_id] = get_option('allowed_themes'); |
|
| 1298 | 1298 | } else { |
| 1299 | - switch_to_blog( $blog_id ); |
|
| 1300 | - $allowed_themes[ $blog_id ] = get_option( 'allowed_themes' ); |
|
| 1299 | + switch_to_blog($blog_id); |
|
| 1300 | + $allowed_themes[$blog_id] = get_option('allowed_themes'); |
|
| 1301 | 1301 | restore_current_blog(); |
| 1302 | 1302 | } |
| 1303 | 1303 | |
| 1304 | - if ( ! is_array( $allowed_themes[ $blog_id ] ) || empty( $allowed_themes[ $blog_id ] ) ) { |
|
| 1305 | - $allowed_themes[ $blog_id ] = array(); |
|
| 1304 | + if ( ! is_array($allowed_themes[$blog_id]) || empty($allowed_themes[$blog_id])) { |
|
| 1305 | + $allowed_themes[$blog_id] = array(); |
|
| 1306 | 1306 | } else { |
| 1307 | 1307 | $converted = array(); |
| 1308 | 1308 | $themes = wp_get_themes(); |
| 1309 | - foreach ( $themes as $stylesheet => $theme_data ) { |
|
| 1310 | - if ( isset( $allowed_themes[ $blog_id ][ $theme_data->get('Name') ] ) ) |
|
| 1311 | - $converted[ $stylesheet ] = true; |
|
| 1309 | + foreach ($themes as $stylesheet => $theme_data) { |
|
| 1310 | + if (isset($allowed_themes[$blog_id][$theme_data->get('Name')])) |
|
| 1311 | + $converted[$stylesheet] = true; |
|
| 1312 | 1312 | } |
| 1313 | - $allowed_themes[ $blog_id ] = $converted; |
|
| 1313 | + $allowed_themes[$blog_id] = $converted; |
|
| 1314 | 1314 | } |
| 1315 | 1315 | // Set the option so we never have to go through this pain again. |
| 1316 | - if ( is_admin() && $allowed_themes[ $blog_id ] ) { |
|
| 1317 | - if ( $current ) { |
|
| 1318 | - update_option( 'allowedthemes', $allowed_themes[ $blog_id ] ); |
|
| 1319 | - delete_option( 'allowed_themes' ); |
|
| 1316 | + if (is_admin() && $allowed_themes[$blog_id]) { |
|
| 1317 | + if ($current) { |
|
| 1318 | + update_option('allowedthemes', $allowed_themes[$blog_id]); |
|
| 1319 | + delete_option('allowed_themes'); |
|
| 1320 | 1320 | } else { |
| 1321 | - switch_to_blog( $blog_id ); |
|
| 1322 | - update_option( 'allowedthemes', $allowed_themes[ $blog_id ] ); |
|
| 1323 | - delete_option( 'allowed_themes' ); |
|
| 1321 | + switch_to_blog($blog_id); |
|
| 1322 | + update_option('allowedthemes', $allowed_themes[$blog_id]); |
|
| 1323 | + delete_option('allowed_themes'); |
|
| 1324 | 1324 | restore_current_blog(); |
| 1325 | 1325 | } |
| 1326 | 1326 | } |
| 1327 | 1327 | } |
| 1328 | 1328 | |
| 1329 | 1329 | /** This filter is documented in wp-includes/class-wp-theme.php */ |
| 1330 | - return (array) apply_filters( 'site_allowed_themes', $allowed_themes[ $blog_id ], $blog_id ); |
|
| 1330 | + return (array) apply_filters('site_allowed_themes', $allowed_themes[$blog_id], $blog_id); |
|
| 1331 | 1331 | } |
| 1332 | 1332 | |
| 1333 | 1333 | /** |
@@ -1339,21 +1339,21 @@ discard block |
||
| 1339 | 1339 | * |
| 1340 | 1340 | * @param string|array $stylesheets Stylesheet name or array of stylesheet names. |
| 1341 | 1341 | */ |
| 1342 | - public static function network_enable_theme( $stylesheets ) { |
|
| 1343 | - if ( ! is_multisite() ) { |
|
| 1342 | + public static function network_enable_theme($stylesheets) { |
|
| 1343 | + if ( ! is_multisite()) { |
|
| 1344 | 1344 | return; |
| 1345 | 1345 | } |
| 1346 | 1346 | |
| 1347 | - if ( ! is_array( $stylesheets ) ) { |
|
| 1348 | - $stylesheets = array( $stylesheets ); |
|
| 1347 | + if ( ! is_array($stylesheets)) { |
|
| 1348 | + $stylesheets = array($stylesheets); |
|
| 1349 | 1349 | } |
| 1350 | 1350 | |
| 1351 | - $allowed_themes = get_site_option( 'allowedthemes' ); |
|
| 1352 | - foreach ( $stylesheets as $stylesheet ) { |
|
| 1353 | - $allowed_themes[ $stylesheet ] = true; |
|
| 1351 | + $allowed_themes = get_site_option('allowedthemes'); |
|
| 1352 | + foreach ($stylesheets as $stylesheet) { |
|
| 1353 | + $allowed_themes[$stylesheet] = true; |
|
| 1354 | 1354 | } |
| 1355 | 1355 | |
| 1356 | - update_site_option( 'allowedthemes', $allowed_themes ); |
|
| 1356 | + update_site_option('allowedthemes', $allowed_themes); |
|
| 1357 | 1357 | } |
| 1358 | 1358 | |
| 1359 | 1359 | /** |
@@ -1365,23 +1365,23 @@ discard block |
||
| 1365 | 1365 | * |
| 1366 | 1366 | * @param string|array $stylesheets Stylesheet name or array of stylesheet names. |
| 1367 | 1367 | */ |
| 1368 | - public static function network_disable_theme( $stylesheets ) { |
|
| 1369 | - if ( ! is_multisite() ) { |
|
| 1368 | + public static function network_disable_theme($stylesheets) { |
|
| 1369 | + if ( ! is_multisite()) { |
|
| 1370 | 1370 | return; |
| 1371 | 1371 | } |
| 1372 | 1372 | |
| 1373 | - if ( ! is_array( $stylesheets ) ) { |
|
| 1374 | - $stylesheets = array( $stylesheets ); |
|
| 1373 | + if ( ! is_array($stylesheets)) { |
|
| 1374 | + $stylesheets = array($stylesheets); |
|
| 1375 | 1375 | } |
| 1376 | 1376 | |
| 1377 | - $allowed_themes = get_site_option( 'allowedthemes' ); |
|
| 1378 | - foreach ( $stylesheets as $stylesheet ) { |
|
| 1379 | - if ( isset( $allowed_themes[ $stylesheet ] ) ) { |
|
| 1380 | - unset( $allowed_themes[ $stylesheet ] ); |
|
| 1377 | + $allowed_themes = get_site_option('allowedthemes'); |
|
| 1378 | + foreach ($stylesheets as $stylesheet) { |
|
| 1379 | + if (isset($allowed_themes[$stylesheet])) { |
|
| 1380 | + unset($allowed_themes[$stylesheet]); |
|
| 1381 | 1381 | } |
| 1382 | 1382 | } |
| 1383 | 1383 | |
| 1384 | - update_site_option( 'allowedthemes', $allowed_themes ); |
|
| 1384 | + update_site_option('allowedthemes', $allowed_themes); |
|
| 1385 | 1385 | } |
| 1386 | 1386 | |
| 1387 | 1387 | /** |
@@ -1394,11 +1394,11 @@ discard block |
||
| 1394 | 1394 | * |
| 1395 | 1395 | * @param array $themes Array of themes to sort, passed by reference. |
| 1396 | 1396 | */ |
| 1397 | - public static function sort_by_name( &$themes ) { |
|
| 1398 | - if ( 0 === strpos( get_locale(), 'en_' ) ) { |
|
| 1399 | - uasort( $themes, array( 'WP_Theme', '_name_sort' ) ); |
|
| 1397 | + public static function sort_by_name(&$themes) { |
|
| 1398 | + if (0 === strpos(get_locale(), 'en_')) { |
|
| 1399 | + uasort($themes, array('WP_Theme', '_name_sort')); |
|
| 1400 | 1400 | } else { |
| 1401 | - uasort( $themes, array( 'WP_Theme', '_name_sort_i18n' ) ); |
|
| 1401 | + uasort($themes, array('WP_Theme', '_name_sort_i18n')); |
|
| 1402 | 1402 | } |
| 1403 | 1403 | } |
| 1404 | 1404 | |
@@ -1418,8 +1418,8 @@ discard block |
||
| 1418 | 1418 | * @return int Negative if `$a` falls lower in the natural order than `$b`. Zero if they fall equally. |
| 1419 | 1419 | * Greater than 0 if `$a` falls higher in the natural order than `$b`. Used with usort(). |
| 1420 | 1420 | */ |
| 1421 | - private static function _name_sort( $a, $b ) { |
|
| 1422 | - return strnatcasecmp( $a->headers['Name'], $b->headers['Name'] ); |
|
| 1421 | + private static function _name_sort($a, $b) { |
|
| 1422 | + return strnatcasecmp($a->headers['Name'], $b->headers['Name']); |
|
| 1423 | 1423 | } |
| 1424 | 1424 | |
| 1425 | 1425 | /** |
@@ -1435,8 +1435,8 @@ discard block |
||
| 1435 | 1435 | * @return int Negative if `$a` falls lower in the natural order than `$b`. Zero if they fall equally. |
| 1436 | 1436 | * Greater than 0 if `$a` falls higher in the natural order than `$b`. Used with usort(). |
| 1437 | 1437 | */ |
| 1438 | - private static function _name_sort_i18n( $a, $b ) { |
|
| 1438 | + private static function _name_sort_i18n($a, $b) { |
|
| 1439 | 1439 | // Don't mark up; Do translate. |
| 1440 | - return strnatcasecmp( $a->display( 'Name', false, true ), $b->display( 'Name', false, true ) ); |
|
| 1440 | + return strnatcasecmp($a->display('Name', false, true), $b->display('Name', false, true)); |
|
| 1441 | 1441 | } |
| 1442 | 1442 | } |
@@ -207,8 +207,9 @@ discard block |
||
| 207 | 207 | self::$persistently_cache = apply_filters( 'wp_cache_themes_persistently', false, 'WP_Theme' ); |
| 208 | 208 | if ( self::$persistently_cache ) { |
| 209 | 209 | wp_cache_add_global_groups( 'themes' ); |
| 210 | - if ( is_int( self::$persistently_cache ) ) |
|
| 211 | - self::$cache_expiration = self::$persistently_cache; |
|
| 210 | + if ( is_int( self::$persistently_cache ) ) { |
|
| 211 | + self::$cache_expiration = self::$persistently_cache; |
|
| 212 | + } |
|
| 212 | 213 | } else { |
| 213 | 214 | wp_cache_add_non_persistent_groups( 'themes' ); |
| 214 | 215 | } |
@@ -230,23 +231,29 @@ discard block |
||
| 230 | 231 | |
| 231 | 232 | if ( is_array( $cache ) ) { |
| 232 | 233 | foreach ( array( 'errors', 'headers', 'template' ) as $key ) { |
| 233 | - if ( isset( $cache[ $key ] ) ) |
|
| 234 | - $this->$key = $cache[ $key ]; |
|
| 234 | + if ( isset( $cache[ $key ] ) ) { |
|
| 235 | + $this->$key = $cache[ $key ]; |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + if ( $this->errors ) { |
|
| 239 | + return; |
|
| 240 | + } |
|
| 241 | + if ( isset( $cache['theme_root_template'] ) ) { |
|
| 242 | + $theme_root_template = $cache['theme_root_template']; |
|
| 235 | 243 | } |
| 236 | - if ( $this->errors ) |
|
| 237 | - return; |
|
| 238 | - if ( isset( $cache['theme_root_template'] ) ) |
|
| 239 | - $theme_root_template = $cache['theme_root_template']; |
|
| 240 | 244 | } elseif ( ! file_exists( $this->theme_root . '/' . $theme_file ) ) { |
| 241 | 245 | $this->headers['Name'] = $this->stylesheet; |
| 242 | - if ( ! file_exists( $this->theme_root . '/' . $this->stylesheet ) ) |
|
| 243 | - $this->errors = new WP_Error( 'theme_not_found', sprintf( __( 'The theme directory "%s" does not exist.' ), esc_html( $this->stylesheet ) ) ); |
|
| 244 | - else |
|
| 245 | - $this->errors = new WP_Error( 'theme_no_stylesheet', __( 'Stylesheet is missing.' ) ); |
|
| 246 | + if ( ! file_exists( $this->theme_root . '/' . $this->stylesheet ) ) { |
|
| 247 | + $this->errors = new WP_Error( 'theme_not_found', sprintf( __( 'The theme directory "%s" does not exist.' ), esc_html( $this->stylesheet ) ) ); |
|
| 248 | + } else { |
|
| 249 | + $this->errors = new WP_Error( 'theme_no_stylesheet', __( 'Stylesheet is missing.' ) ); |
|
| 250 | + } |
|
| 246 | 251 | $this->template = $this->stylesheet; |
| 247 | 252 | $this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) ); |
| 248 | - if ( ! file_exists( $this->theme_root ) ) // Don't cache this one. |
|
| 253 | + if ( ! file_exists( $this->theme_root ) ) { |
|
| 254 | + // Don't cache this one. |
|
| 249 | 255 | $this->errors->add( 'theme_root_missing', __( 'ERROR: The themes directory is either empty or doesn’t exist. Please check your installation.' ) ); |
| 256 | + } |
|
| 250 | 257 | return; |
| 251 | 258 | } elseif ( ! is_readable( $this->theme_root . '/' . $theme_file ) ) { |
| 252 | 259 | $this->headers['Name'] = $this->stylesheet; |
@@ -259,8 +266,9 @@ discard block |
||
| 259 | 266 | // Default themes always trump their pretenders. |
| 260 | 267 | // Properly identify default themes that are inside a directory within wp-content/themes. |
| 261 | 268 | if ( $default_theme_slug = array_search( $this->headers['Name'], self::$default_themes ) ) { |
| 262 | - if ( basename( $this->stylesheet ) != $default_theme_slug ) |
|
| 263 | - $this->headers['Name'] .= '/' . $this->stylesheet; |
|
| 269 | + if ( basename( $this->stylesheet ) != $default_theme_slug ) { |
|
| 270 | + $this->headers['Name'] .= '/' . $this->stylesheet; |
|
| 271 | + } |
|
| 264 | 272 | } |
| 265 | 273 | } |
| 266 | 274 | |
@@ -323,8 +331,9 @@ discard block |
||
| 323 | 331 | if ( ! is_array( $cache ) ) { |
| 324 | 332 | $cache = array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ); |
| 325 | 333 | // If the parent theme is in another root, we'll want to cache this. Avoids an entire branch of filesystem calls above. |
| 326 | - if ( isset( $theme_root_template ) ) |
|
| 327 | - $cache['theme_root_template'] = $theme_root_template; |
|
| 334 | + if ( isset( $theme_root_template ) ) { |
|
| 335 | + $cache['theme_root_template'] = $theme_root_template; |
|
| 336 | + } |
|
| 328 | 337 | $this->cache_add( 'theme', $cache ); |
| 329 | 338 | } |
| 330 | 339 | } |
@@ -567,8 +576,9 @@ discard block |
||
| 567 | 576 | * @access public |
| 568 | 577 | */ |
| 569 | 578 | public function cache_delete() { |
| 570 | - foreach ( array( 'theme', 'screenshot', 'headers', 'page_templates' ) as $key ) |
|
| 571 | - wp_cache_delete( $key . '-' . $this->cache_hash, 'themes' ); |
|
| 579 | + foreach ( array( 'theme', 'screenshot', 'headers', 'page_templates' ) as $key ) { |
|
| 580 | + wp_cache_delete( $key . '-' . $this->cache_hash, 'themes' ); |
|
| 581 | + } |
|
| 572 | 582 | $this->template = $this->textdomain_loaded = $this->theme_root_uri = $this->parent = $this->errors = $this->headers_sanitized = $this->name_translated = null; |
| 573 | 583 | $this->headers = array(); |
| 574 | 584 | $this->__construct( $this->stylesheet, $this->theme_root ); |
@@ -592,22 +602,26 @@ discard block |
||
| 592 | 602 | * @return string|false String on success, false on failure. |
| 593 | 603 | */ |
| 594 | 604 | public function get( $header ) { |
| 595 | - if ( ! isset( $this->headers[ $header ] ) ) |
|
| 596 | - return false; |
|
| 605 | + if ( ! isset( $this->headers[ $header ] ) ) { |
|
| 606 | + return false; |
|
| 607 | + } |
|
| 597 | 608 | |
| 598 | 609 | if ( ! isset( $this->headers_sanitized ) ) { |
| 599 | 610 | $this->headers_sanitized = $this->cache_get( 'headers' ); |
| 600 | - if ( ! is_array( $this->headers_sanitized ) ) |
|
| 601 | - $this->headers_sanitized = array(); |
|
| 611 | + if ( ! is_array( $this->headers_sanitized ) ) { |
|
| 612 | + $this->headers_sanitized = array(); |
|
| 613 | + } |
|
| 602 | 614 | } |
| 603 | 615 | |
| 604 | - if ( isset( $this->headers_sanitized[ $header ] ) ) |
|
| 605 | - return $this->headers_sanitized[ $header ]; |
|
| 616 | + if ( isset( $this->headers_sanitized[ $header ] ) ) { |
|
| 617 | + return $this->headers_sanitized[ $header ]; |
|
| 618 | + } |
|
| 606 | 619 | |
| 607 | 620 | // If themes are a persistent group, sanitize everything and cache it. One cache add is better than many cache sets. |
| 608 | 621 | if ( self::$persistently_cache ) { |
| 609 | - foreach ( array_keys( $this->headers ) as $_header ) |
|
| 610 | - $this->headers_sanitized[ $_header ] = $this->sanitize_header( $_header, $this->headers[ $_header ] ); |
|
| 622 | + foreach ( array_keys( $this->headers ) as $_header ) { |
|
| 623 | + $this->headers_sanitized[ $_header ] = $this->sanitize_header( $_header, $this->headers[ $_header ] ); |
|
| 624 | + } |
|
| 611 | 625 | $this->cache_add( 'headers', $this->headers_sanitized ); |
| 612 | 626 | } else { |
| 613 | 627 | $this->headers_sanitized[ $header ] = $this->sanitize_header( $header, $this->headers[ $header ] ); |
@@ -633,14 +647,17 @@ discard block |
||
| 633 | 647 | return false; |
| 634 | 648 | } |
| 635 | 649 | |
| 636 | - if ( $translate && ( empty( $value ) || ! $this->load_textdomain() ) ) |
|
| 637 | - $translate = false; |
|
| 650 | + if ( $translate && ( empty( $value ) || ! $this->load_textdomain() ) ) { |
|
| 651 | + $translate = false; |
|
| 652 | + } |
|
| 638 | 653 | |
| 639 | - if ( $translate ) |
|
| 640 | - $value = $this->translate_header( $header, $value ); |
|
| 654 | + if ( $translate ) { |
|
| 655 | + $value = $this->translate_header( $header, $value ); |
|
| 656 | + } |
|
| 641 | 657 | |
| 642 | - if ( $markup ) |
|
| 643 | - $value = $this->markup_header( $header, $value, $translate ); |
|
| 658 | + if ( $markup ) { |
|
| 659 | + $value = $this->markup_header( $header, $value, $translate ); |
|
| 660 | + } |
|
| 644 | 661 | |
| 645 | 662 | return $value; |
| 646 | 663 | } |
@@ -720,8 +737,9 @@ discard block |
||
| 720 | 737 | private function markup_header( $header, $value, $translate ) { |
| 721 | 738 | switch ( $header ) { |
| 722 | 739 | case 'Name' : |
| 723 | - if ( empty( $value ) ) |
|
| 724 | - $value = $this->get_stylesheet(); |
|
| 740 | + if ( empty( $value ) ) { |
|
| 741 | + $value = $this->get_stylesheet(); |
|
| 742 | + } |
|
| 725 | 743 | break; |
| 726 | 744 | case 'Description' : |
| 727 | 745 | $value = wptexturize( $value ); |
@@ -766,8 +784,9 @@ discard block |
||
| 766 | 784 | switch ( $header ) { |
| 767 | 785 | case 'Name' : |
| 768 | 786 | // Cached for sorting reasons. |
| 769 | - if ( isset( $this->name_translated ) ) |
|
| 770 | - return $this->name_translated; |
|
| 787 | + if ( isset( $this->name_translated ) ) { |
|
| 788 | + return $this->name_translated; |
|
| 789 | + } |
|
| 771 | 790 | $this->name_translated = translate( $value, $this->get('TextDomain' ) ); |
| 772 | 791 | return $this->name_translated; |
| 773 | 792 | case 'Tags' : |
@@ -853,8 +872,9 @@ discard block |
||
| 853 | 872 | * @return string Absolute path of the stylesheet directory. |
| 854 | 873 | */ |
| 855 | 874 | public function get_stylesheet_directory() { |
| 856 | - if ( $this->errors() && in_array( 'theme_root_missing', $this->errors()->get_error_codes() ) ) |
|
| 857 | - return ''; |
|
| 875 | + if ( $this->errors() && in_array( 'theme_root_missing', $this->errors()->get_error_codes() ) ) { |
|
| 876 | + return ''; |
|
| 877 | + } |
|
| 858 | 878 | |
| 859 | 879 | return $this->theme_root . '/' . $this->stylesheet; |
| 860 | 880 | } |
@@ -871,10 +891,11 @@ discard block |
||
| 871 | 891 | * @return string Absolute path of the template directory. |
| 872 | 892 | */ |
| 873 | 893 | public function get_template_directory() { |
| 874 | - if ( $this->parent() ) |
|
| 875 | - $theme_root = $this->parent()->theme_root; |
|
| 876 | - else |
|
| 877 | - $theme_root = $this->theme_root; |
|
| 894 | + if ( $this->parent() ) { |
|
| 895 | + $theme_root = $this->parent()->theme_root; |
|
| 896 | + } else { |
|
| 897 | + $theme_root = $this->theme_root; |
|
| 898 | + } |
|
| 878 | 899 | |
| 879 | 900 | return $theme_root . '/' . $this->template; |
| 880 | 901 | } |
@@ -906,10 +927,11 @@ discard block |
||
| 906 | 927 | * @return string URL to the template directory. |
| 907 | 928 | */ |
| 908 | 929 | public function get_template_directory_uri() { |
| 909 | - if ( $this->parent() ) |
|
| 910 | - $theme_root_uri = $this->parent()->get_theme_root_uri(); |
|
| 911 | - else |
|
| 912 | - $theme_root_uri = $this->get_theme_root_uri(); |
|
| 930 | + if ( $this->parent() ) { |
|
| 931 | + $theme_root_uri = $this->parent()->get_theme_root_uri(); |
|
| 932 | + } else { |
|
| 933 | + $theme_root_uri = $this->get_theme_root_uri(); |
|
| 934 | + } |
|
| 913 | 935 | |
| 914 | 936 | return $theme_root_uri . '/' . str_replace( '%2F', '/', rawurlencode( $this->template ) ); |
| 915 | 937 | } |
@@ -941,8 +963,9 @@ discard block |
||
| 941 | 963 | * @return string Theme root URI. |
| 942 | 964 | */ |
| 943 | 965 | public function get_theme_root_uri() { |
| 944 | - if ( ! isset( $this->theme_root_uri ) ) |
|
| 945 | - $this->theme_root_uri = get_theme_root_uri( $this->stylesheet, $this->theme_root ); |
|
| 966 | + if ( ! isset( $this->theme_root_uri ) ) { |
|
| 967 | + $this->theme_root_uri = get_theme_root_uri( $this->stylesheet, $this->theme_root ); |
|
| 968 | + } |
|
| 946 | 969 | return $this->theme_root_uri; |
| 947 | 970 | } |
| 948 | 971 | |
@@ -963,8 +986,9 @@ discard block |
||
| 963 | 986 | public function get_screenshot( $uri = 'uri' ) { |
| 964 | 987 | $screenshot = $this->cache_get( 'screenshot' ); |
| 965 | 988 | if ( $screenshot ) { |
| 966 | - if ( 'relative' == $uri ) |
|
| 967 | - return $screenshot; |
|
| 989 | + if ( 'relative' == $uri ) { |
|
| 990 | + return $screenshot; |
|
| 991 | + } |
|
| 968 | 992 | return $this->get_stylesheet_directory_uri() . '/' . $screenshot; |
| 969 | 993 | } elseif ( 0 === $screenshot ) { |
| 970 | 994 | return false; |
@@ -973,8 +997,9 @@ discard block |
||
| 973 | 997 | foreach ( array( 'png', 'gif', 'jpg', 'jpeg' ) as $ext ) { |
| 974 | 998 | if ( file_exists( $this->get_stylesheet_directory() . "/screenshot.$ext" ) ) { |
| 975 | 999 | $this->cache_add( 'screenshot', 'screenshot.' . $ext ); |
| 976 | - if ( 'relative' == $uri ) |
|
| 977 | - return 'screenshot.' . $ext; |
|
| 1000 | + if ( 'relative' == $uri ) { |
|
| 1001 | + return 'screenshot.' . $ext; |
|
| 1002 | + } |
|
| 978 | 1003 | return $this->get_stylesheet_directory_uri() . '/' . 'screenshot.' . $ext; |
| 979 | 1004 | } |
| 980 | 1005 | } |
@@ -998,8 +1023,9 @@ discard block |
||
| 998 | 1023 | public function get_files( $type = null, $depth = 0, $search_parent = false ) { |
| 999 | 1024 | $files = (array) self::scandir( $this->get_stylesheet_directory(), $type, $depth ); |
| 1000 | 1025 | |
| 1001 | - if ( $search_parent && $this->parent() ) |
|
| 1002 | - $files += (array) self::scandir( $this->get_template_directory(), $type, $depth ); |
|
| 1026 | + if ( $search_parent && $this->parent() ) { |
|
| 1027 | + $files += (array) self::scandir( $this->get_template_directory(), $type, $depth ); |
|
| 1028 | + } |
|
| 1003 | 1029 | |
| 1004 | 1030 | return $files; |
| 1005 | 1031 | } |
@@ -1015,8 +1041,9 @@ discard block |
||
| 1015 | 1041 | */ |
| 1016 | 1042 | public function get_page_templates( $post = null ) { |
| 1017 | 1043 | // If you screw up your current theme and we invalidate your parent, most things still work. Let it slide. |
| 1018 | - if ( $this->errors() && $this->errors()->get_error_codes() !== array( 'theme_parent_invalid' ) ) |
|
| 1019 | - return array(); |
|
| 1044 | + if ( $this->errors() && $this->errors()->get_error_codes() !== array( 'theme_parent_invalid' ) ) { |
|
| 1045 | + return array(); |
|
| 1046 | + } |
|
| 1020 | 1047 | |
| 1021 | 1048 | $page_templates = $this->cache_get( 'page_templates' ); |
| 1022 | 1049 | |
@@ -1026,8 +1053,9 @@ discard block |
||
| 1026 | 1053 | $files = (array) $this->get_files( 'php', 1 ); |
| 1027 | 1054 | |
| 1028 | 1055 | foreach ( $files as $file => $full_path ) { |
| 1029 | - if ( ! preg_match( '|Template Name:(.*)$|mi', file_get_contents( $full_path ), $header ) ) |
|
| 1030 | - continue; |
|
| 1056 | + if ( ! preg_match( '|Template Name:(.*)$|mi', file_get_contents( $full_path ), $header ) ) { |
|
| 1057 | + continue; |
|
| 1058 | + } |
|
| 1031 | 1059 | $page_templates[ $file ] = _cleanup_header_comment( $header[1] ); |
| 1032 | 1060 | } |
| 1033 | 1061 | |
@@ -1040,8 +1068,9 @@ discard block |
||
| 1040 | 1068 | } |
| 1041 | 1069 | } |
| 1042 | 1070 | |
| 1043 | - if ( $this->parent() ) |
|
| 1044 | - $page_templates += $this->parent()->get_page_templates( $post ); |
|
| 1071 | + if ( $this->parent() ) { |
|
| 1072 | + $page_templates += $this->parent()->get_page_templates( $post ); |
|
| 1073 | + } |
|
| 1045 | 1074 | |
| 1046 | 1075 | /** |
| 1047 | 1076 | * Filters list of page templates for a theme. |
@@ -1077,8 +1106,9 @@ discard block |
||
| 1077 | 1106 | * with `$relative_path`, with the values being absolute paths. False otherwise. |
| 1078 | 1107 | */ |
| 1079 | 1108 | private static function scandir( $path, $extensions = null, $depth = 0, $relative_path = '' ) { |
| 1080 | - if ( ! is_dir( $path ) ) |
|
| 1081 | - return false; |
|
| 1109 | + if ( ! is_dir( $path ) ) { |
|
| 1110 | + return false; |
|
| 1111 | + } |
|
| 1082 | 1112 | |
| 1083 | 1113 | if ( $extensions ) { |
| 1084 | 1114 | $extensions = (array) $extensions; |
@@ -1086,18 +1116,21 @@ discard block |
||
| 1086 | 1116 | } |
| 1087 | 1117 | |
| 1088 | 1118 | $relative_path = trailingslashit( $relative_path ); |
| 1089 | - if ( '/' == $relative_path ) |
|
| 1090 | - $relative_path = ''; |
|
| 1119 | + if ( '/' == $relative_path ) { |
|
| 1120 | + $relative_path = ''; |
|
| 1121 | + } |
|
| 1091 | 1122 | |
| 1092 | 1123 | $results = scandir( $path ); |
| 1093 | 1124 | $files = array(); |
| 1094 | 1125 | |
| 1095 | 1126 | foreach ( $results as $result ) { |
| 1096 | - if ( '.' == $result[0] ) |
|
| 1097 | - continue; |
|
| 1127 | + if ( '.' == $result[0] ) { |
|
| 1128 | + continue; |
|
| 1129 | + } |
|
| 1098 | 1130 | if ( is_dir( $path . '/' . $result ) ) { |
| 1099 | - if ( ! $depth || 'CVS' == $result ) |
|
| 1100 | - continue; |
|
| 1131 | + if ( ! $depth || 'CVS' == $result ) { |
|
| 1132 | + continue; |
|
| 1133 | + } |
|
| 1101 | 1134 | $found = self::scandir( $path . '/' . $result, $extensions, $depth - 1 , $relative_path . $result ); |
| 1102 | 1135 | $files = array_merge_recursive( $files, $found ); |
| 1103 | 1136 | } elseif ( ! $extensions || preg_match( '~\.(' . $_extensions . ')$~', $result ) ) { |
@@ -1121,8 +1154,9 @@ discard block |
||
| 1121 | 1154 | * False if no textdomain was specified in the file headers, or if the domain could not be loaded. |
| 1122 | 1155 | */ |
| 1123 | 1156 | public function load_textdomain() { |
| 1124 | - if ( isset( $this->textdomain_loaded ) ) |
|
| 1125 | - return $this->textdomain_loaded; |
|
| 1157 | + if ( isset( $this->textdomain_loaded ) ) { |
|
| 1158 | + return $this->textdomain_loaded; |
|
| 1159 | + } |
|
| 1126 | 1160 | |
| 1127 | 1161 | $textdomain = $this->get('TextDomain'); |
| 1128 | 1162 | if ( ! $textdomain ) { |
@@ -1136,10 +1170,11 @@ discard block |
||
| 1136 | 1170 | } |
| 1137 | 1171 | |
| 1138 | 1172 | $path = $this->get_stylesheet_directory(); |
| 1139 | - if ( $domainpath = $this->get('DomainPath') ) |
|
| 1140 | - $path .= $domainpath; |
|
| 1141 | - else |
|
| 1142 | - $path .= '/languages'; |
|
| 1173 | + if ( $domainpath = $this->get('DomainPath') ) { |
|
| 1174 | + $path .= $domainpath; |
|
| 1175 | + } else { |
|
| 1176 | + $path .= '/languages'; |
|
| 1177 | + } |
|
| 1143 | 1178 | |
| 1144 | 1179 | $this->textdomain_loaded = load_theme_textdomain( $textdomain, $path ); |
| 1145 | 1180 | return $this->textdomain_loaded; |
@@ -1157,19 +1192,22 @@ discard block |
||
| 1157 | 1192 | * @return bool Whether the theme is allowed for the network. Returns true in single-site. |
| 1158 | 1193 | */ |
| 1159 | 1194 | public function is_allowed( $check = 'both', $blog_id = null ) { |
| 1160 | - if ( ! is_multisite() ) |
|
| 1161 | - return true; |
|
| 1195 | + if ( ! is_multisite() ) { |
|
| 1196 | + return true; |
|
| 1197 | + } |
|
| 1162 | 1198 | |
| 1163 | 1199 | if ( 'both' == $check || 'network' == $check ) { |
| 1164 | 1200 | $allowed = self::get_allowed_on_network(); |
| 1165 | - if ( ! empty( $allowed[ $this->get_stylesheet() ] ) ) |
|
| 1166 | - return true; |
|
| 1201 | + if ( ! empty( $allowed[ $this->get_stylesheet() ] ) ) { |
|
| 1202 | + return true; |
|
| 1203 | + } |
|
| 1167 | 1204 | } |
| 1168 | 1205 | |
| 1169 | 1206 | if ( 'both' == $check || 'site' == $check ) { |
| 1170 | 1207 | $allowed = self::get_allowed_on_site( $blog_id ); |
| 1171 | - if ( ! empty( $allowed[ $this->get_stylesheet() ] ) ) |
|
| 1172 | - return true; |
|
| 1208 | + if ( ! empty( $allowed[ $this->get_stylesheet() ] ) ) { |
|
| 1209 | + return true; |
|
| 1210 | + } |
|
| 1173 | 1211 | } |
| 1174 | 1212 | |
| 1175 | 1213 | return false; |
@@ -1265,8 +1303,9 @@ discard block |
||
| 1265 | 1303 | public static function get_allowed_on_site( $blog_id = null ) { |
| 1266 | 1304 | static $allowed_themes = array(); |
| 1267 | 1305 | |
| 1268 | - if ( ! $blog_id || ! is_multisite() ) |
|
| 1269 | - $blog_id = get_current_blog_id(); |
|
| 1306 | + if ( ! $blog_id || ! is_multisite() ) { |
|
| 1307 | + $blog_id = get_current_blog_id(); |
|
| 1308 | + } |
|
| 1270 | 1309 | |
| 1271 | 1310 | if ( isset( $allowed_themes[ $blog_id ] ) ) { |
| 1272 | 1311 | /** |
@@ -1307,8 +1346,9 @@ discard block |
||
| 1307 | 1346 | $converted = array(); |
| 1308 | 1347 | $themes = wp_get_themes(); |
| 1309 | 1348 | foreach ( $themes as $stylesheet => $theme_data ) { |
| 1310 | - if ( isset( $allowed_themes[ $blog_id ][ $theme_data->get('Name') ] ) ) |
|
| 1311 | - $converted[ $stylesheet ] = true; |
|
| 1349 | + if ( isset( $allowed_themes[ $blog_id ][ $theme_data->get('Name') ] ) ) { |
|
| 1350 | + $converted[ $stylesheet ] = true; |
|
| 1351 | + } |
|
| 1312 | 1352 | } |
| 1313 | 1353 | $allowed_themes[ $blog_id ] = $converted; |
| 1314 | 1354 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | function get_the_ID() { |
| 28 | 28 | $post = get_post(); |
| 29 | - return ! empty( $post ) ? $post->ID : false; |
|
| 29 | + return ! empty($post) ? $post->ID : false; |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | /** |
@@ -39,15 +39,15 @@ discard block |
||
| 39 | 39 | * @param bool $echo Optional, default to true.Whether to display or return. |
| 40 | 40 | * @return string|void String if $echo parameter is false. |
| 41 | 41 | */ |
| 42 | -function the_title( $before = '', $after = '', $echo = true ) { |
|
| 42 | +function the_title($before = '', $after = '', $echo = true) { |
|
| 43 | 43 | $title = get_the_title(); |
| 44 | 44 | |
| 45 | - if ( strlen($title) == 0 ) |
|
| 45 | + if (strlen($title) == 0) |
|
| 46 | 46 | return; |
| 47 | 47 | |
| 48 | - $title = $before . $title . $after; |
|
| 48 | + $title = $before.$title.$after; |
|
| 49 | 49 | |
| 50 | - if ( $echo ) |
|
| 50 | + if ($echo) |
|
| 51 | 51 | echo $title; |
| 52 | 52 | else |
| 53 | 53 | return $title; |
@@ -75,20 +75,20 @@ discard block |
||
| 75 | 75 | * } |
| 76 | 76 | * @return string|void String when echo is false. |
| 77 | 77 | */ |
| 78 | -function the_title_attribute( $args = '' ) { |
|
| 79 | - $defaults = array( 'before' => '', 'after' => '', 'echo' => true, 'post' => get_post() ); |
|
| 80 | - $r = wp_parse_args( $args, $defaults ); |
|
| 78 | +function the_title_attribute($args = '') { |
|
| 79 | + $defaults = array('before' => '', 'after' => '', 'echo' => true, 'post' => get_post()); |
|
| 80 | + $r = wp_parse_args($args, $defaults); |
|
| 81 | 81 | |
| 82 | - $title = get_the_title( $r['post'] ); |
|
| 82 | + $title = get_the_title($r['post']); |
|
| 83 | 83 | |
| 84 | - if ( strlen( $title ) == 0 ) { |
|
| 84 | + if (strlen($title) == 0) { |
|
| 85 | 85 | return; |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - $title = $r['before'] . $title . $r['after']; |
|
| 89 | - $title = esc_attr( strip_tags( $title ) ); |
|
| 88 | + $title = $r['before'].$title.$r['after']; |
|
| 89 | + $title = esc_attr(strip_tags($title)); |
|
| 90 | 90 | |
| 91 | - if ( $r['echo'] ) { |
|
| 91 | + if ($r['echo']) { |
|
| 92 | 92 | echo $title; |
| 93 | 93 | } else { |
| 94 | 94 | return $title; |
@@ -107,14 +107,14 @@ discard block |
||
| 107 | 107 | * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. |
| 108 | 108 | * @return string |
| 109 | 109 | */ |
| 110 | -function get_the_title( $post = 0 ) { |
|
| 111 | - $post = get_post( $post ); |
|
| 110 | +function get_the_title($post = 0) { |
|
| 111 | + $post = get_post($post); |
|
| 112 | 112 | |
| 113 | - $title = isset( $post->post_title ) ? $post->post_title : ''; |
|
| 114 | - $id = isset( $post->ID ) ? $post->ID : 0; |
|
| 113 | + $title = isset($post->post_title) ? $post->post_title : ''; |
|
| 114 | + $id = isset($post->ID) ? $post->ID : 0; |
|
| 115 | 115 | |
| 116 | - if ( ! is_admin() ) { |
|
| 117 | - if ( ! empty( $post->post_password ) ) { |
|
| 116 | + if ( ! is_admin()) { |
|
| 117 | + if ( ! empty($post->post_password)) { |
|
| 118 | 118 | |
| 119 | 119 | /** |
| 120 | 120 | * Filters the text prepended to the post title for protected posts. |
@@ -127,9 +127,9 @@ discard block |
||
| 127 | 127 | * Default 'Protected: %s'. |
| 128 | 128 | * @param WP_Post $post Current post object. |
| 129 | 129 | */ |
| 130 | - $protected_title_format = apply_filters( 'protected_title_format', __( 'Protected: %s' ), $post ); |
|
| 131 | - $title = sprintf( $protected_title_format, $title ); |
|
| 132 | - } elseif ( isset( $post->post_status ) && 'private' == $post->post_status ) { |
|
| 130 | + $protected_title_format = apply_filters('protected_title_format', __('Protected: %s'), $post); |
|
| 131 | + $title = sprintf($protected_title_format, $title); |
|
| 132 | + } elseif (isset($post->post_status) && 'private' == $post->post_status) { |
|
| 133 | 133 | |
| 134 | 134 | /** |
| 135 | 135 | * Filters the text prepended to the post title of private posts. |
@@ -142,8 +142,8 @@ discard block |
||
| 142 | 142 | * Default 'Private: %s'. |
| 143 | 143 | * @param WP_Post $post Current post object. |
| 144 | 144 | */ |
| 145 | - $private_title_format = apply_filters( 'private_title_format', __( 'Private: %s' ), $post ); |
|
| 146 | - $title = sprintf( $private_title_format, $title ); |
|
| 145 | + $private_title_format = apply_filters('private_title_format', __('Private: %s'), $post); |
|
| 146 | + $title = sprintf($private_title_format, $title); |
|
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | 149 | |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | * @param string $title The post title. |
| 156 | 156 | * @param int $id The post ID. |
| 157 | 157 | */ |
| 158 | - return apply_filters( 'the_title', $title, $id ); |
|
| 158 | + return apply_filters('the_title', $title, $id); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | /** |
@@ -171,11 +171,11 @@ discard block |
||
| 171 | 171 | * |
| 172 | 172 | * @param int|WP_Post $post Optional. Post ID or post object. Default is global $post. |
| 173 | 173 | */ |
| 174 | -function the_guid( $post = 0 ) { |
|
| 175 | - $post = get_post( $post ); |
|
| 174 | +function the_guid($post = 0) { |
|
| 175 | + $post = get_post($post); |
|
| 176 | 176 | |
| 177 | - $guid = isset( $post->guid ) ? get_the_guid( $post ) : ''; |
|
| 178 | - $id = isset( $post->ID ) ? $post->ID : 0; |
|
| 177 | + $guid = isset($post->guid) ? get_the_guid($post) : ''; |
|
| 178 | + $id = isset($post->ID) ? $post->ID : 0; |
|
| 179 | 179 | |
| 180 | 180 | /** |
| 181 | 181 | * Filters the escaped Global Unique Identifier (guid) of the post. |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | * @param string $guid Escaped Global Unique Identifier (guid) of the post. |
| 188 | 188 | * @param int $id The post ID. |
| 189 | 189 | */ |
| 190 | - echo apply_filters( 'the_guid', $guid, $id ); |
|
| 190 | + echo apply_filters('the_guid', $guid, $id); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | /** |
@@ -202,11 +202,11 @@ discard block |
||
| 202 | 202 | * @param int|WP_Post $post Optional. Post ID or post object. Default is global $post. |
| 203 | 203 | * @return string |
| 204 | 204 | */ |
| 205 | -function get_the_guid( $post = 0 ) { |
|
| 206 | - $post = get_post( $post ); |
|
| 205 | +function get_the_guid($post = 0) { |
|
| 206 | + $post = get_post($post); |
|
| 207 | 207 | |
| 208 | - $guid = isset( $post->guid ) ? $post->guid : ''; |
|
| 209 | - $id = isset( $post->ID ) ? $post->ID : 0; |
|
| 208 | + $guid = isset($post->guid) ? $post->guid : ''; |
|
| 209 | + $id = isset($post->ID) ? $post->ID : 0; |
|
| 210 | 210 | |
| 211 | 211 | /** |
| 212 | 212 | * Filters the Global Unique Identifier (guid) of the post. |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | * @param string $guid Global Unique Identifier (guid) of the post. |
| 217 | 217 | * @param int $id The post ID. |
| 218 | 218 | */ |
| 219 | - return apply_filters( 'get_the_guid', $guid, $id ); |
|
| 219 | + return apply_filters('get_the_guid', $guid, $id); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -227,8 +227,8 @@ discard block |
||
| 227 | 227 | * @param string $more_link_text Optional. Content for when there is more text. |
| 228 | 228 | * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false. |
| 229 | 229 | */ |
| 230 | -function the_content( $more_link_text = null, $strip_teaser = false) { |
|
| 231 | - $content = get_the_content( $more_link_text, $strip_teaser ); |
|
| 230 | +function the_content($more_link_text = null, $strip_teaser = false) { |
|
| 231 | + $content = get_the_content($more_link_text, $strip_teaser); |
|
| 232 | 232 | |
| 233 | 233 | /** |
| 234 | 234 | * Filters the post content. |
@@ -237,8 +237,8 @@ discard block |
||
| 237 | 237 | * |
| 238 | 238 | * @param string $content Content of the current post. |
| 239 | 239 | */ |
| 240 | - $content = apply_filters( 'the_content', $content ); |
|
| 241 | - $content = str_replace( ']]>', ']]>', $content ); |
|
| 240 | + $content = apply_filters('the_content', $content); |
|
| 241 | + $content = str_replace(']]>', ']]>', $content); |
|
| 242 | 242 | echo $content; |
| 243 | 243 | } |
| 244 | 244 | |
@@ -257,20 +257,20 @@ discard block |
||
| 257 | 257 | * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false. |
| 258 | 258 | * @return string |
| 259 | 259 | */ |
| 260 | -function get_the_content( $more_link_text = null, $strip_teaser = false ) { |
|
| 260 | +function get_the_content($more_link_text = null, $strip_teaser = false) { |
|
| 261 | 261 | global $page, $more, $preview, $pages, $multipage; |
| 262 | 262 | |
| 263 | 263 | $post = get_post(); |
| 264 | 264 | |
| 265 | - if ( null === $more_link_text ) { |
|
| 265 | + if (null === $more_link_text) { |
|
| 266 | 266 | $more_link_text = sprintf( |
| 267 | 267 | '<span aria-label="%1$s">%2$s</span>', |
| 268 | 268 | sprintf( |
| 269 | 269 | /* translators: %s: Name of current post */ |
| 270 | - __( 'Continue reading %s' ), |
|
| 271 | - the_title_attribute( array( 'echo' => false ) ) |
|
| 270 | + __('Continue reading %s'), |
|
| 271 | + the_title_attribute(array('echo' => false)) |
|
| 272 | 272 | ), |
| 273 | - __( '(more…)' ) |
|
| 273 | + __('(more…)') |
|
| 274 | 274 | ); |
| 275 | 275 | } |
| 276 | 276 | |
@@ -278,38 +278,38 @@ discard block |
||
| 278 | 278 | $has_teaser = false; |
| 279 | 279 | |
| 280 | 280 | // If post password required and it doesn't match the cookie. |
| 281 | - if ( post_password_required( $post ) ) |
|
| 282 | - return get_the_password_form( $post ); |
|
| 281 | + if (post_password_required($post)) |
|
| 282 | + return get_the_password_form($post); |
|
| 283 | 283 | |
| 284 | - if ( $page > count( $pages ) ) // if the requested page doesn't exist |
|
| 285 | - $page = count( $pages ); // give them the highest numbered page that DOES exist |
|
| 284 | + if ($page > count($pages)) // if the requested page doesn't exist |
|
| 285 | + $page = count($pages); // give them the highest numbered page that DOES exist |
|
| 286 | 286 | |
| 287 | 287 | $content = $pages[$page - 1]; |
| 288 | - if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) { |
|
| 289 | - $content = explode( $matches[0], $content, 2 ); |
|
| 290 | - if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) ) |
|
| 291 | - $more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) ); |
|
| 288 | + if (preg_match('/<!--more(.*?)?-->/', $content, $matches)) { |
|
| 289 | + $content = explode($matches[0], $content, 2); |
|
| 290 | + if ( ! empty($matches[1]) && ! empty($more_link_text)) |
|
| 291 | + $more_link_text = strip_tags(wp_kses_no_null(trim($matches[1]))); |
|
| 292 | 292 | |
| 293 | 293 | $has_teaser = true; |
| 294 | 294 | } else { |
| 295 | - $content = array( $content ); |
|
| 295 | + $content = array($content); |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | - if ( false !== strpos( $post->post_content, '<!--noteaser-->' ) && ( ! $multipage || $page == 1 ) ) |
|
| 298 | + if (false !== strpos($post->post_content, '<!--noteaser-->') && ( ! $multipage || $page == 1)) |
|
| 299 | 299 | $strip_teaser = true; |
| 300 | 300 | |
| 301 | 301 | $teaser = $content[0]; |
| 302 | 302 | |
| 303 | - if ( $more && $strip_teaser && $has_teaser ) |
|
| 303 | + if ($more && $strip_teaser && $has_teaser) |
|
| 304 | 304 | $teaser = ''; |
| 305 | 305 | |
| 306 | 306 | $output .= $teaser; |
| 307 | 307 | |
| 308 | - if ( count( $content ) > 1 ) { |
|
| 309 | - if ( $more ) { |
|
| 310 | - $output .= '<span id="more-' . $post->ID . '"></span>' . $content[1]; |
|
| 308 | + if (count($content) > 1) { |
|
| 309 | + if ($more) { |
|
| 310 | + $output .= '<span id="more-'.$post->ID.'"></span>'.$content[1]; |
|
| 311 | 311 | } else { |
| 312 | - if ( ! empty( $more_link_text ) ) |
|
| 312 | + if ( ! empty($more_link_text)) |
|
| 313 | 313 | |
| 314 | 314 | /** |
| 315 | 315 | * Filters the Read More link text. |
@@ -319,13 +319,13 @@ discard block |
||
| 319 | 319 | * @param string $more_link_element Read More link element. |
| 320 | 320 | * @param string $more_link_text Read More text. |
| 321 | 321 | */ |
| 322 | - $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-{$post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text ); |
|
| 323 | - $output = force_balance_tags( $output ); |
|
| 322 | + $output .= apply_filters('the_content_more_link', ' <a href="'.get_permalink()."#more-{$post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text); |
|
| 323 | + $output = force_balance_tags($output); |
|
| 324 | 324 | } |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | - if ( $preview ) // Preview fix for JavaScript bug with foreign languages. |
|
| 328 | - $output = preg_replace_callback( '/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output ); |
|
| 327 | + if ($preview) // Preview fix for JavaScript bug with foreign languages. |
|
| 328 | + $output = preg_replace_callback('/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output); |
|
| 329 | 329 | |
| 330 | 330 | return $output; |
| 331 | 331 | } |
@@ -339,8 +339,8 @@ discard block |
||
| 339 | 339 | * @param array $match Match array from preg_replace_callback. |
| 340 | 340 | * @return string |
| 341 | 341 | */ |
| 342 | -function _convert_urlencoded_to_entities( $match ) { |
|
| 343 | - return '&#' . base_convert( $match[1], 16, 10 ) . ';'; |
|
| 342 | +function _convert_urlencoded_to_entities($match) { |
|
| 343 | + return '&#'.base_convert($match[1], 16, 10).';'; |
|
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | /** |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | * |
| 360 | 360 | * @param string $post_excerpt The post excerpt. |
| 361 | 361 | */ |
| 362 | - echo apply_filters( 'the_excerpt', get_the_excerpt() ); |
|
| 362 | + echo apply_filters('the_excerpt', get_the_excerpt()); |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | /** |
@@ -371,18 +371,18 @@ discard block |
||
| 371 | 371 | * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. |
| 372 | 372 | * @return string Post excerpt. |
| 373 | 373 | */ |
| 374 | -function get_the_excerpt( $post = null ) { |
|
| 375 | - if ( is_bool( $post ) ) { |
|
| 376 | - _deprecated_argument( __FUNCTION__, '2.3.0' ); |
|
| 374 | +function get_the_excerpt($post = null) { |
|
| 375 | + if (is_bool($post)) { |
|
| 376 | + _deprecated_argument(__FUNCTION__, '2.3.0'); |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - $post = get_post( $post ); |
|
| 380 | - if ( empty( $post ) ) { |
|
| 379 | + $post = get_post($post); |
|
| 380 | + if (empty($post)) { |
|
| 381 | 381 | return ''; |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | - if ( post_password_required( $post ) ) { |
|
| 385 | - return __( 'There is no excerpt because this is a protected post.' ); |
|
| 384 | + if (post_password_required($post)) { |
|
| 385 | + return __('There is no excerpt because this is a protected post.'); |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | /** |
@@ -394,7 +394,7 @@ discard block |
||
| 394 | 394 | * @param string $post_excerpt The post excerpt. |
| 395 | 395 | * @param WP_Post $post Post object. |
| 396 | 396 | */ |
| 397 | - return apply_filters( 'get_the_excerpt', $post->post_excerpt, $post ); |
|
| 397 | + return apply_filters('get_the_excerpt', $post->post_excerpt, $post); |
|
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | /** |
@@ -405,9 +405,9 @@ discard block |
||
| 405 | 405 | * @param int|WP_Post $id Optional. Post ID or post object. |
| 406 | 406 | * @return bool |
| 407 | 407 | */ |
| 408 | -function has_excerpt( $id = 0 ) { |
|
| 409 | - $post = get_post( $id ); |
|
| 410 | - return ( !empty( $post->post_excerpt ) ); |
|
| 408 | +function has_excerpt($id = 0) { |
|
| 409 | + $post = get_post($id); |
|
| 410 | + return ( ! empty($post->post_excerpt)); |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | /** |
@@ -418,9 +418,9 @@ discard block |
||
| 418 | 418 | * @param string|array $class One or more classes to add to the class list. |
| 419 | 419 | * @param int|WP_Post $post_id Optional. Post ID or post object. Defaults to the global `$post`. |
| 420 | 420 | */ |
| 421 | -function post_class( $class = '', $post_id = null ) { |
|
| 421 | +function post_class($class = '', $post_id = null) { |
|
| 422 | 422 | // Separates classes with a single space, collates classes for post DIV |
| 423 | - echo 'class="' . join( ' ', get_post_class( $class, $post_id ) ) . '"'; |
|
| 423 | + echo 'class="'.join(' ', get_post_class($class, $post_id)).'"'; |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | /** |
@@ -444,60 +444,60 @@ discard block |
||
| 444 | 444 | * @param int|WP_Post $post_id Optional. Post ID or post object. |
| 445 | 445 | * @return array Array of classes. |
| 446 | 446 | */ |
| 447 | -function get_post_class( $class = '', $post_id = null ) { |
|
| 448 | - $post = get_post( $post_id ); |
|
| 447 | +function get_post_class($class = '', $post_id = null) { |
|
| 448 | + $post = get_post($post_id); |
|
| 449 | 449 | |
| 450 | 450 | $classes = array(); |
| 451 | 451 | |
| 452 | - if ( $class ) { |
|
| 453 | - if ( ! is_array( $class ) ) { |
|
| 454 | - $class = preg_split( '#\s+#', $class ); |
|
| 452 | + if ($class) { |
|
| 453 | + if ( ! is_array($class)) { |
|
| 454 | + $class = preg_split('#\s+#', $class); |
|
| 455 | 455 | } |
| 456 | - $classes = array_map( 'esc_attr', $class ); |
|
| 456 | + $classes = array_map('esc_attr', $class); |
|
| 457 | 457 | } else { |
| 458 | 458 | // Ensure that we always coerce class to being an array. |
| 459 | 459 | $class = array(); |
| 460 | 460 | } |
| 461 | 461 | |
| 462 | - if ( ! $post ) { |
|
| 462 | + if ( ! $post) { |
|
| 463 | 463 | return $classes; |
| 464 | 464 | } |
| 465 | 465 | |
| 466 | - $classes[] = 'post-' . $post->ID; |
|
| 467 | - if ( ! is_admin() ) |
|
| 466 | + $classes[] = 'post-'.$post->ID; |
|
| 467 | + if ( ! is_admin()) |
|
| 468 | 468 | $classes[] = $post->post_type; |
| 469 | - $classes[] = 'type-' . $post->post_type; |
|
| 470 | - $classes[] = 'status-' . $post->post_status; |
|
| 469 | + $classes[] = 'type-'.$post->post_type; |
|
| 470 | + $classes[] = 'status-'.$post->post_status; |
|
| 471 | 471 | |
| 472 | 472 | // Post Format |
| 473 | - if ( post_type_supports( $post->post_type, 'post-formats' ) ) { |
|
| 474 | - $post_format = get_post_format( $post->ID ); |
|
| 473 | + if (post_type_supports($post->post_type, 'post-formats')) { |
|
| 474 | + $post_format = get_post_format($post->ID); |
|
| 475 | 475 | |
| 476 | - if ( $post_format && !is_wp_error($post_format) ) |
|
| 477 | - $classes[] = 'format-' . sanitize_html_class( $post_format ); |
|
| 476 | + if ($post_format && ! is_wp_error($post_format)) |
|
| 477 | + $classes[] = 'format-'.sanitize_html_class($post_format); |
|
| 478 | 478 | else |
| 479 | 479 | $classes[] = 'format-standard'; |
| 480 | 480 | } |
| 481 | 481 | |
| 482 | - $post_password_required = post_password_required( $post->ID ); |
|
| 482 | + $post_password_required = post_password_required($post->ID); |
|
| 483 | 483 | |
| 484 | 484 | // Post requires password. |
| 485 | - if ( $post_password_required ) { |
|
| 485 | + if ($post_password_required) { |
|
| 486 | 486 | $classes[] = 'post-password-required'; |
| 487 | - } elseif ( ! empty( $post->post_password ) ) { |
|
| 487 | + } elseif ( ! empty($post->post_password)) { |
|
| 488 | 488 | $classes[] = 'post-password-protected'; |
| 489 | 489 | } |
| 490 | 490 | |
| 491 | 491 | // Post thumbnails. |
| 492 | - if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $post->ID ) && ! is_attachment( $post ) && ! $post_password_required ) { |
|
| 492 | + if (current_theme_supports('post-thumbnails') && has_post_thumbnail($post->ID) && ! is_attachment($post) && ! $post_password_required) { |
|
| 493 | 493 | $classes[] = 'has-post-thumbnail'; |
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | // sticky for Sticky Posts |
| 497 | - if ( is_sticky( $post->ID ) ) { |
|
| 498 | - if ( is_home() && ! is_paged() ) { |
|
| 497 | + if (is_sticky($post->ID)) { |
|
| 498 | + if (is_home() && ! is_paged()) { |
|
| 499 | 499 | $classes[] = 'sticky'; |
| 500 | - } elseif ( is_admin() ) { |
|
| 500 | + } elseif (is_admin()) { |
|
| 501 | 501 | $classes[] = 'status-sticky'; |
| 502 | 502 | } |
| 503 | 503 | } |
@@ -506,30 +506,30 @@ discard block |
||
| 506 | 506 | $classes[] = 'hentry'; |
| 507 | 507 | |
| 508 | 508 | // All public taxonomies |
| 509 | - $taxonomies = get_taxonomies( array( 'public' => true ) ); |
|
| 510 | - foreach ( (array) $taxonomies as $taxonomy ) { |
|
| 511 | - if ( is_object_in_taxonomy( $post->post_type, $taxonomy ) ) { |
|
| 512 | - foreach ( (array) get_the_terms( $post->ID, $taxonomy ) as $term ) { |
|
| 513 | - if ( empty( $term->slug ) ) { |
|
| 509 | + $taxonomies = get_taxonomies(array('public' => true)); |
|
| 510 | + foreach ((array) $taxonomies as $taxonomy) { |
|
| 511 | + if (is_object_in_taxonomy($post->post_type, $taxonomy)) { |
|
| 512 | + foreach ((array) get_the_terms($post->ID, $taxonomy) as $term) { |
|
| 513 | + if (empty($term->slug)) { |
|
| 514 | 514 | continue; |
| 515 | 515 | } |
| 516 | 516 | |
| 517 | - $term_class = sanitize_html_class( $term->slug, $term->term_id ); |
|
| 518 | - if ( is_numeric( $term_class ) || ! trim( $term_class, '-' ) ) { |
|
| 517 | + $term_class = sanitize_html_class($term->slug, $term->term_id); |
|
| 518 | + if (is_numeric($term_class) || ! trim($term_class, '-')) { |
|
| 519 | 519 | $term_class = $term->term_id; |
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | // 'post_tag' uses the 'tag' prefix for backward compatibility. |
| 523 | - if ( 'post_tag' == $taxonomy ) { |
|
| 524 | - $classes[] = 'tag-' . $term_class; |
|
| 523 | + if ('post_tag' == $taxonomy) { |
|
| 524 | + $classes[] = 'tag-'.$term_class; |
|
| 525 | 525 | } else { |
| 526 | - $classes[] = sanitize_html_class( $taxonomy . '-' . $term_class, $taxonomy . '-' . $term->term_id ); |
|
| 526 | + $classes[] = sanitize_html_class($taxonomy.'-'.$term_class, $taxonomy.'-'.$term->term_id); |
|
| 527 | 527 | } |
| 528 | 528 | } |
| 529 | 529 | } |
| 530 | 530 | } |
| 531 | 531 | |
| 532 | - $classes = array_map( 'esc_attr', $classes ); |
|
| 532 | + $classes = array_map('esc_attr', $classes); |
|
| 533 | 533 | |
| 534 | 534 | /** |
| 535 | 535 | * Filters the list of CSS classes for the current post. |
@@ -540,9 +540,9 @@ discard block |
||
| 540 | 540 | * @param array $class An array of additional classes added to the post. |
| 541 | 541 | * @param int $post_id The post ID. |
| 542 | 542 | */ |
| 543 | - $classes = apply_filters( 'post_class', $classes, $class, $post->ID ); |
|
| 543 | + $classes = apply_filters('post_class', $classes, $class, $post->ID); |
|
| 544 | 544 | |
| 545 | - return array_unique( $classes ); |
|
| 545 | + return array_unique($classes); |
|
| 546 | 546 | } |
| 547 | 547 | |
| 548 | 548 | /** |
@@ -552,9 +552,9 @@ discard block |
||
| 552 | 552 | * |
| 553 | 553 | * @param string|array $class One or more classes to add to the class list. |
| 554 | 554 | */ |
| 555 | -function body_class( $class = '' ) { |
|
| 555 | +function body_class($class = '') { |
|
| 556 | 556 | // Separates classes with a single space, collates classes for body element |
| 557 | - echo 'class="' . join( ' ', get_body_class( $class ) ) . '"'; |
|
| 557 | + echo 'class="'.join(' ', get_body_class($class)).'"'; |
|
| 558 | 558 | } |
| 559 | 559 | |
| 560 | 560 | /** |
@@ -567,193 +567,193 @@ discard block |
||
| 567 | 567 | * @param string|array $class One or more classes to add to the class list. |
| 568 | 568 | * @return array Array of classes. |
| 569 | 569 | */ |
| 570 | -function get_body_class( $class = '' ) { |
|
| 570 | +function get_body_class($class = '') { |
|
| 571 | 571 | global $wp_query; |
| 572 | 572 | |
| 573 | 573 | $classes = array(); |
| 574 | 574 | |
| 575 | - if ( is_rtl() ) |
|
| 575 | + if (is_rtl()) |
|
| 576 | 576 | $classes[] = 'rtl'; |
| 577 | 577 | |
| 578 | - if ( is_front_page() ) |
|
| 578 | + if (is_front_page()) |
|
| 579 | 579 | $classes[] = 'home'; |
| 580 | - if ( is_home() ) |
|
| 580 | + if (is_home()) |
|
| 581 | 581 | $classes[] = 'blog'; |
| 582 | - if ( is_archive() ) |
|
| 582 | + if (is_archive()) |
|
| 583 | 583 | $classes[] = 'archive'; |
| 584 | - if ( is_date() ) |
|
| 584 | + if (is_date()) |
|
| 585 | 585 | $classes[] = 'date'; |
| 586 | - if ( is_search() ) { |
|
| 586 | + if (is_search()) { |
|
| 587 | 587 | $classes[] = 'search'; |
| 588 | 588 | $classes[] = $wp_query->posts ? 'search-results' : 'search-no-results'; |
| 589 | 589 | } |
| 590 | - if ( is_paged() ) |
|
| 590 | + if (is_paged()) |
|
| 591 | 591 | $classes[] = 'paged'; |
| 592 | - if ( is_attachment() ) |
|
| 592 | + if (is_attachment()) |
|
| 593 | 593 | $classes[] = 'attachment'; |
| 594 | - if ( is_404() ) |
|
| 594 | + if (is_404()) |
|
| 595 | 595 | $classes[] = 'error404'; |
| 596 | 596 | |
| 597 | - if ( is_single() ) { |
|
| 597 | + if (is_single()) { |
|
| 598 | 598 | $post_id = $wp_query->get_queried_object_id(); |
| 599 | 599 | $post = $wp_query->get_queried_object(); |
| 600 | 600 | |
| 601 | 601 | $classes[] = 'single'; |
| 602 | - if ( isset( $post->post_type ) ) { |
|
| 603 | - $classes[] = 'single-' . sanitize_html_class($post->post_type, $post_id); |
|
| 604 | - $classes[] = 'postid-' . $post_id; |
|
| 602 | + if (isset($post->post_type)) { |
|
| 603 | + $classes[] = 'single-'.sanitize_html_class($post->post_type, $post_id); |
|
| 604 | + $classes[] = 'postid-'.$post_id; |
|
| 605 | 605 | |
| 606 | 606 | // Post Format |
| 607 | - if ( post_type_supports( $post->post_type, 'post-formats' ) ) { |
|
| 608 | - $post_format = get_post_format( $post->ID ); |
|
| 607 | + if (post_type_supports($post->post_type, 'post-formats')) { |
|
| 608 | + $post_format = get_post_format($post->ID); |
|
| 609 | 609 | |
| 610 | - if ( $post_format && !is_wp_error($post_format) ) |
|
| 611 | - $classes[] = 'single-format-' . sanitize_html_class( $post_format ); |
|
| 610 | + if ($post_format && ! is_wp_error($post_format)) |
|
| 611 | + $classes[] = 'single-format-'.sanitize_html_class($post_format); |
|
| 612 | 612 | else |
| 613 | 613 | $classes[] = 'single-format-standard'; |
| 614 | 614 | } |
| 615 | 615 | } |
| 616 | 616 | |
| 617 | - if ( is_attachment() ) { |
|
| 617 | + if (is_attachment()) { |
|
| 618 | 618 | $mime_type = get_post_mime_type($post_id); |
| 619 | - $mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' ); |
|
| 620 | - $classes[] = 'attachmentid-' . $post_id; |
|
| 621 | - $classes[] = 'attachment-' . str_replace( $mime_prefix, '', $mime_type ); |
|
| 619 | + $mime_prefix = array('application/', 'image/', 'text/', 'audio/', 'video/', 'music/'); |
|
| 620 | + $classes[] = 'attachmentid-'.$post_id; |
|
| 621 | + $classes[] = 'attachment-'.str_replace($mime_prefix, '', $mime_type); |
|
| 622 | 622 | } |
| 623 | - } elseif ( is_archive() ) { |
|
| 624 | - if ( is_post_type_archive() ) { |
|
| 623 | + } elseif (is_archive()) { |
|
| 624 | + if (is_post_type_archive()) { |
|
| 625 | 625 | $classes[] = 'post-type-archive'; |
| 626 | - $post_type = get_query_var( 'post_type' ); |
|
| 627 | - if ( is_array( $post_type ) ) |
|
| 628 | - $post_type = reset( $post_type ); |
|
| 629 | - $classes[] = 'post-type-archive-' . sanitize_html_class( $post_type ); |
|
| 630 | - } elseif ( is_author() ) { |
|
| 626 | + $post_type = get_query_var('post_type'); |
|
| 627 | + if (is_array($post_type)) |
|
| 628 | + $post_type = reset($post_type); |
|
| 629 | + $classes[] = 'post-type-archive-'.sanitize_html_class($post_type); |
|
| 630 | + } elseif (is_author()) { |
|
| 631 | 631 | $author = $wp_query->get_queried_object(); |
| 632 | 632 | $classes[] = 'author'; |
| 633 | - if ( isset( $author->user_nicename ) ) { |
|
| 634 | - $classes[] = 'author-' . sanitize_html_class( $author->user_nicename, $author->ID ); |
|
| 635 | - $classes[] = 'author-' . $author->ID; |
|
| 633 | + if (isset($author->user_nicename)) { |
|
| 634 | + $classes[] = 'author-'.sanitize_html_class($author->user_nicename, $author->ID); |
|
| 635 | + $classes[] = 'author-'.$author->ID; |
|
| 636 | 636 | } |
| 637 | - } elseif ( is_category() ) { |
|
| 637 | + } elseif (is_category()) { |
|
| 638 | 638 | $cat = $wp_query->get_queried_object(); |
| 639 | 639 | $classes[] = 'category'; |
| 640 | - if ( isset( $cat->term_id ) ) { |
|
| 641 | - $cat_class = sanitize_html_class( $cat->slug, $cat->term_id ); |
|
| 642 | - if ( is_numeric( $cat_class ) || ! trim( $cat_class, '-' ) ) { |
|
| 640 | + if (isset($cat->term_id)) { |
|
| 641 | + $cat_class = sanitize_html_class($cat->slug, $cat->term_id); |
|
| 642 | + if (is_numeric($cat_class) || ! trim($cat_class, '-')) { |
|
| 643 | 643 | $cat_class = $cat->term_id; |
| 644 | 644 | } |
| 645 | 645 | |
| 646 | - $classes[] = 'category-' . $cat_class; |
|
| 647 | - $classes[] = 'category-' . $cat->term_id; |
|
| 646 | + $classes[] = 'category-'.$cat_class; |
|
| 647 | + $classes[] = 'category-'.$cat->term_id; |
|
| 648 | 648 | } |
| 649 | - } elseif ( is_tag() ) { |
|
| 649 | + } elseif (is_tag()) { |
|
| 650 | 650 | $tag = $wp_query->get_queried_object(); |
| 651 | 651 | $classes[] = 'tag'; |
| 652 | - if ( isset( $tag->term_id ) ) { |
|
| 653 | - $tag_class = sanitize_html_class( $tag->slug, $tag->term_id ); |
|
| 654 | - if ( is_numeric( $tag_class ) || ! trim( $tag_class, '-' ) ) { |
|
| 652 | + if (isset($tag->term_id)) { |
|
| 653 | + $tag_class = sanitize_html_class($tag->slug, $tag->term_id); |
|
| 654 | + if (is_numeric($tag_class) || ! trim($tag_class, '-')) { |
|
| 655 | 655 | $tag_class = $tag->term_id; |
| 656 | 656 | } |
| 657 | 657 | |
| 658 | - $classes[] = 'tag-' . $tag_class; |
|
| 659 | - $classes[] = 'tag-' . $tag->term_id; |
|
| 658 | + $classes[] = 'tag-'.$tag_class; |
|
| 659 | + $classes[] = 'tag-'.$tag->term_id; |
|
| 660 | 660 | } |
| 661 | - } elseif ( is_tax() ) { |
|
| 661 | + } elseif (is_tax()) { |
|
| 662 | 662 | $term = $wp_query->get_queried_object(); |
| 663 | - if ( isset( $term->term_id ) ) { |
|
| 664 | - $term_class = sanitize_html_class( $term->slug, $term->term_id ); |
|
| 665 | - if ( is_numeric( $term_class ) || ! trim( $term_class, '-' ) ) { |
|
| 663 | + if (isset($term->term_id)) { |
|
| 664 | + $term_class = sanitize_html_class($term->slug, $term->term_id); |
|
| 665 | + if (is_numeric($term_class) || ! trim($term_class, '-')) { |
|
| 666 | 666 | $term_class = $term->term_id; |
| 667 | 667 | } |
| 668 | 668 | |
| 669 | - $classes[] = 'tax-' . sanitize_html_class( $term->taxonomy ); |
|
| 670 | - $classes[] = 'term-' . $term_class; |
|
| 671 | - $classes[] = 'term-' . $term->term_id; |
|
| 669 | + $classes[] = 'tax-'.sanitize_html_class($term->taxonomy); |
|
| 670 | + $classes[] = 'term-'.$term_class; |
|
| 671 | + $classes[] = 'term-'.$term->term_id; |
|
| 672 | 672 | } |
| 673 | 673 | } |
| 674 | - } elseif ( is_page() ) { |
|
| 674 | + } elseif (is_page()) { |
|
| 675 | 675 | $classes[] = 'page'; |
| 676 | 676 | |
| 677 | 677 | $page_id = $wp_query->get_queried_object_id(); |
| 678 | 678 | |
| 679 | 679 | $post = get_post($page_id); |
| 680 | 680 | |
| 681 | - $classes[] = 'page-id-' . $page_id; |
|
| 681 | + $classes[] = 'page-id-'.$page_id; |
|
| 682 | 682 | |
| 683 | - if ( get_pages( array( 'parent' => $page_id, 'number' => 1 ) ) ) { |
|
| 683 | + if (get_pages(array('parent' => $page_id, 'number' => 1))) { |
|
| 684 | 684 | $classes[] = 'page-parent'; |
| 685 | 685 | } |
| 686 | 686 | |
| 687 | - if ( $post->post_parent ) { |
|
| 687 | + if ($post->post_parent) { |
|
| 688 | 688 | $classes[] = 'page-child'; |
| 689 | - $classes[] = 'parent-pageid-' . $post->post_parent; |
|
| 689 | + $classes[] = 'parent-pageid-'.$post->post_parent; |
|
| 690 | 690 | } |
| 691 | - if ( is_page_template() ) { |
|
| 691 | + if (is_page_template()) { |
|
| 692 | 692 | $classes[] = 'page-template'; |
| 693 | 693 | |
| 694 | - $template_slug = get_page_template_slug( $page_id ); |
|
| 695 | - $template_parts = explode( '/', $template_slug ); |
|
| 694 | + $template_slug = get_page_template_slug($page_id); |
|
| 695 | + $template_parts = explode('/', $template_slug); |
|
| 696 | 696 | |
| 697 | - foreach ( $template_parts as $part ) { |
|
| 698 | - $classes[] = 'page-template-' . sanitize_html_class( str_replace( array( '.', '/' ), '-', basename( $part, '.php' ) ) ); |
|
| 697 | + foreach ($template_parts as $part) { |
|
| 698 | + $classes[] = 'page-template-'.sanitize_html_class(str_replace(array('.', '/'), '-', basename($part, '.php'))); |
|
| 699 | 699 | } |
| 700 | - $classes[] = 'page-template-' . sanitize_html_class( str_replace( '.', '-', $template_slug ) ); |
|
| 700 | + $classes[] = 'page-template-'.sanitize_html_class(str_replace('.', '-', $template_slug)); |
|
| 701 | 701 | } else { |
| 702 | 702 | $classes[] = 'page-template-default'; |
| 703 | 703 | } |
| 704 | 704 | } |
| 705 | 705 | |
| 706 | - if ( is_user_logged_in() ) |
|
| 706 | + if (is_user_logged_in()) |
|
| 707 | 707 | $classes[] = 'logged-in'; |
| 708 | 708 | |
| 709 | - if ( is_admin_bar_showing() ) { |
|
| 709 | + if (is_admin_bar_showing()) { |
|
| 710 | 710 | $classes[] = 'admin-bar'; |
| 711 | 711 | $classes[] = 'no-customize-support'; |
| 712 | 712 | } |
| 713 | 713 | |
| 714 | - if ( get_background_color() !== get_theme_support( 'custom-background', 'default-color' ) || get_background_image() ) |
|
| 714 | + if (get_background_color() !== get_theme_support('custom-background', 'default-color') || get_background_image()) |
|
| 715 | 715 | $classes[] = 'custom-background'; |
| 716 | 716 | |
| 717 | - if ( has_custom_logo() ) { |
|
| 717 | + if (has_custom_logo()) { |
|
| 718 | 718 | $classes[] = 'wp-custom-logo'; |
| 719 | 719 | } |
| 720 | 720 | |
| 721 | - $page = $wp_query->get( 'page' ); |
|
| 722 | - |
|
| 723 | - if ( ! $page || $page < 2 ) |
|
| 724 | - $page = $wp_query->get( 'paged' ); |
|
| 725 | - |
|
| 726 | - if ( $page && $page > 1 && ! is_404() ) { |
|
| 727 | - $classes[] = 'paged-' . $page; |
|
| 728 | - |
|
| 729 | - if ( is_single() ) |
|
| 730 | - $classes[] = 'single-paged-' . $page; |
|
| 731 | - elseif ( is_page() ) |
|
| 732 | - $classes[] = 'page-paged-' . $page; |
|
| 733 | - elseif ( is_category() ) |
|
| 734 | - $classes[] = 'category-paged-' . $page; |
|
| 735 | - elseif ( is_tag() ) |
|
| 736 | - $classes[] = 'tag-paged-' . $page; |
|
| 737 | - elseif ( is_date() ) |
|
| 738 | - $classes[] = 'date-paged-' . $page; |
|
| 739 | - elseif ( is_author() ) |
|
| 740 | - $classes[] = 'author-paged-' . $page; |
|
| 741 | - elseif ( is_search() ) |
|
| 742 | - $classes[] = 'search-paged-' . $page; |
|
| 743 | - elseif ( is_post_type_archive() ) |
|
| 744 | - $classes[] = 'post-type-paged-' . $page; |
|
| 721 | + $page = $wp_query->get('page'); |
|
| 722 | + |
|
| 723 | + if ( ! $page || $page < 2) |
|
| 724 | + $page = $wp_query->get('paged'); |
|
| 725 | + |
|
| 726 | + if ($page && $page > 1 && ! is_404()) { |
|
| 727 | + $classes[] = 'paged-'.$page; |
|
| 728 | + |
|
| 729 | + if (is_single()) |
|
| 730 | + $classes[] = 'single-paged-'.$page; |
|
| 731 | + elseif (is_page()) |
|
| 732 | + $classes[] = 'page-paged-'.$page; |
|
| 733 | + elseif (is_category()) |
|
| 734 | + $classes[] = 'category-paged-'.$page; |
|
| 735 | + elseif (is_tag()) |
|
| 736 | + $classes[] = 'tag-paged-'.$page; |
|
| 737 | + elseif (is_date()) |
|
| 738 | + $classes[] = 'date-paged-'.$page; |
|
| 739 | + elseif (is_author()) |
|
| 740 | + $classes[] = 'author-paged-'.$page; |
|
| 741 | + elseif (is_search()) |
|
| 742 | + $classes[] = 'search-paged-'.$page; |
|
| 743 | + elseif (is_post_type_archive()) |
|
| 744 | + $classes[] = 'post-type-paged-'.$page; |
|
| 745 | 745 | } |
| 746 | 746 | |
| 747 | - if ( ! empty( $class ) ) { |
|
| 748 | - if ( !is_array( $class ) ) |
|
| 749 | - $class = preg_split( '#\s+#', $class ); |
|
| 750 | - $classes = array_merge( $classes, $class ); |
|
| 747 | + if ( ! empty($class)) { |
|
| 748 | + if ( ! is_array($class)) |
|
| 749 | + $class = preg_split('#\s+#', $class); |
|
| 750 | + $classes = array_merge($classes, $class); |
|
| 751 | 751 | } else { |
| 752 | 752 | // Ensure that we always coerce class to being an array. |
| 753 | 753 | $class = array(); |
| 754 | 754 | } |
| 755 | 755 | |
| 756 | - $classes = array_map( 'esc_attr', $classes ); |
|
| 756 | + $classes = array_map('esc_attr', $classes); |
|
| 757 | 757 | |
| 758 | 758 | /** |
| 759 | 759 | * Filters the list of CSS body classes for the current post or page. |
@@ -763,9 +763,9 @@ discard block |
||
| 763 | 763 | * @param array $classes An array of body classes. |
| 764 | 764 | * @param array $class An array of additional classes added to the body. |
| 765 | 765 | */ |
| 766 | - $classes = apply_filters( 'body_class', $classes, $class ); |
|
| 766 | + $classes = apply_filters('body_class', $classes, $class); |
|
| 767 | 767 | |
| 768 | - return array_unique( $classes ); |
|
| 768 | + return array_unique($classes); |
|
| 769 | 769 | } |
| 770 | 770 | |
| 771 | 771 | /** |
@@ -776,23 +776,23 @@ discard block |
||
| 776 | 776 | * @param int|WP_Post|null $post An optional post. Global $post used if not provided. |
| 777 | 777 | * @return bool false if a password is not required or the correct password cookie is present, true otherwise. |
| 778 | 778 | */ |
| 779 | -function post_password_required( $post = null ) { |
|
| 779 | +function post_password_required($post = null) { |
|
| 780 | 780 | $post = get_post($post); |
| 781 | 781 | |
| 782 | - if ( empty( $post->post_password ) ) |
|
| 782 | + if (empty($post->post_password)) |
|
| 783 | 783 | return false; |
| 784 | 784 | |
| 785 | - if ( ! isset( $_COOKIE['wp-postpass_' . COOKIEHASH] ) ) |
|
| 785 | + if ( ! isset($_COOKIE['wp-postpass_'.COOKIEHASH])) |
|
| 786 | 786 | return true; |
| 787 | 787 | |
| 788 | - require_once ABSPATH . WPINC . '/class-phpass.php'; |
|
| 789 | - $hasher = new PasswordHash( 8, true ); |
|
| 788 | + require_once ABSPATH.WPINC.'/class-phpass.php'; |
|
| 789 | + $hasher = new PasswordHash(8, true); |
|
| 790 | 790 | |
| 791 | - $hash = wp_unslash( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] ); |
|
| 792 | - if ( 0 !== strpos( $hash, '$P$B' ) ) |
|
| 791 | + $hash = wp_unslash($_COOKIE['wp-postpass_'.COOKIEHASH]); |
|
| 792 | + if (0 !== strpos($hash, '$P$B')) |
|
| 793 | 793 | return true; |
| 794 | 794 | |
| 795 | - return ! $hasher->CheckPassword( $post->post_password, $hash ); |
|
| 795 | + return ! $hasher->CheckPassword($post->post_password, $hash); |
|
| 796 | 796 | } |
| 797 | 797 | |
| 798 | 798 | // |
@@ -833,23 +833,23 @@ discard block |
||
| 833 | 833 | * } |
| 834 | 834 | * @return string Formatted output in HTML. |
| 835 | 835 | */ |
| 836 | -function wp_link_pages( $args = '' ) { |
|
| 836 | +function wp_link_pages($args = '') { |
|
| 837 | 837 | global $page, $numpages, $multipage, $more; |
| 838 | 838 | |
| 839 | 839 | $defaults = array( |
| 840 | - 'before' => '<p>' . __( 'Pages:' ), |
|
| 840 | + 'before' => '<p>'.__('Pages:'), |
|
| 841 | 841 | 'after' => '</p>', |
| 842 | 842 | 'link_before' => '', |
| 843 | 843 | 'link_after' => '', |
| 844 | 844 | 'next_or_number' => 'number', |
| 845 | 845 | 'separator' => ' ', |
| 846 | - 'nextpagelink' => __( 'Next page' ), |
|
| 847 | - 'previouspagelink' => __( 'Previous page' ), |
|
| 846 | + 'nextpagelink' => __('Next page'), |
|
| 847 | + 'previouspagelink' => __('Previous page'), |
|
| 848 | 848 | 'pagelink' => '%', |
| 849 | 849 | 'echo' => 1 |
| 850 | 850 | ); |
| 851 | 851 | |
| 852 | - $params = wp_parse_args( $args, $defaults ); |
|
| 852 | + $params = wp_parse_args($args, $defaults); |
|
| 853 | 853 | |
| 854 | 854 | /** |
| 855 | 855 | * Filters the arguments used in retrieving page links for paginated posts. |
@@ -858,16 +858,16 @@ discard block |
||
| 858 | 858 | * |
| 859 | 859 | * @param array $params An array of arguments for page links for paginated posts. |
| 860 | 860 | */ |
| 861 | - $r = apply_filters( 'wp_link_pages_args', $params ); |
|
| 861 | + $r = apply_filters('wp_link_pages_args', $params); |
|
| 862 | 862 | |
| 863 | 863 | $output = ''; |
| 864 | - if ( $multipage ) { |
|
| 865 | - if ( 'number' == $r['next_or_number'] ) { |
|
| 864 | + if ($multipage) { |
|
| 865 | + if ('number' == $r['next_or_number']) { |
|
| 866 | 866 | $output .= $r['before']; |
| 867 | - for ( $i = 1; $i <= $numpages; $i++ ) { |
|
| 868 | - $link = $r['link_before'] . str_replace( '%', $i, $r['pagelink'] ) . $r['link_after']; |
|
| 869 | - if ( $i != $page || ! $more && 1 == $page ) { |
|
| 870 | - $link = _wp_link_page( $i ) . $link . '</a>'; |
|
| 867 | + for ($i = 1; $i <= $numpages; $i++) { |
|
| 868 | + $link = $r['link_before'].str_replace('%', $i, $r['pagelink']).$r['link_after']; |
|
| 869 | + if ($i != $page || ! $more && 1 == $page) { |
|
| 870 | + $link = _wp_link_page($i).$link.'</a>'; |
|
| 871 | 871 | } |
| 872 | 872 | /** |
| 873 | 873 | * Filters the HTML output of individual page number links. |
@@ -877,31 +877,31 @@ discard block |
||
| 877 | 877 | * @param string $link The page number HTML output. |
| 878 | 878 | * @param int $i Page number for paginated posts' page links. |
| 879 | 879 | */ |
| 880 | - $link = apply_filters( 'wp_link_pages_link', $link, $i ); |
|
| 880 | + $link = apply_filters('wp_link_pages_link', $link, $i); |
|
| 881 | 881 | |
| 882 | 882 | // Use the custom links separator beginning with the second link. |
| 883 | - $output .= ( 1 === $i ) ? ' ' : $r['separator']; |
|
| 883 | + $output .= (1 === $i) ? ' ' : $r['separator']; |
|
| 884 | 884 | $output .= $link; |
| 885 | 885 | } |
| 886 | 886 | $output .= $r['after']; |
| 887 | - } elseif ( $more ) { |
|
| 887 | + } elseif ($more) { |
|
| 888 | 888 | $output .= $r['before']; |
| 889 | 889 | $prev = $page - 1; |
| 890 | - if ( $prev > 0 ) { |
|
| 891 | - $link = _wp_link_page( $prev ) . $r['link_before'] . $r['previouspagelink'] . $r['link_after'] . '</a>'; |
|
| 890 | + if ($prev > 0) { |
|
| 891 | + $link = _wp_link_page($prev).$r['link_before'].$r['previouspagelink'].$r['link_after'].'</a>'; |
|
| 892 | 892 | |
| 893 | 893 | /** This filter is documented in wp-includes/post-template.php */ |
| 894 | - $output .= apply_filters( 'wp_link_pages_link', $link, $prev ); |
|
| 894 | + $output .= apply_filters('wp_link_pages_link', $link, $prev); |
|
| 895 | 895 | } |
| 896 | 896 | $next = $page + 1; |
| 897 | - if ( $next <= $numpages ) { |
|
| 898 | - if ( $prev ) { |
|
| 897 | + if ($next <= $numpages) { |
|
| 898 | + if ($prev) { |
|
| 899 | 899 | $output .= $r['separator']; |
| 900 | 900 | } |
| 901 | - $link = _wp_link_page( $next ) . $r['link_before'] . $r['nextpagelink'] . $r['link_after'] . '</a>'; |
|
| 901 | + $link = _wp_link_page($next).$r['link_before'].$r['nextpagelink'].$r['link_after'].'</a>'; |
|
| 902 | 902 | |
| 903 | 903 | /** This filter is documented in wp-includes/post-template.php */ |
| 904 | - $output .= apply_filters( 'wp_link_pages_link', $link, $next ); |
|
| 904 | + $output .= apply_filters('wp_link_pages_link', $link, $next); |
|
| 905 | 905 | } |
| 906 | 906 | $output .= $r['after']; |
| 907 | 907 | } |
@@ -915,9 +915,9 @@ discard block |
||
| 915 | 915 | * @param string $output HTML output of paginated posts' page links. |
| 916 | 916 | * @param array $args An array of arguments. |
| 917 | 917 | */ |
| 918 | - $html = apply_filters( 'wp_link_pages', $output, $args ); |
|
| 918 | + $html = apply_filters('wp_link_pages', $output, $args); |
|
| 919 | 919 | |
| 920 | - if ( $r['echo'] ) { |
|
| 920 | + if ($r['echo']) { |
|
| 921 | 921 | echo $html; |
| 922 | 922 | } |
| 923 | 923 | return $html; |
@@ -934,33 +934,33 @@ discard block |
||
| 934 | 934 | * @param int $i Page number. |
| 935 | 935 | * @return string Link. |
| 936 | 936 | */ |
| 937 | -function _wp_link_page( $i ) { |
|
| 937 | +function _wp_link_page($i) { |
|
| 938 | 938 | global $wp_rewrite; |
| 939 | 939 | $post = get_post(); |
| 940 | 940 | $query_args = array(); |
| 941 | 941 | |
| 942 | - if ( 1 == $i ) { |
|
| 942 | + if (1 == $i) { |
|
| 943 | 943 | $url = get_permalink(); |
| 944 | 944 | } else { |
| 945 | - if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) ) |
|
| 946 | - $url = add_query_arg( 'page', $i, get_permalink() ); |
|
| 947 | - elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID ) |
|
| 948 | - $url = trailingslashit(get_permalink()) . user_trailingslashit("$wp_rewrite->pagination_base/" . $i, 'single_paged'); |
|
| 945 | + if ('' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending'))) |
|
| 946 | + $url = add_query_arg('page', $i, get_permalink()); |
|
| 947 | + elseif ('page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID) |
|
| 948 | + $url = trailingslashit(get_permalink()).user_trailingslashit("$wp_rewrite->pagination_base/".$i, 'single_paged'); |
|
| 949 | 949 | else |
| 950 | - $url = trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged'); |
|
| 950 | + $url = trailingslashit(get_permalink()).user_trailingslashit($i, 'single_paged'); |
|
| 951 | 951 | } |
| 952 | 952 | |
| 953 | - if ( is_preview() ) { |
|
| 953 | + if (is_preview()) { |
|
| 954 | 954 | |
| 955 | - if ( ( 'draft' !== $post->post_status ) && isset( $_GET['preview_id'], $_GET['preview_nonce'] ) ) { |
|
| 956 | - $query_args['preview_id'] = wp_unslash( $_GET['preview_id'] ); |
|
| 957 | - $query_args['preview_nonce'] = wp_unslash( $_GET['preview_nonce'] ); |
|
| 955 | + if (('draft' !== $post->post_status) && isset($_GET['preview_id'], $_GET['preview_nonce'])) { |
|
| 956 | + $query_args['preview_id'] = wp_unslash($_GET['preview_id']); |
|
| 957 | + $query_args['preview_nonce'] = wp_unslash($_GET['preview_nonce']); |
|
| 958 | 958 | } |
| 959 | 959 | |
| 960 | - $url = get_preview_post_link( $post, $query_args, $url ); |
|
| 960 | + $url = get_preview_post_link($post, $query_args, $url); |
|
| 961 | 961 | } |
| 962 | 962 | |
| 963 | - return '<a href="' . esc_url( $url ) . '">'; |
|
| 963 | + return '<a href="'.esc_url($url).'">'; |
|
| 964 | 964 | } |
| 965 | 965 | |
| 966 | 966 | // |
@@ -975,12 +975,12 @@ discard block |
||
| 975 | 975 | * @param string $key Meta data key name. |
| 976 | 976 | * @return false|string|array Array of values or single value, if only one element exists. False will be returned if key does not exist. |
| 977 | 977 | */ |
| 978 | -function post_custom( $key = '' ) { |
|
| 978 | +function post_custom($key = '') { |
|
| 979 | 979 | $custom = get_post_custom(); |
| 980 | 980 | |
| 981 | - if ( !isset( $custom[$key] ) ) |
|
| 981 | + if ( ! isset($custom[$key])) |
|
| 982 | 982 | return false; |
| 983 | - elseif ( 1 == count($custom[$key]) ) |
|
| 983 | + elseif (1 == count($custom[$key])) |
|
| 984 | 984 | return $custom[$key][0]; |
| 985 | 985 | else |
| 986 | 986 | return $custom[$key]; |
@@ -995,14 +995,14 @@ discard block |
||
| 995 | 995 | * |
| 996 | 996 | */ |
| 997 | 997 | function the_meta() { |
| 998 | - if ( $keys = get_post_custom_keys() ) { |
|
| 998 | + if ($keys = get_post_custom_keys()) { |
|
| 999 | 999 | echo "<ul class='post-meta'>\n"; |
| 1000 | - foreach ( (array) $keys as $key ) { |
|
| 1000 | + foreach ((array) $keys as $key) { |
|
| 1001 | 1001 | $keyt = trim($key); |
| 1002 | - if ( is_protected_meta( $keyt, 'post' ) ) |
|
| 1002 | + if (is_protected_meta($keyt, 'post')) |
|
| 1003 | 1003 | continue; |
| 1004 | 1004 | $values = array_map('trim', get_post_custom_values($key)); |
| 1005 | - $value = implode($values,', '); |
|
| 1005 | + $value = implode($values, ', '); |
|
| 1006 | 1006 | |
| 1007 | 1007 | /** |
| 1008 | 1008 | * Filters the HTML output of the li element in the post custom fields list. |
@@ -1013,7 +1013,7 @@ discard block |
||
| 1013 | 1013 | * @param string $key Meta key. |
| 1014 | 1014 | * @param string $value Meta value. |
| 1015 | 1015 | */ |
| 1016 | - echo apply_filters( 'the_meta_key', "<li><span class='post-meta-key'>$key:</span> $value</li>\n", $key, $value ); |
|
| 1016 | + echo apply_filters('the_meta_key', "<li><span class='post-meta-key'>$key:</span> $value</li>\n", $key, $value); |
|
| 1017 | 1017 | } |
| 1018 | 1018 | echo "</ul>\n"; |
| 1019 | 1019 | } |
@@ -1051,7 +1051,7 @@ discard block |
||
| 1051 | 1051 | * } |
| 1052 | 1052 | * @return string HTML content, if not displaying. |
| 1053 | 1053 | */ |
| 1054 | -function wp_dropdown_pages( $args = '' ) { |
|
| 1054 | +function wp_dropdown_pages($args = '') { |
|
| 1055 | 1055 | $defaults = array( |
| 1056 | 1056 | 'depth' => 0, 'child_of' => 0, |
| 1057 | 1057 | 'selected' => 0, 'echo' => 1, |
@@ -1062,29 +1062,29 @@ discard block |
||
| 1062 | 1062 | 'value_field' => 'ID', |
| 1063 | 1063 | ); |
| 1064 | 1064 | |
| 1065 | - $r = wp_parse_args( $args, $defaults ); |
|
| 1065 | + $r = wp_parse_args($args, $defaults); |
|
| 1066 | 1066 | |
| 1067 | - $pages = get_pages( $r ); |
|
| 1067 | + $pages = get_pages($r); |
|
| 1068 | 1068 | $output = ''; |
| 1069 | 1069 | // Back-compat with old system where both id and name were based on $name argument |
| 1070 | - if ( empty( $r['id'] ) ) { |
|
| 1070 | + if (empty($r['id'])) { |
|
| 1071 | 1071 | $r['id'] = $r['name']; |
| 1072 | 1072 | } |
| 1073 | 1073 | |
| 1074 | - if ( ! empty( $pages ) ) { |
|
| 1074 | + if ( ! empty($pages)) { |
|
| 1075 | 1075 | $class = ''; |
| 1076 | - if ( ! empty( $r['class'] ) ) { |
|
| 1077 | - $class = " class='" . esc_attr( $r['class'] ) . "'"; |
|
| 1076 | + if ( ! empty($r['class'])) { |
|
| 1077 | + $class = " class='".esc_attr($r['class'])."'"; |
|
| 1078 | 1078 | } |
| 1079 | 1079 | |
| 1080 | - $output = "<select name='" . esc_attr( $r['name'] ) . "'" . $class . " id='" . esc_attr( $r['id'] ) . "'>\n"; |
|
| 1081 | - if ( $r['show_option_no_change'] ) { |
|
| 1082 | - $output .= "\t<option value=\"-1\">" . $r['show_option_no_change'] . "</option>\n"; |
|
| 1080 | + $output = "<select name='".esc_attr($r['name'])."'".$class." id='".esc_attr($r['id'])."'>\n"; |
|
| 1081 | + if ($r['show_option_no_change']) { |
|
| 1082 | + $output .= "\t<option value=\"-1\">".$r['show_option_no_change']."</option>\n"; |
|
| 1083 | 1083 | } |
| 1084 | - if ( $r['show_option_none'] ) { |
|
| 1085 | - $output .= "\t<option value=\"" . esc_attr( $r['option_none_value'] ) . '">' . $r['show_option_none'] . "</option>\n"; |
|
| 1084 | + if ($r['show_option_none']) { |
|
| 1085 | + $output .= "\t<option value=\"".esc_attr($r['option_none_value']).'">'.$r['show_option_none']."</option>\n"; |
|
| 1086 | 1086 | } |
| 1087 | - $output .= walk_page_dropdown_tree( $pages, $r['depth'], $r ); |
|
| 1087 | + $output .= walk_page_dropdown_tree($pages, $r['depth'], $r); |
|
| 1088 | 1088 | $output .= "</select>\n"; |
| 1089 | 1089 | } |
| 1090 | 1090 | |
@@ -1098,9 +1098,9 @@ discard block |
||
| 1098 | 1098 | * @param array $r The parsed arguments array. |
| 1099 | 1099 | * @param array $pages List of WP_Post objects returned by `get_pages()` |
| 1100 | 1100 | */ |
| 1101 | - $html = apply_filters( 'wp_dropdown_pages', $output, $r, $pages ); |
|
| 1101 | + $html = apply_filters('wp_dropdown_pages', $output, $r, $pages); |
|
| 1102 | 1102 | |
| 1103 | - if ( $r['echo'] ) { |
|
| 1103 | + if ($r['echo']) { |
|
| 1104 | 1104 | echo $html; |
| 1105 | 1105 | } |
| 1106 | 1106 | return $html; |
@@ -1143,26 +1143,26 @@ discard block |
||
| 1143 | 1143 | * } |
| 1144 | 1144 | * @return string|void HTML list of pages. |
| 1145 | 1145 | */ |
| 1146 | -function wp_list_pages( $args = '' ) { |
|
| 1146 | +function wp_list_pages($args = '') { |
|
| 1147 | 1147 | $defaults = array( |
| 1148 | 1148 | 'depth' => 0, 'show_date' => '', |
| 1149 | - 'date_format' => get_option( 'date_format' ), |
|
| 1149 | + 'date_format' => get_option('date_format'), |
|
| 1150 | 1150 | 'child_of' => 0, 'exclude' => '', |
| 1151 | - 'title_li' => __( 'Pages' ), 'echo' => 1, |
|
| 1151 | + 'title_li' => __('Pages'), 'echo' => 1, |
|
| 1152 | 1152 | 'authors' => '', 'sort_column' => 'menu_order, post_title', |
| 1153 | 1153 | 'link_before' => '', 'link_after' => '', 'walker' => '', |
| 1154 | 1154 | ); |
| 1155 | 1155 | |
| 1156 | - $r = wp_parse_args( $args, $defaults ); |
|
| 1156 | + $r = wp_parse_args($args, $defaults); |
|
| 1157 | 1157 | |
| 1158 | 1158 | $output = ''; |
| 1159 | 1159 | $current_page = 0; |
| 1160 | 1160 | |
| 1161 | 1161 | // sanitize, mostly to keep spaces out |
| 1162 | - $r['exclude'] = preg_replace( '/[^0-9,]/', '', $r['exclude'] ); |
|
| 1162 | + $r['exclude'] = preg_replace('/[^0-9,]/', '', $r['exclude']); |
|
| 1163 | 1163 | |
| 1164 | 1164 | // Allow plugins to filter an array of excluded pages (but don't put a nullstring into the array) |
| 1165 | - $exclude_array = ( $r['exclude'] ) ? explode( ',', $r['exclude'] ) : array(); |
|
| 1165 | + $exclude_array = ($r['exclude']) ? explode(',', $r['exclude']) : array(); |
|
| 1166 | 1166 | |
| 1167 | 1167 | /** |
| 1168 | 1168 | * Filters the array of pages to exclude from the pages list. |
@@ -1171,29 +1171,29 @@ discard block |
||
| 1171 | 1171 | * |
| 1172 | 1172 | * @param array $exclude_array An array of page IDs to exclude. |
| 1173 | 1173 | */ |
| 1174 | - $r['exclude'] = implode( ',', apply_filters( 'wp_list_pages_excludes', $exclude_array ) ); |
|
| 1174 | + $r['exclude'] = implode(',', apply_filters('wp_list_pages_excludes', $exclude_array)); |
|
| 1175 | 1175 | |
| 1176 | 1176 | // Query pages. |
| 1177 | 1177 | $r['hierarchical'] = 0; |
| 1178 | - $pages = get_pages( $r ); |
|
| 1178 | + $pages = get_pages($r); |
|
| 1179 | 1179 | |
| 1180 | - if ( ! empty( $pages ) ) { |
|
| 1181 | - if ( $r['title_li'] ) { |
|
| 1182 | - $output .= '<li class="pagenav">' . $r['title_li'] . '<ul>'; |
|
| 1180 | + if ( ! empty($pages)) { |
|
| 1181 | + if ($r['title_li']) { |
|
| 1182 | + $output .= '<li class="pagenav">'.$r['title_li'].'<ul>'; |
|
| 1183 | 1183 | } |
| 1184 | 1184 | global $wp_query; |
| 1185 | - if ( is_page() || is_attachment() || $wp_query->is_posts_page ) { |
|
| 1185 | + if (is_page() || is_attachment() || $wp_query->is_posts_page) { |
|
| 1186 | 1186 | $current_page = get_queried_object_id(); |
| 1187 | - } elseif ( is_singular() ) { |
|
| 1187 | + } elseif (is_singular()) { |
|
| 1188 | 1188 | $queried_object = get_queried_object(); |
| 1189 | - if ( is_post_type_hierarchical( $queried_object->post_type ) ) { |
|
| 1189 | + if (is_post_type_hierarchical($queried_object->post_type)) { |
|
| 1190 | 1190 | $current_page = $queried_object->ID; |
| 1191 | 1191 | } |
| 1192 | 1192 | } |
| 1193 | 1193 | |
| 1194 | - $output .= walk_page_tree( $pages, $r['depth'], $current_page, $r ); |
|
| 1194 | + $output .= walk_page_tree($pages, $r['depth'], $current_page, $r); |
|
| 1195 | 1195 | |
| 1196 | - if ( $r['title_li'] ) { |
|
| 1196 | + if ($r['title_li']) { |
|
| 1197 | 1197 | $output .= '</ul></li>'; |
| 1198 | 1198 | } |
| 1199 | 1199 | } |
@@ -1210,9 +1210,9 @@ discard block |
||
| 1210 | 1210 | * @param array $r An array of page-listing arguments. |
| 1211 | 1211 | * @param array $pages List of WP_Post objects returned by `get_pages()` |
| 1212 | 1212 | */ |
| 1213 | - $html = apply_filters( 'wp_list_pages', $output, $r, $pages ); |
|
| 1213 | + $html = apply_filters('wp_list_pages', $output, $r, $pages); |
|
| 1214 | 1214 | |
| 1215 | - if ( $r['echo'] ) { |
|
| 1215 | + if ($r['echo']) { |
|
| 1216 | 1216 | echo $html; |
| 1217 | 1217 | } else { |
| 1218 | 1218 | return $html; |
@@ -1248,7 +1248,7 @@ discard block |
||
| 1248 | 1248 | * } |
| 1249 | 1249 | * @return string|void HTML menu |
| 1250 | 1250 | */ |
| 1251 | -function wp_page_menu( $args = array() ) { |
|
| 1251 | +function wp_page_menu($args = array()) { |
|
| 1252 | 1252 | $defaults = array( |
| 1253 | 1253 | 'sort_column' => 'menu_order, post_title', |
| 1254 | 1254 | 'menu_id' => '', |
@@ -1261,7 +1261,7 @@ discard block |
||
| 1261 | 1261 | 'after' => '</ul>', |
| 1262 | 1262 | 'walker' => '', |
| 1263 | 1263 | ); |
| 1264 | - $args = wp_parse_args( $args, $defaults ); |
|
| 1264 | + $args = wp_parse_args($args, $defaults); |
|
| 1265 | 1265 | |
| 1266 | 1266 | /** |
| 1267 | 1267 | * Filters the arguments used to generate a page-based menu. |
@@ -1272,25 +1272,25 @@ discard block |
||
| 1272 | 1272 | * |
| 1273 | 1273 | * @param array $args An array of page menu arguments. |
| 1274 | 1274 | */ |
| 1275 | - $args = apply_filters( 'wp_page_menu_args', $args ); |
|
| 1275 | + $args = apply_filters('wp_page_menu_args', $args); |
|
| 1276 | 1276 | |
| 1277 | 1277 | $menu = ''; |
| 1278 | 1278 | |
| 1279 | 1279 | $list_args = $args; |
| 1280 | 1280 | |
| 1281 | 1281 | // Show Home in the menu |
| 1282 | - if ( ! empty($args['show_home']) ) { |
|
| 1283 | - if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] ) |
|
| 1282 | + if ( ! empty($args['show_home'])) { |
|
| 1283 | + if (true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home']) |
|
| 1284 | 1284 | $text = __('Home'); |
| 1285 | 1285 | else |
| 1286 | 1286 | $text = $args['show_home']; |
| 1287 | 1287 | $class = ''; |
| 1288 | - if ( is_front_page() && !is_paged() ) |
|
| 1288 | + if (is_front_page() && ! is_paged()) |
|
| 1289 | 1289 | $class = 'class="current_page_item"'; |
| 1290 | - $menu .= '<li ' . $class . '><a href="' . home_url( '/' ) . '">' . $args['link_before'] . $text . $args['link_after'] . '</a></li>'; |
|
| 1290 | + $menu .= '<li '.$class.'><a href="'.home_url('/').'">'.$args['link_before'].$text.$args['link_after'].'</a></li>'; |
|
| 1291 | 1291 | // If the front page is a page, add it to the exclude list |
| 1292 | 1292 | if (get_option('show_on_front') == 'page') { |
| 1293 | - if ( !empty( $list_args['exclude'] ) ) { |
|
| 1293 | + if ( ! empty($list_args['exclude'])) { |
|
| 1294 | 1294 | $list_args['exclude'] .= ','; |
| 1295 | 1295 | } else { |
| 1296 | 1296 | $list_args['exclude'] = ''; |
@@ -1301,38 +1301,38 @@ discard block |
||
| 1301 | 1301 | |
| 1302 | 1302 | $list_args['echo'] = false; |
| 1303 | 1303 | $list_args['title_li'] = ''; |
| 1304 | - $menu .= str_replace( array( "\r", "\n", "\t" ), '', wp_list_pages($list_args) ); |
|
| 1304 | + $menu .= str_replace(array("\r", "\n", "\t"), '', wp_list_pages($list_args)); |
|
| 1305 | 1305 | |
| 1306 | - $container = sanitize_text_field( $args['container'] ); |
|
| 1306 | + $container = sanitize_text_field($args['container']); |
|
| 1307 | 1307 | |
| 1308 | 1308 | // Fallback in case `wp_nav_menu()` was called without a container. |
| 1309 | - if ( empty( $container ) ) { |
|
| 1309 | + if (empty($container)) { |
|
| 1310 | 1310 | $container = 'div'; |
| 1311 | 1311 | } |
| 1312 | 1312 | |
| 1313 | - if ( $menu ) { |
|
| 1313 | + if ($menu) { |
|
| 1314 | 1314 | |
| 1315 | 1315 | // wp_nav_menu doesn't set before and after |
| 1316 | - if ( isset( $args['fallback_cb'] ) && |
|
| 1316 | + if (isset($args['fallback_cb']) && |
|
| 1317 | 1317 | 'wp_page_menu' === $args['fallback_cb'] && |
| 1318 | - 'ul' !== $container ) { |
|
| 1318 | + 'ul' !== $container) { |
|
| 1319 | 1319 | $args['before'] = '<ul>'; |
| 1320 | 1320 | $args['after'] = '</ul>'; |
| 1321 | 1321 | } |
| 1322 | 1322 | |
| 1323 | - $menu = $args['before'] . $menu . $args['after']; |
|
| 1323 | + $menu = $args['before'].$menu.$args['after']; |
|
| 1324 | 1324 | } |
| 1325 | 1325 | |
| 1326 | 1326 | $attrs = ''; |
| 1327 | - if ( ! empty( $args['menu_id'] ) ) { |
|
| 1328 | - $attrs .= ' id="' . esc_attr( $args['menu_id'] ) . '"'; |
|
| 1327 | + if ( ! empty($args['menu_id'])) { |
|
| 1328 | + $attrs .= ' id="'.esc_attr($args['menu_id']).'"'; |
|
| 1329 | 1329 | } |
| 1330 | 1330 | |
| 1331 | - if ( ! empty( $args['menu_class'] ) ) { |
|
| 1332 | - $attrs .= ' class="' . esc_attr( $args['menu_class'] ) . '"'; |
|
| 1331 | + if ( ! empty($args['menu_class'])) { |
|
| 1332 | + $attrs .= ' class="'.esc_attr($args['menu_class']).'"'; |
|
| 1333 | 1333 | } |
| 1334 | 1334 | |
| 1335 | - $menu = "<{$container}{$attrs}>" . $menu . "</{$container}>\n"; |
|
| 1335 | + $menu = "<{$container}{$attrs}>".$menu."</{$container}>\n"; |
|
| 1336 | 1336 | |
| 1337 | 1337 | /** |
| 1338 | 1338 | * Filters the HTML output of a page-based menu. |
@@ -1344,8 +1344,8 @@ discard block |
||
| 1344 | 1344 | * @param string $menu The HTML output. |
| 1345 | 1345 | * @param array $args An array of arguments. |
| 1346 | 1346 | */ |
| 1347 | - $menu = apply_filters( 'wp_page_menu', $menu, $args ); |
|
| 1348 | - if ( $args['echo'] ) |
|
| 1347 | + $menu = apply_filters('wp_page_menu', $menu, $args); |
|
| 1348 | + if ($args['echo']) |
|
| 1349 | 1349 | echo $menu; |
| 1350 | 1350 | else |
| 1351 | 1351 | return $menu; |
@@ -1367,15 +1367,15 @@ discard block |
||
| 1367 | 1367 | * @param array $r |
| 1368 | 1368 | * @return string |
| 1369 | 1369 | */ |
| 1370 | -function walk_page_tree( $pages, $depth, $current_page, $r ) { |
|
| 1371 | - if ( empty($r['walker']) ) |
|
| 1370 | +function walk_page_tree($pages, $depth, $current_page, $r) { |
|
| 1371 | + if (empty($r['walker'])) |
|
| 1372 | 1372 | $walker = new Walker_Page; |
| 1373 | 1373 | else |
| 1374 | 1374 | $walker = $r['walker']; |
| 1375 | 1375 | |
| 1376 | - foreach ( (array) $pages as $page ) { |
|
| 1377 | - if ( $page->post_parent ) |
|
| 1378 | - $r['pages_with_children'][ $page->post_parent ] = true; |
|
| 1376 | + foreach ((array) $pages as $page) { |
|
| 1377 | + if ($page->post_parent) |
|
| 1378 | + $r['pages_with_children'][$page->post_parent] = true; |
|
| 1379 | 1379 | } |
| 1380 | 1380 | |
| 1381 | 1381 | $args = array($pages, $depth, $r, $current_page); |
@@ -1393,7 +1393,7 @@ discard block |
||
| 1393 | 1393 | */ |
| 1394 | 1394 | function walk_page_dropdown_tree() { |
| 1395 | 1395 | $args = func_get_args(); |
| 1396 | - if ( empty($args[2]['walker']) ) // the user's options are the third parameter |
|
| 1396 | + if (empty($args[2]['walker'])) // the user's options are the third parameter |
|
| 1397 | 1397 | $walker = new Walker_PageDropdown; |
| 1398 | 1398 | else |
| 1399 | 1399 | $walker = $args[2]['walker']; |
@@ -1415,11 +1415,11 @@ discard block |
||
| 1415 | 1415 | * @param bool $deprecated Deprecated. Not used. |
| 1416 | 1416 | * @param bool $permalink Optional, default is false. Whether to include permalink. |
| 1417 | 1417 | */ |
| 1418 | -function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $permalink = false ) { |
|
| 1419 | - if ( !empty( $deprecated ) ) |
|
| 1420 | - _deprecated_argument( __FUNCTION__, '2.5.0' ); |
|
| 1418 | +function the_attachment_link($id = 0, $fullsize = false, $deprecated = false, $permalink = false) { |
|
| 1419 | + if ( ! empty($deprecated)) |
|
| 1420 | + _deprecated_argument(__FUNCTION__, '2.5.0'); |
|
| 1421 | 1421 | |
| 1422 | - if ( $fullsize ) |
|
| 1422 | + if ($fullsize) |
|
| 1423 | 1423 | echo wp_get_attachment_link($id, 'full', $permalink); |
| 1424 | 1424 | else |
| 1425 | 1425 | echo wp_get_attachment_link($id, 'thumbnail', $permalink); |
@@ -1442,24 +1442,24 @@ discard block |
||
| 1442 | 1442 | * @param array|string $attr Optional. Array or string of attributes. Default empty. |
| 1443 | 1443 | * @return string HTML content. |
| 1444 | 1444 | */ |
| 1445 | -function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '' ) { |
|
| 1446 | - $_post = get_post( $id ); |
|
| 1445 | +function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '') { |
|
| 1446 | + $_post = get_post($id); |
|
| 1447 | 1447 | |
| 1448 | - if ( empty( $_post ) || ( 'attachment' != $_post->post_type ) || ! $url = wp_get_attachment_url( $_post->ID ) ) |
|
| 1449 | - return __( 'Missing Attachment' ); |
|
| 1448 | + if (empty($_post) || ('attachment' != $_post->post_type) || ! $url = wp_get_attachment_url($_post->ID)) |
|
| 1449 | + return __('Missing Attachment'); |
|
| 1450 | 1450 | |
| 1451 | - if ( $permalink ) |
|
| 1452 | - $url = get_attachment_link( $_post->ID ); |
|
| 1451 | + if ($permalink) |
|
| 1452 | + $url = get_attachment_link($_post->ID); |
|
| 1453 | 1453 | |
| 1454 | - if ( $text ) { |
|
| 1454 | + if ($text) { |
|
| 1455 | 1455 | $link_text = $text; |
| 1456 | - } elseif ( $size && 'none' != $size ) { |
|
| 1457 | - $link_text = wp_get_attachment_image( $_post->ID, $size, $icon, $attr ); |
|
| 1456 | + } elseif ($size && 'none' != $size) { |
|
| 1457 | + $link_text = wp_get_attachment_image($_post->ID, $size, $icon, $attr); |
|
| 1458 | 1458 | } else { |
| 1459 | 1459 | $link_text = ''; |
| 1460 | 1460 | } |
| 1461 | 1461 | |
| 1462 | - if ( trim( $link_text ) == '' ) |
|
| 1462 | + if (trim($link_text) == '') |
|
| 1463 | 1463 | $link_text = $_post->post_title; |
| 1464 | 1464 | |
| 1465 | 1465 | /** |
@@ -1475,7 +1475,7 @@ discard block |
||
| 1475 | 1475 | * @param bool $icon Whether to include an icon. Default false. |
| 1476 | 1476 | * @param string|bool $text If string, will be link text. Default false. |
| 1477 | 1477 | */ |
| 1478 | - return apply_filters( 'wp_get_attachment_link', "<a href='" . esc_url( $url ) . "'>$link_text</a>", $id, $size, $permalink, $icon, $text ); |
|
| 1478 | + return apply_filters('wp_get_attachment_link', "<a href='".esc_url($url)."'>$link_text</a>", $id, $size, $permalink, $icon, $text); |
|
| 1479 | 1479 | } |
| 1480 | 1480 | |
| 1481 | 1481 | /** |
@@ -1489,22 +1489,22 @@ discard block |
||
| 1489 | 1489 | function prepend_attachment($content) { |
| 1490 | 1490 | $post = get_post(); |
| 1491 | 1491 | |
| 1492 | - if ( empty($post->post_type) || $post->post_type != 'attachment' ) |
|
| 1492 | + if (empty($post->post_type) || $post->post_type != 'attachment') |
|
| 1493 | 1493 | return $content; |
| 1494 | 1494 | |
| 1495 | - if ( wp_attachment_is( 'video', $post ) ) { |
|
| 1496 | - $meta = wp_get_attachment_metadata( get_the_ID() ); |
|
| 1497 | - $atts = array( 'src' => wp_get_attachment_url() ); |
|
| 1498 | - if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) { |
|
| 1495 | + if (wp_attachment_is('video', $post)) { |
|
| 1496 | + $meta = wp_get_attachment_metadata(get_the_ID()); |
|
| 1497 | + $atts = array('src' => wp_get_attachment_url()); |
|
| 1498 | + if ( ! empty($meta['width']) && ! empty($meta['height'])) { |
|
| 1499 | 1499 | $atts['width'] = (int) $meta['width']; |
| 1500 | 1500 | $atts['height'] = (int) $meta['height']; |
| 1501 | 1501 | } |
| 1502 | - if ( has_post_thumbnail() ) { |
|
| 1503 | - $atts['poster'] = wp_get_attachment_url( get_post_thumbnail_id() ); |
|
| 1502 | + if (has_post_thumbnail()) { |
|
| 1503 | + $atts['poster'] = wp_get_attachment_url(get_post_thumbnail_id()); |
|
| 1504 | 1504 | } |
| 1505 | - $p = wp_video_shortcode( $atts ); |
|
| 1506 | - } elseif ( wp_attachment_is( 'audio', $post ) ) { |
|
| 1507 | - $p = wp_audio_shortcode( array( 'src' => wp_get_attachment_url() ) ); |
|
| 1505 | + $p = wp_video_shortcode($atts); |
|
| 1506 | + } elseif (wp_attachment_is('audio', $post)) { |
|
| 1507 | + $p = wp_audio_shortcode(array('src' => wp_get_attachment_url())); |
|
| 1508 | 1508 | } else { |
| 1509 | 1509 | $p = '<p class="attachment">'; |
| 1510 | 1510 | // show the medium sized image representation of the attachment if available, and link to the raw file |
@@ -1521,7 +1521,7 @@ discard block |
||
| 1521 | 1521 | * |
| 1522 | 1522 | * @param string $p The attachment HTML output. |
| 1523 | 1523 | */ |
| 1524 | - $p = apply_filters( 'prepend_attachment', $p ); |
|
| 1524 | + $p = apply_filters('prepend_attachment', $p); |
|
| 1525 | 1525 | |
| 1526 | 1526 | return "$p\n$content"; |
| 1527 | 1527 | } |
@@ -1538,12 +1538,12 @@ discard block |
||
| 1538 | 1538 | * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. |
| 1539 | 1539 | * @return string HTML content for password form for password protected post. |
| 1540 | 1540 | */ |
| 1541 | -function get_the_password_form( $post = 0 ) { |
|
| 1542 | - $post = get_post( $post ); |
|
| 1543 | - $label = 'pwbox-' . ( empty($post->ID) ? rand() : $post->ID ); |
|
| 1544 | - $output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" class="post-password-form" method="post"> |
|
| 1545 | - <p>' . __( 'This content is password protected. To view it please enter your password below:' ) . '</p> |
|
| 1546 | - <p><label for="' . $label . '">' . __( 'Password:' ) . ' <input name="post_password" id="' . $label . '" type="password" size="20" /></label> <input type="submit" name="Submit" value="' . esc_attr_x( 'Enter', 'post password form' ) . '" /></p></form> |
|
| 1541 | +function get_the_password_form($post = 0) { |
|
| 1542 | + $post = get_post($post); |
|
| 1543 | + $label = 'pwbox-'.(empty($post->ID) ? rand() : $post->ID); |
|
| 1544 | + $output = '<form action="'.esc_url(site_url('wp-login.php?action=postpass', 'login_post')).'" class="post-password-form" method="post"> |
|
| 1545 | + <p>' . __('This content is password protected. To view it please enter your password below:').'</p> |
|
| 1546 | + <p><label for="' . $label.'">'.__('Password:').' <input name="post_password" id="'.$label.'" type="password" size="20" /></label> <input type="submit" name="Submit" value="'.esc_attr_x('Enter', 'post password form').'" /></p></form> |
|
| 1547 | 1547 | '; |
| 1548 | 1548 | |
| 1549 | 1549 | /** |
@@ -1557,7 +1557,7 @@ discard block |
||
| 1557 | 1557 | * |
| 1558 | 1558 | * @param string $output The password form HTML output. |
| 1559 | 1559 | */ |
| 1560 | - return apply_filters( 'the_password_form', $output ); |
|
| 1560 | + return apply_filters('the_password_form', $output); |
|
| 1561 | 1561 | } |
| 1562 | 1562 | |
| 1563 | 1563 | /** |
@@ -1573,27 +1573,27 @@ discard block |
||
| 1573 | 1573 | * @param string|array $template The specific template name or array of templates to match. |
| 1574 | 1574 | * @return bool True on success, false on failure. |
| 1575 | 1575 | */ |
| 1576 | -function is_page_template( $template = '' ) { |
|
| 1577 | - if ( ! is_page() ) |
|
| 1576 | +function is_page_template($template = '') { |
|
| 1577 | + if ( ! is_page()) |
|
| 1578 | 1578 | return false; |
| 1579 | 1579 | |
| 1580 | - $page_template = get_page_template_slug( get_queried_object_id() ); |
|
| 1580 | + $page_template = get_page_template_slug(get_queried_object_id()); |
|
| 1581 | 1581 | |
| 1582 | - if ( empty( $template ) ) |
|
| 1582 | + if (empty($template)) |
|
| 1583 | 1583 | return (bool) $page_template; |
| 1584 | 1584 | |
| 1585 | - if ( $template == $page_template ) |
|
| 1585 | + if ($template == $page_template) |
|
| 1586 | 1586 | return true; |
| 1587 | 1587 | |
| 1588 | - if ( is_array( $template ) ) { |
|
| 1589 | - if ( ( in_array( 'default', $template, true ) && ! $page_template ) |
|
| 1590 | - || in_array( $page_template, $template, true ) |
|
| 1588 | + if (is_array($template)) { |
|
| 1589 | + if ((in_array('default', $template, true) && ! $page_template) |
|
| 1590 | + || in_array($page_template, $template, true) |
|
| 1591 | 1591 | ) { |
| 1592 | 1592 | return true; |
| 1593 | 1593 | } |
| 1594 | 1594 | } |
| 1595 | 1595 | |
| 1596 | - return ( 'default' === $template && ! $page_template ); |
|
| 1596 | + return ('default' === $template && ! $page_template); |
|
| 1597 | 1597 | } |
| 1598 | 1598 | |
| 1599 | 1599 | /** |
@@ -1605,12 +1605,12 @@ discard block |
||
| 1605 | 1605 | * @return string|false Page template filename. Returns an empty string when the default page template |
| 1606 | 1606 | * is in use. Returns false if the post is not a page. |
| 1607 | 1607 | */ |
| 1608 | -function get_page_template_slug( $post_id = null ) { |
|
| 1609 | - $post = get_post( $post_id ); |
|
| 1610 | - if ( ! $post || 'page' != $post->post_type ) |
|
| 1608 | +function get_page_template_slug($post_id = null) { |
|
| 1609 | + $post = get_post($post_id); |
|
| 1610 | + if ( ! $post || 'page' != $post->post_type) |
|
| 1611 | 1611 | return false; |
| 1612 | - $template = get_post_meta( $post->ID, '_wp_page_template', true ); |
|
| 1613 | - if ( ! $template || 'default' == $template ) |
|
| 1612 | + $template = get_post_meta($post->ID, '_wp_page_template', true); |
|
| 1613 | + if ( ! $template || 'default' == $template) |
|
| 1614 | 1614 | return ''; |
| 1615 | 1615 | return $template; |
| 1616 | 1616 | } |
@@ -1624,28 +1624,28 @@ discard block |
||
| 1624 | 1624 | * @param bool $link Optional, default is true. Link to revisions's page? |
| 1625 | 1625 | * @return string|false i18n formatted datetimestamp or localized 'Current Revision'. |
| 1626 | 1626 | */ |
| 1627 | -function wp_post_revision_title( $revision, $link = true ) { |
|
| 1628 | - if ( !$revision = get_post( $revision ) ) |
|
| 1627 | +function wp_post_revision_title($revision, $link = true) { |
|
| 1628 | + if ( ! $revision = get_post($revision)) |
|
| 1629 | 1629 | return $revision; |
| 1630 | 1630 | |
| 1631 | - if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) |
|
| 1631 | + if ( ! in_array($revision->post_type, array('post', 'page', 'revision'))) |
|
| 1632 | 1632 | return false; |
| 1633 | 1633 | |
| 1634 | 1634 | /* translators: revision date format, see https://secure.php.net/date */ |
| 1635 | - $datef = _x( 'F j, Y @ H:i:s', 'revision date format' ); |
|
| 1635 | + $datef = _x('F j, Y @ H:i:s', 'revision date format'); |
|
| 1636 | 1636 | /* translators: 1: date */ |
| 1637 | - $autosavef = _x( '%1$s [Autosave]', 'post revision title extra' ); |
|
| 1637 | + $autosavef = _x('%1$s [Autosave]', 'post revision title extra'); |
|
| 1638 | 1638 | /* translators: 1: date */ |
| 1639 | - $currentf = _x( '%1$s [Current Revision]', 'post revision title extra' ); |
|
| 1639 | + $currentf = _x('%1$s [Current Revision]', 'post revision title extra'); |
|
| 1640 | 1640 | |
| 1641 | - $date = date_i18n( $datef, strtotime( $revision->post_modified ) ); |
|
| 1642 | - if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) ) |
|
| 1641 | + $date = date_i18n($datef, strtotime($revision->post_modified)); |
|
| 1642 | + if ($link && current_user_can('edit_post', $revision->ID) && $link = get_edit_post_link($revision->ID)) |
|
| 1643 | 1643 | $date = "<a href='$link'>$date</a>"; |
| 1644 | 1644 | |
| 1645 | - if ( !wp_is_post_revision( $revision ) ) |
|
| 1646 | - $date = sprintf( $currentf, $date ); |
|
| 1647 | - elseif ( wp_is_post_autosave( $revision ) ) |
|
| 1648 | - $date = sprintf( $autosavef, $date ); |
|
| 1645 | + if ( ! wp_is_post_revision($revision)) |
|
| 1646 | + $date = sprintf($currentf, $date); |
|
| 1647 | + elseif (wp_is_post_autosave($revision)) |
|
| 1648 | + $date = sprintf($autosavef, $date); |
|
| 1649 | 1649 | |
| 1650 | 1650 | return $date; |
| 1651 | 1651 | } |
@@ -1659,39 +1659,39 @@ discard block |
||
| 1659 | 1659 | * @param bool $link Optional, default is true. Link to revisions's page? |
| 1660 | 1660 | * @return string|false gravatar, user, i18n formatted datetimestamp or localized 'Current Revision'. |
| 1661 | 1661 | */ |
| 1662 | -function wp_post_revision_title_expanded( $revision, $link = true ) { |
|
| 1663 | - if ( !$revision = get_post( $revision ) ) |
|
| 1662 | +function wp_post_revision_title_expanded($revision, $link = true) { |
|
| 1663 | + if ( ! $revision = get_post($revision)) |
|
| 1664 | 1664 | return $revision; |
| 1665 | 1665 | |
| 1666 | - if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) |
|
| 1666 | + if ( ! in_array($revision->post_type, array('post', 'page', 'revision'))) |
|
| 1667 | 1667 | return false; |
| 1668 | 1668 | |
| 1669 | - $author = get_the_author_meta( 'display_name', $revision->post_author ); |
|
| 1669 | + $author = get_the_author_meta('display_name', $revision->post_author); |
|
| 1670 | 1670 | /* translators: revision date format, see https://secure.php.net/date */ |
| 1671 | - $datef = _x( 'F j, Y @ H:i:s', 'revision date format' ); |
|
| 1671 | + $datef = _x('F j, Y @ H:i:s', 'revision date format'); |
|
| 1672 | 1672 | |
| 1673 | - $gravatar = get_avatar( $revision->post_author, 24 ); |
|
| 1673 | + $gravatar = get_avatar($revision->post_author, 24); |
|
| 1674 | 1674 | |
| 1675 | - $date = date_i18n( $datef, strtotime( $revision->post_modified ) ); |
|
| 1676 | - if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) ) |
|
| 1675 | + $date = date_i18n($datef, strtotime($revision->post_modified)); |
|
| 1676 | + if ($link && current_user_can('edit_post', $revision->ID) && $link = get_edit_post_link($revision->ID)) |
|
| 1677 | 1677 | $date = "<a href='$link'>$date</a>"; |
| 1678 | 1678 | |
| 1679 | 1679 | $revision_date_author = sprintf( |
| 1680 | 1680 | /* translators: post revision title: 1: author avatar, 2: author name, 3: time ago, 4: date */ |
| 1681 | - _x( '%1$s %2$s, %3$s ago (%4$s)', 'post revision title' ), |
|
| 1681 | + _x('%1$s %2$s, %3$s ago (%4$s)', 'post revision title'), |
|
| 1682 | 1682 | $gravatar, |
| 1683 | 1683 | $author, |
| 1684 | - human_time_diff( strtotime( $revision->post_modified ), current_time( 'timestamp' ) ), |
|
| 1684 | + human_time_diff(strtotime($revision->post_modified), current_time('timestamp')), |
|
| 1685 | 1685 | $date |
| 1686 | 1686 | ); |
| 1687 | 1687 | |
| 1688 | - $autosavef = __( '%1$s [Autosave]' ); |
|
| 1689 | - $currentf = __( '%1$s [Current Revision]' ); |
|
| 1688 | + $autosavef = __('%1$s [Autosave]'); |
|
| 1689 | + $currentf = __('%1$s [Current Revision]'); |
|
| 1690 | 1690 | |
| 1691 | - if ( !wp_is_post_revision( $revision ) ) |
|
| 1692 | - $revision_date_author = sprintf( $currentf, $revision_date_author ); |
|
| 1693 | - elseif ( wp_is_post_autosave( $revision ) ) |
|
| 1694 | - $revision_date_author = sprintf( $autosavef, $revision_date_author ); |
|
| 1691 | + if ( ! wp_is_post_revision($revision)) |
|
| 1692 | + $revision_date_author = sprintf($currentf, $revision_date_author); |
|
| 1693 | + elseif (wp_is_post_autosave($revision)) |
|
| 1694 | + $revision_date_author = sprintf($autosavef, $revision_date_author); |
|
| 1695 | 1695 | |
| 1696 | 1696 | /** |
| 1697 | 1697 | * Filters the formatted author and date for a revision. |
@@ -1703,7 +1703,7 @@ discard block |
||
| 1703 | 1703 | * @param bool $link Whether to link to the revisions page, as passed into |
| 1704 | 1704 | * wp_post_revision_title_expanded(). |
| 1705 | 1705 | */ |
| 1706 | - return apply_filters( 'wp_post_revision_title_expanded', $revision_date_author, $revision, $link ); |
|
| 1706 | + return apply_filters('wp_post_revision_title_expanded', $revision_date_author, $revision, $link); |
|
| 1707 | 1707 | } |
| 1708 | 1708 | |
| 1709 | 1709 | /** |
@@ -1717,32 +1717,32 @@ discard block |
||
| 1717 | 1717 | * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post. |
| 1718 | 1718 | * @param string $type 'all' (default), 'revision' or 'autosave' |
| 1719 | 1719 | */ |
| 1720 | -function wp_list_post_revisions( $post_id = 0, $type = 'all' ) { |
|
| 1721 | - if ( ! $post = get_post( $post_id ) ) |
|
| 1720 | +function wp_list_post_revisions($post_id = 0, $type = 'all') { |
|
| 1721 | + if ( ! $post = get_post($post_id)) |
|
| 1722 | 1722 | return; |
| 1723 | 1723 | |
| 1724 | 1724 | // $args array with (parent, format, right, left, type) deprecated since 3.6 |
| 1725 | - if ( is_array( $type ) ) { |
|
| 1726 | - $type = ! empty( $type['type'] ) ? $type['type'] : $type; |
|
| 1727 | - _deprecated_argument( __FUNCTION__, '3.6.0' ); |
|
| 1725 | + if (is_array($type)) { |
|
| 1726 | + $type = ! empty($type['type']) ? $type['type'] : $type; |
|
| 1727 | + _deprecated_argument(__FUNCTION__, '3.6.0'); |
|
| 1728 | 1728 | } |
| 1729 | 1729 | |
| 1730 | - if ( ! $revisions = wp_get_post_revisions( $post->ID ) ) |
|
| 1730 | + if ( ! $revisions = wp_get_post_revisions($post->ID)) |
|
| 1731 | 1731 | return; |
| 1732 | 1732 | |
| 1733 | 1733 | $rows = ''; |
| 1734 | - foreach ( $revisions as $revision ) { |
|
| 1735 | - if ( ! current_user_can( 'read_post', $revision->ID ) ) |
|
| 1734 | + foreach ($revisions as $revision) { |
|
| 1735 | + if ( ! current_user_can('read_post', $revision->ID)) |
|
| 1736 | 1736 | continue; |
| 1737 | 1737 | |
| 1738 | - $is_autosave = wp_is_post_autosave( $revision ); |
|
| 1739 | - if ( ( 'revision' === $type && $is_autosave ) || ( 'autosave' === $type && ! $is_autosave ) ) |
|
| 1738 | + $is_autosave = wp_is_post_autosave($revision); |
|
| 1739 | + if (('revision' === $type && $is_autosave) || ('autosave' === $type && ! $is_autosave)) |
|
| 1740 | 1740 | continue; |
| 1741 | 1741 | |
| 1742 | - $rows .= "\t<li>" . wp_post_revision_title_expanded( $revision ) . "</li>\n"; |
|
| 1742 | + $rows .= "\t<li>".wp_post_revision_title_expanded($revision)."</li>\n"; |
|
| 1743 | 1743 | } |
| 1744 | 1744 | |
| 1745 | - echo "<div class='hide-if-js'><p>" . __( 'JavaScript must be enabled to use this feature.' ) . "</p></div>\n"; |
|
| 1745 | + echo "<div class='hide-if-js'><p>".__('JavaScript must be enabled to use this feature.')."</p></div>\n"; |
|
| 1746 | 1746 | |
| 1747 | 1747 | echo "<ul class='post-revisions hide-if-no-js'>\n"; |
| 1748 | 1748 | echo $rows; |
@@ -42,16 +42,18 @@ discard block |
||
| 42 | 42 | function the_title( $before = '', $after = '', $echo = true ) { |
| 43 | 43 | $title = get_the_title(); |
| 44 | 44 | |
| 45 | - if ( strlen($title) == 0 ) |
|
| 46 | - return; |
|
| 45 | + if ( strlen($title) == 0 ) { |
|
| 46 | + return; |
|
| 47 | + } |
|
| 47 | 48 | |
| 48 | 49 | $title = $before . $title . $after; |
| 49 | 50 | |
| 50 | - if ( $echo ) |
|
| 51 | - echo $title; |
|
| 52 | - else |
|
| 53 | - return $title; |
|
| 54 | -} |
|
| 51 | + if ( $echo ) { |
|
| 52 | + echo $title; |
|
| 53 | + } else { |
|
| 54 | + return $title; |
|
| 55 | + } |
|
| 56 | + } |
|
| 55 | 57 | |
| 56 | 58 | /** |
| 57 | 59 | * Sanitize the current title when retrieving or displaying. |
@@ -278,30 +280,37 @@ discard block |
||
| 278 | 280 | $has_teaser = false; |
| 279 | 281 | |
| 280 | 282 | // If post password required and it doesn't match the cookie. |
| 281 | - if ( post_password_required( $post ) ) |
|
| 282 | - return get_the_password_form( $post ); |
|
| 283 | + if ( post_password_required( $post ) ) { |
|
| 284 | + return get_the_password_form( $post ); |
|
| 285 | + } |
|
| 283 | 286 | |
| 284 | - if ( $page > count( $pages ) ) // if the requested page doesn't exist |
|
| 285 | - $page = count( $pages ); // give them the highest numbered page that DOES exist |
|
| 287 | + if ( $page > count( $pages ) ) { |
|
| 288 | + // if the requested page doesn't exist |
|
| 289 | + $page = count( $pages ); |
|
| 290 | + } |
|
| 291 | + // give them the highest numbered page that DOES exist |
|
| 286 | 292 | |
| 287 | 293 | $content = $pages[$page - 1]; |
| 288 | 294 | if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) { |
| 289 | 295 | $content = explode( $matches[0], $content, 2 ); |
| 290 | - if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) ) |
|
| 291 | - $more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) ); |
|
| 296 | + if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) ) { |
|
| 297 | + $more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) ); |
|
| 298 | + } |
|
| 292 | 299 | |
| 293 | 300 | $has_teaser = true; |
| 294 | 301 | } else { |
| 295 | 302 | $content = array( $content ); |
| 296 | 303 | } |
| 297 | 304 | |
| 298 | - if ( false !== strpos( $post->post_content, '<!--noteaser-->' ) && ( ! $multipage || $page == 1 ) ) |
|
| 299 | - $strip_teaser = true; |
|
| 305 | + if ( false !== strpos( $post->post_content, '<!--noteaser-->' ) && ( ! $multipage || $page == 1 ) ) { |
|
| 306 | + $strip_teaser = true; |
|
| 307 | + } |
|
| 300 | 308 | |
| 301 | 309 | $teaser = $content[0]; |
| 302 | 310 | |
| 303 | - if ( $more && $strip_teaser && $has_teaser ) |
|
| 304 | - $teaser = ''; |
|
| 311 | + if ( $more && $strip_teaser && $has_teaser ) { |
|
| 312 | + $teaser = ''; |
|
| 313 | + } |
|
| 305 | 314 | |
| 306 | 315 | $output .= $teaser; |
| 307 | 316 | |
@@ -309,8 +318,8 @@ discard block |
||
| 309 | 318 | if ( $more ) { |
| 310 | 319 | $output .= '<span id="more-' . $post->ID . '"></span>' . $content[1]; |
| 311 | 320 | } else { |
| 312 | - if ( ! empty( $more_link_text ) ) |
|
| 313 | - |
|
| 321 | + if ( ! empty( $more_link_text ) ) { |
|
| 322 | + |
|
| 314 | 323 | /** |
| 315 | 324 | * Filters the Read More link text. |
| 316 | 325 | * |
@@ -320,12 +329,15 @@ discard block |
||
| 320 | 329 | * @param string $more_link_text Read More text. |
| 321 | 330 | */ |
| 322 | 331 | $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-{$post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text ); |
| 332 | + } |
|
| 323 | 333 | $output = force_balance_tags( $output ); |
| 324 | 334 | } |
| 325 | 335 | } |
| 326 | 336 | |
| 327 | - if ( $preview ) // Preview fix for JavaScript bug with foreign languages. |
|
| 337 | + if ( $preview ) { |
|
| 338 | + // Preview fix for JavaScript bug with foreign languages. |
|
| 328 | 339 | $output = preg_replace_callback( '/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output ); |
| 340 | + } |
|
| 329 | 341 | |
| 330 | 342 | return $output; |
| 331 | 343 | } |
@@ -464,8 +476,9 @@ discard block |
||
| 464 | 476 | } |
| 465 | 477 | |
| 466 | 478 | $classes[] = 'post-' . $post->ID; |
| 467 | - if ( ! is_admin() ) |
|
| 468 | - $classes[] = $post->post_type; |
|
| 479 | + if ( ! is_admin() ) { |
|
| 480 | + $classes[] = $post->post_type; |
|
| 481 | + } |
|
| 469 | 482 | $classes[] = 'type-' . $post->post_type; |
| 470 | 483 | $classes[] = 'status-' . $post->post_status; |
| 471 | 484 | |
@@ -473,10 +486,11 @@ discard block |
||
| 473 | 486 | if ( post_type_supports( $post->post_type, 'post-formats' ) ) { |
| 474 | 487 | $post_format = get_post_format( $post->ID ); |
| 475 | 488 | |
| 476 | - if ( $post_format && !is_wp_error($post_format) ) |
|
| 477 | - $classes[] = 'format-' . sanitize_html_class( $post_format ); |
|
| 478 | - else |
|
| 479 | - $classes[] = 'format-standard'; |
|
| 489 | + if ( $post_format && !is_wp_error($post_format) ) { |
|
| 490 | + $classes[] = 'format-' . sanitize_html_class( $post_format ); |
|
| 491 | + } else { |
|
| 492 | + $classes[] = 'format-standard'; |
|
| 493 | + } |
|
| 480 | 494 | } |
| 481 | 495 | |
| 482 | 496 | $post_password_required = post_password_required( $post->ID ); |
@@ -572,27 +586,35 @@ discard block |
||
| 572 | 586 | |
| 573 | 587 | $classes = array(); |
| 574 | 588 | |
| 575 | - if ( is_rtl() ) |
|
| 576 | - $classes[] = 'rtl'; |
|
| 577 | - |
|
| 578 | - if ( is_front_page() ) |
|
| 579 | - $classes[] = 'home'; |
|
| 580 | - if ( is_home() ) |
|
| 581 | - $classes[] = 'blog'; |
|
| 582 | - if ( is_archive() ) |
|
| 583 | - $classes[] = 'archive'; |
|
| 584 | - if ( is_date() ) |
|
| 585 | - $classes[] = 'date'; |
|
| 589 | + if ( is_rtl() ) { |
|
| 590 | + $classes[] = 'rtl'; |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + if ( is_front_page() ) { |
|
| 594 | + $classes[] = 'home'; |
|
| 595 | + } |
|
| 596 | + if ( is_home() ) { |
|
| 597 | + $classes[] = 'blog'; |
|
| 598 | + } |
|
| 599 | + if ( is_archive() ) { |
|
| 600 | + $classes[] = 'archive'; |
|
| 601 | + } |
|
| 602 | + if ( is_date() ) { |
|
| 603 | + $classes[] = 'date'; |
|
| 604 | + } |
|
| 586 | 605 | if ( is_search() ) { |
| 587 | 606 | $classes[] = 'search'; |
| 588 | 607 | $classes[] = $wp_query->posts ? 'search-results' : 'search-no-results'; |
| 589 | 608 | } |
| 590 | - if ( is_paged() ) |
|
| 591 | - $classes[] = 'paged'; |
|
| 592 | - if ( is_attachment() ) |
|
| 593 | - $classes[] = 'attachment'; |
|
| 594 | - if ( is_404() ) |
|
| 595 | - $classes[] = 'error404'; |
|
| 609 | + if ( is_paged() ) { |
|
| 610 | + $classes[] = 'paged'; |
|
| 611 | + } |
|
| 612 | + if ( is_attachment() ) { |
|
| 613 | + $classes[] = 'attachment'; |
|
| 614 | + } |
|
| 615 | + if ( is_404() ) { |
|
| 616 | + $classes[] = 'error404'; |
|
| 617 | + } |
|
| 596 | 618 | |
| 597 | 619 | if ( is_single() ) { |
| 598 | 620 | $post_id = $wp_query->get_queried_object_id(); |
@@ -607,10 +629,11 @@ discard block |
||
| 607 | 629 | if ( post_type_supports( $post->post_type, 'post-formats' ) ) { |
| 608 | 630 | $post_format = get_post_format( $post->ID ); |
| 609 | 631 | |
| 610 | - if ( $post_format && !is_wp_error($post_format) ) |
|
| 611 | - $classes[] = 'single-format-' . sanitize_html_class( $post_format ); |
|
| 612 | - else |
|
| 613 | - $classes[] = 'single-format-standard'; |
|
| 632 | + if ( $post_format && !is_wp_error($post_format) ) { |
|
| 633 | + $classes[] = 'single-format-' . sanitize_html_class( $post_format ); |
|
| 634 | + } else { |
|
| 635 | + $classes[] = 'single-format-standard'; |
|
| 636 | + } |
|
| 614 | 637 | } |
| 615 | 638 | } |
| 616 | 639 | |
@@ -624,8 +647,9 @@ discard block |
||
| 624 | 647 | if ( is_post_type_archive() ) { |
| 625 | 648 | $classes[] = 'post-type-archive'; |
| 626 | 649 | $post_type = get_query_var( 'post_type' ); |
| 627 | - if ( is_array( $post_type ) ) |
|
| 628 | - $post_type = reset( $post_type ); |
|
| 650 | + if ( is_array( $post_type ) ) { |
|
| 651 | + $post_type = reset( $post_type ); |
|
| 652 | + } |
|
| 629 | 653 | $classes[] = 'post-type-archive-' . sanitize_html_class( $post_type ); |
| 630 | 654 | } elseif ( is_author() ) { |
| 631 | 655 | $author = $wp_query->get_queried_object(); |
@@ -703,16 +727,18 @@ discard block |
||
| 703 | 727 | } |
| 704 | 728 | } |
| 705 | 729 | |
| 706 | - if ( is_user_logged_in() ) |
|
| 707 | - $classes[] = 'logged-in'; |
|
| 730 | + if ( is_user_logged_in() ) { |
|
| 731 | + $classes[] = 'logged-in'; |
|
| 732 | + } |
|
| 708 | 733 | |
| 709 | 734 | if ( is_admin_bar_showing() ) { |
| 710 | 735 | $classes[] = 'admin-bar'; |
| 711 | 736 | $classes[] = 'no-customize-support'; |
| 712 | 737 | } |
| 713 | 738 | |
| 714 | - if ( get_background_color() !== get_theme_support( 'custom-background', 'default-color' ) || get_background_image() ) |
|
| 715 | - $classes[] = 'custom-background'; |
|
| 739 | + if ( get_background_color() !== get_theme_support( 'custom-background', 'default-color' ) || get_background_image() ) { |
|
| 740 | + $classes[] = 'custom-background'; |
|
| 741 | + } |
|
| 716 | 742 | |
| 717 | 743 | if ( has_custom_logo() ) { |
| 718 | 744 | $classes[] = 'wp-custom-logo'; |
@@ -720,33 +746,36 @@ discard block |
||
| 720 | 746 | |
| 721 | 747 | $page = $wp_query->get( 'page' ); |
| 722 | 748 | |
| 723 | - if ( ! $page || $page < 2 ) |
|
| 724 | - $page = $wp_query->get( 'paged' ); |
|
| 749 | + if ( ! $page || $page < 2 ) { |
|
| 750 | + $page = $wp_query->get( 'paged' ); |
|
| 751 | + } |
|
| 725 | 752 | |
| 726 | 753 | if ( $page && $page > 1 && ! is_404() ) { |
| 727 | 754 | $classes[] = 'paged-' . $page; |
| 728 | 755 | |
| 729 | - if ( is_single() ) |
|
| 730 | - $classes[] = 'single-paged-' . $page; |
|
| 731 | - elseif ( is_page() ) |
|
| 732 | - $classes[] = 'page-paged-' . $page; |
|
| 733 | - elseif ( is_category() ) |
|
| 734 | - $classes[] = 'category-paged-' . $page; |
|
| 735 | - elseif ( is_tag() ) |
|
| 736 | - $classes[] = 'tag-paged-' . $page; |
|
| 737 | - elseif ( is_date() ) |
|
| 738 | - $classes[] = 'date-paged-' . $page; |
|
| 739 | - elseif ( is_author() ) |
|
| 740 | - $classes[] = 'author-paged-' . $page; |
|
| 741 | - elseif ( is_search() ) |
|
| 742 | - $classes[] = 'search-paged-' . $page; |
|
| 743 | - elseif ( is_post_type_archive() ) |
|
| 744 | - $classes[] = 'post-type-paged-' . $page; |
|
| 756 | + if ( is_single() ) { |
|
| 757 | + $classes[] = 'single-paged-' . $page; |
|
| 758 | + } elseif ( is_page() ) { |
|
| 759 | + $classes[] = 'page-paged-' . $page; |
|
| 760 | + } elseif ( is_category() ) { |
|
| 761 | + $classes[] = 'category-paged-' . $page; |
|
| 762 | + } elseif ( is_tag() ) { |
|
| 763 | + $classes[] = 'tag-paged-' . $page; |
|
| 764 | + } elseif ( is_date() ) { |
|
| 765 | + $classes[] = 'date-paged-' . $page; |
|
| 766 | + } elseif ( is_author() ) { |
|
| 767 | + $classes[] = 'author-paged-' . $page; |
|
| 768 | + } elseif ( is_search() ) { |
|
| 769 | + $classes[] = 'search-paged-' . $page; |
|
| 770 | + } elseif ( is_post_type_archive() ) { |
|
| 771 | + $classes[] = 'post-type-paged-' . $page; |
|
| 772 | + } |
|
| 745 | 773 | } |
| 746 | 774 | |
| 747 | 775 | if ( ! empty( $class ) ) { |
| 748 | - if ( !is_array( $class ) ) |
|
| 749 | - $class = preg_split( '#\s+#', $class ); |
|
| 776 | + if ( !is_array( $class ) ) { |
|
| 777 | + $class = preg_split( '#\s+#', $class ); |
|
| 778 | + } |
|
| 750 | 779 | $classes = array_merge( $classes, $class ); |
| 751 | 780 | } else { |
| 752 | 781 | // Ensure that we always coerce class to being an array. |
@@ -779,18 +808,21 @@ discard block |
||
| 779 | 808 | function post_password_required( $post = null ) { |
| 780 | 809 | $post = get_post($post); |
| 781 | 810 | |
| 782 | - if ( empty( $post->post_password ) ) |
|
| 783 | - return false; |
|
| 811 | + if ( empty( $post->post_password ) ) { |
|
| 812 | + return false; |
|
| 813 | + } |
|
| 784 | 814 | |
| 785 | - if ( ! isset( $_COOKIE['wp-postpass_' . COOKIEHASH] ) ) |
|
| 786 | - return true; |
|
| 815 | + if ( ! isset( $_COOKIE['wp-postpass_' . COOKIEHASH] ) ) { |
|
| 816 | + return true; |
|
| 817 | + } |
|
| 787 | 818 | |
| 788 | 819 | require_once ABSPATH . WPINC . '/class-phpass.php'; |
| 789 | 820 | $hasher = new PasswordHash( 8, true ); |
| 790 | 821 | |
| 791 | 822 | $hash = wp_unslash( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] ); |
| 792 | - if ( 0 !== strpos( $hash, '$P$B' ) ) |
|
| 793 | - return true; |
|
| 823 | + if ( 0 !== strpos( $hash, '$P$B' ) ) { |
|
| 824 | + return true; |
|
| 825 | + } |
|
| 794 | 826 | |
| 795 | 827 | return ! $hasher->CheckPassword( $post->post_password, $hash ); |
| 796 | 828 | } |
@@ -942,12 +974,13 @@ discard block |
||
| 942 | 974 | if ( 1 == $i ) { |
| 943 | 975 | $url = get_permalink(); |
| 944 | 976 | } else { |
| 945 | - if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) ) |
|
| 946 | - $url = add_query_arg( 'page', $i, get_permalink() ); |
|
| 947 | - elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID ) |
|
| 948 | - $url = trailingslashit(get_permalink()) . user_trailingslashit("$wp_rewrite->pagination_base/" . $i, 'single_paged'); |
|
| 949 | - else |
|
| 950 | - $url = trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged'); |
|
| 977 | + if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) ) { |
|
| 978 | + $url = add_query_arg( 'page', $i, get_permalink() ); |
|
| 979 | + } elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID ) { |
|
| 980 | + $url = trailingslashit(get_permalink()) . user_trailingslashit("$wp_rewrite->pagination_base/" . $i, 'single_paged'); |
|
| 981 | + } else { |
|
| 982 | + $url = trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged'); |
|
| 983 | + } |
|
| 951 | 984 | } |
| 952 | 985 | |
| 953 | 986 | if ( is_preview() ) { |
@@ -978,13 +1011,14 @@ discard block |
||
| 978 | 1011 | function post_custom( $key = '' ) { |
| 979 | 1012 | $custom = get_post_custom(); |
| 980 | 1013 | |
| 981 | - if ( !isset( $custom[$key] ) ) |
|
| 982 | - return false; |
|
| 983 | - elseif ( 1 == count($custom[$key]) ) |
|
| 984 | - return $custom[$key][0]; |
|
| 985 | - else |
|
| 986 | - return $custom[$key]; |
|
| 987 | -} |
|
| 1014 | + if ( !isset( $custom[$key] ) ) { |
|
| 1015 | + return false; |
|
| 1016 | + } elseif ( 1 == count($custom[$key]) ) { |
|
| 1017 | + return $custom[$key][0]; |
|
| 1018 | + } else { |
|
| 1019 | + return $custom[$key]; |
|
| 1020 | + } |
|
| 1021 | + } |
|
| 988 | 1022 | |
| 989 | 1023 | /** |
| 990 | 1024 | * Display list of post custom fields. |
@@ -999,8 +1033,9 @@ discard block |
||
| 999 | 1033 | echo "<ul class='post-meta'>\n"; |
| 1000 | 1034 | foreach ( (array) $keys as $key ) { |
| 1001 | 1035 | $keyt = trim($key); |
| 1002 | - if ( is_protected_meta( $keyt, 'post' ) ) |
|
| 1003 | - continue; |
|
| 1036 | + if ( is_protected_meta( $keyt, 'post' ) ) { |
|
| 1037 | + continue; |
|
| 1038 | + } |
|
| 1004 | 1039 | $values = array_map('trim', get_post_custom_values($key)); |
| 1005 | 1040 | $value = implode($values,', '); |
| 1006 | 1041 | |
@@ -1280,13 +1315,15 @@ discard block |
||
| 1280 | 1315 | |
| 1281 | 1316 | // Show Home in the menu |
| 1282 | 1317 | if ( ! empty($args['show_home']) ) { |
| 1283 | - if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] ) |
|
| 1284 | - $text = __('Home'); |
|
| 1285 | - else |
|
| 1286 | - $text = $args['show_home']; |
|
| 1318 | + if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] ) { |
|
| 1319 | + $text = __('Home'); |
|
| 1320 | + } else { |
|
| 1321 | + $text = $args['show_home']; |
|
| 1322 | + } |
|
| 1287 | 1323 | $class = ''; |
| 1288 | - if ( is_front_page() && !is_paged() ) |
|
| 1289 | - $class = 'class="current_page_item"'; |
|
| 1324 | + if ( is_front_page() && !is_paged() ) { |
|
| 1325 | + $class = 'class="current_page_item"'; |
|
| 1326 | + } |
|
| 1290 | 1327 | $menu .= '<li ' . $class . '><a href="' . home_url( '/' ) . '">' . $args['link_before'] . $text . $args['link_after'] . '</a></li>'; |
| 1291 | 1328 | // If the front page is a page, add it to the exclude list |
| 1292 | 1329 | if (get_option('show_on_front') == 'page') { |
@@ -1345,11 +1382,12 @@ discard block |
||
| 1345 | 1382 | * @param array $args An array of arguments. |
| 1346 | 1383 | */ |
| 1347 | 1384 | $menu = apply_filters( 'wp_page_menu', $menu, $args ); |
| 1348 | - if ( $args['echo'] ) |
|
| 1349 | - echo $menu; |
|
| 1350 | - else |
|
| 1351 | - return $menu; |
|
| 1352 | -} |
|
| 1385 | + if ( $args['echo'] ) { |
|
| 1386 | + echo $menu; |
|
| 1387 | + } else { |
|
| 1388 | + return $menu; |
|
| 1389 | + } |
|
| 1390 | + } |
|
| 1353 | 1391 | |
| 1354 | 1392 | // |
| 1355 | 1393 | // Page helpers |
@@ -1368,14 +1406,16 @@ discard block |
||
| 1368 | 1406 | * @return string |
| 1369 | 1407 | */ |
| 1370 | 1408 | function walk_page_tree( $pages, $depth, $current_page, $r ) { |
| 1371 | - if ( empty($r['walker']) ) |
|
| 1372 | - $walker = new Walker_Page; |
|
| 1373 | - else |
|
| 1374 | - $walker = $r['walker']; |
|
| 1409 | + if ( empty($r['walker']) ) { |
|
| 1410 | + $walker = new Walker_Page; |
|
| 1411 | + } else { |
|
| 1412 | + $walker = $r['walker']; |
|
| 1413 | + } |
|
| 1375 | 1414 | |
| 1376 | 1415 | foreach ( (array) $pages as $page ) { |
| 1377 | - if ( $page->post_parent ) |
|
| 1378 | - $r['pages_with_children'][ $page->post_parent ] = true; |
|
| 1416 | + if ( $page->post_parent ) { |
|
| 1417 | + $r['pages_with_children'][ $page->post_parent ] = true; |
|
| 1418 | + } |
|
| 1379 | 1419 | } |
| 1380 | 1420 | |
| 1381 | 1421 | $args = array($pages, $depth, $r, $current_page); |
@@ -1393,10 +1433,12 @@ discard block |
||
| 1393 | 1433 | */ |
| 1394 | 1434 | function walk_page_dropdown_tree() { |
| 1395 | 1435 | $args = func_get_args(); |
| 1396 | - if ( empty($args[2]['walker']) ) // the user's options are the third parameter |
|
| 1436 | + if ( empty($args[2]['walker']) ) { |
|
| 1437 | + // the user's options are the third parameter |
|
| 1397 | 1438 | $walker = new Walker_PageDropdown; |
| 1398 | - else |
|
| 1399 | - $walker = $args[2]['walker']; |
|
| 1439 | + } else { |
|
| 1440 | + $walker = $args[2]['walker']; |
|
| 1441 | + } |
|
| 1400 | 1442 | |
| 1401 | 1443 | return call_user_func_array(array($walker, 'walk'), $args); |
| 1402 | 1444 | } |
@@ -1416,14 +1458,16 @@ discard block |
||
| 1416 | 1458 | * @param bool $permalink Optional, default is false. Whether to include permalink. |
| 1417 | 1459 | */ |
| 1418 | 1460 | function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $permalink = false ) { |
| 1419 | - if ( !empty( $deprecated ) ) |
|
| 1420 | - _deprecated_argument( __FUNCTION__, '2.5.0' ); |
|
| 1461 | + if ( !empty( $deprecated ) ) { |
|
| 1462 | + _deprecated_argument( __FUNCTION__, '2.5.0' ); |
|
| 1463 | + } |
|
| 1421 | 1464 | |
| 1422 | - if ( $fullsize ) |
|
| 1423 | - echo wp_get_attachment_link($id, 'full', $permalink); |
|
| 1424 | - else |
|
| 1425 | - echo wp_get_attachment_link($id, 'thumbnail', $permalink); |
|
| 1426 | -} |
|
| 1465 | + if ( $fullsize ) { |
|
| 1466 | + echo wp_get_attachment_link($id, 'full', $permalink); |
|
| 1467 | + } else { |
|
| 1468 | + echo wp_get_attachment_link($id, 'thumbnail', $permalink); |
|
| 1469 | + } |
|
| 1470 | + } |
|
| 1427 | 1471 | |
| 1428 | 1472 | /** |
| 1429 | 1473 | * Retrieve an attachment page link using an image or icon, if possible. |
@@ -1445,11 +1489,13 @@ discard block |
||
| 1445 | 1489 | function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '' ) { |
| 1446 | 1490 | $_post = get_post( $id ); |
| 1447 | 1491 | |
| 1448 | - if ( empty( $_post ) || ( 'attachment' != $_post->post_type ) || ! $url = wp_get_attachment_url( $_post->ID ) ) |
|
| 1449 | - return __( 'Missing Attachment' ); |
|
| 1492 | + if ( empty( $_post ) || ( 'attachment' != $_post->post_type ) || ! $url = wp_get_attachment_url( $_post->ID ) ) { |
|
| 1493 | + return __( 'Missing Attachment' ); |
|
| 1494 | + } |
|
| 1450 | 1495 | |
| 1451 | - if ( $permalink ) |
|
| 1452 | - $url = get_attachment_link( $_post->ID ); |
|
| 1496 | + if ( $permalink ) { |
|
| 1497 | + $url = get_attachment_link( $_post->ID ); |
|
| 1498 | + } |
|
| 1453 | 1499 | |
| 1454 | 1500 | if ( $text ) { |
| 1455 | 1501 | $link_text = $text; |
@@ -1459,8 +1505,9 @@ discard block |
||
| 1459 | 1505 | $link_text = ''; |
| 1460 | 1506 | } |
| 1461 | 1507 | |
| 1462 | - if ( trim( $link_text ) == '' ) |
|
| 1463 | - $link_text = $_post->post_title; |
|
| 1508 | + if ( trim( $link_text ) == '' ) { |
|
| 1509 | + $link_text = $_post->post_title; |
|
| 1510 | + } |
|
| 1464 | 1511 | |
| 1465 | 1512 | /** |
| 1466 | 1513 | * Filters a retrieved attachment page link. |
@@ -1489,8 +1536,9 @@ discard block |
||
| 1489 | 1536 | function prepend_attachment($content) { |
| 1490 | 1537 | $post = get_post(); |
| 1491 | 1538 | |
| 1492 | - if ( empty($post->post_type) || $post->post_type != 'attachment' ) |
|
| 1493 | - return $content; |
|
| 1539 | + if ( empty($post->post_type) || $post->post_type != 'attachment' ) { |
|
| 1540 | + return $content; |
|
| 1541 | + } |
|
| 1494 | 1542 | |
| 1495 | 1543 | if ( wp_attachment_is( 'video', $post ) ) { |
| 1496 | 1544 | $meta = wp_get_attachment_metadata( get_the_ID() ); |
@@ -1574,16 +1622,19 @@ discard block |
||
| 1574 | 1622 | * @return bool True on success, false on failure. |
| 1575 | 1623 | */ |
| 1576 | 1624 | function is_page_template( $template = '' ) { |
| 1577 | - if ( ! is_page() ) |
|
| 1578 | - return false; |
|
| 1625 | + if ( ! is_page() ) { |
|
| 1626 | + return false; |
|
| 1627 | + } |
|
| 1579 | 1628 | |
| 1580 | 1629 | $page_template = get_page_template_slug( get_queried_object_id() ); |
| 1581 | 1630 | |
| 1582 | - if ( empty( $template ) ) |
|
| 1583 | - return (bool) $page_template; |
|
| 1631 | + if ( empty( $template ) ) { |
|
| 1632 | + return (bool) $page_template; |
|
| 1633 | + } |
|
| 1584 | 1634 | |
| 1585 | - if ( $template == $page_template ) |
|
| 1586 | - return true; |
|
| 1635 | + if ( $template == $page_template ) { |
|
| 1636 | + return true; |
|
| 1637 | + } |
|
| 1587 | 1638 | |
| 1588 | 1639 | if ( is_array( $template ) ) { |
| 1589 | 1640 | if ( ( in_array( 'default', $template, true ) && ! $page_template ) |
@@ -1607,11 +1658,13 @@ discard block |
||
| 1607 | 1658 | */ |
| 1608 | 1659 | function get_page_template_slug( $post_id = null ) { |
| 1609 | 1660 | $post = get_post( $post_id ); |
| 1610 | - if ( ! $post || 'page' != $post->post_type ) |
|
| 1611 | - return false; |
|
| 1661 | + if ( ! $post || 'page' != $post->post_type ) { |
|
| 1662 | + return false; |
|
| 1663 | + } |
|
| 1612 | 1664 | $template = get_post_meta( $post->ID, '_wp_page_template', true ); |
| 1613 | - if ( ! $template || 'default' == $template ) |
|
| 1614 | - return ''; |
|
| 1665 | + if ( ! $template || 'default' == $template ) { |
|
| 1666 | + return ''; |
|
| 1667 | + } |
|
| 1615 | 1668 | return $template; |
| 1616 | 1669 | } |
| 1617 | 1670 | |
@@ -1625,11 +1678,13 @@ discard block |
||
| 1625 | 1678 | * @return string|false i18n formatted datetimestamp or localized 'Current Revision'. |
| 1626 | 1679 | */ |
| 1627 | 1680 | function wp_post_revision_title( $revision, $link = true ) { |
| 1628 | - if ( !$revision = get_post( $revision ) ) |
|
| 1629 | - return $revision; |
|
| 1681 | + if ( !$revision = get_post( $revision ) ) { |
|
| 1682 | + return $revision; |
|
| 1683 | + } |
|
| 1630 | 1684 | |
| 1631 | - if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) |
|
| 1632 | - return false; |
|
| 1685 | + if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) { |
|
| 1686 | + return false; |
|
| 1687 | + } |
|
| 1633 | 1688 | |
| 1634 | 1689 | /* translators: revision date format, see https://secure.php.net/date */ |
| 1635 | 1690 | $datef = _x( 'F j, Y @ H:i:s', 'revision date format' ); |
@@ -1639,13 +1694,15 @@ discard block |
||
| 1639 | 1694 | $currentf = _x( '%1$s [Current Revision]', 'post revision title extra' ); |
| 1640 | 1695 | |
| 1641 | 1696 | $date = date_i18n( $datef, strtotime( $revision->post_modified ) ); |
| 1642 | - if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) ) |
|
| 1643 | - $date = "<a href='$link'>$date</a>"; |
|
| 1697 | + if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) ) { |
|
| 1698 | + $date = "<a href='$link'>$date</a>"; |
|
| 1699 | + } |
|
| 1644 | 1700 | |
| 1645 | - if ( !wp_is_post_revision( $revision ) ) |
|
| 1646 | - $date = sprintf( $currentf, $date ); |
|
| 1647 | - elseif ( wp_is_post_autosave( $revision ) ) |
|
| 1648 | - $date = sprintf( $autosavef, $date ); |
|
| 1701 | + if ( !wp_is_post_revision( $revision ) ) { |
|
| 1702 | + $date = sprintf( $currentf, $date ); |
|
| 1703 | + } elseif ( wp_is_post_autosave( $revision ) ) { |
|
| 1704 | + $date = sprintf( $autosavef, $date ); |
|
| 1705 | + } |
|
| 1649 | 1706 | |
| 1650 | 1707 | return $date; |
| 1651 | 1708 | } |
@@ -1660,11 +1717,13 @@ discard block |
||
| 1660 | 1717 | * @return string|false gravatar, user, i18n formatted datetimestamp or localized 'Current Revision'. |
| 1661 | 1718 | */ |
| 1662 | 1719 | function wp_post_revision_title_expanded( $revision, $link = true ) { |
| 1663 | - if ( !$revision = get_post( $revision ) ) |
|
| 1664 | - return $revision; |
|
| 1720 | + if ( !$revision = get_post( $revision ) ) { |
|
| 1721 | + return $revision; |
|
| 1722 | + } |
|
| 1665 | 1723 | |
| 1666 | - if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) |
|
| 1667 | - return false; |
|
| 1724 | + if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) { |
|
| 1725 | + return false; |
|
| 1726 | + } |
|
| 1668 | 1727 | |
| 1669 | 1728 | $author = get_the_author_meta( 'display_name', $revision->post_author ); |
| 1670 | 1729 | /* translators: revision date format, see https://secure.php.net/date */ |
@@ -1673,8 +1732,9 @@ discard block |
||
| 1673 | 1732 | $gravatar = get_avatar( $revision->post_author, 24 ); |
| 1674 | 1733 | |
| 1675 | 1734 | $date = date_i18n( $datef, strtotime( $revision->post_modified ) ); |
| 1676 | - if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) ) |
|
| 1677 | - $date = "<a href='$link'>$date</a>"; |
|
| 1735 | + if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) ) { |
|
| 1736 | + $date = "<a href='$link'>$date</a>"; |
|
| 1737 | + } |
|
| 1678 | 1738 | |
| 1679 | 1739 | $revision_date_author = sprintf( |
| 1680 | 1740 | /* translators: post revision title: 1: author avatar, 2: author name, 3: time ago, 4: date */ |
@@ -1688,10 +1748,11 @@ discard block |
||
| 1688 | 1748 | $autosavef = __( '%1$s [Autosave]' ); |
| 1689 | 1749 | $currentf = __( '%1$s [Current Revision]' ); |
| 1690 | 1750 | |
| 1691 | - if ( !wp_is_post_revision( $revision ) ) |
|
| 1692 | - $revision_date_author = sprintf( $currentf, $revision_date_author ); |
|
| 1693 | - elseif ( wp_is_post_autosave( $revision ) ) |
|
| 1694 | - $revision_date_author = sprintf( $autosavef, $revision_date_author ); |
|
| 1751 | + if ( !wp_is_post_revision( $revision ) ) { |
|
| 1752 | + $revision_date_author = sprintf( $currentf, $revision_date_author ); |
|
| 1753 | + } elseif ( wp_is_post_autosave( $revision ) ) { |
|
| 1754 | + $revision_date_author = sprintf( $autosavef, $revision_date_author ); |
|
| 1755 | + } |
|
| 1695 | 1756 | |
| 1696 | 1757 | /** |
| 1697 | 1758 | * Filters the formatted author and date for a revision. |
@@ -1718,8 +1779,9 @@ discard block |
||
| 1718 | 1779 | * @param string $type 'all' (default), 'revision' or 'autosave' |
| 1719 | 1780 | */ |
| 1720 | 1781 | function wp_list_post_revisions( $post_id = 0, $type = 'all' ) { |
| 1721 | - if ( ! $post = get_post( $post_id ) ) |
|
| 1722 | - return; |
|
| 1782 | + if ( ! $post = get_post( $post_id ) ) { |
|
| 1783 | + return; |
|
| 1784 | + } |
|
| 1723 | 1785 | |
| 1724 | 1786 | // $args array with (parent, format, right, left, type) deprecated since 3.6 |
| 1725 | 1787 | if ( is_array( $type ) ) { |
@@ -1727,17 +1789,20 @@ discard block |
||
| 1727 | 1789 | _deprecated_argument( __FUNCTION__, '3.6.0' ); |
| 1728 | 1790 | } |
| 1729 | 1791 | |
| 1730 | - if ( ! $revisions = wp_get_post_revisions( $post->ID ) ) |
|
| 1731 | - return; |
|
| 1792 | + if ( ! $revisions = wp_get_post_revisions( $post->ID ) ) { |
|
| 1793 | + return; |
|
| 1794 | + } |
|
| 1732 | 1795 | |
| 1733 | 1796 | $rows = ''; |
| 1734 | 1797 | foreach ( $revisions as $revision ) { |
| 1735 | - if ( ! current_user_can( 'read_post', $revision->ID ) ) |
|
| 1736 | - continue; |
|
| 1798 | + if ( ! current_user_can( 'read_post', $revision->ID ) ) { |
|
| 1799 | + continue; |
|
| 1800 | + } |
|
| 1737 | 1801 | |
| 1738 | 1802 | $is_autosave = wp_is_post_autosave( $revision ); |
| 1739 | - if ( ( 'revision' === $type && $is_autosave ) || ( 'autosave' === $type && ! $is_autosave ) ) |
|
| 1740 | - continue; |
|
| 1803 | + if ( ( 'revision' === $type && $is_autosave ) || ( 'autosave' === $type && ! $is_autosave ) ) { |
|
| 1804 | + continue; |
|
| 1805 | + } |
|
| 1741 | 1806 | |
| 1742 | 1807 | $rows .= "\t<li>" . wp_post_revision_title_expanded( $revision ) . "</li>\n"; |
| 1743 | 1808 | } |