diff --git a/index.php b/index.php index dd3d554472..86334797d6 100644 --- a/index.php +++ b/index.php @@ -11,7 +11,7 @@ * * @var bool */ -define('WP_USE_THEMES', true); +define( 'WP_USE_THEMES', true ); /** Loads the WordPress Environment and Template */ require( dirname( __FILE__ ) . '/wp-blog-header.php' ); diff --git a/wp-activate.php b/wp-activate.php index 1a7d1ecdb9..5150c299f4 100644 --- a/wp-activate.php +++ b/wp-activate.php @@ -9,17 +9,18 @@ define( 'WP_INSTALLING', true ); /** Sets up the WordPress Environment. */ -require( dirname(__FILE__) . '/wp-load.php' ); +require( dirname( __FILE__ ) . '/wp-load.php' ); require( dirname( __FILE__ ) . '/wp-blog-header.php' ); -if ( !is_multisite() ) { +if ( ! is_multisite() ) { wp_redirect( wp_registration_url() ); die(); } -if ( is_object( $wp_object_cache ) ) +if ( is_object( $wp_object_cache ) ) { $wp_object_cache->cache_enabled = false; +} // Fix for page title $wp_query->is_404 = false; @@ -43,10 +44,10 @@ function do_activate_header() { * Fires before the Site Activation page is loaded. * * Fires on the {@see 'wp_head'} action. - * - * @since 3.0.0 - */ - do_action( 'activate_wp_head' ); + * + * @since 3.0.0 + */ + do_action( 'activate_wp_head' ); } add_action( 'wp_head', 'do_activate_header' ); @@ -73,28 +74,29 @@ get_header( 'wp-activate' );
- + -

-
+

+

- -
+ +

- +

- get_error_code() || 'blog_taken' == $result->get_error_code() ) { - $signup = $result->get_error_data(); - ?> -

+ $key = ! empty( $_GET['key'] ) ? $_GET['key'] : $_POST['key']; + $result = wpmu_activate_signup( $key ); + if ( is_wp_error( $result ) ) { + if ( 'already_active' == $result->get_error_code() || 'blog_taken' == $result->get_error_code() ) { + $signup = $result->get_error_data(); + ?> +

'; if ( $signup->domain . $signup->path == '' ) { @@ -117,40 +119,46 @@ get_header( 'wp-activate' ); ); } echo '

'; - } else { - ?> -

+ } else { + ?> +

get_error_message(); ?>

-

+ } + } else { + $url = isset( $result['blog_id'] ) ? get_home_url( (int) $result['blog_id'] ) : ''; + $user = get_userdata( (int) $result['user_id'] ); + ?> +

-

user_login ?>

-

+

user_login; ?>

+

- -

+ View your site or Log in' ), $url, esc_url( $login_url ) ); - ?>

- -

+

+ +

+ Log in or go back to the homepage.' ), network_site_url( 'wp-login.php', 'login' ), network_home_url() ); - ?>

- +

+
@@ -158,4 +166,5 @@ get_header( 'wp-activate' ); var key_input = document.getElementById('key'); key_input && key_input.focus(); -

-

+

@@ -114,7 +114,7 @@ include( ABSPATH . 'wp-admin/admin-header.php' );

-

+

@@ -182,33 +182,42 @@ include( ABSPATH . 'wp-admin/admin-header.php' ); ); ?> -

early tester or getting involved with the Gutenberg project? Contribute on GitHub.' ), +

+ early tester or getting involved with the Gutenberg project? Contribute on GitHub.' ), __( 'https://wordpress.org/plugins/gutenberg/' ), - 'https://github.com/WordPress/gutenberg' ); ?>

+ 'https://github.com/WordPress/gutenberg' + ); + ?> +


-

+

+ ?> +

-

+ Check out the full list.' ), 'https://make.wordpress.org/core/2017/11/01/improvements-to-the-customize-js-api-in-4-9/' ); - ?>

+ ?> +

@@ -352,16 +361,22 @@ __( 'Version %s addressed one security issue.' ); __( 'Version %s addressed some security issues.' ); /* translators: 1: WordPress version number, 2: plural number of bugs. */ -_n_noop( 'Version %1$s addressed %2$s bug.', - 'Version %1$s addressed %2$s bugs.' ); +_n_noop( + 'Version %1$s addressed %2$s bug.', + 'Version %1$s addressed %2$s bugs.' +); /* translators: 1: WordPress version number, 2: plural number of bugs. Singular security issue. */ -_n_noop( 'Version %1$s addressed a security issue and fixed %2$s bug.', - 'Version %1$s addressed a security issue and fixed %2$s bugs.' ); +_n_noop( + 'Version %1$s addressed a security issue and fixed %2$s bug.', + 'Version %1$s addressed a security issue and fixed %2$s bugs.' +); /* translators: 1: WordPress version number, 2: plural number of bugs. More than one security issue. */ -_n_noop( 'Version %1$s addressed some security issues and fixed %2$s bug.', - 'Version %1$s addressed some security issues and fixed %2$s bugs.' ); +_n_noop( + 'Version %1$s addressed some security issues and fixed %2$s bug.', + 'Version %1$s addressed some security issues and fixed %2$s bugs.' +); /* translators: %s: Codex URL */ __( 'For more information, see the release notes.' ); diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index 8a1533254f..02254ec454 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -25,8 +25,9 @@ require_once( dirname( dirname( __FILE__ ) ) . '/wp-load.php' ); send_origin_headers(); // Require an action parameter -if ( empty( $_REQUEST['action'] ) ) +if ( empty( $_REQUEST['action'] ) ) { wp_die( '0', 400 ); +} /** Load WordPress Administration APIs */ require_once( ABSPATH . 'wp-admin/includes/admin.php' ); @@ -44,39 +45,104 @@ nocache_headers(); do_action( 'admin_init' ); $core_actions_get = array( - 'fetch-list', 'ajax-tag-search', 'wp-compression-test', 'imgedit-preview', 'oembed-cache', - 'autocomplete-user', 'dashboard-widgets', 'logged-in', + 'fetch-list', + 'ajax-tag-search', + 'wp-compression-test', + 'imgedit-preview', + 'oembed-cache', + 'autocomplete-user', + 'dashboard-widgets', + 'logged-in', ); $core_actions_post = array( - 'oembed-cache', 'image-editor', 'delete-comment', 'delete-tag', 'delete-link', - 'delete-meta', 'delete-post', 'trash-post', 'untrash-post', 'delete-page', 'dim-comment', - 'add-link-category', 'add-tag', 'get-tagcloud', 'get-comments', 'replyto-comment', - 'edit-comment', 'add-menu-item', 'add-meta', 'add-user', 'closed-postboxes', - 'hidden-columns', 'update-welcome-panel', 'menu-get-metabox', 'wp-link-ajax', - 'menu-locations-save', 'menu-quick-search', 'meta-box-order', 'get-permalink', - 'sample-permalink', 'inline-save', 'inline-save-tax', 'find_posts', 'widgets-order', - 'save-widget', 'delete-inactive-widgets', 'set-post-thumbnail', 'date_format', 'time_format', - 'wp-remove-post-lock', 'dismiss-wp-pointer', 'upload-attachment', 'get-attachment', - 'query-attachments', 'save-attachment', 'save-attachment-compat', 'send-link-to-editor', - 'send-attachment-to-editor', 'save-attachment-order', 'heartbeat', 'get-revision-diffs', - 'save-user-color-scheme', 'update-widget', 'query-themes', 'parse-embed', 'set-attachment-thumbnail', - 'parse-media-shortcode', 'destroy-sessions', 'install-plugin', 'update-plugin', 'crop-image', - 'generate-password', 'save-wporg-username', 'delete-plugin', 'search-plugins', - 'search-install-plugins', 'activate-plugin', 'update-theme', 'delete-theme', 'install-theme', - 'get-post-thumbnail-html', 'get-community-events', 'edit-theme-plugin-file', + 'oembed-cache', + 'image-editor', + 'delete-comment', + 'delete-tag', + 'delete-link', + 'delete-meta', + 'delete-post', + 'trash-post', + 'untrash-post', + 'delete-page', + 'dim-comment', + 'add-link-category', + 'add-tag', + 'get-tagcloud', + 'get-comments', + 'replyto-comment', + 'edit-comment', + 'add-menu-item', + 'add-meta', + 'add-user', + 'closed-postboxes', + 'hidden-columns', + 'update-welcome-panel', + 'menu-get-metabox', + 'wp-link-ajax', + 'menu-locations-save', + 'menu-quick-search', + 'meta-box-order', + 'get-permalink', + 'sample-permalink', + 'inline-save', + 'inline-save-tax', + 'find_posts', + 'widgets-order', + 'save-widget', + 'delete-inactive-widgets', + 'set-post-thumbnail', + 'date_format', + 'time_format', + 'wp-remove-post-lock', + 'dismiss-wp-pointer', + 'upload-attachment', + 'get-attachment', + 'query-attachments', + 'save-attachment', + 'save-attachment-compat', + 'send-link-to-editor', + 'send-attachment-to-editor', + 'save-attachment-order', + 'heartbeat', + 'get-revision-diffs', + 'save-user-color-scheme', + 'update-widget', + 'query-themes', + 'parse-embed', + 'set-attachment-thumbnail', + 'parse-media-shortcode', + 'destroy-sessions', + 'install-plugin', + 'update-plugin', + 'crop-image', + 'generate-password', + 'save-wporg-username', + 'delete-plugin', + 'search-plugins', + 'search-install-plugins', + 'activate-plugin', + 'update-theme', + 'delete-theme', + 'install-theme', + 'get-post-thumbnail-html', + 'get-community-events', + 'edit-theme-plugin-file', ); // Deprecated $core_actions_post_deprecated = array( 'wp-fullscreen-save-post', 'press-this-save-post', 'press-this-add-category' ); -$core_actions_post = array_merge( $core_actions_post, $core_actions_post_deprecated ); +$core_actions_post = array_merge( $core_actions_post, $core_actions_post_deprecated ); // Register core Ajax calls. -if ( ! empty( $_GET['action'] ) && in_array( $_GET['action'], $core_actions_get ) ) +if ( ! empty( $_GET['action'] ) && in_array( $_GET['action'], $core_actions_get ) ) { add_action( 'wp_ajax_' . $_GET['action'], 'wp_ajax_' . str_replace( '-', '_', $_GET['action'] ), 1 ); +} -if ( ! empty( $_POST['action'] ) && in_array( $_POST['action'], $core_actions_post ) ) +if ( ! empty( $_POST['action'] ) && in_array( $_POST['action'], $core_actions_post ) ) { add_action( 'wp_ajax_' . $_POST['action'], 'wp_ajax_' . str_replace( '-', '_', $_POST['action'] ), 1 ); +} add_action( 'wp_ajax_nopriv_heartbeat', 'wp_ajax_nopriv_heartbeat', 1 ); diff --git a/wp-admin/admin-footer.php b/wp-admin/admin-footer.php index 2317a03bd8..6014d1767d 100644 --- a/wp-admin/admin-footer.php +++ b/wp-admin/admin-footer.php @@ -7,8 +7,9 @@ */ // don't load directly -if ( !defined('ABSPATH') ) - die('-1'); +if ( ! defined( 'ABSPATH' ) ) { + die( '-1' ); +} /** * @global string $hook_suffix @@ -99,9 +100,10 @@ do_action( 'admin_print_footer_scripts' ); do_action( "admin_footer-{$hook_suffix}" ); // get_site_option() won't exist when auto upgrading from <= 2.7 -if ( function_exists('get_site_option') ) { - if ( false === get_site_option('can_compress_scripts') ) +if ( function_exists( 'get_site_option' ) ) { + if ( false === get_site_option( 'can_compress_scripts' ) ) { compression_test(); + } } ?> diff --git a/wp-admin/admin-functions.php b/wp-admin/admin-functions.php index abbb07998e..1185268744 100644 --- a/wp-admin/admin-functions.php +++ b/wp-admin/admin-functions.php @@ -9,7 +9,7 @@ * @subpackage Administration */ -_deprecated_file( basename(__FILE__), '2.5.0', 'wp-admin/includes/admin.php' ); +_deprecated_file( basename( __FILE__ ), '2.5.0', 'wp-admin/includes/admin.php' ); /** WordPress Administration API: Includes all Administration functions. */ -require_once(ABSPATH . 'wp-admin/includes/admin.php'); +require_once( ABSPATH . 'wp-admin/includes/admin.php' ); diff --git a/wp-admin/admin-header.php b/wp-admin/admin-header.php index d5ceeccd61..ed9c0399f9 100644 --- a/wp-admin/admin-header.php +++ b/wp-admin/admin-header.php @@ -6,9 +6,10 @@ * @subpackage Administration */ -@header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset')); -if ( ! defined( 'WP_ADMIN' ) ) +@header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) ); +if ( ! defined( 'WP_ADMIN' ) ) { require_once( dirname( __FILE__ ) . '/admin.php' ); +} /** * In case admin-header.php is included in a function. @@ -26,8 +27,9 @@ global $title, $hook_suffix, $current_screen, $wp_locale, $pagenow, $update_title, $total_update_count, $parent_file; // Catch plugins that include admin-header.php before admin.php completes. -if ( empty( $current_screen ) ) +if ( empty( $current_screen ) ) { set_current_screen(); +} get_admin_page_title(); $title = esc_html( strip_tags( $title ) ); @@ -69,10 +71,10 @@ _wp_admin_html_begin(); wp_enqueue_style( 'colors' ); wp_enqueue_style( 'ie' ); -wp_enqueue_script('utils'); +wp_enqueue_script( 'utils' ); wp_enqueue_script( 'svg-painter' ); -$admin_body_class = preg_replace('/[^a-z0-9_-]+/i', '-', $hook_suffix); +$admin_body_class = preg_replace( '/[^a-z0-9_-]+/i', '-', $hook_suffix ); ?> -Links / Edit Link' ), 'link-manager.php' ); - $submit_text = __('Update Link'); - $form_name = 'editlink'; +if ( ! empty( $link_id ) ) { + $heading = sprintf( __( 'Links / Edit Link' ), 'link-manager.php' ); + $submit_text = __( 'Update Link' ); + $form_name = 'editlink'; $nonce_action = 'update-bookmark_' . $link_id; } else { - $heading = sprintf( __( 'Links / Add New Link' ), 'link-manager.php' ); - $submit_text = __('Add Link'); - $form_name = 'addlink'; + $heading = sprintf( __( 'Links / Add New Link' ), 'link-manager.php' ); + $submit_text = __( 'Add Link' ); + $form_name = 'addlink'; $nonce_action = 'add-bookmark'; } require_once( ABSPATH . 'wp-admin/includes/meta-boxes.php' ); -add_meta_box('linksubmitdiv', __('Save'), 'link_submit_meta_box', null, 'side', 'core'); -add_meta_box('linkcategorydiv', __('Categories'), 'link_categories_meta_box', null, 'normal', 'core'); -add_meta_box('linktargetdiv', __('Target'), 'link_target_meta_box', null, 'normal', 'core'); -add_meta_box('linkxfndiv', __('Link Relationship (XFN)'), 'link_xfn_meta_box', null, 'normal', 'core'); -add_meta_box('linkadvanceddiv', __('Advanced'), 'link_advanced_meta_box', null, 'normal', 'core'); +add_meta_box( 'linksubmitdiv', __( 'Save' ), 'link_submit_meta_box', null, 'side', 'core' ); +add_meta_box( 'linkcategorydiv', __( 'Categories' ), 'link_categories_meta_box', null, 'normal', 'core' ); +add_meta_box( 'linktargetdiv', __( 'Target' ), 'link_target_meta_box', null, 'normal', 'core' ); +add_meta_box( 'linkxfndiv', __( 'Link Relationship (XFN)' ), 'link_xfn_meta_box', null, 'normal', 'core' ); +add_meta_box( 'linkadvanceddiv', __( 'Advanced' ), 'link_advanced_meta_box', null, 'normal', 'core' ); /** This action is documented in wp-admin/edit-form-advanced.php */ do_action( 'add_meta_boxes', 'link', $link ); @@ -49,16 +50,23 @@ do_action( 'do_meta_boxes', 'link', 'advanced', $link ); /** This action is documented in wp-admin/edit-form-advanced.php */ do_action( 'do_meta_boxes', 'link', 'side', $link ); -add_screen_option('layout_columns', array('max' => 2, 'default' => 2) ); +add_screen_option( + 'layout_columns', array( + 'max' => 2, + 'default' => 2, + ) +); -get_current_screen()->add_help_tab( array( - 'id' => 'overview', - 'title' => __('Overview'), - 'content' => - '

' . __( 'You can add or edit links on this screen by entering information in each of the boxes. Only the link’s web address and name (the text you want to display on your site as the link) are required fields.' ) . '

' . - '

' . __( 'The boxes for link name, web address, and description have fixed positions, while the others may be repositioned using drag and drop. You can also hide boxes you don’t use in the Screen Options tab, or minimize boxes by clicking on the title bar of the box.' ) . '

' . - '

' . __( 'XFN stands for XHTML Friends Network, which is optional. WordPress allows the generation of XFN attributes to show how you are related to the authors/owners of the site to which you are linking.' ) . '

' -) ); +get_current_screen()->add_help_tab( + array( + 'id' => 'overview', + 'title' => __( 'Overview' ), + 'content' => + '

' . __( 'You can add or edit links on this screen by entering information in each of the boxes. Only the link’s web address and name (the text you want to display on your site as the link) are required fields.' ) . '

' . + '

' . __( 'The boxes for link name, web address, and description have fixed positions, while the others may be repositioned using drag and drop. You can also hide boxes you don’t use in the Screen Options tab, or minimize boxes by clicking on the title bar of the box.' ) . '

' . + '

' . __( 'XFN stands for XHTML Friends Network, which is optional. WordPress allows the generation of XFN attributes to show how you are related to the authors/owners of the site to which you are linking.' ) . '

', + ) +); get_current_screen()->set_help_sidebar( '

' . __( 'For more information:' ) . '

' . @@ -70,16 +78,18 @@ require_once( ABSPATH . 'wp-admin/admin-header.php' ); ?>
-

+

+?> +
-

+

@@ -90,33 +100,34 @@ if ( ! empty( $link_added ) ) { wp_nonce_field( $nonce_action ); wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); -wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?> +wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); +?>
-

+

- -

+ +

-

+

- -

http://wordpress.org/ — don’t forget the http://'); ?>

+ +

http://wordpress.org/ — don’t forget the http://' ); ?>

-

+

- -

+ +

@@ -133,19 +144,20 @@ $side_meta_boxes = do_meta_boxes( 'link', 'side', $link );
+if ( $link_id ) : +?> - - + + diff --git a/wp-admin/edit-tag-form.php b/wp-admin/edit-tag-form.php index f8c83feac3..9b29553c3a 100644 --- a/wp-admin/edit-tag-form.php +++ b/wp-admin/edit-tag-form.php @@ -14,7 +14,7 @@ if ( ! defined( 'ABSPATH' ) ) { // Back compat hooks if ( 'category' == $taxonomy ) { /** - * Fires before the Edit Category form. + * Fires before the Edit Category form. * * @since 2.1.0 * @deprecated 3.0.0 Use {$taxonomy}_pre_edit_form instead. @@ -74,16 +74,19 @@ do_action( "{$taxonomy}_pre_edit_form", $tag, $taxonomy ); ?>
- * @since 3.7.0 */ do_action( "{$taxonomy}_term_edit_form_tag" ); -?>> +?> +> - - + + name ) ) { -

+

- + name ) ) { $slug = isset( $tag->slug ) ? apply_filters( 'editable_slug', $tag->slug, $tag ) : ''; ?> -

+

- + @@ -167,7 +171,8 @@ if ( isset( $tag->name ) ) { /** This filter is documented in wp-admin/edit-tags.php */ $dropdown_args = apply_filters( 'taxonomy_parent_dropdown_args', $dropdown_args, $taxonomy, 'edit' ); - wp_dropdown_categories( $dropdown_args ); ?> + wp_dropdown_categories( $dropdown_args ); + ?>

@@ -179,7 +184,7 @@ if ( isset( $tag->name ) ) { -

+

term_id ) ) : ?> - term_id", 'delete-tag_' . $tag->term_id ) ) ?>"> + term_id", 'delete-tag_' . $tag->term_id ) ); ?>"> @@ -279,4 +284,5 @@ do_action( "{$taxonomy}_edit_form", $tag, $taxonomy ); -name, get_taxonomies( array( 'show_ui' => true ) ) ) ) { wp_die( __( 'Sorry, you are not allowed to edit terms in this taxonomy.' ) ); @@ -36,149 +38,168 @@ if ( ! current_user_can( $tax->cap->manage_terms ) ) { */ global $post_type; -$wp_list_table = _get_list_table('WP_Terms_List_Table'); -$pagenum = $wp_list_table->get_pagenum(); +$wp_list_table = _get_list_table( 'WP_Terms_List_Table' ); +$pagenum = $wp_list_table->get_pagenum(); $title = $tax->labels->name; if ( 'post' != $post_type ) { - $parent_file = ( 'attachment' == $post_type ) ? 'upload.php' : "edit.php?post_type=$post_type"; + $parent_file = ( 'attachment' == $post_type ) ? 'upload.php' : "edit.php?post_type=$post_type"; $submenu_file = "edit-tags.php?taxonomy=$taxonomy&post_type=$post_type"; } elseif ( 'link_category' == $tax->name ) { - $parent_file = 'link-manager.php'; + $parent_file = 'link-manager.php'; $submenu_file = 'edit-tags.php?taxonomy=link_category'; } else { - $parent_file = 'edit.php'; + $parent_file = 'edit.php'; $submenu_file = "edit-tags.php?taxonomy=$taxonomy"; } -add_screen_option( 'per_page', array( 'default' => 20, 'option' => 'edit_' . $tax->name . '_per_page' ) ); +add_screen_option( + 'per_page', array( + 'default' => 20, + 'option' => 'edit_' . $tax->name . '_per_page', + ) +); -get_current_screen()->set_screen_reader_content( array( - 'heading_pagination' => $tax->labels->items_list_navigation, - 'heading_list' => $tax->labels->items_list, -) ); +get_current_screen()->set_screen_reader_content( + array( + 'heading_pagination' => $tax->labels->items_list_navigation, + 'heading_list' => $tax->labels->items_list, + ) +); $location = false; -$referer = wp_get_referer(); +$referer = wp_get_referer(); if ( ! $referer ) { // For POST requests. $referer = wp_unslash( $_SERVER['REQUEST_URI'] ); } $referer = remove_query_arg( array( '_wp_http_referer', '_wpnonce', 'error', 'message', 'paged' ), $referer ); switch ( $wp_list_table->current_action() ) { -case 'add-tag': - check_admin_referer( 'add-tag', '_wpnonce_add-tag' ); + case 'add-tag': + check_admin_referer( 'add-tag', '_wpnonce_add-tag' ); - if ( ! current_user_can( $tax->cap->edit_terms ) ) { - wp_die( - '

' . __( 'Cheatin’ uh?' ) . '

' . - '

' . __( 'Sorry, you are not allowed to create terms in this taxonomy.' ) . '

', - 403 - ); - } + if ( ! current_user_can( $tax->cap->edit_terms ) ) { + wp_die( + '

' . __( 'Cheatin’ uh?' ) . '

' . + '

' . __( 'Sorry, you are not allowed to create terms in this taxonomy.' ) . '

', + 403 + ); + } - $ret = wp_insert_term( $_POST['tag-name'], $taxonomy, $_POST ); - if ( $ret && !is_wp_error( $ret ) ) - $location = add_query_arg( 'message', 1, $referer ); - else - $location = add_query_arg( array( 'error' => true, 'message' => 4 ), $referer ); + $ret = wp_insert_term( $_POST['tag-name'], $taxonomy, $_POST ); + if ( $ret && ! is_wp_error( $ret ) ) { + $location = add_query_arg( 'message', 1, $referer ); + } else { + $location = add_query_arg( + array( + 'error' => true, + 'message' => 4, + ), $referer + ); + } - break; - -case 'delete': - if ( ! isset( $_REQUEST['tag_ID'] ) ) { break; - } - $tag_ID = (int) $_REQUEST['tag_ID']; - check_admin_referer( 'delete-tag_' . $tag_ID ); + case 'delete': + if ( ! isset( $_REQUEST['tag_ID'] ) ) { + break; + } - if ( ! current_user_can( 'delete_term', $tag_ID ) ) { - wp_die( - '

' . __( 'Cheatin’ uh?' ) . '

' . - '

' . __( 'Sorry, you are not allowed to delete this item.' ) . '

', - 403 - ); - } + $tag_ID = (int) $_REQUEST['tag_ID']; + check_admin_referer( 'delete-tag_' . $tag_ID ); - wp_delete_term( $tag_ID, $taxonomy ); + if ( ! current_user_can( 'delete_term', $tag_ID ) ) { + wp_die( + '

' . __( 'Cheatin’ uh?' ) . '

' . + '

' . __( 'Sorry, you are not allowed to delete this item.' ) . '

', + 403 + ); + } - $location = add_query_arg( 'message', 2, $referer ); - - // When deleting a term, prevent the action from redirecting back to a term that no longer exists. - $location = remove_query_arg( array( 'tag_ID', 'action' ), $location ); - - break; - -case 'bulk-delete': - check_admin_referer( 'bulk-tags' ); - - if ( ! current_user_can( $tax->cap->delete_terms ) ) { - wp_die( - '

' . __( 'Cheatin’ uh?' ) . '

' . - '

' . __( 'Sorry, you are not allowed to delete these items.' ) . '

', - 403 - ); - } - - $tags = (array) $_REQUEST['delete_tags']; - foreach ( $tags as $tag_ID ) { wp_delete_term( $tag_ID, $taxonomy ); - } - $location = add_query_arg( 'message', 6, $referer ); + $location = add_query_arg( 'message', 2, $referer ); - break; + // When deleting a term, prevent the action from redirecting back to a term that no longer exists. + $location = remove_query_arg( array( 'tag_ID', 'action' ), $location ); -case 'edit': - if ( ! isset( $_REQUEST['tag_ID'] ) ) { break; - } - $term_id = (int) $_REQUEST['tag_ID']; - $term = get_term( $term_id ); + case 'bulk-delete': + check_admin_referer( 'bulk-tags' ); - if ( ! $term instanceof WP_Term ) { - wp_die( __( 'You attempted to edit an item that doesn’t exist. Perhaps it was deleted?' ) ); - } + if ( ! current_user_can( $tax->cap->delete_terms ) ) { + wp_die( + '

' . __( 'Cheatin’ uh?' ) . '

' . + '

' . __( 'Sorry, you are not allowed to delete these items.' ) . '

', + 403 + ); + } - wp_redirect( esc_url_raw( get_edit_term_link( $term_id, $taxonomy, $post_type ) ) ); - exit; + $tags = (array) $_REQUEST['delete_tags']; + foreach ( $tags as $tag_ID ) { + wp_delete_term( $tag_ID, $taxonomy ); + } -case 'editedtag': - $tag_ID = (int) $_POST['tag_ID']; - check_admin_referer( 'update-tag_' . $tag_ID ); + $location = add_query_arg( 'message', 6, $referer ); - if ( ! current_user_can( 'edit_term', $tag_ID ) ) { - wp_die( - '

' . __( 'Cheatin’ uh?' ) . '

' . - '

' . __( 'Sorry, you are not allowed to edit this item.' ) . '

', - 403 - ); - } - - $tag = get_term( $tag_ID, $taxonomy ); - if ( ! $tag ) - wp_die( __( 'You attempted to edit an item that doesn’t exist. Perhaps it was deleted?' ) ); - - $ret = wp_update_term( $tag_ID, $taxonomy, $_POST ); - - if ( $ret && ! is_wp_error( $ret ) ) { - $location = add_query_arg( 'message', 3, $referer ); - } else { - $location = add_query_arg( array( 'error' => true, 'message' => 5 ), $referer ); - } - break; -default: - if ( ! $wp_list_table->current_action() || ! isset( $_REQUEST['delete_tags'] ) ) { break; - } - check_admin_referer( 'bulk-tags' ); - $tags = (array) $_REQUEST['delete_tags']; - /** This action is documented in wp-admin/edit-comments.php */ - $location = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $location, $wp_list_table->current_action(), $tags ); - break; + + case 'edit': + if ( ! isset( $_REQUEST['tag_ID'] ) ) { + break; + } + + $term_id = (int) $_REQUEST['tag_ID']; + $term = get_term( $term_id ); + + if ( ! $term instanceof WP_Term ) { + wp_die( __( 'You attempted to edit an item that doesn’t exist. Perhaps it was deleted?' ) ); + } + + wp_redirect( esc_url_raw( get_edit_term_link( $term_id, $taxonomy, $post_type ) ) ); + exit; + + case 'editedtag': + $tag_ID = (int) $_POST['tag_ID']; + check_admin_referer( 'update-tag_' . $tag_ID ); + + if ( ! current_user_can( 'edit_term', $tag_ID ) ) { + wp_die( + '

' . __( 'Cheatin’ uh?' ) . '

' . + '

' . __( 'Sorry, you are not allowed to edit this item.' ) . '

', + 403 + ); + } + + $tag = get_term( $tag_ID, $taxonomy ); + if ( ! $tag ) { + wp_die( __( 'You attempted to edit an item that doesn’t exist. Perhaps it was deleted?' ) ); + } + + $ret = wp_update_term( $tag_ID, $taxonomy, $_POST ); + + if ( $ret && ! is_wp_error( $ret ) ) { + $location = add_query_arg( 'message', 3, $referer ); + } else { + $location = add_query_arg( + array( + 'error' => true, + 'message' => 5, + ), $referer + ); + } + break; + default: + if ( ! $wp_list_table->current_action() || ! isset( $_REQUEST['delete_tags'] ) ) { + break; + } + check_admin_referer( 'bulk-tags' ); + $tags = (array) $_REQUEST['delete_tags']; + /** This action is documented in wp-admin/edit-comments.php */ + $location = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $location, $wp_list_table->current_action(), $tags ); + break; } if ( ! $location && ! empty( $_REQUEST['_wp_http_referer'] ) ) { @@ -210,66 +231,77 @@ if ( $pagenum > $total_pages && $total_pages > 0 ) { exit; } -wp_enqueue_script('admin-tags'); -if ( current_user_can($tax->cap->edit_terms) ) - wp_enqueue_script('inline-edit-tax'); +wp_enqueue_script( 'admin-tags' ); +if ( current_user_can( $tax->cap->edit_terms ) ) { + wp_enqueue_script( 'inline-edit-tax' ); +} -if ( 'category' == $taxonomy || 'link_category' == $taxonomy || 'post_tag' == $taxonomy ) { - $help =''; - if ( 'category' == $taxonomy ) - $help = '

' . sprintf(__( 'You can use categories to define sections of your site and group related posts. The default category is “Uncategorized” until you change it in your writing settings.' ) , 'options-writing.php' ) . '

'; - elseif ( 'link_category' == $taxonomy ) +if ( 'category' == $taxonomy || 'link_category' == $taxonomy || 'post_tag' == $taxonomy ) { + $help = ''; + if ( 'category' == $taxonomy ) { + $help = '

' . sprintf( __( 'You can use categories to define sections of your site and group related posts. The default category is “Uncategorized” until you change it in your writing settings.' ), 'options-writing.php' ) . '

'; + } elseif ( 'link_category' == $taxonomy ) { $help = '

' . __( 'You can create groups of links by using Link Categories. Link Category names must be unique and Link Categories are separate from the categories you use for posts.' ) . '

'; - else + } else { $help = '

' . __( 'You can assign keywords to your posts using tags. Unlike categories, tags have no hierarchy, meaning there’s no relationship from one tag to another.' ) . '

'; + } - if ( 'link_category' == $taxonomy ) + if ( 'link_category' == $taxonomy ) { $help .= '

' . __( 'You can delete Link Categories in the Bulk Action pull-down, but that action does not delete the links within the category. Instead, it moves them to the default Link Category.' ) . '

'; - else - $help .='

' . __( 'What’s the difference between categories and tags? Normally, tags are ad-hoc keywords that identify important information in your post (names, subjects, etc) that may or may not recur in other posts, while categories are pre-determined sections. If you think of your site like a book, the categories are like the Table of Contents and the tags are like the terms in the index.' ) . '

'; + } else { + $help .= '

' . __( 'What’s the difference between categories and tags? Normally, tags are ad-hoc keywords that identify important information in your post (names, subjects, etc) that may or may not recur in other posts, while categories are pre-determined sections. If you think of your site like a book, the categories are like the Table of Contents and the tags are like the terms in the index.' ) . '

'; + } - get_current_screen()->add_help_tab( array( - 'id' => 'overview', - 'title' => __('Overview'), - 'content' => $help, - ) ); + get_current_screen()->add_help_tab( + array( + 'id' => 'overview', + 'title' => __( 'Overview' ), + 'content' => $help, + ) + ); if ( 'category' == $taxonomy || 'post_tag' == $taxonomy ) { - if ( 'category' == $taxonomy ) + if ( 'category' == $taxonomy ) { $help = '

' . __( 'When adding a new category on this screen, you’ll fill in the following fields:' ) . '

'; - else + } else { $help = '

' . __( 'When adding a new tag on this screen, you’ll fill in the following fields:' ) . '

'; + } $help .= '
    ' . '
  • ' . __( 'Name — The name is how it appears on your site.' ) . '
  • '; - if ( ! global_terms_enabled() ) + if ( ! global_terms_enabled() ) { $help .= '
  • ' . __( 'Slug — The “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.' ) . '
  • '; + } - if ( 'category' == $taxonomy ) + if ( 'category' == $taxonomy ) { $help .= '
  • ' . __( 'Parent — Categories, unlike tags, can have a hierarchy. You might have a Jazz category, and under that have child categories for Bebop and Big Band. Totally optional. To create a subcategory, just choose another category from the Parent dropdown.' ) . '
  • '; + } $help .= '
  • ' . __( 'Description — The description is not prominent by default; however, some themes may display it.' ) . '
  • ' . '
' . '

' . __( 'You can change the display of this screen using the Screen Options tab to set how many items are displayed per screen and to display/hide columns in the table.' ) . '

'; - get_current_screen()->add_help_tab( array( - 'id' => 'adding-terms', - 'title' => 'category' == $taxonomy ? __( 'Adding Categories' ) : __( 'Adding Tags' ), - 'content' => $help, - ) ); + get_current_screen()->add_help_tab( + array( + 'id' => 'adding-terms', + 'title' => 'category' == $taxonomy ? __( 'Adding Categories' ) : __( 'Adding Tags' ), + 'content' => $help, + ) + ); } $help = '

' . __( 'For more information:' ) . '

'; - if ( 'category' == $taxonomy ) + if ( 'category' == $taxonomy ) { $help .= '

' . __( 'Documentation on Categories' ) . '

'; - elseif ( 'link_category' == $taxonomy ) + } elseif ( 'link_category' == $taxonomy ) { $help .= '

' . __( 'Documentation on Link Categories' ) . '

'; - else + } else { $help .= '

' . __( 'Documentation on Tags' ) . '

'; + } - $help .= '

' . __('Support Forums') . '

'; + $help .= '

' . __( 'Support Forums' ) . '

'; get_current_screen()->set_help_sidebar( $help ); @@ -305,13 +337,15 @@ if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) {

- +
- - + + search_box( $tax->labels->search_items, 'tag' ); ?> @@ -324,10 +358,10 @@ endif; ?> cap->edit_terms) ) { +if ( current_user_can( $tax->cap->edit_terms ) ) { if ( 'category' == $taxonomy ) { /** - * Fires before the Add Category form. + * Fires before the Add Category form. * * @since 2.1.0 * @deprecated 3.0.0 Use {$taxonomy}_pre_add_form instead. @@ -371,7 +405,8 @@ if ( current_user_can($tax->cap->edit_terms) ) {

labels->add_new_item; ?>

-cap->edit_terms) ) { * @since 3.7.0 */ do_action( "{$taxonomy}_term_new_form_tag" ); -?>> +?> +> - - - - + + + +
-

+

-

+

- +
-

+

' . apply_filters( 'the_category', get_cat_name( get_option( 'default_category') ), '', '' ) . '' + '' . apply_filters( 'the_category', get_cat_name( get_option( 'default_category' ) ), '', '' ) . '' ); ?>

-

category to tag converter.' ), esc_url( $import_link ) ) ?>

+

category to tag converter.' ), esc_url( $import_link ) ); ?>

-

tag to category converter.' ), esc_url( $import_link ) ) ;?>

+

tag to category converter.' ), esc_url( $import_link ) ); ?>

- true ) ) ) ) { wp_die( __( 'Sorry, you are not allowed to edit posts in this post type.' ) ); @@ -28,11 +29,12 @@ if ( 'attachment' === $typenow ) { */ global $post_type, $post_type_object; -$post_type = $typenow; +$post_type = $typenow; $post_type_object = get_post_type_object( $post_type ); -if ( ! $post_type_object ) +if ( ! $post_type_object ) { wp_die( __( 'Invalid post type.' ) ); +} if ( ! current_user_can( $post_type_object->cap->edit_posts ) ) { wp_die( @@ -42,8 +44,8 @@ if ( ! current_user_can( $post_type_object->cap->edit_posts ) ) { ); } -$wp_list_table = _get_list_table('WP_Posts_List_Table'); -$pagenum = $wp_list_table->get_pagenum(); +$wp_list_table = _get_list_table( 'WP_Posts_List_Table' ); +$pagenum = $wp_list_table->get_pagenum(); // Back-compat for viewing comments of an entry foreach ( array( 'p', 'attachment_id', 'page_id' ) as $_redirect ) { @@ -55,30 +57,32 @@ foreach ( array( 'p', 'attachment_id', 'page_id' ) as $_redirect ) { unset( $_redirect ); if ( 'post' != $post_type ) { - $parent_file = "edit.php?post_type=$post_type"; - $submenu_file = "edit.php?post_type=$post_type"; + $parent_file = "edit.php?post_type=$post_type"; + $submenu_file = "edit.php?post_type=$post_type"; $post_new_file = "post-new.php?post_type=$post_type"; } else { - $parent_file = 'edit.php'; - $submenu_file = 'edit.php'; + $parent_file = 'edit.php'; + $submenu_file = 'edit.php'; $post_new_file = 'post-new.php'; } $doaction = $wp_list_table->current_action(); if ( $doaction ) { - check_admin_referer('bulk-posts'); + check_admin_referer( 'bulk-posts' ); - $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'locked', 'ids'), wp_get_referer() ); - if ( ! $sendback ) + $sendback = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'locked', 'ids' ), wp_get_referer() ); + if ( ! $sendback ) { $sendback = admin_url( $parent_file ); + } $sendback = add_query_arg( 'paged', $pagenum, $sendback ); - if ( strpos($sendback, 'post.php') !== false ) - $sendback = admin_url($post_new_file); + if ( strpos( $sendback, 'post.php' ) !== false ) { + $sendback = admin_url( $post_new_file ); + } if ( 'delete_all' == $doaction ) { // Prepare for deletion of all posts with a specified post status (i.e. Empty trash). - $post_status = preg_replace('/[^a-z0-9_-]+/i', '', $_REQUEST['post_status']); + $post_status = preg_replace( '/[^a-z0-9_-]+/i', '', $_REQUEST['post_status'] ); // Validate the post status exists. if ( get_post_status_object( $post_status ) ) { $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type=%s AND post_status = %s", $post_type, $post_status ) ); @@ -88,11 +92,11 @@ if ( $doaction ) { $post_ids = $_REQUEST['media']; } elseif ( isset( $_REQUEST['ids'] ) ) { $post_ids = explode( ',', $_REQUEST['ids'] ); - } elseif ( !empty( $_REQUEST['post'] ) ) { - $post_ids = array_map('intval', $_REQUEST['post']); + } elseif ( ! empty( $_REQUEST['post'] ) ) { + $post_ids = array_map( 'intval', $_REQUEST['post'] ); } - if ( !isset( $post_ids ) ) { + if ( ! isset( $post_ids ) ) { wp_redirect( $sendback ); exit; } @@ -102,63 +106,76 @@ if ( $doaction ) { $trashed = $locked = 0; foreach ( (array) $post_ids as $post_id ) { - if ( !current_user_can( 'delete_post', $post_id) ) - wp_die( __('Sorry, you are not allowed to move this item to the Trash.') ); + if ( ! current_user_can( 'delete_post', $post_id ) ) { + wp_die( __( 'Sorry, you are not allowed to move this item to the Trash.' ) ); + } if ( wp_check_post_lock( $post_id ) ) { $locked++; continue; } - if ( !wp_trash_post($post_id) ) - wp_die( __('Error in moving to Trash.') ); + if ( ! wp_trash_post( $post_id ) ) { + wp_die( __( 'Error in moving to Trash.' ) ); + } $trashed++; } - $sendback = add_query_arg( array('trashed' => $trashed, 'ids' => join(',', $post_ids), 'locked' => $locked ), $sendback ); + $sendback = add_query_arg( + array( + 'trashed' => $trashed, + 'ids' => join( ',', $post_ids ), + 'locked' => $locked, + ), $sendback + ); break; case 'untrash': $untrashed = 0; foreach ( (array) $post_ids as $post_id ) { - if ( !current_user_can( 'delete_post', $post_id) ) - wp_die( __('Sorry, you are not allowed to restore this item from the Trash.') ); + if ( ! current_user_can( 'delete_post', $post_id ) ) { + wp_die( __( 'Sorry, you are not allowed to restore this item from the Trash.' ) ); + } - if ( !wp_untrash_post($post_id) ) - wp_die( __('Error in restoring from Trash.') ); + if ( ! wp_untrash_post( $post_id ) ) { + wp_die( __( 'Error in restoring from Trash.' ) ); + } $untrashed++; } - $sendback = add_query_arg('untrashed', $untrashed, $sendback); + $sendback = add_query_arg( 'untrashed', $untrashed, $sendback ); break; case 'delete': $deleted = 0; foreach ( (array) $post_ids as $post_id ) { - $post_del = get_post($post_id); + $post_del = get_post( $post_id ); - if ( !current_user_can( 'delete_post', $post_id ) ) - wp_die( __('Sorry, you are not allowed to delete this item.') ); + if ( ! current_user_can( 'delete_post', $post_id ) ) { + wp_die( __( 'Sorry, you are not allowed to delete this item.' ) ); + } if ( $post_del->post_type == 'attachment' ) { - if ( ! wp_delete_attachment($post_id) ) - wp_die( __('Error in deleting.') ); + if ( ! wp_delete_attachment( $post_id ) ) { + wp_die( __( 'Error in deleting.' ) ); + } } else { - if ( !wp_delete_post($post_id) ) - wp_die( __('Error in deleting.') ); + if ( ! wp_delete_post( $post_id ) ) { + wp_die( __( 'Error in deleting.' ) ); + } } $deleted++; } - $sendback = add_query_arg('deleted', $deleted, $sendback); + $sendback = add_query_arg( 'deleted', $deleted, $sendback ); break; case 'edit': - if ( isset($_REQUEST['bulk_edit']) ) { - $done = bulk_edit_posts($_REQUEST); + if ( isset( $_REQUEST['bulk_edit'] ) ) { + $done = bulk_edit_posts( $_REQUEST ); - if ( is_array($done) ) { + if ( is_array( $done ) ) { $done['updated'] = count( $done['updated'] ); $done['skipped'] = count( $done['skipped'] ); - $done['locked'] = count( $done['locked'] ); - $sendback = add_query_arg( $done, $sendback ); + $done['locked'] = count( $done['locked'] ); + $sendback = add_query_arg( $done, $sendback ); } } break; @@ -168,107 +185,126 @@ if ( $doaction ) { break; } - $sendback = remove_query_arg( array('action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status', 'post', 'bulk_edit', 'post_view'), $sendback ); + $sendback = remove_query_arg( array( 'action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status', 'post', 'bulk_edit', 'post_view' ), $sendback ); - wp_redirect($sendback); + wp_redirect( $sendback ); exit(); -} elseif ( ! empty($_REQUEST['_wp_http_referer']) ) { - wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), wp_unslash($_SERVER['REQUEST_URI']) ) ); +} elseif ( ! empty( $_REQUEST['_wp_http_referer'] ) ) { + wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ); exit; } $wp_list_table->prepare_items(); -wp_enqueue_script('inline-edit-post'); -wp_enqueue_script('heartbeat'); +wp_enqueue_script( 'inline-edit-post' ); +wp_enqueue_script( 'heartbeat' ); $title = $post_type_object->labels->name; if ( 'post' == $post_type ) { - get_current_screen()->add_help_tab( array( - 'id' => 'overview', - 'title' => __('Overview'), - 'content' => - '

' . __('This screen provides access to all of your posts. You can customize the display of this screen to suit your workflow.') . '

' - ) ); - get_current_screen()->add_help_tab( array( - 'id' => 'screen-content', - 'title' => __('Screen Content'), - 'content' => - '

' . __('You can customize the display of this screen’s contents in a number of ways:') . '

' . - '
    ' . - '
  • ' . __('You can hide/display columns based on your needs and decide how many posts to list per screen using the Screen Options tab.') . '
  • ' . - '
  • ' . __( 'You can filter the list of posts by post status using the text links above the posts list to only show posts with that status. The default view is to show all posts.' ) . '
  • ' . - '
  • ' . __('You can view posts in a simple title list or with an excerpt using the Screen Options tab.') . '
  • ' . - '
  • ' . __('You can refine the list to show only posts in a specific category or from a specific month by using the dropdown menus above the posts list. Click the Filter button after making your selection. You also can refine the list by clicking on the post author, category or tag in the posts list.') . '
  • ' . - '
' - ) ); - get_current_screen()->add_help_tab( array( - 'id' => 'action-links', - 'title' => __('Available Actions'), - 'content' => - '

' . __('Hovering over a row in the posts list will display action links that allow you to manage your post. You can perform the following actions:') . '

' . - '
    ' . - '
  • ' . __('Edit takes you to the editing screen for that post. You can also reach that screen by clicking on the post title.') . '
  • ' . - '
  • ' . __('Quick Edit provides inline access to the metadata of your post, allowing you to update post details without leaving this screen.') . '
  • ' . - '
  • ' . __('Trash removes your post from this list and places it in the trash, from which you can permanently delete it.') . '
  • ' . - '
  • ' . __('Preview will show you what your draft post will look like if you publish it. View will take you to your live site to view the post. Which link is available depends on your post’s status.') . '
  • ' . - '
' - ) ); - get_current_screen()->add_help_tab( array( - 'id' => 'bulk-actions', - 'title' => __('Bulk Actions'), - 'content' => - '

' . __('You can also edit or move multiple posts to the trash at once. Select the posts you want to act on using the checkboxes, then select the action you want to take from the Bulk Actions menu and click Apply.') . '

' . - '

' . __('When using Bulk Edit, you can change the metadata (categories, author, etc.) for all selected posts at once. To remove a post from the grouping, just click the x next to its name in the Bulk Edit area that appears.') . '

' - ) ); + get_current_screen()->add_help_tab( + array( + 'id' => 'overview', + 'title' => __( 'Overview' ), + 'content' => + '

' . __( 'This screen provides access to all of your posts. You can customize the display of this screen to suit your workflow.' ) . '

', + ) + ); + get_current_screen()->add_help_tab( + array( + 'id' => 'screen-content', + 'title' => __( 'Screen Content' ), + 'content' => + '

' . __( 'You can customize the display of this screen’s contents in a number of ways:' ) . '

' . + '
    ' . + '
  • ' . __( 'You can hide/display columns based on your needs and decide how many posts to list per screen using the Screen Options tab.' ) . '
  • ' . + '
  • ' . __( 'You can filter the list of posts by post status using the text links above the posts list to only show posts with that status. The default view is to show all posts.' ) . '
  • ' . + '
  • ' . __( 'You can view posts in a simple title list or with an excerpt using the Screen Options tab.' ) . '
  • ' . + '
  • ' . __( 'You can refine the list to show only posts in a specific category or from a specific month by using the dropdown menus above the posts list. Click the Filter button after making your selection. You also can refine the list by clicking on the post author, category or tag in the posts list.' ) . '
  • ' . + '
', + ) + ); + get_current_screen()->add_help_tab( + array( + 'id' => 'action-links', + 'title' => __( 'Available Actions' ), + 'content' => + '

' . __( 'Hovering over a row in the posts list will display action links that allow you to manage your post. You can perform the following actions:' ) . '

' . + '
    ' . + '
  • ' . __( 'Edit takes you to the editing screen for that post. You can also reach that screen by clicking on the post title.' ) . '
  • ' . + '
  • ' . __( 'Quick Edit provides inline access to the metadata of your post, allowing you to update post details without leaving this screen.' ) . '
  • ' . + '
  • ' . __( 'Trash removes your post from this list and places it in the trash, from which you can permanently delete it.' ) . '
  • ' . + '
  • ' . __( 'Preview will show you what your draft post will look like if you publish it. View will take you to your live site to view the post. Which link is available depends on your post’s status.' ) . '
  • ' . + '
', + ) + ); + get_current_screen()->add_help_tab( + array( + 'id' => 'bulk-actions', + 'title' => __( 'Bulk Actions' ), + 'content' => + '

' . __( 'You can also edit or move multiple posts to the trash at once. Select the posts you want to act on using the checkboxes, then select the action you want to take from the Bulk Actions menu and click Apply.' ) . '

' . + '

' . __( 'When using Bulk Edit, you can change the metadata (categories, author, etc.) for all selected posts at once. To remove a post from the grouping, just click the x next to its name in the Bulk Edit area that appears.' ) . '

', + ) + ); get_current_screen()->set_help_sidebar( - '

' . __('For more information:') . '

' . - '

' . __('Documentation on Managing Posts') . '

' . - '

' . __('Support Forums') . '

' + '

' . __( 'For more information:' ) . '

' . + '

' . __( 'Documentation on Managing Posts' ) . '

' . + '

' . __( 'Support Forums' ) . '

' ); } elseif ( 'page' == $post_type ) { - get_current_screen()->add_help_tab( array( - 'id' => 'overview', - 'title' => __('Overview'), - 'content' => - '

' . __('Pages are similar to posts in that they have a title, body text, and associated metadata, but they are different in that they are not part of the chronological blog stream, kind of like permanent posts. Pages are not categorized or tagged, but can have a hierarchy. You can nest pages under other pages by making one the “Parent” of the other, creating a group of pages.') . '

' - ) ); - get_current_screen()->add_help_tab( array( - 'id' => 'managing-pages', - 'title' => __('Managing Pages'), - 'content' => - '

' . __('Managing pages is very similar to managing posts, and the screens can be customized in the same way.') . '

' . - '

' . __('You can also perform the same types of actions, including narrowing the list by using the filters, acting on a page using the action links that appear when you hover over a row, or using the Bulk Actions menu to edit the metadata for multiple pages at once.') . '

' - ) ); + get_current_screen()->add_help_tab( + array( + 'id' => 'overview', + 'title' => __( 'Overview' ), + 'content' => + '

' . __( 'Pages are similar to posts in that they have a title, body text, and associated metadata, but they are different in that they are not part of the chronological blog stream, kind of like permanent posts. Pages are not categorized or tagged, but can have a hierarchy. You can nest pages under other pages by making one the “Parent” of the other, creating a group of pages.' ) . '

', + ) + ); + get_current_screen()->add_help_tab( + array( + 'id' => 'managing-pages', + 'title' => __( 'Managing Pages' ), + 'content' => + '

' . __( 'Managing pages is very similar to managing posts, and the screens can be customized in the same way.' ) . '

' . + '

' . __( 'You can also perform the same types of actions, including narrowing the list by using the filters, acting on a page using the action links that appear when you hover over a row, or using the Bulk Actions menu to edit the metadata for multiple pages at once.' ) . '

', + ) + ); get_current_screen()->set_help_sidebar( - '

' . __('For more information:') . '

' . - '

' . __('Documentation on Managing Pages') . '

' . - '

' . __('Support Forums') . '

' + '

' . __( 'For more information:' ) . '

' . + '

' . __( 'Documentation on Managing Pages' ) . '

' . + '

' . __( 'Support Forums' ) . '

' ); } -get_current_screen()->set_screen_reader_content( array( - 'heading_views' => $post_type_object->labels->filter_items_list, - 'heading_pagination' => $post_type_object->labels->items_list_navigation, - 'heading_list' => $post_type_object->labels->items_list, -) ); +get_current_screen()->set_screen_reader_content( + array( + 'heading_views' => $post_type_object->labels->filter_items_list, + 'heading_pagination' => $post_type_object->labels->items_list_navigation, + 'heading_list' => $post_type_object->labels->items_list, + ) +); -add_screen_option( 'per_page', array( 'default' => 20, 'option' => 'edit_' . $post_type . '_per_page' ) ); +add_screen_option( + 'per_page', array( + 'default' => 20, + 'option' => 'edit_' . $post_type . '_per_page', + ) +); $bulk_counts = array( - 'updated' => isset( $_REQUEST['updated'] ) ? absint( $_REQUEST['updated'] ) : 0, - 'locked' => isset( $_REQUEST['locked'] ) ? absint( $_REQUEST['locked'] ) : 0, - 'deleted' => isset( $_REQUEST['deleted'] ) ? absint( $_REQUEST['deleted'] ) : 0, - 'trashed' => isset( $_REQUEST['trashed'] ) ? absint( $_REQUEST['trashed'] ) : 0, + 'updated' => isset( $_REQUEST['updated'] ) ? absint( $_REQUEST['updated'] ) : 0, + 'locked' => isset( $_REQUEST['locked'] ) ? absint( $_REQUEST['locked'] ) : 0, + 'deleted' => isset( $_REQUEST['deleted'] ) ? absint( $_REQUEST['deleted'] ) : 0, + 'trashed' => isset( $_REQUEST['trashed'] ) ? absint( $_REQUEST['trashed'] ) : 0, 'untrashed' => isset( $_REQUEST['untrashed'] ) ? absint( $_REQUEST['untrashed'] ) : 0, ); -$bulk_messages = array(); +$bulk_messages = array(); $bulk_messages['post'] = array( 'updated' => _n( '%s post updated.', '%s posts updated.', $bulk_counts['updated'] ), 'locked' => ( 1 == $bulk_counts['locked'] ) ? __( '1 post not updated, somebody is editing it.' ) : @@ -298,14 +334,16 @@ $bulk_messages['page'] = array( * @param array $bulk_counts Array of item counts for each message, used to build internationalized strings. */ $bulk_messages = apply_filters( 'bulk_post_updated_messages', $bulk_messages, $bulk_counts ); -$bulk_counts = array_filter( $bulk_counts ); +$bulk_counts = array_filter( $bulk_counts ); require_once( ABSPATH . 'wp-admin/admin-header.php' ); ?>
-

+labels->name ); -?>

+?> + cap->create_posts ) ) { @@ -324,19 +362,21 @@ if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) { // If we have a bulk message to issue: $messages = array(); foreach ( $bulk_counts as $message => $count ) { - if ( isset( $bulk_messages[ $post_type ][ $message ] ) ) + if ( isset( $bulk_messages[ $post_type ][ $message ] ) ) { $messages[] = sprintf( $bulk_messages[ $post_type ][ $message ], number_format_i18n( $count ) ); - elseif ( isset( $bulk_messages['post'][ $message ] ) ) + } elseif ( isset( $bulk_messages['post'][ $message ] ) ) { $messages[] = sprintf( $bulk_messages['post'][ $message ], number_format_i18n( $count ) ); + } if ( $message == 'trashed' && isset( $_REQUEST['ids'] ) ) { - $ids = preg_replace( '/[^0-9,]/', '', $_REQUEST['ids'] ); - $messages[] = '' . __('Undo') . ''; + $ids = preg_replace( '/[^0-9,]/', '', $_REQUEST['ids'] ); + $messages[] = '' . __( 'Undo' ) . ''; } } -if ( $messages ) +if ( $messages ) { echo '

' . join( ' ', $messages ) . '

'; +} unset( $messages ); $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'locked', 'skipped', 'updated', 'deleted', 'trashed', 'untrashed' ), $_SERVER['REQUEST_URI'] ); @@ -348,7 +388,7 @@ $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'locked', 'skipped', 'updated search_box( $post_type_object->labels->search_items, 'post' ); ?> - + @@ -364,8 +404,9 @@ $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'locked', 'skipped', 'updated has_items() ) +if ( $wp_list_table->has_items() ) { $wp_list_table->inline_edit(); +} ?>
diff --git a/wp-admin/export.php b/wp-admin/export.php index c1d4d8b529..89e5d34da6 100644 --- a/wp-admin/export.php +++ b/wp-admin/export.php @@ -9,12 +9,13 @@ /** Load WordPress Bootstrap */ require_once( dirname( __FILE__ ) . '/admin.php' ); -if ( !current_user_can('export') ) - wp_die(__('Sorry, you are not allowed to export the content of this site.')); +if ( ! current_user_can( 'export' ) ) { + wp_die( __( 'Sorry, you are not allowed to export the content of this site.' ) ); +} /** Load WordPress export API */ require_once( ABSPATH . 'wp-admin/includes/export.php' ); -$title = __('Export'); +$title = __( 'Export' ); /** * Display JavaScript on the page. @@ -25,34 +26,36 @@ function export_add_js() { ?> add_help_tab( array( - 'id' => 'overview', - 'title' => __('Overview'), - 'content' => '

' . __('You can export a file of your site’s content in order to import it into another installation or platform. The export file will be an XML file format called WXR. Posts, pages, comments, custom fields, categories, and tags can be included. You can choose for the WXR file to include only certain posts or pages by setting the dropdown filters to limit the export by category, author, date range by month, or publishing status.') . '

' . - '

' . __('Once generated, your WXR file can be imported by another WordPress site or by another blogging platform able to access this format.') . '

', -) ); +get_current_screen()->add_help_tab( + array( + 'id' => 'overview', + 'title' => __( 'Overview' ), + 'content' => '

' . __( 'You can export a file of your site’s content in order to import it into another installation or platform. The export file will be an XML file format called WXR. Posts, pages, comments, custom fields, categories, and tags can be included. You can choose for the WXR file to include only certain posts or pages by setting the dropdown filters to limit the export by category, author, date range by month, or publishing status.' ) . '

' . + '

' . __( 'Once generated, your WXR file can be imported by another WordPress site or by another blogging platform able to access this format.' ) . '

', + ) +); get_current_screen()->set_help_sidebar( - '

' . __('For more information:') . '

' . - '

' . __('Documentation on Export') . '

' . - '

' . __('Support Forums') . '

' + '

' . __( 'For more information:' ) . '

' . + '

' . __( 'Documentation on Export' ) . '

' . + '

' . __( 'Support Forums' ) . '

' ); // If the 'download' URL parameter is set, a WXR export file is baked and returned. @@ -64,41 +67,45 @@ if ( isset( $_GET['download'] ) ) { } elseif ( 'posts' == $_GET['content'] ) { $args['content'] = 'post'; - if ( $_GET['cat'] ) + if ( $_GET['cat'] ) { $args['category'] = (int) $_GET['cat']; + } - if ( $_GET['post_author'] ) + if ( $_GET['post_author'] ) { $args['author'] = (int) $_GET['post_author']; + } if ( $_GET['post_start_date'] || $_GET['post_end_date'] ) { $args['start_date'] = $_GET['post_start_date']; - $args['end_date'] = $_GET['post_end_date']; + $args['end_date'] = $_GET['post_end_date']; } - if ( $_GET['post_status'] ) + if ( $_GET['post_status'] ) { $args['status'] = $_GET['post_status']; + } } elseif ( 'pages' == $_GET['content'] ) { $args['content'] = 'page'; - if ( $_GET['page_author'] ) + if ( $_GET['page_author'] ) { $args['author'] = (int) $_GET['page_author']; + } if ( $_GET['page_start_date'] || $_GET['page_end_date'] ) { $args['start_date'] = $_GET['page_start_date']; - $args['end_date'] = $_GET['page_end_date']; + $args['end_date'] = $_GET['page_end_date']; } - if ( $_GET['page_status'] ) + if ( $_GET['page_status'] ) { $args['status'] = $_GET['page_status']; + } } elseif ( 'attachment' == $_GET['content'] ) { $args['content'] = 'attachment'; if ( $_GET['attachment_start_date'] || $_GET['attachment_end_date'] ) { $args['start_date'] = $_GET['attachment_start_date']; - $args['end_date'] = $_GET['attachment_end_date']; + $args['end_date'] = $_GET['attachment_end_date']; } - } - else { + } else { $args['content'] = $_GET['content']; } @@ -130,20 +137,26 @@ require_once( ABSPATH . 'wp-admin/admin-header.php' ); function export_date_options( $post_type = 'post' ) { global $wpdb, $wp_locale; - $months = $wpdb->get_results( $wpdb->prepare( " + $months = $wpdb->get_results( + $wpdb->prepare( + " SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month FROM $wpdb->posts WHERE post_type = %s AND post_status != 'auto-draft' ORDER BY post_date DESC - ", $post_type ) ); + ", $post_type + ) + ); $month_count = count( $months ); - if ( !$month_count || ( 1 == $month_count && 0 == $months[0]->month ) ) + if ( ! $month_count || ( 1 == $month_count && 0 == $months[0]->month ) ) { return; + } foreach ( $months as $date ) { - if ( 0 == $date->year ) + if ( 0 == $date->year ) { continue; + } $month = zeroise( $date->month, 2 ); echo ''; @@ -154,9 +167,9 @@ function export_date_options( $post_type = 'post' ) {

-

-

-

+

+

+

@@ -170,20 +183,23 @@ function export_date_options( $post_type = 'post' ) {
  • @@ -205,8 +221,10 @@ function export_date_options( $post_type = 'post' ) { @@ -219,13 +237,16 @@ function export_date_options( $post_type = 'post' ) {
  • @@ -254,7 +275,14 @@ function export_date_options( $post_type = 'post' ) {
- false, 'can_export' => true ), 'objects' ) as $post_type ) : ?> + false, + 'can_export' => true, + ), 'objects' +) as $post_type ) : +?>

@@ -287,7 +315,7 @@ function export_date_options( $post_type = 'post' ) { do_action( 'export_filters' ); ?> - +
diff --git a/wp-admin/freedoms.php b/wp-admin/freedoms.php index 28c16461b7..e3fd29ff79 100644 --- a/wp-admin/freedoms.php +++ b/wp-admin/freedoms.php @@ -42,12 +42,15 @@ include( ABSPATH . 'wp-admin/admin-header.php' );

check out our trademark guidelines first.' ), 'https://wordpressfoundation.org/trademark-policy/' ); ?>

-

+ plugins and themes there. If you get a plugin or theme from another source, make sure to ask them if it’s GPL first. If they don’t respect the WordPress license, we don’t recommend them.' ), $plugins_url, $themes_url, 'https://wordpress.org/about/license/' ); ?>

+ printf( __( 'Every plugin and theme in WordPress.org’s directory is 100%% GPL or a similarly free and compatible license, so you can feel safe finding plugins and themes there. If you get a plugin or theme from another source, make sure to ask them if it’s GPL first. If they don’t respect the WordPress license, we don’t recommend them.' ), $plugins_url, $themes_url, 'https://wordpress.org/about/license/' ); + ?> +

Free Software Foundation.' ); ?>

diff --git a/wp-admin/import.php b/wp-admin/import.php index 1aa682ae9b..48051c940e 100644 --- a/wp-admin/import.php +++ b/wp-admin/import.php @@ -6,7 +6,7 @@ * @subpackage Administration */ -define('WP_LOAD_IMPORTERS', true); +define( 'WP_LOAD_IMPORTERS', true ); /** Load WordPress Bootstrap */ require_once( dirname( __FILE__ ) . '/admin.php' ); @@ -15,26 +15,28 @@ if ( ! current_user_can( 'import' ) ) { wp_die( __( 'Sorry, you are not allowed to import content.' ) ); } -$title = __('Import'); +$title = __( 'Import' ); -get_current_screen()->add_help_tab( array( - 'id' => 'overview', - 'title' => __('Overview'), - 'content' => '

' . __('This screen lists links to plugins to import data from blogging/content management platforms. Choose the platform you want to import from, and click Install Now when you are prompted in the popup window. If your platform is not listed, click the link to search the plugin directory for other importer plugins to see if there is one for your platform.') . '

' . - '

' . __('In previous versions of WordPress, all importers were built-in. They have been turned into plugins since most people only use them once or infrequently.') . '

', -) ); +get_current_screen()->add_help_tab( + array( + 'id' => 'overview', + 'title' => __( 'Overview' ), + 'content' => '

' . __( 'This screen lists links to plugins to import data from blogging/content management platforms. Choose the platform you want to import from, and click Install Now when you are prompted in the popup window. If your platform is not listed, click the link to search the plugin directory for other importer plugins to see if there is one for your platform.' ) . '

' . + '

' . __( 'In previous versions of WordPress, all importers were built-in. They have been turned into plugins since most people only use them once or infrequently.' ) . '

', + ) +); get_current_screen()->set_help_sidebar( - '

' . __('For more information:') . '

' . - '

' . __('Documentation on Import') . '

' . - '

' . __('Support Forums') . '

' + '

' . __( 'For more information:' ) . '

' . + '

' . __( 'Documentation on Import' ) . '

' . + '

' . __( 'Support Forums' ) . '

' ); if ( current_user_can( 'install_plugins' ) ) { // List of popular importer plugins from the WordPress.org API. $popular_importers = wp_get_popular_importers(); } else { - $popular_importers = array(); + $popular_importers = array(); } // Detect and redirect invalid importers like 'movabletype', which is registered as 'mt' @@ -59,13 +61,15 @@ $parent_file = 'tools.php';

-

' . esc_html( $_GET['invalid'] ) . '' ); - ?>

+

+ ' . esc_html( $_GET['invalid'] ) . '' ); + ?> +

-

+

$pop_data ) { - if ( isset( $importers[ $pop_importer ] ) ) + if ( isset( $importers[ $pop_importer ] ) ) { continue; - if ( isset( $importers[ $pop_data['importer-id'] ] ) ) + } + if ( isset( $importers[ $pop_data['importer-id'] ] ) ) { continue; + } // Fill the array of registered (already installed) importers with data of the popular importers from the WordPress.org API. - $importers[ $pop_data['importer-id'] ] = array( $pop_data['name'], $pop_data['description'], 'install' => $pop_data['plugin-slug'] ); + $importers[ $pop_data['importer-id'] ] = array( + $pop_data['name'], + $pop_data['description'], + 'install' => $pop_data['plugin-slug'], + ); } if ( empty( $importers ) ) { - echo '

' . __('No importers are available.') . '

'; // TODO: make more helpful + echo '

' . __( 'No importers are available.' ) . '

'; // TODO: make more helpful } else { uasort( $importers, '_usort_by_first_member' ); ?> @@ -91,7 +101,7 @@ if ( empty( $importers ) ) { $data ) { - $plugin_slug = $action = ''; + $plugin_slug = $action = ''; $is_plugin_installed = false; if ( isset( $data['install'] ) ) { @@ -101,14 +111,18 @@ if ( empty( $importers ) ) { // Looks like an importer is installed, but not active. $plugins = get_plugins( '/' . $plugin_slug ); if ( ! empty( $plugins ) ) { - $keys = array_keys( $plugins ); + $keys = array_keys( $plugins ); $plugin_file = $plugin_slug . '/' . $keys[0]; - $url = wp_nonce_url( add_query_arg( array( - 'action' => 'activate', - 'plugin' => $plugin_file, - 'from' => 'import', - ), admin_url( 'plugins.php' ) ), 'activate-plugin_' . $plugin_file ); - $action = sprintf( + $url = wp_nonce_url( + add_query_arg( + array( + 'action' => 'activate', + 'plugin' => $plugin_file, + 'from' => 'import', + ), admin_url( 'plugins.php' ) + ), 'activate-plugin_' . $plugin_file + ); + $action = sprintf( '%s', esc_url( $url ), /* translators: %s: Importer name */ @@ -122,11 +136,15 @@ if ( empty( $importers ) ) { if ( empty( $action ) ) { if ( is_main_site() ) { - $url = wp_nonce_url( add_query_arg( array( - 'action' => 'install-plugin', - 'plugin' => $plugin_slug, - 'from' => 'import', - ), self_admin_url( 'update.php' ) ), 'install-plugin_' . $plugin_slug ); + $url = wp_nonce_url( + add_query_arg( + array( + 'action' => 'install-plugin', + 'plugin' => $plugin_slug, + 'from' => 'import', + ), self_admin_url( 'update.php' ) + ), 'install-plugin_' . $plugin_slug + ); $action = sprintf( '%5$s', esc_url( $url ), @@ -145,9 +163,11 @@ if ( empty( $importers ) ) { } } } else { - $url = add_query_arg( array( - 'import' => $importer_id, - ), self_admin_url( 'admin.php' ) ); + $url = add_query_arg( + array( + 'import' => $importer_id, + ), self_admin_url( 'admin.php' ) + ); $action = sprintf( '%3$s', esc_url( $url ), @@ -160,14 +180,16 @@ if ( empty( $importers ) ) { } if ( ! $is_plugin_installed && is_main_site() ) { - $url = add_query_arg( array( - 'tab' => 'plugin-information', - 'plugin' => $plugin_slug, - 'from' => 'import', - 'TB_iframe' => 'true', - 'width' => 600, - 'height' => 550, - ), network_admin_url( 'plugin-install.php' ) ); + $url = add_query_arg( + array( + 'tab' => 'plugin-information', + 'plugin' => $plugin_slug, + 'from' => 'import', + 'TB_iframe' => 'true', + 'width' => 600, + 'height' => 550, + ), network_admin_url( 'plugin-install.php' ) + ); $action .= sprintf( ' | %3$s', esc_url( $url ), @@ -193,8 +215,9 @@ if ( empty( $importers ) ) { ' . sprintf( __('If the importer you need is not listed, search the plugin directory to see if an importer is available.'), esc_url( network_admin_url( 'plugin-install.php?tab=search&type=tag&s=importer' ) ) ) . '

'; +if ( current_user_can( 'install_plugins' ) ) { + echo '

' . sprintf( __( 'If the importer you need is not listed, search the plugin directory to see if an importer is available.' ), esc_url( network_admin_url( 'plugin-install.php?tab=search&type=tag&s=importer' ) ) ) . '

'; +} ?>
diff --git a/wp-admin/includes/admin-filters.php b/wp-admin/includes/admin-filters.php index 79751a4ef6..62e6c4cfc4 100644 --- a/wp-admin/includes/admin-filters.php +++ b/wp-admin/includes/admin-filters.php @@ -19,16 +19,16 @@ add_action( 'attachment_submitbox_misc_actions', 'attachment_submitbox_metadata' add_action( 'media_upload_image', 'wp_media_upload_handler' ); add_action( 'media_upload_audio', 'wp_media_upload_handler' ); add_action( 'media_upload_video', 'wp_media_upload_handler' ); -add_action( 'media_upload_file', 'wp_media_upload_handler' ); +add_action( 'media_upload_file', 'wp_media_upload_handler' ); add_action( 'post-plupload-upload-ui', 'media_upload_flash_bypass' ); -add_action( 'post-html-upload-ui', 'media_upload_html_bypass' ); +add_action( 'post-html-upload-ui', 'media_upload_html_bypass' ); add_filter( 'async_upload_image', 'get_media_item', 10, 2 ); add_filter( 'async_upload_audio', 'get_media_item', 10, 2 ); add_filter( 'async_upload_video', 'get_media_item', 10, 2 ); -add_filter( 'async_upload_file', 'get_media_item', 10, 2 ); +add_filter( 'async_upload_file', 'get_media_item', 10, 2 ); add_filter( 'attachment_fields_to_save', 'image_attachment_fields_to_save', 10, 2 ); @@ -38,33 +38,33 @@ add_filter( 'media_upload_library', 'media_upload_library' ); add_filter( 'media_upload_tabs', 'update_gallery_tab' ); // Misc hooks. -add_action( 'admin_init', 'wp_admin_headers' ); -add_action( 'login_init', 'wp_admin_headers' ); -add_action( 'admin_head', 'wp_admin_canonical_url' ); +add_action( 'admin_init', 'wp_admin_headers' ); +add_action( 'login_init', 'wp_admin_headers' ); +add_action( 'admin_head', 'wp_admin_canonical_url' ); add_action( 'admin_head', 'wp_color_scheme_settings' ); -add_action( 'admin_head', 'wp_site_icon' ); -add_action( 'admin_head', '_ipad_meta' ); +add_action( 'admin_head', 'wp_site_icon' ); +add_action( 'admin_head', '_ipad_meta' ); // Prerendering. if ( ! is_customize_preview() ) { add_filter( 'admin_print_styles', 'wp_resource_hints', 1 ); } -add_action( 'admin_print_scripts-post.php', 'wp_page_reload_on_back_button_js' ); +add_action( 'admin_print_scripts-post.php', 'wp_page_reload_on_back_button_js' ); add_action( 'admin_print_scripts-post-new.php', 'wp_page_reload_on_back_button_js' ); -add_action( 'update_option_home', 'update_home_siteurl', 10, 2 ); -add_action( 'update_option_siteurl', 'update_home_siteurl', 10, 2 ); +add_action( 'update_option_home', 'update_home_siteurl', 10, 2 ); +add_action( 'update_option_siteurl', 'update_home_siteurl', 10, 2 ); add_action( 'update_option_page_on_front', 'update_home_siteurl', 10, 2 ); -add_action( 'update_option_admin_email', 'wp_site_admin_email_change_notification', 10, 3 ); +add_action( 'update_option_admin_email', 'wp_site_admin_email_change_notification', 10, 3 ); -add_action( 'add_option_new_admin_email', 'update_option_new_admin_email', 10, 2 ); +add_action( 'add_option_new_admin_email', 'update_option_new_admin_email', 10, 2 ); add_action( 'update_option_new_admin_email', 'update_option_new_admin_email', 10, 2 ); -add_filter( 'heartbeat_received', 'wp_check_locked_posts', 10, 3 ); -add_filter( 'heartbeat_received', 'wp_refresh_post_lock', 10, 3 ); -add_filter( 'wp_refresh_nonces', 'wp_refresh_post_nonces', 10, 3 ); -add_filter( 'heartbeat_received', 'heartbeat_autosave', 500, 2 ); +add_filter( 'heartbeat_received', 'wp_check_locked_posts', 10, 3 ); +add_filter( 'heartbeat_received', 'wp_refresh_post_lock', 10, 3 ); +add_filter( 'wp_refresh_nonces', 'wp_refresh_post_nonces', 10, 3 ); +add_filter( 'heartbeat_received', 'heartbeat_autosave', 500, 2 ); add_filter( 'heartbeat_settings', 'wp_heartbeat_set_suspension' ); @@ -75,19 +75,19 @@ add_action( 'admin_head-nav-menus.php', '_wp_delete_orphaned_draft_menu_items' ) add_filter( 'whitelist_options', 'option_update_filter' ); // Plugin Install hooks. -add_action( 'install_plugins_featured', 'install_dashboard' ); -add_action( 'install_plugins_upload', 'install_plugins_upload' ); -add_action( 'install_plugins_search', 'display_plugins_table' ); -add_action( 'install_plugins_popular', 'display_plugins_table' ); -add_action( 'install_plugins_recommended', 'display_plugins_table' ); -add_action( 'install_plugins_new', 'display_plugins_table' ); -add_action( 'install_plugins_beta', 'display_plugins_table' ); -add_action( 'install_plugins_favorites', 'display_plugins_table' ); +add_action( 'install_plugins_featured', 'install_dashboard' ); +add_action( 'install_plugins_upload', 'install_plugins_upload' ); +add_action( 'install_plugins_search', 'display_plugins_table' ); +add_action( 'install_plugins_popular', 'display_plugins_table' ); +add_action( 'install_plugins_recommended', 'display_plugins_table' ); +add_action( 'install_plugins_new', 'display_plugins_table' ); +add_action( 'install_plugins_beta', 'display_plugins_table' ); +add_action( 'install_plugins_favorites', 'display_plugins_table' ); add_action( 'install_plugins_pre_plugin-information', 'install_plugin_information' ); // Template hooks. -add_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) ); -add_action( 'user_register', array( 'WP_Internal_Pointers', 'dismiss_pointers_for_new_users' ) ); +add_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) ); +add_action( 'user_register', array( 'WP_Internal_Pointers', 'dismiss_pointers_for_new_users' ) ); // Theme hooks. add_action( 'customize_controls_print_footer_scripts', 'customize_themes_print_templates' ); @@ -115,7 +115,7 @@ add_action( 'personal_options_update', 'send_confirmation_on_profile_email' ); add_action( 'load-plugins.php', 'wp_plugin_update_rows', 20 ); // After wp_update_plugins() is called. add_action( 'load-themes.php', 'wp_theme_update_rows', 20 ); // After wp_update_themes() is called. -add_action( 'admin_notices', 'update_nag', 3 ); +add_action( 'admin_notices', 'update_nag', 3 ); add_action( 'admin_notices', 'maintenance_nag', 10 ); add_filter( 'update_footer', 'core_update_footer' ); diff --git a/wp-admin/includes/admin.php b/wp-admin/includes/admin.php index ee197714ad..af4f7cc04c 100644 --- a/wp-admin/includes/admin.php +++ b/wp-admin/includes/admin.php @@ -7,7 +7,7 @@ * @since 2.3.0 */ -if ( ! defined('WP_ADMIN') ) { +if ( ! defined( 'WP_ADMIN' ) ) { /* * This file is being included from a file other than wp-admin/admin.php, so * some setup was skipped. Make sure the admin message catalog is loaded since @@ -17,71 +17,71 @@ if ( ! defined('WP_ADMIN') ) { } /** WordPress Administration Hooks */ -require_once(ABSPATH . 'wp-admin/includes/admin-filters.php'); +require_once( ABSPATH . 'wp-admin/includes/admin-filters.php' ); /** WordPress Bookmark Administration API */ -require_once(ABSPATH . 'wp-admin/includes/bookmark.php'); +require_once( ABSPATH . 'wp-admin/includes/bookmark.php' ); /** WordPress Comment Administration API */ -require_once(ABSPATH . 'wp-admin/includes/comment.php'); +require_once( ABSPATH . 'wp-admin/includes/comment.php' ); /** WordPress Administration File API */ -require_once(ABSPATH . 'wp-admin/includes/file.php'); +require_once( ABSPATH . 'wp-admin/includes/file.php' ); /** WordPress Image Administration API */ -require_once(ABSPATH . 'wp-admin/includes/image.php'); +require_once( ABSPATH . 'wp-admin/includes/image.php' ); /** WordPress Media Administration API */ -require_once(ABSPATH . 'wp-admin/includes/media.php'); +require_once( ABSPATH . 'wp-admin/includes/media.php' ); /** WordPress Import Administration API */ -require_once(ABSPATH . 'wp-admin/includes/import.php'); +require_once( ABSPATH . 'wp-admin/includes/import.php' ); /** WordPress Misc Administration API */ -require_once(ABSPATH . 'wp-admin/includes/misc.php'); +require_once( ABSPATH . 'wp-admin/includes/misc.php' ); /** WordPress Options Administration API */ -require_once(ABSPATH . 'wp-admin/includes/options.php'); +require_once( ABSPATH . 'wp-admin/includes/options.php' ); /** WordPress Plugin Administration API */ -require_once(ABSPATH . 'wp-admin/includes/plugin.php'); +require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); /** WordPress Post Administration API */ -require_once(ABSPATH . 'wp-admin/includes/post.php'); +require_once( ABSPATH . 'wp-admin/includes/post.php' ); /** WordPress Administration Screen API */ -require_once(ABSPATH . 'wp-admin/includes/class-wp-screen.php'); -require_once(ABSPATH . 'wp-admin/includes/screen.php'); +require_once( ABSPATH . 'wp-admin/includes/class-wp-screen.php' ); +require_once( ABSPATH . 'wp-admin/includes/screen.php' ); /** WordPress Taxonomy Administration API */ -require_once(ABSPATH . 'wp-admin/includes/taxonomy.php'); +require_once( ABSPATH . 'wp-admin/includes/taxonomy.php' ); /** WordPress Template Administration API */ -require_once(ABSPATH . 'wp-admin/includes/template.php'); +require_once( ABSPATH . 'wp-admin/includes/template.php' ); /** WordPress List Table Administration API and base class */ -require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php'); -require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table-compat.php'); -require_once(ABSPATH . 'wp-admin/includes/list-table.php'); +require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); +require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table-compat.php' ); +require_once( ABSPATH . 'wp-admin/includes/list-table.php' ); /** WordPress Theme Administration API */ -require_once(ABSPATH . 'wp-admin/includes/theme.php'); +require_once( ABSPATH . 'wp-admin/includes/theme.php' ); /** WordPress User Administration API */ -require_once(ABSPATH . 'wp-admin/includes/user.php'); +require_once( ABSPATH . 'wp-admin/includes/user.php' ); /** WordPress Site Icon API */ -require_once(ABSPATH . 'wp-admin/includes/class-wp-site-icon.php'); +require_once( ABSPATH . 'wp-admin/includes/class-wp-site-icon.php' ); /** WordPress Update Administration API */ -require_once(ABSPATH . 'wp-admin/includes/update.php'); +require_once( ABSPATH . 'wp-admin/includes/update.php' ); /** WordPress Deprecated Administration API */ -require_once(ABSPATH . 'wp-admin/includes/deprecated.php'); +require_once( ABSPATH . 'wp-admin/includes/deprecated.php' ); /** WordPress Multisite support API */ if ( is_multisite() ) { - require_once(ABSPATH . 'wp-admin/includes/ms-admin-filters.php'); - require_once(ABSPATH . 'wp-admin/includes/ms.php'); - require_once(ABSPATH . 'wp-admin/includes/ms-deprecated.php'); + require_once( ABSPATH . 'wp-admin/includes/ms-admin-filters.php' ); + require_once( ABSPATH . 'wp-admin/includes/ms.php' ); + require_once( ABSPATH . 'wp-admin/includes/ms-deprecated.php' ); } diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php index 230da6a958..e05ec0a273 100644 --- a/wp-admin/includes/ajax-actions.php +++ b/wp-admin/includes/ajax-actions.php @@ -23,12 +23,13 @@ function wp_ajax_nopriv_heartbeat() { $response = array(); // screen_id is the same as $current_screen->id and the JS global 'pagenow'. - if ( ! empty($_POST['screen_id']) ) - $screen_id = sanitize_key($_POST['screen_id']); - else + if ( ! empty( $_POST['screen_id'] ) ) { + $screen_id = sanitize_key( $_POST['screen_id'] ); + } else { $screen_id = 'front'; + } - if ( ! empty($_POST['data']) ) { + if ( ! empty( $_POST['data'] ) ) { $data = wp_unslash( (array) $_POST['data'] ); /** @@ -68,7 +69,7 @@ function wp_ajax_nopriv_heartbeat() { // Send the current time according to the server. $response['server_time'] = time(); - wp_send_json($response); + wp_send_json( $response ); } // @@ -109,7 +110,7 @@ function wp_ajax_ajax_tag_search() { } $taxonomy = sanitize_key( $_GET['tax'] ); - $tax = get_taxonomy( $taxonomy ); + $tax = get_taxonomy( $taxonomy ); if ( ! $tax ) { wp_die( 0 ); } @@ -121,11 +122,12 @@ function wp_ajax_ajax_tag_search() { $s = wp_unslash( $_GET['q'] ); $comma = _x( ',', 'tag delimiter' ); - if ( ',' !== $comma ) + if ( ',' !== $comma ) { $s = str_replace( $comma, ',', $s ); + } if ( false !== strpos( $s, ',' ) ) { $s = explode( ',', $s ); - $s = $s[count( $s ) - 1]; + $s = $s[ count( $s ) - 1 ]; } $s = trim( $s ); @@ -144,11 +146,17 @@ function wp_ajax_ajax_tag_search() { * Require $term_search_min_chars chars for matching (default: 2) * ensure it's a non-negative, non-zero integer. */ - if ( ( $term_search_min_chars == 0 ) || ( strlen( $s ) < $term_search_min_chars ) ){ + if ( ( $term_search_min_chars == 0 ) || ( strlen( $s ) < $term_search_min_chars ) ) { wp_die(); } - $results = get_terms( $taxonomy, array( 'name__like' => $s, 'fields' => 'names', 'hide_empty' => false ) ); + $results = get_terms( + $taxonomy, array( + 'name__like' => $s, + 'fields' => 'names', + 'hide_empty' => false, + ) + ); echo join( $results, "\n" ); wp_die(); @@ -160,33 +168,35 @@ function wp_ajax_ajax_tag_search() { * @since 3.1.0 */ function wp_ajax_wp_compression_test() { - if ( !current_user_can( 'manage_options' ) ) + if ( ! current_user_can( 'manage_options' ) ) { wp_die( -1 ); + } - if ( ini_get('zlib.output_compression') || 'ob_gzhandler' == ini_get('output_handler') ) { - update_site_option('can_compress_scripts', 0); + if ( ini_get( 'zlib.output_compression' ) || 'ob_gzhandler' == ini_get( 'output_handler' ) ) { + update_site_option( 'can_compress_scripts', 0 ); wp_die( 0 ); } - if ( isset($_GET['test']) ) { + if ( isset( $_GET['test'] ) ) { header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' ); header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' ); header( 'Cache-Control: no-cache, must-revalidate, max-age=0' ); - header('Content-Type: application/javascript; charset=UTF-8'); - $force_gzip = ( defined('ENFORCE_GZIP') && ENFORCE_GZIP ); - $test_str = '"wpCompressionTest Lorem ipsum dolor sit amet consectetuer mollis sapien urna ut a. Eu nonummy condimentum fringilla tempor pretium platea vel nibh netus Maecenas. Hac molestie amet justo quis pellentesque est ultrices interdum nibh Morbi. Cras mattis pretium Phasellus ante ipsum ipsum ut sociis Suspendisse Lorem. Ante et non molestie. Porta urna Vestibulum egestas id congue nibh eu risus gravida sit. Ac augue auctor Ut et non a elit massa id sodales. Elit eu Nulla at nibh adipiscing mattis lacus mauris at tempus. Netus nibh quis suscipit nec feugiat eget sed lorem et urna. Pellentesque lacus at ut massa consectetuer ligula ut auctor semper Pellentesque. Ut metus massa nibh quam Curabitur molestie nec mauris congue. Volutpat molestie elit justo facilisis neque ac risus Ut nascetur tristique. Vitae sit lorem tellus et quis Phasellus lacus tincidunt nunc Fusce. Pharetra wisi Suspendisse mus sagittis libero lacinia Integer consequat ac Phasellus. Et urna ac cursus tortor aliquam Aliquam amet tellus volutpat Vestibulum. Justo interdum condimentum In augue congue tellus sollicitudin Quisque quis nibh."'; + header( 'Content-Type: application/javascript; charset=UTF-8' ); + $force_gzip = ( defined( 'ENFORCE_GZIP' ) && ENFORCE_GZIP ); + $test_str = '"wpCompressionTest Lorem ipsum dolor sit amet consectetuer mollis sapien urna ut a. Eu nonummy condimentum fringilla tempor pretium platea vel nibh netus Maecenas. Hac molestie amet justo quis pellentesque est ultrices interdum nibh Morbi. Cras mattis pretium Phasellus ante ipsum ipsum ut sociis Suspendisse Lorem. Ante et non molestie. Porta urna Vestibulum egestas id congue nibh eu risus gravida sit. Ac augue auctor Ut et non a elit massa id sodales. Elit eu Nulla at nibh adipiscing mattis lacus mauris at tempus. Netus nibh quis suscipit nec feugiat eget sed lorem et urna. Pellentesque lacus at ut massa consectetuer ligula ut auctor semper Pellentesque. Ut metus massa nibh quam Curabitur molestie nec mauris congue. Volutpat molestie elit justo facilisis neque ac risus Ut nascetur tristique. Vitae sit lorem tellus et quis Phasellus lacus tincidunt nunc Fusce. Pharetra wisi Suspendisse mus sagittis libero lacinia Integer consequat ac Phasellus. Et urna ac cursus tortor aliquam Aliquam amet tellus volutpat Vestibulum. Justo interdum condimentum In augue congue tellus sollicitudin Quisque quis nibh."'; if ( 1 == $_GET['test'] ) { - echo $test_str; - wp_die(); + echo $test_str; + wp_die(); } elseif ( 2 == $_GET['test'] ) { - if ( !isset($_SERVER['HTTP_ACCEPT_ENCODING']) ) + if ( ! isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) { wp_die( -1 ); - if ( false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate') && function_exists('gzdeflate') && ! $force_gzip ) { - header('Content-Encoding: deflate'); + } + if ( false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate' ) && function_exists( 'gzdeflate' ) && ! $force_gzip ) { + header( 'Content-Encoding: deflate' ); $out = gzdeflate( $test_str, 1 ); - } elseif ( false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') && function_exists('gzencode') ) { - header('Content-Encoding: gzip'); + } elseif ( false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip' ) && function_exists( 'gzencode' ) ) { + header( 'Content-Encoding: gzip' ); $out = gzencode( $test_str, 1 ); } else { wp_die( -1 ); @@ -195,10 +205,10 @@ function wp_ajax_wp_compression_test() { wp_die(); } elseif ( 'no' == $_GET['test'] ) { check_ajax_referer( 'update_can_compress_scripts' ); - update_site_option('can_compress_scripts', 0); + update_site_option( 'can_compress_scripts', 0 ); } elseif ( 'yes' == $_GET['test'] ) { check_ajax_referer( 'update_can_compress_scripts' ); - update_site_option('can_compress_scripts', 1); + update_site_option( 'can_compress_scripts', 1 ); } } @@ -211,15 +221,17 @@ function wp_ajax_wp_compression_test() { * @since 3.1.0 */ function wp_ajax_imgedit_preview() { - $post_id = intval($_GET['postid']); - if ( empty($post_id) || !current_user_can('edit_post', $post_id) ) + $post_id = intval( $_GET['postid'] ); + if ( empty( $post_id ) || ! current_user_can( 'edit_post', $post_id ) ) { wp_die( -1 ); + } check_ajax_referer( "image_editor-$post_id" ); include_once( ABSPATH . 'wp-admin/includes/image-edit.php' ); - if ( ! stream_preview_image($post_id) ) + if ( ! stream_preview_image( $post_id ) ) { wp_die( -1 ); + } wp_die(); } @@ -242,12 +254,14 @@ function wp_ajax_oembed_cache() { * @since 3.4.0 */ function wp_ajax_autocomplete_user() { - if ( ! is_multisite() || ! current_user_can( 'promote_users' ) || wp_is_large_network( 'users' ) ) + if ( ! is_multisite() || ! current_user_can( 'promote_users' ) || wp_is_large_network( 'users' ) ) { wp_die( -1 ); + } /** This filter is documented in wp-admin/user-new.php */ - if ( ! current_user_can( 'manage_network_users' ) && ! apply_filters( 'autocomplete_users_for_site_admins', false ) ) + if ( ! current_user_can( 'manage_network_users' ) && ! apply_filters( 'autocomplete_users_for_site_admins', false ) ) { wp_die( -1 ); + } $return = array(); @@ -274,16 +288,28 @@ function wp_ajax_autocomplete_user() { $id = get_current_blog_id(); } - $include_blog_users = ( $type == 'search' ? get_users( array( 'blog_id' => $id, 'fields' => 'ID' ) ) : array() ); - $exclude_blog_users = ( $type == 'add' ? get_users( array( 'blog_id' => $id, 'fields' => 'ID' ) ) : array() ); + $include_blog_users = ( $type == 'search' ? get_users( + array( + 'blog_id' => $id, + 'fields' => 'ID', + ) + ) : array() ); + $exclude_blog_users = ( $type == 'add' ? get_users( + array( + 'blog_id' => $id, + 'fields' => 'ID', + ) + ) : array() ); - $users = get_users( array( - 'blog_id' => false, - 'search' => '*' . $_REQUEST['term'] . '*', - 'include' => $include_blog_users, - 'exclude' => $exclude_blog_users, - 'search_columns' => array( 'user_login', 'user_nicename', 'user_email' ), - ) ); + $users = get_users( + array( + 'blog_id' => false, + 'search' => '*' . $_REQUEST['term'] . '*', + 'include' => $include_blog_users, + 'exclude' => $exclude_blog_users, + 'search_columns' => array( 'user_login', 'user_nicename', 'user_email' ), + ) + ); foreach ( $users as $user ) { $return[] = array( @@ -315,9 +341,11 @@ function wp_ajax_get_community_events() { $ip_changed = false; if ( is_wp_error( $events ) ) { - wp_send_json_error( array( - 'error' => $events->get_error_message(), - ) ); + wp_send_json_error( + array( + 'error' => $events->get_error_message(), + ) + ); } else { if ( empty( $saved_location['ip'] ) && ! empty( $events['location']['ip'] ) ) { $ip_changed = true; @@ -360,7 +388,7 @@ function wp_ajax_dashboard_widgets() { } switch ( $_GET['widget'] ) { - case 'dashboard_primary' : + case 'dashboard_primary': wp_dashboard_primary(); break; } @@ -392,10 +420,10 @@ function wp_ajax_logged_in() { * @param int $delta */ function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) { - $total = isset( $_POST['_total'] ) ? (int) $_POST['_total'] : 0; + $total = isset( $_POST['_total'] ) ? (int) $_POST['_total'] : 0; $per_page = isset( $_POST['_per_page'] ) ? (int) $_POST['_per_page'] : 0; - $page = isset( $_POST['_page'] ) ? (int) $_POST['_page'] : 0; - $url = isset( $_POST['_url'] ) ? esc_url_raw( $_POST['_url'] ) : ''; + $page = isset( $_POST['_page'] ) ? (int) $_POST['_page'] : 0; + $url = isset( $_POST['_url'] ) ? esc_url_raw( $_POST['_url'] ) : ''; // JS didn't send us everything we need to know. Just die with success message if ( ! $total || ! $per_page || ! $page || ! $url ) { @@ -414,32 +442,35 @@ function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) { $counts = wp_count_comments(); - $x = new WP_Ajax_Response( array( - 'what' => 'comment', - // Here for completeness - not used. - 'id' => $comment_id, - 'supplemental' => array( - 'status' => $comment_status, - 'postId' => $comment ? $comment->comment_post_ID : '', - 'time' => $time, - 'in_moderation' => $counts->moderated, - 'i18n_comments_text' => sprintf( - _n( '%s Comment', '%s Comments', $counts->approved ), - number_format_i18n( $counts->approved ) + $x = new WP_Ajax_Response( + array( + 'what' => 'comment', + // Here for completeness - not used. + 'id' => $comment_id, + 'supplemental' => array( + 'status' => $comment_status, + 'postId' => $comment ? $comment->comment_post_ID : '', + 'time' => $time, + 'in_moderation' => $counts->moderated, + 'i18n_comments_text' => sprintf( + _n( '%s Comment', '%s Comments', $counts->approved ), + number_format_i18n( $counts->approved ) + ), + 'i18n_moderation_text' => sprintf( + _nx( '%s in moderation', '%s in moderation', $counts->moderated, 'comments' ), + number_format_i18n( $counts->moderated ) + ), + 'comment_link' => $comment_link, ), - 'i18n_moderation_text' => sprintf( - _nx( '%s in moderation', '%s in moderation', $counts->moderated, 'comments' ), - number_format_i18n( $counts->moderated ) - ), - 'comment_link' => $comment_link, ) - ) ); + ); $x->send(); } $total += $delta; - if ( $total < 0 ) + if ( $total < 0 ) { $total = 0; + } // Only do the expensive stuff on a page-break, and about 1 other time per page if ( 0 == $total % $per_page || 1 == mt_rand( 1, $per_page ) ) { @@ -449,17 +480,20 @@ function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) { $parsed = parse_url( $url ); if ( isset( $parsed['query'] ) ) { parse_str( $parsed['query'], $query_vars ); - if ( !empty( $query_vars['comment_status'] ) ) + if ( ! empty( $query_vars['comment_status'] ) ) { $status = $query_vars['comment_status']; - if ( !empty( $query_vars['p'] ) ) + } + if ( ! empty( $query_vars['p'] ) ) { $post_id = (int) $query_vars['p']; - if ( ! empty( $query_vars['comment_type'] ) ) + } + if ( ! empty( $query_vars['comment_type'] ) ) { $type = $query_vars['comment_type']; + } } if ( empty( $type ) ) { // Only use the comment count if not filtering by a comment_type. - $comment_count = wp_count_comments($post_id); + $comment_count = wp_count_comments( $post_id ); // We're looking for a known type of comment count. if ( isset( $comment_count->$status ) ) { @@ -470,23 +504,25 @@ function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) { } // The time since the last comment count. - $time = time(); + $time = time(); $comment = get_comment( $comment_id ); - $x = new WP_Ajax_Response( array( - 'what' => 'comment', - // Here for completeness - not used. - 'id' => $comment_id, - 'supplemental' => array( - 'status' => $comment ? $comment->comment_approved : '', - 'postId' => $comment ? $comment->comment_post_ID : '', - 'total_items_i18n' => sprintf( _n( '%s item', '%s items', $total ), number_format_i18n( $total ) ), - 'total_pages' => ceil( $total / $per_page ), - 'total_pages_i18n' => number_format_i18n( ceil( $total / $per_page ) ), - 'total' => $total, - 'time' => $time + $x = new WP_Ajax_Response( + array( + 'what' => 'comment', + // Here for completeness - not used. + 'id' => $comment_id, + 'supplemental' => array( + 'status' => $comment ? $comment->comment_approved : '', + 'postId' => $comment ? $comment->comment_post_ID : '', + 'total_items_i18n' => sprintf( _n( '%s item', '%s items', $total ), number_format_i18n( $total ) ), + 'total_pages' => ceil( $total / $per_page ), + 'total_pages_i18n' => number_format_i18n( ceil( $total / $per_page ) ), + 'total' => $total, + 'time' => $time, + ), ) - ) ); + ); $x->send(); } @@ -501,27 +537,31 @@ function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) { * @since 3.1.0 */ function _wp_ajax_add_hierarchical_term() { - $action = $_POST['action']; - $taxonomy = get_taxonomy(substr($action, 4)); + $action = $_POST['action']; + $taxonomy = get_taxonomy( substr( $action, 4 ) ); check_ajax_referer( $action, '_ajax_nonce-add-' . $taxonomy->name ); - if ( !current_user_can( $taxonomy->cap->edit_terms ) ) + if ( ! current_user_can( $taxonomy->cap->edit_terms ) ) { wp_die( -1 ); - $names = explode(',', $_POST['new'.$taxonomy->name]); - $parent = isset($_POST['new'.$taxonomy->name.'_parent']) ? (int) $_POST['new'.$taxonomy->name.'_parent'] : 0; - if ( 0 > $parent ) + } + $names = explode( ',', $_POST[ 'new' . $taxonomy->name ] ); + $parent = isset( $_POST[ 'new' . $taxonomy->name . '_parent' ] ) ? (int) $_POST[ 'new' . $taxonomy->name . '_parent' ] : 0; + if ( 0 > $parent ) { $parent = 0; - if ( $taxonomy->name == 'category' ) - $post_category = isset($_POST['post_category']) ? (array) $_POST['post_category'] : array(); - else - $post_category = ( isset($_POST['tax_input']) && isset($_POST['tax_input'][$taxonomy->name]) ) ? (array) $_POST['tax_input'][$taxonomy->name] : array(); + } + if ( $taxonomy->name == 'category' ) { + $post_category = isset( $_POST['post_category'] ) ? (array) $_POST['post_category'] : array(); + } else { + $post_category = ( isset( $_POST['tax_input'] ) && isset( $_POST['tax_input'][ $taxonomy->name ] ) ) ? (array) $_POST['tax_input'][ $taxonomy->name ] : array(); + } $checked_categories = array_map( 'absint', (array) $post_category ); - $popular_ids = wp_popular_terms_checklist($taxonomy->name, 0, 10, false); + $popular_ids = wp_popular_terms_checklist( $taxonomy->name, 0, 10, false ); foreach ( $names as $cat_name ) { - $cat_name = trim($cat_name); - $category_nicename = sanitize_title($cat_name); - if ( '' === $category_nicename ) + $cat_name = trim( $cat_name ); + $category_nicename = sanitize_title( $cat_name ); + if ( '' === $category_nicename ) { continue; + } $cat_id = wp_insert_term( $cat_name, $taxonomy->name, array( 'parent' => $parent ) ); if ( ! $cat_id || is_wp_error( $cat_id ) ) { @@ -530,54 +570,76 @@ function _wp_ajax_add_hierarchical_term() { $cat_id = $cat_id['term_id']; } $checked_categories[] = $cat_id; - if ( $parent ) // Do these all at once in a second + if ( $parent ) { // Do these all at once in a second continue; + } ob_start(); - wp_terms_checklist( 0, array( 'taxonomy' => $taxonomy->name, 'descendants_and_self' => $cat_id, 'selected_cats' => $checked_categories, 'popular_cats' => $popular_ids )); + wp_terms_checklist( + 0, array( + 'taxonomy' => $taxonomy->name, + 'descendants_and_self' => $cat_id, + 'selected_cats' => $checked_categories, + 'popular_cats' => $popular_ids, + ) + ); $data = ob_get_clean(); $add = array( - 'what' => $taxonomy->name, - 'id' => $cat_id, - 'data' => str_replace( array("\n", "\t"), '', $data), - 'position' => -1 + 'what' => $taxonomy->name, + 'id' => $cat_id, + 'data' => str_replace( array( "\n", "\t" ), '', $data ), + 'position' => -1, ); } if ( $parent ) { // Foncy - replace the parent and all its children - $parent = get_term( $parent, $taxonomy->name ); + $parent = get_term( $parent, $taxonomy->name ); $term_id = $parent->term_id; while ( $parent->parent ) { // get the top parent $parent = get_term( $parent->parent, $taxonomy->name ); - if ( is_wp_error( $parent ) ) + if ( is_wp_error( $parent ) ) { break; + } $term_id = $parent->term_id; } ob_start(); - wp_terms_checklist( 0, array('taxonomy' => $taxonomy->name, 'descendants_and_self' => $term_id, 'selected_cats' => $checked_categories, 'popular_cats' => $popular_ids)); + wp_terms_checklist( + 0, array( + 'taxonomy' => $taxonomy->name, + 'descendants_and_self' => $term_id, + 'selected_cats' => $checked_categories, + 'popular_cats' => $popular_ids, + ) + ); $data = ob_get_clean(); $add = array( - 'what' => $taxonomy->name, - 'id' => $term_id, - 'data' => str_replace( array("\n", "\t"), '', $data), - 'position' => -1 + 'what' => $taxonomy->name, + 'id' => $term_id, + 'data' => str_replace( array( "\n", "\t" ), '', $data ), + 'position' => -1, ); } ob_start(); - wp_dropdown_categories( array( - 'taxonomy' => $taxonomy->name, 'hide_empty' => 0, 'name' => 'new'.$taxonomy->name.'_parent', 'orderby' => 'name', - 'hierarchical' => 1, 'show_option_none' => '— '.$taxonomy->labels->parent_item.' —' - ) ); + wp_dropdown_categories( + array( + 'taxonomy' => $taxonomy->name, + 'hide_empty' => 0, + 'name' => 'new' . $taxonomy->name . '_parent', + 'orderby' => 'name', + 'hierarchical' => 1, + 'show_option_none' => '— ' . $taxonomy->labels->parent_item . ' —', + ) + ); $sup = ob_get_clean(); @@ -595,43 +657,52 @@ function _wp_ajax_add_hierarchical_term() { function wp_ajax_delete_comment() { $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; - if ( !$comment = get_comment( $id ) ) + if ( ! $comment = get_comment( $id ) ) { wp_die( time() ); - if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) + } + if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) { wp_die( -1 ); + } check_ajax_referer( "delete-comment_$id" ); $status = wp_get_comment_status( $comment ); $delta = -1; - if ( isset($_POST['trash']) && 1 == $_POST['trash'] ) { - if ( 'trash' == $status ) + if ( isset( $_POST['trash'] ) && 1 == $_POST['trash'] ) { + if ( 'trash' == $status ) { wp_die( time() ); + } $r = wp_trash_comment( $comment ); - } elseif ( isset($_POST['untrash']) && 1 == $_POST['untrash'] ) { - if ( 'trash' != $status ) + } elseif ( isset( $_POST['untrash'] ) && 1 == $_POST['untrash'] ) { + if ( 'trash' != $status ) { wp_die( time() ); + } $r = wp_untrash_comment( $comment ); - if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'trash' ) // undo trash, not in trash + if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'trash' ) { // undo trash, not in trash $delta = 1; - } elseif ( isset($_POST['spam']) && 1 == $_POST['spam'] ) { - if ( 'spam' == $status ) + } + } elseif ( isset( $_POST['spam'] ) && 1 == $_POST['spam'] ) { + if ( 'spam' == $status ) { wp_die( time() ); + } $r = wp_spam_comment( $comment ); - } elseif ( isset($_POST['unspam']) && 1 == $_POST['unspam'] ) { - if ( 'spam' != $status ) + } elseif ( isset( $_POST['unspam'] ) && 1 == $_POST['unspam'] ) { + if ( 'spam' != $status ) { wp_die( time() ); + } $r = wp_unspam_comment( $comment ); - if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'spam' ) // undo spam, not in spam + if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'spam' ) { // undo spam, not in spam $delta = 1; - } elseif ( isset($_POST['delete']) && 1 == $_POST['delete'] ) { + } + } elseif ( isset( $_POST['delete'] ) && 1 == $_POST['delete'] ) { $r = wp_delete_comment( $comment ); } else { wp_die( -1 ); } - if ( $r ) // Decide if we need to send back '1' or a more complicated response including page links and comment counts + if ( $r ) { // Decide if we need to send back '1' or a more complicated response including page links and comment counts _wp_ajax_delete_comment_response( $comment->comment_ID, $delta ); + } wp_die( 0 ); } @@ -648,15 +719,17 @@ function wp_ajax_delete_tag() { wp_die( -1 ); } - $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag'; - $tag = get_term( $tag_id, $taxonomy ); - if ( !$tag || is_wp_error( $tag ) ) + $taxonomy = ! empty( $_POST['taxonomy'] ) ? $_POST['taxonomy'] : 'post_tag'; + $tag = get_term( $tag_id, $taxonomy ); + if ( ! $tag || is_wp_error( $tag ) ) { wp_die( 1 ); + } - if ( wp_delete_term($tag_id, $taxonomy)) + if ( wp_delete_term( $tag_id, $taxonomy ) ) { wp_die( 1 ); - else + } else { wp_die( 0 ); + } } /** @@ -668,17 +741,20 @@ function wp_ajax_delete_link() { $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; check_ajax_referer( "delete-bookmark_$id" ); - if ( !current_user_can( 'manage_links' ) ) + if ( ! current_user_can( 'manage_links' ) ) { wp_die( -1 ); + } $link = get_bookmark( $id ); - if ( !$link || is_wp_error( $link ) ) + if ( ! $link || is_wp_error( $link ) ) { wp_die( 1 ); + } - if ( wp_delete_link( $id ) ) + if ( wp_delete_link( $id ) ) { wp_die( 1 ); - else + } else { wp_die( 0 ); + } } /** @@ -690,13 +766,16 @@ function wp_ajax_delete_meta() { $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; check_ajax_referer( "delete-meta_$id" ); - if ( !$meta = get_metadata_by_mid( 'post', $id ) ) + if ( ! $meta = get_metadata_by_mid( 'post', $id ) ) { wp_die( 1 ); + } - if ( is_protected_meta( $meta->meta_key, 'post' ) || ! current_user_can( 'delete_post_meta', $meta->post_id, $meta->meta_key ) ) + if ( is_protected_meta( $meta->meta_key, 'post' ) || ! current_user_can( 'delete_post_meta', $meta->post_id, $meta->meta_key ) ) { wp_die( -1 ); - if ( delete_meta( $meta->meta_id ) ) + } + if ( delete_meta( $meta->meta_id ) ) { wp_die( 1 ); + } wp_die( 0 ); } @@ -708,21 +787,25 @@ function wp_ajax_delete_meta() { * @param string $action Action to perform. */ function wp_ajax_delete_post( $action ) { - if ( empty( $action ) ) + if ( empty( $action ) ) { $action = 'delete-post'; + } $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; check_ajax_referer( "{$action}_$id" ); - if ( !current_user_can( 'delete_post', $id ) ) + if ( ! current_user_can( 'delete_post', $id ) ) { wp_die( -1 ); + } - if ( !get_post( $id ) ) + if ( ! get_post( $id ) ) { wp_die( 1 ); + } - if ( wp_delete_post( $id ) ) + if ( wp_delete_post( $id ) ) { wp_die( 1 ); - else + } else { wp_die( 0 ); + } } /** @@ -733,24 +816,29 @@ function wp_ajax_delete_post( $action ) { * @param string $action Action to perform. */ function wp_ajax_trash_post( $action ) { - if ( empty( $action ) ) + if ( empty( $action ) ) { $action = 'trash-post'; + } $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; check_ajax_referer( "{$action}_$id" ); - if ( !current_user_can( 'delete_post', $id ) ) + if ( ! current_user_can( 'delete_post', $id ) ) { wp_die( -1 ); + } - if ( !get_post( $id ) ) + if ( ! get_post( $id ) ) { wp_die( 1 ); + } - if ( 'trash-post' == $action ) + if ( 'trash-post' == $action ) { $done = wp_trash_post( $id ); - else + } else { $done = wp_untrash_post( $id ); + } - if ( $done ) + if ( $done ) { wp_die( 1 ); + } wp_die( 0 ); } @@ -763,8 +851,9 @@ function wp_ajax_trash_post( $action ) { * @param string $action Action to perform. */ function wp_ajax_untrash_post( $action ) { - if ( empty( $action ) ) + if ( empty( $action ) ) { $action = 'untrash-post'; + } wp_ajax_trash_post( $action ); } @@ -774,21 +863,25 @@ function wp_ajax_untrash_post( $action ) { * @param string $action */ function wp_ajax_delete_page( $action ) { - if ( empty( $action ) ) + if ( empty( $action ) ) { $action = 'delete-page'; + } $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; check_ajax_referer( "{$action}_$id" ); - if ( !current_user_can( 'delete_page', $id ) ) + if ( ! current_user_can( 'delete_page', $id ) ) { wp_die( -1 ); + } - if ( ! get_post( $id ) ) + if ( ! get_post( $id ) ) { wp_die( 1 ); + } - if ( wp_delete_post( $id ) ) + if ( wp_delete_post( $id ) ) { wp_die( 1 ); - else + } else { wp_die( 0 ); + } } /** @@ -799,20 +892,24 @@ function wp_ajax_delete_page( $action ) { function wp_ajax_dim_comment() { $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; - if ( !$comment = get_comment( $id ) ) { - $x = new WP_Ajax_Response( array( - 'what' => 'comment', - 'id' => new WP_Error('invalid_comment', sprintf(__('Comment %d does not exist'), $id)) - ) ); + if ( ! $comment = get_comment( $id ) ) { + $x = new WP_Ajax_Response( + array( + 'what' => 'comment', + 'id' => new WP_Error( 'invalid_comment', sprintf( __( 'Comment %d does not exist' ), $id ) ), + ) + ); $x->send(); } - if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) && ! current_user_can( 'moderate_comments' ) ) + if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) && ! current_user_can( 'moderate_comments' ) ) { wp_die( -1 ); + } $current = wp_get_comment_status( $comment ); - if ( isset( $_POST['new'] ) && $_POST['new'] == $current ) + if ( isset( $_POST['new'] ) && $_POST['new'] == $current ) { wp_die( time() ); + } check_ajax_referer( "approve-comment_$id" ); if ( in_array( $current, array( 'unapproved', 'spam' ) ) ) { @@ -821,11 +918,13 @@ function wp_ajax_dim_comment() { $result = wp_set_comment_status( $comment, 'hold', true ); } - if ( is_wp_error($result) ) { - $x = new WP_Ajax_Response( array( - 'what' => 'comment', - 'id' => $result - ) ); + if ( is_wp_error( $result ) ) { + $x = new WP_Ajax_Response( + array( + 'what' => 'comment', + 'id' => $result, + ) + ); $x->send(); } @@ -842,20 +941,22 @@ function wp_ajax_dim_comment() { * @param string $action Action to perform. */ function wp_ajax_add_link_category( $action ) { - if ( empty( $action ) ) + if ( empty( $action ) ) { $action = 'add-link-category'; + } check_ajax_referer( $action ); $tax = get_taxonomy( 'link_category' ); if ( ! current_user_can( $tax->cap->manage_terms ) ) { wp_die( -1 ); } - $names = explode(',', wp_unslash( $_POST['newcat'] ) ); - $x = new WP_Ajax_Response(); + $names = explode( ',', wp_unslash( $_POST['newcat'] ) ); + $x = new WP_Ajax_Response(); foreach ( $names as $cat_name ) { - $cat_name = trim($cat_name); - $slug = sanitize_title($cat_name); - if ( '' === $slug ) + $cat_name = trim( $cat_name ); + $slug = sanitize_title( $cat_name ); + if ( '' === $slug ) { continue; + } $cat_id = wp_insert_term( $cat_name, 'link_category' ); if ( ! $cat_id || is_wp_error( $cat_id ) ) { @@ -864,12 +965,14 @@ function wp_ajax_add_link_category( $action ) { $cat_id = $cat_id['term_id']; } $cat_name = esc_html( $cat_name ); - $x->add( array( - 'what' => 'link-category', - 'id' => $cat_id, - 'data' => "", - 'position' => -1 - ) ); + $x->add( + array( + 'what' => 'link-category', + 'id' => $cat_id, + 'data' => "", + 'position' => -1, + ) + ); } $x->send(); } @@ -881,32 +984,36 @@ function wp_ajax_add_link_category( $action ) { */ function wp_ajax_add_tag() { check_ajax_referer( 'add-tag', '_wpnonce_add-tag' ); - $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag'; - $tax = get_taxonomy($taxonomy); + $taxonomy = ! empty( $_POST['taxonomy'] ) ? $_POST['taxonomy'] : 'post_tag'; + $tax = get_taxonomy( $taxonomy ); - if ( !current_user_can( $tax->cap->edit_terms ) ) + if ( ! current_user_can( $tax->cap->edit_terms ) ) { wp_die( -1 ); + } $x = new WP_Ajax_Response(); - $tag = wp_insert_term($_POST['tag-name'], $taxonomy, $_POST ); + $tag = wp_insert_term( $_POST['tag-name'], $taxonomy, $_POST ); - if ( !$tag || is_wp_error($tag) || (!$tag = get_term( $tag['term_id'], $taxonomy )) ) { - $message = __('An error has occurred. Please reload the page and try again.'); - if ( is_wp_error($tag) && $tag->get_error_message() ) + if ( ! $tag || is_wp_error( $tag ) || ( ! $tag = get_term( $tag['term_id'], $taxonomy ) ) ) { + $message = __( 'An error has occurred. Please reload the page and try again.' ); + if ( is_wp_error( $tag ) && $tag->get_error_message() ) { $message = $tag->get_error_message(); + } - $x->add( array( - 'what' => 'taxonomy', - 'data' => new WP_Error('error', $message ) - ) ); + $x->add( + array( + 'what' => 'taxonomy', + 'data' => new WP_Error( 'error', $message ), + ) + ); $x->send(); } $wp_list_table = _get_list_table( 'WP_Terms_List_Table', array( 'screen' => $_POST['screen'] ) ); $level = 0; - if ( is_taxonomy_hierarchical($taxonomy) ) { + if ( is_taxonomy_hierarchical( $taxonomy ) ) { $level = count( get_ancestors( $tag->term_id, $taxonomy, 'taxonomy' ) ); ob_start(); $wp_list_table->single_row( $tag, $level ); @@ -917,15 +1024,19 @@ function wp_ajax_add_tag() { $wp_list_table->single_row( $tag ); $parents = ob_get_clean(); - $x->add( array( - 'what' => 'taxonomy', - 'supplemental' => compact('parents', 'noparents') - ) ); - $x->add( array( - 'what' => 'term', - 'position' => $level, - 'supplemental' => (array) $tag - ) ); + $x->add( + array( + 'what' => 'taxonomy', + 'supplemental' => compact( 'parents', 'noparents' ), + ) + ); + $x->add( + array( + 'what' => 'term', + 'position' => $level, + 'supplemental' => (array) $tag, + ) + ); $x->send(); } @@ -940,7 +1051,7 @@ function wp_ajax_get_tagcloud() { } $taxonomy = sanitize_key( $_POST['tax'] ); - $tax = get_taxonomy( $taxonomy ); + $tax = get_taxonomy( $taxonomy ); if ( ! $tax ) { wp_die( 0 ); } @@ -949,24 +1060,38 @@ function wp_ajax_get_tagcloud() { wp_die( -1 ); } - $tags = get_terms( $taxonomy, array( 'number' => 45, 'orderby' => 'count', 'order' => 'DESC' ) ); + $tags = get_terms( + $taxonomy, array( + 'number' => 45, + 'orderby' => 'count', + 'order' => 'DESC', + ) + ); - if ( empty( $tags ) ) + if ( empty( $tags ) ) { wp_die( $tax->labels->not_found ); + } - if ( is_wp_error( $tags ) ) + if ( is_wp_error( $tags ) ) { wp_die( $tags->get_error_message() ); + } foreach ( $tags as $key => $tag ) { $tags[ $key ]->link = '#'; - $tags[ $key ]->id = $tag->term_id; + $tags[ $key ]->id = $tag->term_id; } // We need raw tag names here, so don't filter the output - $return = wp_generate_tag_cloud( $tags, array( 'filter' => 0, 'format' => 'list' ) ); + $return = wp_generate_tag_cloud( + $tags, array( + 'filter' => 0, + 'format' => 'list', + ) + ); - if ( empty($return) ) + if ( empty( $return ) ) { wp_die( 0 ); + } echo $return; @@ -1015,17 +1140,20 @@ function wp_ajax_get_comments( $action ) { $x = new WP_Ajax_Response(); ob_start(); foreach ( $wp_list_table->items as $comment ) { - if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) && 0 === $comment->comment_approved ) + if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) && 0 === $comment->comment_approved ) { continue; + } get_comment( $comment ); $wp_list_table->single_row( $comment ); } $comment_list_item = ob_get_clean(); - $x->add( array( - 'what' => 'comments', - 'data' => $comment_list_item - ) ); + $x->add( + array( + 'what' => 'comments', + 'data' => $comment_list_item, + ) + ); $x->send(); } @@ -1037,35 +1165,40 @@ function wp_ajax_get_comments( $action ) { * @param string $action Action to perform. */ function wp_ajax_replyto_comment( $action ) { - if ( empty( $action ) ) + if ( empty( $action ) ) { $action = 'replyto-comment'; + } check_ajax_referer( $action, '_ajax_nonce-replyto-comment' ); $comment_post_ID = (int) $_POST['comment_post_ID']; - $post = get_post( $comment_post_ID ); - if ( ! $post ) + $post = get_post( $comment_post_ID ); + if ( ! $post ) { wp_die( -1 ); + } - if ( !current_user_can( 'edit_post', $comment_post_ID ) ) + if ( ! current_user_can( 'edit_post', $comment_post_ID ) ) { wp_die( -1 ); + } - if ( empty( $post->post_status ) ) + if ( empty( $post->post_status ) ) { wp_die( 1 ); - elseif ( in_array($post->post_status, array('draft', 'pending', 'trash') ) ) - wp_die( __('ERROR: you are replying to a comment on a draft post.') ); + } elseif ( in_array( $post->post_status, array( 'draft', 'pending', 'trash' ) ) ) { + wp_die( __( 'ERROR: you are replying to a comment on a draft post.' ) ); + } $user = wp_get_current_user(); if ( $user->exists() ) { - $user_ID = $user->ID; + $user_ID = $user->ID; $comment_author = wp_slash( $user->display_name ); $comment_author_email = wp_slash( $user->user_email ); $comment_author_url = wp_slash( $user->user_url ); $comment_content = trim( $_POST['content'] ); $comment_type = isset( $_POST['comment_type'] ) ? trim( $_POST['comment_type'] ) : ''; if ( current_user_can( 'unfiltered_html' ) ) { - if ( ! isset( $_POST['_wp_unfiltered_html_comment'] ) ) + if ( ! isset( $_POST['_wp_unfiltered_html_comment'] ) ) { $_POST['_wp_unfiltered_html_comment'] = ''; + } if ( wp_create_nonce( 'unfiltered-html-comment' ) != $_POST['_wp_unfiltered_html_comment'] ) { kses_remove_filters(); // start with a clean slate @@ -1076,17 +1209,19 @@ function wp_ajax_replyto_comment( $action ) { wp_die( __( 'Sorry, you must be logged in to reply to a comment.' ) ); } - if ( '' == $comment_content ) + if ( '' == $comment_content ) { wp_die( __( 'ERROR: please type a comment.' ) ); + } $comment_parent = 0; - if ( isset( $_POST['comment_ID'] ) ) + if ( isset( $_POST['comment_ID'] ) ) { $comment_parent = absint( $_POST['comment_ID'] ); + } $comment_auto_approved = false; - $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID'); + $commentdata = compact( 'comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID' ); // Automatically approve parent comment. - if ( !empty($_POST['approve_parent']) ) { + if ( ! empty( $_POST['approve_parent'] ) ) { $parent = get_comment( $comment_parent ); if ( $parent && $parent->comment_approved === '0' && $parent->comment_post_ID == $comment_post_ID ) { @@ -1094,8 +1229,9 @@ function wp_ajax_replyto_comment( $action ) { wp_die( -1 ); } - if ( wp_set_comment_status( $parent, 'approve' ) ) + if ( wp_set_comment_status( $parent, 'approve' ) ) { $comment_auto_approved = true; + } } } @@ -1105,10 +1241,12 @@ function wp_ajax_replyto_comment( $action ) { wp_die( $comment_id->get_error_message() ); } - $comment = get_comment($comment_id); - if ( ! $comment ) wp_die( 1 ); + $comment = get_comment( $comment_id ); + if ( ! $comment ) { + wp_die( 1 ); + } - $position = ( isset($_POST['position']) && (int) $_POST['position'] ) ? (int) $_POST['position'] : '-1'; + $position = ( isset( $_POST['position'] ) && (int) $_POST['position'] ) ? (int) $_POST['position'] : '-1'; ob_start(); if ( isset( $_REQUEST['mode'] ) && 'dashboard' == $_REQUEST['mode'] ) { @@ -1116,37 +1254,37 @@ function wp_ajax_replyto_comment( $action ) { _wp_dashboard_recent_comments_row( $comment ); } else { if ( isset( $_REQUEST['mode'] ) && 'single' == $_REQUEST['mode'] ) { - $wp_list_table = _get_list_table('WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); + $wp_list_table = _get_list_table( 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); } else { - $wp_list_table = _get_list_table('WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); + $wp_list_table = _get_list_table( 'WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); } $wp_list_table->single_row( $comment ); } $comment_list_item = ob_get_clean(); - $response = array( - 'what' => 'comment', - 'id' => $comment->comment_ID, - 'data' => $comment_list_item, - 'position' => $position + $response = array( + 'what' => 'comment', + 'id' => $comment->comment_ID, + 'data' => $comment_list_item, + 'position' => $position, ); - $counts = wp_count_comments(); + $counts = wp_count_comments(); $response['supplemental'] = array( - 'in_moderation' => $counts->moderated, - 'i18n_comments_text' => sprintf( + 'in_moderation' => $counts->moderated, + 'i18n_comments_text' => sprintf( _n( '%s Comment', '%s Comments', $counts->approved ), number_format_i18n( $counts->approved ) ), 'i18n_moderation_text' => sprintf( _nx( '%s in moderation', '%s in moderation', $counts->moderated, 'comments' ), number_format_i18n( $counts->moderated ) - ) + ), ); if ( $comment_auto_approved ) { $response['supplemental']['parent_approved'] = $parent->comment_ID; - $response['supplemental']['parent_post_id'] = $parent->comment_post_ID; + $response['supplemental']['parent_post_id'] = $parent->comment_post_ID; } $x = new WP_Ajax_Response(); @@ -1163,23 +1301,27 @@ function wp_ajax_edit_comment() { check_ajax_referer( 'replyto-comment', '_ajax_nonce-replyto-comment' ); $comment_id = (int) $_POST['comment_ID']; - if ( ! current_user_can( 'edit_comment', $comment_id ) ) + if ( ! current_user_can( 'edit_comment', $comment_id ) ) { wp_die( -1 ); + } - if ( '' == $_POST['content'] ) + if ( '' == $_POST['content'] ) { wp_die( __( 'ERROR: please type a comment.' ) ); + } - if ( isset( $_POST['status'] ) ) + if ( isset( $_POST['status'] ) ) { $_POST['comment_status'] = $_POST['status']; + } edit_comment(); - $position = ( isset($_POST['position']) && (int) $_POST['position']) ? (int) $_POST['position'] : '-1'; - $checkbox = ( isset($_POST['checkbox']) && true == $_POST['checkbox'] ) ? 1 : 0; + $position = ( isset( $_POST['position'] ) && (int) $_POST['position'] ) ? (int) $_POST['position'] : '-1'; + $checkbox = ( isset( $_POST['checkbox'] ) && true == $_POST['checkbox'] ) ? 1 : 0; $wp_list_table = _get_list_table( $checkbox ? 'WP_Comments_List_Table' : 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); $comment = get_comment( $comment_id ); - if ( empty( $comment->comment_ID ) ) + if ( empty( $comment->comment_ID ) ) { wp_die( -1 ); + } ob_start(); $wp_list_table->single_row( $comment ); @@ -1187,12 +1329,14 @@ function wp_ajax_edit_comment() { $x = new WP_Ajax_Response(); - $x->add( array( - 'what' => 'edit_comment', - 'id' => $comment->comment_ID, - 'data' => $comment_list_item, - 'position' => $position - )); + $x->add( + array( + 'what' => 'edit_comment', + 'id' => $comment->comment_ID, + 'data' => $comment_list_item, + 'position' => $position, + ) + ); $x->send(); } @@ -1205,8 +1349,9 @@ function wp_ajax_edit_comment() { function wp_ajax_add_menu_item() { check_ajax_referer( 'add-menu_item', 'menu-settings-column-nonce' ); - if ( ! current_user_can( 'edit_theme_options' ) ) + if ( ! current_user_can( 'edit_theme_options' ) ) { wp_die( -1 ); + } require_once ABSPATH . 'wp-admin/includes/nav-menu.php'; @@ -1220,22 +1365,22 @@ function wp_ajax_add_menu_item() { 'custom' != $menu_item_data['menu-item-type'] && ! empty( $menu_item_data['menu-item-object-id'] ) ) { - switch( $menu_item_data['menu-item-type'] ) { - case 'post_type' : + switch ( $menu_item_data['menu-item-type'] ) { + case 'post_type': $_object = get_post( $menu_item_data['menu-item-object-id'] ); - break; + break; - case 'post_type_archive' : + case 'post_type_archive': $_object = get_post_type_object( $menu_item_data['menu-item-object'] ); - break; + break; - case 'taxonomy' : + case 'taxonomy': $_object = get_term( $menu_item_data['menu-item-object-id'], $menu_item_data['menu-item-object'] ); - break; + break; } $_menu_items = array_map( 'wp_setup_nav_menu_item', array( $_object ) ); - $_menu_item = reset( $_menu_items ); + $_menu_item = reset( $_menu_items ); // Restore the missing menu item properties $menu_item_data['menu-item-description'] = $_menu_item->description; @@ -1245,33 +1390,35 @@ function wp_ajax_add_menu_item() { } $item_ids = wp_save_nav_menu_items( 0, $menu_items_data ); - if ( is_wp_error( $item_ids ) ) + if ( is_wp_error( $item_ids ) ) { wp_die( 0 ); + } $menu_items = array(); foreach ( (array) $item_ids as $menu_item_id ) { $menu_obj = get_post( $menu_item_id ); if ( ! empty( $menu_obj->ID ) ) { - $menu_obj = wp_setup_nav_menu_item( $menu_obj ); + $menu_obj = wp_setup_nav_menu_item( $menu_obj ); $menu_obj->label = $menu_obj->title; // don't show "(pending)" in ajax-added items - $menu_items[] = $menu_obj; + $menu_items[] = $menu_obj; } } /** This filter is documented in wp-admin/includes/nav-menu.php */ $walker_class_name = apply_filters( 'wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $_POST['menu'] ); - if ( ! class_exists( $walker_class_name ) ) + if ( ! class_exists( $walker_class_name ) ) { wp_die( 0 ); + } if ( ! empty( $menu_items ) ) { $args = array( - 'after' => '', - 'before' => '', - 'link_after' => '', + 'after' => '', + 'before' => '', + 'link_after' => '', 'link_before' => '', - 'walker' => new $walker_class_name, + 'walker' => new $walker_class_name, ); echo walk_nav_menu_tree( $menu_items, 0, (object) $args ); } @@ -1285,39 +1432,44 @@ function wp_ajax_add_menu_item() { */ function wp_ajax_add_meta() { check_ajax_referer( 'add-meta', '_ajax_nonce-add-meta' ); - $c = 0; - $pid = (int) $_POST['post_id']; + $c = 0; + $pid = (int) $_POST['post_id']; $post = get_post( $pid ); - if ( isset($_POST['metakeyselect']) || isset($_POST['metakeyinput']) ) { - if ( !current_user_can( 'edit_post', $pid ) ) + if ( isset( $_POST['metakeyselect'] ) || isset( $_POST['metakeyinput'] ) ) { + if ( ! current_user_can( 'edit_post', $pid ) ) { wp_die( -1 ); - if ( isset($_POST['metakeyselect']) && '#NONE#' == $_POST['metakeyselect'] && empty($_POST['metakeyinput']) ) + } + if ( isset( $_POST['metakeyselect'] ) && '#NONE#' == $_POST['metakeyselect'] && empty( $_POST['metakeyinput'] ) ) { wp_die( 1 ); + } // If the post is an autodraft, save the post as a draft and then attempt to save the meta. if ( $post->post_status == 'auto-draft' ) { - $post_data = array(); - $post_data['action'] = 'draft'; // Warning fix - $post_data['post_ID'] = $pid; - $post_data['post_type'] = $post->post_type; + $post_data = array(); + $post_data['action'] = 'draft'; // Warning fix + $post_data['post_ID'] = $pid; + $post_data['post_type'] = $post->post_type; $post_data['post_status'] = 'draft'; - $now = current_time('timestamp', 1); + $now = current_time( 'timestamp', 1 ); /* translators: 1: Post creation date, 2: Post creation time */ $post_data['post_title'] = sprintf( __( 'Draft created on %1$s at %2$s' ), date( __( 'F j, Y' ), $now ), date( __( 'g:i a' ), $now ) ); $pid = edit_post( $post_data ); if ( $pid ) { if ( is_wp_error( $pid ) ) { - $x = new WP_Ajax_Response( array( - 'what' => 'meta', - 'data' => $pid - ) ); + $x = new WP_Ajax_Response( + array( + 'what' => 'meta', + 'data' => $pid, + ) + ); $x->send(); } - if ( !$mid = add_meta( $pid ) ) + if ( ! $mid = add_meta( $pid ) ) { wp_die( __( 'Please provide a custom field value.' ) ); + } } else { wp_die( 0 ); } @@ -1326,45 +1478,57 @@ function wp_ajax_add_meta() { } $meta = get_metadata_by_mid( 'post', $mid ); - $pid = (int) $meta->post_id; + $pid = (int) $meta->post_id; $meta = get_object_vars( $meta ); - $x = new WP_Ajax_Response( array( - 'what' => 'meta', - 'id' => $mid, - 'data' => _list_meta_row( $meta, $c ), - 'position' => 1, - 'supplemental' => array('postid' => $pid) - ) ); + $x = new WP_Ajax_Response( + array( + 'what' => 'meta', + 'id' => $mid, + 'data' => _list_meta_row( $meta, $c ), + 'position' => 1, + 'supplemental' => array( 'postid' => $pid ), + ) + ); } else { // Update? - $mid = (int) key( $_POST['meta'] ); - $key = wp_unslash( $_POST['meta'][$mid]['key'] ); - $value = wp_unslash( $_POST['meta'][$mid]['value'] ); - if ( '' == trim($key) ) + $mid = (int) key( $_POST['meta'] ); + $key = wp_unslash( $_POST['meta'][ $mid ]['key'] ); + $value = wp_unslash( $_POST['meta'][ $mid ]['value'] ); + if ( '' == trim( $key ) ) { wp_die( __( 'Please provide a custom field name.' ) ); - if ( '' == trim($value) ) + } + if ( '' == trim( $value ) ) { wp_die( __( 'Please provide a custom field value.' ) ); - if ( ! $meta = get_metadata_by_mid( 'post', $mid ) ) + } + if ( ! $meta = get_metadata_by_mid( 'post', $mid ) ) { wp_die( 0 ); // if meta doesn't exist + } if ( is_protected_meta( $meta->meta_key, 'post' ) || is_protected_meta( $key, 'post' ) || ! current_user_can( 'edit_post_meta', $meta->post_id, $meta->meta_key ) || - ! current_user_can( 'edit_post_meta', $meta->post_id, $key ) ) + ! current_user_can( 'edit_post_meta', $meta->post_id, $key ) ) { wp_die( -1 ); + } if ( $meta->meta_value != $value || $meta->meta_key != $key ) { - if ( !$u = update_metadata_by_mid( 'post', $mid, $value, $key ) ) + if ( ! $u = update_metadata_by_mid( 'post', $mid, $value, $key ) ) { wp_die( 0 ); // We know meta exists; we also know it's unchanged (or DB error, in which case there are bigger problems). + } } - $x = new WP_Ajax_Response( array( - 'what' => 'meta', - 'id' => $mid, 'old_id' => $mid, - 'data' => _list_meta_row( array( - 'meta_key' => $key, - 'meta_value' => $value, - 'meta_id' => $mid - ), $c ), - 'position' => 0, - 'supplemental' => array('postid' => $meta->post_id) - ) ); + $x = new WP_Ajax_Response( + array( + 'what' => 'meta', + 'id' => $mid, + 'old_id' => $mid, + 'data' => _list_meta_row( + array( + 'meta_key' => $key, + 'meta_value' => $value, + 'meta_id' => $mid, + ), $c + ), + 'position' => 0, + 'supplemental' => array( 'postid' => $meta->post_id ), + ) + ); } $x->send(); } @@ -1382,36 +1546,41 @@ function wp_ajax_add_user( $action ) { } check_ajax_referer( $action ); - if ( ! current_user_can('create_users') ) + if ( ! current_user_can( 'create_users' ) ) { wp_die( -1 ); + } if ( ! $user_id = edit_user() ) { wp_die( 0 ); } elseif ( is_wp_error( $user_id ) ) { - $x = new WP_Ajax_Response( array( - 'what' => 'user', - 'id' => $user_id - ) ); + $x = new WP_Ajax_Response( + array( + 'what' => 'user', + 'id' => $user_id, + ) + ); $x->send(); } $user_object = get_userdata( $user_id ); - $wp_list_table = _get_list_table('WP_Users_List_Table'); + $wp_list_table = _get_list_table( 'WP_Users_List_Table' ); $role = current( $user_object->roles ); - $x = new WP_Ajax_Response( array( - 'what' => 'user', - 'id' => $user_id, - 'data' => $wp_list_table->single_row( $user_object, '', $role ), - 'supplemental' => array( - 'show-link' => sprintf( - /* translators: %s: the new user */ - __( 'User %s added' ), - '' . $user_object->user_login . '' + $x = new WP_Ajax_Response( + array( + 'what' => 'user', + 'id' => $user_id, + 'data' => $wp_list_table->single_row( $user_object, '', $role ), + 'supplemental' => array( + 'show-link' => sprintf( + /* translators: %s: the new user */ + __( 'User %s added' ), + '' . $user_object->user_login . '' + ), + 'role' => $role, ), - 'role' => $role, ) - ) ); + ); $x->send(); } @@ -1422,26 +1591,29 @@ function wp_ajax_add_user( $action ) { */ function wp_ajax_closed_postboxes() { check_ajax_referer( 'closedpostboxes', 'closedpostboxesnonce' ); - $closed = isset( $_POST['closed'] ) ? explode( ',', $_POST['closed']) : array(); - $closed = array_filter($closed); + $closed = isset( $_POST['closed'] ) ? explode( ',', $_POST['closed'] ) : array(); + $closed = array_filter( $closed ); - $hidden = isset( $_POST['hidden'] ) ? explode( ',', $_POST['hidden']) : array(); - $hidden = array_filter($hidden); + $hidden = isset( $_POST['hidden'] ) ? explode( ',', $_POST['hidden'] ) : array(); + $hidden = array_filter( $hidden ); $page = isset( $_POST['page'] ) ? $_POST['page'] : ''; - if ( $page != sanitize_key( $page ) ) + if ( $page != sanitize_key( $page ) ) { wp_die( 0 ); + } - if ( ! $user = wp_get_current_user() ) + if ( ! $user = wp_get_current_user() ) { wp_die( -1 ); + } - if ( is_array($closed) ) - update_user_option($user->ID, "closedpostboxes_$page", $closed, true); + if ( is_array( $closed ) ) { + update_user_option( $user->ID, "closedpostboxes_$page", $closed, true ); + } - if ( is_array($hidden) ) { - $hidden = array_diff( $hidden, array('submitdiv', 'linksubmitdiv', 'manage-menu', 'create-menu') ); // postboxes that are always shown - update_user_option($user->ID, "metaboxhidden_$page", $hidden, true); + if ( is_array( $hidden ) ) { + $hidden = array_diff( $hidden, array( 'submitdiv', 'linksubmitdiv', 'manage-menu', 'create-menu' ) ); // postboxes that are always shown + update_user_option( $user->ID, "metaboxhidden_$page", $hidden, true ); } wp_die( 1 ); @@ -1456,11 +1628,13 @@ function wp_ajax_hidden_columns() { check_ajax_referer( 'screen-options-nonce', 'screenoptionnonce' ); $page = isset( $_POST['page'] ) ? $_POST['page'] : ''; - if ( $page != sanitize_key( $page ) ) + if ( $page != sanitize_key( $page ) ) { wp_die( 0 ); + } - if ( ! $user = wp_get_current_user() ) + if ( ! $user = wp_get_current_user() ) { wp_die( -1 ); + } $hidden = ! empty( $_POST['hidden'] ) ? explode( ',', $_POST['hidden'] ) : array(); update_user_option( $user->ID, "manage{$page}columnshidden", $hidden, true ); @@ -1476,8 +1650,9 @@ function wp_ajax_hidden_columns() { function wp_ajax_update_welcome_panel() { check_ajax_referer( 'welcome-panel-nonce', 'welcomepanelnonce' ); - if ( ! current_user_can( 'edit_theme_options' ) ) + if ( ! current_user_can( 'edit_theme_options' ) ) { wp_die( -1 ); + } update_user_meta( get_current_user_id(), 'show_welcome_panel', empty( $_POST['visible'] ) ? 0 : 1 ); @@ -1490,43 +1665,48 @@ function wp_ajax_update_welcome_panel() { * @since 3.1.0 */ function wp_ajax_menu_get_metabox() { - if ( ! current_user_can( 'edit_theme_options' ) ) + if ( ! current_user_can( 'edit_theme_options' ) ) { wp_die( -1 ); + } require_once ABSPATH . 'wp-admin/includes/nav-menu.php'; if ( isset( $_POST['item-type'] ) && 'post_type' == $_POST['item-type'] ) { - $type = 'posttype'; + $type = 'posttype'; $callback = 'wp_nav_menu_item_post_type_meta_box'; - $items = (array) get_post_types( array( 'show_in_nav_menus' => true ), 'object' ); + $items = (array) get_post_types( array( 'show_in_nav_menus' => true ), 'object' ); } elseif ( isset( $_POST['item-type'] ) && 'taxonomy' == $_POST['item-type'] ) { - $type = 'taxonomy'; + $type = 'taxonomy'; $callback = 'wp_nav_menu_item_taxonomy_meta_box'; - $items = (array) get_taxonomies( array( 'show_ui' => true ), 'object' ); + $items = (array) get_taxonomies( array( 'show_ui' => true ), 'object' ); } - if ( ! empty( $_POST['item-object'] ) && isset( $items[$_POST['item-object']] ) ) { + if ( ! empty( $_POST['item-object'] ) && isset( $items[ $_POST['item-object'] ] ) ) { $menus_meta_box_object = $items[ $_POST['item-object'] ]; /** This filter is documented in wp-admin/includes/nav-menu.php */ $item = apply_filters( 'nav_menu_meta_box_object', $menus_meta_box_object ); ob_start(); - call_user_func_array($callback, array( - null, - array( - 'id' => 'add-' . $item->name, - 'title' => $item->labels->name, - 'callback' => $callback, - 'args' => $item, + call_user_func_array( + $callback, array( + null, + array( + 'id' => 'add-' . $item->name, + 'title' => $item->labels->name, + 'callback' => $callback, + 'args' => $item, + ), ) - )); + ); $markup = ob_get_clean(); - echo wp_json_encode(array( - 'replace-id' => $type . '-' . $item->name, - 'markup' => $markup, - )); + echo wp_json_encode( + array( + 'replace-id' => $type . '-' . $item->name, + 'markup' => $markup, + ) + ); } wp_die(); @@ -1558,8 +1738,9 @@ function wp_ajax_wp_link_ajax() { $results = _WP_Editors::wp_link_query( $args ); - if ( ! isset( $results ) ) + if ( ! isset( $results ) ) { wp_die( 0 ); + } echo wp_json_encode( $results ); echo "\n"; @@ -1573,11 +1754,13 @@ function wp_ajax_wp_link_ajax() { * @since 3.1.0 */ function wp_ajax_menu_locations_save() { - if ( ! current_user_can( 'edit_theme_options' ) ) + if ( ! current_user_can( 'edit_theme_options' ) ) { wp_die( -1 ); + } check_ajax_referer( 'add-menu_item', 'menu-settings-column-nonce' ); - if ( ! isset( $_POST['menu-locations'] ) ) + if ( ! isset( $_POST['menu-locations'] ) ) { wp_die( 0 ); + } set_theme_mod( 'nav_menu_locations', array_map( 'absint', $_POST['menu-locations'] ) ); wp_die( 1 ); } @@ -1589,25 +1772,30 @@ function wp_ajax_menu_locations_save() { */ function wp_ajax_meta_box_order() { check_ajax_referer( 'meta-box-order' ); - $order = isset( $_POST['order'] ) ? (array) $_POST['order'] : false; + $order = isset( $_POST['order'] ) ? (array) $_POST['order'] : false; $page_columns = isset( $_POST['page_columns'] ) ? $_POST['page_columns'] : 'auto'; - if ( $page_columns != 'auto' ) + if ( $page_columns != 'auto' ) { $page_columns = (int) $page_columns; + } $page = isset( $_POST['page'] ) ? $_POST['page'] : ''; - if ( $page != sanitize_key( $page ) ) + if ( $page != sanitize_key( $page ) ) { wp_die( 0 ); + } - if ( ! $user = wp_get_current_user() ) + if ( ! $user = wp_get_current_user() ) { wp_die( -1 ); + } - if ( $order ) - update_user_option($user->ID, "meta-box-order_$page", $order, true); + if ( $order ) { + update_user_option( $user->ID, "meta-box-order_$page", $order, true ); + } - if ( $page_columns ) - update_user_option($user->ID, "screen_layout_$page", $page_columns, true); + if ( $page_columns ) { + update_user_option( $user->ID, "screen_layout_$page", $page_columns, true ); + } wp_die( 1 ); } @@ -1618,8 +1806,9 @@ function wp_ajax_meta_box_order() { * @since 3.1.0 */ function wp_ajax_menu_quick_search() { - if ( ! current_user_can( 'edit_theme_options' ) ) + if ( ! current_user_can( 'edit_theme_options' ) ) { wp_die( -1 ); + } require_once ABSPATH . 'wp-admin/includes/nav-menu.php'; @@ -1635,7 +1824,7 @@ function wp_ajax_menu_quick_search() { */ function wp_ajax_get_permalink() { check_ajax_referer( 'getpermalink', 'getpermalinknonce' ); - $post_id = isset($_POST['post_id'])? intval($_POST['post_id']) : 0; + $post_id = isset( $_POST['post_id'] ) ? intval( $_POST['post_id'] ) : 0; wp_die( get_preview_post_link( $post_id ) ); } @@ -1646,9 +1835,9 @@ function wp_ajax_get_permalink() { */ function wp_ajax_sample_permalink() { check_ajax_referer( 'samplepermalink', 'samplepermalinknonce' ); - $post_id = isset($_POST['post_id'])? intval($_POST['post_id']) : 0; - $title = isset($_POST['new_title'])? $_POST['new_title'] : ''; - $slug = isset($_POST['new_slug'])? $_POST['new_slug'] : null; + $post_id = isset( $_POST['post_id'] ) ? intval( $_POST['post_id'] ) : 0; + $title = isset( $_POST['new_title'] ) ? $_POST['new_title'] : ''; + $slug = isset( $_POST['new_slug'] ) ? $_POST['new_slug'] : null; wp_die( get_sample_permalink_html( $post_id, $title, $slug ) ); } @@ -1664,21 +1853,24 @@ function wp_ajax_inline_save() { check_ajax_referer( 'inlineeditnonce', '_inline_edit' ); - if ( ! isset($_POST['post_ID']) || ! ( $post_ID = (int) $_POST['post_ID'] ) ) + if ( ! isset( $_POST['post_ID'] ) || ! ( $post_ID = (int) $_POST['post_ID'] ) ) { wp_die(); + } if ( 'page' == $_POST['post_type'] ) { - if ( ! current_user_can( 'edit_page', $post_ID ) ) + if ( ! current_user_can( 'edit_page', $post_ID ) ) { wp_die( __( 'Sorry, you are not allowed to edit this page.' ) ); + } } else { - if ( ! current_user_can( 'edit_post', $post_ID ) ) + if ( ! current_user_can( 'edit_post', $post_ID ) ) { wp_die( __( 'Sorry, you are not allowed to edit this post.' ) ); + } } if ( $last = wp_check_post_lock( $post_ID ) ) { - $last_user = get_userdata( $last ); + $last_user = get_userdata( $last ); $last_user_name = $last_user ? $last_user->display_name : __( 'Someone' ); - printf( $_POST['post_type'] == 'page' ? __( 'Saving is disabled: %s is currently editing this page.' ) : __( 'Saving is disabled: %s is currently editing this post.' ), esc_html( $last_user_name ) ); + printf( $_POST['post_type'] == 'page' ? __( 'Saving is disabled: %s is currently editing this page.' ) : __( 'Saving is disabled: %s is currently editing this post.' ), esc_html( $last_user_name ) ); wp_die(); } @@ -1687,7 +1879,7 @@ function wp_ajax_inline_save() { $post = get_post( $post_ID, ARRAY_A ); // Since it's coming from the database. - $post = wp_slash($post); + $post = wp_slash( $post ); $data['content'] = $post['post_content']; $data['excerpt'] = $post['post_excerpt']; @@ -1695,8 +1887,9 @@ function wp_ajax_inline_save() { // Rename. $data['user_ID'] = get_current_user_id(); - if ( isset($data['post_parent']) ) + if ( isset( $data['post_parent'] ) ) { $data['parent_id'] = $data['post_parent']; + } // Status. if ( isset( $data['keep_private'] ) && 'private' == $data['keep_private'] ) { @@ -1706,10 +1899,12 @@ function wp_ajax_inline_save() { $data['post_status'] = $data['_status']; } - if ( empty($data['comment_status']) ) + if ( empty( $data['comment_status'] ) ) { $data['comment_status'] = 'closed'; - if ( empty($data['ping_status']) ) + } + if ( empty( $data['ping_status'] ) ) { $data['ping_status'] = 'closed'; + } // Exclude terms from taxonomies that are not supposed to appear in Quick Edit. if ( ! empty( $data['tax_input'] ) ) { @@ -1725,7 +1920,7 @@ function wp_ajax_inline_save() { // Hack: wp_unique_post_slug() doesn't work for drafts, so we will fake that our post is published. if ( ! empty( $data['post_name'] ) && in_array( $post['post_status'], array( 'draft', 'pending' ) ) ) { $post['post_status'] = 'publish'; - $data['post_name'] = wp_unique_post_slug( $data['post_name'], $post['ID'], $post['post_status'], $post['post_type'], $post['post_parent'] ); + $data['post_name'] = wp_unique_post_slug( $data['post_name'], $post['ID'], $post['post_status'], $post['post_type'], $post['post_parent'] ); } // Update the post. @@ -1761,9 +1956,10 @@ function wp_ajax_inline_save_tax() { check_ajax_referer( 'taxinlineeditnonce', '_inline_edit' ); $taxonomy = sanitize_key( $_POST['taxonomy'] ); - $tax = get_taxonomy( $taxonomy ); - if ( ! $tax ) + $tax = get_taxonomy( $taxonomy ); + if ( ! $tax ) { wp_die( 0 ); + } if ( ! isset( $_POST['tax_ID'] ) || ! ( $id = (int) $_POST['tax_ID'] ) ) { wp_die( -1 ); @@ -1775,27 +1971,29 @@ function wp_ajax_inline_save_tax() { $wp_list_table = _get_list_table( 'WP_Terms_List_Table', array( 'screen' => 'edit-' . $taxonomy ) ); - $tag = get_term( $id, $taxonomy ); + $tag = get_term( $id, $taxonomy ); $_POST['description'] = $tag->description; - $updated = wp_update_term($id, $taxonomy, $_POST); - if ( $updated && !is_wp_error($updated) ) { + $updated = wp_update_term( $id, $taxonomy, $_POST ); + if ( $updated && ! is_wp_error( $updated ) ) { $tag = get_term( $updated['term_id'], $taxonomy ); - if ( !$tag || is_wp_error( $tag ) ) { - if ( is_wp_error($tag) && $tag->get_error_message() ) + if ( ! $tag || is_wp_error( $tag ) ) { + if ( is_wp_error( $tag ) && $tag->get_error_message() ) { wp_die( $tag->get_error_message() ); + } wp_die( __( 'Item not updated.' ) ); } } else { - if ( is_wp_error($updated) && $updated->get_error_message() ) + if ( is_wp_error( $updated ) && $updated->get_error_message() ) { wp_die( $updated->get_error_message() ); + } wp_die( __( 'Item not updated.' ) ); } - $level = 0; + $level = 0; $parent = $tag->parent; while ( $parent > 0 ) { $parent_tag = get_term( $parent, $taxonomy ); - $parent = $parent_tag->parent; + $parent = $parent_tag->parent; $level++; } $wp_list_table->single_row( $tag, $level ); @@ -1815,14 +2013,15 @@ function wp_ajax_find_posts() { $post_types = get_post_types( array( 'public' => true ), 'objects' ); unset( $post_types['attachment'] ); - $s = wp_unslash( $_POST['ps'] ); + $s = wp_unslash( $_POST['ps'] ); $args = array( - 'post_type' => array_keys( $post_types ), - 'post_status' => 'any', + 'post_type' => array_keys( $post_types ), + 'post_status' => 'any', 'posts_per_page' => 50, ); - if ( '' !== $s ) + if ( '' !== $s ) { $args['s'] = $s; + } $posts = get_posts( $args ); @@ -1830,25 +2029,25 @@ function wp_ajax_find_posts() { wp_send_json_error( __( 'No items found.' ) ); } - $html = ''; - $alt = ''; + $html = '

'.__('Title').''.__('Type').''.__('Date').''.__('Status').'
'; + $alt = ''; foreach ( $posts as $post ) { $title = trim( $post->post_title ) ? $post->post_title : __( '(no title)' ); - $alt = ( 'alternate' == $alt ) ? '' : 'alternate'; + $alt = ( 'alternate' == $alt ) ? '' : 'alternate'; switch ( $post->post_status ) { - case 'publish' : - case 'private' : - $stat = __('Published'); + case 'publish': + case 'private': + $stat = __( 'Published' ); break; - case 'future' : - $stat = __('Scheduled'); + case 'future': + $stat = __( 'Scheduled' ); break; - case 'pending' : - $stat = __('Pending Review'); + case 'pending': + $stat = __( 'Pending Review' ); break; - case 'draft' : - $stat = __('Draft'); + case 'draft': + $stat = __( 'Draft' ); break; } @@ -1856,11 +2055,11 @@ function wp_ajax_find_posts() { $time = ''; } else { /* translators: date format in table columns, see https://secure.php.net/date */ - $time = mysql2date(__('Y/m/d'), $post->post_date); + $time = mysql2date( __( 'Y/m/d' ), $post->post_date ); } - $html .= ''; - $html .= '' . "\n\n"; + $html .= ''; + $html .= '' . "\n\n"; } $html .= '

' . __( 'Title' ) . '' . __( 'Type' ) . '' . __( 'Date' ) . '' . __( 'Status' ) . '
' . esc_html( $post_types[$post->post_type]->labels->singular_name ) . ''.esc_html( $time ) . '' . esc_html( $stat ). '
' . esc_html( $post_types[ $post->post_type ]->labels->singular_name ) . '' . esc_html( $time ) . '' . esc_html( $stat ) . '
'; @@ -1876,28 +2075,30 @@ function wp_ajax_find_posts() { function wp_ajax_widgets_order() { check_ajax_referer( 'save-sidebar-widgets', 'savewidgets' ); - if ( !current_user_can('edit_theme_options') ) + if ( ! current_user_can( 'edit_theme_options' ) ) { wp_die( -1 ); + } unset( $_POST['savewidgets'], $_POST['action'] ); // Save widgets order for all sidebars. - if ( is_array($_POST['sidebars']) ) { + if ( is_array( $_POST['sidebars'] ) ) { $sidebars = array(); foreach ( wp_unslash( $_POST['sidebars'] ) as $key => $val ) { $sb = array(); - if ( !empty($val) ) { - $val = explode(',', $val); + if ( ! empty( $val ) ) { + $val = explode( ',', $val ); foreach ( $val as $k => $v ) { - if ( strpos($v, 'widget-') === false ) + if ( strpos( $v, 'widget-' ) === false ) { continue; + } - $sb[$k] = substr($v, strpos($v, '_') + 1); + $sb[ $k ] = substr( $v, strpos( $v, '_' ) + 1 ); } } - $sidebars[$key] = $sb; + $sidebars[ $key ] = $sb; } - wp_set_sidebars_widgets($sidebars); + wp_set_sidebars_widgets( $sidebars ); wp_die( 1 ); } @@ -1918,8 +2119,9 @@ function wp_ajax_save_widget() { check_ajax_referer( 'save-sidebar-widgets', 'savewidgets' ); - if ( !current_user_can('edit_theme_options') || !isset($_POST['id_base']) ) + if ( ! current_user_can( 'edit_theme_options' ) || ! isset( $_POST['id_base'] ) ) { wp_die( -1 ); + } unset( $_POST['savewidgets'], $_POST['action'] ); @@ -1940,43 +2142,51 @@ function wp_ajax_save_widget() { /** This action is documented in wp-admin/widgets.php */ do_action( 'sidebar_admin_setup' ); - $id_base = wp_unslash( $_POST['id_base'] ); - $widget_id = wp_unslash( $_POST['widget-id'] ); - $sidebar_id = $_POST['sidebar']; - $multi_number = !empty($_POST['multi_number']) ? (int) $_POST['multi_number'] : 0; - $settings = isset($_POST['widget-' . $id_base]) && is_array($_POST['widget-' . $id_base]) ? $_POST['widget-' . $id_base] : false; - $error = '

' . __('An error has occurred. Please reload the page and try again.') . '

'; + $id_base = wp_unslash( $_POST['id_base'] ); + $widget_id = wp_unslash( $_POST['widget-id'] ); + $sidebar_id = $_POST['sidebar']; + $multi_number = ! empty( $_POST['multi_number'] ) ? (int) $_POST['multi_number'] : 0; + $settings = isset( $_POST[ 'widget-' . $id_base ] ) && is_array( $_POST[ 'widget-' . $id_base ] ) ? $_POST[ 'widget-' . $id_base ] : false; + $error = '

' . __( 'An error has occurred. Please reload the page and try again.' ) . '

'; $sidebars = wp_get_sidebars_widgets(); - $sidebar = isset($sidebars[$sidebar_id]) ? $sidebars[$sidebar_id] : array(); + $sidebar = isset( $sidebars[ $sidebar_id ] ) ? $sidebars[ $sidebar_id ] : array(); // Delete. - if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) { + if ( isset( $_POST['delete_widget'] ) && $_POST['delete_widget'] ) { - if ( !isset($wp_registered_widgets[$widget_id]) ) + if ( ! isset( $wp_registered_widgets[ $widget_id ] ) ) { wp_die( $error ); + } - $sidebar = array_diff( $sidebar, array($widget_id) ); - $_POST = array('sidebar' => $sidebar_id, 'widget-' . $id_base => array(), 'the-widget-id' => $widget_id, 'delete_widget' => '1'); + $sidebar = array_diff( $sidebar, array( $widget_id ) ); + $_POST = array( + 'sidebar' => $sidebar_id, + 'widget-' . $id_base => array(), + 'the-widget-id' => $widget_id, + 'delete_widget' => '1', + ); /** This action is documented in wp-admin/widgets.php */ do_action( 'delete_widget', $widget_id, $sidebar_id, $id_base ); - } elseif ( $settings && preg_match( '/__i__|%i%/', key($settings) ) ) { - if ( !$multi_number ) + } elseif ( $settings && preg_match( '/__i__|%i%/', key( $settings ) ) ) { + if ( ! $multi_number ) { wp_die( $error ); + } $_POST[ 'widget-' . $id_base ] = array( $multi_number => reset( $settings ) ); - $widget_id = $id_base . '-' . $multi_number; - $sidebar[] = $widget_id; + $widget_id = $id_base . '-' . $multi_number; + $sidebar[] = $widget_id; } $_POST['widget-id'] = $sidebar; foreach ( (array) $wp_registered_widget_updates as $name => $control ) { if ( $name == $id_base ) { - if ( !is_callable( $control['callback'] ) ) + if ( ! is_callable( $control['callback'] ) ) { continue; + } ob_start(); call_user_func_array( $control['callback'], $control['params'] ); @@ -1985,18 +2195,20 @@ function wp_ajax_save_widget() { } } - if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) { - $sidebars[$sidebar_id] = $sidebar; - wp_set_sidebars_widgets($sidebars); + if ( isset( $_POST['delete_widget'] ) && $_POST['delete_widget'] ) { + $sidebars[ $sidebar_id ] = $sidebar; + wp_set_sidebars_widgets( $sidebars ); echo "deleted:$widget_id"; wp_die(); } - if ( !empty($_POST['add_new']) ) + if ( ! empty( $_POST['add_new'] ) ) { wp_die(); + } - if ( $form = $wp_registered_widget_controls[$widget_id] ) + if ( $form = $wp_registered_widget_controls[ $widget_id ] ) { call_user_func_array( $form['callback'], $form['params'] ); + } wp_die(); } @@ -2036,13 +2248,13 @@ function wp_ajax_delete_inactive_widgets() { $sidebars_widgets = wp_get_sidebars_widgets(); foreach ( $sidebars_widgets['wp_inactive_widgets'] as $key => $widget_id ) { - $pieces = explode( '-', $widget_id ); + $pieces = explode( '-', $widget_id ); $multi_number = array_pop( $pieces ); - $id_base = implode( '-', $pieces ); - $widget = get_option( 'widget_' . $id_base ); - unset( $widget[$multi_number] ); + $id_base = implode( '-', $pieces ); + $widget = get_option( 'widget_' . $id_base ); + unset( $widget[ $multi_number ] ); update_option( 'widget_' . $id_base, $widget ); - unset( $sidebars_widgets['wp_inactive_widgets'][$key] ); + unset( $sidebars_widgets['wp_inactive_widgets'][ $key ] ); } wp_set_sidebars_widgets( $sidebars_widgets ); @@ -2064,13 +2276,15 @@ function wp_ajax_upload_attachment() { */ if ( ! current_user_can( 'upload_files' ) ) { - echo wp_json_encode( array( - 'success' => false, - 'data' => array( - 'message' => __( 'Sorry, you are not allowed to upload files.' ), - 'filename' => $_FILES['async-upload']['name'], + echo wp_json_encode( + array( + 'success' => false, + 'data' => array( + 'message' => __( 'Sorry, you are not allowed to upload files.' ), + 'filename' => $_FILES['async-upload']['name'], + ), ) - ) ); + ); wp_die(); } @@ -2078,13 +2292,15 @@ function wp_ajax_upload_attachment() { if ( isset( $_REQUEST['post_id'] ) ) { $post_id = $_REQUEST['post_id']; if ( ! current_user_can( 'edit_post', $post_id ) ) { - echo wp_json_encode( array( - 'success' => false, - 'data' => array( - 'message' => __( 'Sorry, you are not allowed to attach files to this post.' ), - 'filename' => $_FILES['async-upload']['name'], + echo wp_json_encode( + array( + 'success' => false, + 'data' => array( + 'message' => __( 'Sorry, you are not allowed to attach files to this post.' ), + 'filename' => $_FILES['async-upload']['name'], + ), ) - ) ); + ); wp_die(); } @@ -2098,13 +2314,15 @@ function wp_ajax_upload_attachment() { if ( isset( $post_data['context'] ) && in_array( $post_data['context'], array( 'custom-header', 'custom-background' ) ) ) { $wp_filetype = wp_check_filetype_and_ext( $_FILES['async-upload']['tmp_name'], $_FILES['async-upload']['name'] ); if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) { - echo wp_json_encode( array( - 'success' => false, - 'data' => array( - 'message' => __( 'The uploaded file is not a valid image. Please try again.' ), - 'filename' => $_FILES['async-upload']['name'], + echo wp_json_encode( + array( + 'success' => false, + 'data' => array( + 'message' => __( 'The uploaded file is not a valid image. Please try again.' ), + 'filename' => $_FILES['async-upload']['name'], + ), ) - ) ); + ); wp_die(); } @@ -2113,32 +2331,39 @@ function wp_ajax_upload_attachment() { $attachment_id = media_handle_upload( 'async-upload', $post_id, $post_data ); if ( is_wp_error( $attachment_id ) ) { - echo wp_json_encode( array( - 'success' => false, - 'data' => array( - 'message' => $attachment_id->get_error_message(), - 'filename' => $_FILES['async-upload']['name'], + echo wp_json_encode( + array( + 'success' => false, + 'data' => array( + 'message' => $attachment_id->get_error_message(), + 'filename' => $_FILES['async-upload']['name'], + ), ) - ) ); + ); wp_die(); } if ( isset( $post_data['context'] ) && isset( $post_data['theme'] ) ) { - if ( 'custom-background' === $post_data['context'] ) + if ( 'custom-background' === $post_data['context'] ) { update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', $post_data['theme'] ); + } - if ( 'custom-header' === $post_data['context'] ) + if ( 'custom-header' === $post_data['context'] ) { update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', $post_data['theme'] ); + } } - if ( ! $attachment = wp_prepare_attachment_for_js( $attachment_id ) ) + if ( ! $attachment = wp_prepare_attachment_for_js( $attachment_id ) ) { wp_die(); + } - echo wp_json_encode( array( - 'success' => true, - 'data' => $attachment, - ) ); + echo wp_json_encode( + array( + 'success' => true, + 'data' => $attachment, + ) + ); wp_die(); } @@ -2149,29 +2374,30 @@ function wp_ajax_upload_attachment() { * @since 3.1.0 */ function wp_ajax_image_editor() { - $attachment_id = intval($_POST['postid']); - if ( empty($attachment_id) || !current_user_can('edit_post', $attachment_id) ) + $attachment_id = intval( $_POST['postid'] ); + if ( empty( $attachment_id ) || ! current_user_can( 'edit_post', $attachment_id ) ) { wp_die( -1 ); + } check_ajax_referer( "image_editor-$attachment_id" ); include_once( ABSPATH . 'wp-admin/includes/image-edit.php' ); $msg = false; switch ( $_POST['do'] ) { - case 'save' : - $msg = wp_save_image($attachment_id); - $msg = wp_json_encode($msg); + case 'save': + $msg = wp_save_image( $attachment_id ); + $msg = wp_json_encode( $msg ); wp_die( $msg ); break; - case 'scale' : - $msg = wp_save_image($attachment_id); + case 'scale': + $msg = wp_save_image( $attachment_id ); break; - case 'restore' : - $msg = wp_restore_image($attachment_id); + case 'restore': + $msg = wp_restore_image( $attachment_id ); break; } - wp_image_editor($attachment_id, $msg); + wp_image_editor( $attachment_id, $msg ); wp_die(); } @@ -2184,15 +2410,17 @@ function wp_ajax_set_post_thumbnail() { $json = ! empty( $_REQUEST['json'] ); // New-style request $post_ID = intval( $_POST['post_id'] ); - if ( ! current_user_can( 'edit_post', $post_ID ) ) + if ( ! current_user_can( 'edit_post', $post_ID ) ) { wp_die( -1 ); + } $thumbnail_id = intval( $_POST['thumbnail_id'] ); - if ( $json ) + if ( $json ) { check_ajax_referer( "update-post_$post_ID" ); - else + } else { check_ajax_referer( "set_post_thumbnail-$post_ID" ); + } if ( $thumbnail_id == '-1' ) { if ( delete_post_thumbnail( $post_ID ) ) { @@ -2316,10 +2544,11 @@ function wp_ajax_wp_fullscreen_save_post() { $post = null; - if ( $post_id ) + if ( $post_id ) { $post = get_post( $post_id ); + } - check_ajax_referer('update-post_' . $post_id, '_wpnonce'); + check_ajax_referer( 'update-post_' . $post_id, '_wpnonce' ); $post_id = edit_post(); @@ -2336,10 +2565,10 @@ function wp_ajax_wp_fullscreen_save_post() { } if ( $last_id = get_post_meta( $post_id, '_edit_last', true ) ) { - $last_user = get_userdata( $last_id ); - $last_edited = sprintf( __('Last edited by %1$s on %2$s at %3$s'), esc_html( $last_user->display_name ), $last_date, $last_time ); + $last_user = get_userdata( $last_id ); + $last_edited = sprintf( __( 'Last edited by %1$s on %2$s at %3$s' ), esc_html( $last_user->display_name ), $last_date, $last_time ); } else { - $last_edited = sprintf( __('Last edited on %1$s at %2$s'), $last_date, $last_time ); + $last_edited = sprintf( __( 'Last edited on %1$s at %2$s' ), $last_date, $last_time ); } wp_send_json_success( array( 'last_edited' => $last_edited ) ); @@ -2351,20 +2580,24 @@ function wp_ajax_wp_fullscreen_save_post() { * @since 3.1.0 */ function wp_ajax_wp_remove_post_lock() { - if ( empty( $_POST['post_ID'] ) || empty( $_POST['active_post_lock'] ) ) + if ( empty( $_POST['post_ID'] ) || empty( $_POST['active_post_lock'] ) ) { wp_die( 0 ); + } $post_id = (int) $_POST['post_ID']; - if ( ! $post = get_post( $post_id ) ) + if ( ! $post = get_post( $post_id ) ) { wp_die( 0 ); + } check_ajax_referer( 'update-post_' . $post_id ); - if ( ! current_user_can( 'edit_post', $post_id ) ) + if ( ! current_user_can( 'edit_post', $post_id ) ) { wp_die( -1 ); + } $active_lock = array_map( 'absint', explode( ':', $_POST['active_post_lock'] ) ); - if ( $active_lock[1] != get_current_user_id() ) + if ( $active_lock[1] != get_current_user_id() ) { wp_die( 0 ); + } /** * Filters the post lock window duration. @@ -2386,18 +2619,20 @@ function wp_ajax_wp_remove_post_lock() { */ function wp_ajax_dismiss_wp_pointer() { $pointer = $_POST['pointer']; - if ( $pointer != sanitize_key( $pointer ) ) + if ( $pointer != sanitize_key( $pointer ) ) { wp_die( 0 ); + } -// check_ajax_referer( 'dismiss-pointer_' . $pointer ); + // check_ajax_referer( 'dismiss-pointer_' . $pointer ); $dismissed = array_filter( explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ) ); - if ( in_array( $pointer, $dismissed ) ) + if ( in_array( $pointer, $dismissed ) ) { wp_die( 0 ); + } $dismissed[] = $pointer; - $dismissed = implode( ',', $dismissed ); + $dismissed = implode( ',', $dismissed ); update_user_meta( get_current_user_id(), 'dismissed_wp_pointers', $dismissed ); wp_die( 1 ); @@ -2409,23 +2644,29 @@ function wp_ajax_dismiss_wp_pointer() { * @since 3.5.0 */ function wp_ajax_get_attachment() { - if ( ! isset( $_REQUEST['id'] ) ) + if ( ! isset( $_REQUEST['id'] ) ) { wp_send_json_error(); + } - if ( ! $id = absint( $_REQUEST['id'] ) ) + if ( ! $id = absint( $_REQUEST['id'] ) ) { wp_send_json_error(); + } - if ( ! $post = get_post( $id ) ) + if ( ! $post = get_post( $id ) ) { wp_send_json_error(); + } - if ( 'attachment' != $post->post_type ) + if ( 'attachment' != $post->post_type ) { wp_send_json_error(); + } - if ( ! current_user_can( 'upload_files' ) ) + if ( ! current_user_can( 'upload_files' ) ) { wp_send_json_error(); + } - if ( ! $attachment = wp_prepare_attachment_for_js( $id ) ) + if ( ! $attachment = wp_prepare_attachment_for_js( $id ) ) { wp_send_json_error(); + } wp_send_json_success( $attachment ); } @@ -2436,13 +2677,23 @@ function wp_ajax_get_attachment() { * @since 3.5.0 */ function wp_ajax_query_attachments() { - if ( ! current_user_can( 'upload_files' ) ) + if ( ! current_user_can( 'upload_files' ) ) { wp_send_json_error(); + } $query = isset( $_REQUEST['query'] ) ? (array) $_REQUEST['query'] : array(); - $keys = array( - 's', 'order', 'orderby', 'posts_per_page', 'paged', 'post_mime_type', - 'post_parent', 'post__in', 'post__not_in', 'year', 'monthnum' + $keys = array( + 's', + 'order', + 'orderby', + 'posts_per_page', + 'paged', + 'post_mime_type', + 'post_parent', + 'post__in', + 'post__not_in', + 'year', + 'monthnum', ); foreach ( get_taxonomies_for_attachments( 'objects' ) as $t ) { if ( $t->query_var && isset( $query[ $t->query_var ] ) ) { @@ -2450,7 +2701,7 @@ function wp_ajax_query_attachments() { } } - $query = array_intersect_key( $query, array_flip( $keys ) ); + $query = array_intersect_key( $query, array_flip( $keys ) ); $query['post_type'] = 'attachment'; if ( MEDIA_TRASH && ! empty( $_REQUEST['query']['post_status'] ) @@ -2460,8 +2711,9 @@ function wp_ajax_query_attachments() { $query['post_status'] = 'inherit'; } - if ( current_user_can( get_post_type_object( 'attachment' )->cap->read_private_posts ) ) + if ( current_user_can( get_post_type_object( 'attachment' )->cap->read_private_posts ) ) { $query['post_status'] .= ',private'; + } // Filter query clauses to include filenames. if ( isset( $query['s'] ) ) { @@ -2493,37 +2745,46 @@ function wp_ajax_query_attachments() { * @since 3.5.0 */ function wp_ajax_save_attachment() { - if ( ! isset( $_REQUEST['id'] ) || ! isset( $_REQUEST['changes'] ) ) + if ( ! isset( $_REQUEST['id'] ) || ! isset( $_REQUEST['changes'] ) ) { wp_send_json_error(); + } - if ( ! $id = absint( $_REQUEST['id'] ) ) + if ( ! $id = absint( $_REQUEST['id'] ) ) { wp_send_json_error(); + } check_ajax_referer( 'update-post_' . $id, 'nonce' ); - if ( ! current_user_can( 'edit_post', $id ) ) + if ( ! current_user_can( 'edit_post', $id ) ) { wp_send_json_error(); + } $changes = $_REQUEST['changes']; $post = get_post( $id, ARRAY_A ); - if ( 'attachment' != $post['post_type'] ) + if ( 'attachment' != $post['post_type'] ) { wp_send_json_error(); + } - if ( isset( $changes['parent'] ) ) + if ( isset( $changes['parent'] ) ) { $post['post_parent'] = $changes['parent']; + } - if ( isset( $changes['title'] ) ) + if ( isset( $changes['title'] ) ) { $post['post_title'] = $changes['title']; + } - if ( isset( $changes['caption'] ) ) + if ( isset( $changes['caption'] ) ) { $post['post_excerpt'] = $changes['caption']; + } - if ( isset( $changes['description'] ) ) + if ( isset( $changes['description'] ) ) { $post['post_content'] = $changes['description']; + } - if ( MEDIA_TRASH && isset( $changes['status'] ) ) + if ( MEDIA_TRASH && isset( $changes['status'] ) ) { $post['post_status'] = $changes['status']; + } if ( isset( $changes['alt'] ) ) { $alt = wp_unslash( $changes['alt'] ); @@ -2542,7 +2803,7 @@ function wp_ajax_save_attachment() { } foreach ( wp_get_attachment_id3_keys( (object) $post, 'edit' ) as $key => $label ) { if ( isset( $changes[ $key ] ) ) { - $changed = true; + $changed = true; $id3data[ $key ] = sanitize_text_field( wp_unslash( $changes[ $key ] ) ); } } @@ -2567,25 +2828,30 @@ function wp_ajax_save_attachment() { * @since 3.5.0 */ function wp_ajax_save_attachment_compat() { - if ( ! isset( $_REQUEST['id'] ) ) + if ( ! isset( $_REQUEST['id'] ) ) { wp_send_json_error(); + } - if ( ! $id = absint( $_REQUEST['id'] ) ) + if ( ! $id = absint( $_REQUEST['id'] ) ) { wp_send_json_error(); + } - if ( empty( $_REQUEST['attachments'] ) || empty( $_REQUEST['attachments'][ $id ] ) ) + if ( empty( $_REQUEST['attachments'] ) || empty( $_REQUEST['attachments'][ $id ] ) ) { wp_send_json_error(); + } $attachment_data = $_REQUEST['attachments'][ $id ]; check_ajax_referer( 'update-post_' . $id, 'nonce' ); - if ( ! current_user_can( 'edit_post', $id ) ) + if ( ! current_user_can( 'edit_post', $id ) ) { wp_send_json_error(); + } $post = get_post( $id, ARRAY_A ); - if ( 'attachment' != $post['post_type'] ) + if ( 'attachment' != $post['post_type'] ) { wp_send_json_error(); + } /** This filter is documented in wp-admin/includes/media.php */ $post = apply_filters( 'attachment_fields_to_save', $post, $attachment_data ); @@ -2598,12 +2864,14 @@ function wp_ajax_save_attachment_compat() { wp_update_post( $post ); foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) { - if ( isset( $attachment_data[ $taxonomy ] ) ) + if ( isset( $attachment_data[ $taxonomy ] ) ) { wp_set_object_terms( $id, array_map( 'trim', preg_split( '/,+/', $attachment_data[ $taxonomy ] ) ), $taxonomy, false ); + } } - if ( ! $attachment = wp_prepare_attachment_for_js( $id ) ) + if ( ! $attachment = wp_prepare_attachment_for_js( $id ) ) { wp_send_json_error(); + } wp_send_json_success( $attachment ); } @@ -2614,31 +2882,43 @@ function wp_ajax_save_attachment_compat() { * @since 3.5.0 */ function wp_ajax_save_attachment_order() { - if ( ! isset( $_REQUEST['post_id'] ) ) + if ( ! isset( $_REQUEST['post_id'] ) ) { wp_send_json_error(); + } - if ( ! $post_id = absint( $_REQUEST['post_id'] ) ) + if ( ! $post_id = absint( $_REQUEST['post_id'] ) ) { wp_send_json_error(); + } - if ( empty( $_REQUEST['attachments'] ) ) + if ( empty( $_REQUEST['attachments'] ) ) { wp_send_json_error(); + } check_ajax_referer( 'update-post_' . $post_id, 'nonce' ); $attachments = $_REQUEST['attachments']; - if ( ! current_user_can( 'edit_post', $post_id ) ) + if ( ! current_user_can( 'edit_post', $post_id ) ) { wp_send_json_error(); + } foreach ( $attachments as $attachment_id => $menu_order ) { - if ( ! current_user_can( 'edit_post', $attachment_id ) ) + if ( ! current_user_can( 'edit_post', $attachment_id ) ) { continue; - if ( ! $attachment = get_post( $attachment_id ) ) + } + if ( ! $attachment = get_post( $attachment_id ) ) { continue; - if ( 'attachment' != $attachment->post_type ) + } + if ( 'attachment' != $attachment->post_type ) { continue; + } - wp_update_post( array( 'ID' => $attachment_id, 'menu_order' => $menu_order ) ); + wp_update_post( + array( + 'ID' => $attachment_id, + 'menu_order' => $menu_order, + ) + ); } wp_send_json_success(); @@ -2660,28 +2940,35 @@ function wp_ajax_send_attachment_to_editor() { $id = intval( $attachment['id'] ); - if ( ! $post = get_post( $id ) ) + if ( ! $post = get_post( $id ) ) { wp_send_json_error(); + } - if ( 'attachment' != $post->post_type ) + if ( 'attachment' != $post->post_type ) { wp_send_json_error(); + } if ( current_user_can( 'edit_post', $id ) ) { // If this attachment is unattached, attach it. Primarily a back compat thing. if ( 0 == $post->post_parent && $insert_into_post_id = intval( $_POST['post_id'] ) ) { - wp_update_post( array( 'ID' => $id, 'post_parent' => $insert_into_post_id ) ); + wp_update_post( + array( + 'ID' => $id, + 'post_parent' => $insert_into_post_id, + ) + ); } } $url = empty( $attachment['url'] ) ? '' : $attachment['url']; - $rel = ( strpos( $url, 'attachment_id') || get_attachment_link( $id ) == $url ); + $rel = ( strpos( $url, 'attachment_id' ) || get_attachment_link( $id ) == $url ); remove_filter( 'media_send_to_editor', 'image_media_send_to_editor' ); if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) { $align = isset( $attachment['align'] ) ? $attachment['align'] : 'none'; - $size = isset( $attachment['image-size'] ) ? $attachment['image-size'] : 'medium'; - $alt = isset( $attachment['image_alt'] ) ? $attachment['image_alt'] : ''; + $size = isset( $attachment['image-size'] ) ? $attachment['image-size'] : 'medium'; + $alt = isset( $attachment['image_alt'] ) ? $attachment['image_alt'] : ''; // No whitespace-only captions. $caption = isset( $attachment['post_excerpt'] ) ? $attachment['post_excerpt'] : ''; @@ -2690,12 +2977,12 @@ function wp_ajax_send_attachment_to_editor() { } $title = ''; // We no longer insert title tags into tags, as they are redundant. - $html = get_image_send_to_editor( $id, $caption, $title, $align, $url, $rel, $size, $alt ); - } elseif ( wp_attachment_is( 'video', $post ) || wp_attachment_is( 'audio', $post ) ) { + $html = get_image_send_to_editor( $id, $caption, $title, $align, $url, $rel, $size, $alt ); + } elseif ( wp_attachment_is( 'video', $post ) || wp_attachment_is( 'audio', $post ) ) { $html = stripslashes_deep( $_POST['html'] ); } else { $html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : ''; - $rel = $rel ? ' rel="attachment wp-att-' . $id . '"' : ''; // Hard-coded string, $id is already sanitized + $rel = $rel ? ' rel="attachment wp-att-' . $id . '"' : ''; // Hard-coded string, $id is already sanitized if ( ! empty( $url ) ) { $html = '' . $html . ''; @@ -2728,22 +3015,26 @@ function wp_ajax_send_link_to_editor() { check_ajax_referer( 'media-send-to-editor', 'nonce' ); - if ( ! $src = wp_unslash( $_POST['src'] ) ) + if ( ! $src = wp_unslash( $_POST['src'] ) ) { wp_send_json_error(); + } - if ( ! strpos( $src, '://' ) ) + if ( ! strpos( $src, '://' ) ) { $src = 'http://' . $src; + } - if ( ! $src = esc_url_raw( $src ) ) + if ( ! $src = esc_url_raw( $src ) ) { wp_send_json_error(); + } - if ( ! $link_text = trim( wp_unslash( $_POST['link_text'] ) ) ) + if ( ! $link_text = trim( wp_unslash( $_POST['link_text'] ) ) ) { $link_text = wp_basename( $src ); + } $post = get_post( isset( $_POST['post_id'] ) ? $_POST['post_id'] : 0 ); // Ping WordPress for an embed. - $check_embed = $wp_embed->run_shortcode( '[embed]'. $src .'[/embed]' ); + $check_embed = $wp_embed->run_shortcode( '[embed]' . $src . '[/embed]' ); // Fallback that WordPress creates when no oEmbed was found. $fallback = $wp_embed->maybe_make_link( $src ); @@ -2760,8 +3051,9 @@ function wp_ajax_send_link_to_editor() { // Figure out what filter to run: $type = 'file'; if ( ( $ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src ) ) && ( $ext_type = wp_ext2type( $ext ) ) - && ( 'audio' == $ext_type || 'video' == $ext_type ) ) + && ( 'audio' == $ext_type || 'video' == $ext_type ) ) { $type = $ext_type; + } /** This filter is documented in wp-admin/includes/media.php */ $html = apply_filters( "{$type}_send_to_editor_url", $html, $src, $link_text ); @@ -2781,12 +3073,12 @@ function wp_ajax_heartbeat() { wp_send_json_error(); } - $response = $data = array(); + $response = $data = array(); $nonce_state = wp_verify_nonce( $_POST['_nonce'], 'heartbeat-nonce' ); // screen_id is the same as $current_screen->id and the JS global 'pagenow'. if ( ! empty( $_POST['screen_id'] ) ) { - $screen_id = sanitize_key($_POST['screen_id']); + $screen_id = sanitize_key( $_POST['screen_id'] ); } else { $screen_id = 'front'; } @@ -2854,15 +3146,18 @@ function wp_ajax_heartbeat() { function wp_ajax_get_revision_diffs() { require ABSPATH . 'wp-admin/includes/revision.php'; - if ( ! $post = get_post( (int) $_REQUEST['post_id'] ) ) + if ( ! $post = get_post( (int) $_REQUEST['post_id'] ) ) { wp_send_json_error(); + } - if ( ! current_user_can( 'edit_post', $post->ID ) ) + if ( ! current_user_can( 'edit_post', $post->ID ) ) { wp_send_json_error(); + } // Really just pre-loading the cache here. - if ( ! $revisions = wp_get_post_revisions( $post->ID, array( 'check_enabled' => false ) ) ) + if ( ! $revisions = wp_get_post_revisions( $post->ID, array( 'check_enabled' => false ) ) ) { wp_send_json_error(); + } $return = array(); @set_time_limit( 0 ); @@ -2871,7 +3166,7 @@ function wp_ajax_get_revision_diffs() { list( $compare_from, $compare_to ) = explode( ':', $compare_key ); // from:to $return[] = array( - 'id' => $compare_key, + 'id' => $compare_key, 'fields' => wp_get_revision_ui_diff( $post, $compare_from, $compare_to ), ); } @@ -2900,10 +3195,12 @@ function wp_ajax_save_user_color_scheme() { $previous_color_scheme = get_user_meta( get_current_user_id(), 'admin_color', true ); update_user_meta( get_current_user_id(), 'admin_color', $color_scheme ); - wp_send_json_success( array( - 'previousScheme' => 'admin-color-' . $previous_color_scheme, - 'currentScheme' => 'admin-color-' . $color_scheme - ) ); + wp_send_json_success( + array( + 'previousScheme' => 'admin-color-' . $previous_color_scheme, + 'currentScheme' => 'admin-color-' . $color_scheme, + ) + ); } /** @@ -2921,10 +3218,12 @@ function wp_ajax_query_themes() { wp_send_json_error(); } - $args = wp_parse_args( wp_unslash( $_REQUEST['request'] ), array( - 'per_page' => 20, - 'fields' => $theme_field_defaults - ) ); + $args = wp_parse_args( + wp_unslash( $_REQUEST['request'] ), array( + 'per_page' => 20, + 'fields' => $theme_field_defaults, + ) + ); if ( isset( $args['browse'] ) && 'favorites' === $args['browse'] && ! isset( $args['user'] ) ) { $user = get_user_option( 'wporg_favorites' ); @@ -2946,38 +3245,53 @@ function wp_ajax_query_themes() { $update_php = network_admin_url( 'update.php?action=install-theme' ); foreach ( $api->themes as &$theme ) { - $theme->install_url = add_query_arg( array( - 'theme' => $theme->slug, - '_wpnonce' => wp_create_nonce( 'install-theme_' . $theme->slug ) - ), $update_php ); + $theme->install_url = add_query_arg( + array( + 'theme' => $theme->slug, + '_wpnonce' => wp_create_nonce( 'install-theme_' . $theme->slug ), + ), $update_php + ); if ( current_user_can( 'switch_themes' ) ) { if ( is_multisite() ) { - $theme->activate_url = add_query_arg( array( - 'action' => 'enable', - '_wpnonce' => wp_create_nonce( 'enable-theme_' . $theme->slug ), - 'theme' => $theme->slug, - ), network_admin_url( 'themes.php' ) ); + $theme->activate_url = add_query_arg( + array( + 'action' => 'enable', + '_wpnonce' => wp_create_nonce( 'enable-theme_' . $theme->slug ), + 'theme' => $theme->slug, + ), network_admin_url( 'themes.php' ) + ); } else { - $theme->activate_url = add_query_arg( array( - 'action' => 'activate', - '_wpnonce' => wp_create_nonce( 'switch-theme_' . $theme->slug ), - 'stylesheet' => $theme->slug, - ), admin_url( 'themes.php' ) ); + $theme->activate_url = add_query_arg( + array( + 'action' => 'activate', + '_wpnonce' => wp_create_nonce( 'switch-theme_' . $theme->slug ), + 'stylesheet' => $theme->slug, + ), admin_url( 'themes.php' ) + ); } } if ( ! is_multisite() && current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { - $theme->customize_url = add_query_arg( array( - 'return' => urlencode( network_admin_url( 'theme-install.php', 'relative' ) ), - ), wp_customize_url( $theme->slug ) ); + $theme->customize_url = add_query_arg( + array( + 'return' => urlencode( network_admin_url( 'theme-install.php', 'relative' ) ), + ), wp_customize_url( $theme->slug ) + ); } $theme->name = wp_kses( $theme->name, $themes_allowedtags ); $theme->author = wp_kses( $theme->author, $themes_allowedtags ); $theme->version = wp_kses( $theme->version, $themes_allowedtags ); $theme->description = wp_kses( $theme->description, $themes_allowedtags ); - $theme->stars = wp_star_rating( array( 'rating' => $theme->rating, 'type' => 'percent', 'number' => $theme->num_ratings, 'echo' => false ) ); + $theme->stars = wp_star_rating( + array( + 'rating' => $theme->rating, + 'type' => 'percent', + 'number' => $theme->num_ratings, + 'echo' => false, + ) + ); $theme->num_ratings = number_format_i18n( $theme->num_ratings ); $theme->preview_url = set_url_scheme( $theme->preview_url ); } @@ -3001,7 +3315,7 @@ function wp_ajax_parse_embed() { if ( empty( $_POST['shortcode'] ) ) { wp_send_json_error(); } - $post_id = isset( $_POST[ 'post_ID' ] ) ? intval( $_POST[ 'post_ID' ] ) : 0; + $post_id = isset( $_POST['post_ID'] ) ? intval( $_POST['post_ID'] ) : 0; if ( $post_id > 0 ) { $post = get_post( $post_id ); if ( ! $post || ! current_user_can( 'edit_post', $post->ID ) ) { @@ -3024,7 +3338,7 @@ function wp_ajax_parse_embed() { $url = ''; } - $parsed = false; + $parsed = false; $wp_embed->return_false_on_fail = true; if ( 0 === $post_id ) { @@ -3040,7 +3354,7 @@ function wp_ajax_parse_embed() { // Admin is ssl and the user pasted non-ssl URL. // Check if the provider supports ssl embeds and use that for the preview. $ssl_shortcode = preg_replace( '%^(\\[embed[^\\]]*\\])http://%i', '$1https://', $shortcode ); - $parsed = $wp_embed->run_shortcode( $ssl_shortcode ); + $parsed = $wp_embed->run_shortcode( $ssl_shortcode ); if ( ! $parsed ) { $no_ssl_support = true; @@ -3061,14 +3375,16 @@ function wp_ajax_parse_embed() { } if ( ! $parsed ) { - wp_send_json_error( array( - 'type' => 'not-embeddable', - 'message' => sprintf( __( '%s failed to embed.' ), '' . esc_html( $url ) . '' ), - ) ); + wp_send_json_error( + array( + 'type' => 'not-embeddable', + 'message' => sprintf( __( '%s failed to embed.' ), '' . esc_html( $url ) . '' ), + ) + ); } if ( has_shortcode( $parsed, 'audio' ) || has_shortcode( $parsed, 'video' ) ) { - $styles = ''; + $styles = ''; $mce_styles = wpview_media_sandbox_styles(); foreach ( $mce_styles as $style ) { $styles .= sprintf( '', $style ); @@ -3090,15 +3406,17 @@ function wp_ajax_parse_embed() { if ( ! empty( $no_ssl_support ) || ( is_ssl() && ( preg_match( '%<(iframe|script|embed) [^>]*src="http://%', $parsed ) || preg_match( '%]*href="http://%', $parsed ) ) ) ) { // Admin is ssl and the embed is not. Iframes, scripts, and other "active content" will be blocked. - wp_send_json_error( array( - 'type' => 'not-ssl', - 'message' => __( 'This preview is unavailable in the editor.' ), - ) ); + wp_send_json_error( + array( + 'type' => 'not-ssl', + 'message' => __( 'This preview is unavailable in the editor.' ), + ) + ); } $return = array( 'body' => $parsed, - 'attr' => $wp_embed->last_attr + 'attr' => $wp_embed->last_attr, ); if ( strpos( $parsed, 'class="wp-embedded-content' ) ) { @@ -3108,7 +3426,7 @@ function wp_ajax_parse_embed() { $script_src = includes_url( 'js/wp-embed.min.js' ); } - $return['head'] = ''; + $return['head'] = ''; $return['sandbox'] = true; } @@ -3143,16 +3461,18 @@ function wp_ajax_parse_media_shortcode() { setup_postdata( $post ); } - $parsed = do_shortcode( $shortcode ); + $parsed = do_shortcode( $shortcode ); if ( empty( $parsed ) ) { - wp_send_json_error( array( - 'type' => 'no-items', - 'message' => __( 'No items found.' ), - ) ); + wp_send_json_error( + array( + 'type' => 'no-items', + 'message' => __( 'No items found.' ), + ) + ); } - $head = ''; + $head = ''; $styles = wpview_media_sandbox_styles(); foreach ( $styles as $style ) { @@ -3175,10 +3495,12 @@ function wp_ajax_parse_media_shortcode() { wp_print_scripts( array( 'mediaelement-vimeo', 'wp-mediaelement' ) ); } - wp_send_json_success( array( - 'head' => $head, - 'body' => ob_get_clean() - ) ); + wp_send_json_success( + array( + 'head' => $head, + 'body' => ob_get_clean(), + ) + ); } /** @@ -3197,9 +3519,11 @@ function wp_ajax_destroy_sessions() { } if ( ! $user ) { - wp_send_json_error( array( - 'message' => __( 'Could not log out user sessions. Please try again.' ), - ) ); + wp_send_json_error( + array( + 'message' => __( 'Could not log out user sessions. Please try again.' ), + ) + ); } $sessions = WP_Session_Tokens::get_instance( $user->ID ); @@ -3268,7 +3592,6 @@ function wp_ajax_crop_image() { break; default: - /** * Fires before a cropped image is saved. * @@ -3300,7 +3623,7 @@ function wp_ajax_crop_image() { ); $attachment_id = wp_insert_attachment( $object, $cropped ); - $metadata = wp_generate_attachment_metadata( $attachment_id, $cropped ); + $metadata = wp_generate_attachment_metadata( $attachment_id, $cropped ); /** * Filters the cropped image attachment metadata. @@ -3371,11 +3694,13 @@ function wp_ajax_install_theme() { check_ajax_referer( 'updates' ); if ( empty( $_POST['slug'] ) ) { - wp_send_json_error( array( - 'slug' => '', - 'errorCode' => 'no_theme_specified', - 'errorMessage' => __( 'No theme specified.' ), - ) ); + wp_send_json_error( + array( + 'slug' => '', + 'errorCode' => 'no_theme_specified', + 'errorMessage' => __( 'No theme specified.' ), + ) + ); } $slug = sanitize_key( wp_unslash( $_POST['slug'] ) ); @@ -3393,10 +3718,12 @@ function wp_ajax_install_theme() { include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); include_once( ABSPATH . 'wp-admin/includes/theme.php' ); - $api = themes_api( 'theme_information', array( - 'slug' => $slug, - 'fields' => array( 'sections' => false ), - ) ); + $api = themes_api( + 'theme_information', array( + 'slug' => $slug, + 'fields' => array( 'sections' => false ), + ) + ); if ( is_wp_error( $api ) ) { $status['errorMessage'] = $api->get_error_message(); @@ -3440,24 +3767,30 @@ function wp_ajax_install_theme() { if ( current_user_can( 'switch_themes' ) ) { if ( is_multisite() ) { - $status['activateUrl'] = add_query_arg( array( - 'action' => 'enable', - '_wpnonce' => wp_create_nonce( 'enable-theme_' . $slug ), - 'theme' => $slug, - ), network_admin_url( 'themes.php' ) ); + $status['activateUrl'] = add_query_arg( + array( + 'action' => 'enable', + '_wpnonce' => wp_create_nonce( 'enable-theme_' . $slug ), + 'theme' => $slug, + ), network_admin_url( 'themes.php' ) + ); } else { - $status['activateUrl'] = add_query_arg( array( - 'action' => 'activate', - '_wpnonce' => wp_create_nonce( 'switch-theme_' . $slug ), - 'stylesheet' => $slug, - ), admin_url( 'themes.php' ) ); + $status['activateUrl'] = add_query_arg( + array( + 'action' => 'activate', + '_wpnonce' => wp_create_nonce( 'switch-theme_' . $slug ), + 'stylesheet' => $slug, + ), admin_url( 'themes.php' ) + ); } } if ( ! is_multisite() && current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { - $status['customizeUrl'] = add_query_arg( array( - 'return' => urlencode( network_admin_url( 'theme-install.php', 'relative' ) ), - ), wp_customize_url( $slug ) ); + $status['customizeUrl'] = add_query_arg( + array( + 'return' => urlencode( network_admin_url( 'theme-install.php', 'relative' ) ), + ), wp_customize_url( $slug ) + ); } /* @@ -3480,11 +3813,13 @@ function wp_ajax_update_theme() { check_ajax_referer( 'updates' ); if ( empty( $_POST['slug'] ) ) { - wp_send_json_error( array( - 'slug' => '', - 'errorCode' => 'no_theme_specified', - 'errorMessage' => __( 'No theme specified.' ), - ) ); + wp_send_json_error( + array( + 'slug' => '', + 'errorCode' => 'no_theme_specified', + 'errorMessage' => __( 'No theme specified.' ), + ) + ); } $stylesheet = preg_replace( '/[^A-z0-9_\-]/', '', wp_unslash( $_POST['slug'] ) ); @@ -3573,11 +3908,13 @@ function wp_ajax_delete_theme() { check_ajax_referer( 'updates' ); if ( empty( $_POST['slug'] ) ) { - wp_send_json_error( array( - 'slug' => '', - 'errorCode' => 'no_theme_specified', - 'errorMessage' => __( 'No theme specified.' ), - ) ); + wp_send_json_error( + array( + 'slug' => '', + 'errorCode' => 'no_theme_specified', + 'errorMessage' => __( 'No theme specified.' ), + ) + ); } $stylesheet = preg_replace( '/[^A-z0-9_\-]/', '', wp_unslash( $_POST['slug'] ) ); @@ -3643,11 +3980,13 @@ function wp_ajax_install_plugin() { check_ajax_referer( 'updates' ); if ( empty( $_POST['slug'] ) ) { - wp_send_json_error( array( - 'slug' => '', - 'errorCode' => 'no_plugin_specified', - 'errorMessage' => __( 'No plugin specified.' ), - ) ); + wp_send_json_error( + array( + 'slug' => '', + 'errorCode' => 'no_plugin_specified', + 'errorMessage' => __( 'No plugin specified.' ), + ) + ); } $status = array( @@ -3663,12 +4002,14 @@ function wp_ajax_install_plugin() { include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); - $api = plugins_api( 'plugin_information', array( - 'slug' => sanitize_key( wp_unslash( $_POST['slug'] ) ), - 'fields' => array( - 'sections' => false, - ), - ) ); + $api = plugins_api( + 'plugin_information', array( + 'slug' => sanitize_key( wp_unslash( $_POST['slug'] ) ), + 'fields' => array( + 'sections' => false, + ), + ) + ); if ( is_wp_error( $api ) ) { $status['errorMessage'] = $api->get_error_message(); @@ -3711,17 +4052,19 @@ function wp_ajax_install_plugin() { } $install_status = install_plugin_install_status( $api ); - $pagenow = isset( $_POST['pagenow'] ) ? sanitize_key( $_POST['pagenow'] ) : ''; + $pagenow = isset( $_POST['pagenow'] ) ? sanitize_key( $_POST['pagenow'] ) : ''; // If installation request is coming from import page, do not return network activation link. $plugins_url = ( 'import' === $pagenow ) ? admin_url( 'plugins.php' ) : network_admin_url( 'plugins.php' ); if ( current_user_can( 'activate_plugin', $install_status['file'] ) && is_plugin_inactive( $install_status['file'] ) ) { - $status['activateUrl'] = add_query_arg( array( - '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $install_status['file'] ), - 'action' => 'activate', - 'plugin' => $install_status['file'], - ), $plugins_url ); + $status['activateUrl'] = add_query_arg( + array( + '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $install_status['file'] ), + 'action' => 'activate', + 'plugin' => $install_status['file'], + ), $plugins_url + ); } if ( is_multisite() && current_user_can( 'manage_network_plugins' ) && 'import' !== $pagenow ) { @@ -3744,11 +4087,13 @@ function wp_ajax_update_plugin() { check_ajax_referer( 'updates' ); if ( empty( $_POST['plugin'] ) || empty( $_POST['slug'] ) ) { - wp_send_json_error( array( - 'slug' => '', - 'errorCode' => 'no_plugin_specified', - 'errorMessage' => __( 'No plugin specified.' ), - ) ); + wp_send_json_error( + array( + 'slug' => '', + 'errorCode' => 'no_plugin_specified', + 'errorMessage' => __( 'No plugin specified.' ), + ) + ); } $plugin = plugin_basename( sanitize_text_field( wp_unslash( $_POST['plugin'] ) ) ); @@ -3849,11 +4194,13 @@ function wp_ajax_delete_plugin() { check_ajax_referer( 'updates' ); if ( empty( $_POST['slug'] ) || empty( $_POST['plugin'] ) ) { - wp_send_json_error( array( - 'slug' => '', - 'errorCode' => 'no_plugin_specified', - 'errorMessage' => __( 'No plugin specified.' ), - ) ); + wp_send_json_error( + array( + 'slug' => '', + 'errorCode' => 'no_plugin_specified', + 'errorMessage' => __( 'No plugin specified.' ), + ) + ); } $plugin = plugin_basename( sanitize_text_field( wp_unslash( $_POST['plugin'] ) ) ); @@ -3925,9 +4272,11 @@ function wp_ajax_search_plugins() { } /** @var WP_Plugins_List_Table $wp_list_table */ - $wp_list_table = _get_list_table( 'WP_Plugins_List_Table', array( - 'screen' => get_current_screen(), - ) ); + $wp_list_table = _get_list_table( + 'WP_Plugins_List_Table', array( + 'screen' => get_current_screen(), + ) + ); $status = array(); @@ -3937,10 +4286,14 @@ function wp_ajax_search_plugins() { } // Set the correct requester, so pagination works. - $_SERVER['REQUEST_URI'] = add_query_arg( array_diff_key( $_POST, array( - '_ajax_nonce' => null, - 'action' => null, - ) ), network_admin_url( 'plugins.php', 'relative' ) ); + $_SERVER['REQUEST_URI'] = add_query_arg( + array_diff_key( + $_POST, array( + '_ajax_nonce' => null, + 'action' => null, + ) + ), network_admin_url( 'plugins.php', 'relative' ) + ); $GLOBALS['s'] = wp_unslash( $_POST['s'] ); @@ -3968,9 +4321,11 @@ function wp_ajax_search_install_plugins() { } /** @var WP_Plugin_Install_List_Table $wp_list_table */ - $wp_list_table = _get_list_table( 'WP_Plugin_Install_List_Table', array( - 'screen' => get_current_screen(), - ) ); + $wp_list_table = _get_list_table( + 'WP_Plugin_Install_List_Table', array( + 'screen' => get_current_screen(), + ) + ); $status = array(); @@ -3980,10 +4335,14 @@ function wp_ajax_search_install_plugins() { } // Set the correct requester, so pagination works. - $_SERVER['REQUEST_URI'] = add_query_arg( array_diff_key( $_POST, array( - '_ajax_nonce' => null, - 'action' => null, - ) ), network_admin_url( 'plugin-install.php', 'relative' ) ); + $_SERVER['REQUEST_URI'] = add_query_arg( + array_diff_key( + $_POST, array( + '_ajax_nonce' => null, + 'action' => null, + ) + ), network_admin_url( 'plugin-install.php', 'relative' ) + ); $wp_list_table->prepare_items(); @@ -4004,16 +4363,20 @@ function wp_ajax_search_install_plugins() { function wp_ajax_edit_theme_plugin_file() { $r = wp_edit_theme_plugin_file( wp_unslash( $_POST ) ); // Validation of args is done in wp_edit_theme_plugin_file(). if ( is_wp_error( $r ) ) { - wp_send_json_error( array_merge( - array( - 'code' => $r->get_error_code(), - 'message' => $r->get_error_message(), - ), - (array) $r->get_error_data() - ) ); + wp_send_json_error( + array_merge( + array( + 'code' => $r->get_error_code(), + 'message' => $r->get_error_message(), + ), + (array) $r->get_error_data() + ) + ); } else { - wp_send_json_success( array( - 'message' => __( 'File edited successfully.' ), - ) ); + wp_send_json_success( + array( + 'message' => __( 'File edited successfully.' ), + ) + ); } } diff --git a/wp-admin/includes/bookmark.php b/wp-admin/includes/bookmark.php index 0f7365ee24..285d716c2a 100644 --- a/wp-admin/includes/bookmark.php +++ b/wp-admin/includes/bookmark.php @@ -34,15 +34,16 @@ function edit_link( $link_id = 0 ) { ); } - $_POST['link_url'] = esc_html( $_POST['link_url'] ); - $_POST['link_url'] = esc_url($_POST['link_url']); - $_POST['link_name'] = esc_html( $_POST['link_name'] ); + $_POST['link_url'] = esc_html( $_POST['link_url'] ); + $_POST['link_url'] = esc_url( $_POST['link_url'] ); + $_POST['link_name'] = esc_html( $_POST['link_name'] ); $_POST['link_image'] = esc_html( $_POST['link_image'] ); - $_POST['link_rss'] = esc_url($_POST['link_rss']); - if ( !isset($_POST['link_visible']) || 'N' != $_POST['link_visible'] ) + $_POST['link_rss'] = esc_url( $_POST['link_rss'] ); + if ( ! isset( $_POST['link_visible'] ) || 'N' != $_POST['link_visible'] ) { $_POST['link_visible'] = 'Y'; + } - if ( !empty( $link_id ) ) { + if ( ! empty( $link_id ) ) { $_POST['link_id'] = $link_id; return wp_update_link( $_POST ); } else { @@ -59,15 +60,17 @@ function edit_link( $link_id = 0 ) { */ function get_default_link_to_edit() { $link = new stdClass; - if ( isset( $_GET['linkurl'] ) ) + if ( isset( $_GET['linkurl'] ) ) { $link->link_url = esc_url( wp_unslash( $_GET['linkurl'] ) ); - else + } else { $link->link_url = ''; + } - if ( isset( $_GET['name'] ) ) + if ( isset( $_GET['name'] ) ) { $link->link_name = esc_attr( wp_unslash( $_GET['name'] ) ); - else + } else { $link->link_name = ''; + } $link->link_visible = 'Y'; @@ -122,7 +125,7 @@ function wp_delete_link( $link_id ) { * @return array The requested link's categories */ function wp_get_link_cats( $link_id = 0 ) { - $cats = wp_get_object_terms( $link_id, 'link_category', array('fields' => 'ids') ); + $cats = wp_get_object_terms( $link_id, 'link_category', array( 'fields' => 'ids' ) ); return array_unique( $cats ); } @@ -152,10 +155,15 @@ function get_link_to_edit( $link ) { function wp_insert_link( $linkdata, $wp_error = false ) { global $wpdb; - $defaults = array( 'link_id' => 0, 'link_name' => '', 'link_url' => '', 'link_rating' => 0 ); + $defaults = array( + 'link_id' => 0, + 'link_name' => '', + 'link_url' => '', + 'link_rating' => 0, + ); $args = wp_parse_args( $linkdata, $defaults ); - $r = wp_unslash( sanitize_bookmark( $args, 'db' ) ); + $r = wp_unslash( sanitize_bookmark( $args, 'db' ) ); $link_id = $r['link_id']; $link_name = $r['link_name']; @@ -249,8 +257,9 @@ function wp_insert_link( $linkdata, $wp_error = false ) { */ function wp_set_link_cats( $link_id = 0, $link_categories = array() ) { // If $link_categories isn't already an array, make it one: - if ( !is_array( $link_categories ) || 0 == count( $link_categories ) ) + if ( ! is_array( $link_categories ) || 0 == count( $link_categories ) ) { $link_categories = array( get_option( 'default_link_category' ) ); + } $link_categories = array_map( 'intval', $link_categories ); $link_categories = array_unique( $link_categories ); @@ -277,13 +286,14 @@ function wp_update_link( $linkdata ) { $link = wp_slash( $link ); // Passed link category list overwrites existing category list if not empty. - if ( isset( $linkdata['link_category'] ) && is_array( $linkdata['link_category'] ) && 0 != count( $linkdata['link_category'] ) ) + if ( isset( $linkdata['link_category'] ) && is_array( $linkdata['link_category'] ) && 0 != count( $linkdata['link_category'] ) ) { $link_cats = $linkdata['link_category']; - else + } else { $link_cats = $link['link_category']; + } // Merge old and new fields with new fields overwriting old ones. - $linkdata = array_merge( $link, $linkdata ); + $linkdata = array_merge( $link, $linkdata ); $linkdata['link_category'] = $link_cats; return wp_insert_link( $linkdata ); @@ -299,8 +309,9 @@ function wp_update_link( $linkdata ) { */ function wp_link_manager_disabled_message() { global $pagenow; - if ( 'link-manager.php' != $pagenow && 'link-add.php' != $pagenow && 'link.php' != $pagenow ) + if ( 'link-manager.php' != $pagenow && 'link-add.php' != $pagenow && 'link.php' != $pagenow ) { return; + } add_filter( 'pre_option_link_manager_enabled', '__return_true', 100 ); $really_can_manage_links = current_user_can( 'manage_links' ); diff --git a/wp-admin/includes/class-automatic-upgrader-skin.php b/wp-admin/includes/class-automatic-upgrader-skin.php index dd37da96db..571068d691 100644 --- a/wp-admin/includes/class-automatic-upgrader-skin.php +++ b/wp-admin/includes/class-automatic-upgrader-skin.php @@ -50,7 +50,6 @@ class Automatic_Upgrader_Skin extends WP_Upgrader_Skin { } /** - * * @return array */ public function get_upgrade_messages() { @@ -58,7 +57,6 @@ class Automatic_Upgrader_Skin extends WP_Upgrader_Skin { } /** - * * @param string|array|WP_Error $data */ public function feedback( $data ) { @@ -69,30 +67,35 @@ class Automatic_Upgrader_Skin extends WP_Upgrader_Skin { } else { $string = $data; } - if ( ! empty( $this->upgrader->strings[ $string ] ) ) + if ( ! empty( $this->upgrader->strings[ $string ] ) ) { $string = $this->upgrader->strings[ $string ]; + } if ( strpos( $string, '%' ) !== false ) { $args = func_get_args(); $args = array_splice( $args, 1 ); - if ( ! empty( $args ) ) + if ( ! empty( $args ) ) { $string = vsprintf( $string, $args ); + } } $string = trim( $string ); // Only allow basic HTML in the messages, as it'll be used in emails/logs rather than direct browser output. - $string = wp_kses( $string, array( - 'a' => array( - 'href' => true - ), - 'br' => true, - 'em' => true, - 'strong' => true, - ) ); + $string = wp_kses( + $string, array( + 'a' => array( + 'href' => true, + ), + 'br' => true, + 'em' => true, + 'strong' => true, + ) + ); - if ( empty( $string ) ) + if ( empty( $string ) ) { return; + } $this->messages[] = $string; } @@ -107,7 +110,8 @@ class Automatic_Upgrader_Skin extends WP_Upgrader_Skin { */ public function footer() { $output = ob_get_clean(); - if ( ! empty( $output ) ) + if ( ! empty( $output ) ) { $this->feedback( $output ); + } } } diff --git a/wp-admin/includes/class-bulk-plugin-upgrader-skin.php b/wp-admin/includes/class-bulk-plugin-upgrader-skin.php index 34dcbd441f..bb85e88be2 100644 --- a/wp-admin/includes/class-bulk-plugin-upgrader-skin.php +++ b/wp-admin/includes/class-bulk-plugin-upgrader-skin.php @@ -20,23 +20,21 @@ class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin { public function add_strings() { parent::add_strings(); - $this->upgrader->strings['skin_before_update_header'] = __('Updating Plugin %1$s (%2$d/%3$d)'); + $this->upgrader->strings['skin_before_update_header'] = __( 'Updating Plugin %1$s (%2$d/%3$d)' ); } /** - * * @param string $title */ - public function before($title = '') { - parent::before($this->plugin_info['Title']); + public function before( $title = '' ) { + parent::before( $this->plugin_info['Title'] ); } /** - * * @param string $title */ - public function after($title = '') { - parent::after($this->plugin_info['Title']); + public function after( $title = '' ) { + parent::after( $this->plugin_info['Title'] ); $this->decrement_update_count( 'plugin' ); } @@ -44,12 +42,13 @@ class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin { */ public function bulk_footer() { parent::bulk_footer(); - $update_actions = array( + $update_actions = array( 'plugins_page' => '' . __( 'Return to Plugins page' ) . '', - 'updates_page' => '' . __( 'Return to WordPress Updates page' ) . '' + 'updates_page' => '' . __( 'Return to WordPress Updates page' ) . '', ); - if ( ! current_user_can( 'activate_plugins' ) ) + if ( ! current_user_can( 'activate_plugins' ) ) { unset( $update_actions['plugins_page'] ); + } /** * Filters the list of action links available following bulk plugin updates. @@ -61,7 +60,8 @@ class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin { */ $update_actions = apply_filters( 'update_bulk_plugins_complete_actions', $update_actions, $this->plugin_info ); - if ( ! empty($update_actions) ) - $this->feedback(implode(' | ', (array)$update_actions)); + if ( ! empty( $update_actions ) ) { + $this->feedback( implode( ' | ', (array) $update_actions ) ); + } } } diff --git a/wp-admin/includes/class-bulk-theme-upgrader-skin.php b/wp-admin/includes/class-bulk-theme-upgrader-skin.php index 85ee6f2e54..8f01c314a3 100644 --- a/wp-admin/includes/class-bulk-theme-upgrader-skin.php +++ b/wp-admin/includes/class-bulk-theme-upgrader-skin.php @@ -20,23 +20,21 @@ class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin { public function add_strings() { parent::add_strings(); - $this->upgrader->strings['skin_before_update_header'] = __('Updating Theme %1$s (%2$d/%3$d)'); + $this->upgrader->strings['skin_before_update_header'] = __( 'Updating Theme %1$s (%2$d/%3$d)' ); } /** - * * @param string $title */ - public function before($title = '') { - parent::before( $this->theme_info->display('Name') ); + public function before( $title = '' ) { + parent::before( $this->theme_info->display( 'Name' ) ); } /** - * * @param string $title */ - public function after($title = '') { - parent::after( $this->theme_info->display('Name') ); + public function after( $title = '' ) { + parent::after( $this->theme_info->display( 'Name' ) ); $this->decrement_update_count( 'theme' ); } @@ -44,12 +42,13 @@ class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin { */ public function bulk_footer() { parent::bulk_footer(); - $update_actions = array( - 'themes_page' => '' . __( 'Return to Themes page' ) . '', - 'updates_page' => '' . __( 'Return to WordPress Updates page' ) . '' + $update_actions = array( + 'themes_page' => '' . __( 'Return to Themes page' ) . '', + 'updates_page' => '' . __( 'Return to WordPress Updates page' ) . '', ); - if ( ! current_user_can( 'switch_themes' ) && ! current_user_can( 'edit_theme_options' ) ) + if ( ! current_user_can( 'switch_themes' ) && ! current_user_can( 'edit_theme_options' ) ) { unset( $update_actions['themes_page'] ); + } /** * Filters the list of action links available following bulk theme updates. @@ -61,7 +60,8 @@ class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin { */ $update_actions = apply_filters( 'update_bulk_theme_complete_actions', $update_actions, $this->theme_info ); - if ( ! empty($update_actions) ) - $this->feedback(implode(' | ', (array)$update_actions)); + if ( ! empty( $update_actions ) ) { + $this->feedback( implode( ' | ', (array) $update_actions ) ); + } } } diff --git a/wp-admin/includes/class-bulk-upgrader-skin.php b/wp-admin/includes/class-bulk-upgrader-skin.php index 6541de925b..2b2ebd00d5 100644 --- a/wp-admin/includes/class-bulk-upgrader-skin.php +++ b/wp-admin/includes/class-bulk-upgrader-skin.php @@ -23,52 +23,56 @@ class Bulk_Upgrader_Skin extends WP_Upgrader_Skin { public $error = false; /** - * * @param array $args */ - public function __construct($args = array()) { - $defaults = array( 'url' => '', 'nonce' => '' ); - $args = wp_parse_args($args, $defaults); + public function __construct( $args = array() ) { + $defaults = array( + 'url' => '', + 'nonce' => '', + ); + $args = wp_parse_args( $args, $defaults ); - parent::__construct($args); + parent::__construct( $args ); } /** */ public function add_strings() { - $this->upgrader->strings['skin_upgrade_start'] = __('The update process is starting. This process may take a while on some hosts, so please be patient.'); + $this->upgrader->strings['skin_upgrade_start'] = __( 'The update process is starting. This process may take a while on some hosts, so please be patient.' ); /* translators: 1: Title of an update, 2: Error message */ - $this->upgrader->strings['skin_update_failed_error'] = __('An error occurred while updating %1$s: %2$s'); + $this->upgrader->strings['skin_update_failed_error'] = __( 'An error occurred while updating %1$s: %2$s' ); /* translators: 1: Title of an update */ - $this->upgrader->strings['skin_update_failed'] = __('The update of %1$s failed.'); + $this->upgrader->strings['skin_update_failed'] = __( 'The update of %1$s failed.' ); /* translators: 1: Title of an update */ $this->upgrader->strings['skin_update_successful'] = __( '%1$s updated successfully.' ); - $this->upgrader->strings['skin_upgrade_end'] = __('All updates have been completed.'); + $this->upgrader->strings['skin_upgrade_end'] = __( 'All updates have been completed.' ); } /** - * * @param string $string */ - public function feedback($string) { - if ( isset( $this->upgrader->strings[$string] ) ) - $string = $this->upgrader->strings[$string]; + public function feedback( $string ) { + if ( isset( $this->upgrader->strings[ $string ] ) ) { + $string = $this->upgrader->strings[ $string ]; + } - if ( strpos($string, '%') !== false ) { + if ( strpos( $string, '%' ) !== false ) { $args = func_get_args(); - $args = array_splice($args, 1); + $args = array_splice( $args, 1 ); if ( $args ) { - $args = array_map( 'strip_tags', $args ); - $args = array_map( 'esc_html', $args ); - $string = vsprintf($string, $args); + $args = array_map( 'strip_tags', $args ); + $args = array_map( 'esc_html', $args ); + $string = vsprintf( $string, $args ); } } - if ( empty($string) ) + if ( empty( $string ) ) { return; - if ( $this->in_loop ) + } + if ( $this->in_loop ) { echo "$string
\n"; - else + } else { echo "

$string

\n"; + } } /** @@ -84,65 +88,64 @@ class Bulk_Upgrader_Skin extends WP_Upgrader_Skin { } /** - * * @param string|WP_Error $error */ - public function error($error) { - if ( is_string($error) && isset( $this->upgrader->strings[$error] ) ) - $this->error = $this->upgrader->strings[$error]; + public function error( $error ) { + if ( is_string( $error ) && isset( $this->upgrader->strings[ $error ] ) ) { + $this->error = $this->upgrader->strings[ $error ]; + } - if ( is_wp_error($error) ) { + if ( is_wp_error( $error ) ) { $messages = array(); foreach ( $error->get_error_messages() as $emessage ) { - if ( $error->get_error_data() && is_string( $error->get_error_data() ) ) + if ( $error->get_error_data() && is_string( $error->get_error_data() ) ) { $messages[] = $emessage . ' ' . esc_html( strip_tags( $error->get_error_data() ) ); - else + } else { $messages[] = $emessage; + } } - $this->error = implode(', ', $messages); + $this->error = implode( ', ', $messages ); } - echo ''; + echo ''; } /** */ public function bulk_header() { - $this->feedback('skin_upgrade_start'); + $this->feedback( 'skin_upgrade_start' ); } /** */ public function bulk_footer() { - $this->feedback('skin_upgrade_end'); + $this->feedback( 'skin_upgrade_end' ); } /** - * * @param string $title */ - public function before($title = '') { + public function before( $title = '' ) { $this->in_loop = true; printf( '

' . $this->upgrader->strings['skin_before_update_header'] . '

', $title, $this->upgrader->update_current, $this->upgrader->update_count ); - echo ''; + echo ''; // This progress messages div gets moved via JavaScript when clicking on "Show details.". - echo '

'; + echo '

'; $this->flush_output(); } /** - * * @param string $title */ - public function after($title = '') { + public function after( $title = '' ) { echo '

'; if ( $this->error || ! $this->result ) { if ( $this->error ) { - echo '

' . sprintf($this->upgrader->strings['skin_update_failed_error'], $title, '' . $this->error . '' ) . '

'; + echo '

' . sprintf( $this->upgrader->strings['skin_update_failed_error'], $title, '' . $this->error . '' ) . '

'; } else { - echo '

' . sprintf($this->upgrader->strings['skin_update_failed'], $title) . '

'; + echo '

' . sprintf( $this->upgrader->strings['skin_update_failed'], $title ) . '

'; } - echo ''; + echo ''; } if ( $this->result && ! is_wp_error( $this->result ) ) { if ( ! $this->error ) { @@ -152,7 +155,7 @@ class Bulk_Upgrader_Skin extends WP_Upgrader_Skin { '

'; } - echo ''; + echo ''; } $this->reset(); @@ -163,7 +166,7 @@ class Bulk_Upgrader_Skin extends WP_Upgrader_Skin { */ public function reset() { $this->in_loop = false; - $this->error = false; + $this->error = false; } /** diff --git a/wp-admin/includes/class-core-upgrader.php b/wp-admin/includes/class-core-upgrader.php index 195e5885e5..0bbf43303f 100644 --- a/wp-admin/includes/class-core-upgrader.php +++ b/wp-admin/includes/class-core-upgrader.php @@ -26,15 +26,15 @@ class Core_Upgrader extends WP_Upgrader { * @since 2.8.0 */ public function upgrade_strings() { - $this->strings['up_to_date'] = __('WordPress is at the latest version.'); - $this->strings['locked'] = __('Another update is currently in progress.'); - $this->strings['no_package'] = __('Update package not available.'); + $this->strings['up_to_date'] = __( 'WordPress is at the latest version.' ); + $this->strings['locked'] = __( 'Another update is currently in progress.' ); + $this->strings['no_package'] = __( 'Update package not available.' ); /* translators: %s: package URL */ - $this->strings['downloading_package'] = sprintf( __( 'Downloading update from %s…' ), '%s' ); - $this->strings['unpack_package'] = __('Unpacking the update…'); - $this->strings['copy_failed'] = __('Could not copy files.'); - $this->strings['copy_failed_space'] = __('Could not copy files. You may have run out of disk space.' ); - $this->strings['start_rollback'] = __( 'Attempting to roll back to previous version.' ); + $this->strings['downloading_package'] = sprintf( __( 'Downloading update from %s…' ), '%s' ); + $this->strings['unpack_package'] = __( 'Unpacking the update…' ); + $this->strings['copy_failed'] = __( 'Could not copy files.' ); + $this->strings['copy_failed_space'] = __( 'Could not copy files. You may have run out of disk space.' ); + $this->strings['start_rollback'] = __( 'Attempting to roll back to previous version.' ); $this->strings['rollback_was_required'] = __( 'Due to an error during updating, WordPress has rolled back to your previous version.' ); } @@ -66,10 +66,10 @@ class Core_Upgrader extends WP_Upgrader { $start_time = time(); - $defaults = array( - 'pre_check_md5' => true, - 'attempt_rollback' => false, - 'do_rollback' => false, + $defaults = array( + 'pre_check_md5' => true, + 'attempt_rollback' => false, + 'do_rollback' => false, 'allow_relaxed_file_ownership' => false, ); $parsed_args = wp_parse_args( $args, $defaults ); @@ -78,21 +78,23 @@ class Core_Upgrader extends WP_Upgrader { $this->upgrade_strings(); // Is an update available? - if ( !isset( $current->response ) || $current->response == 'latest' ) - return new WP_Error('up_to_date', $this->strings['up_to_date']); + if ( ! isset( $current->response ) || $current->response == 'latest' ) { + return new WP_Error( 'up_to_date', $this->strings['up_to_date'] ); + } $res = $this->fs_connect( array( ABSPATH, WP_CONTENT_DIR ), $parsed_args['allow_relaxed_file_ownership'] ); if ( ! $res || is_wp_error( $res ) ) { return $res; } - $wp_dir = trailingslashit($wp_filesystem->abspath()); + $wp_dir = trailingslashit( $wp_filesystem->abspath() ); $partial = true; - if ( $parsed_args['do_rollback'] ) + if ( $parsed_args['do_rollback'] ) { $partial = false; - elseif ( $parsed_args['pre_check_md5'] && ! $this->check_files() ) + } elseif ( $parsed_args['pre_check_md5'] && ! $this->check_files() ) { $partial = false; + } /* * If partial update is returned from the API, use that, unless we're doing @@ -100,17 +102,18 @@ class Core_Upgrader extends WP_Upgrader { * the new_bundled zip. Don't though if the constant is set to skip bundled items. * If the API returns a no_content zip, go with it. Finally, default to the full zip. */ - if ( $parsed_args['do_rollback'] && $current->packages->rollback ) + if ( $parsed_args['do_rollback'] && $current->packages->rollback ) { $to_download = 'rollback'; - elseif ( $current->packages->partial && 'reinstall' != $current->response && $wp_version == $current->partial_version && $partial ) + } elseif ( $current->packages->partial && 'reinstall' != $current->response && $wp_version == $current->partial_version && $partial ) { $to_download = 'partial'; - elseif ( $current->packages->new_bundled && version_compare( $wp_version, $current->new_bundled, '<' ) - && ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) ) + } elseif ( $current->packages->new_bundled && version_compare( $wp_version, $current->new_bundled, '<' ) + && ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) ) { $to_download = 'new_bundled'; - elseif ( $current->packages->no_content ) + } elseif ( $current->packages->no_content ) { $to_download = 'no_content'; - else + } else { $to_download = 'full'; + } // Lock to prevent multiple Core Updates occurring $lock = WP_Upgrader::create_lock( 'core_updater', 15 * MINUTE_IN_SECONDS ); @@ -131,12 +134,12 @@ class Core_Upgrader extends WP_Upgrader { } // Copy update-core.php from the new version into place. - if ( !$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true) ) { - $wp_filesystem->delete($working_dir, true); + if ( ! $wp_filesystem->copy( $working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true ) ) { + $wp_filesystem->delete( $working_dir, true ); WP_Upgrader::release_lock( 'core_updater' ); return new WP_Error( 'copy_failed_for_update_core_file', __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ), 'wp-admin/includes/update-core.php' ); } - $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE); + $wp_filesystem->chmod( $wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE ); require_once( ABSPATH . 'wp-admin/includes/update-core.php' ); @@ -157,12 +160,13 @@ class Core_Upgrader extends WP_Upgrader { * mkdir_failed__copy_dir, copy_failed__copy_dir_retry, and disk_full. * do_rollback allows for update_core() to trigger a rollback if needed. */ - if ( false !== strpos( $error_code, 'do_rollback' ) ) + if ( false !== strpos( $error_code, 'do_rollback' ) ) { $try_rollback = true; - elseif ( false !== strpos( $error_code, '__copy_dir' ) ) + } elseif ( false !== strpos( $error_code, '__copy_dir' ) ) { $try_rollback = true; - elseif ( 'disk_full' === $error_code ) + } elseif ( 'disk_full' === $error_code ) { $try_rollback = true; + } } if ( $try_rollback ) { @@ -175,12 +179,22 @@ class Core_Upgrader extends WP_Upgrader { $rollback_result = $this->upgrade( $current, array_merge( $parsed_args, array( 'do_rollback' => true ) ) ); $original_result = $result; - $result = new WP_Error( 'rollback_was_required', $this->strings['rollback_was_required'], (object) array( 'update' => $original_result, 'rollback' => $rollback_result ) ); + $result = new WP_Error( + 'rollback_was_required', $this->strings['rollback_was_required'], (object) array( + 'update' => $original_result, + 'rollback' => $rollback_result, + ) + ); } } /** This action is documented in wp-admin/includes/class-wp-upgrader.php */ - do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'core' ) ); + do_action( + 'upgrader_process_complete', $this, array( + 'action' => 'update', + 'type' => 'core', + ) + ); // Clear the current updates delete_site_transient( 'update_core' ); @@ -191,7 +205,7 @@ class Core_Upgrader extends WP_Upgrader { 'success' => true, 'fs_method' => $wp_filesystem->method, 'fs_method_forced' => defined( 'FS_METHOD' ) || has_filter( 'filesystem_method' ), - 'fs_method_direct' => !empty( $GLOBALS['_wp_filesystem_direct_method'] ) ? $GLOBALS['_wp_filesystem_direct_method'] : '', + 'fs_method_direct' => ! empty( $GLOBALS['_wp_filesystem_direct_method'] ) ? $GLOBALS['_wp_filesystem_direct_method'] : '', 'time_taken' => time() - $start_time, 'reported' => $wp_version, 'attempted' => $current->version, @@ -236,8 +250,8 @@ class Core_Upgrader extends WP_Upgrader { public static function should_update_to_version( $offered_ver ) { include( ABSPATH . WPINC . '/version.php' ); // $wp_version; // x.y.z - $current_branch = implode( '.', array_slice( preg_split( '/[.-]/', $wp_version ), 0, 2 ) ); // x.y - $new_branch = implode( '.', array_slice( preg_split( '/[.-]/', $offered_ver ), 0, 2 ) ); // x.y + $current_branch = implode( '.', array_slice( preg_split( '/[.-]/', $wp_version ), 0, 2 ) ); // x.y + $new_branch = implode( '.', array_slice( preg_split( '/[.-]/', $offered_ver ), 0, 2 ) ); // x.y $current_is_development_version = (bool) strpos( $wp_version, '-' ); // Defaults: @@ -255,34 +269,39 @@ class Core_Upgrader extends WP_Upgrader { $upgrade_dev = $upgrade_minor = $upgrade_major = true; } elseif ( 'minor' === WP_AUTO_UPDATE_CORE ) { // Only minor updates for core - $upgrade_dev = $upgrade_major = false; + $upgrade_dev = $upgrade_major = false; $upgrade_minor = true; } } // 1: If we're already on that version, not much point in updating? - if ( $offered_ver == $wp_version ) + if ( $offered_ver == $wp_version ) { return false; + } // 2: If we're running a newer version, that's a nope - if ( version_compare( $wp_version, $offered_ver, '>' ) ) + if ( version_compare( $wp_version, $offered_ver, '>' ) ) { return false; + } $failure_data = get_site_option( 'auto_core_update_failed' ); if ( $failure_data ) { // If this was a critical update failure, cannot update. - if ( ! empty( $failure_data['critical'] ) ) + if ( ! empty( $failure_data['critical'] ) ) { return false; + } // Don't claim we can update on update-core.php if we have a non-critical failure logged. - if ( $wp_version == $failure_data['current'] && false !== strpos( $offered_ver, '.1.next.minor' ) ) + if ( $wp_version == $failure_data['current'] && false !== strpos( $offered_ver, '.1.next.minor' ) ) { return false; + } // Cannot update if we're retrying the same A to B update that caused a non-critical failure. // Some non-critical failures do allow retries, like download_failed. // 3.7.1 => 3.7.2 resulted in files_not_writable, if we are still on 3.7.1 and still trying to update to 3.7.2. - if ( empty( $failure_data['retry'] ) && $wp_version == $failure_data['current'] && $offered_ver == $failure_data['attempted'] ) + if ( empty( $failure_data['retry'] ) && $wp_version == $failure_data['current'] && $offered_ver == $failure_data['attempted'] ) { return false; + } } // 3: 3.7-alpha-25000 -> 3.7-alpha-25678 -> 3.7-beta1 -> 3.7-beta2 @@ -296,8 +315,9 @@ class Core_Upgrader extends WP_Upgrader { * @param bool $upgrade_dev Whether to enable automatic updates for * development versions. */ - if ( ! apply_filters( 'allow_dev_auto_core_updates', $upgrade_dev ) ) + if ( ! apply_filters( 'allow_dev_auto_core_updates', $upgrade_dev ) ) { return false; + } // Else fall through to minor + major branches below. } @@ -346,15 +366,18 @@ class Core_Upgrader extends WP_Upgrader { $checksums = get_core_checksums( $wp_version, isset( $wp_local_package ) ? $wp_local_package : 'en_US' ); - if ( ! is_array( $checksums ) ) + if ( ! is_array( $checksums ) ) { return false; + } foreach ( $checksums as $file => $checksum ) { // Skip files which get updated - if ( 'wp-content' == substr( $file, 0, 10 ) ) + if ( 'wp-content' == substr( $file, 0, 10 ) ) { continue; - if ( ! file_exists( ABSPATH . $file ) || md5_file( ABSPATH . $file ) !== $checksum ) + } + if ( ! file_exists( ABSPATH . $file ) || md5_file( ABSPATH . $file ) !== $checksum ) { return false; + } } return true; diff --git a/wp-admin/includes/class-file-upload-upgrader.php b/wp-admin/includes/class-file-upload-upgrader.php index a182b62ccd..c3d8a79552 100644 --- a/wp-admin/includes/class-file-upload-upgrader.php +++ b/wp-admin/includes/class-file-upload-upgrader.php @@ -52,28 +52,33 @@ class File_Upload_Upgrader { */ public function __construct( $form, $urlholder ) { - if ( empty($_FILES[$form]['name']) && empty($_GET[$urlholder]) ) - wp_die(__('Please select a file')); + if ( empty( $_FILES[ $form ]['name'] ) && empty( $_GET[ $urlholder ] ) ) { + wp_die( __( 'Please select a file' ) ); + } //Handle a newly uploaded file, Else assume it's already been uploaded - if ( ! empty($_FILES) ) { - $overrides = array( 'test_form' => false, 'test_type' => false ); - $file = wp_handle_upload( $_FILES[$form], $overrides ); + if ( ! empty( $_FILES ) ) { + $overrides = array( + 'test_form' => false, + 'test_type' => false, + ); + $file = wp_handle_upload( $_FILES[ $form ], $overrides ); - if ( isset( $file['error'] ) ) + if ( isset( $file['error'] ) ) { wp_die( $file['error'] ); + } - $this->filename = $_FILES[$form]['name']; - $this->package = $file['file']; + $this->filename = $_FILES[ $form ]['name']; + $this->package = $file['file']; // Construct the object array $object = array( - 'post_title' => $this->filename, - 'post_content' => $file['url'], + 'post_title' => $this->filename, + 'post_content' => $file['url'], 'post_mime_type' => $file['type'], - 'guid' => $file['url'], - 'context' => 'upgrader', - 'post_status' => 'private' + 'guid' => $file['url'], + 'context' => 'upgrader', + 'post_status' => 'private', ); // Save the data. @@ -82,22 +87,24 @@ class File_Upload_Upgrader { // Schedule a cleanup for 2 hours from now in case of failed installation. wp_schedule_single_event( time() + 2 * HOUR_IN_SECONDS, 'upgrader_scheduled_cleanup', array( $this->id ) ); - } elseif ( is_numeric( $_GET[$urlholder] ) ) { + } elseif ( is_numeric( $_GET[ $urlholder ] ) ) { // Numeric Package = previously uploaded file, see above. - $this->id = (int) $_GET[$urlholder]; + $this->id = (int) $_GET[ $urlholder ]; $attachment = get_post( $this->id ); - if ( empty($attachment) ) - wp_die(__('Please select a file')); + if ( empty( $attachment ) ) { + wp_die( __( 'Please select a file' ) ); + } $this->filename = $attachment->post_title; - $this->package = get_attached_file( $attachment->ID ); + $this->package = get_attached_file( $attachment->ID ); } else { // Else, It's set to something, Back compat for plugins using the old (pre-3.3) File_Uploader handler. - if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) ) + if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) ) { wp_die( $uploads['error'] ); + } $this->filename = sanitize_file_name( $_GET[ $urlholder ] ); - $this->package = $uploads['basedir'] . '/' . $this->filename; + $this->package = $uploads['basedir'] . '/' . $this->filename; if ( 0 !== strpos( realpath( $this->package ), realpath( $uploads['basedir'] ) ) ) { wp_die( __( 'Please select a file' ) ); @@ -113,11 +120,12 @@ class File_Upload_Upgrader { * @return bool Whether the cleanup was successful. */ public function cleanup() { - if ( $this->id ) + if ( $this->id ) { wp_delete_attachment( $this->id ); - elseif ( file_exists( $this->package ) ) + } elseif ( file_exists( $this->package ) ) { return @unlink( $this->package ); + } return true; } diff --git a/wp-admin/includes/class-language-pack-upgrader-skin.php b/wp-admin/includes/class-language-pack-upgrader-skin.php index 9efc877ef0..4fa1f29d38 100644 --- a/wp-admin/includes/class-language-pack-upgrader-skin.php +++ b/wp-admin/includes/class-language-pack-upgrader-skin.php @@ -16,21 +16,25 @@ * @see WP_Upgrader_Skin */ class Language_Pack_Upgrader_Skin extends WP_Upgrader_Skin { - public $language_update = null; - public $done_header = false; - public $done_footer = false; + public $language_update = null; + public $done_header = false; + public $done_footer = false; public $display_footer_actions = true; /** - * * @param array $args */ public function __construct( $args = array() ) { - $defaults = array( 'url' => '', 'nonce' => '', 'title' => __( 'Update Translations' ), 'skip_header_footer' => false ); - $args = wp_parse_args( $args, $defaults ); + $defaults = array( + 'url' => '', + 'nonce' => '', + 'title' => __( 'Update Translations' ), + 'skip_header_footer' => false, + ); + $args = wp_parse_args( $args, $defaults ); if ( $args['skip_header_footer'] ) { - $this->done_header = true; - $this->done_footer = true; + $this->done_header = true; + $this->done_footer = true; $this->display_footer_actions = false; } parent::__construct( $args ); @@ -47,7 +51,6 @@ class Language_Pack_Upgrader_Skin extends WP_Upgrader_Skin { } /** - * * @param string|WP_Error $error */ public function error( $error ) { @@ -66,7 +69,7 @@ class Language_Pack_Upgrader_Skin extends WP_Upgrader_Skin { */ public function bulk_footer() { $this->decrement_update_count( 'translation' ); - $update_actions = array(); + $update_actions = array(); $update_actions['updates_page'] = '' . __( 'Return to WordPress Updates page' ) . ''; /** @@ -78,7 +81,8 @@ class Language_Pack_Upgrader_Skin extends WP_Upgrader_Skin { */ $update_actions = apply_filters( 'update_translations_complete_actions', $update_actions ); - if ( $update_actions && $this->display_footer_actions ) + if ( $update_actions && $this->display_footer_actions ) { $this->feedback( implode( ' | ', $update_actions ) ); + } } } diff --git a/wp-admin/includes/class-language-pack-upgrader.php b/wp-admin/includes/class-language-pack-upgrader.php index 404c4a2771..6eff004b8a 100644 --- a/wp-admin/includes/class-language-pack-upgrader.php +++ b/wp-admin/includes/class-language-pack-upgrader.php @@ -94,9 +94,11 @@ class Language_Pack_Upgrader extends WP_Upgrader { if ( $upgrader && $upgrader->skin instanceof Automatic_Upgrader_Skin ) { $skin = $upgrader->skin; } else { - $skin = new Language_Pack_Upgrader_Skin( array( - 'skip_header_footer' => true, - ) ); + $skin = new Language_Pack_Upgrader_Skin( + array( + 'skip_header_footer' => true, + ) + ); } $lp_upgrader = new Language_Pack_Upgrader( $skin ); @@ -110,13 +112,13 @@ class Language_Pack_Upgrader extends WP_Upgrader { */ public function upgrade_strings() { $this->strings['starting_upgrade'] = __( 'Some of your translations need updating. Sit tight for a few more seconds while we update them as well.' ); - $this->strings['up_to_date'] = __( 'The translations are up to date.' ); - $this->strings['no_package'] = __( 'Update package not available.' ); + $this->strings['up_to_date'] = __( 'The translations are up to date.' ); + $this->strings['no_package'] = __( 'Update package not available.' ); /* translators: %s: package URL */ $this->strings['downloading_package'] = sprintf( __( 'Downloading translation from %s…' ), '%s' ); - $this->strings['unpack_package'] = __( 'Unpacking the update…' ); - $this->strings['process_failed'] = __( 'Translation update failed.' ); - $this->strings['process_success'] = __( 'Translation updated successfully.' ); + $this->strings['unpack_package'] = __( 'Unpacking the update…' ); + $this->strings['process_failed'] = __( 'Translation update failed.' ); + $this->strings['process_success'] = __( 'Translation updated successfully.' ); } /** @@ -163,7 +165,7 @@ class Language_Pack_Upgrader extends WP_Upgrader { public function bulk_upgrade( $language_updates = array(), $args = array() ) { global $wp_filesystem; - $defaults = array( + $defaults = array( 'clear_update_cache' => true, ); $parsed_args = wp_parse_args( $args, $defaults ); @@ -171,8 +173,9 @@ class Language_Pack_Upgrader extends WP_Upgrader { $this->init(); $this->upgrade_strings(); - if ( ! $language_updates ) + if ( ! $language_updates ) { $language_updates = wp_get_translation_updates(); + } if ( empty( $language_updates ) ) { $this->skin->header(); @@ -183,8 +186,9 @@ class Language_Pack_Upgrader extends WP_Upgrader { return true; } - if ( 'upgrader_process_complete' == current_filter() ) + if ( 'upgrader_process_complete' == current_filter() ) { $this->skin->feedback( 'starting_upgrade' ); + } // Remove any existing upgrade filters from the plugin/theme upgraders #WP29425 & #WP29230 remove_all_filters( 'upgrader_pre_install' ); @@ -205,7 +209,7 @@ class Language_Pack_Upgrader extends WP_Upgrader { $results = array(); - $this->update_count = count( $language_updates ); + $this->update_count = count( $language_updates ); $this->update_current = 0; /* @@ -213,9 +217,11 @@ class Language_Pack_Upgrader extends WP_Upgrader { * as we then may need to create a /plugins or /themes directory inside of it. */ $remote_destination = $wp_filesystem->find_folder( WP_LANG_DIR ); - if ( ! $wp_filesystem->exists( $remote_destination ) ) - if ( ! $wp_filesystem->mkdir( $remote_destination, FS_CHMOD_DIR ) ) + if ( ! $wp_filesystem->exists( $remote_destination ) ) { + if ( ! $wp_filesystem->mkdir( $remote_destination, FS_CHMOD_DIR ) ) { return new WP_Error( 'mkdir_failed_lang_dir', $this->strings['mkdir_failed'], $remote_destination ); + } + } $language_updates_results = array(); @@ -224,24 +230,25 @@ class Language_Pack_Upgrader extends WP_Upgrader { $this->skin->language_update = $language_update; $destination = WP_LANG_DIR; - if ( 'plugin' == $language_update->type ) + if ( 'plugin' == $language_update->type ) { $destination .= '/plugins'; - elseif ( 'theme' == $language_update->type ) + } elseif ( 'theme' == $language_update->type ) { $destination .= '/themes'; + } $this->update_current++; $options = array( - 'package' => $language_update->package, - 'destination' => $destination, - 'clear_destination' => false, + 'package' => $language_update->package, + 'destination' => $destination, + 'clear_destination' => false, 'abort_if_destination_exists' => false, // We expect the destination to exist. - 'clear_working' => true, - 'is_multi' => true, - 'hook_extra' => array( + 'clear_working' => true, + 'is_multi' => true, + 'hook_extra' => array( 'language_update_type' => $language_update->type, - 'language_update' => $language_update, - ) + 'language_update' => $language_update, + ), ); $result = $this->run( $options ); @@ -268,12 +275,14 @@ class Language_Pack_Upgrader extends WP_Upgrader { remove_action( 'upgrader_process_complete', 'wp_update_themes' ); /** This action is documented in wp-admin/includes/class-wp-upgrader.php */ - do_action( 'upgrader_process_complete', $this, array( - 'action' => 'update', - 'type' => 'translation', - 'bulk' => true, - 'translations' => $language_updates_results - ) ); + do_action( + 'upgrader_process_complete', $this, array( + 'action' => 'update', + 'type' => 'translation', + 'bulk' => true, + 'translations' => $language_updates_results, + ) + ); // Re-add upgrade hooks. add_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 ); @@ -311,8 +320,9 @@ class Language_Pack_Upgrader extends WP_Upgrader { public function check_package( $source, $remote_source ) { global $wp_filesystem; - if ( is_wp_error( $source ) ) + if ( is_wp_error( $source ) ) { return $source; + } // Check that the folder contains a valid language. $files = $wp_filesystem->dirlist( $remote_source ); @@ -320,16 +330,19 @@ class Language_Pack_Upgrader extends WP_Upgrader { // Check to see if a .po and .mo exist in the folder. $po = $mo = false; foreach ( (array) $files as $file => $filedata ) { - if ( '.po' == substr( $file, -3 ) ) + if ( '.po' == substr( $file, -3 ) ) { $po = true; - elseif ( '.mo' == substr( $file, -3 ) ) + } elseif ( '.mo' == substr( $file, -3 ) ) { $mo = true; + } } if ( ! $mo || ! $po ) { - return new WP_Error( 'incompatible_archive_pomo', $this->strings['incompatible_archive'], + return new WP_Error( + 'incompatible_archive_pomo', $this->strings['incompatible_archive'], /* translators: 1: .po 2: .mo */ - sprintf( __( 'The language pack is missing either the %1$s or %2$s files.' ), + sprintf( + __( 'The language pack is missing either the %1$s or %2$s files.' ), '.po', '.mo' ) @@ -354,14 +367,16 @@ class Language_Pack_Upgrader extends WP_Upgrader { case 'theme': $theme = wp_get_theme( $update->slug ); - if ( $theme->exists() ) + if ( $theme->exists() ) { return $theme->Get( 'Name' ); + } break; case 'plugin': $plugin_data = get_plugins( '/' . $update->slug ); $plugin_data = reset( $plugin_data ); - if ( $plugin_data ) + if ( $plugin_data ) { return $plugin_data['Name']; + } break; } return ''; diff --git a/wp-admin/includes/class-plugin-installer-skin.php b/wp-admin/includes/class-plugin-installer-skin.php index 66f406227b..300d6684d9 100644 --- a/wp-admin/includes/class-plugin-installer-skin.php +++ b/wp-admin/includes/class-plugin-installer-skin.php @@ -20,24 +20,30 @@ class Plugin_Installer_Skin extends WP_Upgrader_Skin { public $type; /** - * * @param array $args */ - public function __construct($args = array()) { - $defaults = array( 'type' => 'web', 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => '' ); - $args = wp_parse_args($args, $defaults); + public function __construct( $args = array() ) { + $defaults = array( + 'type' => 'web', + 'url' => '', + 'plugin' => '', + 'nonce' => '', + 'title' => '', + ); + $args = wp_parse_args( $args, $defaults ); $this->type = $args['type']; - $this->api = isset($args['api']) ? $args['api'] : array(); + $this->api = isset( $args['api'] ) ? $args['api'] : array(); - parent::__construct($args); + parent::__construct( $args ); } /** */ public function before() { - if ( !empty($this->api) ) - $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the plugin %s %s.'), $this->api->name, $this->api->version); + if ( ! empty( $this->api ) ) { + $this->upgrader->strings['process_success'] = sprintf( __( 'Successfully installed the plugin %1$s %2$s.' ), $this->api->name, $this->api->version ); + } } /** @@ -47,11 +53,11 @@ class Plugin_Installer_Skin extends WP_Upgrader_Skin { $install_actions = array(); - $from = isset($_GET['from']) ? wp_unslash( $_GET['from'] ) : 'plugins'; + $from = isset( $_GET['from'] ) ? wp_unslash( $_GET['from'] ) : 'plugins'; if ( 'import' == $from ) { $install_actions['activate_plugin'] = '' . __( 'Activate Plugin & Run Importer' ) . ''; - } else if ( 'press-this' == $from ) { + } elseif ( 'press-this' == $from ) { $install_actions['activate_plugin'] = '' . __( 'Activate Plugin & Return to Press This' ) . ''; } else { $install_actions['activate_plugin'] = '' . __( 'Activate Plugin' ) . ''; @@ -72,7 +78,7 @@ class Plugin_Installer_Skin extends WP_Upgrader_Skin { $install_actions['plugins_page'] = '' . __( 'Return to Plugins page' ) . ''; } - if ( ! $this->result || is_wp_error($this->result) ) { + if ( ! $this->result || is_wp_error( $this->result ) ) { unset( $install_actions['activate_plugin'], $install_actions['network_activate'] ); } elseif ( ! current_user_can( 'activate_plugin', $plugin_file ) ) { unset( $install_actions['activate_plugin'] ); diff --git a/wp-admin/includes/class-plugin-upgrader-skin.php b/wp-admin/includes/class-plugin-upgrader-skin.php index ba8c30fbc4..036166a2b0 100644 --- a/wp-admin/includes/class-plugin-upgrader-skin.php +++ b/wp-admin/includes/class-plugin-upgrader-skin.php @@ -16,43 +16,48 @@ * @see WP_Upgrader_Skin */ class Plugin_Upgrader_Skin extends WP_Upgrader_Skin { - public $plugin = ''; - public $plugin_active = false; + public $plugin = ''; + public $plugin_active = false; public $plugin_network_active = false; /** - * * @param array $args */ public function __construct( $args = array() ) { - $defaults = array( 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => __('Update Plugin') ); - $args = wp_parse_args($args, $defaults); + $defaults = array( + 'url' => '', + 'plugin' => '', + 'nonce' => '', + 'title' => __( 'Update Plugin' ), + ); + $args = wp_parse_args( $args, $defaults ); $this->plugin = $args['plugin']; - $this->plugin_active = is_plugin_active( $this->plugin ); + $this->plugin_active = is_plugin_active( $this->plugin ); $this->plugin_network_active = is_plugin_active_for_network( $this->plugin ); - parent::__construct($args); + parent::__construct( $args ); } /** */ public function after() { $this->plugin = $this->upgrader->plugin_info(); - if ( !empty($this->plugin) && !is_wp_error($this->result) && $this->plugin_active ){ + if ( ! empty( $this->plugin ) && ! is_wp_error( $this->result ) && $this->plugin_active ) { // Currently used only when JS is off for a single plugin update? echo ''; } $this->decrement_update_count( 'plugin' ); - $update_actions = array( - 'activate_plugin' => '' . __( 'Activate Plugin' ) . '', - 'plugins_page' => '' . __( 'Return to Plugins page' ) . '' + $update_actions = array( + 'activate_plugin' => '' . __( 'Activate Plugin' ) . '', + 'plugins_page' => '' . __( 'Return to Plugins page' ) . '', ); - if ( $this->plugin_active || ! $this->result || is_wp_error( $this->result ) || ! current_user_can( 'activate_plugin', $this->plugin ) ) + if ( $this->plugin_active || ! $this->result || is_wp_error( $this->result ) || ! current_user_can( 'activate_plugin', $this->plugin ) ) { unset( $update_actions['activate_plugin'] ); + } /** * Filters the list of action links available following a single plugin update. @@ -64,7 +69,8 @@ class Plugin_Upgrader_Skin extends WP_Upgrader_Skin { */ $update_actions = apply_filters( 'update_plugin_complete_actions', $update_actions, $this->plugin ); - if ( ! empty($update_actions) ) - $this->feedback(implode(' | ', (array)$update_actions)); + if ( ! empty( $update_actions ) ) { + $this->feedback( implode( ' | ', (array) $update_actions ) ); + } } } diff --git a/wp-admin/includes/class-plugin-upgrader.php b/wp-admin/includes/class-plugin-upgrader.php index 3c05353bc1..c7bdc58799 100644 --- a/wp-admin/includes/class-plugin-upgrader.php +++ b/wp-admin/includes/class-plugin-upgrader.php @@ -44,16 +44,16 @@ class Plugin_Upgrader extends WP_Upgrader { * @since 2.8.0 */ public function upgrade_strings() { - $this->strings['up_to_date'] = __('The plugin is at the latest version.'); - $this->strings['no_package'] = __('Update package not available.'); + $this->strings['up_to_date'] = __( 'The plugin is at the latest version.' ); + $this->strings['no_package'] = __( 'Update package not available.' ); /* translators: %s: package URL */ - $this->strings['downloading_package'] = sprintf( __( 'Downloading update from %s…' ), '%s' ); - $this->strings['unpack_package'] = __('Unpacking the update…'); - $this->strings['remove_old'] = __('Removing the old version of the plugin…'); - $this->strings['remove_old_failed'] = __('Could not remove the old plugin.'); - $this->strings['process_failed'] = __('Plugin update failed.'); - $this->strings['process_success'] = __('Plugin updated successfully.'); - $this->strings['process_bulk_success'] = __('Plugins updated successfully.'); + $this->strings['downloading_package'] = sprintf( __( 'Downloading update from %s…' ), '%s' ); + $this->strings['unpack_package'] = __( 'Unpacking the update…' ); + $this->strings['remove_old'] = __( 'Removing the old version of the plugin…' ); + $this->strings['remove_old_failed'] = __( 'Could not remove the old plugin.' ); + $this->strings['process_failed'] = __( 'Plugin update failed.' ); + $this->strings['process_success'] = __( 'Plugin updated successfully.' ); + $this->strings['process_bulk_success'] = __( 'Plugins updated successfully.' ); } /** @@ -62,14 +62,14 @@ class Plugin_Upgrader extends WP_Upgrader { * @since 2.8.0 */ public function install_strings() { - $this->strings['no_package'] = __('Installation package not available.'); + $this->strings['no_package'] = __( 'Installation package not available.' ); /* translators: %s: package URL */ $this->strings['downloading_package'] = sprintf( __( 'Downloading installation package from %s…' ), '%s' ); - $this->strings['unpack_package'] = __('Unpacking the package…'); - $this->strings['installing_package'] = __('Installing the plugin…'); - $this->strings['no_files'] = __('The plugin contains no files.'); - $this->strings['process_failed'] = __('Plugin installation failed.'); - $this->strings['process_success'] = __('Plugin installed successfully.'); + $this->strings['unpack_package'] = __( 'Unpacking the package…' ); + $this->strings['installing_package'] = __( 'Installing the plugin…' ); + $this->strings['no_files'] = __( 'The plugin contains no files.' ); + $this->strings['process_failed'] = __( 'Plugin installation failed.' ); + $this->strings['process_success'] = __( 'Plugin installed successfully.' ); } /** @@ -89,7 +89,7 @@ class Plugin_Upgrader extends WP_Upgrader { */ public function install( $package, $args = array() ) { - $defaults = array( + $defaults = array( 'clear_update_cache' => true, ); $parsed_args = wp_parse_args( $args, $defaults ); @@ -97,28 +97,31 @@ class Plugin_Upgrader extends WP_Upgrader { $this->init(); $this->install_strings(); - add_filter('upgrader_source_selection', array($this, 'check_package') ); + add_filter( 'upgrader_source_selection', array( $this, 'check_package' ) ); if ( $parsed_args['clear_update_cache'] ) { // Clear cache so wp_update_plugins() knows about the new plugin. add_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9, 0 ); } - $this->run( array( - 'package' => $package, - 'destination' => WP_PLUGIN_DIR, - 'clear_destination' => false, // Do not overwrite files. - 'clear_working' => true, - 'hook_extra' => array( - 'type' => 'plugin', - 'action' => 'install', + $this->run( + array( + 'package' => $package, + 'destination' => WP_PLUGIN_DIR, + 'clear_destination' => false, // Do not overwrite files. + 'clear_working' => true, + 'hook_extra' => array( + 'type' => 'plugin', + 'action' => 'install', + ), ) - ) ); + ); remove_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9 ); - remove_filter('upgrader_source_selection', array($this, 'check_package') ); + remove_filter( 'upgrader_source_selection', array( $this, 'check_package' ) ); - if ( ! $this->result || is_wp_error($this->result) ) + if ( ! $this->result || is_wp_error( $this->result ) ) { return $this->result; + } // Force refresh of plugin update information wp_clean_plugins_cache( $parsed_args['clear_update_cache'] ); @@ -143,7 +146,7 @@ class Plugin_Upgrader extends WP_Upgrader { */ public function upgrade( $plugin, $args = array() ) { - $defaults = array( + $defaults = array( 'clear_update_cache' => true, ); $parsed_args = wp_parse_args( $args, $defaults ); @@ -152,10 +155,10 @@ class Plugin_Upgrader extends WP_Upgrader { $this->upgrade_strings(); $current = get_site_transient( 'update_plugins' ); - if ( !isset( $current->response[ $plugin ] ) ) { + if ( ! isset( $current->response[ $plugin ] ) ) { $this->skin->before(); - $this->skin->set_result(false); - $this->skin->error('up_to_date'); + $this->skin->set_result( false ); + $this->skin->error( 'up_to_date' ); $this->skin->after(); return false; } @@ -163,33 +166,36 @@ class Plugin_Upgrader extends WP_Upgrader { // Get the URL to the zip file $r = $current->response[ $plugin ]; - add_filter('upgrader_pre_install', array($this, 'deactivate_plugin_before_upgrade'), 10, 2); - add_filter('upgrader_clear_destination', array($this, 'delete_old_plugin'), 10, 4); + add_filter( 'upgrader_pre_install', array( $this, 'deactivate_plugin_before_upgrade' ), 10, 2 ); + add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ), 10, 4 ); //'source_selection' => array($this, 'source_selection'), //there's a trac ticket to move up the directory for zip's which are made a bit differently, useful for non-.org plugins. if ( $parsed_args['clear_update_cache'] ) { // Clear cache so wp_update_plugins() knows about the new plugin. add_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9, 0 ); } - $this->run( array( - 'package' => $r->package, - 'destination' => WP_PLUGIN_DIR, - 'clear_destination' => true, - 'clear_working' => true, - 'hook_extra' => array( - 'plugin' => $plugin, - 'type' => 'plugin', - 'action' => 'update', - ), - ) ); + $this->run( + array( + 'package' => $r->package, + 'destination' => WP_PLUGIN_DIR, + 'clear_destination' => true, + 'clear_working' => true, + 'hook_extra' => array( + 'plugin' => $plugin, + 'type' => 'plugin', + 'action' => 'update', + ), + ) + ); // Cleanup our hooks, in case something else does a upgrade on this connection. remove_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9 ); - remove_filter('upgrader_pre_install', array($this, 'deactivate_plugin_before_upgrade')); - remove_filter('upgrader_clear_destination', array($this, 'delete_old_plugin')); + remove_filter( 'upgrader_pre_install', array( $this, 'deactivate_plugin_before_upgrade' ) ); + remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ) ); - if ( ! $this->result || is_wp_error($this->result) ) + if ( ! $this->result || is_wp_error( $this->result ) ) { return $this->result; + } // Force refresh of plugin update information wp_clean_plugins_cache( $parsed_args['clear_update_cache'] ); @@ -214,7 +220,7 @@ class Plugin_Upgrader extends WP_Upgrader { */ public function bulk_upgrade( $plugins, $args = array() ) { - $defaults = array( + $defaults = array( 'clear_update_cache' => true, ); $parsed_args = wp_parse_args( $args, $defaults ); @@ -225,12 +231,12 @@ class Plugin_Upgrader extends WP_Upgrader { $current = get_site_transient( 'update_plugins' ); - add_filter('upgrader_clear_destination', array($this, 'delete_old_plugin'), 10, 4); + add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ), 10, 4 ); $this->skin->header(); // Connect to the Filesystem first. - $res = $this->fs_connect( array(WP_CONTENT_DIR, WP_PLUGIN_DIR) ); + $res = $this->fs_connect( array( WP_CONTENT_DIR, WP_PLUGIN_DIR ) ); if ( ! $res ) { $this->skin->footer(); return false; @@ -245,70 +251,77 @@ class Plugin_Upgrader extends WP_Upgrader { * @TODO: For multisite, maintenance mode should only kick in for individual sites if at all possible. */ $maintenance = ( is_multisite() && ! empty( $plugins ) ); - foreach ( $plugins as $plugin ) - $maintenance = $maintenance || ( is_plugin_active( $plugin ) && isset( $current->response[ $plugin] ) ); - if ( $maintenance ) - $this->maintenance_mode(true); + foreach ( $plugins as $plugin ) { + $maintenance = $maintenance || ( is_plugin_active( $plugin ) && isset( $current->response[ $plugin ] ) ); + } + if ( $maintenance ) { + $this->maintenance_mode( true ); + } $results = array(); - $this->update_count = count($plugins); + $this->update_count = count( $plugins ); $this->update_current = 0; foreach ( $plugins as $plugin ) { $this->update_current++; - $this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true); + $this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true ); - if ( !isset( $current->response[ $plugin ] ) ) { - $this->skin->set_result('up_to_date'); + if ( ! isset( $current->response[ $plugin ] ) ) { + $this->skin->set_result( 'up_to_date' ); $this->skin->before(); - $this->skin->feedback('up_to_date'); + $this->skin->feedback( 'up_to_date' ); $this->skin->after(); - $results[$plugin] = true; + $results[ $plugin ] = true; continue; } // Get the URL to the zip file. $r = $current->response[ $plugin ]; - $this->skin->plugin_active = is_plugin_active($plugin); + $this->skin->plugin_active = is_plugin_active( $plugin ); - $result = $this->run( array( - 'package' => $r->package, - 'destination' => WP_PLUGIN_DIR, - 'clear_destination' => true, - 'clear_working' => true, - 'is_multi' => true, - 'hook_extra' => array( - 'plugin' => $plugin + $result = $this->run( + array( + 'package' => $r->package, + 'destination' => WP_PLUGIN_DIR, + 'clear_destination' => true, + 'clear_working' => true, + 'is_multi' => true, + 'hook_extra' => array( + 'plugin' => $plugin, + ), ) - ) ); + ); - $results[$plugin] = $this->result; + $results[ $plugin ] = $this->result; // Prevent credentials auth screen from displaying multiple times - if ( false === $result ) + if ( false === $result ) { break; + } } //end foreach $plugins - $this->maintenance_mode(false); + $this->maintenance_mode( false ); // Force refresh of plugin update information. wp_clean_plugins_cache( $parsed_args['clear_update_cache'] ); /** This action is documented in wp-admin/includes/class-wp-upgrader.php */ - do_action( 'upgrader_process_complete', $this, array( - 'action' => 'update', - 'type' => 'plugin', - 'bulk' => true, - 'plugins' => $plugins, - ) ); + do_action( + 'upgrader_process_complete', $this, array( + 'action' => 'update', + 'type' => 'plugin', + 'bulk' => true, + 'plugins' => $plugins, + ) + ); $this->skin->bulk_footer(); $this->skin->footer(); // Cleanup our hooks, in case something else does a upgrade on this connection. - remove_filter('upgrader_clear_destination', array($this, 'delete_old_plugin')); + remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ) ); return $results; } @@ -327,19 +340,21 @@ class Plugin_Upgrader extends WP_Upgrader { * @return string|WP_Error The source as passed, or a WP_Error object * if no plugins were found. */ - public function check_package($source) { + public function check_package( $source ) { global $wp_filesystem; - if ( is_wp_error($source) ) + if ( is_wp_error( $source ) ) { return $source; + } - $working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit(WP_CONTENT_DIR), $source); - if ( ! is_dir($working_directory) ) // Sanity check, if the above fails, let's not prevent installation. + $working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit( WP_CONTENT_DIR ), $source ); + if ( ! is_dir( $working_directory ) ) { // Sanity check, if the above fails, let's not prevent installation. return $source; + } // Check the folder contains at least 1 valid plugin. $plugins_found = false; - $files = glob( $working_directory . '*.php' ); + $files = glob( $working_directory . '*.php' ); if ( $files ) { foreach ( $files as $file ) { $info = get_plugin_data( $file, false, false ); @@ -350,8 +365,9 @@ class Plugin_Upgrader extends WP_Upgrader { } } - if ( ! $plugins_found ) + if ( ! $plugins_found ) { return new WP_Error( 'incompatible_archive_no_plugins', $this->strings['incompatible_archive'], __( 'No valid plugins were found.' ) ); + } return $source; } @@ -366,16 +382,19 @@ class Plugin_Upgrader extends WP_Upgrader { * @return string|false The full path to the main plugin file, or false. */ public function plugin_info() { - if ( ! is_array($this->result) ) + if ( ! is_array( $this->result ) ) { return false; - if ( empty($this->result['destination_name']) ) + } + if ( empty( $this->result['destination_name'] ) ) { return false; + } - $plugin = get_plugins('/' . $this->result['destination_name']); //Ensure to pass with leading slash - if ( empty($plugin) ) + $plugin = get_plugins( '/' . $this->result['destination_name'] ); //Ensure to pass with leading slash + if ( empty( $plugin ) ) { return false; + } - $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list + $pluginfiles = array_keys( $plugin ); //Assume the requested plugin is the first in the list return $this->result['destination_name'] . '/' . $pluginfiles[0]; } @@ -392,22 +411,25 @@ class Plugin_Upgrader extends WP_Upgrader { * @param array $plugin Plugin package arguments. * @return bool|WP_Error The passed in $return param or WP_Error. */ - public function deactivate_plugin_before_upgrade($return, $plugin) { + public function deactivate_plugin_before_upgrade( $return, $plugin ) { - if ( is_wp_error($return) ) //Bypass. + if ( is_wp_error( $return ) ) { //Bypass. return $return; + } // When in cron (background updates) don't deactivate the plugin, as we require a browser to reactivate it - if ( wp_doing_cron() ) + if ( wp_doing_cron() ) { return $return; + } - $plugin = isset($plugin['plugin']) ? $plugin['plugin'] : ''; - if ( empty($plugin) ) - return new WP_Error('bad_request', $this->strings['bad_request']); + $plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : ''; + if ( empty( $plugin ) ) { + return new WP_Error( 'bad_request', $this->strings['bad_request'] ); + } - if ( is_plugin_active($plugin) ) { + if ( is_plugin_active( $plugin ) ) { //Deactivate the plugin silently, Prevent deactivation hooks from running. - deactivate_plugins($plugin, true); + deactivate_plugins( $plugin, true ); } return $return; @@ -422,37 +444,42 @@ class Plugin_Upgrader extends WP_Upgrader { * @since 2.8.0 * * @global WP_Filesystem_Base $wp_filesystem Subclass - * + * * @param bool|WP_Error $removed * @param string $local_destination * @param string $remote_destination * @param array $plugin * @return WP_Error|bool */ - public function delete_old_plugin($removed, $local_destination, $remote_destination, $plugin) { + public function delete_old_plugin( $removed, $local_destination, $remote_destination, $plugin ) { global $wp_filesystem; - if ( is_wp_error($removed) ) + if ( is_wp_error( $removed ) ) { return $removed; //Pass errors through. + } - $plugin = isset($plugin['plugin']) ? $plugin['plugin'] : ''; - if ( empty($plugin) ) - return new WP_Error('bad_request', $this->strings['bad_request']); + $plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : ''; + if ( empty( $plugin ) ) { + return new WP_Error( 'bad_request', $this->strings['bad_request'] ); + } - $plugins_dir = $wp_filesystem->wp_plugins_dir(); - $this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin) ); + $plugins_dir = $wp_filesystem->wp_plugins_dir(); + $this_plugin_dir = trailingslashit( dirname( $plugins_dir . $plugin ) ); - if ( ! $wp_filesystem->exists($this_plugin_dir) ) //If it's already vanished. + if ( ! $wp_filesystem->exists( $this_plugin_dir ) ) { //If it's already vanished. return $removed; + } // If plugin is in its own directory, recursively delete the directory. - if ( strpos($plugin, '/') && $this_plugin_dir != $plugins_dir ) //base check on if plugin includes directory separator AND that it's not the root plugin folder - $deleted = $wp_filesystem->delete($this_plugin_dir, true); - else - $deleted = $wp_filesystem->delete($plugins_dir . $plugin); + if ( strpos( $plugin, '/' ) && $this_plugin_dir != $plugins_dir ) { //base check on if plugin includes directory separator AND that it's not the root plugin folder + $deleted = $wp_filesystem->delete( $this_plugin_dir, true ); + } else { + $deleted = $wp_filesystem->delete( $plugins_dir . $plugin ); + } - if ( ! $deleted ) - return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']); + if ( ! $deleted ) { + return new WP_Error( 'remove_old_failed', $this->strings['remove_old_failed'] ); + } return true; } diff --git a/wp-admin/includes/class-theme-installer-skin.php b/wp-admin/includes/class-theme-installer-skin.php index 3d39492226..32302fea5d 100644 --- a/wp-admin/includes/class-theme-installer-skin.php +++ b/wp-admin/includes/class-theme-installer-skin.php @@ -20,53 +20,63 @@ class Theme_Installer_Skin extends WP_Upgrader_Skin { public $type; /** - * * @param array $args */ - public function __construct($args = array()) { - $defaults = array( 'type' => 'web', 'url' => '', 'theme' => '', 'nonce' => '', 'title' => '' ); - $args = wp_parse_args($args, $defaults); + public function __construct( $args = array() ) { + $defaults = array( + 'type' => 'web', + 'url' => '', + 'theme' => '', + 'nonce' => '', + 'title' => '', + ); + $args = wp_parse_args( $args, $defaults ); $this->type = $args['type']; - $this->api = isset($args['api']) ? $args['api'] : array(); + $this->api = isset( $args['api'] ) ? $args['api'] : array(); - parent::__construct($args); + parent::__construct( $args ); } /** */ public function before() { - if ( !empty($this->api) ) - $this->upgrader->strings['process_success'] = sprintf( $this->upgrader->strings['process_success_specific'], $this->api->name, $this->api->version); + if ( ! empty( $this->api ) ) { + $this->upgrader->strings['process_success'] = sprintf( $this->upgrader->strings['process_success_specific'], $this->api->name, $this->api->version ); + } } /** */ public function after() { - if ( empty($this->upgrader->result['destination_name']) ) + if ( empty( $this->upgrader->result['destination_name'] ) ) { return; + } $theme_info = $this->upgrader->theme_info(); - if ( empty( $theme_info ) ) + if ( empty( $theme_info ) ) { return; + } - $name = $theme_info->display('Name'); + $name = $theme_info->display( 'Name' ); $stylesheet = $this->upgrader->result['destination_name']; $template = $theme_info->get_template(); - $activate_link = add_query_arg( array( - 'action' => 'activate', - 'template' => urlencode( $template ), - 'stylesheet' => urlencode( $stylesheet ), - ), admin_url('themes.php') ); + $activate_link = add_query_arg( + array( + 'action' => 'activate', + 'template' => urlencode( $template ), + 'stylesheet' => urlencode( $stylesheet ), + ), admin_url( 'themes.php' ) + ); $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet ); $install_actions = array(); if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { - $customize_url = add_query_arg( + $customize_url = add_query_arg( array( - 'theme' => urlencode( $stylesheet ), + 'theme' => urlencode( $stylesheet ), 'return' => urlencode( admin_url( 'web' === $this->type ? 'theme-install.php' : 'themes.php' ) ), ), admin_url( 'customize.php' ) @@ -75,16 +85,19 @@ class Theme_Installer_Skin extends WP_Upgrader_Skin { } $install_actions['activate'] = '' . sprintf( __( 'Activate “%s”' ), $name ) . ''; - if ( is_network_admin() && current_user_can( 'manage_network_themes' ) ) + if ( is_network_admin() && current_user_can( 'manage_network_themes' ) ) { $install_actions['network_enable'] = '' . __( 'Network Enable' ) . ''; + } - if ( $this->type == 'web' ) + if ( $this->type == 'web' ) { $install_actions['themes_page'] = '' . __( 'Return to Theme Installer' ) . ''; - elseif ( current_user_can( 'switch_themes' ) || current_user_can( 'edit_theme_options' ) ) + } elseif ( current_user_can( 'switch_themes' ) || current_user_can( 'edit_theme_options' ) ) { $install_actions['themes_page'] = '' . __( 'Return to Themes page' ) . ''; + } - if ( ! $this->result || is_wp_error($this->result) || is_network_admin() || ! current_user_can( 'switch_themes' ) ) + if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() || ! current_user_can( 'switch_themes' ) ) { unset( $install_actions['activate'], $install_actions['preview'] ); + } /** * Filters the list of action links available following a single theme installation. @@ -97,7 +110,8 @@ class Theme_Installer_Skin extends WP_Upgrader_Skin { * @param WP_Theme $theme_info Theme object. */ $install_actions = apply_filters( 'install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info ); - if ( ! empty($install_actions) ) - $this->feedback(implode(' | ', (array)$install_actions)); + if ( ! empty( $install_actions ) ) { + $this->feedback( implode( ' | ', (array) $install_actions ) ); + } } } diff --git a/wp-admin/includes/class-theme-upgrader-skin.php b/wp-admin/includes/class-theme-upgrader-skin.php index f92375745f..b5f03017ca 100644 --- a/wp-admin/includes/class-theme-upgrader-skin.php +++ b/wp-admin/includes/class-theme-upgrader-skin.php @@ -19,16 +19,20 @@ class Theme_Upgrader_Skin extends WP_Upgrader_Skin { public $theme = ''; /** - * * @param array $args */ - public function __construct($args = array()) { - $defaults = array( 'url' => '', 'theme' => '', 'nonce' => '', 'title' => __('Update Theme') ); - $args = wp_parse_args($args, $defaults); + public function __construct( $args = array() ) { + $defaults = array( + 'url' => '', + 'theme' => '', + 'nonce' => '', + 'title' => __( 'Update Theme' ), + ); + $args = wp_parse_args( $args, $defaults ); $this->theme = $args['theme']; - parent::__construct($args); + parent::__construct( $args ); } /** @@ -38,27 +42,29 @@ class Theme_Upgrader_Skin extends WP_Upgrader_Skin { $update_actions = array(); if ( ! empty( $this->upgrader->result['destination_name'] ) && $theme_info = $this->upgrader->theme_info() ) { - $name = $theme_info->display('Name'); + $name = $theme_info->display( 'Name' ); $stylesheet = $this->upgrader->result['destination_name']; $template = $theme_info->get_template(); - $activate_link = add_query_arg( array( - 'action' => 'activate', - 'template' => urlencode( $template ), - 'stylesheet' => urlencode( $stylesheet ), - ), admin_url('themes.php') ); + $activate_link = add_query_arg( + array( + 'action' => 'activate', + 'template' => urlencode( $template ), + 'stylesheet' => urlencode( $stylesheet ), + ), admin_url( 'themes.php' ) + ); $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet ); $customize_url = add_query_arg( array( - 'theme' => urlencode( $stylesheet ), + 'theme' => urlencode( $stylesheet ), 'return' => urlencode( admin_url( 'themes.php' ) ), ), admin_url( 'customize.php' ) ); if ( get_stylesheet() == $stylesheet ) { if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { - $update_actions['preview'] = '' . sprintf( __( 'Customize “%s”' ), $name ) . ''; + $update_actions['preview'] = '' . sprintf( __( 'Customize “%s”' ), $name ) . ''; } } elseif ( current_user_can( 'switch_themes' ) ) { if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { @@ -67,8 +73,9 @@ class Theme_Upgrader_Skin extends WP_Upgrader_Skin { $update_actions['activate'] = '' . sprintf( __( 'Activate “%s”' ), $name ) . ''; } - if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() ) + if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() ) { unset( $update_actions['preview'], $update_actions['activate'] ); + } } $update_actions['themes_page'] = '' . __( 'Return to Themes page' ) . ''; @@ -83,7 +90,8 @@ class Theme_Upgrader_Skin extends WP_Upgrader_Skin { */ $update_actions = apply_filters( 'update_theme_complete_actions', $update_actions, $this->theme ); - if ( ! empty($update_actions) ) - $this->feedback(implode(' | ', (array)$update_actions)); + if ( ! empty( $update_actions ) ) { + $this->feedback( implode( ' | ', (array) $update_actions ) ); + } } } diff --git a/wp-admin/includes/class-theme-upgrader.php b/wp-admin/includes/class-theme-upgrader.php index 7e46b5f5a2..390398a8d4 100644 --- a/wp-admin/includes/class-theme-upgrader.php +++ b/wp-admin/includes/class-theme-upgrader.php @@ -43,15 +43,15 @@ class Theme_Upgrader extends WP_Upgrader { * @since 2.8.0 */ public function upgrade_strings() { - $this->strings['up_to_date'] = __('The theme is at the latest version.'); - $this->strings['no_package'] = __('Update package not available.'); + $this->strings['up_to_date'] = __( 'The theme is at the latest version.' ); + $this->strings['no_package'] = __( 'Update package not available.' ); /* translators: %s: package URL */ $this->strings['downloading_package'] = sprintf( __( 'Downloading update from %s…' ), '%s' ); - $this->strings['unpack_package'] = __('Unpacking the update…'); - $this->strings['remove_old'] = __('Removing the old version of the theme…'); - $this->strings['remove_old_failed'] = __('Could not remove the old theme.'); - $this->strings['process_failed'] = __('Theme update failed.'); - $this->strings['process_success'] = __('Theme updated successfully.'); + $this->strings['unpack_package'] = __( 'Unpacking the update…' ); + $this->strings['remove_old'] = __( 'Removing the old version of the theme…' ); + $this->strings['remove_old_failed'] = __( 'Could not remove the old theme.' ); + $this->strings['process_failed'] = __( 'Theme update failed.' ); + $this->strings['process_success'] = __( 'Theme updated successfully.' ); } /** @@ -60,23 +60,23 @@ class Theme_Upgrader extends WP_Upgrader { * @since 2.8.0 */ public function install_strings() { - $this->strings['no_package'] = __('Installation package not available.'); + $this->strings['no_package'] = __( 'Installation package not available.' ); /* translators: %s: package URL */ $this->strings['downloading_package'] = sprintf( __( 'Downloading installation package from %s…' ), '%s' ); - $this->strings['unpack_package'] = __('Unpacking the package…'); - $this->strings['installing_package'] = __('Installing the theme…'); - $this->strings['no_files'] = __('The theme contains no files.'); - $this->strings['process_failed'] = __('Theme installation failed.'); - $this->strings['process_success'] = __('Theme installed successfully.'); + $this->strings['unpack_package'] = __( 'Unpacking the package…' ); + $this->strings['installing_package'] = __( 'Installing the theme…' ); + $this->strings['no_files'] = __( 'The theme contains no files.' ); + $this->strings['process_failed'] = __( 'Theme installation failed.' ); + $this->strings['process_success'] = __( 'Theme installed successfully.' ); /* translators: 1: theme name, 2: version */ - $this->strings['process_success_specific'] = __('Successfully installed the theme %1$s %2$s.'); - $this->strings['parent_theme_search'] = __('This theme requires a parent theme. Checking if it is installed…'); + $this->strings['process_success_specific'] = __( 'Successfully installed the theme %1$s %2$s.' ); + $this->strings['parent_theme_search'] = __( 'This theme requires a parent theme. Checking if it is installed…' ); /* translators: 1: theme name, 2: version */ - $this->strings['parent_theme_prepare_install'] = __('Preparing to install %1$s %2$s…'); + $this->strings['parent_theme_prepare_install'] = __( 'Preparing to install %1$s %2$s…' ); /* translators: 1: theme name, 2: version */ - $this->strings['parent_theme_currently_installed'] = __('The parent theme, %1$s %2$s, is currently installed.'); + $this->strings['parent_theme_currently_installed'] = __( 'The parent theme, %1$s %2$s, is currently installed.' ); /* translators: 1: theme name, 2: version */ - $this->strings['parent_theme_install_success'] = __('Successfully installed the parent theme, %1$s %2$s.'); + $this->strings['parent_theme_install_success'] = __( 'Successfully installed the parent theme, %1$s %2$s.' ); /* translators: %s: theme name */ $this->strings['parent_theme_not_found'] = sprintf( __( 'The parent theme could not be found. You will need to install the parent theme, %s, before you can use this child theme.' ), '%s' ); } @@ -97,56 +97,68 @@ class Theme_Upgrader extends WP_Upgrader { // Check to see if we need to install a parent theme $theme_info = $this->theme_info(); - if ( ! $theme_info->parent() ) + if ( ! $theme_info->parent() ) { return $install_result; + } $this->skin->feedback( 'parent_theme_search' ); if ( ! $theme_info->parent()->errors() ) { - $this->skin->feedback( 'parent_theme_currently_installed', $theme_info->parent()->display('Name'), $theme_info->parent()->display('Version') ); + $this->skin->feedback( 'parent_theme_currently_installed', $theme_info->parent()->display( 'Name' ), $theme_info->parent()->display( 'Version' ) ); // We already have the theme, fall through. return $install_result; } // We don't have the parent theme, let's install it. - $api = themes_api('theme_information', array('slug' => $theme_info->get('Template'), 'fields' => array('sections' => false, 'tags' => false) ) ); //Save on a bit of bandwidth. + $api = themes_api( + 'theme_information', array( + 'slug' => $theme_info->get( 'Template' ), + 'fields' => array( + 'sections' => false, + 'tags' => false, + ), + ) + ); //Save on a bit of bandwidth. - if ( ! $api || is_wp_error($api) ) { - $this->skin->feedback( 'parent_theme_not_found', $theme_info->get('Template') ); + if ( ! $api || is_wp_error( $api ) ) { + $this->skin->feedback( 'parent_theme_not_found', $theme_info->get( 'Template' ) ); // Don't show activate or preview actions after installation - add_filter('install_theme_complete_actions', array($this, 'hide_activate_preview_actions') ); + add_filter( 'install_theme_complete_actions', array( $this, 'hide_activate_preview_actions' ) ); return $install_result; } // Backup required data we're going to override: - $child_api = $this->skin->api; + $child_api = $this->skin->api; $child_success_message = $this->strings['process_success']; // Override them - $this->skin->api = $api; + $this->skin->api = $api; $this->strings['process_success_specific'] = $this->strings['parent_theme_install_success'];//, $api->name, $api->version); - $this->skin->feedback('parent_theme_prepare_install', $api->name, $api->version); + $this->skin->feedback( 'parent_theme_prepare_install', $api->name, $api->version ); - add_filter('install_theme_complete_actions', '__return_false', 999); // Don't show any actions after installing the theme. + add_filter( 'install_theme_complete_actions', '__return_false', 999 ); // Don't show any actions after installing the theme. // Install the parent theme - $parent_result = $this->run( array( - 'package' => $api->download_link, - 'destination' => get_theme_root(), - 'clear_destination' => false, //Do not overwrite files. - 'clear_working' => true - ) ); + $parent_result = $this->run( + array( + 'package' => $api->download_link, + 'destination' => get_theme_root(), + 'clear_destination' => false, //Do not overwrite files. + 'clear_working' => true, + ) + ); - if ( is_wp_error($parent_result) ) - add_filter('install_theme_complete_actions', array($this, 'hide_activate_preview_actions') ); + if ( is_wp_error( $parent_result ) ) { + add_filter( 'install_theme_complete_actions', array( $this, 'hide_activate_preview_actions' ) ); + } // Start cleaning up after the parents installation - remove_filter('install_theme_complete_actions', '__return_false', 999); + remove_filter( 'install_theme_complete_actions', '__return_false', 999 ); // Reset child's result and data - $this->result = $child_result; - $this->skin->api = $child_api; + $this->result = $child_result; + $this->skin->api = $child_api; $this->strings['process_success'] = $child_success_message; return $install_result; @@ -165,7 +177,7 @@ class Theme_Upgrader extends WP_Upgrader { * @return array */ public function hide_activate_preview_actions( $actions ) { - unset($actions['activate'], $actions['preview']); + unset( $actions['activate'], $actions['preview'] ); return $actions; } @@ -187,7 +199,7 @@ class Theme_Upgrader extends WP_Upgrader { */ public function install( $package, $args = array() ) { - $defaults = array( + $defaults = array( 'clear_update_cache' => true, ); $parsed_args = wp_parse_args( $args, $defaults ); @@ -195,30 +207,33 @@ class Theme_Upgrader extends WP_Upgrader { $this->init(); $this->install_strings(); - add_filter('upgrader_source_selection', array($this, 'check_package') ); - add_filter('upgrader_post_install', array($this, 'check_parent_theme_filter'), 10, 3); + add_filter( 'upgrader_source_selection', array( $this, 'check_package' ) ); + add_filter( 'upgrader_post_install', array( $this, 'check_parent_theme_filter' ), 10, 3 ); if ( $parsed_args['clear_update_cache'] ) { // Clear cache so wp_update_themes() knows about the new theme. add_action( 'upgrader_process_complete', 'wp_clean_themes_cache', 9, 0 ); } - $this->run( array( - 'package' => $package, - 'destination' => get_theme_root(), - 'clear_destination' => false, //Do not overwrite files. - 'clear_working' => true, - 'hook_extra' => array( - 'type' => 'theme', - 'action' => 'install', - ), - ) ); + $this->run( + array( + 'package' => $package, + 'destination' => get_theme_root(), + 'clear_destination' => false, //Do not overwrite files. + 'clear_working' => true, + 'hook_extra' => array( + 'type' => 'theme', + 'action' => 'install', + ), + ) + ); remove_action( 'upgrader_process_complete', 'wp_clean_themes_cache', 9 ); - remove_filter('upgrader_source_selection', array($this, 'check_package') ); - remove_filter('upgrader_post_install', array($this, 'check_parent_theme_filter')); + remove_filter( 'upgrader_source_selection', array( $this, 'check_package' ) ); + remove_filter( 'upgrader_post_install', array( $this, 'check_parent_theme_filter' ) ); - if ( ! $this->result || is_wp_error($this->result) ) + if ( ! $this->result || is_wp_error( $this->result ) ) { return $this->result; + } // Refresh the Theme Update information wp_clean_themes_cache( $parsed_args['clear_update_cache'] ); @@ -243,7 +258,7 @@ class Theme_Upgrader extends WP_Upgrader { */ public function upgrade( $theme, $args = array() ) { - $defaults = array( + $defaults = array( 'clear_update_cache' => true, ); $parsed_args = wp_parse_args( $args, $defaults ); @@ -253,9 +268,9 @@ class Theme_Upgrader extends WP_Upgrader { // Is an update available? $current = get_site_transient( 'update_themes' ); - if ( !isset( $current->response[ $theme ] ) ) { + if ( ! isset( $current->response[ $theme ] ) ) { $this->skin->before(); - $this->skin->set_result(false); + $this->skin->set_result( false ); $this->skin->error( 'up_to_date' ); $this->skin->after(); return false; @@ -263,33 +278,36 @@ class Theme_Upgrader extends WP_Upgrader { $r = $current->response[ $theme ]; - add_filter('upgrader_pre_install', array($this, 'current_before'), 10, 2); - add_filter('upgrader_post_install', array($this, 'current_after'), 10, 2); - add_filter('upgrader_clear_destination', array($this, 'delete_old_theme'), 10, 4); + add_filter( 'upgrader_pre_install', array( $this, 'current_before' ), 10, 2 ); + add_filter( 'upgrader_post_install', array( $this, 'current_after' ), 10, 2 ); + add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_theme' ), 10, 4 ); if ( $parsed_args['clear_update_cache'] ) { // Clear cache so wp_update_themes() knows about the new theme. add_action( 'upgrader_process_complete', 'wp_clean_themes_cache', 9, 0 ); } - $this->run( array( - 'package' => $r['package'], - 'destination' => get_theme_root( $theme ), - 'clear_destination' => true, - 'clear_working' => true, - 'hook_extra' => array( - 'theme' => $theme, - 'type' => 'theme', - 'action' => 'update', - ), - ) ); + $this->run( + array( + 'package' => $r['package'], + 'destination' => get_theme_root( $theme ), + 'clear_destination' => true, + 'clear_working' => true, + 'hook_extra' => array( + 'theme' => $theme, + 'type' => 'theme', + 'action' => 'update', + ), + ) + ); remove_action( 'upgrader_process_complete', 'wp_clean_themes_cache', 9 ); - remove_filter('upgrader_pre_install', array($this, 'current_before')); - remove_filter('upgrader_post_install', array($this, 'current_after')); - remove_filter('upgrader_clear_destination', array($this, 'delete_old_theme')); + remove_filter( 'upgrader_pre_install', array( $this, 'current_before' ) ); + remove_filter( 'upgrader_post_install', array( $this, 'current_after' ) ); + remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_theme' ) ); - if ( ! $this->result || is_wp_error($this->result) ) + if ( ! $this->result || is_wp_error( $this->result ) ) { return $this->result; + } wp_clean_themes_cache( $parsed_args['clear_update_cache'] ); @@ -313,7 +331,7 @@ class Theme_Upgrader extends WP_Upgrader { */ public function bulk_upgrade( $themes, $args = array() ) { - $defaults = array( + $defaults = array( 'clear_update_cache' => true, ); $parsed_args = wp_parse_args( $args, $defaults ); @@ -324,14 +342,14 @@ class Theme_Upgrader extends WP_Upgrader { $current = get_site_transient( 'update_themes' ); - add_filter('upgrader_pre_install', array($this, 'current_before'), 10, 2); - add_filter('upgrader_post_install', array($this, 'current_after'), 10, 2); - add_filter('upgrader_clear_destination', array($this, 'delete_old_theme'), 10, 4); + add_filter( 'upgrader_pre_install', array( $this, 'current_before' ), 10, 2 ); + add_filter( 'upgrader_post_install', array( $this, 'current_after' ), 10, 2 ); + add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_theme' ), 10, 4 ); $this->skin->header(); // Connect to the Filesystem first. - $res = $this->fs_connect( array(WP_CONTENT_DIR) ); + $res = $this->fs_connect( array( WP_CONTENT_DIR ) ); if ( ! $res ) { $this->skin->footer(); return false; @@ -344,71 +362,78 @@ class Theme_Upgrader extends WP_Upgrader { // - a theme with an update available is currently in use. // @TODO: For multisite, maintenance mode should only kick in for individual sites if at all possible. $maintenance = ( is_multisite() && ! empty( $themes ) ); - foreach ( $themes as $theme ) + foreach ( $themes as $theme ) { $maintenance = $maintenance || $theme == get_stylesheet() || $theme == get_template(); - if ( $maintenance ) - $this->maintenance_mode(true); + } + if ( $maintenance ) { + $this->maintenance_mode( true ); + } $results = array(); - $this->update_count = count($themes); + $this->update_count = count( $themes ); $this->update_current = 0; foreach ( $themes as $theme ) { $this->update_current++; - $this->skin->theme_info = $this->theme_info($theme); + $this->skin->theme_info = $this->theme_info( $theme ); - if ( !isset( $current->response[ $theme ] ) ) { - $this->skin->set_result(true); + if ( ! isset( $current->response[ $theme ] ) ) { + $this->skin->set_result( true ); $this->skin->before(); $this->skin->feedback( 'up_to_date' ); $this->skin->after(); - $results[$theme] = true; + $results[ $theme ] = true; continue; } // Get the URL to the zip file $r = $current->response[ $theme ]; - $result = $this->run( array( - 'package' => $r['package'], - 'destination' => get_theme_root( $theme ), - 'clear_destination' => true, - 'clear_working' => true, - 'is_multi' => true, - 'hook_extra' => array( - 'theme' => $theme - ), - ) ); + $result = $this->run( + array( + 'package' => $r['package'], + 'destination' => get_theme_root( $theme ), + 'clear_destination' => true, + 'clear_working' => true, + 'is_multi' => true, + 'hook_extra' => array( + 'theme' => $theme, + ), + ) + ); - $results[$theme] = $this->result; + $results[ $theme ] = $this->result; // Prevent credentials auth screen from displaying multiple times - if ( false === $result ) + if ( false === $result ) { break; + } } //end foreach $plugins - $this->maintenance_mode(false); + $this->maintenance_mode( false ); // Refresh the Theme Update information wp_clean_themes_cache( $parsed_args['clear_update_cache'] ); /** This action is documented in wp-admin/includes/class-wp-upgrader.php */ - do_action( 'upgrader_process_complete', $this, array( - 'action' => 'update', - 'type' => 'theme', - 'bulk' => true, - 'themes' => $themes, - ) ); + do_action( + 'upgrader_process_complete', $this, array( + 'action' => 'update', + 'type' => 'theme', + 'bulk' => true, + 'themes' => $themes, + ) + ); $this->skin->bulk_footer(); $this->skin->footer(); // Cleanup our hooks, in case something else does a upgrade on this connection. - remove_filter('upgrader_pre_install', array($this, 'current_before')); - remove_filter('upgrader_post_install', array($this, 'current_after')); - remove_filter('upgrader_clear_destination', array($this, 'delete_old_theme')); + remove_filter( 'upgrader_pre_install', array( $this, 'current_before' ) ); + remove_filter( 'upgrader_post_install', array( $this, 'current_after' ) ); + remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_theme' ) ); return $results; } @@ -430,30 +455,41 @@ class Theme_Upgrader extends WP_Upgrader { public function check_package( $source ) { global $wp_filesystem; - if ( is_wp_error($source) ) + if ( is_wp_error( $source ) ) { return $source; + } // Check the folder contains a valid theme - $working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit(WP_CONTENT_DIR), $source); - if ( ! is_dir($working_directory) ) // Sanity check, if the above fails, let's not prevent installation. + $working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit( WP_CONTENT_DIR ), $source ); + if ( ! is_dir( $working_directory ) ) { // Sanity check, if the above fails, let's not prevent installation. return $source; + } // A proper archive should have a style.css file in the single subdirectory if ( ! file_exists( $working_directory . 'style.css' ) ) { - return new WP_Error( 'incompatible_archive_theme_no_style', $this->strings['incompatible_archive'], + return new WP_Error( + 'incompatible_archive_theme_no_style', $this->strings['incompatible_archive'], /* translators: %s: style.css */ - sprintf( __( 'The theme is missing the %s stylesheet.' ), + sprintf( + __( 'The theme is missing the %s stylesheet.' ), 'style.css' ) ); } - $info = get_file_data( $working_directory . 'style.css', array( 'Name' => 'Theme Name', 'Template' => 'Template' ) ); + $info = get_file_data( + $working_directory . 'style.css', array( + 'Name' => 'Theme Name', + 'Template' => 'Template', + ) + ); if ( empty( $info['Name'] ) ) { - return new WP_Error( 'incompatible_archive_theme_no_name', $this->strings['incompatible_archive'], + return new WP_Error( + 'incompatible_archive_theme_no_name', $this->strings['incompatible_archive'], /* translators: %s: style.css */ - sprintf( __( 'The %s stylesheet doesn’t contain a valid theme header.' ), + sprintf( + __( 'The %s stylesheet doesn’t contain a valid theme header.' ), 'style.css' ) ); @@ -461,9 +497,11 @@ class Theme_Upgrader extends WP_Upgrader { // If it's not a child theme, it must have at least an index.php to be legit. if ( empty( $info['Template'] ) && ! file_exists( $working_directory . 'index.php' ) ) { - return new WP_Error( 'incompatible_archive_theme_no_index', $this->strings['incompatible_archive'], + return new WP_Error( + 'incompatible_archive_theme_no_index', $this->strings['incompatible_archive'], /* translators: %s: index.php */ - sprintf( __( 'The theme is missing the %s file.' ), + sprintf( + __( 'The theme is missing the %s file.' ), 'index.php' ) ); @@ -484,17 +522,20 @@ class Theme_Upgrader extends WP_Upgrader { * @param array $theme * @return bool|WP_Error */ - public function current_before($return, $theme) { - if ( is_wp_error($return) ) + public function current_before( $return, $theme ) { + if ( is_wp_error( $return ) ) { return $return; + } - $theme = isset($theme['theme']) ? $theme['theme'] : ''; + $theme = isset( $theme['theme'] ) ? $theme['theme'] : ''; - if ( $theme != get_stylesheet() ) //If not current + if ( $theme != get_stylesheet() ) { //If not current return $return; + } //Change to maintenance mode now. - if ( ! $this->bulk ) - $this->maintenance_mode(true); + if ( ! $this->bulk ) { + $this->maintenance_mode( true ); + } return $return; } @@ -511,14 +552,16 @@ class Theme_Upgrader extends WP_Upgrader { * @param array $theme * @return bool|WP_Error */ - public function current_after($return, $theme) { - if ( is_wp_error($return) ) + public function current_after( $return, $theme ) { + if ( is_wp_error( $return ) ) { return $return; + } - $theme = isset($theme['theme']) ? $theme['theme'] : ''; + $theme = isset( $theme['theme'] ) ? $theme['theme'] : ''; - if ( $theme != get_stylesheet() ) // If not current + if ( $theme != get_stylesheet() ) { // If not current return $return; + } // Ensure stylesheet name hasn't changed after the upgrade: if ( $theme == get_stylesheet() && $theme != $this->result['destination_name'] ) { @@ -528,8 +571,9 @@ class Theme_Upgrader extends WP_Upgrader { } //Time to remove maintenance mode - if ( ! $this->bulk ) - $this->maintenance_mode(false); + if ( ! $this->bulk ) { + $this->maintenance_mode( false ); + } return $return; } @@ -552,17 +596,20 @@ class Theme_Upgrader extends WP_Upgrader { public function delete_old_theme( $removed, $local_destination, $remote_destination, $theme ) { global $wp_filesystem; - if ( is_wp_error( $removed ) ) + if ( is_wp_error( $removed ) ) { return $removed; // Pass errors through. + } - if ( ! isset( $theme['theme'] ) ) + if ( ! isset( $theme['theme'] ) ) { return $removed; + } - $theme = $theme['theme']; + $theme = $theme['theme']; $themes_dir = trailingslashit( $wp_filesystem->wp_themes_dir( $theme ) ); if ( $wp_filesystem->exists( $themes_dir . $theme ) ) { - if ( ! $wp_filesystem->delete( $themes_dir . $theme, true ) ) + if ( ! $wp_filesystem->delete( $themes_dir . $theme, true ) ) { return false; + } } return true; @@ -579,13 +626,14 @@ class Theme_Upgrader extends WP_Upgrader { * @return WP_Theme|false The theme's info object, or false `$theme` is not supplied * and the last result isn't set. */ - public function theme_info($theme = null) { + public function theme_info( $theme = null ) { - if ( empty($theme) ) { - if ( !empty($this->result['destination_name']) ) + if ( empty( $theme ) ) { + if ( ! empty( $this->result['destination_name'] ) ) { $theme = $this->result['destination_name']; - else + } else { return false; + } } return wp_get_theme( $theme ); } diff --git a/wp-admin/includes/class-walker-category-checklist.php b/wp-admin/includes/class-walker-category-checklist.php index cd5e1572c6..d8719debf4 100644 --- a/wp-admin/includes/class-walker-category-checklist.php +++ b/wp-admin/includes/class-walker-category-checklist.php @@ -18,7 +18,10 @@ */ class Walker_Category_Checklist extends Walker { public $tree_type = 'category'; - public $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this + public $db_fields = array( + 'parent' => 'parent', + 'id' => 'term_id', + ); //TODO: decouple this /** * Starts the list before the elements are added. @@ -32,7 +35,7 @@ class Walker_Category_Checklist extends Walker { * @param array $args An array of arguments. @see wp_terms_checklist() */ public function start_lvl( &$output, $depth = 0, $args = array() ) { - $indent = str_repeat("\t", $depth); + $indent = str_repeat( "\t", $depth ); $output .= "$indent
    \n"; } @@ -48,7 +51,7 @@ class Walker_Category_Checklist extends Walker { * @param array $args An array of arguments. @see wp_terms_checklist() */ public function end_lvl( &$output, $depth = 0, $args = array() ) { - $indent = str_repeat("\t", $depth); + $indent = str_repeat( "\t", $depth ); $output .= "$indent
\n"; } @@ -79,13 +82,13 @@ class Walker_Category_Checklist extends Walker { } $args['popular_cats'] = empty( $args['popular_cats'] ) ? array() : $args['popular_cats']; - $class = in_array( $category->term_id, $args['popular_cats'] ) ? ' class="popular-category"' : ''; + $class = in_array( $category->term_id, $args['popular_cats'] ) ? ' class="popular-category"' : ''; $args['selected_cats'] = empty( $args['selected_cats'] ) ? array() : $args['selected_cats']; if ( ! empty( $args['list_only'] ) ) { $aria_checked = 'false'; - $inner_class = 'category'; + $inner_class = 'category'; if ( in_array( $category->term_id, $args['selected_cats'] ) ) { $inner_class .= ' selected'; @@ -100,7 +103,7 @@ class Walker_Category_Checklist extends Walker { } else { /** This filter is documented in wp-includes/category-template.php */ $output .= "\n
  • " . - ''; diff --git a/wp-admin/includes/class-walker-nav-menu-checklist.php b/wp-admin/includes/class-walker-nav-menu-checklist.php index a4d8018dcc..881e9e7192 100644 --- a/wp-admin/includes/class-walker-nav-menu-checklist.php +++ b/wp-admin/includes/class-walker-nav-menu-checklist.php @@ -15,7 +15,6 @@ */ class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu { /** - * * @param array $fields */ public function __construct( $fields = false ) { @@ -36,7 +35,7 @@ class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu { * @param array $args Not used. */ public function start_lvl( &$output, $depth = 0, $args = array() ) { - $indent = str_repeat( "\t", $depth ); + $indent = str_repeat( "\t", $depth ); $output .= "\n$indent
      \n"; } @@ -52,7 +51,7 @@ class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu { * @param array $args Not used. */ public function end_lvl( &$output, $depth = 0, $args = array() ) { - $indent = str_repeat( "\t", $depth ); + $indent = str_repeat( "\t", $depth ); $output .= "\n$indent
    "; } @@ -74,9 +73,9 @@ class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu { public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { global $_nav_menu_placeholder; - $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1; - $possible_object_id = isset( $item->post_type ) && 'nav_menu_item' == $item->post_type ? $item->object_id : $_nav_menu_placeholder; - $possible_db_id = ( ! empty( $item->ID ) ) && ( 0 < $possible_object_id ) ? (int) $item->ID : 0; + $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval( $_nav_menu_placeholder ) - 1 : -1; + $possible_object_id = isset( $item->post_type ) && 'nav_menu_item' == $item->post_type ? $item->object_id : $_nav_menu_placeholder; + $possible_db_id = ( ! empty( $item->ID ) ) && ( 0 < $possible_object_id ) ? (int) $item->ID : 0; $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; @@ -84,34 +83,36 @@ class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu { $output .= ''; + $output .= ''; // Menu item hidden fields $output .= ''; - $output .= ''; - $output .= ''; - $output .= ''; - $output .= ''; - $output .= ''; - $output .= ''; - $output .= ''; - $output .= ''; - $output .= ''; + $output .= ''; + $output .= ''; + $output .= ''; + $output .= ''; + $output .= ''; + $output .= ''; + $output .= ''; + $output .= ''; + $output .= ''; } } // Walker_Nav_Menu_Checklist diff --git a/wp-admin/includes/class-walker-nav-menu-edit.php b/wp-admin/includes/class-walker-nav-menu-edit.php index 36ced4034d..d53c0c8988 100644 --- a/wp-admin/includes/class-walker-nav-menu-edit.php +++ b/wp-admin/includes/class-walker-nav-menu-edit.php @@ -60,7 +60,7 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu { $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth; ob_start(); - $item_id = esc_attr( $item->ID ); + $item_id = esc_attr( $item->ID ); $removed_args = array( 'action', 'customlink-tab', @@ -73,11 +73,12 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu { $original_title = false; if ( 'taxonomy' == $item->type ) { $original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' ); - if ( is_wp_error( $original_title ) ) + if ( is_wp_error( $original_title ) ) { $original_title = false; + } } elseif ( 'post_type' == $item->type ) { $original_object = get_post( $item->object_id ); - $original_title = get_the_title( $original_object->ID ); + $original_title = get_the_title( $original_object->ID ); } elseif ( 'post_type_archive' == $item->type ) { $original_object = get_post_type_object( $item->object ); if ( $original_object ) { @@ -88,7 +89,7 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu { $classes = array( 'menu-item menu-item-depth-' . $depth, 'menu-item-' . esc_attr( $item->object ), - 'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'), + 'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive' ), ); $title = $item->title; @@ -100,52 +101,59 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu { } elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) { $classes[] = 'pending'; /* translators: %s: title of menu item in draft status */ - $title = sprintf( __('%s (Pending)'), $item->title ); + $title = sprintf( __( '%s (Pending)' ), $item->title ); } $title = ( ! isset( $item->label ) || '' == $item->label ) ? $title : $item->label; $submenu_text = ''; - if ( 0 == $depth ) + if ( 0 == $depth ) { $submenu_text = 'style="display: none;"'; + } ?> -
  • @@ -590,7 +611,15 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
    - $plugin['rating'], 'type' => 'percent', 'number' => $plugin['num_ratings'] ) ); ?> + $plugin['rating'], + 'type' => 'percent', + 'number' => $plugin['num_ratings'], + ) + ); +?>
    diff --git a/wp-admin/includes/class-wp-plugins-list-table.php b/wp-admin/includes/class-wp-plugins-list-table.php index cbd9eed838..4ae764547a 100644 --- a/wp-admin/includes/class-wp-plugins-list-table.php +++ b/wp-admin/includes/class-wp-plugins-list-table.php @@ -32,17 +32,21 @@ class WP_Plugins_List_Table extends WP_List_Table { public function __construct( $args = array() ) { global $status, $page; - parent::__construct( array( - 'plural' => 'plugins', - 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, - ) ); + parent::__construct( + array( + 'plural' => 'plugins', + 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, + ) + ); $status = 'all'; - if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search' ) ) ) + if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search' ) ) ) { $status = $_REQUEST['plugin_status']; + } - if ( isset($_REQUEST['s']) ) - $_SERVER['REQUEST_URI'] = add_query_arg('s', wp_unslash($_REQUEST['s']) ); + if ( isset( $_REQUEST['s'] ) ) { + $_SERVER['REQUEST_URI'] = add_query_arg( 's', wp_unslash( $_REQUEST['s'] ) ); + } $page = $this->get_pagenum(); } @@ -58,11 +62,10 @@ class WP_Plugins_List_Table extends WP_List_Table { * @return bool */ public function ajax_user_can() { - return current_user_can('activate_plugins'); + return current_user_can( 'activate_plugins' ); } /** - * * @global string $status * @global array $plugins * @global array $totals @@ -122,15 +125,16 @@ class WP_Plugins_List_Table extends WP_List_Table { } /** This action is documented in wp-admin/includes/class-wp-plugins-list-table.php */ - if ( apply_filters( 'show_advanced_plugins', true, 'dropins' ) ) + if ( apply_filters( 'show_advanced_plugins', true, 'dropins' ) ) { $plugins['dropins'] = get_dropins(); + } if ( current_user_can( 'update_plugins' ) ) { $current = get_site_transient( 'update_plugins' ); foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) { if ( isset( $current->response[ $plugin_file ] ) ) { $plugins['all'][ $plugin_file ]['update'] = true; - $plugins['upgrade'][ $plugin_file ] = $plugins['all'][ $plugin_file ]; + $plugins['upgrade'][ $plugin_file ] = $plugins['all'][ $plugin_file ]; } } } @@ -164,7 +168,7 @@ class WP_Plugins_List_Table extends WP_List_Table { foreach ( $recently_activated as $key => $time ) { if ( $time + WEEK_IN_SECONDS < time() ) { - unset( $recently_activated[$key] ); + unset( $recently_activated[ $key ] ); } } @@ -184,7 +188,6 @@ class WP_Plugins_List_Table extends WP_List_Table { if ( isset( $plugins['upgrade'][ $plugin_file ] ) ) { $plugins['upgrade'][ $plugin_file ] = $plugin_data = array_merge( (array) $plugin_info->response[ $plugin_file ], $plugin_data ); } - } elseif ( isset( $plugin_info->no_update[ $plugin_file ] ) ) { $plugins['all'][ $plugin_file ] = $plugin_data = array_merge( (array) $plugin_info->no_update[ $plugin_file ], $plugin_data ); // Make sure that $plugins['upgrade'] also receives the extra info since it is used on ?plugin_status=upgrade @@ -226,21 +229,23 @@ class WP_Plugins_List_Table extends WP_List_Table { } if ( strlen( $s ) ) { - $status = 'search'; + $status = 'search'; $plugins['search'] = array_filter( $plugins['all'], array( $this, '_search_callback' ) ); } $totals = array(); - foreach ( $plugins as $type => $list ) + foreach ( $plugins as $type => $list ) { $totals[ $type ] = count( $list ); + } - if ( empty( $plugins[ $status ] ) && !in_array( $status, array( 'all', 'search' ) ) ) + if ( empty( $plugins[ $status ] ) && ! in_array( $status, array( 'all', 'search' ) ) ) { $status = 'all'; + } $this->items = array(); foreach ( $plugins[ $status ] as $plugin_file => $plugin_data ) { // Translate, Don't Apply Markup, Sanitize HTML - $this->items[$plugin_file] = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, false, true ); + $this->items[ $plugin_file ] = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, false, true ); } $total_this_page = $totals[ $status ]; @@ -250,10 +255,12 @@ class WP_Plugins_List_Table extends WP_List_Table { $js_plugins[ $key ] = array_keys( (array) $list ); } - wp_localize_script( 'updates', '_wpUpdatesItemCounts', array( - 'plugins' => $js_plugins, - 'totals' => wp_get_update_data(), - ) ); + wp_localize_script( + 'updates', '_wpUpdatesItemCounts', array( + 'plugins' => $js_plugins, + 'totals' => wp_get_update_data(), + ) + ); if ( ! $orderby ) { $orderby = 'Name'; @@ -269,13 +276,16 @@ class WP_Plugins_List_Table extends WP_List_Table { $start = ( $page - 1 ) * $plugins_per_page; - if ( $total_this_page > $plugins_per_page ) + if ( $total_this_page > $plugins_per_page ) { $this->items = array_slice( $this->items, $start, $plugins_per_page ); + } - $this->set_pagination_args( array( - 'total_items' => $total_this_page, - 'per_page' => $plugins_per_page, - ) ); + $this->set_pagination_args( + array( + 'total_items' => $total_this_page, + 'per_page' => $plugins_per_page, + ) + ); } /** @@ -306,11 +316,12 @@ class WP_Plugins_List_Table extends WP_List_Table { public function _order_callback( $plugin_a, $plugin_b ) { global $orderby, $order; - $a = $plugin_a[$orderby]; - $b = $plugin_b[$orderby]; + $a = $plugin_a[ $orderby ]; + $b = $plugin_b[ $orderby ]; - if ( $a == $b ) + if ( $a == $b ) { return 0; + } if ( 'DESC' === $order ) { return strcasecmp( $b, $a ); @@ -320,7 +331,6 @@ class WP_Plugins_List_Table extends WP_List_Table { } /** - * * @global array $plugins */ public function no_items() { @@ -335,10 +345,11 @@ class WP_Plugins_List_Table extends WP_List_Table { if ( ! is_multisite() && current_user_can( 'install_plugins' ) ) { echo ' ' . __( 'Search for plugins in the WordPress Plugin Directory.' ) . ''; } - } elseif ( ! empty( $plugins['all'] ) ) + } elseif ( ! empty( $plugins['all'] ) ) { _e( 'No plugins found.' ); - else + } else { _e( 'You do not appear to have any plugins available at this time.' ); + } } /** @@ -372,7 +383,6 @@ class WP_Plugins_List_Table extends WP_List_Table { } /** - * * @global string $status * @return array */ @@ -380,7 +390,7 @@ class WP_Plugins_List_Table extends WP_List_Table { global $status; return array( - 'cb' => !in_array( $status, array( 'mustuse', 'dropins' ) ) ? '' : '', + 'cb' => ! in_array( $status, array( 'mustuse', 'dropins' ) ) ? '' : '', 'name' => __( 'Plugin' ), 'description' => __( 'Description' ), ); @@ -394,7 +404,6 @@ class WP_Plugins_List_Table extends WP_List_Table { } /** - * * @global array $totals * @global string $status * @return array @@ -404,8 +413,9 @@ class WP_Plugins_List_Table extends WP_List_Table { $status_links = array(); foreach ( $totals as $type => $count ) { - if ( !$count ) + if ( ! $count ) { continue; + } switch ( $type ) { case 'all': @@ -432,11 +442,12 @@ class WP_Plugins_List_Table extends WP_List_Table { } if ( 'search' !== $type ) { - $status_links[$type] = sprintf( "%s", - add_query_arg('plugin_status', $type, 'plugins.php'), + $status_links[ $type ] = sprintf( + "%s", + add_query_arg( 'plugin_status', $type, 'plugins.php' ), ( $type === $status ) ? ' class="current" aria-current="page"' : '', sprintf( $text, number_format_i18n( $count ) ) - ); + ); } } @@ -444,7 +455,6 @@ class WP_Plugins_List_Table extends WP_List_Table { } /** - * * @global string $status * @return array */ @@ -453,17 +463,21 @@ class WP_Plugins_List_Table extends WP_List_Table { $actions = array(); - if ( 'active' != $status ) + if ( 'active' != $status ) { $actions['activate-selected'] = $this->screen->in_admin( 'network' ) ? __( 'Network Activate' ) : __( 'Activate' ); + } - if ( 'inactive' != $status && 'recent' != $status ) + if ( 'inactive' != $status && 'recent' != $status ) { $actions['deactivate-selected'] = $this->screen->in_admin( 'network' ) ? __( 'Network Deactivate' ) : __( 'Deactivate' ); + } - if ( !is_multisite() || $this->screen->in_admin( 'network' ) ) { - if ( current_user_can( 'update_plugins' ) ) + if ( ! is_multisite() || $this->screen->in_admin( 'network' ) ) { + if ( current_user_can( 'update_plugins' ) ) { $actions['update-selected'] = __( 'Update' ); - if ( current_user_can( 'delete_plugins' ) && ( 'active' != $status ) ) + } + if ( current_user_can( 'delete_plugins' ) && ( 'active' != $status ) ) { $actions['delete-selected'] = __( 'Delete' ); + } } return $actions; @@ -476,8 +490,9 @@ class WP_Plugins_List_Table extends WP_List_Table { public function bulk_actions( $which = '' ) { global $status; - if ( in_array( $status, array( 'mustuse', 'dropins' ) ) ) + if ( in_array( $status, array( 'mustuse', 'dropins' ) ) ) { return; + } parent::bulk_actions( $which ); } @@ -489,8 +504,9 @@ class WP_Plugins_List_Table extends WP_List_Table { protected function extra_tablenav( $which ) { global $status; - if ( ! in_array($status, array('recently_activated', 'mustuse', 'dropins') ) ) + if ( ! in_array( $status, array( 'recently_activated', 'mustuse', 'dropins' ) ) ) { return; + } echo '
    '; @@ -498,12 +514,14 @@ class WP_Plugins_List_Table extends WP_List_Table { submit_button( __( 'Clear List' ), '', 'clear-recent-list', false ); } elseif ( 'top' === $which && 'mustuse' === $status ) { /* translators: %s: mu-plugins directory name */ - echo '

    ' . sprintf( __( 'Files in the %s directory are executed automatically.' ), + echo '

    ' . sprintf( + __( 'Files in the %s directory are executed automatically.' ), '' . str_replace( ABSPATH, '/', WPMU_PLUGIN_DIR ) . '' ) . '

    '; } elseif ( 'top' === $which && 'dropins' === $status ) { /* translators: %s: wp-content directory name */ - echo '

    ' . sprintf( __( 'Drop-ins are advanced plugins in the %s directory that replace WordPress functionality when present.' ), + echo '

    ' . sprintf( + __( 'Drop-ins are advanced plugins in the %s directory that replace WordPress functionality when present.' ), '' . str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '' ) . '

    '; } @@ -514,24 +532,26 @@ class WP_Plugins_List_Table extends WP_List_Table { * @return string */ public function current_action() { - if ( isset($_POST['clear-recent-list']) ) + if ( isset( $_POST['clear-recent-list'] ) ) { return 'clear-recent-list'; + } return parent::current_action(); } /** - * * @global string $status */ public function display_rows() { global $status; - if ( is_multisite() && ! $this->screen->in_admin( 'network' ) && in_array( $status, array( 'mustuse', 'dropins' ) ) ) + if ( is_multisite() && ! $this->screen->in_admin( 'network' ) && in_array( $status, array( 'mustuse', 'dropins' ) ) ) { return; + } - foreach ( $this->items as $plugin_file => $plugin_data ) + foreach ( $this->items as $plugin_file => $plugin_data ) { $this->single_row( array( $plugin_file, $plugin_data ) ); + } } /** @@ -546,52 +566,55 @@ class WP_Plugins_List_Table extends WP_List_Table { global $status, $page, $s, $totals; list( $plugin_file, $plugin_data ) = $item; - $context = $status; - $screen = $this->screen; + $context = $status; + $screen = $this->screen; // Pre-order. $actions = array( 'deactivate' => '', - 'activate' => '', - 'details' => '', - 'delete' => '', + 'activate' => '', + 'details' => '', + 'delete' => '', ); // Do not restrict by default $restrict_network_active = false; - $restrict_network_only = false; + $restrict_network_only = false; if ( 'mustuse' === $context ) { $is_active = true; } elseif ( 'dropins' === $context ) { - $dropins = _get_dropins(); + $dropins = _get_dropins(); $plugin_name = $plugin_file; - if ( $plugin_file != $plugin_data['Name'] ) + if ( $plugin_file != $plugin_data['Name'] ) { $plugin_name .= '
    ' . $plugin_data['Name']; + } if ( true === ( $dropins[ $plugin_file ][1] ) ) { // Doesn't require a constant - $is_active = true; + $is_active = true; $description = '

    ' . $dropins[ $plugin_file ][0] . '

    '; } elseif ( defined( $dropins[ $plugin_file ][1] ) && constant( $dropins[ $plugin_file ][1] ) ) { // Constant is true - $is_active = true; + $is_active = true; $description = '

    ' . $dropins[ $plugin_file ][0] . '

    '; } else { - $is_active = false; + $is_active = false; $description = '

    ' . $dropins[ $plugin_file ][0] . ' ' . __( 'Inactive:' ) . ' ' . /* translators: 1: drop-in constant name, 2: wp-config.php */ - sprintf( __( 'Requires %1$s in %2$s file.' ), + sprintf( + __( 'Requires %1$s in %2$s file.' ), "define('" . $dropins[ $plugin_file ][1] . "', true);", 'wp-config.php' ) . '

    '; } - if ( $plugin_data['Description'] ) + if ( $plugin_data['Description'] ) { $description .= '

    ' . $plugin_data['Description'] . '

    '; + } } else { if ( $screen->in_admin( 'network' ) ) { $is_active = is_plugin_active_for_network( $plugin_file ); } else { - $is_active = is_plugin_active( $plugin_file ); + $is_active = is_plugin_active( $plugin_file ); $restrict_network_active = ( is_multisite() && is_plugin_active_for_network( $plugin_file ) ); - $restrict_network_only = ( is_multisite() && is_network_only_plugin( $plugin_file ) && ! $is_active ); + $restrict_network_only = ( is_multisite() && is_network_only_plugin( $plugin_file ) && ! $is_active ); } if ( $screen->in_admin( 'network' ) ) { @@ -599,7 +622,7 @@ class WP_Plugins_List_Table extends WP_List_Table { if ( current_user_can( 'manage_network_plugins' ) ) { /* translators: %s: plugin name */ $actions['deactivate'] = '' . __( 'Network Deactivate' ) . ''; - } + } } else { if ( current_user_can( 'manage_network_plugins' ) ) { /* translators: %s: plugin name */ @@ -635,9 +658,7 @@ class WP_Plugins_List_Table extends WP_List_Table { $actions['delete'] = '' . __( 'Delete' ) . ''; } } // end if $is_active - } // end if $screen->in_admin( 'network' ) - } // end if $context $actions = array_filter( $actions ); @@ -715,12 +736,12 @@ class WP_Plugins_List_Table extends WP_List_Table { } - $class = $is_active ? 'active' : 'inactive'; - $checkbox_id = "checkbox_" . md5($plugin_data['Name']); + $class = $is_active ? 'active' : 'inactive'; + $checkbox_id = 'checkbox_' . md5( $plugin_data['Name'] ); if ( $restrict_network_active || $restrict_network_only || in_array( $status, array( 'mustuse', 'dropins' ) ) ) { $checkbox = ''; } else { - $checkbox = "" + $checkbox = "' . ""; } if ( 'dropins' != $context ) { @@ -728,11 +749,13 @@ class WP_Plugins_List_Table extends WP_List_Table { $plugin_name = $plugin_data['Name']; } - if ( ! empty( $totals['upgrade'] ) && ! empty( $plugin_data['update'] ) ) + if ( ! empty( $totals['upgrade'] ) && ! empty( $plugin_data['update'] ) ) { $class .= ' update'; + } $plugin_slug = isset( $plugin_data['slug'] ) ? $plugin_data['slug'] : sanitize_title( $plugin_name ); - printf( '', + printf( + '', esc_attr( $class ), esc_attr( $plugin_slug ), esc_attr( $plugin_file ) @@ -753,7 +776,7 @@ class WP_Plugins_List_Table extends WP_List_Table { case 'name': echo "$plugin_name"; echo $this->row_actions( $actions, true ); - echo ""; + echo ''; break; case 'description': $classes = 'column-description desc'; @@ -763,26 +786,34 @@ class WP_Plugins_List_Table extends WP_List_Table {
    "; $plugin_meta = array(); - if ( !empty( $plugin_data['Version'] ) ) + if ( ! empty( $plugin_data['Version'] ) ) { $plugin_meta[] = sprintf( __( 'Version %s' ), $plugin_data['Version'] ); - if ( !empty( $plugin_data['Author'] ) ) { + } + if ( ! empty( $plugin_data['Author'] ) ) { $author = $plugin_data['Author']; - if ( !empty( $plugin_data['AuthorURI'] ) ) + if ( ! empty( $plugin_data['AuthorURI'] ) ) { $author = '' . $plugin_data['Author'] . ''; + } $plugin_meta[] = sprintf( __( 'By %s' ), $author ); } // Details link using API info, if available if ( isset( $plugin_data['slug'] ) && current_user_can( 'install_plugins' ) ) { - $plugin_meta[] = sprintf( '%s', - esc_url( network_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $plugin_data['slug'] . - '&TB_iframe=true&width=600&height=550' ) ), + $plugin_meta[] = sprintf( + '%s', + esc_url( + network_admin_url( + 'plugin-install.php?tab=plugin-information&plugin=' . $plugin_data['slug'] . + '&TB_iframe=true&width=600&height=550' + ) + ), esc_attr( sprintf( __( 'More information about %s' ), $plugin_name ) ), esc_attr( $plugin_name ), __( 'View details' ) ); } elseif ( ! empty( $plugin_data['PluginURI'] ) ) { - $plugin_meta[] = sprintf( '%s', + $plugin_meta[] = sprintf( + '%s', esc_url( $plugin_data['PluginURI'] ), __( 'Visit plugin site' ) ); @@ -805,7 +836,7 @@ class WP_Plugins_List_Table extends WP_List_Table { $plugin_meta = apply_filters( 'plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $status ); echo implode( ' | ', $plugin_meta ); - echo "
    "; + echo '
    '; break; default: $classes = "$column_name column-$column_name $class"; @@ -823,11 +854,11 @@ class WP_Plugins_List_Table extends WP_List_Table { */ do_action( 'manage_plugins_custom_column', $column_name, $plugin_file, $plugin_data ); - echo ""; + echo ''; } } - echo ""; + echo ''; /** * Fires after each row in the Plugins list table. diff --git a/wp-admin/includes/class-wp-post-comments-list-table.php b/wp-admin/includes/class-wp-post-comments-list-table.php index 719d65537e..f49d039778 100644 --- a/wp-admin/includes/class-wp-post-comments-list-table.php +++ b/wp-admin/includes/class-wp-post-comments-list-table.php @@ -18,14 +18,13 @@ class WP_Post_Comments_List_Table extends WP_Comments_List_Table { /** - * * @return array */ protected function get_column_info() { return array( array( - 'author' => __( 'Author' ), - 'comment' => _x( 'Comment', 'column name' ), + 'author' => __( 'Author' ), + 'comment' => _x( 'Comment', 'column name' ), ), array(), array(), @@ -34,40 +33,42 @@ class WP_Post_Comments_List_Table extends WP_Comments_List_Table { } /** - * * @return array */ protected function get_table_classes() { - $classes = parent::get_table_classes(); + $classes = parent::get_table_classes(); $classes[] = 'wp-list-table'; $classes[] = 'comments-box'; return $classes; } /** - * * @param bool $output_empty */ public function display( $output_empty = false ) { $singular = $this->_args['singular']; - wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' ); + wp_nonce_field( 'fetch-list-' . get_class( $this ), '_ajax_fetch_list_nonce' ); ?> - > - + > + display_rows_or_placeholder(); - } ?> + } + ?> 'posts', - 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, - ) ); + parent::__construct( + array( + 'plural' => 'posts', + 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, + ) + ); $post_type = $this->screen->post_type; $post_type_object = get_post_type_object( $post_type ); - $exclude_states = get_post_stati( array( - 'show_in_admin_all_list' => false, - ) ); - $this->user_posts_count = intval( $wpdb->get_var( $wpdb->prepare( " + $exclude_states = get_post_stati( + array( + 'show_in_admin_all_list' => false, + ) + ); + $this->user_posts_count = intval( + $wpdb->get_var( + $wpdb->prepare( + " SELECT COUNT( 1 ) FROM $wpdb->posts WHERE post_type = %s AND post_status NOT IN ( '" . implode( "','", $exclude_states ) . "' ) AND post_author = %d - ", $post_type, get_current_user_id() ) ) ); + ", $post_type, get_current_user_id() + ) + ) + ); if ( $this->user_posts_count && ! current_user_can( $post_type_object->cap->edit_others_posts ) && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) && empty( $_REQUEST['author'] ) && empty( $_REQUEST['show_sticky'] ) ) { $_GET['author'] = get_current_user_id(); } if ( 'post' === $post_type && $sticky_posts = get_option( 'sticky_posts' ) ) { - $sticky_posts = implode( ', ', array_map( 'absint', (array) $sticky_posts ) ); + $sticky_posts = implode( ', ', array_map( 'absint', (array) $sticky_posts ) ); $this->sticky_posts_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( 1 ) FROM $wpdb->posts WHERE post_type = %s AND post_status NOT IN ('trash', 'auto-draft') AND ID IN ($sticky_posts)", $post_type ) ); } } @@ -115,7 +125,6 @@ class WP_Posts_List_Table extends WP_List_Table { } /** - * * @return bool */ public function ajax_user_can() { @@ -123,7 +132,6 @@ class WP_Posts_List_Table extends WP_List_Table { } /** - * * @global array $avail_post_stati * @global WP_Query $wp_query * @global int $per_page @@ -138,10 +146,10 @@ class WP_Posts_List_Table extends WP_List_Table { $this->set_hierarchical_display( is_post_type_hierarchical( $this->screen->post_type ) && 'menu_order title' === $wp_query->query['orderby'] ); $post_type = $this->screen->post_type; - $per_page = $this->get_items_per_page( 'edit_' . $post_type . '_per_page' ); + $per_page = $this->get_items_per_page( 'edit_' . $post_type . '_per_page' ); /** This filter is documented in wp-admin/includes/post.php */ - $per_page = apply_filters( 'edit_posts_per_page', $per_page, $post_type ); + $per_page = apply_filters( 'edit_posts_per_page', $per_page, $post_type ); if ( $this->hierarchical_display ) { $total_items = $wp_query->post_count; @@ -150,7 +158,7 @@ class WP_Posts_List_Table extends WP_List_Table { } else { $post_counts = (array) wp_count_posts( $post_type, 'readable' ); - if ( isset( $_REQUEST['post_status'] ) && in_array( $_REQUEST['post_status'] , $avail_post_stati ) ) { + if ( isset( $_REQUEST['post_status'] ) && in_array( $_REQUEST['post_status'], $avail_post_stati ) ) { $total_items = $post_counts[ $_REQUEST['post_status'] ]; } elseif ( isset( $_REQUEST['show_sticky'] ) && $_REQUEST['show_sticky'] ) { $total_items = $this->sticky_posts_count; @@ -175,14 +183,15 @@ class WP_Posts_List_Table extends WP_List_Table { $this->is_trash = isset( $_REQUEST['post_status'] ) && $_REQUEST['post_status'] === 'trash'; - $this->set_pagination_args( array( - 'total_items' => $total_items, - 'per_page' => $per_page - ) ); + $this->set_pagination_args( + array( + 'total_items' => $total_items, + 'per_page' => $per_page, + ) + ); } /** - * * @return bool */ public function has_items() { @@ -192,10 +201,11 @@ class WP_Posts_List_Table extends WP_List_Table { /** */ public function no_items() { - if ( isset( $_REQUEST['post_status'] ) && 'trash' === $_REQUEST['post_status'] ) + if ( isset( $_REQUEST['post_status'] ) && 'trash' === $_REQUEST['post_status'] ) { echo get_post_type_object( $this->screen->post_type )->labels->not_found_in_trash; - else + } else { echo get_post_type_object( $this->screen->post_type )->labels->not_found; + } } /** @@ -253,7 +263,6 @@ class WP_Posts_List_Table extends WP_List_Table { } /** - * * @global array $locked_post_status This seems to be deprecated. * @global array $avail_post_stati * @return array @@ -263,17 +272,18 @@ class WP_Posts_List_Table extends WP_List_Table { $post_type = $this->screen->post_type; - if ( !empty($locked_post_status) ) + if ( ! empty( $locked_post_status ) ) { return array(); + } $status_links = array(); - $num_posts = wp_count_posts( $post_type, 'readable' ); - $total_posts = array_sum( (array) $num_posts ); - $class = ''; + $num_posts = wp_count_posts( $post_type, 'readable' ); + $total_posts = array_sum( (array) $num_posts ); + $class = ''; $current_user_id = get_current_user_id(); - $all_args = array( 'post_type' => $post_type ); - $mine = ''; + $all_args = array( 'post_type' => $post_type ); + $mine = ''; // Subtract post types that are not included in the admin all list. foreach ( get_post_stati( array( 'show_in_admin_all_list' => false ) ) as $state ) { @@ -287,7 +297,7 @@ class WP_Posts_List_Table extends WP_List_Table { $mine_args = array( 'post_type' => $post_type, - 'author' => $current_user_id + 'author' => $current_user_id, ); $mine_inner_html = sprintf( @@ -303,7 +313,7 @@ class WP_Posts_List_Table extends WP_List_Table { $mine = $this->get_edit_link( $mine_args, $mine_inner_html, $class ); $all_args['all_posts'] = 1; - $class = ''; + $class = ''; } if ( empty( $class ) && ( $this->is_base_request() || isset( $_REQUEST['all_posts'] ) ) ) { @@ -325,7 +335,7 @@ class WP_Posts_List_Table extends WP_List_Table { $status_links['mine'] = $mine; } - foreach ( get_post_stati(array('show_in_admin_status_list' => true), 'objects') as $status ) { + foreach ( get_post_stati( array( 'show_in_admin_status_list' => true ), 'objects' ) as $status ) { $class = ''; $status_name = $status->name; @@ -334,13 +344,13 @@ class WP_Posts_List_Table extends WP_List_Table { continue; } - if ( isset($_REQUEST['post_status']) && $status_name === $_REQUEST['post_status'] ) { + if ( isset( $_REQUEST['post_status'] ) && $status_name === $_REQUEST['post_status'] ) { $class = 'current'; } $status_args = array( 'post_status' => $status_name, - 'post_type' => $post_type, + 'post_type' => $post_type, ); $status_label = sprintf( @@ -355,8 +365,8 @@ class WP_Posts_List_Table extends WP_List_Table { $class = ! empty( $_REQUEST['show_sticky'] ) ? 'current' : ''; $sticky_args = array( - 'post_type' => $post_type, - 'show_sticky' => 1 + 'post_type' => $post_type, + 'show_sticky' => 1, ); $sticky_inner_html = sprintf( @@ -370,11 +380,11 @@ class WP_Posts_List_Table extends WP_List_Table { ); $sticky_link = array( - 'sticky' => $this->get_edit_link( $sticky_args, $sticky_inner_html, $class ) + 'sticky' => $this->get_edit_link( $sticky_args, $sticky_inner_html, $class ), ); // Sticky comes after Publish, or if not listed, after All. - $split = 1 + array_search( ( isset( $status_links['publish'] ) ? 'publish' : 'all' ), array_keys( $status_links ) ); + $split = 1 + array_search( ( isset( $status_links['publish'] ) ? 'publish' : 'all' ), array_keys( $status_links ) ); $status_links = array_merge( array_slice( $status_links, 0, $split ), $sticky_link, array_slice( $status_links, $split ) ); } @@ -382,11 +392,10 @@ class WP_Posts_List_Table extends WP_List_Table { } /** - * * @return array */ protected function get_bulk_actions() { - $actions = array(); + $actions = array(); $post_type_obj = get_post_type_object( $this->screen->post_type ); if ( current_user_can( $post_type_obj->cap->edit_posts ) ) { @@ -435,11 +444,11 @@ class WP_Posts_List_Table extends WP_List_Table { if ( is_object_in_taxonomy( $post_type, 'category' ) ) { $dropdown_options = array( 'show_option_all' => get_taxonomy( 'category' )->labels->all_items, - 'hide_empty' => 0, - 'hierarchical' => 1, - 'show_count' => 0, - 'orderby' => 'name', - 'selected' => $cat + 'hide_empty' => 0, + 'hierarchical' => 1, + 'show_count' => 0, + 'orderby' => 'name', + 'selected' => $cat, ); echo ''; @@ -454,40 +463,40 @@ class WP_Posts_List_Table extends WP_List_Table { ?>
    months_dropdown( $this->screen->post_type ); - $this->categories_dropdown( $this->screen->post_type ); + $this->months_dropdown( $this->screen->post_type ); + $this->categories_dropdown( $this->screen->post_type ); - /** - * Fires before the Filter button on the Posts and Pages list tables. - * - * The Filter button allows sorting by date and/or category on the - * Posts list table, and sorting by date on the Pages list table. - * - * @since 2.1.0 - * @since 4.4.0 The `$post_type` parameter was added. - * @since 4.6.0 The `$which` parameter was added. - * - * @param string $post_type The post type slug. - * @param string $which The location of the extra table nav markup: - * 'top' or 'bottom' for WP_Posts_List_Table, - * 'bar' for WP_Media_List_Table. - */ - do_action( 'restrict_manage_posts', $this->screen->post_type, $which ); + /** + * Fires before the Filter button on the Posts and Pages list tables. + * + * The Filter button allows sorting by date and/or category on the + * Posts list table, and sorting by date on the Pages list table. + * + * @since 2.1.0 + * @since 4.4.0 The `$post_type` parameter was added. + * @since 4.6.0 The `$which` parameter was added. + * + * @param string $post_type The post type slug. + * @param string $which The location of the extra table nav markup: + * 'top' or 'bottom' for WP_Posts_List_Table, + * 'bar' for WP_Media_List_Table. + */ + do_action( 'restrict_manage_posts', $this->screen->post_type, $which ); - $output = ob_get_clean(); + $output = ob_get_clean(); - if ( ! empty( $output ) ) { - echo $output; - submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) ); - } - } + if ( ! empty( $output ) ) { + echo $output; + submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) ); + } +} - if ( $this->is_trash && current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_others_posts ) && $this->has_items() ) { - submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false ); - } +if ( $this->is_trash && current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_others_posts ) && $this->has_items() ) { + submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false ); +} ?>
    labels->name; } - $post_status = !empty( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : 'all'; - if ( post_type_supports( $post_type, 'comments' ) && !in_array( $post_status, array( 'pending', 'draft', 'future' ) ) ) + $post_status = ! empty( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : 'all'; + if ( post_type_supports( $post_type, 'comments' ) && ! in_array( $post_status, array( 'pending', 'draft', 'future' ) ) ) { $posts_columns['comments'] = '' . __( 'Comments' ) . ''; + } $posts_columns['date'] = __( 'Date' ); @@ -609,7 +618,6 @@ class WP_Posts_List_Table extends WP_List_Table { } /** - * * @return array */ protected function get_sortable_columns() { @@ -617,7 +625,7 @@ class WP_Posts_List_Table extends WP_List_Table { 'title' => 'title', 'parent' => 'parent', 'comments' => 'comment_count', - 'date' => array( 'date', true ) + 'date' => array( 'date', true ), ); } @@ -630,8 +638,9 @@ class WP_Posts_List_Table extends WP_List_Table { public function display_rows( $posts = array(), $level = 0 ) { global $wp_query, $per_page; - if ( empty( $posts ) ) + if ( empty( $posts ) ) { $posts = $wp_query->posts; + } add_filter( 'the_title', 'esc_html' ); @@ -650,13 +659,15 @@ class WP_Posts_List_Table extends WP_List_Table { // Create array of post IDs. $post_ids = array(); - foreach ( $posts as $a_post ) + foreach ( $posts as $a_post ) { $post_ids[] = $a_post->ID; + } $this->comment_pending_count = get_pending_comments_num( $post_ids ); - foreach ( $posts as $post ) + foreach ( $posts as $post ) { $this->single_row( $post, $level ); + } } /** @@ -674,8 +685,9 @@ class WP_Posts_List_Table extends WP_List_Table { if ( ! $pages ) { $pages = get_pages( array( 'sort_column' => 'menu_order' ) ); - if ( ! $pages ) + if ( ! $pages ) { return; + } } /* @@ -688,7 +700,7 @@ class WP_Posts_List_Table extends WP_List_Table { if ( empty( $_REQUEST['s'] ) ) { $top_level_pages = array(); - $children_pages = array(); + $children_pages = array(); foreach ( $pages as $page ) { @@ -699,43 +711,47 @@ class WP_Posts_List_Table extends WP_List_Table { clean_post_cache( $page ); } - if ( 0 == $page->post_parent ) + if ( 0 == $page->post_parent ) { $top_level_pages[] = $page; - else + } else { $children_pages[ $page->post_parent ][] = $page; + } } $pages = &$top_level_pages; } - $count = 0; - $start = ( $pagenum - 1 ) * $per_page; - $end = $start + $per_page; + $count = 0; + $start = ( $pagenum - 1 ) * $per_page; + $end = $start + $per_page; $to_display = array(); foreach ( $pages as $page ) { - if ( $count >= $end ) + if ( $count >= $end ) { break; + } if ( $count >= $start ) { - $to_display[$page->ID] = $level; + $to_display[ $page->ID ] = $level; } $count++; - if ( isset( $children_pages ) ) + if ( isset( $children_pages ) ) { $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display ); + } } // If it is the last pagenum and there are orphaned pages, display them with paging as well. - if ( isset( $children_pages ) && $count < $end ){ - foreach ( $children_pages as $orphans ){ + if ( isset( $children_pages ) && $count < $end ) { + foreach ( $children_pages as $orphans ) { foreach ( $orphans as $op ) { - if ( $count >= $end ) + if ( $count >= $end ) { break; + } if ( $count >= $start ) { - $to_display[$op->ID] = 0; + $to_display[ $op->ID ] = 0; } $count++; @@ -772,20 +788,22 @@ class WP_Posts_List_Table extends WP_List_Table { * @param array $to_display List of pages to be displayed. Passed by reference. */ private function _page_rows( &$children_pages, &$count, $parent, $level, $pagenum, $per_page, &$to_display ) { - if ( ! isset( $children_pages[$parent] ) ) + if ( ! isset( $children_pages[ $parent ] ) ) { return; + } $start = ( $pagenum - 1 ) * $per_page; - $end = $start + $per_page; + $end = $start + $per_page; - foreach ( $children_pages[$parent] as $page ) { - if ( $count >= $end ) + foreach ( $children_pages[ $parent ] as $page ) { + if ( $count >= $end ) { break; + } // If the page starts in a subtree, print the parents. if ( $count == $start && $page->post_parent > 0 ) { $my_parents = array(); - $my_parent = $page->post_parent; + $my_parent = $page->post_parent; while ( $my_parent ) { // Get the ID from the list or the attribute if my_parent is an object $parent_id = $my_parent; @@ -793,21 +811,22 @@ class WP_Posts_List_Table extends WP_List_Table { $parent_id = $my_parent->ID; } - $my_parent = get_post( $parent_id ); + $my_parent = get_post( $parent_id ); $my_parents[] = $my_parent; - if ( !$my_parent->post_parent ) + if ( ! $my_parent->post_parent ) { break; + } $my_parent = $my_parent->post_parent; } $num_parents = count( $my_parents ); while ( $my_parent = array_pop( $my_parents ) ) { - $to_display[$my_parent->ID] = $level - $num_parents; + $to_display[ $my_parent->ID ] = $level - $num_parents; $num_parents--; } } if ( $count >= $start ) { - $to_display[$page->ID] = $level; + $to_display[ $page->ID ] = $level; } $count++; @@ -815,7 +834,7 @@ class WP_Posts_List_Table extends WP_List_Table { $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display ); } - unset( $children_pages[$parent] ); //required in order to keep track of orphans + unset( $children_pages[ $parent ] ); //required in order to keep track of orphans } /** @@ -826,22 +845,28 @@ class WP_Posts_List_Table extends WP_List_Table { * @param WP_Post $post The current WP_Post object. */ public function column_cb( $post ) { - if ( current_user_can( 'edit_post', $post->ID ) ): ?> - + if ( current_user_can( 'edit_post', $post->ID ) ) : + ?> +
    - + + ?> +
    - ID ); if ( $lock_holder ) { - $lock_holder = get_userdata( $lock_holder ); + $lock_holder = get_userdata( $lock_holder ); $locked_avatar = get_avatar( $lock_holder->ID, 18 ); - $locked_text = esc_html( sprintf( __( '%s is currently editing' ), $lock_holder->display_name ) ); + $locked_text = esc_html( sprintf( __( '%s is currently editing' ), $lock_holder->display_name ) ); } else { $locked_avatar = $locked_text = ''; } @@ -910,7 +935,7 @@ class WP_Posts_List_Table extends WP_List_Table { } $pad = str_repeat( '— ', $this->current_level ); - echo ""; + echo ''; $format = get_post_format( $post->ID ); if ( $format ) { @@ -920,7 +945,7 @@ class WP_Posts_List_Table extends WP_List_Table { $format_args = array( 'post_format' => $format, - 'post_type' => $post->post_type + 'post_type' => $post->post_type, ); echo $this->get_edit_link( $format_args, $label . ':', $format_class ); @@ -972,12 +997,12 @@ class WP_Posts_List_Table extends WP_List_Table { global $mode; if ( '0000-00-00 00:00:00' === $post->post_date ) { - $t_time = $h_time = __( 'Unpublished' ); + $t_time = $h_time = __( 'Unpublished' ); $time_diff = 0; } else { $t_time = get_the_time( __( 'Y/m/d g:i:s a' ) ); $m_time = $post->post_date; - $time = get_post_time( 'G', true, $post ); + $time = get_post_time( 'G', true, $post ); $time_diff = time() - $time; @@ -1050,7 +1075,7 @@ class WP_Posts_List_Table extends WP_List_Table { ?>
    comment_pending_count[$post->ID] ) ? $this->comment_pending_count[$post->ID] : 0; + $pending_comments = isset( $this->comment_pending_count[ $post->ID ] ) ? $this->comment_pending_count[ $post->ID ] : 0; $this->comments_bubble( $post->ID, $pending_comments ); ?> @@ -1068,7 +1093,7 @@ class WP_Posts_List_Table extends WP_List_Table { public function column_author( $post ) { $args = array( 'post_type' => $post->post_type, - 'author' => get_the_author_meta( 'ID' ) + 'author' => get_the_author_meta( 'ID' ), ); echo $this->get_edit_link( $args, get_the_author() ); } @@ -1093,7 +1118,7 @@ class WP_Posts_List_Table extends WP_List_Table { } if ( $taxonomy ) { $taxonomy_object = get_taxonomy( $taxonomy ); - $terms = get_the_terms( $post->ID, $taxonomy ); + $terms = get_the_terms( $post->ID, $taxonomy ); if ( is_array( $terms ) ) { $out = array(); foreach ( $terms as $t ) { @@ -1105,7 +1130,7 @@ class WP_Posts_List_Table extends WP_List_Table { $posts_in_term_qv[ $taxonomy_object->query_var ] = $t->slug; } else { $posts_in_term_qv['taxonomy'] = $taxonomy; - $posts_in_term_qv['term'] = $t->slug; + $posts_in_term_qv['term'] = $t->slug; } $label = esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) ); @@ -1171,7 +1196,7 @@ class WP_Posts_List_Table extends WP_List_Table { public function single_row( $post, $level = 0 ) { $global_post = get_post(); - $post = get_post( $post ); + $post = get_post( $post ); $this->current_level = $level; $GLOBALS['post'] = $post; @@ -1185,10 +1210,10 @@ class WP_Posts_List_Table extends WP_List_Table { } if ( $post->post_parent ) { - $count = count( get_post_ancestors( $post->ID ) ); - $classes .= ' level-'. $count; + $count = count( get_post_ancestors( $post->ID ) ); + $classes .= ' level-' . $count; } else { - $classes .= ' level-0'; + $classes .= ' level-0'; } ?> @@ -1225,9 +1250,9 @@ class WP_Posts_List_Table extends WP_List_Table { } $post_type_object = get_post_type_object( $post->post_type ); - $can_edit_post = current_user_can( 'edit_post', $post->ID ); - $actions = array(); - $title = _draft_or_post_title(); + $can_edit_post = current_user_can( 'edit_post', $post->ID ); + $actions = array(); + $title = _draft_or_post_title(); if ( $can_edit_post && 'trash' != $post->post_status ) { $actions['edit'] = sprintf( @@ -1277,7 +1302,7 @@ class WP_Posts_List_Table extends WP_List_Table { if ( is_post_type_viewable( $post_type_object ) ) { if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) { if ( $can_edit_post ) { - $preview_link = get_preview_post_link( $post ); + $preview_link = get_preview_post_link( $post ); $actions['view'] = sprintf( '%s', esc_url( $preview_link ), @@ -1344,12 +1369,12 @@ class WP_Posts_List_Table extends WP_List_Table { $screen = $this->screen; - $post = get_default_post_to_edit( $screen->post_type ); + $post = get_default_post_to_edit( $screen->post_type ); $post_type_object = get_post_type_object( $screen->post_type ); - $taxonomy_names = get_object_taxonomies( $screen->post_type ); + $taxonomy_names = get_object_taxonomies( $screen->post_type ); $hierarchical_taxonomies = array(); - $flat_taxonomies = array(); + $flat_taxonomies = array(); foreach ( $taxonomy_names as $taxonomy_name ) { $taxonomy = get_taxonomy( $taxonomy_name ); @@ -1369,31 +1394,44 @@ class WP_Posts_List_Table extends WP_List_Table { continue; } - if ( $taxonomy->hierarchical ) + if ( $taxonomy->hierarchical ) { $hierarchical_taxonomies[] = $taxonomy; - else + } else { $flat_taxonomies[] = $taxonomy; + } } - $m = ( isset( $mode ) && 'excerpt' === $mode ) ? 'excerpt' : 'list'; - $can_publish = current_user_can( $post_type_object->cap->publish_posts ); - $core_columns = array( 'cb' => true, 'date' => true, 'title' => true, 'categories' => true, 'tags' => true, 'comments' => true, 'author' => true ); + $m = ( isset( $mode ) && 'excerpt' === $mode ) ? 'excerpt' : 'list'; + $can_publish = current_user_can( $post_type_object->cap->publish_posts ); + $core_columns = array( + 'cb' => true, + 'date' => true, + 'title' => true, + 'categories' => true, + 'tags' => true, + 'comments' => true, + 'author' => true, + ); ?>
    post_type}"; $quick_edit_classes = "quick-edit-row quick-edit-row-$hclass inline-edit-{$screen->post_type}"; $bulk = 0; - while ( $bulk < 2 ) { ?> + while ( $bulk < 2 ) { + ?> - @@ -381,8 +400,9 @@ function upload_space_setting( $id ) { function update_user_status( $id, $pref, $value, $deprecated = null ) { global $wpdb; - if ( null !== $deprecated ) + if ( null !== $deprecated ) { _deprecated_argument( __FUNCTION__, '3.0.2' ); + } $wpdb->update( $wpdb->users, array( sanitize_key( $pref ) => $value ), array( 'ID' => $id ) ); @@ -425,8 +445,9 @@ function update_user_status( $id, $pref, $value, $deprecated = null ) { function refresh_user_details( $id ) { $id = (int) $id; - if ( !$user = get_userdata( $id ) ) + if ( ! $user = get_userdata( $id ) ) { return false; + } clean_user_cache( $user ); @@ -443,19 +464,194 @@ function refresh_user_details( $id ) { * then the first two letters of $code is returned. */ function format_code_lang( $code = '' ) { - $code = strtolower( substr( $code, 0, 2 ) ); + $code = strtolower( substr( $code, 0, 2 ) ); $lang_codes = array( - 'aa' => 'Afar', 'ab' => 'Abkhazian', 'af' => 'Afrikaans', 'ak' => 'Akan', 'sq' => 'Albanian', 'am' => 'Amharic', 'ar' => 'Arabic', 'an' => 'Aragonese', 'hy' => 'Armenian', 'as' => 'Assamese', 'av' => 'Avaric', 'ae' => 'Avestan', 'ay' => 'Aymara', 'az' => 'Azerbaijani', 'ba' => 'Bashkir', 'bm' => 'Bambara', 'eu' => 'Basque', 'be' => 'Belarusian', 'bn' => 'Bengali', - 'bh' => 'Bihari', 'bi' => 'Bislama', 'bs' => 'Bosnian', 'br' => 'Breton', 'bg' => 'Bulgarian', 'my' => 'Burmese', 'ca' => 'Catalan; Valencian', 'ch' => 'Chamorro', 'ce' => 'Chechen', 'zh' => 'Chinese', 'cu' => 'Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic', 'cv' => 'Chuvash', 'kw' => 'Cornish', 'co' => 'Corsican', 'cr' => 'Cree', - 'cs' => 'Czech', 'da' => 'Danish', 'dv' => 'Divehi; Dhivehi; Maldivian', 'nl' => 'Dutch; Flemish', 'dz' => 'Dzongkha', 'en' => 'English', 'eo' => 'Esperanto', 'et' => 'Estonian', 'ee' => 'Ewe', 'fo' => 'Faroese', 'fj' => 'Fijjian', 'fi' => 'Finnish', 'fr' => 'French', 'fy' => 'Western Frisian', 'ff' => 'Fulah', 'ka' => 'Georgian', 'de' => 'German', 'gd' => 'Gaelic; Scottish Gaelic', - 'ga' => 'Irish', 'gl' => 'Galician', 'gv' => 'Manx', 'el' => 'Greek, Modern', 'gn' => 'Guarani', 'gu' => 'Gujarati', 'ht' => 'Haitian; Haitian Creole', 'ha' => 'Hausa', 'he' => 'Hebrew', 'hz' => 'Herero', 'hi' => 'Hindi', 'ho' => 'Hiri Motu', 'hu' => 'Hungarian', 'ig' => 'Igbo', 'is' => 'Icelandic', 'io' => 'Ido', 'ii' => 'Sichuan Yi', 'iu' => 'Inuktitut', 'ie' => 'Interlingue', - 'ia' => 'Interlingua (International Auxiliary Language Association)', 'id' => 'Indonesian', 'ik' => 'Inupiaq', 'it' => 'Italian', 'jv' => 'Javanese', 'ja' => 'Japanese', 'kl' => 'Kalaallisut; Greenlandic', 'kn' => 'Kannada', 'ks' => 'Kashmiri', 'kr' => 'Kanuri', 'kk' => 'Kazakh', 'km' => 'Central Khmer', 'ki' => 'Kikuyu; Gikuyu', 'rw' => 'Kinyarwanda', 'ky' => 'Kirghiz; Kyrgyz', - 'kv' => 'Komi', 'kg' => 'Kongo', 'ko' => 'Korean', 'kj' => 'Kuanyama; Kwanyama', 'ku' => 'Kurdish', 'lo' => 'Lao', 'la' => 'Latin', 'lv' => 'Latvian', 'li' => 'Limburgan; Limburger; Limburgish', 'ln' => 'Lingala', 'lt' => 'Lithuanian', 'lb' => 'Luxembourgish; Letzeburgesch', 'lu' => 'Luba-Katanga', 'lg' => 'Ganda', 'mk' => 'Macedonian', 'mh' => 'Marshallese', 'ml' => 'Malayalam', - 'mi' => 'Maori', 'mr' => 'Marathi', 'ms' => 'Malay', 'mg' => 'Malagasy', 'mt' => 'Maltese', 'mo' => 'Moldavian', 'mn' => 'Mongolian', 'na' => 'Nauru', 'nv' => 'Navajo; Navaho', 'nr' => 'Ndebele, South; South Ndebele', 'nd' => 'Ndebele, North; North Ndebele', 'ng' => 'Ndonga', 'ne' => 'Nepali', 'nn' => 'Norwegian Nynorsk; Nynorsk, Norwegian', 'nb' => 'Bokmål, Norwegian, Norwegian Bokmål', - 'no' => 'Norwegian', 'ny' => 'Chichewa; Chewa; Nyanja', 'oc' => 'Occitan, Provençal', 'oj' => 'Ojibwa', 'or' => 'Oriya', 'om' => 'Oromo', 'os' => 'Ossetian; Ossetic', 'pa' => 'Panjabi; Punjabi', 'fa' => 'Persian', 'pi' => 'Pali', 'pl' => 'Polish', 'pt' => 'Portuguese', 'ps' => 'Pushto', 'qu' => 'Quechua', 'rm' => 'Romansh', 'ro' => 'Romanian', 'rn' => 'Rundi', 'ru' => 'Russian', - 'sg' => 'Sango', 'sa' => 'Sanskrit', 'sr' => 'Serbian', 'hr' => 'Croatian', 'si' => 'Sinhala; Sinhalese', 'sk' => 'Slovak', 'sl' => 'Slovenian', 'se' => 'Northern Sami', 'sm' => 'Samoan', 'sn' => 'Shona', 'sd' => 'Sindhi', 'so' => 'Somali', 'st' => 'Sotho, Southern', 'es' => 'Spanish; Castilian', 'sc' => 'Sardinian', 'ss' => 'Swati', 'su' => 'Sundanese', 'sw' => 'Swahili', - 'sv' => 'Swedish', 'ty' => 'Tahitian', 'ta' => 'Tamil', 'tt' => 'Tatar', 'te' => 'Telugu', 'tg' => 'Tajik', 'tl' => 'Tagalog', 'th' => 'Thai', 'bo' => 'Tibetan', 'ti' => 'Tigrinya', 'to' => 'Tonga (Tonga Islands)', 'tn' => 'Tswana', 'ts' => 'Tsonga', 'tk' => 'Turkmen', 'tr' => 'Turkish', 'tw' => 'Twi', 'ug' => 'Uighur; Uyghur', 'uk' => 'Ukrainian', 'ur' => 'Urdu', 'uz' => 'Uzbek', - 've' => 'Venda', 'vi' => 'Vietnamese', 'vo' => 'Volapük', 'cy' => 'Welsh','wa' => 'Walloon','wo' => 'Wolof', 'xh' => 'Xhosa', 'yi' => 'Yiddish', 'yo' => 'Yoruba', 'za' => 'Zhuang; Chuang', 'zu' => 'Zulu' ); + 'aa' => 'Afar', + 'ab' => 'Abkhazian', + 'af' => 'Afrikaans', + 'ak' => 'Akan', + 'sq' => 'Albanian', + 'am' => 'Amharic', + 'ar' => 'Arabic', + 'an' => 'Aragonese', + 'hy' => 'Armenian', + 'as' => 'Assamese', + 'av' => 'Avaric', + 'ae' => 'Avestan', + 'ay' => 'Aymara', + 'az' => 'Azerbaijani', + 'ba' => 'Bashkir', + 'bm' => 'Bambara', + 'eu' => 'Basque', + 'be' => 'Belarusian', + 'bn' => 'Bengali', + 'bh' => 'Bihari', + 'bi' => 'Bislama', + 'bs' => 'Bosnian', + 'br' => 'Breton', + 'bg' => 'Bulgarian', + 'my' => 'Burmese', + 'ca' => 'Catalan; Valencian', + 'ch' => 'Chamorro', + 'ce' => 'Chechen', + 'zh' => 'Chinese', + 'cu' => 'Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic', + 'cv' => 'Chuvash', + 'kw' => 'Cornish', + 'co' => 'Corsican', + 'cr' => 'Cree', + 'cs' => 'Czech', + 'da' => 'Danish', + 'dv' => 'Divehi; Dhivehi; Maldivian', + 'nl' => 'Dutch; Flemish', + 'dz' => 'Dzongkha', + 'en' => 'English', + 'eo' => 'Esperanto', + 'et' => 'Estonian', + 'ee' => 'Ewe', + 'fo' => 'Faroese', + 'fj' => 'Fijjian', + 'fi' => 'Finnish', + 'fr' => 'French', + 'fy' => 'Western Frisian', + 'ff' => 'Fulah', + 'ka' => 'Georgian', + 'de' => 'German', + 'gd' => 'Gaelic; Scottish Gaelic', + 'ga' => 'Irish', + 'gl' => 'Galician', + 'gv' => 'Manx', + 'el' => 'Greek, Modern', + 'gn' => 'Guarani', + 'gu' => 'Gujarati', + 'ht' => 'Haitian; Haitian Creole', + 'ha' => 'Hausa', + 'he' => 'Hebrew', + 'hz' => 'Herero', + 'hi' => 'Hindi', + 'ho' => 'Hiri Motu', + 'hu' => 'Hungarian', + 'ig' => 'Igbo', + 'is' => 'Icelandic', + 'io' => 'Ido', + 'ii' => 'Sichuan Yi', + 'iu' => 'Inuktitut', + 'ie' => 'Interlingue', + 'ia' => 'Interlingua (International Auxiliary Language Association)', + 'id' => 'Indonesian', + 'ik' => 'Inupiaq', + 'it' => 'Italian', + 'jv' => 'Javanese', + 'ja' => 'Japanese', + 'kl' => 'Kalaallisut; Greenlandic', + 'kn' => 'Kannada', + 'ks' => 'Kashmiri', + 'kr' => 'Kanuri', + 'kk' => 'Kazakh', + 'km' => 'Central Khmer', + 'ki' => 'Kikuyu; Gikuyu', + 'rw' => 'Kinyarwanda', + 'ky' => 'Kirghiz; Kyrgyz', + 'kv' => 'Komi', + 'kg' => 'Kongo', + 'ko' => 'Korean', + 'kj' => 'Kuanyama; Kwanyama', + 'ku' => 'Kurdish', + 'lo' => 'Lao', + 'la' => 'Latin', + 'lv' => 'Latvian', + 'li' => 'Limburgan; Limburger; Limburgish', + 'ln' => 'Lingala', + 'lt' => 'Lithuanian', + 'lb' => 'Luxembourgish; Letzeburgesch', + 'lu' => 'Luba-Katanga', + 'lg' => 'Ganda', + 'mk' => 'Macedonian', + 'mh' => 'Marshallese', + 'ml' => 'Malayalam', + 'mi' => 'Maori', + 'mr' => 'Marathi', + 'ms' => 'Malay', + 'mg' => 'Malagasy', + 'mt' => 'Maltese', + 'mo' => 'Moldavian', + 'mn' => 'Mongolian', + 'na' => 'Nauru', + 'nv' => 'Navajo; Navaho', + 'nr' => 'Ndebele, South; South Ndebele', + 'nd' => 'Ndebele, North; North Ndebele', + 'ng' => 'Ndonga', + 'ne' => 'Nepali', + 'nn' => 'Norwegian Nynorsk; Nynorsk, Norwegian', + 'nb' => 'Bokmål, Norwegian, Norwegian Bokmål', + 'no' => 'Norwegian', + 'ny' => 'Chichewa; Chewa; Nyanja', + 'oc' => 'Occitan, Provençal', + 'oj' => 'Ojibwa', + 'or' => 'Oriya', + 'om' => 'Oromo', + 'os' => 'Ossetian; Ossetic', + 'pa' => 'Panjabi; Punjabi', + 'fa' => 'Persian', + 'pi' => 'Pali', + 'pl' => 'Polish', + 'pt' => 'Portuguese', + 'ps' => 'Pushto', + 'qu' => 'Quechua', + 'rm' => 'Romansh', + 'ro' => 'Romanian', + 'rn' => 'Rundi', + 'ru' => 'Russian', + 'sg' => 'Sango', + 'sa' => 'Sanskrit', + 'sr' => 'Serbian', + 'hr' => 'Croatian', + 'si' => 'Sinhala; Sinhalese', + 'sk' => 'Slovak', + 'sl' => 'Slovenian', + 'se' => 'Northern Sami', + 'sm' => 'Samoan', + 'sn' => 'Shona', + 'sd' => 'Sindhi', + 'so' => 'Somali', + 'st' => 'Sotho, Southern', + 'es' => 'Spanish; Castilian', + 'sc' => 'Sardinian', + 'ss' => 'Swati', + 'su' => 'Sundanese', + 'sw' => 'Swahili', + 'sv' => 'Swedish', + 'ty' => 'Tahitian', + 'ta' => 'Tamil', + 'tt' => 'Tatar', + 'te' => 'Telugu', + 'tg' => 'Tajik', + 'tl' => 'Tagalog', + 'th' => 'Thai', + 'bo' => 'Tibetan', + 'ti' => 'Tigrinya', + 'to' => 'Tonga (Tonga Islands)', + 'tn' => 'Tswana', + 'ts' => 'Tsonga', + 'tk' => 'Turkmen', + 'tr' => 'Turkish', + 'tw' => 'Twi', + 'ug' => 'Uighur; Uyghur', + 'uk' => 'Ukrainian', + 'ur' => 'Urdu', + 'uz' => 'Uzbek', + 've' => 'Venda', + 'vi' => 'Vietnamese', + 'vo' => 'Volapük', + 'cy' => 'Welsh', + 'wa' => 'Walloon', + 'wo' => 'Wolof', + 'xh' => 'Xhosa', + 'yi' => 'Yiddish', + 'yo' => 'Yoruba', + 'za' => 'Zhuang; Chuang', + 'zu' => 'Zulu', + ); /** * Filters the language codes. @@ -500,30 +696,33 @@ function sync_category_tag_slugs( $term, $taxonomy ) { * @access private */ function _access_denied_splash() { - if ( ! is_user_logged_in() || is_network_admin() ) + if ( ! is_user_logged_in() || is_network_admin() ) { return; + } $blogs = get_blogs_of_user( get_current_user_id() ); - if ( wp_list_filter( $blogs, array( 'userblog_id' => get_current_blog_id() ) ) ) + if ( wp_list_filter( $blogs, array( 'userblog_id' => get_current_blog_id() ) ) ) { return; + } $blog_name = get_bloginfo( 'name' ); - if ( empty( $blogs ) ) + if ( empty( $blogs ) ) { wp_die( sprintf( __( 'You attempted to access the "%1$s" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "%1$s" dashboard, please contact your network administrator.' ), $blog_name ), 403 ); + } - $output = '

    ' . sprintf( __( 'You attempted to access the "%1$s" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "%1$s" dashboard, please contact your network administrator.' ), $blog_name ) . '

    '; + $output = '

    ' . sprintf( __( 'You attempted to access the "%1$s" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "%1$s" dashboard, please contact your network administrator.' ), $blog_name ) . '

    '; $output .= '

    ' . __( 'If you reached this screen by accident and meant to visit one of your own sites, here are some shortcuts to help you find your way.' ) . '

    '; - $output .= '

    ' . __('Your Sites') . '

    '; + $output .= '

    ' . __( 'Your Sites' ) . '

    '; $output .= '
    '; foreach ( $blogs as $blog ) { $output .= ''; $output .= ""; $output .= ''; + '' . __( 'View Site' ) . ''; $output .= ''; } @@ -558,29 +757,29 @@ function check_import_new_users( $permission ) { * @param string $current Optional. The current language code. Default empty. */ function mu_dropdown_languages( $lang_files = array(), $current = '' ) { - $flag = false; + $flag = false; $output = array(); foreach ( (array) $lang_files as $val ) { $code_lang = basename( $val, '.mo' ); if ( $code_lang == 'en_US' ) { // American English - $flag = true; - $ae = __( 'American English' ); - $output[$ae] = ''; + $flag = true; + $ae = __( 'American English' ); + $output[ $ae ] = ''; } elseif ( $code_lang == 'en_GB' ) { // British English - $flag = true; - $be = __( 'British English' ); - $output[$be] = ''; + $flag = true; + $be = __( 'British English' ); + $output[ $be ] = ''; } else { - $translated = format_code_lang( $code_lang ); - $output[$translated] = ''; + $translated = format_code_lang( $code_lang ); + $output[ $translated ] = ''; } - } - if ( $flag === false ) // WordPress english - $output[] = '"; + if ( $flag === false ) { // WordPress english + $output[] = ''; + } // Order by name uksort( $output, 'strnatcasecmp' ); @@ -621,7 +820,7 @@ function site_admin_notice() { } if ( get_site_option( 'wpmu_upgrade_site' ) != $wp_db_version ) { - echo "
    " . sprintf( __( 'Thank you for Updating! Please visit the Upgrade Network page to update all your sites.' ), esc_url( network_admin_url( 'upgrade.php' ) ) ) . "
    "; + echo "
    " . sprintf( __( 'Thank you for Updating! Please visit the Upgrade Network page to update all your sites.' ), esc_url( network_admin_url( 'upgrade.php' ) ) ) . '
    '; } } @@ -638,18 +837,22 @@ function site_admin_notice() { * @return array The new array of post data after checking for collisions. */ function avoid_blog_page_permalink_collision( $data, $postarr ) { - if ( is_subdomain_install() ) + if ( is_subdomain_install() ) { return $data; - if ( $data['post_type'] != 'page' ) + } + if ( $data['post_type'] != 'page' ) { return $data; - if ( !isset( $data['post_name'] ) || $data['post_name'] == '' ) + } + if ( ! isset( $data['post_name'] ) || $data['post_name'] == '' ) { return $data; - if ( !is_main_site() ) + } + if ( ! is_main_site() ) { return $data; + } $post_name = $data['post_name']; - $c = 0; - while( $c < 10 && get_id_from_blogname( $post_name ) ) { + $c = 0; + while ( $c < 10 && get_id_from_blogname( $post_name ) ) { $post_name .= mt_rand( 1, 10 ); $c ++; } @@ -675,30 +878,36 @@ function choose_primary_blog() { @@ -719,10 +928,11 @@ function choose_primary_blog() { * @return bool True if network can be edited, otherwise false. */ function can_edit_network( $network_id ) { - if ( $network_id == get_current_network_id() ) + if ( $network_id == get_current_network_id() ) { $result = true; - else + } else { $result = false; + } /** * Filters whether this network can be edited from this page. @@ -751,7 +961,6 @@ var tb_pathToImage = "ID ) . '">' . $current_user->user_login . ''; ?> + $admin_out = ''; + ?>
    {$blog->blogname}' . __( 'Visit Dashboard' ) . ' | ' . - '' . __( 'View Site' ) . '
    1 ) { $found = false; ?> userblog_id ); } } elseif ( count( $all_blogs ) == 1 ) { $blog = reset( $all_blogs ); echo esc_url( get_home_url( $blog->userblog_id ) ); - if ( $primary_blog != $blog->userblog_id ) // Set the primary blog again if it's out of sync with blog list. + if ( $primary_blog != $blog->userblog_id ) { // Set the primary blog again if it's out of sync with blog list. update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id ); + } } else { - echo "N/A"; + echo 'N/A'; } ?>
    - user_login; ?> ' . "\n"; ?> - - "; + echo ''; } else { ?> - + if ( ! allow_subdirectory_install() ) { + echo ' ' . __( 'Warning:' ) . ' ' . __( 'The main site in a sub-directory installation will need to use a modified permalink structure, potentially breaking existing links.' ) . ''; + } + ?> + - + - + if ( ! allow_subdirectory_install() ) { + echo ' ' . __( 'Warning:' ) . ' ' . __( 'The main site in a sub-directory installation will need to use a modified permalink structure, potentially breaking existing links.' ) . ''; + } + ?> + - + - + ?> + @@ -354,7 +391,6 @@ function network_step2( $errors = false ) { $wp_siteurl_subdir = preg_replace( '#^' . preg_quote( $home_path, '#' ) . '#', '', $abspath_fix ); $rewrite_base = ! empty( $wp_siteurl_subdir ) ? ltrim( trailingslashit( $wp_siteurl_subdir ), '/' ) : ''; - $location_of_wp_config = $abspath_fix; if ( ! file_exists( ABSPATH . 'wp-config.php' ) && file_exists( dirname( ABSPATH ) . '/wp-config.php' ) ) { $location_of_wp_config = dirname( $abspath_fix ); @@ -362,14 +398,16 @@ function network_step2( $errors = false ) { $location_of_wp_config = trailingslashit( $location_of_wp_config ); // Wildcard DNS message. - if ( is_wp_error( $errors ) ) + if ( is_wp_error( $errors ) ) { echo '
    ' . $errors->get_error_message() . '
    '; + } if ( $_POST ) { - if ( allow_subdomain_install() ) + if ( allow_subdomain_install() ) { $subdomain_install = allow_subdirectory_install() ? ! empty( $_POST['subdomain_install'] ) : true; - else + } else { $subdomain_install = false; + } } else { if ( is_multisite() ) { $subdomain_install = is_subdomain_install(); @@ -393,37 +431,41 @@ function network_step2( $errors = false ) { ?>

    -

    ' . __( 'Caution:' ) . ' '; - printf( - /* translators: 1: wp-config.php 2: .htaccess */ - __( 'We recommend you back up your existing %1$s and %2$s files.' ), - 'wp-config.php', - '.htaccess' - ); - } elseif ( file_exists( $home_path . 'web.config' ) ) { - echo '' . __( 'Caution:' ) . ' '; - printf( - /* translators: 1: wp-config.php 2: web.config */ - __( 'We recommend you back up your existing %1$s and %2$s files.' ), - 'wp-config.php', - 'web.config' - ); - } else { - echo '' . __( 'Caution:' ) . ' '; - printf( - /* translators: 1: wp-config.php */ - __( 'We recommend you back up your existing %s file.' ), - 'wp-config.php' - ); - } - ?>

    +

    + ' . __( 'Caution:' ) . ' '; + printf( + /* translators: 1: wp-config.php 2: .htaccess */ + __( 'We recommend you back up your existing %1$s and %2$s files.' ), + 'wp-config.php', + '.htaccess' + ); + } elseif ( file_exists( $home_path . 'web.config' ) ) { + echo '' . __( 'Caution:' ) . ' '; + printf( + /* translators: 1: wp-config.php 2: web.config */ + __( 'We recommend you back up your existing %1$s and %2$s files.' ), + 'wp-config.php', + 'web.config' + ); + } else { + echo '' . __( 'Caution:' ) . ' '; + printf( + /* translators: 1: wp-config.php */ + __( 'We recommend you back up your existing %s file.' ), + 'wp-config.php' + ); + } + ?> +

      -
    1. + above the line reading %3$s:' ), 'wp-config.php', @@ -434,7 +476,9 @@ function network_step2( $errors = false ) { * https://i18n.svn.wordpress.org//branches//dist/wp-config-sample.php */ '/* ' . __( 'That’s all, stop editing! Happy blogging.' ) . ' */' - ); ?>

      + ); + ?> +

      '', 'SECURE_AUTH_KEY' => '', 'LOGGED_IN_KEY' => '', 'NONCE_KEY' => '', 'AUTH_SALT' => '', 'SECURE_AUTH_SALT' => '', 'LOGGED_IN_SALT' => '', 'NONCE_SALT' => '' ); - foreach ( $keys_salts as $c => $v ) { - if ( defined( $c ) ) - unset( $keys_salts[ $c ] ); + $keys_salts = array( + 'AUTH_KEY' => '', + 'SECURE_AUTH_KEY' => '', + 'LOGGED_IN_KEY' => '', + 'NONCE_KEY' => '', + 'AUTH_SALT' => '', + 'SECURE_AUTH_SALT' => '', + 'LOGGED_IN_SALT' => '', + 'NONCE_SALT' => '', + ); +foreach ( $keys_salts as $c => $v ) { + if ( defined( $c ) ) { + unset( $keys_salts[ $c ] ); } +} - if ( ! empty( $keys_salts ) ) { - $keys_salts_str = ''; - $from_api = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' ); - if ( is_wp_error( $from_api ) ) { - foreach ( $keys_salts as $c => $v ) { - $keys_salts_str .= "\ndefine( '$c', '" . wp_generate_password( 64, true, true ) . "' );"; - } - } else { - $from_api = explode( "\n", wp_remote_retrieve_body( $from_api ) ); - foreach ( $keys_salts as $c => $v ) { - $keys_salts_str .= "\ndefine( '$c', '" . substr( array_shift( $from_api ), 28, 64 ) . "' );"; - } +if ( ! empty( $keys_salts ) ) { + $keys_salts_str = ''; + $from_api = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' ); + if ( is_wp_error( $from_api ) ) { + foreach ( $keys_salts as $c => $v ) { + $keys_salts_str .= "\ndefine( '$c', '" . wp_generate_password( 64, true, true ) . "' );"; } - $num_keys_salts = count( $keys_salts ); + } else { + $from_api = explode( "\n", wp_remote_retrieve_body( $from_api ) ); + foreach ( $keys_salts as $c => $v ) { + $keys_salts_str .= "\ndefine( '$c', '" . substr( array_shift( $from_api ), 28, 64 ) . "' );"; + } + } + $num_keys_salts = count( $keys_salts ); ?> -

      - wp-config.php' - ); - } else { - printf( - /* translators: 1: wp-config.php */ - __( 'These unique authentication keys are also missing from your %s file.' ), - 'wp-config.php' - ); - } +

      + wp-config.php' + ); + } else { + printf( + /* translators: 1: wp-config.php */ + __( 'These unique authentication keys are also missing from your %s file.' ), + 'wp-config.php' + ); + } ?>

    2. + $web_config_file = ' @@ -504,14 +558,14 @@ define('BLOG_ID_CURRENT_SITE', 1); '; - if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) { - $web_config_file .= ' + if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) { + $web_config_file .= ' '; - } - $web_config_file .= ' + } + $web_config_file .= ' @@ -542,26 +596,28 @@ define('BLOG_ID_CURRENT_SITE', 1); '; - echo '
    3. '; - printf( - /* translators: 1: a filename like .htaccess. 2: a file path. */ - __( 'Add the following to your %1$s file in %2$s, replacing other WordPress rules:' ), - 'web.config', - '' . $home_path . '' - ); - echo '

      '; - if ( ! $subdomain_install && WP_CONTENT_DIR != ABSPATH . 'wp-content' ) - echo '

      ' . __( 'Warning:' ) . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '

      '; - ?> -
    - ' . $home_path . '' ); echo '

    '; - if ( ! $subdomain_install && WP_CONTENT_DIR != ABSPATH . 'wp-content' ) + if ( ! $subdomain_install && WP_CONTENT_DIR != ABSPATH . 'wp-content' ) { echo '

    ' . __( 'Warning:' ) . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '

    '; + } ?> - + if ( ! is_multisite() ) { + ?>

    - 15, + 'timeout' => 15, 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ), - 'body' => array( - 'action' => $action, - 'request' => serialize( $args ) - ) + 'body' => array( + 'action' => $action, + 'request' => serialize( $args ), + ), ); - $request = wp_remote_post( $url, $http_args ); + $request = wp_remote_post( $url, $http_args ); if ( $ssl && is_wp_error( $request ) ) { trigger_error( @@ -170,8 +171,9 @@ function plugins_api( $action, $args = array() ) { $request = wp_remote_post( $http_url, $http_args ); } - if ( is_wp_error($request) ) { - $res = new WP_Error( 'plugins_api_failed', + if ( is_wp_error( $request ) ) { + $res = new WP_Error( + 'plugins_api_failed', sprintf( /* translators: %s: support forums URL */ __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the support forums.' ), @@ -182,7 +184,8 @@ function plugins_api( $action, $args = array() ) { } else { $res = maybe_unserialize( wp_remote_retrieve_body( $request ) ); if ( ! is_object( $res ) && ! is_array( $res ) ) { - $res = new WP_Error( 'plugins_api_failed', + $res = new WP_Error( + 'plugins_api_failed', sprintf( /* translators: %s: support forums URL */ __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the support forums.' ), @@ -192,7 +195,7 @@ function plugins_api( $action, $args = array() ) { ); } } - } elseif ( !is_wp_error($res) ) { + } elseif ( ! is_wp_error( $res ) ) { $res->external = true; } @@ -217,14 +220,16 @@ function plugins_api( $action, $args = array() ) { * @return array */ function install_popular_tags( $args = array() ) { - $key = md5(serialize($args)); - if ( false !== ($tags = get_site_transient('poptags_' . $key) ) ) + $key = md5( serialize( $args ) ); + if ( false !== ( $tags = get_site_transient( 'poptags_' . $key ) ) ) { return $tags; + } - $tags = plugins_api('hot_tags', $args); + $tags = plugins_api( 'hot_tags', $args ); - if ( is_wp_error($tags) ) + if ( is_wp_error( $tags ) ) { return $tags; + } set_site_transient( 'poptags_' . $key, $tags, 3 * HOUR_IN_SECONDS ); @@ -241,30 +246,35 @@ function install_dashboard() { '; } @@ -280,7 +290,8 @@ function install_dashboard() { function install_search_form( $deprecated = true ) { $type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term'; $term = isset( $_REQUEST['s'] ) ? wp_unslash( $_REQUEST['s'] ) : ''; - ?> + ?> + 'search-submit' ) ); ?> - +
    -

    -
    +

    + @@ -315,8 +328,8 @@ function install_plugins_upload() { /** * Show a username form for the favorites page - * @since 3.5.0 * + * @since 3.5.0 */ function install_plugins_favorites_form() { $user = get_user_option( 'wporg_favorites' ); @@ -346,15 +359,15 @@ function display_plugins_table() { global $wp_list_table; switch ( current_filter() ) { - case 'install_plugins_favorites' : + case 'install_plugins_favorites': if ( empty( $_GET['user'] ) && ! get_user_option( 'wporg_favorites' ) ) { return; } break; - case 'install_plugins_recommended' : + case 'install_plugins_recommended': echo '

    ' . __( 'These suggestions are based on the plugins you and other users have installed.' ) . '

    '; break; - case 'install_plugins_beta' : + case 'install_plugins_beta': printf( '

    ' . __( 'You are using a development version of WordPress. These feature plugins are also under development. Learn more.' ) . '

    ', 'https://make.wordpress.org/core/handbook/about/release-cycle/features-as-plugins/' @@ -385,29 +398,31 @@ function display_plugins_table() { * @type string $file Plugin filename relative to the plugins directory. * } */ -function install_plugin_install_status($api, $loop = false) { +function install_plugin_install_status( $api, $loop = false ) { // This function is called recursively, $loop prevents further loops. - if ( is_array($api) ) + if ( is_array( $api ) ) { $api = (object) $api; + } // Default to a "new" plugin - $status = 'install'; - $url = false; + $status = 'install'; + $url = false; $update_file = false; /* * Check to see if this plugin is known to be installed, * and has an update awaiting it. */ - $update_plugins = get_site_transient('update_plugins'); + $update_plugins = get_site_transient( 'update_plugins' ); if ( isset( $update_plugins->response ) ) { - foreach ( (array)$update_plugins->response as $file => $plugin ) { + foreach ( (array) $update_plugins->response as $file => $plugin ) { if ( $plugin->slug === $api->slug ) { - $status = 'update_available'; + $status = 'update_available'; $update_file = $file; - $version = $plugin->new_version; - if ( current_user_can('update_plugins') ) - $url = wp_nonce_url(self_admin_url('update.php?action=upgrade-plugin&plugin=' . $update_file), 'upgrade-plugin_' . $update_file); + $version = $plugin->new_version; + if ( current_user_can( 'update_plugins' ) ) { + $url = wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' . $update_file ), 'upgrade-plugin_' . $update_file ); + } break; } } @@ -415,36 +430,39 @@ function install_plugin_install_status($api, $loop = false) { if ( 'install' == $status ) { if ( is_dir( WP_PLUGIN_DIR . '/' . $api->slug ) ) { - $installed_plugin = get_plugins('/' . $api->slug); - if ( empty($installed_plugin) ) { - if ( current_user_can('install_plugins') ) - $url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug); + $installed_plugin = get_plugins( '/' . $api->slug ); + if ( empty( $installed_plugin ) ) { + if ( current_user_can( 'install_plugins' ) ) { + $url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $api->slug ), 'install-plugin_' . $api->slug ); + } } else { - $key = array_keys( $installed_plugin ); - $key = reset( $key ); //Use the first plugin regardless of the name, Could have issues for multiple-plugins in one directory if they share different version numbers + $key = array_keys( $installed_plugin ); + $key = reset( $key ); //Use the first plugin regardless of the name, Could have issues for multiple-plugins in one directory if they share different version numbers $update_file = $api->slug . '/' . $key; - if ( version_compare($api->version, $installed_plugin[ $key ]['Version'], '=') ){ + if ( version_compare( $api->version, $installed_plugin[ $key ]['Version'], '=' ) ) { $status = 'latest_installed'; - } elseif ( version_compare($api->version, $installed_plugin[ $key ]['Version'], '<') ) { - $status = 'newer_installed'; + } elseif ( version_compare( $api->version, $installed_plugin[ $key ]['Version'], '<' ) ) { + $status = 'newer_installed'; $version = $installed_plugin[ $key ]['Version']; } else { //If the above update check failed, Then that probably means that the update checker has out-of-date information, force a refresh if ( ! $loop ) { - delete_site_transient('update_plugins'); + delete_site_transient( 'update_plugins' ); wp_update_plugins(); - return install_plugin_install_status($api, true); + return install_plugin_install_status( $api, true ); } } } } else { // "install" & no directory with that slug - if ( current_user_can('install_plugins') ) - $url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug); + if ( current_user_can( 'install_plugins' ) ) { + $url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $api->slug ), 'install-plugin_' . $api->slug ); + } } } - if ( isset($_GET['from']) ) + if ( isset( $_GET['from'] ) ) { $url .= '&from=' . urlencode( wp_unslash( $_GET['from'] ) ); + } $file = $update_file; return compact( 'status', 'url', 'version', 'file' ); @@ -464,45 +482,69 @@ function install_plugin_information() { return; } - $api = plugins_api( 'plugin_information', array( - 'slug' => wp_unslash( $_REQUEST['plugin'] ), - 'is_ssl' => is_ssl(), - 'fields' => array( - 'banners' => true, - 'reviews' => true, - 'downloaded' => false, - 'active_installs' => true + $api = plugins_api( + 'plugin_information', array( + 'slug' => wp_unslash( $_REQUEST['plugin'] ), + 'is_ssl' => is_ssl(), + 'fields' => array( + 'banners' => true, + 'reviews' => true, + 'downloaded' => false, + 'active_installs' => true, + ), ) - ) ); + ); if ( is_wp_error( $api ) ) { wp_die( $api ); } $plugins_allowedtags = array( - 'a' => array( 'href' => array(), 'title' => array(), 'target' => array() ), - 'abbr' => array( 'title' => array() ), 'acronym' => array( 'title' => array() ), - 'code' => array(), 'pre' => array(), 'em' => array(), 'strong' => array(), - 'div' => array( 'class' => array() ), 'span' => array( 'class' => array() ), - 'p' => array(), 'br' => array(), 'ul' => array(), 'ol' => array(), 'li' => array(), - 'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), 'h5' => array(), 'h6' => array(), - 'img' => array( 'src' => array(), 'class' => array(), 'alt' => array() ), + 'a' => array( + 'href' => array(), + 'title' => array(), + 'target' => array(), + ), + 'abbr' => array( 'title' => array() ), + 'acronym' => array( 'title' => array() ), + 'code' => array(), + 'pre' => array(), + 'em' => array(), + 'strong' => array(), + 'div' => array( 'class' => array() ), + 'span' => array( 'class' => array() ), + 'p' => array(), + 'br' => array(), + 'ul' => array(), + 'ol' => array(), + 'li' => array(), + 'h1' => array(), + 'h2' => array(), + 'h3' => array(), + 'h4' => array(), + 'h5' => array(), + 'h6' => array(), + 'img' => array( + 'src' => array(), + 'class' => array(), + 'alt' => array(), + ), 'blockquote' => array( 'cite' => true ), ); $plugins_section_titles = array( - 'description' => _x( 'Description', 'Plugin installer section title' ), + 'description' => _x( 'Description', 'Plugin installer section title' ), 'installation' => _x( 'Installation', 'Plugin installer section title' ), - 'faq' => _x( 'FAQ', 'Plugin installer section title' ), - 'screenshots' => _x( 'Screenshots', 'Plugin installer section title' ), - 'changelog' => _x( 'Changelog', 'Plugin installer section title' ), - 'reviews' => _x( 'Reviews', 'Plugin installer section title' ), - 'other_notes' => _x( 'Other Notes', 'Plugin installer section title' ) + 'faq' => _x( 'FAQ', 'Plugin installer section title' ), + 'screenshots' => _x( 'Screenshots', 'Plugin installer section title' ), + 'changelog' => _x( 'Changelog', 'Plugin installer section title' ), + 'reviews' => _x( 'Reviews', 'Plugin installer section title' ), + 'other_notes' => _x( 'Other Notes', 'Plugin installer section title' ), ); // Sanitize HTML foreach ( (array) $api->sections as $section_name => $content ) { - $api->sections[$section_name] = wp_kses( $content, $plugins_allowedtags ); + $api->sections[ $section_name ] = wp_kses( $content, $plugins_allowedtags ); } foreach ( array( 'version', 'author', 'requires', 'tested', 'homepage', 'downloaded', 'slug' ) as $key ) { @@ -516,7 +558,7 @@ function install_plugin_information() { $section = isset( $_REQUEST['section'] ) ? wp_unslash( $_REQUEST['section'] ) : 'description'; // Default to the Description tab, Do not translate, API returns English. if ( empty( $section ) || ! isset( $api->sections[ $section ] ) ) { $section_titles = array_keys( (array) $api->sections ); - $section = reset( $section_titles ); + $section = reset( $section_titles ); } iframe_header( __( 'Plugin Installation' ) ); @@ -525,8 +567,8 @@ function install_plugin_information() { if ( ! empty( $api->banners ) && ( ! empty( $api->banners['low'] ) || ! empty( $api->banners['high'] ) ) ) { $_with_banner = 'with-banner'; - $low = empty( $api->banners['low'] ) ? $api->banners['high'] : $api->banners['low']; - $high = empty( $api->banners['high'] ) ? $api->banners['low'] : $api->banners['high']; + $low = empty( $api->banners['low'] ) ? $api->banners['high'] : $api->banners['low']; + $high = empty( $api->banners['high'] ) ? $api->banners['low'] : $api->banners['high']; ?> Header admin panel. - * - * Referenced via add_theme_support('custom-header') in twentyeleven_setup(). - * - * @since Twenty Eleven 1.0 - */ -function twentyeleven_admin_header_style() { -?> + /** + * Styles the header image displayed on the Appearance > Header admin panel. + * + * Referenced via add_theme_support('custom-header') in twentyeleven_setup(). + * + * @since Twenty Eleven 1.0 + */ + function twentyeleven_admin_header_style() { + ?> - Header admin panel. - * - * Referenced via add_theme_support('custom-header') in twentyeleven_setup(). - * - * @since Twenty Eleven 1.0 - */ -function twentyeleven_admin_header_image() { ?> -
    - -

    + /** + * Custom header image markup displayed on the Appearance > Header admin panel. + * + * Referenced via add_theme_support('custom-header') in twentyeleven_setup(). + * + * @since Twenty Eleven 1.0 + */ + function twentyeleven_admin_header_image() { + +?> +
    + +

    - + -
    - + ' . __( 'Continue reading ', 'twentyeleven' ) . ''; -} + /** + * Return a "Continue Reading" link for excerpts + * + * @since Twenty Eleven 1.0 + * + * @return string The "Continue Reading" HTML link. + */ + function twentyeleven_continue_reading_link() { + return ' ' . __( 'Continue reading ', 'twentyeleven' ) . ''; + } endif; // twentyeleven_continue_reading_link /** @@ -428,8 +438,9 @@ add_filter( 'get_the_excerpt', 'twentyeleven_custom_excerpt_more' ); * @return array The filtered page menu arguments. */ function twentyeleven_page_menu_args( $args ) { - if ( ! isset( $args['show_home'] ) ) + if ( ! isset( $args['show_home'] ) ) { $args['show_home'] = true; + } return $args; } add_filter( 'wp_page_menu_args', 'twentyeleven_page_menu_args' ); @@ -445,76 +456,88 @@ function twentyeleven_widgets_init() { register_widget( 'Twenty_Eleven_Ephemera_Widget' ); - register_sidebar( array( - 'name' => __( 'Main Sidebar', 'twentyeleven' ), - 'id' => 'sidebar-1', - 'before_widget' => '', - 'before_title' => '

    ', - 'after_title' => '

    ', - ) ); + register_sidebar( + array( + 'name' => __( 'Main Sidebar', 'twentyeleven' ), + 'id' => 'sidebar-1', + 'before_widget' => '', + 'before_title' => '

    ', + 'after_title' => '

    ', + ) + ); - register_sidebar( array( - 'name' => __( 'Showcase Sidebar', 'twentyeleven' ), - 'id' => 'sidebar-2', - 'description' => __( 'The sidebar for the optional Showcase Template', 'twentyeleven' ), - 'before_widget' => '', - 'before_title' => '

    ', - 'after_title' => '

    ', - ) ); + register_sidebar( + array( + 'name' => __( 'Showcase Sidebar', 'twentyeleven' ), + 'id' => 'sidebar-2', + 'description' => __( 'The sidebar for the optional Showcase Template', 'twentyeleven' ), + 'before_widget' => '', + 'before_title' => '

    ', + 'after_title' => '

    ', + ) + ); - register_sidebar( array( - 'name' => __( 'Footer Area One', 'twentyeleven' ), - 'id' => 'sidebar-3', - 'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ), - 'before_widget' => '', - 'before_title' => '

    ', - 'after_title' => '

    ', - ) ); + register_sidebar( + array( + 'name' => __( 'Footer Area One', 'twentyeleven' ), + 'id' => 'sidebar-3', + 'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ), + 'before_widget' => '', + 'before_title' => '

    ', + 'after_title' => '

    ', + ) + ); - register_sidebar( array( - 'name' => __( 'Footer Area Two', 'twentyeleven' ), - 'id' => 'sidebar-4', - 'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ), - 'before_widget' => '', - 'before_title' => '

    ', - 'after_title' => '

    ', - ) ); + register_sidebar( + array( + 'name' => __( 'Footer Area Two', 'twentyeleven' ), + 'id' => 'sidebar-4', + 'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ), + 'before_widget' => '', + 'before_title' => '

    ', + 'after_title' => '

    ', + ) + ); - register_sidebar( array( - 'name' => __( 'Footer Area Three', 'twentyeleven' ), - 'id' => 'sidebar-5', - 'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ), - 'before_widget' => '', - 'before_title' => '

    ', - 'after_title' => '

    ', - ) ); + register_sidebar( + array( + 'name' => __( 'Footer Area Three', 'twentyeleven' ), + 'id' => 'sidebar-5', + 'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ), + 'before_widget' => '', + 'before_title' => '

    ', + 'after_title' => '

    ', + ) + ); } add_action( 'widgets_init', 'twentyeleven_widgets_init' ); if ( ! function_exists( 'twentyeleven_content_nav' ) ) : -/** - * Display navigation to next/previous pages when applicable. - * - * @since Twenty Eleven 1.0 - * - * @param string $html_id The HTML id attribute. - */ -function twentyeleven_content_nav( $html_id ) { - global $wp_query; + /** + * Display navigation to next/previous pages when applicable. + * + * @since Twenty Eleven 1.0 + * + * @param string $html_id The HTML id attribute. + */ + function twentyeleven_content_nav( $html_id ) { + global $wp_query; - if ( $wp_query->max_num_pages > 1 ) : ?> - - max_num_pages > 1 ) : + ?> + + ]*?href=[\'"](.+?)[\'"]/is', get_the_content(), $matches ) ) + if ( ! preg_match( '/]*?href=[\'"](.+?)[\'"]/is', get_the_content(), $matches ) ) { return false; + } return esc_url_raw( $matches[1] ); } @@ -560,14 +585,17 @@ function twentyeleven_url_grabber() { function twentyeleven_footer_sidebar_class() { $count = 0; - if ( is_active_sidebar( 'sidebar-3' ) ) + if ( is_active_sidebar( 'sidebar-3' ) ) { $count++; + } - if ( is_active_sidebar( 'sidebar-4' ) ) + if ( is_active_sidebar( 'sidebar-4' ) ) { $count++; + } - if ( is_active_sidebar( 'sidebar-5' ) ) + if ( is_active_sidebar( 'sidebar-5' ) ) { $count++; + } $class = ''; @@ -583,102 +611,117 @@ function twentyeleven_footer_sidebar_class() { break; } - if ( $class ) + if ( $class ) { echo 'class="' . esc_attr( $class ) . '"'; + } } if ( ! function_exists( 'twentyeleven_comment' ) ) : -/** - * Template for comments and pingbacks. - * - * To override this walker in a child theme without modifying the comments template - * simply create your own twentyeleven_comment(), and that function will be used instead. - * - * Used as a callback by wp_list_comments() for displaying the comments. - * - * @since Twenty Eleven 1.0 - * - * @param object $comment The comment object. - * @param array $args An array of comment arguments. @see get_comment_reply_link() - * @param int $depth The depth of the comment. - */ -function twentyeleven_comment( $comment, $args, $depth ) { - $GLOBALS['comment'] = $comment; - switch ( $comment->comment_type ) : - case 'pingback' : - case 'trackback' : - ?> -
  • + /** + * Template for comments and pingbacks. + * + * To override this walker in a child theme without modifying the comments template + * simply create your own twentyeleven_comment(), and that function will be used instead. + * + * Used as a callback by wp_list_comments() for displaying the comments. + * + * @since Twenty Eleven 1.0 + * + * @param object $comment The comment object. + * @param array $args An array of comment arguments. @see get_comment_reply_link() + * @param int $depth The depth of the comment. + */ + function twentyeleven_comment( $comment, $args, $depth ) { + $GLOBALS['comment'] = $comment; + switch ( $comment->comment_type ) : + case 'pingback': + case 'trackback': + ?> +
  • ', '' ); ?>

    -
  • id="li-comment-"> + break; + default: + ?> +
  • id="li-comment-">
    comment_parent ) - $avatar_size = 39; + if ( '0' != $comment->comment_parent ) { + $avatar_size = 39; + } echo get_avatar( $comment, $avatar_size ); /* translators: 1: comment author, 2: date and time */ - printf( __( '%1$s on %2$s said:', 'twentyeleven' ), + printf( + __( '%1$s on %2$s said:', 'twentyeleven' ), sprintf( '%s', get_comment_author_link() ), - sprintf( '', + sprintf( + '', esc_url( get_comment_link( $comment->comment_ID ) ), get_comment_time( 'c' ), /* translators: 1: date, 2: time */ sprintf( __( '%1$s at %2$s', 'twentyeleven' ), get_comment_date(), get_comment_time() ) ) ); - ?> + ?> - ', '' ); ?> -
    + ', '' ); ?> +
  • - comment_approved == '0' ) : ?> + comment_approved == '0' ) : ?>
    - + -
    +
    -
    - __( 'Reply ', 'twentyeleven' ), 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?> -
    - +
    + __( 'Reply ', 'twentyeleven' ), + 'depth' => $depth, + 'max_depth' => $args['max_depth'], + ) + ) + ); +?> +
    + - Posted on by ', 'twentyeleven' ), - esc_url( get_permalink() ), - esc_attr( get_the_time() ), - esc_attr( get_the_date( 'c' ) ), - esc_html( get_the_date() ), - esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), - esc_attr( sprintf( __( 'View all posts by %s', 'twentyeleven' ), get_the_author() ) ), - get_the_author() - ); -} + /** + * Print HTML with meta information for the current post-date/time and author. + * + * Create your own twentyeleven_posted_on to override in a child theme + * + * @since Twenty Eleven 1.0 + */ + function twentyeleven_posted_on() { + printf( + __( 'Posted on by ', 'twentyeleven' ), + esc_url( get_permalink() ), + esc_attr( get_the_time() ), + esc_attr( get_the_date( 'c' ) ), + esc_html( get_the_date() ), + esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), + esc_attr( sprintf( __( 'View all posts by %s', 'twentyeleven' ), get_the_author() ) ), + get_the_author() + ); + } endif; /** @@ -694,11 +737,13 @@ endif; */ function twentyeleven_body_classes( $classes ) { - if ( function_exists( 'is_multi_author' ) && ! is_multi_author() ) + if ( function_exists( 'is_multi_author' ) && ! is_multi_author() ) { $classes[] = 'single-author'; + } - if ( is_singular() && ! is_home() && ! is_page_template( 'showcase.php' ) && ! is_page_template( 'sidebar-page.php' ) ) + if ( is_singular() && ! is_home() && ! is_page_template( 'showcase.php' ) && ! is_page_template( 'sidebar-page.php' ) ) { $classes[] = 'singular'; + } return $classes; } @@ -719,26 +764,30 @@ function twentyeleven_get_gallery_images() { if ( function_exists( 'get_post_galleries' ) ) { $galleries = get_post_galleries( get_the_ID(), false ); - if ( isset( $galleries[0]['ids'] ) ) + if ( isset( $galleries[0]['ids'] ) ) { $images = explode( ',', $galleries[0]['ids'] ); + } } else { $pattern = get_shortcode_regex(); preg_match( "/$pattern/s", get_the_content(), $match ); $atts = shortcode_parse_atts( $match[3] ); - if ( isset( $atts['ids'] ) ) + if ( isset( $atts['ids'] ) ) { $images = explode( ',', $atts['ids'] ); + } } if ( ! $images ) { - $images = get_posts( array( - 'fields' => 'ids', - 'numberposts' => 999, - 'order' => 'ASC', - 'orderby' => 'menu_order', - 'post_mime_type' => 'image', - 'post_parent' => get_the_ID(), - 'post_type' => 'attachment', - ) ); + $images = get_posts( + array( + 'fields' => 'ids', + 'numberposts' => 999, + 'order' => 'ASC', + 'orderby' => 'menu_order', + 'post_mime_type' => 'image', + 'post_parent' => get_the_ID(), + 'post_type' => 'attachment', + ) + ); } return $images; diff --git a/wp-content/themes/twentyeleven/header.php b/wp-content/themes/twentyeleven/header.php index a2ad51a211..df8f7eeef9 100644 --- a/wp-content/themes/twentyeleven/header.php +++ b/wp-content/themes/twentyeleven/header.php @@ -24,7 +24,8 @@ -<?php +<title> +<?php // Print the <title> tag based on what is being viewed. global $page, $paged; @@ -35,14 +36,17 @@ // Add the blog description for the home/front page. $site_description = get_bloginfo( 'description', 'display' ); - if ( $site_description && ( is_home() || is_front_page() ) ) - echo " | $site_description"; +if ( $site_description && ( is_home() || is_front_page() ) ) { + echo " | $site_description"; +} // Add a page number if necessary: - if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) - echo esc_html( ' | ' . sprintf( __( 'Page %s', 'twentyeleven' ), max( $paged, $page ) ) ); +if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) { + echo esc_html( ' | ' . sprintf( __( 'Page %s', 'twentyeleven' ), max( $paged, $page ) ) ); +} - ?> + ?> + @@ -54,8 +58,9 @@ * We add some JavaScript to pages with the comment form * to support sites with threaded comments (when in use). */ - if ( is_singular() && get_option( 'thread_comments' ) ) - wp_enqueue_script( 'comment-reply' ); +if ( is_singular() && get_option( 'thread_comments' ) ) { + wp_enqueue_script( 'comment-reply' ); +} /* * Always have wp_head() just before the closing @@ -78,39 +83,39 @@ + if ( $header_image ) : + // Compatibility with versions of WordPress prior to 3.4. + if ( function_exists( 'get_custom_header' ) ) { + /* + * We need to figure out what the minimum width should be for our featured image. + * This result would be the suggested width if the theme were to implement flexible widths. + */ + $header_image_width = get_theme_support( 'custom-header', 'width' ); + } else { + $header_image_width = HEADER_IMAGE_WIDTH; + } + ?> ID ) && - ( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( $header_image_width, $header_image_width ) ) ) && - $image[1] >= $header_image_width ) : - // Houston, we have a new header image! - echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' ); - else : - // Compatibility with versions of WordPress prior to 3.4. - if ( function_exists( 'get_custom_header' ) ) { - $header_image_width = get_custom_header()->width; - $header_image_height = get_custom_header()->height; - } else { - $header_image_width = HEADER_IMAGE_WIDTH; - $header_image_height = HEADER_IMAGE_HEIGHT; - } - ?> + /* + * The header image. + * Check if this is a post or page, if it has a thumbnail, and if it's a big one + */ + if ( is_singular() && has_post_thumbnail( $post->ID ) && + ( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( $header_image_width, $header_image_width ) ) ) && + $image[1] >= $header_image_width ) : + // Houston, we have a new header image! + echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' ); + else : + // Compatibility with versions of WordPress prior to 3.4. + if ( function_exists( 'get_custom_header' ) ) { + $header_image_width = get_custom_header()->width; + $header_image_height = get_custom_header()->height; + } else { + $header_image_width = HEADER_IMAGE_WIDTH; + $header_image_height = HEADER_IMAGE_HEIGHT; + } + ?> <?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?> @@ -118,15 +123,15 @@ -
    - -
    +
    + +
    diff --git a/wp-content/themes/twentyeleven/image.php b/wp-content/themes/twentyeleven/image.php index 5c855904f6..ea20928542 100644 --- a/wp-content/themes/twentyeleven/image.php +++ b/wp-content/themes/twentyeleven/image.php @@ -12,12 +12,15 @@ get_header(); ?>
    - +
    > @@ -27,7 +30,8 @@ get_header(); ?>
    - \ No newline at end of file + diff --git a/wp-content/themes/twentyeleven/inc/theme-options.php b/wp-content/themes/twentyeleven/inc/theme-options.php index e71ab9a167..8974b151e9 100644 --- a/wp-content/themes/twentyeleven/inc/theme-options.php +++ b/wp-content/themes/twentyeleven/inc/theme-options.php @@ -59,8 +59,8 @@ function twentyeleven_theme_options_init() { 'general' // Settings section. Same as the first argument in the add_settings_section() above ); - add_settings_field( 'link_color', __( 'Link Color', 'twentyeleven' ), 'twentyeleven_settings_field_link_color', 'theme_options', 'general' ); - add_settings_field( 'layout', __( 'Default Layout', 'twentyeleven' ), 'twentyeleven_settings_field_layout', 'theme_options', 'general' ); + add_settings_field( 'link_color', __( 'Link Color', 'twentyeleven' ), 'twentyeleven_settings_field_link_color', 'theme_options', 'general' ); + add_settings_field( 'layout', __( 'Default Layout', 'twentyeleven' ), 'twentyeleven_settings_field_layout', 'theme_options', 'general' ); } add_action( 'admin_init', 'twentyeleven_theme_options_init' ); @@ -99,8 +99,9 @@ function twentyeleven_theme_options_add_page() { 'twentyeleven_theme_options_render_page' // Function that renders the options page ); - if ( ! $theme_page ) + if ( ! $theme_page ) { return; + } add_action( "load-$theme_page", 'twentyeleven_theme_options_help' ); } @@ -124,10 +125,11 @@ function twentyeleven_theme_options_help() { if ( method_exists( $screen, 'add_help_tab' ) ) { // WordPress 3.3.0 - $screen->add_help_tab( array( - 'title' => __( 'Overview', 'twentyeleven' ), - 'id' => 'theme-options-help', - 'content' => $help, + $screen->add_help_tab( + array( + 'title' => __( 'Overview', 'twentyeleven' ), + 'id' => 'theme-options-help', + 'content' => $help, ) ); @@ -146,15 +148,15 @@ function twentyeleven_theme_options_help() { function twentyeleven_color_schemes() { $color_scheme_options = array( 'light' => array( - 'value' => 'light', - 'label' => __( 'Light', 'twentyeleven' ), - 'thumbnail' => get_template_directory_uri() . '/inc/images/light.png', + 'value' => 'light', + 'label' => __( 'Light', 'twentyeleven' ), + 'thumbnail' => get_template_directory_uri() . '/inc/images/light.png', 'default_link_color' => '#1b8be0', ), - 'dark' => array( - 'value' => 'dark', - 'label' => __( 'Dark', 'twentyeleven' ), - 'thumbnail' => get_template_directory_uri() . '/inc/images/dark.png', + 'dark' => array( + 'value' => 'dark', + 'label' => __( 'Dark', 'twentyeleven' ), + 'thumbnail' => get_template_directory_uri() . '/inc/images/dark.png', 'default_link_color' => '#e4741f', ), ); @@ -177,18 +179,18 @@ function twentyeleven_color_schemes() { function twentyeleven_layouts() { $layout_options = array( 'content-sidebar' => array( - 'value' => 'content-sidebar', - 'label' => __( 'Content on left', 'twentyeleven' ), + 'value' => 'content-sidebar', + 'label' => __( 'Content on left', 'twentyeleven' ), 'thumbnail' => get_template_directory_uri() . '/inc/images/content-sidebar.png', ), 'sidebar-content' => array( - 'value' => 'sidebar-content', - 'label' => __( 'Content on right', 'twentyeleven' ), + 'value' => 'sidebar-content', + 'label' => __( 'Content on right', 'twentyeleven' ), 'thumbnail' => get_template_directory_uri() . '/inc/images/sidebar-content.png', ), - 'content' => array( - 'value' => 'content', - 'label' => __( 'One-column, no sidebar', 'twentyeleven' ), + 'content' => array( + 'value' => 'content', + 'label' => __( 'One-column, no sidebar', 'twentyeleven' ), 'thumbnail' => get_template_directory_uri() . '/inc/images/content.png', ), ); @@ -217,8 +219,9 @@ function twentyeleven_get_default_theme_options() { 'theme_layout' => 'content-sidebar', ); - if ( is_rtl() ) + if ( is_rtl() ) { $default_theme_options['theme_layout'] = 'sidebar-content'; + } /** * Filter the Twenty Eleven default options. @@ -238,16 +241,17 @@ function twentyeleven_get_default_theme_options() { * @param string $color_scheme Optional. Color scheme. * Default null (or the active color scheme). * @return string The default link color. -*/ + */ function twentyeleven_get_default_link_color( $color_scheme = null ) { if ( null === $color_scheme ) { - $options = twentyeleven_get_theme_options(); + $options = twentyeleven_get_theme_options(); $color_scheme = $options['color_scheme']; } $color_schemes = twentyeleven_color_schemes(); - if ( ! isset( $color_schemes[ $color_scheme ] ) ) + if ( ! isset( $color_schemes[ $color_scheme ] ) ) { return false; + } return $color_schemes[ $color_scheme ]['default_link_color']; } @@ -364,19 +368,22 @@ function twentyeleven_theme_options_validate( $input ) { $output = $defaults = twentyeleven_get_default_theme_options(); // Color scheme must be in our array of color scheme options - if ( isset( $input['color_scheme'] ) && array_key_exists( $input['color_scheme'], twentyeleven_color_schemes() ) ) + if ( isset( $input['color_scheme'] ) && array_key_exists( $input['color_scheme'], twentyeleven_color_schemes() ) ) { $output['color_scheme'] = $input['color_scheme']; + } // Our defaults for the link color may have changed, based on the color scheme. $output['link_color'] = $defaults['link_color'] = twentyeleven_get_default_link_color( $output['color_scheme'] ); // Link color must be 3 or 6 hexadecimal characters - if ( isset( $input['link_color'] ) && preg_match( '/^#?([a-f0-9]{3}){1,2}$/i', $input['link_color'] ) ) + if ( isset( $input['link_color'] ) && preg_match( '/^#?([a-f0-9]{3}){1,2}$/i', $input['link_color'] ) ) { $output['link_color'] = '#' . strtolower( ltrim( $input['link_color'], '#' ) ); + } // Theme layout must be in our array of theme layout options - if ( isset( $input['theme_layout'] ) && array_key_exists( $input['theme_layout'], twentyeleven_layouts() ) ) + if ( isset( $input['theme_layout'] ) && array_key_exists( $input['theme_layout'], twentyeleven_layouts() ) ) { $output['theme_layout'] = $input['theme_layout']; + } /** * Filter the Twenty Eleven sanitized form input array. @@ -396,11 +403,12 @@ function twentyeleven_theme_options_validate( $input ) { * @since Twenty Eleven 1.0 */ function twentyeleven_enqueue_color_scheme() { - $options = twentyeleven_get_theme_options(); + $options = twentyeleven_get_theme_options(); $color_scheme = $options['color_scheme']; - if ( 'dark' == $color_scheme ) + if ( 'dark' == $color_scheme ) { wp_enqueue_style( 'dark', get_template_directory_uri() . '/colors/dark.css', array(), null ); + } /** * Fires after the styles for the Twenty Eleven color scheme are enqueued. @@ -421,14 +429,15 @@ add_action( 'wp_enqueue_scripts', 'twentyeleven_enqueue_color_scheme' ); * @since Twenty Eleven 1.0 */ function twentyeleven_print_link_color_style() { - $options = twentyeleven_get_theme_options(); + $options = twentyeleven_get_theme_options(); $link_color = $options['link_color']; $default_options = twentyeleven_get_default_theme_options(); // Don't do anything if the current link color is the default. - if ( $default_options['link_color'] == $link_color ) + if ( $default_options['link_color'] == $link_color ) { return; + } ?> get_setting( 'blogdescription' )->transport = 'postMessage'; if ( isset( $wp_customize->selective_refresh ) ) { - $wp_customize->selective_refresh->add_partial( 'blogname', array( - 'selector' => '.site-title a', - 'container_inclusive' => false, - 'render_callback' => 'twentyfifteen_customize_partial_blogname', - ) ); - $wp_customize->selective_refresh->add_partial( 'blogdescription', array( - 'selector' => '.site-description', - 'container_inclusive' => false, - 'render_callback' => 'twentyfifteen_customize_partial_blogdescription', - ) ); + $wp_customize->selective_refresh->add_partial( + 'blogname', array( + 'selector' => '.site-title a', + 'container_inclusive' => false, + 'render_callback' => 'twentyfifteen_customize_partial_blogname', + ) + ); + $wp_customize->selective_refresh->add_partial( + 'blogdescription', array( + 'selector' => '.site-description', + 'container_inclusive' => false, + 'render_callback' => 'twentyfifteen_customize_partial_blogdescription', + ) + ); } // Add color scheme setting and control. - $wp_customize->add_setting( 'color_scheme', array( - 'default' => 'default', - 'sanitize_callback' => 'twentyfifteen_sanitize_color_scheme', - 'transport' => 'postMessage', - ) ); + $wp_customize->add_setting( + 'color_scheme', array( + 'default' => 'default', + 'sanitize_callback' => 'twentyfifteen_sanitize_color_scheme', + 'transport' => 'postMessage', + ) + ); - $wp_customize->add_control( 'color_scheme', array( - 'label' => __( 'Base Color Scheme', 'twentyfifteen' ), - 'section' => 'colors', - 'type' => 'select', - 'choices' => twentyfifteen_get_color_scheme_choices(), - 'priority' => 1, - ) ); + $wp_customize->add_control( + 'color_scheme', array( + 'label' => __( 'Base Color Scheme', 'twentyfifteen' ), + 'section' => 'colors', + 'type' => 'select', + 'choices' => twentyfifteen_get_color_scheme_choices(), + 'priority' => 1, + ) + ); // Add custom header and sidebar text color setting and control. - $wp_customize->add_setting( 'sidebar_textcolor', array( - 'default' => $color_scheme[4], - 'sanitize_callback' => 'sanitize_hex_color', - 'transport' => 'postMessage', - ) ); + $wp_customize->add_setting( + 'sidebar_textcolor', array( + 'default' => $color_scheme[4], + 'sanitize_callback' => 'sanitize_hex_color', + 'transport' => 'postMessage', + ) + ); - $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'sidebar_textcolor', array( - 'label' => __( 'Header and Sidebar Text Color', 'twentyfifteen' ), - 'description' => __( 'Applied to the header on small screens and the sidebar on wide screens.', 'twentyfifteen' ), - 'section' => 'colors', - ) ) ); + $wp_customize->add_control( + new WP_Customize_Color_Control( + $wp_customize, 'sidebar_textcolor', array( + 'label' => __( 'Header and Sidebar Text Color', 'twentyfifteen' ), + 'description' => __( 'Applied to the header on small screens and the sidebar on wide screens.', 'twentyfifteen' ), + 'section' => 'colors', + ) + ) + ); // Remove the core header textcolor control, as it shares the sidebar text color. $wp_customize->remove_control( 'header_textcolor' ); // Add custom header and sidebar background color setting and control. - $wp_customize->add_setting( 'header_background_color', array( - 'default' => $color_scheme[1], - 'sanitize_callback' => 'sanitize_hex_color', - 'transport' => 'postMessage', - ) ); + $wp_customize->add_setting( + 'header_background_color', array( + 'default' => $color_scheme[1], + 'sanitize_callback' => 'sanitize_hex_color', + 'transport' => 'postMessage', + ) + ); - $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'header_background_color', array( - 'label' => __( 'Header and Sidebar Background Color', 'twentyfifteen' ), - 'description' => __( 'Applied to the header on small screens and the sidebar on wide screens.', 'twentyfifteen' ), - 'section' => 'colors', - ) ) ); + $wp_customize->add_control( + new WP_Customize_Color_Control( + $wp_customize, 'header_background_color', array( + 'label' => __( 'Header and Sidebar Background Color', 'twentyfifteen' ), + 'description' => __( 'Applied to the header on small screens and the sidebar on wide screens.', 'twentyfifteen' ), + 'section' => 'colors', + ) + ) + ); // Add an additional description to the header image section. $wp_customize->get_section( 'header_image' )->description = __( 'Applied to the header on small screens and the sidebar on wide screens.', 'twentyfifteen' ); @@ -145,134 +165,136 @@ function twentyfifteen_get_color_schemes() { * } * } */ - return apply_filters( 'twentyfifteen_color_schemes', array( - 'default' => array( - 'label' => __( 'Default', 'twentyfifteen' ), - 'colors' => array( - '#f1f1f1', - '#ffffff', - '#ffffff', - '#333333', - '#333333', - '#f7f7f7', + return apply_filters( + 'twentyfifteen_color_schemes', array( + 'default' => array( + 'label' => __( 'Default', 'twentyfifteen' ), + 'colors' => array( + '#f1f1f1', + '#ffffff', + '#ffffff', + '#333333', + '#333333', + '#f7f7f7', + ), ), - ), - 'dark' => array( - 'label' => __( 'Dark', 'twentyfifteen' ), - 'colors' => array( - '#111111', - '#202020', - '#202020', - '#bebebe', - '#bebebe', - '#1b1b1b', + 'dark' => array( + 'label' => __( 'Dark', 'twentyfifteen' ), + 'colors' => array( + '#111111', + '#202020', + '#202020', + '#bebebe', + '#bebebe', + '#1b1b1b', + ), ), - ), - 'yellow' => array( - 'label' => __( 'Yellow', 'twentyfifteen' ), - 'colors' => array( - '#f4ca16', - '#ffdf00', - '#ffffff', - '#111111', - '#111111', - '#f1f1f1', + 'yellow' => array( + 'label' => __( 'Yellow', 'twentyfifteen' ), + 'colors' => array( + '#f4ca16', + '#ffdf00', + '#ffffff', + '#111111', + '#111111', + '#f1f1f1', + ), ), - ), - 'pink' => array( - 'label' => __( 'Pink', 'twentyfifteen' ), - 'colors' => array( - '#ffe5d1', - '#e53b51', - '#ffffff', - '#352712', - '#ffffff', - '#f1f1f1', + 'pink' => array( + 'label' => __( 'Pink', 'twentyfifteen' ), + 'colors' => array( + '#ffe5d1', + '#e53b51', + '#ffffff', + '#352712', + '#ffffff', + '#f1f1f1', + ), ), - ), - 'purple' => array( - 'label' => __( 'Purple', 'twentyfifteen' ), - 'colors' => array( - '#674970', - '#2e2256', - '#ffffff', - '#2e2256', - '#ffffff', - '#f1f1f1', + 'purple' => array( + 'label' => __( 'Purple', 'twentyfifteen' ), + 'colors' => array( + '#674970', + '#2e2256', + '#ffffff', + '#2e2256', + '#ffffff', + '#f1f1f1', + ), ), - ), - 'blue' => array( - 'label' => __( 'Blue', 'twentyfifteen' ), - 'colors' => array( - '#e9f2f9', - '#55c3dc', - '#ffffff', - '#22313f', - '#ffffff', - '#f1f1f1', + 'blue' => array( + 'label' => __( 'Blue', 'twentyfifteen' ), + 'colors' => array( + '#e9f2f9', + '#55c3dc', + '#ffffff', + '#22313f', + '#ffffff', + '#f1f1f1', + ), ), - ), - ) ); + ) + ); } if ( ! function_exists( 'twentyfifteen_get_color_scheme' ) ) : -/** - * Get the current Twenty Fifteen color scheme. - * - * @since Twenty Fifteen 1.0 - * - * @return array An associative array of either the current or default color scheme hex values. - */ -function twentyfifteen_get_color_scheme() { - $color_scheme_option = get_theme_mod( 'color_scheme', 'default' ); - $color_schemes = twentyfifteen_get_color_schemes(); + /** + * Get the current Twenty Fifteen color scheme. + * + * @since Twenty Fifteen 1.0 + * + * @return array An associative array of either the current or default color scheme hex values. + */ + function twentyfifteen_get_color_scheme() { + $color_scheme_option = get_theme_mod( 'color_scheme', 'default' ); + $color_schemes = twentyfifteen_get_color_schemes(); - if ( array_key_exists( $color_scheme_option, $color_schemes ) ) { - return $color_schemes[ $color_scheme_option ]['colors']; + if ( array_key_exists( $color_scheme_option, $color_schemes ) ) { + return $color_schemes[ $color_scheme_option ]['colors']; + } + + return $color_schemes['default']['colors']; } - - return $color_schemes['default']['colors']; -} endif; // twentyfifteen_get_color_scheme if ( ! function_exists( 'twentyfifteen_get_color_scheme_choices' ) ) : -/** - * Returns an array of color scheme choices registered for Twenty Fifteen. - * - * @since Twenty Fifteen 1.0 - * - * @return array Array of color schemes. - */ -function twentyfifteen_get_color_scheme_choices() { - $color_schemes = twentyfifteen_get_color_schemes(); - $color_scheme_control_options = array(); + /** + * Returns an array of color scheme choices registered for Twenty Fifteen. + * + * @since Twenty Fifteen 1.0 + * + * @return array Array of color schemes. + */ + function twentyfifteen_get_color_scheme_choices() { + $color_schemes = twentyfifteen_get_color_schemes(); + $color_scheme_control_options = array(); - foreach ( $color_schemes as $color_scheme => $value ) { - $color_scheme_control_options[ $color_scheme ] = $value['label']; + foreach ( $color_schemes as $color_scheme => $value ) { + $color_scheme_control_options[ $color_scheme ] = $value['label']; + } + + return $color_scheme_control_options; } - - return $color_scheme_control_options; -} endif; // twentyfifteen_get_color_scheme_choices if ( ! function_exists( 'twentyfifteen_sanitize_color_scheme' ) ) : -/** - * Sanitization callback for color schemes. - * - * @since Twenty Fifteen 1.0 - * - * @param string $value Color scheme name value. - * @return string Color scheme name. - */ -function twentyfifteen_sanitize_color_scheme( $value ) { - $color_schemes = twentyfifteen_get_color_scheme_choices(); + /** + * Sanitization callback for color schemes. + * + * @since Twenty Fifteen 1.0 + * + * @param string $value Color scheme name value. + * @return string Color scheme name. + */ + function twentyfifteen_sanitize_color_scheme( $value ) { + $color_schemes = twentyfifteen_get_color_scheme_choices(); - if ( ! array_key_exists( $value, $color_schemes ) ) { - $value = 'default'; + if ( ! array_key_exists( $value, $color_schemes ) ) { + $value = 'default'; + } + + return $value; } - - return $value; -} endif; // twentyfifteen_sanitize_color_scheme /** @@ -295,7 +317,7 @@ function twentyfifteen_color_scheme_css() { // Convert main and sidebar text hex color to rgba. $color_textcolor_rgb = twentyfifteen_hex2rgb( $color_scheme[3] ); $color_sidebar_textcolor_rgb = twentyfifteen_hex2rgb( $color_scheme[4] ); - $colors = array( + $colors = array( 'background_color' => $color_scheme[0], 'header_background_color' => $color_scheme[1], 'box_background_color' => $color_scheme[2], @@ -348,20 +370,22 @@ add_action( 'customize_preview_init', 'twentyfifteen_customize_preview_js' ); * @return string Color scheme CSS. */ function twentyfifteen_get_color_scheme_css( $colors ) { - $colors = wp_parse_args( $colors, array( - 'background_color' => '', - 'header_background_color' => '', - 'box_background_color' => '', - 'textcolor' => '', - 'secondary_textcolor' => '', - 'border_color' => '', - 'border_focus_color' => '', - 'sidebar_textcolor' => '', - 'sidebar_border_color' => '', - 'sidebar_border_focus_color' => '', - 'secondary_sidebar_textcolor' => '', - 'meta_box_background_color' => '', - ) ); + $colors = wp_parse_args( + $colors, array( + 'background_color' => '', + 'header_background_color' => '', + 'box_background_color' => '', + 'textcolor' => '', + 'secondary_textcolor' => '', + 'border_color' => '', + 'border_focus_color' => '', + 'sidebar_textcolor' => '', + 'sidebar_border_color' => '', + 'sidebar_border_focus_color' => '', + 'secondary_sidebar_textcolor' => '', + 'meta_box_background_color' => '', + ) + ); $css = << 1 && get_option( 'page_comments' ) ) : - ?> -
    - - + + %s', __( 'Featured', 'twentyfifteen' ) ); - } - - $format = get_post_format(); - if ( current_theme_supports( 'post-formats', $format ) ) { - printf( '%1$s%3$s', - sprintf( '%s ', _x( 'Format', 'Used before post format.', 'twentyfifteen' ) ), - esc_url( get_post_format_link( $format ) ), - get_post_format_string( $format ) - ); - } - - if ( in_array( get_post_type(), array( 'post', 'attachment' ) ) ) { - $time_string = ''; - - if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) { - $time_string = ''; + /** + * Prints HTML with meta information for the categories, tags. + * + * @since Twenty Fifteen 1.0 + */ + function twentyfifteen_entry_meta() { + if ( is_sticky() && is_home() && ! is_paged() ) { + printf( '%s', __( 'Featured', 'twentyfifteen' ) ); } - $time_string = sprintf( $time_string, - esc_attr( get_the_date( 'c' ) ), - get_the_date(), - esc_attr( get_the_modified_date( 'c' ) ), - get_the_modified_date() - ); - - printf( '%1$s %3$s', - _x( 'Posted on', 'Used before publish date.', 'twentyfifteen' ), - esc_url( get_permalink() ), - $time_string - ); - } - - if ( 'post' == get_post_type() ) { - if ( is_singular() || is_multi_author() ) { - printf( '', - _x( 'Author', 'Used before post author name.', 'twentyfifteen' ), - esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), - get_the_author() + $format = get_post_format(); + if ( current_theme_supports( 'post-formats', $format ) ) { + printf( + '%1$s%3$s', + sprintf( '%s ', _x( 'Format', 'Used before post format.', 'twentyfifteen' ) ), + esc_url( get_post_format_link( $format ) ), + get_post_format_string( $format ) ); } - $categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfifteen' ) ); - if ( $categories_list && twentyfifteen_categorized_blog() ) { - printf( '%1$s %2$s', - _x( 'Categories', 'Used before category names.', 'twentyfifteen' ), - $categories_list + if ( in_array( get_post_type(), array( 'post', 'attachment' ) ) ) { + $time_string = ''; + + if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) { + $time_string = ''; + } + + $time_string = sprintf( + $time_string, + esc_attr( get_the_date( 'c' ) ), + get_the_date(), + esc_attr( get_the_modified_date( 'c' ) ), + get_the_modified_date() + ); + + printf( + '%1$s %3$s', + _x( 'Posted on', 'Used before publish date.', 'twentyfifteen' ), + esc_url( get_permalink() ), + $time_string ); } - $tags_list = get_the_tag_list( '', _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfifteen' ) ); - if ( $tags_list && ! is_wp_error( $tags_list ) ) { - printf( '%1$s %2$s', - _x( 'Tags', 'Used before tag names.', 'twentyfifteen' ), - $tags_list + if ( 'post' == get_post_type() ) { + if ( is_singular() || is_multi_author() ) { + printf( + '', + _x( 'Author', 'Used before post author name.', 'twentyfifteen' ), + esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), + get_the_author() + ); + } + + $categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfifteen' ) ); + if ( $categories_list && twentyfifteen_categorized_blog() ) { + printf( + '%1$s %2$s', + _x( 'Categories', 'Used before category names.', 'twentyfifteen' ), + $categories_list + ); + } + + $tags_list = get_the_tag_list( '', _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfifteen' ) ); + if ( $tags_list && ! is_wp_error( $tags_list ) ) { + printf( + '%1$s %2$s', + _x( 'Tags', 'Used before tag names.', 'twentyfifteen' ), + $tags_list + ); + } + } + + if ( is_attachment() && wp_attachment_is_image() ) { + // Retrieve attachment metadata. + $metadata = wp_get_attachment_metadata(); + + printf( + '%1$s %3$s × %4$s', + _x( 'Full size', 'Used before full size attachment link.', 'twentyfifteen' ), + esc_url( wp_get_attachment_url() ), + $metadata['width'], + $metadata['height'] ); } - } - if ( is_attachment() && wp_attachment_is_image() ) { - // Retrieve attachment metadata. - $metadata = wp_get_attachment_metadata(); - - printf( '%1$s %3$s × %4$s', - _x( 'Full size', 'Used before full size attachment link.', 'twentyfifteen' ), - esc_url( wp_get_attachment_url() ), - $metadata['width'], - $metadata['height'] - ); + if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) { + echo ''; + /* translators: %s: post title */ + comments_popup_link( sprintf( __( 'Leave a comment on %s', 'twentyfifteen' ), get_the_title() ) ); + echo ''; + } } - - if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) { - echo ''; - /* translators: %s: post title */ - comments_popup_link( sprintf( __( 'Leave a comment on %s', 'twentyfifteen' ), get_the_title() ) ); - echo ''; - } -} endif; /** @@ -136,13 +143,15 @@ endif; function twentyfifteen_categorized_blog() { if ( false === ( $all_the_cool_cats = get_transient( 'twentyfifteen_categories' ) ) ) { // Create an array of all the categories that are attached to posts. - $all_the_cool_cats = get_categories( array( - 'fields' => 'ids', - 'hide_empty' => 1, + $all_the_cool_cats = get_categories( + array( + 'fields' => 'ids', + 'hide_empty' => 1, - // We only need to know if there is more than one category. - 'number' => 2, - ) ); + // We only need to know if there is more than one category. + 'number' => 2, + ) + ); // Count the number of categories that are attached to the posts. $all_the_cool_cats = count( $all_the_cool_cats ); @@ -169,26 +178,26 @@ function twentyfifteen_category_transient_flusher() { delete_transient( 'twentyfifteen_categories' ); } add_action( 'edit_category', 'twentyfifteen_category_transient_flusher' ); -add_action( 'save_post', 'twentyfifteen_category_transient_flusher' ); +add_action( 'save_post', 'twentyfifteen_category_transient_flusher' ); if ( ! function_exists( 'twentyfifteen_post_thumbnail' ) ) : -/** - * Display an optional post thumbnail. - * - * Wraps the post thumbnail in an anchor element on index views, or a div - * element when on single views. - * - * @since Twenty Fifteen 1.0 - */ -function twentyfifteen_post_thumbnail() { - if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) { - return; - } + /** + * Display an optional post thumbnail. + * + * Wraps the post thumbnail in an anchor element on index views, or a div + * element when on single views. + * + * @since Twenty Fifteen 1.0 + */ + function twentyfifteen_post_thumbnail() { + if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) { + return; + } - if ( is_singular() ) : - ?> + if ( is_singular() ) : + ?> -
    +
    @@ -200,59 +209,61 @@ function twentyfifteen_post_thumbnail() { ?> - %2$s', - esc_url( get_permalink( get_the_ID() ) ), - /* translators: %s: Name of current post */ - sprintf( __( 'Continue reading %s', 'twentyfifteen' ), '' . get_the_title( get_the_ID() ) . '' ) + /** + * Replaces "[...]" (appended to automatically generated excerpts) with ... and a 'Continue reading' link. + * + * @since Twenty Fifteen 1.0 + * + * @return string 'Continue reading' link prepended with an ellipsis. + */ + function twentyfifteen_excerpt_more( $more ) { + $link = sprintf( + '%2$s', + esc_url( get_permalink( get_the_ID() ) ), + /* translators: %s: Name of current post */ + sprintf( __( 'Continue reading %s', 'twentyfifteen' ), '' . get_the_title( get_the_ID() ) . '' ) ); - return ' … ' . $link; -} -add_filter( 'excerpt_more', 'twentyfifteen_excerpt_more' ); + return ' … ' . $link; + } + add_filter( 'excerpt_more', 'twentyfifteen_excerpt_more' ); endif; if ( ! function_exists( 'twentyfifteen_the_custom_logo' ) ) : -/** - * Displays the optional custom logo. - * - * Does nothing if the custom logo is not available. - * - * @since Twenty Fifteen 1.5 - */ -function twentyfifteen_the_custom_logo() { - if ( function_exists( 'the_custom_logo' ) ) { - the_custom_logo(); + /** + * Displays the optional custom logo. + * + * Does nothing if the custom logo is not available. + * + * @since Twenty Fifteen 1.5 + */ + function twentyfifteen_the_custom_logo() { + if ( function_exists( 'the_custom_logo' ) ) { + the_custom_logo(); + } } -} endif; diff --git a/wp-content/themes/twentyfifteen/index.php b/wp-content/themes/twentyfifteen/index.php index db77651ebf..4ad3d3829d 100644 --- a/wp-content/themes/twentyfifteen/index.php +++ b/wp-content/themes/twentyfifteen/index.php @@ -29,7 +29,8 @@ get_header(); ?> */ get_template_part( 'content', get_post_format() ); - // End the loop. + // End the loop. endwhile; // Previous/next page navigation. - the_posts_pagination( array( - 'prev_text' => __( 'Previous page', 'twentyfifteen' ), - 'next_text' => __( 'Next page', 'twentyfifteen' ), - 'before_page_number' => '' . __( 'Page', 'twentyfifteen' ) . ' ', - ) ); + the_posts_pagination( + array( + 'prev_text' => __( 'Previous page', 'twentyfifteen' ), + 'next_text' => __( 'Next page', 'twentyfifteen' ), + 'before_page_number' => '' . __( 'Page', 'twentyfifteen' ) . ' ', + ) + ); - // If no content, include the "No posts found" template. + // If no content, include the "No posts found" template. else : get_template_part( 'content', 'none' ); diff --git a/wp-content/themes/twentyfifteen/page.php b/wp-content/themes/twentyfifteen/page.php index 5c7a0b077a..50d0bf1c12 100644 --- a/wp-content/themes/twentyfifteen/page.php +++ b/wp-content/themes/twentyfifteen/page.php @@ -18,7 +18,8 @@ get_header(); ?> comments_template(); endif; - // End the loop. + // End the loop. endwhile; ?> diff --git a/wp-content/themes/twentyfifteen/search.php b/wp-content/themes/twentyfifteen/search.php index 3352841560..174c9f6f92 100644 --- a/wp-content/themes/twentyfifteen/search.php +++ b/wp-content/themes/twentyfifteen/search.php @@ -20,7 +20,9 @@ get_header(); ?> + while ( have_posts() ) : + the_post(); + ?> */ get_template_part( 'content', 'search' ); - // End the loop. + // End the loop. endwhile; // Previous/next page navigation. - the_posts_pagination( array( - 'prev_text' => __( 'Previous page', 'twentyfifteen' ), - 'next_text' => __( 'Next page', 'twentyfifteen' ), - 'before_page_number' => '' . __( 'Page', 'twentyfifteen' ) . ' ', - ) ); + the_posts_pagination( + array( + 'prev_text' => __( 'Previous page', 'twentyfifteen' ), + 'next_text' => __( 'Next page', 'twentyfifteen' ), + 'before_page_number' => '' . __( 'Page', 'twentyfifteen' ) . ' ', + ) + ); - // If no content, include the "No posts found" template. + // If no content, include the "No posts found" template. else : get_template_part( 'content', 'none' ); diff --git a/wp-content/themes/twentyfifteen/sidebar.php b/wp-content/themes/twentyfifteen/sidebar.php index 02308efc37..f2326a8c8f 100644 --- a/wp-content/themes/twentyfifteen/sidebar.php +++ b/wp-content/themes/twentyfifteen/sidebar.php @@ -7,17 +7,19 @@ * @since Twenty Fifteen 1.0 */ -if ( has_nav_menu( 'primary' ) || has_nav_menu( 'social' ) || is_active_sidebar( 'sidebar-1' ) ) : ?> +if ( has_nav_menu( 'primary' ) || has_nav_menu( 'social' ) || is_active_sidebar( 'sidebar-1' ) ) : ?>
    @@ -26,12 +28,14 @@ if ( has_nav_menu( 'primary' ) || has_nav_menu( 'social' ) || is_active_sidebar( diff --git a/wp-content/themes/twentyfifteen/single.php b/wp-content/themes/twentyfifteen/single.php index fda8b5ecdb..4de3a493ad 100644 --- a/wp-content/themes/twentyfifteen/single.php +++ b/wp-content/themes/twentyfifteen/single.php @@ -14,7 +14,8 @@ get_header(); ?> endif; // Previous/next post navigation. - the_post_navigation( array( - 'next_text' => ' ' . - '' . __( 'Next post:', 'twentyfifteen' ) . ' ' . - '%title', - 'prev_text' => ' ' . - '' . __( 'Previous post:', 'twentyfifteen' ) . ' ' . - '%title', - ) ); + the_post_navigation( + array( + 'next_text' => ' ' . + '' . __( 'Next post:', 'twentyfifteen' ) . ' ' . + '%title', + 'prev_text' => ' ' . + '' . __( 'Previous post:', 'twentyfifteen' ) . ' ' . + '%title', + ) + ); - // End the loop. + // End the loop. endwhile; ?> diff --git a/wp-content/themes/twentyfourteen/archive.php b/wp-content/themes/twentyfourteen/archive.php index 6a4deed0f2..e2b4b4145a 100644 --- a/wp-content/themes/twentyfourteen/archive.php +++ b/wp-content/themes/twentyfourteen/archive.php @@ -27,8 +27,8 @@ get_header(); ?>
    ', $term_description ); + if ( ! empty( $term_description ) ) : + printf( '
    %s
    ', $term_description ); endif; ?> @@ -55,11 +55,13 @@ if ( post_password_required() ) {
      'ol', - 'short_ping' => true, - 'avatar_size' => 34, - ) ); + wp_list_comments( + array( + 'style' => 'ol', + 'short_ping' => true, + 'avatar_size' => 34, + ) + ); ?>
    diff --git a/wp-content/themes/twentyfourteen/content-aside.php b/wp-content/themes/twentyfourteen/content-aside.php index 0401579df0..554416dfea 100644 --- a/wp-content/themes/twentyfourteen/content-aside.php +++ b/wp-content/themes/twentyfourteen/content-aside.php @@ -19,8 +19,8 @@ ', '' ); +if ( is_single() ) : + the_title( '

    ', '

    ' ); else : the_title( '

    ', '

    ' ); endif; @@ -44,17 +44,21 @@
    →', 'twentyfourteen' ), - the_title( '', '', false ) - ) ); + the_content( + sprintf( + __( 'Continue reading %s ', 'twentyfourteen' ), + the_title( '', '', false ) + ) + ); - wp_link_pages( array( - 'before' => '', - 'link_before' => '', - 'link_after' => '', - ) ); + wp_link_pages( + array( + 'before' => '', + 'link_before' => '', + 'link_after' => '', + ) + ); ?>
    diff --git a/wp-content/themes/twentyfourteen/content-audio.php b/wp-content/themes/twentyfourteen/content-audio.php index 9fa9df41d4..8fc2095ada 100644 --- a/wp-content/themes/twentyfourteen/content-audio.php +++ b/wp-content/themes/twentyfourteen/content-audio.php @@ -19,8 +19,8 @@ ', '' ); +if ( is_single() ) : + the_title( '

    ', '

    ' ); else : the_title( '

    ', '

    ' ); endif; @@ -44,17 +44,21 @@
    →', 'twentyfourteen' ), - the_title( '', '', false ) - ) ); + the_content( + sprintf( + __( 'Continue reading %s ', 'twentyfourteen' ), + the_title( '', '', false ) + ) + ); - wp_link_pages( array( - 'before' => '', - 'link_before' => '', - 'link_after' => '', - ) ); + wp_link_pages( + array( + 'before' => '', + 'link_before' => '', + 'link_after' => '', + ) + ); ?>
    diff --git a/wp-content/themes/twentyfourteen/content-featured-post.php b/wp-content/themes/twentyfourteen/content-featured-post.php index 6cc88224b4..d5a16fef20 100644 --- a/wp-content/themes/twentyfourteen/content-featured-post.php +++ b/wp-content/themes/twentyfourteen/content-featured-post.php @@ -12,12 +12,12 @@ @@ -29,6 +29,6 @@
    - ','' ); ?> + ', '' ); ?> diff --git a/wp-content/themes/twentyfourteen/content-gallery.php b/wp-content/themes/twentyfourteen/content-gallery.php index 6e3fe83249..db382fef7f 100644 --- a/wp-content/themes/twentyfourteen/content-gallery.php +++ b/wp-content/themes/twentyfourteen/content-gallery.php @@ -19,8 +19,8 @@ ', '' ); +if ( is_single() ) : + the_title( '

    ', '

    ' ); else : the_title( '

    ', '

    ' ); endif; @@ -44,17 +44,21 @@
    →', 'twentyfourteen' ), - the_title( '', '', false ) - ) ); + the_content( + sprintf( + __( 'Continue reading %s ', 'twentyfourteen' ), + the_title( '', '', false ) + ) + ); - wp_link_pages( array( - 'before' => '', - 'link_before' => '', - 'link_after' => '', - ) ); + wp_link_pages( + array( + 'before' => '', + 'link_before' => '', + 'link_after' => '', + ) + ); ?>
    diff --git a/wp-content/themes/twentyfourteen/content-image.php b/wp-content/themes/twentyfourteen/content-image.php index a81e493d06..11aa1e8fd8 100644 --- a/wp-content/themes/twentyfourteen/content-image.php +++ b/wp-content/themes/twentyfourteen/content-image.php @@ -19,8 +19,8 @@ ', '' ); +if ( is_single() ) : + the_title( '

    ', '

    ' ); else : the_title( '

    ', '

    ' ); endif; @@ -44,17 +44,21 @@
    →', 'twentyfourteen' ), - the_title( '', '', false ) - ) ); + the_content( + sprintf( + __( 'Continue reading %s ', 'twentyfourteen' ), + the_title( '', '', false ) + ) + ); - wp_link_pages( array( - 'before' => '', - 'link_before' => '', - 'link_after' => '', - ) ); + wp_link_pages( + array( + 'before' => '', + 'link_before' => '', + 'link_after' => '', + ) + ); ?>
    diff --git a/wp-content/themes/twentyfourteen/content-link.php b/wp-content/themes/twentyfourteen/content-link.php index 858301efc1..5c97986315 100644 --- a/wp-content/themes/twentyfourteen/content-link.php +++ b/wp-content/themes/twentyfourteen/content-link.php @@ -19,8 +19,8 @@ ', '' ); +if ( is_single() ) : + the_title( '

    ', '

    ' ); else : the_title( '

    ', '

    ' ); endif; @@ -44,17 +44,21 @@
    →', 'twentyfourteen' ), - the_title( '', '', false ) - ) ); + the_content( + sprintf( + __( 'Continue reading %s ', 'twentyfourteen' ), + the_title( '', '', false ) + ) + ); - wp_link_pages( array( - 'before' => '', - 'link_before' => '', - 'link_after' => '', - ) ); + wp_link_pages( + array( + 'before' => '', + 'link_before' => '', + 'link_after' => '', + ) + ); ?>
    diff --git a/wp-content/themes/twentyfourteen/content-page.php b/wp-content/themes/twentyfourteen/content-page.php index 98394190b3..6a33baa706 100644 --- a/wp-content/themes/twentyfourteen/content-page.php +++ b/wp-content/themes/twentyfourteen/content-page.php @@ -18,12 +18,14 @@
    '', - 'link_before' => '', - 'link_after' => '', - ) ); + wp_link_pages( + array( + 'before' => '', + 'link_before' => '', + 'link_after' => '', + ) + ); edit_post_link( __( 'Edit', 'twentyfourteen' ), '', '' ); ?> diff --git a/wp-content/themes/twentyfourteen/content-quote.php b/wp-content/themes/twentyfourteen/content-quote.php index 10a5d1122b..fa0b899268 100644 --- a/wp-content/themes/twentyfourteen/content-quote.php +++ b/wp-content/themes/twentyfourteen/content-quote.php @@ -19,8 +19,8 @@ ', '' ); +if ( is_single() ) : + the_title( '

    ', '

    ' ); else : the_title( '

    ', '

    ' ); endif; @@ -44,17 +44,21 @@
    →', 'twentyfourteen' ), - the_title( '', '', false ) - ) ); + the_content( + sprintf( + __( 'Continue reading %s ', 'twentyfourteen' ), + the_title( '', '', false ) + ) + ); - wp_link_pages( array( - 'before' => '', - 'link_before' => '', - 'link_after' => '', - ) ); + wp_link_pages( + array( + 'before' => '', + 'link_before' => '', + 'link_after' => '', + ) + ); ?>
    diff --git a/wp-content/themes/twentyfourteen/content-video.php b/wp-content/themes/twentyfourteen/content-video.php index 4c49aaa145..951a13cffa 100644 --- a/wp-content/themes/twentyfourteen/content-video.php +++ b/wp-content/themes/twentyfourteen/content-video.php @@ -19,8 +19,8 @@ ', '' ); +if ( is_single() ) : + the_title( '

    ', '

    ' ); else : the_title( '

    ', '

    ' ); endif; @@ -44,17 +44,21 @@
    →', 'twentyfourteen' ), - the_title( '', '', false ) - ) ); + the_content( + sprintf( + __( 'Continue reading %s ', 'twentyfourteen' ), + the_title( '', '', false ) + ) + ); - wp_link_pages( array( - 'before' => '', - 'link_before' => '', - 'link_after' => '', - ) ); + wp_link_pages( + array( + 'before' => '', + 'link_before' => '', + 'link_after' => '', + ) + ); ?>
    diff --git a/wp-content/themes/twentyfourteen/content.php b/wp-content/themes/twentyfourteen/content.php index e571d8b38a..03eb3e89dc 100644 --- a/wp-content/themes/twentyfourteen/content.php +++ b/wp-content/themes/twentyfourteen/content.php @@ -21,8 +21,8 @@ ', '' ); +if ( is_single() ) : + the_title( '

    ', '

    ' ); else : the_title( '

    ', '

    ' ); endif; @@ -30,10 +30,11 @@ diff --git a/wp-content/themes/twentyfourteen/featured-content.php b/wp-content/themes/twentyfourteen/featured-content.php index c56edf3e24..f9f32dd33b 100644 --- a/wp-content/themes/twentyfourteen/featured-content.php +++ b/wp-content/themes/twentyfourteen/featured-content.php @@ -19,11 +19,11 @@ do_action( 'twentyfourteen_featured_posts_before' ); $featured_posts = twentyfourteen_get_featured_posts(); - foreach ( (array) $featured_posts as $order => $post ) : - setup_postdata( $post ); + foreach ( (array) $featured_posts as $order => $post ) : + setup_postdata( $post ); - // Include the featured content template. - get_template_part( 'content', 'featured-post' ); + // Include the featured content template. + get_template_part( 'content', 'featured-post' ); endforeach; /** diff --git a/wp-content/themes/twentyfourteen/footer.php b/wp-content/themes/twentyfourteen/footer.php index 519e1288e3..0193c64777 100644 --- a/wp-content/themes/twentyfourteen/footer.php +++ b/wp-content/themes/twentyfourteen/footer.php @@ -25,4 +25,4 @@ - \ No newline at end of file + diff --git a/wp-content/themes/twentyfourteen/functions.php b/wp-content/themes/twentyfourteen/functions.php index 2946d19ddb..49deb790ba 100644 --- a/wp-content/themes/twentyfourteen/functions.php +++ b/wp-content/themes/twentyfourteen/functions.php @@ -44,79 +44,101 @@ if ( version_compare( $GLOBALS['wp_version'], '3.6', '<' ) ) { } if ( ! function_exists( 'twentyfourteen_setup' ) ) : -/** - * Twenty Fourteen setup. - * - * Set up theme defaults and registers support for various WordPress features. - * - * Note that this function is hooked into the after_setup_theme hook, which - * runs before the init hook. The init hook is too late for some features, such - * as indicating support post thumbnails. - * - * @since Twenty Fourteen 1.0 - */ -function twentyfourteen_setup() { - - /* - * Make Twenty Fourteen available for translation. + /** + * Twenty Fourteen setup. * - * Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/twentyfourteen - * If you're building a theme based on Twenty Fourteen, use a find and - * replace to change 'twentyfourteen' to the name of your theme in all - * template files. + * Set up theme defaults and registers support for various WordPress features. + * + * Note that this function is hooked into the after_setup_theme hook, which + * runs before the init hook. The init hook is too late for some features, such + * as indicating support post thumbnails. + * + * @since Twenty Fourteen 1.0 */ - load_theme_textdomain( 'twentyfourteen' ); + function twentyfourteen_setup() { - // This theme styles the visual editor to resemble the theme style. - add_editor_style( array( 'css/editor-style.css', twentyfourteen_font_url(), 'genericons/genericons.css' ) ); + /* + * Make Twenty Fourteen available for translation. + * + * Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/twentyfourteen + * If you're building a theme based on Twenty Fourteen, use a find and + * replace to change 'twentyfourteen' to the name of your theme in all + * template files. + */ + load_theme_textdomain( 'twentyfourteen' ); - // Add RSS feed links to for posts and comments. - add_theme_support( 'automatic-feed-links' ); + // This theme styles the visual editor to resemble the theme style. + add_editor_style( array( 'css/editor-style.css', twentyfourteen_font_url(), 'genericons/genericons.css' ) ); - // Enable support for Post Thumbnails, and declare two sizes. - add_theme_support( 'post-thumbnails' ); - set_post_thumbnail_size( 672, 372, true ); - add_image_size( 'twentyfourteen-full-width', 1038, 576, true ); + // Add RSS feed links to for posts and comments. + add_theme_support( 'automatic-feed-links' ); - // This theme uses wp_nav_menu() in two locations. - register_nav_menus( array( - 'primary' => __( 'Top primary menu', 'twentyfourteen' ), - 'secondary' => __( 'Secondary menu in left sidebar', 'twentyfourteen' ), - ) ); + // Enable support for Post Thumbnails, and declare two sizes. + add_theme_support( 'post-thumbnails' ); + set_post_thumbnail_size( 672, 372, true ); + add_image_size( 'twentyfourteen-full-width', 1038, 576, true ); - /* - * Switch default core markup for search form, comment form, and comments - * to output valid HTML5. - */ - add_theme_support( 'html5', array( - 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption' - ) ); + // This theme uses wp_nav_menu() in two locations. + register_nav_menus( + array( + 'primary' => __( 'Top primary menu', 'twentyfourteen' ), + 'secondary' => __( 'Secondary menu in left sidebar', 'twentyfourteen' ), + ) + ); - /* - * Enable support for Post Formats. - * See https://codex.wordpress.org/Post_Formats - */ - add_theme_support( 'post-formats', array( - 'aside', 'image', 'video', 'audio', 'quote', 'link', 'gallery', - ) ); + /* + * Switch default core markup for search form, comment form, and comments + * to output valid HTML5. + */ + add_theme_support( + 'html5', array( + 'search-form', + 'comment-form', + 'comment-list', + 'gallery', + 'caption', + ) + ); - // This theme allows users to set a custom background. - add_theme_support( 'custom-background', apply_filters( 'twentyfourteen_custom_background_args', array( - 'default-color' => 'f5f5f5', - ) ) ); + /* + * Enable support for Post Formats. + * See https://codex.wordpress.org/Post_Formats + */ + add_theme_support( + 'post-formats', array( + 'aside', + 'image', + 'video', + 'audio', + 'quote', + 'link', + 'gallery', + ) + ); - // Add support for featured content. - add_theme_support( 'featured-content', array( - 'featured_content_filter' => 'twentyfourteen_get_featured_posts', - 'max_posts' => 6, - ) ); + // This theme allows users to set a custom background. + add_theme_support( + 'custom-background', apply_filters( + 'twentyfourteen_custom_background_args', array( + 'default-color' => 'f5f5f5', + ) + ) + ); - // This theme uses its own gallery styles. - add_filter( 'use_default_gallery_style', '__return_false' ); + // Add support for featured content. + add_theme_support( + 'featured-content', array( + 'featured_content_filter' => 'twentyfourteen_get_featured_posts', + 'max_posts' => 6, + ) + ); - // Indicate widget sidebars can use selective refresh in the Customizer. - add_theme_support( 'customize-selective-refresh-widgets' ); -} + // This theme uses its own gallery styles. + add_filter( 'use_default_gallery_style', '__return_false' ); + + // Indicate widget sidebars can use selective refresh in the Customizer. + add_theme_support( 'customize-selective-refresh-widgets' ); + } endif; // twentyfourteen_setup add_action( 'after_setup_theme', 'twentyfourteen_setup' ); @@ -170,33 +192,39 @@ function twentyfourteen_widgets_init() { require get_template_directory() . '/inc/widgets.php'; register_widget( 'Twenty_Fourteen_Ephemera_Widget' ); - register_sidebar( array( - 'name' => __( 'Primary Sidebar', 'twentyfourteen' ), - 'id' => 'sidebar-1', - 'description' => __( 'Main sidebar that appears on the left.', 'twentyfourteen' ), - 'before_widget' => '', - 'before_title' => '

    ', - 'after_title' => '

    ', - ) ); - register_sidebar( array( - 'name' => __( 'Content Sidebar', 'twentyfourteen' ), - 'id' => 'sidebar-2', - 'description' => __( 'Additional sidebar that appears on the right.', 'twentyfourteen' ), - 'before_widget' => '', - 'before_title' => '

    ', - 'after_title' => '

    ', - ) ); - register_sidebar( array( - 'name' => __( 'Footer Widget Area', 'twentyfourteen' ), - 'id' => 'sidebar-3', - 'description' => __( 'Appears in the footer section of the site.', 'twentyfourteen' ), - 'before_widget' => '', - 'before_title' => '

    ', - 'after_title' => '

    ', - ) ); + register_sidebar( + array( + 'name' => __( 'Primary Sidebar', 'twentyfourteen' ), + 'id' => 'sidebar-1', + 'description' => __( 'Main sidebar that appears on the left.', 'twentyfourteen' ), + 'before_widget' => '', + 'before_title' => '

    ', + 'after_title' => '

    ', + ) + ); + register_sidebar( + array( + 'name' => __( 'Content Sidebar', 'twentyfourteen' ), + 'id' => 'sidebar-2', + 'description' => __( 'Additional sidebar that appears on the right.', 'twentyfourteen' ), + 'before_widget' => '', + 'before_title' => '

    ', + 'after_title' => '

    ', + ) + ); + register_sidebar( + array( + 'name' => __( 'Footer Widget Area', 'twentyfourteen' ), + 'id' => 'sidebar-3', + 'description' => __( 'Appears in the footer section of the site.', 'twentyfourteen' ), + 'before_widget' => '', + 'before_title' => '

    ', + 'after_title' => '

    ', + ) + ); } add_action( 'widgets_init', 'twentyfourteen_widgets_init' ); @@ -218,7 +246,7 @@ function twentyfourteen_font_url() { 'family' => urlencode( 'Lato:300,400,700,900,300italic,400italic,700italic' ), 'subset' => urlencode( 'latin,latin-ext' ), ); - $font_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' ); + $font_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' ); } return $font_url; @@ -257,10 +285,12 @@ function twentyfourteen_scripts() { if ( is_front_page() && 'slider' == get_theme_mod( 'featured_content_layout' ) ) { wp_enqueue_script( 'twentyfourteen-slider', get_template_directory_uri() . '/js/slider.js', array( 'jquery' ), '20131205', true ); - wp_localize_script( 'twentyfourteen-slider', 'featuredSliderDefaults', array( - 'prevText' => __( 'Previous', 'twentyfourteen' ), - 'nextText' => __( 'Next', 'twentyfourteen' ) - ) ); + wp_localize_script( + 'twentyfourteen-slider', 'featuredSliderDefaults', array( + 'prevText' => __( 'Previous', 'twentyfourteen' ), + 'nextText' => __( 'Next', 'twentyfourteen' ), + ) + ); } wp_enqueue_script( 'twentyfourteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20150315', true ); @@ -303,96 +333,99 @@ function twentyfourteen_resource_hints( $urls, $relation_type ) { add_filter( 'wp_resource_hints', 'twentyfourteen_resource_hints', 10, 2 ); if ( ! function_exists( 'twentyfourteen_the_attached_image' ) ) : -/** - * Print the attached image with a link to the next attached image. - * - * @since Twenty Fourteen 1.0 - */ -function twentyfourteen_the_attached_image() { - $post = get_post(); /** - * Filter the default Twenty Fourteen attachment size. + * Print the attached image with a link to the next attached image. * * @since Twenty Fourteen 1.0 - * - * @param array $dimensions { - * An array of height and width dimensions. - * - * @type int $height Height of the image in pixels. Default 810. - * @type int $width Width of the image in pixels. Default 810. - * } */ - $attachment_size = apply_filters( 'twentyfourteen_attachment_size', array( 810, 810 ) ); - $next_attachment_url = wp_get_attachment_url(); + function twentyfourteen_the_attached_image() { + $post = get_post(); + /** + * Filter the default Twenty Fourteen attachment size. + * + * @since Twenty Fourteen 1.0 + * + * @param array $dimensions { + * An array of height and width dimensions. + * + * @type int $height Height of the image in pixels. Default 810. + * @type int $width Width of the image in pixels. Default 810. + * } + */ + $attachment_size = apply_filters( 'twentyfourteen_attachment_size', array( 810, 810 ) ); + $next_attachment_url = wp_get_attachment_url(); - /* - * Grab the IDs of all the image attachments in a gallery so we can get the URL - * of the next adjacent image in a gallery, or the first image (if we're - * looking at the last image in a gallery), or, in a gallery of one, just the - * link to that image file. - */ - $attachment_ids = get_posts( array( - 'post_parent' => $post->post_parent, - 'fields' => 'ids', - 'numberposts' => -1, - 'post_status' => 'inherit', - 'post_type' => 'attachment', - 'post_mime_type' => 'image', - 'order' => 'ASC', - 'orderby' => 'menu_order ID', - ) ); + /* + * Grab the IDs of all the image attachments in a gallery so we can get the URL + * of the next adjacent image in a gallery, or the first image (if we're + * looking at the last image in a gallery), or, in a gallery of one, just the + * link to that image file. + */ + $attachment_ids = get_posts( + array( + 'post_parent' => $post->post_parent, + 'fields' => 'ids', + 'numberposts' => -1, + 'post_status' => 'inherit', + 'post_type' => 'attachment', + 'post_mime_type' => 'image', + 'order' => 'ASC', + 'orderby' => 'menu_order ID', + ) + ); - // If there is more than 1 attachment in a gallery... - if ( count( $attachment_ids ) > 1 ) { - foreach ( $attachment_ids as $idx => $attachment_id ) { - if ( $attachment_id == $post->ID ) { - $next_id = $attachment_ids[ ( $idx + 1 ) % count( $attachment_ids ) ]; - break; + // If there is more than 1 attachment in a gallery... + if ( count( $attachment_ids ) > 1 ) { + foreach ( $attachment_ids as $idx => $attachment_id ) { + if ( $attachment_id == $post->ID ) { + $next_id = $attachment_ids[ ( $idx + 1 ) % count( $attachment_ids ) ]; + break; + } + } + + // get the URL of the next image attachment... + if ( $next_id ) { + $next_attachment_url = get_attachment_link( $next_id ); + } // or get the URL of the first image attachment. + else { + $next_attachment_url = get_attachment_link( reset( $attachment_ids ) ); } } - // get the URL of the next image attachment... - if ( $next_id ) { - $next_attachment_url = get_attachment_link( $next_id ); - } - - // or get the URL of the first image attachment. - else { - $next_attachment_url = get_attachment_link( reset( $attachment_ids ) ); - } + printf( + '%2$s', + esc_url( $next_attachment_url ), + wp_get_attachment_image( $post->ID, $attachment_size ) + ); } - - printf( '%2$s', - esc_url( $next_attachment_url ), - wp_get_attachment_image( $post->ID, $attachment_size ) - ); -} endif; if ( ! function_exists( 'twentyfourteen_list_authors' ) ) : -/** - * Print a list of all site contributors who published at least one post. - * - * @since Twenty Fourteen 1.0 - */ -function twentyfourteen_list_authors() { - $contributor_ids = get_users( array( - 'fields' => 'ID', - 'orderby' => 'post_count', - 'order' => 'DESC', - 'who' => 'authors', - ) ); + /** + * Print a list of all site contributors who published at least one post. + * + * @since Twenty Fourteen 1.0 + */ + function twentyfourteen_list_authors() { + $contributor_ids = get_users( + array( + 'fields' => 'ID', + 'orderby' => 'post_count', + 'order' => 'DESC', + 'who' => 'authors', + ) + ); - foreach ( $contributor_ids as $contributor_id ) : - $post_count = count_user_posts( $contributor_id ); + foreach ( $contributor_ids as $contributor_id ) : + $post_count = count_user_posts( $contributor_id ); - // Move on if user has not published a post (yet). - if ( ! $post_count ) { - continue; - } - ?> + // Move on if user has not published a post (yet). + if ( ! $post_count ) { + continue; + } + ?> -
    +
    @@ -409,7 +442,7 @@ function twentyfourteen_list_authors() { is_preview(); -} + return ( $wp_customize instanceof WP_Customize_Manager ) && $wp_customize->is_preview(); + } endif; diff --git a/wp-content/themes/twentyfourteen/header.php b/wp-content/themes/twentyfourteen/header.php index 7286d88938..4dec164aee 100644 --- a/wp-content/themes/twentyfourteen/header.php +++ b/wp-content/themes/twentyfourteen/header.php @@ -51,7 +51,15 @@
    diff --git a/wp-content/themes/twentyfourteen/image.php b/wp-content/themes/twentyfourteen/image.php index 83ac67f68d..999800fa2c 100644 --- a/wp-content/themes/twentyfourteen/image.php +++ b/wp-content/themes/twentyfourteen/image.php @@ -18,45 +18,48 @@ get_header(); -
    + -
    -
    -
    - -
    +
    +
    +
    + +
    - +
    -
    +
    - '', 'link_before' => '', 'link_after' => '', - ) ); - ?> + ) + ); + ?>
    diff --git a/wp-content/themes/twentyfourteen/inc/back-compat.php b/wp-content/themes/twentyfourteen/inc/back-compat.php index c184d912c7..3943aeefc7 100644 --- a/wp-content/themes/twentyfourteen/inc/back-compat.php +++ b/wp-content/themes/twentyfourteen/inc/back-compat.php @@ -44,9 +44,11 @@ function twentyfourteen_upgrade_notice() { * @since Twenty Fourteen 1.0 */ function twentyfourteen_customize() { - wp_die( sprintf( __( 'Twenty Fourteen requires at least WordPress version 3.6. You are running version %s. Please upgrade and try again.', 'twentyfourteen' ), $GLOBALS['wp_version'] ), '', array( - 'back_link' => true, - ) ); + wp_die( + sprintf( __( 'Twenty Fourteen requires at least WordPress version 3.6. You are running version %s. Please upgrade and try again.', 'twentyfourteen' ), $GLOBALS['wp_version'] ), '', array( + 'back_link' => true, + ) + ); } add_action( 'load-customize.php', 'twentyfourteen_customize' ); diff --git a/wp-content/themes/twentyfourteen/inc/custom-header.php b/wp-content/themes/twentyfourteen/inc/custom-header.php index 287b10682d..bfea8976c1 100644 --- a/wp-content/themes/twentyfourteen/inc/custom-header.php +++ b/wp-content/themes/twentyfourteen/inc/custom-header.php @@ -35,36 +35,40 @@ function twentyfourteen_custom_header_setup() { * the Appearance > Header screen. * } */ - add_theme_support( 'custom-header', apply_filters( 'twentyfourteen_custom_header_args', array( - 'default-text-color' => 'fff', - 'width' => 1260, - 'height' => 240, - 'flex-height' => true, - 'wp-head-callback' => 'twentyfourteen_header_style', - 'admin-head-callback' => 'twentyfourteen_admin_header_style', - 'admin-preview-callback' => 'twentyfourteen_admin_header_image', - ) ) ); + add_theme_support( + 'custom-header', apply_filters( + 'twentyfourteen_custom_header_args', array( + 'default-text-color' => 'fff', + 'width' => 1260, + 'height' => 240, + 'flex-height' => true, + 'wp-head-callback' => 'twentyfourteen_header_style', + 'admin-head-callback' => 'twentyfourteen_admin_header_style', + 'admin-preview-callback' => 'twentyfourteen_admin_header_image', + ) + ) + ); } add_action( 'after_setup_theme', 'twentyfourteen_custom_header_setup' ); if ( ! function_exists( 'twentyfourteen_header_style' ) ) : -/** - * Styles the header image and text displayed on the blog - * - * @see twentyfourteen_custom_header_setup(). - * - */ -function twentyfourteen_header_style() { - $text_color = get_header_textcolor(); + /** + * Styles the header image and text displayed on the blog + * + * @see twentyfourteen_custom_header_setup(). + */ + function twentyfourteen_header_style() { + $text_color = get_header_textcolor(); - // If no custom color for text is set, let's bail. - if ( display_header_text() && $text_color === get_theme_support( 'custom-header', 'default-text-color' ) ) - return; + // If no custom color for text is set, let's bail. + if ( display_header_text() && $text_color === get_theme_support( 'custom-header', 'default-text-color' ) ) { + return; + } - // If we get this far, we have custom styles. - ?> - Header screen. - * - * @see twentyfourteen_custom_header_setup() - * - * @since Twenty Fourteen 1.0 - */ -function twentyfourteen_admin_header_style() { -?> + /** + * Style the header image displayed on the Appearance > Header screen. + * + * @see twentyfourteen_custom_header_setup() + * + * @since Twenty Fourteen 1.0 + */ + function twentyfourteen_admin_header_style() { + ?> - Header screen. - * - * @see twentyfourteen_custom_header_setup() - * - * @since Twenty Fourteen 1.0 - */ -function twentyfourteen_admin_header_image() { -?> + /** + * Create the custom header image markup displayed on the Appearance > Header screen. + * + * @see twentyfourteen_custom_header_setup() + * + * @since Twenty Fourteen 1.0 + */ + function twentyfourteen_admin_header_image() { + ?>
    @@ -143,5 +147,5 @@ function twentyfourteen_admin_header_image() {

    get_setting( 'blogname' )->transport = 'postMessage'; - $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; - $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; + $wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; + $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; + $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; if ( isset( $wp_customize->selective_refresh ) ) { - $wp_customize->selective_refresh->add_partial( 'blogname', array( - 'selector' => '.site-title a', - 'container_inclusive' => false, - 'render_callback' => 'twentyfourteen_customize_partial_blogname', - ) ); - $wp_customize->selective_refresh->add_partial( 'blogdescription', array( - 'selector' => '.site-description', - 'container_inclusive' => false, - 'render_callback' => 'twentyfourteen_customize_partial_blogdescription', - ) ); + $wp_customize->selective_refresh->add_partial( + 'blogname', array( + 'selector' => '.site-title a', + 'container_inclusive' => false, + 'render_callback' => 'twentyfourteen_customize_partial_blogname', + ) + ); + $wp_customize->selective_refresh->add_partial( + 'blogdescription', array( + 'selector' => '.site-description', + 'container_inclusive' => false, + 'render_callback' => 'twentyfourteen_customize_partial_blogdescription', + ) + ); } // Rename the label to "Site Title Color" because this only affects the site title in this theme. @@ -49,31 +53,38 @@ function twentyfourteen_customize_register( $wp_customize ) { } // Add the featured content section in case it's not already there. - $wp_customize->add_section( 'featured_content', array( - 'title' => __( 'Featured Content', 'twentyfourteen' ), - 'description' => sprintf( __( 'Use a tag to feature your posts. If no posts match the tag, sticky posts will be displayed instead.', 'twentyfourteen' ), - esc_url( add_query_arg( 'tag', _x( 'featured', 'featured content default tag slug', 'twentyfourteen' ), admin_url( 'edit.php' ) ) ), - admin_url( 'edit.php?show_sticky=1' ) - ), - 'priority' => 130, - 'active_callback' => 'is_front_page', - ) ); + $wp_customize->add_section( + 'featured_content', array( + 'title' => __( 'Featured Content', 'twentyfourteen' ), + 'description' => sprintf( + __( 'Use a tag to feature your posts. If no posts match the tag, sticky posts will be displayed instead.', 'twentyfourteen' ), + esc_url( add_query_arg( 'tag', _x( 'featured', 'featured content default tag slug', 'twentyfourteen' ), admin_url( 'edit.php' ) ) ), + admin_url( 'edit.php?show_sticky=1' ) + ), + 'priority' => 130, + 'active_callback' => 'is_front_page', + ) + ); // Add the featured content layout setting and control. - $wp_customize->add_setting( 'featured_content_layout', array( - 'default' => 'grid', - 'sanitize_callback' => 'twentyfourteen_sanitize_layout', - ) ); + $wp_customize->add_setting( + 'featured_content_layout', array( + 'default' => 'grid', + 'sanitize_callback' => 'twentyfourteen_sanitize_layout', + ) + ); - $wp_customize->add_control( 'featured_content_layout', array( - 'label' => __( 'Layout', 'twentyfourteen' ), - 'section' => 'featured_content', - 'type' => 'select', - 'choices' => array( - 'grid' => __( 'Grid', 'twentyfourteen' ), - 'slider' => __( 'Slider', 'twentyfourteen' ), - ), - ) ); + $wp_customize->add_control( + 'featured_content_layout', array( + 'label' => __( 'Layout', 'twentyfourteen' ), + 'section' => 'featured_content', + 'type' => 'select', + 'choices' => array( + 'grid' => __( 'Grid', 'twentyfourteen' ), + 'slider' => __( 'Slider', 'twentyfourteen' ), + ), + ) + ); } add_action( 'customize_register', 'twentyfourteen_customize_register' ); @@ -137,16 +148,18 @@ function twentyfourteen_contextual_help() { return; } - get_current_screen()->add_help_tab( array( - 'id' => 'twentyfourteen', - 'title' => __( 'Twenty Fourteen', 'twentyfourteen' ), - 'content' => - '
      ' . - '
    • ' . sprintf( __( 'The home page features your choice of up to 6 posts prominently displayed in a grid or slider, controlled by a tag; you can change the tag and layout in Appearance → Customize. If no posts match the tag, sticky posts will be displayed instead.', 'twentyfourteen' ), esc_url( add_query_arg( 'tag', _x( 'featured', 'featured content default tag slug', 'twentyfourteen' ), admin_url( 'edit.php' ) ) ), admin_url( 'customize.php' ), admin_url( 'edit.php?show_sticky=1' ) ) . '
    • ' . - '
    • ' . sprintf( __( 'Enhance your site design by using Featured Images for posts you’d like to stand out (also known as post thumbnails). This allows you to associate an image with your post without inserting it. Twenty Fourteen uses featured images for posts and pages—above the title—and in the Featured Content area on the home page.', 'twentyfourteen' ), 'https://codex.wordpress.org/Post_Thumbnails#Setting_a_Post_Thumbnail' ) . '
    • ' . - '
    • ' . sprintf( __( 'For an in-depth tutorial, and more tips and tricks, visit the Twenty Fourteen documentation.', 'twentyfourteen' ), 'https://codex.wordpress.org/Twenty_Fourteen' ) . '
    • ' . - '
    ', - ) ); + get_current_screen()->add_help_tab( + array( + 'id' => 'twentyfourteen', + 'title' => __( 'Twenty Fourteen', 'twentyfourteen' ), + 'content' => + '
      ' . + '
    • ' . sprintf( __( 'The home page features your choice of up to 6 posts prominently displayed in a grid or slider, controlled by a tag; you can change the tag and layout in Appearance → Customize. If no posts match the tag, sticky posts will be displayed instead.', 'twentyfourteen' ), esc_url( add_query_arg( 'tag', _x( 'featured', 'featured content default tag slug', 'twentyfourteen' ), admin_url( 'edit.php' ) ) ), admin_url( 'customize.php' ), admin_url( 'edit.php?show_sticky=1' ) ) . '
    • ' . + '
    • ' . sprintf( __( 'Enhance your site design by using Featured Images for posts you’d like to stand out (also known as post thumbnails). This allows you to associate an image with your post without inserting it. Twenty Fourteen uses featured images for posts and pages—above the title—and in the Featured Content area on the home page.', 'twentyfourteen' ), 'https://codex.wordpress.org/Post_Thumbnails#Setting_a_Post_Thumbnail' ) . '
    • ' . + '
    • ' . sprintf( __( 'For an in-depth tutorial, and more tips and tricks, visit the Twenty Fourteen documentation.', 'twentyfourteen' ), 'https://codex.wordpress.org/Twenty_Fourteen' ) . '
    • ' . + '
    ', + ) + ); } add_action( 'admin_head-themes.php', 'twentyfourteen_contextual_help' ); -add_action( 'admin_head-edit.php', 'twentyfourteen_contextual_help' ); +add_action( 'admin_head-edit.php', 'twentyfourteen_contextual_help' ); diff --git a/wp-content/themes/twentyfourteen/inc/featured-content.php b/wp-content/themes/twentyfourteen/inc/featured-content.php index ffeb993db8..424e134b99 100644 --- a/wp-content/themes/twentyfourteen/inc/featured-content.php +++ b/wp-content/themes/twentyfourteen/inc/featured-content.php @@ -83,15 +83,15 @@ class Featured_Content { self::$max_posts = absint( $theme_support[0]['max_posts'] ); } - add_filter( $filter, array( __CLASS__, 'get_featured_posts' ) ); - add_action( 'customize_register', array( __CLASS__, 'customize_register' ), 9 ); - add_action( 'admin_init', array( __CLASS__, 'register_setting' ) ); - add_action( 'switch_theme', array( __CLASS__, 'delete_transient' ) ); - add_action( 'save_post', array( __CLASS__, 'delete_transient' ) ); - add_action( 'delete_post_tag', array( __CLASS__, 'delete_post_tag' ) ); - add_action( 'customize_controls_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ) ); - add_action( 'pre_get_posts', array( __CLASS__, 'pre_get_posts' ) ); - add_action( 'wp_loaded', array( __CLASS__, 'wp_loaded' ) ); + add_filter( $filter, array( __CLASS__, 'get_featured_posts' ) ); + add_action( 'customize_register', array( __CLASS__, 'customize_register' ), 9 ); + add_action( 'admin_init', array( __CLASS__, 'register_setting' ) ); + add_action( 'switch_theme', array( __CLASS__, 'delete_transient' ) ); + add_action( 'save_post', array( __CLASS__, 'delete_transient' ) ); + add_action( 'delete_post_tag', array( __CLASS__, 'delete_post_tag' ) ); + add_action( 'customize_controls_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ) ); + add_action( 'pre_get_posts', array( __CLASS__, 'pre_get_posts' ) ); + add_action( 'wp_loaded', array( __CLASS__, 'wp_loaded' ) ); } /** @@ -106,7 +106,7 @@ class Featured_Content { */ public static function wp_loaded() { if ( self::get_setting( 'hide-tag' ) ) { - add_filter( 'get_terms', array( __CLASS__, 'hide_featured_term' ), 10, 3 ); + add_filter( 'get_terms', array( __CLASS__, 'hide_featured_term' ), 10, 3 ); add_filter( 'get_the_terms', array( __CLASS__, 'hide_the_featured_term' ), 10, 3 ); } } @@ -128,10 +128,12 @@ class Featured_Content { return array(); } - $featured_posts = get_posts( array( - 'include' => $post_ids, - 'posts_per_page' => count( $post_ids ), - ) ); + $featured_posts = get_posts( + array( + 'include' => $post_ids, + 'posts_per_page' => count( $post_ids ), + ) + ); return $featured_posts; } @@ -160,18 +162,20 @@ class Featured_Content { if ( $term ) { // Query for featured posts. - $featured_ids = get_posts( array( - 'fields' => 'ids', - 'numberposts' => self::$max_posts, - 'suppress_filters' => false, - 'tax_query' => array( - array( - 'field' => 'term_id', - 'taxonomy' => 'post_tag', - 'terms' => $term->term_id, + $featured_ids = get_posts( + array( + 'fields' => 'ids', + 'numberposts' => self::$max_posts, + 'suppress_filters' => false, + 'tax_query' => array( + array( + 'field' => 'term_id', + 'taxonomy' => 'post_tag', + 'terms' => $term->term_id, + ), ), - ), - ) ); + ) + ); } // Get sticky posts if no Featured Content exists. @@ -283,7 +287,7 @@ class Featured_Content { } $settings['tag-id'] = 0; - $settings = self::validate_settings( $settings ); + $settings = self::validate_settings( $settings ); update_option( 'featured-content', $settings ); } @@ -399,40 +403,51 @@ class Featured_Content { * @param WP_Customize_Manager $wp_customize Customizer object. */ public static function customize_register( $wp_customize ) { - $wp_customize->add_section( 'featured_content', array( - 'title' => __( 'Featured Content', 'twentyfourteen' ), - 'description' => sprintf( __( 'Use a tag to feature your posts. If no posts match the tag, sticky posts will be displayed instead.', 'twentyfourteen' ), - esc_url( add_query_arg( 'tag', _x( 'featured', 'featured content default tag slug', 'twentyfourteen' ), admin_url( 'edit.php' ) ) ), - admin_url( 'edit.php?show_sticky=1' ) - ), - 'priority' => 130, - 'theme_supports' => 'featured-content', - ) ); + $wp_customize->add_section( + 'featured_content', array( + 'title' => __( 'Featured Content', 'twentyfourteen' ), + 'description' => sprintf( + __( 'Use a tag to feature your posts. If no posts match the tag, sticky posts will be displayed instead.', 'twentyfourteen' ), + esc_url( add_query_arg( 'tag', _x( 'featured', 'featured content default tag slug', 'twentyfourteen' ), admin_url( 'edit.php' ) ) ), + admin_url( 'edit.php?show_sticky=1' ) + ), + 'priority' => 130, + 'theme_supports' => 'featured-content', + ) + ); // Add Featured Content settings. - $wp_customize->add_setting( 'featured-content[tag-name]', array( - 'default' => _x( 'featured', 'featured content default tag slug', 'twentyfourteen' ), - 'type' => 'option', - 'sanitize_js_callback' => array( __CLASS__, 'delete_transient' ), - ) ); - $wp_customize->add_setting( 'featured-content[hide-tag]', array( - 'default' => true, - 'type' => 'option', - 'sanitize_js_callback' => array( __CLASS__, 'delete_transient' ), - ) ); + $wp_customize->add_setting( + 'featured-content[tag-name]', array( + 'default' => _x( 'featured', 'featured content default tag slug', 'twentyfourteen' ), + 'type' => 'option', + 'sanitize_js_callback' => array( __CLASS__, 'delete_transient' ), + ) + ); + $wp_customize->add_setting( + 'featured-content[hide-tag]', array( + 'default' => true, + 'type' => 'option', + 'sanitize_js_callback' => array( __CLASS__, 'delete_transient' ), + ) + ); // Add Featured Content controls. - $wp_customize->add_control( 'featured-content[tag-name]', array( - 'label' => __( 'Tag Name', 'twentyfourteen' ), - 'section' => 'featured_content', - 'priority' => 20, - ) ); - $wp_customize->add_control( 'featured-content[hide-tag]', array( - 'label' => __( 'Don’t display tag on front end.', 'twentyfourteen' ), - 'section' => 'featured_content', - 'type' => 'checkbox', - 'priority' => 30, - ) ); + $wp_customize->add_control( + 'featured-content[tag-name]', array( + 'label' => __( 'Tag Name', 'twentyfourteen' ), + 'section' => 'featured_content', + 'priority' => 20, + ) + ); + $wp_customize->add_control( + 'featured-content[hide-tag]', array( + 'label' => __( 'Don’t display tag on front end.', 'twentyfourteen' ), + 'section' => 'featured_content', + 'type' => 'checkbox', + 'priority' => 30, + ) + ); } /** diff --git a/wp-content/themes/twentyfourteen/inc/template-tags.php b/wp-content/themes/twentyfourteen/inc/template-tags.php index 1d35d0d5b9..893933164f 100644 --- a/wp-content/themes/twentyfourteen/inc/template-tags.php +++ b/wp-content/themes/twentyfourteen/inc/template-tags.php @@ -8,53 +8,55 @@ */ if ( ! function_exists( 'twentyfourteen_paging_nav' ) ) : -/** - * Display navigation to next/previous set of posts when applicable. - * - * @since Twenty Fourteen 1.0 - * - * @global WP_Query $wp_query WordPress Query object. - * @global WP_Rewrite $wp_rewrite WordPress Rewrite object. - */ -function twentyfourteen_paging_nav() { - global $wp_query, $wp_rewrite; + /** + * Display navigation to next/previous set of posts when applicable. + * + * @since Twenty Fourteen 1.0 + * + * @global WP_Query $wp_query WordPress Query object. + * @global WP_Rewrite $wp_rewrite WordPress Rewrite object. + */ + function twentyfourteen_paging_nav() { + global $wp_query, $wp_rewrite; - // Don't print empty markup if there's only one page. - if ( $wp_query->max_num_pages < 2 ) { - return; - } + // Don't print empty markup if there's only one page. + if ( $wp_query->max_num_pages < 2 ) { + return; + } - $paged = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1; - $pagenum_link = html_entity_decode( get_pagenum_link() ); - $query_args = array(); - $url_parts = explode( '?', $pagenum_link ); + $paged = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1; + $pagenum_link = html_entity_decode( get_pagenum_link() ); + $query_args = array(); + $url_parts = explode( '?', $pagenum_link ); - if ( isset( $url_parts[1] ) ) { - wp_parse_str( $url_parts[1], $query_args ); - } + if ( isset( $url_parts[1] ) ) { + wp_parse_str( $url_parts[1], $query_args ); + } - $pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link ); - $pagenum_link = trailingslashit( $pagenum_link ) . '%_%'; + $pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link ); + $pagenum_link = trailingslashit( $pagenum_link ) . '%_%'; - $format = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : ''; - $format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%'; + $format = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : ''; + $format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%'; - // Set up paginated links. - $links = paginate_links( array( - 'base' => $pagenum_link, - 'format' => $format, - 'total' => $wp_query->max_num_pages, - 'current' => $paged, - 'mid_size' => 1, - 'add_args' => array_map( 'urlencode', $query_args ), - 'prev_text' => __( '← Previous', 'twentyfourteen' ), - 'next_text' => __( 'Next →', 'twentyfourteen' ), - ) ); + // Set up paginated links. + $links = paginate_links( + array( + 'base' => $pagenum_link, + 'format' => $format, + 'total' => $wp_query->max_num_pages, + 'current' => $paged, + 'mid_size' => 1, + 'add_args' => array_map( 'urlencode', $query_args ), + 'prev_text' => __( '← Previous', 'twentyfourteen' ), + 'next_text' => __( 'Next →', 'twentyfourteen' ), + ) + ); - if ( $links ) : + if ( $links ) : - ?> -
    + + ' . __( 'Sticky', 'twentyfourteen' ) . ''; - } + /** + * Print HTML with meta information for the current post-date/time and author. + * + * @since Twenty Fourteen 1.0 + */ + function twentyfourteen_posted_on() { + if ( is_sticky() && is_home() && ! is_paged() ) { + echo '' . __( 'Sticky', 'twentyfourteen' ) . ''; + } - // Set up and print post meta information. - printf( ' ', - esc_url( get_permalink() ), - esc_attr( get_the_date( 'c' ) ), - esc_html( get_the_date() ), - esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), - get_the_author() - ); -} + // Set up and print post meta information. + printf( + ' ', + esc_url( get_permalink() ), + esc_attr( get_the_date( 'c' ) ), + esc_html( get_the_date() ), + esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), + get_the_author() + ); + } endif; /** @@ -130,9 +133,11 @@ endif; function twentyfourteen_categorized_blog() { if ( false === ( $all_the_cool_cats = get_transient( 'twentyfourteen_category_count' ) ) ) { // Create an array of all the categories that are attached to posts - $all_the_cool_cats = get_categories( array( - 'hide_empty' => 1, - ) ); + $all_the_cool_cats = get_categories( + array( + 'hide_empty' => 1, + ) + ); // Count the number of categories that are attached to the posts $all_the_cool_cats = count( $all_the_cool_cats ); @@ -159,69 +164,71 @@ function twentyfourteen_category_transient_flusher() { delete_transient( 'twentyfourteen_category_count' ); } add_action( 'edit_category', 'twentyfourteen_category_transient_flusher' ); -add_action( 'save_post', 'twentyfourteen_category_transient_flusher' ); +add_action( 'save_post', 'twentyfourteen_category_transient_flusher' ); if ( ! function_exists( 'twentyfourteen_post_thumbnail' ) ) : -/** - * Display an optional post thumbnail. - * - * Wraps the post thumbnail in an anchor element on index - * views, or a div element when on single views. - * - * @since Twenty Fourteen 1.0 - * @since Twenty Fourteen 1.4 Was made 'pluggable', or overridable. - */ -function twentyfourteen_post_thumbnail() { - if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) { - return; - } + /** + * Display an optional post thumbnail. + * + * Wraps the post thumbnail in an anchor element on index + * views, or a div element when on single views. + * + * @since Twenty Fourteen 1.0 + * @since Twenty Fourteen 1.4 Was made 'pluggable', or overridable. + */ + function twentyfourteen_post_thumbnail() { + if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) { + return; + } - if ( is_singular() ) : - ?> + if ( is_singular() ) : + ?> -
    - + -
    + ?> +
    - + - %2$s', - esc_url( get_permalink( get_the_ID() ) ), + /** + * Replaces "[...]" (appended to automatically generated excerpts) with ... + * and a Continue reading link. + * + * @since Twenty Fourteen 1.3 + * + * @param string $more Default Read More excerpt link. + * @return string Filtered Read More excerpt link. + */ + function twentyfourteen_excerpt_more( $more ) { + $link = sprintf( + '%2$s', + esc_url( get_permalink( get_the_ID() ) ), /* translators: %s: Name of current post */ sprintf( __( 'Continue reading %s ', 'twentyfourteen' ), '' . get_the_title( get_the_ID() ) . '' ) ); - return ' … ' . $link; -} -add_filter( 'excerpt_more', 'twentyfourteen_excerpt_more' ); + return ' … ' . $link; + } + add_filter( 'excerpt_more', 'twentyfourteen_excerpt_more' ); endif; diff --git a/wp-content/themes/twentyfourteen/inc/widgets.php b/wp-content/themes/twentyfourteen/inc/widgets.php index 533f34a5b7..3603402215 100644 --- a/wp-content/themes/twentyfourteen/inc/widgets.php +++ b/wp-content/themes/twentyfourteen/inc/widgets.php @@ -31,11 +31,13 @@ class Twenty_Fourteen_Ephemera_Widget extends WP_Widget { * @return Twenty_Fourteen_Ephemera_Widget */ public function __construct() { - parent::__construct( 'widget_twentyfourteen_ephemera', __( 'Twenty Fourteen Ephemera', 'twentyfourteen' ), array( - 'classname' => 'widget_twentyfourteen_ephemera', - 'description' => __( 'Use this widget to list your recent Aside, Quote, Video, Audio, Image, Gallery, and Link posts.', 'twentyfourteen' ), - 'customize_selective_refresh' => true, - ) ); + parent::__construct( + 'widget_twentyfourteen_ephemera', __( 'Twenty Fourteen Ephemera', 'twentyfourteen' ), array( + 'classname' => 'widget_twentyfourteen_ephemera', + 'description' => __( 'Use this widget to list your recent Aside, Quote, Video, Audio, Image, Gallery, and Link posts.', 'twentyfourteen' ), + 'customize_selective_refresh' => true, + ) + ); if ( is_active_widget( false, false, $this->id_base ) || is_customize_preview() ) { add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); @@ -106,24 +108,26 @@ class Twenty_Fourteen_Ephemera_Widget extends WP_Widget { $number = empty( $instance['number'] ) ? 2 : absint( $instance['number'] ); $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? $format_string : $instance['title'], $instance, $this->id_base ); - $ephemera = new WP_Query( array( - 'order' => 'DESC', - 'posts_per_page' => $number, - 'no_found_rows' => true, - 'post_status' => 'publish', - 'post__not_in' => get_option( 'sticky_posts' ), - 'tax_query' => array( - array( - 'taxonomy' => 'post_format', - 'terms' => array( "post-format-$format" ), - 'field' => 'slug', - 'operator' => 'IN', + $ephemera = new WP_Query( + array( + 'order' => 'DESC', + 'posts_per_page' => $number, + 'no_found_rows' => true, + 'post_status' => 'publish', + 'post__not_in' => get_option( 'sticky_posts' ), + 'tax_query' => array( + array( + 'taxonomy' => 'post_format', + 'terms' => array( "post-format-$format" ), + 'field' => 'slug', + 'operator' => 'IN', + ), ), - ), - ) ); + ) + ); if ( $ephemera->have_posts() ) : - $tmp_content_width = $GLOBALS['content_width']; + $tmp_content_width = $GLOBALS['content_width']; $GLOBALS['content_width'] = 306; echo $args['before_widget']; @@ -134,61 +138,65 @@ class Twenty_Fourteen_Ephemera_Widget extends WP_Widget {
      have_posts() ) : - $ephemera->the_post(); - $tmp_more = $GLOBALS['more']; - $GLOBALS['more'] = 0; + while ( $ephemera->have_posts() ) : + $ephemera->the_post(); + $tmp_more = $GLOBALS['more']; + $GLOBALS['more'] = 0; ?>
    1. > -
      - + →', 'twentyfourteen' ) ); - else : - $images = array(); + if ( post_password_required() ) : + the_content( __( 'Continue reading ', 'twentyfourteen' ) ); + else : + $images = array(); - $galleries = get_post_galleries( get_the_ID(), false ); - if ( isset( $galleries[0]['ids'] ) ) - $images = explode( ',', $galleries[0]['ids'] ); + $galleries = get_post_galleries( get_the_ID(), false ); + if ( isset( $galleries[0]['ids'] ) ) { + $images = explode( ',', $galleries[0]['ids'] ); + } - if ( ! $images ) : - $images = get_posts( array( - 'fields' => 'ids', - 'numberposts' => -1, - 'order' => 'ASC', - 'orderby' => 'menu_order', + if ( ! $images ) : + $images = get_posts( + array( + 'fields' => 'ids', + 'numberposts' => -1, + 'order' => 'ASC', + 'orderby' => 'menu_order', 'post_mime_type' => 'image', - 'post_parent' => get_the_ID(), - 'post_type' => 'attachment', - ) ); - endif; + 'post_parent' => get_the_ID(), + 'post_type' => 'attachment', + ) + ); + endif; - $total_images = count( $images ); + $total_images = count( $images ); - if ( has_post_thumbnail() ) : - $post_thumbnail = get_the_post_thumbnail(); + if ( has_post_thumbnail() ) : + $post_thumbnail = get_the_post_thumbnail(); elseif ( $total_images > 0 ) : $image = reset( $images ); $post_thumbnail = wp_get_attachment_image( $image, 'post-thumbnail' ); endif; - if ( ! empty ( $post_thumbnail ) ) : + if ( ! empty( $post_thumbnail ) ) : ?>

      - %2$s photo.', 'This gallery contains %2$s photos.', $total_images, 'twentyfourteen' ), - esc_url( get_permalink() ), - number_format_i18n( $total_images ) - ); - ?> + %2$s photo.', 'This gallery contains %2$s photos.', $total_images, 'twentyfourteen' ), + esc_url( get_permalink() ), + number_format_i18n( $total_images ) + ); + ?>

      →', 'twentyfourteen' ) ); @@ -198,20 +206,21 @@ class Twenty_Fourteen_Ephemera_Widget extends WP_Widget {
      ' ); +

      ', '

      ' ); - // Output the authors list. - twentyfourteen_list_authors(); + // Output the authors list. + twentyfourteen_list_authors(); - edit_post_link( __( 'Edit', 'twentyfourteen' ), '
      ', '
      ' ); - ?> + edit_post_link( __( 'Edit', 'twentyfourteen' ), '
      ', '
      ' ); + ?>
    diff --git a/wp-content/themes/twentyfourteen/page-templates/full-width.php b/wp-content/themes/twentyfourteen/page-templates/full-width.php index 8830c870a5..ea5fa58873 100644 --- a/wp-content/themes/twentyfourteen/page-templates/full-width.php +++ b/wp-content/themes/twentyfourteen/page-templates/full-width.php @@ -12,25 +12,26 @@ get_header(); ?>
    diff --git a/wp-content/themes/twentyfourteen/page.php b/wp-content/themes/twentyfourteen/page.php index 44724e9466..bd033aeb48 100644 --- a/wp-content/themes/twentyfourteen/page.php +++ b/wp-content/themes/twentyfourteen/page.php @@ -16,25 +16,26 @@ get_header(); ?>
    diff --git a/wp-content/themes/twentyfourteen/search.php b/wp-content/themes/twentyfourteen/search.php index d90d88a146..6945c40a5f 100644 --- a/wp-content/themes/twentyfourteen/search.php +++ b/wp-content/themes/twentyfourteen/search.php @@ -20,14 +20,15 @@ get_header(); ?>

    diff --git a/wp-content/themes/twentyfourteen/single.php b/wp-content/themes/twentyfourteen/single.php index e089165e58..1940c7329f 100644 --- a/wp-content/themes/twentyfourteen/single.php +++ b/wp-content/themes/twentyfourteen/single.php @@ -13,22 +13,23 @@ get_header(); ?>
    diff --git a/wp-content/themes/twentyfourteen/tag.php b/wp-content/themes/twentyfourteen/tag.php index 5930d2cf27..663fe5e9f0 100644 --- a/wp-content/themes/twentyfourteen/tag.php +++ b/wp-content/themes/twentyfourteen/tag.php @@ -24,22 +24,23 @@ get_header(); ?> %s
    ', $term_description ); + if ( ! empty( $term_description ) ) : + printf( '
    %s
    ', $term_description ); endif; ?>

    -
    + if ( have_posts() ) : + ?> endwhile; - the_posts_pagination( array( - 'prev_text' => twentyseventeen_get_svg( array( 'icon' => 'arrow-left' ) ) . '' . __( 'Previous page', 'twentyseventeen' ) . '', - 'next_text' => '' . __( 'Next page', 'twentyseventeen' ) . '' . twentyseventeen_get_svg( array( 'icon' => 'arrow-right' ) ), - 'before_page_number' => '' . __( 'Page', 'twentyseventeen' ) . ' ', - ) ); + the_posts_pagination( + array( + 'prev_text' => twentyseventeen_get_svg( array( 'icon' => 'arrow-left' ) ) . '' . __( 'Previous page', 'twentyseventeen' ) . '', + 'next_text' => '' . __( 'Next page', 'twentyseventeen' ) . '' . twentyseventeen_get_svg( array( 'icon' => 'arrow-right' ) ), + 'before_page_number' => '' . __( 'Page', 'twentyseventeen' ) . ' ', + ) + ); else : get_template_part( 'template-parts/post/content', 'none' ); - endif; ?> + endif; + ?>
    - + if ( have_comments() ) : + ?>

    100, - 'style' => 'ol', - 'short_ping' => true, - 'reply_text' => twentyseventeen_get_svg( array( 'icon' => 'mail-reply' ) ) . __( 'Reply', 'twentyseventeen' ), - ) ); + wp_list_comments( + array( + 'avatar_size' => 100, + 'style' => 'ol', + 'short_ping' => true, + 'reply_text' => twentyseventeen_get_svg( array( 'icon' => 'mail-reply' ) ) . __( 'Reply', 'twentyseventeen' ), + ) + ); ?> - twentyseventeen_get_svg( array( 'icon' => 'arrow-left' ) ) . '' . __( 'Previous', 'twentyseventeen' ) . '', - 'next_text' => '' . __( 'Next', 'twentyseventeen' ) . '' . twentyseventeen_get_svg( array( 'icon' => 'arrow-right' ) ), - ) ); + twentyseventeen_get_svg( array( 'icon' => 'arrow-left' ) ) . '' . __( 'Previous', 'twentyseventeen' ) . '', + 'next_text' => '' . __( 'Next', 'twentyseventeen' ) . '' . twentyseventeen_get_svg( array( 'icon' => 'arrow-right' ) ), + ) + ); endif; // Check for have_comments(). // If comments are closed and there are comments, let's leave a little note, shall we? - if ( ! comments_open() && get_comments_number() && post_type_supports( get_post_type(), 'comments' ) ) : ?> + if ( ! comments_open() && get_comments_number() && post_type_supports( get_post_type(), 'comments' ) ) : + ?>

    + if ( has_nav_menu( 'social' ) ) : + ?> - diff --git a/wp-content/themes/twentyseventeen/front-page.php b/wp-content/themes/twentyseventeen/front-page.php index a169ad29db..0c653917c8 100644 --- a/wp-content/themes/twentyseventeen/front-page.php +++ b/wp-content/themes/twentyseventeen/front-page.php @@ -17,14 +17,17 @@ get_header(); ?>
    - + endif; + ?> twentyseventeen_front_page_section( null, $i ); } - endif; // The if ( 0 !== twentyseventeen_panel_count() ) ends here. ?> + endif; // The if ( 0 !== twentyseventeen_panel_count() ) ends here. + ?>
    - __( 'Top Menu', 'twentyseventeen' ), - 'social' => __( 'Social Links Menu', 'twentyseventeen' ), - ) ); + register_nav_menus( + array( + 'top' => __( 'Top Menu', 'twentyseventeen' ), + 'social' => __( 'Social Links Menu', 'twentyseventeen' ), + ) + ); /* * Switch default core markup for search form, comment form, and comments * to output valid HTML5. */ - add_theme_support( 'html5', array( - 'comment-form', - 'comment-list', - 'gallery', - 'caption', - ) ); + add_theme_support( + 'html5', array( + 'comment-form', + 'comment-list', + 'gallery', + 'caption', + ) + ); /* * Enable support for Post Formats. * * See: https://codex.wordpress.org/Post_Formats */ - add_theme_support( 'post-formats', array( - 'aside', - 'image', - 'video', - 'quote', - 'link', - 'gallery', - 'audio', - ) ); + add_theme_support( + 'post-formats', array( + 'aside', + 'image', + 'video', + 'quote', + 'link', + 'gallery', + 'audio', + ) + ); // Add theme support for Custom Logo. - add_theme_support( 'custom-logo', array( - 'width' => 250, - 'height' => 250, - 'flex-width' => true, - ) ); + add_theme_support( + 'custom-logo', array( + 'width' => 250, + 'height' => 250, + 'flex-width' => true, + ) + ); // Add theme support for selective refresh for widgets. add_theme_support( 'customize-selective-refresh-widgets' ); @@ -103,12 +111,12 @@ function twentyseventeen_setup() { /* * This theme styles the visual editor to resemble the theme style, * specifically font, colors, and column width. - */ + */ add_editor_style( array( 'assets/css/editor-style.css', twentyseventeen_fonts_url() ) ); // Define and register starter content to showcase the theme on new sites. $starter_content = array( - 'widgets' => array( + 'widgets' => array( // Place three core-defined widgets in the sidebar area. 'sidebar-1' => array( 'text_business_info', @@ -129,15 +137,15 @@ function twentyseventeen_setup() { ), // Specify the core-defined pages to create and add custom thumbnails to some of them. - 'posts' => array( + 'posts' => array( 'home', - 'about' => array( + 'about' => array( 'thumbnail' => '{{image-sandwich}}', ), - 'contact' => array( + 'contact' => array( 'thumbnail' => '{{image-espresso}}', ), - 'blog' => array( + 'blog' => array( 'thumbnail' => '{{image-coffee}}', ), 'homepage-section' => array( @@ -149,27 +157,27 @@ function twentyseventeen_setup() { 'attachments' => array( 'image-espresso' => array( 'post_title' => _x( 'Espresso', 'Theme starter content', 'twentyseventeen' ), - 'file' => 'assets/images/espresso.jpg', // URL relative to the template directory. + 'file' => 'assets/images/espresso.jpg', // URL relative to the template directory. ), 'image-sandwich' => array( 'post_title' => _x( 'Sandwich', 'Theme starter content', 'twentyseventeen' ), - 'file' => 'assets/images/sandwich.jpg', + 'file' => 'assets/images/sandwich.jpg', ), - 'image-coffee' => array( + 'image-coffee' => array( 'post_title' => _x( 'Coffee', 'Theme starter content', 'twentyseventeen' ), - 'file' => 'assets/images/coffee.jpg', + 'file' => 'assets/images/coffee.jpg', ), ), // Default to a static front page and assign the front and posts pages. - 'options' => array( - 'show_on_front' => 'page', - 'page_on_front' => '{{home}}', + 'options' => array( + 'show_on_front' => 'page', + 'page_on_front' => '{{home}}', 'page_for_posts' => '{{blog}}', ), // Set the front page section theme mods to the IDs of the core-registered pages. - 'theme_mods' => array( + 'theme_mods' => array( 'panel_1' => '{{homepage-section}}', 'panel_2' => '{{about}}', 'panel_3' => '{{blog}}', @@ -177,10 +185,10 @@ function twentyseventeen_setup() { ), // Set up nav menus for each of the two areas registered in the theme. - 'nav_menus' => array( + 'nav_menus' => array( // Assign a menu to the "top" location. - 'top' => array( - 'name' => __( 'Top Menu', 'twentyseventeen' ), + 'top' => array( + 'name' => __( 'Top Menu', 'twentyseventeen' ), 'items' => array( 'link_home', // Note that the core "home" page is actually a link in case a static front page is not used. 'page_about', @@ -191,7 +199,7 @@ function twentyseventeen_setup() { // Assign a menu to the "social" location. 'social' => array( - 'name' => __( 'Social Links Menu', 'twentyseventeen' ), + 'name' => __( 'Social Links Menu', 'twentyseventeen' ), 'items' => array( 'link_yelp', 'link_facebook', @@ -311,35 +319,41 @@ add_filter( 'wp_resource_hints', 'twentyseventeen_resource_hints', 10, 2 ); * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar */ function twentyseventeen_widgets_init() { - register_sidebar( array( - 'name' => __( 'Blog Sidebar', 'twentyseventeen' ), - 'id' => 'sidebar-1', - 'description' => __( 'Add widgets here to appear in your sidebar on blog posts and archive pages.', 'twentyseventeen' ), - 'before_widget' => '
    ', - 'after_widget' => '
    ', - 'before_title' => '

    ', - 'after_title' => '

    ', - ) ); + register_sidebar( + array( + 'name' => __( 'Blog Sidebar', 'twentyseventeen' ), + 'id' => 'sidebar-1', + 'description' => __( 'Add widgets here to appear in your sidebar on blog posts and archive pages.', 'twentyseventeen' ), + 'before_widget' => '
    ', + 'after_widget' => '
    ', + 'before_title' => '

    ', + 'after_title' => '

    ', + ) + ); - register_sidebar( array( - 'name' => __( 'Footer 1', 'twentyseventeen' ), - 'id' => 'sidebar-2', - 'description' => __( 'Add widgets here to appear in your footer.', 'twentyseventeen' ), - 'before_widget' => '
    ', - 'after_widget' => '
    ', - 'before_title' => '

    ', - 'after_title' => '

    ', - ) ); + register_sidebar( + array( + 'name' => __( 'Footer 1', 'twentyseventeen' ), + 'id' => 'sidebar-2', + 'description' => __( 'Add widgets here to appear in your footer.', 'twentyseventeen' ), + 'before_widget' => '
    ', + 'after_widget' => '
    ', + 'before_title' => '

    ', + 'after_title' => '

    ', + ) + ); - register_sidebar( array( - 'name' => __( 'Footer 2', 'twentyseventeen' ), - 'id' => 'sidebar-3', - 'description' => __( 'Add widgets here to appear in your footer.', 'twentyseventeen' ), - 'before_widget' => '
    ', - 'after_widget' => '
    ', - 'before_title' => '

    ', - 'after_title' => '

    ', - ) ); + register_sidebar( + array( + 'name' => __( 'Footer 2', 'twentyseventeen' ), + 'id' => 'sidebar-3', + 'description' => __( 'Add widgets here to appear in your footer.', 'twentyseventeen' ), + 'before_widget' => '
    ', + 'after_widget' => '
    ', + 'before_title' => '

    ', + 'after_title' => '

    ', + ) + ); } add_action( 'widgets_init', 'twentyseventeen_widgets_init' ); @@ -357,7 +371,8 @@ function twentyseventeen_excerpt_more( $link ) { return $link; } - $link = sprintf( '', + $link = sprintf( + '', esc_url( get_permalink( get_the_ID() ) ), /* translators: %s: Name of current post */ sprintf( __( 'Continue reading "%s"', 'twentyseventeen' ), get_the_title( get_the_ID() ) ) @@ -407,7 +422,8 @@ function twentyseventeen_colors_css_wrap() { - twentyseventeen_get_svg( array( 'icon' => 'quote-right' ) ), + 'quote' => twentyseventeen_get_svg( array( 'icon' => 'quote-right' ) ), ); if ( has_nav_menu( 'top' ) ) { wp_enqueue_script( 'twentyseventeen-navigation', get_theme_file_uri( '/assets/js/navigation.js' ), array( 'jquery' ), '1.0', true ); - $twentyseventeen_l10n['expand'] = __( 'Expand child menu', 'twentyseventeen' ); - $twentyseventeen_l10n['collapse'] = __( 'Collapse child menu', 'twentyseventeen' ); - $twentyseventeen_l10n['icon'] = twentyseventeen_get_svg( array( 'icon' => 'angle-down', 'fallback' => true ) ); + $twentyseventeen_l10n['expand'] = __( 'Expand child menu', 'twentyseventeen' ); + $twentyseventeen_l10n['collapse'] = __( 'Collapse child menu', 'twentyseventeen' ); + $twentyseventeen_l10n['icon'] = twentyseventeen_get_svg( + array( + 'icon' => 'angle-down', + 'fallback' => true, + ) + ); } wp_enqueue_script( 'twentyseventeen-global', get_theme_file_uri( '/assets/js/global.js' ), array( 'jquery' ), '1.0', true ); @@ -544,7 +565,7 @@ add_filter( 'wp_get_attachment_image_attributes', 'twentyseventeen_post_thumbnai function twentyseventeen_front_page_template( $template ) { return is_home() ? '' : $template; } -add_filter( 'frontpage_template', 'twentyseventeen_front_page_template' ); +add_filter( 'frontpage_template', 'twentyseventeen_front_page_template' ); /** * Modifies tag cloud widget arguments to display all tags in the same font size diff --git a/wp-content/themes/twentyseventeen/inc/back-compat.php b/wp-content/themes/twentyseventeen/inc/back-compat.php index 4772f5621a..fad87f91ba 100644 --- a/wp-content/themes/twentyseventeen/inc/back-compat.php +++ b/wp-content/themes/twentyseventeen/inc/back-compat.php @@ -48,9 +48,11 @@ function twentyseventeen_upgrade_notice() { * @global string $wp_version WordPress version. */ function twentyseventeen_customize() { - wp_die( sprintf( __( 'Twenty Seventeen requires at least WordPress version 4.7. You are running version %s. Please upgrade and try again.', 'twentyseventeen' ), $GLOBALS['wp_version'] ), '', array( - 'back_link' => true, - ) ); + wp_die( + sprintf( __( 'Twenty Seventeen requires at least WordPress version 4.7. You are running version %s. Please upgrade and try again.', 'twentyseventeen' ), $GLOBALS['wp_version'] ), '', array( + 'back_link' => true, + ) + ); } add_action( 'load-customize.php', 'twentyseventeen_customize' ); diff --git a/wp-content/themes/twentyseventeen/inc/color-patterns.php b/wp-content/themes/twentyseventeen/inc/color-patterns.php index 74d5031dbb..2eaca03131 100644 --- a/wp-content/themes/twentyseventeen/inc/color-patterns.php +++ b/wp-content/themes/twentyseventeen/inc/color-patterns.php @@ -20,10 +20,10 @@ function twentyseventeen_custom_colors_css() { * * @param int $saturation Color saturation level. */ - $saturation = absint( apply_filters( 'twentyseventeen_custom_colors_saturation', 50 ) ); + $saturation = absint( apply_filters( 'twentyseventeen_custom_colors_saturation', 50 ) ); $reduced_saturation = ( .8 * $saturation ) . '%'; - $saturation = $saturation . '%'; - $css = ' + $saturation = $saturation . '%'; + $css = ' /** * Twenty Seventeen: Color Patterns * diff --git a/wp-content/themes/twentyseventeen/inc/custom-header.php b/wp-content/themes/twentyseventeen/inc/custom-header.php index 6e19a7f98b..1cc6114a98 100644 --- a/wp-content/themes/twentyseventeen/inc/custom-header.php +++ b/wp-content/themes/twentyseventeen/inc/custom-header.php @@ -24,53 +24,59 @@ function twentyseventeen_custom_header_setup() { * @param array $args { * An array of custom-header support arguments. * - * @type string $default-image Default image of the header. + * @type string $default-image Default image of the header. * @type string $default_text_color Default color of the header text. * @type int $width Width in pixels of the custom header image. Default 954. * @type int $height Height in pixels of the custom header image. Default 1300. * @type string $wp-head-callback Callback function used to styles the header image and text * displayed on the blog. - * @type string $flex-height Flex support for height of header. + * @type string $flex-height Flex support for height of header. * } */ - add_theme_support( 'custom-header', apply_filters( 'twentyseventeen_custom_header_args', array( - 'default-image' => get_parent_theme_file_uri( '/assets/images/header.jpg' ), - 'width' => 2000, - 'height' => 1200, - 'flex-height' => true, - 'video' => true, - 'wp-head-callback' => 'twentyseventeen_header_style', - ) ) ); + add_theme_support( + 'custom-header', apply_filters( + 'twentyseventeen_custom_header_args', array( + 'default-image' => get_parent_theme_file_uri( '/assets/images/header.jpg' ), + 'width' => 2000, + 'height' => 1200, + 'flex-height' => true, + 'video' => true, + 'wp-head-callback' => 'twentyseventeen_header_style', + ) + ) + ); - register_default_headers( array( - 'default-image' => array( - 'url' => '%s/assets/images/header.jpg', - 'thumbnail_url' => '%s/assets/images/header.jpg', - 'description' => __( 'Default Header Image', 'twentyseventeen' ), - ), - ) ); + register_default_headers( + array( + 'default-image' => array( + 'url' => '%s/assets/images/header.jpg', + 'thumbnail_url' => '%s/assets/images/header.jpg', + 'description' => __( 'Default Header Image', 'twentyseventeen' ), + ), + ) + ); } add_action( 'after_setup_theme', 'twentyseventeen_custom_header_setup' ); if ( ! function_exists( 'twentyseventeen_header_style' ) ) : -/** - * Styles the header image and text displayed on the blog. - * - * @see twentyseventeen_custom_header_setup(). - */ -function twentyseventeen_header_style() { - $header_text_color = get_header_textcolor(); + /** + * Styles the header image and text displayed on the blog. + * + * @see twentyseventeen_custom_header_setup(). + */ + function twentyseventeen_header_style() { + $header_text_color = get_header_textcolor(); - // If no custom options for text are set, let's bail. - // get_header_textcolor() options: add_theme_support( 'custom-header' ) is default, hide text (returns 'blank') or any hex value. - if ( get_theme_support( 'custom-header', 'default-text-color' ) === $header_text_color ) { - return; - } + // If no custom options for text are set, let's bail. + // get_header_textcolor() options: add_theme_support( 'custom-header' ) is default, hide text (returns 'blank') or any hex value. + if ( get_theme_support( 'custom-header', 'default-text-color' ) === $header_text_color ) { + return; + } - // If we get this far, we have custom styles. Let's do this. - ?> - ' . __( 'Play background video', 'twentyseventeen' ) . '' . twentyseventeen_get_svg( array( 'icon' => 'play' ) ); + $settings['l10n']['play'] = '' . __( 'Play background video', 'twentyseventeen' ) . '' . twentyseventeen_get_svg( array( 'icon' => 'play' ) ); $settings['l10n']['pause'] = '' . __( 'Pause background video', 'twentyseventeen' ) . '' . twentyseventeen_get_svg( array( 'icon' => 'pause' ) ); return $settings; } diff --git a/wp-content/themes/twentyseventeen/inc/customizer.php b/wp-content/themes/twentyseventeen/inc/customizer.php index bc6bbea31c..abc27fb057 100644 --- a/wp-content/themes/twentyseventeen/inc/customizer.php +++ b/wp-content/themes/twentyseventeen/inc/customizer.php @@ -13,77 +13,97 @@ * @param WP_Customize_Manager $wp_customize Theme Customizer object. */ function twentyseventeen_customize_register( $wp_customize ) { - $wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; - $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; - $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; + $wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; + $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; + $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; - $wp_customize->selective_refresh->add_partial( 'blogname', array( - 'selector' => '.site-title a', - 'render_callback' => 'twentyseventeen_customize_partial_blogname', - ) ); - $wp_customize->selective_refresh->add_partial( 'blogdescription', array( - 'selector' => '.site-description', - 'render_callback' => 'twentyseventeen_customize_partial_blogdescription', - ) ); + $wp_customize->selective_refresh->add_partial( + 'blogname', array( + 'selector' => '.site-title a', + 'render_callback' => 'twentyseventeen_customize_partial_blogname', + ) + ); + $wp_customize->selective_refresh->add_partial( + 'blogdescription', array( + 'selector' => '.site-description', + 'render_callback' => 'twentyseventeen_customize_partial_blogdescription', + ) + ); /** * Custom colors. */ - $wp_customize->add_setting( 'colorscheme', array( - 'default' => 'light', - 'transport' => 'postMessage', - 'sanitize_callback' => 'twentyseventeen_sanitize_colorscheme', - ) ); + $wp_customize->add_setting( + 'colorscheme', array( + 'default' => 'light', + 'transport' => 'postMessage', + 'sanitize_callback' => 'twentyseventeen_sanitize_colorscheme', + ) + ); - $wp_customize->add_setting( 'colorscheme_hue', array( - 'default' => 250, - 'transport' => 'postMessage', - 'sanitize_callback' => 'absint', // The hue is stored as a positive integer. - ) ); + $wp_customize->add_setting( + 'colorscheme_hue', array( + 'default' => 250, + 'transport' => 'postMessage', + 'sanitize_callback' => 'absint', // The hue is stored as a positive integer. + ) + ); - $wp_customize->add_control( 'colorscheme', array( - 'type' => 'radio', - 'label' => __( 'Color Scheme', 'twentyseventeen' ), - 'choices' => array( - 'light' => __( 'Light', 'twentyseventeen' ), - 'dark' => __( 'Dark', 'twentyseventeen' ), - 'custom' => __( 'Custom', 'twentyseventeen' ), - ), - 'section' => 'colors', - 'priority' => 5, - ) ); + $wp_customize->add_control( + 'colorscheme', array( + 'type' => 'radio', + 'label' => __( 'Color Scheme', 'twentyseventeen' ), + 'choices' => array( + 'light' => __( 'Light', 'twentyseventeen' ), + 'dark' => __( 'Dark', 'twentyseventeen' ), + 'custom' => __( 'Custom', 'twentyseventeen' ), + ), + 'section' => 'colors', + 'priority' => 5, + ) + ); - $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'colorscheme_hue', array( - 'mode' => 'hue', - 'section' => 'colors', - 'priority' => 6, - ) ) ); + $wp_customize->add_control( + new WP_Customize_Color_Control( + $wp_customize, 'colorscheme_hue', array( + 'mode' => 'hue', + 'section' => 'colors', + 'priority' => 6, + ) + ) + ); /** * Theme options. */ - $wp_customize->add_section( 'theme_options', array( - 'title' => __( 'Theme Options', 'twentyseventeen' ), - 'priority' => 130, // Before Additional CSS. - ) ); + $wp_customize->add_section( + 'theme_options', array( + 'title' => __( 'Theme Options', 'twentyseventeen' ), + 'priority' => 130, // Before Additional CSS. + ) + ); - $wp_customize->add_setting( 'page_layout', array( - 'default' => 'two-column', - 'sanitize_callback' => 'twentyseventeen_sanitize_page_layout', - 'transport' => 'postMessage', - ) ); + $wp_customize->add_setting( + 'page_layout', array( + 'default' => 'two-column', + 'sanitize_callback' => 'twentyseventeen_sanitize_page_layout', + 'transport' => 'postMessage', + ) + ); - $wp_customize->add_control( 'page_layout', array( - 'label' => __( 'Page Layout', 'twentyseventeen' ), - 'section' => 'theme_options', - 'type' => 'radio', - 'description' => __( 'When the two-column layout is assigned, the page title is in one column and content is in the other.', 'twentyseventeen' ), - 'choices' => array( - 'one-column' => __( 'One Column', 'twentyseventeen' ), - 'two-column' => __( 'Two Column', 'twentyseventeen' ), - ), - 'active_callback' => 'twentyseventeen_is_view_with_layout_option', - ) ); + $wp_customize->add_control( + 'page_layout', array( + 'label' => __( 'Page Layout', 'twentyseventeen' ), + 'section' => 'theme_options', + 'type' => 'radio', + 'description' => __( 'When the two-column layout is assigned, the page title is in one column and content is in the other.', 'twentyseventeen' ), + 'choices' => array( + 'one-column' => __( 'One Column', 'twentyseventeen' ), + 'two-column' => __( 'Two Column', 'twentyseventeen' ), + ), + 'active_callback' => 'twentyseventeen_is_view_with_layout_option', + ) + ); /** * Filter number of front page sections in Twenty Seventeen. @@ -96,27 +116,33 @@ function twentyseventeen_customize_register( $wp_customize ) { // Create a setting and control for each of the sections available in the theme. for ( $i = 1; $i < ( 1 + $num_sections ); $i++ ) { - $wp_customize->add_setting( 'panel_' . $i, array( - 'default' => false, - 'sanitize_callback' => 'absint', - 'transport' => 'postMessage', - ) ); + $wp_customize->add_setting( + 'panel_' . $i, array( + 'default' => false, + 'sanitize_callback' => 'absint', + 'transport' => 'postMessage', + ) + ); - $wp_customize->add_control( 'panel_' . $i, array( - /* translators: %d is the front page section number */ - 'label' => sprintf( __( 'Front Page Section %d Content', 'twentyseventeen' ), $i ), - 'description' => ( 1 !== $i ? '' : __( 'Select pages to feature in each area from the dropdowns. Add an image to a section by setting a featured image in the page editor. Empty sections will not be displayed.', 'twentyseventeen' ) ), - 'section' => 'theme_options', - 'type' => 'dropdown-pages', - 'allow_addition' => true, - 'active_callback' => 'twentyseventeen_is_static_front_page', - ) ); + $wp_customize->add_control( + 'panel_' . $i, array( + /* translators: %d is the front page section number */ + 'label' => sprintf( __( 'Front Page Section %d Content', 'twentyseventeen' ), $i ), + 'description' => ( 1 !== $i ? '' : __( 'Select pages to feature in each area from the dropdowns. Add an image to a section by setting a featured image in the page editor. Empty sections will not be displayed.', 'twentyseventeen' ) ), + 'section' => 'theme_options', + 'type' => 'dropdown-pages', + 'allow_addition' => true, + 'active_callback' => 'twentyseventeen_is_static_front_page', + ) + ); - $wp_customize->selective_refresh->add_partial( 'panel_' . $i, array( - 'selector' => '#panel' . $i, - 'render_callback' => 'twentyseventeen_front_page_section', - 'container_inclusive' => true, - ) ); + $wp_customize->selective_refresh->add_partial( + 'panel_' . $i, array( + 'selector' => '#panel' . $i, + 'render_callback' => 'twentyseventeen_front_page_section', + 'container_inclusive' => true, + ) + ); } } add_action( 'customize_register', 'twentyseventeen_customize_register' ); diff --git a/wp-content/themes/twentyseventeen/inc/icon-functions.php b/wp-content/themes/twentyseventeen/inc/icon-functions.php index 3425f740df..87572bcecd 100644 --- a/wp-content/themes/twentyseventeen/inc/icon-functions.php +++ b/wp-content/themes/twentyseventeen/inc/icon-functions.php @@ -46,10 +46,10 @@ function twentyseventeen_get_svg( $args = array() ) { // Set defaults. $defaults = array( - 'icon' => '', - 'title' => '', - 'desc' => '', - 'fallback' => false, + 'icon' => '', + 'title' => '', + 'desc' => '', + 'fallback' => false, ); // Parse args. diff --git a/wp-content/themes/twentyseventeen/inc/template-functions.php b/wp-content/themes/twentyseventeen/inc/template-functions.php index 9ecbe56a84..d51b897406 100644 --- a/wp-content/themes/twentyseventeen/inc/template-functions.php +++ b/wp-content/themes/twentyseventeen/inc/template-functions.php @@ -59,7 +59,7 @@ function twentyseventeen_body_classes( $classes ) { } // Get the colorscheme or the default if there isn't one. - $colors = twentyseventeen_sanitize_colorscheme( get_theme_mod( 'colorscheme', 'light' ) ); + $colors = twentyseventeen_sanitize_colorscheme( get_theme_mod( 'colorscheme', 'light' ) ); $classes[] = 'colors-' . $colors; return $classes; diff --git a/wp-content/themes/twentyseventeen/inc/template-tags.php b/wp-content/themes/twentyseventeen/inc/template-tags.php index a99230d963..8fec665a28 100644 --- a/wp-content/themes/twentyseventeen/inc/template-tags.php +++ b/wp-content/themes/twentyseventeen/inc/template-tags.php @@ -10,83 +10,84 @@ */ if ( ! function_exists( 'twentyseventeen_posted_on' ) ) : -/** - * Prints HTML with meta information for the current post-date/time and author. - */ -function twentyseventeen_posted_on() { + /** + * Prints HTML with meta information for the current post-date/time and author. + */ + function twentyseventeen_posted_on() { - // Get the author name; wrap it in a link. - $byline = sprintf( - /* translators: %s: post author */ - __( 'by %s', 'twentyseventeen' ), - '' . get_the_author() . '' - ); + // Get the author name; wrap it in a link. + $byline = sprintf( + /* translators: %s: post author */ + __( 'by %s', 'twentyseventeen' ), + '' . get_the_author() . '' + ); - // Finally, let's write all of this to the page. - echo '' . twentyseventeen_time_link() . ''; -} + // Finally, let's write all of this to the page. + echo '' . twentyseventeen_time_link() . ''; + } endif; if ( ! function_exists( 'twentyseventeen_time_link' ) ) : -/** - * Gets a nicely formatted string for the published date. - */ -function twentyseventeen_time_link() { - $time_string = ''; - if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) { - $time_string = ''; + /** + * Gets a nicely formatted string for the published date. + */ + function twentyseventeen_time_link() { + $time_string = ''; + if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) { + $time_string = ''; + } + + $time_string = sprintf( + $time_string, + get_the_date( DATE_W3C ), + get_the_date(), + get_the_modified_date( DATE_W3C ), + get_the_modified_date() + ); + + // Wrap the time string in a link, and preface it with 'Posted on'. + return sprintf( + /* translators: %s: post date */ + __( 'Posted on %s', 'twentyseventeen' ), + '' . $time_string . '' + ); } - - $time_string = sprintf( $time_string, - get_the_date( DATE_W3C ), - get_the_date(), - get_the_modified_date( DATE_W3C ), - get_the_modified_date() - ); - - // Wrap the time string in a link, and preface it with 'Posted on'. - return sprintf( - /* translators: %s: post date */ - __( 'Posted on %s', 'twentyseventeen' ), - '' . $time_string . '' - ); -} endif; if ( ! function_exists( 'twentyseventeen_entry_footer' ) ) : -/** - * Prints HTML with meta information for the categories, tags and comments. - */ -function twentyseventeen_entry_footer() { + /** + * Prints HTML with meta information for the categories, tags and comments. + */ + function twentyseventeen_entry_footer() { - /* translators: used between list items, there is a space after the comma */ - $separate_meta = __( ', ', 'twentyseventeen' ); + /* translators: used between list items, there is a space after the comma */ + $separate_meta = __( ', ', 'twentyseventeen' ); - // Get Categories for posts. - $categories_list = get_the_category_list( $separate_meta ); + // Get Categories for posts. + $categories_list = get_the_category_list( $separate_meta ); - // Get Tags for posts. - $tags_list = get_the_tag_list( '', $separate_meta ); + // Get Tags for posts. + $tags_list = get_the_tag_list( '', $separate_meta ); - // We don't want to output .entry-footer if it will be empty, so make sure its not. - if ( ( ( twentyseventeen_categorized_blog() && $categories_list ) || $tags_list ) || get_edit_post_link() ) { + // We don't want to output .entry-footer if it will be empty, so make sure its not. + if ( ( ( twentyseventeen_categorized_blog() && $categories_list ) || $tags_list ) || get_edit_post_link() ) { - echo '
    '; + echo '
    '; if ( 'post' === get_post_type() ) { if ( ( $categories_list && twentyseventeen_categorized_blog() ) || $tags_list ) { echo ''; // Make sure there's more than one category before displaying. - if ( $categories_list && twentyseventeen_categorized_blog() ) { - echo '' . twentyseventeen_get_svg( array( 'icon' => 'folder-open' ) ) . '' . __( 'Categories', 'twentyseventeen' ) . '' . $categories_list . ''; - } + if ( $categories_list && twentyseventeen_categorized_blog() ) { + echo '' . twentyseventeen_get_svg( array( 'icon' => 'folder-open' ) ) . '' . __( 'Categories', 'twentyseventeen' ) . '' . $categories_list . ''; + } - if ( $tags_list && ! is_wp_error( $tags_list ) ) { - echo '' . twentyseventeen_get_svg( array( 'icon' => 'hashtag' ) ) . '' . __( 'Tags', 'twentyseventeen' ) . '' . $tags_list . ''; - } + if ( $tags_list && ! is_wp_error( $tags_list ) ) { + echo '' . twentyseventeen_get_svg( array( 'icon' => 'hashtag' ) ) . '' . __( 'Tags', 'twentyseventeen' ) . '' . $tags_list . ''; + } echo ''; } @@ -94,32 +95,32 @@ function twentyseventeen_entry_footer() { twentyseventeen_edit_link(); - echo '
    '; + echo '
    '; + } } -} endif; if ( ! function_exists( 'twentyseventeen_edit_link' ) ) : -/** - * Returns an accessibility-friendly link to edit a post or page. - * - * This also gives us a little context about what exactly we're editing - * (post or page?) so that users understand a bit more where they are in terms - * of the template hierarchy and their content. Helpful when/if the single-page - * layout with multiple posts/pages shown gets confusing. - */ -function twentyseventeen_edit_link() { - edit_post_link( - sprintf( - /* translators: %s: Name of current post */ - __( 'Edit "%s"', 'twentyseventeen' ), - get_the_title() - ), - '', - '' - ); -} + /** + * Returns an accessibility-friendly link to edit a post or page. + * + * This also gives us a little context about what exactly we're editing + * (post or page?) so that users understand a bit more where they are in terms + * of the template hierarchy and their content. Helpful when/if the single-page + * layout with multiple posts/pages shown gets confusing. + */ + function twentyseventeen_edit_link() { + edit_post_link( + sprintf( + /* translators: %s: Name of current post */ + __( 'Edit "%s"', 'twentyseventeen' ), + get_the_title() + ), + '', + '' + ); + } endif; /** @@ -132,7 +133,7 @@ function twentyseventeen_front_page_section( $partial = null, $id = 0 ) { if ( is_a( $partial, 'WP_Customize_Partial' ) ) { // Find out the id and set it up during a selective refresh. global $twentyseventeencounter; - $id = str_replace( 'panel_', '', $partial->id ); + $id = str_replace( 'panel_', '', $partial->id ); $twentyseventeencounter = $id; } @@ -161,12 +162,14 @@ function twentyseventeen_categorized_blog() { if ( false === $category_count ) { // Create an array of all the categories that are attached to posts. - $categories = get_categories( array( - 'fields' => 'ids', - 'hide_empty' => 1, - // We only need to know if there is more than one category. - 'number' => 2, - ) ); + $categories = get_categories( + array( + 'fields' => 'ids', + 'hide_empty' => 1, + // We only need to know if there is more than one category. + 'number' => 2, + ) + ); // Count the number of categories that are attached to the posts. $category_count = count( $categories ); @@ -194,4 +197,4 @@ function twentyseventeen_category_transient_flusher() { delete_transient( 'twentyseventeen_categories' ); } add_action( 'edit_category', 'twentyseventeen_category_transient_flusher' ); -add_action( 'save_post', 'twentyseventeen_category_transient_flusher' ); +add_action( 'save_post', 'twentyseventeen_category_transient_flusher' ); diff --git a/wp-content/themes/twentyseventeen/index.php b/wp-content/themes/twentyseventeen/index.php index 78d1b4c93e..3eab9ff656 100644 --- a/wp-content/themes/twentyseventeen/index.php +++ b/wp-content/themes/twentyseventeen/index.php @@ -35,7 +35,8 @@ get_header(); ?> if ( have_posts() ) : /* Start the Loop */ - while ( have_posts() ) : the_post(); + while ( have_posts() ) : + the_post(); /* * Include the Post-Format-specific template for the content. @@ -46,11 +47,13 @@ get_header(); ?> endwhile; - the_posts_pagination( array( - 'prev_text' => twentyseventeen_get_svg( array( 'icon' => 'arrow-left' ) ) . '' . __( 'Previous page', 'twentyseventeen' ) . '', - 'next_text' => '' . __( 'Next page', 'twentyseventeen' ) . '' . twentyseventeen_get_svg( array( 'icon' => 'arrow-right' ) ), - 'before_page_number' => '' . __( 'Page', 'twentyseventeen' ) . ' ', - ) ); + the_posts_pagination( + array( + 'prev_text' => twentyseventeen_get_svg( array( 'icon' => 'arrow-left' ) ) . '' . __( 'Previous page', 'twentyseventeen' ) . '', + 'next_text' => '' . __( 'Next page', 'twentyseventeen' ) . '' . twentyseventeen_get_svg( array( 'icon' => 'arrow-right' ) ), + 'before_page_number' => '' . __( 'Page', 'twentyseventeen' ) . ' ', + ) + ); else : @@ -64,4 +67,5 @@ get_header(); ?>
    -
    - endwhile; // End of the loop. - the_posts_pagination( array( - 'prev_text' => twentyseventeen_get_svg( array( 'icon' => 'arrow-left' ) ) . '' . __( 'Previous page', 'twentyseventeen' ) . '', - 'next_text' => '' . __( 'Next page', 'twentyseventeen' ) . '' . twentyseventeen_get_svg( array( 'icon' => 'arrow-right' ) ), - 'before_page_number' => '' . __( 'Page', 'twentyseventeen' ) . ' ', - ) ); + the_posts_pagination( + array( + 'prev_text' => twentyseventeen_get_svg( array( 'icon' => 'arrow-left' ) ) . '' . __( 'Previous page', 'twentyseventeen' ) . '', + 'next_text' => '' . __( 'Next page', 'twentyseventeen' ) . '' . twentyseventeen_get_svg( array( 'icon' => 'arrow-right' ) ), + 'before_page_number' => '' . __( 'Page', 'twentyseventeen' ) . ' ', + ) + ); - else : ?> + else : + ?>

    - comments_template(); endif; - the_post_navigation( array( - 'prev_text' => '' . __( 'Previous Post', 'twentyseventeen' ) . '' . twentyseventeen_get_svg( array( 'icon' => 'arrow-left' ) ) . '%title', - 'next_text' => '' . __( 'Next Post', 'twentyseventeen' ) . '%title' . twentyseventeen_get_svg( array( 'icon' => 'arrow-right' ) ) . '', - ) ); + the_post_navigation( + array( + 'prev_text' => '' . __( 'Previous Post', 'twentyseventeen' ) . '' . twentyseventeen_get_svg( array( 'icon' => 'arrow-left' ) ) . '%title', + 'next_text' => '' . __( 'Next Post', 'twentyseventeen' ) . '%title' . twentyseventeen_get_svg( array( 'icon' => 'arrow-right' ) ) . '', + ) + ); endwhile; // End of the loop. ?> @@ -40,4 +43,5 @@ get_header(); ?> -"> + if ( is_active_sidebar( 'sidebar-2' ) ) { + ?> - + diff --git a/wp-content/themes/twentyseventeen/template-parts/navigation/navigation-top.php b/wp-content/themes/twentyseventeen/template-parts/navigation/navigation-top.php index 2c2115e60b..5cfc99876c 100644 --- a/wp-content/themes/twentyseventeen/template-parts/navigation/navigation-top.php +++ b/wp-content/themes/twentyseventeen/template-parts/navigation/navigation-top.php @@ -18,10 +18,14 @@ ?> - 'top', - 'menu_id' => 'top-menu', - ) ); ?> + 'top', + 'menu_id' => 'top-menu', + ) + ); + ?> 'arrow-right' ) ); ?> diff --git a/wp-content/themes/twentyseventeen/template-parts/page/content-front-page-panels.php b/wp-content/themes/twentyseventeen/template-parts/page/content-front-page-panels.php index 79e11949b9..93433fb50f 100644 --- a/wp-content/themes/twentyseventeen/template-parts/page/content-front-page-panels.php +++ b/wp-content/themes/twentyseventeen/template-parts/page/content-front-page-panels.php @@ -14,7 +14,8 @@ global $twentyseventeencounter;
    > - ID ), 'twentyseventeen-featured-image' ); // Calculate aspect ratio: h / w * 100%. @@ -39,32 +40,39 @@ global $twentyseventeencounter;
    "%s"', 'twentyseventeen' ), - get_the_title() - ) ); + the_content( + sprintf( + __( 'Continue reading "%s"', 'twentyseventeen' ), + get_the_title() + ) + ); ?>
    + if ( get_the_ID() === (int) get_option( 'page_for_posts' ) ) : + ?> - 3, - 'post_status' => 'publish', - 'ignore_sticky_posts' => true, - 'no_found_rows' => true, - ) ); + 3, + 'post_status' => 'publish', + 'ignore_sticky_posts' => true, + 'no_found_rows' => true, + ) + ); ?> - have_posts() ) : ?> + have_posts() ) : ?>
    have_posts() ) : $recent_posts->the_post(); + while ( $recent_posts->have_posts() ) : + $recent_posts->the_post(); get_template_part( 'template-parts/post/content', 'excerpt' ); endwhile; wp_reset_postdata(); diff --git a/wp-content/themes/twentyseventeen/template-parts/page/content-front-page.php b/wp-content/themes/twentyseventeen/template-parts/page/content-front-page.php index 84a0d7e448..a745c950d3 100644 --- a/wp-content/themes/twentyseventeen/template-parts/page/content-front-page.php +++ b/wp-content/themes/twentyseventeen/template-parts/page/content-front-page.php @@ -11,7 +11,8 @@ ?>
    > - ID ), 'twentyseventeen-featured-image' ); // Calculate aspect ratio: h / w * 100%. @@ -36,10 +37,12 @@
    "%s"', 'twentyseventeen' ), - get_the_title() - ) ); + the_content( + sprintf( + __( 'Continue reading "%s"', 'twentyseventeen' ), + get_the_title() + ) + ); ?>
    diff --git a/wp-content/themes/twentyseventeen/template-parts/page/content-page.php b/wp-content/themes/twentyseventeen/template-parts/page/content-page.php index 4c470acfbe..cc054a0885 100644 --- a/wp-content/themes/twentyseventeen/template-parts/page/content-page.php +++ b/wp-content/themes/twentyseventeen/template-parts/page/content-page.php @@ -21,10 +21,12 @@ '', - ) ); + wp_link_pages( + array( + 'before' => '', + ) + ); ?>
    diff --git a/wp-content/themes/twentyseventeen/template-parts/post/content-audio.php b/wp-content/themes/twentyseventeen/template-parts/post/content-audio.php index 63cf2e54cb..627c0ff2d7 100644 --- a/wp-content/themes/twentyseventeen/template-parts/post/content-audio.php +++ b/wp-content/themes/twentyseventeen/template-parts/post/content-audio.php @@ -14,41 +14,41 @@
    > 'thumb-tack' ) ); - } + if ( is_sticky() && is_home() ) { + echo twentyseventeen_get_svg( array( 'icon' => 'thumb-tack' ) ); + } ?>
    '; - if ( is_single() ) { - twentyseventeen_posted_on(); - } else { - echo twentyseventeen_time_link(); - twentyseventeen_edit_link(); - }; - echo ''; - }; - + if ( 'post' === get_post_type() ) { + echo ''; + }; + + if ( is_single() ) { + the_title( '

    ', '

    ' ); + } elseif ( is_front_page() && is_home() ) { + the_title( '

    ', '

    ' ); + } else { + the_title( '

    ', '

    ' ); + } ?>
    @@ -79,17 +79,21 @@ if ( is_single() || empty( $audio ) ) { /* translators: %s: Name of current post */ - the_content( sprintf( - __( 'Continue reading "%s"', 'twentyseventeen' ), - get_the_title() - ) ); + the_content( + sprintf( + __( 'Continue reading "%s"', 'twentyseventeen' ), + get_the_title() + ) + ); - wp_link_pages( array( - 'before' => '', - 'link_before' => '', - 'link_after' => '', - ) ); + wp_link_pages( + array( + 'before' => '', + 'link_before' => '', + 'link_after' => '', + ) + ); }; ?> diff --git a/wp-content/themes/twentyseventeen/template-parts/post/content-excerpt.php b/wp-content/themes/twentyseventeen/template-parts/post/content-excerpt.php index a552fba0cd..0c640b6ead 100644 --- a/wp-content/themes/twentyseventeen/template-parts/post/content-excerpt.php +++ b/wp-content/themes/twentyseventeen/template-parts/post/content-excerpt.php @@ -30,13 +30,15 @@ - ', esc_url( get_permalink() ) ), '' ); } else { the_title( sprintf( '

    ', esc_url( get_permalink() ) ), '

    ' ); - } ?> + } + ?>
    diff --git a/wp-content/themes/twentyseventeen/template-parts/post/content-gallery.php b/wp-content/themes/twentyseventeen/template-parts/post/content-gallery.php index f5934e136d..0ede45c4c3 100644 --- a/wp-content/themes/twentyseventeen/template-parts/post/content-gallery.php +++ b/wp-content/themes/twentyseventeen/template-parts/post/content-gallery.php @@ -22,12 +22,12 @@ '; - if ( is_single() ) { - twentyseventeen_posted_on(); - } else { - echo twentyseventeen_time_link(); - twentyseventeen_edit_link(); - }; + if ( is_single() ) { + twentyseventeen_posted_on(); + } else { + echo twentyseventeen_time_link(); + twentyseventeen_edit_link(); + }; echo '
    '; }; @@ -66,17 +66,21 @@ if ( is_single() || ! get_post_gallery() ) { /* translators: %s: Name of current post */ - the_content( sprintf( - __( 'Continue reading "%s"', 'twentyseventeen' ), - get_the_title() - ) ); + the_content( + sprintf( + __( 'Continue reading "%s"', 'twentyseventeen' ), + get_the_title() + ) + ); - wp_link_pages( array( - 'before' => '', - 'link_before' => '', - 'link_after' => '', - ) ); + wp_link_pages( + array( + 'before' => '', + 'link_before' => '', + 'link_after' => '', + ) + ); }; ?> diff --git a/wp-content/themes/twentyseventeen/template-parts/post/content-image.php b/wp-content/themes/twentyseventeen/template-parts/post/content-image.php index 91c6545065..e577b4b9a6 100644 --- a/wp-content/themes/twentyseventeen/template-parts/post/content-image.php +++ b/wp-content/themes/twentyseventeen/template-parts/post/content-image.php @@ -14,30 +14,30 @@
    > 'thumb-tack' ) ); - } + if ( is_sticky() && is_home() ) { + echo twentyseventeen_get_svg( array( 'icon' => 'thumb-tack' ) ); + } ?>
    '; - if ( is_single() ) { - twentyseventeen_posted_on(); - } else { - echo twentyseventeen_time_link(); - twentyseventeen_edit_link(); - }; - echo ''; - }; - + if ( 'post' === get_post_type() ) { + echo ''; + }; + + if ( is_single() ) { + the_title( '

    ', '

    ' ); + } elseif ( is_front_page() && is_home() ) { + the_title( '

    ', '

    ' ); + } else { + the_title( '

    ', '

    ' ); + } ?>
    @@ -51,21 +51,26 @@
    - "%s"', 'twentyseventeen' ), - get_the_title() - ) ); + the_content( + sprintf( + __( 'Continue reading "%s"', 'twentyseventeen' ), + get_the_title() + ) + ); - wp_link_pages( array( - 'before' => '', - 'link_before' => '', - 'link_after' => '', - ) ); + wp_link_pages( + array( + 'before' => '', + 'link_before' => '', + 'link_after' => '', + ) + ); }; ?> diff --git a/wp-content/themes/twentyseventeen/template-parts/post/content-none.php b/wp-content/themes/twentyseventeen/template-parts/post/content-none.php index c42941bb8d..9654c1e974 100644 --- a/wp-content/themes/twentyseventeen/template-parts/post/content-none.php +++ b/wp-content/themes/twentyseventeen/template-parts/post/content-none.php @@ -18,7 +18,8 @@
    + if ( is_home() && current_user_can( 'publish_posts' ) ) : + ?>

    Get started here.', 'twentyseventeen' ), esc_url( admin_url( 'post-new.php' ) ) ); ?>

    @@ -28,6 +29,7 @@ + endif; + ?>
    diff --git a/wp-content/themes/twentyseventeen/template-parts/post/content-video.php b/wp-content/themes/twentyseventeen/template-parts/post/content-video.php index dad681fb8e..67300ada36 100644 --- a/wp-content/themes/twentyseventeen/template-parts/post/content-video.php +++ b/wp-content/themes/twentyseventeen/template-parts/post/content-video.php @@ -14,41 +14,41 @@
    > 'thumb-tack' ) ); - } + if ( is_sticky() && is_home() ) { + echo twentyseventeen_get_svg( array( 'icon' => 'thumb-tack' ) ); + } ?>
    '; - if ( is_single() ) { - twentyseventeen_posted_on(); - } else { - echo twentyseventeen_time_link(); - twentyseventeen_edit_link(); - } - echo '
    '; - }; - + if ( 'post' === get_post_type() ) { + echo ''; + }; + + if ( is_single() ) { + the_title( '

    ', '

    ' ); + } elseif ( is_front_page() && is_home() ) { + the_title( '

    ', '

    ' ); + } else { + the_title( '

    ', '

    ' ); + } ?> @@ -78,17 +78,21 @@ if ( is_single() || empty( $video ) ) { /* translators: %s: Name of current post */ - the_content( sprintf( - __( 'Continue reading "%s"', 'twentyseventeen' ), - get_the_title() - ) ); + the_content( + sprintf( + __( 'Continue reading "%s"', 'twentyseventeen' ), + get_the_title() + ) + ); - wp_link_pages( array( - 'before' => '', - 'link_before' => '', - 'link_after' => '', - ) ); + wp_link_pages( + array( + 'before' => '', + 'link_before' => '', + 'link_after' => '', + ) + ); }; ?> diff --git a/wp-content/themes/twentyseventeen/template-parts/post/content.php b/wp-content/themes/twentyseventeen/template-parts/post/content.php index 90c3a4d4c4..6881be7675 100644 --- a/wp-content/themes/twentyseventeen/template-parts/post/content.php +++ b/wp-content/themes/twentyseventeen/template-parts/post/content.php @@ -22,12 +22,12 @@ '; - if ( is_single() ) { - twentyseventeen_posted_on(); - } else { - echo twentyseventeen_time_link(); - twentyseventeen_edit_link(); - }; + if ( is_single() ) { + twentyseventeen_posted_on(); + } else { + echo twentyseventeen_time_link(); + twentyseventeen_edit_link(); + }; echo ''; }; @@ -52,17 +52,21 @@
    "%s"', 'twentyseventeen' ), - get_the_title() - ) ); + the_content( + sprintf( + __( 'Continue reading "%s"', 'twentyseventeen' ), + get_the_title() + ) + ); - wp_link_pages( array( - 'before' => '', - 'link_before' => '', - 'link_after' => '', - ) ); + wp_link_pages( + array( + 'before' => '', + 'link_before' => '', + 'link_after' => '', + ) + ); ?>
    diff --git a/wp-content/themes/twentysixteen/archive.php b/wp-content/themes/twentysixteen/archive.php index bdd2967e52..7f302359ab 100644 --- a/wp-content/themes/twentysixteen/archive.php +++ b/wp-content/themes/twentysixteen/archive.php @@ -32,7 +32,8 @@ get_header(); ?> */ get_template_part( 'template-parts/content', get_post_format() ); - // End the loop. + // End the loop. endwhile; // Previous/next page navigation. - the_posts_pagination( array( - 'prev_text' => __( 'Previous page', 'twentysixteen' ), - 'next_text' => __( 'Next page', 'twentysixteen' ), - 'before_page_number' => '' . __( 'Page', 'twentysixteen' ) . ' ', - ) ); + the_posts_pagination( + array( + 'prev_text' => __( 'Previous page', 'twentysixteen' ), + 'next_text' => __( 'Next page', 'twentysixteen' ), + 'before_page_number' => '' . __( 'Page', 'twentysixteen' ) . ' ', + ) + ); - // If no content, include the "No posts found" template. + // If no content, include the "No posts found" template. else : get_template_part( 'template-parts/content', 'none' ); diff --git a/wp-content/themes/twentysixteen/comments.php b/wp-content/themes/twentysixteen/comments.php index 7ff5b32d0c..95dd5651e3 100644 --- a/wp-content/themes/twentysixteen/comments.php +++ b/wp-content/themes/twentysixteen/comments.php @@ -26,23 +26,23 @@ if ( post_password_required() ) {

    @@ -50,11 +50,13 @@ if ( post_password_required() ) {
      'ol', - 'short_ping' => true, - 'avatar_size' => 42, - ) ); + wp_list_comments( + array( + 'style' => 'ol', + 'short_ping' => true, + 'avatar_size' => 42, + ) + ); ?>
    @@ -64,16 +66,18 @@ if ( post_password_required() ) { -

    +

    '

    ', - 'title_reply_after' => '

    ', - ) ); + comment_form( + array( + 'title_reply_before' => '

    ', + 'title_reply_after' => '

    ', + ) + ); ?> diff --git a/wp-content/themes/twentysixteen/footer.php b/wp-content/themes/twentysixteen/footer.php index 5cf4622770..037633a98d 100644 --- a/wp-content/themes/twentysixteen/footer.php +++ b/wp-content/themes/twentysixteen/footer.php @@ -16,10 +16,12 @@ @@ -27,13 +29,15 @@ diff --git a/wp-content/themes/twentysixteen/functions.php b/wp-content/themes/twentysixteen/functions.php index d6e58e1a92..3e675eafb8 100644 --- a/wp-content/themes/twentysixteen/functions.php +++ b/wp-content/themes/twentysixteen/functions.php @@ -33,100 +33,108 @@ if ( version_compare( $GLOBALS['wp_version'], '4.4-alpha', '<' ) ) { } if ( ! function_exists( 'twentysixteen_setup' ) ) : -/** - * Sets up theme defaults and registers support for various WordPress features. - * - * Note that this function is hooked into the after_setup_theme hook, which - * runs before the init hook. The init hook is too late for some features, such - * as indicating support for post thumbnails. - * - * Create your own twentysixteen_setup() function to override in a child theme. - * - * @since Twenty Sixteen 1.0 - */ -function twentysixteen_setup() { - /* - * Make theme available for translation. - * Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/twentysixteen - * If you're building a theme based on Twenty Sixteen, use a find and replace - * to change 'twentysixteen' to the name of your theme in all the template files - */ - load_theme_textdomain( 'twentysixteen' ); - - // Add default posts and comments RSS feed links to head. - add_theme_support( 'automatic-feed-links' ); - - /* - * Let WordPress manage the document title. - * By adding theme support, we declare that this theme does not use a - * hard-coded tag in the document head, and expect WordPress to - * provide it for us. - */ - add_theme_support( 'title-tag' ); - - /* - * Enable support for custom logo. + /** + * Sets up theme defaults and registers support for various WordPress features. * - * @since Twenty Sixteen 1.2 - */ - add_theme_support( 'custom-logo', array( - 'height' => 240, - 'width' => 240, - 'flex-height' => true, - ) ); - - /* - * Enable support for Post Thumbnails on posts and pages. + * Note that this function is hooked into the after_setup_theme hook, which + * runs before the init hook. The init hook is too late for some features, such + * as indicating support for post thumbnails. * - * @link https://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails - */ - add_theme_support( 'post-thumbnails' ); - set_post_thumbnail_size( 1200, 9999 ); - - // This theme uses wp_nav_menu() in two locations. - register_nav_menus( array( - 'primary' => __( 'Primary Menu', 'twentysixteen' ), - 'social' => __( 'Social Links Menu', 'twentysixteen' ), - ) ); - - /* - * Switch default core markup for search form, comment form, and comments - * to output valid HTML5. - */ - add_theme_support( 'html5', array( - 'search-form', - 'comment-form', - 'comment-list', - 'gallery', - 'caption', - ) ); - - /* - * Enable support for Post Formats. + * Create your own twentysixteen_setup() function to override in a child theme. * - * See: https://codex.wordpress.org/Post_Formats + * @since Twenty Sixteen 1.0 */ - add_theme_support( 'post-formats', array( - 'aside', - 'image', - 'video', - 'quote', - 'link', - 'gallery', - 'status', - 'audio', - 'chat', - ) ); + function twentysixteen_setup() { + /* + * Make theme available for translation. + * Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/twentysixteen + * If you're building a theme based on Twenty Sixteen, use a find and replace + * to change 'twentysixteen' to the name of your theme in all the template files + */ + load_theme_textdomain( 'twentysixteen' ); - /* - * This theme styles the visual editor to resemble the theme style, - * specifically font, colors, icons, and column width. - */ - add_editor_style( array( 'css/editor-style.css', twentysixteen_fonts_url() ) ); + // Add default posts and comments RSS feed links to head. + add_theme_support( 'automatic-feed-links' ); - // Indicate widget sidebars can use selective refresh in the Customizer. - add_theme_support( 'customize-selective-refresh-widgets' ); -} + /* + * Let WordPress manage the document title. + * By adding theme support, we declare that this theme does not use a + * hard-coded <title> tag in the document head, and expect WordPress to + * provide it for us. + */ + add_theme_support( 'title-tag' ); + + /* + * Enable support for custom logo. + * + * @since Twenty Sixteen 1.2 + */ + add_theme_support( + 'custom-logo', array( + 'height' => 240, + 'width' => 240, + 'flex-height' => true, + ) + ); + + /* + * Enable support for Post Thumbnails on posts and pages. + * + * @link https://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails + */ + add_theme_support( 'post-thumbnails' ); + set_post_thumbnail_size( 1200, 9999 ); + + // This theme uses wp_nav_menu() in two locations. + register_nav_menus( + array( + 'primary' => __( 'Primary Menu', 'twentysixteen' ), + 'social' => __( 'Social Links Menu', 'twentysixteen' ), + ) + ); + + /* + * Switch default core markup for search form, comment form, and comments + * to output valid HTML5. + */ + add_theme_support( + 'html5', array( + 'search-form', + 'comment-form', + 'comment-list', + 'gallery', + 'caption', + ) + ); + + /* + * Enable support for Post Formats. + * + * See: https://codex.wordpress.org/Post_Formats + */ + add_theme_support( + 'post-formats', array( + 'aside', + 'image', + 'video', + 'quote', + 'link', + 'gallery', + 'status', + 'audio', + 'chat', + ) + ); + + /* + * This theme styles the visual editor to resemble the theme style, + * specifically font, colors, icons, and column width. + */ + add_editor_style( array( 'css/editor-style.css', twentysixteen_fonts_url() ) ); + + // Indicate widget sidebars can use selective refresh in the Customizer. + add_theme_support( 'customize-selective-refresh-widgets' ); + } endif; // twentysixteen_setup add_action( 'after_setup_theme', 'twentysixteen_setup' ); @@ -152,77 +160,85 @@ add_action( 'after_setup_theme', 'twentysixteen_content_width', 0 ); * @since Twenty Sixteen 1.0 */ function twentysixteen_widgets_init() { - register_sidebar( array( - 'name' => __( 'Sidebar', 'twentysixteen' ), - 'id' => 'sidebar-1', - 'description' => __( 'Add widgets here to appear in your sidebar.', 'twentysixteen' ), - 'before_widget' => '<section id="%1$s" class="widget %2$s">', - 'after_widget' => '</section>', - 'before_title' => '<h2 class="widget-title">', - 'after_title' => '</h2>', - ) ); + register_sidebar( + array( + 'name' => __( 'Sidebar', 'twentysixteen' ), + 'id' => 'sidebar-1', + 'description' => __( 'Add widgets here to appear in your sidebar.', 'twentysixteen' ), + 'before_widget' => '<section id="%1$s" class="widget %2$s">', + 'after_widget' => '</section>', + 'before_title' => '<h2 class="widget-title">', + 'after_title' => '</h2>', + ) + ); - register_sidebar( array( - 'name' => __( 'Content Bottom 1', 'twentysixteen' ), - 'id' => 'sidebar-2', - 'description' => __( 'Appears at the bottom of the content on posts and pages.', 'twentysixteen' ), - 'before_widget' => '<section id="%1$s" class="widget %2$s">', - 'after_widget' => '</section>', - 'before_title' => '<h2 class="widget-title">', - 'after_title' => '</h2>', - ) ); + register_sidebar( + array( + 'name' => __( 'Content Bottom 1', 'twentysixteen' ), + 'id' => 'sidebar-2', + 'description' => __( 'Appears at the bottom of the content on posts and pages.', 'twentysixteen' ), + 'before_widget' => '<section id="%1$s" class="widget %2$s">', + 'after_widget' => '</section>', + 'before_title' => '<h2 class="widget-title">', + 'after_title' => '</h2>', + ) + ); - register_sidebar( array( - 'name' => __( 'Content Bottom 2', 'twentysixteen' ), - 'id' => 'sidebar-3', - 'description' => __( 'Appears at the bottom of the content on posts and pages.', 'twentysixteen' ), - 'before_widget' => '<section id="%1$s" class="widget %2$s">', - 'after_widget' => '</section>', - 'before_title' => '<h2 class="widget-title">', - 'after_title' => '</h2>', - ) ); + register_sidebar( + array( + 'name' => __( 'Content Bottom 2', 'twentysixteen' ), + 'id' => 'sidebar-3', + 'description' => __( 'Appears at the bottom of the content on posts and pages.', 'twentysixteen' ), + 'before_widget' => '<section id="%1$s" class="widget %2$s">', + 'after_widget' => '</section>', + 'before_title' => '<h2 class="widget-title">', + 'after_title' => '</h2>', + ) + ); } add_action( 'widgets_init', 'twentysixteen_widgets_init' ); if ( ! function_exists( 'twentysixteen_fonts_url' ) ) : -/** - * Register Google fonts for Twenty Sixteen. - * - * Create your own twentysixteen_fonts_url() function to override in a child theme. - * - * @since Twenty Sixteen 1.0 - * - * @return string Google fonts URL for the theme. - */ -function twentysixteen_fonts_url() { - $fonts_url = ''; - $fonts = array(); - $subsets = 'latin,latin-ext'; + /** + * Register Google fonts for Twenty Sixteen. + * + * Create your own twentysixteen_fonts_url() function to override in a child theme. + * + * @since Twenty Sixteen 1.0 + * + * @return string Google fonts URL for the theme. + */ + function twentysixteen_fonts_url() { + $fonts_url = ''; + $fonts = array(); + $subsets = 'latin,latin-ext'; - /* translators: If there are characters in your language that are not supported by Merriweather, translate this to 'off'. Do not translate into your own language. */ - if ( 'off' !== _x( 'on', 'Merriweather font: on or off', 'twentysixteen' ) ) { - $fonts[] = 'Merriweather:400,700,900,400italic,700italic,900italic'; + /* translators: If there are characters in your language that are not supported by Merriweather, translate this to 'off'. Do not translate into your own language. */ + if ( 'off' !== _x( 'on', 'Merriweather font: on or off', 'twentysixteen' ) ) { + $fonts[] = 'Merriweather:400,700,900,400italic,700italic,900italic'; + } + + /* translators: If there are characters in your language that are not supported by Montserrat, translate this to 'off'. Do not translate into your own language. */ + if ( 'off' !== _x( 'on', 'Montserrat font: on or off', 'twentysixteen' ) ) { + $fonts[] = 'Montserrat:400,700'; + } + + /* translators: If there are characters in your language that are not supported by Inconsolata, translate this to 'off'. Do not translate into your own language. */ + if ( 'off' !== _x( 'on', 'Inconsolata font: on or off', 'twentysixteen' ) ) { + $fonts[] = 'Inconsolata:400'; + } + + if ( $fonts ) { + $fonts_url = add_query_arg( + array( + 'family' => urlencode( implode( '|', $fonts ) ), + 'subset' => urlencode( $subsets ), + ), 'https://fonts.googleapis.com/css' + ); + } + + return $fonts_url; } - - /* translators: If there are characters in your language that are not supported by Montserrat, translate this to 'off'. Do not translate into your own language. */ - if ( 'off' !== _x( 'on', 'Montserrat font: on or off', 'twentysixteen' ) ) { - $fonts[] = 'Montserrat:400,700'; - } - - /* translators: If there are characters in your language that are not supported by Inconsolata, translate this to 'off'. Do not translate into your own language. */ - if ( 'off' !== _x( 'on', 'Inconsolata font: on or off', 'twentysixteen' ) ) { - $fonts[] = 'Inconsolata:400'; - } - - if ( $fonts ) { - $fonts_url = add_query_arg( array( - 'family' => urlencode( implode( '|', $fonts ) ), - 'subset' => urlencode( $subsets ), - ), 'https://fonts.googleapis.com/css' ); - } - - return $fonts_url; -} endif; /** @@ -280,10 +296,12 @@ function twentysixteen_scripts() { wp_enqueue_script( 'twentysixteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20160816', true ); - wp_localize_script( 'twentysixteen-script', 'screenReaderText', array( - 'expand' => __( 'expand child menu', 'twentysixteen' ), - 'collapse' => __( 'collapse child menu', 'twentysixteen' ), - ) ); + wp_localize_script( + 'twentysixteen-script', 'screenReaderText', array( + 'expand' => __( 'expand child menu', 'twentysixteen' ), + 'collapse' => __( 'collapse child menu', 'twentysixteen' ), + ) + ); } add_action( 'wp_enqueue_scripts', 'twentysixteen_scripts' ); @@ -333,10 +351,10 @@ function twentysixteen_hex2rgb( $color ) { $color = trim( $color, '#' ); if ( strlen( $color ) === 3 ) { - $r = hexdec( substr( $color, 0, 1 ).substr( $color, 0, 1 ) ); - $g = hexdec( substr( $color, 1, 1 ).substr( $color, 1, 1 ) ); - $b = hexdec( substr( $color, 2, 1 ).substr( $color, 2, 1 ) ); - } else if ( strlen( $color ) === 6 ) { + $r = hexdec( substr( $color, 0, 1 ) . substr( $color, 0, 1 ) ); + $g = hexdec( substr( $color, 1, 1 ) . substr( $color, 1, 1 ) ); + $b = hexdec( substr( $color, 2, 1 ) . substr( $color, 2, 1 ) ); + } elseif ( strlen( $color ) === 6 ) { $r = hexdec( substr( $color, 0, 2 ) ); $g = hexdec( substr( $color, 2, 2 ) ); $b = hexdec( substr( $color, 4, 2 ) ); @@ -344,7 +362,11 @@ function twentysixteen_hex2rgb( $color ) { return array(); } - return array( 'red' => $r, 'green' => $g, 'blue' => $b ); + return array( + 'red' => $r, + 'green' => $g, + 'blue' => $b, + ); } /** @@ -389,7 +411,7 @@ function twentysixteen_content_image_sizes_attr( $sizes, $size ) { return $sizes; } -add_filter( 'wp_calculate_image_sizes', 'twentysixteen_content_image_sizes_attr', 10 , 2 ); +add_filter( 'wp_calculate_image_sizes', 'twentysixteen_content_image_sizes_attr', 10, 2 ); /** * Add custom image sizes attribute to enhance responsive image functionality @@ -412,7 +434,7 @@ function twentysixteen_post_thumbnail_sizes_attr( $attr, $attachment, $size ) { } return $attr; } -add_filter( 'wp_get_attachment_image_attributes', 'twentysixteen_post_thumbnail_sizes_attr', 10 , 3 ); +add_filter( 'wp_get_attachment_image_attributes', 'twentysixteen_post_thumbnail_sizes_attr', 10, 3 ); /** * Modifies tag cloud widget arguments to display all tags in the same font size @@ -427,7 +449,7 @@ function twentysixteen_widget_tag_cloud_args( $args ) { $args['largest'] = 1; $args['smallest'] = 1; $args['unit'] = 'em'; - $args['format'] = 'list'; + $args['format'] = 'list'; return $args; } diff --git a/wp-content/themes/twentysixteen/header.php b/wp-content/themes/twentysixteen/header.php index 497f441866..9bc0d3e643 100644 --- a/wp-content/themes/twentysixteen/header.php +++ b/wp-content/themes/twentysixteen/header.php @@ -35,10 +35,12 @@ <h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1> <?php else : ?> <p class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></p> - <?php endif; + <?php + endif; $description = get_bloginfo( 'description', 'display' ); - if ( $description || is_customize_preview() ) : ?> +if ( $description || is_customize_preview() ) : + ?> <p class="site-description"><?php echo $description; ?></p> <?php endif; ?> </div><!-- .site-branding --> @@ -50,10 +52,12 @@ <?php if ( has_nav_menu( 'primary' ) ) : ?> <nav id="site-navigation" class="main-navigation" role="navigation" aria-label="<?php esc_attr_e( 'Primary Menu', 'twentysixteen' ); ?>"> <?php - wp_nav_menu( array( - 'theme_location' => 'primary', - 'menu_class' => 'primary-menu', - ) ); + wp_nav_menu( + array( + 'theme_location' => 'primary', + 'menu_class' => 'primary-menu', + ) + ); ?> </nav><!-- .main-navigation --> <?php endif; ?> @@ -61,13 +65,15 @@ <?php if ( has_nav_menu( 'social' ) ) : ?> <nav id="social-navigation" class="social-navigation" role="navigation" aria-label="<?php esc_attr_e( 'Social Links Menu', 'twentysixteen' ); ?>"> <?php - wp_nav_menu( array( - 'theme_location' => 'social', - 'menu_class' => 'social-links-menu', - 'depth' => 1, - 'link_before' => '<span class="screen-reader-text">', - 'link_after' => '</span>', - ) ); + wp_nav_menu( + array( + 'theme_location' => 'social', + 'menu_class' => 'social-links-menu', + 'depth' => 1, + 'link_before' => '<span class="screen-reader-text">', + 'link_after' => '</span>', + ) + ); ?> </nav><!-- .social-navigation --> <?php endif; ?> diff --git a/wp-content/themes/twentysixteen/image.php b/wp-content/themes/twentysixteen/image.php index 434b0b0220..f67048b3b4 100644 --- a/wp-content/themes/twentysixteen/image.php +++ b/wp-content/themes/twentysixteen/image.php @@ -14,93 +14,99 @@ get_header(); ?> <?php // Start the loop. - while ( have_posts() ) : the_post(); + while ( have_posts() ) : + the_post(); ?> - <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> + <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> - <nav id="image-navigation" class="navigation image-navigation"> - <div class="nav-links"> - <div class="nav-previous"><?php previous_image_link( false, __( 'Previous Image', 'twentysixteen' ) ); ?></div> - <div class="nav-next"><?php next_image_link( false, __( 'Next Image', 'twentysixteen' ) ); ?></div> - </div><!-- .nav-links --> - </nav><!-- .image-navigation --> + <nav id="image-navigation" class="navigation image-navigation"> + <div class="nav-links"> + <div class="nav-previous"><?php previous_image_link( false, __( 'Previous Image', 'twentysixteen' ) ); ?></div> + <div class="nav-next"><?php next_image_link( false, __( 'Next Image', 'twentysixteen' ) ); ?></div> + </div><!-- .nav-links --> + </nav><!-- .image-navigation --> - <header class="entry-header"> - <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?> - </header><!-- .entry-header --> + <header class="entry-header"> + <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?> + </header><!-- .entry-header --> - <div class="entry-content"> + <div class="entry-content"> - <div class="entry-attachment"> - <?php - /** - * Filter the default twentysixteen image attachment size. - * - * @since Twenty Sixteen 1.0 - * - * @param string $image_size Image size. Default 'large'. - */ - $image_size = apply_filters( 'twentysixteen_attachment_size', 'large' ); + <div class="entry-attachment"> + <?php + /** + * Filter the default twentysixteen image attachment size. + * + * @since Twenty Sixteen 1.0 + * + * @param string $image_size Image size. Default 'large'. + */ + $image_size = apply_filters( 'twentysixteen_attachment_size', 'large' ); - echo wp_get_attachment_image( get_the_ID(), $image_size ); - ?> + echo wp_get_attachment_image( get_the_ID(), $image_size ); + ?> - <?php twentysixteen_excerpt( 'entry-caption' ); ?> + <?php twentysixteen_excerpt( 'entry-caption' ); ?> </div><!-- .entry-attachment --> <?php - the_content(); - wp_link_pages( array( + the_content(); + wp_link_pages( + array( 'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentysixteen' ) . '</span>', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>', 'pagelink' => '<span class="screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>%', 'separator' => '<span class="screen-reader-text">, </span>', - ) ); - ?> + ) + ); + ?> </div><!-- .entry-content --> <footer class="entry-footer"> - <?php twentysixteen_entry_meta(); ?> + <?php twentysixteen_entry_meta(); ?> <?php - // Retrieve attachment metadata. - $metadata = wp_get_attachment_metadata(); - if ( $metadata ) { - printf( '<span class="full-size-link"><span class="screen-reader-text">%1$s </span><a href="%2$s">%3$s × %4$s</a></span>', - esc_html_x( 'Full size', 'Used before full size attachment link.', 'twentysixteen' ), - esc_url( wp_get_attachment_url() ), - absint( $metadata['width'] ), - absint( $metadata['height'] ) - ); - } - ?> - <?php - edit_post_link( - sprintf( - /* translators: %s: Name of current post */ - __( 'Edit<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ), - get_the_title() - ), - '<span class="edit-link">', - '</span>' + // Retrieve attachment metadata. + $metadata = wp_get_attachment_metadata(); + if ( $metadata ) { + printf( + '<span class="full-size-link"><span class="screen-reader-text">%1$s </span><a href="%2$s">%3$s × %4$s</a></span>', + esc_html_x( 'Full size', 'Used before full size attachment link.', 'twentysixteen' ), + esc_url( wp_get_attachment_url() ), + absint( $metadata['width'] ), + absint( $metadata['height'] ) ); + } ?> + <?php + edit_post_link( + sprintf( + /* translators: %s: Name of current post */ + __( 'Edit<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ), + get_the_title() + ), + '<span class="edit-link">', + '</span>' + ); + ?> </footer><!-- .entry-footer --> </article><!-- #post-## --> <?php - // If comments are open or we have at least one comment, load up the comment template. - if ( comments_open() || get_comments_number() ) { - comments_template(); - } + // If comments are open or we have at least one comment, load up the comment template. + if ( comments_open() || get_comments_number() ) { + comments_template(); + } - // Parent post navigation. - the_post_navigation( array( + // Parent post navigation. + the_post_navigation( + array( 'prev_text' => _x( '<span class="meta-nav">Published in</span><span class="post-title">%title</span>', 'Parent post link', 'twentysixteen' ), - ) ); + ) + ); // End the loop. endwhile; ?> diff --git a/wp-content/themes/twentysixteen/inc/back-compat.php b/wp-content/themes/twentysixteen/inc/back-compat.php index 7ed4240c8b..ed0f86df03 100644 --- a/wp-content/themes/twentysixteen/inc/back-compat.php +++ b/wp-content/themes/twentysixteen/inc/back-compat.php @@ -50,9 +50,11 @@ function twentysixteen_upgrade_notice() { * @global string $wp_version WordPress version. */ function twentysixteen_customize() { - wp_die( sprintf( __( 'Twenty Sixteen requires at least WordPress version 4.4. You are running version %s. Please upgrade and try again.', 'twentysixteen' ), $GLOBALS['wp_version'] ), '', array( - 'back_link' => true, - ) ); + wp_die( + sprintf( __( 'Twenty Sixteen requires at least WordPress version 4.4. You are running version %s. Please upgrade and try again.', 'twentysixteen' ), $GLOBALS['wp_version'] ), '', array( + 'back_link' => true, + ) + ); } add_action( 'load-customize.php', 'twentysixteen_customize' ); diff --git a/wp-content/themes/twentysixteen/inc/customizer.php b/wp-content/themes/twentysixteen/inc/customizer.php index 62eb1b0b39..0cc2fb5296 100644 --- a/wp-content/themes/twentysixteen/inc/customizer.php +++ b/wp-content/themes/twentysixteen/inc/customizer.php @@ -30,9 +30,13 @@ function twentysixteen_custom_header_and_background() { * @type string $default-color Default color of the background. * } */ - add_theme_support( 'custom-background', apply_filters( 'twentysixteen_custom_background_args', array( - 'default-color' => $default_background_color, - ) ) ); + add_theme_support( + 'custom-background', apply_filters( + 'twentysixteen_custom_background_args', array( + 'default-color' => $default_background_color, + ) + ) + ); /** * Filter the arguments used when adding 'custom-header' support in Twenty Sixteen. @@ -50,35 +54,39 @@ function twentysixteen_custom_header_and_background() { * displayed on the blog. * } */ - add_theme_support( 'custom-header', apply_filters( 'twentysixteen_custom_header_args', array( - 'default-text-color' => $default_text_color, - 'width' => 1200, - 'height' => 280, - 'flex-height' => true, - 'wp-head-callback' => 'twentysixteen_header_style', - ) ) ); + add_theme_support( + 'custom-header', apply_filters( + 'twentysixteen_custom_header_args', array( + 'default-text-color' => $default_text_color, + 'width' => 1200, + 'height' => 280, + 'flex-height' => true, + 'wp-head-callback' => 'twentysixteen_header_style', + ) + ) + ); } add_action( 'after_setup_theme', 'twentysixteen_custom_header_and_background' ); if ( ! function_exists( 'twentysixteen_header_style' ) ) : -/** - * Styles the header text displayed on the site. - * - * Create your own twentysixteen_header_style() function to override in a child theme. - * - * @since Twenty Sixteen 1.0 - * - * @see twentysixteen_custom_header_and_background(). - */ -function twentysixteen_header_style() { - // If the header text option is untouched, let's bail. - if ( display_header_text() ) { - return; - } + /** + * Styles the header text displayed on the site. + * + * Create your own twentysixteen_header_style() function to override in a child theme. + * + * @since Twenty Sixteen 1.0 + * + * @see twentysixteen_custom_header_and_background(). + */ + function twentysixteen_header_style() { + // If the header text option is untouched, let's bail. + if ( display_header_text() ) { + return; + } - // If the header text has been hidden. - ?> - <style type="text/css" id="twentysixteen-header-css"> + // If the header text has been hidden. + ?> + <style type="text/css" id="twentysixteen-header-css"> .site-branding { margin: 0 auto 0 0; } @@ -88,9 +96,9 @@ function twentysixteen_header_style() { clip: rect(1px, 1px, 1px, 1px); position: absolute; } - </style> - <?php -} + </style> + <?php + } endif; // twentysixteen_header_style /** @@ -103,87 +111,119 @@ endif; // twentysixteen_header_style function twentysixteen_customize_register( $wp_customize ) { $color_scheme = twentysixteen_get_color_scheme(); - $wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; - $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; + $wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; + $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; if ( isset( $wp_customize->selective_refresh ) ) { - $wp_customize->selective_refresh->add_partial( 'blogname', array( - 'selector' => '.site-title a', - 'container_inclusive' => false, - 'render_callback' => 'twentysixteen_customize_partial_blogname', - ) ); - $wp_customize->selective_refresh->add_partial( 'blogdescription', array( - 'selector' => '.site-description', - 'container_inclusive' => false, - 'render_callback' => 'twentysixteen_customize_partial_blogdescription', - ) ); + $wp_customize->selective_refresh->add_partial( + 'blogname', array( + 'selector' => '.site-title a', + 'container_inclusive' => false, + 'render_callback' => 'twentysixteen_customize_partial_blogname', + ) + ); + $wp_customize->selective_refresh->add_partial( + 'blogdescription', array( + 'selector' => '.site-description', + 'container_inclusive' => false, + 'render_callback' => 'twentysixteen_customize_partial_blogdescription', + ) + ); } // Add color scheme setting and control. - $wp_customize->add_setting( 'color_scheme', array( - 'default' => 'default', - 'sanitize_callback' => 'twentysixteen_sanitize_color_scheme', - 'transport' => 'postMessage', - ) ); + $wp_customize->add_setting( + 'color_scheme', array( + 'default' => 'default', + 'sanitize_callback' => 'twentysixteen_sanitize_color_scheme', + 'transport' => 'postMessage', + ) + ); - $wp_customize->add_control( 'color_scheme', array( - 'label' => __( 'Base Color Scheme', 'twentysixteen' ), - 'section' => 'colors', - 'type' => 'select', - 'choices' => twentysixteen_get_color_scheme_choices(), - 'priority' => 1, - ) ); + $wp_customize->add_control( + 'color_scheme', array( + 'label' => __( 'Base Color Scheme', 'twentysixteen' ), + 'section' => 'colors', + 'type' => 'select', + 'choices' => twentysixteen_get_color_scheme_choices(), + 'priority' => 1, + ) + ); // Add page background color setting and control. - $wp_customize->add_setting( 'page_background_color', array( - 'default' => $color_scheme[1], - 'sanitize_callback' => 'sanitize_hex_color', - 'transport' => 'postMessage', - ) ); + $wp_customize->add_setting( + 'page_background_color', array( + 'default' => $color_scheme[1], + 'sanitize_callback' => 'sanitize_hex_color', + 'transport' => 'postMessage', + ) + ); - $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'page_background_color', array( - 'label' => __( 'Page Background Color', 'twentysixteen' ), - 'section' => 'colors', - ) ) ); + $wp_customize->add_control( + new WP_Customize_Color_Control( + $wp_customize, 'page_background_color', array( + 'label' => __( 'Page Background Color', 'twentysixteen' ), + 'section' => 'colors', + ) + ) + ); // Remove the core header textcolor control, as it shares the main text color. $wp_customize->remove_control( 'header_textcolor' ); // Add link color setting and control. - $wp_customize->add_setting( 'link_color', array( - 'default' => $color_scheme[2], - 'sanitize_callback' => 'sanitize_hex_color', - 'transport' => 'postMessage', - ) ); + $wp_customize->add_setting( + 'link_color', array( + 'default' => $color_scheme[2], + 'sanitize_callback' => 'sanitize_hex_color', + 'transport' => 'postMessage', + ) + ); - $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'link_color', array( - 'label' => __( 'Link Color', 'twentysixteen' ), - 'section' => 'colors', - ) ) ); + $wp_customize->add_control( + new WP_Customize_Color_Control( + $wp_customize, 'link_color', array( + 'label' => __( 'Link Color', 'twentysixteen' ), + 'section' => 'colors', + ) + ) + ); // Add main text color setting and control. - $wp_customize->add_setting( 'main_text_color', array( - 'default' => $color_scheme[3], - 'sanitize_callback' => 'sanitize_hex_color', - 'transport' => 'postMessage', - ) ); + $wp_customize->add_setting( + 'main_text_color', array( + 'default' => $color_scheme[3], + 'sanitize_callback' => 'sanitize_hex_color', + 'transport' => 'postMessage', + ) + ); - $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'main_text_color', array( - 'label' => __( 'Main Text Color', 'twentysixteen' ), - 'section' => 'colors', - ) ) ); + $wp_customize->add_control( + new WP_Customize_Color_Control( + $wp_customize, 'main_text_color', array( + 'label' => __( 'Main Text Color', 'twentysixteen' ), + 'section' => 'colors', + ) + ) + ); // Add secondary text color setting and control. - $wp_customize->add_setting( 'secondary_text_color', array( - 'default' => $color_scheme[4], - 'sanitize_callback' => 'sanitize_hex_color', - 'transport' => 'postMessage', - ) ); + $wp_customize->add_setting( + 'secondary_text_color', array( + 'default' => $color_scheme[4], + 'sanitize_callback' => 'sanitize_hex_color', + 'transport' => 'postMessage', + ) + ); - $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'secondary_text_color', array( - 'label' => __( 'Secondary Text Color', 'twentysixteen' ), - 'section' => 'colors', - ) ) ); + $wp_customize->add_control( + new WP_Customize_Color_Control( + $wp_customize, 'secondary_text_color', array( + 'label' => __( 'Secondary Text Color', 'twentysixteen' ), + 'section' => 'colors', + ) + ) + ); } add_action( 'customize_register', 'twentysixteen_customize_register', 11 ); @@ -248,127 +288,129 @@ function twentysixteen_get_color_schemes() { * } * } */ - return apply_filters( 'twentysixteen_color_schemes', array( - 'default' => array( - 'label' => __( 'Default', 'twentysixteen' ), - 'colors' => array( - '#1a1a1a', - '#ffffff', - '#007acc', - '#1a1a1a', - '#686868', + return apply_filters( + 'twentysixteen_color_schemes', array( + 'default' => array( + 'label' => __( 'Default', 'twentysixteen' ), + 'colors' => array( + '#1a1a1a', + '#ffffff', + '#007acc', + '#1a1a1a', + '#686868', + ), ), - ), - 'dark' => array( - 'label' => __( 'Dark', 'twentysixteen' ), - 'colors' => array( - '#262626', - '#1a1a1a', - '#9adffd', - '#e5e5e5', - '#c1c1c1', + 'dark' => array( + 'label' => __( 'Dark', 'twentysixteen' ), + 'colors' => array( + '#262626', + '#1a1a1a', + '#9adffd', + '#e5e5e5', + '#c1c1c1', + ), ), - ), - 'gray' => array( - 'label' => __( 'Gray', 'twentysixteen' ), - 'colors' => array( - '#616a73', - '#4d545c', - '#c7c7c7', - '#f2f2f2', - '#f2f2f2', + 'gray' => array( + 'label' => __( 'Gray', 'twentysixteen' ), + 'colors' => array( + '#616a73', + '#4d545c', + '#c7c7c7', + '#f2f2f2', + '#f2f2f2', + ), ), - ), - 'red' => array( - 'label' => __( 'Red', 'twentysixteen' ), - 'colors' => array( - '#ffffff', - '#ff675f', - '#640c1f', - '#402b30', - '#402b30', + 'red' => array( + 'label' => __( 'Red', 'twentysixteen' ), + 'colors' => array( + '#ffffff', + '#ff675f', + '#640c1f', + '#402b30', + '#402b30', + ), ), - ), - 'yellow' => array( - 'label' => __( 'Yellow', 'twentysixteen' ), - 'colors' => array( - '#3b3721', - '#ffef8e', - '#774e24', - '#3b3721', - '#5b4d3e', + 'yellow' => array( + 'label' => __( 'Yellow', 'twentysixteen' ), + 'colors' => array( + '#3b3721', + '#ffef8e', + '#774e24', + '#3b3721', + '#5b4d3e', + ), ), - ), - ) ); + ) + ); } if ( ! function_exists( 'twentysixteen_get_color_scheme' ) ) : -/** - * Retrieves the current Twenty Sixteen color scheme. - * - * Create your own twentysixteen_get_color_scheme() function to override in a child theme. - * - * @since Twenty Sixteen 1.0 - * - * @return array An associative array of either the current or default color scheme HEX values. - */ -function twentysixteen_get_color_scheme() { - $color_scheme_option = get_theme_mod( 'color_scheme', 'default' ); - $color_schemes = twentysixteen_get_color_schemes(); + /** + * Retrieves the current Twenty Sixteen color scheme. + * + * Create your own twentysixteen_get_color_scheme() function to override in a child theme. + * + * @since Twenty Sixteen 1.0 + * + * @return array An associative array of either the current or default color scheme HEX values. + */ + function twentysixteen_get_color_scheme() { + $color_scheme_option = get_theme_mod( 'color_scheme', 'default' ); + $color_schemes = twentysixteen_get_color_schemes(); - if ( array_key_exists( $color_scheme_option, $color_schemes ) ) { - return $color_schemes[ $color_scheme_option ]['colors']; + if ( array_key_exists( $color_scheme_option, $color_schemes ) ) { + return $color_schemes[ $color_scheme_option ]['colors']; + } + + return $color_schemes['default']['colors']; } - - return $color_schemes['default']['colors']; -} endif; // twentysixteen_get_color_scheme if ( ! function_exists( 'twentysixteen_get_color_scheme_choices' ) ) : -/** - * Retrieves an array of color scheme choices registered for Twenty Sixteen. - * - * Create your own twentysixteen_get_color_scheme_choices() function to override - * in a child theme. - * - * @since Twenty Sixteen 1.0 - * - * @return array Array of color schemes. - */ -function twentysixteen_get_color_scheme_choices() { - $color_schemes = twentysixteen_get_color_schemes(); - $color_scheme_control_options = array(); + /** + * Retrieves an array of color scheme choices registered for Twenty Sixteen. + * + * Create your own twentysixteen_get_color_scheme_choices() function to override + * in a child theme. + * + * @since Twenty Sixteen 1.0 + * + * @return array Array of color schemes. + */ + function twentysixteen_get_color_scheme_choices() { + $color_schemes = twentysixteen_get_color_schemes(); + $color_scheme_control_options = array(); - foreach ( $color_schemes as $color_scheme => $value ) { - $color_scheme_control_options[ $color_scheme ] = $value['label']; + foreach ( $color_schemes as $color_scheme => $value ) { + $color_scheme_control_options[ $color_scheme ] = $value['label']; + } + + return $color_scheme_control_options; } - - return $color_scheme_control_options; -} endif; // twentysixteen_get_color_scheme_choices if ( ! function_exists( 'twentysixteen_sanitize_color_scheme' ) ) : -/** - * Handles sanitization for Twenty Sixteen color schemes. - * - * Create your own twentysixteen_sanitize_color_scheme() function to override - * in a child theme. - * - * @since Twenty Sixteen 1.0 - * - * @param string $value Color scheme name value. - * @return string Color scheme name. - */ -function twentysixteen_sanitize_color_scheme( $value ) { - $color_schemes = twentysixteen_get_color_scheme_choices(); + /** + * Handles sanitization for Twenty Sixteen color schemes. + * + * Create your own twentysixteen_sanitize_color_scheme() function to override + * in a child theme. + * + * @since Twenty Sixteen 1.0 + * + * @param string $value Color scheme name value. + * @return string Color scheme name. + */ + function twentysixteen_sanitize_color_scheme( $value ) { + $color_schemes = twentysixteen_get_color_scheme_choices(); - if ( ! array_key_exists( $value, $color_schemes ) ) { - return 'default'; + if ( ! array_key_exists( $value, $color_schemes ) ) { + return 'default'; + } + + return $value; } - - return $value; -} endif; // twentysixteen_sanitize_color_scheme /** @@ -445,14 +487,16 @@ add_action( 'customize_preview_init', 'twentysixteen_customize_preview_js' ); * @return string Color scheme CSS. */ function twentysixteen_get_color_scheme_css( $colors ) { - $colors = wp_parse_args( $colors, array( - 'background_color' => '', - 'page_background_color' => '', - 'link_color' => '', - 'main_text_color' => '', - 'secondary_text_color' => '', - 'border_color' => '', - ) ); + $colors = wp_parse_args( + $colors, array( + 'background_color' => '', + 'page_background_color' => '', + 'link_color' => '', + 'main_text_color' => '', + 'secondary_text_color' => '', + 'border_color' => '', + ) + ); return <<<CSS /* Color Scheme */ @@ -869,9 +913,9 @@ add_action( 'wp_enqueue_scripts', 'twentysixteen_page_background_color_css', 11 * @see wp_add_inline_style() */ function twentysixteen_link_color_css() { - $color_scheme = twentysixteen_get_color_scheme(); - $default_color = $color_scheme[2]; - $link_color = get_theme_mod( 'link_color', $default_color ); + $color_scheme = twentysixteen_get_color_scheme(); + $default_color = $color_scheme[2]; + $link_color = get_theme_mod( 'link_color', $default_color ); // Don't do anything if the current color is the default. if ( $link_color === $default_color ) { @@ -1126,8 +1170,8 @@ add_action( 'wp_enqueue_scripts', 'twentysixteen_main_text_color_css', 11 ); * @see wp_add_inline_style() */ function twentysixteen_secondary_text_color_css() { - $color_scheme = twentysixteen_get_color_scheme(); - $default_color = $color_scheme[4]; + $color_scheme = twentysixteen_get_color_scheme(); + $default_color = $color_scheme[4]; $secondary_text_color = get_theme_mod( 'secondary_text_color', $default_color ); // Don't do anything if the current color is the default. diff --git a/wp-content/themes/twentysixteen/inc/template-tags.php b/wp-content/themes/twentysixteen/inc/template-tags.php index 9b8f1f3901..ce5190a001 100644 --- a/wp-content/themes/twentysixteen/inc/template-tags.php +++ b/wp-content/themes/twentysixteen/inc/template-tags.php @@ -10,126 +10,132 @@ */ if ( ! function_exists( 'twentysixteen_entry_meta' ) ) : -/** - * Prints HTML with meta information for the categories, tags. - * - * Create your own twentysixteen_entry_meta() function to override in a child theme. - * - * @since Twenty Sixteen 1.0 - */ -function twentysixteen_entry_meta() { - if ( 'post' === get_post_type() ) { - $author_avatar_size = apply_filters( 'twentysixteen_author_avatar_size', 49 ); - printf( '<span class="byline"><span class="author vcard">%1$s<span class="screen-reader-text">%2$s </span> <a class="url fn n" href="%3$s">%4$s</a></span></span>', - get_avatar( get_the_author_meta( 'user_email' ), $author_avatar_size ), - _x( 'Author', 'Used before post author name.', 'twentysixteen' ), - esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), - get_the_author() - ); - } + /** + * Prints HTML with meta information for the categories, tags. + * + * Create your own twentysixteen_entry_meta() function to override in a child theme. + * + * @since Twenty Sixteen 1.0 + */ + function twentysixteen_entry_meta() { + if ( 'post' === get_post_type() ) { + $author_avatar_size = apply_filters( 'twentysixteen_author_avatar_size', 49 ); + printf( + '<span class="byline"><span class="author vcard">%1$s<span class="screen-reader-text">%2$s </span> <a class="url fn n" href="%3$s">%4$s</a></span></span>', + get_avatar( get_the_author_meta( 'user_email' ), $author_avatar_size ), + _x( 'Author', 'Used before post author name.', 'twentysixteen' ), + esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), + get_the_author() + ); + } - if ( in_array( get_post_type(), array( 'post', 'attachment' ) ) ) { - twentysixteen_entry_date(); - } + if ( in_array( get_post_type(), array( 'post', 'attachment' ) ) ) { + twentysixteen_entry_date(); + } - $format = get_post_format(); - if ( current_theme_supports( 'post-formats', $format ) ) { - printf( '<span class="entry-format">%1$s<a href="%2$s">%3$s</a></span>', - sprintf( '<span class="screen-reader-text">%s </span>', _x( 'Format', 'Used before post format.', 'twentysixteen' ) ), - esc_url( get_post_format_link( $format ) ), - get_post_format_string( $format ) - ); - } + $format = get_post_format(); + if ( current_theme_supports( 'post-formats', $format ) ) { + printf( + '<span class="entry-format">%1$s<a href="%2$s">%3$s</a></span>', + sprintf( '<span class="screen-reader-text">%s </span>', _x( 'Format', 'Used before post format.', 'twentysixteen' ) ), + esc_url( get_post_format_link( $format ) ), + get_post_format_string( $format ) + ); + } - if ( 'post' === get_post_type() ) { - twentysixteen_entry_taxonomies(); - } + if ( 'post' === get_post_type() ) { + twentysixteen_entry_taxonomies(); + } - if ( ! is_singular() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) { - echo '<span class="comments-link">'; - comments_popup_link( sprintf( __( 'Leave a comment<span class="screen-reader-text"> on %s</span>', 'twentysixteen' ), get_the_title() ) ); - echo '</span>'; + if ( ! is_singular() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) { + echo '<span class="comments-link">'; + comments_popup_link( sprintf( __( 'Leave a comment<span class="screen-reader-text"> on %s</span>', 'twentysixteen' ), get_the_title() ) ); + echo '</span>'; + } } -} endif; if ( ! function_exists( 'twentysixteen_entry_date' ) ) : -/** - * Prints HTML with date information for current post. - * - * Create your own twentysixteen_entry_date() function to override in a child theme. - * - * @since Twenty Sixteen 1.0 - */ -function twentysixteen_entry_date() { - $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>'; + /** + * Prints HTML with date information for current post. + * + * Create your own twentysixteen_entry_date() function to override in a child theme. + * + * @since Twenty Sixteen 1.0 + */ + function twentysixteen_entry_date() { + $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>'; - if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) { - $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>'; + if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) { + $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>'; + } + + $time_string = sprintf( + $time_string, + esc_attr( get_the_date( 'c' ) ), + get_the_date(), + esc_attr( get_the_modified_date( 'c' ) ), + get_the_modified_date() + ); + + printf( + '<span class="posted-on"><span class="screen-reader-text">%1$s </span><a href="%2$s" rel="bookmark">%3$s</a></span>', + _x( 'Posted on', 'Used before publish date.', 'twentysixteen' ), + esc_url( get_permalink() ), + $time_string + ); } - - $time_string = sprintf( $time_string, - esc_attr( get_the_date( 'c' ) ), - get_the_date(), - esc_attr( get_the_modified_date( 'c' ) ), - get_the_modified_date() - ); - - printf( '<span class="posted-on"><span class="screen-reader-text">%1$s </span><a href="%2$s" rel="bookmark">%3$s</a></span>', - _x( 'Posted on', 'Used before publish date.', 'twentysixteen' ), - esc_url( get_permalink() ), - $time_string - ); -} endif; if ( ! function_exists( 'twentysixteen_entry_taxonomies' ) ) : -/** - * Prints HTML with category and tags for current post. - * - * Create your own twentysixteen_entry_taxonomies() function to override in a child theme. - * - * @since Twenty Sixteen 1.0 - */ -function twentysixteen_entry_taxonomies() { - $categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'twentysixteen' ) ); - if ( $categories_list && twentysixteen_categorized_blog() ) { - printf( '<span class="cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>', - _x( 'Categories', 'Used before category names.', 'twentysixteen' ), - $categories_list - ); - } + /** + * Prints HTML with category and tags for current post. + * + * Create your own twentysixteen_entry_taxonomies() function to override in a child theme. + * + * @since Twenty Sixteen 1.0 + */ + function twentysixteen_entry_taxonomies() { + $categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'twentysixteen' ) ); + if ( $categories_list && twentysixteen_categorized_blog() ) { + printf( + '<span class="cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>', + _x( 'Categories', 'Used before category names.', 'twentysixteen' ), + $categories_list + ); + } - $tags_list = get_the_tag_list( '', _x( ', ', 'Used between list items, there is a space after the comma.', 'twentysixteen' ) ); - if ( $tags_list && ! is_wp_error( $tags_list ) ) { - printf( '<span class="tags-links"><span class="screen-reader-text">%1$s </span>%2$s</span>', - _x( 'Tags', 'Used before tag names.', 'twentysixteen' ), - $tags_list - ); + $tags_list = get_the_tag_list( '', _x( ', ', 'Used between list items, there is a space after the comma.', 'twentysixteen' ) ); + if ( $tags_list && ! is_wp_error( $tags_list ) ) { + printf( + '<span class="tags-links"><span class="screen-reader-text">%1$s </span>%2$s</span>', + _x( 'Tags', 'Used before tag names.', 'twentysixteen' ), + $tags_list + ); + } } -} endif; if ( ! function_exists( 'twentysixteen_post_thumbnail' ) ) : -/** - * Displays an optional post thumbnail. - * - * Wraps the post thumbnail in an anchor element on index views, or a div - * element when on single views. - * - * Create your own twentysixteen_post_thumbnail() function to override in a child theme. - * - * @since Twenty Sixteen 1.0 - */ -function twentysixteen_post_thumbnail() { - if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) { - return; - } + /** + * Displays an optional post thumbnail. + * + * Wraps the post thumbnail in an anchor element on index views, or a div + * element when on single views. + * + * Create your own twentysixteen_post_thumbnail() function to override in a child theme. + * + * @since Twenty Sixteen 1.0 + */ + function twentysixteen_post_thumbnail() { + if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) { + return; + } - if ( is_singular() ) : - ?> + if ( is_singular() ) : + ?> - <div class="post-thumbnail"> + <div class="post-thumbnail"> <?php the_post_thumbnail(); ?> </div><!-- .post-thumbnail --> @@ -139,8 +145,9 @@ function twentysixteen_post_thumbnail() { <?php the_post_thumbnail( 'post-thumbnail', array( 'alt' => the_title_attribute( 'echo=0' ) ) ); ?> </a> - <?php endif; // End is_singular() -} + <?php + endif; // End is_singular() + } endif; if ( ! function_exists( 'twentysixteen_excerpt' ) ) : @@ -158,69 +165,74 @@ if ( ! function_exists( 'twentysixteen_excerpt' ) ) : function twentysixteen_excerpt( $class = 'entry-summary' ) { $class = esc_attr( $class ); - if ( has_excerpt() || is_search() ) : ?> + if ( has_excerpt() || is_search() ) : + ?> <div class="<?php echo $class; ?>"> <?php the_excerpt(); ?> </div><!-- .<?php echo $class; ?> --> - <?php endif; + <?php + endif; } endif; if ( ! function_exists( 'twentysixteen_excerpt_more' ) && ! is_admin() ) : -/** - * Replaces "[...]" (appended to automatically generated excerpts) with ... and - * a 'Continue reading' link. - * - * Create your own twentysixteen_excerpt_more() function to override in a child theme. - * - * @since Twenty Sixteen 1.0 - * - * @return string 'Continue reading' link prepended with an ellipsis. - */ -function twentysixteen_excerpt_more() { - $link = sprintf( '<a href="%1$s" class="more-link">%2$s</a>', - esc_url( get_permalink( get_the_ID() ) ), - /* translators: %s: Name of current post */ - sprintf( __( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ), get_the_title( get_the_ID() ) ) - ); - return ' … ' . $link; -} -add_filter( 'excerpt_more', 'twentysixteen_excerpt_more' ); + /** + * Replaces "[...]" (appended to automatically generated excerpts) with ... and + * a 'Continue reading' link. + * + * Create your own twentysixteen_excerpt_more() function to override in a child theme. + * + * @since Twenty Sixteen 1.0 + * + * @return string 'Continue reading' link prepended with an ellipsis. + */ + function twentysixteen_excerpt_more() { + $link = sprintf( + '<a href="%1$s" class="more-link">%2$s</a>', + esc_url( get_permalink( get_the_ID() ) ), + /* translators: %s: Name of current post */ + sprintf( __( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ), get_the_title( get_the_ID() ) ) + ); + return ' … ' . $link; + } + add_filter( 'excerpt_more', 'twentysixteen_excerpt_more' ); endif; if ( ! function_exists( 'twentysixteen_categorized_blog' ) ) : -/** - * Determines whether blog/site has more than one category. - * - * Create your own twentysixteen_categorized_blog() function to override in a child theme. - * - * @since Twenty Sixteen 1.0 - * - * @return bool True if there is more than one category, false otherwise. - */ -function twentysixteen_categorized_blog() { - if ( false === ( $all_the_cool_cats = get_transient( 'twentysixteen_categories' ) ) ) { - // Create an array of all the categories that are attached to posts. - $all_the_cool_cats = get_categories( array( - 'fields' => 'ids', - // We only need to know if there is more than one category. - 'number' => 2, - ) ); + /** + * Determines whether blog/site has more than one category. + * + * Create your own twentysixteen_categorized_blog() function to override in a child theme. + * + * @since Twenty Sixteen 1.0 + * + * @return bool True if there is more than one category, false otherwise. + */ + function twentysixteen_categorized_blog() { + if ( false === ( $all_the_cool_cats = get_transient( 'twentysixteen_categories' ) ) ) { + // Create an array of all the categories that are attached to posts. + $all_the_cool_cats = get_categories( + array( + 'fields' => 'ids', + // We only need to know if there is more than one category. + 'number' => 2, + ) + ); - // Count the number of categories that are attached to the posts. - $all_the_cool_cats = count( $all_the_cool_cats ); + // Count the number of categories that are attached to the posts. + $all_the_cool_cats = count( $all_the_cool_cats ); - set_transient( 'twentysixteen_categories', $all_the_cool_cats ); + set_transient( 'twentysixteen_categories', $all_the_cool_cats ); + } + + if ( $all_the_cool_cats > 1 || is_preview() ) { + // This blog has more than 1 category so twentysixteen_categorized_blog should return true. + return true; + } else { + // This blog has only 1 category so twentysixteen_categorized_blog should return false. + return false; + } } - - if ( $all_the_cool_cats > 1 || is_preview() ) { - // This blog has more than 1 category so twentysixteen_categorized_blog should return true. - return true; - } else { - // This blog has only 1 category so twentysixteen_categorized_blog should return false. - return false; - } -} endif; /** @@ -236,19 +248,19 @@ function twentysixteen_category_transient_flusher() { delete_transient( 'twentysixteen_categories' ); } add_action( 'edit_category', 'twentysixteen_category_transient_flusher' ); -add_action( 'save_post', 'twentysixteen_category_transient_flusher' ); +add_action( 'save_post', 'twentysixteen_category_transient_flusher' ); if ( ! function_exists( 'twentysixteen_the_custom_logo' ) ) : -/** - * Displays the optional custom logo. - * - * Does nothing if the custom logo is not available. - * - * @since Twenty Sixteen 1.2 - */ -function twentysixteen_the_custom_logo() { - if ( function_exists( 'the_custom_logo' ) ) { - the_custom_logo(); + /** + * Displays the optional custom logo. + * + * Does nothing if the custom logo is not available. + * + * @since Twenty Sixteen 1.2 + */ + function twentysixteen_the_custom_logo() { + if ( function_exists( 'the_custom_logo' ) ) { + the_custom_logo(); + } } -} endif; diff --git a/wp-content/themes/twentysixteen/index.php b/wp-content/themes/twentysixteen/index.php index 3f621abef0..d31ef2f804 100644 --- a/wp-content/themes/twentysixteen/index.php +++ b/wp-content/themes/twentysixteen/index.php @@ -29,7 +29,8 @@ get_header(); ?> <?php // Start the loop. - while ( have_posts() ) : the_post(); + while ( have_posts() ) : + the_post(); /* * Include the Post-Format-specific template for the content. @@ -38,17 +39,19 @@ get_header(); ?> */ get_template_part( 'template-parts/content', get_post_format() ); - // End the loop. + // End the loop. endwhile; // Previous/next page navigation. - the_posts_pagination( array( - 'prev_text' => __( 'Previous page', 'twentysixteen' ), - 'next_text' => __( 'Next page', 'twentysixteen' ), - 'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>', - ) ); + the_posts_pagination( + array( + 'prev_text' => __( 'Previous page', 'twentysixteen' ), + 'next_text' => __( 'Next page', 'twentysixteen' ), + 'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>', + ) + ); - // If no content, include the "No posts found" template. + // If no content, include the "No posts found" template. else : get_template_part( 'template-parts/content', 'none' ); diff --git a/wp-content/themes/twentysixteen/page.php b/wp-content/themes/twentysixteen/page.php index 315a3da70a..a232c9fce1 100644 --- a/wp-content/themes/twentysixteen/page.php +++ b/wp-content/themes/twentysixteen/page.php @@ -17,7 +17,8 @@ get_header(); ?> <main id="main" class="site-main" role="main"> <?php // Start the loop. - while ( have_posts() ) : the_post(); + while ( have_posts() ) : + the_post(); // Include the page content template. get_template_part( 'template-parts/content', 'page' ); diff --git a/wp-content/themes/twentysixteen/search.php b/wp-content/themes/twentysixteen/search.php index 4180b5f9e1..0f893636fc 100644 --- a/wp-content/themes/twentysixteen/search.php +++ b/wp-content/themes/twentysixteen/search.php @@ -20,7 +20,8 @@ get_header(); ?> <?php // Start the loop. - while ( have_posts() ) : the_post(); + while ( have_posts() ) : + the_post(); /** * Run the loop for the search to output the results. @@ -29,17 +30,19 @@ get_header(); ?> */ get_template_part( 'template-parts/content', 'search' ); - // End the loop. + // End the loop. endwhile; // Previous/next page navigation. - the_posts_pagination( array( - 'prev_text' => __( 'Previous page', 'twentysixteen' ), - 'next_text' => __( 'Next page', 'twentysixteen' ), - 'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>', - ) ); + the_posts_pagination( + array( + 'prev_text' => __( 'Previous page', 'twentysixteen' ), + 'next_text' => __( 'Next page', 'twentysixteen' ), + 'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>', + ) + ); - // If no content, include the "No posts found" template. + // If no content, include the "No posts found" template. else : get_template_part( 'template-parts/content', 'none' ); diff --git a/wp-content/themes/twentysixteen/sidebar.php b/wp-content/themes/twentysixteen/sidebar.php index d4d893ebb2..45aff971ab 100644 --- a/wp-content/themes/twentysixteen/sidebar.php +++ b/wp-content/themes/twentysixteen/sidebar.php @@ -8,7 +8,7 @@ */ ?> -<?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?> +<?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?> <aside id="secondary" class="sidebar widget-area" role="complementary"> <?php dynamic_sidebar( 'sidebar-1' ); ?> </aside><!-- .sidebar .widget-area --> diff --git a/wp-content/themes/twentysixteen/single.php b/wp-content/themes/twentysixteen/single.php index 07e0df290d..3454170335 100644 --- a/wp-content/themes/twentysixteen/single.php +++ b/wp-content/themes/twentysixteen/single.php @@ -13,7 +13,8 @@ get_header(); ?> <main id="main" class="site-main" role="main"> <?php // Start the loop. - while ( have_posts() ) : the_post(); + while ( have_posts() ) : + the_post(); // Include the single post content template. get_template_part( 'template-parts/content', 'single' ); @@ -25,19 +26,23 @@ get_header(); ?> if ( is_singular( 'attachment' ) ) { // Parent post navigation. - the_post_navigation( array( - 'prev_text' => _x( '<span class="meta-nav">Published in</span><span class="post-title">%title</span>', 'Parent post link', 'twentysixteen' ), - ) ); + the_post_navigation( + array( + 'prev_text' => _x( '<span class="meta-nav">Published in</span><span class="post-title">%title</span>', 'Parent post link', 'twentysixteen' ), + ) + ); } elseif ( is_singular( 'post' ) ) { // Previous/next post navigation. - the_post_navigation( array( - 'next_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Next', 'twentysixteen' ) . '</span> ' . - '<span class="screen-reader-text">' . __( 'Next post:', 'twentysixteen' ) . '</span> ' . - '<span class="post-title">%title</span>', - 'prev_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Previous', 'twentysixteen' ) . '</span> ' . - '<span class="screen-reader-text">' . __( 'Previous post:', 'twentysixteen' ) . '</span> ' . - '<span class="post-title">%title</span>', - ) ); + the_post_navigation( + array( + 'next_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Next', 'twentysixteen' ) . '</span> ' . + '<span class="screen-reader-text">' . __( 'Next post:', 'twentysixteen' ) . '</span> ' . + '<span class="post-title">%title</span>', + 'prev_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Previous', 'twentysixteen' ) . '</span> ' . + '<span class="screen-reader-text">' . __( 'Previous post:', 'twentysixteen' ) . '</span> ' . + '<span class="post-title">%title</span>', + ) + ); } // End of the loop. diff --git a/wp-content/themes/twentysixteen/template-parts/content-page.php b/wp-content/themes/twentysixteen/template-parts/content-page.php index 2b57d2b5c1..470776b405 100644 --- a/wp-content/themes/twentysixteen/template-parts/content-page.php +++ b/wp-content/themes/twentysixteen/template-parts/content-page.php @@ -19,14 +19,16 @@ <?php the_content(); - wp_link_pages( array( - 'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentysixteen' ) . '</span>', - 'after' => '</div>', - 'link_before' => '<span>', - 'link_after' => '</span>', - 'pagelink' => '<span class="screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>%', - 'separator' => '<span class="screen-reader-text">, </span>', - ) ); + wp_link_pages( + array( + 'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentysixteen' ) . '</span>', + 'after' => '</div>', + 'link_before' => '<span>', + 'link_after' => '</span>', + 'pagelink' => '<span class="screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>%', + 'separator' => '<span class="screen-reader-text">, </span>', + ) + ); ?> </div><!-- .entry-content --> diff --git a/wp-content/themes/twentysixteen/template-parts/content-single.php b/wp-content/themes/twentysixteen/template-parts/content-single.php index 241f52855e..58f829b45e 100644 --- a/wp-content/themes/twentysixteen/template-parts/content-single.php +++ b/wp-content/themes/twentysixteen/template-parts/content-single.php @@ -21,14 +21,16 @@ <?php the_content(); - wp_link_pages( array( - 'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentysixteen' ) . '</span>', - 'after' => '</div>', - 'link_before' => '<span>', - 'link_after' => '</span>', - 'pagelink' => '<span class="screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>%', - 'separator' => '<span class="screen-reader-text">, </span>', - ) ); + wp_link_pages( + array( + 'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentysixteen' ) . '</span>', + 'after' => '</div>', + 'link_before' => '<span>', + 'link_after' => '</span>', + 'pagelink' => '<span class="screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>%', + 'separator' => '<span class="screen-reader-text">, </span>', + ) + ); if ( '' !== get_the_author_meta( 'description' ) ) { get_template_part( 'template-parts/biography' ); diff --git a/wp-content/themes/twentysixteen/template-parts/content.php b/wp-content/themes/twentysixteen/template-parts/content.php index 22b0ea418d..703487dca4 100644 --- a/wp-content/themes/twentysixteen/template-parts/content.php +++ b/wp-content/themes/twentysixteen/template-parts/content.php @@ -24,19 +24,23 @@ <div class="entry-content"> <?php /* translators: %s: Name of current post */ - the_content( sprintf( - __( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ), - get_the_title() - ) ); + the_content( + sprintf( + __( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ), + get_the_title() + ) + ); - wp_link_pages( array( - 'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentysixteen' ) . '</span>', - 'after' => '</div>', - 'link_before' => '<span>', - 'link_after' => '</span>', - 'pagelink' => '<span class="screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>%', - 'separator' => '<span class="screen-reader-text">, </span>', - ) ); + wp_link_pages( + array( + 'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentysixteen' ) . '</span>', + 'after' => '</div>', + 'link_before' => '<span>', + 'link_after' => '</span>', + 'pagelink' => '<span class="screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>%', + 'separator' => '<span class="screen-reader-text">, </span>', + ) + ); ?> </div><!-- .entry-content --> diff --git a/wp-content/themes/twentyten/404.php b/wp-content/themes/twentyten/404.php index 6cc489cdb9..914ef01089 100644 --- a/wp-content/themes/twentyten/404.php +++ b/wp-content/themes/twentyten/404.php @@ -27,4 +27,4 @@ get_header(); ?> document.getElementById('s') && document.getElementById('s').focus(); </script> -<?php get_footer(); ?> \ No newline at end of file +<?php get_footer(); ?> diff --git a/wp-content/themes/twentyten/archive.php b/wp-content/themes/twentyten/archive.php index 138b088ee8..5b8e6e1e94 100644 --- a/wp-content/themes/twentyten/archive.php +++ b/wp-content/themes/twentyten/archive.php @@ -25,8 +25,9 @@ get_header(); ?> * We reset this later so we can run the loop * properly with a call to rewind_posts(). */ - if ( have_posts() ) - the_post(); +if ( have_posts() ) { + the_post(); +} ?> <h1 class="page-title"> diff --git a/wp-content/themes/twentyten/author.php b/wp-content/themes/twentyten/author.php index 2b221b57f2..b851764f11 100644 --- a/wp-content/themes/twentyten/author.php +++ b/wp-content/themes/twentyten/author.php @@ -21,15 +21,17 @@ get_header(); ?> * We reset this later so we can run the loop * properly with a call to rewind_posts(). */ - if ( have_posts() ) - the_post(); +if ( have_posts() ) { + the_post(); +} ?> <h1 class="page-title author"><?php printf( __( 'Author Archives: %s', 'twentyten' ), '<span class="vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '" title="' . esc_attr( get_the_author() ) . '" rel="me">' . get_the_author() . '</a></span>' ); ?></h1> <?php // If a user has filled out their description, show a bio on their entries. -if ( get_the_author_meta( 'description' ) ) : ?> +if ( get_the_author_meta( 'description' ) ) : +?> <div id="entry-author-info"> <div id="author-avatar"> <?php diff --git a/wp-content/themes/twentyten/category.php b/wp-content/themes/twentyten/category.php index 50ffbf3ec6..00714e85df 100644 --- a/wp-content/themes/twentyten/category.php +++ b/wp-content/themes/twentyten/category.php @@ -12,13 +12,16 @@ get_header(); ?> <div id="container"> <div id="content" role="main"> - <h1 class="page-title"><?php + <h1 class="page-title"> + <?php printf( __( 'Category Archives: %s', 'twentyten' ), '<span>' . single_cat_title( '', false ) . '</span>' ); - ?></h1> + ?> + </h1> <?php $category_description = category_description(); - if ( ! empty( $category_description ) ) - echo '<div class="archive-meta">' . $category_description . '</div>'; + if ( ! empty( $category_description ) ) { + echo '<div class="archive-meta">' . $category_description . '</div>'; + } /* * Run the loop for the category page to output the posts. diff --git a/wp-content/themes/twentyten/comments.php b/wp-content/themes/twentyten/comments.php index 6825a510ba..4b0943fb95 100644 --- a/wp-content/themes/twentyten/comments.php +++ b/wp-content/themes/twentyten/comments.php @@ -32,10 +32,14 @@ ?> <?php if ( have_comments() ) : ?> - <h3 id="comments-title"><?php - printf( _n( 'One Response to %2$s', '%1$s Responses to %2$s', get_comments_number(), 'twentyten' ), - number_format_i18n( get_comments_number() ), '<em>' . get_the_title() . '</em>' ); - ?></h3> + <h3 id="comments-title"> + <?php + printf( + _n( 'One Response to %2$s', '%1$s Responses to %2$s', get_comments_number(), 'twentyten' ), + number_format_i18n( get_comments_number() ), '<em>' . get_the_title() . '</em>' + ); + ?> + </h3> <?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // Are there comments to navigate through? ?> <div class="navigation"> @@ -69,9 +73,10 @@ * If there are no comments and comments are closed, let's leave a little note, shall we? * But we only want the note on posts and pages that had comments in the first place. */ - if ( ! comments_open() && get_comments_number() ) : ?> - <p class="nocomments"><?php _e( 'Comments are closed.' , 'twentyten' ); ?></p> - <?php endif; ?> + if ( ! comments_open() && get_comments_number() ) : + ?> + <p class="nocomments"><?php _e( 'Comments are closed.', 'twentyten' ); ?></p> + <?php endif; ?> <?php endif; // end have_comments() ?> diff --git a/wp-content/themes/twentyten/footer.php b/wp-content/themes/twentyten/footer.php index 4bc8c548f7..bb32687930 100644 --- a/wp-content/themes/twentyten/footer.php +++ b/wp-content/themes/twentyten/footer.php @@ -36,7 +36,8 @@ * * @since Twenty Ten 1.0 */ - do_action( 'twentyten_credits' ); ?> + do_action( 'twentyten_credits' ); + ?> <a href="<?php echo esc_url( __( 'https://wordpress.org/', 'twentyten' ) ); ?>" title="<?php esc_attr_e( 'Semantic Personal Publishing Platform', 'twentyten' ); ?>"><?php printf( __( 'Proudly powered by %s.', 'twentyten' ), 'WordPress' ); ?></a> </div><!-- #site-generator --> diff --git a/wp-content/themes/twentyten/functions.php b/wp-content/themes/twentyten/functions.php index 3db0ab0ed7..0686cbee2b 100644 --- a/wp-content/themes/twentyten/functions.php +++ b/wp-content/themes/twentyten/functions.php @@ -44,195 +44,202 @@ * Used to set the width of images and content. Should be equal to the width the theme * is designed for, generally via the style.css stylesheet. */ -if ( ! isset( $content_width ) ) +if ( ! isset( $content_width ) ) { $content_width = 640; +} /* Tell WordPress to run twentyten_setup() when the 'after_setup_theme' hook is run. */ add_action( 'after_setup_theme', 'twentyten_setup' ); -if ( ! function_exists( 'twentyten_setup' ) ): -/** - * Set up theme defaults and registers support for various WordPress features. - * - * Note that this function is hooked into the after_setup_theme hook, which runs - * before the init hook. The init hook is too late for some features, such as indicating - * support post thumbnails. - * - * To override twentyten_setup() in a child theme, add your own twentyten_setup to your child theme's - * functions.php file. - * - * @uses add_theme_support() To add support for post thumbnails, custom headers and backgrounds, and automatic feed links. - * @uses register_nav_menus() To add support for navigation menus. - * @uses add_editor_style() To style the visual editor. - * @uses load_theme_textdomain() For translation/localization support. - * @uses register_default_headers() To register the default custom header images provided with the theme. - * @uses set_post_thumbnail_size() To set a custom post thumbnail size. - * - * @since Twenty Ten 1.0 - */ -function twentyten_setup() { - - // This theme styles the visual editor with editor-style.css to match the theme style. - add_editor_style(); - - // Post Format support. You can also use the legacy "gallery" or "asides" (note the plural) categories. - add_theme_support( 'post-formats', array( 'aside', 'gallery' ) ); - - // This theme uses post thumbnails - add_theme_support( 'post-thumbnails' ); - - // Add default posts and comments RSS feed links to head - add_theme_support( 'automatic-feed-links' ); - - /* - * Make theme available for translation. - * Translations can be filed in the /languages/ directory +if ( ! function_exists( 'twentyten_setup' ) ) : + /** + * Set up theme defaults and registers support for various WordPress features. + * + * Note that this function is hooked into the after_setup_theme hook, which runs + * before the init hook. The init hook is too late for some features, such as indicating + * support post thumbnails. + * + * To override twentyten_setup() in a child theme, add your own twentyten_setup to your child theme's + * functions.php file. + * + * @uses add_theme_support() To add support for post thumbnails, custom headers and backgrounds, and automatic feed links. + * @uses register_nav_menus() To add support for navigation menus. + * @uses add_editor_style() To style the visual editor. + * @uses load_theme_textdomain() For translation/localization support. + * @uses register_default_headers() To register the default custom header images provided with the theme. + * @uses set_post_thumbnail_size() To set a custom post thumbnail size. + * + * @since Twenty Ten 1.0 */ - load_theme_textdomain( 'twentyten', get_template_directory() . '/languages' ); + function twentyten_setup() { - // This theme uses wp_nav_menu() in one location. - register_nav_menus( array( - 'primary' => __( 'Primary Navigation', 'twentyten' ), - ) ); + // This theme styles the visual editor with editor-style.css to match the theme style. + add_editor_style(); - // This theme allows users to set a custom background. - add_theme_support( 'custom-background', array( - // Let WordPress know what our default background color is. - 'default-color' => 'f1f1f1', - ) ); + // Post Format support. You can also use the legacy "gallery" or "asides" (note the plural) categories. + add_theme_support( 'post-formats', array( 'aside', 'gallery' ) ); - // The custom header business starts here. + // This theme uses post thumbnails + add_theme_support( 'post-thumbnails' ); + + // Add default posts and comments RSS feed links to head + add_theme_support( 'automatic-feed-links' ); - $custom_header_support = array( /* - * The default image to use. - * The %s is a placeholder for the theme template directory URI. + * Make theme available for translation. + * Translations can be filed in the /languages/ directory */ - 'default-image' => '%s/images/headers/path.jpg', - // The height and width of our custom header. - /** - * Filter the Twenty Ten default header image width. - * - * @since Twenty Ten 1.0 - * - * @param int The default header image width in pixels. Default 940. - */ - 'width' => apply_filters( 'twentyten_header_image_width', 940 ), - /** - * Filter the Twenty Ten defaul header image height. - * - * @since Twenty Ten 1.0 - * - * @param int The default header image height in pixels. Default 198. - */ - 'height' => apply_filters( 'twentyten_header_image_height', 198 ), - // Support flexible heights. - 'flex-height' => true, - // Don't support text inside the header image. - 'header-text' => false, - // Callback for styling the header preview in the admin. - 'admin-head-callback' => 'twentyten_admin_header_style', - ); + load_theme_textdomain( 'twentyten', get_template_directory() . '/languages' ); - add_theme_support( 'custom-header', $custom_header_support ); + // This theme uses wp_nav_menu() in one location. + register_nav_menus( + array( + 'primary' => __( 'Primary Navigation', 'twentyten' ), + ) + ); - if ( ! function_exists( 'get_custom_header' ) ) { - // This is all for compatibility with versions of WordPress prior to 3.4. - define( 'HEADER_TEXTCOLOR', '' ); - define( 'NO_HEADER_TEXT', true ); - define( 'HEADER_IMAGE', $custom_header_support['default-image'] ); - define( 'HEADER_IMAGE_WIDTH', $custom_header_support['width'] ); - define( 'HEADER_IMAGE_HEIGHT', $custom_header_support['height'] ); - add_custom_image_header( '', $custom_header_support['admin-head-callback'] ); - add_custom_background(); + // This theme allows users to set a custom background. + add_theme_support( + 'custom-background', array( + // Let WordPress know what our default background color is. + 'default-color' => 'f1f1f1', + ) + ); + + // The custom header business starts here. + + $custom_header_support = array( + /* + * The default image to use. + * The %s is a placeholder for the theme template directory URI. + */ + 'default-image' => '%s/images/headers/path.jpg', + // The height and width of our custom header. + /** + * Filter the Twenty Ten default header image width. + * + * @since Twenty Ten 1.0 + * + * @param int The default header image width in pixels. Default 940. + */ + 'width' => apply_filters( 'twentyten_header_image_width', 940 ), + /** + * Filter the Twenty Ten defaul header image height. + * + * @since Twenty Ten 1.0 + * + * @param int The default header image height in pixels. Default 198. + */ + 'height' => apply_filters( 'twentyten_header_image_height', 198 ), + // Support flexible heights. + 'flex-height' => true, + // Don't support text inside the header image. + 'header-text' => false, + // Callback for styling the header preview in the admin. + 'admin-head-callback' => 'twentyten_admin_header_style', + ); + + add_theme_support( 'custom-header', $custom_header_support ); + + if ( ! function_exists( 'get_custom_header' ) ) { + // This is all for compatibility with versions of WordPress prior to 3.4. + define( 'HEADER_TEXTCOLOR', '' ); + define( 'NO_HEADER_TEXT', true ); + define( 'HEADER_IMAGE', $custom_header_support['default-image'] ); + define( 'HEADER_IMAGE_WIDTH', $custom_header_support['width'] ); + define( 'HEADER_IMAGE_HEIGHT', $custom_header_support['height'] ); + add_custom_image_header( '', $custom_header_support['admin-head-callback'] ); + add_custom_background(); + } + + /* + * We'll be using post thumbnails for custom header images on posts and pages. + * We want them to be 940 pixels wide by 198 pixels tall. + * Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php. + */ + set_post_thumbnail_size( $custom_header_support['width'], $custom_header_support['height'], true ); + + // ... and thus ends the custom header business. + + // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI. + register_default_headers( + array( + 'berries' => array( + 'url' => '%s/images/headers/berries.jpg', + 'thumbnail_url' => '%s/images/headers/berries-thumbnail.jpg', + /* translators: header image description */ + 'description' => __( 'Berries', 'twentyten' ), + ), + 'cherryblossom' => array( + 'url' => '%s/images/headers/cherryblossoms.jpg', + 'thumbnail_url' => '%s/images/headers/cherryblossoms-thumbnail.jpg', + /* translators: header image description */ + 'description' => __( 'Cherry Blossoms', 'twentyten' ), + ), + 'concave' => array( + 'url' => '%s/images/headers/concave.jpg', + 'thumbnail_url' => '%s/images/headers/concave-thumbnail.jpg', + /* translators: header image description */ + 'description' => __( 'Concave', 'twentyten' ), + ), + 'fern' => array( + 'url' => '%s/images/headers/fern.jpg', + 'thumbnail_url' => '%s/images/headers/fern-thumbnail.jpg', + /* translators: header image description */ + 'description' => __( 'Fern', 'twentyten' ), + ), + 'forestfloor' => array( + 'url' => '%s/images/headers/forestfloor.jpg', + 'thumbnail_url' => '%s/images/headers/forestfloor-thumbnail.jpg', + /* translators: header image description */ + 'description' => __( 'Forest Floor', 'twentyten' ), + ), + 'inkwell' => array( + 'url' => '%s/images/headers/inkwell.jpg', + 'thumbnail_url' => '%s/images/headers/inkwell-thumbnail.jpg', + /* translators: header image description */ + 'description' => __( 'Inkwell', 'twentyten' ), + ), + 'path' => array( + 'url' => '%s/images/headers/path.jpg', + 'thumbnail_url' => '%s/images/headers/path-thumbnail.jpg', + /* translators: header image description */ + 'description' => __( 'Path', 'twentyten' ), + ), + 'sunset' => array( + 'url' => '%s/images/headers/sunset.jpg', + 'thumbnail_url' => '%s/images/headers/sunset-thumbnail.jpg', + /* translators: header image description */ + 'description' => __( 'Sunset', 'twentyten' ), + ), + ) + ); } - - /* - * We'll be using post thumbnails for custom header images on posts and pages. - * We want them to be 940 pixels wide by 198 pixels tall. - * Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php. - */ - set_post_thumbnail_size( $custom_header_support['width'], $custom_header_support['height'], true ); - - // ... and thus ends the custom header business. - - // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI. - register_default_headers( array( - 'berries' => array( - 'url' => '%s/images/headers/berries.jpg', - 'thumbnail_url' => '%s/images/headers/berries-thumbnail.jpg', - /* translators: header image description */ - 'description' => __( 'Berries', 'twentyten' ) - ), - 'cherryblossom' => array( - 'url' => '%s/images/headers/cherryblossoms.jpg', - 'thumbnail_url' => '%s/images/headers/cherryblossoms-thumbnail.jpg', - /* translators: header image description */ - 'description' => __( 'Cherry Blossoms', 'twentyten' ) - ), - 'concave' => array( - 'url' => '%s/images/headers/concave.jpg', - 'thumbnail_url' => '%s/images/headers/concave-thumbnail.jpg', - /* translators: header image description */ - 'description' => __( 'Concave', 'twentyten' ) - ), - 'fern' => array( - 'url' => '%s/images/headers/fern.jpg', - 'thumbnail_url' => '%s/images/headers/fern-thumbnail.jpg', - /* translators: header image description */ - 'description' => __( 'Fern', 'twentyten' ) - ), - 'forestfloor' => array( - 'url' => '%s/images/headers/forestfloor.jpg', - 'thumbnail_url' => '%s/images/headers/forestfloor-thumbnail.jpg', - /* translators: header image description */ - 'description' => __( 'Forest Floor', 'twentyten' ) - ), - 'inkwell' => array( - 'url' => '%s/images/headers/inkwell.jpg', - 'thumbnail_url' => '%s/images/headers/inkwell-thumbnail.jpg', - /* translators: header image description */ - 'description' => __( 'Inkwell', 'twentyten' ) - ), - 'path' => array( - 'url' => '%s/images/headers/path.jpg', - 'thumbnail_url' => '%s/images/headers/path-thumbnail.jpg', - /* translators: header image description */ - 'description' => __( 'Path', 'twentyten' ) - ), - 'sunset' => array( - 'url' => '%s/images/headers/sunset.jpg', - 'thumbnail_url' => '%s/images/headers/sunset-thumbnail.jpg', - /* translators: header image description */ - 'description' => __( 'Sunset', 'twentyten' ) - ) - ) ); -} endif; if ( ! function_exists( 'twentyten_admin_header_style' ) ) : -/** - * Style the header image displayed on the Appearance > Header admin panel. - * - * Referenced via add_custom_image_header() in twentyten_setup(). - * - * @since Twenty Ten 1.0 - */ -function twentyten_admin_header_style() { -?> -<style type="text/css" id="twentyten-admin-header-css"> -/* Shows the same border as on front end */ -#headimg { + /** + * Style the header image displayed on the Appearance > Header admin panel. + * + * Referenced via add_custom_image_header() in twentyten_setup(). + * + * @since Twenty Ten 1.0 + */ + function twentyten_admin_header_style() { + ?> + <style type="text/css" id="twentyten-admin-header-css"> + /* Shows the same border as on front end */ + #headimg { border-bottom: 1px solid #000; border-top: 4px solid #000; -} -/* If header-text was supported, you would style the text with these selectors: + } + /* If header-text was supported, you would style the text with these selectors: #headimg #name { } #headimg #desc { } -*/ -</style> -<?php -} + */ + </style> + <?php + } endif; /** @@ -246,8 +253,9 @@ endif; * @param array $args An optional array of arguments. @see wp_page_menu() */ function twentyten_page_menu_args( $args ) { - if ( ! isset( $args['show_home'] ) ) + if ( ! isset( $args['show_home'] ) ) { $args['show_home'] = true; + } return $args; } add_filter( 'wp_page_menu_args', 'twentyten_page_menu_args' ); @@ -269,16 +277,16 @@ function twentyten_excerpt_length( $length ) { add_filter( 'excerpt_length', 'twentyten_excerpt_length' ); if ( ! function_exists( 'twentyten_continue_reading_link' ) ) : -/** - * Return a "Continue Reading" link for excerpts. - * - * @since Twenty Ten 1.0 - * - * @return string "Continue Reading" link. - */ -function twentyten_continue_reading_link() { - return ' <a href="'. get_permalink() . '">' . __( 'Continue reading <span class="meta-nav">→</span>', 'twentyten' ) . '</a>'; -} + /** + * Return a "Continue Reading" link for excerpts. + * + * @since Twenty Ten 1.0 + * + * @return string "Continue Reading" link. + */ + function twentyten_continue_reading_link() { + return ' <a href="' . get_permalink() . '">' . __( 'Continue reading <span class="meta-nav">→</span>', 'twentyten' ) . '</a>'; + } endif; /** @@ -346,30 +354,31 @@ function twentyten_remove_gallery_css( $css ) { return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css ); } // Backwards compatibility with WordPress 3.0. -if ( version_compare( $GLOBALS['wp_version'], '3.1', '<' ) ) +if ( version_compare( $GLOBALS['wp_version'], '3.1', '<' ) ) { add_filter( 'gallery_style', 'twentyten_remove_gallery_css' ); +} if ( ! function_exists( 'twentyten_comment' ) ) : -/** - * Template for comments and pingbacks. - * - * To override this walker in a child theme without modifying the comments template - * simply create your own twentyten_comment(), and that function will be used instead. - * - * Used as a callback by wp_list_comments() for displaying the comments. - * - * @since Twenty Ten 1.0 - * - * @param object $comment The comment object. - * @param array $args An array of arguments. @see get_comment_reply_link() - * @param int $depth The depth of the comment. - */ -function twentyten_comment( $comment, $args, $depth ) { - $GLOBALS['comment'] = $comment; - switch ( $comment->comment_type ) : - case '' : - ?> - <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>"> + /** + * Template for comments and pingbacks. + * + * To override this walker in a child theme without modifying the comments template + * simply create your own twentyten_comment(), and that function will be used instead. + * + * Used as a callback by wp_list_comments() for displaying the comments. + * + * @since Twenty Ten 1.0 + * + * @param object $comment The comment object. + * @param array $args An array of arguments. @see get_comment_reply_link() + * @param int $depth The depth of the comment. + */ + function twentyten_comment( $comment, $args, $depth ) { + $GLOBALS['comment'] = $comment; + switch ( $comment->comment_type ) : + case '': + ?> + <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>"> <div id="comment-<?php comment_ID(); ?>"> <div class="comment-author vcard"> <?php echo get_avatar( $comment, 40 ); ?> @@ -383,28 +392,41 @@ function twentyten_comment( $comment, $args, $depth ) { <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>"> <?php /* translators: 1: date, 2: time */ - printf( __( '%1$s at %2$s', 'twentyten' ), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' ); + printf( __( '%1$s at %2$s', 'twentyten' ), get_comment_date(), get_comment_time() ); + ?> + </a> + <?php + edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' ); ?> - </div><!-- .comment-meta .commentmetadata --> + </div><!-- .comment-meta .commentmetadata --> - <div class="comment-body"><?php comment_text(); ?></div> + <div class="comment-body"><?php comment_text(); ?></div> - <div class="reply"> - <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?> - </div><!-- .reply --> - </div><!-- #comment-## --> + <div class="reply"> + <?php + comment_reply_link( + array_merge( + $args, array( + 'depth' => $depth, + 'max_depth' => $args['max_depth'], + ) + ) + ); +?> + </div><!-- .reply --> + </div><!-- #comment-## --> - <?php - break; - case 'pingback' : - case 'trackback' : - ?> - <li class="post pingback"> + <?php + break; + case 'pingback': + case 'trackback': + ?> + <li class="post pingback"> <p><?php _e( 'Pingback:', 'twentyten' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' ); ?></p> <?php - break; - endswitch; -} + break; + endswitch; + } endif; /** @@ -419,70 +441,82 @@ endif; */ function twentyten_widgets_init() { // Area 1, located at the top of the sidebar. - register_sidebar( array( - 'name' => __( 'Primary Widget Area', 'twentyten' ), - 'id' => 'primary-widget-area', - 'description' => __( 'Add widgets here to appear in your sidebar.', 'twentyten' ), - 'before_widget' => '<li id="%1$s" class="widget-container %2$s">', - 'after_widget' => '</li>', - 'before_title' => '<h3 class="widget-title">', - 'after_title' => '</h3>', - ) ); + register_sidebar( + array( + 'name' => __( 'Primary Widget Area', 'twentyten' ), + 'id' => 'primary-widget-area', + 'description' => __( 'Add widgets here to appear in your sidebar.', 'twentyten' ), + 'before_widget' => '<li id="%1$s" class="widget-container %2$s">', + 'after_widget' => '</li>', + 'before_title' => '<h3 class="widget-title">', + 'after_title' => '</h3>', + ) + ); // Area 2, located below the Primary Widget Area in the sidebar. Empty by default. - register_sidebar( array( - 'name' => __( 'Secondary Widget Area', 'twentyten' ), - 'id' => 'secondary-widget-area', - 'description' => __( 'An optional secondary widget area, displays below the primary widget area in your sidebar.', 'twentyten' ), - 'before_widget' => '<li id="%1$s" class="widget-container %2$s">', - 'after_widget' => '</li>', - 'before_title' => '<h3 class="widget-title">', - 'after_title' => '</h3>', - ) ); + register_sidebar( + array( + 'name' => __( 'Secondary Widget Area', 'twentyten' ), + 'id' => 'secondary-widget-area', + 'description' => __( 'An optional secondary widget area, displays below the primary widget area in your sidebar.', 'twentyten' ), + 'before_widget' => '<li id="%1$s" class="widget-container %2$s">', + 'after_widget' => '</li>', + 'before_title' => '<h3 class="widget-title">', + 'after_title' => '</h3>', + ) + ); // Area 3, located in the footer. Empty by default. - register_sidebar( array( - 'name' => __( 'First Footer Widget Area', 'twentyten' ), - 'id' => 'first-footer-widget-area', - 'description' => __( 'An optional widget area for your site footer.', 'twentyten' ), - 'before_widget' => '<li id="%1$s" class="widget-container %2$s">', - 'after_widget' => '</li>', - 'before_title' => '<h3 class="widget-title">', - 'after_title' => '</h3>', - ) ); + register_sidebar( + array( + 'name' => __( 'First Footer Widget Area', 'twentyten' ), + 'id' => 'first-footer-widget-area', + 'description' => __( 'An optional widget area for your site footer.', 'twentyten' ), + 'before_widget' => '<li id="%1$s" class="widget-container %2$s">', + 'after_widget' => '</li>', + 'before_title' => '<h3 class="widget-title">', + 'after_title' => '</h3>', + ) + ); // Area 4, located in the footer. Empty by default. - register_sidebar( array( - 'name' => __( 'Second Footer Widget Area', 'twentyten' ), - 'id' => 'second-footer-widget-area', - 'description' => __( 'An optional widget area for your site footer.', 'twentyten' ), - 'before_widget' => '<li id="%1$s" class="widget-container %2$s">', - 'after_widget' => '</li>', - 'before_title' => '<h3 class="widget-title">', - 'after_title' => '</h3>', - ) ); + register_sidebar( + array( + 'name' => __( 'Second Footer Widget Area', 'twentyten' ), + 'id' => 'second-footer-widget-area', + 'description' => __( 'An optional widget area for your site footer.', 'twentyten' ), + 'before_widget' => '<li id="%1$s" class="widget-container %2$s">', + 'after_widget' => '</li>', + 'before_title' => '<h3 class="widget-title">', + 'after_title' => '</h3>', + ) + ); // Area 5, located in the footer. Empty by default. - register_sidebar( array( - 'name' => __( 'Third Footer Widget Area', 'twentyten' ), - 'id' => 'third-footer-widget-area', - 'description' => __( 'An optional widget area for your site footer.', 'twentyten' ), - 'before_widget' => '<li id="%1$s" class="widget-container %2$s">', - 'after_widget' => '</li>', - 'before_title' => '<h3 class="widget-title">', - 'after_title' => '</h3>', - ) ); + register_sidebar( + array( + 'name' => __( 'Third Footer Widget Area', 'twentyten' ), + 'id' => 'third-footer-widget-area', + 'description' => __( 'An optional widget area for your site footer.', 'twentyten' ), + 'before_widget' => '<li id="%1$s" class="widget-container %2$s">', + 'after_widget' => '</li>', + 'before_title' => '<h3 class="widget-title">', + 'after_title' => '</h3>', + ) + ); // Area 6, located in the footer. Empty by default. - register_sidebar( array( - 'name' => __( 'Fourth Footer Widget Area', 'twentyten' ), - 'id' => 'fourth-footer-widget-area', - 'description' => __( 'An optional widget area for your site footer.', 'twentyten' ), - 'before_widget' => '<li id="%1$s" class="widget-container %2$s">', - 'after_widget' => '</li>', - 'before_title' => '<h3 class="widget-title">', - 'after_title' => '</h3>', - ) ); + register_sidebar( + array( + 'name' => __( 'Fourth Footer Widget Area', 'twentyten' ), + 'id' => 'fourth-footer-widget-area', + 'description' => __( 'An optional widget area for your site footer.', 'twentyten' ), + 'before_widget' => '<li id="%1$s" class="widget-container %2$s">', + 'after_widget' => '</li>', + 'before_title' => '<h3 class="widget-title">', + 'after_title' => '</h3>', + ) + ); } /** Register sidebars by running twentyten_widgets_init() on the widgets_init hook. */ add_action( 'widgets_init', 'twentyten_widgets_init' ); @@ -505,53 +539,56 @@ function twentyten_remove_recent_comments_style() { add_action( 'widgets_init', 'twentyten_remove_recent_comments_style' ); if ( ! function_exists( 'twentyten_posted_on' ) ) : -/** - * Print HTML with meta information for the current post-date/time and author. - * - * @since Twenty Ten 1.0 - */ -function twentyten_posted_on() { - printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ), - 'meta-prep meta-prep-author', - sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>', - get_permalink(), - esc_attr( get_the_time() ), - get_the_date() - ), - sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>', - get_author_posts_url( get_the_author_meta( 'ID' ) ), - esc_attr( sprintf( __( 'View all posts by %s', 'twentyten' ), get_the_author() ) ), - get_the_author() - ) - ); -} + /** + * Print HTML with meta information for the current post-date/time and author. + * + * @since Twenty Ten 1.0 + */ + function twentyten_posted_on() { + printf( + __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ), + 'meta-prep meta-prep-author', + sprintf( + '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>', + get_permalink(), + esc_attr( get_the_time() ), + get_the_date() + ), + sprintf( + '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>', + get_author_posts_url( get_the_author_meta( 'ID' ) ), + esc_attr( sprintf( __( 'View all posts by %s', 'twentyten' ), get_the_author() ) ), + get_the_author() + ) + ); + } endif; if ( ! function_exists( 'twentyten_posted_in' ) ) : -/** - * Print HTML with meta information for the current post (category, tags and permalink). - * - * @since Twenty Ten 1.0 - */ -function twentyten_posted_in() { - // Retrieves tag list of current post, separated by commas. - $tag_list = get_the_tag_list( '', ', ' ); - if ( $tag_list && ! is_wp_error( $tag_list ) ) { - $posted_in = __( 'This entry was posted in %1$s and tagged %2$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' ); - } elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) { - $posted_in = __( 'This entry was posted in %1$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' ); - } else { - $posted_in = __( 'Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' ); + /** + * Print HTML with meta information for the current post (category, tags and permalink). + * + * @since Twenty Ten 1.0 + */ + function twentyten_posted_in() { + // Retrieves tag list of current post, separated by commas. + $tag_list = get_the_tag_list( '', ', ' ); + if ( $tag_list && ! is_wp_error( $tag_list ) ) { + $posted_in = __( 'This entry was posted in %1$s and tagged %2$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' ); + } elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) { + $posted_in = __( 'This entry was posted in %1$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' ); + } else { + $posted_in = __( 'Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' ); + } + // Prints the string, replacing the placeholders. + printf( + $posted_in, + get_the_category_list( ', ' ), + $tag_list, + get_permalink(), + the_title_attribute( 'echo=0' ) + ); } - // Prints the string, replacing the placeholders. - printf( - $posted_in, - get_the_category_list( ', ' ), - $tag_list, - get_permalink(), - the_title_attribute( 'echo=0' ) - ); -} endif; /** @@ -569,26 +606,30 @@ function twentyten_get_gallery_images() { if ( function_exists( 'get_post_galleries' ) ) { $galleries = get_post_galleries( get_the_ID(), false ); - if ( isset( $galleries[0]['ids'] ) ) + if ( isset( $galleries[0]['ids'] ) ) { $images = explode( ',', $galleries[0]['ids'] ); + } } else { $pattern = get_shortcode_regex(); preg_match( "/$pattern/s", get_the_content(), $match ); $atts = shortcode_parse_atts( $match[3] ); - if ( isset( $atts['ids'] ) ) + if ( isset( $atts['ids'] ) ) { $images = explode( ',', $atts['ids'] ); + } } if ( ! $images ) { - $images = get_posts( array( - 'fields' => 'ids', - 'numberposts' => 999, - 'order' => 'ASC', - 'orderby' => 'menu_order', - 'post_mime_type' => 'image', - 'post_parent' => get_the_ID(), - 'post_type' => 'attachment', - ) ); + $images = get_posts( + array( + 'fields' => 'ids', + 'numberposts' => 999, + 'order' => 'ASC', + 'orderby' => 'menu_order', + 'post_mime_type' => 'image', + 'post_parent' => get_the_ID(), + 'post_type' => 'attachment', + ) + ); } return $images; diff --git a/wp-content/themes/twentyten/header.php b/wp-content/themes/twentyten/header.php index f1a70982e6..6c2ee4c46b 100644 --- a/wp-content/themes/twentyten/header.php +++ b/wp-content/themes/twentyten/header.php @@ -12,7 +12,8 @@ <html <?php language_attributes(); ?>> <head> <meta charset="<?php bloginfo( 'charset' ); ?>" /> -<title><?php +<title> +<?php /* * Print the <title> tag based on what is being viewed. */ @@ -25,14 +26,17 @@ // Add the blog description for the home/front page. $site_description = get_bloginfo( 'description', 'display' ); - if ( $site_description && ( is_home() || is_front_page() ) ) - echo " | $site_description"; +if ( $site_description && ( is_home() || is_front_page() ) ) { + echo " | $site_description"; +} // Add a page number if necessary: - if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) - echo esc_html( ' | ' . sprintf( __( 'Page %s', 'twentyten' ), max( $paged, $page ) ) ); +if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) { + echo esc_html( ' | ' . sprintf( __( 'Page %s', 'twentyten' ), max( $paged, $page ) ) ); +} - ?> + ?> + @@ -41,8 +45,9 @@ * We add some JavaScript to pages with the comment form * to support sites with threaded comments (when in use). */ - if ( is_singular() && get_option( 'thread_comments' ) ) - wp_enqueue_script( 'comment-reply' ); +if ( is_singular() && get_option( 'thread_comments' ) ) { + wp_enqueue_script( 'comment-reply' ); +} /* * Always have wp_head() just before the closing @@ -69,23 +74,23 @@ ID ) && ( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ) ) && $image[1] >= $header_image_width ) : - // Houston, we have a new header image! - echo get_the_post_thumbnail( $post->ID ); + // Houston, we have a new header image! + echo get_the_post_thumbnail( $post->ID ); elseif ( get_header_image() ) : // Compatibility with versions of WordPress prior to 3.4. if ( function_exists( 'get_custom_header' ) ) { @@ -104,7 +109,14 @@ - 'menu-header', 'theme_location' => 'primary' ) ); ?> + 'menu-header', + 'theme_location' => 'primary', + ) + ); +?> diff --git a/wp-content/themes/twentyten/loop-attachment.php b/wp-content/themes/twentyten/loop-attachment.php index a2dfae6e24..04da9f48d4 100644 --- a/wp-content/themes/twentyten/loop-attachment.php +++ b/wp-content/themes/twentyten/loop-attachment.php @@ -15,34 +15,44 @@ */ ?> - + post_parent ) ) : ?> -

    ← %s', 'twentyten' ), get_the_title( $post->post_parent ) ); - ?>

    +

    + ← %s', 'twentyten' ), get_the_title( $post->post_parent ) ); + ?> +

    -
    > +
    >

    + ?> + | ', '' ); ?> +
    -
    +
    - $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) ) ); - foreach ( $attachments as $k => $attachment ) { - if ( $attachment->ID == $post->ID ) - break; - } + $post->post_parent, + 'post_status' => 'inherit', + 'post_type' => 'attachment', + 'post_mime_type' => 'image', + 'order' => 'ASC', + 'orderby' => 'menu_order ID', + ) + ) + ); + foreach ( $attachments as $k => $attachment ) { + if ( $attachment->ID == $post->ID ) { + break; + } + } - // If there is more than 1 image attachment in a gallery - if ( count( $attachments ) > 1 ) { - $k++; - if ( isset( $attachments[ $k ] ) ) - // get the URL of the next image attachment - $next_attachment_url = get_attachment_link( $attachments[ $k ]->ID ); - else - // or get the URL of the first image attachment - $next_attachment_url = get_attachment_link( $attachments[0]->ID ); - } else { - // or, if there's only 1 image attachment, get the URL of the image - $next_attachment_url = wp_get_attachment_url(); - } -?> -

    ID, array( $attachment_width, $attachment_height ) ); // filterable image width with, essentially, no limit for image height. - ?>

    + // If there is more than 1 image attachment in a gallery + if ( count( $attachments ) > 1 ) { + $k++; + if ( isset( $attachments[ $k ] ) ) { + // get the URL of the next image attachment + $next_attachment_url = get_attachment_link( $attachments[ $k ]->ID ); + } else { // or get the URL of the first image attachment + $next_attachment_url = get_attachment_link( $attachments[0]->ID ); + } + } else { + // or, if there's only 1 image attachment, get the URL of the image + $next_attachment_url = wp_get_attachment_url(); + } + ?> +

    + ID, array( $attachment_width, $attachment_height ) ); // filterable image width with, essentially, no limit for image height. + ?> +

    - -
    post_excerpt ) ) the_excerpt(); ?>
    +
    + post_excerpt ) ) { + the_excerpt();} +?> +
    -→', 'twentyten' ) ); ?> - '' ) ); ?> + →', 'twentyten' ) ); ?> + '', + ) + ); + ?>
    @@ -129,4 +168,5 @@ - + diff --git a/wp-content/themes/twentyten/loop-page.php b/wp-content/themes/twentyten/loop-page.php index 989881f74a..f522cff95f 100644 --- a/wp-content/themes/twentyten/loop-page.php +++ b/wp-content/themes/twentyten/loop-page.php @@ -15,7 +15,11 @@ */ ?> - +
    > @@ -26,11 +30,19 @@
    - '' ) ); ?> + '', + ) + ); + ?> ', '' ); ?>
    - + diff --git a/wp-content/themes/twentyten/loop-single.php b/wp-content/themes/twentyten/loop-single.php index 68dd08f6f8..b9a791a628 100644 --- a/wp-content/themes/twentyten/loop-single.php +++ b/wp-content/themes/twentyten/loop-single.php @@ -15,7 +15,11 @@ */ ?> - + +
    + -
    - - ', '' ); ?> -
    -
    +
    + + ', '' ); ?> +
    +
    - + - + - + diff --git a/wp-content/themes/twentyten/loop.php b/wp-content/themes/twentyten/loop.php index 9f3088544f..220ba7b0ec 100644 --- a/wp-content/themes/twentyten/loop.php +++ b/wp-content/themes/twentyten/loop.php @@ -55,7 +55,10 @@ * Without further ado, the loop: */ ?> - + @@ -73,17 +76,22 @@ - -

    %2$s photo.', 'This gallery contains %2$s photos.', $total_images, 'twentyten' ), - 'href="' . esc_url( get_permalink() ) . '" title="' . esc_attr( sprintf( __( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ) ) . '" rel="bookmark"', - number_format_i18n( $total_images ) - ); ?>

    + +

    + %2$s photo.', 'This gallery contains %2$s photos.', $total_images, 'twentyten' ), + 'href="' . esc_url( get_permalink() ) . '" title="' . esc_attr( sprintf( __( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ) ) . '" rel="bookmark"', + number_format_i18n( $total_images ) + ); + ?> +

    @@ -104,7 +112,7 @@ - ID ) ) || in_category( _x( 'asides', 'asides category slug', 'twentyten' ) ) ) : ?> + ID ) ) || in_category( _x( 'asides', 'asides category slug', 'twentyten' ) ) ) : ?>
    > @@ -142,7 +150,14 @@
    →', 'twentyten' ) ); ?> - '' ) ); ?> + '', + ) + ); +?>
    @@ -155,12 +170,12 @@ - - Tagged %2$s', 'twentyten' ), 'entry-utility-prep entry-utility-prep-tag-links', $tags_list ); ?> - - | + + Tagged %2$s', 'twentyten' ), 'entry-utility-prep entry-utility-prep-tag-links', $tags_list ); ?> + + | | ', '' ); ?> @@ -174,7 +189,7 @@ -max_num_pages > 1 ) : ?> +max_num_pages > 1 ) : ?> \ No newline at end of file +
    diff --git a/wp-content/themes/twentythirteen/author.php b/wp-content/themes/twentythirteen/author.php index c7b5d87ada..efdd005db7 100644 --- a/wp-content/themes/twentythirteen/author.php +++ b/wp-content/themes/twentythirteen/author.php @@ -45,7 +45,10 @@ get_header(); ?> - + diff --git a/wp-content/themes/twentythirteen/category.php b/wp-content/themes/twentythirteen/category.php index f82e0abccb..a219d544aa 100644 --- a/wp-content/themes/twentythirteen/category.php +++ b/wp-content/themes/twentythirteen/category.php @@ -24,7 +24,10 @@ get_header(); ?> - + diff --git a/wp-content/themes/twentythirteen/comments.php b/wp-content/themes/twentythirteen/comments.php index 3d1aff46bd..9b92c68f8b 100644 --- a/wp-content/themes/twentythirteen/comments.php +++ b/wp-content/themes/twentythirteen/comments.php @@ -13,8 +13,9 @@ * If the current post is protected by a password and the visitor has not yet * entered the password we will return early without loading the comments. */ -if ( post_password_required() ) +if ( post_password_required() ) { return; +} ?>
    @@ -22,38 +23,42 @@ if ( post_password_required() )

    ' . get_the_title() . '' ); + printf( + _nx( 'One thought on “%2$s”', '%1$s thoughts on “%2$s”', get_comments_number(), 'comments title', 'twentythirteen' ), + number_format_i18n( get_comments_number() ), '' . get_the_title() . '' + ); ?>

      'ol', - 'short_ping' => true, - 'avatar_size' => 74, - ) ); + wp_list_comments( + array( + 'style' => 'ol', + 'short_ping' => true, + 'avatar_size' => 74, + ) + ); ?>
    1 && get_option( 'page_comments' ) ) : + if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : ?> -

    +

    -
    \ No newline at end of file + diff --git a/wp-content/themes/twentythirteen/content-aside.php b/wp-content/themes/twentythirteen/content-aside.php index fbc01e618d..bbec8c9b94 100644 --- a/wp-content/themes/twentythirteen/content-aside.php +++ b/wp-content/themes/twentythirteen/content-aside.php @@ -12,12 +12,21 @@
    →', 'twentythirteen' ), - the_title( '', '', false ) - ) ); + the_content( + sprintf( + __( 'Continue reading %s ', 'twentythirteen' ), + the_title( '', '', false ) + ) + ); - wp_link_pages( array( 'before' => '', 'link_before' => '', 'link_after' => '' ) ); + wp_link_pages( + array( + 'before' => '', + 'link_before' => '', + 'link_after' => '', + ) + ); ?>
    diff --git a/wp-content/themes/twentythirteen/content-audio.php b/wp-content/themes/twentythirteen/content-audio.php index 73a0d692b5..728a68a8f7 100644 --- a/wp-content/themes/twentythirteen/content-audio.php +++ b/wp-content/themes/twentythirteen/content-audio.php @@ -23,12 +23,21 @@
    →', 'twentythirteen' ), - the_title( '', '', false ) - ) ); + the_content( + sprintf( + __( 'Continue reading %s ', 'twentythirteen' ), + the_title( '', '', false ) + ) + ); - wp_link_pages( array( 'before' => '', 'link_before' => '', 'link_after' => '' ) ); + wp_link_pages( + array( + 'before' => '', + 'link_before' => '', + 'link_after' => '', + ) + ); ?>
    diff --git a/wp-content/themes/twentythirteen/content-chat.php b/wp-content/themes/twentythirteen/content-chat.php index 6a40b89326..92c703c8cd 100644 --- a/wp-content/themes/twentythirteen/content-chat.php +++ b/wp-content/themes/twentythirteen/content-chat.php @@ -22,12 +22,21 @@
    →', 'twentythirteen' ), - the_title( '', '', false ) - ) ); + the_content( + sprintf( + __( 'Continue reading %s ', 'twentythirteen' ), + the_title( '', '', false ) + ) + ); - wp_link_pages( array( 'before' => '', 'link_before' => '', 'link_after' => '' ) ); + wp_link_pages( + array( + 'before' => '', + 'link_before' => '', + 'link_after' => '', + ) + ); ?>
    diff --git a/wp-content/themes/twentythirteen/content-gallery.php b/wp-content/themes/twentythirteen/content-gallery.php index a43647f73e..705cb2da96 100644 --- a/wp-content/themes/twentythirteen/content-gallery.php +++ b/wp-content/themes/twentythirteen/content-gallery.php @@ -23,12 +23,21 @@ →', 'twentythirteen' ), - the_title( '', '', false ) - ) ); + the_content( + sprintf( + __( 'Continue reading %s ', 'twentythirteen' ), + the_title( '', '', false ) + ) + ); - wp_link_pages( array( 'before' => '', 'link_before' => '', 'link_after' => '' ) ); + wp_link_pages( + array( + 'before' => '', + 'link_before' => '', + 'link_after' => '', + ) + ); ?> diff --git a/wp-content/themes/twentythirteen/content-image.php b/wp-content/themes/twentythirteen/content-image.php index 01e2f34793..866e63f89b 100644 --- a/wp-content/themes/twentythirteen/content-image.php +++ b/wp-content/themes/twentythirteen/content-image.php @@ -22,12 +22,21 @@
    →', 'twentythirteen' ), - the_title( '', '', false ) - ) ); + the_content( + sprintf( + __( 'Continue reading %s ', 'twentythirteen' ), + the_title( '', '', false ) + ) + ); - wp_link_pages( array( 'before' => '', 'link_before' => '', 'link_after' => '' ) ); + wp_link_pages( + array( + 'before' => '', + 'link_before' => '', + 'link_after' => '', + ) + ); ?>
    diff --git a/wp-content/themes/twentythirteen/content-link.php b/wp-content/themes/twentythirteen/content-link.php index cc02d8240b..5fdbb8f9de 100644 --- a/wp-content/themes/twentythirteen/content-link.php +++ b/wp-content/themes/twentythirteen/content-link.php @@ -23,12 +23,21 @@
    →', 'twentythirteen' ), - the_title( '', '', false ) - ) ); + the_content( + sprintf( + __( 'Continue reading %s ', 'twentythirteen' ), + the_title( '', '', false ) + ) + ); - wp_link_pages( array( 'before' => '', 'link_before' => '', 'link_after' => '' ) ); + wp_link_pages( + array( + 'before' => '', + 'link_before' => '', + 'link_after' => '', + ) + ); ?>
    diff --git a/wp-content/themes/twentythirteen/content-quote.php b/wp-content/themes/twentythirteen/content-quote.php index ac4de67293..83562bc5ad 100644 --- a/wp-content/themes/twentythirteen/content-quote.php +++ b/wp-content/themes/twentythirteen/content-quote.php @@ -12,12 +12,21 @@
    →', 'twentythirteen' ), - the_title( '', '', false ) - ) ); + the_content( + sprintf( + __( 'Continue reading %s ', 'twentythirteen' ), + the_title( '', '', false ) + ) + ); - wp_link_pages( array( 'before' => '', 'link_before' => '', 'link_after' => '' ) ); + wp_link_pages( + array( + 'before' => '', + 'link_before' => '', + 'link_after' => '', + ) + ); ?>
    diff --git a/wp-content/themes/twentythirteen/content-status.php b/wp-content/themes/twentythirteen/content-status.php index e0e51f30ea..f37539660c 100644 --- a/wp-content/themes/twentythirteen/content-status.php +++ b/wp-content/themes/twentythirteen/content-status.php @@ -12,12 +12,21 @@
    →', 'twentythirteen' ), - the_title( '', '', false ) - ) ); + the_content( + sprintf( + __( 'Continue reading %s ', 'twentythirteen' ), + the_title( '', '', false ) + ) + ); - wp_link_pages( array( 'before' => '', 'link_before' => '', 'link_after' => '' ) ); + wp_link_pages( + array( + 'before' => '', + 'link_before' => '', + 'link_after' => '', + ) + ); ?>
    diff --git a/wp-content/themes/twentythirteen/content-video.php b/wp-content/themes/twentythirteen/content-video.php index 8118a080fc..aa81176329 100644 --- a/wp-content/themes/twentythirteen/content-video.php +++ b/wp-content/themes/twentythirteen/content-video.php @@ -22,12 +22,21 @@
    →', 'twentythirteen' ), - the_title( '', '', false ) - ) ); + the_content( + sprintf( + __( 'Continue reading %s ', 'twentythirteen' ), + the_title( '', '', false ) + ) + ); - wp_link_pages( array( 'before' => '', 'link_before' => '', 'link_after' => '' ) ); + wp_link_pages( + array( + 'before' => '', + 'link_before' => '', + 'link_after' => '', + ) + ); ?>
    diff --git a/wp-content/themes/twentythirteen/content.php b/wp-content/themes/twentythirteen/content.php index 98b6c31955..aace9cdaba 100644 --- a/wp-content/themes/twentythirteen/content.php +++ b/wp-content/themes/twentythirteen/content.php @@ -40,12 +40,21 @@
    →', 'twentythirteen' ), - the_title( '', '', false ) - ) ); + the_content( + sprintf( + __( 'Continue reading %s ', 'twentythirteen' ), + the_title( '', '', false ) + ) + ); - wp_link_pages( array( 'before' => '', 'link_before' => '', 'link_after' => '' ) ); + wp_link_pages( + array( + 'before' => '', + 'link_before' => '', + 'link_after' => '', + ) + ); ?>
    diff --git a/wp-content/themes/twentythirteen/footer.php b/wp-content/themes/twentythirteen/footer.php index 40fbc34bc1..37eef9b332 100644 --- a/wp-content/themes/twentythirteen/footer.php +++ b/wp-content/themes/twentythirteen/footer.php @@ -23,4 +23,4 @@ - \ No newline at end of file + diff --git a/wp-content/themes/twentythirteen/functions.php b/wp-content/themes/twentythirteen/functions.php index 312dc63d75..68a3871317 100644 --- a/wp-content/themes/twentythirteen/functions.php +++ b/wp-content/themes/twentythirteen/functions.php @@ -28,8 +28,9 @@ * * @see twentythirteen_content_width() for template-specific adjustments. */ -if ( ! isset( $content_width ) ) +if ( ! isset( $content_width ) ) { $content_width = 604; +} /** * Add support for a custom header image. @@ -39,8 +40,9 @@ require get_template_directory() . '/inc/custom-header.php'; /** * Twenty Thirteen only works in WordPress 3.6 or later. */ -if ( version_compare( $GLOBALS['wp_version'], '3.6-alpha', '<' ) ) +if ( version_compare( $GLOBALS['wp_version'], '3.6-alpha', '<' ) ) { require get_template_directory() . '/inc/back-compat.php'; +} /** * Twenty Thirteen setup. @@ -81,17 +83,33 @@ function twentythirteen_setup() { * Switches default core markup for search form, comment form, * and comments to output valid HTML5. */ - add_theme_support( 'html5', array( - 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption' - ) ); + add_theme_support( + 'html5', array( + 'search-form', + 'comment-form', + 'comment-list', + 'gallery', + 'caption', + ) + ); /* * This theme supports all available post formats by default. * See https://codex.wordpress.org/Post_Formats */ - add_theme_support( 'post-formats', array( - 'aside', 'audio', 'chat', 'gallery', 'image', 'link', 'quote', 'status', 'video' - ) ); + add_theme_support( + 'post-formats', array( + 'aside', + 'audio', + 'chat', + 'gallery', + 'image', + 'link', + 'quote', + 'status', + 'video', + ) + ); // This theme uses wp_nav_menu() in one location. register_nav_menu( 'primary', __( 'Navigation Menu', 'twentythirteen' ) ); @@ -139,17 +157,19 @@ function twentythirteen_fonts_url() { if ( 'off' !== $source_sans_pro || 'off' !== $bitter ) { $font_families = array(); - if ( 'off' !== $source_sans_pro ) + if ( 'off' !== $source_sans_pro ) { $font_families[] = 'Source Sans Pro:300,400,700,300italic,400italic,700italic'; + } - if ( 'off' !== $bitter ) + if ( 'off' !== $bitter ) { $font_families[] = 'Bitter:400,700'; + } $query_args = array( 'family' => urlencode( implode( '|', $font_families ) ), 'subset' => urlencode( 'latin,latin-ext' ), ); - $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' ); + $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' ); } return $fonts_url; @@ -165,12 +185,14 @@ function twentythirteen_scripts_styles() { * Adds JavaScript to pages with the comment form to support * sites with threaded comments (when in use). */ - if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) + if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { wp_enqueue_script( 'comment-reply' ); + } // Adds Masonry to handle vertical alignment of footer widgets. - if ( is_active_sidebar( 'sidebar-1' ) ) + if ( is_active_sidebar( 'sidebar-1' ) ) { wp_enqueue_script( 'jquery-masonry' ); + } // Loads JavaScript file with functionality specific to Twenty Thirteen. wp_enqueue_script( 'twentythirteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20160717', true ); @@ -230,20 +252,23 @@ add_filter( 'wp_resource_hints', 'twentythirteen_resource_hints', 10, 2 ); function twentythirteen_wp_title( $title, $sep ) { global $paged, $page; - if ( is_feed() ) + if ( is_feed() ) { return $title; + } // Add the site name. $title .= get_bloginfo( 'name', 'display' ); // Add the site description for the home/front page. $site_description = get_bloginfo( 'description', 'display' ); - if ( $site_description && ( is_home() || is_front_page() ) ) + if ( $site_description && ( is_home() || is_front_page() ) ) { $title = "$title $sep $site_description"; + } // Add a page number if necessary. - if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) + if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) { $title = "$title $sep " . sprintf( __( 'Page %s', 'twentythirteen' ), max( $paged, $page ) ); + } return $title; } @@ -255,42 +280,47 @@ add_filter( 'wp_title', 'twentythirteen_wp_title', 10, 2 ); * @since Twenty Thirteen 1.0 */ function twentythirteen_widgets_init() { - register_sidebar( array( - 'name' => __( 'Main Widget Area', 'twentythirteen' ), - 'id' => 'sidebar-1', - 'description' => __( 'Appears in the footer section of the site.', 'twentythirteen' ), - 'before_widget' => '', - 'before_title' => '

    ', - 'after_title' => '

    ', - ) ); + register_sidebar( + array( + 'name' => __( 'Main Widget Area', 'twentythirteen' ), + 'id' => 'sidebar-1', + 'description' => __( 'Appears in the footer section of the site.', 'twentythirteen' ), + 'before_widget' => '', + 'before_title' => '

    ', + 'after_title' => '

    ', + ) + ); - register_sidebar( array( - 'name' => __( 'Secondary Widget Area', 'twentythirteen' ), - 'id' => 'sidebar-2', - 'description' => __( 'Appears on posts and pages in the sidebar.', 'twentythirteen' ), - 'before_widget' => '', - 'before_title' => '

    ', - 'after_title' => '

    ', - ) ); + register_sidebar( + array( + 'name' => __( 'Secondary Widget Area', 'twentythirteen' ), + 'id' => 'sidebar-2', + 'description' => __( 'Appears on posts and pages in the sidebar.', 'twentythirteen' ), + 'before_widget' => '', + 'before_title' => '

    ', + 'after_title' => '

    ', + ) + ); } add_action( 'widgets_init', 'twentythirteen_widgets_init' ); if ( ! function_exists( 'twentythirteen_paging_nav' ) ) : -/** - * Display navigation to next/previous set of posts when applicable. - * - * @since Twenty Thirteen 1.0 - */ -function twentythirteen_paging_nav() { - global $wp_query; + /** + * Display navigation to next/previous set of posts when applicable. + * + * @since Twenty Thirteen 1.0 + */ + function twentythirteen_paging_nav() { + global $wp_query; - // Don't print empty markup if there's only one page. - if ( $wp_query->max_num_pages < 2 ) - return; - ?> -

    + ' . $delete_user->user_login . '' - ); ?>

    + ); + ?> +

    $details ) { - $blog_users = get_users( array( 'blog_id' => $details->userblog_id, 'fields' => array( 'ID', 'user_login' ) ) ); - if ( is_array( $blog_users ) && !empty( $blog_users ) ) { - $user_site = "{$details->blogname}"; - $user_dropdown = ''; + $blog_users = get_users( + array( + 'blog_id' => $details->userblog_id, + 'fields' => array( 'ID', 'user_login' ), + ) + ); + if ( is_array( $blog_users ) && ! empty( $blog_users ) ) { + $user_site = "{$details->blogname}"; + $user_dropdown = ''; $user_dropdown .= " +
  • -
  • @@ -846,13 +1067,15 @@ function confirm_delete_users( $users ) { /** This action is documented in wp-admin/users.php */ do_action( 'delete_user_form', $current_user, $allusers ); - if ( 1 == count( $users ) ) : ?> + if ( 1 == count( $users ) ) : + ?>

    - array( 'label' => __( 'Info' ), 'url' => 'site-info.php', 'cap' => 'manage_sites' ), - 'site-users' => array( 'label' => __( 'Users' ), 'url' => 'site-users.php', 'cap' => 'manage_sites' ), - 'site-themes' => array( 'label' => __( 'Themes' ), 'url' => 'site-themes.php', 'cap' => 'manage_sites' ), - 'site-settings' => array( 'label' => __( 'Settings' ), 'url' => 'site-settings.php', 'cap' => 'manage_sites' ) - ) ); + $links = apply_filters( + 'network_edit_site_nav_links', array( + 'site-info' => array( + 'label' => __( 'Info' ), + 'url' => 'site-info.php', + 'cap' => 'manage_sites', + ), + 'site-users' => array( + 'label' => __( 'Users' ), + 'url' => 'site-users.php', + 'cap' => 'manage_sites', + ), + 'site-themes' => array( + 'label' => __( 'Themes' ), + 'url' => 'site-themes.php', + 'cap' => 'manage_sites', + ), + 'site-settings' => array( + 'label' => __( 'Settings' ), + 'url' => 'site-settings.php', + 'cap' => 'manage_sites', + ), + ) + ); // Parse arguments - $r = wp_parse_args( $args, array( - 'blog_id' => isset( $_GET['blog_id'] ) ? (int) $_GET['blog_id'] : 0, - 'links' => $links, - 'selected' => 'site-info', - ) ); + $r = wp_parse_args( + $args, array( + 'blog_id' => isset( $_GET['blog_id'] ) ? (int) $_GET['blog_id'] : 0, + 'links' => $links, + 'selected' => 'site-info', + ) + ); // Setup the links array $screen_links = array(); @@ -974,13 +1217,13 @@ function network_edit_site_nav( $args = array() ) { function get_site_screen_help_tab_args() { return array( 'id' => 'overview', - 'title' => __('Overview'), + 'title' => __( 'Overview' ), 'content' => - '

    ' . __('The menu is for editing information specific to individual sites, particularly if the admin area of a site is unavailable.') . '

    ' . - '

    ' . __('Info — The site URL is rarely edited as this can cause the site to not work properly. The Registered date and Last Updated date are displayed. Network admins can mark a site as archived, spam, deleted and mature, to remove from public listings or disable.') . '

    ' . - '

    ' . __('Users — This displays the users associated with this site. You can also change their role, reset their password, or remove them from the site. Removing the user from the site does not remove the user from the network.') . '

    ' . - '

    ' . sprintf( __('Themes — This area shows themes that are not already enabled across the network. Enabling a theme in this menu makes it accessible to this site. It does not activate the theme, but allows it to show in the site’s Appearance menu. To enable a theme for the entire network, see the Network Themes screen.' ), network_admin_url( 'themes.php' ) ) . '

    ' . - '

    ' . __('Settings — This page shows a list of all settings associated with this site. Some are created by WordPress and others are created by plugins you activate. Note that some fields are grayed out and say Serialized Data. You cannot modify these values due to the way the setting is stored in the database.') . '

    ' + '

    ' . __( 'The menu is for editing information specific to individual sites, particularly if the admin area of a site is unavailable.' ) . '

    ' . + '

    ' . __( 'Info — The site URL is rarely edited as this can cause the site to not work properly. The Registered date and Last Updated date are displayed. Network admins can mark a site as archived, spam, deleted and mature, to remove from public listings or disable.' ) . '

    ' . + '

    ' . __( 'Users — This displays the users associated with this site. You can also change their role, reset their password, or remove them from the site. Removing the user from the site does not remove the user from the network.' ) . '

    ' . + '

    ' . sprintf( __( 'Themes — This area shows themes that are not already enabled across the network. Enabling a theme in this menu makes it accessible to this site. It does not activate the theme, but allows it to show in the site’s Appearance menu. To enable a theme for the entire network, see the Network Themes screen.' ), network_admin_url( 'themes.php' ) ) . '

    ' . + '

    ' . __( 'Settings — This page shows a list of all settings associated with this site. Some are created by WordPress and others are created by plugins you activate. Note that some fields are grayed out and say Serialized Data. You cannot modify these values due to the way the setting is stored in the database.' ) . '

    ', ); } @@ -992,7 +1235,7 @@ function get_site_screen_help_tab_args() { * @return string Help sidebar content. */ function get_site_screen_help_sidebar_content() { - return '

    ' . __('For more information:') . '

    ' . - '

    ' . __('Documentation on Site Management') . '

    ' . - '

    ' . __('Support Forums') . '

    '; + return '

    ' . __( 'For more information:' ) . '

    ' . + '

    ' . __( 'Documentation on Site Management' ) . '

    ' . + '

    ' . __( 'Support Forums' ) . '

    '; } diff --git a/wp-admin/includes/nav-menu.php b/wp-admin/includes/nav-menu.php index c98b2c7377..74209af075 100644 --- a/wp-admin/includes/nav-menu.php +++ b/wp-admin/includes/nav-menu.php @@ -21,10 +21,10 @@ require_once( ABSPATH . 'wp-admin/includes/class-walker-nav-menu-checklist.php' * @param array $request The unsanitized request values. */ function _wp_ajax_menu_quick_search( $request = array() ) { - $args = array(); - $type = isset( $request['type'] ) ? $request['type'] : ''; - $object_type = isset( $request['object_type'] ) ? $request['object_type'] : ''; - $query = isset( $request['q'] ) ? $request['q'] : ''; + $args = array(); + $type = isset( $request['type'] ) ? $request['type'] : ''; + $object_type = isset( $request['object_type'] ) ? $request['object_type'] : ''; + $query = isset( $request['q'] ) ? $request['q'] : ''; $response_format = isset( $request['response-format'] ) && in_array( $request['response-format'], array( 'json', 'markup' ) ) ? $request['response-format'] : 'json'; if ( 'markup' == $response_format ) { @@ -36,13 +36,13 @@ function _wp_ajax_menu_quick_search( $request = array() ) { if ( isset( $request['ID'] ) ) { $object_id = (int) $request['ID']; if ( 'markup' == $response_format ) { - echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_post( $object_id ) ) ), 0, (object) $args ); + echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( get_post( $object_id ) ) ), 0, (object) $args ); } elseif ( 'json' == $response_format ) { echo wp_json_encode( array( - 'ID' => $object_id, + 'ID' => $object_id, 'post_title' => get_the_title( $object_id ), - 'post_type' => get_post_type( $object_id ), + 'post_type' => get_post_type( $object_id ), ) ); echo "\n"; @@ -52,26 +52,24 @@ function _wp_ajax_menu_quick_search( $request = array() ) { if ( isset( $request['ID'] ) ) { $object_id = (int) $request['ID']; if ( 'markup' == $response_format ) { - echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_term( $object_id, $object_type ) ) ), 0, (object) $args ); + echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( get_term( $object_id, $object_type ) ) ), 0, (object) $args ); } elseif ( 'json' == $response_format ) { $post_obj = get_term( $object_id, $object_type ); echo wp_json_encode( array( - 'ID' => $object_id, + 'ID' => $object_id, 'post_title' => $post_obj->name, - 'post_type' => $object_type, + 'post_type' => $object_type, ) ); echo "\n"; } } - } - - } elseif ( preg_match('/quick-search-(posttype|taxonomy)-([a-zA-Z_-]*\b)/', $type, $matches) ) { + } elseif ( preg_match( '/quick-search-(posttype|taxonomy)-([a-zA-Z_-]*\b)/', $type, $matches ) ) { if ( 'posttype' == $matches[1] && get_post_type_object( $matches[2] ) ) { $post_type_obj = _wp_nav_menu_meta_box_object( get_post_type_object( $matches[2] ) ); - $args = array_merge( + $args = array_merge( $args, array( 'no_found_rows' => true, @@ -93,34 +91,37 @@ function _wp_ajax_menu_quick_search( $request = array() ) { $post = $search_results_query->next_post(); if ( 'markup' == $response_format ) { $var_by_ref = $post->ID; - echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_post( $var_by_ref ) ) ), 0, (object) $args ); + echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( get_post( $var_by_ref ) ) ), 0, (object) $args ); } elseif ( 'json' == $response_format ) { echo wp_json_encode( array( - 'ID' => $post->ID, + 'ID' => $post->ID, 'post_title' => get_the_title( $post->ID ), - 'post_type' => $matches[2], + 'post_type' => $matches[2], ) ); echo "\n"; } } } elseif ( 'taxonomy' == $matches[1] ) { - $terms = get_terms( $matches[2], array( - 'name__like' => $query, - 'number' => 10, - )); - if ( empty( $terms ) || is_wp_error( $terms ) ) + $terms = get_terms( + $matches[2], array( + 'name__like' => $query, + 'number' => 10, + ) + ); + if ( empty( $terms ) || is_wp_error( $terms ) ) { return; + } foreach ( (array) $terms as $term ) { if ( 'markup' == $response_format ) { - echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( $term ) ), 0, (object) $args ); + echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( $term ) ), 0, (object) $args ); } elseif ( 'json' == $response_format ) { echo wp_json_encode( array( - 'ID' => $term->term_id, + 'ID' => $term->term_id, 'post_title' => $term->name, - 'post_type' => $matches[2], + 'post_type' => $matches[2], ) ); echo "\n"; @@ -134,7 +135,7 @@ function _wp_ajax_menu_quick_search( $request = array() ) { * Register nav menu meta boxes and advanced menu items. * * @since 3.0.0 - **/ + */ function wp_nav_menu_setup() { // Register meta boxes wp_nav_menu_post_type_meta_boxes(); @@ -147,9 +148,17 @@ function wp_nav_menu_setup() { // If first time editing, disable advanced items by default. if ( false === get_user_option( 'managenav-menuscolumnshidden' ) ) { $user = wp_get_current_user(); - update_user_option($user->ID, 'managenav-menuscolumnshidden', - array( 0 => 'link-target', 1 => 'css-classes', 2 => 'xfn', 3 => 'description', 4 => 'title-attribute', ), - true); + update_user_option( + $user->ID, 'managenav-menuscolumnshidden', + array( + 0 => 'link-target', + 1 => 'css-classes', + 2 => 'xfn', + 3 => 'description', + 4 => 'title-attribute', + ), + true + ); } } @@ -159,19 +168,20 @@ function wp_nav_menu_setup() { * @since 3.0.0 * * @global array $wp_meta_boxes - **/ + */ function wp_initial_nav_menu_meta_boxes() { global $wp_meta_boxes; - if ( get_user_option( 'metaboxhidden_nav-menus' ) !== false || ! is_array($wp_meta_boxes) ) + if ( get_user_option( 'metaboxhidden_nav-menus' ) !== false || ! is_array( $wp_meta_boxes ) ) { return; + } $initial_meta_boxes = array( 'add-post-type-page', 'add-post-type-post', 'add-custom-links', 'add-category' ); - $hidden_meta_boxes = array(); + $hidden_meta_boxes = array(); - foreach ( array_keys($wp_meta_boxes['nav-menus']) as $context ) { - foreach ( array_keys($wp_meta_boxes['nav-menus'][$context]) as $priority ) { - foreach ( $wp_meta_boxes['nav-menus'][$context][$priority] as $box ) { + foreach ( array_keys( $wp_meta_boxes['nav-menus'] ) as $context ) { + foreach ( array_keys( $wp_meta_boxes['nav-menus'][ $context ] ) as $priority ) { + foreach ( $wp_meta_boxes['nav-menus'][ $context ][ $priority ] as $box ) { if ( in_array( $box['id'], $initial_meta_boxes ) ) { unset( $box['id'] ); } else { @@ -193,8 +203,9 @@ function wp_initial_nav_menu_meta_boxes() { function wp_nav_menu_post_type_meta_boxes() { $post_types = get_post_types( array( 'show_in_nav_menus' => true ), 'object' ); - if ( ! $post_types ) + if ( ! $post_types ) { return; + } foreach ( $post_types as $post_type ) { /** @@ -227,8 +238,9 @@ function wp_nav_menu_post_type_meta_boxes() { function wp_nav_menu_taxonomy_meta_boxes() { $taxonomies = get_taxonomies( array( 'show_in_nav_menus' => true ), 'object' ); - if ( !$taxonomies ) + if ( ! $taxonomies ) { return; + } foreach ( $taxonomies as $tax ) { /** This filter is documented in wp-admin/includes/nav-menu.php */ @@ -253,8 +265,9 @@ function wp_nav_menu_taxonomy_meta_boxes() { function wp_nav_menu_disabled_check( $nav_menu_selected_id ) { global $one_theme_location_no_menus; - if ( $one_theme_location_no_menus ) + if ( $one_theme_location_no_menus ) { return false; + } return disabled( $nav_menu_selected_id, 0 ); } @@ -287,7 +300,7 @@ function wp_nav_menu_item_link_meta_box() {

    - class="button submit-add-to-menu right" value="" name="add-custom-menu-item" id="submit-customlinkdiv" /> + class="button submit-add-to-menu right" value="" name="add-custom-menu-item" id="submit-customlinkdiv" />

    @@ -321,26 +334,27 @@ function wp_nav_menu_item_post_type_meta_box( $object, $box ) { // Paginate browsing for large numbers of post objects. $per_page = 50; - $pagenum = isset( $_REQUEST[$post_type_name . '-tab'] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1; - $offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0; + $pagenum = isset( $_REQUEST[ $post_type_name . '-tab' ] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1; + $offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0; $args = array( - 'offset' => $offset, - 'order' => 'ASC', - 'orderby' => 'title', - 'posts_per_page' => $per_page, - 'post_type' => $post_type_name, - 'suppress_filters' => true, + 'offset' => $offset, + 'order' => 'ASC', + 'orderby' => 'title', + 'posts_per_page' => $per_page, + 'post_type' => $post_type_name, + 'suppress_filters' => true, 'update_post_term_cache' => false, - 'update_post_meta_cache' => false + 'update_post_meta_cache' => false, ); - if ( isset( $box['args']->_default_query ) ) - $args = array_merge($args, (array) $box['args']->_default_query ); + if ( isset( $box['args']->_default_query ) ) { + $args = array_merge( $args, (array) $box['args']->_default_query ); + } // @todo transient caching of these results with proper invalidation on updating of a post of this type $get_posts = new WP_Query; - $posts = $get_posts->query( $args ); + $posts = $get_posts->query( $args ); if ( ! $get_posts->post_count ) { echo '

    ' . __( 'No items.' ) . '

    '; return; @@ -348,36 +362,41 @@ function wp_nav_menu_item_post_type_meta_box( $object, $box ) { $num_pages = $get_posts->max_num_pages; - $page_links = paginate_links( array( - 'base' => add_query_arg( - array( - $post_type_name . '-tab' => 'all', - 'paged' => '%#%', - 'item-type' => 'post_type', - 'item-object' => $post_type_name, - ) - ), - 'format' => '', - 'prev_text' => '' . __( '«' ) . '', - 'next_text' => '' . __( '»' ) . '', - 'before_page_number' => '' . __( 'Page' ) . ' ', - 'total' => $num_pages, - 'current' => $pagenum - )); + $page_links = paginate_links( + array( + 'base' => add_query_arg( + array( + $post_type_name . '-tab' => 'all', + 'paged' => '%#%', + 'item-type' => 'post_type', + 'item-object' => $post_type_name, + ) + ), + 'format' => '', + 'prev_text' => '' . __( '«' ) . '', + 'next_text' => '' . __( '»' ) . '', + 'before_page_number' => '' . __( 'Page' ) . ' ', + 'total' => $num_pages, + 'current' => $pagenum, + ) + ); $db_fields = false; if ( is_post_type_hierarchical( $post_type_name ) ) { - $db_fields = array( 'parent' => 'post_parent', 'id' => 'ID' ); + $db_fields = array( + 'parent' => 'post_parent', + 'id' => 'ID', + ); } $walker = new Walker_Nav_Menu_Checklist( $db_fields ); $current_tab = 'most-recent'; - if ( isset( $_REQUEST[$post_type_name . '-tab'] ) && in_array( $_REQUEST[$post_type_name . '-tab'], array('all', 'search') ) ) { - $current_tab = $_REQUEST[$post_type_name . '-tab']; + if ( isset( $_REQUEST[ $post_type_name . '-tab' ] ) && in_array( $_REQUEST[ $post_type_name . '-tab' ], array( 'all', 'search' ) ) ) { + $current_tab = $_REQUEST[ $post_type_name . '-tab' ]; } - if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) { + if ( ! empty( $_REQUEST[ 'quick-search-posttype-' . $post_type_name ] ) ) { $current_tab = 'search'; } @@ -392,9 +411,9 @@ function wp_nav_menu_item_post_type_meta_box( $object, $box ) { $most_recent_url = $view_all_url = $search_url = ''; if ( $nav_menu_selected_id ) { - $most_recent_url = esc_url(add_query_arg($post_type_name . '-tab', 'most-recent', remove_query_arg($removed_args))); - $view_all_url = esc_url(add_query_arg($post_type_name . '-tab', 'all', remove_query_arg($removed_args))); - $search_url = esc_url(add_query_arg($post_type_name . '-tab', 'search', remove_query_arg($removed_args))); + $most_recent_url = esc_url( add_query_arg( $post_type_name . '-tab', 'most-recent', remove_query_arg( $removed_args ) ) ); + $view_all_url = esc_url( add_query_arg( $post_type_name . '-tab', 'all', remove_query_arg( $removed_args ) ) ); + $search_url = esc_url( add_query_arg( $post_type_name . '-tab', 'search', remove_query_arg( $removed_args ) ) ); } ?>
    @@ -411,18 +430,26 @@ function wp_nav_menu_item_post_type_meta_box( $object, $box ) {
  • > - +
  • -
    +
      'post_date', 'order' => 'DESC', 'posts_per_page' => 15 ) ); - $most_recent = $get_posts->query( $recent_args ); + $recent_args = array_merge( + $args, array( + 'orderby' => 'post_date', + 'order' => 'DESC', + 'posts_per_page' => 15, + ) + ); + $most_recent = $get_posts->query( $recent_args ); $args['walker'] = $walker; /** @@ -446,15 +473,24 @@ function wp_nav_menu_item_post_type_meta_box( $object, $box ) {
    -
    " id="tabs-panel-posttype--search"> + ?> + " id="tabs-panel-posttype--search"> $searched, 'post_type' => $post_type_name, 'fields' => 'all', 'order' => 'DESC', ) ); + if ( isset( $_REQUEST[ 'quick-search-posttype-' . $post_type_name ] ) ) { + $searched = esc_attr( $_REQUEST[ 'quick-search-posttype-' . $post_type_name ] ); + $search_results = get_posts( + array( + 's' => $searched, + 'post_type' => $post_type_name, + 'fields' => 'all', + 'order' => 'DESC', + ) + ); } else { - $searched = ''; + $searched = ''; $search_results = array(); } ?> @@ -465,29 +501,31 @@ function wp_nav_menu_item_post_type_meta_box( $object, $box ) { 'submit-quick-search-posttype-' . $post_type_name ) ); ?>

    -
      +
      • get_error_message(); ?>
      • -
      • +
    -
    +
    -
      +
        front_or_home = true; array_unshift( $posts, $front_page_obj ); } else { - $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1; - array_unshift( $posts, (object) array( - 'front_or_home' => true, - 'ID' => 0, - 'object_id' => $_nav_menu_placeholder, - 'post_content' => '', - 'post_excerpt' => '', - 'post_parent' => '', - 'post_title' => _x('Home', 'nav menu home label'), - 'post_type' => 'nav_menu_item', - 'type' => 'custom', - 'url' => home_url('/'), - ) ); + $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval( $_nav_menu_placeholder ) - 1 : -1; + array_unshift( + $posts, (object) array( + 'front_or_home' => true, + 'ID' => 0, + 'object_id' => $_nav_menu_placeholder, + 'post_content' => '', + 'post_excerpt' => '', + 'post_parent' => '', + 'post_title' => _x( 'Home', 'nav menu home label' ), + 'post_type' => 'nav_menu_item', + 'type' => 'custom', + 'url' => home_url( '/' ), + ) + ); } } $post_type = get_post_type_object( $post_type_name ); if ( $post_type->has_archive ) { - $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1; - array_unshift( $posts, (object) array( - 'ID' => 0, - 'object_id' => $_nav_menu_placeholder, - 'object' => $post_type_name, - 'post_content' => '', - 'post_excerpt' => '', - 'post_title' => $post_type->labels->archives, - 'post_type' => 'nav_menu_item', - 'type' => 'post_type_archive', - 'url' => get_post_type_archive_link( $post_type_name ), - ) ); + $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval( $_nav_menu_placeholder ) - 1 : -1; + array_unshift( + $posts, (object) array( + 'ID' => 0, + 'object_id' => $_nav_menu_placeholder, + 'object' => $post_type_name, + 'post_content' => '', + 'post_excerpt' => '', + 'post_title' => $post_type->labels->archives, + 'post_type' => 'nav_menu_item', + 'type' => 'post_type_archive', + 'url' => get_post_type_archive_link( $post_type_name ), + ) + ); } /** @@ -553,10 +595,10 @@ function wp_nav_menu_item_post_type_meta_box( $object, $box ) { */ $posts = apply_filters( "nav_menu_items_{$post_type_name}", $posts, $args, $post_type ); - $checkbox_items = walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $posts), 0, (object) $args ); + $checkbox_items = walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $posts ), 0, (object) $args ); if ( 'all' == $current_tab && ! empty( $_REQUEST['selectall'] ) ) { - $checkbox_items = preg_replace('/(type=(.)checkbox(\2))/', '$1 checked=$2checked$2', $checkbox_items); + $checkbox_items = preg_replace( '/(type=(.)checkbox(\2))/', '$1 checked=$2checked$2', $checkbox_items ); } @@ -572,15 +614,19 @@ function wp_nav_menu_item_post_type_meta_box( $object, $box ) {

        - + @@ -613,65 +659,79 @@ function wp_nav_menu_item_post_type_meta_box( $object, $box ) { function wp_nav_menu_item_taxonomy_meta_box( $object, $box ) { global $nav_menu_selected_id; $taxonomy_name = $box['args']->name; - $taxonomy = get_taxonomy( $taxonomy_name ); + $taxonomy = get_taxonomy( $taxonomy_name ); // Paginate browsing for large numbers of objects. $per_page = 50; - $pagenum = isset( $_REQUEST[$taxonomy_name . '-tab'] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1; - $offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0; + $pagenum = isset( $_REQUEST[ $taxonomy_name . '-tab' ] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1; + $offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0; $args = array( - 'child_of' => 0, - 'exclude' => '', - 'hide_empty' => false, + 'child_of' => 0, + 'exclude' => '', + 'hide_empty' => false, 'hierarchical' => 1, - 'include' => '', - 'number' => $per_page, - 'offset' => $offset, - 'order' => 'ASC', - 'orderby' => 'name', - 'pad_counts' => false, + 'include' => '', + 'number' => $per_page, + 'offset' => $offset, + 'order' => 'ASC', + 'orderby' => 'name', + 'pad_counts' => false, ); $terms = get_terms( $taxonomy_name, $args ); - if ( ! $terms || is_wp_error($terms) ) { + if ( ! $terms || is_wp_error( $terms ) ) { echo '

        ' . __( 'No items.' ) . '

        '; return; } - $num_pages = ceil( wp_count_terms( $taxonomy_name , array_merge( $args, array('number' => '', 'offset' => '') ) ) / $per_page ); - - $page_links = paginate_links( array( - 'base' => add_query_arg( - array( - $taxonomy_name . '-tab' => 'all', - 'paged' => '%#%', - 'item-type' => 'taxonomy', - 'item-object' => $taxonomy_name, + $num_pages = ceil( + wp_count_terms( + $taxonomy_name, array_merge( + $args, array( + 'number' => '', + 'offset' => '', + ) ) - ), - 'format' => '', - 'prev_text' => '' . __( '«' ) . '', - 'next_text' => '' . __( '»' ) . '', - 'before_page_number' => '' . __( 'Page' ) . ' ', - 'total' => $num_pages, - 'current' => $pagenum - )); + ) / $per_page + ); + + $page_links = paginate_links( + array( + 'base' => add_query_arg( + array( + $taxonomy_name . '-tab' => 'all', + 'paged' => '%#%', + 'item-type' => 'taxonomy', + 'item-object' => $taxonomy_name, + ) + ), + 'format' => '', + 'prev_text' => '' . __( '«' ) . '', + 'next_text' => '' . __( '»' ) . '', + 'before_page_number' => '' . __( 'Page' ) . ' ', + 'total' => $num_pages, + 'current' => $pagenum, + ) + ); $db_fields = false; if ( is_taxonomy_hierarchical( $taxonomy_name ) ) { - $db_fields = array( 'parent' => 'parent', 'id' => 'term_id' ); + $db_fields = array( + 'parent' => 'parent', + 'id' => 'term_id', + ); } $walker = new Walker_Nav_Menu_Checklist( $db_fields ); $current_tab = 'most-used'; - if ( isset( $_REQUEST[$taxonomy_name . '-tab'] ) && in_array( $_REQUEST[$taxonomy_name . '-tab'], array('all', 'most-used', 'search') ) ) { - $current_tab = $_REQUEST[$taxonomy_name . '-tab']; + if ( isset( $_REQUEST[ $taxonomy_name . '-tab' ] ) && in_array( $_REQUEST[ $taxonomy_name . '-tab' ], array( 'all', 'most-used', 'search' ) ) ) { + $current_tab = $_REQUEST[ $taxonomy_name . '-tab' ]; } - if ( ! empty( $_REQUEST['quick-search-taxonomy-' . $taxonomy_name] ) ) { + if ( ! empty( $_REQUEST[ 'quick-search-taxonomy-' . $taxonomy_name ] ) ) { $current_tab = 'search'; } @@ -686,9 +746,9 @@ function wp_nav_menu_item_taxonomy_meta_box( $object, $box ) { $most_used_url = $view_all_url = $search_url = ''; if ( $nav_menu_selected_id ) { - $most_used_url = esc_url(add_query_arg($taxonomy_name . '-tab', 'most-used', remove_query_arg($removed_args))); - $view_all_url = esc_url(add_query_arg($taxonomy_name . '-tab', 'all', remove_query_arg($removed_args))); - $search_url = esc_url(add_query_arg($taxonomy_name . '-tab', 'search', remove_query_arg($removed_args))); + $most_used_url = esc_url( add_query_arg( $taxonomy_name . '-tab', 'most-used', remove_query_arg( $removed_args ) ) ); + $view_all_url = esc_url( add_query_arg( $taxonomy_name . '-tab', 'all', remove_query_arg( $removed_args ) ) ); + $search_url = esc_url( add_query_arg( $taxonomy_name . '-tab', 'search', remove_query_arg( $removed_args ) ) ); } ?>
        @@ -710,30 +770,41 @@ function wp_nav_menu_item_taxonomy_meta_box( $object, $box ) {
      -
      +
        'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) ); + $popular_terms = get_terms( + $taxonomy_name, array( + 'orderby' => 'count', + 'order' => 'DESC', + 'number' => 10, + 'hierarchical' => false, + ) + ); $args['walker'] = $walker; - echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $popular_terms), 0, (object) $args ); + echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $popular_terms ), 0, (object) $args ); ?>
      -
      +
      -
        +
        @@ -743,15 +814,25 @@ function wp_nav_menu_item_taxonomy_meta_box( $object, $box ) {
      -
      " id="tabs-panel-search-taxonomy-"> + ?> + " id="tabs-panel-search-taxonomy-"> $searched, 'fields' => 'all', 'orderby' => 'count', 'order' => 'DESC', 'hierarchical' => false ) ); + if ( isset( $_REQUEST[ 'quick-search-taxonomy-' . $taxonomy_name ] ) ) { + $searched = esc_attr( $_REQUEST[ 'quick-search-taxonomy-' . $taxonomy_name ] ); + $search_results = get_terms( + $taxonomy_name, array( + 'name__like' => $searched, + 'fields' => 'all', + 'orderby' => 'count', + 'order' => 'DESC', + 'hierarchical' => false, + ) + ); } else { - $searched = ''; + $searched = ''; $search_results = array(); } ?> @@ -762,31 +843,35 @@ function wp_nav_menu_item_taxonomy_meta_box( $object, $box ) { 'submit-quick-search-taxonomy-' . $taxonomy_name ) ); ?>

      -
        +
        • get_error_message(); ?>
        • -
        • +

      - + @@ -809,7 +894,7 @@ function wp_nav_menu_item_taxonomy_meta_box( $object, $box ) { * @return array The database IDs of the items saved */ function wp_save_nav_menu_items( $menu_id = 0, $menu_data = array() ) { - $menu_id = (int) $menu_id; + $menu_id = (int) $menu_id; $items_saved = array(); if ( 0 == $menu_id || is_nav_menu( $menu_id ) ) { @@ -845,19 +930,19 @@ function wp_save_nav_menu_items( $menu_id = 0, $menu_data = array() ) { } $args = array( - 'menu-item-db-id' => ( isset( $_item_object_data['menu-item-db-id'] ) ? $_item_object_data['menu-item-db-id'] : '' ), - 'menu-item-object-id' => ( isset( $_item_object_data['menu-item-object-id'] ) ? $_item_object_data['menu-item-object-id'] : '' ), - 'menu-item-object' => ( isset( $_item_object_data['menu-item-object'] ) ? $_item_object_data['menu-item-object'] : '' ), - 'menu-item-parent-id' => ( isset( $_item_object_data['menu-item-parent-id'] ) ? $_item_object_data['menu-item-parent-id'] : '' ), - 'menu-item-position' => ( isset( $_item_object_data['menu-item-position'] ) ? $_item_object_data['menu-item-position'] : '' ), - 'menu-item-type' => ( isset( $_item_object_data['menu-item-type'] ) ? $_item_object_data['menu-item-type'] : '' ), - 'menu-item-title' => ( isset( $_item_object_data['menu-item-title'] ) ? $_item_object_data['menu-item-title'] : '' ), - 'menu-item-url' => ( isset( $_item_object_data['menu-item-url'] ) ? $_item_object_data['menu-item-url'] : '' ), + 'menu-item-db-id' => ( isset( $_item_object_data['menu-item-db-id'] ) ? $_item_object_data['menu-item-db-id'] : '' ), + 'menu-item-object-id' => ( isset( $_item_object_data['menu-item-object-id'] ) ? $_item_object_data['menu-item-object-id'] : '' ), + 'menu-item-object' => ( isset( $_item_object_data['menu-item-object'] ) ? $_item_object_data['menu-item-object'] : '' ), + 'menu-item-parent-id' => ( isset( $_item_object_data['menu-item-parent-id'] ) ? $_item_object_data['menu-item-parent-id'] : '' ), + 'menu-item-position' => ( isset( $_item_object_data['menu-item-position'] ) ? $_item_object_data['menu-item-position'] : '' ), + 'menu-item-type' => ( isset( $_item_object_data['menu-item-type'] ) ? $_item_object_data['menu-item-type'] : '' ), + 'menu-item-title' => ( isset( $_item_object_data['menu-item-title'] ) ? $_item_object_data['menu-item-title'] : '' ), + 'menu-item-url' => ( isset( $_item_object_data['menu-item-url'] ) ? $_item_object_data['menu-item-url'] : '' ), 'menu-item-description' => ( isset( $_item_object_data['menu-item-description'] ) ? $_item_object_data['menu-item-description'] : '' ), - 'menu-item-attr-title' => ( isset( $_item_object_data['menu-item-attr-title'] ) ? $_item_object_data['menu-item-attr-title'] : '' ), - 'menu-item-target' => ( isset( $_item_object_data['menu-item-target'] ) ? $_item_object_data['menu-item-target'] : '' ), - 'menu-item-classes' => ( isset( $_item_object_data['menu-item-classes'] ) ? $_item_object_data['menu-item-classes'] : '' ), - 'menu-item-xfn' => ( isset( $_item_object_data['menu-item-xfn'] ) ? $_item_object_data['menu-item-xfn'] : '' ), + 'menu-item-attr-title' => ( isset( $_item_object_data['menu-item-attr-title'] ) ? $_item_object_data['menu-item-attr-title'] : '' ), + 'menu-item-target' => ( isset( $_item_object_data['menu-item-target'] ) ? $_item_object_data['menu-item-target'] : '' ), + 'menu-item-classes' => ( isset( $_item_object_data['menu-item-classes'] ) ? $_item_object_data['menu-item-classes'] : '' ), + 'menu-item-xfn' => ( isset( $_item_object_data['menu-item-xfn'] ) ? $_item_object_data['menu-item-xfn'] : '' ), ); $items_saved[] = wp_update_nav_menu_item( $menu_id, $_actual_db_id, $args ); @@ -882,24 +967,24 @@ function _wp_nav_menu_meta_box_object( $object = null ) { if ( 'page' == $object->name ) { $object->_default_query = array( - 'orderby' => 'menu_order title', + 'orderby' => 'menu_order title', 'post_status' => 'publish', ); - // Posts should show only published items. + // Posts should show only published items. } elseif ( 'post' == $object->name ) { $object->_default_query = array( 'post_status' => 'publish', ); - // Categories should be in reverse chronological order. + // Categories should be in reverse chronological order. } elseif ( 'category' == $object->name ) { $object->_default_query = array( 'orderby' => 'id', - 'order' => 'DESC', + 'order' => 'DESC', ); - // Custom post types should show only published items. + // Custom post types should show only published items. } else { $object->_default_query = array( 'post_status' => 'publish', @@ -923,14 +1008,15 @@ function wp_get_nav_menu_to_edit( $menu_id = 0 ) { // If the menu exists, get its items. if ( is_nav_menu( $menu ) ) { - $menu_items = wp_get_nav_menu_items( $menu->term_id, array('post_status' => 'any') ); - $result = '

      ' : '">'; - $result .= '

      ' . __( 'Add menu items from the column on the left.' ) . '

      '; - $result .= '
      '; + $menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'post_status' => 'any' ) ); + $result = '
      ' : '">'; + $result .= '

      ' . __( 'Add menu items from the column on the left.' ) . '

      '; + $result .= '
      '; - if ( empty($menu_items) ) + if ( empty( $menu_items ) ) { return $result . ' '; + } /** * Filters the Walker class used when adding nav menu items. @@ -945,9 +1031,11 @@ function wp_get_nav_menu_to_edit( $menu_id = 0 ) { if ( class_exists( $walker_class_name ) ) { $walker = new $walker_class_name; } else { - return new WP_Error( 'menu_walker_not_exist', + return new WP_Error( + 'menu_walker_not_exist', /* translators: %s: walker class name */ - sprintf( __( 'The Walker class named %s does not exist.' ), + sprintf( + __( 'The Walker class named %s does not exist.' ), '' . $walker_class_name . '' ) ); @@ -955,10 +1043,12 @@ function wp_get_nav_menu_to_edit( $menu_id = 0 ) { $some_pending_menu_items = $some_invalid_menu_items = false; foreach ( (array) $menu_items as $menu_item ) { - if ( isset( $menu_item->post_status ) && 'draft' == $menu_item->post_status ) + if ( isset( $menu_item->post_status ) && 'draft' == $menu_item->post_status ) { $some_pending_menu_items = true; - if ( ! empty( $menu_item->_invalid ) ) + } + if ( ! empty( $menu_item->_invalid ) ) { $some_invalid_menu_items = true; + } } if ( $some_pending_menu_items ) { @@ -970,7 +1060,7 @@ function wp_get_nav_menu_to_edit( $menu_id = 0 ) { } $result .= ' '; return $result; } elseif ( is_wp_error( $menu ) ) { @@ -1011,10 +1101,11 @@ function _wp_delete_orphaned_draft_menu_items() { $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS ); // Delete orphaned draft menu items. - $menu_items_to_delete = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS m ON p.ID = m.post_id WHERE post_type = 'nav_menu_item' AND post_status = 'draft' AND meta_key = '_menu_item_orphaned' AND meta_value < %d", $delete_timestamp ) ); + $menu_items_to_delete = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS m ON p.ID = m.post_id WHERE post_type = 'nav_menu_item' AND post_status = 'draft' AND meta_key = '_menu_item_orphaned' AND meta_value < %d", $delete_timestamp ) ); - foreach ( (array) $menu_items_to_delete as $menu_item_id ) + foreach ( (array) $menu_items_to_delete as $menu_item_id ) { wp_delete_post( $menu_item_id, true ); + } } /** @@ -1026,19 +1117,36 @@ function _wp_delete_orphaned_draft_menu_items() { * @param string $nav_menu_selected_title Title of the currently-selected menu * @return array $messages The menu updated message */ -function wp_nav_menu_update_menu_items ( $nav_menu_selected_id, $nav_menu_selected_title ) { - $unsorted_menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array( 'orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID', 'post_status' => 'draft,publish' ) ); - $messages = array(); - $menu_items = array(); +function wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selected_title ) { + $unsorted_menu_items = wp_get_nav_menu_items( + $nav_menu_selected_id, array( + 'orderby' => 'ID', + 'output' => ARRAY_A, + 'output_key' => 'ID', + 'post_status' => 'draft,publish', + ) + ); + $messages = array(); + $menu_items = array(); // Index menu items by db ID - foreach ( $unsorted_menu_items as $_item ) - $menu_items[$_item->db_id] = $_item; + foreach ( $unsorted_menu_items as $_item ) { + $menu_items[ $_item->db_id ] = $_item; + } $post_fields = array( - 'menu-item-db-id', 'menu-item-object-id', 'menu-item-object', - 'menu-item-parent-id', 'menu-item-position', 'menu-item-type', - 'menu-item-title', 'menu-item-url', 'menu-item-description', - 'menu-item-attr-title', 'menu-item-target', 'menu-item-classes', 'menu-item-xfn' + 'menu-item-db-id', + 'menu-item-object-id', + 'menu-item-object', + 'menu-item-parent-id', + 'menu-item-position', + 'menu-item-type', + 'menu-item-title', + 'menu-item-url', + 'menu-item-description', + 'menu-item-attr-title', + 'menu-item-target', + 'menu-item-classes', + 'menu-item-xfn', ); wp_defer_term_counting( true ); @@ -1047,14 +1155,16 @@ function wp_nav_menu_update_menu_items ( $nav_menu_selected_id, $nav_menu_select foreach ( (array) $_POST['menu-item-db-id'] as $_key => $k ) { // Menu item title can't be blank - if ( ! isset( $_POST['menu-item-title'][ $_key ] ) || '' == $_POST['menu-item-title'][ $_key ] ) + if ( ! isset( $_POST['menu-item-title'][ $_key ] ) || '' == $_POST['menu-item-title'][ $_key ] ) { continue; + } $args = array(); - foreach ( $post_fields as $field ) - $args[$field] = isset( $_POST[$field][$_key] ) ? $_POST[$field][$_key] : ''; + foreach ( $post_fields as $field ) { + $args[ $field ] = isset( $_POST[ $field ][ $_key ] ) ? $_POST[ $field ][ $_key ] : ''; + } - $menu_item_db_id = wp_update_nav_menu_item( $nav_menu_selected_id, ( $_POST['menu-item-db-id'][$_key] != $_key ? 0 : $_key ), $args ); + $menu_item_db_id = wp_update_nav_menu_item( $nav_menu_selected_id, ( $_POST['menu-item-db-id'][ $_key ] != $_key ? 0 : $_key ), $args ); if ( is_wp_error( $menu_item_db_id ) ) { $messages[] = '

      ' . $menu_item_db_id->get_error_message() . '

      '; @@ -1074,16 +1184,19 @@ function wp_nav_menu_update_menu_items ( $nav_menu_selected_id, $nav_menu_select } // Store 'auto-add' pages. - $auto_add = ! empty( $_POST['auto-add-pages'] ); + $auto_add = ! empty( $_POST['auto-add-pages'] ); $nav_menu_option = (array) get_option( 'nav_menu_options' ); - if ( ! isset( $nav_menu_option['auto_add'] ) ) + if ( ! isset( $nav_menu_option['auto_add'] ) ) { $nav_menu_option['auto_add'] = array(); + } if ( $auto_add ) { - if ( ! in_array( $nav_menu_selected_id, $nav_menu_option['auto_add'] ) ) + if ( ! in_array( $nav_menu_selected_id, $nav_menu_option['auto_add'] ) ) { $nav_menu_option['auto_add'][] = $nav_menu_selected_id; + } } else { - if ( false !== ( $key = array_search( $nav_menu_selected_id, $nav_menu_option['auto_add'] ) ) ) - unset( $nav_menu_option['auto_add'][$key] ); + if ( false !== ( $key = array_search( $nav_menu_selected_id, $nav_menu_option['auto_add'] ) ) ) { + unset( $nav_menu_option['auto_add'][ $key ] ); + } } // Remove nonexistent/deleted menus $nav_menu_option['auto_add'] = array_intersect( $nav_menu_option['auto_add'], wp_get_nav_menus( array( 'fields' => 'ids' ) ) ); @@ -1096,7 +1209,8 @@ function wp_nav_menu_update_menu_items ( $nav_menu_selected_id, $nav_menu_select $messages[] = '

      ' . /* translators: %s: nav menu title */ - sprintf( __( '%s has been updated.' ), + sprintf( + __( '%s has been updated.' ), '' . $nav_menu_selected_title . '' ) . '

      '; diff --git a/wp-admin/includes/network.php b/wp-admin/includes/network.php index f9c5a79ec6..da7aec32a3 100644 --- a/wp-admin/includes/network.php +++ b/wp-admin/includes/network.php @@ -19,7 +19,7 @@ function network_domain_check() { global $wpdb; - $sql = $wpdb->prepare( "SHOW TABLES LIKE %s", $wpdb->esc_like( $wpdb->site ) ); + $sql = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $wpdb->site ) ); if ( $wpdb->get_var( $sql ) ) { return $wpdb->get_var( "SELECT domain FROM $wpdb->site ORDER BY id ASC LIMIT 1" ); } @@ -34,8 +34,9 @@ function network_domain_check() { */ function allow_subdomain_install() { $domain = preg_replace( '|https?://([^/]+)|', '$1', get_option( 'home' ) ); - if ( parse_url( get_option( 'home' ), PHP_URL_PATH ) || 'localhost' == $domain || preg_match( '|^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$|', $domain ) ) + if ( parse_url( get_option( 'home' ), PHP_URL_PATH ) || 'localhost' == $domain || preg_match( '|^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$|', $domain ) ) { return false; + } return true; } @@ -51,22 +52,25 @@ function allow_subdomain_install() { */ function allow_subdirectory_install() { global $wpdb; - /** - * Filters whether to enable the subdirectory installation feature in Multisite. - * - * @since 3.0.0 - * - * @param bool $allow Whether to enable the subdirectory installation feature in Multisite. Default is false. - */ - if ( apply_filters( 'allow_subdirectory_install', false ) ) + /** + * Filters whether to enable the subdirectory installation feature in Multisite. + * + * @since 3.0.0 + * + * @param bool $allow Whether to enable the subdirectory installation feature in Multisite. Default is false. + */ + if ( apply_filters( 'allow_subdirectory_install', false ) ) { return true; + } - if ( defined( 'ALLOW_SUBDIRECTORY_INSTALL' ) && ALLOW_SUBDIRECTORY_INSTALL ) + if ( defined( 'ALLOW_SUBDIRECTORY_INSTALL' ) && ALLOW_SUBDIRECTORY_INSTALL ) { return true; + } $post = $wpdb->get_row( "SELECT ID FROM $wpdb->posts WHERE post_date < DATE_SUB(NOW(), INTERVAL 1 MONTH) AND post_status = 'publish'" ); - if ( empty( $post ) ) + if ( empty( $post ) ) { return true; + } return false; } @@ -78,11 +82,13 @@ function allow_subdirectory_install() { * @return string Base domain. */ function get_clean_basedomain() { - if ( $existing_domain = network_domain_check() ) + if ( $existing_domain = network_domain_check() ) { return $existing_domain; + } $domain = preg_replace( '|https?://|', '', get_option( 'siteurl' ) ); - if ( $slash = strpos( $domain, '/' ) ) + if ( $slash = strpos( $domain, '/' ) ) { $domain = substr( $domain, 0, $slash ); + } return $domain; } @@ -90,7 +96,7 @@ function get_clean_basedomain() { * Prints step 1 for Network installation process. * * @todo Realistically, step 1 should be a welcome screen explaining what a Network is and such. Navigating to Tools > Network - * should not be a sudden "Welcome to a new install process! Fill this out and click here." See also contextual help todo. + * should not be a sudden "Welcome to a new install process! Fill this out and click here." See also contextual help todo. * * @since 3.0.0 * @@ -101,7 +107,7 @@ function get_clean_basedomain() { function network_step1( $errors = false ) { global $is_apache; - if ( defined('DO_NOT_UPGRADE_GLOBAL_TABLES') ) { + if ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) { echo '

      ' . __( 'ERROR:' ) . ' ' . sprintf( /* translators: %s: DO_NOT_UPGRADE_GLOBAL_TABLES */ __( 'The constant %s cannot be defined when creating a network.' ), @@ -125,7 +131,7 @@ function network_step1( $errors = false ) { die(); } - $hostname = get_clean_basedomain(); + $hostname = get_clean_basedomain(); $has_ports = strstr( $hostname, ':' ); if ( ( false !== $has_ports && ! in_array( $has_ports, array( ':80', ':443' ) ) ) ) { echo '

      ' . __( 'ERROR:' ) . ' ' . __( 'You cannot install a network of sites with your server address.' ) . '

      '; @@ -147,8 +153,9 @@ function network_step1( $errors = false ) { $error_codes = array(); if ( is_wp_error( $errors ) ) { echo '

      ' . __( 'ERROR: The network could not be created.' ) . '

      '; - foreach ( $errors->get_error_messages() as $error ) + foreach ( $errors->get_error_messages() as $error ) { echo "

      $error

      "; + } echo '
      '; $error_codes = $errors->get_error_codes(); } @@ -172,23 +179,25 @@ function network_step1( $errors = false ) { if ( isset( $_POST['subdomain_install'] ) ) { $subdomain_install = (bool) $_POST['subdomain_install']; - } elseif ( apache_mod_loaded('mod_rewrite') ) { // assume nothing + } elseif ( apache_mod_loaded( 'mod_rewrite' ) ) { // assume nothing $subdomain_install = true; - } elseif ( !allow_subdirectory_install() ) { + } elseif ( ! allow_subdirectory_install() ) { $subdomain_install = true; } else { $subdomain_install = false; if ( $got_mod_rewrite = got_mod_rewrite() ) { // dangerous assumptions echo '

      ' . __( 'Note:' ) . ' '; /* translators: %s: mod_rewrite */ - printf( __( 'Please make sure the Apache %s module is installed as it will be used at the end of this installation.' ), + printf( + __( 'Please make sure the Apache %s module is installed as it will be used at the end of this installation.' ), 'mod_rewrite' ); echo '

      '; } elseif ( $is_apache ) { echo '

      ' . __( 'Warning:' ) . ' '; /* translators: %s: mod_rewrite */ - printf( __( 'It looks like the Apache %s module is not installed.' ), + printf( + __( 'It looks like the Apache %s module is not installed.' ), 'mod_rewrite' ); echo '

      '; @@ -197,7 +206,8 @@ function network_step1( $errors = false ) { if ( $got_mod_rewrite || $is_apache ) { // Protect against mod_rewrite mimicry (but ! Apache) echo '

      '; /* translators: 1: mod_rewrite, 2: mod_rewrite documentation URL, 3: Google search for mod_rewrite */ - printf( __( 'If %1$s is disabled, ask your administrator to enable that module, or look at the Apache documentation or elsewhere for help setting it up.' ), + printf( + __( 'If %1$s is disabled, ask your administrator to enable that module, or look at the Apache documentation or elsewhere for help setting it up.' ), 'mod_rewrite', 'https://httpd.apache.org/docs/mod/mod_rewrite.html', 'https://www.google.com/search?q=apache+mod_rewrite' @@ -206,7 +216,8 @@ function network_step1( $errors = false ) { } } - if ( allow_subdomain_install() && allow_subdirectory_install() ) : ?> + if ( allow_subdomain_install() && allow_subdirectory_install() ) : + ?>

      @@ -215,48 +226,63 @@ function network_step1( $errors = false ) { - + ); + ?> + - + ); + ?> +
      + site1.%1$s and site2.%1$s', 'subdomain examples' ), $hostname - ); ?>
      + %1$s/site1 and %1$s/site2', 'subdirectory examples' ), $hostname - ); ?>

      ' . __( 'Warning:' ) . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '

      '; + if ( WP_CONTENT_DIR != ABSPATH . 'wp-content' && ( allow_subdirectory_install() || ! allow_subdomain_install() ) ) { + echo '

      ' . __( 'Warning:' ) . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '

      '; + } $is_www = ( 0 === strpos( $hostname, 'www.' ) ); - if ( $is_www ) : + if ( $is_www ) : ?>

      -

      + ' . substr( $hostname, 4 ) . '', '' . $hostname . '', 'www' - ); ?>

      + ); + ?> +

      - -
      - + + ' . $hostname . '' - ); ?> + ); + ?>
      @@ -267,7 +293,8 @@ function network_step1( $errors = false ) {
    + localhost.localdomain' ); // Uh oh: - if ( !allow_subdirectory_install() ) - echo ' ' . __( 'Warning:' ) . ' ' . __( 'The main site in a sub-directory installation will need to use a modified permalink structure, potentially breaking existing links.' ) . ''; - ?>
    + ' . __( 'Warning:' ) . ' ' . __( 'The main site in a sub-directory installation will need to use a modified permalink structure, potentially breaking existing links.' ) . ''; - ?>
    + ' . __( 'The main site in a sub-directory installation will need to use a modified permalink structure, potentially breaking existing links.' ) . ''; - ?>
    - ' . $hostname . '' - ); ?> + ); + ?>
    \n"; + if ( is_object( $id_or_email ) && isset( $id_or_email->comment_ID ) ) { + $id_or_email = get_comment( $id_or_email ); + } - if ( ! empty( $args[ 'show_split_view' ] ) ) { - $r .= ""; - } else { - $r .= ""; + /** + * Filters whether to retrieve the avatar URL early. + * + * Passing a non-null value will effectively short-circuit get_avatar(), passing + * the value through the {@see 'get_avatar'} filter and returning early. + * + * @since 4.2.0 + * + * @param string $avatar HTML for the user's avatar. Default null. + * @param mixed $id_or_email The Gravatar to retrieve. Accepts a user_id, gravatar md5 hash, + * user email, WP_User object, WP_Post object, or WP_Comment object. + * @param array $args Arguments passed to get_avatar_url(), after processing. + */ + $avatar = apply_filters( 'pre_get_avatar', null, $id_or_email, $args ); + + if ( ! is_null( $avatar ) ) { + /** This filter is documented in wp-includes/pluggable.php */ + return apply_filters( 'get_avatar', $avatar, $id_or_email, $args['size'], $args['default'], $args['alt'], $args ); + } + + if ( ! $args['force_display'] && ! get_option( 'show_avatars' ) ) { + return false; + } + + $url2x = get_avatar_url( $id_or_email, array_merge( $args, array( 'size' => $args['size'] * 2 ) ) ); + + $args = get_avatar_data( $id_or_email, $args ); + + $url = $args['url']; + + if ( ! $url || is_wp_error( $url ) ) { + return false; + } + + $class = array( 'avatar', 'avatar-' . (int) $args['size'], 'photo' ); + + if ( ! $args['found_avatar'] || $args['force_default'] ) { + $class[] = 'avatar-default'; + } + + if ( $args['class'] ) { + if ( is_array( $args['class'] ) ) { + $class = array_merge( $class, $args['class'] ); + } else { + $class[] = $args['class']; + } + } + + $avatar = sprintf( + "%s", + esc_attr( $args['alt'] ), + esc_url( $url ), + esc_url( $url2x ) . ' 2x', + esc_attr( join( ' ', $class ) ), + (int) $args['height'], + (int) $args['width'], + $args['extra_attr'] + ); + + /** + * Filters the avatar to retrieve. + * + * @since 2.5.0 + * @since 4.2.0 The `$args` parameter was added. + * + * @param string $avatar <img> tag for the user's avatar. + * @param mixed $id_or_email The Gravatar to retrieve. Accepts a user_id, gravatar md5 hash, + * user email, WP_User object, WP_Post object, or WP_Comment object. + * @param int $size Square avatar width and height in pixels to retrieve. + * @param string $default URL for the default image or a default type. Accepts '404', 'retro', 'monsterid', + * 'wavatar', 'indenticon','mystery' (or 'mm', or 'mysteryman'), 'blank', or 'gravatar_default'. + * Default is the value of the 'avatar_default' option, with a fallback of 'mystery'. + * @param string $alt Alternative text to use in the avatar image tag. Default empty. + * @param array $args Arguments passed to get_avatar_data(), after processing. + */ + return apply_filters( 'get_avatar', $avatar, $id_or_email, $args['size'], $args['default'], $args['alt'], $args ); + } +endif; + +if ( ! function_exists( 'wp_text_diff' ) ) : + /** + * Displays a human readable HTML representation of the difference between two strings. + * + * The Diff is available for getting the changes between versions. The output is + * HTML, so the primary use is for displaying the changes. If the two strings + * are equivalent, then an empty string will be returned. + * + * The arguments supported and can be changed are listed below. + * + * 'title' : Default is an empty string. Titles the diff in a manner compatible + * with the output. + * 'title_left' : Default is an empty string. Change the HTML to the left of the + * title. + * 'title_right' : Default is an empty string. Change the HTML to the right of + * the title. + * + * @since 2.6.0 + * + * @see wp_parse_args() Used to change defaults to user defined settings. + * @uses Text_Diff + * @uses WP_Text_Diff_Renderer_Table + * + * @param string $left_string "old" (left) version of string + * @param string $right_string "new" (right) version of string + * @param string|array $args Optional. Change 'title', 'title_left', and 'title_right' defaults. + * @return string Empty string if strings are equivalent or HTML with differences. + */ + function wp_text_diff( $left_string, $right_string, $args = null ) { + $defaults = array( + 'title' => '', + 'title_left' => '', + 'title_right' => '', + ); + $args = wp_parse_args( $args, $defaults ); + + if ( ! class_exists( 'WP_Text_Diff_Renderer_Table', false ) ) { + require( ABSPATH . WPINC . '/wp-diff.php' ); + } + + $left_string = normalize_whitespace( $left_string ); + $right_string = normalize_whitespace( $right_string ); + + $left_lines = explode( "\n", $left_string ); + $right_lines = explode( "\n", $right_string ); + $text_diff = new Text_Diff( $left_lines, $right_lines ); + $renderer = new WP_Text_Diff_Renderer_Table( $args ); + $diff = $renderer->render( $text_diff ); + + if ( ! $diff ) { + return ''; + } + + $r = "
    \n"; + + if ( ! empty( $args['show_split_view'] ) ) { + $r .= ""; + } else { + $r .= ""; + } + + if ( $args['title'] || $args['title_left'] || $args['title_right'] ) { + $r .= ''; + } + if ( $args['title'] ) { + $r .= "\n"; + } + if ( $args['title_left'] || $args['title_right'] ) { + $r .= "\n"; + $r .= "\t\n"; + $r .= "\t\n"; + $r .= "\n"; + } + if ( $args['title'] || $args['title_left'] || $args['title_right'] ) { + $r .= "\n"; + } + + $r .= "\n$diff\n\n"; + $r .= '
    $args[title]
    $args[title_left]$args[title_right]
    '; + + return $r; } - - if ( $args['title'] || $args['title_left'] || $args['title_right'] ) - $r .= ""; - if ( $args['title'] ) - $r .= "$args[title]\n"; - if ( $args['title_left'] || $args['title_right'] ) { - $r .= "\n"; - $r .= "\t$args[title_left]\n"; - $r .= "\t$args[title_right]\n"; - $r .= "\n"; - } - if ( $args['title'] || $args['title_left'] || $args['title_right'] ) - $r .= "\n"; - - $r .= "\n$diff\n\n"; - $r .= ""; - - return $r; -} endif; diff --git a/wp-includes/plugin.php b/wp-includes/plugin.php index 5a87e40635..879bb12fd4 100644 --- a/wp-includes/plugin.php +++ b/wp-includes/plugin.php @@ -33,11 +33,13 @@ if ( $wp_filter ) { $wp_filter = array(); } -if ( ! isset( $wp_actions ) ) +if ( ! isset( $wp_actions ) ) { $wp_actions = array(); +} -if ( ! isset( $wp_current_filter ) ) +if ( ! isset( $wp_current_filter ) ) { $wp_current_filter = array(); +} /** * Hook a function or method to a specific filter action. @@ -128,7 +130,7 @@ function add_filter( $tag, $function_to_add, $priority = 10, $accepted_args = 1 * that evaluates to false (e.g.) 0, so use the === operator for testing the * return value. */ -function has_filter($tag, $function_to_check = false) { +function has_filter( $tag, $function_to_check = false ) { global $wp_filter; if ( ! isset( $wp_filter[ $tag ] ) ) { @@ -179,23 +181,26 @@ function apply_filters( $tag, $value ) { $args = array(); // Do 'all' actions first. - if ( isset($wp_filter['all']) ) { + if ( isset( $wp_filter['all'] ) ) { $wp_current_filter[] = $tag; - $args = func_get_args(); - _wp_call_all_hook($args); + $args = func_get_args(); + _wp_call_all_hook( $args ); } - if ( !isset($wp_filter[$tag]) ) { - if ( isset($wp_filter['all']) ) - array_pop($wp_current_filter); + if ( ! isset( $wp_filter[ $tag ] ) ) { + if ( isset( $wp_filter['all'] ) ) { + array_pop( $wp_current_filter ); + } return $value; } - if ( !isset($wp_filter['all']) ) + if ( ! isset( $wp_filter['all'] ) ) { $wp_current_filter[] = $tag; + } - if ( empty($args) ) + if ( empty( $args ) ) { $args = func_get_args(); + } // don't pass the tag name to WP_Hook array_shift( $args ); @@ -222,24 +227,26 @@ function apply_filters( $tag, $value ) { * @param array $args The arguments supplied to the functions hooked to $tag. * @return mixed The filtered value after all hooked functions are applied to it. */ -function apply_filters_ref_array($tag, $args) { +function apply_filters_ref_array( $tag, $args ) { global $wp_filter, $wp_current_filter; // Do 'all' actions first - if ( isset($wp_filter['all']) ) { + if ( isset( $wp_filter['all'] ) ) { $wp_current_filter[] = $tag; - $all_args = func_get_args(); - _wp_call_all_hook($all_args); + $all_args = func_get_args(); + _wp_call_all_hook( $all_args ); } - if ( !isset($wp_filter[$tag]) ) { - if ( isset($wp_filter['all']) ) - array_pop($wp_current_filter); + if ( ! isset( $wp_filter[ $tag ] ) ) { + if ( isset( $wp_filter['all'] ) ) { + array_pop( $wp_current_filter ); + } return $args[0]; } - if ( !isset($wp_filter['all']) ) + if ( ! isset( $wp_filter['all'] ) ) { $wp_current_filter[] = $tag; + } $filtered = $wp_filter[ $tag ]->apply_filters( $args[0], $args ); @@ -296,7 +303,7 @@ function remove_filter( $tag, $function_to_remove, $priority = 10 ) { function remove_all_filters( $tag, $priority = false ) { global $wp_filter; - if ( isset( $wp_filter[ $tag ]) ) { + if ( isset( $wp_filter[ $tag ] ) ) { $wp_filter[ $tag ]->remove_all_filters( $priority ); if ( ! $wp_filter[ $tag ]->has_filters() ) { unset( $wp_filter[ $tag ] ); @@ -395,8 +402,8 @@ function doing_action( $action = null ) { * @param int $accepted_args Optional. The number of arguments the function accepts. Default 1. * @return true Will always return true. */ -function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) { - return add_filter($tag, $function_to_add, $priority, $accepted_args); +function add_action( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) { + return add_filter( $tag, $function_to_add, $priority, $accepted_args ); } /** @@ -418,41 +425,46 @@ function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) * @param mixed $arg,... Optional. Additional arguments which are passed on to the * functions hooked to the action. Default empty. */ -function do_action($tag, $arg = '') { +function do_action( $tag, $arg = '' ) { global $wp_filter, $wp_actions, $wp_current_filter; - if ( ! isset($wp_actions[$tag]) ) - $wp_actions[$tag] = 1; - else - ++$wp_actions[$tag]; - - // Do 'all' actions first - if ( isset($wp_filter['all']) ) { - $wp_current_filter[] = $tag; - $all_args = func_get_args(); - _wp_call_all_hook($all_args); + if ( ! isset( $wp_actions[ $tag ] ) ) { + $wp_actions[ $tag ] = 1; + } else { + ++$wp_actions[ $tag ]; } - if ( !isset($wp_filter[$tag]) ) { - if ( isset($wp_filter['all']) ) - array_pop($wp_current_filter); + // Do 'all' actions first + if ( isset( $wp_filter['all'] ) ) { + $wp_current_filter[] = $tag; + $all_args = func_get_args(); + _wp_call_all_hook( $all_args ); + } + + if ( ! isset( $wp_filter[ $tag ] ) ) { + if ( isset( $wp_filter['all'] ) ) { + array_pop( $wp_current_filter ); + } return; } - if ( !isset($wp_filter['all']) ) + if ( ! isset( $wp_filter['all'] ) ) { $wp_current_filter[] = $tag; + } $args = array(); - if ( is_array($arg) && 1 == count($arg) && isset($arg[0]) && is_object($arg[0]) ) // array(&$this) + if ( is_array( $arg ) && 1 == count( $arg ) && isset( $arg[0] ) && is_object( $arg[0] ) ) { // array(&$this) $args[] =& $arg[0]; - else + } else { $args[] = $arg; - for ( $a = 2, $num = func_num_args(); $a < $num; $a++ ) - $args[] = func_get_arg($a); + } + for ( $a = 2, $num = func_num_args(); $a < $num; $a++ ) { + $args[] = func_get_arg( $a ); + } $wp_filter[ $tag ]->do_action( $args ); - array_pop($wp_current_filter); + array_pop( $wp_current_filter ); } /** @@ -465,13 +477,14 @@ function do_action($tag, $arg = '') { * @param string $tag The name of the action hook. * @return int The number of times action hook $tag is fired. */ -function did_action($tag) { +function did_action( $tag ) { global $wp_actions; - if ( ! isset( $wp_actions[ $tag ] ) ) + if ( ! isset( $wp_actions[ $tag ] ) ) { return 0; + } - return $wp_actions[$tag]; + return $wp_actions[ $tag ]; } /** @@ -488,33 +501,36 @@ function did_action($tag) { * @param string $tag The name of the action to be executed. * @param array $args The arguments supplied to the functions hooked to `$tag`. */ -function do_action_ref_array($tag, $args) { +function do_action_ref_array( $tag, $args ) { global $wp_filter, $wp_actions, $wp_current_filter; - if ( ! isset($wp_actions[$tag]) ) - $wp_actions[$tag] = 1; - else - ++$wp_actions[$tag]; - - // Do 'all' actions first - if ( isset($wp_filter['all']) ) { - $wp_current_filter[] = $tag; - $all_args = func_get_args(); - _wp_call_all_hook($all_args); + if ( ! isset( $wp_actions[ $tag ] ) ) { + $wp_actions[ $tag ] = 1; + } else { + ++$wp_actions[ $tag ]; } - if ( !isset($wp_filter[$tag]) ) { - if ( isset($wp_filter['all']) ) - array_pop($wp_current_filter); + // Do 'all' actions first + if ( isset( $wp_filter['all'] ) ) { + $wp_current_filter[] = $tag; + $all_args = func_get_args(); + _wp_call_all_hook( $all_args ); + } + + if ( ! isset( $wp_filter[ $tag ] ) ) { + if ( isset( $wp_filter['all'] ) ) { + array_pop( $wp_current_filter ); + } return; } - if ( !isset($wp_filter['all']) ) + if ( ! isset( $wp_filter['all'] ) ) { $wp_current_filter[] = $tag; + } $wp_filter[ $tag ]->do_action( $args ); - array_pop($wp_current_filter); + array_pop( $wp_current_filter ); } /** @@ -533,8 +549,8 @@ function do_action_ref_array($tag, $args) { * that evaluates to false (e.g.) 0, so use the === operator for testing the * return value. */ -function has_action($tag, $function_to_check = false) { - return has_filter($tag, $function_to_check); +function has_action( $tag, $function_to_check = false ) { + return has_filter( $tag, $function_to_check ); } /** @@ -564,8 +580,8 @@ function remove_action( $tag, $function_to_remove, $priority = 10 ) { * @param int|bool $priority The priority number to remove them from. Default false. * @return true True when finished. */ -function remove_all_actions($tag, $priority = false) { - return remove_all_filters($tag, $priority); +function remove_all_actions( $tag, $priority = false ) { + return remove_all_filters( $tag, $priority ); } /** @@ -660,11 +676,11 @@ function plugin_basename( $file ) { } } - $plugin_dir = wp_normalize_path( WP_PLUGIN_DIR ); + $plugin_dir = wp_normalize_path( WP_PLUGIN_DIR ); $mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR ); - $file = preg_replace('#^' . preg_quote($plugin_dir, '#') . '/|^' . preg_quote($mu_plugin_dir, '#') . '/#','',$file); // get relative path from plugins dir - $file = trim($file, '/'); + $file = preg_replace( '#^' . preg_quote( $plugin_dir, '#' ) . '/|^' . preg_quote( $mu_plugin_dir, '#' ) . '/#', '', $file ); // get relative path from plugins dir + $file = trim( $file, '/' ); return $file; } @@ -691,11 +707,11 @@ function wp_register_plugin_realpath( $file ) { // Normalize, but store as static to avoid recalculation of a constant value static $wp_plugin_path = null, $wpmu_plugin_path = null; if ( ! isset( $wp_plugin_path ) ) { - $wp_plugin_path = wp_normalize_path( WP_PLUGIN_DIR ); + $wp_plugin_path = wp_normalize_path( WP_PLUGIN_DIR ); $wpmu_plugin_path = wp_normalize_path( WPMU_PLUGIN_DIR ); } - $plugin_path = wp_normalize_path( dirname( $file ) ); + $plugin_path = wp_normalize_path( dirname( $file ) ); $plugin_realpath = wp_normalize_path( dirname( realpath( $file ) ) ); if ( $plugin_path === $wp_plugin_path || $plugin_path === $wpmu_plugin_path ) { @@ -751,9 +767,9 @@ function plugin_dir_url( $file ) { * @param string $file The filename of the plugin including the path. * @param callable $function The function hooked to the 'activate_PLUGIN' action. */ -function register_activation_hook($file, $function) { - $file = plugin_basename($file); - add_action('activate_' . $file, $function); +function register_activation_hook( $file, $function ) { + $file = plugin_basename( $file ); + add_action( 'activate_' . $file, $function ); } /** @@ -774,9 +790,9 @@ function register_activation_hook($file, $function) { * @param string $file The filename of the plugin including the path. * @param callable $function The function hooked to the 'deactivate_PLUGIN' action. */ -function register_deactivation_hook($file, $function) { - $file = plugin_basename($file); - add_action('deactivate_' . $file, $function); +function register_deactivation_hook( $file, $function ) { + $file = plugin_basename( $file ); + add_action( 'deactivate_' . $file, $function ); } /** @@ -816,10 +832,10 @@ function register_uninstall_hook( $file, $callback ) { * cases. Emphasis should be put on using the 'uninstall.php' way of * uninstalling the plugin. */ - $uninstallable_plugins = (array) get_option('uninstall_plugins'); - $uninstallable_plugins[plugin_basename($file)] = $callback; + $uninstallable_plugins = (array) get_option( 'uninstall_plugins' ); + $uninstallable_plugins[ plugin_basename( $file ) ] = $callback; - update_option('uninstall_plugins', $uninstallable_plugins); + update_option( 'uninstall_plugins', $uninstallable_plugins ); } /** @@ -840,7 +856,7 @@ function register_uninstall_hook( $file, $callback ) { * * @param array $args The collected parameters from the hook that was called. */ -function _wp_call_all_hook($args) { +function _wp_call_all_hook( $args ) { global $wp_filter; $wp_filter['all']->do_all_hook( $args ); @@ -880,30 +896,32 @@ function _wp_call_all_hook($args) { * and $function is an object reference, and it does not already have * a unique id. */ -function _wp_filter_build_unique_id($tag, $function, $priority) { +function _wp_filter_build_unique_id( $tag, $function, $priority ) { global $wp_filter; static $filter_id_count = 0; - if ( is_string($function) ) + if ( is_string( $function ) ) { return $function; + } - if ( is_object($function) ) { + if ( is_object( $function ) ) { // Closures are currently implemented as objects $function = array( $function, '' ); } else { $function = (array) $function; } - if (is_object($function[0]) ) { + if ( is_object( $function[0] ) ) { // Object Class Calling - if ( function_exists('spl_object_hash') ) { - return spl_object_hash($function[0]) . $function[1]; + if ( function_exists( 'spl_object_hash' ) ) { + return spl_object_hash( $function[0] ) . $function[1]; } else { - $obj_idx = get_class($function[0]).$function[1]; - if ( !isset($function[0]->wp_filter_id) ) { - if ( false === $priority ) + $obj_idx = get_class( $function[0] ) . $function[1]; + if ( ! isset( $function[0]->wp_filter_id ) ) { + if ( false === $priority ) { return false; - $obj_idx .= isset($wp_filter[$tag][$priority]) ? count((array)$wp_filter[$tag][$priority]) : $filter_id_count; + } + $obj_idx .= isset( $wp_filter[ $tag ][ $priority ] ) ? count( (array) $wp_filter[ $tag ][ $priority ] ) : $filter_id_count; $function[0]->wp_filter_id = $filter_id_count; ++$filter_id_count; } else { diff --git a/wp-includes/pomo/entry.php b/wp-includes/pomo/entry.php index 788092ba4b..a750a944a9 100644 --- a/wp-includes/pomo/entry.php +++ b/wp-includes/pomo/entry.php @@ -7,87 +7,97 @@ * @subpackage entry */ -if ( ! class_exists( 'Translation_Entry', false ) ): -/** - * Translation_Entry class encapsulates a translatable string - */ -class Translation_Entry { - +if ( ! class_exists( 'Translation_Entry', false ) ) : /** - * Whether the entry contains a string and its plural form, default is false - * - * @var boolean + * Translation_Entry class encapsulates a translatable string */ - var $is_plural = false; + class Translation_Entry { - var $context = null; - var $singular = null; - var $plural = null; - var $translations = array(); - var $translator_comments = ''; - var $extracted_comments = ''; - var $references = array(); - var $flags = array(); + /** + * Whether the entry contains a string and its plural form, default is false + * + * @var boolean + */ + var $is_plural = false; - /** - * @param array $args associative array, support following keys: - * - singular (string) -- the string to translate, if omitted and empty entry will be created - * - plural (string) -- the plural form of the string, setting this will set {@link $is_plural} to true - * - translations (array) -- translations of the string and possibly -- its plural forms - * - context (string) -- a string differentiating two equal strings used in different contexts - * - translator_comments (string) -- comments left by translators - * - extracted_comments (string) -- comments left by developers - * - references (array) -- places in the code this strings is used, in relative_to_root_path/file.php:linenum form - * - flags (array) -- flags like php-format - */ - function __construct( $args = array() ) { - // if no singular -- empty object - if (!isset($args['singular'])) { - return; - } - // get member variable values from args hash - foreach ($args as $varname => $value) { - $this->$varname = $value; - } - if (isset($args['plural']) && $args['plural']) $this->is_plural = true; - if (!is_array($this->translations)) $this->translations = array(); - if (!is_array($this->references)) $this->references = array(); - if (!is_array($this->flags)) $this->flags = array(); - } + var $context = null; + var $singular = null; + var $plural = null; + var $translations = array(); + var $translator_comments = ''; + var $extracted_comments = ''; + var $references = array(); + var $flags = array(); - /** - * PHP4 constructor. - */ - public function Translation_Entry( $args = array() ) { - self::__construct( $args ); - } - - /** - * Generates a unique key for this entry - * - * @return string|bool the key or false if the entry is empty - */ - function key() { - if ( null === $this->singular || '' === $this->singular ) return false; - - // Prepend context and EOT, like in MO files - $key = !$this->context? $this->singular : $this->context.chr(4).$this->singular; - // Standardize on \n line endings - $key = str_replace( array( "\r\n", "\r" ), "\n", $key ); - - return $key; - } - - /** - * @param object $other - */ - function merge_with(&$other) { - $this->flags = array_unique( array_merge( $this->flags, $other->flags ) ); - $this->references = array_unique( array_merge( $this->references, $other->references ) ); - if ( $this->extracted_comments != $other->extracted_comments ) { - $this->extracted_comments .= $other->extracted_comments; + /** + * @param array $args associative array, support following keys: + * - singular (string) -- the string to translate, if omitted and empty entry will be created + * - plural (string) -- the plural form of the string, setting this will set {@link $is_plural} to true + * - translations (array) -- translations of the string and possibly -- its plural forms + * - context (string) -- a string differentiating two equal strings used in different contexts + * - translator_comments (string) -- comments left by translators + * - extracted_comments (string) -- comments left by developers + * - references (array) -- places in the code this strings is used, in relative_to_root_path/file.php:linenum form + * - flags (array) -- flags like php-format + */ + function __construct( $args = array() ) { + // if no singular -- empty object + if ( ! isset( $args['singular'] ) ) { + return; + } + // get member variable values from args hash + foreach ( $args as $varname => $value ) { + $this->$varname = $value; + } + if ( isset( $args['plural'] ) && $args['plural'] ) { + $this->is_plural = true; + } + if ( ! is_array( $this->translations ) ) { + $this->translations = array(); + } + if ( ! is_array( $this->references ) ) { + $this->references = array(); + } + if ( ! is_array( $this->flags ) ) { + $this->flags = array(); + } } + /** + * PHP4 constructor. + */ + public function Translation_Entry( $args = array() ) { + self::__construct( $args ); + } + + /** + * Generates a unique key for this entry + * + * @return string|bool the key or false if the entry is empty + */ + function key() { + if ( null === $this->singular || '' === $this->singular ) { + return false; + } + + // Prepend context and EOT, like in MO files + $key = ! $this->context ? $this->singular : $this->context . chr( 4 ) . $this->singular; + // Standardize on \n line endings + $key = str_replace( array( "\r\n", "\r" ), "\n", $key ); + + return $key; + } + + /** + * @param object $other + */ + function merge_with( &$other ) { + $this->flags = array_unique( array_merge( $this->flags, $other->flags ) ); + $this->references = array_unique( array_merge( $this->references, $other->references ) ); + if ( $this->extracted_comments != $other->extracted_comments ) { + $this->extracted_comments .= $other->extracted_comments; + } + + } } -} -endif; \ No newline at end of file +endif; diff --git a/wp-includes/pomo/mo.php b/wp-includes/pomo/mo.php index 47e9b6afe4..6ec35245b9 100644 --- a/wp-includes/pomo/mo.php +++ b/wp-includes/pomo/mo.php @@ -7,317 +7,333 @@ * @subpackage mo */ -require_once dirname(__FILE__) . '/translations.php'; -require_once dirname(__FILE__) . '/streams.php'; +require_once dirname( __FILE__ ) . '/translations.php'; +require_once dirname( __FILE__ ) . '/streams.php'; -if ( ! class_exists( 'MO', false ) ): -class MO extends Gettext_Translations { +if ( ! class_exists( 'MO', false ) ) : + class MO extends Gettext_Translations { - var $_nplurals = 2; + var $_nplurals = 2; - /** - * Loaded MO file. - * - * @var string - */ - private $filename = ''; + /** + * Loaded MO file. + * + * @var string + */ + private $filename = ''; - /** - * Returns the loaded MO file. - * - * @return string The loaded MO file. - */ - public function get_filename() { - return $this->filename; - } - - /** - * Fills up with the entries from MO file $filename - * - * @param string $filename MO file to load - */ - function import_from_file($filename) { - $reader = new POMO_FileReader( $filename ); - - if ( ! $reader->is_resource() ) { - return false; + /** + * Returns the loaded MO file. + * + * @return string The loaded MO file. + */ + public function get_filename() { + return $this->filename; } - $this->filename = (string) $filename; + /** + * Fills up with the entries from MO file $filename + * + * @param string $filename MO file to load + */ + function import_from_file( $filename ) { + $reader = new POMO_FileReader( $filename ); - return $this->import_from_reader( $reader ); - } + if ( ! $reader->is_resource() ) { + return false; + } - /** - * @param string $filename - * @return bool - */ - function export_to_file($filename) { - $fh = fopen($filename, 'wb'); - if ( !$fh ) return false; - $res = $this->export_to_file_handle( $fh ); - fclose($fh); - return $res; - } + $this->filename = (string) $filename; - /** - * @return string|false - */ - function export() { - $tmp_fh = fopen("php://temp", 'r+'); - if ( !$tmp_fh ) return false; - $this->export_to_file_handle( $tmp_fh ); - rewind( $tmp_fh ); - return stream_get_contents( $tmp_fh ); - } - - /** - * @param Translation_Entry $entry - * @return bool - */ - function is_entry_good_for_export( $entry ) { - if ( empty( $entry->translations ) ) { - return false; + return $this->import_from_reader( $reader ); } - if ( !array_filter( $entry->translations ) ) { - return false; + /** + * @param string $filename + * @return bool + */ + function export_to_file( $filename ) { + $fh = fopen( $filename, 'wb' ); + if ( ! $fh ) { + return false; + } + $res = $this->export_to_file_handle( $fh ); + fclose( $fh ); + return $res; } - return true; - } - - /** - * @param resource $fh - * @return true - */ - function export_to_file_handle($fh) { - $entries = array_filter( $this->entries, array( $this, 'is_entry_good_for_export' ) ); - ksort($entries); - $magic = 0x950412de; - $revision = 0; - $total = count($entries) + 1; // all the headers are one entry - $originals_lenghts_addr = 28; - $translations_lenghts_addr = $originals_lenghts_addr + 8 * $total; - $size_of_hash = 0; - $hash_addr = $translations_lenghts_addr + 8 * $total; - $current_addr = $hash_addr; - fwrite($fh, pack('V*', $magic, $revision, $total, $originals_lenghts_addr, - $translations_lenghts_addr, $size_of_hash, $hash_addr)); - fseek($fh, $originals_lenghts_addr); - - // headers' msgid is an empty string - fwrite($fh, pack('VV', 0, $current_addr)); - $current_addr++; - $originals_table = chr(0); - - $reader = new POMO_Reader(); - - foreach($entries as $entry) { - $originals_table .= $this->export_original($entry) . chr(0); - $length = $reader->strlen($this->export_original($entry)); - fwrite($fh, pack('VV', $length, $current_addr)); - $current_addr += $length + 1; // account for the NULL byte after + /** + * @return string|false + */ + function export() { + $tmp_fh = fopen( 'php://temp', 'r+' ); + if ( ! $tmp_fh ) { + return false; + } + $this->export_to_file_handle( $tmp_fh ); + rewind( $tmp_fh ); + return stream_get_contents( $tmp_fh ); } - $exported_headers = $this->export_headers(); - fwrite($fh, pack('VV', $reader->strlen($exported_headers), $current_addr)); - $current_addr += strlen($exported_headers) + 1; - $translations_table = $exported_headers . chr(0); + /** + * @param Translation_Entry $entry + * @return bool + */ + function is_entry_good_for_export( $entry ) { + if ( empty( $entry->translations ) ) { + return false; + } - foreach($entries as $entry) { - $translations_table .= $this->export_translations($entry) . chr(0); - $length = $reader->strlen($this->export_translations($entry)); - fwrite($fh, pack('VV', $length, $current_addr)); - $current_addr += $length + 1; + if ( ! array_filter( $entry->translations ) ) { + return false; + } + + return true; } - fwrite($fh, $originals_table); - fwrite($fh, $translations_table); - return true; - } + /** + * @param resource $fh + * @return true + */ + function export_to_file_handle( $fh ) { + $entries = array_filter( $this->entries, array( $this, 'is_entry_good_for_export' ) ); + ksort( $entries ); + $magic = 0x950412de; + $revision = 0; + $total = count( $entries ) + 1; // all the headers are one entry + $originals_lenghts_addr = 28; + $translations_lenghts_addr = $originals_lenghts_addr + 8 * $total; + $size_of_hash = 0; + $hash_addr = $translations_lenghts_addr + 8 * $total; + $current_addr = $hash_addr; + fwrite( + $fh, pack( + 'V*', $magic, $revision, $total, $originals_lenghts_addr, + $translations_lenghts_addr, $size_of_hash, $hash_addr + ) + ); + fseek( $fh, $originals_lenghts_addr ); - /** - * @param Translation_Entry $entry - * @return string - */ - function export_original($entry) { - //TODO: warnings for control characters - $exported = $entry->singular; - if ($entry->is_plural) $exported .= chr(0).$entry->plural; - if ($entry->context) $exported = $entry->context . chr(4) . $exported; - return $exported; - } + // headers' msgid is an empty string + fwrite( $fh, pack( 'VV', 0, $current_addr ) ); + $current_addr++; + $originals_table = chr( 0 ); - /** - * @param Translation_Entry $entry - * @return string - */ - function export_translations($entry) { - //TODO: warnings for control characters - return $entry->is_plural ? implode(chr(0), $entry->translations) : $entry->translations[0]; - } + $reader = new POMO_Reader(); - /** - * @return string - */ - function export_headers() { - $exported = ''; - foreach($this->headers as $header => $value) { - $exported.= "$header: $value\n"; - } - return $exported; - } + foreach ( $entries as $entry ) { + $originals_table .= $this->export_original( $entry ) . chr( 0 ); + $length = $reader->strlen( $this->export_original( $entry ) ); + fwrite( $fh, pack( 'VV', $length, $current_addr ) ); + $current_addr += $length + 1; // account for the NULL byte after + } - /** - * @param int $magic - * @return string|false - */ - function get_byteorder($magic) { - // The magic is 0x950412de + $exported_headers = $this->export_headers(); + fwrite( $fh, pack( 'VV', $reader->strlen( $exported_headers ), $current_addr ) ); + $current_addr += strlen( $exported_headers ) + 1; + $translations_table = $exported_headers . chr( 0 ); - // bug in PHP 5.0.2, see https://savannah.nongnu.org/bugs/?func=detailitem&item_id=10565 - $magic_little = (int) - 1794895138; - $magic_little_64 = (int) 2500072158; - // 0xde120495 - $magic_big = ((int) - 569244523) & 0xFFFFFFFF; - if ($magic_little == $magic || $magic_little_64 == $magic) { - return 'little'; - } else if ($magic_big == $magic) { - return 'big'; - } else { - return false; - } - } + foreach ( $entries as $entry ) { + $translations_table .= $this->export_translations( $entry ) . chr( 0 ); + $length = $reader->strlen( $this->export_translations( $entry ) ); + fwrite( $fh, pack( 'VV', $length, $current_addr ) ); + $current_addr += $length + 1; + } - /** - * @param POMO_FileReader $reader - */ - function import_from_reader($reader) { - $endian_string = MO::get_byteorder($reader->readint32()); - if (false === $endian_string) { - return false; - } - $reader->setEndian($endian_string); - - $endian = ('big' == $endian_string)? 'N' : 'V'; - - $header = $reader->read(24); - if ($reader->strlen($header) != 24) - return false; - - // parse header - $header = unpack("{$endian}revision/{$endian}total/{$endian}originals_lenghts_addr/{$endian}translations_lenghts_addr/{$endian}hash_length/{$endian}hash_addr", $header); - if (!is_array($header)) - return false; - - // support revision 0 of MO format specs, only - if ( $header['revision'] != 0 ) { - return false; + fwrite( $fh, $originals_table ); + fwrite( $fh, $translations_table ); + return true; } - // seek to data blocks - $reader->seekto( $header['originals_lenghts_addr'] ); - - // read originals' indices - $originals_lengths_length = $header['translations_lenghts_addr'] - $header['originals_lenghts_addr']; - if ( $originals_lengths_length != $header['total'] * 8 ) { - return false; + /** + * @param Translation_Entry $entry + * @return string + */ + function export_original( $entry ) { + //TODO: warnings for control characters + $exported = $entry->singular; + if ( $entry->is_plural ) { + $exported .= chr( 0 ) . $entry->plural; + } + if ( $entry->context ) { + $exported = $entry->context . chr( 4 ) . $exported; + } + return $exported; } - $originals = $reader->read($originals_lengths_length); - if ( $reader->strlen( $originals ) != $originals_lengths_length ) { - return false; + /** + * @param Translation_Entry $entry + * @return string + */ + function export_translations( $entry ) { + //TODO: warnings for control characters + return $entry->is_plural ? implode( chr( 0 ), $entry->translations ) : $entry->translations[0]; } - // read translations' indices - $translations_lenghts_length = $header['hash_addr'] - $header['translations_lenghts_addr']; - if ( $translations_lenghts_length != $header['total'] * 8 ) { - return false; + /** + * @return string + */ + function export_headers() { + $exported = ''; + foreach ( $this->headers as $header => $value ) { + $exported .= "$header: $value\n"; + } + return $exported; } - $translations = $reader->read($translations_lenghts_length); - if ( $reader->strlen( $translations ) != $translations_lenghts_length ) { - return false; - } + /** + * @param int $magic + * @return string|false + */ + function get_byteorder( $magic ) { + // The magic is 0x950412de - // transform raw data into set of indices - $originals = $reader->str_split( $originals, 8 ); - $translations = $reader->str_split( $translations, 8 ); - - // skip hash table - $strings_addr = $header['hash_addr'] + $header['hash_length'] * 4; - - $reader->seekto($strings_addr); - - $strings = $reader->read_all(); - $reader->close(); - - for ( $i = 0; $i < $header['total']; $i++ ) { - $o = unpack( "{$endian}length/{$endian}pos", $originals[$i] ); - $t = unpack( "{$endian}length/{$endian}pos", $translations[$i] ); - if ( !$o || !$t ) return false; - - // adjust offset due to reading strings to separate space before - $o['pos'] -= $strings_addr; - $t['pos'] -= $strings_addr; - - $original = $reader->substr( $strings, $o['pos'], $o['length'] ); - $translation = $reader->substr( $strings, $t['pos'], $t['length'] ); - - if ('' === $original) { - $this->set_headers($this->make_headers($translation)); + // bug in PHP 5.0.2, see https://savannah.nongnu.org/bugs/?func=detailitem&item_id=10565 + $magic_little = (int) - 1794895138; + $magic_little_64 = (int) 2500072158; + // 0xde120495 + $magic_big = ( (int) - 569244523 ) & 0xFFFFFFFF; + if ( $magic_little == $magic || $magic_little_64 == $magic ) { + return 'little'; + } elseif ( $magic_big == $magic ) { + return 'big'; } else { - $entry = &$this->make_entry($original, $translation); - $this->entries[$entry->key()] = &$entry; + return false; } } - return true; - } - /** - * Build a Translation_Entry from original string and translation strings, - * found in a MO file - * - * @static - * @param string $original original string to translate from MO file. Might contain - * 0x04 as context separator or 0x00 as singular/plural separator - * @param string $translation translation string from MO file. Might contain - * 0x00 as a plural translations separator - */ - function &make_entry($original, $translation) { - $entry = new Translation_Entry(); - // look for context - $parts = explode(chr(4), $original); - if (isset($parts[1])) { - $original = $parts[1]; - $entry->context = $parts[0]; + /** + * @param POMO_FileReader $reader + */ + function import_from_reader( $reader ) { + $endian_string = MO::get_byteorder( $reader->readint32() ); + if ( false === $endian_string ) { + return false; + } + $reader->setEndian( $endian_string ); + + $endian = ( 'big' == $endian_string ) ? 'N' : 'V'; + + $header = $reader->read( 24 ); + if ( $reader->strlen( $header ) != 24 ) { + return false; + } + + // parse header + $header = unpack( "{$endian}revision/{$endian}total/{$endian}originals_lenghts_addr/{$endian}translations_lenghts_addr/{$endian}hash_length/{$endian}hash_addr", $header ); + if ( ! is_array( $header ) ) { + return false; + } + + // support revision 0 of MO format specs, only + if ( $header['revision'] != 0 ) { + return false; + } + + // seek to data blocks + $reader->seekto( $header['originals_lenghts_addr'] ); + + // read originals' indices + $originals_lengths_length = $header['translations_lenghts_addr'] - $header['originals_lenghts_addr']; + if ( $originals_lengths_length != $header['total'] * 8 ) { + return false; + } + + $originals = $reader->read( $originals_lengths_length ); + if ( $reader->strlen( $originals ) != $originals_lengths_length ) { + return false; + } + + // read translations' indices + $translations_lenghts_length = $header['hash_addr'] - $header['translations_lenghts_addr']; + if ( $translations_lenghts_length != $header['total'] * 8 ) { + return false; + } + + $translations = $reader->read( $translations_lenghts_length ); + if ( $reader->strlen( $translations ) != $translations_lenghts_length ) { + return false; + } + + // transform raw data into set of indices + $originals = $reader->str_split( $originals, 8 ); + $translations = $reader->str_split( $translations, 8 ); + + // skip hash table + $strings_addr = $header['hash_addr'] + $header['hash_length'] * 4; + + $reader->seekto( $strings_addr ); + + $strings = $reader->read_all(); + $reader->close(); + + for ( $i = 0; $i < $header['total']; $i++ ) { + $o = unpack( "{$endian}length/{$endian}pos", $originals[ $i ] ); + $t = unpack( "{$endian}length/{$endian}pos", $translations[ $i ] ); + if ( ! $o || ! $t ) { + return false; + } + + // adjust offset due to reading strings to separate space before + $o['pos'] -= $strings_addr; + $t['pos'] -= $strings_addr; + + $original = $reader->substr( $strings, $o['pos'], $o['length'] ); + $translation = $reader->substr( $strings, $t['pos'], $t['length'] ); + + if ( '' === $original ) { + $this->set_headers( $this->make_headers( $translation ) ); + } else { + $entry = &$this->make_entry( $original, $translation ); + $this->entries[ $entry->key() ] = &$entry; + } + } + return true; } - // look for plural original - $parts = explode(chr(0), $original); - $entry->singular = $parts[0]; - if (isset($parts[1])) { - $entry->is_plural = true; - $entry->plural = $parts[1]; + + /** + * Build a Translation_Entry from original string and translation strings, + * found in a MO file + * + * @static + * @param string $original original string to translate from MO file. Might contain + * 0x04 as context separator or 0x00 as singular/plural separator + * @param string $translation translation string from MO file. Might contain + * 0x00 as a plural translations separator + */ + function &make_entry( $original, $translation ) { + $entry = new Translation_Entry(); + // look for context + $parts = explode( chr( 4 ), $original ); + if ( isset( $parts[1] ) ) { + $original = $parts[1]; + $entry->context = $parts[0]; + } + // look for plural original + $parts = explode( chr( 0 ), $original ); + $entry->singular = $parts[0]; + if ( isset( $parts[1] ) ) { + $entry->is_plural = true; + $entry->plural = $parts[1]; + } + // plural translations are also separated by \0 + $entry->translations = explode( chr( 0 ), $translation ); + return $entry; } - // plural translations are also separated by \0 - $entry->translations = explode(chr(0), $translation); - return $entry; - } - /** - * @param int $count - * @return string - */ - function select_plural_form($count) { - return $this->gettext_select_plural_form($count); - } + /** + * @param int $count + * @return string + */ + function select_plural_form( $count ) { + return $this->gettext_select_plural_form( $count ); + } - /** - * @return int - */ - function get_plural_forms_count() { - return $this->_nplurals; + /** + * @return int + */ + function get_plural_forms_count() { + return $this->_nplurals; + } } -} endif; diff --git a/wp-includes/pomo/plural-forms.php b/wp-includes/pomo/plural-forms.php index a41c659598..cabc807180 100644 --- a/wp-includes/pomo/plural-forms.php +++ b/wp-includes/pomo/plural-forms.php @@ -34,11 +34,11 @@ class Plural_Forms { * @var array $op_precedence Operator precedence from highest to lowest. */ protected static $op_precedence = array( - '%' => 6, + '%' => 6, - '<' => 5, + '<' => 5, '<=' => 5, - '>' => 5, + '>' => 5, '>=' => 5, '==' => 4, @@ -49,10 +49,10 @@ class Plural_Forms { '||' => 2, '?:' => 1, - '?' => 1, + '?' => 1, - '(' => 0, - ')' => 0, + '(' => 0, + ')' => 0, ); /** @@ -98,7 +98,7 @@ class Plural_Forms { // Convert infix operators to postfix using the shunting-yard algorithm. $output = array(); - $stack = array(); + $stack = array(); while ( $pos < $len ) { $next = substr( $str, $pos, 1 ); @@ -153,7 +153,7 @@ class Plural_Forms { case '%': case '?': $end_operator = strspn( $str, self::OP_CHARS, $pos ); - $operator = substr( $str, $pos, $end_operator ); + $operator = substr( $str, $pos, $end_operator ); if ( ! array_key_exists( $operator, self::$op_precedence ) ) { throw new Exception( sprintf( 'Unknown operator "%s"', $operator ) ); } @@ -191,7 +191,7 @@ class Plural_Forms { // Replace. $stack[ $s_pos ] = '?:'; - $found = true; + $found = true; break; } @@ -204,9 +204,9 @@ class Plural_Forms { // Default - number or invalid default: if ( $next >= '0' && $next <= '9' ) { - $span = strspn( $str, self::NUM_CHARS, $pos ); + $span = strspn( $str, self::NUM_CHARS, $pos ); $output[] = array( 'value', intval( substr( $str, $pos, $span ) ) ); - $pos += $span; + $pos += $span; continue; } @@ -253,10 +253,10 @@ class Plural_Forms { */ public function execute( $n ) { $stack = array(); - $i = 0; + $i = 0; $total = count( $this->tokens ); while ( $i < $total ) { - $next = $this->tokens[$i]; + $next = $this->tokens[ $i ]; $i++; if ( $next[0] === 'var' ) { $stack[] = $n; @@ -269,63 +269,63 @@ class Plural_Forms { // Only operators left. switch ( $next[1] ) { case '%': - $v2 = array_pop( $stack ); - $v1 = array_pop( $stack ); + $v2 = array_pop( $stack ); + $v1 = array_pop( $stack ); $stack[] = $v1 % $v2; break; case '||': - $v2 = array_pop( $stack ); - $v1 = array_pop( $stack ); + $v2 = array_pop( $stack ); + $v1 = array_pop( $stack ); $stack[] = $v1 || $v2; break; case '&&': - $v2 = array_pop( $stack ); - $v1 = array_pop( $stack ); + $v2 = array_pop( $stack ); + $v1 = array_pop( $stack ); $stack[] = $v1 && $v2; break; case '<': - $v2 = array_pop( $stack ); - $v1 = array_pop( $stack ); + $v2 = array_pop( $stack ); + $v1 = array_pop( $stack ); $stack[] = $v1 < $v2; break; case '<=': - $v2 = array_pop( $stack ); - $v1 = array_pop( $stack ); + $v2 = array_pop( $stack ); + $v1 = array_pop( $stack ); $stack[] = $v1 <= $v2; break; case '>': - $v2 = array_pop( $stack ); - $v1 = array_pop( $stack ); + $v2 = array_pop( $stack ); + $v1 = array_pop( $stack ); $stack[] = $v1 > $v2; break; case '>=': - $v2 = array_pop( $stack ); - $v1 = array_pop( $stack ); + $v2 = array_pop( $stack ); + $v1 = array_pop( $stack ); $stack[] = $v1 >= $v2; break; case '!=': - $v2 = array_pop( $stack ); - $v1 = array_pop( $stack ); + $v2 = array_pop( $stack ); + $v1 = array_pop( $stack ); $stack[] = $v1 != $v2; break; case '==': - $v2 = array_pop( $stack ); - $v1 = array_pop( $stack ); + $v2 = array_pop( $stack ); + $v1 = array_pop( $stack ); $stack[] = $v1 == $v2; break; case '?:': - $v3 = array_pop( $stack ); - $v2 = array_pop( $stack ); - $v1 = array_pop( $stack ); + $v3 = array_pop( $stack ); + $v2 = array_pop( $stack ); + $v1 = array_pop( $stack ); $stack[] = $v1 ? $v2 : $v3; break; diff --git a/wp-includes/pomo/po.php b/wp-includes/pomo/po.php index 98e0760d19..17e1d71f83 100644 --- a/wp-includes/pomo/po.php +++ b/wp-includes/pomo/po.php @@ -7,463 +7,506 @@ * @subpackage po */ -require_once dirname(__FILE__) . '/translations.php'; +require_once dirname( __FILE__ ) . '/translations.php'; if ( ! defined( 'PO_MAX_LINE_LEN' ) ) { - define('PO_MAX_LINE_LEN', 79); + define( 'PO_MAX_LINE_LEN', 79 ); } -ini_set('auto_detect_line_endings', 1); +ini_set( 'auto_detect_line_endings', 1 ); /** * Routines for working with PO files */ -if ( ! class_exists( 'PO', false ) ): -class PO extends Gettext_Translations { +if ( ! class_exists( 'PO', false ) ) : + class PO extends Gettext_Translations { - var $comments_before_headers = ''; + var $comments_before_headers = ''; - /** - * Exports headers to a PO entry - * - * @return string msgid/msgstr PO entry for this PO file headers, doesn't contain newline at the end - */ - function export_headers() { - $header_string = ''; - foreach($this->headers as $header => $value) { - $header_string.= "$header: $value\n"; + /** + * Exports headers to a PO entry + * + * @return string msgid/msgstr PO entry for this PO file headers, doesn't contain newline at the end + */ + function export_headers() { + $header_string = ''; + foreach ( $this->headers as $header => $value ) { + $header_string .= "$header: $value\n"; + } + $poified = PO::poify( $header_string ); + if ( $this->comments_before_headers ) { + $before_headers = $this->prepend_each_line( rtrim( $this->comments_before_headers ) . "\n", '# ' ); + } else { + $before_headers = ''; + } + return rtrim( "{$before_headers}msgid \"\"\nmsgstr $poified" ); } - $poified = PO::poify($header_string); - if ($this->comments_before_headers) - $before_headers = $this->prepend_each_line(rtrim($this->comments_before_headers)."\n", '# '); - else - $before_headers = ''; - return rtrim("{$before_headers}msgid \"\"\nmsgstr $poified"); - } - /** - * Exports all entries to PO format - * - * @return string sequence of mgsgid/msgstr PO strings, doesn't containt newline at the end - */ - function export_entries() { - //TODO sorting - return implode("\n\n", array_map(array('PO', 'export_entry'), $this->entries)); - } - - /** - * Exports the whole PO file as a string - * - * @param bool $include_headers whether to include the headers in the export - * @return string ready for inclusion in PO file string for headers and all the enrtries - */ - function export($include_headers = true) { - $res = ''; - if ($include_headers) { - $res .= $this->export_headers(); - $res .= "\n\n"; + /** + * Exports all entries to PO format + * + * @return string sequence of mgsgid/msgstr PO strings, doesn't containt newline at the end + */ + function export_entries() { + //TODO sorting + return implode( "\n\n", array_map( array( 'PO', 'export_entry' ), $this->entries ) ); } - $res .= $this->export_entries(); - return $res; - } - /** - * Same as {@link export}, but writes the result to a file - * - * @param string $filename where to write the PO string - * @param bool $include_headers whether to include tje headers in the export - * @return bool true on success, false on error - */ - function export_to_file($filename, $include_headers = true) { - $fh = fopen($filename, 'w'); - if (false === $fh) return false; - $export = $this->export($include_headers); - $res = fwrite($fh, $export); - if (false === $res) return false; - return fclose($fh); - } - - /** - * Text to include as a comment before the start of the PO contents - * - * Doesn't need to include # in the beginning of lines, these are added automatically - */ - function set_comment_before_headers( $text ) { - $this->comments_before_headers = $text; - } - - /** - * Formats a string in PO-style - * - * @static - * @param string $string the string to format - * @return string the poified string - */ - public static function poify($string) { - $quote = '"'; - $slash = '\\'; - $newline = "\n"; - - $replaces = array( - "$slash" => "$slash$slash", - "$quote" => "$slash$quote", - "\t" => '\t', - ); - - $string = str_replace(array_keys($replaces), array_values($replaces), $string); - - $po = $quote.implode("${slash}n$quote$newline$quote", explode($newline, $string)).$quote; - // add empty string on first line for readbility - if (false !== strpos($string, $newline) && - (substr_count($string, $newline) > 1 || !($newline === substr($string, -strlen($newline))))) { - $po = "$quote$quote$newline$po"; + /** + * Exports the whole PO file as a string + * + * @param bool $include_headers whether to include the headers in the export + * @return string ready for inclusion in PO file string for headers and all the enrtries + */ + function export( $include_headers = true ) { + $res = ''; + if ( $include_headers ) { + $res .= $this->export_headers(); + $res .= "\n\n"; + } + $res .= $this->export_entries(); + return $res; } - // remove empty strings - $po = str_replace("$newline$quote$quote", '', $po); - return $po; - } - /** - * Gives back the original string from a PO-formatted string - * - * @static - * @param string $string PO-formatted string - * @return string enascaped string - */ - public static function unpoify($string) { - $escapes = array('t' => "\t", 'n' => "\n", 'r' => "\r", '\\' => '\\'); - $lines = array_map('trim', explode("\n", $string)); - $lines = array_map(array('PO', 'trim_quotes'), $lines); - $unpoified = ''; - $previous_is_backslash = false; - foreach($lines as $line) { - preg_match_all('/./u', $line, $chars); - $chars = $chars[0]; - foreach($chars as $char) { - if (!$previous_is_backslash) { - if ('\\' == $char) - $previous_is_backslash = true; - else - $unpoified .= $char; - } else { - $previous_is_backslash = false; - $unpoified .= isset($escapes[$char])? $escapes[$char] : $char; + /** + * Same as {@link export}, but writes the result to a file + * + * @param string $filename where to write the PO string + * @param bool $include_headers whether to include tje headers in the export + * @return bool true on success, false on error + */ + function export_to_file( $filename, $include_headers = true ) { + $fh = fopen( $filename, 'w' ); + if ( false === $fh ) { + return false; + } + $export = $this->export( $include_headers ); + $res = fwrite( $fh, $export ); + if ( false === $res ) { + return false; + } + return fclose( $fh ); + } + + /** + * Text to include as a comment before the start of the PO contents + * + * Doesn't need to include # in the beginning of lines, these are added automatically + */ + function set_comment_before_headers( $text ) { + $this->comments_before_headers = $text; + } + + /** + * Formats a string in PO-style + * + * @static + * @param string $string the string to format + * @return string the poified string + */ + public static function poify( $string ) { + $quote = '"'; + $slash = '\\'; + $newline = "\n"; + + $replaces = array( + "$slash" => "$slash$slash", + "$quote" => "$slash$quote", + "\t" => '\t', + ); + + $string = str_replace( array_keys( $replaces ), array_values( $replaces ), $string ); + + $po = $quote . implode( "${slash}n$quote$newline$quote", explode( $newline, $string ) ) . $quote; + // add empty string on first line for readbility + if ( false !== strpos( $string, $newline ) && + ( substr_count( $string, $newline ) > 1 || ! ( $newline === substr( $string, -strlen( $newline ) ) ) ) ) { + $po = "$quote$quote$newline$po"; + } + // remove empty strings + $po = str_replace( "$newline$quote$quote", '', $po ); + return $po; + } + + /** + * Gives back the original string from a PO-formatted string + * + * @static + * @param string $string PO-formatted string + * @return string enascaped string + */ + public static function unpoify( $string ) { + $escapes = array( + 't' => "\t", + 'n' => "\n", + 'r' => "\r", + '\\' => '\\', + ); + $lines = array_map( 'trim', explode( "\n", $string ) ); + $lines = array_map( array( 'PO', 'trim_quotes' ), $lines ); + $unpoified = ''; + $previous_is_backslash = false; + foreach ( $lines as $line ) { + preg_match_all( '/./u', $line, $chars ); + $chars = $chars[0]; + foreach ( $chars as $char ) { + if ( ! $previous_is_backslash ) { + if ( '\\' == $char ) { + $previous_is_backslash = true; + } else { + $unpoified .= $char; + } + } else { + $previous_is_backslash = false; + $unpoified .= isset( $escapes[ $char ] ) ? $escapes[ $char ] : $char; + } } } + + // Standardise the line endings on imported content, technically PO files shouldn't contain \r + $unpoified = str_replace( array( "\r\n", "\r" ), "\n", $unpoified ); + + return $unpoified; } - // Standardise the line endings on imported content, technically PO files shouldn't contain \r - $unpoified = str_replace( array( "\r\n", "\r" ), "\n", $unpoified ); - - return $unpoified; - } - - /** - * Inserts $with in the beginning of every new line of $string and - * returns the modified string - * - * @static - * @param string $string prepend lines in this string - * @param string $with prepend lines with this string - */ - public static function prepend_each_line($string, $with) { - $lines = explode("\n", $string); - $append = ''; - if ("\n" === substr($string, -1) && '' === end($lines)) { - // Last line might be empty because $string was terminated - // with a newline, remove it from the $lines array, - // we'll restore state by re-terminating the string at the end - array_pop($lines); - $append = "\n"; - } - foreach ($lines as &$line) { - $line = $with . $line; - } - unset($line); - return implode("\n", $lines) . $append; - } - - /** - * Prepare a text as a comment -- wraps the lines and prepends # - * and a special character to each line - * - * @access private - * @param string $text the comment text - * @param string $char character to denote a special PO comment, - * like :, default is a space - */ - public static function comment_block($text, $char=' ') { - $text = wordwrap($text, PO_MAX_LINE_LEN - 3); - return PO::prepend_each_line($text, "#$char "); - } - - /** - * Builds a string from the entry for inclusion in PO file - * - * @static - * @param Translation_Entry $entry the entry to convert to po string (passed by reference). - * @return false|string PO-style formatted string for the entry or - * false if the entry is empty - */ - public static function export_entry(&$entry) { - if ( null === $entry->singular || '' === $entry->singular ) return false; - $po = array(); - if (!empty($entry->translator_comments)) $po[] = PO::comment_block($entry->translator_comments); - if (!empty($entry->extracted_comments)) $po[] = PO::comment_block($entry->extracted_comments, '.'); - if (!empty($entry->references)) $po[] = PO::comment_block(implode(' ', $entry->references), ':'); - if (!empty($entry->flags)) $po[] = PO::comment_block(implode(", ", $entry->flags), ','); - if ($entry->context) $po[] = 'msgctxt '.PO::poify($entry->context); - $po[] = 'msgid '.PO::poify($entry->singular); - if (!$entry->is_plural) { - $translation = empty($entry->translations)? '' : $entry->translations[0]; - $translation = PO::match_begin_and_end_newlines( $translation, $entry->singular ); - $po[] = 'msgstr '.PO::poify($translation); - } else { - $po[] = 'msgid_plural '.PO::poify($entry->plural); - $translations = empty($entry->translations)? array('', '') : $entry->translations; - foreach($translations as $i => $translation) { - $translation = PO::match_begin_and_end_newlines( $translation, $entry->plural ); - $po[] = "msgstr[$i] ".PO::poify($translation); + /** + * Inserts $with in the beginning of every new line of $string and + * returns the modified string + * + * @static + * @param string $string prepend lines in this string + * @param string $with prepend lines with this string + */ + public static function prepend_each_line( $string, $with ) { + $lines = explode( "\n", $string ); + $append = ''; + if ( "\n" === substr( $string, -1 ) && '' === end( $lines ) ) { + // Last line might be empty because $string was terminated + // with a newline, remove it from the $lines array, + // we'll restore state by re-terminating the string at the end + array_pop( $lines ); + $append = "\n"; } + foreach ( $lines as &$line ) { + $line = $with . $line; + } + unset( $line ); + return implode( "\n", $lines ) . $append; } - return implode("\n", $po); - } - public static function match_begin_and_end_newlines( $translation, $original ) { - if ( '' === $translation ) { + /** + * Prepare a text as a comment -- wraps the lines and prepends # + * and a special character to each line + * + * @access private + * @param string $text the comment text + * @param string $char character to denote a special PO comment, + * like :, default is a space + */ + public static function comment_block( $text, $char = ' ' ) { + $text = wordwrap( $text, PO_MAX_LINE_LEN - 3 ); + return PO::prepend_each_line( $text, "#$char " ); + } + + /** + * Builds a string from the entry for inclusion in PO file + * + * @static + * @param Translation_Entry $entry the entry to convert to po string (passed by reference). + * @return false|string PO-style formatted string for the entry or + * false if the entry is empty + */ + public static function export_entry( &$entry ) { + if ( null === $entry->singular || '' === $entry->singular ) { + return false; + } + $po = array(); + if ( ! empty( $entry->translator_comments ) ) { + $po[] = PO::comment_block( $entry->translator_comments ); + } + if ( ! empty( $entry->extracted_comments ) ) { + $po[] = PO::comment_block( $entry->extracted_comments, '.' ); + } + if ( ! empty( $entry->references ) ) { + $po[] = PO::comment_block( implode( ' ', $entry->references ), ':' ); + } + if ( ! empty( $entry->flags ) ) { + $po[] = PO::comment_block( implode( ', ', $entry->flags ), ',' ); + } + if ( $entry->context ) { + $po[] = 'msgctxt ' . PO::poify( $entry->context ); + } + $po[] = 'msgid ' . PO::poify( $entry->singular ); + if ( ! $entry->is_plural ) { + $translation = empty( $entry->translations ) ? '' : $entry->translations[0]; + $translation = PO::match_begin_and_end_newlines( $translation, $entry->singular ); + $po[] = 'msgstr ' . PO::poify( $translation ); + } else { + $po[] = 'msgid_plural ' . PO::poify( $entry->plural ); + $translations = empty( $entry->translations ) ? array( '', '' ) : $entry->translations; + foreach ( $translations as $i => $translation ) { + $translation = PO::match_begin_and_end_newlines( $translation, $entry->plural ); + $po[] = "msgstr[$i] " . PO::poify( $translation ); + } + } + return implode( "\n", $po ); + } + + public static function match_begin_and_end_newlines( $translation, $original ) { + if ( '' === $translation ) { + return $translation; + } + + $original_begin = "\n" === substr( $original, 0, 1 ); + $original_end = "\n" === substr( $original, -1 ); + $translation_begin = "\n" === substr( $translation, 0, 1 ); + $translation_end = "\n" === substr( $translation, -1 ); + + if ( $original_begin ) { + if ( ! $translation_begin ) { + $translation = "\n" . $translation; + } + } elseif ( $translation_begin ) { + $translation = ltrim( $translation, "\n" ); + } + + if ( $original_end ) { + if ( ! $translation_end ) { + $translation .= "\n"; + } + } elseif ( $translation_end ) { + $translation = rtrim( $translation, "\n" ); + } + return $translation; } - $original_begin = "\n" === substr( $original, 0, 1 ); - $original_end = "\n" === substr( $original, -1 ); - $translation_begin = "\n" === substr( $translation, 0, 1 ); - $translation_end = "\n" === substr( $translation, -1 ); - - if ( $original_begin ) { - if ( ! $translation_begin ) { - $translation = "\n" . $translation; + /** + * @param string $filename + * @return boolean + */ + function import_from_file( $filename ) { + $f = fopen( $filename, 'r' ); + if ( ! $f ) { + return false; } - } elseif ( $translation_begin ) { - $translation = ltrim( $translation, "\n" ); - } - - if ( $original_end ) { - if ( ! $translation_end ) { - $translation .= "\n"; + $lineno = 0; + while ( true ) { + $res = $this->read_entry( $f, $lineno ); + if ( ! $res ) { + break; + } + if ( $res['entry']->singular == '' ) { + $this->set_headers( $this->make_headers( $res['entry']->translations[0] ) ); + } else { + $this->add_entry( $res['entry'] ); + } } - } elseif ( $translation_end ) { - $translation = rtrim( $translation, "\n" ); - } - - return $translation; - } - - /** - * @param string $filename - * @return boolean - */ - function import_from_file($filename) { - $f = fopen($filename, 'r'); - if (!$f) return false; - $lineno = 0; - while (true) { - $res = $this->read_entry($f, $lineno); - if (!$res) break; - if ($res['entry']->singular == '') { - $this->set_headers($this->make_headers($res['entry']->translations[0])); - } else { - $this->add_entry($res['entry']); + PO::read_line( $f, 'clear' ); + if ( false === $res ) { + return false; } + if ( ! $this->headers && ! $this->entries ) { + return false; + } + return true; } - PO::read_line($f, 'clear'); - if ( false === $res ) { - return false; - } - if ( ! $this->headers && ! $this->entries ) { - return false; - } - return true; - } - /** - * Helper function for read_entry - * @param string $context - * @return bool - */ - protected static function is_final($context) { - return ($context === 'msgstr') || ($context === 'msgstr_plural'); - } + /** + * Helper function for read_entry + * + * @param string $context + * @return bool + */ + protected static function is_final( $context ) { + return ( $context === 'msgstr' ) || ( $context === 'msgstr_plural' ); + } - /** - * @param resource $f - * @param int $lineno - * @return null|false|array - */ - function read_entry($f, $lineno = 0) { - $entry = new Translation_Entry(); - // where were we in the last step - // can be: comment, msgctxt, msgid, msgid_plural, msgstr, msgstr_plural - $context = ''; - $msgstr_index = 0; - while (true) { - $lineno++; - $line = PO::read_line($f); - if (!$line) { - if (feof($f)) { - if (self::is_final($context)) - break; - elseif (!$context) // we haven't read a line and eof came - return null; - else + /** + * @param resource $f + * @param int $lineno + * @return null|false|array + */ + function read_entry( $f, $lineno = 0 ) { + $entry = new Translation_Entry(); + // where were we in the last step + // can be: comment, msgctxt, msgid, msgid_plural, msgstr, msgstr_plural + $context = ''; + $msgstr_index = 0; + while ( true ) { + $lineno++; + $line = PO::read_line( $f ); + if ( ! $line ) { + if ( feof( $f ) ) { + if ( self::is_final( $context ) ) { + break; + } elseif ( ! $context ) { // we haven't read a line and eof came + return null; + } else { + return false; + } + } else { return false; + } + } + if ( $line == "\n" ) { + continue; + } + $line = trim( $line ); + if ( preg_match( '/^#/', $line, $m ) ) { + // the comment is the start of a new entry + if ( self::is_final( $context ) ) { + PO::read_line( $f, 'put-back' ); + $lineno--; + break; + } + // comments have to be at the beginning + if ( $context && $context != 'comment' ) { + return false; + } + // add comment + $this->add_comment_to_entry( $entry, $line ); + } elseif ( preg_match( '/^msgctxt\s+(".*")/', $line, $m ) ) { + if ( self::is_final( $context ) ) { + PO::read_line( $f, 'put-back' ); + $lineno--; + break; + } + if ( $context && $context != 'comment' ) { + return false; + } + $context = 'msgctxt'; + $entry->context .= PO::unpoify( $m[1] ); + } elseif ( preg_match( '/^msgid\s+(".*")/', $line, $m ) ) { + if ( self::is_final( $context ) ) { + PO::read_line( $f, 'put-back' ); + $lineno--; + break; + } + if ( $context && $context != 'msgctxt' && $context != 'comment' ) { + return false; + } + $context = 'msgid'; + $entry->singular .= PO::unpoify( $m[1] ); + } elseif ( preg_match( '/^msgid_plural\s+(".*")/', $line, $m ) ) { + if ( $context != 'msgid' ) { + return false; + } + $context = 'msgid_plural'; + $entry->is_plural = true; + $entry->plural .= PO::unpoify( $m[1] ); + } elseif ( preg_match( '/^msgstr\s+(".*")/', $line, $m ) ) { + if ( $context != 'msgid' ) { + return false; + } + $context = 'msgstr'; + $entry->translations = array( PO::unpoify( $m[1] ) ); + } elseif ( preg_match( '/^msgstr\[(\d+)\]\s+(".*")/', $line, $m ) ) { + if ( $context != 'msgid_plural' && $context != 'msgstr_plural' ) { + return false; + } + $context = 'msgstr_plural'; + $msgstr_index = $m[1]; + $entry->translations[ $m[1] ] = PO::unpoify( $m[2] ); + } elseif ( preg_match( '/^".*"$/', $line ) ) { + $unpoified = PO::unpoify( $line ); + switch ( $context ) { + case 'msgid': + $entry->singular .= $unpoified; + break; + case 'msgctxt': + $entry->context .= $unpoified; + break; + case 'msgid_plural': + $entry->plural .= $unpoified; + break; + case 'msgstr': + $entry->translations[0] .= $unpoified; + break; + case 'msgstr_plural': + $entry->translations[ $msgstr_index ] .= $unpoified; + break; + default: + return false; + } } else { return false; } } - if ($line == "\n") continue; - $line = trim($line); - if (preg_match('/^#/', $line, $m)) { - // the comment is the start of a new entry - if (self::is_final($context)) { - PO::read_line($f, 'put-back'); - $lineno--; + + $have_translations = false; + foreach ( $entry->translations as $t ) { + if ( $t || ( '0' === $t ) ) { + $have_translations = true; break; } - // comments have to be at the beginning - if ($context && $context != 'comment') { - return false; - } - // add comment - $this->add_comment_to_entry($entry, $line); - } elseif (preg_match('/^msgctxt\s+(".*")/', $line, $m)) { - if (self::is_final($context)) { - PO::read_line($f, 'put-back'); - $lineno--; - break; - } - if ($context && $context != 'comment') { - return false; - } - $context = 'msgctxt'; - $entry->context .= PO::unpoify($m[1]); - } elseif (preg_match('/^msgid\s+(".*")/', $line, $m)) { - if (self::is_final($context)) { - PO::read_line($f, 'put-back'); - $lineno--; - break; - } - if ($context && $context != 'msgctxt' && $context != 'comment') { - return false; - } - $context = 'msgid'; - $entry->singular .= PO::unpoify($m[1]); - } elseif (preg_match('/^msgid_plural\s+(".*")/', $line, $m)) { - if ($context != 'msgid') { - return false; - } - $context = 'msgid_plural'; - $entry->is_plural = true; - $entry->plural .= PO::unpoify($m[1]); - } elseif (preg_match('/^msgstr\s+(".*")/', $line, $m)) { - if ($context != 'msgid') { - return false; - } - $context = 'msgstr'; - $entry->translations = array(PO::unpoify($m[1])); - } elseif (preg_match('/^msgstr\[(\d+)\]\s+(".*")/', $line, $m)) { - if ($context != 'msgid_plural' && $context != 'msgstr_plural') { - return false; - } - $context = 'msgstr_plural'; - $msgstr_index = $m[1]; - $entry->translations[$m[1]] = PO::unpoify($m[2]); - } elseif (preg_match('/^".*"$/', $line)) { - $unpoified = PO::unpoify($line); - switch ($context) { - case 'msgid': - $entry->singular .= $unpoified; break; - case 'msgctxt': - $entry->context .= $unpoified; break; - case 'msgid_plural': - $entry->plural .= $unpoified; break; - case 'msgstr': - $entry->translations[0] .= $unpoified; break; - case 'msgstr_plural': - $entry->translations[$msgstr_index] .= $unpoified; break; - default: - return false; - } + } + if ( false === $have_translations ) { + $entry->translations = array(); + } + + return array( + 'entry' => $entry, + 'lineno' => $lineno, + ); + } + + /** + * @staticvar string $last_line + * @staticvar boolean $use_last_line + * + * @param resource $f + * @param string $action + * @return boolean + */ + function read_line( $f, $action = 'read' ) { + static $last_line = ''; + static $use_last_line = false; + if ( 'clear' == $action ) { + $last_line = ''; + return true; + } + if ( 'put-back' == $action ) { + $use_last_line = true; + return true; + } + $line = $use_last_line ? $last_line : fgets( $f ); + $line = ( "\r\n" == substr( $line, -2 ) ) ? rtrim( $line, "\r\n" ) . "\n" : $line; + $last_line = $line; + $use_last_line = false; + return $line; + } + + /** + * @param Translation_Entry $entry + * @param string $po_comment_line + */ + function add_comment_to_entry( &$entry, $po_comment_line ) { + $first_two = substr( $po_comment_line, 0, 2 ); + $comment = trim( substr( $po_comment_line, 2 ) ); + if ( '#:' == $first_two ) { + $entry->references = array_merge( $entry->references, preg_split( '/\s+/', $comment ) ); + } elseif ( '#.' == $first_two ) { + $entry->extracted_comments = trim( $entry->extracted_comments . "\n" . $comment ); + } elseif ( '#,' == $first_two ) { + $entry->flags = array_merge( $entry->flags, preg_split( '/,\s*/', $comment ) ); } else { - return false; + $entry->translator_comments = trim( $entry->translator_comments . "\n" . $comment ); } } - $have_translations = false; - foreach ( $entry->translations as $t ) { - if ( $t || ('0' === $t) ) { - $have_translations = true; - break; + /** + * @param string $s + * @return sring + */ + public static function trim_quotes( $s ) { + if ( substr( $s, 0, 1 ) == '"' ) { + $s = substr( $s, 1 ); } - } - if ( false === $have_translations ) { - $entry->translations = array(); - } - - return array('entry' => $entry, 'lineno' => $lineno); - } - - /** - * @staticvar string $last_line - * @staticvar boolean $use_last_line - * - * @param resource $f - * @param string $action - * @return boolean - */ - function read_line($f, $action = 'read') { - static $last_line = ''; - static $use_last_line = false; - if ('clear' == $action) { - $last_line = ''; - return true; - } - if ('put-back' == $action) { - $use_last_line = true; - return true; - } - $line = $use_last_line? $last_line : fgets($f); - $line = ( "\r\n" == substr( $line, -2 ) ) ? rtrim( $line, "\r\n" ) . "\n" : $line; - $last_line = $line; - $use_last_line = false; - return $line; - } - - /** - * @param Translation_Entry $entry - * @param string $po_comment_line - */ - function add_comment_to_entry(&$entry, $po_comment_line) { - $first_two = substr($po_comment_line, 0, 2); - $comment = trim(substr($po_comment_line, 2)); - if ('#:' == $first_two) { - $entry->references = array_merge($entry->references, preg_split('/\s+/', $comment)); - } elseif ('#.' == $first_two) { - $entry->extracted_comments = trim($entry->extracted_comments . "\n" . $comment); - } elseif ('#,' == $first_two) { - $entry->flags = array_merge($entry->flags, preg_split('/,\s*/', $comment)); - } else { - $entry->translator_comments = trim($entry->translator_comments . "\n" . $comment); + if ( substr( $s, -1, 1 ) == '"' ) { + $s = substr( $s, 0, -1 ); + } + return $s; } } - - /** - * @param string $s - * @return sring - */ - public static function trim_quotes($s) { - if ( substr($s, 0, 1) == '"') $s = substr($s, 1); - if ( substr($s, -1, 1) == '"') $s = substr($s, 0, -1); - return $s; - } -} endif; diff --git a/wp-includes/pomo/streams.php b/wp-includes/pomo/streams.php index 5e37c9c412..b0605057d9 100644 --- a/wp-includes/pomo/streams.php +++ b/wp-includes/pomo/streams.php @@ -8,308 +8,317 @@ * @subpackage streams */ -if ( ! class_exists( 'POMO_Reader', false ) ): -class POMO_Reader { +if ( ! class_exists( 'POMO_Reader', false ) ) : + class POMO_Reader { - var $endian = 'little'; - var $_post = ''; + var $endian = 'little'; + var $_post = ''; - /** - * PHP5 constructor. - */ - function __construct() { - $this->is_overloaded = ((ini_get("mbstring.func_overload") & 2) != 0) && function_exists('mb_substr'); - $this->_pos = 0; - } + /** + * PHP5 constructor. + */ + function __construct() { + $this->is_overloaded = ( ( ini_get( 'mbstring.func_overload' ) & 2 ) != 0 ) && function_exists( 'mb_substr' ); + $this->_pos = 0; + } - /** - * PHP4 constructor. - */ - public function POMO_Reader() { - self::__construct(); - } + /** + * PHP4 constructor. + */ + public function POMO_Reader() { + self::__construct(); + } - /** - * Sets the endianness of the file. - * - * @param $endian string 'big' or 'little' - */ - function setEndian($endian) { - $this->endian = $endian; - } + /** + * Sets the endianness of the file. + * + * @param $endian string 'big' or 'little' + */ + function setEndian( $endian ) { + $this->endian = $endian; + } - /** - * Reads a 32bit Integer from the Stream - * - * @return mixed The integer, corresponding to the next 32 bits from - * the stream of false if there are not enough bytes or on error - */ - function readint32() { - $bytes = $this->read(4); - if (4 != $this->strlen($bytes)) - return false; - $endian_letter = ('big' == $this->endian)? 'N' : 'V'; - $int = unpack($endian_letter, $bytes); - return reset( $int ); - } + /** + * Reads a 32bit Integer from the Stream + * + * @return mixed The integer, corresponding to the next 32 bits from + * the stream of false if there are not enough bytes or on error + */ + function readint32() { + $bytes = $this->read( 4 ); + if ( 4 != $this->strlen( $bytes ) ) { + return false; + } + $endian_letter = ( 'big' == $this->endian ) ? 'N' : 'V'; + $int = unpack( $endian_letter, $bytes ); + return reset( $int ); + } - /** - * Reads an array of 32-bit Integers from the Stream - * - * @param integer count How many elements should be read - * @return mixed Array of integers or false if there isn't - * enough data or on error - */ - function readint32array($count) { - $bytes = $this->read(4 * $count); - if (4*$count != $this->strlen($bytes)) - return false; - $endian_letter = ('big' == $this->endian)? 'N' : 'V'; - return unpack($endian_letter.$count, $bytes); - } + /** + * Reads an array of 32-bit Integers from the Stream + * + * @param integer count How many elements should be read + * @return mixed Array of integers or false if there isn't + * enough data or on error + */ + function readint32array( $count ) { + $bytes = $this->read( 4 * $count ); + if ( 4 * $count != $this->strlen( $bytes ) ) { + return false; + } + $endian_letter = ( 'big' == $this->endian ) ? 'N' : 'V'; + return unpack( $endian_letter . $count, $bytes ); + } - /** - * @param string $string - * @param int $start - * @param int $length - * @return string - */ - function substr($string, $start, $length) { - if ($this->is_overloaded) { - return mb_substr($string, $start, $length, 'ascii'); - } else { - return substr($string, $start, $length); + /** + * @param string $string + * @param int $start + * @param int $length + * @return string + */ + function substr( $string, $start, $length ) { + if ( $this->is_overloaded ) { + return mb_substr( $string, $start, $length, 'ascii' ); + } else { + return substr( $string, $start, $length ); + } + } + + /** + * @param string $string + * @return int + */ + function strlen( $string ) { + if ( $this->is_overloaded ) { + return mb_strlen( $string, 'ascii' ); + } else { + return strlen( $string ); + } + } + + /** + * @param string $string + * @param int $chunk_size + * @return array + */ + function str_split( $string, $chunk_size ) { + if ( ! function_exists( 'str_split' ) ) { + $length = $this->strlen( $string ); + $out = array(); + for ( $i = 0; $i < $length; $i += $chunk_size ) { + $out[] = $this->substr( $string, $i, $chunk_size ); + } + return $out; + } else { + return str_split( $string, $chunk_size ); + } + } + + /** + * @return int + */ + function pos() { + return $this->_pos; + } + + /** + * @return true + */ + function is_resource() { + return true; + } + + /** + * @return true + */ + function close() { + return true; } } +endif; - /** - * @param string $string - * @return int - */ - function strlen($string) { - if ($this->is_overloaded) { - return mb_strlen($string, 'ascii'); - } else { - return strlen($string); +if ( ! class_exists( 'POMO_FileReader', false ) ) : + class POMO_FileReader extends POMO_Reader { + + /** + * @param string $filename + */ + function __construct( $filename ) { + parent::POMO_Reader(); + $this->_f = fopen( $filename, 'rb' ); + } + + /** + * PHP4 constructor. + */ + public function POMO_FileReader( $filename ) { + self::__construct( $filename ); + } + + /** + * @param int $bytes + */ + function read( $bytes ) { + return fread( $this->_f, $bytes ); + } + + /** + * @param int $pos + * @return boolean + */ + function seekto( $pos ) { + if ( -1 == fseek( $this->_f, $pos, SEEK_SET ) ) { + return false; + } + $this->_pos = $pos; + return true; + } + + /** + * @return bool + */ + function is_resource() { + return is_resource( $this->_f ); + } + + /** + * @return bool + */ + function feof() { + return feof( $this->_f ); + } + + /** + * @return bool + */ + function close() { + return fclose( $this->_f ); + } + + /** + * @return string + */ + function read_all() { + $all = ''; + while ( ! $this->feof() ) { + $all .= $this->read( 4096 ); + } + return $all; } } +endif; +if ( ! class_exists( 'POMO_StringReader', false ) ) : /** - * @param string $string - * @param int $chunk_size - * @return array + * Provides file-like methods for manipulating a string instead + * of a physical file. */ - function str_split($string, $chunk_size) { - if (!function_exists('str_split')) { - $length = $this->strlen($string); - $out = array(); - for ($i = 0; $i < $length; $i += $chunk_size) - $out[] = $this->substr($string, $i, $chunk_size); - return $out; - } else { - return str_split( $string, $chunk_size ); + class POMO_StringReader extends POMO_Reader { + + var $_str = ''; + + /** + * PHP5 constructor. + */ + function __construct( $str = '' ) { + parent::POMO_Reader(); + $this->_str = $str; + $this->_pos = 0; + } + + /** + * PHP4 constructor. + */ + public function POMO_StringReader( $str = '' ) { + self::__construct( $str ); + } + + /** + * @param string $bytes + * @return string + */ + function read( $bytes ) { + $data = $this->substr( $this->_str, $this->_pos, $bytes ); + $this->_pos += $bytes; + if ( $this->strlen( $this->_str ) < $this->_pos ) { + $this->_pos = $this->strlen( $this->_str ); + } + return $data; + } + + /** + * @param int $pos + * @return int + */ + function seekto( $pos ) { + $this->_pos = $pos; + if ( $this->strlen( $this->_str ) < $this->_pos ) { + $this->_pos = $this->strlen( $this->_str ); + } + return $this->_pos; + } + + /** + * @return int + */ + function length() { + return $this->strlen( $this->_str ); + } + + /** + * @return string + */ + function read_all() { + return $this->substr( $this->_str, $this->_pos, $this->strlen( $this->_str ) ); + } + + } +endif; + +if ( ! class_exists( 'POMO_CachedFileReader', false ) ) : + /** + * Reads the contents of the file in the beginning. + */ + class POMO_CachedFileReader extends POMO_StringReader { + /** + * PHP5 constructor. + */ + function __construct( $filename ) { + parent::POMO_StringReader(); + $this->_str = file_get_contents( $filename ); + if ( false === $this->_str ) { + return false; + } + $this->_pos = 0; + } + + /** + * PHP4 constructor. + */ + public function POMO_CachedFileReader( $filename ) { + self::__construct( $filename ); } } - - /** - * @return int - */ - function pos() { - return $this->_pos; - } - - /** - * @return true - */ - function is_resource() { - return true; - } - - /** - * @return true - */ - function close() { - return true; - } -} endif; -if ( ! class_exists( 'POMO_FileReader', false ) ): -class POMO_FileReader extends POMO_Reader { - +if ( ! class_exists( 'POMO_CachedIntFileReader', false ) ) : /** - * @param string $filename + * Reads the contents of the file in the beginning. */ - function __construct( $filename ) { - parent::POMO_Reader(); - $this->_f = fopen($filename, 'rb'); - } - - /** - * PHP4 constructor. - */ - public function POMO_FileReader( $filename ) { - self::__construct( $filename ); - } - - /** - * @param int $bytes - */ - function read($bytes) { - return fread($this->_f, $bytes); - } - - /** - * @param int $pos - * @return boolean - */ - function seekto($pos) { - if ( -1 == fseek($this->_f, $pos, SEEK_SET)) { - return false; + class POMO_CachedIntFileReader extends POMO_CachedFileReader { + /** + * PHP5 constructor. + */ + public function __construct( $filename ) { + parent::POMO_CachedFileReader( $filename ); } - $this->_pos = $pos; - return true; - } - /** - * @return bool - */ - function is_resource() { - return is_resource($this->_f); + /** + * PHP4 constructor. + */ + function POMO_CachedIntFileReader( $filename ) { + self::__construct( $filename ); + } } - - /** - * @return bool - */ - function feof() { - return feof($this->_f); - } - - /** - * @return bool - */ - function close() { - return fclose($this->_f); - } - - /** - * @return string - */ - function read_all() { - $all = ''; - while ( !$this->feof() ) - $all .= $this->read(4096); - return $all; - } -} -endif; - -if ( ! class_exists( 'POMO_StringReader', false ) ): -/** - * Provides file-like methods for manipulating a string instead - * of a physical file. - */ -class POMO_StringReader extends POMO_Reader { - - var $_str = ''; - - /** - * PHP5 constructor. - */ - function __construct( $str = '' ) { - parent::POMO_Reader(); - $this->_str = $str; - $this->_pos = 0; - } - - /** - * PHP4 constructor. - */ - public function POMO_StringReader( $str = '' ) { - self::__construct( $str ); - } - - /** - * @param string $bytes - * @return string - */ - function read($bytes) { - $data = $this->substr($this->_str, $this->_pos, $bytes); - $this->_pos += $bytes; - if ($this->strlen($this->_str) < $this->_pos) $this->_pos = $this->strlen($this->_str); - return $data; - } - - /** - * @param int $pos - * @return int - */ - function seekto($pos) { - $this->_pos = $pos; - if ($this->strlen($this->_str) < $this->_pos) $this->_pos = $this->strlen($this->_str); - return $this->_pos; - } - - /** - * @return int - */ - function length() { - return $this->strlen($this->_str); - } - - /** - * @return string - */ - function read_all() { - return $this->substr($this->_str, $this->_pos, $this->strlen($this->_str)); - } - -} -endif; - -if ( ! class_exists( 'POMO_CachedFileReader', false ) ): -/** - * Reads the contents of the file in the beginning. - */ -class POMO_CachedFileReader extends POMO_StringReader { - /** - * PHP5 constructor. - */ - function __construct( $filename ) { - parent::POMO_StringReader(); - $this->_str = file_get_contents($filename); - if (false === $this->_str) - return false; - $this->_pos = 0; - } - - /** - * PHP4 constructor. - */ - public function POMO_CachedFileReader( $filename ) { - self::__construct( $filename ); - } -} -endif; - -if ( ! class_exists( 'POMO_CachedIntFileReader', false ) ): -/** - * Reads the contents of the file in the beginning. - */ -class POMO_CachedIntFileReader extends POMO_CachedFileReader { - /** - * PHP5 constructor. - */ - public function __construct( $filename ) { - parent::POMO_CachedFileReader($filename); - } - - /** - * PHP4 constructor. - */ - function POMO_CachedIntFileReader( $filename ) { - self::__construct( $filename ); - } -} endif; diff --git a/wp-includes/pomo/translations.php b/wp-includes/pomo/translations.php index 1e20c37d90..be9081a2fc 100644 --- a/wp-includes/pomo/translations.php +++ b/wp-includes/pomo/translations.php @@ -7,355 +7,373 @@ * @subpackage translations */ -require_once dirname(__FILE__) . '/plural-forms.php'; -require_once dirname(__FILE__) . '/entry.php'; +require_once dirname( __FILE__ ) . '/plural-forms.php'; +require_once dirname( __FILE__ ) . '/entry.php'; -if ( ! class_exists( 'Translations', false ) ): -class Translations { - var $entries = array(); - var $headers = array(); +if ( ! class_exists( 'Translations', false ) ) : + class Translations { + var $entries = array(); + var $headers = array(); - /** - * Add entry to the PO structure - * - * @param array|Translation_Entry $entry - * @return bool true on success, false if the entry doesn't have a key - */ - function add_entry($entry) { - if (is_array($entry)) { - $entry = new Translation_Entry($entry); + /** + * Add entry to the PO structure + * + * @param array|Translation_Entry $entry + * @return bool true on success, false if the entry doesn't have a key + */ + function add_entry( $entry ) { + if ( is_array( $entry ) ) { + $entry = new Translation_Entry( $entry ); + } + $key = $entry->key(); + if ( false === $key ) { + return false; + } + $this->entries[ $key ] = &$entry; + return true; } - $key = $entry->key(); - if (false === $key) return false; - $this->entries[$key] = &$entry; - return true; - } - /** - * @param array|Translation_Entry $entry - * @return bool - */ - function add_entry_or_merge($entry) { - if (is_array($entry)) { - $entry = new Translation_Entry($entry); + /** + * @param array|Translation_Entry $entry + * @return bool + */ + function add_entry_or_merge( $entry ) { + if ( is_array( $entry ) ) { + $entry = new Translation_Entry( $entry ); + } + $key = $entry->key(); + if ( false === $key ) { + return false; + } + if ( isset( $this->entries[ $key ] ) ) { + $this->entries[ $key ]->merge_with( $entry ); + } else { + $this->entries[ $key ] = &$entry; + } + return true; } - $key = $entry->key(); - if (false === $key) return false; - if (isset($this->entries[$key])) - $this->entries[$key]->merge_with($entry); - else - $this->entries[$key] = &$entry; - return true; - } - /** - * Sets $header PO header to $value - * - * If the header already exists, it will be overwritten - * - * TODO: this should be out of this class, it is gettext specific - * - * @param string $header header name, without trailing : - * @param string $value header value, without trailing \n - */ - function set_header($header, $value) { - $this->headers[$header] = $value; - } - - /** - * @param array $headers - */ - function set_headers($headers) { - foreach($headers as $header => $value) { - $this->set_header($header, $value); + /** + * Sets $header PO header to $value + * + * If the header already exists, it will be overwritten + * + * TODO: this should be out of this class, it is gettext specific + * + * @param string $header header name, without trailing : + * @param string $value header value, without trailing \n + */ + function set_header( $header, $value ) { + $this->headers[ $header ] = $value; } - } - /** - * @param string $header - */ - function get_header($header) { - return isset($this->headers[$header])? $this->headers[$header] : false; - } - - /** - * @param Translation_Entry $entry - */ - function translate_entry(&$entry) { - $key = $entry->key(); - return isset($this->entries[$key])? $this->entries[$key] : false; - } - - /** - * @param string $singular - * @param string $context - * @return string - */ - function translate($singular, $context=null) { - $entry = new Translation_Entry(array('singular' => $singular, 'context' => $context)); - $translated = $this->translate_entry($entry); - return ($translated && !empty($translated->translations))? $translated->translations[0] : $singular; - } - - /** - * Given the number of items, returns the 0-based index of the plural form to use - * - * Here, in the base Translations class, the common logic for English is implemented: - * 0 if there is one element, 1 otherwise - * - * This function should be overridden by the sub-classes. For example MO/PO can derive the logic - * from their headers. - * - * @param integer $count number of items - */ - function select_plural_form($count) { - return 1 == $count? 0 : 1; - } - - /** - * @return int - */ - function get_plural_forms_count() { - return 2; - } - - /** - * @param string $singular - * @param string $plural - * @param int $count - * @param string $context - */ - function translate_plural($singular, $plural, $count, $context = null) { - $entry = new Translation_Entry(array('singular' => $singular, 'plural' => $plural, 'context' => $context)); - $translated = $this->translate_entry($entry); - $index = $this->select_plural_form($count); - $total_plural_forms = $this->get_plural_forms_count(); - if ($translated && 0 <= $index && $index < $total_plural_forms && - is_array($translated->translations) && - isset($translated->translations[$index])) - return $translated->translations[$index]; - else - return 1 == $count? $singular : $plural; - } - - /** - * Merge $other in the current object. - * - * @param Object $other Another Translation object, whose translations will be merged in this one (passed by reference). - * @return void - **/ - function merge_with(&$other) { - foreach( $other->entries as $entry ) { - $this->entries[$entry->key()] = $entry; - } - } - - /** - * @param object $other - */ - function merge_originals_with(&$other) { - foreach( $other->entries as $entry ) { - if ( !isset( $this->entries[$entry->key()] ) ) - $this->entries[$entry->key()] = $entry; - else - $this->entries[$entry->key()]->merge_with($entry); - } - } -} - -class Gettext_Translations extends Translations { - /** - * The gettext implementation of select_plural_form. - * - * It lives in this class, because there are more than one descendand, which will use it and - * they can't share it effectively. - * - * @param int $count - */ - function gettext_select_plural_form($count) { - if (!isset($this->_gettext_select_plural_form) || is_null($this->_gettext_select_plural_form)) { - list( $nplurals, $expression ) = $this->nplurals_and_expression_from_header($this->get_header('Plural-Forms')); - $this->_nplurals = $nplurals; - $this->_gettext_select_plural_form = $this->make_plural_form_function($nplurals, $expression); - } - return call_user_func($this->_gettext_select_plural_form, $count); - } - - /** - * @param string $header - * @return array - */ - function nplurals_and_expression_from_header($header) { - if (preg_match('/^\s*nplurals\s*=\s*(\d+)\s*;\s+plural\s*=\s*(.+)$/', $header, $matches)) { - $nplurals = (int)$matches[1]; - $expression = trim( $matches[2] ); - return array($nplurals, $expression); - } else { - return array(2, 'n != 1'); - } - } - - /** - * Makes a function, which will return the right translation index, according to the - * plural forms header - * @param int $nplurals - * @param string $expression - */ - function make_plural_form_function($nplurals, $expression) { - try { - $handler = new Plural_Forms( rtrim( $expression, ';' ) ); - return array( $handler, 'get' ); - } catch ( Exception $e ) { - // Fall back to default plural-form function. - return $this->make_plural_form_function( 2, 'n != 1' ); - } - } - - /** - * Adds parentheses to the inner parts of ternary operators in - * plural expressions, because PHP evaluates ternary oerators from left to right - * - * @param string $expression the expression without parentheses - * @return string the expression with parentheses added - */ - function parenthesize_plural_exression($expression) { - $expression .= ';'; - $res = ''; - $depth = 0; - for ($i = 0; $i < strlen($expression); ++$i) { - $char = $expression[$i]; - switch ($char) { - case '?': - $res .= ' ? ('; - $depth++; - break; - case ':': - $res .= ') : ('; - break; - case ';': - $res .= str_repeat(')', $depth) . ';'; - $depth= 0; - break; - default: - $res .= $char; + /** + * @param array $headers + */ + function set_headers( $headers ) { + foreach ( $headers as $header => $value ) { + $this->set_header( $header, $value ); } } - return rtrim($res, ';'); - } - /** - * @param string $translation - * @return array - */ - function make_headers($translation) { - $headers = array(); - // sometimes \ns are used instead of real new lines - $translation = str_replace('\n', "\n", $translation); - $lines = explode("\n", $translation); - foreach($lines as $line) { - $parts = explode(':', $line, 2); - if (!isset($parts[1])) continue; - $headers[trim($parts[0])] = trim($parts[1]); + /** + * @param string $header + */ + function get_header( $header ) { + return isset( $this->headers[ $header ] ) ? $this->headers[ $header ] : false; } - return $headers; - } - /** - * @param string $header - * @param string $value - */ - function set_header($header, $value) { - parent::set_header($header, $value); - if ('Plural-Forms' == $header) { - list( $nplurals, $expression ) = $this->nplurals_and_expression_from_header($this->get_header('Plural-Forms')); - $this->_nplurals = $nplurals; - $this->_gettext_select_plural_form = $this->make_plural_form_function($nplurals, $expression); + /** + * @param Translation_Entry $entry + */ + function translate_entry( &$entry ) { + $key = $entry->key(); + return isset( $this->entries[ $key ] ) ? $this->entries[ $key ] : false; + } + + /** + * @param string $singular + * @param string $context + * @return string + */ + function translate( $singular, $context = null ) { + $entry = new Translation_Entry( + array( + 'singular' => $singular, + 'context' => $context, + ) + ); + $translated = $this->translate_entry( $entry ); + return ( $translated && ! empty( $translated->translations ) ) ? $translated->translations[0] : $singular; + } + + /** + * Given the number of items, returns the 0-based index of the plural form to use + * + * Here, in the base Translations class, the common logic for English is implemented: + * 0 if there is one element, 1 otherwise + * + * This function should be overridden by the sub-classes. For example MO/PO can derive the logic + * from their headers. + * + * @param integer $count number of items + */ + function select_plural_form( $count ) { + return 1 == $count ? 0 : 1; + } + + /** + * @return int + */ + function get_plural_forms_count() { + return 2; + } + + /** + * @param string $singular + * @param string $plural + * @param int $count + * @param string $context + */ + function translate_plural( $singular, $plural, $count, $context = null ) { + $entry = new Translation_Entry( + array( + 'singular' => $singular, + 'plural' => $plural, + 'context' => $context, + ) + ); + $translated = $this->translate_entry( $entry ); + $index = $this->select_plural_form( $count ); + $total_plural_forms = $this->get_plural_forms_count(); + if ( $translated && 0 <= $index && $index < $total_plural_forms && + is_array( $translated->translations ) && + isset( $translated->translations[ $index ] ) ) { + return $translated->translations[ $index ]; + } else { + return 1 == $count ? $singular : $plural; + } + } + + /** + * Merge $other in the current object. + * + * @param Object $other Another Translation object, whose translations will be merged in this one (passed by reference). + * @return void + */ + function merge_with( &$other ) { + foreach ( $other->entries as $entry ) { + $this->entries[ $entry->key() ] = $entry; + } + } + + /** + * @param object $other + */ + function merge_originals_with( &$other ) { + foreach ( $other->entries as $entry ) { + if ( ! isset( $this->entries[ $entry->key() ] ) ) { + $this->entries[ $entry->key() ] = $entry; + } else { + $this->entries[ $entry->key() ]->merge_with( $entry ); + } + } + } + } + + class Gettext_Translations extends Translations { + /** + * The gettext implementation of select_plural_form. + * + * It lives in this class, because there are more than one descendand, which will use it and + * they can't share it effectively. + * + * @param int $count + */ + function gettext_select_plural_form( $count ) { + if ( ! isset( $this->_gettext_select_plural_form ) || is_null( $this->_gettext_select_plural_form ) ) { + list( $nplurals, $expression ) = $this->nplurals_and_expression_from_header( $this->get_header( 'Plural-Forms' ) ); + $this->_nplurals = $nplurals; + $this->_gettext_select_plural_form = $this->make_plural_form_function( $nplurals, $expression ); + } + return call_user_func( $this->_gettext_select_plural_form, $count ); + } + + /** + * @param string $header + * @return array + */ + function nplurals_and_expression_from_header( $header ) { + if ( preg_match( '/^\s*nplurals\s*=\s*(\d+)\s*;\s+plural\s*=\s*(.+)$/', $header, $matches ) ) { + $nplurals = (int) $matches[1]; + $expression = trim( $matches[2] ); + return array( $nplurals, $expression ); + } else { + return array( 2, 'n != 1' ); + } + } + + /** + * Makes a function, which will return the right translation index, according to the + * plural forms header + * + * @param int $nplurals + * @param string $expression + */ + function make_plural_form_function( $nplurals, $expression ) { + try { + $handler = new Plural_Forms( rtrim( $expression, ';' ) ); + return array( $handler, 'get' ); + } catch ( Exception $e ) { + // Fall back to default plural-form function. + return $this->make_plural_form_function( 2, 'n != 1' ); + } + } + + /** + * Adds parentheses to the inner parts of ternary operators in + * plural expressions, because PHP evaluates ternary oerators from left to right + * + * @param string $expression the expression without parentheses + * @return string the expression with parentheses added + */ + function parenthesize_plural_exression( $expression ) { + $expression .= ';'; + $res = ''; + $depth = 0; + for ( $i = 0; $i < strlen( $expression ); ++$i ) { + $char = $expression[ $i ]; + switch ( $char ) { + case '?': + $res .= ' ? ('; + $depth++; + break; + case ':': + $res .= ') : ('; + break; + case ';': + $res .= str_repeat( ')', $depth ) . ';'; + $depth = 0; + break; + default: + $res .= $char; + } + } + return rtrim( $res, ';' ); + } + + /** + * @param string $translation + * @return array + */ + function make_headers( $translation ) { + $headers = array(); + // sometimes \ns are used instead of real new lines + $translation = str_replace( '\n', "\n", $translation ); + $lines = explode( "\n", $translation ); + foreach ( $lines as $line ) { + $parts = explode( ':', $line, 2 ); + if ( ! isset( $parts[1] ) ) { + continue; + } + $headers[ trim( $parts[0] ) ] = trim( $parts[1] ); + } + return $headers; + } + + /** + * @param string $header + * @param string $value + */ + function set_header( $header, $value ) { + parent::set_header( $header, $value ); + if ( 'Plural-Forms' == $header ) { + list( $nplurals, $expression ) = $this->nplurals_and_expression_from_header( $this->get_header( 'Plural-Forms' ) ); + $this->_nplurals = $nplurals; + $this->_gettext_select_plural_form = $this->make_plural_form_function( $nplurals, $expression ); + } } } -} endif; -if ( ! class_exists( 'NOOP_Translations', false ) ): -/** - * Provides the same interface as Translations, but doesn't do anything - */ -class NOOP_Translations { - var $entries = array(); - var $headers = array(); - - function add_entry($entry) { - return true; - } - +if ( ! class_exists( 'NOOP_Translations', false ) ) : /** - * - * @param string $header - * @param string $value + * Provides the same interface as Translations, but doesn't do anything */ - function set_header($header, $value) { - } + class NOOP_Translations { + var $entries = array(); + var $headers = array(); - /** - * - * @param array $headers - */ - function set_headers($headers) { - } + function add_entry( $entry ) { + return true; + } - /** - * @param string $header - * @return false - */ - function get_header($header) { - return false; - } + /** + * @param string $header + * @param string $value + */ + function set_header( $header, $value ) { + } - /** - * @param Translation_Entry $entry - * @return false - */ - function translate_entry(&$entry) { - return false; - } + /** + * @param array $headers + */ + function set_headers( $headers ) { + } - /** - * @param string $singular - * @param string $context - */ - function translate($singular, $context=null) { - return $singular; - } + /** + * @param string $header + * @return false + */ + function get_header( $header ) { + return false; + } - /** - * - * @param int $count - * @return bool - */ - function select_plural_form($count) { - return 1 == $count? 0 : 1; - } + /** + * @param Translation_Entry $entry + * @return false + */ + function translate_entry( &$entry ) { + return false; + } - /** - * @return int - */ - function get_plural_forms_count() { - return 2; - } + /** + * @param string $singular + * @param string $context + */ + function translate( $singular, $context = null ) { + return $singular; + } - /** - * @param string $singular - * @param string $plural - * @param int $count - * @param string $context - */ - function translate_plural($singular, $plural, $count, $context = null) { - return 1 == $count? $singular : $plural; - } + /** + * @param int $count + * @return bool + */ + function select_plural_form( $count ) { + return 1 == $count ? 0 : 1; + } - /** - * @param object $other - */ - function merge_with(&$other) { + /** + * @return int + */ + function get_plural_forms_count() { + return 2; + } + + /** + * @param string $singular + * @param string $plural + * @param int $count + * @param string $context + */ + function translate_plural( $singular, $plural, $count, $context = null ) { + return 1 == $count ? $singular : $plural; + } + + /** + * @param object $other + */ + function merge_with( &$other ) { + } } -} endif; diff --git a/wp-includes/post-formats.php b/wp-includes/post-formats.php index 47db10b176..eb6fef0380 100644 --- a/wp-includes/post-formats.php +++ b/wp-includes/post-formats.php @@ -15,20 +15,23 @@ * @return string|false The format if successful. False otherwise. */ function get_post_format( $post = null ) { - if ( ! $post = get_post( $post ) ) + if ( ! $post = get_post( $post ) ) { return false; + } - if ( ! post_type_supports( $post->post_type, 'post-formats' ) ) + if ( ! post_type_supports( $post->post_type, 'post-formats' ) ) { return false; + } $_format = get_the_terms( $post->ID, 'post_format' ); - if ( empty( $_format ) ) + if ( empty( $_format ) ) { return false; + } $format = reset( $_format ); - return str_replace('post-format-', '', $format->slug ); + return str_replace( 'post-format-', '', $format->slug ); } /** @@ -64,15 +67,17 @@ function has_post_format( $format = array(), $post = null ) { function set_post_format( $post, $format ) { $post = get_post( $post ); - if ( empty( $post ) ) + if ( empty( $post ) ) { return new WP_Error( 'invalid_post', __( 'Invalid post.' ) ); + } if ( ! empty( $format ) ) { $format = sanitize_key( $format ); - if ( 'standard' === $format || ! in_array( $format, get_post_format_slugs() ) ) + if ( 'standard' === $format || ! in_array( $format, get_post_format_slugs() ) ) { $format = ''; - else + } else { $format = 'post-format-' . $format; + } } return wp_set_post_terms( $post->ID, $format, 'post_format' ); @@ -88,15 +93,15 @@ function set_post_format( $post, $format ) { function get_post_format_strings() { $strings = array( 'standard' => _x( 'Standard', 'Post format' ), // Special case. any value that evals to false will be considered standard - 'aside' => _x( 'Aside', 'Post format' ), - 'chat' => _x( 'Chat', 'Post format' ), - 'gallery' => _x( 'Gallery', 'Post format' ), - 'link' => _x( 'Link', 'Post format' ), - 'image' => _x( 'Image', 'Post format' ), - 'quote' => _x( 'Quote', 'Post format' ), - 'status' => _x( 'Status', 'Post format' ), - 'video' => _x( 'Video', 'Post format' ), - 'audio' => _x( 'Audio', 'Post format' ), + 'aside' => _x( 'Aside', 'Post format' ), + 'chat' => _x( 'Chat', 'Post format' ), + 'gallery' => _x( 'Gallery', 'Post format' ), + 'link' => _x( 'Link', 'Post format' ), + 'image' => _x( 'Image', 'Post format' ), + 'quote' => _x( 'Quote', 'Post format' ), + 'status' => _x( 'Status', 'Post format' ), + 'video' => _x( 'Video', 'Post format' ), + 'audio' => _x( 'Audio', 'Post format' ), ); return $strings; } @@ -123,10 +128,11 @@ function get_post_format_slugs() { */ function get_post_format_string( $slug ) { $strings = get_post_format_strings(); - if ( !$slug ) + if ( ! $slug ) { return $strings['standard']; - else - return ( isset( $strings[$slug] ) ) ? $strings[$slug] : ''; + } else { + return ( isset( $strings[ $slug ] ) ) ? $strings[ $slug ] : ''; + } } /** @@ -138,9 +144,10 @@ function get_post_format_string( $slug ) { * @return string|WP_Error|false The post format term link. */ function get_post_format_link( $format ) { - $term = get_term_by('slug', 'post-format-' . $format, 'post_format' ); - if ( ! $term || is_wp_error( $term ) ) + $term = get_term_by( 'slug', 'post-format-' . $format, 'post_format' ); + if ( ! $term || is_wp_error( $term ) ) { return false; + } return get_term_link( $term ); } @@ -154,14 +161,17 @@ function get_post_format_link( $format ) { * @return array */ function _post_format_request( $qvs ) { - if ( ! isset( $qvs['post_format'] ) ) + if ( ! isset( $qvs['post_format'] ) ) { return $qvs; + } $slugs = get_post_format_slugs(); - if ( isset( $slugs[ $qvs['post_format'] ] ) ) + if ( isset( $slugs[ $qvs['post_format'] ] ) ) { $qvs['post_format'] = 'post-format-' . $slugs[ $qvs['post_format'] ]; + } $tax = get_taxonomy( 'post_format' ); - if ( ! is_admin() ) + if ( ! is_admin() ) { $qvs['post_type'] = $tax->object_type; + } return $qvs; } @@ -222,12 +232,12 @@ function _post_format_get_terms( $terms, $taxonomies, $args ) { if ( in_array( 'post_format', (array) $taxonomies ) ) { if ( isset( $args['fields'] ) && 'names' == $args['fields'] ) { foreach ( $terms as $order => $name ) { - $terms[$order] = get_post_format_string( str_replace( 'post-format-', '', $name ) ); + $terms[ $order ] = get_post_format_string( str_replace( 'post-format-', '', $name ) ); } } else { foreach ( (array) $terms as $order => $term ) { if ( isset( $term->taxonomy ) && 'post_format' == $term->taxonomy ) { - $terms[$order]->name = get_post_format_string( str_replace( 'post-format-', '', $term->slug ) ); + $terms[ $order ]->name = get_post_format_string( str_replace( 'post-format-', '', $term->slug ) ); } } } @@ -247,7 +257,7 @@ function _post_format_get_terms( $terms, $taxonomies, $args ) { function _post_format_wp_get_object_terms( $terms ) { foreach ( (array) $terms as $order => $term ) { if ( isset( $term->taxonomy ) && 'post_format' == $term->taxonomy ) { - $terms[$order]->name = get_post_format_string( str_replace( 'post-format-', '', $term->slug ) ); + $terms[ $order ]->name = get_post_format_string( str_replace( 'post-format-', '', $term->slug ) ); } } return $terms; diff --git a/wp-includes/post-template.php b/wp-includes/post-template.php index 5443340970..36dec909ac 100644 --- a/wp-includes/post-template.php +++ b/wp-includes/post-template.php @@ -42,15 +42,17 @@ function get_the_ID() { function the_title( $before = '', $after = '', $echo = true ) { $title = get_the_title(); - if ( strlen($title) == 0 ) + if ( strlen( $title ) == 0 ) { return; + } $title = $before . $title . $after; - if ( $echo ) + if ( $echo ) { echo $title; - else + } else { return $title; + } } /** @@ -76,8 +78,13 @@ function the_title( $before = '', $after = '', $echo = true ) { * @return string|void String when echo is false. */ function the_title_attribute( $args = '' ) { - $defaults = array( 'before' => '', 'after' => '', 'echo' => true, 'post' => get_post() ); - $r = wp_parse_args( $args, $defaults ); + $defaults = array( + 'before' => '', + 'after' => '', + 'echo' => true, + 'post' => get_post(), + ); + $r = wp_parse_args( $args, $defaults ); $title = get_the_title( $r['post'] ); @@ -111,7 +118,7 @@ function get_the_title( $post = 0 ) { $post = get_post( $post ); $title = isset( $post->post_title ) ? $post->post_title : ''; - $id = isset( $post->ID ) ? $post->ID : 0; + $id = isset( $post->ID ) ? $post->ID : 0; if ( ! is_admin() ) { if ( ! empty( $post->post_password ) ) { @@ -128,7 +135,7 @@ function get_the_title( $post = 0 ) { * @param WP_Post $post Current post object. */ $protected_title_format = apply_filters( 'protected_title_format', __( 'Protected: %s' ), $post ); - $title = sprintf( $protected_title_format, $title ); + $title = sprintf( $protected_title_format, $title ); } elseif ( isset( $post->post_status ) && 'private' == $post->post_status ) { /** @@ -143,7 +150,7 @@ function get_the_title( $post = 0 ) { * @param WP_Post $post Current post object. */ $private_title_format = apply_filters( 'private_title_format', __( 'Private: %s' ), $post ); - $title = sprintf( $private_title_format, $title ); + $title = sprintf( $private_title_format, $title ); } } @@ -227,7 +234,7 @@ function get_the_guid( $post = 0 ) { * @param string $more_link_text Optional. Content for when there is more text. * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false. */ -function the_content( $more_link_text = null, $strip_teaser = false) { +function the_content( $more_link_text = null, $strip_teaser = false ) { $content = get_the_content( $more_link_text, $strip_teaser ); /** @@ -274,34 +281,39 @@ function get_the_content( $more_link_text = null, $strip_teaser = false ) { ); } - $output = ''; + $output = ''; $has_teaser = false; // If post password required and it doesn't match the cookie. - if ( post_password_required( $post ) ) + if ( post_password_required( $post ) ) { return get_the_password_form( $post ); + } - if ( $page > count( $pages ) ) // if the requested page doesn't exist + if ( $page > count( $pages ) ) { // if the requested page doesn't exist $page = count( $pages ); // give them the highest numbered page that DOES exist + } - $content = $pages[$page - 1]; + $content = $pages[ $page - 1 ]; if ( preg_match( '//', $content, $matches ) ) { $content = explode( $matches[0], $content, 2 ); - if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) ) + if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) ) { $more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) ); + } $has_teaser = true; } else { $content = array( $content ); } - if ( false !== strpos( $post->post_content, '' ) && ( ! $multipage || $page == 1 ) ) + if ( false !== strpos( $post->post_content, '' ) && ( ! $multipage || $page == 1 ) ) { $strip_teaser = true; + } $teaser = $content[0]; - if ( $more && $strip_teaser && $has_teaser ) + if ( $more && $strip_teaser && $has_teaser ) { $teaser = ''; + } $output .= $teaser; @@ -309,7 +321,7 @@ function get_the_content( $more_link_text = null, $strip_teaser = false ) { if ( $more ) { $output .= '' . $content[1]; } else { - if ( ! empty( $more_link_text ) ) + if ( ! empty( $more_link_text ) ) { /** * Filters the Read More link text. @@ -320,12 +332,14 @@ function get_the_content( $more_link_text = null, $strip_teaser = false ) { * @param string $more_link_text Read More text. */ $output .= apply_filters( 'the_content_more_link', ' ID}\" class=\"more-link\">$more_link_text", $more_link_text ); + } $output = force_balance_tags( $output ); } } - if ( $preview ) // Preview fix for JavaScript bug with foreign languages. - $output = preg_replace_callback( '/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output ); + if ( $preview ) { // Preview fix for JavaScript bug with foreign languages. + $output = preg_replace_callback( '/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output ); + } return $output; } @@ -407,7 +421,7 @@ function get_the_excerpt( $post = null ) { */ function has_excerpt( $post = 0 ) { $post = get_post( $post ); - return ( !empty( $post->post_excerpt ) ); + return ( ! empty( $post->post_excerpt ) ); } /** @@ -464,8 +478,9 @@ function get_post_class( $class = '', $post_id = null ) { } $classes[] = 'post-' . $post->ID; - if ( ! is_admin() ) + if ( ! is_admin() ) { $classes[] = $post->post_type; + } $classes[] = 'type-' . $post->post_type; $classes[] = 'status-' . $post->post_status; @@ -473,10 +488,11 @@ function get_post_class( $class = '', $post_id = null ) { if ( post_type_supports( $post->post_type, 'post-formats' ) ) { $post_format = get_post_format( $post->ID ); - if ( $post_format && !is_wp_error($post_format) ) + if ( $post_format && ! is_wp_error( $post_format ) ) { $classes[] = 'format-' . sanitize_html_class( $post_format ); - else + } else { $classes[] = 'format-standard'; + } } $post_password_required = post_password_required( $post->ID ); @@ -572,31 +588,39 @@ function get_body_class( $class = '' ) { $classes = array(); - if ( is_rtl() ) + if ( is_rtl() ) { $classes[] = 'rtl'; + } - if ( is_front_page() ) + if ( is_front_page() ) { $classes[] = 'home'; - if ( is_home() ) + } + if ( is_home() ) { $classes[] = 'blog'; - if ( is_archive() ) + } + if ( is_archive() ) { $classes[] = 'archive'; - if ( is_date() ) + } + if ( is_date() ) { $classes[] = 'date'; + } if ( is_search() ) { $classes[] = 'search'; $classes[] = $wp_query->posts ? 'search-results' : 'search-no-results'; } - if ( is_paged() ) + if ( is_paged() ) { $classes[] = 'paged'; - if ( is_attachment() ) + } + if ( is_attachment() ) { $classes[] = 'attachment'; - if ( is_404() ) + } + if ( is_404() ) { $classes[] = 'error404'; + } if ( is_singular() ) { - $post_id = $wp_query->get_queried_object_id(); - $post = $wp_query->get_queried_object(); + $post_id = $wp_query->get_queried_object_id(); + $post = $wp_query->get_queried_object(); $post_type = $post->post_type; if ( is_page_template() ) { @@ -623,29 +647,35 @@ function get_body_class( $class = '' ) { if ( post_type_supports( $post->post_type, 'post-formats' ) ) { $post_format = get_post_format( $post->ID ); - if ( $post_format && !is_wp_error($post_format) ) + if ( $post_format && ! is_wp_error( $post_format ) ) { $classes[] = 'single-format-' . sanitize_html_class( $post_format ); - else + } else { $classes[] = 'single-format-standard'; + } } } } if ( is_attachment() ) { - $mime_type = get_post_mime_type($post_id); + $mime_type = get_post_mime_type( $post_id ); $mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' ); - $classes[] = 'attachmentid-' . $post_id; - $classes[] = 'attachment-' . str_replace( $mime_prefix, '', $mime_type ); + $classes[] = 'attachmentid-' . $post_id; + $classes[] = 'attachment-' . str_replace( $mime_prefix, '', $mime_type ); } elseif ( is_page() ) { $classes[] = 'page'; $page_id = $wp_query->get_queried_object_id(); - $post = get_post($page_id); + $post = get_post( $page_id ); $classes[] = 'page-id-' . $page_id; - if ( get_pages( array( 'parent' => $page_id, 'number' => 1 ) ) ) { + if ( get_pages( + array( + 'parent' => $page_id, + 'number' => 1, + ) + ) ) { $classes[] = 'page-parent'; } @@ -658,18 +688,19 @@ function get_body_class( $class = '' ) { if ( is_post_type_archive() ) { $classes[] = 'post-type-archive'; $post_type = get_query_var( 'post_type' ); - if ( is_array( $post_type ) ) + if ( is_array( $post_type ) ) { $post_type = reset( $post_type ); + } $classes[] = 'post-type-archive-' . sanitize_html_class( $post_type ); } elseif ( is_author() ) { - $author = $wp_query->get_queried_object(); + $author = $wp_query->get_queried_object(); $classes[] = 'author'; if ( isset( $author->user_nicename ) ) { $classes[] = 'author-' . sanitize_html_class( $author->user_nicename, $author->ID ); $classes[] = 'author-' . $author->ID; } } elseif ( is_category() ) { - $cat = $wp_query->get_queried_object(); + $cat = $wp_query->get_queried_object(); $classes[] = 'category'; if ( isset( $cat->term_id ) ) { $cat_class = sanitize_html_class( $cat->slug, $cat->term_id ); @@ -681,7 +712,7 @@ function get_body_class( $class = '' ) { $classes[] = 'category-' . $cat->term_id; } } elseif ( is_tag() ) { - $tag = $wp_query->get_queried_object(); + $tag = $wp_query->get_queried_object(); $classes[] = 'tag'; if ( isset( $tag->term_id ) ) { $tag_class = sanitize_html_class( $tag->slug, $tag->term_id ); @@ -707,16 +738,18 @@ function get_body_class( $class = '' ) { } } - if ( is_user_logged_in() ) + if ( is_user_logged_in() ) { $classes[] = 'logged-in'; + } if ( is_admin_bar_showing() ) { $classes[] = 'admin-bar'; $classes[] = 'no-customize-support'; } - if ( get_background_color() !== get_theme_support( 'custom-background', 'default-color' ) || get_background_image() ) + if ( get_background_color() !== get_theme_support( 'custom-background', 'default-color' ) || get_background_image() ) { $classes[] = 'custom-background'; + } if ( has_custom_logo() ) { $classes[] = 'wp-custom-logo'; @@ -724,33 +757,36 @@ function get_body_class( $class = '' ) { $page = $wp_query->get( 'page' ); - if ( ! $page || $page < 2 ) + if ( ! $page || $page < 2 ) { $page = $wp_query->get( 'paged' ); + } if ( $page && $page > 1 && ! is_404() ) { $classes[] = 'paged-' . $page; - if ( is_single() ) + if ( is_single() ) { $classes[] = 'single-paged-' . $page; - elseif ( is_page() ) + } elseif ( is_page() ) { $classes[] = 'page-paged-' . $page; - elseif ( is_category() ) + } elseif ( is_category() ) { $classes[] = 'category-paged-' . $page; - elseif ( is_tag() ) + } elseif ( is_tag() ) { $classes[] = 'tag-paged-' . $page; - elseif ( is_date() ) + } elseif ( is_date() ) { $classes[] = 'date-paged-' . $page; - elseif ( is_author() ) + } elseif ( is_author() ) { $classes[] = 'author-paged-' . $page; - elseif ( is_search() ) + } elseif ( is_search() ) { $classes[] = 'search-paged-' . $page; - elseif ( is_post_type_archive() ) + } elseif ( is_post_type_archive() ) { $classes[] = 'post-type-paged-' . $page; + } } if ( ! empty( $class ) ) { - if ( !is_array( $class ) ) + if ( ! is_array( $class ) ) { $class = preg_split( '#\s+#', $class ); + } $classes = array_merge( $classes, $class ); } else { // Ensure that we always coerce class to being an array. @@ -781,7 +817,7 @@ function get_body_class( $class = '' ) { * @return bool false if a password is not required or the correct password cookie is present, true otherwise. */ function post_password_required( $post = null ) { - $post = get_post($post); + $post = get_post( $post ); if ( empty( $post->post_password ) ) { /** This filter is documented in wp-includes/post-template.php */ @@ -866,7 +902,7 @@ function wp_link_pages( $args = '' ) { 'nextpagelink' => __( 'Next page' ), 'previouspagelink' => __( 'Previous page' ), 'pagelink' => '%', - 'echo' => 1 + 'echo' => 1, ); $params = wp_parse_args( $args, $defaults ); @@ -906,7 +942,7 @@ function wp_link_pages( $args = '' ) { $output .= $r['after']; } elseif ( $more ) { $output .= $r['before']; - $prev = $page - 1; + $prev = $page - 1; if ( $prev > 0 ) { $link = _wp_link_page( $prev ) . $r['link_before'] . $r['previouspagelink'] . $r['link_after'] . ''; @@ -956,24 +992,25 @@ function wp_link_pages( $args = '' ) { */ function _wp_link_page( $i ) { global $wp_rewrite; - $post = get_post(); + $post = get_post(); $query_args = array(); if ( 1 == $i ) { $url = get_permalink(); } else { - if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) ) + if ( '' == get_option( 'permalink_structure' ) || in_array( $post->post_status, array( 'draft', 'pending' ) ) ) { $url = add_query_arg( 'page', $i, get_permalink() ); - elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID ) - $url = trailingslashit(get_permalink()) . user_trailingslashit("$wp_rewrite->pagination_base/" . $i, 'single_paged'); - else - $url = trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged'); + } elseif ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post->ID ) { + $url = trailingslashit( get_permalink() ) . user_trailingslashit( "$wp_rewrite->pagination_base/" . $i, 'single_paged' ); + } else { + $url = trailingslashit( get_permalink() ) . user_trailingslashit( $i, 'single_paged' ); + } } if ( is_preview() ) { if ( ( 'draft' !== $post->post_status ) && isset( $_GET['preview_id'], $_GET['preview_nonce'] ) ) { - $query_args['preview_id'] = wp_unslash( $_GET['preview_id'] ); + $query_args['preview_id'] = wp_unslash( $_GET['preview_id'] ); $query_args['preview_nonce'] = wp_unslash( $_GET['preview_nonce'] ); } @@ -998,12 +1035,13 @@ function _wp_link_page( $i ) { function post_custom( $key = '' ) { $custom = get_post_custom(); - if ( !isset( $custom[$key] ) ) + if ( ! isset( $custom[ $key ] ) ) { return false; - elseif ( 1 == count($custom[$key]) ) - return $custom[$key][0]; - else - return $custom[$key]; + } elseif ( 1 == count( $custom[ $key ] ) ) { + return $custom[ $key ][0]; + } else { + return $custom[ $key ]; + } } /** @@ -1012,7 +1050,6 @@ function post_custom( $key = '' ) { * @since 1.2.0 * * @internal This will probably change at some point... - * */ function the_meta() { if ( $keys = get_post_custom_keys() ) { @@ -1024,9 +1061,10 @@ function the_meta() { } $values = array_map( 'trim', get_post_custom_values( $key ) ); - $value = implode( $values, ', ' ); + $value = implode( $values, ', ' ); - $html = sprintf( "
  • %s
  • \n", + $html = sprintf( + "
  • %s
  • \n", /* translators: %s: Post custom field name */ sprintf( _x( '%s:', 'Post custom field name' ), $key ), $value @@ -1084,18 +1122,22 @@ function the_meta() { */ function wp_dropdown_pages( $args = '' ) { $defaults = array( - 'depth' => 0, 'child_of' => 0, - 'selected' => 0, 'echo' => 1, - 'name' => 'page_id', 'id' => '', - 'class' => '', - 'show_option_none' => '', 'show_option_no_change' => '', - 'option_none_value' => '', - 'value_field' => 'ID', + 'depth' => 0, + 'child_of' => 0, + 'selected' => 0, + 'echo' => 1, + 'name' => 'page_id', + 'id' => '', + 'class' => '', + 'show_option_none' => '', + 'show_option_no_change' => '', + 'option_none_value' => '', + 'value_field' => 'ID', ); $r = wp_parse_args( $args, $defaults ); - $pages = get_pages( $r ); + $pages = get_pages( $r ); $output = ''; // Back-compat with old system where both id and name were based on $name argument if ( empty( $r['id'] ) ) { @@ -1128,7 +1170,7 @@ function wp_dropdown_pages( $args = '' ) { * @param string $output HTML output for drop down list of pages. * @param array $r The parsed arguments array. * @param array $pages List of WP_Post objects returned by `get_pages()` - */ + */ $html = apply_filters( 'wp_dropdown_pages', $output, $r, $pages ); if ( $r['echo'] ) { @@ -1201,7 +1243,7 @@ function wp_list_pages( $args = '' ) { $r['item_spacing'] = $defaults['item_spacing']; } - $output = ''; + $output = ''; $current_page = 0; // sanitize, mostly to keep spaces out @@ -1221,7 +1263,7 @@ function wp_list_pages( $args = '' ) { // Query pages. $r['hierarchical'] = 0; - $pages = get_pages( $r ); + $pages = get_pages( $r ); if ( ! empty( $pages ) ) { if ( $r['title_li'] ) { @@ -1310,7 +1352,7 @@ function wp_page_menu( $args = array() ) { 'item_spacing' => 'discard', 'walker' => '', ); - $args = wp_parse_args( $args, $defaults ); + $args = wp_parse_args( $args, $defaults ); if ( ! in_array( $args['item_spacing'], array( 'preserve', 'discard' ) ) ) { // invalid value, fall back to default. @@ -1341,29 +1383,31 @@ function wp_page_menu( $args = array() ) { $list_args = $args; // Show Home in the menu - if ( ! empty($args['show_home']) ) { - if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] ) - $text = __('Home'); - else + if ( ! empty( $args['show_home'] ) ) { + if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] ) { + $text = __( 'Home' ); + } else { $text = $args['show_home']; + } $class = ''; - if ( is_front_page() && !is_paged() ) + if ( is_front_page() && ! is_paged() ) { $class = 'class="current_page_item"'; + } $menu .= '
  • ' . $args['link_before'] . $text . $args['link_after'] . '
  • '; // If the front page is a page, add it to the exclude list - if (get_option('show_on_front') == 'page') { - if ( !empty( $list_args['exclude'] ) ) { + if ( get_option( 'show_on_front' ) == 'page' ) { + if ( ! empty( $list_args['exclude'] ) ) { $list_args['exclude'] .= ','; } else { $list_args['exclude'] = ''; } - $list_args['exclude'] .= get_option('page_on_front'); + $list_args['exclude'] .= get_option( 'page_on_front' ); } } - $list_args['echo'] = false; + $list_args['echo'] = false; $list_args['title_li'] = ''; - $menu .= wp_list_pages( $list_args ); + $menu .= wp_list_pages( $list_args ); $container = sanitize_text_field( $args['container'] ); @@ -1379,7 +1423,7 @@ function wp_page_menu( $args = array() ) { 'wp_page_menu' === $args['fallback_cb'] && 'ul' !== $container ) { $args['before'] = "
      {$n}"; - $args['after'] = '
    '; + $args['after'] = ''; } $menu = $args['before'] . $menu . $args['after']; @@ -1407,10 +1451,11 @@ function wp_page_menu( $args = array() ) { * @param array $args An array of arguments. */ $menu = apply_filters( 'wp_page_menu', $menu, $args ); - if ( $args['echo'] ) + if ( $args['echo'] ) { echo $menu; - else + } else { return $menu; + } } // @@ -1430,18 +1475,20 @@ function wp_page_menu( $args = array() ) { * @return string */ function walk_page_tree( $pages, $depth, $current_page, $r ) { - if ( empty($r['walker']) ) + if ( empty( $r['walker'] ) ) { $walker = new Walker_Page; - else + } else { $walker = $r['walker']; - - foreach ( (array) $pages as $page ) { - if ( $page->post_parent ) - $r['pages_with_children'][ $page->post_parent ] = true; } - $args = array($pages, $depth, $r, $current_page); - return call_user_func_array(array($walker, 'walk'), $args); + foreach ( (array) $pages as $page ) { + if ( $page->post_parent ) { + $r['pages_with_children'][ $page->post_parent ] = true; + } + } + + $args = array( $pages, $depth, $r, $current_page ); + return call_user_func_array( array( $walker, 'walk' ), $args ); } /** @@ -1455,12 +1502,13 @@ function walk_page_tree( $pages, $depth, $current_page, $r ) { */ function walk_page_dropdown_tree() { $args = func_get_args(); - if ( empty($args[2]['walker']) ) // the user's options are the third parameter + if ( empty( $args[2]['walker'] ) ) { // the user's options are the third parameter $walker = new Walker_PageDropdown; - else + } else { $walker = $args[2]['walker']; + } - return call_user_func_array(array($walker, 'walk'), $args); + return call_user_func_array( array( $walker, 'walk' ), $args ); } // @@ -1478,13 +1526,15 @@ function walk_page_dropdown_tree() { * @param bool $permalink Optional, default is false. Whether to include permalink. */ function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $permalink = false ) { - if ( !empty( $deprecated ) ) + if ( ! empty( $deprecated ) ) { _deprecated_argument( __FUNCTION__, '2.5.0' ); + } - if ( $fullsize ) - echo wp_get_attachment_link($id, 'full', $permalink); - else - echo wp_get_attachment_link($id, 'thumbnail', $permalink); + if ( $fullsize ) { + echo wp_get_attachment_link( $id, 'full', $permalink ); + } else { + echo wp_get_attachment_link( $id, 'thumbnail', $permalink ); + } } /** @@ -1554,17 +1604,18 @@ function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = fals * @param string $content * @return string */ -function prepend_attachment($content) { +function prepend_attachment( $content ) { $post = get_post(); - if ( empty($post->post_type) || $post->post_type != 'attachment' ) + if ( empty( $post->post_type ) || $post->post_type != 'attachment' ) { return $content; + } if ( wp_attachment_is( 'video', $post ) ) { $meta = wp_get_attachment_metadata( get_the_ID() ); $atts = array( 'src' => wp_get_attachment_url() ); if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) { - $atts['width'] = (int) $meta['width']; + $atts['width'] = (int) $meta['width']; $atts['height'] = (int) $meta['height']; } if ( has_post_thumbnail() ) { @@ -1576,7 +1627,7 @@ function prepend_attachment($content) { } else { $p = '

    '; // show the medium sized image representation of the attachment if available, and link to the raw file - $p .= wp_get_attachment_link(0, 'medium', false); + $p .= wp_get_attachment_link( 0, 'medium', false ); $p .= '

    '; } @@ -1607,8 +1658,8 @@ function prepend_attachment($content) { * @return string HTML content for password form for password protected post. */ function get_the_password_form( $post = 0 ) { - $post = get_post( $post ); - $label = 'pwbox-' . ( empty($post->ID) ? rand() : $post->ID ); + $post = get_post( $post ); + $label = 'pwbox-' . ( empty( $post->ID ) ? rand() : $post->ID ); $output = '

    ' . __( 'This content is password protected. To view it please enter your password below:' ) . '

    @@ -1649,11 +1700,13 @@ function is_page_template( $template = '' ) { $page_template = get_page_template_slug( get_queried_object_id() ); - if ( empty( $template ) ) + if ( empty( $template ) ) { return (bool) $page_template; + } - if ( $template == $page_template ) + if ( $template == $page_template ) { return true; + } if ( is_array( $template ) ) { if ( ( in_array( 'default', $template, true ) && ! $page_template ) @@ -1674,7 +1727,7 @@ function is_page_template( $template = '' ) { * * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. * @return string|false Page template filename. Returns an empty string when the default page template - * is in use. Returns false if the post does not exist. + * is in use. Returns false if the post does not exist. */ function get_page_template_slug( $post = null ) { $post = get_post( $post ); @@ -1702,27 +1755,31 @@ function get_page_template_slug( $post = null ) { * @return string|false i18n formatted datetimestamp or localized 'Current Revision'. */ function wp_post_revision_title( $revision, $link = true ) { - if ( !$revision = get_post( $revision ) ) + if ( ! $revision = get_post( $revision ) ) { return $revision; + } - if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) + if ( ! in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) { return false; + } /* translators: revision date format, see https://secure.php.net/date */ $datef = _x( 'F j, Y @ H:i:s', 'revision date format' ); /* translators: %s: revision date */ $autosavef = __( '%s [Autosave]' ); /* translators: %s: revision date */ - $currentf = __( '%s [Current Revision]' ); + $currentf = __( '%s [Current Revision]' ); $date = date_i18n( $datef, strtotime( $revision->post_modified ) ); - if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) ) + if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) ) { $date = "$date"; + } - if ( !wp_is_post_revision( $revision ) ) + if ( ! wp_is_post_revision( $revision ) ) { $date = sprintf( $currentf, $date ); - elseif ( wp_is_post_autosave( $revision ) ) + } elseif ( wp_is_post_autosave( $revision ) ) { $date = sprintf( $autosavef, $date ); + } return $date; } @@ -1737,11 +1794,13 @@ function wp_post_revision_title( $revision, $link = true ) { * @return string|false gravatar, user, i18n formatted datetimestamp or localized 'Current Revision'. */ function wp_post_revision_title_expanded( $revision, $link = true ) { - if ( !$revision = get_post( $revision ) ) + if ( ! $revision = get_post( $revision ) ) { return $revision; + } - if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) + if ( ! in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) { return false; + } $author = get_the_author_meta( 'display_name', $revision->post_author ); /* translators: revision date format, see https://secure.php.net/date */ @@ -1750,8 +1809,9 @@ function wp_post_revision_title_expanded( $revision, $link = true ) { $gravatar = get_avatar( $revision->post_author, 24 ); $date = date_i18n( $datef, strtotime( $revision->post_modified ) ); - if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) ) + if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) ) { $date = "$date"; + } $revision_date_author = sprintf( /* translators: post revision title: 1: author avatar, 2: author name, 3: time ago, 4: date */ @@ -1765,12 +1825,13 @@ function wp_post_revision_title_expanded( $revision, $link = true ) { /* translators: %s: revision date with author avatar */ $autosavef = __( '%s [Autosave]' ); /* translators: %s: revision date with author avatar */ - $currentf = __( '%s [Current Revision]' ); + $currentf = __( '%s [Current Revision]' ); - if ( !wp_is_post_revision( $revision ) ) + if ( ! wp_is_post_revision( $revision ) ) { $revision_date_author = sprintf( $currentf, $revision_date_author ); - elseif ( wp_is_post_autosave( $revision ) ) + } elseif ( wp_is_post_autosave( $revision ) ) { $revision_date_author = sprintf( $autosavef, $revision_date_author ); + } /** * Filters the formatted author and date for a revision. @@ -1797,26 +1858,30 @@ function wp_post_revision_title_expanded( $revision, $link = true ) { * @param string $type 'all' (default), 'revision' or 'autosave' */ function wp_list_post_revisions( $post_id = 0, $type = 'all' ) { - if ( ! $post = get_post( $post_id ) ) + if ( ! $post = get_post( $post_id ) ) { return; + } // $args array with (parent, format, right, left, type) deprecated since 3.6 if ( is_array( $type ) ) { - $type = ! empty( $type['type'] ) ? $type['type'] : $type; + $type = ! empty( $type['type'] ) ? $type['type'] : $type; _deprecated_argument( __FUNCTION__, '3.6.0' ); } - if ( ! $revisions = wp_get_post_revisions( $post->ID ) ) + if ( ! $revisions = wp_get_post_revisions( $post->ID ) ) { return; + } $rows = ''; foreach ( $revisions as $revision ) { - if ( ! current_user_can( 'read_post', $revision->ID ) ) + if ( ! current_user_can( 'read_post', $revision->ID ) ) { continue; + } $is_autosave = wp_is_post_autosave( $revision ); - if ( ( 'revision' === $type && $is_autosave ) || ( 'autosave' === $type && ! $is_autosave ) ) + if ( ( 'revision' === $type && $is_autosave ) || ( 'autosave' === $type && ! $is_autosave ) ) { continue; + } $rows .= "\t
  • " . wp_post_revision_title_expanded( $revision ) . "
  • \n"; } @@ -1825,5 +1890,5 @@ function wp_list_post_revisions( $post_id = 0, $type = 'all' ) { echo "
      \n"; echo $rows; - echo "
    "; + echo ''; } diff --git a/wp-includes/post-thumbnail-template.php b/wp-includes/post-thumbnail-template.php index 0dbe74aad6..fbc7be5873 100644 --- a/wp-includes/post-thumbnail-template.php +++ b/wp-includes/post-thumbnail-template.php @@ -72,19 +72,22 @@ function the_post_thumbnail( $size = 'post-thumbnail', $attr = '' ) { * @param WP_Query $wp_query Optional. A WP_Query instance. Defaults to the $wp_query global. */ function update_post_thumbnail_cache( $wp_query = null ) { - if ( ! $wp_query ) + if ( ! $wp_query ) { $wp_query = $GLOBALS['wp_query']; + } - if ( $wp_query->thumbnails_cached ) + if ( $wp_query->thumbnails_cached ) { return; + } $thumb_ids = array(); foreach ( $wp_query->posts as $post ) { - if ( $id = get_post_thumbnail_id( $post->ID ) ) + if ( $id = get_post_thumbnail_id( $post->ID ) ) { $thumb_ids[] = $id; + } } - if ( ! empty ( $thumb_ids ) ) { + if ( ! empty( $thumb_ids ) ) { _prime_post_caches( $thumb_ids, false, true ); } @@ -145,8 +148,9 @@ function get_the_post_thumbnail( $post = null, $size = 'post-thumbnail', $attr = * and height values (in that order). Default 'post-thumbnail'. */ do_action( 'begin_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size ); - if ( in_the_loop() ) + if ( in_the_loop() ) { update_post_thumbnail_cache(); + } $html = wp_get_attachment_image( $post_thumbnail_id, $size, false, $attr ); /** diff --git a/wp-includes/post.php b/wp-includes/post.php index 2af241b6c5..45fb3573b8 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -18,253 +18,285 @@ * @since 2.9.0 */ function create_initial_post_types() { - register_post_type( 'post', array( - 'labels' => array( - 'name_admin_bar' => _x( 'Post', 'add new from admin bar' ), - ), - 'public' => true, - '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ - '_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */ - 'capability_type' => 'post', - 'map_meta_cap' => true, - 'menu_position' => 5, - 'hierarchical' => false, - 'rewrite' => false, - 'query_var' => false, - 'delete_with_user' => true, - 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'post-formats' ), - 'show_in_rest' => true, - 'rest_base' => 'posts', - 'rest_controller_class' => 'WP_REST_Posts_Controller', - ) ); + register_post_type( + 'post', array( + 'labels' => array( + 'name_admin_bar' => _x( 'Post', 'add new from admin bar' ), + ), + 'public' => true, + '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ + '_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */ + 'capability_type' => 'post', + 'map_meta_cap' => true, + 'menu_position' => 5, + 'hierarchical' => false, + 'rewrite' => false, + 'query_var' => false, + 'delete_with_user' => true, + 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'post-formats' ), + 'show_in_rest' => true, + 'rest_base' => 'posts', + 'rest_controller_class' => 'WP_REST_Posts_Controller', + ) + ); - register_post_type( 'page', array( - 'labels' => array( - 'name_admin_bar' => _x( 'Page', 'add new from admin bar' ), - ), - 'public' => true, - 'publicly_queryable' => false, - '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ - '_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */ - 'capability_type' => 'page', - 'map_meta_cap' => true, - 'menu_position' => 20, - 'hierarchical' => true, - 'rewrite' => false, - 'query_var' => false, - 'delete_with_user' => true, - 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'comments', 'revisions' ), - 'show_in_rest' => true, - 'rest_base' => 'pages', - 'rest_controller_class' => 'WP_REST_Posts_Controller', - ) ); + register_post_type( + 'page', array( + 'labels' => array( + 'name_admin_bar' => _x( 'Page', 'add new from admin bar' ), + ), + 'public' => true, + 'publicly_queryable' => false, + '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ + '_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */ + 'capability_type' => 'page', + 'map_meta_cap' => true, + 'menu_position' => 20, + 'hierarchical' => true, + 'rewrite' => false, + 'query_var' => false, + 'delete_with_user' => true, + 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'comments', 'revisions' ), + 'show_in_rest' => true, + 'rest_base' => 'pages', + 'rest_controller_class' => 'WP_REST_Posts_Controller', + ) + ); - register_post_type( 'attachment', array( - 'labels' => array( - 'name' => _x('Media', 'post type general name'), - 'name_admin_bar' => _x( 'Media', 'add new from admin bar' ), - 'add_new' => _x( 'Add New', 'add new media' ), - 'edit_item' => __( 'Edit Media' ), - 'view_item' => __( 'View Attachment Page' ), - 'attributes' => __( 'Attachment Attributes' ), - ), - 'public' => true, - 'show_ui' => true, - '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ - '_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */ - 'capability_type' => 'post', - 'capabilities' => array( - 'create_posts' => 'upload_files', - ), - 'map_meta_cap' => true, - 'hierarchical' => false, - 'rewrite' => false, - 'query_var' => false, - 'show_in_nav_menus' => false, - 'delete_with_user' => true, - 'supports' => array( 'title', 'author', 'comments' ), - 'show_in_rest' => true, - 'rest_base' => 'media', - 'rest_controller_class' => 'WP_REST_Attachments_Controller', - ) ); + register_post_type( + 'attachment', array( + 'labels' => array( + 'name' => _x( 'Media', 'post type general name' ), + 'name_admin_bar' => _x( 'Media', 'add new from admin bar' ), + 'add_new' => _x( 'Add New', 'add new media' ), + 'edit_item' => __( 'Edit Media' ), + 'view_item' => __( 'View Attachment Page' ), + 'attributes' => __( 'Attachment Attributes' ), + ), + 'public' => true, + 'show_ui' => true, + '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ + '_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */ + 'capability_type' => 'post', + 'capabilities' => array( + 'create_posts' => 'upload_files', + ), + 'map_meta_cap' => true, + 'hierarchical' => false, + 'rewrite' => false, + 'query_var' => false, + 'show_in_nav_menus' => false, + 'delete_with_user' => true, + 'supports' => array( 'title', 'author', 'comments' ), + 'show_in_rest' => true, + 'rest_base' => 'media', + 'rest_controller_class' => 'WP_REST_Attachments_Controller', + ) + ); add_post_type_support( 'attachment:audio', 'thumbnail' ); add_post_type_support( 'attachment:video', 'thumbnail' ); - register_post_type( 'revision', array( - 'labels' => array( - 'name' => __( 'Revisions' ), - 'singular_name' => __( 'Revision' ), - ), - 'public' => false, - '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ - '_edit_link' => 'revision.php?revision=%d', /* internal use only. don't use this when registering your own post type. */ - 'capability_type' => 'post', - 'map_meta_cap' => true, - 'hierarchical' => false, - 'rewrite' => false, - 'query_var' => false, - 'can_export' => false, - 'delete_with_user' => true, - 'supports' => array( 'author' ), - ) ); + register_post_type( + 'revision', array( + 'labels' => array( + 'name' => __( 'Revisions' ), + 'singular_name' => __( 'Revision' ), + ), + 'public' => false, + '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ + '_edit_link' => 'revision.php?revision=%d', /* internal use only. don't use this when registering your own post type. */ + 'capability_type' => 'post', + 'map_meta_cap' => true, + 'hierarchical' => false, + 'rewrite' => false, + 'query_var' => false, + 'can_export' => false, + 'delete_with_user' => true, + 'supports' => array( 'author' ), + ) + ); - register_post_type( 'nav_menu_item', array( - 'labels' => array( - 'name' => __( 'Navigation Menu Items' ), - 'singular_name' => __( 'Navigation Menu Item' ), - ), - 'public' => false, - '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ - 'hierarchical' => false, - 'rewrite' => false, - 'delete_with_user' => false, - 'query_var' => false, - ) ); + register_post_type( + 'nav_menu_item', array( + 'labels' => array( + 'name' => __( 'Navigation Menu Items' ), + 'singular_name' => __( 'Navigation Menu Item' ), + ), + 'public' => false, + '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ + 'hierarchical' => false, + 'rewrite' => false, + 'delete_with_user' => false, + 'query_var' => false, + ) + ); - register_post_type( 'custom_css', array( - 'labels' => array( - 'name' => __( 'Custom CSS' ), - 'singular_name' => __( 'Custom CSS' ), - ), - 'public' => false, - 'hierarchical' => false, - 'rewrite' => false, - 'query_var' => false, - 'delete_with_user' => false, - 'can_export' => true, - '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ - 'supports' => array( 'title', 'revisions' ), - 'capabilities' => array( - 'delete_posts' => 'edit_theme_options', - 'delete_post' => 'edit_theme_options', - 'delete_published_posts' => 'edit_theme_options', - 'delete_private_posts' => 'edit_theme_options', - 'delete_others_posts' => 'edit_theme_options', - 'edit_post' => 'edit_css', - 'edit_posts' => 'edit_css', - 'edit_others_posts' => 'edit_css', - 'edit_published_posts' => 'edit_css', - 'read_post' => 'read', - 'read_private_posts' => 'read', - 'publish_posts' => 'edit_theme_options', - ), - ) ); + register_post_type( + 'custom_css', array( + 'labels' => array( + 'name' => __( 'Custom CSS' ), + 'singular_name' => __( 'Custom CSS' ), + ), + 'public' => false, + 'hierarchical' => false, + 'rewrite' => false, + 'query_var' => false, + 'delete_with_user' => false, + 'can_export' => true, + '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ + 'supports' => array( 'title', 'revisions' ), + 'capabilities' => array( + 'delete_posts' => 'edit_theme_options', + 'delete_post' => 'edit_theme_options', + 'delete_published_posts' => 'edit_theme_options', + 'delete_private_posts' => 'edit_theme_options', + 'delete_others_posts' => 'edit_theme_options', + 'edit_post' => 'edit_css', + 'edit_posts' => 'edit_css', + 'edit_others_posts' => 'edit_css', + 'edit_published_posts' => 'edit_css', + 'read_post' => 'read', + 'read_private_posts' => 'read', + 'publish_posts' => 'edit_theme_options', + ), + ) + ); - register_post_type( 'customize_changeset', array( - 'labels' => array( - 'name' => _x( 'Changesets', 'post type general name' ), - 'singular_name' => _x( 'Changeset', 'post type singular name' ), - 'menu_name' => _x( 'Changesets', 'admin menu' ), - 'name_admin_bar' => _x( 'Changeset', 'add new on admin bar' ), - 'add_new' => _x( 'Add New', 'Customize Changeset' ), - 'add_new_item' => __( 'Add New Changeset' ), - 'new_item' => __( 'New Changeset' ), - 'edit_item' => __( 'Edit Changeset' ), - 'view_item' => __( 'View Changeset' ), - 'all_items' => __( 'All Changesets' ), - 'search_items' => __( 'Search Changesets' ), - 'not_found' => __( 'No changesets found.' ), - 'not_found_in_trash' => __( 'No changesets found in Trash.' ), - ), - 'public' => false, - '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ - 'map_meta_cap' => true, - 'hierarchical' => false, - 'rewrite' => false, - 'query_var' => false, - 'can_export' => false, - 'delete_with_user' => false, - 'supports' => array( 'title', 'author' ), - 'capability_type' => 'customize_changeset', - 'capabilities' => array( - 'create_posts' => 'customize', - 'delete_others_posts' => 'customize', - 'delete_post' => 'customize', - 'delete_posts' => 'customize', - 'delete_private_posts' => 'customize', - 'delete_published_posts' => 'customize', - 'edit_others_posts' => 'customize', - 'edit_post' => 'customize', - 'edit_posts' => 'customize', - 'edit_private_posts' => 'customize', - 'edit_published_posts' => 'do_not_allow', - 'publish_posts' => 'customize', - 'read' => 'read', - 'read_post' => 'customize', - 'read_private_posts' => 'customize', - ), - ) ); + register_post_type( + 'customize_changeset', array( + 'labels' => array( + 'name' => _x( 'Changesets', 'post type general name' ), + 'singular_name' => _x( 'Changeset', 'post type singular name' ), + 'menu_name' => _x( 'Changesets', 'admin menu' ), + 'name_admin_bar' => _x( 'Changeset', 'add new on admin bar' ), + 'add_new' => _x( 'Add New', 'Customize Changeset' ), + 'add_new_item' => __( 'Add New Changeset' ), + 'new_item' => __( 'New Changeset' ), + 'edit_item' => __( 'Edit Changeset' ), + 'view_item' => __( 'View Changeset' ), + 'all_items' => __( 'All Changesets' ), + 'search_items' => __( 'Search Changesets' ), + 'not_found' => __( 'No changesets found.' ), + 'not_found_in_trash' => __( 'No changesets found in Trash.' ), + ), + 'public' => false, + '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ + 'map_meta_cap' => true, + 'hierarchical' => false, + 'rewrite' => false, + 'query_var' => false, + 'can_export' => false, + 'delete_with_user' => false, + 'supports' => array( 'title', 'author' ), + 'capability_type' => 'customize_changeset', + 'capabilities' => array( + 'create_posts' => 'customize', + 'delete_others_posts' => 'customize', + 'delete_post' => 'customize', + 'delete_posts' => 'customize', + 'delete_private_posts' => 'customize', + 'delete_published_posts' => 'customize', + 'edit_others_posts' => 'customize', + 'edit_post' => 'customize', + 'edit_posts' => 'customize', + 'edit_private_posts' => 'customize', + 'edit_published_posts' => 'do_not_allow', + 'publish_posts' => 'customize', + 'read' => 'read', + 'read_post' => 'customize', + 'read_private_posts' => 'customize', + ), + ) + ); - register_post_type( 'oembed_cache', array( - 'labels' => array( - 'name' => __( 'oEmbed Responses' ), - 'singular_name' => __( 'oEmbed Response' ), - ), - 'public' => false, - 'hierarchical' => false, - 'rewrite' => false, - 'query_var' => false, - 'delete_with_user' => false, - 'can_export' => false, - '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ - 'supports' => array(), - ) ); + register_post_type( + 'oembed_cache', array( + 'labels' => array( + 'name' => __( 'oEmbed Responses' ), + 'singular_name' => __( 'oEmbed Response' ), + ), + 'public' => false, + 'hierarchical' => false, + 'rewrite' => false, + 'query_var' => false, + 'delete_with_user' => false, + 'can_export' => false, + '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ + 'supports' => array(), + ) + ); - register_post_status( 'publish', array( - 'label' => _x( 'Published', 'post status' ), - 'public' => true, - '_builtin' => true, /* internal use only. */ - 'label_count' => _n_noop( 'Published (%s)', 'Published (%s)' ), - ) ); + register_post_status( + 'publish', array( + 'label' => _x( 'Published', 'post status' ), + 'public' => true, + '_builtin' => true, /* internal use only. */ + 'label_count' => _n_noop( 'Published (%s)', 'Published (%s)' ), + ) + ); - register_post_status( 'future', array( - 'label' => _x( 'Scheduled', 'post status' ), - 'protected' => true, - '_builtin' => true, /* internal use only. */ - 'label_count' => _n_noop('Scheduled (%s)', 'Scheduled (%s)' ), - ) ); + register_post_status( + 'future', array( + 'label' => _x( 'Scheduled', 'post status' ), + 'protected' => true, + '_builtin' => true, /* internal use only. */ + 'label_count' => _n_noop( 'Scheduled (%s)', 'Scheduled (%s)' ), + ) + ); - register_post_status( 'draft', array( - 'label' => _x( 'Draft', 'post status' ), - 'protected' => true, - '_builtin' => true, /* internal use only. */ - 'label_count' => _n_noop( 'Draft (%s)', 'Drafts (%s)' ), - ) ); + register_post_status( + 'draft', array( + 'label' => _x( 'Draft', 'post status' ), + 'protected' => true, + '_builtin' => true, /* internal use only. */ + 'label_count' => _n_noop( 'Draft (%s)', 'Drafts (%s)' ), + ) + ); - register_post_status( 'pending', array( - 'label' => _x( 'Pending', 'post status' ), - 'protected' => true, - '_builtin' => true, /* internal use only. */ - 'label_count' => _n_noop( 'Pending (%s)', 'Pending (%s)' ), - ) ); + register_post_status( + 'pending', array( + 'label' => _x( 'Pending', 'post status' ), + 'protected' => true, + '_builtin' => true, /* internal use only. */ + 'label_count' => _n_noop( 'Pending (%s)', 'Pending (%s)' ), + ) + ); - register_post_status( 'private', array( - 'label' => _x( 'Private', 'post status' ), - 'private' => true, - '_builtin' => true, /* internal use only. */ - 'label_count' => _n_noop( 'Private (%s)', 'Private (%s)' ), - ) ); + register_post_status( + 'private', array( + 'label' => _x( 'Private', 'post status' ), + 'private' => true, + '_builtin' => true, /* internal use only. */ + 'label_count' => _n_noop( 'Private (%s)', 'Private (%s)' ), + ) + ); - register_post_status( 'trash', array( - 'label' => _x( 'Trash', 'post status' ), - 'internal' => true, - '_builtin' => true, /* internal use only. */ - 'label_count' => _n_noop( 'Trash (%s)', 'Trash (%s)' ), - 'show_in_admin_status_list' => true, - ) ); + register_post_status( + 'trash', array( + 'label' => _x( 'Trash', 'post status' ), + 'internal' => true, + '_builtin' => true, /* internal use only. */ + 'label_count' => _n_noop( 'Trash (%s)', 'Trash (%s)' ), + 'show_in_admin_status_list' => true, + ) + ); - register_post_status( 'auto-draft', array( - 'label' => 'auto-draft', - 'internal' => true, - '_builtin' => true, /* internal use only. */ - ) ); + register_post_status( + 'auto-draft', array( + 'label' => 'auto-draft', + 'internal' => true, + '_builtin' => true, /* internal use only. */ + ) + ); - register_post_status( 'inherit', array( - 'label' => 'inherit', - 'internal' => true, - '_builtin' => true, /* internal use only. */ - 'exclude_from_search' => false, - ) ); + register_post_status( + 'inherit', array( + 'label' => 'inherit', + 'internal' => true, + '_builtin' => true, /* internal use only. */ + 'exclude_from_search' => false, + ) + ); } /** @@ -321,8 +353,9 @@ function get_attached_file( $attachment_id, $unfiltered = false ) { * @return bool True on success, false on failure. */ function update_attached_file( $attachment_id, $file ) { - if ( !get_post( $attachment_id ) ) + if ( ! get_post( $attachment_id ) ) { return false; + } /** * Filters the path to the attached file to update. @@ -334,10 +367,11 @@ function update_attached_file( $attachment_id, $file ) { */ $file = apply_filters( 'update_attached_file', $file, $attachment_id ); - if ( $file = _wp_relative_upload_path( $file ) ) + if ( $file = _wp_relative_upload_path( $file ) ) { return update_post_meta( $attachment_id, '_wp_attached_file', $file ); - else + } else { return delete_post_meta( $attachment_id, '_wp_attached_file' ); + } } /** @@ -425,48 +459,53 @@ function get_children( $args = '', $output = OBJECT ) { $kids = array(); if ( empty( $args ) ) { if ( isset( $GLOBALS['post'] ) ) { - $args = array('post_parent' => (int) $GLOBALS['post']->post_parent ); + $args = array( 'post_parent' => (int) $GLOBALS['post']->post_parent ); } else { return $kids; } } elseif ( is_object( $args ) ) { - $args = array('post_parent' => (int) $args->post_parent ); + $args = array( 'post_parent' => (int) $args->post_parent ); } elseif ( is_numeric( $args ) ) { - $args = array('post_parent' => (int) $args); + $args = array( 'post_parent' => (int) $args ); } $defaults = array( - 'numberposts' => -1, 'post_type' => 'any', - 'post_status' => 'any', 'post_parent' => 0, + 'numberposts' => -1, + 'post_type' => 'any', + 'post_status' => 'any', + 'post_parent' => 0, ); $r = wp_parse_args( $args, $defaults ); $children = get_posts( $r ); - if ( ! $children ) + if ( ! $children ) { return $kids; + } - if ( ! empty( $r['fields'] ) ) + if ( ! empty( $r['fields'] ) ) { return $children; + } - update_post_cache($children); + update_post_cache( $children ); - foreach ( $children as $key => $child ) - $kids[$child->ID] = $children[$key]; + foreach ( $children as $key => $child ) { + $kids[ $child->ID ] = $children[ $key ]; + } if ( $output == OBJECT ) { return $kids; } elseif ( $output == ARRAY_A ) { $weeuns = array(); foreach ( (array) $kids as $kid ) { - $weeuns[$kid->ID] = get_object_vars($kids[$kid->ID]); + $weeuns[ $kid->ID ] = get_object_vars( $kids[ $kid->ID ] ); } return $weeuns; } elseif ( $output == ARRAY_N ) { $babes = array(); foreach ( (array) $kids as $kid ) { - $babes[$kid->ID] = array_values(get_object_vars($kids[$kid->ID])); + $babes[ $kid->ID ] = array_values( get_object_vars( $kids[ $kid->ID ] ) ); } return $babes; } else { @@ -492,21 +531,25 @@ function get_children( $args = '', $output = OBJECT ) { */ function get_extended( $post ) { //Match the new style more links. - if ( preg_match('//', $post, $matches) ) { - list($main, $extended) = explode($matches[0], $post, 2); - $more_text = $matches[1]; + if ( preg_match( '//', $post, $matches ) ) { + list($main, $extended) = explode( $matches[0], $post, 2 ); + $more_text = $matches[1]; } else { - $main = $post; - $extended = ''; + $main = $post; + $extended = ''; $more_text = ''; } // leading and trailing whitespace. - $main = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $main); - $extended = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $extended); - $more_text = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $more_text); + $main = preg_replace( '/^[\s]*(.*)[\s]*$/', '\\1', $main ); + $extended = preg_replace( '/^[\s]*(.*)[\s]*$/', '\\1', $extended ); + $more_text = preg_replace( '/^[\s]*(.*)[\s]*$/', '\\1', $more_text ); - return array( 'main' => $main, 'extended' => $extended, 'more_text' => $more_text ); + return array( + 'main' => $main, + 'extended' => $extended, + 'more_text' => $more_text, + ); } /** @@ -528,8 +571,9 @@ function get_extended( $post ) { * When $output is OBJECT, a `WP_Post` instance is returned. */ function get_post( $post = null, $output = OBJECT, $filter = 'raw' ) { - if ( empty( $post ) && isset( $GLOBALS['post'] ) ) + if ( empty( $post ) && isset( $GLOBALS['post'] ) ) { $post = $GLOBALS['post']; + } if ( $post instanceof WP_Post ) { $_post = $post; @@ -546,15 +590,17 @@ function get_post( $post = null, $output = OBJECT, $filter = 'raw' ) { $_post = WP_Post::get_instance( $post ); } - if ( ! $_post ) + if ( ! $_post ) { return null; + } $_post = $_post->filter( $filter ); - if ( $output == ARRAY_A ) + if ( $output == ARRAY_A ) { return $_post->to_array(); - elseif ( $output == ARRAY_N ) + } elseif ( $output == ARRAY_N ) { return array_values( $_post->to_array() ); + } return $_post; } @@ -570,8 +616,9 @@ function get_post( $post = null, $output = OBJECT, $filter = 'raw' ) { function get_post_ancestors( $post ) { $post = get_post( $post ); - if ( ! $post || empty( $post->post_parent ) || $post->post_parent == $post->ID ) + if ( ! $post || empty( $post->post_parent ) || $post->post_parent == $post->ID ) { return array(); + } $ancestors = array(); @@ -579,8 +626,9 @@ function get_post_ancestors( $post ) { while ( $ancestor = get_post( $id ) ) { // Loop detection: If the ancestor has been seen before, break. - if ( empty( $ancestor->post_parent ) || ( $ancestor->post_parent == $post->ID ) || in_array( $ancestor->post_parent, $ancestors ) ) + if ( empty( $ancestor->post_parent ) || ( $ancestor->post_parent == $post->ID ) || in_array( $ancestor->post_parent, $ancestors ) ) { break; + } $id = $ancestors[] = $ancestor->post_parent; } @@ -611,13 +659,15 @@ function get_post_ancestors( $post ) { function get_post_field( $field, $post = null, $context = 'display' ) { $post = get_post( $post ); - if ( !$post ) + if ( ! $post ) { return ''; + } - if ( !isset($post->$field) ) + if ( ! isset( $post->$field ) ) { return ''; + } - return sanitize_post_field($field, $post->$field, $post->ID, $context); + return sanitize_post_field( $field, $post->$field, $post->ID, $context ); } /** @@ -632,10 +682,11 @@ function get_post_field( $field, $post = null, $context = 'display' ) { * @return string|false The mime type on success, false on failure. */ function get_post_mime_type( $ID = '' ) { - $post = get_post($ID); + $post = get_post( $ID ); - if ( is_object($post) ) + if ( is_object( $post ) ) { return $post->post_mime_type; + } return false; } @@ -652,18 +703,21 @@ function get_post_mime_type( $ID = '' ) { * @return string|false Post status on success, false on failure. */ function get_post_status( $ID = '' ) { - $post = get_post($ID); + $post = get_post( $ID ); - if ( !is_object($post) ) + if ( ! is_object( $post ) ) { return false; + } if ( 'attachment' == $post->post_type ) { - if ( 'private' == $post->post_status ) + if ( 'private' == $post->post_status ) { return 'private'; + } // Unattached attachments are assumed to be published. - if ( ( 'inherit' == $post->post_status ) && ( 0 == $post->post_parent) ) + if ( ( 'inherit' == $post->post_status ) && ( 0 == $post->post_parent ) ) { return 'publish'; + } // Inherit status from the parent. if ( $post->post_parent && ( $post->ID != $post->post_parent ) ) { @@ -674,7 +728,6 @@ function get_post_status( $ID = '' ) { return $parent_post_status; } } - } /** @@ -703,7 +756,7 @@ function get_post_statuses() { 'draft' => __( 'Draft' ), 'pending' => __( 'Pending Review' ), 'private' => __( 'Private' ), - 'publish' => __( 'Published' ) + 'publish' => __( 'Published' ), ); return $status; @@ -723,7 +776,7 @@ function get_page_statuses() { $status = array( 'draft' => __( 'Draft' ), 'private' => __( 'Private' ), - 'publish' => __( 'Published' ) + 'publish' => __( 'Published' ), ); return $status; @@ -775,64 +828,76 @@ function get_page_statuses() { function register_post_status( $post_status, $args = array() ) { global $wp_post_statuses; - if (!is_array($wp_post_statuses)) + if ( ! is_array( $wp_post_statuses ) ) { $wp_post_statuses = array(); + } // Args prefixed with an underscore are reserved for internal use. $defaults = array( - 'label' => false, - 'label_count' => false, - 'exclude_from_search' => null, - '_builtin' => false, - 'public' => null, - 'internal' => null, - 'protected' => null, - 'private' => null, - 'publicly_queryable' => null, + 'label' => false, + 'label_count' => false, + 'exclude_from_search' => null, + '_builtin' => false, + 'public' => null, + 'internal' => null, + 'protected' => null, + 'private' => null, + 'publicly_queryable' => null, 'show_in_admin_status_list' => null, - 'show_in_admin_all_list' => null, + 'show_in_admin_all_list' => null, ); - $args = wp_parse_args($args, $defaults); - $args = (object) $args; + $args = wp_parse_args( $args, $defaults ); + $args = (object) $args; - $post_status = sanitize_key($post_status); - $args->name = $post_status; + $post_status = sanitize_key( $post_status ); + $args->name = $post_status; // Set various defaults. - if ( null === $args->public && null === $args->internal && null === $args->protected && null === $args->private ) + if ( null === $args->public && null === $args->internal && null === $args->protected && null === $args->private ) { $args->internal = true; + } - if ( null === $args->public ) + if ( null === $args->public ) { $args->public = false; + } - if ( null === $args->private ) + if ( null === $args->private ) { $args->private = false; + } - if ( null === $args->protected ) + if ( null === $args->protected ) { $args->protected = false; + } - if ( null === $args->internal ) + if ( null === $args->internal ) { $args->internal = false; + } - if ( null === $args->publicly_queryable ) + if ( null === $args->publicly_queryable ) { $args->publicly_queryable = $args->public; + } - if ( null === $args->exclude_from_search ) + if ( null === $args->exclude_from_search ) { $args->exclude_from_search = $args->internal; + } - if ( null === $args->show_in_admin_all_list ) - $args->show_in_admin_all_list = !$args->internal; + if ( null === $args->show_in_admin_all_list ) { + $args->show_in_admin_all_list = ! $args->internal; + } - if ( null === $args->show_in_admin_status_list ) - $args->show_in_admin_status_list = !$args->internal; + if ( null === $args->show_in_admin_status_list ) { + $args->show_in_admin_status_list = ! $args->internal; + } - if ( false === $args->label ) + if ( false === $args->label ) { $args->label = $post_status; + } - if ( false === $args->label_count ) + if ( false === $args->label_count ) { $args->label_count = _n_noop( $args->label, $args->label ); + } - $wp_post_statuses[$post_status] = $args; + $wp_post_statuses[ $post_status ] = $args; return $args; } @@ -852,10 +917,11 @@ function register_post_status( $post_status, $args = array() ) { function get_post_status_object( $post_status ) { global $wp_post_statuses; - if ( empty($wp_post_statuses[$post_status]) ) + if ( empty( $wp_post_statuses[ $post_status ] ) ) { return null; + } - return $wp_post_statuses[$post_status]; + return $wp_post_statuses[ $post_status ]; } /** @@ -878,9 +944,9 @@ function get_post_status_object( $post_status ) { function get_post_stati( $args = array(), $output = 'names', $operator = 'and' ) { global $wp_post_statuses; - $field = ('names' == $output) ? 'name' : false; + $field = ( 'names' == $output ) ? 'name' : false; - return wp_filter_object_list($wp_post_statuses, $args, $operator, $field); + return wp_filter_object_list( $wp_post_statuses, $args, $operator, $field ); } /** @@ -896,8 +962,9 @@ function get_post_stati( $args = array(), $output = 'names', $operator = 'and' ) * @return bool Whether post type is hierarchical. */ function is_post_type_hierarchical( $post_type ) { - if ( ! post_type_exists( $post_type ) ) + if ( ! post_type_exists( $post_type ) ) { return false; + } $post_type = get_post_type_object( $post_type ); return $post_type->hierarchical; @@ -926,8 +993,9 @@ function post_type_exists( $post_type ) { * @return string|false Post type on success, false on failure. */ function get_post_type( $post = null ) { - if ( $post = get_post( $post ) ) + if ( $post = get_post( $post ) ) { return $post->post_type; + } return false; } @@ -976,9 +1044,9 @@ function get_post_type_object( $post_type ) { function get_post_types( $args = array(), $output = 'names', $operator = 'and' ) { global $wp_post_types; - $field = ('names' == $output) ? 'name' : false; + $field = ( 'names' == $output ) ? 'name' : false; - return wp_filter_object_list($wp_post_types, $args, $operator, $field); + return wp_filter_object_list( $wp_post_types, $args, $operator, $field ); } /** @@ -1258,21 +1326,22 @@ function unregister_post_type( $post_type ) { * @return object Object with all the capabilities as member variables. */ function get_post_type_capabilities( $args ) { - if ( ! is_array( $args->capability_type ) ) + if ( ! is_array( $args->capability_type ) ) { $args->capability_type = array( $args->capability_type, $args->capability_type . 's' ); + } // Singular base for meta capabilities, plural base for primitive capabilities. list( $singular_base, $plural_base ) = $args->capability_type; $default_capabilities = array( // Meta capabilities - 'edit_post' => 'edit_' . $singular_base, - 'read_post' => 'read_' . $singular_base, - 'delete_post' => 'delete_' . $singular_base, + 'edit_post' => 'edit_' . $singular_base, + 'read_post' => 'read_' . $singular_base, + 'delete_post' => 'delete_' . $singular_base, // Primitive capabilities used outside of map_meta_cap(): - 'edit_posts' => 'edit_' . $plural_base, - 'edit_others_posts' => 'edit_others_' . $plural_base, - 'publish_posts' => 'publish_' . $plural_base, + 'edit_posts' => 'edit_' . $plural_base, + 'edit_others_posts' => 'edit_others_' . $plural_base, + 'publish_posts' => 'publish_' . $plural_base, 'read_private_posts' => 'read_private_' . $plural_base, ); @@ -1280,25 +1349,27 @@ function get_post_type_capabilities( $args ) { if ( $args->map_meta_cap ) { $default_capabilities_for_mapping = array( 'read' => 'read', - 'delete_posts' => 'delete_' . $plural_base, - 'delete_private_posts' => 'delete_private_' . $plural_base, + 'delete_posts' => 'delete_' . $plural_base, + 'delete_private_posts' => 'delete_private_' . $plural_base, 'delete_published_posts' => 'delete_published_' . $plural_base, - 'delete_others_posts' => 'delete_others_' . $plural_base, - 'edit_private_posts' => 'edit_private_' . $plural_base, - 'edit_published_posts' => 'edit_published_' . $plural_base, + 'delete_others_posts' => 'delete_others_' . $plural_base, + 'edit_private_posts' => 'edit_private_' . $plural_base, + 'edit_published_posts' => 'edit_published_' . $plural_base, ); - $default_capabilities = array_merge( $default_capabilities, $default_capabilities_for_mapping ); + $default_capabilities = array_merge( $default_capabilities, $default_capabilities_for_mapping ); } $capabilities = array_merge( $default_capabilities, $args->capabilities ); // Post creation capability simply maps to edit_posts by default: - if ( ! isset( $capabilities['create_posts'] ) ) + if ( ! isset( $capabilities['create_posts'] ) ) { $capabilities['create_posts'] = $capabilities['edit_posts']; + } // Remember meta capabilities for future reference. - if ( $args->map_meta_cap ) + if ( $args->map_meta_cap ) { _post_type_meta_capabilities( $capabilities ); + } return (object) $capabilities; } @@ -1381,31 +1452,31 @@ function _post_type_meta_capabilities( $capabilities = null ) { * @return object Object with all the labels as member variables. */ function get_post_type_labels( $post_type_object ) { - $nohier_vs_hier_defaults = array( - 'name' => array( _x('Posts', 'post type general name'), _x('Pages', 'post type general name') ), - 'singular_name' => array( _x('Post', 'post type singular name'), _x('Page', 'post type singular name') ), - 'add_new' => array( _x('Add New', 'post'), _x('Add New', 'page') ), - 'add_new_item' => array( __('Add New Post'), __('Add New Page') ), - 'edit_item' => array( __('Edit Post'), __('Edit Page') ), - 'new_item' => array( __('New Post'), __('New Page') ), - 'view_item' => array( __('View Post'), __('View Page') ), - 'view_items' => array( __('View Posts'), __('View Pages') ), - 'search_items' => array( __('Search Posts'), __('Search Pages') ), - 'not_found' => array( __('No posts found.'), __('No pages found.') ), - 'not_found_in_trash' => array( __('No posts found in Trash.'), __('No pages found in Trash.') ), - 'parent_item_colon' => array( null, __('Parent Page:') ), - 'all_items' => array( __( 'All Posts' ), __( 'All Pages' ) ), - 'archives' => array( __( 'Post Archives' ), __( 'Page Archives' ) ), - 'attributes' => array( __( 'Post Attributes' ), __( 'Page Attributes' ) ), - 'insert_into_item' => array( __( 'Insert into post' ), __( 'Insert into page' ) ), + $nohier_vs_hier_defaults = array( + 'name' => array( _x( 'Posts', 'post type general name' ), _x( 'Pages', 'post type general name' ) ), + 'singular_name' => array( _x( 'Post', 'post type singular name' ), _x( 'Page', 'post type singular name' ) ), + 'add_new' => array( _x( 'Add New', 'post' ), _x( 'Add New', 'page' ) ), + 'add_new_item' => array( __( 'Add New Post' ), __( 'Add New Page' ) ), + 'edit_item' => array( __( 'Edit Post' ), __( 'Edit Page' ) ), + 'new_item' => array( __( 'New Post' ), __( 'New Page' ) ), + 'view_item' => array( __( 'View Post' ), __( 'View Page' ) ), + 'view_items' => array( __( 'View Posts' ), __( 'View Pages' ) ), + 'search_items' => array( __( 'Search Posts' ), __( 'Search Pages' ) ), + 'not_found' => array( __( 'No posts found.' ), __( 'No pages found.' ) ), + 'not_found_in_trash' => array( __( 'No posts found in Trash.' ), __( 'No pages found in Trash.' ) ), + 'parent_item_colon' => array( null, __( 'Parent Page:' ) ), + 'all_items' => array( __( 'All Posts' ), __( 'All Pages' ) ), + 'archives' => array( __( 'Post Archives' ), __( 'Page Archives' ) ), + 'attributes' => array( __( 'Post Attributes' ), __( 'Page Attributes' ) ), + 'insert_into_item' => array( __( 'Insert into post' ), __( 'Insert into page' ) ), 'uploaded_to_this_item' => array( __( 'Uploaded to this post' ), __( 'Uploaded to this page' ) ), - 'featured_image' => array( _x( 'Featured Image', 'post' ), _x( 'Featured Image', 'page' ) ), - 'set_featured_image' => array( _x( 'Set featured image', 'post' ), _x( 'Set featured image', 'page' ) ), + 'featured_image' => array( _x( 'Featured Image', 'post' ), _x( 'Featured Image', 'page' ) ), + 'set_featured_image' => array( _x( 'Set featured image', 'post' ), _x( 'Set featured image', 'page' ) ), 'remove_featured_image' => array( _x( 'Remove featured image', 'post' ), _x( 'Remove featured image', 'page' ) ), - 'use_featured_image' => array( _x( 'Use as featured image', 'post' ), _x( 'Use as featured image', 'page' ) ), - 'filter_items_list' => array( __( 'Filter posts list' ), __( 'Filter pages list' ) ), + 'use_featured_image' => array( _x( 'Use as featured image', 'post' ), _x( 'Use as featured image', 'page' ) ), + 'filter_items_list' => array( __( 'Filter posts list' ), __( 'Filter pages list' ) ), 'items_list_navigation' => array( __( 'Posts list navigation' ), __( 'Pages list navigation' ) ), - 'items_list' => array( __( 'Posts list' ), __( 'Pages list' ) ), + 'items_list' => array( __( 'Posts list' ), __( 'Pages list' ) ), ); $nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name']; @@ -1449,30 +1520,35 @@ function get_post_type_labels( $post_type_object ) { function _get_custom_object_labels( $object, $nohier_vs_hier_defaults ) { $object->labels = (array) $object->labels; - if ( isset( $object->label ) && empty( $object->labels['name'] ) ) + if ( isset( $object->label ) && empty( $object->labels['name'] ) ) { $object->labels['name'] = $object->label; + } - if ( !isset( $object->labels['singular_name'] ) && isset( $object->labels['name'] ) ) + if ( ! isset( $object->labels['singular_name'] ) && isset( $object->labels['name'] ) ) { $object->labels['singular_name'] = $object->labels['name']; + } - if ( ! isset( $object->labels['name_admin_bar'] ) ) + if ( ! isset( $object->labels['name_admin_bar'] ) ) { $object->labels['name_admin_bar'] = isset( $object->labels['singular_name'] ) ? $object->labels['singular_name'] : $object->name; + } - if ( !isset( $object->labels['menu_name'] ) && isset( $object->labels['name'] ) ) + if ( ! isset( $object->labels['menu_name'] ) && isset( $object->labels['name'] ) ) { $object->labels['menu_name'] = $object->labels['name']; + } - if ( !isset( $object->labels['all_items'] ) && isset( $object->labels['menu_name'] ) ) + if ( ! isset( $object->labels['all_items'] ) && isset( $object->labels['menu_name'] ) ) { $object->labels['all_items'] = $object->labels['menu_name']; + } - if ( !isset( $object->labels['archives'] ) && isset( $object->labels['all_items'] ) ) { + if ( ! isset( $object->labels['archives'] ) && isset( $object->labels['all_items'] ) ) { $object->labels['archives'] = $object->labels['all_items']; } $defaults = array(); foreach ( $nohier_vs_hier_defaults as $key => $value ) { - $defaults[$key] = $object->hierarchical ? $value[1] : $value[0]; + $defaults[ $key ] = $object->hierarchical ? $value[1] : $value[0]; } - $labels = array_merge( $defaults, $object->labels ); + $labels = array_merge( $defaults, $object->labels ); $object->labels = (object) $object->labels; return (object) $labels; @@ -1488,8 +1564,9 @@ function _add_post_type_submenus() { foreach ( get_post_types( array( 'show_ui' => true ) ) as $ptype ) { $ptype_obj = get_post_type_object( $ptype ); // Sub-menus only. - if ( ! $ptype_obj->show_in_menu || $ptype_obj->show_in_menu === true ) + if ( ! $ptype_obj->show_in_menu || $ptype_obj->show_in_menu === true ) { continue; + } add_submenu_page( $ptype_obj->show_in_menu, $ptype_obj->labels->name, $ptype_obj->labels->all_items, $ptype_obj->cap->edit_posts, "edit.php?post_type=$ptype" ); } } @@ -1518,11 +1595,12 @@ function add_post_type_support( $post_type, $feature ) { global $_wp_post_type_features; $features = (array) $feature; - foreach ($features as $feature) { - if ( func_num_args() == 2 ) - $_wp_post_type_features[$post_type][$feature] = true; - else - $_wp_post_type_features[$post_type][$feature] = array_slice( func_get_args(), 2 ); + foreach ( $features as $feature ) { + if ( func_num_args() == 2 ) { + $_wp_post_type_features[ $post_type ][ $feature ] = true; + } else { + $_wp_post_type_features[ $post_type ][ $feature ] = array_slice( func_get_args(), 2 ); + } } } @@ -1555,8 +1633,9 @@ function remove_post_type_support( $post_type, $feature ) { function get_all_post_type_supports( $post_type ) { global $_wp_post_type_features; - if ( isset( $_wp_post_type_features[$post_type] ) ) - return $_wp_post_type_features[$post_type]; + if ( isset( $_wp_post_type_features[ $post_type ] ) ) { + return $_wp_post_type_features[ $post_type ]; + } return array(); } @@ -1575,7 +1654,7 @@ function get_all_post_type_supports( $post_type ) { function post_type_supports( $post_type, $feature ) { global $_wp_post_type_features; - return ( isset( $_wp_post_type_features[$post_type][$feature] ) ); + return ( isset( $_wp_post_type_features[ $post_type ][ $feature ] ) ); } /** @@ -1617,8 +1696,8 @@ function get_post_types_by_support( $feature, $operator = 'and' ) { function set_post_type( $post_id = 0, $post_type = 'post' ) { global $wpdb; - $post_type = sanitize_post_field('post_type', $post_type, $post_id, 'db'); - $return = $wpdb->update( $wpdb->posts, array('post_type' => $post_type), array('ID' => $post_id) ); + $post_type = sanitize_post_field( 'post_type', $post_type, $post_id, 'db' ); + $return = $wpdb->update( $wpdb->posts, array( 'post_type' => $post_type ), array( 'ID' => $post_id ) ); clean_post_cache( $post_id ); @@ -1675,33 +1754,41 @@ function is_post_type_viewable( $post_type ) { */ function get_posts( $args = null ) { $defaults = array( - 'numberposts' => 5, - 'category' => 0, 'orderby' => 'date', - 'order' => 'DESC', 'include' => array(), - 'exclude' => array(), 'meta_key' => '', - 'meta_value' =>'', 'post_type' => 'post', - 'suppress_filters' => true + 'numberposts' => 5, + 'category' => 0, + 'orderby' => 'date', + 'order' => 'DESC', + 'include' => array(), + 'exclude' => array(), + 'meta_key' => '', + 'meta_value' => '', + 'post_type' => 'post', + 'suppress_filters' => true, ); $r = wp_parse_args( $args, $defaults ); - if ( empty( $r['post_status'] ) ) + if ( empty( $r['post_status'] ) ) { $r['post_status'] = ( 'attachment' == $r['post_type'] ) ? 'inherit' : 'publish'; - if ( ! empty($r['numberposts']) && empty($r['posts_per_page']) ) + } + if ( ! empty( $r['numberposts'] ) && empty( $r['posts_per_page'] ) ) { $r['posts_per_page'] = $r['numberposts']; - if ( ! empty($r['category']) ) + } + if ( ! empty( $r['category'] ) ) { $r['cat'] = $r['category']; - if ( ! empty($r['include']) ) { - $incposts = wp_parse_id_list( $r['include'] ); - $r['posts_per_page'] = count($incposts); // only the number of posts included - $r['post__in'] = $incposts; - } elseif ( ! empty($r['exclude']) ) + } + if ( ! empty( $r['include'] ) ) { + $incposts = wp_parse_id_list( $r['include'] ); + $r['posts_per_page'] = count( $incposts ); // only the number of posts included + $r['post__in'] = $incposts; + } elseif ( ! empty( $r['exclude'] ) ) { $r['post__not_in'] = wp_parse_id_list( $r['exclude'] ); + } $r['ignore_sticky_posts'] = true; - $r['no_found_rows'] = true; + $r['no_found_rows'] = true; $get_posts = new WP_Query; - return $get_posts->query($r); + return $get_posts->query( $r ); } @@ -1725,8 +1812,9 @@ function get_posts( $args = null ) { */ function add_post_meta( $post_id, $meta_key, $meta_value, $unique = false ) { // Make sure meta is added to the post, not a revision. - if ( $the_post = wp_is_post_revision($post_id) ) + if ( $the_post = wp_is_post_revision( $post_id ) ) { $post_id = $the_post; + } $added = add_metadata( 'post', $post_id, $meta_key, $meta_value, $unique ); if ( $added ) { @@ -1752,8 +1840,9 @@ function add_post_meta( $post_id, $meta_key, $meta_value, $unique = false ) { */ function delete_post_meta( $post_id, $meta_key, $meta_value = '' ) { // Make sure meta is added to the post, not a revision. - if ( $the_post = wp_is_post_revision($post_id) ) + if ( $the_post = wp_is_post_revision( $post_id ) ) { $post_id = $the_post; + } $deleted = delete_metadata( 'post', $post_id, $meta_key, $meta_value ); if ( $deleted ) { @@ -1777,7 +1866,7 @@ function delete_post_meta( $post_id, $meta_key, $meta_value = '' ) { * field if $single is true. */ function get_post_meta( $post_id, $key = '', $single = false ) { - return get_metadata('post', $post_id, $key, $single); + return get_metadata( 'post', $post_id, $key, $single ); } /** @@ -1800,8 +1889,9 @@ function get_post_meta( $post_id, $key = '', $single = false ) { */ function update_post_meta( $post_id, $meta_key, $meta_value, $prev_value = '' ) { // Make sure meta is added to the post, not a revision. - if ( $the_post = wp_is_post_revision($post_id) ) + if ( $the_post = wp_is_post_revision( $post_id ) ) { $post_id = $the_post; + } $updated = update_metadata( 'post', $post_id, $meta_key, $meta_value, $prev_value ); if ( $updated ) { @@ -1839,8 +1929,9 @@ function delete_post_meta_by_key( $post_meta_key ) { */ function get_post_custom( $post_id = 0 ) { $post_id = absint( $post_id ); - if ( ! $post_id ) + if ( ! $post_id ) { $post_id = get_the_ID(); + } return get_post_meta( $post_id ); } @@ -1858,11 +1949,13 @@ function get_post_custom( $post_id = 0 ) { function get_post_custom_keys( $post_id = 0 ) { $custom = get_post_custom( $post_id ); - if ( !is_array($custom) ) + if ( ! is_array( $custom ) ) { return; + } - if ( $keys = array_keys($custom) ) + if ( $keys = array_keys( $custom ) ) { return $keys; + } } /** @@ -1878,12 +1971,13 @@ function get_post_custom_keys( $post_id = 0 ) { * @return array|null Meta field values. */ function get_post_custom_values( $key = '', $post_id = 0 ) { - if ( !$key ) + if ( ! $key ) { return null; + } - $custom = get_post_custom($post_id); + $custom = get_post_custom( $post_id ); - return isset($custom[$key]) ? $custom[$key] : null; + return isset( $custom[ $key ] ) ? $custom[ $key ] : null; } /** @@ -1900,16 +1994,19 @@ function get_post_custom_values( $key = '', $post_id = 0 ) { function is_sticky( $post_id = 0 ) { $post_id = absint( $post_id ); - if ( ! $post_id ) + if ( ! $post_id ) { $post_id = get_the_ID(); + } $stickies = get_option( 'sticky_posts' ); - if ( ! is_array( $stickies ) ) + if ( ! is_array( $stickies ) ) { return false; + } - if ( in_array( $post_id, $stickies ) ) + if ( in_array( $post_id, $stickies ) ) { return true; + } return false; } @@ -1932,23 +2029,29 @@ function is_sticky( $post_id = 0 ) { * same type as $post). */ function sanitize_post( $post, $context = 'display' ) { - if ( is_object($post) ) { + if ( is_object( $post ) ) { // Check if post already filtered for this context. - if ( isset($post->filter) && $context == $post->filter ) + if ( isset( $post->filter ) && $context == $post->filter ) { return $post; - if ( !isset($post->ID) ) + } + if ( ! isset( $post->ID ) ) { $post->ID = 0; - foreach ( array_keys(get_object_vars($post)) as $field ) - $post->$field = sanitize_post_field($field, $post->$field, $post->ID, $context); + } + foreach ( array_keys( get_object_vars( $post ) ) as $field ) { + $post->$field = sanitize_post_field( $field, $post->$field, $post->ID, $context ); + } $post->filter = $context; } elseif ( is_array( $post ) ) { // Check if post already filtered for this context. - if ( isset($post['filter']) && $context == $post['filter'] ) + if ( isset( $post['filter'] ) && $context == $post['filter'] ) { return $post; - if ( !isset($post['ID']) ) + } + if ( ! isset( $post['ID'] ) ) { $post['ID'] = 0; - foreach ( array_keys($post) as $field ) - $post[$field] = sanitize_post_field($field, $post[$field], $post['ID'], $context); + } + foreach ( array_keys( $post ) as $field ) { + $post[ $field ] = sanitize_post_field( $field, $post[ $field ], $post['ID'], $context ); + } $post['filter'] = $context; } return $post; @@ -1972,28 +2075,30 @@ function sanitize_post( $post, $context = 'display' ) { * @return mixed Sanitized value. */ function sanitize_post_field( $field, $value, $post_id, $context = 'display' ) { - $int_fields = array('ID', 'post_parent', 'menu_order'); - if ( in_array($field, $int_fields) ) + $int_fields = array( 'ID', 'post_parent', 'menu_order' ); + if ( in_array( $field, $int_fields ) ) { $value = (int) $value; + } // Fields which contain arrays of integers. $array_int_fields = array( 'ancestors' ); - if ( in_array($field, $array_int_fields) ) { - $value = array_map( 'absint', $value); + if ( in_array( $field, $array_int_fields ) ) { + $value = array_map( 'absint', $value ); return $value; } - if ( 'raw' == $context ) + if ( 'raw' == $context ) { return $value; + } $prefixed = false; - if ( false !== strpos($field, 'post_') ) { - $prefixed = true; - $field_no_prefix = str_replace('post_', '', $field); + if ( false !== strpos( $field, 'post_' ) ) { + $prefixed = true; + $field_no_prefix = str_replace( 'post_', '', $field ); } if ( 'edit' == $context ) { - $format_to_edit = array('post_content', 'post_excerpt', 'post_title', 'post_password'); + $format_to_edit = array( 'post_content', 'post_excerpt', 'post_title', 'post_password' ); if ( $prefixed ) { @@ -2026,13 +2131,14 @@ function sanitize_post_field( $field, $value, $post_id, $context = 'display' ) { $value = apply_filters( "edit_post_{$field}", $value, $post_id ); } - if ( in_array($field, $format_to_edit) ) { - if ( 'post_content' == $field ) - $value = format_to_edit($value, user_can_richedit()); - else - $value = format_to_edit($value); + if ( in_array( $field, $format_to_edit ) ) { + if ( 'post_content' == $field ) { + $value = format_to_edit( $value, user_can_richedit() ); + } else { + $value = format_to_edit( $value ); + } } else { - $value = esc_attr($value); + $value = esc_attr( $value ); } } elseif ( 'db' == $context ) { if ( $prefixed ) { @@ -2119,13 +2225,15 @@ function sanitize_post_field( $field, $value, $post_id, $context = 'display' ) { * @param int $post_id Post ID. */ function stick_post( $post_id ) { - $stickies = get_option('sticky_posts'); + $stickies = get_option( 'sticky_posts' ); - if ( !is_array($stickies) ) - $stickies = array($post_id); + if ( ! is_array( $stickies ) ) { + $stickies = array( $post_id ); + } - if ( ! in_array($post_id, $stickies) ) + if ( ! in_array( $post_id, $stickies ) ) { $stickies[] = $post_id; + } $updated = update_option( 'sticky_posts', $stickies ); @@ -2151,19 +2259,22 @@ function stick_post( $post_id ) { * @param int $post_id Post ID. */ function unstick_post( $post_id ) { - $stickies = get_option('sticky_posts'); + $stickies = get_option( 'sticky_posts' ); - if ( !is_array($stickies) ) + if ( ! is_array( $stickies ) ) { return; + } - if ( ! in_array($post_id, $stickies) ) + if ( ! in_array( $post_id, $stickies ) ) { return; + } - $offset = array_search($post_id, $stickies); - if ( false === $offset ) + $offset = array_search( $post_id, $stickies ); + if ( false === $offset ) { return; + } - array_splice($stickies, $offset, 1); + array_splice( $stickies, $offset, 1 ); $updated = update_option( 'sticky_posts', $stickies ); @@ -2221,8 +2332,9 @@ function _count_posts_cache_key( $type = 'post', $perm = '' ) { function wp_count_posts( $type = 'post', $perm = '' ) { global $wpdb; - if ( ! post_type_exists( $type ) ) + if ( ! post_type_exists( $type ) ) { return new stdClass; + } $cache_key = _count_posts_cache_key( $type, $perm ); @@ -2234,9 +2346,10 @@ function wp_count_posts( $type = 'post', $perm = '' ) { $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s"; if ( 'readable' == $perm && is_user_logged_in() ) { - $post_type_object = get_post_type_object($type); + $post_type_object = get_post_type_object( $type ); if ( ! current_user_can( $post_type_object->cap->read_private_posts ) ) { - $query .= $wpdb->prepare( " AND (post_status != 'private' OR ( post_author = %d AND post_status = 'private' ))", + $query .= $wpdb->prepare( + " AND (post_status != 'private' OR ( post_author = %d AND post_status = 'private' ))", get_current_user_id() ); } @@ -2244,7 +2357,7 @@ function wp_count_posts( $type = 'post', $perm = '' ) { $query .= ' GROUP BY post_status'; $results = (array) $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A ); - $counts = array_fill_keys( get_post_stati(), 0 ); + $counts = array_fill_keys( get_post_stati(), 0 ); foreach ( $results as $row ) { $counts[ $row['post_status'] ] = $row['num_posts']; @@ -2286,14 +2399,14 @@ function wp_count_posts( $type = 'post', $perm = '' ) { function wp_count_attachments( $mime_type = '' ) { global $wpdb; - $and = wp_post_mime_type_where( $mime_type ); + $and = wp_post_mime_type_where( $mime_type ); $count = $wpdb->get_results( "SELECT post_mime_type, COUNT( * ) AS num_posts FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' $and GROUP BY post_mime_type", ARRAY_A ); $counts = array(); foreach ( (array) $count as $row ) { $counts[ $row['post_mime_type'] ] = $row['num_posts']; } - $counts['trash'] = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status = 'trash' $and"); + $counts['trash'] = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status = 'trash' $and" ); /** * Modify returned attachment counts by mime type. @@ -2316,10 +2429,10 @@ function wp_count_attachments( $mime_type = '' ) { * @return array List of post mime types. */ function get_post_mime_types() { - $post_mime_types = array( // array( adj, noun ) - 'image' => array(__('Images'), __('Manage Images'), _n_noop('Image (%s)', 'Images (%s)')), - 'audio' => array(__('Audio'), __('Manage Audio'), _n_noop('Audio (%s)', 'Audio (%s)')), - 'video' => array(__('Video'), __('Manage Video'), _n_noop('Video (%s)', 'Video (%s)')), + $post_mime_types = array( // array( adj, noun ) + 'image' => array( __( 'Images' ), __( 'Manage Images' ), _n_noop( 'Image (%s)', 'Images (%s)' ) ), + 'audio' => array( __( 'Audio' ), __( 'Manage Audio' ), _n_noop( 'Audio (%s)', 'Audio (%s)' ) ), + 'video' => array( __( 'Video' ), __( 'Manage Video' ), _n_noop( 'Video (%s)', 'Video (%s)' ) ), ); /** @@ -2356,16 +2469,16 @@ function wp_match_mime_types( $wildcard_mime_types, $real_mime_types ) { } $patternses = array(); - $wild = '[-._a-z0-9]*'; + $wild = '[-._a-z0-9]*'; foreach ( (array) $wildcard_mime_types as $type ) { $mimes = array_map( 'trim', explode( ',', $type ) ); foreach ( $mimes as $mime ) { - $regex = str_replace( '__wildcard__', $wild, preg_quote( str_replace( '*', '__wildcard__', $mime ) ) ); - $patternses[][$type] = "^$regex$"; + $regex = str_replace( '__wildcard__', $wild, preg_quote( str_replace( '*', '__wildcard__', $mime ) ) ); + $patternses[][ $type ] = "^$regex$"; if ( false === strpos( $mime, '/' ) ) { - $patternses[][$type] = "^$regex/"; - $patternses[][$type] = $regex; + $patternses[][ $type ] = "^$regex/"; + $patternses[][ $type ] = $regex; } } } @@ -2374,8 +2487,8 @@ function wp_match_mime_types( $wildcard_mime_types, $real_mime_types ) { foreach ( $patternses as $patterns ) { foreach ( $patterns as $type => $pattern ) { foreach ( (array) $real_mime_types as $real ) { - if ( preg_match( "#$pattern#", $real ) && ( empty( $matches[$type] ) || false === array_search( $real, $matches[$type] ) ) ) { - $matches[$type][] = $real; + if ( preg_match( "#$pattern#", $real ) && ( empty( $matches[ $type ] ) || false === array_search( $real, $matches[ $type ] ) ) ) { + $matches[ $type ][] = $real; } } } @@ -2395,42 +2508,48 @@ function wp_match_mime_types( $wildcard_mime_types, $real_mime_types ) { * @return string The SQL AND clause for mime searching. */ function wp_post_mime_type_where( $post_mime_types, $table_alias = '' ) { - $where = ''; - $wildcards = array('', '%', '%/%'); - if ( is_string($post_mime_types) ) - $post_mime_types = array_map('trim', explode(',', $post_mime_types)); + $where = ''; + $wildcards = array( '', '%', '%/%' ); + if ( is_string( $post_mime_types ) ) { + $post_mime_types = array_map( 'trim', explode( ',', $post_mime_types ) ); + } $wheres = array(); foreach ( (array) $post_mime_types as $mime_type ) { - $mime_type = preg_replace('/\s/', '', $mime_type); - $slashpos = strpos($mime_type, '/'); + $mime_type = preg_replace( '/\s/', '', $mime_type ); + $slashpos = strpos( $mime_type, '/' ); if ( false !== $slashpos ) { - $mime_group = preg_replace('/[^-*.a-zA-Z0-9]/', '', substr($mime_type, 0, $slashpos)); - $mime_subgroup = preg_replace('/[^-*.+a-zA-Z0-9]/', '', substr($mime_type, $slashpos + 1)); - if ( empty($mime_subgroup) ) + $mime_group = preg_replace( '/[^-*.a-zA-Z0-9]/', '', substr( $mime_type, 0, $slashpos ) ); + $mime_subgroup = preg_replace( '/[^-*.+a-zA-Z0-9]/', '', substr( $mime_type, $slashpos + 1 ) ); + if ( empty( $mime_subgroup ) ) { $mime_subgroup = '*'; - else - $mime_subgroup = str_replace('/', '', $mime_subgroup); + } else { + $mime_subgroup = str_replace( '/', '', $mime_subgroup ); + } $mime_pattern = "$mime_group/$mime_subgroup"; } else { - $mime_pattern = preg_replace('/[^-*.a-zA-Z0-9]/', '', $mime_type); - if ( false === strpos($mime_pattern, '*') ) + $mime_pattern = preg_replace( '/[^-*.a-zA-Z0-9]/', '', $mime_type ); + if ( false === strpos( $mime_pattern, '*' ) ) { $mime_pattern .= '/*'; + } } - $mime_pattern = preg_replace('/\*+/', '%', $mime_pattern); + $mime_pattern = preg_replace( '/\*+/', '%', $mime_pattern ); - if ( in_array( $mime_type, $wildcards ) ) + if ( in_array( $mime_type, $wildcards ) ) { return ''; + } - if ( false !== strpos($mime_pattern, '%') ) - $wheres[] = empty($table_alias) ? "post_mime_type LIKE '$mime_pattern'" : "$table_alias.post_mime_type LIKE '$mime_pattern'"; - else - $wheres[] = empty($table_alias) ? "post_mime_type = '$mime_pattern'" : "$table_alias.post_mime_type = '$mime_pattern'"; + if ( false !== strpos( $mime_pattern, '%' ) ) { + $wheres[] = empty( $table_alias ) ? "post_mime_type LIKE '$mime_pattern'" : "$table_alias.post_mime_type LIKE '$mime_pattern'"; + } else { + $wheres[] = empty( $table_alias ) ? "post_mime_type = '$mime_pattern'" : "$table_alias.post_mime_type = '$mime_pattern'"; + } + } + if ( ! empty( $wheres ) ) { + $where = ' AND (' . join( ' OR ', $wheres ) . ') '; } - if ( !empty($wheres) ) - $where = ' AND (' . join(' OR ', $wheres) . ') '; return $where; } @@ -2499,18 +2618,18 @@ function wp_delete_post( $postid = 0, $force_delete = false ) { */ do_action( 'before_delete_post', $postid ); - delete_post_meta($postid,'_wp_trash_meta_status'); - delete_post_meta($postid,'_wp_trash_meta_time'); + delete_post_meta( $postid, '_wp_trash_meta_status' ); + delete_post_meta( $postid, '_wp_trash_meta_time' ); - wp_delete_object_term_relationships($postid, get_object_taxonomies($post->post_type)); + wp_delete_object_term_relationships( $postid, get_object_taxonomies( $post->post_type ) ); - $parent_data = array( 'post_parent' => $post->post_parent ); + $parent_data = array( 'post_parent' => $post->post_parent ); $parent_where = array( 'post_parent' => $postid ); if ( is_post_type_hierarchical( $post->post_type ) ) { // Point children of this page to its parent, also clean the cache of affected children. $children_query = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_parent = %d AND post_type = %s", $postid, $post->post_type ); - $children = $wpdb->get_results( $children_query ); + $children = $wpdb->get_results( $children_query ); if ( $children ) { $wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => $post->post_type ) ); } @@ -2519,24 +2638,26 @@ function wp_delete_post( $postid = 0, $force_delete = false ) { // Do raw query. wp_get_post_revisions() is filtered. $revision_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'revision'", $postid ) ); // Use wp_delete_post (via wp_delete_post_revision) again. Ensures any meta/misplaced data gets cleaned up. - foreach ( $revision_ids as $revision_id ) + foreach ( $revision_ids as $revision_id ) { wp_delete_post_revision( $revision_id ); + } // Point all attachments to this post up one level. $wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => 'attachment' ) ); wp_defer_comment_counting( true ); - $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $postid )); + $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $postid ) ); foreach ( $comment_ids as $comment_id ) { wp_delete_comment( $comment_id, true ); } wp_defer_comment_counting( false ); - $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $postid )); - foreach ( $post_meta_ids as $mid ) + $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $postid ) ); + foreach ( $post_meta_ids as $mid ) { delete_metadata_by_mid( 'post', $mid ); + } /** * Fires immediately before a post is deleted from the database. @@ -2563,11 +2684,12 @@ function wp_delete_post( $postid = 0, $force_delete = false ) { clean_post_cache( $post ); if ( is_post_type_hierarchical( $post->post_type ) && $children ) { - foreach ( $children as $child ) + foreach ( $children as $child ) { clean_post_cache( $child ); + } } - wp_clear_scheduled_hook('publish_future_post', array( $postid ) ); + wp_clear_scheduled_hook( 'publish_future_post', array( $postid ) ); /** * Fires after a post is deleted, at the conclusion of wp_delete_post(). @@ -2597,10 +2719,10 @@ function wp_delete_post( $postid = 0, $force_delete = false ) { function _reset_front_page_settings_for_post( $post_id ) { $post = get_post( $post_id ); if ( 'page' == $post->post_type ) { - /* - * If the page is defined in option page_on_front or post_for_posts, - * adjust the corresponding options. - */ + /* + * If the page is defined in option page_on_front or post_for_posts, + * adjust the corresponding options. + */ if ( get_option( 'page_on_front' ) == $post->ID ) { update_option( 'show_on_front', 'posts' ); update_option( 'page_on_front', 0 ); @@ -2665,7 +2787,12 @@ function wp_trash_post( $post_id = 0 ) { add_post_meta( $post_id, '_wp_trash_meta_status', $post->post_status ); add_post_meta( $post_id, '_wp_trash_meta_time', time() ); - wp_update_post( array( 'ID' => $post_id, 'post_status' => 'trash' ) ); + wp_update_post( + array( + 'ID' => $post_id, + 'post_status' => 'trash', + ) + ); wp_trash_post_comments( $post_id ); @@ -2727,7 +2854,12 @@ function wp_untrash_post( $post_id = 0 ) { delete_post_meta( $post_id, '_wp_trash_meta_status' ); delete_post_meta( $post_id, '_wp_trash_meta_time' ); - wp_update_post( array( 'ID' => $post_id, 'post_status' => $post_status ) ); + wp_update_post( + array( + 'ID' => $post_id, + 'post_status' => $post_status, + ) + ); wp_untrash_post_comments( $post_id ); @@ -2756,9 +2888,10 @@ function wp_untrash_post( $post_id = 0 ) { function wp_trash_post_comments( $post = null ) { global $wpdb; - $post = get_post($post); - if ( empty($post) ) + $post = get_post( $post ); + if ( empty( $post ) ) { return; + } $post_id = $post->ID; @@ -2771,20 +2904,22 @@ function wp_trash_post_comments( $post = null ) { */ do_action( 'trash_post_comments', $post_id ); - $comments = $wpdb->get_results( $wpdb->prepare("SELECT comment_ID, comment_approved FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id) ); - if ( empty($comments) ) + $comments = $wpdb->get_results( $wpdb->prepare( "SELECT comment_ID, comment_approved FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ) ); + if ( empty( $comments ) ) { return; + } // Cache current status for each comment. $statuses = array(); - foreach ( $comments as $comment ) - $statuses[$comment->comment_ID] = $comment->comment_approved; - add_post_meta($post_id, '_wp_trash_meta_comments_status', $statuses); + foreach ( $comments as $comment ) { + $statuses[ $comment->comment_ID ] = $comment->comment_approved; + } + add_post_meta( $post_id, '_wp_trash_meta_comments_status', $statuses ); // Set status for all comments to post-trashed. - $result = $wpdb->update($wpdb->comments, array('comment_approved' => 'post-trashed'), array('comment_post_ID' => $post_id)); + $result = $wpdb->update( $wpdb->comments, array( 'comment_approved' => 'post-trashed' ), array( 'comment_post_ID' => $post_id ) ); - clean_comment_cache( array_keys($statuses) ); + clean_comment_cache( array_keys( $statuses ) ); /** * Fires after comments are sent to the trash. @@ -2812,16 +2947,18 @@ function wp_trash_post_comments( $post = null ) { function wp_untrash_post_comments( $post = null ) { global $wpdb; - $post = get_post($post); - if ( empty($post) ) + $post = get_post( $post ); + if ( empty( $post ) ) { return; + } $post_id = $post->ID; - $statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true); + $statuses = get_post_meta( $post_id, '_wp_trash_meta_comments_status', true ); - if ( empty($statuses) ) + if ( empty( $statuses ) ) { return true; + } /** * Fires before comments are restored for a post from the trash. @@ -2834,8 +2971,9 @@ function wp_untrash_post_comments( $post = null ) { // Restore each comment to its original status. $group_by_status = array(); - foreach ( $statuses as $comment_id => $comment_status ) - $group_by_status[$comment_status][] = $comment_id; + foreach ( $statuses as $comment_id => $comment_status ) { + $group_by_status[ $comment_status ][] = $comment_id; + } foreach ( $group_by_status as $status => $comments ) { // Sanity check. This shouldn't happen. @@ -2846,9 +2984,9 @@ function wp_untrash_post_comments( $post = null ) { $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->comments SET comment_approved = %s WHERE comment_ID IN ($comments_in)", $status ) ); } - clean_comment_cache( array_keys($statuses) ); + clean_comment_cache( array_keys( $statuses ) ); - delete_post_meta($post_id, '_wp_trash_meta_comments_status'); + delete_post_meta( $post_id, '_wp_trash_meta_comments_status' ); /** * Fires after comments are restored for a post from the trash. @@ -2882,10 +3020,10 @@ function wp_untrash_post_comments( $post = null ) { function wp_get_post_categories( $post_id = 0, $args = array() ) { $post_id = (int) $post_id; - $defaults = array('fields' => 'ids'); - $args = wp_parse_args( $args, $defaults ); + $defaults = array( 'fields' => 'ids' ); + $args = wp_parse_args( $args, $defaults ); - $cats = wp_get_object_terms($post_id, 'category', $args); + $cats = wp_get_object_terms( $post_id, 'category', $args ); return $cats; } @@ -2906,7 +3044,7 @@ function wp_get_post_categories( $post_id = 0, $args = array() ) { * WP_Error object if 'post_tag' taxonomy doesn't exist. */ function wp_get_post_tags( $post_id = 0, $args = array() ) { - return wp_get_post_terms( $post_id, 'post_tag', $args); + return wp_get_post_terms( $post_id, 'post_tag', $args ); } /** @@ -2929,10 +3067,10 @@ function wp_get_post_tags( $post_id = 0, $args = array() ) { function wp_get_post_terms( $post_id = 0, $taxonomy = 'post_tag', $args = array() ) { $post_id = (int) $post_id; - $defaults = array('fields' => 'all'); - $args = wp_parse_args( $args, $defaults ); + $defaults = array( 'fields' => 'all' ); + $args = wp_parse_args( $args, $defaults ); - $tags = wp_get_object_terms($post_id, $taxonomy, $args); + $tags = wp_get_object_terms( $post_id, $taxonomy, $args ); return $tags; } @@ -2959,12 +3097,18 @@ function wp_get_recent_posts( $args = array(), $output = ARRAY_A ) { // Set default arguments. $defaults = array( - 'numberposts' => 10, 'offset' => 0, - 'category' => 0, 'orderby' => 'post_date', - 'order' => 'DESC', 'include' => '', - 'exclude' => '', 'meta_key' => '', - 'meta_value' =>'', 'post_type' => 'post', 'post_status' => 'draft, publish, future, pending, private', - 'suppress_filters' => true + 'numberposts' => 10, + 'offset' => 0, + 'category' => 0, + 'orderby' => 'post_date', + 'order' => 'DESC', + 'include' => '', + 'exclude' => '', + 'meta_key' => '', + 'meta_value' => '', + 'post_type' => 'post', + 'post_status' => 'draft, publish, future, pending, private', + 'suppress_filters' => true, ); $r = wp_parse_args( $args, $defaults ); @@ -2972,9 +3116,9 @@ function wp_get_recent_posts( $args = array(), $output = ARRAY_A ) { $results = get_posts( $r ); // Backward compatibility. Prior to 3.1 expected posts to be returned in array. - if ( ARRAY_A == $output ){ + if ( ARRAY_A == $output ) { foreach ( $results as $key => $result ) { - $results[$key] = get_object_vars( $result ); + $results[ $key ] = get_object_vars( $result ); } return $results ? $results : array(); } @@ -3049,41 +3193,41 @@ function wp_insert_post( $postarr, $wp_error = false ) { $user_id = get_current_user_id(); $defaults = array( - 'post_author' => $user_id, - 'post_content' => '', + 'post_author' => $user_id, + 'post_content' => '', 'post_content_filtered' => '', - 'post_title' => '', - 'post_excerpt' => '', - 'post_status' => 'draft', - 'post_type' => 'post', - 'comment_status' => '', - 'ping_status' => '', - 'post_password' => '', - 'to_ping' => '', - 'pinged' => '', - 'post_parent' => 0, - 'menu_order' => 0, - 'guid' => '', - 'import_id' => 0, - 'context' => '', + 'post_title' => '', + 'post_excerpt' => '', + 'post_status' => 'draft', + 'post_type' => 'post', + 'comment_status' => '', + 'ping_status' => '', + 'post_password' => '', + 'to_ping' => '', + 'pinged' => '', + 'post_parent' => 0, + 'menu_order' => 0, + 'guid' => '', + 'import_id' => 0, + 'context' => '', ); - $postarr = wp_parse_args($postarr, $defaults); + $postarr = wp_parse_args( $postarr, $defaults ); - unset( $postarr[ 'filter' ] ); + unset( $postarr['filter'] ); - $postarr = sanitize_post($postarr, 'db'); + $postarr = sanitize_post( $postarr, 'db' ); // Are we updating or creating? $post_ID = 0; - $update = false; - $guid = $postarr['guid']; + $update = false; + $guid = $postarr['guid']; if ( ! empty( $postarr['ID'] ) ) { $update = true; // Get the post ID and GUID. - $post_ID = $postarr['ID']; + $post_ID = $postarr['ID']; $post_before = get_post( $post_ID ); if ( is_null( $post_before ) ) { if ( $wp_error ) { @@ -3092,15 +3236,15 @@ function wp_insert_post( $postarr, $wp_error = false ) { return 0; } - $guid = get_post_field( 'guid', $post_ID ); - $previous_status = get_post_field('post_status', $post_ID ); + $guid = get_post_field( 'guid', $post_ID ); + $previous_status = get_post_field( 'post_status', $post_ID ); } else { $previous_status = 'new'; } $post_type = empty( $postarr['post_type'] ) ? 'post' : $postarr['post_type']; - $post_title = $postarr['post_title']; + $post_title = $postarr['post_title']; $post_content = $postarr['post_content']; $post_excerpt = $postarr['post_excerpt']; if ( isset( $postarr['post_name'] ) ) { @@ -3154,14 +3298,14 @@ function wp_insert_post( $postarr, $wp_error = false ) { if ( empty( $post_category ) || 0 == count( $post_category ) || ! is_array( $post_category ) ) { // 'post' requires at least one category. if ( 'post' == $post_type && 'auto-draft' != $post_status ) { - $post_category = array( get_option('default_category') ); + $post_category = array( get_option( 'default_category' ) ); } else { $post_category = array(); } } // Don't allow contributors to set the post slug for pending review posts. - if ( 'pending' == $post_status && !current_user_can( 'publish_posts' ) ) { + if ( 'pending' == $post_status && ! current_user_can( 'publish_posts' ) ) { $post_name = ''; } @@ -3169,9 +3313,9 @@ function wp_insert_post( $postarr, $wp_error = false ) { * Create a valid post name. Drafts and pending posts are allowed to have * an empty post name. */ - if ( empty($post_name) ) { - if ( !in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) { - $post_name = sanitize_title($post_title); + if ( empty( $post_name ) ) { + if ( ! in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) { + $post_name = sanitize_title( $post_title ); } else { $post_name = ''; } @@ -3181,7 +3325,7 @@ function wp_insert_post( $postarr, $wp_error = false ) { if ( $update && strtolower( urlencode( $post_name ) ) == $check_name && get_post_field( 'post_name', $post_ID ) == $check_name ) { $post_name = $check_name; } else { // new post, or slug has changed. - $post_name = sanitize_title($post_name); + $post_name = sanitize_title( $post_name ); } } @@ -3200,9 +3344,9 @@ function wp_insert_post( $postarr, $wp_error = false ) { } // Validate the date. - $mm = substr( $post_date, 5, 2 ); - $jj = substr( $post_date, 8, 2 ); - $aa = substr( $post_date, 0, 4 ); + $mm = substr( $post_date, 5, 2 ); + $jj = substr( $post_date, 8, 2 ); + $aa = substr( $post_date, 0, 4 ); $valid_date = wp_checkdate( $mm, $jj, $aa, $post_date ); if ( ! $valid_date ) { if ( $wp_error ) { @@ -3232,13 +3376,13 @@ function wp_insert_post( $postarr, $wp_error = false ) { if ( 'attachment' !== $post_type ) { if ( 'publish' == $post_status ) { - $now = gmdate('Y-m-d H:i:59'); - if ( mysql2date('U', $post_date_gmt, false) > mysql2date('U', $now, false) ) { + $now = gmdate( 'Y-m-d H:i:59' ); + if ( mysql2date( 'U', $post_date_gmt, false ) > mysql2date( 'U', $now, false ) ) { $post_status = 'future'; } } elseif ( 'future' == $post_status ) { - $now = gmdate('Y-m-d H:i:59'); - if ( mysql2date('U', $post_date_gmt, false) <= mysql2date('U', $now, false) ) { + $now = gmdate( 'Y-m-d H:i:59' ); + if ( mysql2date( 'U', $post_date_gmt, false ) <= mysql2date( 'U', $now, false ) ) { $post_status = 'publish'; } } @@ -3257,11 +3401,11 @@ function wp_insert_post( $postarr, $wp_error = false ) { // These variables are needed by compact() later. $post_content_filtered = $postarr['post_content_filtered']; - $post_author = isset( $postarr['post_author'] ) ? $postarr['post_author'] : $user_id; - $ping_status = empty( $postarr['ping_status'] ) ? get_default_comment_status( $post_type, 'pingback' ) : $postarr['ping_status']; - $to_ping = isset( $postarr['to_ping'] ) ? sanitize_trackback_urls( $postarr['to_ping'] ) : ''; - $pinged = isset( $postarr['pinged'] ) ? $postarr['pinged'] : ''; - $import_id = isset( $postarr['import_id'] ) ? $postarr['import_id'] : 0; + $post_author = isset( $postarr['post_author'] ) ? $postarr['post_author'] : $user_id; + $ping_status = empty( $postarr['ping_status'] ) ? get_default_comment_status( $post_type, 'pingback' ) : $postarr['ping_status']; + $to_ping = isset( $postarr['to_ping'] ) ? sanitize_trackback_urls( $postarr['to_ping'] ) : ''; + $pinged = isset( $postarr['pinged'] ) ? $postarr['pinged'] : ''; + $import_id = isset( $postarr['import_id'] ) ? $postarr['import_id'] : 0; /* * The 'wp_insert_post_parent' filter expects all variables to be present. @@ -3358,7 +3502,7 @@ function wp_insert_post( $postarr, $wp_error = false ) { */ $data = apply_filters( 'wp_insert_post_data', $data, $postarr ); } - $data = wp_unslash( $data ); + $data = wp_unslash( $data ); $where = array( 'ID' => $post_ID ); if ( $update ) { @@ -3373,7 +3517,7 @@ function wp_insert_post( $postarr, $wp_error = false ) { do_action( 'pre_post_update', $post_ID, $data ); if ( false === $wpdb->update( $wpdb->posts, $data, $where ) ) { if ( $wp_error ) { - return new WP_Error('db_update_error', __('Could not update post in the database'), $wpdb->last_error); + return new WP_Error( 'db_update_error', __( 'Could not update post in the database' ), $wpdb->last_error ); } else { return 0; } @@ -3382,13 +3526,13 @@ function wp_insert_post( $postarr, $wp_error = false ) { // If there is a suggested ID, use it if not already present. if ( ! empty( $import_id ) ) { $import_id = (int) $import_id; - if ( ! $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE ID = %d", $import_id) ) ) { + if ( ! $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE ID = %d", $import_id ) ) ) { $data['ID'] = $import_id; } } if ( false === $wpdb->insert( $wpdb->posts, $data ) ) { if ( $wp_error ) { - return new WP_Error('db_insert_error', __('Could not insert post into the database'), $wpdb->last_error); + return new WP_Error( 'db_insert_error', __( 'Could not insert post into the database' ), $wpdb->last_error ); } else { return 0; } @@ -3416,7 +3560,7 @@ function wp_insert_post( $postarr, $wp_error = false ) { // New-style support for all custom taxonomies. if ( ! empty( $postarr['tax_input'] ) ) { foreach ( $postarr['tax_input'] as $taxonomy => $tags ) { - $taxonomy_obj = get_taxonomy($taxonomy); + $taxonomy_obj = get_taxonomy( $taxonomy ); if ( ! $taxonomy_obj ) { /* translators: %s: taxonomy name */ _doing_it_wrong( __FUNCTION__, sprintf( __( 'Invalid taxonomy: %s.' ), $taxonomy ), '4.4.0' ); @@ -3425,7 +3569,7 @@ function wp_insert_post( $postarr, $wp_error = false ) { // array = hierarchical, string = non-hierarchical. if ( is_array( $tags ) ) { - $tags = array_filter($tags); + $tags = array_filter( $tags ); } if ( current_user_can( $taxonomy_obj->cap->assign_terms ) ) { wp_set_post_terms( $post_ID, $tags, $taxonomy ); @@ -3483,7 +3627,7 @@ function wp_insert_post( $postarr, $wp_error = false ) { if ( ! empty( $postarr['page_template'] ) ) { $post->page_template = $postarr['page_template']; - $page_templates = wp_get_theme()->get_page_templates( $post ); + $page_templates = wp_get_theme()->get_page_templates( $post ); if ( 'default' != $postarr['page_template'] && ! isset( $page_templates[ $postarr['page_template'] ] ) ) { if ( $wp_error ) { return new WP_Error( 'invalid_page_template', __( 'Invalid page template.' ) ); @@ -3543,7 +3687,7 @@ function wp_insert_post( $postarr, $wp_error = false ) { * @param WP_Post $post Post object. */ do_action( 'edit_post', $post_ID, $post ); - $post_after = get_post($post_ID); + $post_after = get_post( $post_ID ); /** * Fires once an existing post has been updated. @@ -3554,7 +3698,7 @@ function wp_insert_post( $postarr, $wp_error = false ) { * @param WP_Post $post_after Post object following the update. * @param WP_Post $post_before Post object before the update. */ - do_action( 'post_updated', $post_ID, $post_after, $post_before); + do_action( 'post_updated', $post_ID, $post_after, $post_before ); } /** @@ -3610,48 +3754,52 @@ function wp_insert_post( $postarr, $wp_error = false ) { * @return int|WP_Error The value 0 or WP_Error on failure. The post ID on success. */ function wp_update_post( $postarr = array(), $wp_error = false ) { - if ( is_object($postarr) ) { + if ( is_object( $postarr ) ) { // Non-escaped post was passed. - $postarr = get_object_vars($postarr); - $postarr = wp_slash($postarr); + $postarr = get_object_vars( $postarr ); + $postarr = wp_slash( $postarr ); } // First, get all of the original fields. - $post = get_post($postarr['ID'], ARRAY_A); + $post = get_post( $postarr['ID'], ARRAY_A ); if ( is_null( $post ) ) { - if ( $wp_error ) + if ( $wp_error ) { return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) ); + } return 0; } // Escape data pulled from DB. - $post = wp_slash($post); + $post = wp_slash( $post ); // Passed post category list overwrites existing category list if not empty. - if ( isset($postarr['post_category']) && is_array($postarr['post_category']) - && 0 != count($postarr['post_category']) ) + if ( isset( $postarr['post_category'] ) && is_array( $postarr['post_category'] ) + && 0 != count( $postarr['post_category'] ) ) { $post_cats = $postarr['post_category']; - else + } else { $post_cats = $post['post_category']; + } // Drafts shouldn't be assigned a date unless explicitly done so by the user. - if ( isset( $post['post_status'] ) && in_array($post['post_status'], array('draft', 'pending', 'auto-draft')) && empty($postarr['edit_date']) && - ('0000-00-00 00:00:00' == $post['post_date_gmt']) ) + if ( isset( $post['post_status'] ) && in_array( $post['post_status'], array( 'draft', 'pending', 'auto-draft' ) ) && empty( $postarr['edit_date'] ) && + ( '0000-00-00 00:00:00' == $post['post_date_gmt'] ) ) { $clear_date = true; - else + } else { $clear_date = false; + } // Merge old and new fields with new fields overwriting old ones. - $postarr = array_merge($post, $postarr); + $postarr = array_merge( $post, $postarr ); $postarr['post_category'] = $post_cats; if ( $clear_date ) { - $postarr['post_date'] = current_time('mysql'); + $postarr['post_date'] = current_time( 'mysql' ); $postarr['post_date_gmt'] = ''; } - if ($postarr['post_type'] == 'attachment') - return wp_insert_attachment($postarr); + if ( $postarr['post_type'] == 'attachment' ) { + return wp_insert_attachment( $postarr ); + } return wp_insert_post( $postarr, $wp_error ); } @@ -3668,17 +3816,19 @@ function wp_update_post( $postarr = array(), $wp_error = false ) { function wp_publish_post( $post ) { global $wpdb; - if ( ! $post = get_post( $post ) ) + if ( ! $post = get_post( $post ) ) { return; + } - if ( 'publish' == $post->post_status ) + if ( 'publish' == $post->post_status ) { return; + } $wpdb->update( $wpdb->posts, array( 'post_status' => 'publish' ), array( 'ID' => $post->ID ) ); clean_post_cache( $post->ID ); - $old_status = $post->post_status; + $old_status = $post->post_status; $post->post_status = 'publish'; wp_transition_post_status( 'publish', $old_status, $post ); @@ -3706,13 +3856,15 @@ function wp_publish_post( $post ) { * @param int|WP_Post $post_id Post ID or post object. */ function check_and_publish_future_post( $post_id ) { - $post = get_post($post_id); + $post = get_post( $post_id ); - if ( empty($post) ) + if ( empty( $post ) ) { return; + } - if ( 'future' != $post->post_status ) + if ( 'future' != $post->post_status ) { return; + } $time = strtotime( $post->post_date_gmt . ' GMT' ); @@ -3743,20 +3895,22 @@ function check_and_publish_future_post( $post_id ) { * @return string Unique slug for the post, based on $post_name (with a -1, -2, etc. suffix) */ function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent ) { - if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) || ( 'inherit' == $post_status && 'revision' == $post_type ) ) + if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) || ( 'inherit' == $post_status && 'revision' == $post_type ) ) { return $slug; + } global $wpdb, $wp_rewrite; $original_slug = $slug; $feeds = $wp_rewrite->feeds; - if ( ! is_array( $feeds ) ) + if ( ! is_array( $feeds ) ) { $feeds = array(); + } if ( 'attachment' == $post_type ) { // Attachment slugs must be unique across all types. - $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d LIMIT 1"; + $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d LIMIT 1"; $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_ID ) ); /** @@ -3770,21 +3924,22 @@ function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_p if ( $post_name_check || in_array( $slug, $feeds ) || 'embed' === $slug || apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $slug ) ) { $suffix = 2; do { - $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; + $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_ID ) ); $suffix++; } while ( $post_name_check ); $slug = $alt_post_name; } } elseif ( is_post_type_hierarchical( $post_type ) ) { - if ( 'nav_menu_item' == $post_type ) + if ( 'nav_menu_item' == $post_type ) { return $slug; + } /* * Page slugs must be unique within their own trees. Pages are in a separate * namespace than posts so page slugs are allowed to overlap post slugs. */ - $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( %s, 'attachment' ) AND ID != %d AND post_parent = %d LIMIT 1"; + $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( %s, 'attachment' ) AND ID != %d AND post_parent = %d LIMIT 1"; $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID, $post_parent ) ); /** @@ -3797,10 +3952,10 @@ function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_p * @param string $post_type Post type. * @param int $post_parent Post parent ID. */ - if ( $post_name_check || in_array( $slug, $feeds ) || 'embed' === $slug || preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug ) || apply_filters( 'wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post_type, $post_parent ) ) { + if ( $post_name_check || in_array( $slug, $feeds ) || 'embed' === $slug || preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug ) || apply_filters( 'wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post_type, $post_parent ) ) { $suffix = 2; do { - $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; + $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_ID, $post_parent ) ); $suffix++; } while ( $post_name_check ); @@ -3808,11 +3963,11 @@ function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_p } } else { // Post slugs must be unique across all posts. - $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1"; + $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1"; $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID ) ); // Prevent new post slugs that could result in URLs that conflict with date archives. - $post = get_post( $post_ID ); + $post = get_post( $post_ID ); $conflicts_with_date_archive = false; if ( 'post' === $post_type && ( ! $post || $post->post_name !== $slug ) && preg_match( '/^[0-9]+$/', $slug ) && $slug_num = intval( $slug ) ) { $permastructs = array_values( array_filter( explode( '/', get_option( 'permalink_structure' ) ) ) ); @@ -3845,7 +4000,7 @@ function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_p if ( $post_name_check || in_array( $slug, $feeds ) || 'embed' === $slug || $conflicts_with_date_archive || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type ) ) { $suffix = 2; do { - $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; + $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_ID ) ); $suffix++; } while ( $post_name_check ); @@ -3883,10 +4038,11 @@ function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_p function _truncate_post_slug( $slug, $length = 200 ) { if ( strlen( $slug ) > $length ) { $decoded_slug = urldecode( $slug ); - if ( $decoded_slug === $slug ) + if ( $decoded_slug === $slug ) { $slug = substr( $slug, 0, $length ); - else + } else { $slug = utf8_uri_encode( $decoded_slug, $length ); + } } return rtrim( $slug, '-' ); @@ -3905,7 +4061,7 @@ function _truncate_post_slug( $slug, $length = 200 ) { * @return array|false|WP_Error Array of affected term IDs. WP_Error or false on failure. */ function wp_add_post_tags( $post_id = 0, $tags = '' ) { - return wp_set_post_tags($post_id, $tags, true); + return wp_set_post_tags( $post_id, $tags, true ); } /** @@ -3923,7 +4079,7 @@ function wp_add_post_tags( $post_id = 0, $tags = '' ) { * @return array|false|WP_Error Array of term taxonomy IDs of affected terms. WP_Error or false on failure. */ function wp_set_post_tags( $post_id = 0, $tags = '', $append = false ) { - return wp_set_post_terms( $post_id, $tags, 'post_tag', $append); + return wp_set_post_terms( $post_id, $tags, 'post_tag', $append ); } /** @@ -3944,16 +4100,19 @@ function wp_set_post_tags( $post_id = 0, $tags = '', $append = false ) { function wp_set_post_terms( $post_id = 0, $tags = '', $taxonomy = 'post_tag', $append = false ) { $post_id = (int) $post_id; - if ( !$post_id ) + if ( ! $post_id ) { return false; + } - if ( empty($tags) ) + if ( empty( $tags ) ) { $tags = array(); + } if ( ! is_array( $tags ) ) { $comma = _x( ',', 'tag delimiter' ); - if ( ',' !== $comma ) + if ( ',' !== $comma ) { $tags = str_replace( $comma, ',', $tags ); + } $tags = explode( ',', trim( $tags, " \n\t\r\0\x0B," ) ); } @@ -3985,15 +4144,15 @@ function wp_set_post_terms( $post_id = 0, $tags = '', $taxonomy = 'post_tag', $a * @return array|false|WP_Error Array of term taxonomy IDs of affected categories. WP_Error or false on failure. */ function wp_set_post_categories( $post_ID = 0, $post_categories = array(), $append = false ) { - $post_ID = (int) $post_ID; - $post_type = get_post_type( $post_ID ); + $post_ID = (int) $post_ID; + $post_type = get_post_type( $post_ID ); $post_status = get_post_status( $post_ID ); // If $post_categories isn't already an array, make it one: $post_categories = (array) $post_categories; if ( empty( $post_categories ) ) { if ( 'post' == $post_type && 'auto-draft' != $post_status ) { - $post_categories = array( get_option('default_category') ); - $append = false; + $post_categories = array( get_option( 'default_category' ) ); + $append = false; } else { $post_categories = array(); } @@ -4101,11 +4260,10 @@ function add_ping( $post_id, $uri ) { if ( is_array( $uri ) ) { $pung = array_merge( $pung, $uri ); - } - else { + } else { $pung[] = $uri; } - $new = implode("\n", $pung); + $new = implode( "\n", $pung ); /** * Filters the new ping URL to add for the given post. @@ -4131,16 +4289,18 @@ function add_ping( $post_id, $uri ) { */ function get_enclosed( $post_id ) { $custom_fields = get_post_custom( $post_id ); - $pung = array(); - if ( !is_array( $custom_fields ) ) + $pung = array(); + if ( ! is_array( $custom_fields ) ) { return $pung; + } foreach ( $custom_fields as $key => $val ) { - if ( 'enclosure' != $key || !is_array( $val ) ) + if ( 'enclosure' != $key || ! is_array( $val ) ) { continue; + } foreach ( $val as $enc ) { $enclosure = explode( "\n", $enc ); - $pung[] = trim( $enclosure[ 0 ] ); + $pung[] = trim( $enclosure[0] ); } } @@ -4201,7 +4361,7 @@ function get_to_ping( $post_id ) { } $to_ping = sanitize_trackback_urls( $post->to_ping ); - $to_ping = preg_split('/\s/', $to_ping, -1, PREG_SPLIT_NO_EMPTY); + $to_ping = preg_split( '/\s/', $to_ping, -1, PREG_SPLIT_NO_EMPTY ); /** * Filters the list of URLs yet to ping for the given post. @@ -4257,10 +4417,10 @@ function trackback_url_list( $tb_list, $post_id ) { function get_all_page_ids() { global $wpdb; - $page_ids = wp_cache_get('all_page_ids', 'posts'); + $page_ids = wp_cache_get( 'all_page_ids', 'posts' ); if ( ! is_array( $page_ids ) ) { - $page_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type = 'page'"); - wp_cache_add('all_page_ids', $page_ids, 'posts'); + $page_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type = 'page'" ); + wp_cache_add( 'all_page_ids', $page_ids, 'posts' ); } return $page_ids; @@ -4281,7 +4441,7 @@ function get_all_page_ids() { * 'edit', 'db', 'display'. Default 'raw'. * @return WP_Post|array|null WP_Post (or array) on success, or null on failure. */ -function get_page( $page, $output = OBJECT, $filter = 'raw') { +function get_page( $page, $output = OBJECT, $filter = 'raw' ) { return get_post( $page, $output, $filter ); } @@ -4303,9 +4463,9 @@ function get_page_by_path( $page_path, $output = OBJECT, $post_type = 'page' ) { $last_changed = wp_cache_get_last_changed( 'posts' ); - $hash = md5( $page_path . serialize( $post_type ) ); + $hash = md5( $page_path . serialize( $post_type ) ); $cache_key = "get_page_by_path:$hash:$last_changed"; - $cached = wp_cache_get( $cache_key, 'posts' ); + $cached = wp_cache_get( $cache_key, 'posts' ); if ( false !== $cached ) { // Special case: '0' is a bad `$page_path`. if ( '0' === $cached || 0 === $cached ) { @@ -4315,11 +4475,11 @@ function get_page_by_path( $page_path, $output = OBJECT, $post_type = 'page' ) { } } - $page_path = rawurlencode(urldecode($page_path)); - $page_path = str_replace('%2F', '/', $page_path); - $page_path = str_replace('%20', ' ', $page_path); - $parts = explode( '/', trim( $page_path, '/' ) ); - $parts = array_map( 'sanitize_title_for_query', $parts ); + $page_path = rawurlencode( urldecode( $page_path ) ); + $page_path = str_replace( '%2F', '/', $page_path ); + $page_path = str_replace( '%20', ' ', $page_path ); + $parts = explode( '/', trim( $page_path, '/' ) ); + $parts = array_map( 'sanitize_title_for_query', $parts ); $escaped_parts = esc_sql( $parts ); $in_string = "'" . implode( "','", $escaped_parts ) . "'"; @@ -4330,9 +4490,9 @@ function get_page_by_path( $page_path, $output = OBJECT, $post_type = 'page' ) { $post_types = array( $post_type, 'attachment' ); } - $post_types = esc_sql( $post_types ); + $post_types = esc_sql( $post_types ); $post_type_in_string = "'" . implode( "','", $post_types ) . "'"; - $sql = " + $sql = " SELECT ID, post_name, post_parent, post_type FROM $wpdb->posts WHERE post_name IN ($in_string) @@ -4347,7 +4507,7 @@ function get_page_by_path( $page_path, $output = OBJECT, $post_type = 'page' ) { foreach ( (array) $pages as $page ) { if ( $page->post_name == $revparts[0] ) { $count = 0; - $p = $page; + $p = $page; /* * Loop through the given path parts from right to left, @@ -4356,15 +4516,17 @@ function get_page_by_path( $page_path, $output = OBJECT, $post_type = 'page' ) { while ( $p->post_parent != 0 && isset( $pages[ $p->post_parent ] ) ) { $count++; $parent = $pages[ $p->post_parent ]; - if ( ! isset( $revparts[ $count ] ) || $parent->post_name != $revparts[ $count ] ) + if ( ! isset( $revparts[ $count ] ) || $parent->post_name != $revparts[ $count ] ) { break; + } $p = $parent; } - if ( $p->post_parent == 0 && $count+1 == count( $revparts ) && $p->post_name == $revparts[ $count ] ) { + if ( $p->post_parent == 0 && $count + 1 == count( $revparts ) && $p->post_name == $revparts[ $count ] ) { $foundid = $page->ID; - if ( $page->post_type == $post_type ) + if ( $page->post_type == $post_type ) { break; + } } } } @@ -4394,21 +4556,25 @@ function get_page_by_title( $page_title, $output = OBJECT, $post_type = 'page' ) global $wpdb; if ( is_array( $post_type ) ) { - $post_type = esc_sql( $post_type ); + $post_type = esc_sql( $post_type ); $post_type_in_string = "'" . implode( "','", $post_type ) . "'"; - $sql = $wpdb->prepare( " + $sql = $wpdb->prepare( + " SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type IN ($post_type_in_string) - ", $page_title ); + ", $page_title + ); } else { - $sql = $wpdb->prepare( " + $sql = $wpdb->prepare( + " SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type = %s - ", $page_title, $post_type ); + ", $page_title, $post_type + ); } $page = $wpdb->get_var( $sql ); @@ -4444,7 +4610,7 @@ function get_page_children( $page_id, $pages ) { $to_look = array_reverse( $children[ $page_id ] ); while ( $to_look ) { - $p = array_pop( $to_look ); + $p = array_pop( $to_look ); $page_list[] = $p; if ( isset( $children[ $p->ID ] ) ) { foreach ( array_reverse( $children[ $p->ID ] ) as $child ) { @@ -4477,7 +4643,7 @@ function get_page_hierarchy( &$pages, $page_id = 0 ) { $children = array(); foreach ( (array) $pages as $p ) { - $parent_id = intval( $p->post_parent ); + $parent_id = intval( $p->post_parent ); $children[ $parent_id ][] = $p; } @@ -4500,9 +4666,9 @@ function get_page_hierarchy( &$pages, $page_id = 0 ) { * @param array $children Parent-children relations (passed by reference). * @param array $result Result (passed by reference). */ -function _page_traverse_name( $page_id, &$children, &$result ){ - if ( isset( $children[ $page_id ] ) ){ - foreach ( (array)$children[ $page_id ] as $child ) { +function _page_traverse_name( $page_id, &$children, &$result ) { + if ( isset( $children[ $page_id ] ) ) { + foreach ( (array) $children[ $page_id ] as $child ) { $result[ $child->ID ] = $child->post_name; _page_traverse_name( $child->ID, $children, $result ); } @@ -4525,8 +4691,9 @@ function get_page_uri( $page = 0 ) { $page = get_post( $page ); } - if ( ! $page ) + if ( ! $page ) { return false; + } $uri = $page->post_name; @@ -4613,15 +4780,15 @@ function get_pages( $args = array() ) { $r = wp_parse_args( $args, $defaults ); - $number = (int) $r['number']; - $offset = (int) $r['offset']; - $child_of = (int) $r['child_of']; + $number = (int) $r['number']; + $offset = (int) $r['offset']; + $child_of = (int) $r['child_of']; $hierarchical = $r['hierarchical']; - $exclude = $r['exclude']; - $meta_key = $r['meta_key']; - $meta_value = $r['meta_value']; - $parent = $r['parent']; - $post_status = $r['post_status']; + $exclude = $r['exclude']; + $meta_key = $r['meta_key']; + $meta_value = $r['meta_value']; + $parent = $r['parent']; + $post_status = $r['post_status']; // Make sure the post type is hierarchical. $hierarchical_post_types = get_post_types( array( 'hierarchical' => true ) ); @@ -4642,7 +4809,7 @@ function get_pages( $args = array() ) { } // $args can be whatever, only use the args defined in defaults to compute the key. - $key = md5( serialize( wp_array_slice_assoc( $r, array_keys( $defaults ) ) ) ); + $key = md5( serialize( wp_array_slice_assoc( $r, array_keys( $defaults ) ) ) ); $last_changed = wp_cache_get_last_changed( 'posts' ); $cache_key = "get_pages:$key:$last_changed"; @@ -4656,15 +4823,15 @@ function get_pages( $args = array() ) { $inclusions = ''; if ( ! empty( $r['include'] ) ) { - $child_of = 0; //ignore child_of, parent, exclude, meta_key, and meta_value params if using include - $parent = -1; - $exclude = ''; - $meta_key = ''; - $meta_value = ''; + $child_of = 0; //ignore child_of, parent, exclude, meta_key, and meta_value params if using include + $parent = -1; + $exclude = ''; + $meta_key = ''; + $meta_value = ''; $hierarchical = false; - $incpages = wp_parse_id_list( $r['include'] ); + $incpages = wp_parse_id_list( $r['include'] ); if ( ! empty( $incpages ) ) { - $inclusions = ' AND ID IN (' . implode( ',', $incpages ) . ')'; + $inclusions = ' AND ID IN (' . implode( ',', $incpages ) . ')'; } } @@ -4672,7 +4839,7 @@ function get_pages( $args = array() ) { if ( ! empty( $exclude ) ) { $expages = wp_parse_id_list( $exclude ); if ( ! empty( $expages ) ) { - $exclusions = ' AND ID NOT IN (' . implode( ',', $expages ) . ')'; + $exclusions = ' AND ID NOT IN (' . implode( ',', $expages ) . ')'; } } @@ -4683,8 +4850,8 @@ function get_pages( $args = array() ) { if ( ! empty( $post_authors ) ) { foreach ( $post_authors as $post_author ) { //Do we have an author id or an author login? - if ( 0 == intval($post_author) ) { - $post_author = get_user_by('login', $post_author); + if ( 0 == intval( $post_author ) ) { + $post_author = get_user_by( 'login', $post_author ); if ( empty( $post_author ) ) { continue; } @@ -4695,9 +4862,9 @@ function get_pages( $args = array() ) { } if ( '' == $author_query ) { - $author_query = $wpdb->prepare(' post_author = %d ', $post_author); + $author_query = $wpdb->prepare( ' post_author = %d ', $post_author ); } else { - $author_query .= $wpdb->prepare(' OR post_author = %d ', $post_author); + $author_query .= $wpdb->prepare( ' OR post_author = %d ', $post_author ); } } if ( '' != $author_query ) { @@ -4706,21 +4873,20 @@ function get_pages( $args = array() ) { } } - $join = ''; + $join = ''; $where = "$exclusions $inclusions "; if ( '' !== $meta_key || '' !== $meta_value ) { $join = " LEFT JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id )"; // meta_key and meta_value might be slashed - $meta_key = wp_unslash($meta_key); - $meta_value = wp_unslash($meta_value); + $meta_key = wp_unslash( $meta_key ); + $meta_value = wp_unslash( $meta_value ); if ( '' !== $meta_key ) { - $where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_key = %s", $meta_key); + $where .= $wpdb->prepare( " AND $wpdb->postmeta.meta_key = %s", $meta_key ); } if ( '' !== $meta_value ) { - $where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_value = %s", $meta_value); + $where .= $wpdb->prepare( " AND $wpdb->postmeta.meta_value = %s", $meta_value ); } - } if ( is_array( $parent ) ) { @@ -4729,20 +4895,37 @@ function get_pages( $args = array() ) { $where .= " AND post_parent IN ($post_parent__in)"; } } elseif ( $parent >= 0 ) { - $where .= $wpdb->prepare(' AND post_parent = %d ', $parent); + $where .= $wpdb->prepare( ' AND post_parent = %d ', $parent ); } if ( 1 == count( $post_status ) ) { - $where_post_type = $wpdb->prepare( "post_type = %s AND post_status = %s", $r['post_type'], reset( $post_status ) ); + $where_post_type = $wpdb->prepare( 'post_type = %s AND post_status = %s', $r['post_type'], reset( $post_status ) ); } else { - $post_status = implode( "', '", $post_status ); + $post_status = implode( "', '", $post_status ); $where_post_type = $wpdb->prepare( "post_type = %s AND post_status IN ('$post_status')", $r['post_type'] ); } $orderby_array = array(); - $allowed_keys = array( 'author', 'post_author', 'date', 'post_date', 'title', 'post_title', 'name', 'post_name', 'modified', - 'post_modified', 'modified_gmt', 'post_modified_gmt', 'menu_order', 'parent', 'post_parent', - 'ID', 'rand', 'comment_count' ); + $allowed_keys = array( + 'author', + 'post_author', + 'date', + 'post_date', + 'title', + 'post_title', + 'name', + 'post_name', + 'modified', + 'post_modified', + 'modified_gmt', + 'post_modified_gmt', + 'menu_order', + 'parent', + 'post_parent', + 'ID', + 'rand', + 'comment_count', + ); foreach ( explode( ',', $r['sort_column'] ) as $orderby ) { $orderby = trim( $orderby ); @@ -4780,33 +4963,33 @@ function get_pages( $args = array() ) { $sort_order = 'ASC'; } - $query = "SELECT * FROM $wpdb->posts $join WHERE ($where_post_type) $where "; + $query = "SELECT * FROM $wpdb->posts $join WHERE ($where_post_type) $where "; $query .= $author_query; - $query .= " ORDER BY " . $sort_column . " " . $sort_order ; + $query .= ' ORDER BY ' . $sort_column . ' ' . $sort_order; if ( ! empty( $number ) ) { $query .= ' LIMIT ' . $offset . ',' . $number; } - $pages = $wpdb->get_results($query); + $pages = $wpdb->get_results( $query ); - if ( empty($pages) ) { + if ( empty( $pages ) ) { /** This filter is documented in wp-includes/post.php */ $pages = apply_filters( 'get_pages', array(), $r ); return $pages; } // Sanitize before caching so it'll only get done once. - $num_pages = count($pages); - for ($i = 0; $i < $num_pages; $i++) { - $pages[$i] = sanitize_post($pages[$i], 'raw'); + $num_pages = count( $pages ); + for ( $i = 0; $i < $num_pages; $i++ ) { + $pages[ $i ] = sanitize_post( $pages[ $i ], 'raw' ); } // Update cache. update_post_cache( $pages ); if ( $child_of || $hierarchical ) { - $pages = get_page_children($child_of, $pages); + $pages = get_page_children( $child_of, $pages ); } if ( ! empty( $r['exclude_tree'] ) ) { @@ -4820,8 +5003,8 @@ function get_pages( $args = array() ) { $num_pages = count( $pages ); for ( $i = 0; $i < $num_pages; $i++ ) { - if ( in_array( $pages[$i]->ID, $exclude ) ) { - unset( $pages[$i] ); + if ( in_array( $pages[ $i ]->ID, $exclude ) ) { + unset( $pages[ $i ] ); } } } @@ -4859,15 +5042,18 @@ function get_pages( $args = array() ) { * @param string $url URL to check * @return bool True on success, false on failure. */ -function is_local_attachment($url) { - if (strpos($url, home_url()) === false) +function is_local_attachment( $url ) { + if ( strpos( $url, home_url() ) === false ) { return false; - if (strpos($url, home_url('/?attachment_id=')) !== false) + } + if ( strpos( $url, home_url( '/?attachment_id=' ) ) !== false ) { return true; - if ( $id = url_to_postid($url) ) { - $post = get_post($id); - if ( 'attachment' == $post->post_type ) + } + if ( $id = url_to_postid( $url ) ) { + $post = get_post( $id ); + if ( 'attachment' == $post->post_type ) { return true; + } } return false; } @@ -4900,7 +5086,7 @@ function is_local_attachment($url) { function wp_insert_attachment( $args, $file = false, $parent = 0, $wp_error = false ) { $defaults = array( 'file' => $file, - 'post_parent' => 0 + 'post_parent' => 0, ); $data = wp_parse_args( $args, $defaults ); @@ -4952,15 +5138,16 @@ function wp_delete_attachment( $post_id, $force_delete = false ) { return wp_trash_post( $post_id ); } - delete_post_meta($post_id, '_wp_trash_meta_status'); - delete_post_meta($post_id, '_wp_trash_meta_time'); + delete_post_meta( $post_id, '_wp_trash_meta_status' ); + delete_post_meta( $post_id, '_wp_trash_meta_time' ); - $meta = wp_get_attachment_metadata( $post_id ); + $meta = wp_get_attachment_metadata( $post_id ); $backup_sizes = get_post_meta( $post->ID, '_wp_attachment_backup_sizes', true ); - $file = get_attached_file( $post_id ); + $file = get_attached_file( $post_id ); - if ( is_multisite() ) + if ( is_multisite() ) { delete_transient( 'dirsize_cache' ); + } /** * Fires before an attachment is deleted, at the start of wp_delete_attachment(). @@ -4971,24 +5158,25 @@ function wp_delete_attachment( $post_id, $force_delete = false ) { */ do_action( 'delete_attachment', $post_id ); - wp_delete_object_term_relationships($post_id, array('category', 'post_tag')); - wp_delete_object_term_relationships($post_id, get_object_taxonomies($post->post_type)); + wp_delete_object_term_relationships( $post_id, array( 'category', 'post_tag' ) ); + wp_delete_object_term_relationships( $post_id, get_object_taxonomies( $post->post_type ) ); // Delete all for any posts. delete_metadata( 'post', null, '_thumbnail_id', $post_id, true ); wp_defer_comment_counting( true ); - $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id )); + $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ) ); foreach ( $comment_ids as $comment_id ) { wp_delete_comment( $comment_id, true ); } wp_defer_comment_counting( false ); - $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $post_id )); - foreach ( $post_meta_ids as $mid ) + $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $post_id ) ); + foreach ( $post_meta_ids as $mid ) { delete_metadata_by_mid( 'post', $mid ); + } /** This action is documented in wp-includes/post.php */ do_action( 'delete_post', $post_id ); @@ -5001,13 +5189,13 @@ function wp_delete_attachment( $post_id, $force_delete = false ) { $uploadpath = wp_get_upload_dir(); - if ( ! empty($meta['thumb']) ) { + if ( ! empty( $meta['thumb'] ) ) { // Don't delete the thumb if another attachment uses it. - if (! $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE %s AND post_id <> %d", '%' . $wpdb->esc_like( $meta['thumb'] ) . '%', $post_id)) ) { - $thumbfile = str_replace(basename($file), $meta['thumb'], $file); + if ( ! $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE %s AND post_id <> %d", '%' . $wpdb->esc_like( $meta['thumb'] ) . '%', $post_id ) ) ) { + $thumbfile = str_replace( basename( $file ), $meta['thumb'], $file ); /** This filter is documented in wp-includes/functions.php */ $thumbfile = apply_filters( 'wp_delete_file', $thumbfile ); - @ unlink( path_join($uploadpath['basedir'], $thumbfile) ); + @ unlink( path_join( $uploadpath['basedir'], $thumbfile ) ); } } @@ -5021,12 +5209,12 @@ function wp_delete_attachment( $post_id, $force_delete = false ) { } } - if ( is_array($backup_sizes) ) { + if ( is_array( $backup_sizes ) ) { foreach ( $backup_sizes as $size ) { - $del_file = path_join( dirname($meta['file']), $size['file'] ); + $del_file = path_join( dirname( $meta['file'] ), $size['file'] ); /** This filter is documented in wp-includes/functions.php */ $del_file = apply_filters( 'wp_delete_file', $del_file ); - @ unlink( path_join($uploadpath['basedir'], $del_file) ); + @ unlink( path_join( $uploadpath['basedir'], $del_file ) ); } } @@ -5054,8 +5242,9 @@ function wp_get_attachment_metadata( $attachment_id = 0, $unfiltered = false ) { $data = get_post_meta( $post->ID, '_wp_attachment_metadata', true ); - if ( $unfiltered ) + if ( $unfiltered ) { return $data; + } /** * Filters the attachment meta data. @@ -5092,10 +5281,11 @@ function wp_update_attachment_metadata( $attachment_id, $data ) { * @param array $data Array of updated attachment meta data. * @param int $attachment_id Attachment post ID. */ - if ( $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID ) ) + if ( $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID ) ) { return update_post_meta( $post->ID, '_wp_attachment_metadata', $data ); - else + } else { return delete_post_meta( $post->ID, '_wp_attachment_metadata' ); + } } /** @@ -5114,8 +5304,9 @@ function wp_get_attachment_url( $attachment_id = 0 ) { return false; } - if ( 'attachment' != $post->post_type ) + if ( 'attachment' != $post->post_type ) { return false; + } $url = ''; // Get attached file. @@ -5125,8 +5316,8 @@ function wp_get_attachment_url( $attachment_id = 0 ) { // Check that the upload base exists in the file location. if ( 0 === strpos( $file, $uploads['basedir'] ) ) { // Replace file location with url location. - $url = str_replace($uploads['basedir'], $uploads['baseurl'], $file); - } elseif ( false !== strpos($file, 'wp-content/uploads') ) { + $url = str_replace( $uploads['basedir'], $uploads['baseurl'], $file ); + } elseif ( false !== strpos( $file, 'wp-content/uploads' ) ) { // Get the directory name relative to the basedir (back compat for pre-2.7 uploads) $url = trailingslashit( $uploads['baseurl'] . '/' . _wp_get_attachment_relative_path( $file ) ) . basename( $file ); } else { @@ -5140,7 +5331,7 @@ function wp_get_attachment_url( $attachment_id = 0 ) { * If any of the above options failed, Fallback on the GUID as used pre-2.7, * not recommended to rely upon this. */ - if ( empty($url) ) { + if ( empty( $url ) ) { $url = get_the_guid( $post->ID ); } @@ -5159,8 +5350,9 @@ function wp_get_attachment_url( $attachment_id = 0 ) { */ $url = apply_filters( 'wp_get_attachment_url', $url, $post->ID ); - if ( empty( $url ) ) + if ( empty( $url ) ) { return false; + } return $url; } @@ -5206,14 +5398,16 @@ function wp_get_attachment_caption( $post_id = 0 ) { */ function wp_get_attachment_thumb_file( $post_id = 0 ) { $post_id = (int) $post_id; - if ( !$post = get_post( $post_id ) ) + if ( ! $post = get_post( $post_id ) ) { return false; - if ( !is_array( $imagedata = wp_get_attachment_metadata( $post->ID ) ) ) + } + if ( ! is_array( $imagedata = wp_get_attachment_metadata( $post->ID ) ) ) { return false; + } $file = get_attached_file( $post->ID ); - if ( !empty($imagedata['thumb']) && ($thumbfile = str_replace(basename($file), $imagedata['thumb'], $file)) && file_exists($thumbfile) ) { + if ( ! empty( $imagedata['thumb'] ) && ( $thumbfile = str_replace( basename( $file ), $imagedata['thumb'], $file ) ) && file_exists( $thumbfile ) ) { /** * Filters the attachment thumbnail file path. * @@ -5237,19 +5431,23 @@ function wp_get_attachment_thumb_file( $post_id = 0 ) { */ function wp_get_attachment_thumb_url( $post_id = 0 ) { $post_id = (int) $post_id; - if ( !$post = get_post( $post_id ) ) + if ( ! $post = get_post( $post_id ) ) { return false; - if ( !$url = wp_get_attachment_url( $post->ID ) ) + } + if ( ! $url = wp_get_attachment_url( $post->ID ) ) { return false; + } $sized = image_downsize( $post_id, 'thumbnail' ); - if ( $sized ) + if ( $sized ) { return $sized[0]; + } - if ( !$thumb = wp_get_attachment_thumb_file( $post->ID ) ) + if ( ! $thumb = wp_get_attachment_thumb_file( $post->ID ) ) { return false; + } - $url = str_replace(basename($url), basename($thumb), $url); + $url = str_replace( basename( $url ), basename( $thumb ), $url ); /** * Filters the attachment thumbnail URL. @@ -5296,18 +5494,18 @@ function wp_attachment_is( $type, $post = null ) { } switch ( $type ) { - case 'image': - $image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' ); - return in_array( $ext, $image_exts ); + case 'image': + $image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' ); + return in_array( $ext, $image_exts ); - case 'audio': - return in_array( $ext, wp_get_audio_extensions() ); + case 'audio': + return in_array( $ext, wp_get_audio_extensions() ); - case 'video': - return in_array( $ext, wp_get_video_extensions() ); + case 'video': + return in_array( $ext, wp_get_video_extensions() ); - default: - return $type === $ext; + default: + return $type === $ext; } } @@ -5334,22 +5532,24 @@ function wp_attachment_is_image( $post = null ) { * @return string|false Icon, false otherwise. */ function wp_mime_type_icon( $mime = 0 ) { - if ( !is_numeric($mime) ) - $icon = wp_cache_get("mime_type_icon_$mime"); + if ( ! is_numeric( $mime ) ) { + $icon = wp_cache_get( "mime_type_icon_$mime" ); + } $post_id = 0; - if ( empty($icon) ) { + if ( empty( $icon ) ) { $post_mimes = array(); - if ( is_numeric($mime) ) { + if ( is_numeric( $mime ) ) { $mime = (int) $mime; if ( $post = get_post( $mime ) ) { $post_id = (int) $post->ID; - $file = get_attached_file( $post_id ); - $ext = preg_replace('/^.+?\.([^.]+)$/', '$1', $file); - if ( !empty($ext) ) { + $file = get_attached_file( $post_id ); + $ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $file ); + if ( ! empty( $ext ) ) { $post_mimes[] = $ext; - if ( $ext_type = wp_ext2type( $ext ) ) + if ( $ext_type = wp_ext2type( $ext ) ) { $post_mimes[] = $ext_type; + } } $mime = $post->post_mime_type; } else { @@ -5359,9 +5559,9 @@ function wp_mime_type_icon( $mime = 0 ) { $post_mimes[] = $mime; } - $icon_files = wp_cache_get('icon_files'); + $icon_files = wp_cache_get( 'icon_files' ); - if ( !is_array($icon_files) ) { + if ( ! is_array( $icon_files ) ) { /** * Filters the icon directory path. * @@ -5387,25 +5587,27 @@ function wp_mime_type_icon( $mime = 0 ) { * * @param array $uris List of icon directory URIs. */ - $dirs = apply_filters( 'icon_dirs', array( $icon_dir => $icon_dir_uri ) ); + $dirs = apply_filters( 'icon_dirs', array( $icon_dir => $icon_dir_uri ) ); $icon_files = array(); while ( $dirs ) { $keys = array_keys( $dirs ); - $dir = array_shift( $keys ); - $uri = array_shift($dirs); - if ( $dh = opendir($dir) ) { - while ( false !== $file = readdir($dh) ) { - $file = basename($file); - if ( substr($file, 0, 1) == '.' ) - continue; - if ( !in_array(strtolower(substr($file, -4)), array('.png', '.gif', '.jpg') ) ) { - if ( is_dir("$dir/$file") ) - $dirs["$dir/$file"] = "$uri/$file"; + $dir = array_shift( $keys ); + $uri = array_shift( $dirs ); + if ( $dh = opendir( $dir ) ) { + while ( false !== $file = readdir( $dh ) ) { + $file = basename( $file ); + if ( substr( $file, 0, 1 ) == '.' ) { continue; } - $icon_files["$dir/$file"] = "$uri/$file"; + if ( ! in_array( strtolower( substr( $file, -4 ) ), array( '.png', '.gif', '.jpg' ) ) ) { + if ( is_dir( "$dir/$file" ) ) { + $dirs[ "$dir/$file" ] = "$uri/$file"; + } + continue; + } + $icon_files[ "$dir/$file" ] = "$uri/$file"; } - closedir($dh); + closedir( $dh ); } } wp_cache_add( 'icon_files', $icon_files, 'default', 600 ); @@ -5413,17 +5615,18 @@ function wp_mime_type_icon( $mime = 0 ) { $types = array(); // Icon basename - extension = MIME wildcard. - foreach ( $icon_files as $file => $uri ) - $types[ preg_replace('/^([^.]*).*$/', '$1', basename($file)) ] =& $icon_files[$file]; - - if ( ! empty($mime) ) { - $post_mimes[] = substr($mime, 0, strpos($mime, '/')); - $post_mimes[] = substr($mime, strpos($mime, '/') + 1); - $post_mimes[] = str_replace('/', '_', $mime); + foreach ( $icon_files as $file => $uri ) { + $types[ preg_replace( '/^([^.]*).*$/', '$1', basename( $file ) ) ] =& $icon_files[ $file ]; } - $matches = wp_match_mime_types(array_keys($types), $post_mimes); - $matches['default'] = array('default'); + if ( ! empty( $mime ) ) { + $post_mimes[] = substr( $mime, 0, strpos( $mime, '/' ) ); + $post_mimes[] = substr( $mime, strpos( $mime, '/' ) + 1 ); + $post_mimes[] = str_replace( '/', '_', $mime ); + } + + $matches = wp_match_mime_types( array_keys( $types ), $post_mimes ); + $matches['default'] = array( 'default' ); foreach ( $matches as $match => $wilds ) { foreach ( $wilds as $wild ) { @@ -5584,7 +5787,7 @@ function get_posts_by_author_sql( $post_type, $full = true, $post_author = null, return $full ? 'WHERE 1 = 0' : '1 = 0'; } - $sql = '( '. implode( ' OR ', $post_type_clauses ) . ' )'; + $sql = '( ' . implode( ' OR ', $post_type_clauses ) . ' )'; if ( null !== $post_author ) { $sql .= $wpdb->prepare( ' AND post_author = %d', $post_author ); @@ -5663,7 +5866,7 @@ function get_lastpostmodified( $timezone = 'server', $post_type = 'any' ) { $lastpostmodified = _get_last_post_time( $timezone, 'modified', $post_type ); - $lastpostdate = get_lastpostdate($timezone); + $lastpostdate = get_lastpostdate( $timezone ); if ( $lastpostdate > $lastpostmodified ) { $lastpostmodified = $lastpostdate; } @@ -5724,14 +5927,14 @@ function _get_last_post_time( $timezone, $field, $post_type = 'any' ) { switch ( $timezone ) { case 'gmt': - $date = $wpdb->get_var("SELECT post_{$field}_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1"); + $date = $wpdb->get_var( "SELECT post_{$field}_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1" ); break; case 'blog': - $date = $wpdb->get_var("SELECT post_{$field} FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1"); + $date = $wpdb->get_var( "SELECT post_{$field} FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1" ); break; case 'server': $add_seconds_server = date( 'Z' ); - $date = $wpdb->get_var("SELECT DATE_ADD(post_{$field}_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1"); + $date = $wpdb->get_var( "SELECT DATE_ADD(post_{$field}_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1" ); break; } @@ -5752,11 +5955,13 @@ function _get_last_post_time( $timezone, $field, $post_type = 'any' ) { * @param array $posts Array of post objects (passed by reference). */ function update_post_cache( &$posts ) { - if ( ! $posts ) + if ( ! $posts ) { return; + } - foreach ( $posts as $post ) + foreach ( $posts as $post ) { wp_cache_add( $post->ID, $post, 'posts' ); + } } /** @@ -5777,12 +5982,14 @@ function update_post_cache( &$posts ) { function clean_post_cache( $post ) { global $_wp_suspend_cache_invalidation; - if ( ! empty( $_wp_suspend_cache_invalidation ) ) + if ( ! empty( $_wp_suspend_cache_invalidation ) ) { return; + } $post = get_post( $post ); - if ( empty( $post ) ) + if ( empty( $post ) ) { return; + } wp_cache_delete( $post->ID, 'posts' ); wp_cache_delete( $post->ID, 'post_meta' ); @@ -5829,20 +6036,23 @@ function clean_post_cache( $post ) { */ function update_post_caches( &$posts, $post_type = 'post', $update_term_cache = true, $update_meta_cache = true ) { // No point in doing all this work if we didn't match any posts. - if ( !$posts ) + if ( ! $posts ) { return; + } - update_post_cache($posts); + update_post_cache( $posts ); $post_ids = array(); - foreach ( $posts as $post ) + foreach ( $posts as $post ) { $post_ids[] = $post->ID; + } - if ( ! $post_type ) + if ( ! $post_type ) { $post_type = 'any'; + } if ( $update_term_cache ) { - if ( is_array($post_type) ) { + if ( is_array( $post_type ) ) { $ptypes = $post_type; } elseif ( 'any' == $post_type ) { $ptypes = array(); @@ -5850,17 +6060,19 @@ function update_post_caches( &$posts, $post_type = 'post', $update_term_cache = foreach ( $posts as $post ) { $ptypes[] = $post->post_type; } - $ptypes = array_unique($ptypes); + $ptypes = array_unique( $ptypes ); } else { - $ptypes = array($post_type); + $ptypes = array( $post_type ); } - if ( ! empty($ptypes) ) - update_object_term_cache($post_ids, $ptypes); + if ( ! empty( $ptypes ) ) { + update_object_term_cache( $post_ids, $ptypes ); + } } - if ( $update_meta_cache ) - update_postmeta_cache($post_ids); + if ( $update_meta_cache ) { + update_postmeta_cache( $post_ids ); + } } /** @@ -5877,7 +6089,7 @@ function update_post_caches( &$posts, $post_type = 'post', $update_term_cache = * of metadata. */ function update_postmeta_cache( $post_ids ) { - return update_meta_cache('post', $post_ids); + return update_meta_cache( 'post', $post_ids ); } /** @@ -5898,16 +6110,18 @@ function update_postmeta_cache( $post_ids ) { function clean_attachment_cache( $id, $clean_terms = false ) { global $_wp_suspend_cache_invalidation; - if ( !empty($_wp_suspend_cache_invalidation) ) + if ( ! empty( $_wp_suspend_cache_invalidation ) ) { return; + } $id = (int) $id; - wp_cache_delete($id, 'posts'); - wp_cache_delete($id, 'post_meta'); + wp_cache_delete( $id, 'posts' ); + wp_cache_delete( $id, 'post_meta' ); - if ( $clean_terms ) - clean_object_term_cache($id, 'attachment'); + if ( $clean_terms ) { + clean_object_term_cache( $id, 'attachment' ); + } /** * Fires after the given attachment's cache is cleaned. @@ -5941,8 +6155,9 @@ function _transition_post_status( $new_status, $old_status, $post ) { if ( $old_status != 'publish' && $new_status == 'publish' ) { // Reset GUID if transitioning to publish and it is empty. - if ( '' == get_the_guid($post->ID) ) + if ( '' == get_the_guid( $post->ID ) ) { $wpdb->update( $wpdb->posts, array( 'guid' => get_permalink( $post->ID ) ), array( 'ID' => $post->ID ) ); + } /** * Fires when a post's status is transitioned from private to published. @@ -5952,11 +6167,11 @@ function _transition_post_status( $new_status, $old_status, $post ) { * * @param int $post_id Post ID. */ - do_action('private_to_published', $post->ID); + do_action( 'private_to_published', $post->ID ); } // If published posts changed clear the lastpostmodified cache. - if ( 'publish' == $new_status || 'publish' == $old_status) { + if ( 'publish' == $new_status || 'publish' == $old_status ) { foreach ( array( 'server', 'gmt', 'blog' ) as $timezone ) { wp_cache_delete( "lastpostmodified:$timezone", 'timeinfo' ); wp_cache_delete( "lastpostdate:$timezone", 'timeinfo' ); @@ -5970,7 +6185,7 @@ function _transition_post_status( $new_status, $old_status, $post ) { } // Always clears the hook in case the post status bounced from future to draft. - wp_clear_scheduled_hook('publish_future_post', array( $post->ID ) ); + wp_clear_scheduled_hook( 'publish_future_post', array( $post->ID ) ); } /** @@ -5988,7 +6203,7 @@ function _transition_post_status( $new_status, $old_status, $post ) { */ function _future_post_hook( $deprecated, $post ) { wp_clear_scheduled_hook( 'publish_future_post', array( $post->ID ) ); - wp_schedule_single_event( strtotime( get_gmt_from_date( $post->post_date ) . ' GMT') , 'publish_future_post', array( $post->ID ) ); + wp_schedule_single_event( strtotime( get_gmt_from_date( $post->post_date ) . ' GMT' ), 'publish_future_post', array( $post->ID ) ); } /** @@ -6013,11 +6228,13 @@ function _publish_post_hook( $post_id ) { do_action( 'xmlrpc_publish_post', $post_id ); } - if ( defined('WP_IMPORTING') ) + if ( defined( 'WP_IMPORTING' ) ) { return; + } - if ( get_option('default_pingback_flag') ) + if ( get_option( 'default_pingback_flag' ) ) { add_post_meta( $post_id, '_pingme', '1' ); + } add_post_meta( $post_id, '_encloseme', '1' ); if ( ! wp_next_scheduled( 'do_pings' ) ) { @@ -6036,8 +6253,9 @@ function _publish_post_hook( $post_id ) { */ function wp_get_post_parent_id( $post_ID ) { $post = get_post( $post_ID ); - if ( !$post || is_wp_error( $post ) ) + if ( ! $post || is_wp_error( $post ) ) { return false; + } return (int) $post->post_parent; } @@ -6057,28 +6275,39 @@ function wp_get_post_parent_id( $post_ID ) { */ function wp_check_post_hierarchy_for_loops( $post_parent, $post_ID ) { // Nothing fancy here - bail. - if ( !$post_parent ) + if ( ! $post_parent ) { return 0; + } // New post can't cause a loop. - if ( empty( $post_ID ) ) + if ( empty( $post_ID ) ) { return $post_parent; + } // Can't be its own parent. - if ( $post_parent == $post_ID ) + if ( $post_parent == $post_ID ) { return 0; + } // Now look for larger loops. - if ( !$loop = wp_find_hierarchy_loop( 'wp_get_post_parent_id', $post_ID, $post_parent ) ) + if ( ! $loop = wp_find_hierarchy_loop( 'wp_get_post_parent_id', $post_ID, $post_parent ) ) { return $post_parent; // No loop + } // Setting $post_parent to the given value causes a loop. - if ( isset( $loop[$post_ID] ) ) + if ( isset( $loop[ $post_ID ] ) ) { return 0; + } // There's a loop, but it doesn't contain $post_ID. Break the loop. - foreach ( array_keys( $loop ) as $loop_member ) - wp_update_post( array( 'ID' => $loop_member, 'post_parent' => 0 ) ); + foreach ( array_keys( $loop ) as $loop_member ) { + wp_update_post( + array( + 'ID' => $loop_member, + 'post_parent' => 0, + ) + ); + } return $post_parent; } @@ -6093,13 +6322,14 @@ function wp_check_post_hierarchy_for_loops( $post_parent, $post_ID ) { * @return int|bool True on success, false on failure. */ function set_post_thumbnail( $post, $thumbnail_id ) { - $post = get_post( $post ); + $post = get_post( $post ); $thumbnail_id = absint( $thumbnail_id ); if ( $post && $thumbnail_id && get_post( $thumbnail_id ) ) { - if ( wp_get_attachment_image( $thumbnail_id, 'thumbnail' ) ) + if ( wp_get_attachment_image( $thumbnail_id, 'thumbnail' ) ) { return update_post_meta( $post->ID, '_thumbnail_id', $thumbnail_id ); - else + } else { return delete_post_meta( $post->ID, '_thumbnail_id' ); + } } return false; } @@ -6114,8 +6344,9 @@ function set_post_thumbnail( $post, $thumbnail_id ) { */ function delete_post_thumbnail( $post ) { $post = get_post( $post ); - if ( $post ) + if ( $post ) { return delete_post_meta( $post->ID, '_thumbnail_id' ); + } return false; } @@ -6213,8 +6444,8 @@ function _prime_post_caches( $ids, $update_term_cache = true, $update_meta_cache global $wpdb; $non_cached_ids = _get_non_cached_ids( $ids, 'posts' ); - if ( !empty( $non_cached_ids ) ) { - $fresh_posts = $wpdb->get_results( sprintf( "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE ID IN (%s)", join( ",", $non_cached_ids ) ) ); + if ( ! empty( $non_cached_ids ) ) { + $fresh_posts = $wpdb->get_results( sprintf( "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE ID IN (%s)", join( ',', $non_cached_ids ) ) ); update_post_caches( $fresh_posts, 'any', $update_term_cache, $update_meta_cache ); } @@ -6235,13 +6466,15 @@ function _prime_post_caches( $ids, $update_term_cache = true, $update_meta_cache * @param string $post_ID Optional. Post ID that should be ignored. Default 0. */ function wp_add_trashed_suffix_to_post_name_for_trashed_posts( $post_name, $post_ID = 0 ) { - $trashed_posts_with_desired_slug = get_posts( array( - 'name' => $post_name, - 'post_status' => 'trash', - 'post_type' => 'any', - 'nopaging' => true, - 'post__not_in' => array( $post_ID ) - ) ); + $trashed_posts_with_desired_slug = get_posts( + array( + 'name' => $post_name, + 'post_status' => 'trash', + 'post_type' => 'any', + 'nopaging' => true, + 'post__not_in' => array( $post_ID ), + ) + ); if ( ! empty( $trashed_posts_with_desired_slug ) ) { foreach ( $trashed_posts_with_desired_slug as $_post ) { @@ -6302,8 +6535,9 @@ function _filter_query_attachment_filenames( $clauses ) { $clauses['where'] = preg_replace( "/\({$wpdb->posts}.post_content (NOT LIKE|LIKE) (\'[^']+\')\)/", - "$0 OR ( sq1.meta_value $1 $2 )", - $clauses['where'] ); + '$0 OR ( sq1.meta_value $1 $2 )', + $clauses['where'] + ); return $clauses; } diff --git a/wp-includes/query.php b/wp-includes/query.php index 0ed1fab575..e689828c21 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -93,9 +93,9 @@ function set_query_var( $var, $value ) { * @param array|string $query Array or string of WP_Query arguments. * @return array List of post objects. */ -function query_posts($query) { +function query_posts( $query ) { $GLOBALS['wp_query'] = new WP_Query(); - return $GLOBALS['wp_query']->query($query); + return $GLOBALS['wp_query']->query( $query ); } /** @@ -873,18 +873,18 @@ function wp_old_slug_redirect() { return; } - $query = $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta, $wpdb->posts WHERE ID = post_id AND post_type = %s AND meta_key = '_wp_old_slug' AND meta_value = %s", $post_type, get_query_var( 'name' ) ); + $query = $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta, $wpdb->posts WHERE ID = post_id AND post_type = %s AND meta_key = '_wp_old_slug' AND meta_value = %s", $post_type, get_query_var( 'name' ) ); // if year, monthnum, or day have been specified, make our query more precise // just in case there are multiple identical _wp_old_slug values if ( get_query_var( 'year' ) ) { - $query .= $wpdb->prepare(" AND YEAR(post_date) = %d", get_query_var( 'year' ) ); + $query .= $wpdb->prepare( ' AND YEAR(post_date) = %d', get_query_var( 'year' ) ); } if ( get_query_var( 'monthnum' ) ) { - $query .= $wpdb->prepare(" AND MONTH(post_date) = %d", get_query_var( 'monthnum' ) ); + $query .= $wpdb->prepare( ' AND MONTH(post_date) = %d', get_query_var( 'monthnum' ) ); } if ( get_query_var( 'day' ) ) { - $query .= $wpdb->prepare(" AND DAYOFMONTH(post_date) = %d", get_query_var( 'day' ) ); + $query .= $wpdb->prepare( ' AND DAYOFMONTH(post_date) = %d', get_query_var( 'day' ) ); } $id = (int) $wpdb->get_var( $query ); @@ -897,7 +897,7 @@ function wp_old_slug_redirect() { if ( get_query_var( 'paged' ) > 1 ) { $link = user_trailingslashit( trailingslashit( $link ) . 'page/' . get_query_var( 'paged' ) ); - } elseif( is_embed() ) { + } elseif ( is_embed() ) { $link = user_trailingslashit( trailingslashit( $link ) . 'embed' ); } diff --git a/wp-includes/registration-functions.php b/wp-includes/registration-functions.php index 2054885f1c..d48fa27466 100644 --- a/wp-includes/registration-functions.php +++ b/wp-includes/registration-functions.php @@ -4,4 +4,4 @@ * * @package WordPress */ -_deprecated_file( basename(__FILE__), '2.1.0', null, __( 'This file no longer needs to be included.' ) ); +_deprecated_file( basename( __FILE__ ), '2.1.0', null, __( 'This file no longer needs to be included.' ) ); diff --git a/wp-includes/registration.php b/wp-includes/registration.php index aa05672dde..c346c1145e 100644 --- a/wp-includes/registration.php +++ b/wp-includes/registration.php @@ -4,4 +4,4 @@ * * @package WordPress */ -_deprecated_file( basename(__FILE__), '3.1.0', null, __( 'This file no longer needs to be included.' ) ); +_deprecated_file( basename( __FILE__ ), '3.1.0', null, __( 'This file no longer needs to be included.' ) ); diff --git a/wp-includes/rest-api.php b/wp-includes/rest-api.php index cba8182af4..0cce9fa62f 100644 --- a/wp-includes/rest-api.php +++ b/wp-includes/rest-api.php @@ -36,7 +36,7 @@ function register_rest_route( $namespace, $route, $args = array(), $override = f */ _doing_it_wrong( 'register_rest_route', __( 'Routes must be namespaced with plugin or theme name and version.' ), '4.4.0' ); return false; - } else if ( empty( $route ) ) { + } elseif ( empty( $route ) ) { _doing_it_wrong( 'register_rest_route', __( 'Route must be specified.' ), '4.4.0' ); return false; } @@ -54,9 +54,9 @@ function register_rest_route( $namespace, $route, $args = array(), $override = f } $defaults = array( - 'methods' => 'GET', - 'callback' => null, - 'args' => array(), + 'methods' => 'GET', + 'callback' => null, + 'args' => array(), ); foreach ( $args as $key => &$arg_group ) { if ( ! is_numeric( $key ) ) { @@ -64,7 +64,7 @@ function register_rest_route( $namespace, $route, $args = array(), $override = f continue; } - $arg_group = array_merge( $defaults, $arg_group ); + $arg_group = array_merge( $defaults, $arg_group ); $arg_group['args'] = array_merge( $common_args, $arg_group['args'] ); } @@ -141,10 +141,10 @@ function rest_api_init() { function rest_api_register_rewrites() { global $wp_rewrite; - add_rewrite_rule( '^' . rest_get_url_prefix() . '/?$','index.php?rest_route=/','top' ); - add_rewrite_rule( '^' . rest_get_url_prefix() . '/(.*)?','index.php?rest_route=/$matches[1]','top' ); - add_rewrite_rule( '^' . $wp_rewrite->index . '/' . rest_get_url_prefix() . '/?$','index.php?rest_route=/','top' ); - add_rewrite_rule( '^' . $wp_rewrite->index . '/' . rest_get_url_prefix() . '/(.*)?','index.php?rest_route=/$matches[1]','top' ); + add_rewrite_rule( '^' . rest_get_url_prefix() . '/?$', 'index.php?rest_route=/', 'top' ); + add_rewrite_rule( '^' . rest_get_url_prefix() . '/(.*)?', 'index.php?rest_route=/$matches[1]', 'top' ); + add_rewrite_rule( '^' . $wp_rewrite->index . '/' . rest_get_url_prefix() . '/?$', 'index.php?rest_route=/', 'top' ); + add_rewrite_rule( '^' . $wp_rewrite->index . '/' . rest_get_url_prefix() . '/(.*)?', 'index.php?rest_route=/$matches[1]', 'top' ); } /** @@ -417,7 +417,7 @@ function rest_get_server() { * @param string $class_name The name of the server class. Default 'WP_REST_Server'. */ $wp_rest_server_class = apply_filters( 'wp_rest_server_class', 'WP_REST_Server' ); - $wp_rest_server = new $wp_rest_server_class; + $wp_rest_server = new $wp_rest_server_class; /** * Fires when preparing to serve an API request. @@ -569,7 +569,7 @@ function rest_handle_options_request( $response, $handler, $request ) { } $response = new WP_REST_Response(); - $data = array(); + $data = array(); foreach ( $handler->get_routes() as $route => $endpoints ) { $match = preg_match( '@^' . $route . '$@i', $request->get_route() ); @@ -651,7 +651,7 @@ function rest_filter_response_fields( $response, $server, $request ) { $data = $response->get_data(); - $fields = is_array( $request['_fields'] ) ? $request['_fields'] : preg_split( '/[\s,]+/', $request['_fields'] ); + $fields = is_array( $request['_fields'] ) ? $request['_fields'] : preg_split( '/[\s,]+/', $request['_fields'] ); if ( 0 === count( $fields ) ) { return $response; @@ -867,9 +867,9 @@ function rest_get_date_with_gmt( $date, $is_utc = false ) { // cases. if ( ! $is_utc && ! $has_timezone ) { $local = date( 'Y-m-d H:i:s', $date ); - $utc = get_gmt_from_date( $local ); + $utc = get_gmt_from_date( $local ); } else { - $utc = date( 'Y-m-d H:i:s', $date ); + $utc = date( 'Y-m-d H:i:s', $date ); $local = get_date_from_gmt( $utc ); } @@ -982,7 +982,7 @@ function rest_is_ip_address( $ip ) { */ function rest_sanitize_boolean( $value ) { // String values are translated to `true`; make sure 'false' is false. - if ( is_string( $value ) ) { + if ( is_string( $value ) ) { $value = strtolower( $value ); if ( in_array( $value, array( 'false', '0' ), true ) ) { $value = false; @@ -1146,18 +1146,18 @@ function rest_validate_value_from_schema( $value, $args, $param = '' ) { if ( isset( $args['format'] ) ) { switch ( $args['format'] ) { - case 'date-time' : + case 'date-time': if ( ! rest_parse_date( $value ) ) { return new WP_Error( 'rest_invalid_date', __( 'Invalid date.' ) ); } break; - case 'email' : + case 'email': if ( ! is_email( $value ) ) { return new WP_Error( 'rest_invalid_email', __( 'Invalid email address.' ) ); } break; - case 'ip' : + case 'ip': if ( ! rest_is_ip_address( $value ) ) { /* translators: %s: IP address */ return new WP_Error( 'rest_invalid_param', sprintf( __( '%s is not a valid IP address.' ), $value ) ); @@ -1270,19 +1270,19 @@ function rest_sanitize_value_from_schema( $value, $args ) { if ( isset( $args['format'] ) ) { switch ( $args['format'] ) { - case 'date-time' : + case 'date-time': return sanitize_text_field( $value ); - case 'email' : + case 'email': /* * sanitize_email() validates, which would be unexpected. */ return sanitize_text_field( $value ); - case 'uri' : + case 'uri': return esc_url_raw( $value ); - case 'ip' : + case 'ip': return sanitize_text_field( $value ); } } diff --git a/wp-includes/rest-api/class-wp-rest-request.php b/wp-includes/rest-api/class-wp-rest-request.php index f9c6317896..49e119ddc3 100644 --- a/wp-includes/rest-api/class-wp-rest-request.php +++ b/wp-includes/rest-api/class-wp-rest-request.php @@ -111,13 +111,13 @@ class WP_REST_Request implements ArrayAccess { */ public function __construct( $method = '', $route = '', $attributes = array() ) { $this->params = array( - 'URL' => array(), - 'GET' => array(), - 'POST' => array(), - 'FILES' => array(), + 'URL' => array(), + 'GET' => array(), + 'POST' => array(), + 'FILES' => array(), // See parse_json_params. - 'JSON' => null, + 'JSON' => null, 'defaults' => array(), ); @@ -235,7 +235,7 @@ class WP_REST_Request implements ArrayAccess { * @param string $value Header value, or list of values. */ public function set_header( $key, $value ) { - $key = $this->canonicalize_header_name( $key ); + $key = $this->canonicalize_header_name( $key ); $value = (array) $value; $this->headers[ $key ] = $value; @@ -250,7 +250,7 @@ class WP_REST_Request implements ArrayAccess { * @param string $value Header value, or list of values. */ public function add_header( $key, $value ) { - $key = $this->canonicalize_header_name( $key ); + $key = $this->canonicalize_header_name( $key ); $value = (array) $value; if ( ! isset( $this->headers[ $key ] ) ) { @@ -368,7 +368,7 @@ class WP_REST_Request implements ArrayAccess { * @param array $order { * An array of types to check, in order of priority. * - * @param string $type The type to check. + * @param string $type The type to check. * } * @param WP_REST_Request $this The request object. */ @@ -405,7 +405,7 @@ class WP_REST_Request implements ArrayAccess { * @param mixed $value Parameter value. */ public function set_param( $key, $value ) { - $order = $this->get_parameter_order(); + $order = $this->get_parameter_order(); $this->params[ $order[0] ][ $key ] = $value; } @@ -587,8 +587,8 @@ class WP_REST_Request implements ArrayAccess { $this->body = $data; // Enable lazy parsing. - $this->parsed_json = false; - $this->parsed_body = false; + $this->parsed_json = false; + $this->parsed_body = false; $this->params['JSON'] = null; } @@ -650,7 +650,7 @@ class WP_REST_Request implements ArrayAccess { 'status' => WP_Http::BAD_REQUEST, ); if ( function_exists( 'json_last_error' ) ) { - $error_data['json_error_code'] = json_last_error(); + $error_data['json_error_code'] = json_last_error(); $error_data['json_error_message'] = json_last_error_msg(); } @@ -802,7 +802,12 @@ class WP_REST_Request implements ArrayAccess { } if ( $invalid_params ) { - return new WP_Error( 'rest_invalid_param', sprintf( __( 'Invalid parameter(s): %s' ), implode( ', ', array_keys( $invalid_params ) ) ), array( 'status' => 400, 'params' => $invalid_params ) ); + return new WP_Error( + 'rest_invalid_param', sprintf( __( 'Invalid parameter(s): %s' ), implode( ', ', array_keys( $invalid_params ) ) ), array( + 'status' => 400, + 'params' => $invalid_params, + ) + ); } return true; @@ -824,7 +829,7 @@ class WP_REST_Request implements ArrayAccess { } $attributes = $this->get_attributes(); - $required = array(); + $required = array(); // No arguments set, skip validation. if ( empty( $attributes['args'] ) ) { @@ -840,7 +845,12 @@ class WP_REST_Request implements ArrayAccess { } if ( ! empty( $required ) ) { - return new WP_Error( 'rest_missing_callback_param', sprintf( __( 'Missing parameter(s): %s' ), implode( ', ', $required ) ), array( 'status' => 400, 'params' => $required ) ); + return new WP_Error( + 'rest_missing_callback_param', sprintf( __( 'Missing parameter(s): %s' ), implode( ', ', $required ) ), array( + 'status' => 400, + 'params' => $required, + ) + ); } /* @@ -868,7 +878,12 @@ class WP_REST_Request implements ArrayAccess { } if ( $invalid_params ) { - return new WP_Error( 'rest_invalid_param', sprintf( __( 'Invalid parameter(s): %s' ), implode( ', ', array_keys( $invalid_params ) ) ), array( 'status' => 400, 'params' => $invalid_params ) ); + return new WP_Error( + 'rest_invalid_param', sprintf( __( 'Invalid parameter(s): %s' ), implode( ', ', array_keys( $invalid_params ) ) ), array( + 'status' => 400, + 'params' => $invalid_params, + ) + ); } return true; @@ -945,7 +960,7 @@ class WP_REST_Request implements ArrayAccess { * @return WP_REST_Request|false WP_REST_Request object on success, false on failure. */ public static function from_url( $url ) { - $bits = parse_url( $url ); + $bits = parse_url( $url ); $query_params = array(); if ( ! empty( $bits['query'] ) ) { @@ -956,7 +971,7 @@ class WP_REST_Request implements ArrayAccess { if ( get_option( 'permalink_structure' ) && 0 === strpos( $url, $api_root ) ) { // Pretty permalinks on, and URL is under the API root. $api_url_part = substr( $url, strlen( untrailingslashit( $api_root ) ) ); - $route = parse_url( $api_url_part, PHP_URL_PATH ); + $route = parse_url( $api_url_part, PHP_URL_PATH ); } elseif ( ! empty( $query_params['rest_route'] ) ) { // ?rest_route=... set directly $route = $query_params['rest_route']; diff --git a/wp-includes/rest-api/class-wp-rest-response.php b/wp-includes/rest-api/class-wp-rest-response.php index 794ba1fb82..f949cdb9cf 100644 --- a/wp-includes/rest-api/class-wp-rest-response.php +++ b/wp-includes/rest-api/class-wp-rest-response.php @@ -232,7 +232,7 @@ class WP_REST_Response extends WP_HTTP_Response { $data = $this->get_data(); $error->add( $data['code'], $data['message'], $data['data'] ); if ( ! empty( $data['additional_errors'] ) ) { - foreach( $data['additional_errors'] as $err ) { + foreach ( $data['additional_errors'] as $err ) { $error->add( $err['code'], $err['message'], $err['data'] ); } } @@ -253,8 +253,8 @@ class WP_REST_Response extends WP_HTTP_Response { public function get_curies() { $curies = array( array( - 'name' => 'wp', - 'href' => 'https://api.w.org/{rel}', + 'name' => 'wp', + 'href' => 'https://api.w.org/{rel}', 'templated' => true, ), ); diff --git a/wp-includes/rest-api/class-wp-rest-server.php b/wp-includes/rest-api/class-wp-rest-server.php index d06974682a..fbc47dab5b 100644 --- a/wp-includes/rest-api/class-wp-rest-server.php +++ b/wp-includes/rest-api/class-wp-rest-server.php @@ -88,8 +88,8 @@ class WP_REST_Server { // Meta endpoints. '/' => array( 'callback' => array( $this, 'get_index' ), - 'methods' => 'GET', - 'args' => array( + 'methods' => 'GET', + 'args' => array( 'context' => array( 'default' => 'view', ), @@ -160,7 +160,11 @@ class WP_REST_Server { foreach ( (array) $error->errors as $code => $messages ) { foreach ( (array) $messages as $message ) { - $errors[] = array( 'code' => $code, 'message' => $message, 'data' => $error->get_error_data( $code ) ); + $errors[] = array( + 'code' => $code, + 'message' => $message, + 'data' => $error->get_error_data( $code ), + ); } } @@ -260,7 +264,8 @@ class WP_REST_Server { * * @param bool $rest_enabled Whether the REST API is enabled. Default true. */ - apply_filters_deprecated( 'rest_enabled', array( true ), '4.7.0', 'rest_authentication_errors', + apply_filters_deprecated( + 'rest_enabled', array( true ), '4.7.0', 'rest_authentication_errors', __( 'The REST API can no longer be completely disabled, the rest_authentication_errors filter can be used to restrict access to the API, instead.' ) ); @@ -398,8 +403,8 @@ class WP_REST_Server { $json_error_message = $this->get_json_last_error(); if ( $json_error_message ) { $json_error_obj = new WP_Error( 'rest_encode_error', $json_error_message, array( 'status' => 500 ) ); - $result = $this->error_to_response( $json_error_obj ); - $result = wp_json_encode( $result->data[0] ); + $result = $this->error_to_response( $json_error_obj ); + $result = wp_json_encode( $result->data[0] ); } if ( $jsonp_callback ) { @@ -471,9 +476,9 @@ class WP_REST_Server { $data[ $rel ] = array(); foreach ( $items as $item ) { - $attributes = $item['attributes']; + $attributes = $item['attributes']; $attributes['href'] = $item['href']; - $data[ $rel ][] = $attributes; + $data[ $rel ][] = $attributes; } } @@ -499,7 +504,7 @@ class WP_REST_Server { return array(); } - $curies = $response->get_curies(); + $curies = $response->get_curies(); $used_curies = array(); foreach ( $links as $rel => $items ) { @@ -515,9 +520,9 @@ class WP_REST_Server { $rel_regex = str_replace( '\{rel\}', '(.+)', preg_quote( $curie['href'], '!' ) ); preg_match( '!' . $rel_regex . '!', $rel, $matches ); if ( $matches ) { - $new_rel = $curie['name'] . ':' . $matches[1]; + $new_rel = $curie['name'] . ':' . $matches[1]; $used_curies[ $curie['name'] ] = $curie; - $links[ $new_rel ] = $items; + $links[ $new_rel ] = $items; unset( $links[ $rel ] ); break; } @@ -652,25 +657,27 @@ class WP_REST_Server { if ( ! isset( $this->namespaces[ $namespace ] ) ) { $this->namespaces[ $namespace ] = array(); - $this->register_route( $namespace, '/' . $namespace, array( - array( - 'methods' => self::READABLE, - 'callback' => array( $this, 'get_namespace_index' ), - 'args' => array( - 'namespace' => array( - 'default' => $namespace, - ), - 'context' => array( - 'default' => 'view', + $this->register_route( + $namespace, '/' . $namespace, array( + array( + 'methods' => self::READABLE, + 'callback' => array( $this, 'get_namespace_index' ), + 'args' => array( + 'namespace' => array( + 'default' => $namespace, + ), + 'context' => array( + 'default' => 'view', + ), ), ), - ), - ) ); + ) + ); } // Associative to avoid double-registration. $this->namespaces[ $namespace ][ $route ] = true; - $route_args['namespace'] = $namespace; + $route_args['namespace'] = $namespace; if ( $override || empty( $this->endpoints[ $route ] ) ) { $this->endpoints[ $route ] = $route_args; @@ -756,7 +763,7 @@ class WP_REST_Server { $handler['methods'] = array(); foreach ( $methods as $method ) { - $method = strtoupper( trim( $method ) ); + $method = strtoupper( trim( $method ) ); $handler['methods'][ $method ] = true; } } @@ -838,7 +845,7 @@ class WP_REST_Server { } foreach ( $handlers as $handler ) { - $callback = $handler['callback']; + $callback = $handler['callback']; $response = null; // Fallback to GET method if no HEAD method is registered. @@ -1063,12 +1070,12 @@ class WP_REST_Server { return new WP_Error( 'rest_invalid_namespace', __( 'The specified namespace could not be found.' ), array( 'status' => 404 ) ); } - $routes = $this->namespaces[ $namespace ]; + $routes = $this->namespaces[ $namespace ]; $endpoints = array_intersect_key( $this->get_routes(), $routes ); - $data = array( + $data = array( 'namespace' => $namespace, - 'routes' => $this->get_data_for_routes( $endpoints, $request['context'] ), + 'routes' => $this->get_data_for_routes( $endpoints, $request['context'] ), ); $response = rest_ensure_response( $data ); @@ -1146,7 +1153,7 @@ class WP_REST_Server { public function get_data_for_route( $route, $callbacks, $context = 'view' ) { $data = array( 'namespace' => '', - 'methods' => array(), + 'methods' => array(), 'endpoints' => array(), ); @@ -1171,7 +1178,7 @@ class WP_REST_Server { } $data['methods'] = array_merge( $data['methods'], array_keys( $callback['methods'] ) ); - $endpoint_data = array( + $endpoint_data = array( 'methods' => array_keys( $callback['methods'] ), ); @@ -1320,7 +1327,11 @@ class WP_REST_Server { $headers = array(); // CONTENT_* headers are not prefixed with HTTP_. - $additional = array( 'CONTENT_LENGTH' => true, 'CONTENT_MD5' => true, 'CONTENT_TYPE' => true ); + $additional = array( + 'CONTENT_LENGTH' => true, + 'CONTENT_MD5' => true, + 'CONTENT_TYPE' => true, + ); foreach ( $server as $key => $value ) { if ( strpos( $key, 'HTTP_' ) === 0 ) { diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php index ed101815a1..528a6ce0c6 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php @@ -75,7 +75,7 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { // Attaching media to a post requires ability to edit said post. if ( ! empty( $request['post'] ) ) { - $parent = get_post( (int) $request['post'] ); + $parent = get_post( (int) $request['post'] ); $post_parent_type = get_post_type_object( $parent->post_type ); if ( ! current_user_can( $post_parent_type->cap->edit_post, $request['post'] ) ) { @@ -101,7 +101,7 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { } // Get the file via $_FILES or raw data. - $files = $request->get_file_params(); + $files = $request->get_file_params(); $headers = $request->get_headers(); if ( ! empty( $files ) ) { @@ -116,11 +116,11 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { $name = basename( $file['file'] ); $name_parts = pathinfo( $name ); - $name = trim( substr( $name, 0, -(1 + strlen( $name_parts['extension'] ) ) ) ); + $name = trim( substr( $name, 0, -( 1 + strlen( $name_parts['extension'] ) ) ) ); - $url = $file['url']; - $type = $file['type']; - $file = $file['file']; + $url = $file['url']; + $type = $file['type']; + $file = $file['file']; // use image exif/iptc data for title and caption defaults if possible $image_meta = @wp_read_image_metadata( $file ); @@ -135,10 +135,10 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { } } - $attachment = $this->prepare_item_for_database( $request ); - $attachment->file = $file; + $attachment = $this->prepare_item_for_database( $request ); + $attachment->file = $file; $attachment->post_mime_type = $type; - $attachment->guid = $url; + $attachment->guid = $url; if ( empty( $attachment->post_title ) ) { $attachment->post_title = preg_replace( '/\.[^.]+$/', '', basename( $file ) ); @@ -213,7 +213,7 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { } $response = rest_ensure_response( $response ); - $data = $response->get_data(); + $data = $response->get_data(); if ( isset( $request['alt_text'] ) ) { update_post_meta( $data['id'], '_wp_attachment_image_alt', $request['alt_text'] ); @@ -284,19 +284,19 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { */ public function prepare_item_for_response( $post, $request ) { $response = parent::prepare_item_for_response( $post, $request ); - $data = $response->get_data(); + $data = $response->get_data(); $data['description'] = array( - 'raw' => $post->post_content, + 'raw' => $post->post_content, /** This filter is documented in wp-includes/post-template.php */ - 'rendered' => apply_filters( 'the_content', $post->post_content ), + 'rendered' => apply_filters( 'the_content', $post->post_content ), ); /** This filter is documented in wp-includes/post-template.php */ - $caption = apply_filters( 'the_excerpt', apply_filters( 'get_the_excerpt', $post->post_excerpt, $post ) ); + $caption = apply_filters( 'the_excerpt', apply_filters( 'get_the_excerpt', $post->post_excerpt, $post ) ); $data['caption'] = array( - 'raw' => $post->post_excerpt, - 'rendered' => $caption, + 'raw' => $post->post_excerpt, + 'rendered' => $caption, ); $data['alt_text'] = get_post_meta( $post->ID, '_wp_attachment_image_alt', true ); @@ -377,10 +377,10 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { $schema = parent::get_item_schema(); $schema['properties']['alt_text'] = array( - 'description' => __( 'Alternative text to display when attachment is not displayed.' ), - 'type' => 'string', - 'context' => array( 'view', 'edit', 'embed' ), - 'arg_options' => array( + 'description' => __( 'Alternative text to display when attachment is not displayed.' ), + 'type' => 'string', + 'context' => array( 'view', 'edit', 'embed' ), + 'arg_options' => array( 'sanitize_callback' => 'sanitize_text_field', ), ); @@ -394,7 +394,7 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { 'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database() ), 'properties' => array( - 'raw' => array( + 'raw' => array( 'description' => __( 'Caption for the attachment, as it exists in the database.' ), 'type' => 'string', 'context' => array( 'edit' ), @@ -417,7 +417,7 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { 'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database() ), 'properties' => array( - 'raw' => array( + 'raw' => array( 'description' => __( 'Description for the object, as it exists in the database.' ), 'type' => 'string', 'context' => array( 'edit' ), @@ -432,39 +432,39 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { ); $schema['properties']['media_type'] = array( - 'description' => __( 'Attachment type.' ), - 'type' => 'string', - 'enum' => array( 'image', 'file' ), - 'context' => array( 'view', 'edit', 'embed' ), - 'readonly' => true, + 'description' => __( 'Attachment type.' ), + 'type' => 'string', + 'enum' => array( 'image', 'file' ), + 'context' => array( 'view', 'edit', 'embed' ), + 'readonly' => true, ); $schema['properties']['mime_type'] = array( - 'description' => __( 'The attachment MIME type.' ), - 'type' => 'string', - 'context' => array( 'view', 'edit', 'embed' ), - 'readonly' => true, + 'description' => __( 'The attachment MIME type.' ), + 'type' => 'string', + 'context' => array( 'view', 'edit', 'embed' ), + 'readonly' => true, ); $schema['properties']['media_details'] = array( - 'description' => __( 'Details about the media file, specific to its type.' ), - 'type' => 'object', - 'context' => array( 'view', 'edit', 'embed' ), - 'readonly' => true, + 'description' => __( 'Details about the media file, specific to its type.' ), + 'type' => 'object', + 'context' => array( 'view', 'edit', 'embed' ), + 'readonly' => true, ); $schema['properties']['post'] = array( - 'description' => __( 'The ID for the associated post of the attachment.' ), - 'type' => 'integer', - 'context' => array( 'view', 'edit' ), + 'description' => __( 'The ID for the associated post of the attachment.' ), + 'type' => 'integer', + 'context' => array( 'view', 'edit' ), ); $schema['properties']['source_url'] = array( - 'description' => __( 'URL to the original attachment file.' ), - 'type' => 'string', - 'format' => 'uri', - 'context' => array( 'view', 'edit', 'embed' ), - 'readonly' => true, + 'description' => __( 'URL to the original attachment file.' ), + 'type' => 'string', + 'format' => 'uri', + 'context' => array( 'view', 'edit', 'embed' ), + 'readonly' => true, ); unset( $schema['properties']['password'] ); @@ -629,16 +629,16 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { * @return array Query parameters for the attachment collection as an array. */ public function get_collection_params() { - $params = parent::get_collection_params(); - $params['status']['default'] = 'inherit'; + $params = parent::get_collection_params(); + $params['status']['default'] = 'inherit'; $params['status']['items']['enum'] = array( 'inherit', 'private', 'trash' ); - $media_types = $this->get_media_types(); + $media_types = $this->get_media_types(); $params['media_type'] = array( - 'default' => null, - 'description' => __( 'Limit result set to attachments of a particular media type.' ), - 'type' => 'string', - 'enum' => array_keys( $media_types ), + 'default' => null, + 'description' => __( 'Limit result set to attachments of a particular media type.' ), + 'type' => 'string', + 'enum' => array_keys( $media_types ), ); $params['mime_type'] = array( @@ -695,7 +695,7 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { // Pass off to WP to handle the actual upload. $overrides = array( - 'test_form' => false, + 'test_form' => false, ); // Bypasses is_uploaded_file() when running unit tests. diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php index 23b1262c3c..3f7a9ed554 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php @@ -43,65 +43,69 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { */ public function register_routes() { - register_rest_route( $this->namespace, '/' . $this->rest_base, array( - array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_items' ), - 'permission_callback' => array( $this, 'get_items_permissions_check' ), - 'args' => $this->get_collection_params(), - ), - array( - 'methods' => WP_REST_Server::CREATABLE, - 'callback' => array( $this, 'create_item' ), - 'permission_callback' => array( $this, 'create_item_permissions_check' ), - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), - ), - 'schema' => array( $this, 'get_public_item_schema' ), - ) ); + register_rest_route( + $this->namespace, '/' . $this->rest_base, array( + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_items' ), + 'permission_callback' => array( $this, 'get_items_permissions_check' ), + 'args' => $this->get_collection_params(), + ), + array( + 'methods' => WP_REST_Server::CREATABLE, + 'callback' => array( $this, 'create_item' ), + 'permission_callback' => array( $this, 'create_item_permissions_check' ), + 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), + ), + 'schema' => array( $this, 'get_public_item_schema' ), + ) + ); - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P[\d]+)', array( - 'args' => array( - 'id' => array( - 'description' => __( 'Unique identifier for the object.' ), - 'type' => 'integer', - ), - ), - array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_item' ), - 'permission_callback' => array( $this, 'get_item_permissions_check' ), - 'args' => array( - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), - 'password' => array( - 'description' => __( 'The password for the parent post of the comment (if the post is password protected).' ), - 'type' => 'string', + register_rest_route( + $this->namespace, '/' . $this->rest_base . '/(?P[\d]+)', array( + 'args' => array( + 'id' => array( + 'description' => __( 'Unique identifier for the object.' ), + 'type' => 'integer', ), ), - ), - array( - 'methods' => WP_REST_Server::EDITABLE, - 'callback' => array( $this, 'update_item' ), - 'permission_callback' => array( $this, 'update_item_permissions_check' ), - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), - ), - array( - 'methods' => WP_REST_Server::DELETABLE, - 'callback' => array( $this, 'delete_item' ), - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), - 'args' => array( - 'force' => array( - 'type' => 'boolean', - 'default' => false, - 'description' => __( 'Whether to bypass trash and force deletion.' ), - ), - 'password' => array( - 'description' => __( 'The password for the parent post of the comment (if the post is password protected).' ), - 'type' => 'string', + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_item' ), + 'permission_callback' => array( $this, 'get_item_permissions_check' ), + 'args' => array( + 'context' => $this->get_context_param( array( 'default' => 'view' ) ), + 'password' => array( + 'description' => __( 'The password for the parent post of the comment (if the post is password protected).' ), + 'type' => 'string', + ), ), ), - ), - 'schema' => array( $this, 'get_public_item_schema' ), - ) ); + array( + 'methods' => WP_REST_Server::EDITABLE, + 'callback' => array( $this, 'update_item' ), + 'permission_callback' => array( $this, 'update_item_permissions_check' ), + 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), + ), + array( + 'methods' => WP_REST_Server::DELETABLE, + 'callback' => array( $this, 'delete_item' ), + 'permission_callback' => array( $this, 'delete_item_permissions_check' ), + 'args' => array( + 'force' => array( + 'type' => 'boolean', + 'default' => false, + 'description' => __( 'Whether to bypass trash and force deletion.' ), + ), + 'password' => array( + 'description' => __( 'The password for the parent post of the comment (if the post is password protected).' ), + 'type' => 'string', + ), + ), + ), + 'schema' => array( $this, 'get_public_item_schema' ), + ) + ); } /** @@ -245,7 +249,7 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { */ $prepared_args = apply_filters( 'rest_comment_query', $prepared_args, $request ); - $query = new WP_Comment_Query; + $query = new WP_Comment_Query; $query_result = $query->query( $prepared_args ); $comments = array(); @@ -255,7 +259,7 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { continue; } - $data = $this->prepare_item_for_response( $comment, $request ); + $data = $this->prepare_item_for_response( $comment, $request ); $comments[] = $this->prepare_response_for_collection( $data ); } @@ -266,11 +270,11 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { // Out-of-bounds, run the query again without LIMIT for total count. unset( $prepared_args['number'], $prepared_args['offset'] ); - $query = new WP_Comment_Query; + $query = new WP_Comment_Query; $prepared_args['count'] = true; $total_comments = $query->query( $prepared_args ); - $max_pages = ceil( $total_comments / $request['per_page'] ); + $max_pages = ceil( $total_comments / $request['per_page'] ); } $response = rest_ensure_response( $comments ); @@ -314,7 +318,7 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { return $error; } - $id = (int) $id; + $id = (int) $id; $comment = get_comment( $id ); if ( empty( $comment ) ) { return $error; @@ -375,7 +379,7 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { return $comment; } - $data = $this->prepare_item_for_response( $comment, $request ); + $data = $this->prepare_item_for_response( $comment, $request ); $response = rest_ensure_response( $data ); return $response; @@ -415,7 +419,8 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { // Limit who can set comment `author`, `author_ip` or `status` to anything other than the default. if ( isset( $request['author'] ) && get_current_user_id() !== $request['author'] && ! current_user_can( 'moderate_comments' ) ) { - return new WP_Error( 'rest_comment_invalid_author', + return new WP_Error( + 'rest_comment_invalid_author', /* translators: %s: request parameter */ sprintf( __( "Sorry, you are not allowed to edit '%s' for comments." ), 'author' ), array( 'status' => rest_authorization_required_code() ) @@ -424,7 +429,8 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { if ( isset( $request['author_ip'] ) && ! current_user_can( 'moderate_comments' ) ) { if ( empty( $_SERVER['REMOTE_ADDR'] ) || $request['author_ip'] !== $_SERVER['REMOTE_ADDR'] ) { - return new WP_Error( 'rest_comment_invalid_author_ip', + return new WP_Error( + 'rest_comment_invalid_author_ip', /* translators: %s: request parameter */ sprintf( __( "Sorry, you are not allowed to edit '%s' for comments." ), 'author_ip' ), array( 'status' => rest_authorization_required_code() ) @@ -433,7 +439,8 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { } if ( isset( $request['status'] ) && ! current_user_can( 'moderate_comments' ) ) { - return new WP_Error( 'rest_comment_invalid_status', + return new WP_Error( + 'rest_comment_invalid_status', /* translators: %s: request parameter */ sprintf( __( "Sorry, you are not allowed to edit '%s' for comments." ), 'status' ), array( 'status' => rest_authorization_required_code() ) @@ -515,10 +522,10 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { if ( is_user_logged_in() && $missing_author ) { $user = wp_get_current_user(); - $prepared_comment['user_id'] = $user->ID; - $prepared_comment['comment_author'] = $user->display_name; + $prepared_comment['user_id'] = $user->ID; + $prepared_comment['comment_author'] = $user->display_name; $prepared_comment['comment_author_email'] = $user->user_email; - $prepared_comment['comment_author_url'] = $user->user_url; + $prepared_comment['comment_author_url'] = $user->user_url; } // Honor the discussion setting that requires a name and email address of the comment author. @@ -631,7 +638,6 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { $response->set_status( 201 ); $response->header( 'Location', rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $comment_id ) ) ); - return $response; } @@ -804,9 +810,14 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { if ( $force ) { $previous = $this->prepare_item_for_response( $comment, $request ); - $result = wp_delete_comment( $comment->comment_ID, true ); + $result = wp_delete_comment( $comment->comment_ID, true ); $response = new WP_REST_Response(); - $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) ); + $response->set_data( + array( + 'deleted' => true, + 'previous' => $previous->get_data(), + ) + ); } else { // If this type doesn't support trashing, error out. if ( ! $supports_trash ) { @@ -818,8 +829,8 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { return new WP_Error( 'rest_already_trashed', __( 'The comment has already been trashed.' ), array( 'status' => 410 ) ); } - $result = wp_trash_comment( $comment->comment_ID ); - $comment = get_comment( $comment->comment_ID ); + $result = wp_trash_comment( $comment->comment_ID ); + $comment = get_comment( $comment->comment_ID ); $response = $this->prepare_item_for_response( $comment, $request ); } @@ -852,25 +863,25 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { */ public function prepare_item_for_response( $comment, $request ) { $data = array( - 'id' => (int) $comment->comment_ID, - 'post' => (int) $comment->comment_post_ID, - 'parent' => (int) $comment->comment_parent, - 'author' => (int) $comment->user_id, - 'author_name' => $comment->comment_author, - 'author_email' => $comment->comment_author_email, - 'author_url' => $comment->comment_author_url, - 'author_ip' => $comment->comment_author_IP, - 'author_user_agent' => $comment->comment_agent, - 'date' => mysql_to_rfc3339( $comment->comment_date ), - 'date_gmt' => mysql_to_rfc3339( $comment->comment_date_gmt ), - 'content' => array( + 'id' => (int) $comment->comment_ID, + 'post' => (int) $comment->comment_post_ID, + 'parent' => (int) $comment->comment_parent, + 'author' => (int) $comment->user_id, + 'author_name' => $comment->comment_author, + 'author_email' => $comment->comment_author_email, + 'author_url' => $comment->comment_author_url, + 'author_ip' => $comment->comment_author_IP, + 'author_user_agent' => $comment->comment_agent, + 'date' => mysql_to_rfc3339( $comment->comment_date ), + 'date_gmt' => mysql_to_rfc3339( $comment->comment_date_gmt ), + 'content' => array( /** This filter is documented in wp-includes/comment-template.php */ 'rendered' => apply_filters( 'comment_text', $comment->comment_content, $comment ), 'raw' => $comment->comment_content, ), - 'link' => get_comment_link( $comment ), - 'status' => $this->prepare_status_response( $comment->comment_approved ), - 'type' => get_comment_type( $comment->comment_ID ), + 'link' => get_comment_link( $comment ), + 'status' => $this->prepare_status_response( $comment->comment_approved ), + 'type' => get_comment_type( $comment->comment_ID ), ); $schema = $this->get_item_schema(); @@ -916,7 +927,7 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { */ protected function prepare_links( $comment ) { $links = array( - 'self' => array( + 'self' => array( 'href' => rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $comment->comment_ID ) ), ), 'collection' => array( @@ -935,7 +946,7 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { $post = get_post( $comment->comment_post_ID ); if ( ! empty( $post->ID ) ) { - $obj = get_post_type_object( $post->post_type ); + $obj = get_post_type_object( $post->post_type ); $base = ! empty( $obj->rest_base ) ? $obj->rest_base : $obj->name; $links['up'] = array( @@ -954,14 +965,16 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { } // Only grab one comment to verify the comment has children. - $comment_children = $comment->get_children( array( - 'number' => 1, - 'count' => true - ) ); + $comment_children = $comment->get_children( + array( + 'number' => 1, + 'count' => true, + ) + ); if ( ! empty( $comment_children ) ) { $args = array( - 'parent' => $comment->comment_ID + 'parent' => $comment->comment_ID, ); $rest_url = add_query_arg( $args, rest_url( $this->namespace . '/' . $this->rest_base ) ); @@ -1070,10 +1083,10 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { $user = new WP_User( $request['author'] ); if ( $user->exists() ) { - $prepared_comment['user_id'] = $user->ID; - $prepared_comment['comment_author'] = $user->display_name; + $prepared_comment['user_id'] = $user->ID; + $prepared_comment['comment_author'] = $user->display_name; $prepared_comment['comment_author_email'] = $user->user_email; - $prepared_comment['comment_author_url'] = $user->user_url; + $prepared_comment['comment_author_url'] = $user->user_url; } else { return new WP_Error( 'rest_comment_author_invalid', __( 'Invalid comment author ID.' ), array( 'status' => 400 ) ); } @@ -1141,125 +1154,125 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { */ public function get_item_schema() { $schema = array( - '$schema' => 'http://json-schema.org/draft-04/schema#', - 'title' => 'comment', - 'type' => 'object', - 'properties' => array( - 'id' => array( - 'description' => __( 'Unique identifier for the object.' ), - 'type' => 'integer', - 'context' => array( 'view', 'edit', 'embed' ), - 'readonly' => true, + '$schema' => 'http://json-schema.org/draft-04/schema#', + 'title' => 'comment', + 'type' => 'object', + 'properties' => array( + 'id' => array( + 'description' => __( 'Unique identifier for the object.' ), + 'type' => 'integer', + 'context' => array( 'view', 'edit', 'embed' ), + 'readonly' => true, ), - 'author' => array( - 'description' => __( 'The ID of the user object, if author was a user.' ), - 'type' => 'integer', - 'context' => array( 'view', 'edit', 'embed' ), + 'author' => array( + 'description' => __( 'The ID of the user object, if author was a user.' ), + 'type' => 'integer', + 'context' => array( 'view', 'edit', 'embed' ), ), - 'author_email' => array( - 'description' => __( 'Email address for the object author.' ), - 'type' => 'string', - 'format' => 'email', - 'context' => array( 'edit' ), - 'arg_options' => array( + 'author_email' => array( + 'description' => __( 'Email address for the object author.' ), + 'type' => 'string', + 'format' => 'email', + 'context' => array( 'edit' ), + 'arg_options' => array( 'sanitize_callback' => array( $this, 'check_comment_author_email' ), 'validate_callback' => null, // skip built-in validation of 'email'. ), ), - 'author_ip' => array( - 'description' => __( 'IP address for the object author.' ), - 'type' => 'string', - 'format' => 'ip', - 'context' => array( 'edit' ), + 'author_ip' => array( + 'description' => __( 'IP address for the object author.' ), + 'type' => 'string', + 'format' => 'ip', + 'context' => array( 'edit' ), ), - 'author_name' => array( - 'description' => __( 'Display name for the object author.' ), - 'type' => 'string', - 'context' => array( 'view', 'edit', 'embed' ), - 'arg_options' => array( + 'author_name' => array( + 'description' => __( 'Display name for the object author.' ), + 'type' => 'string', + 'context' => array( 'view', 'edit', 'embed' ), + 'arg_options' => array( 'sanitize_callback' => 'sanitize_text_field', ), ), - 'author_url' => array( - 'description' => __( 'URL for the object author.' ), - 'type' => 'string', - 'format' => 'uri', - 'context' => array( 'view', 'edit', 'embed' ), + 'author_url' => array( + 'description' => __( 'URL for the object author.' ), + 'type' => 'string', + 'format' => 'uri', + 'context' => array( 'view', 'edit', 'embed' ), ), - 'author_user_agent' => array( - 'description' => __( 'User agent for the object author.' ), - 'type' => 'string', - 'context' => array( 'edit' ), - 'arg_options' => array( + 'author_user_agent' => array( + 'description' => __( 'User agent for the object author.' ), + 'type' => 'string', + 'context' => array( 'edit' ), + 'arg_options' => array( 'sanitize_callback' => 'sanitize_text_field', ), ), - 'content' => array( - 'description' => __( 'The content for the object.' ), - 'type' => 'object', - 'context' => array( 'view', 'edit', 'embed' ), - 'arg_options' => array( + 'content' => array( + 'description' => __( 'The content for the object.' ), + 'type' => 'object', + 'context' => array( 'view', 'edit', 'embed' ), + 'arg_options' => array( 'sanitize_callback' => null, // Note: sanitization implemented in self::prepare_item_for_database() 'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database() ), - 'properties' => array( - 'raw' => array( - 'description' => __( 'Content for the object, as it exists in the database.' ), - 'type' => 'string', - 'context' => array( 'edit' ), + 'properties' => array( + 'raw' => array( + 'description' => __( 'Content for the object, as it exists in the database.' ), + 'type' => 'string', + 'context' => array( 'edit' ), ), - 'rendered' => array( - 'description' => __( 'HTML content for the object, transformed for display.' ), - 'type' => 'string', - 'context' => array( 'view', 'edit', 'embed' ), - 'readonly' => true, + 'rendered' => array( + 'description' => __( 'HTML content for the object, transformed for display.' ), + 'type' => 'string', + 'context' => array( 'view', 'edit', 'embed' ), + 'readonly' => true, ), ), ), - 'date' => array( - 'description' => __( "The date the object was published, in the site's timezone." ), - 'type' => 'string', - 'format' => 'date-time', - 'context' => array( 'view', 'edit', 'embed' ), + 'date' => array( + 'description' => __( "The date the object was published, in the site's timezone." ), + 'type' => 'string', + 'format' => 'date-time', + 'context' => array( 'view', 'edit', 'embed' ), ), - 'date_gmt' => array( - 'description' => __( 'The date the object was published, as GMT.' ), - 'type' => 'string', - 'format' => 'date-time', - 'context' => array( 'view', 'edit' ), + 'date_gmt' => array( + 'description' => __( 'The date the object was published, as GMT.' ), + 'type' => 'string', + 'format' => 'date-time', + 'context' => array( 'view', 'edit' ), ), - 'link' => array( - 'description' => __( 'URL to the object.' ), - 'type' => 'string', - 'format' => 'uri', - 'context' => array( 'view', 'edit', 'embed' ), - 'readonly' => true, + 'link' => array( + 'description' => __( 'URL to the object.' ), + 'type' => 'string', + 'format' => 'uri', + 'context' => array( 'view', 'edit', 'embed' ), + 'readonly' => true, ), - 'parent' => array( - 'description' => __( 'The ID for the parent of the object.' ), - 'type' => 'integer', - 'context' => array( 'view', 'edit', 'embed' ), - 'default' => 0, + 'parent' => array( + 'description' => __( 'The ID for the parent of the object.' ), + 'type' => 'integer', + 'context' => array( 'view', 'edit', 'embed' ), + 'default' => 0, ), - 'post' => array( - 'description' => __( 'The ID of the associated post object.' ), - 'type' => 'integer', - 'context' => array( 'view', 'edit' ), - 'default' => 0, + 'post' => array( + 'description' => __( 'The ID of the associated post object.' ), + 'type' => 'integer', + 'context' => array( 'view', 'edit' ), + 'default' => 0, ), - 'status' => array( - 'description' => __( 'State of the object.' ), - 'type' => 'string', - 'context' => array( 'view', 'edit' ), - 'arg_options' => array( + 'status' => array( + 'description' => __( 'State of the object.' ), + 'type' => 'string', + 'context' => array( 'view', 'edit' ), + 'arg_options' => array( 'sanitize_callback' => 'sanitize_key', ), ), - 'type' => array( - 'description' => __( 'Type of Comment for the object.' ), - 'type' => 'string', - 'context' => array( 'view', 'edit', 'embed' ), - 'readonly' => true, + 'type' => array( + 'description' => __( 'Type of Comment for the object.' ), + 'type' => 'string', + 'context' => array( 'view', 'edit', 'embed' ), + 'readonly' => true, ), ), ); @@ -1279,11 +1292,11 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { } $schema['properties']['author_avatar_urls'] = array( - 'description' => __( 'Avatar URLs for the object author.' ), - 'type' => 'object', - 'context' => array( 'view', 'edit', 'embed' ), - 'readonly' => true, - 'properties' => $avatar_properties, + 'description' => __( 'Avatar URLs for the object author.' ), + 'type' => 'object', + 'context' => array( 'view', 'edit', 'embed' ), + 'readonly' => true, + 'properties' => $avatar_properties, ); } @@ -1305,78 +1318,78 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { $query_params['context']['default'] = 'view'; $query_params['after'] = array( - 'description' => __( 'Limit response to comments published after a given ISO8601 compliant date.' ), - 'type' => 'string', - 'format' => 'date-time', + 'description' => __( 'Limit response to comments published after a given ISO8601 compliant date.' ), + 'type' => 'string', + 'format' => 'date-time', ); $query_params['author'] = array( - 'description' => __( 'Limit result set to comments assigned to specific user IDs. Requires authorization.' ), - 'type' => 'array', - 'items' => array( - 'type' => 'integer', + 'description' => __( 'Limit result set to comments assigned to specific user IDs. Requires authorization.' ), + 'type' => 'array', + 'items' => array( + 'type' => 'integer', ), ); $query_params['author_exclude'] = array( - 'description' => __( 'Ensure result set excludes comments assigned to specific user IDs. Requires authorization.' ), - 'type' => 'array', - 'items' => array( - 'type' => 'integer', + 'description' => __( 'Ensure result set excludes comments assigned to specific user IDs. Requires authorization.' ), + 'type' => 'array', + 'items' => array( + 'type' => 'integer', ), ); $query_params['author_email'] = array( - 'default' => null, - 'description' => __( 'Limit result set to that from a specific author email. Requires authorization.' ), - 'format' => 'email', - 'type' => 'string', + 'default' => null, + 'description' => __( 'Limit result set to that from a specific author email. Requires authorization.' ), + 'format' => 'email', + 'type' => 'string', ); $query_params['before'] = array( - 'description' => __( 'Limit response to comments published before a given ISO8601 compliant date.' ), - 'type' => 'string', - 'format' => 'date-time', + 'description' => __( 'Limit response to comments published before a given ISO8601 compliant date.' ), + 'type' => 'string', + 'format' => 'date-time', ); $query_params['exclude'] = array( - 'description' => __( 'Ensure result set excludes specific IDs.' ), - 'type' => 'array', - 'items' => array( - 'type' => 'integer', + 'description' => __( 'Ensure result set excludes specific IDs.' ), + 'type' => 'array', + 'items' => array( + 'type' => 'integer', ), - 'default' => array(), + 'default' => array(), ); $query_params['include'] = array( - 'description' => __( 'Limit result set to specific IDs.' ), - 'type' => 'array', - 'items' => array( - 'type' => 'integer', + 'description' => __( 'Limit result set to specific IDs.' ), + 'type' => 'array', + 'items' => array( + 'type' => 'integer', ), - 'default' => array(), + 'default' => array(), ); $query_params['offset'] = array( - 'description' => __( 'Offset the result set by a specific number of items.' ), - 'type' => 'integer', + 'description' => __( 'Offset the result set by a specific number of items.' ), + 'type' => 'integer', ); - $query_params['order'] = array( - 'description' => __( 'Order sort attribute ascending or descending.' ), - 'type' => 'string', - 'default' => 'desc', - 'enum' => array( + $query_params['order'] = array( + 'description' => __( 'Order sort attribute ascending or descending.' ), + 'type' => 'string', + 'default' => 'desc', + 'enum' => array( 'asc', 'desc', ), ); - $query_params['orderby'] = array( - 'description' => __( 'Sort collection by object attribute.' ), - 'type' => 'string', - 'default' => 'date_gmt', - 'enum' => array( + $query_params['orderby'] = array( + 'description' => __( 'Sort collection by object attribute.' ), + 'type' => 'string', + 'default' => 'date_gmt', + 'enum' => array( 'date', 'date_gmt', 'id', @@ -1388,29 +1401,29 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { ); $query_params['parent'] = array( - 'default' => array(), - 'description' => __( 'Limit result set to comments of specific parent IDs.' ), - 'type' => 'array', - 'items' => array( - 'type' => 'integer', + 'default' => array(), + 'description' => __( 'Limit result set to comments of specific parent IDs.' ), + 'type' => 'array', + 'items' => array( + 'type' => 'integer', ), ); $query_params['parent_exclude'] = array( - 'default' => array(), - 'description' => __( 'Ensure result set excludes specific parent IDs.' ), - 'type' => 'array', - 'items' => array( - 'type' => 'integer', + 'default' => array(), + 'description' => __( 'Ensure result set excludes specific parent IDs.' ), + 'type' => 'array', + 'items' => array( + 'type' => 'integer', ), ); - $query_params['post'] = array( - 'default' => array(), - 'description' => __( 'Limit result set to comments assigned to specific post IDs.' ), - 'type' => 'array', - 'items' => array( - 'type' => 'integer', + $query_params['post'] = array( + 'default' => array(), + 'description' => __( 'Limit result set to comments assigned to specific post IDs.' ), + 'type' => 'array', + 'items' => array( + 'type' => 'integer', ), ); @@ -1466,7 +1479,7 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { } switch ( $new_status ) { - case 'approved' : + case 'approved': case 'approve': case '1': $changed = wp_set_comment_status( $comment_id, 'approve' ); @@ -1475,19 +1488,19 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { case '0': $changed = wp_set_comment_status( $comment_id, 'hold' ); break; - case 'spam' : + case 'spam': $changed = wp_spam_comment( $comment_id ); break; - case 'unspam' : + case 'unspam': $changed = wp_unspam_comment( $comment_id ); break; - case 'trash' : + case 'trash': $changed = wp_trash_comment( $comment_id ); break; - case 'untrash' : + case 'untrash': $changed = wp_untrash_comment( $comment_id ); break; - default : + default: $changed = false; break; } @@ -1508,12 +1521,12 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { */ protected function check_read_post_permission( $post, $request ) { $posts_controller = new WP_REST_Posts_Controller( $post->post_type ); - $post_type = get_post_type_object( $post->post_type ); + $post_type = get_post_type_object( $post->post_type ); $has_password_filter = false; // Only check password if a specific post was queried for or a single comment - $requested_post = ! empty( $request['post'] ) && ( !is_array( $request['post'] ) || 1 === count( $request['post'] ) ); + $requested_post = ! empty( $request['post'] ) && ( ! is_array( $request['post'] ) || 1 === count( $request['post'] ) ); $requested_comment = ! empty( $request['id'] ); if ( ( $requested_post || $requested_comment ) && $posts_controller->can_access_password_content( $post, $request ) ) { add_filter( 'post_password_required', '__return_false' ); diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-controller.php index f26e87606a..076d06c0ce 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-controller.php @@ -305,29 +305,29 @@ abstract class WP_REST_Controller { */ public function get_collection_params() { return array( - 'context' => $this->get_context_param(), - 'page' => array( - 'description' => __( 'Current page of the collection.' ), - 'type' => 'integer', - 'default' => 1, - 'sanitize_callback' => 'absint', - 'validate_callback' => 'rest_validate_request_arg', - 'minimum' => 1, + 'context' => $this->get_context_param(), + 'page' => array( + 'description' => __( 'Current page of the collection.' ), + 'type' => 'integer', + 'default' => 1, + 'sanitize_callback' => 'absint', + 'validate_callback' => 'rest_validate_request_arg', + 'minimum' => 1, ), - 'per_page' => array( - 'description' => __( 'Maximum number of items to be returned in result set.' ), - 'type' => 'integer', - 'default' => 10, - 'minimum' => 1, - 'maximum' => 100, - 'sanitize_callback' => 'absint', - 'validate_callback' => 'rest_validate_request_arg', + 'per_page' => array( + 'description' => __( 'Maximum number of items to be returned in result set.' ), + 'type' => 'integer', + 'default' => 10, + 'minimum' => 1, + 'maximum' => 100, + 'sanitize_callback' => 'absint', + 'validate_callback' => 'rest_validate_request_arg', ), - 'search' => array( - 'description' => __( 'Limit results to those matching a string.' ), - 'type' => 'string', - 'sanitize_callback' => 'sanitize_text_field', - 'validate_callback' => 'rest_validate_request_arg', + 'search' => array( + 'description' => __( 'Limit results to those matching a string.' ), + 'type' => 'string', + 'sanitize_callback' => 'sanitize_text_field', + 'validate_callback' => 'rest_validate_request_arg', ), ); } @@ -344,10 +344,10 @@ abstract class WP_REST_Controller { */ public function get_context_param( $args = array() ) { $param_details = array( - 'description' => __( 'Scope under which the request is made; determines fields present in response.' ), - 'type' => 'string', - 'sanitize_callback' => 'sanitize_key', - 'validate_callback' => 'rest_validate_request_arg', + 'description' => __( 'Scope under which the request is made; determines fields present in response.' ), + 'type' => 'string', + 'sanitize_callback' => 'sanitize_key', + 'validate_callback' => 'rest_validate_request_arg', ); $schema = $this->get_item_schema(); @@ -556,7 +556,12 @@ abstract class WP_REST_Controller { // Only use required / default from arg_options on CREATABLE endpoints. if ( WP_REST_Server::CREATABLE !== $method ) { - $params['arg_options'] = array_diff_key( $params['arg_options'], array( 'required' => '', 'default' => '' ) ); + $params['arg_options'] = array_diff_key( + $params['arg_options'], array( + 'required' => '', + 'default' => '', + ) + ); } $endpoint_args[ $field_id ] = array_merge( $endpoint_args[ $field_id ], $params['arg_options'] ); diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php index e2cce55b65..c6aadddb18 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php @@ -35,33 +35,37 @@ class WP_REST_Post_Statuses_Controller extends WP_REST_Controller { */ public function register_routes() { - register_rest_route( $this->namespace, '/' . $this->rest_base, array( - array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_items' ), - 'permission_callback' => array( $this, 'get_items_permissions_check' ), - 'args' => $this->get_collection_params(), - ), - 'schema' => array( $this, 'get_public_item_schema' ), - ) ); + register_rest_route( + $this->namespace, '/' . $this->rest_base, array( + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_items' ), + 'permission_callback' => array( $this, 'get_items_permissions_check' ), + 'args' => $this->get_collection_params(), + ), + 'schema' => array( $this, 'get_public_item_schema' ), + ) + ); - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P[\w-]+)', array( - 'args' => array( - 'status' => array( - 'description' => __( 'An alphanumeric identifier for the status.' ), - 'type' => 'string', + register_rest_route( + $this->namespace, '/' . $this->rest_base . '/(?P[\w-]+)', array( + 'args' => array( + 'status' => array( + 'description' => __( 'An alphanumeric identifier for the status.' ), + 'type' => 'string', + ), ), - ), - array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_item' ), - 'permission_callback' => array( $this, 'get_item_permissions_check' ), - 'args' => array( - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_item' ), + 'permission_callback' => array( $this, 'get_item_permissions_check' ), + 'args' => array( + 'context' => $this->get_context_param( array( 'default' => 'view' ) ), + ), ), - ), - 'schema' => array( $this, 'get_public_item_schema' ), - ) ); + 'schema' => array( $this, 'get_public_item_schema' ), + ) + ); } /** @@ -96,8 +100,8 @@ class WP_REST_Post_Statuses_Controller extends WP_REST_Controller { * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. */ public function get_items( $request ) { - $data = array(); - $statuses = get_post_stati( array( 'internal' => false ), 'object' ); + $data = array(); + $statuses = get_post_stati( array( 'internal' => false ), 'object' ); $statuses['trash'] = get_post_status_object( 'trash' ); foreach ( $statuses as $slug => $obj ) { @@ -107,7 +111,7 @@ class WP_REST_Post_Statuses_Controller extends WP_REST_Controller { continue; } - $status = $this->prepare_item_for_response( $obj, $request ); + $status = $this->prepare_item_for_response( $obj, $request ); $data[ $obj->name ] = $this->prepare_response_for_collection( $status ); } @@ -206,8 +210,8 @@ class WP_REST_Post_Statuses_Controller extends WP_REST_Controller { ); $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; - $data = $this->add_additional_fields_to_object( $data, $request ); - $data = $this->filter_response_by_context( $data, $context ); + $data = $this->add_additional_fields_to_object( $data, $request ); + $data = $this->filter_response_by_context( $data, $context ); $response = rest_ensure_response( $data ); @@ -240,51 +244,51 @@ class WP_REST_Post_Statuses_Controller extends WP_REST_Controller { */ public function get_item_schema() { $schema = array( - '$schema' => 'http://json-schema.org/draft-04/schema#', - 'title' => 'status', - 'type' => 'object', - 'properties' => array( - 'name' => array( - 'description' => __( 'The title for the status.' ), - 'type' => 'string', - 'context' => array( 'embed', 'view', 'edit' ), - 'readonly' => true, + '$schema' => 'http://json-schema.org/draft-04/schema#', + 'title' => 'status', + 'type' => 'object', + 'properties' => array( + 'name' => array( + 'description' => __( 'The title for the status.' ), + 'type' => 'string', + 'context' => array( 'embed', 'view', 'edit' ), + 'readonly' => true, ), - 'private' => array( - 'description' => __( 'Whether posts with this status should be private.' ), - 'type' => 'boolean', - 'context' => array( 'edit' ), - 'readonly' => true, + 'private' => array( + 'description' => __( 'Whether posts with this status should be private.' ), + 'type' => 'boolean', + 'context' => array( 'edit' ), + 'readonly' => true, ), - 'protected' => array( - 'description' => __( 'Whether posts with this status should be protected.' ), - 'type' => 'boolean', - 'context' => array( 'edit' ), - 'readonly' => true, + 'protected' => array( + 'description' => __( 'Whether posts with this status should be protected.' ), + 'type' => 'boolean', + 'context' => array( 'edit' ), + 'readonly' => true, ), - 'public' => array( - 'description' => __( 'Whether posts of this status should be shown in the front end of the site.' ), - 'type' => 'boolean', - 'context' => array( 'view', 'edit' ), - 'readonly' => true, + 'public' => array( + 'description' => __( 'Whether posts of this status should be shown in the front end of the site.' ), + 'type' => 'boolean', + 'context' => array( 'view', 'edit' ), + 'readonly' => true, ), - 'queryable' => array( - 'description' => __( 'Whether posts with this status should be publicly-queryable.' ), - 'type' => 'boolean', - 'context' => array( 'view', 'edit' ), - 'readonly' => true, + 'queryable' => array( + 'description' => __( 'Whether posts with this status should be publicly-queryable.' ), + 'type' => 'boolean', + 'context' => array( 'view', 'edit' ), + 'readonly' => true, ), - 'show_in_list' => array( - 'description' => __( 'Whether to include posts in the edit listing for their post type.' ), - 'type' => 'boolean', - 'context' => array( 'edit' ), - 'readonly' => true, + 'show_in_list' => array( + 'description' => __( 'Whether to include posts in the edit listing for their post type.' ), + 'type' => 'boolean', + 'context' => array( 'edit' ), + 'readonly' => true, ), - 'slug' => array( - 'description' => __( 'An alphanumeric identifier for the status.' ), - 'type' => 'string', - 'context' => array( 'embed', 'view', 'edit' ), - 'readonly' => true, + 'slug' => array( + 'description' => __( 'An alphanumeric identifier for the status.' ), + 'type' => 'string', + 'context' => array( 'embed', 'view', 'edit' ), + 'readonly' => true, ), ), ); diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php index d574ba8372..203cea2530 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php @@ -35,32 +35,36 @@ class WP_REST_Post_Types_Controller extends WP_REST_Controller { */ public function register_routes() { - register_rest_route( $this->namespace, '/' . $this->rest_base, array( - array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_items' ), - 'permission_callback' => array( $this, 'get_items_permissions_check' ), - 'args' => $this->get_collection_params(), - ), - 'schema' => array( $this, 'get_public_item_schema' ), - ) ); + register_rest_route( + $this->namespace, '/' . $this->rest_base, array( + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_items' ), + 'permission_callback' => array( $this, 'get_items_permissions_check' ), + 'args' => $this->get_collection_params(), + ), + 'schema' => array( $this, 'get_public_item_schema' ), + ) + ); - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P[\w-]+)', array( - 'args' => array( - 'type' => array( - 'description' => __( 'An alphanumeric identifier for the post type.' ), - 'type' => 'string', + register_rest_route( + $this->namespace, '/' . $this->rest_base . '/(?P[\w-]+)', array( + 'args' => array( + 'type' => array( + 'description' => __( 'An alphanumeric identifier for the post type.' ), + 'type' => 'string', + ), ), - ), - array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_item' ), - 'args' => array( - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_item' ), + 'args' => array( + 'context' => $this->get_context_param( array( 'default' => 'view' ) ), + ), ), - ), - 'schema' => array( $this, 'get_public_item_schema' ), - ) ); + 'schema' => array( $this, 'get_public_item_schema' ), + ) + ); } /** @@ -101,7 +105,7 @@ class WP_REST_Post_Types_Controller extends WP_REST_Controller { continue; } - $post_type = $this->prepare_item_for_response( $obj, $request ); + $post_type = $this->prepare_item_for_response( $obj, $request ); $data[ $obj->name ] = $this->prepare_response_for_collection( $post_type ); } @@ -148,10 +152,10 @@ class WP_REST_Post_Types_Controller extends WP_REST_Controller { public function prepare_item_for_response( $post_type, $request ) { $taxonomies = wp_list_filter( get_object_taxonomies( $post_type->name, 'objects' ), array( 'show_in_rest' => true ) ); $taxonomies = wp_list_pluck( $taxonomies, 'name' ); - $base = ! empty( $post_type->rest_base ) ? $post_type->rest_base : $post_type->name; - $supports = get_all_post_type_supports( $post_type->name ); + $base = ! empty( $post_type->rest_base ) ? $post_type->rest_base : $post_type->name; + $supports = get_all_post_type_supports( $post_type->name ); - $data = array( + $data = array( 'capabilities' => $post_type->cap, 'description' => $post_type->description, 'hierarchical' => $post_type->hierarchical, @@ -169,14 +173,16 @@ class WP_REST_Post_Types_Controller extends WP_REST_Controller { // Wrap the data in a response object. $response = rest_ensure_response( $data ); - $response->add_links( array( - 'collection' => array( - 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), - ), - 'https://api.w.org/items' => array( - 'href' => rest_url( sprintf( 'wp/v2/%s', $base ) ), - ), - ) ); + $response->add_links( + array( + 'collection' => array( + 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), + ), + 'https://api.w.org/items' => array( + 'href' => rest_url( sprintf( 'wp/v2/%s', $base ) ), + ), + ) + ); /** * Filters a post type returned from the API. @@ -201,66 +207,66 @@ class WP_REST_Post_Types_Controller extends WP_REST_Controller { */ public function get_item_schema() { $schema = array( - '$schema' => 'http://json-schema.org/draft-04/schema#', - 'title' => 'type', - 'type' => 'object', - 'properties' => array( - 'capabilities' => array( - 'description' => __( 'All capabilities used by the post type.' ), - 'type' => 'object', - 'context' => array( 'edit' ), - 'readonly' => true, + '$schema' => 'http://json-schema.org/draft-04/schema#', + 'title' => 'type', + 'type' => 'object', + 'properties' => array( + 'capabilities' => array( + 'description' => __( 'All capabilities used by the post type.' ), + 'type' => 'object', + 'context' => array( 'edit' ), + 'readonly' => true, ), - 'description' => array( - 'description' => __( 'A human-readable description of the post type.' ), - 'type' => 'string', - 'context' => array( 'view', 'edit' ), - 'readonly' => true, + 'description' => array( + 'description' => __( 'A human-readable description of the post type.' ), + 'type' => 'string', + 'context' => array( 'view', 'edit' ), + 'readonly' => true, ), - 'hierarchical' => array( - 'description' => __( 'Whether or not the post type should have children.' ), - 'type' => 'boolean', - 'context' => array( 'view', 'edit' ), - 'readonly' => true, + 'hierarchical' => array( + 'description' => __( 'Whether or not the post type should have children.' ), + 'type' => 'boolean', + 'context' => array( 'view', 'edit' ), + 'readonly' => true, ), - 'labels' => array( - 'description' => __( 'Human-readable labels for the post type for various contexts.' ), - 'type' => 'object', - 'context' => array( 'edit' ), - 'readonly' => true, + 'labels' => array( + 'description' => __( 'Human-readable labels for the post type for various contexts.' ), + 'type' => 'object', + 'context' => array( 'edit' ), + 'readonly' => true, ), - 'name' => array( - 'description' => __( 'The title for the post type.' ), - 'type' => 'string', - 'context' => array( 'view', 'edit', 'embed' ), - 'readonly' => true, + 'name' => array( + 'description' => __( 'The title for the post type.' ), + 'type' => 'string', + 'context' => array( 'view', 'edit', 'embed' ), + 'readonly' => true, ), - 'slug' => array( - 'description' => __( 'An alphanumeric identifier for the post type.' ), - 'type' => 'string', - 'context' => array( 'view', 'edit', 'embed' ), - 'readonly' => true, + 'slug' => array( + 'description' => __( 'An alphanumeric identifier for the post type.' ), + 'type' => 'string', + 'context' => array( 'view', 'edit', 'embed' ), + 'readonly' => true, ), - 'supports' => array( - 'description' => __( 'All features, supported by the post type.' ), - 'type' => 'object', - 'context' => array( 'edit' ), - 'readonly' => true, + 'supports' => array( + 'description' => __( 'All features, supported by the post type.' ), + 'type' => 'object', + 'context' => array( 'edit' ), + 'readonly' => true, ), - 'taxonomies' => array( - 'description' => __( 'Taxonomies associated with post type.' ), - 'type' => 'array', - 'items' => array( + 'taxonomies' => array( + 'description' => __( 'Taxonomies associated with post type.' ), + 'type' => 'array', + 'items' => array( 'type' => 'string', ), - 'context' => array( 'view', 'edit' ), - 'readonly' => true, + 'context' => array( 'view', 'edit' ), + 'readonly' => true, ), - 'rest_base' => array( - 'description' => __( 'REST base route for the post type.' ), - 'type' => 'string', - 'context' => array( 'view', 'edit', 'embed' ), - 'readonly' => true, + 'rest_base' => array( + 'description' => __( 'REST base route for the post type.' ), + 'type' => 'string', + 'context' => array( 'view', 'edit', 'embed' ), + 'readonly' => true, ), ), ); diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index 2a24a9048b..7d8b5d6109 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -42,7 +42,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { public function __construct( $post_type ) { $this->post_type = $post_type; $this->namespace = 'wp/v2'; - $obj = get_post_type_object( $post_type ); + $obj = get_post_type_object( $post_type ); $this->rest_base = ! empty( $obj->rest_base ) ? $obj->rest_base : $obj->name; $this->meta = new WP_REST_Post_Meta_Fields( $this->post_type ); @@ -57,25 +57,27 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { */ public function register_routes() { - register_rest_route( $this->namespace, '/' . $this->rest_base, array( - array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_items' ), - 'permission_callback' => array( $this, 'get_items_permissions_check' ), - 'args' => $this->get_collection_params(), - ), - array( - 'methods' => WP_REST_Server::CREATABLE, - 'callback' => array( $this, 'create_item' ), - 'permission_callback' => array( $this, 'create_item_permissions_check' ), - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), - ), - 'schema' => array( $this, 'get_public_item_schema' ), - ) ); + register_rest_route( + $this->namespace, '/' . $this->rest_base, array( + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_items' ), + 'permission_callback' => array( $this, 'get_items_permissions_check' ), + 'args' => $this->get_collection_params(), + ), + array( + 'methods' => WP_REST_Server::CREATABLE, + 'callback' => array( $this, 'create_item' ), + 'permission_callback' => array( $this, 'create_item_permissions_check' ), + 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), + ), + 'schema' => array( $this, 'get_public_item_schema' ), + ) + ); - $schema = $this->get_item_schema(); + $schema = $this->get_item_schema(); $get_item_args = array( - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), + 'context' => $this->get_context_param( array( 'default' => 'view' ) ), ); if ( isset( $schema['properties']['password'] ) ) { $get_item_args['password'] = array( @@ -83,39 +85,41 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { 'type' => 'string', ); } - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P[\d]+)', array( - 'args' => array( - 'id' => array( - 'description' => __( 'Unique identifier for the object.' ), - 'type' => 'integer', - ), - ), - array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_item' ), - 'permission_callback' => array( $this, 'get_item_permissions_check' ), - 'args' => $get_item_args, - ), - array( - 'methods' => WP_REST_Server::EDITABLE, - 'callback' => array( $this, 'update_item' ), - 'permission_callback' => array( $this, 'update_item_permissions_check' ), - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), - ), - array( - 'methods' => WP_REST_Server::DELETABLE, - 'callback' => array( $this, 'delete_item' ), - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), - 'args' => array( - 'force' => array( - 'type' => 'boolean', - 'default' => false, - 'description' => __( 'Whether to bypass trash and force deletion.' ), + register_rest_route( + $this->namespace, '/' . $this->rest_base . '/(?P[\d]+)', array( + 'args' => array( + 'id' => array( + 'description' => __( 'Unique identifier for the object.' ), + 'type' => 'integer', ), ), - ), - 'schema' => array( $this, 'get_public_item_schema' ), - ) ); + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_item' ), + 'permission_callback' => array( $this, 'get_item_permissions_check' ), + 'args' => $get_item_args, + ), + array( + 'methods' => WP_REST_Server::EDITABLE, + 'callback' => array( $this, 'update_item' ), + 'permission_callback' => array( $this, 'update_item_permissions_check' ), + 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), + ), + array( + 'methods' => WP_REST_Server::DELETABLE, + 'callback' => array( $this, 'delete_item' ), + 'permission_callback' => array( $this, 'delete_item_permissions_check' ), + 'args' => array( + 'force' => array( + 'type' => 'boolean', + 'default' => false, + 'description' => __( 'Whether to bypass trash and force deletion.' ), + ), + ), + ), + 'schema' => array( $this, 'get_public_item_schema' ), + ) + ); } /** @@ -159,7 +163,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { // Retrieve the list of registered collection query parameters. $registered = $this->get_collection_params(); - $args = array(); + $args = array(); /* * This array defines mappings between public API query parameters whose @@ -258,13 +262,13 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { * @param array $args Key value array of query var to query value. * @param WP_REST_Request $request The request used. */ - $args = apply_filters( "rest_{$this->post_type}_query", $args, $request ); + $args = apply_filters( "rest_{$this->post_type}_query", $args, $request ); $query_args = $this->prepare_items_query( $args, $request ); $taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) ); foreach ( $taxonomies as $taxonomy ) { - $base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name; + $base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name; $tax_exclude = $base . '_exclude'; if ( ! empty( $request[ $base ] ) ) { @@ -311,7 +315,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { remove_filter( 'post_password_required', '__return_false' ); } - $page = (int) $query_args['paged']; + $page = (int) $query_args['paged']; $total_posts = $posts_query->found_posts; if ( $total_posts < 1 ) { @@ -329,13 +333,13 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { return new WP_Error( 'rest_post_invalid_page_number', __( 'The page number requested is larger than the number of pages available.' ), array( 'status' => 400 ) ); } - $response = rest_ensure_response( $posts ); + $response = rest_ensure_response( $posts ); $response->header( 'X-WP-Total', (int) $total_posts ); $response->header( 'X-WP-TotalPages', (int) $max_pages ); $request_params = $request->get_query_params(); - $base = add_query_arg( $request_params, rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) ); + $base = add_query_arg( $request_params, rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) ); if ( $page > 1 ) { $prev_page = $page - 1; @@ -466,7 +470,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { $response = rest_ensure_response( $data ); if ( is_post_type_viewable( get_post_type_object( $post->post_type ) ) ) { - $response->link_header( 'alternate', get_permalink( $post->ID ), array( 'type' => 'text/html' ) ); + $response->link_header( 'alternate', get_permalink( $post->ID ), array( 'type' => 'text/html' ) ); } return $response; @@ -591,7 +595,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { } } - $post = get_post( $post_id ); + $post = get_post( $post_id ); $fields_update = $this->update_additional_fields_for_object( $post, $request ); if ( is_wp_error( $fields_update ) ) { @@ -717,7 +721,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { } } - $post = get_post( $post_id ); + $post = get_post( $post_id ); $fields_update = $this->update_additional_fields_for_object( $post, $request ); if ( is_wp_error( $fields_update ) ) { @@ -795,13 +799,17 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { $request->set_param( 'context', 'edit' ); - // If we're forcing, then delete permanently. if ( $force ) { $previous = $this->prepare_item_for_response( $post, $request ); - $result = wp_delete_post( $id, true ); + $result = wp_delete_post( $id, true ); $response = new WP_REST_Response(); - $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) ); + $response->set_data( + array( + 'deleted' => true, + 'previous' => $previous->get_data(), + ) + ); } else { // If we don't support trashing for this type, error out. if ( ! $supports_trash ) { @@ -816,8 +824,8 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { // (Note that internally this falls through to `wp_delete_post` if // the trash is disabled.) - $result = wp_trash_post( $id ); - $post = get_post( $id ); + $result = wp_trash_post( $id ); + $post = get_post( $id ); $response = $this->prepare_item_for_response( $post, $request ); } @@ -991,14 +999,14 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { if ( ! empty( $date_data ) ) { list( $prepared_post->post_date, $prepared_post->post_date_gmt ) = $date_data; - $prepared_post->edit_date = true; + $prepared_post->edit_date = true; } } elseif ( ! empty( $schema['properties']['date_gmt'] ) && ! empty( $request['date_gmt'] ) ) { $date_data = rest_get_date_with_gmt( $request['date_gmt'], true ); if ( ! empty( $date_data ) ) { list( $prepared_post->post_date, $prepared_post->post_date_gmt ) = $date_data; - $prepared_post->edit_date = true; + $prepared_post->edit_date = true; } } @@ -1502,7 +1510,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { if ( ! empty( $schema['properties']['excerpt'] ) ) { /** This filter is documented in wp-includes/post-template.php */ - $excerpt = apply_filters( 'the_excerpt', apply_filters( 'get_the_excerpt', $post->post_excerpt, $post ) ); + $excerpt = apply_filters( 'the_excerpt', apply_filters( 'get_the_excerpt', $post->post_excerpt, $post ) ); $data['excerpt'] = array( 'raw' => $post->post_excerpt, 'rendered' => post_password_required( $post ) ? '' : $excerpt, @@ -1570,7 +1578,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { $base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name; if ( ! empty( $schema['properties'][ $base ] ) ) { - $terms = get_the_terms( $post, $taxonomy->name ); + $terms = get_the_terms( $post, $taxonomy->name ); $data[ $base ] = $terms ? array_values( wp_list_pluck( $terms, 'term_id' ) ) : array(); } } @@ -1626,14 +1634,14 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { // Entity meta. $links = array( - 'self' => array( - 'href' => rest_url( trailingslashit( $base ) . $post->ID ), + 'self' => array( + 'href' => rest_url( trailingslashit( $base ) . $post->ID ), ), 'collection' => array( - 'href' => rest_url( $base ), + 'href' => rest_url( $base ), ), 'about' => array( - 'href' => rest_url( 'wp/v2/types/' . $this->post_type ), + 'href' => rest_url( 'wp/v2/types/' . $this->post_type ), ), ); @@ -1736,19 +1744,19 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { 'type' => 'object', // Base properties for every Post. 'properties' => array( - 'date' => array( + 'date' => array( 'description' => __( "The date the object was published, in the site's timezone." ), 'type' => 'string', 'format' => 'date-time', 'context' => array( 'view', 'edit', 'embed' ), ), - 'date_gmt' => array( + 'date_gmt' => array( 'description' => __( 'The date the object was published, as GMT.' ), 'type' => 'string', 'format' => 'date-time', 'context' => array( 'view', 'edit' ), ), - 'guid' => array( + 'guid' => array( 'description' => __( 'The globally unique identifier for the object.' ), 'type' => 'object', 'context' => array( 'view', 'edit' ), @@ -1768,34 +1776,34 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { ), ), ), - 'id' => array( + 'id' => array( 'description' => __( 'Unique identifier for the object.' ), 'type' => 'integer', 'context' => array( 'view', 'edit', 'embed' ), 'readonly' => true, ), - 'link' => array( + 'link' => array( 'description' => __( 'URL to the object.' ), 'type' => 'string', 'format' => 'uri', 'context' => array( 'view', 'edit', 'embed' ), 'readonly' => true, ), - 'modified' => array( + 'modified' => array( 'description' => __( "The date the object was last modified, in the site's timezone." ), 'type' => 'string', 'format' => 'date-time', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), - 'modified_gmt' => array( + 'modified_gmt' => array( 'description' => __( 'The date the object was last modified, as GMT.' ), 'type' => 'string', 'format' => 'date-time', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), - 'slug' => array( + 'slug' => array( 'description' => __( 'An alphanumeric identifier for the object unique to its type.' ), 'type' => 'string', 'context' => array( 'view', 'edit', 'embed' ), @@ -1803,19 +1811,19 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { 'sanitize_callback' => array( $this, 'sanitize_slug' ), ), ), - 'status' => array( + 'status' => array( 'description' => __( 'A named status for the object.' ), 'type' => 'string', 'enum' => array_keys( get_post_stati( array( 'internal' => false ) ) ), 'context' => array( 'view', 'edit' ), ), - 'type' => array( + 'type' => array( 'description' => __( 'Type of Post for the object.' ), 'type' => 'string', 'context' => array( 'view', 'edit', 'embed' ), 'readonly' => true, ), - 'password' => array( + 'password' => array( 'description' => __( 'A password to protect access to the content and excerpt.' ), 'type' => 'string', 'context' => array( 'edit' ), @@ -1845,8 +1853,8 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { 'post-formats', 'custom-fields', ); - $fixed_schemas = array( - 'post' => array( + $fixed_schemas = array( + 'post' => array( 'title', 'editor', 'author', @@ -1857,7 +1865,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { 'post-formats', 'custom-fields', ), - 'page' => array( + 'page' => array( 'title', 'editor', 'author', @@ -1895,7 +1903,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { 'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database() ), 'properties' => array( - 'raw' => array( + 'raw' => array( 'description' => __( 'Title for the object, as it exists in the database.' ), 'type' => 'string', 'context' => array( 'edit' ), @@ -1920,18 +1928,18 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { 'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database() ), 'properties' => array( - 'raw' => array( + 'raw' => array( 'description' => __( 'Content for the object, as it exists in the database.' ), 'type' => 'string', 'context' => array( 'edit' ), ), - 'rendered' => array( + 'rendered' => array( 'description' => __( 'HTML content for the object, transformed for display.' ), 'type' => 'string', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), - 'protected' => array( + 'protected' => array( 'description' => __( 'Whether the content is protected with a password.' ), 'type' => 'boolean', 'context' => array( 'view', 'edit', 'embed' ), @@ -1959,18 +1967,18 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { 'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database() ), 'properties' => array( - 'raw' => array( + 'raw' => array( 'description' => __( 'Excerpt for the object, as it exists in the database.' ), 'type' => 'string', 'context' => array( 'edit' ), ), - 'rendered' => array( + 'rendered' => array( 'description' => __( 'HTML excerpt for the object, transformed for display.' ), 'type' => 'string', 'context' => array( 'view', 'edit', 'embed' ), 'readonly' => true, ), - 'protected' => array( + 'protected' => array( 'description' => __( 'Whether the excerpt is protected with a password.' ), 'type' => 'boolean', 'context' => array( 'view', 'edit', 'embed' ), @@ -1995,7 +2003,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { 'enum' => array( 'open', 'closed' ), 'context' => array( 'view', 'edit' ), ); - $schema['properties']['ping_status'] = array( + $schema['properties']['ping_status'] = array( 'description' => __( 'Whether or not the object can be pinged.' ), 'type' => 'string', 'enum' => array( 'open', 'closed' ), @@ -2049,13 +2057,13 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { $taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) ); foreach ( $taxonomies as $taxonomy ) { - $base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name; + $base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name; $schema['properties'][ $base ] = array( /* translators: %s: taxonomy name */ 'description' => sprintf( __( 'The terms assigned to the object in the %s taxonomy.' ), $taxonomy->name ), 'type' => 'array', 'items' => array( - 'type' => 'integer', + 'type' => 'integer', ), 'context' => array( 'view', 'edit' ), ); @@ -2077,78 +2085,78 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { $query_params['context']['default'] = 'view'; $query_params['after'] = array( - 'description' => __( 'Limit response to posts published after a given ISO8601 compliant date.' ), - 'type' => 'string', - 'format' => 'date-time', + 'description' => __( 'Limit response to posts published after a given ISO8601 compliant date.' ), + 'type' => 'string', + 'format' => 'date-time', ); if ( post_type_supports( $this->post_type, 'author' ) ) { - $query_params['author'] = array( - 'description' => __( 'Limit result set to posts assigned to specific authors.' ), - 'type' => 'array', - 'items' => array( - 'type' => 'integer', + $query_params['author'] = array( + 'description' => __( 'Limit result set to posts assigned to specific authors.' ), + 'type' => 'array', + 'items' => array( + 'type' => 'integer', ), - 'default' => array(), + 'default' => array(), ); $query_params['author_exclude'] = array( - 'description' => __( 'Ensure result set excludes posts assigned to specific authors.' ), - 'type' => 'array', - 'items' => array( - 'type' => 'integer', + 'description' => __( 'Ensure result set excludes posts assigned to specific authors.' ), + 'type' => 'array', + 'items' => array( + 'type' => 'integer', ), - 'default' => array(), + 'default' => array(), ); } $query_params['before'] = array( - 'description' => __( 'Limit response to posts published before a given ISO8601 compliant date.' ), - 'type' => 'string', - 'format' => 'date-time', + 'description' => __( 'Limit response to posts published before a given ISO8601 compliant date.' ), + 'type' => 'string', + 'format' => 'date-time', ); $query_params['exclude'] = array( - 'description' => __( 'Ensure result set excludes specific IDs.' ), - 'type' => 'array', - 'items' => array( - 'type' => 'integer', + 'description' => __( 'Ensure result set excludes specific IDs.' ), + 'type' => 'array', + 'items' => array( + 'type' => 'integer', ), - 'default' => array(), + 'default' => array(), ); $query_params['include'] = array( - 'description' => __( 'Limit result set to specific IDs.' ), - 'type' => 'array', - 'items' => array( - 'type' => 'integer', + 'description' => __( 'Limit result set to specific IDs.' ), + 'type' => 'array', + 'items' => array( + 'type' => 'integer', ), - 'default' => array(), + 'default' => array(), ); if ( 'page' === $this->post_type || post_type_supports( $this->post_type, 'page-attributes' ) ) { $query_params['menu_order'] = array( - 'description' => __( 'Limit result set to posts with a specific menu_order value.' ), - 'type' => 'integer', + 'description' => __( 'Limit result set to posts with a specific menu_order value.' ), + 'type' => 'integer', ); } $query_params['offset'] = array( - 'description' => __( 'Offset the result set by a specific number of items.' ), - 'type' => 'integer', + 'description' => __( 'Offset the result set by a specific number of items.' ), + 'type' => 'integer', ); $query_params['order'] = array( - 'description' => __( 'Order sort attribute ascending or descending.' ), - 'type' => 'string', - 'default' => 'desc', - 'enum' => array( 'asc', 'desc' ), + 'description' => __( 'Order sort attribute ascending or descending.' ), + 'type' => 'string', + 'default' => 'desc', + 'enum' => array( 'asc', 'desc' ), ); $query_params['orderby'] = array( - 'description' => __( 'Sort collection by object attribute.' ), - 'type' => 'string', - 'default' => 'date', - 'enum' => array( + 'description' => __( 'Sort collection by object attribute.' ), + 'type' => 'string', + 'default' => 'date', + 'enum' => array( 'author', 'date', 'id', @@ -2169,21 +2177,21 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { $post_type = get_post_type_object( $this->post_type ); if ( $post_type->hierarchical || 'attachment' === $this->post_type ) { - $query_params['parent'] = array( - 'description' => __( 'Limit result set to items with particular parent IDs.' ), - 'type' => 'array', - 'items' => array( - 'type' => 'integer', + $query_params['parent'] = array( + 'description' => __( 'Limit result set to items with particular parent IDs.' ), + 'type' => 'array', + 'items' => array( + 'type' => 'integer', ), - 'default' => array(), + 'default' => array(), ); $query_params['parent_exclude'] = array( - 'description' => __( 'Limit result set to all items except those of a particular parent ID.' ), - 'type' => 'array', - 'items' => array( - 'type' => 'integer', + 'description' => __( 'Limit result set to all items except those of a particular parent ID.' ), + 'type' => 'array', + 'items' => array( + 'type' => 'integer', ), - 'default' => array(), + 'default' => array(), ); } @@ -2191,7 +2199,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { 'description' => __( 'Limit result set to posts with one or more specific slugs.' ), 'type' => 'array', 'items' => array( - 'type' => 'string', + 'type' => 'string', ), 'sanitize_callback' => 'wp_parse_slug_list', ); @@ -2201,8 +2209,8 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { 'description' => __( 'Limit result set to posts assigned one or more statuses.' ), 'type' => 'array', 'items' => array( - 'enum' => array_merge( array_keys( get_post_stati() ), array( 'any' ) ), - 'type' => 'string', + 'enum' => array_merge( array_keys( get_post_stati() ), array( 'any' ) ), + 'type' => 'string', ), 'sanitize_callback' => array( $this, 'sanitize_post_statuses' ), ); @@ -2214,12 +2222,12 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { $query_params[ $base ] = array( /* translators: %s: taxonomy name */ - 'description' => sprintf( __( 'Limit result set to all items that have the specified term assigned in the %s taxonomy.' ), $base ), - 'type' => 'array', - 'items' => array( - 'type' => 'integer', + 'description' => sprintf( __( 'Limit result set to all items that have the specified term assigned in the %s taxonomy.' ), $base ), + 'type' => 'array', + 'items' => array( + 'type' => 'integer', ), - 'default' => array(), + 'default' => array(), ); $query_params[ $base . '_exclude' ] = array( @@ -2227,16 +2235,16 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { 'description' => sprintf( __( 'Limit result set to all items except those that have the specified term assigned in the %s taxonomy.' ), $base ), 'type' => 'array', 'items' => array( - 'type' => 'integer', + 'type' => 'integer', ), - 'default' => array(), + 'default' => array(), ); } if ( 'post' === $this->post_type ) { $query_params['sticky'] = array( - 'description' => __( 'Limit result set to items that are sticky.' ), - 'type' => 'boolean', + 'description' => __( 'Limit result set to items that are sticky.' ), + 'type' => 'boolean', ); } @@ -2273,7 +2281,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { $statuses = wp_parse_slug_list( $statuses ); // The default status is different in WP_REST_Attachments_Controller - $attributes = $request->get_attributes(); + $attributes = $request->get_attributes(); $default_status = $attributes['args']['status']['default']; foreach ( $statuses as $status ) { diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php index 298fcc5748..471c4c4b4f 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php @@ -48,12 +48,12 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller { * @param string $parent_post_type Post type of the parent. */ public function __construct( $parent_post_type ) { - $this->parent_post_type = $parent_post_type; + $this->parent_post_type = $parent_post_type; $this->parent_controller = new WP_REST_Posts_Controller( $parent_post_type ); - $this->namespace = 'wp/v2'; - $this->rest_base = 'revisions'; - $post_type_object = get_post_type_object( $parent_post_type ); - $this->parent_base = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name; + $this->namespace = 'wp/v2'; + $this->rest_base = 'revisions'; + $post_type_object = get_post_type_object( $parent_post_type ); + $this->parent_base = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name; } /** @@ -65,55 +65,59 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller { */ public function register_routes() { - register_rest_route( $this->namespace, '/' . $this->parent_base . '/(?P[\d]+)/' . $this->rest_base, array( - 'args' => array( - 'parent' => array( - 'description' => __( 'The ID for the parent of the object.' ), - 'type' => 'integer', - ), - ), - array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_items' ), - 'permission_callback' => array( $this, 'get_items_permissions_check' ), - 'args' => $this->get_collection_params(), - ), - 'schema' => array( $this, 'get_public_item_schema' ), - ) ); - - register_rest_route( $this->namespace, '/' . $this->parent_base . '/(?P[\d]+)/' . $this->rest_base . '/(?P[\d]+)', array( - 'args' => array( - 'parent' => array( - 'description' => __( 'The ID for the parent of the object.' ), - 'type' => 'integer', - ), - 'id' => array( - 'description' => __( 'Unique identifier for the object.' ), - 'type' => 'integer', - ), - ), - array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_item' ), - 'permission_callback' => array( $this, 'get_item_permissions_check' ), - 'args' => array( - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), - ), - ), - array( - 'methods' => WP_REST_Server::DELETABLE, - 'callback' => array( $this, 'delete_item' ), - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), - 'args' => array( - 'force' => array( - 'type' => 'boolean', - 'default' => false, - 'description' => __( 'Required to be true, as revisions do not support trashing.' ), + register_rest_route( + $this->namespace, '/' . $this->parent_base . '/(?P[\d]+)/' . $this->rest_base, array( + 'args' => array( + 'parent' => array( + 'description' => __( 'The ID for the parent of the object.' ), + 'type' => 'integer', ), ), - ), - 'schema' => array( $this, 'get_public_item_schema' ), - )); + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_items' ), + 'permission_callback' => array( $this, 'get_items_permissions_check' ), + 'args' => $this->get_collection_params(), + ), + 'schema' => array( $this, 'get_public_item_schema' ), + ) + ); + + register_rest_route( + $this->namespace, '/' . $this->parent_base . '/(?P[\d]+)/' . $this->rest_base . '/(?P[\d]+)', array( + 'args' => array( + 'parent' => array( + 'description' => __( 'The ID for the parent of the object.' ), + 'type' => 'integer', + ), + 'id' => array( + 'description' => __( 'Unique identifier for the object.' ), + 'type' => 'integer', + ), + ), + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_item' ), + 'permission_callback' => array( $this, 'get_item_permissions_check' ), + 'args' => array( + 'context' => $this->get_context_param( array( 'default' => 'view' ) ), + ), + ), + array( + 'methods' => WP_REST_Server::DELETABLE, + 'callback' => array( $this, 'delete_item' ), + 'permission_callback' => array( $this, 'delete_item_permissions_check' ), + 'args' => array( + 'force' => array( + 'type' => 'boolean', + 'default' => false, + 'description' => __( 'Required to be true, as revisions do not support trashing.' ), + ), + ), + ), + 'schema' => array( $this, 'get_public_item_schema' ), + ) + ); } @@ -201,7 +205,7 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller { $response = array(); foreach ( $revisions as $revision ) { - $data = $this->prepare_item_for_response( $revision, $request ); + $data = $this->prepare_item_for_response( $revision, $request ); $response[] = $this->prepare_response_for_collection( $data ); } return rest_ensure_response( $response ); @@ -313,7 +317,12 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller { } $response = new WP_REST_Response(); - $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) ); + $response->set_data( + array( + 'deleted' => true, + 'previous' => $previous->get_data(), + ) + ); return $response; } @@ -398,9 +407,9 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller { ); } - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; - $data = $this->add_additional_fields_to_object( $data, $request ); - $data = $this->filter_response_by_context( $data, $context ); + $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; + $data = $this->add_additional_fields_to_object( $data, $request ); + $data = $this->filter_response_by_context( $data, $context ); $response = rest_ensure_response( $data ); if ( ! empty( $data['parent'] ) ) { @@ -457,51 +466,51 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller { 'type' => 'object', // Base properties for every Revision. 'properties' => array( - 'author' => array( + 'author' => array( 'description' => __( 'The ID for the author of the object.' ), 'type' => 'integer', 'context' => array( 'view', 'edit', 'embed' ), ), - 'date' => array( + 'date' => array( 'description' => __( "The date the object was published, in the site's timezone." ), 'type' => 'string', 'format' => 'date-time', 'context' => array( 'view', 'edit', 'embed' ), ), - 'date_gmt' => array( + 'date_gmt' => array( 'description' => __( 'The date the object was published, as GMT.' ), 'type' => 'string', 'format' => 'date-time', 'context' => array( 'view', 'edit' ), ), - 'guid' => array( + 'guid' => array( 'description' => __( 'GUID for the object, as it exists in the database.' ), 'type' => 'string', 'context' => array( 'view', 'edit' ), ), - 'id' => array( + 'id' => array( 'description' => __( 'Unique identifier for the object.' ), 'type' => 'integer', 'context' => array( 'view', 'edit', 'embed' ), ), - 'modified' => array( + 'modified' => array( 'description' => __( "The date the object was last modified, in the site's timezone." ), 'type' => 'string', 'format' => 'date-time', 'context' => array( 'view', 'edit' ), ), - 'modified_gmt' => array( + 'modified_gmt' => array( 'description' => __( 'The date the object was last modified, as GMT.' ), 'type' => 'string', 'format' => 'date-time', 'context' => array( 'view', 'edit' ), ), - 'parent' => array( + 'parent' => array( 'description' => __( 'The ID for the parent of the object.' ), 'type' => 'integer', 'context' => array( 'view', 'edit', 'embed' ), - ), - 'slug' => array( + ), + 'slug' => array( 'description' => __( 'An alphanumeric identifier for the object unique to its type.' ), 'type' => 'string', 'context' => array( 'view', 'edit', 'embed' ), diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php index 82a22101f2..1a38261a08 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php @@ -35,21 +35,23 @@ class WP_REST_Settings_Controller extends WP_REST_Controller { */ public function register_routes() { - register_rest_route( $this->namespace, '/' . $this->rest_base, array( - array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_item' ), - 'args' => array(), - 'permission_callback' => array( $this, 'get_item_permissions_check' ), - ), - array( - 'methods' => WP_REST_Server::EDITABLE, - 'callback' => array( $this, 'update_item' ), - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), - 'permission_callback' => array( $this, 'get_item_permissions_check' ), - ), - 'schema' => array( $this, 'get_public_item_schema' ), - ) ); + register_rest_route( + $this->namespace, '/' . $this->rest_base, array( + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_item' ), + 'args' => array(), + 'permission_callback' => array( $this, 'get_item_permissions_check' ), + ), + array( + 'methods' => WP_REST_Server::EDITABLE, + 'callback' => array( $this, 'update_item' ), + 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), + 'permission_callback' => array( $this, 'get_item_permissions_check' ), + ), + 'schema' => array( $this, 'get_public_item_schema' ), + ) + ); } @@ -139,7 +141,7 @@ class WP_REST_Settings_Controller extends WP_REST_Controller { public function update_item( $request ) { $options = $this->get_registered_options(); - $params = $request->get_params(); + $params = $request->get_params(); foreach ( $options as $name => $args ) { if ( ! array_key_exists( $name, $params ) ) { @@ -232,7 +234,7 @@ class WP_REST_Settings_Controller extends WP_REST_Controller { 'default' => isset( $args['default'] ) ? $args['default'] : null, ); - $rest_args['schema'] = array_merge( $default_schema, $rest_args['schema'] ); + $rest_args['schema'] = array_merge( $default_schema, $rest_args['schema'] ); $rest_args['option_name'] = $name; // Skip over settings that don't have a defined type in the schema. @@ -274,7 +276,7 @@ class WP_REST_Settings_Controller extends WP_REST_Controller { ); foreach ( $options as $option_name => $option ) { - $schema['properties'][ $option_name ] = $option['schema']; + $schema['properties'][ $option_name ] = $option['schema']; $schema['properties'][ $option_name ]['arg_options'] = array( 'sanitize_callback' => array( $this, 'sanitize_callback' ), ); diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php index 9720a20945..14384814ee 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php @@ -35,33 +35,37 @@ class WP_REST_Taxonomies_Controller extends WP_REST_Controller { */ public function register_routes() { - register_rest_route( $this->namespace, '/' . $this->rest_base, array( - array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_items' ), - 'permission_callback' => array( $this, 'get_items_permissions_check' ), - 'args' => $this->get_collection_params(), - ), - 'schema' => array( $this, 'get_public_item_schema' ), - ) ); + register_rest_route( + $this->namespace, '/' . $this->rest_base, array( + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_items' ), + 'permission_callback' => array( $this, 'get_items_permissions_check' ), + 'args' => $this->get_collection_params(), + ), + 'schema' => array( $this, 'get_public_item_schema' ), + ) + ); - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P[\w-]+)', array( - 'args' => array( - 'taxonomy' => array( - 'description' => __( 'An alphanumeric identifier for the taxonomy.' ), - 'type' => 'string', + register_rest_route( + $this->namespace, '/' . $this->rest_base . '/(?P[\w-]+)', array( + 'args' => array( + 'taxonomy' => array( + 'description' => __( 'An alphanumeric identifier for the taxonomy.' ), + 'type' => 'string', + ), ), - ), - array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_item' ), - 'permission_callback' => array( $this, 'get_item_permissions_check' ), - 'args' => array( - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_item' ), + 'permission_callback' => array( $this, 'get_item_permissions_check' ), + 'args' => array( + 'context' => $this->get_context_param( array( 'default' => 'view' ) ), + ), ), - ), - 'schema' => array( $this, 'get_public_item_schema' ), - ) ); + 'schema' => array( $this, 'get_public_item_schema' ), + ) + ); } /** @@ -112,8 +116,8 @@ class WP_REST_Taxonomies_Controller extends WP_REST_Controller { if ( empty( $value->show_in_rest ) || ( 'edit' === $request['context'] && ! current_user_can( $value->cap->manage_terms ) ) ) { continue; } - $tax = $this->prepare_item_for_response( $value, $request ); - $tax = $this->prepare_response_for_collection( $tax ); + $tax = $this->prepare_item_for_response( $value, $request ); + $tax = $this->prepare_response_for_collection( $tax ); $data[ $tax_type ] = $tax; } @@ -190,20 +194,22 @@ class WP_REST_Taxonomies_Controller extends WP_REST_Controller { ); $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; - $data = $this->add_additional_fields_to_object( $data, $request ); - $data = $this->filter_response_by_context( $data, $context ); + $data = $this->add_additional_fields_to_object( $data, $request ); + $data = $this->filter_response_by_context( $data, $context ); // Wrap the data in a response object. $response = rest_ensure_response( $data ); - $response->add_links( array( - 'collection' => array( - 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), - ), - 'https://api.w.org/items' => array( - 'href' => rest_url( sprintf( 'wp/v2/%s', $base ) ), - ), - ) ); + $response->add_links( + array( + 'collection' => array( + 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), + ), + 'https://api.w.org/items' => array( + 'href' => rest_url( sprintf( 'wp/v2/%s', $base ) ), + ), + ) + ); /** * Filters a taxonomy returned from the REST API. @@ -228,66 +234,66 @@ class WP_REST_Taxonomies_Controller extends WP_REST_Controller { */ public function get_item_schema() { $schema = array( - '$schema' => 'http://json-schema.org/draft-04/schema#', - 'title' => 'taxonomy', - 'type' => 'object', - 'properties' => array( - 'capabilities' => array( - 'description' => __( 'All capabilities used by the taxonomy.' ), - 'type' => 'object', - 'context' => array( 'edit' ), - 'readonly' => true, + '$schema' => 'http://json-schema.org/draft-04/schema#', + 'title' => 'taxonomy', + 'type' => 'object', + 'properties' => array( + 'capabilities' => array( + 'description' => __( 'All capabilities used by the taxonomy.' ), + 'type' => 'object', + 'context' => array( 'edit' ), + 'readonly' => true, ), - 'description' => array( - 'description' => __( 'A human-readable description of the taxonomy.' ), - 'type' => 'string', - 'context' => array( 'view', 'edit' ), - 'readonly' => true, + 'description' => array( + 'description' => __( 'A human-readable description of the taxonomy.' ), + 'type' => 'string', + 'context' => array( 'view', 'edit' ), + 'readonly' => true, ), - 'hierarchical' => array( - 'description' => __( 'Whether or not the taxonomy should have children.' ), - 'type' => 'boolean', - 'context' => array( 'view', 'edit' ), - 'readonly' => true, + 'hierarchical' => array( + 'description' => __( 'Whether or not the taxonomy should have children.' ), + 'type' => 'boolean', + 'context' => array( 'view', 'edit' ), + 'readonly' => true, ), - 'labels' => array( - 'description' => __( 'Human-readable labels for the taxonomy for various contexts.' ), - 'type' => 'object', - 'context' => array( 'edit' ), - 'readonly' => true, + 'labels' => array( + 'description' => __( 'Human-readable labels for the taxonomy for various contexts.' ), + 'type' => 'object', + 'context' => array( 'edit' ), + 'readonly' => true, ), - 'name' => array( - 'description' => __( 'The title for the taxonomy.' ), - 'type' => 'string', - 'context' => array( 'view', 'edit', 'embed' ), - 'readonly' => true, + 'name' => array( + 'description' => __( 'The title for the taxonomy.' ), + 'type' => 'string', + 'context' => array( 'view', 'edit', 'embed' ), + 'readonly' => true, ), - 'slug' => array( - 'description' => __( 'An alphanumeric identifier for the taxonomy.' ), - 'type' => 'string', - 'context' => array( 'view', 'edit', 'embed' ), - 'readonly' => true, + 'slug' => array( + 'description' => __( 'An alphanumeric identifier for the taxonomy.' ), + 'type' => 'string', + 'context' => array( 'view', 'edit', 'embed' ), + 'readonly' => true, ), - 'show_cloud' => array( - 'description' => __( 'Whether or not the term cloud should be displayed.' ), - 'type' => 'boolean', - 'context' => array( 'edit' ), - 'readonly' => true, + 'show_cloud' => array( + 'description' => __( 'Whether or not the term cloud should be displayed.' ), + 'type' => 'boolean', + 'context' => array( 'edit' ), + 'readonly' => true, ), - 'types' => array( - 'description' => __( 'Types associated with the taxonomy.' ), - 'type' => 'array', - 'items' => array( + 'types' => array( + 'description' => __( 'Types associated with the taxonomy.' ), + 'type' => 'array', + 'items' => array( 'type' => 'string', ), - 'context' => array( 'view', 'edit' ), - 'readonly' => true, + 'context' => array( 'view', 'edit' ), + 'readonly' => true, ), - 'rest_base' => array( - 'description' => __( 'REST base route for the taxonomy.' ), - 'type' => 'string', - 'context' => array( 'view', 'edit', 'embed' ), - 'readonly' => true, + 'rest_base' => array( + 'description' => __( 'REST base route for the taxonomy.' ), + 'type' => 'string', + 'context' => array( 'view', 'edit', 'embed' ), + 'readonly' => true, ), ), ); @@ -302,11 +308,11 @@ class WP_REST_Taxonomies_Controller extends WP_REST_Controller { * @return array Collection parameters. */ public function get_collection_params() { - $new_params = array(); + $new_params = array(); $new_params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); - $new_params['type'] = array( - 'description' => __( 'Limit results to taxonomies associated with a specific post type.' ), - 'type' => 'string', + $new_params['type'] = array( + 'description' => __( 'Limit results to taxonomies associated with a specific post type.' ), + 'type' => 'string', ); return $new_params; } diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php index 749a6d6870..459ef3e948 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php @@ -56,9 +56,9 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { * @param string $taxonomy Taxonomy key. */ public function __construct( $taxonomy ) { - $this->taxonomy = $taxonomy; + $this->taxonomy = $taxonomy; $this->namespace = 'wp/v2'; - $tax_obj = get_taxonomy( $taxonomy ); + $tax_obj = get_taxonomy( $taxonomy ); $this->rest_base = ! empty( $tax_obj->rest_base ) ? $tax_obj->rest_base : $tax_obj->name; $this->meta = new WP_REST_Term_Meta_Fields( $taxonomy ); @@ -73,57 +73,61 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { */ public function register_routes() { - register_rest_route( $this->namespace, '/' . $this->rest_base, array( - array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_items' ), - 'permission_callback' => array( $this, 'get_items_permissions_check' ), - 'args' => $this->get_collection_params(), - ), - array( - 'methods' => WP_REST_Server::CREATABLE, - 'callback' => array( $this, 'create_item' ), - 'permission_callback' => array( $this, 'create_item_permissions_check' ), - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), - ), - 'schema' => array( $this, 'get_public_item_schema' ), - ) ); + register_rest_route( + $this->namespace, '/' . $this->rest_base, array( + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_items' ), + 'permission_callback' => array( $this, 'get_items_permissions_check' ), + 'args' => $this->get_collection_params(), + ), + array( + 'methods' => WP_REST_Server::CREATABLE, + 'callback' => array( $this, 'create_item' ), + 'permission_callback' => array( $this, 'create_item_permissions_check' ), + 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), + ), + 'schema' => array( $this, 'get_public_item_schema' ), + ) + ); - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P[\d]+)', array( - 'args' => array( - 'id' => array( - 'description' => __( 'Unique identifier for the term.' ), - 'type' => 'integer', - ), - ), - array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_item' ), - 'permission_callback' => array( $this, 'get_item_permissions_check' ), - 'args' => array( - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), - ), - ), - array( - 'methods' => WP_REST_Server::EDITABLE, - 'callback' => array( $this, 'update_item' ), - 'permission_callback' => array( $this, 'update_item_permissions_check' ), - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), - ), - array( - 'methods' => WP_REST_Server::DELETABLE, - 'callback' => array( $this, 'delete_item' ), - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), - 'args' => array( - 'force' => array( - 'type' => 'boolean', - 'default' => false, - 'description' => __( 'Required to be true, as terms do not support trashing.' ), + register_rest_route( + $this->namespace, '/' . $this->rest_base . '/(?P[\d]+)', array( + 'args' => array( + 'id' => array( + 'description' => __( 'Unique identifier for the term.' ), + 'type' => 'integer', ), ), - ), - 'schema' => array( $this, 'get_public_item_schema' ), - ) ); + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_item' ), + 'permission_callback' => array( $this, 'get_item_permissions_check' ), + 'args' => array( + 'context' => $this->get_context_param( array( 'default' => 'view' ) ), + ), + ), + array( + 'methods' => WP_REST_Server::EDITABLE, + 'callback' => array( $this, 'update_item' ), + 'permission_callback' => array( $this, 'update_item_permissions_check' ), + 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), + ), + array( + 'methods' => WP_REST_Server::DELETABLE, + 'callback' => array( $this, 'delete_item' ), + 'permission_callback' => array( $this, 'delete_item_permissions_check' ), + 'args' => array( + 'force' => array( + 'type' => 'boolean', + 'default' => false, + 'description' => __( 'Required to be true, as terms do not support trashing.' ), + ), + ), + ), + 'schema' => array( $this, 'get_public_item_schema' ), + ) + ); } /** @@ -235,7 +239,7 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { */ $prepared_args = apply_filters( "rest_{$this->taxonomy}_query", $prepared_args, $request ); - if ( ! empty( $prepared_args['post'] ) ) { + if ( ! empty( $prepared_args['post'] ) ) { $query_result = wp_get_object_terms( $prepared_args['post'], $this->taxonomy, $prepared_args ); // Used when calling wp_count_terms() below. @@ -258,7 +262,7 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { $response = array(); foreach ( $query_result as $term ) { - $data = $this->prepare_item_for_response( $term, $request ); + $data = $this->prepare_item_for_response( $term, $request ); $response[] = $this->prepare_response_for_collection( $data ); } @@ -601,7 +605,12 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { } $response = new WP_REST_Response(); - $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) ); + $response->set_data( + array( + 'deleted' => true, + 'previous' => $previous->get_data(), + ) + ); /** * Fires after a single term is deleted via the REST API. @@ -754,7 +763,7 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { * @return array Links for the given term. */ protected function prepare_links( $term ) { - $base = $this->namespace . '/' . $this->rest_base; + $base = $this->namespace . '/' . $this->rest_base; $links = array( 'self' => array( 'href' => rest_url( trailingslashit( $base ) . $term->term_id ), @@ -793,7 +802,7 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { continue; } - $rest_base = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name; + $rest_base = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name; $post_type_links[] = array( 'href' => add_query_arg( $this->rest_base, $term->term_id, rest_url( sprintf( 'wp/v2/%s', $rest_base ) ) ), ); @@ -820,52 +829,52 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { 'type' => 'object', 'properties' => array( 'id' => array( - 'description' => __( 'Unique identifier for the term.' ), - 'type' => 'integer', - 'context' => array( 'view', 'embed', 'edit' ), - 'readonly' => true, + 'description' => __( 'Unique identifier for the term.' ), + 'type' => 'integer', + 'context' => array( 'view', 'embed', 'edit' ), + 'readonly' => true, ), 'count' => array( - 'description' => __( 'Number of published posts for the term.' ), - 'type' => 'integer', - 'context' => array( 'view', 'edit' ), - 'readonly' => true, + 'description' => __( 'Number of published posts for the term.' ), + 'type' => 'integer', + 'context' => array( 'view', 'edit' ), + 'readonly' => true, ), 'description' => array( - 'description' => __( 'HTML description of the term.' ), - 'type' => 'string', - 'context' => array( 'view', 'edit' ), + 'description' => __( 'HTML description of the term.' ), + 'type' => 'string', + 'context' => array( 'view', 'edit' ), ), 'link' => array( - 'description' => __( 'URL of the term.' ), - 'type' => 'string', - 'format' => 'uri', - 'context' => array( 'view', 'embed', 'edit' ), - 'readonly' => true, + 'description' => __( 'URL of the term.' ), + 'type' => 'string', + 'format' => 'uri', + 'context' => array( 'view', 'embed', 'edit' ), + 'readonly' => true, ), 'name' => array( - 'description' => __( 'HTML title for the term.' ), - 'type' => 'string', - 'context' => array( 'view', 'embed', 'edit' ), - 'arg_options' => array( + 'description' => __( 'HTML title for the term.' ), + 'type' => 'string', + 'context' => array( 'view', 'embed', 'edit' ), + 'arg_options' => array( 'sanitize_callback' => 'sanitize_text_field', ), - 'required' => true, + 'required' => true, ), 'slug' => array( - 'description' => __( 'An alphanumeric identifier for the term unique to its type.' ), - 'type' => 'string', - 'context' => array( 'view', 'embed', 'edit' ), - 'arg_options' => array( + 'description' => __( 'An alphanumeric identifier for the term unique to its type.' ), + 'type' => 'string', + 'context' => array( 'view', 'embed', 'edit' ), + 'arg_options' => array( 'sanitize_callback' => array( $this, 'sanitize_slug' ), ), ), 'taxonomy' => array( - 'description' => __( 'Type attribution for the term.' ), - 'type' => 'string', - 'enum' => array_keys( get_taxonomies() ), - 'context' => array( 'view', 'embed', 'edit' ), - 'readonly' => true, + 'description' => __( 'Type attribution for the term.' ), + 'type' => 'string', + 'enum' => array_keys( get_taxonomies() ), + 'context' => array( 'view', 'embed', 'edit' ), + 'readonly' => true, ), ), ); @@ -874,9 +883,9 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { if ( $taxonomy->hierarchical ) { $schema['properties']['parent'] = array( - 'description' => __( 'The parent term ID.' ), - 'type' => 'integer', - 'context' => array( 'view', 'edit' ), + 'description' => __( 'The parent term ID.' ), + 'type' => 'integer', + 'context' => array( 'view', 'edit' ), ); } @@ -894,50 +903,50 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { */ public function get_collection_params() { $query_params = parent::get_collection_params(); - $taxonomy = get_taxonomy( $this->taxonomy ); + $taxonomy = get_taxonomy( $this->taxonomy ); $query_params['context']['default'] = 'view'; $query_params['exclude'] = array( - 'description' => __( 'Ensure result set excludes specific IDs.' ), - 'type' => 'array', - 'items' => array( - 'type' => 'integer', + 'description' => __( 'Ensure result set excludes specific IDs.' ), + 'type' => 'array', + 'items' => array( + 'type' => 'integer', ), - 'default' => array(), + 'default' => array(), ); $query_params['include'] = array( - 'description' => __( 'Limit result set to specific IDs.' ), - 'type' => 'array', - 'items' => array( - 'type' => 'integer', + 'description' => __( 'Limit result set to specific IDs.' ), + 'type' => 'array', + 'items' => array( + 'type' => 'integer', ), - 'default' => array(), + 'default' => array(), ); if ( ! $taxonomy->hierarchical ) { $query_params['offset'] = array( - 'description' => __( 'Offset the result set by a specific number of items.' ), - 'type' => 'integer', + 'description' => __( 'Offset the result set by a specific number of items.' ), + 'type' => 'integer', ); } $query_params['order'] = array( - 'description' => __( 'Order sort attribute ascending or descending.' ), - 'type' => 'string', - 'default' => 'asc', - 'enum' => array( + 'description' => __( 'Order sort attribute ascending or descending.' ), + 'type' => 'string', + 'default' => 'asc', + 'enum' => array( 'asc', 'desc', ), ); $query_params['orderby'] = array( - 'description' => __( 'Sort collection by term attribute.' ), - 'type' => 'string', - 'default' => 'name', - 'enum' => array( + 'description' => __( 'Sort collection by term attribute.' ), + 'type' => 'string', + 'default' => 'name', + 'enum' => array( 'id', 'include', 'name', @@ -950,29 +959,29 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { ); $query_params['hide_empty'] = array( - 'description' => __( 'Whether to hide terms not assigned to any posts.' ), - 'type' => 'boolean', - 'default' => false, + 'description' => __( 'Whether to hide terms not assigned to any posts.' ), + 'type' => 'boolean', + 'default' => false, ); if ( $taxonomy->hierarchical ) { $query_params['parent'] = array( - 'description' => __( 'Limit result set to terms assigned to a specific parent.' ), - 'type' => 'integer', + 'description' => __( 'Limit result set to terms assigned to a specific parent.' ), + 'type' => 'integer', ); } $query_params['post'] = array( - 'description' => __( 'Limit result set to terms assigned to a specific post.' ), - 'type' => 'integer', - 'default' => null, + 'description' => __( 'Limit result set to terms assigned to a specific post.' ), + 'type' => 'integer', + 'default' => null, ); $query_params['slug'] = array( - 'description' => __( 'Limit result set to terms with one or more specific slugs.' ), - 'type' => 'array', - 'items' => array( - 'type' => 'string' + 'description' => __( 'Limit result set to terms with one or more specific slugs.' ), + 'type' => 'array', + 'items' => array( + 'type' => 'string', ), ); diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php index c7c32a73db..e741b2149d 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php @@ -45,98 +45,104 @@ class WP_REST_Users_Controller extends WP_REST_Controller { */ public function register_routes() { - register_rest_route( $this->namespace, '/' . $this->rest_base, array( - array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_items' ), - 'permission_callback' => array( $this, 'get_items_permissions_check' ), - 'args' => $this->get_collection_params(), - ), - array( - 'methods' => WP_REST_Server::CREATABLE, - 'callback' => array( $this, 'create_item' ), - 'permission_callback' => array( $this, 'create_item_permissions_check' ), - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), - ), - 'schema' => array( $this, 'get_public_item_schema' ), - ) ); + register_rest_route( + $this->namespace, '/' . $this->rest_base, array( + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_items' ), + 'permission_callback' => array( $this, 'get_items_permissions_check' ), + 'args' => $this->get_collection_params(), + ), + array( + 'methods' => WP_REST_Server::CREATABLE, + 'callback' => array( $this, 'create_item' ), + 'permission_callback' => array( $this, 'create_item_permissions_check' ), + 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), + ), + 'schema' => array( $this, 'get_public_item_schema' ), + ) + ); - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P[\d]+)', array( - 'args' => array( - 'id' => array( - 'description' => __( 'Unique identifier for the user.' ), - 'type' => 'integer', - ), - ), - array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_item' ), - 'permission_callback' => array( $this, 'get_item_permissions_check' ), - 'args' => array( - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), - ), - ), - array( - 'methods' => WP_REST_Server::EDITABLE, - 'callback' => array( $this, 'update_item' ), - 'permission_callback' => array( $this, 'update_item_permissions_check' ), - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), - ), - array( - 'methods' => WP_REST_Server::DELETABLE, - 'callback' => array( $this, 'delete_item' ), - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), - 'args' => array( - 'force' => array( - 'type' => 'boolean', - 'default' => false, - 'description' => __( 'Required to be true, as users do not support trashing.' ), - ), - 'reassign' => array( + register_rest_route( + $this->namespace, '/' . $this->rest_base . '/(?P[\d]+)', array( + 'args' => array( + 'id' => array( + 'description' => __( 'Unique identifier for the user.' ), 'type' => 'integer', - 'description' => __( 'Reassign the deleted user\'s posts and links to this user ID.' ), - 'required' => true, - 'sanitize_callback' => array( $this, 'check_reassign' ), ), ), - ), - 'schema' => array( $this, 'get_public_item_schema' ), - ) ); + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_item' ), + 'permission_callback' => array( $this, 'get_item_permissions_check' ), + 'args' => array( + 'context' => $this->get_context_param( array( 'default' => 'view' ) ), + ), + ), + array( + 'methods' => WP_REST_Server::EDITABLE, + 'callback' => array( $this, 'update_item' ), + 'permission_callback' => array( $this, 'update_item_permissions_check' ), + 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), + ), + array( + 'methods' => WP_REST_Server::DELETABLE, + 'callback' => array( $this, 'delete_item' ), + 'permission_callback' => array( $this, 'delete_item_permissions_check' ), + 'args' => array( + 'force' => array( + 'type' => 'boolean', + 'default' => false, + 'description' => __( 'Required to be true, as users do not support trashing.' ), + ), + 'reassign' => array( + 'type' => 'integer', + 'description' => __( 'Reassign the deleted user\'s posts and links to this user ID.' ), + 'required' => true, + 'sanitize_callback' => array( $this, 'check_reassign' ), + ), + ), + ), + 'schema' => array( $this, 'get_public_item_schema' ), + ) + ); - register_rest_route( $this->namespace, '/' . $this->rest_base . '/me', array( - array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_current_item' ), - 'args' => array( - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), - ), - ), - array( - 'methods' => WP_REST_Server::EDITABLE, - 'callback' => array( $this, 'update_current_item' ), - 'permission_callback' => array( $this, 'update_current_item_permissions_check' ), - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), - ), - array( - 'methods' => WP_REST_Server::DELETABLE, - 'callback' => array( $this, 'delete_current_item' ), - 'permission_callback' => array( $this, 'delete_current_item_permissions_check' ), - 'args' => array( - 'force' => array( - 'type' => 'boolean', - 'default' => false, - 'description' => __( 'Required to be true, as users do not support trashing.' ), - ), - 'reassign' => array( - 'type' => 'integer', - 'description' => __( 'Reassign the deleted user\'s posts and links to this user ID.' ), - 'required' => true, - 'sanitize_callback' => array( $this, 'check_reassign' ), + register_rest_route( + $this->namespace, '/' . $this->rest_base . '/me', array( + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_current_item' ), + 'args' => array( + 'context' => $this->get_context_param( array( 'default' => 'view' ) ), ), ), - ), - 'schema' => array( $this, 'get_public_item_schema' ), - )); + array( + 'methods' => WP_REST_Server::EDITABLE, + 'callback' => array( $this, 'update_current_item' ), + 'permission_callback' => array( $this, 'update_current_item_permissions_check' ), + 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), + ), + array( + 'methods' => WP_REST_Server::DELETABLE, + 'callback' => array( $this, 'delete_current_item' ), + 'permission_callback' => array( $this, 'delete_current_item_permissions_check' ), + 'args' => array( + 'force' => array( + 'type' => 'boolean', + 'default' => false, + 'description' => __( 'Required to be true, as users do not support trashing.' ), + ), + 'reassign' => array( + 'type' => 'integer', + 'description' => __( 'Reassign the deleted user\'s posts and links to this user ID.' ), + 'required' => true, + 'sanitize_callback' => array( $this, 'check_reassign' ), + ), + ), + ), + 'schema' => array( $this, 'get_public_item_schema' ), + ) + ); } /** @@ -233,11 +239,11 @@ class WP_REST_Users_Controller extends WP_REST_Controller { if ( isset( $registered['offset'] ) && ! empty( $request['offset'] ) ) { $prepared_args['offset'] = $request['offset']; } else { - $prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number']; + $prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number']; } if ( isset( $registered['orderby'] ) ) { - $orderby_possibles = array( + $orderby_possibles = array( 'id' => 'ID', 'include' => 'include', 'name' => 'display_name', @@ -274,7 +280,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller { $users = array(); foreach ( $query->results as $user ) { - $data = $this->prepare_item_for_response( $user, $request ); + $data = $this->prepare_item_for_response( $user, $request ); $users[] = $this->prepare_response_for_collection( $data ); } @@ -391,7 +397,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller { return $user; } - $user = $this->prepare_item_for_response( $user, $request ); + $user = $this->prepare_item_for_response( $user, $request ); $response = rest_ensure_response( $user ); return $response; @@ -416,7 +422,6 @@ class WP_REST_Users_Controller extends WP_REST_Controller { $response = $this->prepare_item_for_response( $user, $request ); $response = rest_ensure_response( $response ); - return $response; } @@ -493,7 +498,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller { return $user_id; } - $result= add_user_to_blog( get_site()->id, $user_id, '' ); + $result = add_user_to_blog( get_site()->id, $user_id, '' ); if ( is_wp_error( $result ) ) { return $result; } @@ -530,7 +535,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller { } } - $user = get_user_by( 'id', $user_id ); + $user = get_user_by( 'id', $user_id ); $fields_update = $this->update_additional_fields_for_object( $user, $request ); if ( is_wp_error( $fields_update ) ) { @@ -653,7 +658,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller { } } - $user = get_user_by( 'id', $user_id ); + $user = get_user_by( 'id', $user_id ); $fields_update = $this->update_additional_fields_for_object( $user, $request ); if ( is_wp_error( $fields_update ) ) { @@ -765,7 +770,12 @@ class WP_REST_Users_Controller extends WP_REST_Controller { } $response = new WP_REST_Response(); - $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) ); + $response->set_data( + array( + 'deleted' => true, + 'previous' => $previous->get_data(), + ) + ); /** * Fires immediately after a user is deleted via the REST API. @@ -928,7 +938,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller { */ protected function prepare_links( $user ) { $links = array( - 'self' => array( + 'self' => array( 'href' => rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $user->ID ) ), ), 'collection' => array( @@ -1114,7 +1124,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller { return new WP_Error( 'rest_user_invalid_password', __( 'Passwords cannot be empty.' ), array( 'status' => 400 ) ); } - if ( false !== strpos( $password, "\\" ) ) { + if ( false !== strpos( $password, '\\' ) ) { return new WP_Error( 'rest_user_invalid_password', __( 'Passwords cannot contain the "\\" character.' ), array( 'status' => 400 ) ); } @@ -1134,13 +1144,13 @@ class WP_REST_Users_Controller extends WP_REST_Controller { 'title' => 'user', 'type' => 'object', 'properties' => array( - 'id' => array( + 'id' => array( 'description' => __( 'Unique identifier for the user.' ), 'type' => 'integer', 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), - 'username' => array( + 'username' => array( 'description' => __( 'Login name for the user.' ), 'type' => 'string', 'context' => array( 'edit' ), @@ -1149,7 +1159,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller { 'sanitize_callback' => array( $this, 'check_username' ), ), ), - 'name' => array( + 'name' => array( 'description' => __( 'Display name for the user.' ), 'type' => 'string', 'context' => array( 'embed', 'view', 'edit' ), @@ -1157,7 +1167,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller { 'sanitize_callback' => 'sanitize_text_field', ), ), - 'first_name' => array( + 'first_name' => array( 'description' => __( 'First name for the user.' ), 'type' => 'string', 'context' => array( 'edit' ), @@ -1165,7 +1175,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller { 'sanitize_callback' => 'sanitize_text_field', ), ), - 'last_name' => array( + 'last_name' => array( 'description' => __( 'Last name for the user.' ), 'type' => 'string', 'context' => array( 'edit' ), @@ -1173,38 +1183,38 @@ class WP_REST_Users_Controller extends WP_REST_Controller { 'sanitize_callback' => 'sanitize_text_field', ), ), - 'email' => array( + 'email' => array( 'description' => __( 'The email address for the user.' ), 'type' => 'string', 'format' => 'email', 'context' => array( 'edit' ), 'required' => true, ), - 'url' => array( + 'url' => array( 'description' => __( 'URL of the user.' ), 'type' => 'string', 'format' => 'uri', 'context' => array( 'embed', 'view', 'edit' ), ), - 'description' => array( + 'description' => array( 'description' => __( 'Description of the user.' ), 'type' => 'string', 'context' => array( 'embed', 'view', 'edit' ), ), - 'link' => array( + 'link' => array( 'description' => __( 'Author URL of the user.' ), 'type' => 'string', 'format' => 'uri', 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), - 'locale' => array( + 'locale' => array( 'description' => __( 'Locale for the user.' ), 'type' => 'string', 'enum' => array_merge( array( '', 'en_US' ), get_available_languages() ), 'context' => array( 'edit' ), ), - 'nickname' => array( + 'nickname' => array( 'description' => __( 'The nickname for the user.' ), 'type' => 'string', 'context' => array( 'edit' ), @@ -1212,7 +1222,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller { 'sanitize_callback' => 'sanitize_text_field', ), ), - 'slug' => array( + 'slug' => array( 'description' => __( 'An alphanumeric identifier for the user.' ), 'type' => 'string', 'context' => array( 'embed', 'view', 'edit' ), @@ -1220,22 +1230,22 @@ class WP_REST_Users_Controller extends WP_REST_Controller { 'sanitize_callback' => array( $this, 'sanitize_slug' ), ), ), - 'registered_date' => array( + 'registered_date' => array( 'description' => __( 'Registration date for the user.' ), 'type' => 'string', 'format' => 'date-time', 'context' => array( 'edit' ), 'readonly' => true, ), - 'roles' => array( + 'roles' => array( 'description' => __( 'Roles assigned to the user.' ), 'type' => 'array', 'items' => array( - 'type' => 'string', + 'type' => 'string', ), 'context' => array( 'edit' ), ), - 'password' => array( + 'password' => array( 'description' => __( 'Password for the user (never included).' ), 'type' => 'string', 'context' => array(), // Password is never displayed. @@ -1244,7 +1254,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller { 'sanitize_callback' => array( $this, 'check_user_password' ), ), ), - 'capabilities' => array( + 'capabilities' => array( 'description' => __( 'All capabilities assigned to the user.' ), 'type' => 'object', 'context' => array( 'edit' ), @@ -1274,7 +1284,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller { ); } - $schema['properties']['avatar_urls'] = array( + $schema['properties']['avatar_urls'] = array( 'description' => __( 'Avatar URLs for the user.' ), 'type' => 'object', 'context' => array( 'embed', 'view', 'edit' ), @@ -1301,39 +1311,39 @@ class WP_REST_Users_Controller extends WP_REST_Controller { $query_params['context']['default'] = 'view'; $query_params['exclude'] = array( - 'description' => __( 'Ensure result set excludes specific IDs.' ), - 'type' => 'array', - 'items' => array( - 'type' => 'integer', + 'description' => __( 'Ensure result set excludes specific IDs.' ), + 'type' => 'array', + 'items' => array( + 'type' => 'integer', ), - 'default' => array(), + 'default' => array(), ); $query_params['include'] = array( - 'description' => __( 'Limit result set to specific IDs.' ), - 'type' => 'array', - 'items' => array( - 'type' => 'integer', + 'description' => __( 'Limit result set to specific IDs.' ), + 'type' => 'array', + 'items' => array( + 'type' => 'integer', ), - 'default' => array(), + 'default' => array(), ); $query_params['offset'] = array( - 'description' => __( 'Offset the result set by a specific number of items.' ), - 'type' => 'integer', + 'description' => __( 'Offset the result set by a specific number of items.' ), + 'type' => 'integer', ); $query_params['order'] = array( - 'default' => 'asc', - 'description' => __( 'Order sort attribute ascending or descending.' ), - 'enum' => array( 'asc', 'desc' ), - 'type' => 'string', + 'default' => 'asc', + 'description' => __( 'Order sort attribute ascending or descending.' ), + 'enum' => array( 'asc', 'desc' ), + 'type' => 'string', ); $query_params['orderby'] = array( - 'default' => 'name', - 'description' => __( 'Sort collection by object attribute.' ), - 'enum' => array( + 'default' => 'name', + 'description' => __( 'Sort collection by object attribute.' ), + 'enum' => array( 'id', 'include', 'name', @@ -1343,22 +1353,22 @@ class WP_REST_Users_Controller extends WP_REST_Controller { 'email', 'url', ), - 'type' => 'string', + 'type' => 'string', ); - $query_params['slug'] = array( - 'description' => __( 'Limit result set to users with one or more specific slugs.' ), - 'type' => 'array', - 'items' => array( - 'type' => 'string', + $query_params['slug'] = array( + 'description' => __( 'Limit result set to users with one or more specific slugs.' ), + 'type' => 'array', + 'items' => array( + 'type' => 'string', ), ); - $query_params['roles'] = array( - 'description' => __( 'Limit result set to users matching at least one specific role provided. Accepts csv list or single role.' ), - 'type' => 'array', - 'items' => array( - 'type' => 'string', + $query_params['roles'] = array( + 'description' => __( 'Limit result set to users matching at least one specific role provided. Accepts csv list or single role.' ), + 'type' => 'array', + 'items' => array( + 'type' => 'string', ), ); diff --git a/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php b/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php index 9288c0a284..e0b41440a9 100644 --- a/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php +++ b/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php @@ -41,11 +41,13 @@ abstract class WP_REST_Meta_Fields { * @see register_rest_field() */ public function register_field() { - register_rest_field( $this->get_rest_field_type(), 'meta', array( - 'get_callback' => array( $this, 'get_value' ), - 'update_callback' => array( $this, 'update_value' ), - 'schema' => $this->get_field_schema(), - )); + register_rest_field( + $this->get_rest_field_type(), 'meta', array( + 'get_callback' => array( $this, 'get_value' ), + 'update_callback' => array( $this, 'update_value' ), + 'schema' => $this->get_field_schema(), + ) + ); } /** @@ -62,7 +64,7 @@ abstract class WP_REST_Meta_Fields { $response = array(); foreach ( $fields as $meta_key => $args ) { - $name = $args['name']; + $name = $args['name']; $all_values = get_metadata( $this->get_meta_type(), $object_id, $meta_key, false ); if ( $args['single'] ) { if ( empty( $all_values ) ) { @@ -174,7 +176,10 @@ abstract class WP_REST_Meta_Fields { 'rest_cannot_delete', /* translators: %s: custom field key */ sprintf( __( 'Sorry, you are not allowed to edit the %s custom field.' ), $name ), - array( 'key' => $name, 'status' => rest_authorization_required_code() ) + array( + 'key' => $name, + 'status' => rest_authorization_required_code(), + ) ); } @@ -182,7 +187,10 @@ abstract class WP_REST_Meta_Fields { return new WP_Error( 'rest_meta_database_error', __( 'Could not delete meta value from database.' ), - array( 'key' => $name, 'status' => WP_Http::INTERNAL_SERVER_ERROR ) + array( + 'key' => $name, + 'status' => WP_Http::INTERNAL_SERVER_ERROR, + ) ); } @@ -209,7 +217,10 @@ abstract class WP_REST_Meta_Fields { 'rest_cannot_update', /* translators: %s: custom field key */ sprintf( __( 'Sorry, you are not allowed to edit the %s custom field.' ), $name ), - array( 'key' => $name, 'status' => rest_authorization_required_code() ) + array( + 'key' => $name, + 'status' => rest_authorization_required_code(), + ) ); } @@ -244,7 +255,10 @@ abstract class WP_REST_Meta_Fields { return new WP_Error( 'rest_meta_database_error', __( 'Could not update meta value in database.' ), - array( 'key' => $name, 'status' => WP_Http::INTERNAL_SERVER_ERROR ) + array( + 'key' => $name, + 'status' => WP_Http::INTERNAL_SERVER_ERROR, + ) ); } } @@ -254,7 +268,10 @@ abstract class WP_REST_Meta_Fields { return new WP_Error( 'rest_meta_database_error', __( 'Could not update meta value in database.' ), - array( 'key' => $name, 'status' => WP_Http::INTERNAL_SERVER_ERROR ) + array( + 'key' => $name, + 'status' => WP_Http::INTERNAL_SERVER_ERROR, + ) ); } } @@ -275,12 +292,15 @@ abstract class WP_REST_Meta_Fields { */ protected function update_meta_value( $object_id, $meta_key, $name, $value ) { $meta_type = $this->get_meta_type(); - if ( ! current_user_can( "edit_{$meta_type}_meta", $object_id, $meta_key ) ) { + if ( ! current_user_can( "edit_{$meta_type}_meta", $object_id, $meta_key ) ) { return new WP_Error( 'rest_cannot_update', /* translators: %s: custom field key */ sprintf( __( 'Sorry, you are not allowed to edit the %s custom field.' ), $name ), - array( 'key' => $name, 'status' => rest_authorization_required_code() ) + array( + 'key' => $name, + 'status' => rest_authorization_required_code(), + ) ); } @@ -300,7 +320,10 @@ abstract class WP_REST_Meta_Fields { return new WP_Error( 'rest_meta_database_error', __( 'Could not update meta value in database.' ), - array( 'key' => $name, 'status' => WP_Http::INTERNAL_SERVER_ERROR ) + array( + 'key' => $name, + 'status' => WP_Http::INTERNAL_SERVER_ERROR, + ) ); } @@ -342,7 +365,7 @@ abstract class WP_REST_Meta_Fields { 'default' => isset( $args['default'] ) ? $args['default'] : null, ); - $rest_args = array_merge( $default_args, $rest_args ); + $rest_args = array_merge( $default_args, $rest_args ); $rest_args['schema'] = array_merge( $default_schema, $rest_args['schema'] ); $type = ! empty( $rest_args['type'] ) ? $rest_args['type'] : null; @@ -356,7 +379,7 @@ abstract class WP_REST_Meta_Fields { $rest_args['schema']['items'] = array( 'type' => $rest_args['type'], ); - $rest_args['schema']['type'] = 'array'; + $rest_args['schema']['type'] = 'array'; } $registered[ $name ] = $rest_args; diff --git a/wp-includes/revision.php b/wp-includes/revision.php index 136395e2f1..bc95631fb6 100644 --- a/wp-includes/revision.php +++ b/wp-includes/revision.php @@ -31,7 +31,7 @@ function _wp_post_revision_fields( $post = array(), $deprecated = false ) { if ( is_null( $fields ) ) { // Allow these to be versioned $fields = array( - 'post_title' => __( 'Title' ), + 'post_title' => __( 'Title' ), 'post_content' => __( 'Content' ), 'post_excerpt' => __( 'Excerpt' ), ); @@ -60,7 +60,6 @@ function _wp_post_revision_fields( $post = array(), $deprecated = false ) { unset( $fields[ $protect ] ); } - return $fields; } @@ -110,20 +109,25 @@ function _wp_post_revision_data( $post = array(), $autosave = false ) { * @return int|WP_Error|void Void or 0 if error, new revision ID, if success. */ function wp_save_post_revision( $post_id ) { - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return; + } - if ( ! $post = get_post( $post_id ) ) + if ( ! $post = get_post( $post_id ) ) { return; + } - if ( ! post_type_supports( $post->post_type, 'revisions' ) ) + if ( ! post_type_supports( $post->post_type, 'revisions' ) ) { return; + } - if ( 'auto-draft' == $post->post_status ) + if ( 'auto-draft' == $post->post_status ) { return; + } - if ( ! wp_revisions_enabled( $post ) ) + if ( ! wp_revisions_enabled( $post ) ) { return; + } // Compare the proposed update with the last stored revision verifying that // they are different, unless a plugin tells us to always save regardless. @@ -149,7 +153,6 @@ function wp_save_post_revision( $post_id ) { * Default true. * @param WP_Post $last_revision The last revision post object. * @param WP_Post $post The post object. - * */ if ( isset( $last_revision ) && apply_filters( 'wp_save_post_revision_check_for_changes', $check_for_changes = true, $last_revision, $post ) ) { $post_has_changed = false; @@ -172,7 +175,6 @@ function wp_save_post_revision( $post_id ) { * @param bool $post_has_changed Whether the post has changed. * @param WP_Post $last_revision The last revision post object. * @param WP_Post $post The post object. - * */ $post_has_changed = (bool) apply_filters( 'wp_save_post_revision_post_has_changed', $post_has_changed, $last_revision, $post ); @@ -189,21 +191,24 @@ function wp_save_post_revision( $post_id ) { // delete the oldest ones. $revisions_to_keep = wp_revisions_to_keep( $post ); - if ( $revisions_to_keep < 0 ) + if ( $revisions_to_keep < 0 ) { return $return; + } $revisions = wp_get_post_revisions( $post_id, array( 'order' => 'ASC' ) ); - $delete = count($revisions) - $revisions_to_keep; + $delete = count( $revisions ) - $revisions_to_keep; - if ( $delete < 1 ) + if ( $delete < 1 ) { return $return; + } $revisions = array_slice( $revisions, 0, $delete ); - for ( $i = 0; isset( $revisions[$i] ); $i++ ) { - if ( false !== strpos( $revisions[ $i ]->post_name, 'autosave' ) ) + for ( $i = 0; isset( $revisions[ $i ] ); $i++ ) { + if ( false !== strpos( $revisions[ $i ]->post_name, 'autosave' ) ) { continue; + } wp_delete_post_revision( $revisions[ $i ]->ID ); } @@ -229,8 +234,9 @@ function wp_get_post_autosave( $post_id, $user_id = 0 ) { foreach ( $revisions as $revision ) { if ( false !== strpos( $revision->post_name, "{$post_id}-autosave" ) ) { - if ( $user_id && $user_id != $revision->post_author ) + if ( $user_id && $user_id != $revision->post_author ) { continue; + } return $revision; } @@ -248,8 +254,9 @@ function wp_get_post_autosave( $post_id, $user_id = 0 ) { * @return false|int False if not a revision, ID of revision's parent otherwise. */ function wp_is_post_revision( $post ) { - if ( !$post = wp_get_post_revision( $post ) ) + if ( ! $post = wp_get_post_revision( $post ) ) { return false; + } return (int) $post->post_parent; } @@ -263,11 +270,13 @@ function wp_is_post_revision( $post ) { * @return false|int False if not a revision, ID of autosave's parent otherwise */ function wp_is_post_autosave( $post ) { - if ( !$post = wp_get_post_revision( $post ) ) + if ( ! $post = wp_get_post_revision( $post ) ) { return false; + } - if ( false !== strpos( $post->post_name, "{$post->post_parent}-autosave" ) ) + if ( false !== strpos( $post->post_name, "{$post->post_parent}-autosave" ) ) { return (int) $post->post_parent; + } return false; } @@ -283,23 +292,27 @@ function wp_is_post_autosave( $post ) { * @return int|WP_Error WP_Error or 0 if error, new revision ID if success. */ function _wp_put_post_revision( $post = null, $autosave = false ) { - if ( is_object($post) ) + if ( is_object( $post ) ) { $post = get_object_vars( $post ); - elseif ( !is_array($post) ) - $post = get_post($post, ARRAY_A); + } elseif ( ! is_array( $post ) ) { + $post = get_post( $post, ARRAY_A ); + } - if ( ! $post || empty($post['ID']) ) + if ( ! $post || empty( $post['ID'] ) ) { return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) ); + } - if ( isset($post['post_type']) && 'revision' == $post['post_type'] ) + if ( isset( $post['post_type'] ) && 'revision' == $post['post_type'] ) { return new WP_Error( 'post_type', __( 'Cannot create a revision of a revision' ) ); + } $post = _wp_post_revision_data( $post, $autosave ); - $post = wp_slash($post); //since data is from db + $post = wp_slash( $post ); //since data is from db $revision_id = wp_insert_post( $post ); - if ( is_wp_error($revision_id) ) + if ( is_wp_error( $revision_id ) ) { return $revision_id; + } if ( $revision_id ) { /** @@ -326,19 +339,21 @@ function _wp_put_post_revision( $post = null, $autosave = false ) { * @param string $filter Optional sanitation filter. See sanitize_post(). * @return WP_Post|array|null WP_Post (or array) on success, or null on failure. */ -function wp_get_post_revision(&$post, $output = OBJECT, $filter = 'raw') { - if ( !$revision = get_post( $post, OBJECT, $filter ) ) +function wp_get_post_revision( &$post, $output = OBJECT, $filter = 'raw' ) { + if ( ! $revision = get_post( $post, OBJECT, $filter ) ) { return $revision; - if ( 'revision' !== $revision->post_type ) + } + if ( 'revision' !== $revision->post_type ) { return null; + } if ( $output == OBJECT ) { return $revision; } elseif ( $output == ARRAY_A ) { - $_revision = get_object_vars($revision); + $_revision = get_object_vars( $revision ); return $_revision; } elseif ( $output == ARRAY_N ) { - $_revision = array_values(get_object_vars($revision)); + $_revision = array_values( get_object_vars( $revision ) ); return $_revision; } @@ -357,27 +372,31 @@ function wp_get_post_revision(&$post, $output = OBJECT, $filter = 'raw') { * @return int|false|null Null if error, false if no fields to restore, (int) post ID if success. */ function wp_restore_post_revision( $revision_id, $fields = null ) { - if ( !$revision = wp_get_post_revision( $revision_id, ARRAY_A ) ) + if ( ! $revision = wp_get_post_revision( $revision_id, ARRAY_A ) ) { return $revision; + } - if ( !is_array( $fields ) ) + if ( ! is_array( $fields ) ) { $fields = array_keys( _wp_post_revision_fields( $revision ) ); + } $update = array(); foreach ( array_intersect( array_keys( $revision ), $fields ) as $field ) { - $update[$field] = $revision[$field]; + $update[ $field ] = $revision[ $field ]; } - if ( !$update ) + if ( ! $update ) { return false; + } $update['ID'] = $revision['post_parent']; $update = wp_slash( $update ); //since data is from db $post_id = wp_update_post( $update ); - if ( ! $post_id || is_wp_error( $post_id ) ) + if ( ! $post_id || is_wp_error( $post_id ) ) { return $post_id; + } // Update last edit user update_post_meta( $post_id, '_edit_last', get_current_user_id() ); @@ -439,19 +458,32 @@ function wp_delete_post_revision( $revision_id ) { */ function wp_get_post_revisions( $post_id = 0, $args = null ) { $post = get_post( $post_id ); - if ( ! $post || empty( $post->ID ) ) + if ( ! $post || empty( $post->ID ) ) { return array(); + } - $defaults = array( 'order' => 'DESC', 'orderby' => 'date ID', 'check_enabled' => true ); - $args = wp_parse_args( $args, $defaults ); + $defaults = array( + 'order' => 'DESC', + 'orderby' => 'date ID', + 'check_enabled' => true, + ); + $args = wp_parse_args( $args, $defaults ); - if ( $args['check_enabled'] && ! wp_revisions_enabled( $post ) ) + if ( $args['check_enabled'] && ! wp_revisions_enabled( $post ) ) { return array(); + } - $args = array_merge( $args, array( 'post_parent' => $post->ID, 'post_type' => 'revision', 'post_status' => 'inherit' ) ); + $args = array_merge( + $args, array( + 'post_parent' => $post->ID, + 'post_type' => 'revision', + 'post_status' => 'inherit', + ) + ); - if ( ! $revisions = get_children( $args ) ) + if ( ! $revisions = get_children( $args ) ) { return array(); + } return $revisions; } @@ -484,13 +516,15 @@ function wp_revisions_enabled( $post ) { function wp_revisions_to_keep( $post ) { $num = WP_POST_REVISIONS; - if ( true === $num ) + if ( true === $num ) { $num = -1; - else + } else { $num = intval( $num ); + } - if ( ! post_type_supports( $post->post_type, 'revisions' ) ) + if ( ! post_type_supports( $post->post_type, 'revisions' ) ) { $num = 0; + } /** * Filters the number of revisions to save for the given post. @@ -527,7 +561,7 @@ function _set_preview( $post ) { $preview = sanitize_post( $preview ); $post->post_content = $preview->post_content; - $post->post_title = $preview->post_title; + $post->post_title = $preview->post_title; $post->post_excerpt = $preview->post_excerpt; add_filter( 'get_the_terms', '_wp_preview_terms_filter', 10, 3 ); @@ -543,13 +577,14 @@ function _set_preview( $post ) { * @access private */ function _show_post_preview() { - if ( isset($_GET['preview_id']) && isset($_GET['preview_nonce']) ) { + if ( isset( $_GET['preview_id'] ) && isset( $_GET['preview_nonce'] ) ) { $id = (int) $_GET['preview_id']; - if ( false === wp_verify_nonce( $_GET['preview_nonce'], 'post_preview_' . $id ) ) - wp_die( __('Sorry, you are not allowed to preview drafts.') ); + if ( false === wp_verify_nonce( $_GET['preview_nonce'], 'post_preview_' . $id ) ) { + wp_die( __( 'Sorry, you are not allowed to preview drafts.' ) ); + } - add_filter('the_preview', '_set_preview'); + add_filter( 'the_preview', '_set_preview' ); } } @@ -565,16 +600,19 @@ function _show_post_preview() { * @return array */ function _wp_preview_terms_filter( $terms, $post_id, $taxonomy ) { - if ( ! $post = get_post() ) + if ( ! $post = get_post() ) { return $terms; + } - if ( empty( $_REQUEST['post_format'] ) || $post->ID != $post_id || 'post_format' != $taxonomy || 'revision' == $post->post_type ) + if ( empty( $_REQUEST['post_format'] ) || $post->ID != $post_id || 'post_format' != $taxonomy || 'revision' == $post->post_type ) { return $terms; + } - if ( 'standard' == $_REQUEST['post_format'] ) + if ( 'standard' == $_REQUEST['post_format'] ) { $terms = array(); - elseif ( $term = get_term_by( 'slug', 'post-format-' . sanitize_key( $_REQUEST['post_format'] ), 'post_format' ) ) + } elseif ( $term = get_term_by( 'slug', 'post-format-' . sanitize_key( $_REQUEST['post_format'] ), 'post_format' ) ) { $terms = array( $term ); // Can only have one post format + } return $terms; } @@ -623,13 +661,15 @@ function _wp_preview_post_thumbnail_filter( $value, $post_id, $meta_key ) { * @return int|false */ function _wp_get_post_revision_version( $revision ) { - if ( is_object( $revision ) ) + if ( is_object( $revision ) ) { $revision = get_object_vars( $revision ); - elseif ( !is_array( $revision ) ) + } elseif ( ! is_array( $revision ) ) { return false; + } - if ( preg_match( '/^\d+-(?:autosave|revision)-v(\d+)$/', $revision['post_name'], $matches ) ) + if ( preg_match( '/^\d+-(?:autosave|revision)-v(\d+)$/', $revision['post_name'], $matches ) ) { return (int) $matches[1]; + } return 0; } @@ -650,8 +690,8 @@ function _wp_upgrade_revisions_of_post( $post, $revisions ) { global $wpdb; // Add post option exclusively - $lock = "revision-upgrade-{$post->ID}"; - $now = time(); + $lock = "revision-upgrade-{$post->ID}"; + $now = time(); $result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, 'no') /* LOCK */", $lock, $now ) ); if ( ! $result ) { // If we couldn't get a lock, see how old the previous lock is @@ -683,8 +723,9 @@ function _wp_upgrade_revisions_of_post( $post, $revisions ) { $this_revision_version = _wp_get_post_revision_version( $this_revision ); // Something terrible happened - if ( false === $this_revision_version ) + if ( false === $this_revision_version ) { continue; + } // 1 is the latest revision version, so we're already up to date. // No need to add a copy of the post as latest revision. @@ -705,23 +746,25 @@ function _wp_upgrade_revisions_of_post( $post, $revisions ) { $prev_revision_version = _wp_get_post_revision_version( $prev_revision ); // If the previous revision is already up to date, it no longer has the information we need :( - if ( $prev_revision_version < 1 ) + if ( $prev_revision_version < 1 ) { $update['post_author'] = $prev_revision->post_author; + } } // Upgrade this revision $result = $wpdb->update( $wpdb->posts, $update, array( 'ID' => $this_revision->ID ) ); - if ( $result ) + if ( $result ) { wp_cache_delete( $this_revision->ID, 'posts' ); - + } } while ( $prev_revision ); delete_option( $lock ); // Add a copy of the post as latest revision. - if ( $add_last ) + if ( $add_last ) { wp_save_post_revision( $post->ID ); + } return true; } diff --git a/wp-includes/rewrite.php b/wp-includes/rewrite.php index 943d7d0079..71a83ac3e9 100644 --- a/wp-includes/rewrite.php +++ b/wp-includes/rewrite.php @@ -11,98 +11,98 @@ * * @since 2.1.0 */ -define('EP_NONE', 0); +define( 'EP_NONE', 0 ); /** * Endpoint Mask for Permalink. * * @since 2.1.0 */ -define('EP_PERMALINK', 1); +define( 'EP_PERMALINK', 1 ); /** * Endpoint Mask for Attachment. * * @since 2.1.0 */ -define('EP_ATTACHMENT', 2); +define( 'EP_ATTACHMENT', 2 ); /** * Endpoint Mask for date. * * @since 2.1.0 */ -define('EP_DATE', 4); +define( 'EP_DATE', 4 ); /** * Endpoint Mask for year * * @since 2.1.0 */ -define('EP_YEAR', 8); +define( 'EP_YEAR', 8 ); /** * Endpoint Mask for month. * * @since 2.1.0 */ -define('EP_MONTH', 16); +define( 'EP_MONTH', 16 ); /** * Endpoint Mask for day. * * @since 2.1.0 */ -define('EP_DAY', 32); +define( 'EP_DAY', 32 ); /** * Endpoint Mask for root. * * @since 2.1.0 */ -define('EP_ROOT', 64); +define( 'EP_ROOT', 64 ); /** * Endpoint Mask for comments. * * @since 2.1.0 */ -define('EP_COMMENTS', 128); +define( 'EP_COMMENTS', 128 ); /** * Endpoint Mask for searches. * * @since 2.1.0 */ -define('EP_SEARCH', 256); +define( 'EP_SEARCH', 256 ); /** * Endpoint Mask for categories. * * @since 2.1.0 */ -define('EP_CATEGORIES', 512); +define( 'EP_CATEGORIES', 512 ); /** * Endpoint Mask for tags. * * @since 2.3.0 */ -define('EP_TAGS', 1024); +define( 'EP_TAGS', 1024 ); /** * Endpoint Mask for authors. * * @since 2.1.0 */ -define('EP_AUTHORS', 2048); +define( 'EP_AUTHORS', 2048 ); /** * Endpoint Mask for pages. * * @since 2.1.0 */ -define('EP_PAGES', 4096); +define( 'EP_PAGES', 4096 ); /** * Endpoint Mask for all archive views. @@ -158,8 +158,9 @@ function add_rewrite_rule( $regex, $query, $after = 'bottom' ) { */ function add_rewrite_tag( $tag, $regex, $query = '' ) { // validate the tag's name - if ( strlen( $tag ) < 3 || $tag[0] != '%' || $tag[ strlen($tag) - 1 ] != '%' ) + if ( strlen( $tag ) < 3 || $tag[0] != '%' || $tag[ strlen( $tag ) - 1 ] != '%' ) { return; + } global $wp_rewrite, $wp; @@ -203,10 +204,12 @@ function add_permastruct( $name, $struct, $args = array() ) { global $wp_rewrite; // Back-compat for the old parameters: $with_front and $ep_mask. - if ( ! is_array( $args ) ) + if ( ! is_array( $args ) ) { $args = array( 'with_front' => $args ); - if ( func_num_args() == 4 ) + } + if ( func_num_args() == 4 ) { $args['ep_mask'] = func_get_arg( 3 ); + } $wp_rewrite->add_permastruct( $name, $struct, $args ); } @@ -266,7 +269,7 @@ function add_feed( $feedname, $function ) { * @global WP_Rewrite $wp_rewrite * * @param bool $hard Whether to update .htaccess (hard flush) or just update - * rewrite_rules transient (soft flush). Default is true (hard). + * rewrite_rules transient (soft flush). Default is true (hard). */ function flush_rewrite_rules( $hard = true ) { global $wp_rewrite; @@ -322,7 +325,7 @@ function add_rewrite_endpoint( $name, $places, $query_var = true ) { * @return string */ function _wp_filter_taxonomy_base( $base ) { - if ( !empty( $base ) ) { + if ( ! empty( $base ) ) { $base = preg_replace( '|^/index\.php/|', '', $base ); $base = trim( $base, '/' ); } @@ -480,31 +483,34 @@ function url_to_postid( $url ) { } // First, check to see if there is a 'p=N' or 'page_id=N' to match against - if ( preg_match('#[?&](p|page_id|attachment_id)=(\d+)#', $url, $values) ) { - $id = absint($values[2]); - if ( $id ) + if ( preg_match( '#[?&](p|page_id|attachment_id)=(\d+)#', $url, $values ) ) { + $id = absint( $values[2] ); + if ( $id ) { return $id; + } } // Get rid of the #anchor - $url_split = explode('#', $url); - $url = $url_split[0]; + $url_split = explode( '#', $url ); + $url = $url_split[0]; // Get rid of URL ?query=string - $url_split = explode('?', $url); - $url = $url_split[0]; + $url_split = explode( '?', $url ); + $url = $url_split[0]; // Set the correct URL scheme. $scheme = parse_url( home_url(), PHP_URL_SCHEME ); - $url = set_url_scheme( $url, $scheme ); + $url = set_url_scheme( $url, $scheme ); // Add 'www.' if it is absent and should be there - if ( false !== strpos(home_url(), '://www.') && false === strpos($url, '://www.') ) - $url = str_replace('://', '://www.', $url); + if ( false !== strpos( home_url(), '://www.' ) && false === strpos( $url, '://www.' ) ) { + $url = str_replace( '://', '://www.', $url ); + } // Strip 'www.' if it is present and shouldn't be - if ( false === strpos(home_url(), '://www.') ) - $url = str_replace('://www.', '://', $url); + if ( false === strpos( home_url(), '://www.' ) ) { + $url = str_replace( '://www.', '://', $url ); + } if ( trim( $url, '/' ) === home_url() && 'page' == get_option( 'show_on_front' ) ) { $page_on_front = get_option( 'page_on_front' ); @@ -518,44 +524,48 @@ function url_to_postid( $url ) { $rewrite = $wp_rewrite->wp_rewrite_rules(); // Not using rewrite rules, and 'p=N' and 'page_id=N' methods failed, so we're out of options - if ( empty($rewrite) ) + if ( empty( $rewrite ) ) { return 0; + } // Strip 'index.php/' if we're not using path info permalinks - if ( !$wp_rewrite->using_index_permalinks() ) + if ( ! $wp_rewrite->using_index_permalinks() ) { $url = str_replace( $wp_rewrite->index . '/', '', $url ); + } if ( false !== strpos( trailingslashit( $url ), home_url( '/' ) ) ) { // Chop off http://domain.com/[path] - $url = str_replace(home_url(), '', $url); + $url = str_replace( home_url(), '', $url ); } else { // Chop off /path/to/blog $home_path = parse_url( home_url( '/' ) ); - $home_path = isset( $home_path['path'] ) ? $home_path['path'] : '' ; - $url = preg_replace( sprintf( '#^%s#', preg_quote( $home_path ) ), '', trailingslashit( $url ) ); + $home_path = isset( $home_path['path'] ) ? $home_path['path'] : ''; + $url = preg_replace( sprintf( '#^%s#', preg_quote( $home_path ) ), '', trailingslashit( $url ) ); } // Trim leading and lagging slashes - $url = trim($url, '/'); + $url = trim( $url, '/' ); - $request = $url; + $request = $url; $post_type_query_vars = array(); - foreach ( get_post_types( array() , 'objects' ) as $post_type => $t ) { - if ( ! empty( $t->query_var ) ) + foreach ( get_post_types( array(), 'objects' ) as $post_type => $t ) { + if ( ! empty( $t->query_var ) ) { $post_type_query_vars[ $t->query_var ] = $post_type; + } } // Look for matches. $request_match = $request; - foreach ( (array)$rewrite as $match => $query) { + foreach ( (array) $rewrite as $match => $query ) { // If the requesting file is the anchor of the match, prepend it // to the path info. - if ( !empty($url) && ($url != $request) && (strpos($match, $url) === 0) ) + if ( ! empty( $url ) && ( $url != $request ) && ( strpos( $match, $url ) === 0 ) ) { $request_match = $url . '/' . $request; + } - if ( preg_match("#^$match#", $request_match, $matches) ) { + if ( preg_match( "#^$match#", $request_match, $matches ) ) { if ( $wp_rewrite->use_verbose_page_rules && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch ) ) { // This is a verbose page match, let's check to be sure about it. @@ -573,21 +583,21 @@ function url_to_postid( $url ) { // Got a match. // Trim the query of everything up to the '?'. - $query = preg_replace("!^.+\?!", '', $query); + $query = preg_replace( '!^.+\?!', '', $query ); // Substitute the substring matches into the query. - $query = addslashes(WP_MatchesMapRegex::apply($query, $matches)); + $query = addslashes( WP_MatchesMapRegex::apply( $query, $matches ) ); // Filter out non-public query vars global $wp; parse_str( $query, $query_vars ); $query = array(); foreach ( (array) $query_vars as $key => $value ) { - if ( in_array( $key, $wp->public_query_vars ) ){ - $query[$key] = $value; - if ( isset( $post_type_query_vars[$key] ) ) { - $query['post_type'] = $post_type_query_vars[$key]; - $query['name'] = $value; + if ( in_array( $key, $wp->public_query_vars ) ) { + $query[ $key ] = $value; + if ( isset( $post_type_query_vars[ $key ] ) ) { + $query['post_type'] = $post_type_query_vars[ $key ]; + $query['name'] = $value; } } } @@ -597,10 +607,11 @@ function url_to_postid( $url ) { // Do the query $query = new WP_Query( $query ); - if ( ! empty( $query->posts ) && $query->is_singular ) + if ( ! empty( $query->posts ) && $query->is_singular ) { return $query->post->ID; - else + } else { return 0; + } } } return 0; diff --git a/wp-includes/rss-functions.php b/wp-includes/rss-functions.php index 034a3e5db4..a7cc30fdaf 100644 --- a/wp-includes/rss-functions.php +++ b/wp-includes/rss-functions.php @@ -5,5 +5,5 @@ * @package WordPress */ -_deprecated_file( basename(__FILE__), '2.1.0', WPINC . '/rss.php' ); +_deprecated_file( basename( __FILE__ ), '2.1.0', WPINC . '/rss.php' ); require_once( ABSPATH . WPINC . '/rss.php' ); diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 0202474f84..a490e6c5af 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -56,100 +56,113 @@ function wp_default_scripts( &$scripts ) { if ( ! $guessurl = site_url() ) { $guessed_url = true; - $guessurl = wp_guess_url(); + $guessurl = wp_guess_url(); } - $scripts->base_url = $guessurl; - $scripts->content_url = defined('WP_CONTENT_URL')? WP_CONTENT_URL : ''; + $scripts->base_url = $guessurl; + $scripts->content_url = defined( 'WP_CONTENT_URL' ) ? WP_CONTENT_URL : ''; $scripts->default_version = get_bloginfo( 'version' ); - $scripts->default_dirs = array('/wp-admin/js/', '/wp-includes/js/'); + $scripts->default_dirs = array( '/wp-admin/js/', '/wp-includes/js/' ); - $suffix = SCRIPT_DEBUG ? '' : '.min'; + $suffix = SCRIPT_DEBUG ? '' : '.min'; $dev_suffix = $develop_src ? '' : '.min'; $scripts->add( 'utils', "/wp-includes/js/utils$suffix.js" ); - did_action( 'init' ) && $scripts->localize( 'utils', 'userSettings', array( - 'url' => (string) SITECOOKIEPATH, - 'uid' => (string) get_current_user_id(), - 'time' => (string) time(), - 'secure' => (string) ( 'https' === parse_url( site_url(), PHP_URL_SCHEME ) ), - ) ); + did_action( 'init' ) && $scripts->localize( + 'utils', 'userSettings', array( + 'url' => (string) SITECOOKIEPATH, + 'uid' => (string) get_current_user_id(), + 'time' => (string) time(), + 'secure' => (string) ( 'https' === parse_url( site_url(), PHP_URL_SCHEME ) ), + ) + ); - $scripts->add( 'common', "/wp-admin/js/common$suffix.js", array('jquery', 'hoverIntent', 'utils'), false, 1 ); - did_action( 'init' ) && $scripts->localize( 'common', 'commonL10n', array( - 'warnDelete' => __( "You are about to permanently delete these items from your site.\nThis action cannot be undone.\n 'Cancel' to stop, 'OK' to delete." ), - 'dismiss' => __( 'Dismiss this notice.' ), - 'collapseMenu' => __( 'Collapse Main menu' ), - 'expandMenu' => __( 'Expand Main menu' ), - ) ); + $scripts->add( 'common', "/wp-admin/js/common$suffix.js", array( 'jquery', 'hoverIntent', 'utils' ), false, 1 ); + did_action( 'init' ) && $scripts->localize( + 'common', 'commonL10n', array( + 'warnDelete' => __( "You are about to permanently delete these items from your site.\nThis action cannot be undone.\n 'Cancel' to stop, 'OK' to delete." ), + 'dismiss' => __( 'Dismiss this notice.' ), + 'collapseMenu' => __( 'Collapse Main menu' ), + 'expandMenu' => __( 'Expand Main menu' ), + ) + ); $scripts->add( 'wp-a11y', "/wp-includes/js/wp-a11y$suffix.js", array( 'jquery' ), false, 1 ); $scripts->add( 'sack', "/wp-includes/js/tw-sack$suffix.js", array(), '1.6.1', 1 ); $scripts->add( 'quicktags', "/wp-includes/js/quicktags$suffix.js", array(), false, 1 ); - did_action( 'init' ) && $scripts->localize( 'quicktags', 'quicktagsL10n', array( - 'closeAllOpenTags' => __( 'Close all open tags' ), - 'closeTags' => __( 'close tags' ), - 'enterURL' => __( 'Enter the URL' ), - 'enterImageURL' => __( 'Enter the URL of the image' ), - 'enterImageDescription' => __( 'Enter a description of the image' ), - 'textdirection' => __( 'text direction' ), - 'toggleTextdirection' => __( 'Toggle Editor Text Direction' ), - 'dfw' => __( 'Distraction-free writing mode' ), - 'strong' => __( 'Bold' ), - 'strongClose' => __( 'Close bold tag' ), - 'em' => __( 'Italic' ), - 'emClose' => __( 'Close italic tag' ), - 'link' => __( 'Insert link' ), - 'blockquote' => __( 'Blockquote' ), - 'blockquoteClose' => __( 'Close blockquote tag' ), - 'del' => __( 'Deleted text (strikethrough)' ), - 'delClose' => __( 'Close deleted text tag' ), - 'ins' => __( 'Inserted text' ), - 'insClose' => __( 'Close inserted text tag' ), - 'image' => __( 'Insert image' ), - 'ul' => __( 'Bulleted list' ), - 'ulClose' => __( 'Close bulleted list tag' ), - 'ol' => __( 'Numbered list' ), - 'olClose' => __( 'Close numbered list tag' ), - 'li' => __( 'List item' ), - 'liClose' => __( 'Close list item tag' ), - 'code' => __( 'Code' ), - 'codeClose' => __( 'Close code tag' ), - 'more' => __( 'Insert Read More tag' ), - ) ); + did_action( 'init' ) && $scripts->localize( + 'quicktags', 'quicktagsL10n', array( + 'closeAllOpenTags' => __( 'Close all open tags' ), + 'closeTags' => __( 'close tags' ), + 'enterURL' => __( 'Enter the URL' ), + 'enterImageURL' => __( 'Enter the URL of the image' ), + 'enterImageDescription' => __( 'Enter a description of the image' ), + 'textdirection' => __( 'text direction' ), + 'toggleTextdirection' => __( 'Toggle Editor Text Direction' ), + 'dfw' => __( 'Distraction-free writing mode' ), + 'strong' => __( 'Bold' ), + 'strongClose' => __( 'Close bold tag' ), + 'em' => __( 'Italic' ), + 'emClose' => __( 'Close italic tag' ), + 'link' => __( 'Insert link' ), + 'blockquote' => __( 'Blockquote' ), + 'blockquoteClose' => __( 'Close blockquote tag' ), + 'del' => __( 'Deleted text (strikethrough)' ), + 'delClose' => __( 'Close deleted text tag' ), + 'ins' => __( 'Inserted text' ), + 'insClose' => __( 'Close inserted text tag' ), + 'image' => __( 'Insert image' ), + 'ul' => __( 'Bulleted list' ), + 'ulClose' => __( 'Close bulleted list tag' ), + 'ol' => __( 'Numbered list' ), + 'olClose' => __( 'Close numbered list tag' ), + 'li' => __( 'List item' ), + 'liClose' => __( 'Close list item tag' ), + 'code' => __( 'Code' ), + 'codeClose' => __( 'Close code tag' ), + 'more' => __( 'Insert Read More tag' ), + ) + ); - $scripts->add( 'colorpicker', "/wp-includes/js/colorpicker$suffix.js", array('prototype'), '3517m' ); + $scripts->add( 'colorpicker', "/wp-includes/js/colorpicker$suffix.js", array( 'prototype' ), '3517m' ); - $scripts->add( 'editor', "/wp-admin/js/editor$suffix.js", array('utils','jquery'), false, 1 ); + $scripts->add( 'editor', "/wp-admin/js/editor$suffix.js", array( 'utils', 'jquery' ), false, 1 ); // Back-compat for old DFW. To-do: remove at the end of 2016. $scripts->add( 'wp-fullscreen-stub', "/wp-admin/js/wp-fullscreen-stub$suffix.js", array(), false, 1 ); - $scripts->add( 'wp-ajax-response', "/wp-includes/js/wp-ajax-response$suffix.js", array('jquery'), false, 1 ); - did_action( 'init' ) && $scripts->localize( 'wp-ajax-response', 'wpAjax', array( - 'noPerm' => __('Sorry, you are not allowed to do that.'), - 'broken' => __('An unidentified error has occurred.') - ) ); + $scripts->add( 'wp-ajax-response', "/wp-includes/js/wp-ajax-response$suffix.js", array( 'jquery' ), false, 1 ); + did_action( 'init' ) && $scripts->localize( + 'wp-ajax-response', 'wpAjax', array( + 'noPerm' => __( 'Sorry, you are not allowed to do that.' ), + 'broken' => __( 'An unidentified error has occurred.' ), + ) + ); $scripts->add( 'wp-api-request', "/wp-includes/js/api-request$suffix.js", array( 'jquery' ), false, 1 ); // `wpApiSettings` is also used by `wp-api`, which depends on this script. - did_action( 'init' ) && $scripts->localize( 'wp-api-request', 'wpApiSettings', array( - 'root' => esc_url_raw( get_rest_url() ), - 'nonce' => ( wp_installing() && ! is_multisite() ) ? '' : wp_create_nonce( 'wp_rest' ), - 'versionString' => 'wp/v2/', - ) ); + did_action( 'init' ) && $scripts->localize( + 'wp-api-request', 'wpApiSettings', array( + 'root' => esc_url_raw( get_rest_url() ), + 'nonce' => ( wp_installing() && ! is_multisite() ) ? '' : wp_create_nonce( 'wp_rest' ), + 'versionString' => 'wp/v2/', + ) + ); $scripts->add( 'wp-pointer', "/wp-includes/js/wp-pointer$suffix.js", array( 'jquery-ui-widget', 'jquery-ui-position' ), '20111129a', 1 ); - did_action( 'init' ) && $scripts->localize( 'wp-pointer', 'wpPointerL10n', array( - 'dismiss' => __('Dismiss'), - ) ); + did_action( 'init' ) && $scripts->localize( + 'wp-pointer', 'wpPointerL10n', array( + 'dismiss' => __( 'Dismiss' ), + ) + ); - $scripts->add( 'autosave', "/wp-includes/js/autosave$suffix.js", array('heartbeat'), false, 1 ); + $scripts->add( 'autosave', "/wp-includes/js/autosave$suffix.js", array( 'heartbeat' ), false, 1 ); - $scripts->add( 'heartbeat', "/wp-includes/js/heartbeat$suffix.js", array('jquery'), false, 1 ); - did_action( 'init' ) && $scripts->localize( 'heartbeat', 'heartbeatSettings', + $scripts->add( 'heartbeat', "/wp-includes/js/heartbeat$suffix.js", array( 'jquery' ), false, 1 ); + did_action( 'init' ) && $scripts->localize( + 'heartbeat', 'heartbeatSettings', /** * Filters the Heartbeat settings. * @@ -160,36 +173,38 @@ function wp_default_scripts( &$scripts ) { apply_filters( 'heartbeat_settings', array() ) ); - $scripts->add( 'wp-auth-check', "/wp-includes/js/wp-auth-check$suffix.js", array('heartbeat'), false, 1 ); - did_action( 'init' ) && $scripts->localize( 'wp-auth-check', 'authcheckL10n', array( - 'beforeunload' => __('Your session has expired. You can log in again from this page or go to the login page.'), + $scripts->add( 'wp-auth-check', "/wp-includes/js/wp-auth-check$suffix.js", array( 'heartbeat' ), false, 1 ); + did_action( 'init' ) && $scripts->localize( + 'wp-auth-check', 'authcheckL10n', array( + 'beforeunload' => __( 'Your session has expired. You can log in again from this page or go to the login page.' ), - /** - * Filters the authentication check interval. - * - * @since 3.6.0 - * - * @param int $interval The interval in which to check a user's authentication. - * Default 3 minutes in seconds, or 180. - */ - 'interval' => apply_filters( 'wp_auth_check_interval', 3 * MINUTE_IN_SECONDS ), - ) ); + /** + * Filters the authentication check interval. + * + * @since 3.6.0 + * + * @param int $interval The interval in which to check a user's authentication. + * Default 3 minutes in seconds, or 180. + */ + 'interval' => apply_filters( 'wp_auth_check_interval', 3 * MINUTE_IN_SECONDS ), + ) + ); $scripts->add( 'wp-lists', "/wp-includes/js/wp-lists$suffix.js", array( 'wp-ajax-response', 'jquery-color' ), false, 1 ); // WordPress no longer uses or bundles Prototype or script.aculo.us. These are now pulled from an external source. - $scripts->add( 'prototype', 'https://ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js', array(), '1.7.1'); - $scripts->add( 'scriptaculous-root', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/scriptaculous.js', array('prototype'), '1.9.0'); - $scripts->add( 'scriptaculous-builder', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/builder.js', array('scriptaculous-root'), '1.9.0'); - $scripts->add( 'scriptaculous-dragdrop', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/dragdrop.js', array('scriptaculous-builder', 'scriptaculous-effects'), '1.9.0'); - $scripts->add( 'scriptaculous-effects', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/effects.js', array('scriptaculous-root'), '1.9.0'); - $scripts->add( 'scriptaculous-slider', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/slider.js', array('scriptaculous-effects'), '1.9.0'); + $scripts->add( 'prototype', 'https://ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js', array(), '1.7.1' ); + $scripts->add( 'scriptaculous-root', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/scriptaculous.js', array( 'prototype' ), '1.9.0' ); + $scripts->add( 'scriptaculous-builder', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/builder.js', array( 'scriptaculous-root' ), '1.9.0' ); + $scripts->add( 'scriptaculous-dragdrop', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/dragdrop.js', array( 'scriptaculous-builder', 'scriptaculous-effects' ), '1.9.0' ); + $scripts->add( 'scriptaculous-effects', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/effects.js', array( 'scriptaculous-root' ), '1.9.0' ); + $scripts->add( 'scriptaculous-slider', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/slider.js', array( 'scriptaculous-effects' ), '1.9.0' ); $scripts->add( 'scriptaculous-sound', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/sound.js', array( 'scriptaculous-root' ), '1.9.0' ); - $scripts->add( 'scriptaculous-controls', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/controls.js', array('scriptaculous-root'), '1.9.0'); - $scripts->add( 'scriptaculous', false, array('scriptaculous-dragdrop', 'scriptaculous-slider', 'scriptaculous-controls') ); + $scripts->add( 'scriptaculous-controls', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/controls.js', array( 'scriptaculous-root' ), '1.9.0' ); + $scripts->add( 'scriptaculous', false, array( 'scriptaculous-dragdrop', 'scriptaculous-slider', 'scriptaculous-controls' ) ); // not used in core, replaced by Jcrop.js - $scripts->add( 'cropper', '/wp-includes/js/crop/cropper.js', array('scriptaculous-dragdrop') ); + $scripts->add( 'cropper', '/wp-includes/js/crop/cropper.js', array( 'scriptaculous-dragdrop' ) ); // jQuery $scripts->add( 'jquery', false, array( 'jquery-core', 'jquery-migrate' ), '1.12.4' ); @@ -197,117 +212,121 @@ function wp_default_scripts( &$scripts ) { $scripts->add( 'jquery-migrate', "/wp-includes/js/jquery/jquery-migrate$suffix.js", array(), '1.4.1' ); // full jQuery UI - $scripts->add( 'jquery-ui-core', "/wp-includes/js/jquery/ui/core$dev_suffix.js", array('jquery'), '1.11.4', 1 ); - $scripts->add( 'jquery-effects-core', "/wp-includes/js/jquery/ui/effect$dev_suffix.js", array('jquery'), '1.11.4', 1 ); + $scripts->add( 'jquery-ui-core', "/wp-includes/js/jquery/ui/core$dev_suffix.js", array( 'jquery' ), '1.11.4', 1 ); + $scripts->add( 'jquery-effects-core', "/wp-includes/js/jquery/ui/effect$dev_suffix.js", array( 'jquery' ), '1.11.4', 1 ); - $scripts->add( 'jquery-effects-blind', "/wp-includes/js/jquery/ui/effect-blind$dev_suffix.js", array('jquery-effects-core'), '1.11.4', 1 ); - $scripts->add( 'jquery-effects-bounce', "/wp-includes/js/jquery/ui/effect-bounce$dev_suffix.js", array('jquery-effects-core'), '1.11.4', 1 ); - $scripts->add( 'jquery-effects-clip', "/wp-includes/js/jquery/ui/effect-clip$dev_suffix.js", array('jquery-effects-core'), '1.11.4', 1 ); - $scripts->add( 'jquery-effects-drop', "/wp-includes/js/jquery/ui/effect-drop$dev_suffix.js", array('jquery-effects-core'), '1.11.4', 1 ); - $scripts->add( 'jquery-effects-explode', "/wp-includes/js/jquery/ui/effect-explode$dev_suffix.js", array('jquery-effects-core'), '1.11.4', 1 ); - $scripts->add( 'jquery-effects-fade', "/wp-includes/js/jquery/ui/effect-fade$dev_suffix.js", array('jquery-effects-core'), '1.11.4', 1 ); - $scripts->add( 'jquery-effects-fold', "/wp-includes/js/jquery/ui/effect-fold$dev_suffix.js", array('jquery-effects-core'), '1.11.4', 1 ); - $scripts->add( 'jquery-effects-highlight', "/wp-includes/js/jquery/ui/effect-highlight$dev_suffix.js", array('jquery-effects-core'), '1.11.4', 1 ); - $scripts->add( 'jquery-effects-puff', "/wp-includes/js/jquery/ui/effect-puff$dev_suffix.js", array('jquery-effects-core', 'jquery-effects-scale'), '1.11.4', 1 ); - $scripts->add( 'jquery-effects-pulsate', "/wp-includes/js/jquery/ui/effect-pulsate$dev_suffix.js", array('jquery-effects-core'), '1.11.4', 1 ); - $scripts->add( 'jquery-effects-scale', "/wp-includes/js/jquery/ui/effect-scale$dev_suffix.js", array('jquery-effects-core', 'jquery-effects-size'), '1.11.4', 1 ); - $scripts->add( 'jquery-effects-shake', "/wp-includes/js/jquery/ui/effect-shake$dev_suffix.js", array('jquery-effects-core'), '1.11.4', 1 ); - $scripts->add( 'jquery-effects-size', "/wp-includes/js/jquery/ui/effect-size$dev_suffix.js", array('jquery-effects-core'), '1.11.4', 1 ); - $scripts->add( 'jquery-effects-slide', "/wp-includes/js/jquery/ui/effect-slide$dev_suffix.js", array('jquery-effects-core'), '1.11.4', 1 ); - $scripts->add( 'jquery-effects-transfer', "/wp-includes/js/jquery/ui/effect-transfer$dev_suffix.js", array('jquery-effects-core'), '1.11.4', 1 ); + $scripts->add( 'jquery-effects-blind', "/wp-includes/js/jquery/ui/effect-blind$dev_suffix.js", array( 'jquery-effects-core' ), '1.11.4', 1 ); + $scripts->add( 'jquery-effects-bounce', "/wp-includes/js/jquery/ui/effect-bounce$dev_suffix.js", array( 'jquery-effects-core' ), '1.11.4', 1 ); + $scripts->add( 'jquery-effects-clip', "/wp-includes/js/jquery/ui/effect-clip$dev_suffix.js", array( 'jquery-effects-core' ), '1.11.4', 1 ); + $scripts->add( 'jquery-effects-drop', "/wp-includes/js/jquery/ui/effect-drop$dev_suffix.js", array( 'jquery-effects-core' ), '1.11.4', 1 ); + $scripts->add( 'jquery-effects-explode', "/wp-includes/js/jquery/ui/effect-explode$dev_suffix.js", array( 'jquery-effects-core' ), '1.11.4', 1 ); + $scripts->add( 'jquery-effects-fade', "/wp-includes/js/jquery/ui/effect-fade$dev_suffix.js", array( 'jquery-effects-core' ), '1.11.4', 1 ); + $scripts->add( 'jquery-effects-fold', "/wp-includes/js/jquery/ui/effect-fold$dev_suffix.js", array( 'jquery-effects-core' ), '1.11.4', 1 ); + $scripts->add( 'jquery-effects-highlight', "/wp-includes/js/jquery/ui/effect-highlight$dev_suffix.js", array( 'jquery-effects-core' ), '1.11.4', 1 ); + $scripts->add( 'jquery-effects-puff', "/wp-includes/js/jquery/ui/effect-puff$dev_suffix.js", array( 'jquery-effects-core', 'jquery-effects-scale' ), '1.11.4', 1 ); + $scripts->add( 'jquery-effects-pulsate', "/wp-includes/js/jquery/ui/effect-pulsate$dev_suffix.js", array( 'jquery-effects-core' ), '1.11.4', 1 ); + $scripts->add( 'jquery-effects-scale', "/wp-includes/js/jquery/ui/effect-scale$dev_suffix.js", array( 'jquery-effects-core', 'jquery-effects-size' ), '1.11.4', 1 ); + $scripts->add( 'jquery-effects-shake', "/wp-includes/js/jquery/ui/effect-shake$dev_suffix.js", array( 'jquery-effects-core' ), '1.11.4', 1 ); + $scripts->add( 'jquery-effects-size', "/wp-includes/js/jquery/ui/effect-size$dev_suffix.js", array( 'jquery-effects-core' ), '1.11.4', 1 ); + $scripts->add( 'jquery-effects-slide', "/wp-includes/js/jquery/ui/effect-slide$dev_suffix.js", array( 'jquery-effects-core' ), '1.11.4', 1 ); + $scripts->add( 'jquery-effects-transfer', "/wp-includes/js/jquery/ui/effect-transfer$dev_suffix.js", array( 'jquery-effects-core' ), '1.11.4', 1 ); - $scripts->add( 'jquery-ui-accordion', "/wp-includes/js/jquery/ui/accordion$dev_suffix.js", array('jquery-ui-core', 'jquery-ui-widget'), '1.11.4', 1 ); + $scripts->add( 'jquery-ui-accordion', "/wp-includes/js/jquery/ui/accordion$dev_suffix.js", array( 'jquery-ui-core', 'jquery-ui-widget' ), '1.11.4', 1 ); $scripts->add( 'jquery-ui-autocomplete', "/wp-includes/js/jquery/ui/autocomplete$dev_suffix.js", array( 'jquery-ui-menu', 'wp-a11y' ), '1.11.4', 1 ); - $scripts->add( 'jquery-ui-button', "/wp-includes/js/jquery/ui/button$dev_suffix.js", array('jquery-ui-core', 'jquery-ui-widget'), '1.11.4', 1 ); - $scripts->add( 'jquery-ui-datepicker', "/wp-includes/js/jquery/ui/datepicker$dev_suffix.js", array('jquery-ui-core'), '1.11.4', 1 ); - $scripts->add( 'jquery-ui-dialog', "/wp-includes/js/jquery/ui/dialog$dev_suffix.js", array('jquery-ui-resizable', 'jquery-ui-draggable', 'jquery-ui-button', 'jquery-ui-position'), '1.11.4', 1 ); - $scripts->add( 'jquery-ui-draggable', "/wp-includes/js/jquery/ui/draggable$dev_suffix.js", array('jquery-ui-mouse'), '1.11.4', 1 ); - $scripts->add( 'jquery-ui-droppable', "/wp-includes/js/jquery/ui/droppable$dev_suffix.js", array('jquery-ui-draggable'), '1.11.4', 1 ); + $scripts->add( 'jquery-ui-button', "/wp-includes/js/jquery/ui/button$dev_suffix.js", array( 'jquery-ui-core', 'jquery-ui-widget' ), '1.11.4', 1 ); + $scripts->add( 'jquery-ui-datepicker', "/wp-includes/js/jquery/ui/datepicker$dev_suffix.js", array( 'jquery-ui-core' ), '1.11.4', 1 ); + $scripts->add( 'jquery-ui-dialog', "/wp-includes/js/jquery/ui/dialog$dev_suffix.js", array( 'jquery-ui-resizable', 'jquery-ui-draggable', 'jquery-ui-button', 'jquery-ui-position' ), '1.11.4', 1 ); + $scripts->add( 'jquery-ui-draggable', "/wp-includes/js/jquery/ui/draggable$dev_suffix.js", array( 'jquery-ui-mouse' ), '1.11.4', 1 ); + $scripts->add( 'jquery-ui-droppable', "/wp-includes/js/jquery/ui/droppable$dev_suffix.js", array( 'jquery-ui-draggable' ), '1.11.4', 1 ); $scripts->add( 'jquery-ui-menu', "/wp-includes/js/jquery/ui/menu$dev_suffix.js", array( 'jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-position' ), '1.11.4', 1 ); $scripts->add( 'jquery-ui-mouse', "/wp-includes/js/jquery/ui/mouse$dev_suffix.js", array( 'jquery-ui-core', 'jquery-ui-widget' ), '1.11.4', 1 ); - $scripts->add( 'jquery-ui-position', "/wp-includes/js/jquery/ui/position$dev_suffix.js", array('jquery'), '1.11.4', 1 ); - $scripts->add( 'jquery-ui-progressbar', "/wp-includes/js/jquery/ui/progressbar$dev_suffix.js", array('jquery-ui-core', 'jquery-ui-widget'), '1.11.4', 1 ); - $scripts->add( 'jquery-ui-resizable', "/wp-includes/js/jquery/ui/resizable$dev_suffix.js", array('jquery-ui-mouse'), '1.11.4', 1 ); - $scripts->add( 'jquery-ui-selectable', "/wp-includes/js/jquery/ui/selectable$dev_suffix.js", array('jquery-ui-mouse'), '1.11.4', 1 ); - $scripts->add( 'jquery-ui-selectmenu', "/wp-includes/js/jquery/ui/selectmenu$dev_suffix.js", array('jquery-ui-menu'), '1.11.4', 1 ); - $scripts->add( 'jquery-ui-slider', "/wp-includes/js/jquery/ui/slider$dev_suffix.js", array('jquery-ui-mouse'), '1.11.4', 1 ); - $scripts->add( 'jquery-ui-sortable', "/wp-includes/js/jquery/ui/sortable$dev_suffix.js", array('jquery-ui-mouse'), '1.11.4', 1 ); + $scripts->add( 'jquery-ui-position', "/wp-includes/js/jquery/ui/position$dev_suffix.js", array( 'jquery' ), '1.11.4', 1 ); + $scripts->add( 'jquery-ui-progressbar', "/wp-includes/js/jquery/ui/progressbar$dev_suffix.js", array( 'jquery-ui-core', 'jquery-ui-widget' ), '1.11.4', 1 ); + $scripts->add( 'jquery-ui-resizable', "/wp-includes/js/jquery/ui/resizable$dev_suffix.js", array( 'jquery-ui-mouse' ), '1.11.4', 1 ); + $scripts->add( 'jquery-ui-selectable', "/wp-includes/js/jquery/ui/selectable$dev_suffix.js", array( 'jquery-ui-mouse' ), '1.11.4', 1 ); + $scripts->add( 'jquery-ui-selectmenu', "/wp-includes/js/jquery/ui/selectmenu$dev_suffix.js", array( 'jquery-ui-menu' ), '1.11.4', 1 ); + $scripts->add( 'jquery-ui-slider', "/wp-includes/js/jquery/ui/slider$dev_suffix.js", array( 'jquery-ui-mouse' ), '1.11.4', 1 ); + $scripts->add( 'jquery-ui-sortable', "/wp-includes/js/jquery/ui/sortable$dev_suffix.js", array( 'jquery-ui-mouse' ), '1.11.4', 1 ); $scripts->add( 'jquery-ui-spinner', "/wp-includes/js/jquery/ui/spinner$dev_suffix.js", array( 'jquery-ui-button' ), '1.11.4', 1 ); - $scripts->add( 'jquery-ui-tabs', "/wp-includes/js/jquery/ui/tabs$dev_suffix.js", array('jquery-ui-core', 'jquery-ui-widget'), '1.11.4', 1 ); + $scripts->add( 'jquery-ui-tabs', "/wp-includes/js/jquery/ui/tabs$dev_suffix.js", array( 'jquery-ui-core', 'jquery-ui-widget' ), '1.11.4', 1 ); $scripts->add( 'jquery-ui-tooltip', "/wp-includes/js/jquery/ui/tooltip$dev_suffix.js", array( 'jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-position' ), '1.11.4', 1 ); - $scripts->add( 'jquery-ui-widget', "/wp-includes/js/jquery/ui/widget$dev_suffix.js", array('jquery'), '1.11.4', 1 ); + $scripts->add( 'jquery-ui-widget', "/wp-includes/js/jquery/ui/widget$dev_suffix.js", array( 'jquery' ), '1.11.4', 1 ); // Strings for 'jquery-ui-autocomplete' live region messages - did_action( 'init' ) && $scripts->localize( 'jquery-ui-autocomplete', 'uiAutocompleteL10n', array( - 'noResults' => __( 'No results found.' ), - /* translators: Number of results found when using jQuery UI Autocomplete */ - 'oneResult' => __( '1 result found. Use up and down arrow keys to navigate.' ), - /* translators: %d: Number of results found when using jQuery UI Autocomplete */ - 'manyResults' => __( '%d results found. Use up and down arrow keys to navigate.' ), - 'itemSelected' => __( 'Item selected.' ), - ) ); + did_action( 'init' ) && $scripts->localize( + 'jquery-ui-autocomplete', 'uiAutocompleteL10n', array( + 'noResults' => __( 'No results found.' ), + /* translators: Number of results found when using jQuery UI Autocomplete */ + 'oneResult' => __( '1 result found. Use up and down arrow keys to navigate.' ), + /* translators: %d: Number of results found when using jQuery UI Autocomplete */ + 'manyResults' => __( '%d results found. Use up and down arrow keys to navigate.' ), + 'itemSelected' => __( 'Item selected.' ), + ) + ); // deprecated, not used in core, most functionality is included in jQuery 1.3 - $scripts->add( 'jquery-form', "/wp-includes/js/jquery/jquery.form$suffix.js", array('jquery'), '4.2.1', 1 ); + $scripts->add( 'jquery-form', "/wp-includes/js/jquery/jquery.form$suffix.js", array( 'jquery' ), '4.2.1', 1 ); // jQuery plugins - $scripts->add( 'jquery-color', "/wp-includes/js/jquery/jquery.color.min.js", array('jquery'), '2.1.1', 1 ); - $scripts->add( 'schedule', '/wp-includes/js/jquery/jquery.schedule.js', array('jquery'), '20m', 1 ); - $scripts->add( 'jquery-query', "/wp-includes/js/jquery/jquery.query.js", array('jquery'), '2.1.7', 1 ); - $scripts->add( 'jquery-serialize-object', "/wp-includes/js/jquery/jquery.serialize-object.js", array('jquery'), '0.2', 1 ); - $scripts->add( 'jquery-hotkeys', "/wp-includes/js/jquery/jquery.hotkeys$suffix.js", array('jquery'), '0.0.2m', 1 ); - $scripts->add( 'jquery-table-hotkeys', "/wp-includes/js/jquery/jquery.table-hotkeys$suffix.js", array('jquery', 'jquery-hotkeys'), false, 1 ); - $scripts->add( 'jquery-touch-punch', "/wp-includes/js/jquery/jquery.ui.touch-punch.js", array('jquery-ui-widget', 'jquery-ui-mouse'), '0.2.2', 1 ); + $scripts->add( 'jquery-color', '/wp-includes/js/jquery/jquery.color.min.js', array( 'jquery' ), '2.1.1', 1 ); + $scripts->add( 'schedule', '/wp-includes/js/jquery/jquery.schedule.js', array( 'jquery' ), '20m', 1 ); + $scripts->add( 'jquery-query', '/wp-includes/js/jquery/jquery.query.js', array( 'jquery' ), '2.1.7', 1 ); + $scripts->add( 'jquery-serialize-object', '/wp-includes/js/jquery/jquery.serialize-object.js', array( 'jquery' ), '0.2', 1 ); + $scripts->add( 'jquery-hotkeys', "/wp-includes/js/jquery/jquery.hotkeys$suffix.js", array( 'jquery' ), '0.0.2m', 1 ); + $scripts->add( 'jquery-table-hotkeys', "/wp-includes/js/jquery/jquery.table-hotkeys$suffix.js", array( 'jquery', 'jquery-hotkeys' ), false, 1 ); + $scripts->add( 'jquery-touch-punch', '/wp-includes/js/jquery/jquery.ui.touch-punch.js', array( 'jquery-ui-widget', 'jquery-ui-mouse' ), '0.2.2', 1 ); // Not used any more, registered for backwards compatibility. - $scripts->add( 'suggest', "/wp-includes/js/jquery/suggest$suffix.js", array('jquery'), '1.1-20110113', 1 ); + $scripts->add( 'suggest', "/wp-includes/js/jquery/suggest$suffix.js", array( 'jquery' ), '1.1-20110113', 1 ); // Masonry v2 depended on jQuery. v3 does not. The older jquery-masonry handle is a shiv. // It sets jQuery as a dependency, as the theme may have been implicitly loading it this way. - $scripts->add( 'imagesloaded', "/wp-includes/js/imagesloaded.min.js", array(), '3.2.0', 1 ); - $scripts->add( 'masonry', "/wp-includes/js/masonry.min.js", array( 'imagesloaded' ), '3.3.2', 1 ); + $scripts->add( 'imagesloaded', '/wp-includes/js/imagesloaded.min.js', array(), '3.2.0', 1 ); + $scripts->add( 'masonry', '/wp-includes/js/masonry.min.js', array( 'imagesloaded' ), '3.3.2', 1 ); $scripts->add( 'jquery-masonry', "/wp-includes/js/jquery/jquery.masonry$dev_suffix.js", array( 'jquery', 'masonry' ), '3.1.2b', 1 ); - $scripts->add( 'thickbox', "/wp-includes/js/thickbox/thickbox.js", array('jquery'), '3.1-20121105', 1 ); - did_action( 'init' ) && $scripts->localize( 'thickbox', 'thickboxL10n', array( - 'next' => __('Next >'), - 'prev' => __('< Prev'), - 'image' => __('Image'), - 'of' => __('of'), - 'close' => __('Close'), - 'noiframes' => __('This feature requires inline frames. You have iframes disabled or your browser does not support them.'), - 'loadingAnimation' => includes_url('js/thickbox/loadingAnimation.gif'), - ) ); + $scripts->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.js', array( 'jquery' ), '3.1-20121105', 1 ); + did_action( 'init' ) && $scripts->localize( + 'thickbox', 'thickboxL10n', array( + 'next' => __( 'Next >' ), + 'prev' => __( '< Prev' ), + 'image' => __( 'Image' ), + 'of' => __( 'of' ), + 'close' => __( 'Close' ), + 'noiframes' => __( 'This feature requires inline frames. You have iframes disabled or your browser does not support them.' ), + 'loadingAnimation' => includes_url( 'js/thickbox/loadingAnimation.gif' ), + ) + ); - $scripts->add( 'jcrop', "/wp-includes/js/jcrop/jquery.Jcrop.min.js", array('jquery'), '0.9.12'); + $scripts->add( 'jcrop', '/wp-includes/js/jcrop/jquery.Jcrop.min.js', array( 'jquery' ), '0.9.12' ); - $scripts->add( 'swfobject', "/wp-includes/js/swfobject.js", array(), '2.2-20120417'); + $scripts->add( 'swfobject', '/wp-includes/js/swfobject.js', array(), '2.2-20120417' ); // Error messages for Plupload. $uploader_l10n = array( - 'queue_limit_exceeded' => __('You have attempted to queue too many files.'), - 'file_exceeds_size_limit' => __('%s exceeds the maximum upload size for this site.'), - 'zero_byte_file' => __('This file is empty. Please try another.'), - 'invalid_filetype' => __('Sorry, this file type is not permitted for security reasons.'), - 'not_an_image' => __('This file is not an image. Please try another.'), - 'image_memory_exceeded' => __('Memory exceeded. Please try another smaller file.'), - 'image_dimensions_exceeded' => __('This is larger than the maximum size. Please try another.'), - 'default_error' => __('An error occurred in the upload. Please try again later.'), - 'missing_upload_url' => __('There was a configuration error. Please contact the server administrator.'), - 'upload_limit_exceeded' => __('You may only upload 1 file.'), - 'http_error' => __('HTTP error.'), - 'upload_failed' => __('Upload failed.'), + 'queue_limit_exceeded' => __( 'You have attempted to queue too many files.' ), + 'file_exceeds_size_limit' => __( '%s exceeds the maximum upload size for this site.' ), + 'zero_byte_file' => __( 'This file is empty. Please try another.' ), + 'invalid_filetype' => __( 'Sorry, this file type is not permitted for security reasons.' ), + 'not_an_image' => __( 'This file is not an image. Please try another.' ), + 'image_memory_exceeded' => __( 'Memory exceeded. Please try another smaller file.' ), + 'image_dimensions_exceeded' => __( 'This is larger than the maximum size. Please try another.' ), + 'default_error' => __( 'An error occurred in the upload. Please try again later.' ), + 'missing_upload_url' => __( 'There was a configuration error. Please contact the server administrator.' ), + 'upload_limit_exceeded' => __( 'You may only upload 1 file.' ), + 'http_error' => __( 'HTTP error.' ), + 'upload_failed' => __( 'Upload failed.' ), /* translators: 1: Opening link tag, 2: Closing link tag */ - 'big_upload_failed' => __('Please try uploading this file with the %1$sbrowser uploader%2$s.'), - 'big_upload_queued' => __('%s exceeds the maximum upload size for the multi-file uploader when used in your browser.'), - 'io_error' => __('IO error.'), - 'security_error' => __('Security error.'), - 'file_cancelled' => __('File canceled.'), - 'upload_stopped' => __('Upload stopped.'), - 'dismiss' => __('Dismiss'), - 'crunching' => __('Crunching…'), - 'deleted' => __('moved to the trash.'), - 'error_uploading' => __('“%s” has failed to upload.') + 'big_upload_failed' => __( 'Please try uploading this file with the %1$sbrowser uploader%2$s.' ), + 'big_upload_queued' => __( '%s exceeds the maximum upload size for the multi-file uploader when used in your browser.' ), + 'io_error' => __( 'IO error.' ), + 'security_error' => __( 'Security error.' ), + 'file_cancelled' => __( 'File canceled.' ), + 'upload_stopped' => __( 'Upload stopped.' ), + 'dismiss' => __( 'Dismiss' ), + 'crunching' => __( 'Crunching…' ), + 'deleted' => __( 'moved to the trash.' ), + 'error_uploading' => __( '“%s” has failed to upload.' ), ); $scripts->add( 'moxiejs', "/wp-includes/js/plupload/moxie$suffix.js", array(), '1.3.5' ); @@ -324,9 +343,9 @@ function wp_default_scripts( &$scripts ) { did_action( 'init' ) && $scripts->localize( 'wp-plupload', 'pluploadL10n', $uploader_l10n ); // keep 'swfupload' for back-compat. - $scripts->add( 'swfupload', '/wp-includes/js/swfupload/swfupload.js', array(), '2201-20110113'); + $scripts->add( 'swfupload', '/wp-includes/js/swfupload/swfupload.js', array(), '2201-20110113' ); $scripts->add( 'swfupload-all', false, array( 'swfupload' ), '2201' ); - $scripts->add( 'swfupload-handlers', "/wp-includes/js/swfupload/handlers$suffix.js", array('swfupload-all', 'jquery'), '2201-20110524'); + $scripts->add( 'swfupload-handlers', "/wp-includes/js/swfupload/handlers$suffix.js", array( 'swfupload-all', 'jquery' ), '2201-20110524' ); did_action( 'init' ) && $scripts->localize( 'swfupload-handlers', 'swfuploadL10n', $uploader_l10n ); $scripts->add( 'comment-reply', "/wp-includes/js/comment-reply$suffix.js", array(), false, 1 ); @@ -335,126 +354,134 @@ function wp_default_scripts( &$scripts ) { did_action( 'init' ) && $scripts->add_data( 'json2', 'conditional', 'lt IE 8' ); $scripts->add( 'underscore', "/wp-includes/js/underscore$dev_suffix.js", array(), '1.8.3', 1 ); - $scripts->add( 'backbone', "/wp-includes/js/backbone$dev_suffix.js", array( 'underscore','jquery' ), '1.2.3', 1 ); + $scripts->add( 'backbone', "/wp-includes/js/backbone$dev_suffix.js", array( 'underscore', 'jquery' ), '1.2.3', 1 ); - $scripts->add( 'wp-util', "/wp-includes/js/wp-util$suffix.js", array('underscore', 'jquery'), false, 1 ); - did_action( 'init' ) && $scripts->localize( 'wp-util', '_wpUtilSettings', array( - 'ajax' => array( - 'url' => admin_url( 'admin-ajax.php', 'relative' ), - ), - ) ); + $scripts->add( 'wp-util', "/wp-includes/js/wp-util$suffix.js", array( 'underscore', 'jquery' ), false, 1 ); + did_action( 'init' ) && $scripts->localize( + 'wp-util', '_wpUtilSettings', array( + 'ajax' => array( + 'url' => admin_url( 'admin-ajax.php', 'relative' ), + ), + ) + ); - $scripts->add( 'wp-sanitize', "/wp-includes/js/wp-sanitize$suffix.js", array('jquery'), false, 1 ); + $scripts->add( 'wp-sanitize', "/wp-includes/js/wp-sanitize$suffix.js", array( 'jquery' ), false, 1 ); - $scripts->add( 'wp-backbone', "/wp-includes/js/wp-backbone$suffix.js", array('backbone', 'wp-util'), false, 1 ); + $scripts->add( 'wp-backbone', "/wp-includes/js/wp-backbone$suffix.js", array( 'backbone', 'wp-util' ), false, 1 ); $scripts->add( 'revisions', "/wp-admin/js/revisions$suffix.js", array( 'wp-backbone', 'jquery-ui-slider', 'hoverIntent' ), false, 1 ); - $scripts->add( 'imgareaselect', "/wp-includes/js/imgareaselect/jquery.imgareaselect$suffix.js", array('jquery'), false, 1 ); + $scripts->add( 'imgareaselect', "/wp-includes/js/imgareaselect/jquery.imgareaselect$suffix.js", array( 'jquery' ), false, 1 ); $scripts->add( 'mediaelement', false, array( 'jquery', 'mediaelement-core', 'mediaelement-migrate' ), '4.2.6-78496d1' ); $scripts->add( 'mediaelement-core', "/wp-includes/js/mediaelement/mediaelement-and-player$suffix.js", array(), '4.2.6-78496d1', 1 ); - $scripts->add( 'mediaelement-migrate', "/wp-includes/js/mediaelement/mediaelement-migrate$suffix.js", array(), false, 1); + $scripts->add( 'mediaelement-migrate', "/wp-includes/js/mediaelement/mediaelement-migrate$suffix.js", array(), false, 1 ); - did_action( 'init' ) && $scripts->add_inline_script( 'mediaelement-core', sprintf( 'var mejsL10n = %s;', wp_json_encode( array( - 'language' => strtolower( strtok( is_admin() ? get_user_locale() : get_locale(), '_-' ) ), - 'strings' => array( - 'mejs.install-flash' => __( 'You are using a browser that does not have Flash player enabled or installed. Please turn on your Flash player plugin or download the latest version from https://get.adobe.com/flashplayer/' ), - 'mejs.fullscreen-off' => __( 'Turn off Fullscreen' ), - 'mejs.fullscreen-on' => __( 'Go Fullscreen' ), - 'mejs.download-video' => __( 'Download Video' ), - 'mejs.fullscreen' => __( 'Fullscreen' ), - 'mejs.time-jump-forward' => array( __( 'Jump forward 1 second' ), __( 'Jump forward %1 seconds' ) ), - 'mejs.loop' => __( 'Toggle Loop' ), - 'mejs.play' => __( 'Play' ), - 'mejs.pause' => __( 'Pause' ), - 'mejs.close' => __( 'Close' ), - 'mejs.time-slider' => __( 'Time Slider' ), - 'mejs.time-help-text' => __( 'Use Left/Right Arrow keys to advance one second, Up/Down arrows to advance ten seconds.' ), - 'mejs.time-skip-back' => array( __( 'Skip back 1 second' ), __( 'Skip back %1 seconds' ) ), - 'mejs.captions-subtitles' => __( 'Captions/Subtitles' ), - 'mejs.captions-chapters' => __( 'Chapters' ), - 'mejs.none' => __( 'None' ), - 'mejs.mute-toggle' => __( 'Mute Toggle' ), - 'mejs.volume-help-text' => __( 'Use Up/Down Arrow keys to increase or decrease volume.' ), - 'mejs.unmute' => __( 'Unmute' ), - 'mejs.mute' => __( 'Mute' ), - 'mejs.volume-slider' => __( 'Volume Slider' ), - 'mejs.video-player' => __( 'Video Player' ), - 'mejs.audio-player' => __( 'Audio Player' ), - 'mejs.ad-skip' => __( 'Skip ad' ), - 'mejs.ad-skip-info' => array( __( 'Skip in 1 second' ), __( 'Skip in %1 seconds' ) ), - 'mejs.source-chooser' => __( 'Source Chooser' ), - 'mejs.stop' => __( 'Stop' ), - 'mejs.speed-rate' => __( 'Speed Rate' ), - 'mejs.live-broadcast' => __( 'Live Broadcast' ), - 'mejs.afrikaans' => __( 'Afrikaans' ), - 'mejs.albanian' => __( 'Albanian' ), - 'mejs.arabic' => __( 'Arabic' ), - 'mejs.belarusian' => __( 'Belarusian' ), - 'mejs.bulgarian' => __( 'Bulgarian' ), - 'mejs.catalan' => __( 'Catalan' ), - 'mejs.chinese' => __( 'Chinese' ), - 'mejs.chinese-simplified' => __( 'Chinese (Simplified)' ), - 'mejs.chinese-traditional' => __( 'Chinese (Traditional)' ), - 'mejs.croatian' => __( 'Croatian' ), - 'mejs.czech' => __( 'Czech' ), - 'mejs.danish' => __( 'Danish' ), - 'mejs.dutch' => __( 'Dutch' ), - 'mejs.english' => __( 'English' ), - 'mejs.estonian' => __( 'Estonian' ), - 'mejs.filipino' => __( 'Filipino' ), - 'mejs.finnish' => __( 'Finnish' ), - 'mejs.french' => __( 'French' ), - 'mejs.galician' => __( 'Galician' ), - 'mejs.german' => __( 'German' ), - 'mejs.greek' => __( 'Greek' ), - 'mejs.haitian-creole' => __( 'Haitian Creole' ), - 'mejs.hebrew' => __( 'Hebrew' ), - 'mejs.hindi' => __( 'Hindi' ), - 'mejs.hungarian' => __( 'Hungarian' ), - 'mejs.icelandic' => __( 'Icelandic' ), - 'mejs.indonesian' => __( 'Indonesian' ), - 'mejs.irish' => __( 'Irish' ), - 'mejs.italian' => __( 'Italian' ), - 'mejs.japanese' => __( 'Japanese' ), - 'mejs.korean' => __( 'Korean' ), - 'mejs.latvian' => __( 'Latvian' ), - 'mejs.lithuanian' => __( 'Lithuanian' ), - 'mejs.macedonian' => __( 'Macedonian' ), - 'mejs.malay' => __( 'Malay' ), - 'mejs.maltese' => __( 'Maltese' ), - 'mejs.norwegian' => __( 'Norwegian' ), - 'mejs.persian' => __( 'Persian' ), - 'mejs.polish' => __( 'Polish' ), - 'mejs.portuguese' => __( 'Portuguese' ), - 'mejs.romanian' => __( 'Romanian' ), - 'mejs.russian' => __( 'Russian' ), - 'mejs.serbian' => __( 'Serbian' ), - 'mejs.slovak' => __( 'Slovak' ), - 'mejs.slovenian' => __( 'Slovenian' ), - 'mejs.spanish' => __( 'Spanish' ), - 'mejs.swahili' => __( 'Swahili' ), - 'mejs.swedish' => __( 'Swedish' ), - 'mejs.tagalog' => __( 'Tagalog' ), - 'mejs.thai' => __( 'Thai' ), - 'mejs.turkish' => __( 'Turkish' ), - 'mejs.ukrainian' => __( 'Ukrainian' ), - 'mejs.vietnamese' => __( 'Vietnamese' ), - 'mejs.welsh' => __( 'Welsh' ), - 'mejs.yiddish' => __( 'Yiddish' ), - ), - ) ) ), 'before' ); - - - $scripts->add( 'mediaelement-vimeo', "/wp-includes/js/mediaelement/renderers/vimeo.min.js", array('mediaelement'), '4.2.6-78496d1', 1 ); - $scripts->add( 'wp-mediaelement', "/wp-includes/js/mediaelement/wp-mediaelement$suffix.js", array('mediaelement'), false, 1 ); - $mejs_settings = array( - 'pluginPath' => includes_url( 'js/mediaelement/', 'relative' ), - 'classPrefix' => 'mejs-', - 'stretching' => 'responsive', + did_action( 'init' ) && $scripts->add_inline_script( + 'mediaelement-core', sprintf( + 'var mejsL10n = %s;', wp_json_encode( + array( + 'language' => strtolower( strtok( is_admin() ? get_user_locale() : get_locale(), '_-' ) ), + 'strings' => array( + 'mejs.install-flash' => __( 'You are using a browser that does not have Flash player enabled or installed. Please turn on your Flash player plugin or download the latest version from https://get.adobe.com/flashplayer/' ), + 'mejs.fullscreen-off' => __( 'Turn off Fullscreen' ), + 'mejs.fullscreen-on' => __( 'Go Fullscreen' ), + 'mejs.download-video' => __( 'Download Video' ), + 'mejs.fullscreen' => __( 'Fullscreen' ), + 'mejs.time-jump-forward' => array( __( 'Jump forward 1 second' ), __( 'Jump forward %1 seconds' ) ), + 'mejs.loop' => __( 'Toggle Loop' ), + 'mejs.play' => __( 'Play' ), + 'mejs.pause' => __( 'Pause' ), + 'mejs.close' => __( 'Close' ), + 'mejs.time-slider' => __( 'Time Slider' ), + 'mejs.time-help-text' => __( 'Use Left/Right Arrow keys to advance one second, Up/Down arrows to advance ten seconds.' ), + 'mejs.time-skip-back' => array( __( 'Skip back 1 second' ), __( 'Skip back %1 seconds' ) ), + 'mejs.captions-subtitles' => __( 'Captions/Subtitles' ), + 'mejs.captions-chapters' => __( 'Chapters' ), + 'mejs.none' => __( 'None' ), + 'mejs.mute-toggle' => __( 'Mute Toggle' ), + 'mejs.volume-help-text' => __( 'Use Up/Down Arrow keys to increase or decrease volume.' ), + 'mejs.unmute' => __( 'Unmute' ), + 'mejs.mute' => __( 'Mute' ), + 'mejs.volume-slider' => __( 'Volume Slider' ), + 'mejs.video-player' => __( 'Video Player' ), + 'mejs.audio-player' => __( 'Audio Player' ), + 'mejs.ad-skip' => __( 'Skip ad' ), + 'mejs.ad-skip-info' => array( __( 'Skip in 1 second' ), __( 'Skip in %1 seconds' ) ), + 'mejs.source-chooser' => __( 'Source Chooser' ), + 'mejs.stop' => __( 'Stop' ), + 'mejs.speed-rate' => __( 'Speed Rate' ), + 'mejs.live-broadcast' => __( 'Live Broadcast' ), + 'mejs.afrikaans' => __( 'Afrikaans' ), + 'mejs.albanian' => __( 'Albanian' ), + 'mejs.arabic' => __( 'Arabic' ), + 'mejs.belarusian' => __( 'Belarusian' ), + 'mejs.bulgarian' => __( 'Bulgarian' ), + 'mejs.catalan' => __( 'Catalan' ), + 'mejs.chinese' => __( 'Chinese' ), + 'mejs.chinese-simplified' => __( 'Chinese (Simplified)' ), + 'mejs.chinese-traditional' => __( 'Chinese (Traditional)' ), + 'mejs.croatian' => __( 'Croatian' ), + 'mejs.czech' => __( 'Czech' ), + 'mejs.danish' => __( 'Danish' ), + 'mejs.dutch' => __( 'Dutch' ), + 'mejs.english' => __( 'English' ), + 'mejs.estonian' => __( 'Estonian' ), + 'mejs.filipino' => __( 'Filipino' ), + 'mejs.finnish' => __( 'Finnish' ), + 'mejs.french' => __( 'French' ), + 'mejs.galician' => __( 'Galician' ), + 'mejs.german' => __( 'German' ), + 'mejs.greek' => __( 'Greek' ), + 'mejs.haitian-creole' => __( 'Haitian Creole' ), + 'mejs.hebrew' => __( 'Hebrew' ), + 'mejs.hindi' => __( 'Hindi' ), + 'mejs.hungarian' => __( 'Hungarian' ), + 'mejs.icelandic' => __( 'Icelandic' ), + 'mejs.indonesian' => __( 'Indonesian' ), + 'mejs.irish' => __( 'Irish' ), + 'mejs.italian' => __( 'Italian' ), + 'mejs.japanese' => __( 'Japanese' ), + 'mejs.korean' => __( 'Korean' ), + 'mejs.latvian' => __( 'Latvian' ), + 'mejs.lithuanian' => __( 'Lithuanian' ), + 'mejs.macedonian' => __( 'Macedonian' ), + 'mejs.malay' => __( 'Malay' ), + 'mejs.maltese' => __( 'Maltese' ), + 'mejs.norwegian' => __( 'Norwegian' ), + 'mejs.persian' => __( 'Persian' ), + 'mejs.polish' => __( 'Polish' ), + 'mejs.portuguese' => __( 'Portuguese' ), + 'mejs.romanian' => __( 'Romanian' ), + 'mejs.russian' => __( 'Russian' ), + 'mejs.serbian' => __( 'Serbian' ), + 'mejs.slovak' => __( 'Slovak' ), + 'mejs.slovenian' => __( 'Slovenian' ), + 'mejs.spanish' => __( 'Spanish' ), + 'mejs.swahili' => __( 'Swahili' ), + 'mejs.swedish' => __( 'Swedish' ), + 'mejs.tagalog' => __( 'Tagalog' ), + 'mejs.thai' => __( 'Thai' ), + 'mejs.turkish' => __( 'Turkish' ), + 'mejs.ukrainian' => __( 'Ukrainian' ), + 'mejs.vietnamese' => __( 'Vietnamese' ), + 'mejs.welsh' => __( 'Welsh' ), + 'mejs.yiddish' => __( 'Yiddish' ), + ), + ) + ) + ), 'before' ); - did_action( 'init' ) && $scripts->localize( 'mediaelement', '_wpmejsSettings', + + $scripts->add( 'mediaelement-vimeo', '/wp-includes/js/mediaelement/renderers/vimeo.min.js', array( 'mediaelement' ), '4.2.6-78496d1', 1 ); + $scripts->add( 'wp-mediaelement', "/wp-includes/js/mediaelement/wp-mediaelement$suffix.js", array( 'mediaelement' ), false, 1 ); + $mejs_settings = array( + 'pluginPath' => includes_url( 'js/mediaelement/', 'relative' ), + 'classPrefix' => 'mejs-', + 'stretching' => 'responsive', + ); + did_action( 'init' ) && $scripts->localize( + 'mediaelement', '_wpmejsSettings', /** * Filters the MediaElement configuration settings. * @@ -473,44 +500,56 @@ function wp_default_scripts( &$scripts ) { $scripts->add( 'htmlhint-kses', '/wp-includes/js/codemirror/htmlhint-kses.js', array( 'htmlhint' ) ); $scripts->add( 'code-editor', "/wp-admin/js/code-editor$suffix.js", array( 'jquery', 'wp-codemirror', 'underscore' ) ); $scripts->add( 'wp-theme-plugin-editor', "/wp-admin/js/theme-plugin-editor$suffix.js", array( 'wp-util', 'wp-sanitize', 'jquery', 'jquery-ui-core', 'wp-a11y', 'underscore' ) ); - did_action( 'init' ) && $scripts->add_inline_script( 'wp-theme-plugin-editor', sprintf( 'wp.themePluginEditor.l10n = %s;', wp_json_encode( array( - 'saveAlert' => __( 'The changes you made will be lost if you navigate away from this page.' ), - 'saveError' => __( 'Something went wrong. Your change may not have been saved. Please try again. There is also a chance that you may need to manually fix and upload the file over FTP.' ), - 'lintError' => array( - /* translators: %d: error count */ - 'singular' => _n( 'There is %d error which must be fixed before you can update this file.', 'There are %d errors which must be fixed before you can update this file.', 1 ), - /* translators: %d: error count */ - 'plural' => _n( 'There is %d error which must be fixed before you can update this file.', 'There are %d errors which must be fixed before you can update this file.', 2 ), // @todo This is lacking, as some languages have a dedicated dual form. For proper handling of plurals in JS, see #20491. - ), - ) ) ) ); + did_action( 'init' ) && $scripts->add_inline_script( + 'wp-theme-plugin-editor', sprintf( + 'wp.themePluginEditor.l10n = %s;', wp_json_encode( + array( + 'saveAlert' => __( 'The changes you made will be lost if you navigate away from this page.' ), + 'saveError' => __( 'Something went wrong. Your change may not have been saved. Please try again. There is also a chance that you may need to manually fix and upload the file over FTP.' ), + 'lintError' => array( + /* translators: %d: error count */ + 'singular' => _n( 'There is %d error which must be fixed before you can update this file.', 'There are %d errors which must be fixed before you can update this file.', 1 ), + /* translators: %d: error count */ + 'plural' => _n( 'There is %d error which must be fixed before you can update this file.', 'There are %d errors which must be fixed before you can update this file.', 2 ), // @todo This is lacking, as some languages have a dedicated dual form. For proper handling of plurals in JS, see #20491. + ), + ) + ) + ) + ); $scripts->add( 'wp-playlist', "/wp-includes/js/mediaelement/wp-playlist$suffix.js", array( 'wp-util', 'backbone', 'mediaelement' ), false, 1 ); $scripts->add( 'zxcvbn-async', "/wp-includes/js/zxcvbn-async$suffix.js", array(), '1.0' ); - did_action( 'init' ) && $scripts->localize( 'zxcvbn-async', '_zxcvbnSettings', array( - 'src' => empty( $guessed_url ) ? includes_url( '/js/zxcvbn.min.js' ) : $scripts->base_url . '/wp-includes/js/zxcvbn.min.js', - ) ); + did_action( 'init' ) && $scripts->localize( + 'zxcvbn-async', '_zxcvbnSettings', array( + 'src' => empty( $guessed_url ) ? includes_url( '/js/zxcvbn.min.js' ) : $scripts->base_url . '/wp-includes/js/zxcvbn.min.js', + ) + ); $scripts->add( 'password-strength-meter', "/wp-admin/js/password-strength-meter$suffix.js", array( 'jquery', 'zxcvbn-async' ), false, 1 ); - did_action( 'init' ) && $scripts->localize( 'password-strength-meter', 'pwsL10n', array( - 'unknown' => _x( 'Password strength unknown', 'password strength' ), - 'short' => _x( 'Very weak', 'password strength' ), - 'bad' => _x( 'Weak', 'password strength' ), - 'good' => _x( 'Medium', 'password strength' ), - 'strong' => _x( 'Strong', 'password strength' ), - 'mismatch' => _x( 'Mismatch', 'password mismatch' ), - ) ); + did_action( 'init' ) && $scripts->localize( + 'password-strength-meter', 'pwsL10n', array( + 'unknown' => _x( 'Password strength unknown', 'password strength' ), + 'short' => _x( 'Very weak', 'password strength' ), + 'bad' => _x( 'Weak', 'password strength' ), + 'good' => _x( 'Medium', 'password strength' ), + 'strong' => _x( 'Strong', 'password strength' ), + 'mismatch' => _x( 'Mismatch', 'password mismatch' ), + ) + ); $scripts->add( 'user-profile', "/wp-admin/js/user-profile$suffix.js", array( 'jquery', 'password-strength-meter', 'wp-util' ), false, 1 ); - did_action( 'init' ) && $scripts->localize( 'user-profile', 'userProfileL10n', array( - 'warn' => __( 'Your new password has not been saved.' ), - 'warnWeak' => __( 'Confirm use of weak password' ), - 'show' => __( 'Show' ), - 'hide' => __( 'Hide' ), - 'cancel' => __( 'Cancel' ), - 'ariaShow' => esc_attr__( 'Show password' ), - 'ariaHide' => esc_attr__( 'Hide password' ), - ) ); + did_action( 'init' ) && $scripts->localize( + 'user-profile', 'userProfileL10n', array( + 'warn' => __( 'Your new password has not been saved.' ), + 'warnWeak' => __( 'Confirm use of weak password' ), + 'show' => __( 'Show' ), + 'hide' => __( 'Hide' ), + 'cancel' => __( 'Cancel' ), + 'ariaShow' => esc_attr__( 'Show password' ), + 'ariaHide' => esc_attr__( 'Hide password' ), + ) + ); $scripts->add( 'language-chooser', "/wp-admin/js/language-chooser$suffix.js", array( 'jquery' ), false, 1 ); @@ -519,15 +558,17 @@ function wp_default_scripts( &$scripts ) { $scripts->add( 'admin-bar', "/wp-includes/js/admin-bar$suffix.js", array(), false, 1 ); $scripts->add( 'wplink', "/wp-includes/js/wplink$suffix.js", array( 'jquery', 'wp-a11y' ), false, 1 ); - did_action( 'init' ) && $scripts->localize( 'wplink', 'wpLinkL10n', array( - 'title' => __('Insert/edit link'), - 'update' => __('Update'), - 'save' => __('Add Link'), - 'noTitle' => __('(no title)'), - 'noMatchesFound' => __('No results found.'), - 'linkSelected' => __( 'Link selected.' ), - 'linkInserted' => __( 'Link inserted.' ), - ) ); + did_action( 'init' ) && $scripts->localize( + 'wplink', 'wpLinkL10n', array( + 'title' => __( 'Insert/edit link' ), + 'update' => __( 'Update' ), + 'save' => __( 'Add Link' ), + 'noTitle' => __( '(no title)' ), + 'noMatchesFound' => __( 'No results found.' ), + 'linkSelected' => __( 'Link selected.' ), + 'linkInserted' => __( 'Link inserted.' ), + ) + ); $scripts->add( 'wpdialogs', "/wp-includes/js/wpdialog$suffix.js", array( 'jquery-ui-dialog' ), false, 1 ); @@ -535,76 +576,78 @@ function wp_default_scripts( &$scripts ) { $scripts->add( 'media-upload', "/wp-admin/js/media-upload$suffix.js", array( 'thickbox', 'shortcode' ), false, 1 ); - $scripts->add( 'hoverIntent', "/wp-includes/js/hoverIntent$suffix.js", array('jquery'), '1.8.1', 1 ); + $scripts->add( 'hoverIntent', "/wp-includes/js/hoverIntent$suffix.js", array( 'jquery' ), '1.8.1', 1 ); - $scripts->add( 'customize-base', "/wp-includes/js/customize-base$suffix.js", array( 'jquery', 'json2', 'underscore' ), false, 1 ); - $scripts->add( 'customize-loader', "/wp-includes/js/customize-loader$suffix.js", array( 'customize-base' ), false, 1 ); - $scripts->add( 'customize-preview', "/wp-includes/js/customize-preview$suffix.js", array( 'wp-a11y', 'customize-base' ), false, 1 ); - $scripts->add( 'customize-models', "/wp-includes/js/customize-models.js", array( 'underscore', 'backbone' ), false, 1 ); - $scripts->add( 'customize-views', "/wp-includes/js/customize-views.js", array( 'jquery', 'underscore', 'imgareaselect', 'customize-models', 'media-editor', 'media-views' ), false, 1 ); + $scripts->add( 'customize-base', "/wp-includes/js/customize-base$suffix.js", array( 'jquery', 'json2', 'underscore' ), false, 1 ); + $scripts->add( 'customize-loader', "/wp-includes/js/customize-loader$suffix.js", array( 'customize-base' ), false, 1 ); + $scripts->add( 'customize-preview', "/wp-includes/js/customize-preview$suffix.js", array( 'wp-a11y', 'customize-base' ), false, 1 ); + $scripts->add( 'customize-models', '/wp-includes/js/customize-models.js', array( 'underscore', 'backbone' ), false, 1 ); + $scripts->add( 'customize-views', '/wp-includes/js/customize-views.js', array( 'jquery', 'underscore', 'imgareaselect', 'customize-models', 'media-editor', 'media-views' ), false, 1 ); $scripts->add( 'customize-controls', "/wp-admin/js/customize-controls$suffix.js", array( 'customize-base', 'wp-a11y', 'wp-util', 'jquery-ui-core' ), false, 1 ); - did_action( 'init' ) && $scripts->localize( 'customize-controls', '_wpCustomizeControlsL10n', array( - 'activate' => __( 'Activate & Publish' ), - 'save' => __( 'Save & Publish' ), // @todo Remove as not required. - 'publish' => __( 'Publish' ), - 'published' => __( 'Published' ), - 'saveDraft' => __( 'Save Draft' ), - 'draftSaved' => __( 'Draft Saved' ), - 'updating' => __( 'Updating' ), - 'schedule' => _x( 'Schedule', 'customizer changeset action/button label' ), - 'scheduled' => _x( 'Scheduled', 'customizer changeset status' ), - 'invalid' => __( 'Invalid' ), - 'saveBeforeShare' => __( 'Please save your changes in order to share the preview.' ), - 'futureDateError' => __( 'You must supply a future date to schedule.' ), - 'saveAlert' => __( 'The changes you made will be lost if you navigate away from this page.' ), - 'saved' => __( 'Saved' ), - 'cancel' => __( 'Cancel' ), - 'close' => __( 'Close' ), - 'action' => __( 'Action' ), - 'discardChanges' => __( 'Discard changes' ), - 'cheatin' => __( 'Cheatin’ uh?' ), - 'notAllowed' => __( 'Sorry, you are not allowed to customize this site.' ), - 'previewIframeTitle' => __( 'Site Preview' ), - 'loginIframeTitle' => __( 'Session expired' ), - 'collapseSidebar' => _x( 'Hide Controls', 'label for hide controls button without length constraints' ), - 'expandSidebar' => _x( 'Show Controls', 'label for hide controls button without length constraints' ), - 'untitledBlogName' => __( '(Untitled)' ), - 'unknownRequestFail' => __( 'Looks like something’s gone wrong. Wait a couple seconds, and then try again.' ), - 'themeDownloading' => __( 'Downloading your new theme…' ), - 'themePreviewWait' => __( 'Setting up your live preview. This may take a bit.' ), - 'revertingChanges' => __( 'Reverting unpublished changes…' ), - 'trashConfirm' => __( 'Are you sure you’d like to discard your unpublished changes?' ), - /* translators: %s: Display name of the user who has taken over the changeset in customizer. */ - 'takenOverMessage' => __( '%s has taken over and is currently customizing.' ), - /* translators: %s: URL to the Customizer to load the autosaved version */ - 'autosaveNotice' => __( 'There is a more recent autosave of your changes than the one you are previewing. Restore the autosave' ), - 'videoHeaderNotice' => __( 'This theme doesn’t support video headers on this page. Navigate to the front page or another page that supports video headers.' ), - // Used for overriding the file types allowed in plupload. - 'allowedFiles' => __( 'Allowed Files' ), - 'customCssError' => array( - /* translators: %d: error count */ - 'singular' => _n( 'There is %d error which must be fixed before you can save.', 'There are %d errors which must be fixed before you can save.', 1 ), - /* translators: %d: error count */ - 'plural' => _n( 'There is %d error which must be fixed before you can save.', 'There are %d errors which must be fixed before you can save.', 2 ), // @todo This is lacking, as some languages have a dedicated dual form. For proper handling of plurals in JS, see #20491. - ), - 'pageOnFrontError' => __( 'Homepage and posts page must be different.' ), - 'saveBlockedError' => array( - /* translators: %s: number of invalid settings */ - 'singular' => _n( 'Unable to save due to %s invalid setting.', 'Unable to save due to %s invalid settings.', 1 ), - /* translators: %s: number of invalid settings */ - 'plural' => _n( 'Unable to save due to %s invalid setting.', 'Unable to save due to %s invalid settings.', 2 ), // @todo This is lacking, as some languages have a dedicated dual form. For proper handling of plurals in JS, see #20491. - ), - 'scheduleDescription' => __( 'Schedule your customization changes to publish ("go live") at a future date.' ), - 'themePreviewUnavailable' => __( 'Sorry, you can’t preview new themes when you have changes scheduled or saved as a draft. Please publish your changes, or wait until they publish to preview new themes.' ), - 'themeInstallUnavailable' => sprintf( - /* translators: %s: URL to Add Themes admin screen */ - __( 'You won’t be able to install new themes from here yet since your install requires SFTP credentials. For now, please add themes in the admin.' ), - esc_url( admin_url( 'theme-install.php' ) ) - ), - 'publishSettings' => __( 'Publish Settings' ), - 'invalidDate' => __( 'Invalid date.' ), - 'invalidValue' => __( 'Invalid value.' ), - ) ); + did_action( 'init' ) && $scripts->localize( + 'customize-controls', '_wpCustomizeControlsL10n', array( + 'activate' => __( 'Activate & Publish' ), + 'save' => __( 'Save & Publish' ), // @todo Remove as not required. + 'publish' => __( 'Publish' ), + 'published' => __( 'Published' ), + 'saveDraft' => __( 'Save Draft' ), + 'draftSaved' => __( 'Draft Saved' ), + 'updating' => __( 'Updating' ), + 'schedule' => _x( 'Schedule', 'customizer changeset action/button label' ), + 'scheduled' => _x( 'Scheduled', 'customizer changeset status' ), + 'invalid' => __( 'Invalid' ), + 'saveBeforeShare' => __( 'Please save your changes in order to share the preview.' ), + 'futureDateError' => __( 'You must supply a future date to schedule.' ), + 'saveAlert' => __( 'The changes you made will be lost if you navigate away from this page.' ), + 'saved' => __( 'Saved' ), + 'cancel' => __( 'Cancel' ), + 'close' => __( 'Close' ), + 'action' => __( 'Action' ), + 'discardChanges' => __( 'Discard changes' ), + 'cheatin' => __( 'Cheatin’ uh?' ), + 'notAllowed' => __( 'Sorry, you are not allowed to customize this site.' ), + 'previewIframeTitle' => __( 'Site Preview' ), + 'loginIframeTitle' => __( 'Session expired' ), + 'collapseSidebar' => _x( 'Hide Controls', 'label for hide controls button without length constraints' ), + 'expandSidebar' => _x( 'Show Controls', 'label for hide controls button without length constraints' ), + 'untitledBlogName' => __( '(Untitled)' ), + 'unknownRequestFail' => __( 'Looks like something’s gone wrong. Wait a couple seconds, and then try again.' ), + 'themeDownloading' => __( 'Downloading your new theme…' ), + 'themePreviewWait' => __( 'Setting up your live preview. This may take a bit.' ), + 'revertingChanges' => __( 'Reverting unpublished changes…' ), + 'trashConfirm' => __( 'Are you sure you’d like to discard your unpublished changes?' ), + /* translators: %s: Display name of the user who has taken over the changeset in customizer. */ + 'takenOverMessage' => __( '%s has taken over and is currently customizing.' ), + /* translators: %s: URL to the Customizer to load the autosaved version */ + 'autosaveNotice' => __( 'There is a more recent autosave of your changes than the one you are previewing. Restore the autosave' ), + 'videoHeaderNotice' => __( 'This theme doesn’t support video headers on this page. Navigate to the front page or another page that supports video headers.' ), + // Used for overriding the file types allowed in plupload. + 'allowedFiles' => __( 'Allowed Files' ), + 'customCssError' => array( + /* translators: %d: error count */ + 'singular' => _n( 'There is %d error which must be fixed before you can save.', 'There are %d errors which must be fixed before you can save.', 1 ), + /* translators: %d: error count */ + 'plural' => _n( 'There is %d error which must be fixed before you can save.', 'There are %d errors which must be fixed before you can save.', 2 ), // @todo This is lacking, as some languages have a dedicated dual form. For proper handling of plurals in JS, see #20491. + ), + 'pageOnFrontError' => __( 'Homepage and posts page must be different.' ), + 'saveBlockedError' => array( + /* translators: %s: number of invalid settings */ + 'singular' => _n( 'Unable to save due to %s invalid setting.', 'Unable to save due to %s invalid settings.', 1 ), + /* translators: %s: number of invalid settings */ + 'plural' => _n( 'Unable to save due to %s invalid setting.', 'Unable to save due to %s invalid settings.', 2 ), // @todo This is lacking, as some languages have a dedicated dual form. For proper handling of plurals in JS, see #20491. + ), + 'scheduleDescription' => __( 'Schedule your customization changes to publish ("go live") at a future date.' ), + 'themePreviewUnavailable' => __( 'Sorry, you can’t preview new themes when you have changes scheduled or saved as a draft. Please publish your changes, or wait until they publish to preview new themes.' ), + 'themeInstallUnavailable' => sprintf( + /* translators: %s: URL to Add Themes admin screen */ + __( 'You won’t be able to install new themes from here yet since your install requires SFTP credentials. For now, please add themes in the admin.' ), + esc_url( admin_url( 'theme-install.php' ) ) + ), + 'publishSettings' => __( 'Publish Settings' ), + 'invalidDate' => __( 'Invalid date.' ), + 'invalidValue' => __( 'Invalid value.' ), + ) + ); $scripts->add( 'customize-selective-refresh', "/wp-includes/js/customize-selective-refresh$suffix.js", array( 'jquery', 'wp-util', 'customize-preview' ), false, 1 ); $scripts->add( 'customize-widgets', "/wp-admin/js/customize-widgets$suffix.js", array( 'jquery', 'jquery-ui-sortable', 'jquery-ui-droppable', 'wp-backbone', 'customize-controls' ), false, 1 ); @@ -619,18 +662,20 @@ function wp_default_scripts( &$scripts ) { $scripts->add( 'shortcode', "/wp-includes/js/shortcode$suffix.js", array( 'underscore' ), false, 1 ); $scripts->add( 'media-models', "/wp-includes/js/media-models$suffix.js", array( 'wp-backbone' ), false, 1 ); - did_action( 'init' ) && $scripts->localize( 'media-models', '_wpMediaModelsL10n', array( - 'settings' => array( - 'ajaxurl' => admin_url( 'admin-ajax.php', 'relative' ), - 'post' => array( 'id' => 0 ), - ), - ) ); + did_action( 'init' ) && $scripts->localize( + 'media-models', '_wpMediaModelsL10n', array( + 'settings' => array( + 'ajaxurl' => admin_url( 'admin-ajax.php', 'relative' ), + 'post' => array( 'id' => 0 ), + ), + ) + ); $scripts->add( 'wp-embed', "/wp-includes/js/wp-embed$suffix.js" ); // To enqueue media-views or media-editor, call wp_enqueue_media(). // Both rely on numerous settings, styles, and templates to operate correctly. - $scripts->add( 'media-views', "/wp-includes/js/media-views$suffix.js", array( 'utils', 'media-models', 'wp-plupload', 'jquery-ui-sortable', 'wp-mediaelement', 'wp-api-request' ), false, 1 ); + $scripts->add( 'media-views', "/wp-includes/js/media-views$suffix.js", array( 'utils', 'media-models', 'wp-plupload', 'jquery-ui-sortable', 'wp-mediaelement', 'wp-api-request' ), false, 1 ); $scripts->add( 'media-editor', "/wp-includes/js/media-editor$suffix.js", array( 'shortcode', 'media-views' ), false, 1 ); $scripts->add( 'media-audiovideo', "/wp-includes/js/media-audiovideo$suffix.js", array( 'media-editor' ), false, 1 ); $scripts->add( 'mce-view', "/wp-includes/js/mce-view$suffix.js", array( 'shortcode', 'jquery', 'media-views', 'media-audiovideo' ), false, 1 ); @@ -639,68 +684,78 @@ function wp_default_scripts( &$scripts ) { if ( is_admin() ) { $scripts->add( 'admin-tags', "/wp-admin/js/tags$suffix.js", array( 'jquery', 'wp-ajax-response' ), false, 1 ); - did_action( 'init' ) && $scripts->localize( 'admin-tags', 'tagsl10n', array( - 'noPerm' => __('Sorry, you are not allowed to do that.'), - 'broken' => __('An unidentified error has occurred.') - )); + did_action( 'init' ) && $scripts->localize( + 'admin-tags', 'tagsl10n', array( + 'noPerm' => __( 'Sorry, you are not allowed to do that.' ), + 'broken' => __( 'An unidentified error has occurred.' ), + ) + ); - $scripts->add( 'admin-comments', "/wp-admin/js/edit-comments$suffix.js", array('wp-lists', 'quicktags', 'jquery-query'), false, 1 ); - did_action( 'init' ) && $scripts->localize( 'admin-comments', 'adminCommentsL10n', array( - 'hotkeys_highlight_first' => isset($_GET['hotkeys_highlight_first']), - 'hotkeys_highlight_last' => isset($_GET['hotkeys_highlight_last']), - 'replyApprove' => __( 'Approve and Reply' ), - 'reply' => __( 'Reply' ), - 'warnQuickEdit' => __( "Are you sure you want to edit this comment?\nThe changes you made will be lost." ), - 'warnCommentChanges' => __( "Are you sure you want to do this?\nThe comment changes you made will be lost." ), - 'docTitleComments' => __( 'Comments' ), - /* translators: %s: comments count */ - 'docTitleCommentsCount' => __( 'Comments (%s)' ), - ) ); + $scripts->add( 'admin-comments', "/wp-admin/js/edit-comments$suffix.js", array( 'wp-lists', 'quicktags', 'jquery-query' ), false, 1 ); + did_action( 'init' ) && $scripts->localize( + 'admin-comments', 'adminCommentsL10n', array( + 'hotkeys_highlight_first' => isset( $_GET['hotkeys_highlight_first'] ), + 'hotkeys_highlight_last' => isset( $_GET['hotkeys_highlight_last'] ), + 'replyApprove' => __( 'Approve and Reply' ), + 'reply' => __( 'Reply' ), + 'warnQuickEdit' => __( "Are you sure you want to edit this comment?\nThe changes you made will be lost." ), + 'warnCommentChanges' => __( "Are you sure you want to do this?\nThe comment changes you made will be lost." ), + 'docTitleComments' => __( 'Comments' ), + /* translators: %s: comments count */ + 'docTitleCommentsCount' => __( 'Comments (%s)' ), + ) + ); - $scripts->add( 'xfn', "/wp-admin/js/xfn$suffix.js", array('jquery'), false, 1 ); + $scripts->add( 'xfn', "/wp-admin/js/xfn$suffix.js", array( 'jquery' ), false, 1 ); - $scripts->add( 'postbox', "/wp-admin/js/postbox$suffix.js", array('jquery-ui-sortable'), false, 1 ); - did_action( 'init' ) && $scripts->localize( 'postbox', 'postBoxL10n', array( - 'postBoxEmptyString' => __( 'Drag boxes here' ), - ) ); + $scripts->add( 'postbox', "/wp-admin/js/postbox$suffix.js", array( 'jquery-ui-sortable' ), false, 1 ); + did_action( 'init' ) && $scripts->localize( + 'postbox', 'postBoxL10n', array( + 'postBoxEmptyString' => __( 'Drag boxes here' ), + ) + ); $scripts->add( 'tags-box', "/wp-admin/js/tags-box$suffix.js", array( 'jquery', 'tags-suggest' ), false, 1 ); $scripts->add( 'tags-suggest', "/wp-admin/js/tags-suggest$suffix.js", array( 'jquery-ui-autocomplete', 'wp-a11y' ), false, 1 ); - did_action( 'init' ) && $scripts->localize( 'tags-suggest', 'tagsSuggestL10n', array( - 'tagDelimiter' => _x( ',', 'tag delimiter' ), - 'removeTerm' => __( 'Remove term:' ), - 'termSelected' => __( 'Term selected.' ), - 'termAdded' => __( 'Term added.' ), - 'termRemoved' => __( 'Term removed.' ), - ) ); + did_action( 'init' ) && $scripts->localize( + 'tags-suggest', 'tagsSuggestL10n', array( + 'tagDelimiter' => _x( ',', 'tag delimiter' ), + 'removeTerm' => __( 'Remove term:' ), + 'termSelected' => __( 'Term selected.' ), + 'termAdded' => __( 'Term added.' ), + 'termRemoved' => __( 'Term removed.' ), + ) + ); $scripts->add( 'post', "/wp-admin/js/post$suffix.js", array( 'suggest', 'wp-lists', 'postbox', 'tags-box', 'underscore', 'word-count', 'wp-a11y' ), false, 1 ); - did_action( 'init' ) && $scripts->localize( 'post', 'postL10n', array( - 'ok' => __('OK'), - 'cancel' => __('Cancel'), - 'publishOn' => __('Publish on:'), - 'publishOnFuture' => __('Schedule for:'), - 'publishOnPast' => __('Published on:'), - /* translators: 1: month, 2: day, 3: year, 4: hour, 5: minute */ - 'dateFormat' => __('%1$s %2$s, %3$s @ %4$s:%5$s'), - 'showcomm' => __('Show more comments'), - 'endcomm' => __('No more comments found.'), - 'publish' => __('Publish'), - 'schedule' => _x('Schedule', 'post action/button label'), - 'update' => __('Update'), - 'savePending' => __('Save as Pending'), - 'saveDraft' => __('Save Draft'), - 'private' => __('Private'), - 'public' => __('Public'), - 'publicSticky' => __('Public, Sticky'), - 'password' => __('Password Protected'), - 'privatelyPublished' => __('Privately Published'), - 'published' => __('Published'), - 'saveAlert' => __('The changes you made will be lost if you navigate away from this page.'), - 'savingText' => __('Saving Draft…'), - 'permalinkSaved' => __( 'Permalink saved' ), - ) ); + did_action( 'init' ) && $scripts->localize( + 'post', 'postL10n', array( + 'ok' => __( 'OK' ), + 'cancel' => __( 'Cancel' ), + 'publishOn' => __( 'Publish on:' ), + 'publishOnFuture' => __( 'Schedule for:' ), + 'publishOnPast' => __( 'Published on:' ), + /* translators: 1: month, 2: day, 3: year, 4: hour, 5: minute */ + 'dateFormat' => __( '%1$s %2$s, %3$s @ %4$s:%5$s' ), + 'showcomm' => __( 'Show more comments' ), + 'endcomm' => __( 'No more comments found.' ), + 'publish' => __( 'Publish' ), + 'schedule' => _x( 'Schedule', 'post action/button label' ), + 'update' => __( 'Update' ), + 'savePending' => __( 'Save as Pending' ), + 'saveDraft' => __( 'Save Draft' ), + 'private' => __( 'Private' ), + 'public' => __( 'Public' ), + 'publicSticky' => __( 'Public, Sticky' ), + 'password' => __( 'Password Protected' ), + 'privatelyPublished' => __( 'Privately Published' ), + 'published' => __( 'Published' ), + 'saveAlert' => __( 'The changes you made will be lost if you navigate away from this page.' ), + 'savingText' => __( 'Saving Draft…' ), + 'permalinkSaved' => __( 'Permalink saved' ), + ) + ); $scripts->add( 'editor-expand', "/wp-admin/js/editor-expand$suffix.js", array( 'jquery', 'underscore' ), false, 1 ); @@ -708,20 +763,28 @@ function wp_default_scripts( &$scripts ) { $scripts->add( 'comment', "/wp-admin/js/comment$suffix.js", array( 'jquery', 'postbox' ) ); $scripts->add_data( 'comment', 'group', 1 ); - did_action( 'init' ) && $scripts->localize( 'comment', 'commentL10n', array( - 'submittedOn' => __( 'Submitted on:' ), - /* translators: 1: month, 2: day, 3: year, 4: hour, 5: minute */ - 'dateFormat' => __( '%1$s %2$s, %3$s @ %4$s:%5$s' ) - ) ); + did_action( 'init' ) && $scripts->localize( + 'comment', 'commentL10n', array( + 'submittedOn' => __( 'Submitted on:' ), + /* translators: 1: month, 2: day, 3: year, 4: hour, 5: minute */ + 'dateFormat' => __( '%1$s %2$s, %3$s @ %4$s:%5$s' ), + ) + ); $scripts->add( 'admin-gallery', "/wp-admin/js/gallery$suffix.js", array( 'jquery-ui-sortable' ) ); $scripts->add( 'admin-widgets', "/wp-admin/js/widgets$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable' ), false, 1 ); - did_action( 'init' ) && $scripts->add_inline_script( 'admin-widgets', sprintf( 'wpWidgets.l10n = %s;', wp_json_encode( array( - 'save' => __( 'Save' ), - 'saved' => __( 'Saved' ), - 'saveAlert' => __( 'The changes you made will be lost if you navigate away from this page.' ), - ) ) ) ); + did_action( 'init' ) && $scripts->add_inline_script( + 'admin-widgets', sprintf( + 'wpWidgets.l10n = %s;', wp_json_encode( + array( + 'save' => __( 'Save' ), + 'saved' => __( 'Saved' ), + 'saveAlert' => __( 'The changes you made will be lost if you navigate away from this page.' ), + ) + ) + ) + ); $scripts->add( 'media-widgets', "/wp-admin/js/widgets/media-widgets$suffix.js", array( 'jquery', 'media-models', 'media-views', 'wp-api-request' ) ); $scripts->add_inline_script( 'media-widgets', 'wp.mediaWidgets.init();', 'after' ); @@ -736,125 +799,135 @@ function wp_default_scripts( &$scripts ) { $scripts->add( 'theme', "/wp-admin/js/theme$suffix.js", array( 'wp-backbone', 'wp-a11y', 'customize-base' ), false, 1 ); $scripts->add( 'inline-edit-post', "/wp-admin/js/inline-edit-post$suffix.js", array( 'jquery', 'tags-suggest', 'wp-a11y' ), false, 1 ); - did_action( 'init' ) && $scripts->localize( 'inline-edit-post', 'inlineEditL10n', array( - 'error' => __( 'Error while saving the changes.' ), - 'ntdeltitle' => __( 'Remove From Bulk Edit' ), - 'notitle' => __( '(no title)' ), - 'comma' => trim( _x( ',', 'tag delimiter' ) ), - 'saved' => __( 'Changes saved.' ), - ) ); + did_action( 'init' ) && $scripts->localize( + 'inline-edit-post', 'inlineEditL10n', array( + 'error' => __( 'Error while saving the changes.' ), + 'ntdeltitle' => __( 'Remove From Bulk Edit' ), + 'notitle' => __( '(no title)' ), + 'comma' => trim( _x( ',', 'tag delimiter' ) ), + 'saved' => __( 'Changes saved.' ), + ) + ); $scripts->add( 'inline-edit-tax', "/wp-admin/js/inline-edit-tax$suffix.js", array( 'jquery', 'wp-a11y' ), false, 1 ); - did_action( 'init' ) && $scripts->localize( 'inline-edit-tax', 'inlineEditL10n', array( - 'error' => __( 'Error while saving the changes.' ), - 'saved' => __( 'Changes saved.' ), - ) ); + did_action( 'init' ) && $scripts->localize( + 'inline-edit-tax', 'inlineEditL10n', array( + 'error' => __( 'Error while saving the changes.' ), + 'saved' => __( 'Changes saved.' ), + ) + ); $scripts->add( 'plugin-install', "/wp-admin/js/plugin-install$suffix.js", array( 'jquery', 'jquery-ui-core', 'thickbox' ), false, 1 ); - did_action( 'init' ) && $scripts->localize( 'plugin-install', 'plugininstallL10n', array( - 'plugin_information' => __( 'Plugin:' ), - 'plugin_modal_label' => __( 'Plugin details' ), - 'ays' => __('Are you sure you want to install this plugin?') - ) ); + did_action( 'init' ) && $scripts->localize( + 'plugin-install', 'plugininstallL10n', array( + 'plugin_information' => __( 'Plugin:' ), + 'plugin_modal_label' => __( 'Plugin details' ), + 'ays' => __( 'Are you sure you want to install this plugin?' ), + ) + ); $scripts->add( 'updates', "/wp-admin/js/updates$suffix.js", array( 'jquery', 'wp-util', 'wp-a11y' ), false, 1 ); - did_action( 'init' ) && $scripts->localize( 'updates', '_wpUpdatesSettings', array( - 'ajax_nonce' => wp_create_nonce( 'updates' ), - 'l10n' => array( - /* translators: %s: Search string */ - 'searchResults' => __( 'Search results for “%s”' ), - 'searchResultsLabel' => __( 'Search Results' ), - 'noPlugins' => __( 'You do not appear to have any plugins available at this time.' ), - 'noItemsSelected' => __( 'Please select at least one item to perform this action on.' ), - 'updating' => __( 'Updating...' ), // No ellipsis. - 'pluginUpdated' => _x( 'Updated!', 'plugin' ), - 'themeUpdated' => _x( 'Updated!', 'theme' ), - 'update' => __( 'Update' ), - 'updateNow' => __( 'Update Now' ), - /* translators: %s: Plugin name and version */ - 'pluginUpdateNowLabel' => _x( 'Update %s now', 'plugin' ), - 'updateFailedShort' => __( 'Update Failed!' ), - /* translators: %s: Error string for a failed update */ - 'updateFailed' => __( 'Update Failed: %s' ), - /* translators: %s: Plugin name and version */ - 'pluginUpdatingLabel' => _x( 'Updating %s...', 'plugin' ), // No ellipsis. - /* translators: %s: Plugin name and version */ - 'pluginUpdatedLabel' => _x( '%s updated!', 'plugin' ), - /* translators: %s: Plugin name and version */ - 'pluginUpdateFailedLabel' => _x( '%s update failed', 'plugin' ), - /* translators: Accessibility text */ - 'updatingMsg' => __( 'Updating... please wait.' ), // No ellipsis. - /* translators: Accessibility text */ - 'updatedMsg' => __( 'Update completed successfully.' ), - /* translators: Accessibility text */ - 'updateCancel' => __( 'Update canceled.' ), - 'beforeunload' => __( 'Updates may not complete if you navigate away from this page.' ), - 'installNow' => __( 'Install Now' ), - /* translators: %s: Plugin name */ - 'pluginInstallNowLabel' => _x( 'Install %s now', 'plugin' ), - 'installing' => __( 'Installing...' ), - 'pluginInstalled' => _x( 'Installed!', 'plugin' ), - 'themeInstalled' => _x( 'Installed!', 'theme' ), - 'installFailedShort' => __( 'Installation Failed!' ), - /* translators: %s: Error string for a failed installation */ - 'installFailed' => __( 'Installation failed: %s' ), - /* translators: %s: Plugin name and version */ - 'pluginInstallingLabel' => _x( 'Installing %s...', 'plugin' ), // no ellipsis - /* translators: %s: Theme name and version */ - 'themeInstallingLabel' => _x( 'Installing %s...', 'theme' ), // no ellipsis - /* translators: %s: Plugin name and version */ - 'pluginInstalledLabel' => _x( '%s installed!', 'plugin' ), - /* translators: %s: Theme name and version */ - 'themeInstalledLabel' => _x( '%s installed!', 'theme' ), - /* translators: %s: Plugin name and version */ - 'pluginInstallFailedLabel' => _x( '%s installation failed', 'plugin' ), - /* translators: %s: Theme name and version */ - 'themeInstallFailedLabel' => _x( '%s installation failed', 'theme' ), - 'installingMsg' => __( 'Installing... please wait.' ), - 'installedMsg' => __( 'Installation completed successfully.' ), - /* translators: %s: Activation URL */ - 'importerInstalledMsg' => __( 'Importer installed successfully. Run importer' ), - /* translators: %s: Theme name */ - 'aysDelete' => __( 'Are you sure you want to delete %s?' ), - /* translators: %s: Plugin name */ - 'aysDeleteUninstall' => __( 'Are you sure you want to delete %s and its data?' ), - 'aysBulkDelete' => __( 'Are you sure you want to delete the selected plugins and their data?' ), - 'aysBulkDeleteThemes' => __( 'Caution: These themes may be active on other sites in the network. Are you sure you want to proceed?' ), - 'deleting' => __( 'Deleting...' ), - /* translators: %s: Error string for a failed deletion */ - 'deleteFailed' => __( 'Deletion failed: %s' ), - 'pluginDeleted' => _x( 'Deleted!', 'plugin' ), - 'themeDeleted' => _x( 'Deleted!', 'theme' ), - 'livePreview' => __( 'Live Preview' ), - 'activatePlugin' => is_network_admin() ? __( 'Network Activate' ) : __( 'Activate' ), - 'activateTheme' => is_network_admin() ? __( 'Network Enable' ) : __( 'Activate' ), - /* translators: %s: Plugin name */ - 'activatePluginLabel' => is_network_admin() ? _x( 'Network Activate %s', 'plugin' ) : _x( 'Activate %s', 'plugin' ), - /* translators: %s: Theme name */ - 'activateThemeLabel' => is_network_admin() ? _x( 'Network Activate %s', 'theme' ) : _x( 'Activate %s', 'theme' ), - 'activateImporter' => __( 'Run Importer' ), - /* translators: %s: Importer name */ - 'activateImporterLabel' => __( 'Run %s' ), - 'unknownError' => __( 'An unidentified error has occurred.' ), - 'connectionError' => __( 'Connection lost or the server is busy. Please try again later.' ), - 'nonceError' => __( 'An error has occurred. Please reload the page and try again.' ), - 'pluginsFound' => __( 'Number of plugins found: %d' ), - 'noPluginsFound' => __( 'No plugins found. Try a different search.' ), - ), - ) ); + did_action( 'init' ) && $scripts->localize( + 'updates', '_wpUpdatesSettings', array( + 'ajax_nonce' => wp_create_nonce( 'updates' ), + 'l10n' => array( + /* translators: %s: Search string */ + 'searchResults' => __( 'Search results for “%s”' ), + 'searchResultsLabel' => __( 'Search Results' ), + 'noPlugins' => __( 'You do not appear to have any plugins available at this time.' ), + 'noItemsSelected' => __( 'Please select at least one item to perform this action on.' ), + 'updating' => __( 'Updating...' ), // No ellipsis. + 'pluginUpdated' => _x( 'Updated!', 'plugin' ), + 'themeUpdated' => _x( 'Updated!', 'theme' ), + 'update' => __( 'Update' ), + 'updateNow' => __( 'Update Now' ), + /* translators: %s: Plugin name and version */ + 'pluginUpdateNowLabel' => _x( 'Update %s now', 'plugin' ), + 'updateFailedShort' => __( 'Update Failed!' ), + /* translators: %s: Error string for a failed update */ + 'updateFailed' => __( 'Update Failed: %s' ), + /* translators: %s: Plugin name and version */ + 'pluginUpdatingLabel' => _x( 'Updating %s...', 'plugin' ), // No ellipsis. + /* translators: %s: Plugin name and version */ + 'pluginUpdatedLabel' => _x( '%s updated!', 'plugin' ), + /* translators: %s: Plugin name and version */ + 'pluginUpdateFailedLabel' => _x( '%s update failed', 'plugin' ), + /* translators: Accessibility text */ + 'updatingMsg' => __( 'Updating... please wait.' ), // No ellipsis. + /* translators: Accessibility text */ + 'updatedMsg' => __( 'Update completed successfully.' ), + /* translators: Accessibility text */ + 'updateCancel' => __( 'Update canceled.' ), + 'beforeunload' => __( 'Updates may not complete if you navigate away from this page.' ), + 'installNow' => __( 'Install Now' ), + /* translators: %s: Plugin name */ + 'pluginInstallNowLabel' => _x( 'Install %s now', 'plugin' ), + 'installing' => __( 'Installing...' ), + 'pluginInstalled' => _x( 'Installed!', 'plugin' ), + 'themeInstalled' => _x( 'Installed!', 'theme' ), + 'installFailedShort' => __( 'Installation Failed!' ), + /* translators: %s: Error string for a failed installation */ + 'installFailed' => __( 'Installation failed: %s' ), + /* translators: %s: Plugin name and version */ + 'pluginInstallingLabel' => _x( 'Installing %s...', 'plugin' ), // no ellipsis + /* translators: %s: Theme name and version */ + 'themeInstallingLabel' => _x( 'Installing %s...', 'theme' ), // no ellipsis + /* translators: %s: Plugin name and version */ + 'pluginInstalledLabel' => _x( '%s installed!', 'plugin' ), + /* translators: %s: Theme name and version */ + 'themeInstalledLabel' => _x( '%s installed!', 'theme' ), + /* translators: %s: Plugin name and version */ + 'pluginInstallFailedLabel' => _x( '%s installation failed', 'plugin' ), + /* translators: %s: Theme name and version */ + 'themeInstallFailedLabel' => _x( '%s installation failed', 'theme' ), + 'installingMsg' => __( 'Installing... please wait.' ), + 'installedMsg' => __( 'Installation completed successfully.' ), + /* translators: %s: Activation URL */ + 'importerInstalledMsg' => __( 'Importer installed successfully. Run importer' ), + /* translators: %s: Theme name */ + 'aysDelete' => __( 'Are you sure you want to delete %s?' ), + /* translators: %s: Plugin name */ + 'aysDeleteUninstall' => __( 'Are you sure you want to delete %s and its data?' ), + 'aysBulkDelete' => __( 'Are you sure you want to delete the selected plugins and their data?' ), + 'aysBulkDeleteThemes' => __( 'Caution: These themes may be active on other sites in the network. Are you sure you want to proceed?' ), + 'deleting' => __( 'Deleting...' ), + /* translators: %s: Error string for a failed deletion */ + 'deleteFailed' => __( 'Deletion failed: %s' ), + 'pluginDeleted' => _x( 'Deleted!', 'plugin' ), + 'themeDeleted' => _x( 'Deleted!', 'theme' ), + 'livePreview' => __( 'Live Preview' ), + 'activatePlugin' => is_network_admin() ? __( 'Network Activate' ) : __( 'Activate' ), + 'activateTheme' => is_network_admin() ? __( 'Network Enable' ) : __( 'Activate' ), + /* translators: %s: Plugin name */ + 'activatePluginLabel' => is_network_admin() ? _x( 'Network Activate %s', 'plugin' ) : _x( 'Activate %s', 'plugin' ), + /* translators: %s: Theme name */ + 'activateThemeLabel' => is_network_admin() ? _x( 'Network Activate %s', 'theme' ) : _x( 'Activate %s', 'theme' ), + 'activateImporter' => __( 'Run Importer' ), + /* translators: %s: Importer name */ + 'activateImporterLabel' => __( 'Run %s' ), + 'unknownError' => __( 'An unidentified error has occurred.' ), + 'connectionError' => __( 'Connection lost or the server is busy. Please try again later.' ), + 'nonceError' => __( 'An error has occurred. Please reload the page and try again.' ), + 'pluginsFound' => __( 'Number of plugins found: %d' ), + 'noPluginsFound' => __( 'No plugins found. Try a different search.' ), + ), + ) + ); - $scripts->add( 'farbtastic', '/wp-admin/js/farbtastic.js', array('jquery'), '1.2' ); + $scripts->add( 'farbtastic', '/wp-admin/js/farbtastic.js', array( 'jquery' ), '1.2' ); $scripts->add( 'iris', '/wp-admin/js/iris.min.js', array( 'jquery-ui-draggable', 'jquery-ui-slider', 'jquery-touch-punch' ), '1.0.7', 1 ); $scripts->add( 'wp-color-picker', "/wp-admin/js/color-picker$suffix.js", array( 'iris' ), false, 1 ); - did_action( 'init' ) && $scripts->localize( 'wp-color-picker', 'wpColorPickerL10n', array( - 'clear' => __( 'Clear' ), - 'clearAriaLabel' => __( 'Clear color' ), - 'defaultString' => __( 'Default' ), - 'defaultAriaLabel' => __( 'Select default color' ), - 'pick' => __( 'Select Color' ), - 'defaultLabel' => __( 'Color value' ), - ) ); + did_action( 'init' ) && $scripts->localize( + 'wp-color-picker', 'wpColorPickerL10n', array( + 'clear' => __( 'Clear' ), + 'clearAriaLabel' => __( 'Clear color' ), + 'defaultString' => __( 'Default' ), + 'defaultAriaLabel' => __( 'Select default color' ), + 'pick' => __( 'Select Color' ), + 'defaultLabel' => __( 'Color value' ), + ) + ); $scripts->add( 'dashboard', "/wp-admin/js/dashboard$suffix.js", array( 'jquery', 'admin-comments', 'postbox', 'wp-util', 'wp-a11y' ), false, 1 ); @@ -862,35 +935,43 @@ function wp_default_scripts( &$scripts ) { $scripts->add( 'media-grid', "/wp-includes/js/media-grid$suffix.js", array( 'media-editor' ), false, 1 ); $scripts->add( 'media', "/wp-admin/js/media$suffix.js", array( 'jquery' ), false, 1 ); - did_action( 'init' ) && $scripts->localize( 'media', 'attachMediaBoxL10n', array( - 'error' => __( 'An error has occurred. Please reload the page and try again.' ), - )); + did_action( 'init' ) && $scripts->localize( + 'media', 'attachMediaBoxL10n', array( + 'error' => __( 'An error has occurred. Please reload the page and try again.' ), + ) + ); - $scripts->add( 'image-edit', "/wp-admin/js/image-edit$suffix.js", array('jquery', 'json2', 'imgareaselect'), false, 1 ); - did_action( 'init' ) && $scripts->localize( 'image-edit', 'imageEditL10n', array( - 'error' => __( 'Could not load the preview image. Please reload the page and try again.' ) - )); + $scripts->add( 'image-edit', "/wp-admin/js/image-edit$suffix.js", array( 'jquery', 'json2', 'imgareaselect' ), false, 1 ); + did_action( 'init' ) && $scripts->localize( + 'image-edit', 'imageEditL10n', array( + 'error' => __( 'Could not load the preview image. Please reload the page and try again.' ), + ) + ); $scripts->add( 'set-post-thumbnail', "/wp-admin/js/set-post-thumbnail$suffix.js", array( 'jquery' ), false, 1 ); - did_action( 'init' ) && $scripts->localize( 'set-post-thumbnail', 'setPostThumbnailL10n', array( - 'setThumbnail' => __( 'Use as featured image' ), - 'saving' => __( 'Saving...' ), // no ellipsis - 'error' => __( 'Could not set that as the thumbnail image. Try a different attachment.' ), - 'done' => __( 'Done' ) - ) ); + did_action( 'init' ) && $scripts->localize( + 'set-post-thumbnail', 'setPostThumbnailL10n', array( + 'setThumbnail' => __( 'Use as featured image' ), + 'saving' => __( 'Saving...' ), // no ellipsis + 'error' => __( 'Could not set that as the thumbnail image. Try a different attachment.' ), + 'done' => __( 'Done' ), + ) + ); // Navigation Menus $scripts->add( 'nav-menu', "/wp-admin/js/nav-menu$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'wp-lists', 'postbox', 'json2' ) ); - did_action( 'init' ) && $scripts->localize( 'nav-menu', 'navMenuL10n', array( - 'noResultsFound' => __( 'No results found.' ), - 'warnDeleteMenu' => __( "You are about to permanently delete this menu. \n 'Cancel' to stop, 'OK' to delete." ), - 'saveAlert' => __( 'The changes you made will be lost if you navigate away from this page.' ), - 'untitled' => _x( '(no label)', 'missing menu item navigation label' ) - ) ); + did_action( 'init' ) && $scripts->localize( + 'nav-menu', 'navMenuL10n', array( + 'noResultsFound' => __( 'No results found.' ), + 'warnDeleteMenu' => __( "You are about to permanently delete this menu. \n 'Cancel' to stop, 'OK' to delete." ), + 'saveAlert' => __( 'The changes you made will be lost if you navigate away from this page.' ), + 'untitled' => _x( '(no label)', 'missing menu item navigation label' ), + ) + ); - $scripts->add( 'custom-header', "/wp-admin/js/custom-header.js", array( 'jquery-masonry' ), false, 1 ); + $scripts->add( 'custom-header', '/wp-admin/js/custom-header.js', array( 'jquery-masonry' ), false, 1 ); $scripts->add( 'custom-background', "/wp-admin/js/custom-background$suffix.js", array( 'wp-color-picker', 'media-views' ), false, 1 ); - $scripts->add( 'media-gallery', "/wp-admin/js/media-gallery$suffix.js", array('jquery'), false, 1 ); + $scripts->add( 'media-gallery', "/wp-admin/js/media-gallery$suffix.js", array( 'jquery' ), false, 1 ); $scripts->add( 'svg-painter', '/wp-admin/js/svg-painter.js', array( 'jquery' ), false, 1 ); } @@ -914,17 +995,19 @@ function wp_default_scripts( &$scripts ) { function wp_default_styles( &$styles ) { include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version - if ( ! defined( 'SCRIPT_DEBUG' ) ) + if ( ! defined( 'SCRIPT_DEBUG' ) ) { define( 'SCRIPT_DEBUG', false !== strpos( $wp_version, '-src' ) ); + } - if ( ! $guessurl = site_url() ) + if ( ! $guessurl = site_url() ) { $guessurl = wp_guess_url(); + } - $styles->base_url = $guessurl; - $styles->content_url = defined('WP_CONTENT_URL')? WP_CONTENT_URL : ''; + $styles->base_url = $guessurl; + $styles->content_url = defined( 'WP_CONTENT_URL' ) ? WP_CONTENT_URL : ''; $styles->default_version = get_bloginfo( 'version' ); - $styles->text_direction = function_exists( 'is_rtl' ) && is_rtl() ? 'rtl' : 'ltr'; - $styles->default_dirs = array('/wp-admin/', '/wp-includes/css/'); + $styles->text_direction = function_exists( 'is_rtl' ) && is_rtl() ? 'rtl' : 'ltr'; + $styles->default_dirs = array( '/wp-admin/', '/wp-includes/css/' ); // Open Sans is no longer used by core, but may be relied upon by themes and plugins. $open_sans_font_url = ''; @@ -958,74 +1041,99 @@ function wp_default_styles( &$styles ) { $suffix = SCRIPT_DEBUG ? '' : '.min'; // Admin CSS - $styles->add( 'common', "/wp-admin/css/common$suffix.css" ); - $styles->add( 'forms', "/wp-admin/css/forms$suffix.css" ); - $styles->add( 'admin-menu', "/wp-admin/css/admin-menu$suffix.css" ); - $styles->add( 'dashboard', "/wp-admin/css/dashboard$suffix.css" ); - $styles->add( 'list-tables', "/wp-admin/css/list-tables$suffix.css" ); - $styles->add( 'edit', "/wp-admin/css/edit$suffix.css" ); - $styles->add( 'revisions', "/wp-admin/css/revisions$suffix.css" ); - $styles->add( 'media', "/wp-admin/css/media$suffix.css" ); - $styles->add( 'themes', "/wp-admin/css/themes$suffix.css" ); - $styles->add( 'about', "/wp-admin/css/about$suffix.css" ); - $styles->add( 'nav-menus', "/wp-admin/css/nav-menus$suffix.css" ); - $styles->add( 'widgets', "/wp-admin/css/widgets$suffix.css", array( 'wp-pointer' ) ); - $styles->add( 'site-icon', "/wp-admin/css/site-icon$suffix.css" ); - $styles->add( 'l10n', "/wp-admin/css/l10n$suffix.css" ); - $styles->add( 'code-editor', "/wp-admin/css/code-editor$suffix.css", array( 'wp-codemirror' ) ); + $styles->add( 'common', "/wp-admin/css/common$suffix.css" ); + $styles->add( 'forms', "/wp-admin/css/forms$suffix.css" ); + $styles->add( 'admin-menu', "/wp-admin/css/admin-menu$suffix.css" ); + $styles->add( 'dashboard', "/wp-admin/css/dashboard$suffix.css" ); + $styles->add( 'list-tables', "/wp-admin/css/list-tables$suffix.css" ); + $styles->add( 'edit', "/wp-admin/css/edit$suffix.css" ); + $styles->add( 'revisions', "/wp-admin/css/revisions$suffix.css" ); + $styles->add( 'media', "/wp-admin/css/media$suffix.css" ); + $styles->add( 'themes', "/wp-admin/css/themes$suffix.css" ); + $styles->add( 'about', "/wp-admin/css/about$suffix.css" ); + $styles->add( 'nav-menus', "/wp-admin/css/nav-menus$suffix.css" ); + $styles->add( 'widgets', "/wp-admin/css/widgets$suffix.css", array( 'wp-pointer' ) ); + $styles->add( 'site-icon', "/wp-admin/css/site-icon$suffix.css" ); + $styles->add( 'l10n', "/wp-admin/css/l10n$suffix.css" ); + $styles->add( 'code-editor', "/wp-admin/css/code-editor$suffix.css", array( 'wp-codemirror' ) ); $styles->add( 'wp-admin', false, array( 'dashicons', 'common', 'forms', 'admin-menu', 'dashboard', 'list-tables', 'edit', 'revisions', 'media', 'themes', 'about', 'nav-menus', 'widgets', 'site-icon', 'l10n' ) ); - $styles->add( 'login', "/wp-admin/css/login$suffix.css", array( 'dashicons', 'buttons', 'forms', 'l10n' ) ); - $styles->add( 'install', "/wp-admin/css/install$suffix.css", array( 'buttons' ) ); - $styles->add( 'wp-color-picker', "/wp-admin/css/color-picker$suffix.css" ); - $styles->add( 'customize-controls', "/wp-admin/css/customize-controls$suffix.css", array( 'wp-admin', 'colors', 'ie', 'imgareaselect' ) ); - $styles->add( 'customize-widgets', "/wp-admin/css/customize-widgets$suffix.css", array( 'wp-admin', 'colors' ) ); + $styles->add( 'login', "/wp-admin/css/login$suffix.css", array( 'dashicons', 'buttons', 'forms', 'l10n' ) ); + $styles->add( 'install', "/wp-admin/css/install$suffix.css", array( 'buttons' ) ); + $styles->add( 'wp-color-picker', "/wp-admin/css/color-picker$suffix.css" ); + $styles->add( 'customize-controls', "/wp-admin/css/customize-controls$suffix.css", array( 'wp-admin', 'colors', 'ie', 'imgareaselect' ) ); + $styles->add( 'customize-widgets', "/wp-admin/css/customize-widgets$suffix.css", array( 'wp-admin', 'colors' ) ); $styles->add( 'customize-nav-menus', "/wp-admin/css/customize-nav-menus$suffix.css", array( 'wp-admin', 'colors' ) ); $styles->add( 'ie', "/wp-admin/css/ie$suffix.css" ); $styles->add_data( 'ie', 'conditional', 'lte IE 7' ); // Common dependencies - $styles->add( 'buttons', "/wp-includes/css/buttons$suffix.css" ); + $styles->add( 'buttons', "/wp-includes/css/buttons$suffix.css" ); $styles->add( 'dashicons', "/wp-includes/css/dashicons$suffix.css" ); // Includes CSS - $styles->add( 'admin-bar', "/wp-includes/css/admin-bar$suffix.css", array( 'dashicons' ) ); - $styles->add( 'wp-auth-check', "/wp-includes/css/wp-auth-check$suffix.css", array( 'dashicons' ) ); - $styles->add( 'editor-buttons', "/wp-includes/css/editor$suffix.css", array( 'dashicons' ) ); - $styles->add( 'media-views', "/wp-includes/css/media-views$suffix.css", array( 'buttons', 'dashicons', 'wp-mediaelement' ) ); - $styles->add( 'wp-pointer', "/wp-includes/css/wp-pointer$suffix.css", array( 'dashicons' ) ); - $styles->add( 'customize-preview', "/wp-includes/css/customize-preview$suffix.css", array( 'dashicons' ) ); + $styles->add( 'admin-bar', "/wp-includes/css/admin-bar$suffix.css", array( 'dashicons' ) ); + $styles->add( 'wp-auth-check', "/wp-includes/css/wp-auth-check$suffix.css", array( 'dashicons' ) ); + $styles->add( 'editor-buttons', "/wp-includes/css/editor$suffix.css", array( 'dashicons' ) ); + $styles->add( 'media-views', "/wp-includes/css/media-views$suffix.css", array( 'buttons', 'dashicons', 'wp-mediaelement' ) ); + $styles->add( 'wp-pointer', "/wp-includes/css/wp-pointer$suffix.css", array( 'dashicons' ) ); + $styles->add( 'customize-preview', "/wp-includes/css/customize-preview$suffix.css", array( 'dashicons' ) ); $styles->add( 'wp-embed-template-ie', "/wp-includes/css/wp-embed-template-ie$suffix.css" ); $styles->add_data( 'wp-embed-template-ie', 'conditional', 'lte IE 8' ); // External libraries and friends - $styles->add( 'imgareaselect', '/wp-includes/js/imgareaselect/imgareaselect.css', array(), '0.9.8' ); + $styles->add( 'imgareaselect', '/wp-includes/js/imgareaselect/imgareaselect.css', array(), '0.9.8' ); $styles->add( 'wp-jquery-ui-dialog', "/wp-includes/css/jquery-ui-dialog$suffix.css", array( 'dashicons' ) ); - $styles->add( 'mediaelement', "/wp-includes/js/mediaelement/mediaelementplayer-legacy.min.css", array(), '4.2.6-78496d1' ); - $styles->add( 'wp-mediaelement', "/wp-includes/js/mediaelement/wp-mediaelement$suffix.css", array( 'mediaelement' ) ); - $styles->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.css', array( 'dashicons' ) ); - $styles->add( 'wp-codemirror', '/wp-includes/js/codemirror/codemirror.min.css', array(), '5.29.1-alpha-ee20357' ); + $styles->add( 'mediaelement', '/wp-includes/js/mediaelement/mediaelementplayer-legacy.min.css', array(), '4.2.6-78496d1' ); + $styles->add( 'wp-mediaelement', "/wp-includes/js/mediaelement/wp-mediaelement$suffix.css", array( 'mediaelement' ) ); + $styles->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.css', array( 'dashicons' ) ); + $styles->add( 'wp-codemirror', '/wp-includes/js/codemirror/codemirror.min.css', array(), '5.29.1-alpha-ee20357' ); // Deprecated CSS $styles->add( 'deprecated-media', "/wp-admin/css/deprecated-media$suffix.css" ); - $styles->add( 'farbtastic', "/wp-admin/css/farbtastic$suffix.css", array(), '1.3u1' ); - $styles->add( 'jcrop', "/wp-includes/js/jcrop/jquery.Jcrop.min.css", array(), '0.9.12' ); + $styles->add( 'farbtastic', "/wp-admin/css/farbtastic$suffix.css", array(), '1.3u1' ); + $styles->add( 'jcrop', '/wp-includes/js/jcrop/jquery.Jcrop.min.css', array(), '0.9.12' ); $styles->add( 'colors-fresh', false, array( 'wp-admin', 'buttons' ) ); // Old handle. $styles->add( 'open-sans', $open_sans_font_url ); // No longer used in core as of 4.6 // RTL CSS $rtl_styles = array( // wp-admin - 'common', 'forms', 'admin-menu', 'dashboard', 'list-tables', 'edit', 'revisions', 'media', 'themes', 'about', 'nav-menus', - 'widgets', 'site-icon', 'l10n', 'install', 'wp-color-picker', 'customize-controls', 'customize-widgets', 'customize-nav-menus', 'customize-preview', - 'ie', 'login', + 'common', + 'forms', + 'admin-menu', + 'dashboard', + 'list-tables', + 'edit', + 'revisions', + 'media', + 'themes', + 'about', + 'nav-menus', + 'widgets', + 'site-icon', + 'l10n', + 'install', + 'wp-color-picker', + 'customize-controls', + 'customize-widgets', + 'customize-nav-menus', + 'customize-preview', + 'ie', + 'login', // wp-includes - 'buttons', 'admin-bar', 'wp-auth-check', 'editor-buttons', 'media-views', 'wp-pointer', + 'buttons', + 'admin-bar', + 'wp-auth-check', + 'editor-buttons', + 'media-views', + 'wp-pointer', 'wp-jquery-ui-dialog', // deprecated - 'deprecated-media', 'farbtastic', + 'deprecated-media', + 'farbtastic', ); foreach ( $rtl_styles as $rtl_style ) { @@ -1045,16 +1153,19 @@ function wp_default_styles( &$styles ) { * @return array Reordered array, if needed. */ function wp_prototype_before_jquery( $js_array ) { - if ( false === $prototype = array_search( 'prototype', $js_array, true ) ) + if ( false === $prototype = array_search( 'prototype', $js_array, true ) ) { return $js_array; + } - if ( false === $jquery = array_search( 'jquery', $js_array, true ) ) + if ( false === $jquery = array_search( 'jquery', $js_array, true ) ) { return $js_array; + } - if ( $prototype < $jquery ) + if ( $prototype < $jquery ) { return $js_array; + } - unset($js_array[$prototype]); + unset( $js_array[ $prototype ] ); array_splice( $js_array, $jquery, 0, 'prototype' ); @@ -1070,24 +1181,30 @@ function wp_prototype_before_jquery( $js_array ) { */ function wp_just_in_time_script_localization() { - wp_localize_script( 'autosave', 'autosaveL10n', array( - 'autosaveInterval' => AUTOSAVE_INTERVAL, - 'blog_id' => get_current_blog_id(), - ) ); + wp_localize_script( + 'autosave', 'autosaveL10n', array( + 'autosaveInterval' => AUTOSAVE_INTERVAL, + 'blog_id' => get_current_blog_id(), + ) + ); - wp_localize_script( 'mce-view', 'mceViewL10n', array( - 'shortcodes' => ! empty( $GLOBALS['shortcode_tags'] ) ? array_keys( $GLOBALS['shortcode_tags'] ) : array() - ) ); + wp_localize_script( + 'mce-view', 'mceViewL10n', array( + 'shortcodes' => ! empty( $GLOBALS['shortcode_tags'] ) ? array_keys( $GLOBALS['shortcode_tags'] ) : array(), + ) + ); - wp_localize_script( 'word-count', 'wordCountL10n', array( - /* - * translators: If your word count is based on single characters (e.g. East Asian characters), - * enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'. - * Do not translate into your own language. - */ - 'type' => _x( 'words', 'Word count type. Do not translate!' ), - 'shortcodes' => ! empty( $GLOBALS['shortcode_tags'] ) ? array_keys( $GLOBALS['shortcode_tags'] ) : array() - ) ); + wp_localize_script( + 'word-count', 'wordCountL10n', array( + /* + * translators: If your word count is based on single characters (e.g. East Asian characters), + * enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'. + * Do not translate into your own language. + */ + 'type' => _x( 'words', 'Word count type. Do not translate!' ), + 'shortcodes' => ! empty( $GLOBALS['shortcode_tags'] ) ? array_keys( $GLOBALS['shortcode_tags'] ) : array(), + ) + ); } /** @@ -1109,32 +1226,48 @@ function wp_localize_jquery_ui_datepicker() { // Convert the PHP date format into jQuery UI's format. $datepicker_date_format = str_replace( array( - 'd', 'j', 'l', 'z', // Day. - 'F', 'M', 'n', 'm', // Month. - 'Y', 'y' // Year. + 'd', + 'j', + 'l', + 'z', // Day. + 'F', + 'M', + 'n', + 'm', // Month. + 'Y', + 'y', // Year. ), array( - 'dd', 'd', 'DD', 'o', - 'MM', 'M', 'm', 'mm', - 'yy', 'y' + 'dd', + 'd', + 'DD', + 'o', + 'MM', + 'M', + 'm', + 'mm', + 'yy', + 'y', ), get_option( 'date_format' ) ); - $datepicker_defaults = wp_json_encode( array( - 'closeText' => __( 'Close' ), - 'currentText' => __( 'Today' ), - 'monthNames' => array_values( $wp_locale->month ), - 'monthNamesShort' => array_values( $wp_locale->month_abbrev ), - 'nextText' => __( 'Next' ), - 'prevText' => __( 'Previous' ), - 'dayNames' => array_values( $wp_locale->weekday ), - 'dayNamesShort' => array_values( $wp_locale->weekday_abbrev ), - 'dayNamesMin' => array_values( $wp_locale->weekday_initial ), - 'dateFormat' => $datepicker_date_format, - 'firstDay' => absint( get_option( 'start_of_week' ) ), - 'isRTL' => $wp_locale->is_rtl(), - ) ); + $datepicker_defaults = wp_json_encode( + array( + 'closeText' => __( 'Close' ), + 'currentText' => __( 'Today' ), + 'monthNames' => array_values( $wp_locale->month ), + 'monthNamesShort' => array_values( $wp_locale->month_abbrev ), + 'nextText' => __( 'Next' ), + 'prevText' => __( 'Previous' ), + 'dayNames' => array_values( $wp_locale->weekday ), + 'dayNamesShort' => array_values( $wp_locale->weekday_abbrev ), + 'dayNamesMin' => array_values( $wp_locale->weekday_initial ), + 'dateFormat' => $datepicker_date_format, + 'firstDay' => absint( get_option( 'start_of_week' ) ), + 'isRTL' => $wp_locale->is_rtl(), + ) + ); wp_add_inline_script( 'jquery-ui-datepicker', "jQuery(document).ready(function(jQuery){jQuery.datepicker.setDefaults({$datepicker_defaults});});" ); } @@ -1170,37 +1303,39 @@ function wp_localize_community_events() { $events_client = new WP_Community_Events( $user_id, $saved_location ); - wp_localize_script( 'dashboard', 'communityEventsData', array( - 'nonce' => wp_create_nonce( 'community_events' ), - 'cache' => $events_client->get_cached_events(), + wp_localize_script( + 'dashboard', 'communityEventsData', array( + 'nonce' => wp_create_nonce( 'community_events' ), + 'cache' => $events_client->get_cached_events(), - 'l10n' => array( - 'enter_closest_city' => __( 'Enter your closest city to find nearby events.' ), - 'error_occurred_please_try_again' => __( 'An error occurred. Please try again.' ), - 'attend_event_near_generic' => __( 'Attend an upcoming event near you.' ), + 'l10n' => array( + 'enter_closest_city' => __( 'Enter your closest city to find nearby events.' ), + 'error_occurred_please_try_again' => __( 'An error occurred. Please try again.' ), + 'attend_event_near_generic' => __( 'Attend an upcoming event near you.' ), - /* - * These specific examples were chosen to highlight the fact that a - * state is not needed, even for cities whose name is not unique. - * It would be too cumbersome to include that in the instructions - * to the user, so it's left as an implication. - */ - /* translators: %s is the name of the city we couldn't locate. - * Replace the examples with cities related to your locale. Test that - * they match the expected location and have upcoming events before - * including them. If no cities related to your locale have events, - * then use cities related to your locale that would be recognizable - * to most users. Use only the city name itself, without any region - * or country. Use the endonym (native locale name) instead of the - * English name if possible. - */ - 'could_not_locate_city' => __( 'We couldn’t locate %s. Please try another nearby city. For example: Kansas City; Springfield; Portland.' ), + /* + * These specific examples were chosen to highlight the fact that a + * state is not needed, even for cities whose name is not unique. + * It would be too cumbersome to include that in the instructions + * to the user, so it's left as an implication. + */ + /* translators: %s is the name of the city we couldn't locate. + * Replace the examples with cities related to your locale. Test that + * they match the expected location and have upcoming events before + * including them. If no cities related to your locale have events, + * then use cities related to your locale that would be recognizable + * to most users. Use only the city name itself, without any region + * or country. Use the endonym (native locale name) instead of the + * English name if possible. + */ + 'could_not_locate_city' => __( 'We couldn’t locate %s. Please try another nearby city. For example: Kansas City; Springfield; Portland.' ), - // This one is only used with wp.a11y.speak(), so it can/should be more brief. - /* translators: %s: the name of a city */ - 'city_updated' => __( 'City updated. Listing events near %s.' ), + // This one is only used with wp.a11y.speak(), so it can/should be more brief. + /* translators: %s: the name of a city */ + 'city_updated' => __( 'City updated. Listing events near %s.' ), + ), ) - ) ); + ); } /** @@ -1226,24 +1361,26 @@ function wp_localize_community_events() { function wp_style_loader_src( $src, $handle ) { global $_wp_admin_css_colors; - if ( wp_installing() ) + if ( wp_installing() ) { return preg_replace( '#^wp-admin/#', './', $src ); + } if ( 'colors' == $handle ) { - $color = get_user_option('admin_color'); + $color = get_user_option( 'admin_color' ); - if ( empty($color) || !isset($_wp_admin_css_colors[$color]) ) + if ( empty( $color ) || ! isset( $_wp_admin_css_colors[ $color ] ) ) { $color = 'fresh'; + } - $color = $_wp_admin_css_colors[$color]; - $url = $color->url; + $color = $_wp_admin_css_colors[ $color ]; + $url = $color->url; if ( ! $url ) { return false; } $parsed = parse_url( $src ); - if ( isset($parsed['query']) && $parsed['query'] ) { + if ( isset( $parsed['query'] ) && $parsed['query'] ) { wp_parse_str( $parsed['query'], $qv ); $url = add_query_arg( $qv, $url ); } @@ -1271,7 +1408,7 @@ function wp_style_loader_src( $src, $handle ) { function print_head_scripts() { global $concatenate_scripts; - if ( ! did_action('wp_print_scripts') ) { + if ( ! did_action( 'wp_print_scripts' ) ) { /** This action is documented in wp-includes/functions.wp-scripts.php */ do_action( 'wp_print_scripts' ); } @@ -1344,12 +1481,13 @@ function _print_scripts() { global $wp_scripts, $compress_scripts; $zip = $compress_scripts ? 1 : 0; - if ( $zip && defined('ENFORCE_GZIP') && ENFORCE_GZIP ) + if ( $zip && defined( 'ENFORCE_GZIP' ) && ENFORCE_GZIP ) { $zip = 'gzip'; + } if ( $concat = trim( $wp_scripts->concat, ', ' ) ) { - if ( !empty($wp_scripts->print_code) ) { + if ( ! empty( $wp_scripts->print_code ) ) { echo "\n\n"; + echo "\n"; } - if ( !empty($wp_scripts->print_html) ) + if ( ! empty( $wp_scripts->print_html ) ) { echo $wp_scripts->print_html; + } } /** @@ -1381,7 +1520,7 @@ function _print_scripts() { * @return array */ function wp_print_head_scripts() { - if ( ! did_action('wp_print_scripts') ) { + if ( ! did_action( 'wp_print_scripts' ) ) { /** This action is documented in wp-includes/functions.wp-scripts.php */ do_action( 'wp_print_scripts' ); } @@ -1451,7 +1590,7 @@ function print_admin_styles() { script_concat_settings(); $wp_styles->do_concat = $concatenate_scripts; - $wp_styles->do_items(false); + $wp_styles->do_items( false ); /** * Filters whether to print the admin styles. @@ -1518,8 +1657,9 @@ function _print_styles() { $wp_styles = wp_styles(); $zip = $compress_css ? 1 : 0; - if ( $zip && defined('ENFORCE_GZIP') && ENFORCE_GZIP ) + if ( $zip && defined( 'ENFORCE_GZIP' ) && ENFORCE_GZIP ) { $zip = 'gzip'; + } if ( $concat = trim( $wp_styles->concat, ', ' ) ) { $dir = $wp_styles->text_direction; @@ -1529,17 +1669,18 @@ function _print_styles() { $concat = 'load%5B%5D=' . implode( '&load%5B%5D=', $concat ); $href = $wp_styles->base_url . "/wp-admin/load-styles.php?c={$zip}&dir={$dir}&" . $concat . '&ver=' . $ver; - echo "\n"; + echo "\n"; - if ( !empty($wp_styles->print_code) ) { + if ( ! empty( $wp_styles->print_code ) ) { echo "\n"; } } - if ( !empty($wp_styles->print_html) ) + if ( ! empty( $wp_styles->print_html ) ) { echo $wp_styles->print_html; + } } /** @@ -1554,23 +1695,26 @@ function _print_styles() { function script_concat_settings() { global $concatenate_scripts, $compress_scripts, $compress_css; - $compressed_output = ( ini_get('zlib.output_compression') || 'ob_gzhandler' == ini_get('output_handler') ); + $compressed_output = ( ini_get( 'zlib.output_compression' ) || 'ob_gzhandler' == ini_get( 'output_handler' ) ); - if ( ! isset($concatenate_scripts) ) { - $concatenate_scripts = defined('CONCATENATE_SCRIPTS') ? CONCATENATE_SCRIPTS : true; - if ( ( ! is_admin() && ! did_action( 'login_init' ) ) || ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) ) + if ( ! isset( $concatenate_scripts ) ) { + $concatenate_scripts = defined( 'CONCATENATE_SCRIPTS' ) ? CONCATENATE_SCRIPTS : true; + if ( ( ! is_admin() && ! did_action( 'login_init' ) ) || ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ) { $concatenate_scripts = false; + } } - if ( ! isset($compress_scripts) ) { - $compress_scripts = defined('COMPRESS_SCRIPTS') ? COMPRESS_SCRIPTS : true; - if ( $compress_scripts && ( ! get_site_option('can_compress_scripts') || $compressed_output ) ) + if ( ! isset( $compress_scripts ) ) { + $compress_scripts = defined( 'COMPRESS_SCRIPTS' ) ? COMPRESS_SCRIPTS : true; + if ( $compress_scripts && ( ! get_site_option( 'can_compress_scripts' ) || $compressed_output ) ) { $compress_scripts = false; + } } - if ( ! isset($compress_css) ) { - $compress_css = defined('COMPRESS_CSS') ? COMPRESS_CSS : true; - if ( $compress_css && ( ! get_site_option('can_compress_scripts') || $compressed_output ) ) + if ( ! isset( $compress_css ) ) { + $compress_css = defined( 'COMPRESS_CSS' ) ? COMPRESS_CSS : true; + if ( $compress_css && ( ! get_site_option( 'can_compress_scripts' ) || $compressed_output ) ) { $compress_css = false; + } } } diff --git a/wp-includes/session.php b/wp-includes/session.php index d9175c9895..3a8411a90b 100644 --- a/wp-includes/session.php +++ b/wp-includes/session.php @@ -8,4 +8,4 @@ _deprecated_file( basename( __FILE__ ), '4.7.0' ); require_once( ABSPATH . WPINC . '/class-wp-session-tokens.php' ); -require_once( ABSPATH . WPINC . '/class-wp-user-meta-session-tokens.php' ); \ No newline at end of file +require_once( ABSPATH . WPINC . '/class-wp-user-meta-session-tokens.php' ); diff --git a/wp-includes/shortcodes.php b/wp-includes/shortcodes.php index 61d6054f67..da583251d8 100644 --- a/wp-includes/shortcodes.php +++ b/wp-includes/shortcodes.php @@ -88,10 +88,10 @@ function add_shortcode( $tag, $callback ) { * * @param string $tag Shortcode tag to remove hook for. */ -function remove_shortcode($tag) { +function remove_shortcode( $tag ) { global $shortcode_tags; - unset($shortcode_tags[$tag]); + unset( $shortcode_tags[ $tag ] ); } /** @@ -144,8 +144,9 @@ function has_shortcode( $content, $tag ) { if ( shortcode_exists( $tag ) ) { preg_match_all( '/' . get_shortcode_regex() . '/', $content, $matches, PREG_SET_ORDER ); - if ( empty( $matches ) ) + if ( empty( $matches ) ) { return false; + } foreach ( $matches as $shortcode ) { if ( $tag === $shortcode[2] ) { @@ -180,8 +181,9 @@ function do_shortcode( $content, $ignore_html = false ) { return $content; } - if (empty($shortcode_tags) || !is_array($shortcode_tags)) + if ( empty( $shortcode_tags ) || ! is_array( $shortcode_tags ) ) { return $content; + } // Find all registered tag names in $content. preg_match_all( '@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches ); @@ -231,7 +233,7 @@ function get_shortcode_regex( $tagnames = null ) { if ( empty( $tagnames ) ) { $tagnames = array_keys( $shortcode_tags ); } - $tagregexp = join( '|', array_map('preg_quote', $tagnames) ); + $tagregexp = join( '|', array_map( 'preg_quote', $tagnames ) ); // WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcode_tag() // Also, see shortcode_unautop() and shortcode.js. @@ -271,6 +273,7 @@ function get_shortcode_regex( $tagnames = null ) { /** * Regular Expression callable for do_shortcode() for calling shortcode hook. + * * @see get_shortcode_regex for details of the match array contents. * * @since 2.5.0 @@ -286,10 +289,10 @@ function do_shortcode_tag( $m ) { // allow [[foo]] syntax for escaping a tag if ( $m[1] == '[' && $m[6] == ']' ) { - return substr($m[0], 1, -1); + return substr( $m[0], 1, -1 ); } - $tag = $m[2]; + $tag = $m[2]; $attr = shortcode_parse_atts( $m[3] ); if ( ! is_callable( $shortcode_tags[ $tag ] ) ) { @@ -351,9 +354,15 @@ function do_shortcode_tag( $m ) { */ function do_shortcodes_in_html_tags( $content, $ignore_html, $tagnames ) { // Normalize entities in unfiltered HTML before adding placeholders. - $trans = array( '[' => '[', ']' => ']' ); + $trans = array( + '[' => '[', + ']' => ']', + ); $content = strtr( $content, $trans ); - $trans = array( '[' => '[', ']' => ']' ); + $trans = array( + '[' => '[', + ']' => ']', + ); $pattern = get_shortcode_regex( $tagnames ); $textarr = wp_html_split( $content ); @@ -363,7 +372,7 @@ function do_shortcodes_in_html_tags( $content, $ignore_html, $tagnames ) { continue; } - $noopen = false === strpos( $element, '[' ); + $noopen = false === strpos( $element, '[' ); $noclose = false === strpos( $element, ']' ); if ( $noopen || $noclose ) { // This element does not contain shortcodes. @@ -393,15 +402,15 @@ function do_shortcodes_in_html_tags( $content, $ignore_html, $tagnames ) { } // Get element name - $front = array_shift( $attributes ); - $back = array_pop( $attributes ); + $front = array_shift( $attributes ); + $back = array_pop( $attributes ); $matches = array(); - preg_match('%[a-zA-Z0-9]+%', $front, $matches); + preg_match( '%[a-zA-Z0-9]+%', $front, $matches ); $elname = $matches[0]; // Look for shortcodes in each attribute separately. foreach ( $attributes as &$attr ) { - $open = strpos( $attr, '[' ); + $open = strpos( $attr, '[' ); $close = strpos( $attr, ']' ); if ( false === $open || false === $close ) { continue; // Go to next attribute. Square braces will be escaped at end of loop. @@ -417,7 +426,7 @@ function do_shortcodes_in_html_tags( $content, $ignore_html, $tagnames ) { } else { // $attr like 'name = "[shortcode]"' or "name = '[shortcode]'" // We do not know if $content was unfiltered. Assume KSES ran before shortcodes. - $count = 0; + $count = 0; $new_attr = preg_replace_callback( "/$pattern/", 'do_shortcode_tag', $attr, -1, $count ); if ( $count > 0 ) { // Sanitize the shortcode output using KSES. @@ -449,11 +458,14 @@ function do_shortcodes_in_html_tags( $content, $ignore_html, $tagnames ) { * @return string Content with placeholders removed. */ function unescape_invalid_shortcodes( $content ) { - // Clean up entire string, avoids re-parsing HTML. - $trans = array( '[' => '[', ']' => ']' ); - $content = strtr( $content, $trans ); + // Clean up entire string, avoids re-parsing HTML. + $trans = array( + '[' => '[', + ']' => ']', + ); + $content = strtr( $content, $trans ); - return $content; + return $content; } /** @@ -482,28 +494,29 @@ function get_shortcode_atts_regex() { * Returns empty string if trim( $text ) == ''. * All other matches are checked for not empty(). */ -function shortcode_parse_atts($text) { - $atts = array(); +function shortcode_parse_atts( $text ) { + $atts = array(); $pattern = get_shortcode_atts_regex(); - $text = preg_replace("/[\x{00a0}\x{200b}]+/u", " ", $text); - if ( preg_match_all($pattern, $text, $match, PREG_SET_ORDER) ) { - foreach ($match as $m) { - if (!empty($m[1])) - $atts[strtolower($m[1])] = stripcslashes($m[2]); - elseif (!empty($m[3])) - $atts[strtolower($m[3])] = stripcslashes($m[4]); - elseif (!empty($m[5])) - $atts[strtolower($m[5])] = stripcslashes($m[6]); - elseif (isset($m[7]) && strlen($m[7])) - $atts[] = stripcslashes($m[7]); - elseif (isset($m[8]) && strlen($m[8])) - $atts[] = stripcslashes($m[8]); - elseif (isset($m[9])) - $atts[] = stripcslashes($m[9]); + $text = preg_replace( "/[\x{00a0}\x{200b}]+/u", ' ', $text ); + if ( preg_match_all( $pattern, $text, $match, PREG_SET_ORDER ) ) { + foreach ( $match as $m ) { + if ( ! empty( $m[1] ) ) { + $atts[ strtolower( $m[1] ) ] = stripcslashes( $m[2] ); + } elseif ( ! empty( $m[3] ) ) { + $atts[ strtolower( $m[3] ) ] = stripcslashes( $m[4] ); + } elseif ( ! empty( $m[5] ) ) { + $atts[ strtolower( $m[5] ) ] = stripcslashes( $m[6] ); + } elseif ( isset( $m[7] ) && strlen( $m[7] ) ) { + $atts[] = stripcslashes( $m[7] ); + } elseif ( isset( $m[8] ) && strlen( $m[8] ) ) { + $atts[] = stripcslashes( $m[8] ); + } elseif ( isset( $m[9] ) ) { + $atts[] = stripcslashes( $m[9] ); + } } // Reject any unclosed HTML elements - foreach( $atts as &$value ) { + foreach ( $atts as &$value ) { if ( false !== strpos( $value, '<' ) ) { if ( 1 !== preg_match( '/^[^<]*+(?:<[^>]*+>[^<]*+)*+$/', $value ) ) { $value = ''; @@ -511,7 +524,7 @@ function shortcode_parse_atts($text) { } } } else { - $atts = ltrim($text); + $atts = ltrim( $text ); } return $atts; } @@ -534,13 +547,14 @@ function shortcode_parse_atts($text) { * @return array Combined and filtered attribute list. */ function shortcode_atts( $pairs, $atts, $shortcode = '' ) { - $atts = (array)$atts; - $out = array(); - foreach ($pairs as $name => $default) { - if ( array_key_exists($name, $atts) ) - $out[$name] = $atts[$name]; - else - $out[$name] = $default; + $atts = (array) $atts; + $out = array(); + foreach ( $pairs as $name => $default ) { + if ( array_key_exists( $name, $atts ) ) { + $out[ $name ] = $atts[ $name ]; + } else { + $out[ $name ] = $default; + } } /** * Filters a shortcode's default attributes. @@ -580,8 +594,9 @@ function strip_shortcodes( $content ) { return $content; } - if (empty($shortcode_tags) || !is_array($shortcode_tags)) + if ( empty( $shortcode_tags ) || ! is_array( $shortcode_tags ) ) { return $content; + } // Find all registered tag names in $content. preg_match_all( '@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches ); @@ -626,7 +641,7 @@ function strip_shortcodes( $content ) { function strip_shortcode_tag( $m ) { // allow [[foo]] syntax for escaping a tag if ( $m[1] == '[' && $m[6] == ']' ) { - return substr($m[0], 1, -1); + return substr( $m[0], 1, -1 ); } return $m[1] . $m[6]; diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index bdbeb3dc9d..293b18b8b6 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -25,7 +25,11 @@ function create_initial_taxonomies() { global $wp_rewrite; if ( ! did_action( 'init' ) ) { - $rewrite = array( 'category' => false, 'post_tag' => false, 'post_format' => false ); + $rewrite = array( + 'category' => false, + 'post_tag' => false, + 'post_format' => false, + ); } else { /** @@ -36,118 +40,128 @@ function create_initial_taxonomies() { * @param string $context Context of the rewrite base. Default 'type'. */ $post_format_base = apply_filters( 'post_format_rewrite_base', 'type' ); - $rewrite = array( - 'category' => array( + $rewrite = array( + 'category' => array( 'hierarchical' => true, - 'slug' => get_option('category_base') ? get_option('category_base') : 'category', - 'with_front' => ! get_option('category_base') || $wp_rewrite->using_index_permalinks(), - 'ep_mask' => EP_CATEGORIES, + 'slug' => get_option( 'category_base' ) ? get_option( 'category_base' ) : 'category', + 'with_front' => ! get_option( 'category_base' ) || $wp_rewrite->using_index_permalinks(), + 'ep_mask' => EP_CATEGORIES, ), - 'post_tag' => array( + 'post_tag' => array( 'hierarchical' => false, - 'slug' => get_option('tag_base') ? get_option('tag_base') : 'tag', - 'with_front' => ! get_option('tag_base') || $wp_rewrite->using_index_permalinks(), - 'ep_mask' => EP_TAGS, + 'slug' => get_option( 'tag_base' ) ? get_option( 'tag_base' ) : 'tag', + 'with_front' => ! get_option( 'tag_base' ) || $wp_rewrite->using_index_permalinks(), + 'ep_mask' => EP_TAGS, ), 'post_format' => $post_format_base ? array( 'slug' => $post_format_base ) : false, ); } - register_taxonomy( 'category', 'post', array( - 'hierarchical' => true, - 'query_var' => 'category_name', - 'rewrite' => $rewrite['category'], - 'public' => true, - 'show_ui' => true, - 'show_admin_column' => true, - '_builtin' => true, - 'capabilities' => array( - 'manage_terms' => 'manage_categories', - 'edit_terms' => 'edit_categories', - 'delete_terms' => 'delete_categories', - 'assign_terms' => 'assign_categories', - ), - 'show_in_rest' => true, - 'rest_base' => 'categories', - 'rest_controller_class' => 'WP_REST_Terms_Controller', - ) ); + register_taxonomy( + 'category', 'post', array( + 'hierarchical' => true, + 'query_var' => 'category_name', + 'rewrite' => $rewrite['category'], + 'public' => true, + 'show_ui' => true, + 'show_admin_column' => true, + '_builtin' => true, + 'capabilities' => array( + 'manage_terms' => 'manage_categories', + 'edit_terms' => 'edit_categories', + 'delete_terms' => 'delete_categories', + 'assign_terms' => 'assign_categories', + ), + 'show_in_rest' => true, + 'rest_base' => 'categories', + 'rest_controller_class' => 'WP_REST_Terms_Controller', + ) + ); - register_taxonomy( 'post_tag', 'post', array( - 'hierarchical' => false, - 'query_var' => 'tag', - 'rewrite' => $rewrite['post_tag'], - 'public' => true, - 'show_ui' => true, - 'show_admin_column' => true, - '_builtin' => true, - 'capabilities' => array( - 'manage_terms' => 'manage_post_tags', - 'edit_terms' => 'edit_post_tags', - 'delete_terms' => 'delete_post_tags', - 'assign_terms' => 'assign_post_tags', - ), - 'show_in_rest' => true, - 'rest_base' => 'tags', - 'rest_controller_class' => 'WP_REST_Terms_Controller', - ) ); + register_taxonomy( + 'post_tag', 'post', array( + 'hierarchical' => false, + 'query_var' => 'tag', + 'rewrite' => $rewrite['post_tag'], + 'public' => true, + 'show_ui' => true, + 'show_admin_column' => true, + '_builtin' => true, + 'capabilities' => array( + 'manage_terms' => 'manage_post_tags', + 'edit_terms' => 'edit_post_tags', + 'delete_terms' => 'delete_post_tags', + 'assign_terms' => 'assign_post_tags', + ), + 'show_in_rest' => true, + 'rest_base' => 'tags', + 'rest_controller_class' => 'WP_REST_Terms_Controller', + ) + ); - register_taxonomy( 'nav_menu', 'nav_menu_item', array( - 'public' => false, - 'hierarchical' => false, - 'labels' => array( - 'name' => __( 'Navigation Menus' ), - 'singular_name' => __( 'Navigation Menu' ), - ), - 'query_var' => false, - 'rewrite' => false, - 'show_ui' => false, - '_builtin' => true, - 'show_in_nav_menus' => false, - ) ); + register_taxonomy( + 'nav_menu', 'nav_menu_item', array( + 'public' => false, + 'hierarchical' => false, + 'labels' => array( + 'name' => __( 'Navigation Menus' ), + 'singular_name' => __( 'Navigation Menu' ), + ), + 'query_var' => false, + 'rewrite' => false, + 'show_ui' => false, + '_builtin' => true, + 'show_in_nav_menus' => false, + ) + ); - register_taxonomy( 'link_category', 'link', array( - 'hierarchical' => false, - 'labels' => array( - 'name' => __( 'Link Categories' ), - 'singular_name' => __( 'Link Category' ), - 'search_items' => __( 'Search Link Categories' ), - 'popular_items' => null, - 'all_items' => __( 'All Link Categories' ), - 'edit_item' => __( 'Edit Link Category' ), - 'update_item' => __( 'Update Link Category' ), - 'add_new_item' => __( 'Add New Link Category' ), - 'new_item_name' => __( 'New Link Category Name' ), - 'separate_items_with_commas' => null, - 'add_or_remove_items' => null, - 'choose_from_most_used' => null, - 'back_to_items' => __( '← Back to Link Categories' ), - ), - 'capabilities' => array( - 'manage_terms' => 'manage_links', - 'edit_terms' => 'manage_links', - 'delete_terms' => 'manage_links', - 'assign_terms' => 'manage_links', - ), - 'query_var' => false, - 'rewrite' => false, - 'public' => false, - 'show_ui' => true, - '_builtin' => true, - ) ); + register_taxonomy( + 'link_category', 'link', array( + 'hierarchical' => false, + 'labels' => array( + 'name' => __( 'Link Categories' ), + 'singular_name' => __( 'Link Category' ), + 'search_items' => __( 'Search Link Categories' ), + 'popular_items' => null, + 'all_items' => __( 'All Link Categories' ), + 'edit_item' => __( 'Edit Link Category' ), + 'update_item' => __( 'Update Link Category' ), + 'add_new_item' => __( 'Add New Link Category' ), + 'new_item_name' => __( 'New Link Category Name' ), + 'separate_items_with_commas' => null, + 'add_or_remove_items' => null, + 'choose_from_most_used' => null, + 'back_to_items' => __( '← Back to Link Categories' ), + ), + 'capabilities' => array( + 'manage_terms' => 'manage_links', + 'edit_terms' => 'manage_links', + 'delete_terms' => 'manage_links', + 'assign_terms' => 'manage_links', + ), + 'query_var' => false, + 'rewrite' => false, + 'public' => false, + 'show_ui' => true, + '_builtin' => true, + ) + ); - register_taxonomy( 'post_format', 'post', array( - 'public' => true, - 'hierarchical' => false, - 'labels' => array( - 'name' => _x( 'Format', 'post format' ), - 'singular_name' => _x( 'Format', 'post format' ), - ), - 'query_var' => true, - 'rewrite' => $rewrite['post_format'], - 'show_ui' => false, - '_builtin' => true, - 'show_in_nav_menus' => current_theme_supports( 'post-formats' ), - ) ); + register_taxonomy( + 'post_format', 'post', array( + 'public' => true, + 'hierarchical' => false, + 'labels' => array( + 'name' => _x( 'Format', 'post format' ), + 'singular_name' => _x( 'Format', 'post format' ), + ), + 'query_var' => true, + 'rewrite' => $rewrite['post_format'], + 'show_ui' => false, + '_builtin' => true, + 'show_in_nav_menus' => current_theme_supports( 'post-formats' ), + ) + ); } /** @@ -169,9 +183,9 @@ function create_initial_taxonomies() { function get_taxonomies( $args = array(), $output = 'names', $operator = 'and' ) { global $wp_taxonomies; - $field = ('names' == $output) ? 'name' : false; + $field = ( 'names' == $output ) ? 'name' : false; - return wp_filter_object_list($wp_taxonomies, $args, $operator, $field); + return wp_filter_object_list( $wp_taxonomies, $args, $operator, $field ); } /** @@ -198,9 +212,10 @@ function get_taxonomies( $args = array(), $output = 'names', $operator = 'and' ) function get_object_taxonomies( $object, $output = 'names' ) { global $wp_taxonomies; - if ( is_object($object) ) { - if ( $object->post_type == 'attachment' ) + if ( is_object( $object ) ) { + if ( $object->post_type == 'attachment' ) { return get_attachment_taxonomies( $object, $output ); + } $object = $object->post_type; } @@ -208,11 +223,12 @@ function get_object_taxonomies( $object, $output = 'names' ) { $taxonomies = array(); foreach ( (array) $wp_taxonomies as $tax_name => $tax_obj ) { - if ( array_intersect($object, (array) $tax_obj->object_type) ) { - if ( 'names' == $output ) + if ( array_intersect( $object, (array) $tax_obj->object_type ) ) { + if ( 'names' == $output ) { $taxonomies[] = $tax_name; - else + } else { $taxonomies[ $tax_name ] = $tax_obj; + } } } @@ -235,10 +251,11 @@ function get_object_taxonomies( $object, $output = 'names' ) { function get_taxonomy( $taxonomy ) { global $wp_taxonomies; - if ( ! taxonomy_exists( $taxonomy ) ) + if ( ! taxonomy_exists( $taxonomy ) ) { return false; + } - return $wp_taxonomies[$taxonomy]; + return $wp_taxonomies[ $taxonomy ]; } /** @@ -256,7 +273,7 @@ function get_taxonomy( $taxonomy ) { function taxonomy_exists( $taxonomy ) { global $wp_taxonomies; - return isset( $wp_taxonomies[$taxonomy] ); + return isset( $wp_taxonomies[ $taxonomy ] ); } /** @@ -272,11 +289,12 @@ function taxonomy_exists( $taxonomy ) { * @param string $taxonomy Name of taxonomy object. * @return bool Whether the taxonomy is hierarchical. */ -function is_taxonomy_hierarchical($taxonomy) { - if ( ! taxonomy_exists($taxonomy) ) +function is_taxonomy_hierarchical( $taxonomy ) { + if ( ! taxonomy_exists( $taxonomy ) ) { return false; + } - $taxonomy = get_taxonomy($taxonomy); + $taxonomy = get_taxonomy( $taxonomy ); return $taxonomy->hierarchical; } @@ -376,8 +394,9 @@ function is_taxonomy_hierarchical($taxonomy) { function register_taxonomy( $taxonomy, $object_type, $args = array() ) { global $wp_taxonomies; - if ( ! is_array( $wp_taxonomies ) ) + if ( ! is_array( $wp_taxonomies ) ) { $wp_taxonomies = array(); + } $args = wp_parse_args( $args ); @@ -393,7 +412,6 @@ function register_taxonomy( $taxonomy, $object_type, $args = array() ) { $taxonomy_object->add_hooks(); - /** * Fires after a taxonomy is registered. * @@ -499,35 +517,37 @@ function unregister_taxonomy( $taxonomy ) { function get_taxonomy_labels( $tax ) { $tax->labels = (array) $tax->labels; - if ( isset( $tax->helps ) && empty( $tax->labels['separate_items_with_commas'] ) ) + if ( isset( $tax->helps ) && empty( $tax->labels['separate_items_with_commas'] ) ) { $tax->labels['separate_items_with_commas'] = $tax->helps; + } - if ( isset( $tax->no_tagcloud ) && empty( $tax->labels['not_found'] ) ) + if ( isset( $tax->no_tagcloud ) && empty( $tax->labels['not_found'] ) ) { $tax->labels['not_found'] = $tax->no_tagcloud; + } $nohier_vs_hier_defaults = array( - 'name' => array( _x( 'Tags', 'taxonomy general name' ), _x( 'Categories', 'taxonomy general name' ) ), - 'singular_name' => array( _x( 'Tag', 'taxonomy singular name' ), _x( 'Category', 'taxonomy singular name' ) ), - 'search_items' => array( __( 'Search Tags' ), __( 'Search Categories' ) ), - 'popular_items' => array( __( 'Popular Tags' ), null ), - 'all_items' => array( __( 'All Tags' ), __( 'All Categories' ) ), - 'parent_item' => array( null, __( 'Parent Category' ) ), - 'parent_item_colon' => array( null, __( 'Parent Category:' ) ), - 'edit_item' => array( __( 'Edit Tag' ), __( 'Edit Category' ) ), - 'view_item' => array( __( 'View Tag' ), __( 'View Category' ) ), - 'update_item' => array( __( 'Update Tag' ), __( 'Update Category' ) ), - 'add_new_item' => array( __( 'Add New Tag' ), __( 'Add New Category' ) ), - 'new_item_name' => array( __( 'New Tag Name' ), __( 'New Category Name' ) ), + 'name' => array( _x( 'Tags', 'taxonomy general name' ), _x( 'Categories', 'taxonomy general name' ) ), + 'singular_name' => array( _x( 'Tag', 'taxonomy singular name' ), _x( 'Category', 'taxonomy singular name' ) ), + 'search_items' => array( __( 'Search Tags' ), __( 'Search Categories' ) ), + 'popular_items' => array( __( 'Popular Tags' ), null ), + 'all_items' => array( __( 'All Tags' ), __( 'All Categories' ) ), + 'parent_item' => array( null, __( 'Parent Category' ) ), + 'parent_item_colon' => array( null, __( 'Parent Category:' ) ), + 'edit_item' => array( __( 'Edit Tag' ), __( 'Edit Category' ) ), + 'view_item' => array( __( 'View Tag' ), __( 'View Category' ) ), + 'update_item' => array( __( 'Update Tag' ), __( 'Update Category' ) ), + 'add_new_item' => array( __( 'Add New Tag' ), __( 'Add New Category' ) ), + 'new_item_name' => array( __( 'New Tag Name' ), __( 'New Category Name' ) ), 'separate_items_with_commas' => array( __( 'Separate tags with commas' ), null ), - 'add_or_remove_items' => array( __( 'Add or remove tags' ), null ), - 'choose_from_most_used' => array( __( 'Choose from the most used tags' ), null ), - 'not_found' => array( __( 'No tags found.' ), __( 'No categories found.' ) ), - 'no_terms' => array( __( 'No tags' ), __( 'No categories' ) ), - 'items_list_navigation' => array( __( 'Tags list navigation' ), __( 'Categories list navigation' ) ), - 'items_list' => array( __( 'Tags list' ), __( 'Categories list' ) ), + 'add_or_remove_items' => array( __( 'Add or remove tags' ), null ), + 'choose_from_most_used' => array( __( 'Choose from the most used tags' ), null ), + 'not_found' => array( __( 'No tags found.' ), __( 'No categories found.' ) ), + 'no_terms' => array( __( 'No tags' ), __( 'No categories' ) ), + 'items_list_navigation' => array( __( 'Tags list navigation' ), __( 'Categories list navigation' ) ), + 'items_list' => array( __( 'Tags list' ), __( 'Categories list' ) ), /* translators: Tab heading when selecting from the most used terms */ - 'most_used' => array( _x( 'Most Used', 'tags' ), _x( 'Most Used', 'categories' ) ), - 'back_to_items' => array( __( '← Back to Tags' ), __( '← Back to Categories' ) ), + 'most_used' => array( _x( 'Most Used', 'tags' ), _x( 'Most Used', 'categories' ) ), + 'back_to_items' => array( __( '← Back to Tags' ), __( '← Back to Categories' ) ), ); $nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name']; @@ -567,17 +587,20 @@ function get_taxonomy_labels( $tax ) { * @param string $object_type Name of the object type. * @return bool True if successful, false if not. */ -function register_taxonomy_for_object_type( $taxonomy, $object_type) { +function register_taxonomy_for_object_type( $taxonomy, $object_type ) { global $wp_taxonomies; - if ( !isset($wp_taxonomies[$taxonomy]) ) + if ( ! isset( $wp_taxonomies[ $taxonomy ] ) ) { return false; + } - if ( ! get_post_type_object($object_type) ) + if ( ! get_post_type_object( $object_type ) ) { return false; + } - if ( ! in_array( $object_type, $wp_taxonomies[$taxonomy]->object_type ) ) - $wp_taxonomies[$taxonomy]->object_type[] = $object_type; + if ( ! in_array( $object_type, $wp_taxonomies[ $taxonomy ]->object_type ) ) { + $wp_taxonomies[ $taxonomy ]->object_type[] = $object_type; + } // Filter out empties. $wp_taxonomies[ $taxonomy ]->object_type = array_filter( $wp_taxonomies[ $taxonomy ]->object_type ); @@ -599,15 +622,18 @@ function register_taxonomy_for_object_type( $taxonomy, $object_type) { function unregister_taxonomy_for_object_type( $taxonomy, $object_type ) { global $wp_taxonomies; - if ( ! isset( $wp_taxonomies[ $taxonomy ] ) ) + if ( ! isset( $wp_taxonomies[ $taxonomy ] ) ) { return false; + } - if ( ! get_post_type_object( $object_type ) ) + if ( ! get_post_type_object( $object_type ) ) { return false; + } $key = array_search( $object_type, $wp_taxonomies[ $taxonomy ]->object_type, true ); - if ( false === $key ) + if ( false === $key ) { return false; + } unset( $wp_taxonomies[ $taxonomy ]->object_type[ $key ] ); return true; @@ -640,7 +666,7 @@ function unregister_taxonomy_for_object_type( $taxonomy, $object_type ) { * @param string|array $taxonomies String of taxonomy name or Array of string values of taxonomy names. * @param array|string $args Change the order of the object_ids, either ASC or DESC. * @return WP_Error|array If the taxonomy does not exist, then WP_Error will be returned. On success. - * the array can be empty meaning that there are no $object_ids found or it will return the $object_ids found. + * the array can be empty meaning that there are no $object_ids found or it will return the $object_ids found. */ function get_objects_in_term( $term_ids, $taxonomies, $args = array() ) { global $wpdb; @@ -658,20 +684,20 @@ function get_objects_in_term( $term_ids, $taxonomies, $args = array() ) { } $defaults = array( 'order' => 'ASC' ); - $args = wp_parse_args( $args, $defaults ); + $args = wp_parse_args( $args, $defaults ); $order = ( 'desc' == strtolower( $args['order'] ) ) ? 'DESC' : 'ASC'; - $term_ids = array_map('intval', $term_ids ); + $term_ids = array_map( 'intval', $term_ids ); $taxonomies = "'" . implode( "', '", array_map( 'esc_sql', $taxonomies ) ) . "'"; - $term_ids = "'" . implode( "', '", $term_ids ) . "'"; + $term_ids = "'" . implode( "', '", $term_ids ) . "'"; $sql = "SELECT tr.object_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ($taxonomies) AND tt.term_id IN ($term_ids) ORDER BY tr.object_id $order"; $last_changed = wp_cache_get_last_changed( 'terms' ); - $cache_key = 'get_objects_in_term:' . md5( $sql ) . ":$last_changed"; - $cache = wp_cache_get( $cache_key, 'terms' ); + $cache_key = 'get_objects_in_term:' . md5( $sql ) . ":$last_changed"; + $cache = wp_cache_get( $cache_key, 'terms' ); if ( false === $cache ) { $object_ids = $wpdb->get_col( $sql ); wp_cache_set( $cache_key, $object_ids, 'terms' ); @@ -679,7 +705,7 @@ function get_objects_in_term( $term_ids, $taxonomies, $args = array() ) { $object_ids = (array) $cache; } - if ( ! $object_ids ){ + if ( ! $object_ids ) { return array(); } return $object_ids; @@ -887,17 +913,17 @@ function get_term_by( $field, $value, $taxonomy = '', $output = OBJECT, $filter ); switch ( $field ) { - case 'slug' : + case 'slug': $args['slug'] = $value; break; - case 'name' : + case 'name': $args['name'] = $value; break; - case 'term_taxonomy_id' : + case 'term_taxonomy_id': $args['term_taxonomy_id'] = $value; - unset( $args[ 'taxonomy' ] ); + unset( $args['taxonomy'] ); break; - default : + default: return false; } @@ -937,20 +963,22 @@ function get_term_children( $term_id, $taxonomy ) { $term_id = intval( $term_id ); - $terms = _get_term_hierarchy($taxonomy); + $terms = _get_term_hierarchy( $taxonomy ); - if ( ! isset($terms[$term_id]) ) + if ( ! isset( $terms[ $term_id ] ) ) { return array(); + } - $children = $terms[$term_id]; + $children = $terms[ $term_id ]; - foreach ( (array) $terms[$term_id] as $child ) { + foreach ( (array) $terms[ $term_id ] as $child ) { if ( $term_id == $child ) { continue; } - if ( isset($terms[$child]) ) - $children = array_merge($children, get_term_children($child, $taxonomy)); + if ( isset( $terms[ $child ] ) ) { + $children = array_merge( $children, get_term_children( $child, $taxonomy ) ); + } } return $children; @@ -974,14 +1002,17 @@ function get_term_children( $term_id, $taxonomy ) { */ function get_term_field( $field, $term, $taxonomy = '', $context = 'display' ) { $term = get_term( $term, $taxonomy ); - if ( is_wp_error($term) ) + if ( is_wp_error( $term ) ) { return $term; + } - if ( !is_object($term) ) + if ( ! is_object( $term ) ) { return ''; + } - if ( !isset($term->$field) ) + if ( ! isset( $term->$field ) ) { return ''; + } return sanitize_term_field( $field, $term->$field, $term->term_id, $term->taxonomy, $context ); } @@ -1001,13 +1032,15 @@ function get_term_field( $field, $term, $taxonomy = '', $context = 'display' ) { function get_term_to_edit( $id, $taxonomy ) { $term = get_term( $id, $taxonomy ); - if ( is_wp_error($term) ) + if ( is_wp_error( $term ) ) { return $term; + } - if ( !is_object($term) ) + if ( ! is_object( $term ) ) { return ''; + } - return sanitize_term($term, $taxonomy, 'edit'); + return sanitize_term( $term, $taxonomy, 'edit' ); } /** @@ -1073,13 +1106,13 @@ function get_terms( $args = array(), $deprecated = '' ) { * (a) a second non-empty parameter is passed, or * (b) the first parameter shares no keys with the default array (ie, it's a list of taxonomies) */ - $_args = wp_parse_args( $args ); + $_args = wp_parse_args( $args ); $key_intersect = array_intersect_key( $term_query->query_var_defaults, (array) $_args ); $do_legacy_args = $deprecated || empty( $key_intersect ); if ( $do_legacy_args ) { - $taxonomies = (array) $args; - $args = wp_parse_args( $deprecated, $defaults ); + $taxonomies = (array) $args; + $args = wp_parse_args( $deprecated, $defaults ); $args['taxonomy'] = $taxonomies; } else { $args = wp_parse_args( $args, $defaults ); @@ -1145,7 +1178,7 @@ function add_term_meta( $term_id, $meta_key, $meta_value, $unique = false ) { } if ( wp_term_is_shared( $term_id ) ) { - return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.'), $term_id ); + return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.' ), $term_id ); } $added = add_metadata( 'term', $term_id, $meta_key, $meta_value, $unique ); @@ -1227,7 +1260,7 @@ function update_term_meta( $term_id, $meta_key, $meta_value, $prev_value = '' ) } if ( wp_term_is_shared( $term_id ) ) { - return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.'), $term_id ); + return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.' ), $term_id ); } $updated = update_metadata( 'term', $term_id, $meta_key, $meta_value, $prev_value ); @@ -1301,50 +1334,54 @@ function has_term_meta( $term_id ) { function term_exists( $term, $taxonomy = '', $parent = null ) { global $wpdb; - $select = "SELECT term_id FROM $wpdb->terms as t WHERE "; + $select = "SELECT term_id FROM $wpdb->terms as t WHERE "; $tax_select = "SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE "; - if ( is_int($term) ) { - if ( 0 == $term ) + if ( is_int( $term ) ) { + if ( 0 == $term ) { return 0; + } $where = 't.term_id = %d'; - if ( !empty($taxonomy) ) - return $wpdb->get_row( $wpdb->prepare( $tax_select . $where . " AND tt.taxonomy = %s", $term, $taxonomy ), ARRAY_A ); - else + if ( ! empty( $taxonomy ) ) { + return $wpdb->get_row( $wpdb->prepare( $tax_select . $where . ' AND tt.taxonomy = %s', $term, $taxonomy ), ARRAY_A ); + } else { return $wpdb->get_var( $wpdb->prepare( $select . $where, $term ) ); + } } $term = trim( wp_unslash( $term ) ); $slug = sanitize_title( $term ); - $where = 't.slug = %s'; - $else_where = 't.name = %s'; - $where_fields = array($slug); - $else_where_fields = array($term); - $orderby = 'ORDER BY t.term_id ASC'; - $limit = 'LIMIT 1'; - if ( !empty($taxonomy) ) { + $where = 't.slug = %s'; + $else_where = 't.name = %s'; + $where_fields = array( $slug ); + $else_where_fields = array( $term ); + $orderby = 'ORDER BY t.term_id ASC'; + $limit = 'LIMIT 1'; + if ( ! empty( $taxonomy ) ) { if ( is_numeric( $parent ) ) { - $parent = (int) $parent; - $where_fields[] = $parent; + $parent = (int) $parent; + $where_fields[] = $parent; $else_where_fields[] = $parent; - $where .= ' AND tt.parent = %d'; - $else_where .= ' AND tt.parent = %d'; + $where .= ' AND tt.parent = %d'; + $else_where .= ' AND tt.parent = %d'; } - $where_fields[] = $taxonomy; + $where_fields[] = $taxonomy; $else_where_fields[] = $taxonomy; - if ( $result = $wpdb->get_row( $wpdb->prepare("SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $where AND tt.taxonomy = %s $orderby $limit", $where_fields), ARRAY_A) ) + if ( $result = $wpdb->get_row( $wpdb->prepare( "SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $where AND tt.taxonomy = %s $orderby $limit", $where_fields ), ARRAY_A ) ) { return $result; + } - return $wpdb->get_row( $wpdb->prepare("SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $else_where AND tt.taxonomy = %s $orderby $limit", $else_where_fields), ARRAY_A); + return $wpdb->get_row( $wpdb->prepare( "SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $else_where AND tt.taxonomy = %s $orderby $limit", $else_where_fields ), ARRAY_A ); } - if ( $result = $wpdb->get_var( $wpdb->prepare("SELECT term_id FROM $wpdb->terms as t WHERE $where $orderby $limit", $where_fields) ) ) + if ( $result = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms as t WHERE $where $orderby $limit", $where_fields ) ) ) { return $result; + } - return $wpdb->get_var( $wpdb->prepare("SELECT term_id FROM $wpdb->terms as t WHERE $else_where $orderby $limit", $else_where_fields) ); + return $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms as t WHERE $else_where $orderby $limit", $else_where_fields ) ); } /** @@ -1360,15 +1397,19 @@ function term_exists( $term, $taxonomy = '', $parent = null ) { * @return bool Whether `$term2` is a child of `$term1`. */ function term_is_ancestor_of( $term1, $term2, $taxonomy ) { - if ( ! isset( $term1->term_id ) ) + if ( ! isset( $term1->term_id ) ) { $term1 = get_term( $term1, $taxonomy ); - if ( ! isset( $term2->parent ) ) + } + if ( ! isset( $term2->parent ) ) { $term2 = get_term( $term2, $taxonomy ); + } - if ( empty( $term1->term_id ) || empty( $term2->parent ) ) + if ( empty( $term1->term_id ) || empty( $term2->parent ) ) { return false; - if ( $term2->parent == $term1->term_id ) + } + if ( $term2->parent == $term1->term_id ) { return true; + } return term_is_ancestor_of( $term1, get_term( $term2->parent, $taxonomy ), $taxonomy ); } @@ -1390,27 +1431,30 @@ function term_is_ancestor_of( $term1, $term2, $taxonomy ) { * 'display', 'attribute', or 'js'. Default 'display'. * @return array|object Term with all fields sanitized. */ -function sanitize_term($term, $taxonomy, $context = 'display') { +function sanitize_term( $term, $taxonomy, $context = 'display' ) { $fields = array( 'term_id', 'name', 'description', 'slug', 'count', 'parent', 'term_group', 'term_taxonomy_id', 'object_id' ); $do_object = is_object( $term ); - $term_id = $do_object ? $term->term_id : (isset($term['term_id']) ? $term['term_id'] : 0); + $term_id = $do_object ? $term->term_id : ( isset( $term['term_id'] ) ? $term['term_id'] : 0 ); foreach ( (array) $fields as $field ) { if ( $do_object ) { - if ( isset($term->$field) ) - $term->$field = sanitize_term_field($field, $term->$field, $term_id, $taxonomy, $context); + if ( isset( $term->$field ) ) { + $term->$field = sanitize_term_field( $field, $term->$field, $term_id, $taxonomy, $context ); + } } else { - if ( isset($term[$field]) ) - $term[$field] = sanitize_term_field($field, $term[$field], $term_id, $taxonomy, $context); + if ( isset( $term[ $field ] ) ) { + $term[ $field ] = sanitize_term_field( $field, $term[ $field ], $term_id, $taxonomy, $context ); + } } } - if ( $do_object ) + if ( $do_object ) { $term->filter = $context; - else + } else { $term['filter'] = $context; + } return $term; } @@ -1438,16 +1482,18 @@ function sanitize_term($term, $taxonomy, $context = 'display') { * 'attribute', or 'js'. * @return mixed Sanitized field. */ -function sanitize_term_field($field, $value, $term_id, $taxonomy, $context) { +function sanitize_term_field( $field, $value, $term_id, $taxonomy, $context ) { $int_fields = array( 'parent', 'term_id', 'count', 'term_group', 'term_taxonomy_id', 'object_id' ); if ( in_array( $field, $int_fields ) ) { $value = (int) $value; - if ( $value < 0 ) + if ( $value < 0 ) { $value = 0; + } } - if ( 'raw' == $context ) + if ( 'raw' == $context ) { return $value; + } if ( 'edit' == $context ) { @@ -1477,10 +1523,11 @@ function sanitize_term_field($field, $value, $term_id, $taxonomy, $context) { */ $value = apply_filters( "edit_{$taxonomy}_{$field}", $value, $term_id ); - if ( 'description' == $field ) - $value = esc_html($value); // textarea_escaped - else - $value = esc_attr($value); + if ( 'description' == $field ) { + $value = esc_html( $value ); // textarea_escaped + } else { + $value = esc_attr( $value ); + } } elseif ( 'db' == $context ) { /** @@ -1520,7 +1567,6 @@ function sanitize_term_field($field, $value, $term_id, $taxonomy, $context) { */ $value = apply_filters( 'pre_category_nicename', $value ); } - } elseif ( 'rss' == $context ) { /** @@ -1579,9 +1625,9 @@ function sanitize_term_field($field, $value, $term_id, $taxonomy, $context) { } if ( 'attribute' == $context ) { - $value = esc_attr($value); + $value = esc_attr( $value ); } elseif ( 'js' == $context ) { - $value = esc_js($value); + $value = esc_js( $value ); } return $value; } @@ -1599,18 +1645,18 @@ function sanitize_term_field($field, $value, $term_id, $taxonomy, $context) { * @return array|int|WP_Error Number of terms in that taxonomy or WP_Error if the taxonomy does not exist. */ function wp_count_terms( $taxonomy, $args = array() ) { - $defaults = array('hide_empty' => false); - $args = wp_parse_args($args, $defaults); + $defaults = array( 'hide_empty' => false ); + $args = wp_parse_args( $args, $defaults ); // backward compatibility - if ( isset($args['ignore_empty']) ) { + if ( isset( $args['ignore_empty'] ) ) { $args['hide_empty'] = $args['ignore_empty']; - unset($args['ignore_empty']); + unset( $args['ignore_empty'] ); } $args['fields'] = 'count'; - return get_terms($taxonomy, $args); + return get_terms( $taxonomy, $args ); } /** @@ -1628,8 +1674,9 @@ function wp_count_terms( $taxonomy, $args = array() ) { function wp_delete_object_term_relationships( $object_id, $taxonomies ) { $object_id = (int) $object_id; - if ( !is_array($taxonomies) ) - $taxonomies = array($taxonomies); + if ( ! is_array( $taxonomies ) ) { + $taxonomies = array( $taxonomies ); + } foreach ( (array) $taxonomies as $taxonomy ) { $term_ids = wp_get_object_terms( $object_id, $taxonomy, array( 'fields' => 'ids' ) ); @@ -1670,10 +1717,12 @@ function wp_delete_term( $term, $taxonomy, $args = array() ) { $term = (int) $term; - if ( ! $ids = term_exists($term, $taxonomy) ) + if ( ! $ids = term_exists( $term, $taxonomy ) ) { return false; - if ( is_wp_error( $ids ) ) + } + if ( is_wp_error( $ids ) ) { return $ids; + } $tt_id = $ids['term_taxonomy_id']; @@ -1681,11 +1730,12 @@ function wp_delete_term( $term, $taxonomy, $args = array() ) { if ( 'category' == $taxonomy ) { $defaults['default'] = get_option( 'default_category' ); - if ( $defaults['default'] == $term ) + if ( $defaults['default'] == $term ) { return 0; // Don't delete the default category + } } - $args = wp_parse_args($args, $defaults); + $args = wp_parse_args( $args, $defaults ); if ( isset( $args['default'] ) ) { $default = (int) $args['default']; @@ -1709,13 +1759,14 @@ function wp_delete_term( $term, $taxonomy, $args = array() ) { do_action( 'pre_delete_term', $term, $taxonomy ); // Update children to point to new parent - if ( is_taxonomy_hierarchical($taxonomy) ) { - $term_obj = get_term($term, $taxonomy); - if ( is_wp_error( $term_obj ) ) + if ( is_taxonomy_hierarchical( $taxonomy ) ) { + $term_obj = get_term( $term, $taxonomy ); + if ( is_wp_error( $term_obj ) ) { return $term_obj; + } $parent = $term_obj->parent; - $edit_ids = $wpdb->get_results( "SELECT term_id, term_taxonomy_id FROM $wpdb->term_taxonomy WHERE `parent` = " . (int)$term_obj->term_id ); + $edit_ids = $wpdb->get_results( "SELECT term_id, term_taxonomy_id FROM $wpdb->term_taxonomy WHERE `parent` = " . (int) $term_obj->term_id ); $edit_tt_ids = wp_list_pluck( $edit_ids, 'term_taxonomy_id' ); /** @@ -1727,7 +1778,7 @@ function wp_delete_term( $term, $taxonomy, $args = array() ) { */ do_action( 'edit_term_taxonomies', $edit_tt_ids ); - $wpdb->update( $wpdb->term_taxonomy, compact( 'parent' ), array( 'parent' => $term_obj->term_id) + compact( 'taxonomy' ) ); + $wpdb->update( $wpdb->term_taxonomy, compact( 'parent' ), array( 'parent' => $term_obj->term_id ) + compact( 'taxonomy' ) ); // Clean the cache for all child terms. $edit_term_ids = wp_list_pluck( $edit_ids, 'term_id' ); @@ -1749,22 +1800,29 @@ function wp_delete_term( $term, $taxonomy, $args = array() ) { $object_ids = (array) $wpdb->get_col( $wpdb->prepare( "SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $tt_id ) ); foreach ( $object_ids as $object_id ) { - $terms = wp_get_object_terms( $object_id, $taxonomy, array( 'fields' => 'ids', 'orderby' => 'none' ) ); - if ( 1 == count($terms) && isset($default) ) { - $terms = array($default); + $terms = wp_get_object_terms( + $object_id, $taxonomy, array( + 'fields' => 'ids', + 'orderby' => 'none', + ) + ); + if ( 1 == count( $terms ) && isset( $default ) ) { + $terms = array( $default ); } else { - $terms = array_diff($terms, array($term)); - if (isset($default) && isset($force_default) && $force_default) - $terms = array_merge($terms, array($default)); + $terms = array_diff( $terms, array( $term ) ); + if ( isset( $default ) && isset( $force_default ) && $force_default ) { + $terms = array_merge( $terms, array( $default ) ); + } } - $terms = array_map('intval', $terms); + $terms = array_map( 'intval', $terms ); wp_set_object_terms( $object_id, $terms, $taxonomy ); } // Clean the relationship caches for all object types using this term. $tax_object = get_taxonomy( $taxonomy ); - foreach ( $tax_object->object_type as $object_type ) + foreach ( $tax_object->object_type as $object_type ) { clean_object_term_cache( $object_ids, $object_type ); + } $term_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->termmeta WHERE term_id = %d ", $term ) ); foreach ( $term_meta_ids as $mid ) { @@ -1791,10 +1849,11 @@ function wp_delete_term( $term, $taxonomy, $args = array() ) { do_action( 'deleted_term_taxonomy', $tt_id ); // Delete the term if no taxonomies use it. - if ( !$wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_taxonomy WHERE term_id = %d", $term) ) ) + if ( ! $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_taxonomy WHERE term_id = %d", $term ) ) ) { $wpdb->delete( $wpdb->terms, array( 'term_id' => $term ) ); + } - clean_term_cache($term, $taxonomy); + clean_term_cache( $term, $taxonomy ); /** * Fires after a term is deleted from the database and the cache is cleaned. @@ -1838,7 +1897,7 @@ function wp_delete_term( $term, $taxonomy, $args = array() ) { * * @param int $cat_ID Category term ID. * @return bool|int|WP_Error Returns true if completes delete action; false if term doesn't exist; - * Zero on attempted deletion of default Category; WP_Error object is also a possibility. + * Zero on attempted deletion of default Category; WP_Error object is also a possibility. */ function wp_delete_category( $cat_ID ) { return wp_delete_term( $cat_ID, 'category' ); @@ -1860,21 +1919,25 @@ function wp_delete_category( $cat_ID ) { * @return array|WP_Error The requested term data or empty array if no terms found. * WP_Error if any of the $taxonomies don't exist. */ -function wp_get_object_terms($object_ids, $taxonomies, $args = array()) { - if ( empty( $object_ids ) || empty( $taxonomies ) ) +function wp_get_object_terms( $object_ids, $taxonomies, $args = array() ) { + if ( empty( $object_ids ) || empty( $taxonomies ) ) { return array(); - - if ( !is_array($taxonomies) ) - $taxonomies = array($taxonomies); - - foreach ( $taxonomies as $taxonomy ) { - if ( ! taxonomy_exists($taxonomy) ) - return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) ); } - if ( !is_array($object_ids) ) - $object_ids = array($object_ids); - $object_ids = array_map('intval', $object_ids); + if ( ! is_array( $taxonomies ) ) { + $taxonomies = array( $taxonomies ); + } + + foreach ( $taxonomies as $taxonomy ) { + if ( ! taxonomy_exists( $taxonomy ) ) { + return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) ); + } + } + + if ( ! is_array( $object_ids ) ) { + $object_ids = array( $object_ids ); + } + $object_ids = array_map( 'intval', $object_ids ); $args = wp_parse_args( $args ); @@ -1910,7 +1973,7 @@ function wp_get_object_terms($object_ids, $taxonomies, $args = array()) { } } - $args['taxonomy'] = $taxonomies; + $args['taxonomy'] = $taxonomies; $args['object_ids'] = $object_ids; // Taxonomies registered without an 'args' param are handled here. @@ -2004,7 +2067,7 @@ function wp_get_object_terms($object_ids, $taxonomies, $args = array()) { function wp_insert_term( $term, $taxonomy, $args = array() ) { global $wpdb; - if ( ! taxonomy_exists($taxonomy) ) { + if ( ! taxonomy_exists( $taxonomy ) ) { return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) ); } /** @@ -2025,25 +2088,30 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) { if ( '' == trim( $term ) ) { return new WP_Error( 'empty_term_name', __( 'A name is required for this term.' ) ); } - $defaults = array( 'alias_of' => '', 'description' => '', 'parent' => 0, 'slug' => ''); - $args = wp_parse_args( $args, $defaults ); + $defaults = array( + 'alias_of' => '', + 'description' => '', + 'parent' => 0, + 'slug' => '', + ); + $args = wp_parse_args( $args, $defaults ); if ( $args['parent'] > 0 && ! term_exists( (int) $args['parent'] ) ) { return new WP_Error( 'missing_parent', __( 'Parent term does not exist.' ) ); } - $args['name'] = $term; + $args['name'] = $term; $args['taxonomy'] = $taxonomy; // Coerce null description to strings, to avoid database errors. $args['description'] = (string) $args['description']; - $args = sanitize_term($args, $taxonomy, 'db'); + $args = sanitize_term( $args, $taxonomy, 'db' ); // expected_slashed ($name) - $name = wp_unslash( $args['name'] ); + $name = wp_unslash( $args['name'] ); $description = wp_unslash( $args['description'] ); - $parent = (int) $args['parent']; + $parent = (int) $args['parent']; $slug_provided = ! empty( $args['slug'] ); if ( ! $slug_provided ) { @@ -2063,11 +2131,13 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) { * The alias is not in a group, so we create a new one * and add the alias to it. */ - $term_group = $wpdb->get_var("SELECT MAX(term_group) FROM $wpdb->terms") + 1; + $term_group = $wpdb->get_var( "SELECT MAX(term_group) FROM $wpdb->terms" ) + 1; - wp_update_term( $alias->term_id, $taxonomy, array( - 'term_group' => $term_group, - ) ); + wp_update_term( + $alias->term_id, $taxonomy, array( + 'term_group' => $term_group, + ) + ); } } @@ -2075,11 +2145,13 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) { * Prevent the creation of terms with duplicate names at the same level of a taxonomy hierarchy, * unless a unique slug has been explicitly provided. */ - $name_matches = get_terms( $taxonomy, array( - 'name' => $name, - 'hide_empty' => false, - 'parent' => $args['parent'], - ) ); + $name_matches = get_terms( + $taxonomy, array( + 'name' => $name, + 'hide_empty' => false, + 'parent' => $args['parent'], + ) + ); /* * The `name` match in `get_terms()` doesn't differentiate accented characters, @@ -2099,7 +2171,12 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) { $slug_match = get_term_by( 'slug', $slug, $taxonomy ); if ( ! $slug_provided || $name_match->slug === $slug || $slug_match ) { if ( is_taxonomy_hierarchical( $taxonomy ) ) { - $siblings = get_terms( $taxonomy, array( 'get' => 'all', 'parent' => $parent ) ); + $siblings = get_terms( + $taxonomy, array( + 'get' => 'all', + 'parent' => $parent, + ) + ); $existing_term = null; if ( ( ! $slug_provided || $name_match->slug === $slug ) && in_array( $name, wp_list_pluck( $siblings, 'name' ) ) ) { @@ -2139,8 +2216,8 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) { $term_id = (int) $wpdb->insert_id; // Seems unreachable, However, Is used in the case that a term name is provided, which sanitizes to an empty string. - if ( empty($slug) ) { - $slug = sanitize_title($slug, $term_id); + if ( empty( $slug ) ) { + $slug = sanitize_title( $slug, $term_id ); /** This action is documented in wp-includes/taxonomy.php */ do_action( 'edit_terms', $term_id, $taxonomy ); @@ -2152,10 +2229,13 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) { $tt_id = $wpdb->get_var( $wpdb->prepare( "SELECT tt.term_taxonomy_id FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d", $taxonomy, $term_id ) ); - if ( !empty($tt_id) ) { - return array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id); + if ( ! empty( $tt_id ) ) { + return array( + 'term_id' => $term_id, + 'term_taxonomy_id' => $tt_id, + ); } - $wpdb->insert( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent') + array( 'count' => 0 ) ); + $wpdb->insert( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent' ) + array( 'count' => 0 ) ); $tt_id = (int) $wpdb->insert_id; /* @@ -2173,7 +2253,10 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) { $tt_id = (int) $duplicate_term->term_taxonomy_id; clean_term_cache( $term_id, $taxonomy ); - return array( 'term_id' => $term_id, 'term_taxonomy_id' => $tt_id ); + return array( + 'term_id' => $term_id, + 'term_taxonomy_id' => $tt_id, + ); } /** @@ -2185,7 +2268,7 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) { * @param int $tt_id Term taxonomy ID. * @param string $taxonomy Taxonomy slug. */ - do_action( "create_term", $term_id, $tt_id, $taxonomy ); + do_action( 'create_term', $term_id, $tt_id, $taxonomy ); /** * Fires after a new term is created for a specific taxonomy. @@ -2210,7 +2293,7 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) { */ $term_id = apply_filters( 'term_id_filter', $term_id, $tt_id ); - clean_term_cache($term_id, $taxonomy); + clean_term_cache( $term_id, $taxonomy ); /** * Fires after a new term is created, and after the term cache has been cleaned. @@ -2236,7 +2319,10 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) { */ do_action( "created_{$taxonomy}", $term_id, $tt_id ); - return array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id); + return array( + 'term_id' => $term_id, + 'term_taxonomy_id' => $tt_id, + ); } /** @@ -2271,36 +2357,47 @@ function wp_set_object_terms( $object_id, $terms, $taxonomy, $append = false ) { return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) ); } - if ( !is_array($terms) ) - $terms = array($terms); + if ( ! is_array( $terms ) ) { + $terms = array( $terms ); + } - if ( ! $append ) - $old_tt_ids = wp_get_object_terms($object_id, $taxonomy, array('fields' => 'tt_ids', 'orderby' => 'none')); - else + if ( ! $append ) { + $old_tt_ids = wp_get_object_terms( + $object_id, $taxonomy, array( + 'fields' => 'tt_ids', + 'orderby' => 'none', + ) + ); + } else { $old_tt_ids = array(); + } - $tt_ids = array(); - $term_ids = array(); + $tt_ids = array(); + $term_ids = array(); $new_tt_ids = array(); - foreach ( (array) $terms as $term) { - if ( !strlen(trim($term)) ) + foreach ( (array) $terms as $term ) { + if ( ! strlen( trim( $term ) ) ) { continue; - - if ( !$term_info = term_exists($term, $taxonomy) ) { - // Skip if a non-existent term ID is passed. - if ( is_int($term) ) - continue; - $term_info = wp_insert_term($term, $taxonomy); } - if ( is_wp_error($term_info) ) - return $term_info; - $term_ids[] = $term_info['term_id']; - $tt_id = $term_info['term_taxonomy_id']; - $tt_ids[] = $tt_id; - if ( $wpdb->get_var( $wpdb->prepare( "SELECT term_taxonomy_id FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id = %d", $object_id, $tt_id ) ) ) + if ( ! $term_info = term_exists( $term, $taxonomy ) ) { + // Skip if a non-existent term ID is passed. + if ( is_int( $term ) ) { + continue; + } + $term_info = wp_insert_term( $term, $taxonomy ); + } + if ( is_wp_error( $term_info ) ) { + return $term_info; + } + $term_ids[] = $term_info['term_id']; + $tt_id = $term_info['term_taxonomy_id']; + $tt_ids[] = $tt_id; + + if ( $wpdb->get_var( $wpdb->prepare( "SELECT term_taxonomy_id FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id = %d", $object_id, $tt_id ) ) ) { continue; + } /** * Fires immediately before an object-term relationship is added. @@ -2313,7 +2410,12 @@ function wp_set_object_terms( $object_id, $terms, $taxonomy, $append = false ) { * @param string $taxonomy Taxonomy slug. */ do_action( 'add_term_relationship', $object_id, $tt_id, $taxonomy ); - $wpdb->insert( $wpdb->term_relationships, array( 'object_id' => $object_id, 'term_taxonomy_id' => $tt_id ) ); + $wpdb->insert( + $wpdb->term_relationships, array( + 'object_id' => $object_id, + 'term_taxonomy_id' => $tt_id, + ) + ); /** * Fires immediately after an object-term relationship is added. @@ -2329,16 +2431,17 @@ function wp_set_object_terms( $object_id, $terms, $taxonomy, $append = false ) { $new_tt_ids[] = $tt_id; } - if ( $new_tt_ids ) + if ( $new_tt_ids ) { wp_update_term_count( $new_tt_ids, $taxonomy ); + } if ( ! $append ) { $delete_tt_ids = array_diff( $old_tt_ids, $tt_ids ); if ( $delete_tt_ids ) { $in_delete_tt_ids = "'" . implode( "', '", $delete_tt_ids ) . "'"; - $delete_term_ids = $wpdb->get_col( $wpdb->prepare( "SELECT tt.term_id FROM $wpdb->term_taxonomy AS tt WHERE tt.taxonomy = %s AND tt.term_taxonomy_id IN ($in_delete_tt_ids)", $taxonomy ) ); - $delete_term_ids = array_map( 'intval', $delete_term_ids ); + $delete_term_ids = $wpdb->get_col( $wpdb->prepare( "SELECT tt.term_id FROM $wpdb->term_taxonomy AS tt WHERE tt.taxonomy = %s AND tt.term_taxonomy_id IN ($in_delete_tt_ids)", $taxonomy ) ); + $delete_term_ids = array_map( 'intval', $delete_term_ids ); $remove = wp_remove_object_terms( $object_id, $delete_term_ids, $taxonomy ); if ( is_wp_error( $remove ) ) { @@ -2347,17 +2450,21 @@ function wp_set_object_terms( $object_id, $terms, $taxonomy, $append = false ) { } } - $t = get_taxonomy($taxonomy); - if ( ! $append && isset($t->sort) && $t->sort ) { - $values = array(); - $term_order = 0; - $final_tt_ids = wp_get_object_terms($object_id, $taxonomy, array('fields' => 'tt_ids')); - foreach ( $tt_ids as $tt_id ) - if ( in_array($tt_id, $final_tt_ids) ) - $values[] = $wpdb->prepare( "(%d, %d, %d)", $object_id, $tt_id, ++$term_order); - if ( $values ) - if ( false === $wpdb->query( "INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id, term_order) VALUES " . join( ',', $values ) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)" ) ) + $t = get_taxonomy( $taxonomy ); + if ( ! $append && isset( $t->sort ) && $t->sort ) { + $values = array(); + $term_order = 0; + $final_tt_ids = wp_get_object_terms( $object_id, $taxonomy, array( 'fields' => 'tt_ids' ) ); + foreach ( $tt_ids as $tt_id ) { + if ( in_array( $tt_id, $final_tt_ids ) ) { + $values[] = $wpdb->prepare( '(%d, %d, %d)', $object_id, $tt_id, ++$term_order ); + } + } + if ( $values ) { + if ( false === $wpdb->query( "INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id, term_order) VALUES " . join( ',', $values ) . ' ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)' ) ) { return new WP_Error( 'db_insert_error', __( 'Could not insert term relationship into the database.' ), $wpdb->last_error ); + } + } } wp_cache_delete( $object_id, $taxonomy . '_relationships' ); @@ -2504,7 +2611,7 @@ function wp_remove_object_terms( $object_id, $terms, $taxonomy ) { function wp_unique_term_slug( $slug, $term ) { global $wpdb; - $needs_suffix = true; + $needs_suffix = true; $original_slug = $slug; // As of 4.1, duplicate slugs are allowed as long as they're in different taxonomies. @@ -2519,17 +2626,19 @@ function wp_unique_term_slug( $slug, $term ) { $parent_suffix = ''; if ( $needs_suffix && is_taxonomy_hierarchical( $term->taxonomy ) && ! empty( $term->parent ) ) { $the_parent = $term->parent; - while ( ! empty($the_parent) ) { - $parent_term = get_term($the_parent, $term->taxonomy); - if ( is_wp_error($parent_term) || empty($parent_term) ) + while ( ! empty( $the_parent ) ) { + $parent_term = get_term( $the_parent, $term->taxonomy ); + if ( is_wp_error( $parent_term ) || empty( $parent_term ) ) { break; + } $parent_suffix .= '-' . $parent_term->slug; if ( ! term_exists( $slug . $parent_suffix ) ) { break; } - if ( empty($parent_term->parent) ) + if ( empty( $parent_term->parent ) ) { break; + } $the_parent = $parent_term->parent; } } @@ -2549,10 +2658,11 @@ function wp_unique_term_slug( $slug, $term ) { if ( $parent_suffix ) { $slug .= $parent_suffix; } else { - if ( ! empty( $term->term_id ) ) + if ( ! empty( $term->term_id ) ) { $query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s AND term_id != %d", $slug, $term->term_id ); - else + } else { $query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s", $slug ); + } if ( $wpdb->get_var( $query ) ) { $num = 2; @@ -2634,18 +2744,23 @@ function wp_update_term( $term_id, $taxonomy, $args = array() ) { $term = wp_slash( $term ); // Merge old and new args with new args overwriting old ones. - $args = array_merge($term, $args); + $args = array_merge( $term, $args ); - $defaults = array( 'alias_of' => '', 'description' => '', 'parent' => 0, 'slug' => ''); - $args = wp_parse_args($args, $defaults); - $args = sanitize_term($args, $taxonomy, 'db'); + $defaults = array( + 'alias_of' => '', + 'description' => '', + 'parent' => 0, + 'slug' => '', + ); + $args = wp_parse_args( $args, $defaults ); + $args = sanitize_term( $args, $taxonomy, 'db' ); $parsed_args = $args; // expected_slashed ($name) - $name = wp_unslash( $args['name'] ); + $name = wp_unslash( $args['name'] ); $description = wp_unslash( $args['description'] ); - $parsed_args['name'] = $name; + $parsed_args['name'] = $name; $parsed_args['description'] = $description; if ( '' == trim( $name ) ) { @@ -2659,7 +2774,7 @@ function wp_update_term( $term_id, $taxonomy, $args = array() ) { $empty_slug = false; if ( empty( $args['slug'] ) ) { $empty_slug = true; - $slug = sanitize_title($name); + $slug = sanitize_title( $name ); } else { $slug = $args['slug']; } @@ -2677,11 +2792,13 @@ function wp_update_term( $term_id, $taxonomy, $args = array() ) { * The alias is not in a group, so we create a new one * and add the alias to it. */ - $term_group = $wpdb->get_var("SELECT MAX(term_group) FROM $wpdb->terms") + 1; + $term_group = $wpdb->get_var( "SELECT MAX(term_group) FROM $wpdb->terms" ) + 1; - wp_update_term( $alias->term_id, $taxonomy, array( - 'term_group' => $term_group, - ) ); + wp_update_term( + $alias->term_id, $taxonomy, array( + 'term_group' => $term_group, + ) + ); } $parsed_args['term_group'] = $term_group; @@ -2707,15 +2824,15 @@ function wp_update_term( $term_id, $taxonomy, $args = array() ) { if ( $duplicate && $duplicate->term_id != $term_id ) { // If an empty slug was passed or the parent changed, reset the slug to something unique. // Otherwise, bail. - if ( $empty_slug || ( $parent != $term['parent']) ) { - $slug = wp_unique_term_slug($slug, (object) $args); + if ( $empty_slug || ( $parent != $term['parent'] ) ) { + $slug = wp_unique_term_slug( $slug, (object) $args ); } else { /* translators: 1: Taxonomy term slug */ return new WP_Error( 'duplicate_term_slug', sprintf( __( 'The slug “%s” is already in use by another term.' ), $slug ) ); } } - $tt_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT tt.term_taxonomy_id FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d", $taxonomy, $term_id) ); + $tt_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT tt.term_taxonomy_id FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d", $taxonomy, $term_id ) ); // Check whether this is a shared term that needs splitting. $_term_id = _split_shared_term( $term_id, $tt_id ); @@ -2748,8 +2865,8 @@ function wp_update_term( $term_id, $taxonomy, $args = array() ) { $data = apply_filters( 'wp_update_term_data', $data, $term_id, $taxonomy, $args ); $wpdb->update( $wpdb->terms, $data, compact( 'term_id' ) ); - if ( empty($slug) ) { - $slug = sanitize_title($name, $term_id); + if ( empty( $slug ) ) { + $slug = sanitize_title( $name, $term_id ); $wpdb->update( $wpdb->terms, compact( 'slug' ), compact( 'term_id' ) ); } @@ -2794,7 +2911,7 @@ function wp_update_term( $term_id, $taxonomy, $args = array() ) { * @param int $tt_id Term taxonomy ID. * @param string $taxonomy Taxonomy slug. */ - do_action( "edit_term", $term_id, $tt_id, $taxonomy ); + do_action( 'edit_term', $term_id, $tt_id, $taxonomy ); /** * Fires after a term in a specific taxonomy has been updated, but before the term @@ -2812,7 +2929,7 @@ function wp_update_term( $term_id, $taxonomy, $args = array() ) { /** This filter is documented in wp-includes/taxonomy.php */ $term_id = apply_filters( 'term_id_filter', $term_id, $tt_id ); - clean_term_cache($term_id, $taxonomy); + clean_term_cache( $term_id, $taxonomy ); /** * Fires after a term has been updated, and the term cache has been cleaned. @@ -2823,7 +2940,7 @@ function wp_update_term( $term_id, $taxonomy, $args = array() ) { * @param int $tt_id Term taxonomy ID. * @param string $taxonomy Taxonomy slug. */ - do_action( "edited_term", $term_id, $tt_id, $taxonomy ); + do_action( 'edited_term', $term_id, $tt_id, $taxonomy ); /** * Fires after a term for a specific taxonomy has been updated, and the term @@ -2838,7 +2955,10 @@ function wp_update_term( $term_id, $taxonomy, $args = array() ) { */ do_action( "edited_{$taxonomy}", $term_id, $tt_id ); - return array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id); + return array( + 'term_id' => $term_id, + 'term_taxonomy_id' => $tt_id, + ); } /** @@ -2851,14 +2971,15 @@ function wp_update_term( $term_id, $taxonomy, $args = array() ) { * @param bool $defer Optional. Enable if true, disable if false. * @return bool Whether term counting is enabled or disabled. */ -function wp_defer_term_counting($defer=null) { +function wp_defer_term_counting( $defer = null ) { static $_defer = false; - if ( is_bool($defer) ) { + if ( is_bool( $defer ) ) { $_defer = $defer; // flush any deferred counts - if ( !$defer ) + if ( ! $defer ) { wp_update_term_count( null, null, true ); + } } return $_defer; @@ -2886,22 +3007,25 @@ function wp_update_term_count( $terms, $taxonomy, $do_deferred = false ) { static $_deferred = array(); if ( $do_deferred ) { - foreach ( (array) array_keys($_deferred) as $tax ) { - wp_update_term_count_now( $_deferred[$tax], $tax ); - unset( $_deferred[$tax] ); + foreach ( (array) array_keys( $_deferred ) as $tax ) { + wp_update_term_count_now( $_deferred[ $tax ], $tax ); + unset( $_deferred[ $tax ] ); } } - if ( empty($terms) ) + if ( empty( $terms ) ) { return false; + } - if ( !is_array($terms) ) - $terms = array($terms); + if ( ! is_array( $terms ) ) { + $terms = array( $terms ); + } if ( wp_defer_term_counting() ) { - if ( !isset($_deferred[$taxonomy]) ) - $_deferred[$taxonomy] = array(); - $_deferred[$taxonomy] = array_unique( array_merge($_deferred[$taxonomy], $terms) ); + if ( ! isset( $_deferred[ $taxonomy ] ) ) { + $_deferred[ $taxonomy ] = array(); + } + $_deferred[ $taxonomy ] = array_unique( array_merge( $_deferred[ $taxonomy ], $terms ) ); return true; } @@ -2918,16 +3042,17 @@ function wp_update_term_count( $terms, $taxonomy, $do_deferred = false ) { * @return true Always true when complete. */ function wp_update_term_count_now( $terms, $taxonomy ) { - $terms = array_map('intval', $terms); + $terms = array_map( 'intval', $terms ); - $taxonomy = get_taxonomy($taxonomy); - if ( !empty($taxonomy->update_count_callback) ) { - call_user_func($taxonomy->update_count_callback, $terms, $taxonomy); + $taxonomy = get_taxonomy( $taxonomy ); + if ( ! empty( $taxonomy->update_count_callback ) ) { + call_user_func( $taxonomy->update_count_callback, $terms, $taxonomy ); } else { $object_types = (array) $taxonomy->object_type; foreach ( $object_types as &$object_type ) { - if ( 0 === strpos( $object_type, 'attachment:' ) ) + if ( 0 === strpos( $object_type, 'attachment:' ) ) { list( $object_type ) = explode( ':', $object_type ); + } } if ( $object_types == array_filter( $object_types, 'post_type_exists' ) ) { @@ -2939,7 +3064,7 @@ function wp_update_term_count_now( $terms, $taxonomy ) { } } - clean_term_cache($terms, '', false); + clean_term_cache( $terms, '', false ); return true; } @@ -2964,21 +3089,22 @@ function wp_update_term_count_now( $terms, $taxonomy ) { * @param int|array $object_ids Single or list of term object ID(s). * @param array|string $object_type The taxonomy object type. */ -function clean_object_term_cache($object_ids, $object_type) { +function clean_object_term_cache( $object_ids, $object_type ) { global $_wp_suspend_cache_invalidation; if ( ! empty( $_wp_suspend_cache_invalidation ) ) { return; } - if ( !is_array($object_ids) ) - $object_ids = array($object_ids); + if ( ! is_array( $object_ids ) ) { + $object_ids = array( $object_ids ); + } $taxonomies = get_object_taxonomies( $object_type ); foreach ( $object_ids as $id ) { foreach ( $taxonomies as $taxonomy ) { - wp_cache_delete($id, "{$taxonomy}_relationships"); + wp_cache_delete( $id, "{$taxonomy}_relationships" ); } } @@ -3007,31 +3133,32 @@ function clean_object_term_cache($object_ids, $object_type) { * @param bool $clean_taxonomy Optional. Whether to clean taxonomy wide caches (true), or just individual * term object caches (false). Default true. */ -function clean_term_cache($ids, $taxonomy = '', $clean_taxonomy = true) { +function clean_term_cache( $ids, $taxonomy = '', $clean_taxonomy = true ) { global $wpdb, $_wp_suspend_cache_invalidation; if ( ! empty( $_wp_suspend_cache_invalidation ) ) { return; } - if ( !is_array($ids) ) - $ids = array($ids); + if ( ! is_array( $ids ) ) { + $ids = array( $ids ); + } $taxonomies = array(); // If no taxonomy, assume tt_ids. - if ( empty($taxonomy) ) { - $tt_ids = array_map('intval', $ids); - $tt_ids = implode(', ', $tt_ids); - $terms = $wpdb->get_results("SELECT term_id, taxonomy FROM $wpdb->term_taxonomy WHERE term_taxonomy_id IN ($tt_ids)"); - $ids = array(); + if ( empty( $taxonomy ) ) { + $tt_ids = array_map( 'intval', $ids ); + $tt_ids = implode( ', ', $tt_ids ); + $terms = $wpdb->get_results( "SELECT term_id, taxonomy FROM $wpdb->term_taxonomy WHERE term_taxonomy_id IN ($tt_ids)" ); + $ids = array(); foreach ( (array) $terms as $term ) { $taxonomies[] = $term->taxonomy; - $ids[] = $term->term_id; + $ids[] = $term->term_id; wp_cache_delete( $term->term_id, 'terms' ); } - $taxonomies = array_unique($taxonomies); + $taxonomies = array_unique( $taxonomies ); } else { - $taxonomies = array($taxonomy); + $taxonomies = array( $taxonomy ); foreach ( $taxonomies as $taxonomy ) { foreach ( $ids as $id ) { wp_cache_delete( $id, 'terms' ); @@ -3152,35 +3279,40 @@ function get_object_term_cache( $id, $taxonomy ) { * @param array|string $object_type The taxonomy object type. * @return void|false False if all of the terms in `$object_ids` are already cached. */ -function update_object_term_cache($object_ids, $object_type) { - if ( empty($object_ids) ) +function update_object_term_cache( $object_ids, $object_type ) { + if ( empty( $object_ids ) ) { return; + } - if ( !is_array($object_ids) ) - $object_ids = explode(',', $object_ids); + if ( ! is_array( $object_ids ) ) { + $object_ids = explode( ',', $object_ids ); + } - $object_ids = array_map('intval', $object_ids); + $object_ids = array_map( 'intval', $object_ids ); - $taxonomies = get_object_taxonomies($object_type); + $taxonomies = get_object_taxonomies( $object_type ); $ids = array(); foreach ( (array) $object_ids as $id ) { foreach ( $taxonomies as $taxonomy ) { - if ( false === wp_cache_get($id, "{$taxonomy}_relationships") ) { + if ( false === wp_cache_get( $id, "{$taxonomy}_relationships" ) ) { $ids[] = $id; break; } } } - if ( empty( $ids ) ) + if ( empty( $ids ) ) { return false; + } - $terms = wp_get_object_terms( $ids, $taxonomies, array( - 'fields' => 'all_with_object_id', - 'orderby' => 'name', - 'update_term_meta_cache' => false, - ) ); + $terms = wp_get_object_terms( + $ids, $taxonomies, array( + 'fields' => 'all_with_object_id', + 'orderby' => 'name', + 'update_term_meta_cache' => false, + ) + ); $object_terms = array(); foreach ( (array) $terms as $term ) { @@ -3189,10 +3321,11 @@ function update_object_term_cache($object_ids, $object_type) { foreach ( $ids as $id ) { foreach ( $taxonomies as $taxonomy ) { - if ( ! isset($object_terms[$id][$taxonomy]) ) { - if ( !isset($object_terms[$id]) ) - $object_terms[$id] = array(); - $object_terms[$id][$taxonomy] = array(); + if ( ! isset( $object_terms[ $id ][ $taxonomy ] ) ) { + if ( ! isset( $object_terms[ $id ] ) ) { + $object_terms[ $id ] = array(); + } + $object_terms[ $id ][ $taxonomy ] = array(); } } } @@ -3238,19 +3371,28 @@ function update_term_cache( $terms, $taxonomy = '' ) { * @return array Empty if $taxonomy isn't hierarchical or returns children as Term IDs. */ function _get_term_hierarchy( $taxonomy ) { - if ( !is_taxonomy_hierarchical($taxonomy) ) + if ( ! is_taxonomy_hierarchical( $taxonomy ) ) { return array(); - $children = get_option("{$taxonomy}_children"); - - if ( is_array($children) ) - return $children; - $children = array(); - $terms = get_terms($taxonomy, array('get' => 'all', 'orderby' => 'id', 'fields' => 'id=>parent')); - foreach ( $terms as $term_id => $parent ) { - if ( $parent > 0 ) - $children[$parent][] = $term_id; } - update_option("{$taxonomy}_children", $children); + $children = get_option( "{$taxonomy}_children" ); + + if ( is_array( $children ) ) { + return $children; + } + $children = array(); + $terms = get_terms( + $taxonomy, array( + 'get' => 'all', + 'orderby' => 'id', + 'fields' => 'id=>parent', + ) + ); + foreach ( $terms as $term_id => $parent ) { + if ( $parent > 0 ) { + $children[ $parent ][] = $term_id; + } + } + update_option( "{$taxonomy}_children", $children ); return $children; } @@ -3276,14 +3418,16 @@ function _get_term_hierarchy( $taxonomy ) { */ function _get_term_children( $term_id, $terms, $taxonomy, &$ancestors = array() ) { $empty_array = array(); - if ( empty($terms) ) + if ( empty( $terms ) ) { return $empty_array; + } - $term_list = array(); - $has_children = _get_term_hierarchy($taxonomy); + $term_list = array(); + $has_children = _get_term_hierarchy( $taxonomy ); - if ( ( 0 != $term_id ) && ! isset($has_children[$term_id]) ) + if ( ( 0 != $term_id ) && ! isset( $has_children[ $term_id ] ) ) { return $empty_array; + } // Include the term itself in the ancestors array, so we can properly detect when a loop has occurred. if ( empty( $ancestors ) ) { @@ -3292,10 +3436,11 @@ function _get_term_children( $term_id, $terms, $taxonomy, &$ancestors = array() foreach ( (array) $terms as $term ) { $use_id = false; - if ( !is_object($term) ) { - $term = get_term($term, $taxonomy); - if ( is_wp_error( $term ) ) + if ( ! is_object( $term ) ) { + $term = get_term( $term, $taxonomy ); + if ( is_wp_error( $term ) ) { return $term; + } $use_id = true; } @@ -3305,18 +3450,21 @@ function _get_term_children( $term_id, $terms, $taxonomy, &$ancestors = array() } if ( $term->parent == $term_id ) { - if ( $use_id ) + if ( $use_id ) { $term_list[] = $term->term_id; - else + } else { $term_list[] = $term; + } - if ( !isset($has_children[$term->term_id]) ) + if ( ! isset( $has_children[ $term->term_id ] ) ) { continue; + } $ancestors[ $term->term_id ] = 1; - if ( $children = _get_term_children( $term->term_id, $terms, $taxonomy, $ancestors) ) - $term_list = array_merge($term_list, $children); + if ( $children = _get_term_children( $term->term_id, $terms, $taxonomy, $ancestors ) ) { + $term_list = array_merge( $term_list, $children ); + } } } @@ -3341,42 +3489,45 @@ function _pad_term_counts( &$terms, $taxonomy ) { global $wpdb; // This function only works for hierarchical taxonomies like post categories. - if ( !is_taxonomy_hierarchical( $taxonomy ) ) + if ( ! is_taxonomy_hierarchical( $taxonomy ) ) { return; + } - $term_hier = _get_term_hierarchy($taxonomy); + $term_hier = _get_term_hierarchy( $taxonomy ); - if ( empty($term_hier) ) + if ( empty( $term_hier ) ) { return; + } - $term_items = array(); + $term_items = array(); $terms_by_id = array(); - $term_ids = array(); + $term_ids = array(); foreach ( (array) $terms as $key => $term ) { - $terms_by_id[$term->term_id] = & $terms[$key]; - $term_ids[$term->term_taxonomy_id] = $term->term_id; + $terms_by_id[ $term->term_id ] = & $terms[ $key ]; + $term_ids[ $term->term_taxonomy_id ] = $term->term_id; } // Get the object and term ids and stick them in a lookup table. - $tax_obj = get_taxonomy($taxonomy); - $object_types = esc_sql($tax_obj->object_type); - $results = $wpdb->get_results("SELECT object_id, term_taxonomy_id FROM $wpdb->term_relationships INNER JOIN $wpdb->posts ON object_id = ID WHERE term_taxonomy_id IN (" . implode(',', array_keys($term_ids)) . ") AND post_type IN ('" . implode("', '", $object_types) . "') AND post_status = 'publish'"); + $tax_obj = get_taxonomy( $taxonomy ); + $object_types = esc_sql( $tax_obj->object_type ); + $results = $wpdb->get_results( "SELECT object_id, term_taxonomy_id FROM $wpdb->term_relationships INNER JOIN $wpdb->posts ON object_id = ID WHERE term_taxonomy_id IN (" . implode( ',', array_keys( $term_ids ) ) . ") AND post_type IN ('" . implode( "', '", $object_types ) . "') AND post_status = 'publish'" ); foreach ( $results as $row ) { - $id = $term_ids[$row->term_taxonomy_id]; - $term_items[$id][$row->object_id] = isset($term_items[$id][$row->object_id]) ? ++$term_items[$id][$row->object_id] : 1; + $id = $term_ids[ $row->term_taxonomy_id ]; + $term_items[ $id ][ $row->object_id ] = isset( $term_items[ $id ][ $row->object_id ] ) ? ++$term_items[ $id ][ $row->object_id ] : 1; } // Touch every ancestor's lookup row for each post in each term. foreach ( $term_ids as $term_id ) { - $child = $term_id; + $child = $term_id; $ancestors = array(); - while ( !empty( $terms_by_id[$child] ) && $parent = $terms_by_id[$child]->parent ) { + while ( ! empty( $terms_by_id[ $child ] ) && $parent = $terms_by_id[ $child ]->parent ) { $ancestors[] = $child; - if ( !empty( $term_items[$term_id] ) ) - foreach ( $term_items[$term_id] as $item_id => $touches ) { - $term_items[$parent][$item_id] = isset($term_items[$parent][$item_id]) ? ++$term_items[$parent][$item_id]: 1; + if ( ! empty( $term_items[ $term_id ] ) ) { + foreach ( $term_items[ $term_id ] as $item_id => $touches ) { + $term_items[ $parent ][ $item_id ] = isset( $term_items[ $parent ][ $item_id ] ) ? ++$term_items[ $parent ][ $item_id ] : 1; } + } $child = $parent; if ( in_array( $parent, $ancestors ) ) { @@ -3386,9 +3537,11 @@ function _pad_term_counts( &$terms, $taxonomy ) { } // Transfer the touched cells. - foreach ( (array) $term_items as $id => $items ) - if ( isset($terms_by_id[$id]) ) - $terms_by_id[$id]->count = count($items); + foreach ( (array) $term_items as $id => $items ) { + if ( isset( $terms_by_id[ $id ] ) ) { + $terms_by_id[ $id ]->count = count( $items ); + } + } } /** @@ -3407,7 +3560,7 @@ function _prime_term_caches( $term_ids, $update_meta_cache = true ) { $non_cached_ids = _get_non_cached_ids( $term_ids, 'terms' ); if ( ! empty( $non_cached_ids ) ) { - $fresh_terms = $wpdb->get_results( sprintf( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE t.term_id IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) ); + $fresh_terms = $wpdb->get_results( sprintf( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE t.term_id IN (%s)", join( ',', array_map( 'intval', $non_cached_ids ) ) ) ); update_term_cache( $fresh_terms, $update_meta_cache ); @@ -3440,8 +3593,9 @@ function _update_post_term_count( $terms, $taxonomy ) { $object_types = (array) $taxonomy->object_type; - foreach ( $object_types as &$object_type ) + foreach ( $object_types as &$object_type ) { list( $object_type ) = explode( ':', $object_type ); + } $object_types = array_unique( $object_types ); @@ -3450,18 +3604,21 @@ function _update_post_term_count( $terms, $taxonomy ) { $check_attachments = true; } - if ( $object_types ) + if ( $object_types ) { $object_types = esc_sql( array_filter( $object_types, 'post_type_exists' ) ); + } foreach ( (array) $terms as $term ) { $count = 0; // Attachments can be 'inherit' status, we need to base count off the parent's status if so. - if ( $check_attachments ) + if ( $check_attachments ) { $count += (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts p1 WHERE p1.ID = $wpdb->term_relationships.object_id AND ( post_status = 'publish' OR ( post_status = 'inherit' AND post_parent > 0 AND ( SELECT post_status FROM $wpdb->posts WHERE ID = p1.post_parent ) = 'publish' ) ) AND post_type = 'attachment' AND term_taxonomy_id = %d", $term ) ); + } - if ( $object_types ) - $count += (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type IN ('" . implode("', '", $object_types ) . "') AND term_taxonomy_id = %d", $term ) ); + if ( $object_types ) { + $count += (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type IN ('" . implode( "', '", $object_types ) . "') AND term_taxonomy_id = %d", $term ) ); + } /** This action is documented in wp-includes/taxonomy.php */ do_action( 'edit_term_taxonomy', $term, $taxonomy->name ); @@ -3527,11 +3684,11 @@ function _split_shared_term( $term_id, $term_taxonomy_id, $record = true ) { if ( is_object( $term_id ) ) { $shared_term = $term_id; - $term_id = intval( $shared_term->term_id ); + $term_id = intval( $shared_term->term_id ); } if ( is_object( $term_taxonomy_id ) ) { - $term_taxonomy = $term_taxonomy_id; + $term_taxonomy = $term_taxonomy_id; $term_taxonomy_id = intval( $term_taxonomy->term_taxonomy_id ); } @@ -3557,8 +3714,8 @@ function _split_shared_term( $term_id, $term_taxonomy_id, $record = true ) { } $new_term_data = array( - 'name' => $shared_term->name, - 'slug' => $shared_term->slug, + 'name' => $shared_term->name, + 'slug' => $shared_term->slug, 'term_group' => $shared_term->term_group, ); @@ -3569,7 +3726,8 @@ function _split_shared_term( $term_id, $term_taxonomy_id, $record = true ) { $new_term_id = (int) $wpdb->insert_id; // Update the existing term_taxonomy to point to the newly created term. - $wpdb->update( $wpdb->term_taxonomy, + $wpdb->update( + $wpdb->term_taxonomy, array( 'term_id' => $new_term_id ), array( 'term_taxonomy_id' => $term_taxonomy_id ) ); @@ -3582,7 +3740,8 @@ function _split_shared_term( $term_id, $term_taxonomy_id, $record = true ) { $children_tt_ids = $wpdb->get_col( $wpdb->prepare( "SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE parent = %d AND taxonomy = %s", $term_id, $term_taxonomy->taxonomy ) ); if ( ! empty( $children_tt_ids ) ) { foreach ( $children_tt_ids as $child_tt_id ) { - $wpdb->update( $wpdb->term_taxonomy, + $wpdb->update( + $wpdb->term_taxonomy, array( 'parent' => $new_term_id ), array( 'term_taxonomy_id' => $child_tt_id ) ); @@ -3603,7 +3762,7 @@ function _split_shared_term( $term_id, $term_taxonomy_id, $record = true ) { // Clean the cache for term taxonomies formerly shared with the current term. $shared_term_taxonomies = $wpdb->get_col( $wpdb->prepare( "SELECT taxonomy FROM $wpdb->term_taxonomy WHERE term_id = %d", $term_id ) ); - $taxonomies_to_clean = array_merge( $taxonomies_to_clean, $shared_term_taxonomies ); + $taxonomies_to_clean = array_merge( $taxonomies_to_clean, $shared_term_taxonomies ); foreach ( $taxonomies_to_clean as $taxonomy_to_clean ) { clean_taxonomy_cache( $taxonomy_to_clean ); @@ -3697,17 +3856,17 @@ function _wp_batch_split_terms() { // Rekey shared term array for faster lookups. $_shared_terms = array(); foreach ( $shared_terms as $shared_term ) { - $term_id = intval( $shared_term->term_id ); + $term_id = intval( $shared_term->term_id ); $_shared_terms[ $term_id ] = $shared_term; } $shared_terms = $_shared_terms; // Get term taxonomy data for all shared terms. $shared_term_ids = implode( ',', array_keys( $shared_terms ) ); - $shared_tts = $wpdb->get_results( "SELECT * FROM {$wpdb->term_taxonomy} WHERE `term_id` IN ({$shared_term_ids})" ); + $shared_tts = $wpdb->get_results( "SELECT * FROM {$wpdb->term_taxonomy} WHERE `term_id` IN ({$shared_term_ids})" ); // Split term data recording is slow, so we do it just once, outside the loop. - $split_term_data = get_option( '_split_terms', array() ); + $split_term_data = get_option( '_split_terms', array() ); $skipped_first_term = $taxonomies = array(); foreach ( $shared_tts as $shared_tt ) { $term_id = intval( $shared_tt->term_id ); @@ -3793,17 +3952,19 @@ function _wp_check_split_default_terms( $term_id, $new_term_id, $term_taxonomy_i */ function _wp_check_split_terms_in_menus( $term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) { global $wpdb; - $post_ids = $wpdb->get_col( $wpdb->prepare( - "SELECT m1.post_id + $post_ids = $wpdb->get_col( + $wpdb->prepare( + "SELECT m1.post_id FROM {$wpdb->postmeta} AS m1 INNER JOIN {$wpdb->postmeta} AS m2 ON ( m2.post_id = m1.post_id ) INNER JOIN {$wpdb->postmeta} AS m3 ON ( m3.post_id = m1.post_id ) WHERE ( m1.meta_key = '_menu_item_type' AND m1.meta_value = 'taxonomy' ) AND ( m2.meta_key = '_menu_item_object' AND m2.meta_value = %s ) AND ( m3.meta_key = '_menu_item_object_id' AND m3.meta_value = %d )", - $taxonomy, - $term_id - ) ); + $taxonomy, + $term_id + ) + ); if ( $post_ids ) { foreach ( $post_ids as $post_id ) { @@ -3917,7 +4078,7 @@ function wp_term_is_shared( $term_id ) { function get_term_link( $term, $taxonomy = '' ) { global $wp_rewrite; - if ( !is_object($term) ) { + if ( ! is_object( $term ) ) { if ( is_int( $term ) ) { $term = get_term( $term, $taxonomy ); } else { @@ -3925,15 +4086,17 @@ function get_term_link( $term, $taxonomy = '' ) { } } - if ( !is_object($term) ) + if ( ! is_object( $term ) ) { $term = new WP_Error( 'invalid_term', __( 'Empty Term.' ) ); + } - if ( is_wp_error( $term ) ) + if ( is_wp_error( $term ) ) { return $term; + } $taxonomy = $term->taxonomy; - $termlink = $wp_rewrite->get_extra_permastruct($taxonomy); + $termlink = $wp_rewrite->get_extra_permastruct( $taxonomy ); /** * Filters the permalink structure for a terms before token replacement occurs. @@ -3946,31 +4109,32 @@ function get_term_link( $term, $taxonomy = '' ) { $termlink = apply_filters( 'pre_term_link', $termlink, $term ); $slug = $term->slug; - $t = get_taxonomy($taxonomy); + $t = get_taxonomy( $taxonomy ); - if ( empty($termlink) ) { - if ( 'category' == $taxonomy ) + if ( empty( $termlink ) ) { + if ( 'category' == $taxonomy ) { $termlink = '?cat=' . $term->term_id; - elseif ( $t->query_var ) + } elseif ( $t->query_var ) { $termlink = "?$t->query_var=$slug"; - else + } else { $termlink = "?taxonomy=$taxonomy&term=$slug"; - $termlink = home_url($termlink); + } + $termlink = home_url( $termlink ); } else { if ( $t->rewrite['hierarchical'] ) { $hierarchical_slugs = array(); - $ancestors = get_ancestors( $term->term_id, $taxonomy, 'taxonomy' ); - foreach ( (array)$ancestors as $ancestor ) { - $ancestor_term = get_term($ancestor, $taxonomy); + $ancestors = get_ancestors( $term->term_id, $taxonomy, 'taxonomy' ); + foreach ( (array) $ancestors as $ancestor ) { + $ancestor_term = get_term( $ancestor, $taxonomy ); $hierarchical_slugs[] = $ancestor_term->slug; } - $hierarchical_slugs = array_reverse($hierarchical_slugs); + $hierarchical_slugs = array_reverse( $hierarchical_slugs ); $hierarchical_slugs[] = $slug; - $termlink = str_replace("%$taxonomy%", implode('/', $hierarchical_slugs), $termlink); + $termlink = str_replace( "%$taxonomy%", implode( '/', $hierarchical_slugs ), $termlink ); } else { - $termlink = str_replace("%$taxonomy%", $slug, $termlink); + $termlink = str_replace( "%$taxonomy%", $slug, $termlink ); } - $termlink = home_url( user_trailingslashit($termlink, 'category') ); + $termlink = home_url( user_trailingslashit( $termlink, 'category' ) ); } // Back Compat filters. if ( 'post_tag' == $taxonomy ) { @@ -4032,10 +4196,10 @@ function get_term_link( $term, $taxonomy = '' ) { */ function the_taxonomies( $args = array() ) { $defaults = array( - 'post' => 0, + 'post' => 0, 'before' => '', - 'sep' => ' ', - 'after' => '', + 'sep' => ' ', + 'after' => '', ); $r = wp_parse_args( $args, $defaults ); @@ -4065,11 +4229,13 @@ function the_taxonomies( $args = array() ) { function get_the_taxonomies( $post = 0, $args = array() ) { $post = get_post( $post ); - $args = wp_parse_args( $args, array( - /* translators: %s: taxonomy label, %l: list of terms formatted as per $term_template */ - 'template' => __( '%s: %l.' ), - 'term_template' => '%2$s', - ) ); + $args = wp_parse_args( + $args, array( + /* translators: %s: taxonomy label, %l: list of terms formatted as per $term_template */ + 'template' => __( '%s: %l.' ), + 'term_template' => '%2$s', + ) + ); $taxonomies = array(); @@ -4102,7 +4268,7 @@ function get_the_taxonomies( $post = 0, $args = array() ) { $links[] = wp_sprintf( $t['term_template'], esc_attr( get_term_link( $term ) ), $term->name ); } if ( $links ) { - $taxonomies[$taxonomy] = wp_sprintf( $t['template'], $t['label'], $links, $terms ); + $taxonomies[ $taxonomy ] = wp_sprintf( $t['template'], $t['label'], $links, $terms ); } } return $taxonomies; @@ -4119,7 +4285,7 @@ function get_the_taxonomies( $post = 0, $args = array() ) { function get_post_taxonomies( $post = 0 ) { $post = get_post( $post ); - return get_object_taxonomies($post); + return get_object_taxonomies( $post ); } /** @@ -4137,8 +4303,9 @@ function get_post_taxonomies( $post = 0 ) { * @return bool|WP_Error WP_Error on input error. */ function is_object_in_term( $object_id, $taxonomy, $terms = null ) { - if ( !$object_id = (int) $object_id ) + if ( ! $object_id = (int) $object_id ) { return new WP_Error( 'invalid_object', __( 'Invalid object ID.' ) ); + } $object_terms = get_object_term_cache( $object_id, $taxonomy ); if ( false === $object_terms ) { @@ -4150,19 +4317,23 @@ function is_object_in_term( $object_id, $taxonomy, $terms = null ) { wp_cache_set( $object_id, wp_list_pluck( $object_terms, 'term_id' ), "{$taxonomy}_relationships" ); } - if ( is_wp_error( $object_terms ) ) + if ( is_wp_error( $object_terms ) ) { return $object_terms; - if ( empty( $object_terms ) ) + } + if ( empty( $object_terms ) ) { return false; - if ( empty( $terms ) ) - return ( !empty( $object_terms ) ); + } + if ( empty( $terms ) ) { + return ( ! empty( $object_terms ) ); + } $terms = (array) $terms; - if ( $ints = array_filter( $terms, 'is_int' ) ) + if ( $ints = array_filter( $terms, 'is_int' ) ) { $strs = array_diff( $terms, $ints ); - else + } else { $strs =& $terms; + } foreach ( $object_terms as $object_term ) { // If term is an int, check against term_ids only. @@ -4177,8 +4348,12 @@ function is_object_in_term( $object_id, $taxonomy, $terms = null ) { return true; } - if ( in_array( $object_term->name, $strs ) ) return true; - if ( in_array( $object_term->slug, $strs ) ) return true; + if ( in_array( $object_term->name, $strs ) ) { + return true; + } + if ( in_array( $object_term->slug, $strs ) ) { + return true; + } } } @@ -4235,13 +4410,13 @@ function get_ancestors( $object_id = 0, $object_type = '', $resource_type = '' ) } if ( 'taxonomy' === $resource_type ) { - $term = get_term($object_id, $object_type); - while ( ! is_wp_error($term) && ! empty( $term->parent ) && ! in_array( $term->parent, $ancestors ) ) { + $term = get_term( $object_id, $object_type ); + while ( ! is_wp_error( $term ) && ! empty( $term->parent ) && ! in_array( $term->parent, $ancestors ) ) { $ancestors[] = (int) $term->parent; - $term = get_term($term->parent, $object_type); + $term = get_term( $term->parent, $object_type ); } } elseif ( 'post_type' === $resource_type ) { - $ancestors = get_post_ancestors($object_id); + $ancestors = get_post_ancestors( $object_id ); } /** @@ -4291,24 +4466,29 @@ function wp_get_term_taxonomy_parent_id( $term_id, $taxonomy ) { */ function wp_check_term_hierarchy_for_loops( $parent, $term_id, $taxonomy ) { // Nothing fancy here - bail - if ( !$parent ) + if ( ! $parent ) { return 0; + } // Can't be its own parent. - if ( $parent == $term_id ) + if ( $parent == $term_id ) { return 0; + } // Now look for larger loops. - if ( !$loop = wp_find_hierarchy_loop( 'wp_get_term_taxonomy_parent_id', $term_id, $parent, array( $taxonomy ) ) ) + if ( ! $loop = wp_find_hierarchy_loop( 'wp_get_term_taxonomy_parent_id', $term_id, $parent, array( $taxonomy ) ) ) { return $parent; // No loop + } // Setting $parent to the given value causes a loop. - if ( isset( $loop[$term_id] ) ) + if ( isset( $loop[ $term_id ] ) ) { return 0; + } // There's a loop, but it doesn't contain $term_id. Break the loop. - foreach ( array_keys( $loop ) as $loop_member ) + foreach ( array_keys( $loop ) as $loop_member ) { wp_update_term( $loop_member, $taxonomy, array( 'parent' => 0 ) ); + } return $parent; } diff --git a/wp-includes/template-loader.php b/wp-includes/template-loader.php index 1ee7c222c1..0d2bafae44 100644 --- a/wp-includes/template-loader.php +++ b/wp-includes/template-loader.php @@ -1,15 +1,17 @@ has_archive ) { @@ -335,7 +337,7 @@ function get_taxonomy_template() { * @return string Full path to date template file. */ function get_date_template() { - return get_query_template('date'); + return get_query_template( 'date' ); } /** @@ -369,7 +371,7 @@ function get_home_template() { * @return string Full path to front page template file. */ function get_front_page_template() { - $templates = array('front-page.php'); + $templates = array( 'front-page.php' ); return get_query_template( 'front_page', $templates ); } @@ -403,20 +405,22 @@ function get_front_page_template() { * @return string Full path to page template file. */ function get_page_template() { - $id = get_queried_object_id(); + $id = get_queried_object_id(); $template = get_page_template_slug(); - $pagename = get_query_var('pagename'); + $pagename = get_query_var( 'pagename' ); if ( ! $pagename && $id ) { // If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object $post = get_queried_object(); - if ( $post ) + if ( $post ) { $pagename = $post->post_name; + } } $templates = array(); - if ( $template && 0 === validate_file( $template ) ) + if ( $template && 0 === validate_file( $template ) ) { $templates[] = $template; + } if ( $pagename ) { $pagename_decoded = urldecode( $pagename ); if ( $pagename_decoded !== $pagename ) { @@ -424,8 +428,9 @@ function get_page_template() { } $templates[] = "page-{$pagename}.php"; } - if ( $id ) + if ( $id ) { $templates[] = "page-{$id}.php"; + } $templates[] = 'page.php'; return get_query_template( 'page', $templates ); @@ -444,7 +449,7 @@ function get_page_template() { * @return string Full path to search template file. */ function get_search_template() { - return get_query_template('search'); + return get_query_template( 'search' ); } /** @@ -498,7 +503,7 @@ function get_single_template() { $templates[] = "single-{$object->post_type}.php"; } - $templates[] = "single.php"; + $templates[] = 'single.php'; return get_query_template( 'single', $templates ); } @@ -540,7 +545,7 @@ function get_embed_template() { $templates[] = "embed-{$object->post_type}.php"; } - $templates[] = "embed.php"; + $templates[] = 'embed.php'; return get_query_template( 'embed', $templates ); } @@ -626,15 +631,16 @@ function get_attachment_template() { * @param bool $require_once Whether to require_once or require. Default true. Has no effect if $load is false. * @return string The template filename if one is located. */ -function locate_template($template_names, $load = false, $require_once = true ) { +function locate_template( $template_names, $load = false, $require_once = true ) { $located = ''; foreach ( (array) $template_names as $template_name ) { - if ( !$template_name ) + if ( ! $template_name ) { continue; - if ( file_exists(STYLESHEETPATH . '/' . $template_name)) { + } + if ( file_exists( STYLESHEETPATH . '/' . $template_name ) ) { $located = STYLESHEETPATH . '/' . $template_name; break; - } elseif ( file_exists(TEMPLATEPATH . '/' . $template_name) ) { + } elseif ( file_exists( TEMPLATEPATH . '/' . $template_name ) ) { $located = TEMPLATEPATH . '/' . $template_name; break; } elseif ( file_exists( ABSPATH . WPINC . '/theme-compat/' . $template_name ) ) { @@ -643,8 +649,9 @@ function locate_template($template_names, $load = false, $require_once = true ) } } - if ( $load && '' != $located ) + if ( $load && '' != $located ) { load_template( $located, $require_once ); + } return $located; } diff --git a/wp-includes/theme-compat/comments.php b/wp-includes/theme-compat/comments.php index cb6d64fd9b..0f2e901e66 100644 --- a/wp-includes/theme-compat/comments.php +++ b/wp-includes/theme-compat/comments.php @@ -5,7 +5,6 @@ * @deprecated 3.0.0 * * This file is here for backward compatibility with old themes and will be removed in a future version - * */ _deprecated_file( /* translators: %s: template name */ @@ -17,14 +16,15 @@ _deprecated_file( ); // Do not delete these lines - if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME'])) - die ('Please do not load this page directly. Thanks!'); +if ( ! empty( $_SERVER['SCRIPT_FILENAME'] ) && 'comments.php' == basename( $_SERVER['SCRIPT_FILENAME'] ) ) { + die( 'Please do not load this page directly. Thanks!' ); +} - if ( post_password_required() ) { ?> -

    +if ( post_password_required() ) { ?> +

    @@ -32,29 +32,31 @@ _deprecated_file(

      - +
    @@ -63,7 +65,7 @@ _deprecated_file( -

    +

    diff --git a/wp-includes/theme-compat/embed-404.php b/wp-includes/theme-compat/embed-404.php index ee766750c1..424b5a6a58 100644 --- a/wp-includes/theme-compat/embed-404.php +++ b/wp-includes/theme-compat/embed-404.php @@ -31,6 +31,6 @@ ?>
    diff --git a/wp-includes/theme-compat/embed-content.php b/wp-includes/theme-compat/embed-content.php index 11bef95df8..bdb38339ad 100644 --- a/wp-includes/theme-compat/embed-content.php +++ b/wp-includes/theme-compat/embed-content.php @@ -75,7 +75,8 @@ $shape = apply_filters( 'embed_thumbnail_image_shape', $shape, $thumbnail_id ); } - if ( $thumbnail_id && 'rectangular' === $shape ) : ?> + if ( $thumbnail_id && 'rectangular' === $shape ) : + ?>