From cfc3b57488458801c64c750cb500c98c1ef635ad Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 29 Jan 2020 00:43:23 +0000 Subject: [PATCH] Docs: Improve inline comments per the documentation standards. Includes minor code layout fixes for better readability. See #48303. git-svn-id: https://develop.svn.wordpress.org/trunk@47122 602fd350-edb4-49c9-b593-d223f7449a82 --- Gruntfile.js | 76 +- phpcompat.xml.dist | 4 +- phpcs.xml.dist | 32 +- phpunit.xml.dist | 6 +- src/index.php | 2 +- src/js/_enqueues/admin/comment.js | 2 +- src/js/_enqueues/admin/common.js | 48 +- src/js/_enqueues/admin/edit-comments.js | 74 +- src/js/_enqueues/admin/inline-edit-post.js | 36 +- src/js/_enqueues/admin/inline-edit-tax.js | 10 +- src/js/_enqueues/admin/link.js | 4 +- src/js/_enqueues/admin/media-upload.js | 8 +- src/js/_enqueues/admin/plugin-install.js | 5 +- src/js/_enqueues/admin/post.js | 39 +- src/js/_enqueues/admin/postbox.js | 23 +- src/js/_enqueues/admin/privacy-tools.js | 10 +- src/js/_enqueues/admin/site-health.js | 8 +- src/js/_enqueues/admin/tags-box.js | 7 + src/js/_enqueues/admin/tags-suggest.js | 16 +- src/js/_enqueues/admin/tags.js | 14 +- src/js/_enqueues/admin/user-profile.js | 8 +- src/js/_enqueues/admin/widgets.js | 22 +- src/js/_enqueues/lib/accordion.js | 6 +- src/js/_enqueues/lib/admin-bar.js | 4 +- src/js/_enqueues/lib/ajax-response.js | 4 +- src/js/_enqueues/lib/auth-check.js | 16 +- src/js/_enqueues/lib/color-picker.js | 3 - src/js/_enqueues/lib/comment-reply.js | 2 +- src/js/_enqueues/lib/cookies.js | 12 +- src/js/_enqueues/lib/gallery.js | 8 +- src/js/_enqueues/lib/image-edit.js | 111 +-- src/js/_enqueues/lib/link.js | 58 +- src/js/_enqueues/lib/nav-menu.js | 148 ++-- src/js/_enqueues/lib/pointer.js | 10 +- src/js/_enqueues/lib/quicktags.js | 58 +- src/js/_enqueues/vendor/plupload/handlers.js | 77 +- .../_enqueues/vendor/plupload/wp-plupload.js | 42 +- .../vendor/tinymce/plugins/compat3x/plugin.js | 2 +- .../tinymce/plugins/wordpress/plugin.js | 56 +- .../tinymce/plugins/wpautoresize/plugin.js | 44 +- .../tinymce/plugins/wpdialogs/plugin.js | 6 +- .../tinymce/plugins/wpeditimage/plugin.js | 84 ++- .../vendor/tinymce/plugins/wpemoji/plugin.js | 16 +- .../tinymce/plugins/wpgallery/plugin.js | 8 +- .../vendor/tinymce/plugins/wplink/plugin.js | 10 +- .../tinymce/plugins/wptextpattern/plugin.js | 6 +- .../vendor/tinymce/plugins/wpview/plugin.js | 8 +- .../_enqueues/vendor/tinymce/wp-tinymce.php | 4 +- src/js/_enqueues/wp/api-request.js | 6 +- src/js/_enqueues/wp/api.js | 14 +- src/js/_enqueues/wp/autosave.js | 42 +- src/js/_enqueues/wp/code-editor.js | 6 +- src/js/_enqueues/wp/custom-header.js | 2 +- src/js/_enqueues/wp/customize/base.js | 42 +- src/js/_enqueues/wp/customize/controls.js | 178 +++-- src/js/_enqueues/wp/customize/loader.js | 10 +- src/js/_enqueues/wp/customize/models.js | 12 +- src/js/_enqueues/wp/customize/nav-menus.js | 42 +- .../_enqueues/wp/customize/preview-widgets.js | 2 +- src/js/_enqueues/wp/customize/preview.js | 6 +- .../wp/customize/selective-refresh.js | 2 +- src/js/_enqueues/wp/customize/widgets.js | 179 ++--- src/js/_enqueues/wp/editor/base.js | 36 +- src/js/_enqueues/wp/editor/dfw.js | 19 +- src/js/_enqueues/wp/emoji.js | 14 +- src/js/_enqueues/wp/heartbeat.js | 109 ++- src/js/_enqueues/wp/mce-view.js | 10 +- src/js/_enqueues/wp/media/audiovideo.js | 2 +- src/js/_enqueues/wp/media/editor.js | 22 +- src/js/_enqueues/wp/media/models.js | 10 +- src/js/_enqueues/wp/media/views.js | 2 +- src/js/_enqueues/wp/shortcode.js | 221 +++--- src/js/_enqueues/wp/svg-painter.js | 20 +- src/js/_enqueues/wp/theme-plugin-editor.js | 14 +- src/js/_enqueues/wp/theme.js | 495 +++++++------ src/js/_enqueues/wp/util.js | 14 +- src/js/_enqueues/wp/utils/word-count.js | 14 +- src/js/media/controllers/collection-add.js | 16 +- src/js/media/controllers/embed.js | 8 +- src/js/media/controllers/state.js | 20 +- src/js/media/models/attachments.js | 23 +- src/js/media/models/post-image.js | 4 +- src/js/media/models/query.js | 32 +- src/js/media/routers/manage.js | 8 +- src/js/media/utils/selection-sync.js | 10 +- src/js/media/views/attachment.js | 52 +- src/js/media/views/attachment/details.js | 8 +- src/js/media/views/attachments.js | 20 +- src/js/media/views/attachments/browser.js | 16 +- .../media/views/button/select-mode-toggle.js | 2 +- src/js/media/views/embed/link.js | 6 +- src/js/media/views/focus-manager.js | 2 +- src/js/media/views/frame/edit-attachments.js | 4 +- src/js/media/views/frame/image-details.js | 12 +- src/js/media/views/frame/manage.js | 6 +- src/js/media/views/frame/post.js | 14 +- src/js/media/views/frame/select.js | 2 +- src/js/media/views/image-details.js | 4 +- src/js/media/views/menu-item.js | 2 +- src/js/media/views/modal.js | 4 +- src/js/media/views/toolbar.js | 2 +- src/js/media/views/uploader/inline.js | 8 +- src/js/media/views/view.js | 8 +- src/wp-activate.php | 2 +- src/wp-admin/_index.php | 4 +- src/wp-admin/admin-ajax.php | 6 +- src/wp-admin/admin-footer.php | 4 +- src/wp-admin/admin.php | 8 +- src/wp-admin/async-upload.php | 4 +- src/wp-admin/comment.php | 4 +- src/wp-admin/credits.php | 2 +- src/wp-admin/edit-comments.php | 2 +- src/wp-admin/edit-form-advanced.php | 6 +- src/wp-admin/edit-form-blocks.php | 12 +- src/wp-admin/edit-form-comment.php | 2 +- src/wp-admin/edit-link-form.php | 2 +- src/wp-admin/edit-tag-form.php | 8 +- src/wp-admin/edit-tags.php | 2 +- src/wp-admin/edit.php | 2 +- src/wp-admin/import.php | 4 +- src/wp-admin/includes/admin-filters.php | 2 +- src/wp-admin/includes/admin.php | 2 +- src/wp-admin/includes/ajax-actions.php | 62 +- .../class-automatic-upgrader-skin.php | 6 +- src/wp-admin/includes/class-core-upgrader.php | 35 +- .../includes/class-custom-background.php | 12 +- .../includes/class-custom-image-header.php | 26 +- .../includes/class-file-upload-upgrader.php | 4 +- .../includes/class-language-pack-upgrader.php | 6 +- .../includes/class-plugin-upgrader.php | 38 +- .../includes/class-theme-upgrader.php | 58 +- .../class-walker-category-checklist.php | 2 +- .../class-walker-nav-menu-checklist.php | 4 +- .../includes/class-walker-nav-menu-edit.php | 2 +- .../includes/class-wp-automatic-updater.php | 50 +- .../includes/class-wp-comments-list-table.php | 6 +- .../includes/class-wp-community-events.php | 2 +- src/wp-admin/includes/class-wp-debug-data.php | 10 +- .../includes/class-wp-filesystem-base.php | 45 +- .../includes/class-wp-filesystem-direct.php | 13 +- .../includes/class-wp-filesystem-ftpext.php | 19 +- .../class-wp-filesystem-ftpsockets.php | 16 +- .../includes/class-wp-filesystem-ssh2.php | 6 +- src/wp-admin/includes/class-wp-importer.php | 28 +- .../includes/class-wp-internal-pointers.php | 10 +- src/wp-admin/includes/class-wp-list-table.php | 8 +- .../includes/class-wp-ms-sites-list-table.php | 4 +- .../class-wp-ms-themes-list-table.php | 2 +- .../includes/class-wp-ms-users-list-table.php | 2 +- .../class-wp-plugin-install-list-table.php | 10 +- .../includes/class-wp-plugins-list-table.php | 38 +- .../includes/class-wp-posts-list-table.php | 693 +++++++++--------- .../class-wp-privacy-requests-table.php | 10 +- src/wp-admin/includes/class-wp-screen.php | 16 +- .../class-wp-site-health-auto-updates.php | 6 +- .../includes/class-wp-site-health.php | 6 +- src/wp-admin/includes/class-wp-site-icon.php | 2 +- .../includes/class-wp-terms-list-table.php | 93 ++- .../class-wp-theme-install-list-table.php | 2 +- .../includes/class-wp-themes-list-table.php | 4 +- src/wp-admin/includes/class-wp-upgrader.php | 67 +- .../includes/class-wp-users-list-table.php | 22 +- src/wp-admin/includes/comment.php | 21 +- src/wp-admin/includes/credits.php | 2 +- src/wp-admin/includes/dashboard.php | 6 +- src/wp-admin/includes/file.php | 4 +- src/wp-admin/includes/image.php | 24 +- src/wp-admin/includes/import.php | 3 +- src/wp-admin/includes/media.php | 6 +- src/wp-admin/includes/privacy-tools.php | 2 +- src/wp-admin/includes/revision.php | 4 +- src/wp-admin/includes/schema.php | 27 +- src/wp-admin/includes/screen.php | 4 +- src/wp-admin/includes/taxonomy.php | 6 +- src/wp-admin/includes/template.php | 46 +- src/wp-admin/includes/theme.php | 17 +- src/wp-admin/includes/translation-install.php | 10 +- src/wp-admin/includes/update-core.php | 90 +-- src/wp-admin/includes/update.php | 3 +- src/wp-admin/includes/upgrade.php | 132 ++-- src/wp-admin/includes/user.php | 6 +- src/wp-admin/includes/widgets.php | 10 +- src/wp-admin/install-helper.php | 4 +- src/wp-admin/install.php | 18 +- src/wp-admin/link-manager.php | 2 +- src/wp-admin/link-parse-opml.php | 6 +- src/wp-admin/load-scripts.php | 2 +- src/wp-admin/load-styles.php | 2 +- src/wp-admin/media-new.php | 2 +- src/wp-admin/media-upload.php | 4 +- src/wp-admin/menu-header.php | 6 +- src/wp-admin/menu.php | 14 +- src/wp-admin/nav-menus.php | 30 +- src/wp-admin/network/settings.php | 2 +- src/wp-admin/network/site-new.php | 4 +- src/wp-admin/network/site-settings.php | 4 +- src/wp-admin/network/themes.php | 2 +- src/wp-admin/network/users.php | 4 +- src/wp-admin/options-discussion.php | 4 +- src/wp-admin/options-general.php | 6 +- src/wp-admin/options-media.php | 2 +- src/wp-admin/options-permalink.php | 2 +- src/wp-admin/options.php | 2 +- src/wp-admin/plugin-editor.php | 230 +++--- src/wp-admin/plugin-install.php | 2 +- src/wp-admin/plugins.php | 23 +- src/wp-admin/post-new.php | 4 +- src/wp-admin/post.php | 14 +- src/wp-admin/revision.php | 4 +- src/wp-admin/setup-config.php | 8 +- src/wp-admin/theme-editor.php | 236 +++--- src/wp-admin/theme-install.php | 2 +- src/wp-admin/themes.php | 16 +- src/wp-admin/update-core.php | 4 +- src/wp-admin/update.php | 16 +- src/wp-admin/upload.php | 4 +- src/wp-admin/user-edit.php | 33 +- src/wp-admin/user-new.php | 14 +- src/wp-admin/users.php | 7 +- src/wp-admin/widgets.php | 23 +- .../themes/twentyeleven/archive.php | 8 +- src/wp-content/themes/twentyeleven/author.php | 11 +- .../themes/twentyeleven/category.php | 5 +- .../themes/twentyeleven/comments.php | 8 +- .../themes/twentyeleven/content-aside.php | 2 +- .../themes/twentyeleven/content-gallery.php | 14 +- .../themes/twentyeleven/content-image.php | 6 +- .../themes/twentyeleven/content-link.php | 2 +- .../themes/twentyeleven/content-quote.php | 12 +- .../themes/twentyeleven/content-single.php | 5 +- .../themes/twentyeleven/content-status.php | 2 +- .../themes/twentyeleven/content.php | 20 +- .../themes/twentyeleven/functions.php | 26 +- src/wp-content/themes/twentyeleven/header.php | 16 +- src/wp-content/themes/twentyeleven/image.php | 34 +- .../twentyeleven/inc/theme-customizer.js | 2 +- .../themes/twentyeleven/inc/theme-options.php | 52 +- .../themes/twentyeleven/inc/widgets.php | 4 +- src/wp-content/themes/twentyeleven/index.php | 2 +- src/wp-content/themes/twentyeleven/page.php | 2 +- src/wp-content/themes/twentyeleven/search.php | 2 +- .../themes/twentyeleven/showcase.php | 20 +- .../themes/twentyeleven/sidebar-page.php | 2 +- .../themes/twentyeleven/sidebar.php | 2 +- src/wp-content/themes/twentyeleven/single.php | 2 +- src/wp-content/themes/twentyeleven/tag.php | 2 +- .../themes/twentyfifteen/archive.php | 8 +- .../themes/twentyfifteen/comments.php | 2 +- .../themes/twentyfifteen/content-link.php | 2 +- .../themes/twentyfifteen/content.php | 2 +- .../themes/twentyfifteen/functions.php | 2 +- src/wp-content/themes/twentyfifteen/image.php | 4 +- .../twentyfifteen/inc/custom-header.php | 2 +- .../themes/twentyfifteen/inc/customizer.php | 6 +- .../twentyfifteen/inc/template-tags.php | 8 +- src/wp-content/themes/twentyfifteen/index.php | 6 +- .../themes/twentyfifteen/js/functions.js | 1 + .../themes/twentyfifteen/single.php | 4 +- .../themes/twentyfourteen/archive.php | 6 +- .../themes/twentyfourteen/author.php | 12 +- .../themes/twentyfourteen/category.php | 6 +- .../twentyfourteen/content-featured-post.php | 2 +- .../themes/twentyfourteen/functions.php | 6 +- .../themes/twentyfourteen/image.php | 4 +- .../twentyfourteen/inc/custom-header.php | 6 +- .../twentyfourteen/inc/template-tags.php | 12 +- .../themes/twentyfourteen/index.php | 4 +- .../themes/twentyfourteen/js/functions.js | 3 +- .../page-templates/contributors.php | 2 +- .../page-templates/full-width.php | 2 +- src/wp-content/themes/twentyfourteen/page.php | 2 +- .../themes/twentyfourteen/search.php | 6 +- .../themes/twentyfourteen/single.php | 6 +- src/wp-content/themes/twentyfourteen/tag.php | 6 +- .../twentyfourteen/taxonomy-post_format.php | 6 +- .../themes/twentynineteen/archive.php | 3 +- .../class-twentynineteen-svg-icons.php | 2 +- .../themes/twentynineteen/comments.php | 4 +- .../themes/twentynineteen/image.php | 2 +- .../twentynineteen/inc/template-functions.php | 6 +- .../twentynineteen/inc/template-tags.php | 6 +- .../twentynineteen/js/customize-preview.js | 4 +- .../themes/twentynineteen/js/priority-menu.js | 40 +- .../js/touch-keyboard-navigation.js | 76 +- src/wp-content/themes/twentynineteen/page.php | 4 +- .../themes/twentynineteen/search.php | 3 +- .../themes/twentynineteen/single.php | 4 +- .../template-parts/header/entry-header.php | 2 +- .../themes/twentyseventeen/archive.php | 5 +- .../assets/js/customize-preview.js | 2 +- .../twentyseventeen/inc/custom-header.php | 2 +- .../twentyseventeen/inc/template-tags.php | 17 +- .../themes/twentyseventeen/index.php | 5 +- .../themes/twentyseventeen/page.php | 2 +- .../themes/twentyseventeen/search.php | 4 +- .../themes/twentyseventeen/single.php | 4 +- .../themes/twentysixteen/archive.php | 5 +- .../themes/twentysixteen/functions.php | 2 +- src/wp-content/themes/twentysixteen/image.php | 2 +- .../themes/twentysixteen/inc/customizer.php | 8 +- .../twentysixteen/inc/template-tags.php | 8 +- src/wp-content/themes/twentysixteen/index.php | 3 +- src/wp-content/themes/twentysixteen/page.php | 2 +- .../themes/twentysixteen/single.php | 2 +- src/wp-content/themes/twentyten/404.php | 2 +- src/wp-content/themes/twentyten/archive.php | 6 +- src/wp-content/themes/twentyten/author.php | 6 +- src/wp-content/themes/twentyten/comments.php | 6 +- src/wp-content/themes/twentyten/functions.php | 14 +- src/wp-content/themes/twentyten/header.php | 12 +- .../themes/twentyten/loop-attachment.php | 50 +- src/wp-content/themes/twentyten/loop-page.php | 2 +- .../themes/twentyten/loop-single.php | 4 +- src/wp-content/themes/twentyten/loop.php | 8 +- src/wp-content/themes/twentyten/sidebar.php | 2 +- src/wp-content/themes/twentyten/tag.php | 16 +- .../themes/twentythirteen/archive.php | 2 +- .../themes/twentythirteen/author.php | 8 +- .../themes/twentythirteen/category.php | 4 +- .../themes/twentythirteen/comments.php | 2 +- .../themes/twentythirteen/content.php | 2 +- .../themes/twentythirteen/functions.php | 8 +- .../themes/twentythirteen/image.php | 4 +- .../themes/twentythirteen/index.php | 2 +- src/wp-content/themes/twentythirteen/page.php | 2 +- .../themes/twentythirteen/search.php | 2 +- .../themes/twentythirteen/single.php | 2 +- src/wp-content/themes/twentythirteen/tag.php | 4 +- .../twentythirteen/taxonomy-post_format.php | 2 +- .../themes/twentytwelve/archive.php | 7 +- src/wp-content/themes/twentytwelve/author.php | 12 +- .../themes/twentytwelve/category.php | 9 +- .../themes/twentytwelve/comments.php | 7 +- .../themes/twentytwelve/content.php | 15 +- .../themes/twentytwelve/functions.php | 6 +- src/wp-content/themes/twentytwelve/image.php | 48 +- .../themes/twentytwelve/inc/custom-header.php | 2 +- src/wp-content/themes/twentytwelve/index.php | 6 +- .../twentytwelve/js/theme-customizer.js | 2 +- .../page-templates/front-page.php | 2 +- .../page-templates/full-width.php | 2 +- src/wp-content/themes/twentytwelve/page.php | 2 +- src/wp-content/themes/twentytwelve/search.php | 2 +- src/wp-content/themes/twentytwelve/single.php | 2 +- src/wp-content/themes/twentytwelve/tag.php | 8 +- .../assets/js/color-calculations.js | 2 + .../assets/js/customize-preview.js | 8 +- .../themes/twentytwenty/assets/js/index.js | 132 ++-- ...class-twentytwenty-non-latin-languages.php | 2 +- .../class-twentytwenty-script-loader.php | 2 +- .../classes/class-twentytwenty-svg-icons.php | 6 +- .../class-twentytwenty-walker-comment.php | 8 +- .../class-twentytwenty-walker-page.php | 2 +- .../themes/twentytwenty/comments.php | 6 +- src/wp-content/themes/twentytwenty/footer.php | 4 +- .../themes/twentytwenty/functions.php | 2 +- .../themes/twentytwenty/inc/custom-css.php | 2 +- .../themes/twentytwenty/inc/svg-icons.php | 2 +- .../themes/twentytwenty/inc/template-tags.php | 8 +- src/wp-content/themes/twentytwenty/index.php | 2 +- .../themes/twentytwenty/searchform.php | 4 +- .../template-parts/content-cover.php | 4 +- .../template-parts/entry-author-bio.php | 2 +- .../template-parts/entry-header.php | 2 +- .../template-parts/featured-image.php | 2 +- .../template-parts/footer-menus-widgets.php | 2 +- .../template-parts/pagination.php | 6 +- src/wp-includes/admin-bar.php | 12 +- src/wp-includes/author-template.php | 2 +- src/wp-includes/bookmark-template.php | 8 +- src/wp-includes/bookmark.php | 4 +- src/wp-includes/canonical.php | 128 ++-- src/wp-includes/capabilities.php | 8 +- src/wp-includes/category-template.php | 11 +- src/wp-includes/category.php | 2 +- src/wp-includes/class-http.php | 10 +- src/wp-includes/class-walker-nav-menu.php | 2 +- src/wp-includes/class-wp-admin-bar.php | 8 +- src/wp-includes/class-wp-ajax-response.php | 2 +- src/wp-includes/class-wp-comment-query.php | 8 +- .../class-wp-customize-manager.php | 32 +- .../class-wp-customize-setting.php | 2 +- .../class-wp-customize-widgets.php | 22 +- src/wp-includes/class-wp-date-query.php | 20 +- src/wp-includes/class-wp-editor.php | 84 ++- src/wp-includes/class-wp-embed.php | 24 +- .../class-wp-fatal-error-handler.php | 2 +- src/wp-includes/class-wp-hook.php | 6 +- src/wp-includes/class-wp-http-ixr-client.php | 14 +- .../class-wp-http-requests-hooks.php | 2 +- src/wp-includes/class-wp-http-streams.php | 8 +- src/wp-includes/class-wp-image-editor-gd.php | 14 +- .../class-wp-image-editor-imagick.php | 24 +- src/wp-includes/class-wp-image-editor.php | 8 +- src/wp-includes/class-wp-locale.php | 10 +- src/wp-includes/class-wp-matchesmapregex.php | 2 +- src/wp-includes/class-wp-network-query.php | 2 +- src/wp-includes/class-wp-network.php | 2 +- src/wp-includes/class-wp-oembed.php | 14 +- .../class-wp-paused-extensions-storage.php | 2 +- src/wp-includes/class-wp-post-type.php | 10 +- src/wp-includes/class-wp-query.php | 118 +-- .../class-wp-recovery-mode-cookie-service.php | 2 +- .../class-wp-recovery-mode-email-service.php | 2 +- .../class-wp-recovery-mode-key-service.php | 2 +- .../class-wp-recovery-mode-link-service.php | 2 +- src/wp-includes/class-wp-recovery-mode.php | 2 +- src/wp-includes/class-wp-rewrite.php | 12 +- src/wp-includes/class-wp-session-tokens.php | 2 +- src/wp-includes/class-wp-simplepie-file.php | 2 +- src/wp-includes/class-wp-site-query.php | 2 +- src/wp-includes/class-wp-tax-query.php | 4 +- src/wp-includes/class-wp-taxonomy.php | 16 +- .../class-wp-text-diff-renderer-table.php | 42 +- src/wp-includes/class-wp-theme.php | 22 +- src/wp-includes/class-wp-user-query.php | 8 +- src/wp-includes/class-wp-user.php | 2 +- src/wp-includes/class-wp-walker.php | 20 +- src/wp-includes/class-wp-widget-factory.php | 2 +- src/wp-includes/class-wp-widget.php | 8 +- src/wp-includes/class-wp-xmlrpc-server.php | 357 ++++----- src/wp-includes/class-wp.php | 27 +- src/wp-includes/class.wp-dependencies.php | 10 +- src/wp-includes/comment-template.php | 26 +- src/wp-includes/comment.php | 108 +-- src/wp-includes/compat.php | 6 +- src/wp-includes/cron.php | 36 +- .../class-wp-customize-nav-menu-setting.php | 2 +- .../class-wp-customize-themes-section.php | 4 +- .../class-wp-customize-upload-control.php | 6 +- src/wp-includes/default-constants.php | 40 +- src/wp-includes/default-filters.php | 132 ++-- src/wp-includes/deprecated.php | 44 +- src/wp-includes/error-protection.php | 2 +- src/wp-includes/feed-atom-comments.php | 85 ++- src/wp-includes/feed-atom.php | 21 +- src/wp-includes/feed-rdf.php | 15 +- src/wp-includes/feed-rss.php | 1 - src/wp-includes/feed-rss2-comments.php | 87 ++- src/wp-includes/feed-rss2.php | 28 +- src/wp-includes/feed.php | 4 +- src/wp-includes/formatting.php | 413 ++++++----- src/wp-includes/functions.php | 164 +++-- src/wp-includes/functions.wp-scripts.php | 2 +- src/wp-includes/functions.wp-styles.php | 2 +- src/wp-includes/general-template.php | 72 +- src/wp-includes/http.php | 6 +- src/wp-includes/kses.php | 100 +-- src/wp-includes/link-template.php | 30 +- src/wp-includes/load.php | 42 +- src/wp-includes/media.php | 137 ++-- src/wp-includes/meta.php | 18 +- src/wp-includes/ms-blogs.php | 6 +- src/wp-includes/ms-default-constants.php | 4 +- src/wp-includes/ms-default-filters.php | 32 +- src/wp-includes/ms-deprecated.php | 26 +- src/wp-includes/ms-files.php | 10 +- src/wp-includes/ms-functions.php | 56 +- src/wp-includes/ms-load.php | 20 +- src/wp-includes/ms-settings.php | 6 +- src/wp-includes/ms-site.php | 8 +- src/wp-includes/nav-menu-template.php | 40 +- src/wp-includes/nav-menu.php | 32 +- src/wp-includes/option.php | 38 +- src/wp-includes/pluggable.php | 165 +++-- src/wp-includes/plugin.php | 33 +- src/wp-includes/pomo/entry.php | 8 +- src/wp-includes/pomo/mo.php | 32 +- src/wp-includes/pomo/plural-forms.php | 14 +- src/wp-includes/pomo/po.php | 28 +- src/wp-includes/pomo/translations.php | 2 +- src/wp-includes/post-formats.php | 2 +- src/wp-includes/post-template.php | 52 +- src/wp-includes/post.php | 40 +- src/wp-includes/query.php | 12 +- src/wp-includes/rest-api.php | 56 +- .../rest-api/class-wp-rest-request.php | 7 +- .../rest-api/class-wp-rest-response.php | 3 + .../rest-api/class-wp-rest-server.php | 43 +- .../class-wp-rest-attachments-controller.php | 124 +++- .../class-wp-rest-autosaves-controller.php | 37 +- ...lass-wp-rest-block-renderer-controller.php | 2 + .../class-wp-rest-comments-controller.php | 233 +++++- .../endpoints/class-wp-rest-controller.php | 110 ++- ...class-wp-rest-post-statuses-controller.php | 25 +- .../class-wp-rest-post-types-controller.php | 25 +- .../class-wp-rest-posts-controller.php | 239 ++++-- .../class-wp-rest-revisions-controller.php | 73 +- .../class-wp-rest-search-controller.php | 31 +- .../class-wp-rest-settings-controller.php | 4 + .../class-wp-rest-taxonomies-controller.php | 29 +- .../class-wp-rest-terms-controller.php | 85 ++- .../class-wp-rest-themes-controller.php | 7 +- .../class-wp-rest-users-controller.php | 203 ++++- .../fields/class-wp-rest-meta-fields.php | 16 +- src/wp-includes/revision.php | 50 +- src/wp-includes/rewrite.php | 36 +- src/wp-includes/script-loader.php | 81 +- src/wp-includes/shortcodes.php | 68 +- src/wp-includes/taxonomy.php | 39 +- src/wp-includes/template.php | 3 +- src/wp-includes/theme-compat/comments.php | 6 +- src/wp-includes/theme-compat/header.php | 4 +- src/wp-includes/theme.php | 80 +- src/wp-includes/update.php | 30 +- src/wp-includes/user.php | 49 +- src/wp-includes/vars.php | 12 +- src/wp-includes/widgets.php | 36 +- .../widgets/class-wp-nav-menu-widget.php | 4 +- .../widgets/class-wp-widget-categories.php | 2 +- .../widgets/class-wp-widget-custom-html.php | 9 +- .../widgets/class-wp-widget-links.php | 2 +- .../widgets/class-wp-widget-media.php | 11 +- .../widgets/class-wp-widget-pages.php | 2 +- .../class-wp-widget-recent-comments.php | 2 +- .../widgets/class-wp-widget-rss.php | 2 +- .../widgets/class-wp-widget-search.php | 2 +- .../widgets/class-wp-widget-tag-cloud.php | 2 +- .../widgets/class-wp-widget-text.php | 10 +- src/wp-includes/wp-db.php | 73 +- src/wp-load.php | 2 +- src/wp-login.php | 20 +- src/wp-mail.php | 15 +- src/wp-settings.php | 10 +- src/wp-signup.php | 8 +- src/xmlrpc.php | 4 +- .../WPHTTP-testcase-redirection-script.php | 4 +- tests/phpunit/data/formatting/whole-posts.php | 2 +- .../data/themedir1/camelCase/index.php | 2 +- .../data/themedir1/default/comments.php | 2 +- .../data/themedir1/default/functions.php | 2 +- .../data/themedir1/page-templates/index.php | 2 +- .../data/themedir1/sandbox/functions.php | 2 +- .../phpunit/data/themedir1/sandbox/index.php | 2 +- .../data/themedir1/theme1-dupe/functions.php | 2 +- .../data/themedir1/theme1-dupe/index.php | 2 +- .../data/themedir1/theme1/functions.php | 2 +- tests/phpunit/data/themedir1/theme1/index.php | 2 +- tests/phpunit/includes/abstract-testcase.php | 19 +- tests/phpunit/includes/bootstrap.php | 12 +- ...ass-wp-unittest-factory-for-attachment.php | 2 +- tests/phpunit/includes/functions.php | 4 +- tests/phpunit/includes/install.php | 2 +- tests/phpunit/includes/mock-fs.php | 25 +- .../includes/phpunit7/speed-trap-listener.php | 2 +- .../phpunit/includes/speed-trap-listener.php | 2 +- tests/phpunit/includes/testcase-ajax.php | 16 +- tests/phpunit/includes/testcase-canonical.php | 13 +- .../testcase-rest-post-type-controller.php | 22 +- tests/phpunit/includes/trac.php | 2 +- tests/phpunit/includes/utils.php | 34 +- tests/phpunit/includes/wp-profiler.php | 35 +- tests/phpunit/multisite.xml | 12 +- tests/phpunit/tests/actions.php | 92 +-- .../phpunit/tests/admin/includesListTable.php | 12 +- tests/phpunit/tests/admin/includesMisc.php | 10 +- tests/phpunit/tests/admin/includesPlugin.php | 2 +- tests/phpunit/tests/admin/includesPost.php | 22 +- tests/phpunit/tests/admin/includesScreen.php | 12 +- .../phpunit/tests/admin/includesTemplate.php | 6 +- tests/phpunit/tests/admin/includesTheme.php | 4 +- tests/phpunit/tests/adminbar.php | 26 +- tests/phpunit/tests/ajax/AddMeta.php | 2 +- tests/phpunit/tests/ajax/Attachments.php | 20 +- tests/phpunit/tests/ajax/Autosave.php | 36 +- tests/phpunit/tests/ajax/Compression.php | 78 +- tests/phpunit/tests/ajax/CustomizeManager.php | 2 +- tests/phpunit/tests/ajax/CustomizeMenus.php | 14 +- tests/phpunit/tests/ajax/DeleteComment.php | 90 +-- tests/phpunit/tests/ajax/DeletePlugin.php | 12 +- tests/phpunit/tests/ajax/DimComment.php | 54 +- tests/phpunit/tests/ajax/EditComment.php | 60 +- tests/phpunit/tests/ajax/GetComments.php | 42 +- tests/phpunit/tests/ajax/ManageThemes.php | 2 +- tests/phpunit/tests/ajax/MediaEdit.php | 6 +- .../tests/ajax/PrivacyErasePersonalData.php | 4 +- .../tests/ajax/PrivacyExportPersonalData.php | 4 +- tests/phpunit/tests/ajax/QuickEdit.php | 6 +- tests/phpunit/tests/ajax/ReplytoComment.php | 64 +- tests/phpunit/tests/ajax/Response.php | 12 +- tests/phpunit/tests/ajax/TagSearch.php | 48 +- tests/phpunit/tests/ajax/UpdatePlugin.php | 14 +- tests/phpunit/tests/attachment/slashes.php | 6 +- tests/phpunit/tests/auth.php | 48 +- tests/phpunit/tests/basic.php | 8 +- tests/phpunit/tests/bookmark/getBookmarks.php | 8 +- tests/phpunit/tests/cache.php | 46 +- tests/phpunit/tests/canonical.php | 72 +- tests/phpunit/tests/canonical/category.php | 5 +- tests/phpunit/tests/canonical/customRules.php | 11 +- tests/phpunit/tests/canonical/noRewrite.php | 159 ++-- tests/phpunit/tests/canonical/pageOnFront.php | 11 +- tests/phpunit/tests/category.php | 46 +- tests/phpunit/tests/comment-submission.php | 6 +- tests/phpunit/tests/comment.php | 2 +- tests/phpunit/tests/comment/dateQuery.php | 8 +- .../tests/comment/getCommentsPagesCount.php | 6 +- .../tests/comment/getPageOfComment.php | 8 +- tests/phpunit/tests/comment/query.php | 6 +- tests/phpunit/tests/comment/slashes.php | 28 +- tests/phpunit/tests/comment/template.php | 2 +- tests/phpunit/tests/comment/walker.php | 4 +- .../phpunit/tests/comment/wpListComments.php | 10 +- tests/phpunit/tests/compat.php | 18 +- tests/phpunit/tests/cron.php | 120 +-- tests/phpunit/tests/customize/manager.php | 14 +- tests/phpunit/tests/customize/setting.php | 2 +- tests/phpunit/tests/customize/widgets.php | 2 +- tests/phpunit/tests/date/query.php | 48 +- tests/phpunit/tests/db.php | 77 +- tests/phpunit/tests/db/charset.php | 72 +- tests/phpunit/tests/dbdelta.php | 6 +- tests/phpunit/tests/dependencies.php | 2 +- tests/phpunit/tests/dependencies/scripts.php | 66 +- tests/phpunit/tests/dependencies/styles.php | 24 +- .../recovery-mode-key-service.php | 6 +- tests/phpunit/tests/external-http/basic.php | 2 +- tests/phpunit/tests/feed/atom.php | 30 +- tests/phpunit/tests/feed/rss2.php | 64 +- tests/phpunit/tests/file.php | 16 +- tests/phpunit/tests/filesystem/base.php | 4 +- tests/phpunit/tests/filesystem/findFolder.php | 2 +- tests/phpunit/tests/filters.php | 56 +- tests/phpunit/tests/formatting/Autop.php | 29 +- tests/phpunit/tests/formatting/BlogInfo.php | 2 +- tests/phpunit/tests/formatting/Emoji.php | 16 +- tests/phpunit/tests/formatting/EscHtml.php | 6 +- tests/phpunit/tests/formatting/EscUrl.php | 2 +- .../tests/formatting/GetUrlInContent.php | 24 +- tests/phpunit/tests/formatting/JSEscape.php | 6 +- tests/phpunit/tests/formatting/LikeEscape.php | 8 +- .../tests/formatting/MakeClickable.php | 44 +- .../tests/formatting/RemoveAccents.php | 28 +- .../tests/formatting/SanitizeMimeType.php | 5 +- .../tests/formatting/SanitizeTextField.php | 8 +- tests/phpunit/tests/formatting/SeemsUtf8.php | 4 +- tests/phpunit/tests/formatting/Smilies.php | 32 +- .../tests/formatting/StripSlashesDeep.php | 10 +- tests/phpunit/tests/formatting/URLShorten.php | 13 +- .../tests/formatting/Utf8UriEncode.php | 2 +- .../tests/formatting/WPSpecialchars.php | 2 +- .../tests/formatting/WPStripAllTags.php | 6 +- .../tests/formatting/WPTargetedLinkRel.php | 4 +- .../phpunit/tests/formatting/WPTexturize.php | 100 +-- .../phpunit/tests/formatting/WPTrimWords.php | 4 +- .../phpunit/tests/formatting/balanceTags.php | 2 +- tests/phpunit/tests/formatting/ent2ncr.php | 2 +- tests/phpunit/tests/functions.php | 76 +- .../tests/functions/allowedProtocols.php | 26 +- tests/phpunit/tests/functions/deprecated.php | 8 +- tests/phpunit/tests/functions/wpAuthCheck.php | 6 +- tests/phpunit/tests/general/paginateLinks.php | 8 +- tests/phpunit/tests/general/template.php | 6 +- tests/phpunit/tests/http/base.php | 72 +- tests/phpunit/tests/http/functions.php | 20 +- tests/phpunit/tests/http/http.php | 39 +- tests/phpunit/tests/image/dimensions.php | 118 +-- tests/phpunit/tests/image/editor.php | 30 +- tests/phpunit/tests/image/editorGd.php | 4 +- tests/phpunit/tests/image/editorImagick.php | 4 +- tests/phpunit/tests/image/functions.php | 52 +- tests/phpunit/tests/image/header.php | 2 +- .../phpunit/tests/image/intermediateSize.php | 72 +- tests/phpunit/tests/image/meta.php | 20 +- tests/phpunit/tests/image/resize.php | 6 +- tests/phpunit/tests/image/siteIcon.php | 2 +- tests/phpunit/tests/image/size.php | 30 +- tests/phpunit/tests/import/base.php | 10 +- tests/phpunit/tests/import/import.php | 14 +- tests/phpunit/tests/import/parser.php | 4 +- tests/phpunit/tests/import/postmeta.php | 6 +- tests/phpunit/tests/includes/helpers.php | 12 +- tests/phpunit/tests/kses.php | 2 +- tests/phpunit/tests/link.php | 14 +- tests/phpunit/tests/link/getAdjacentPost.php | 22 +- .../tests/link/getAdjacentPostLink.php | 2 +- tests/phpunit/tests/mail.php | 14 +- tests/phpunit/tests/media.php | 56 +- tests/phpunit/tests/meta.php | 30 +- tests/phpunit/tests/meta/query.php | 34 +- tests/phpunit/tests/meta/slashes.php | 22 +- tests/phpunit/tests/multisite.php | 6 +- tests/phpunit/tests/multisite/site.php | 30 +- tests/phpunit/tests/multisite/siteDetails.php | 2 +- tests/phpunit/tests/multisite/siteQuery.php | 2 +- tests/phpunit/tests/oembed/postEmbedUrl.php | 2 +- tests/phpunit/tests/option/multisite.php | 54 +- tests/phpunit/tests/option/option.php | 6 +- tests/phpunit/tests/option/siteOption.php | 14 +- tests/phpunit/tests/option/slashes.php | 4 +- tests/phpunit/tests/option/transient.php | 26 +- tests/phpunit/tests/option/userSettings.php | 2 +- tests/phpunit/tests/pluggable.php | 4 +- tests/phpunit/tests/pomo/pluralForms.php | 10 +- tests/phpunit/tests/pomo/po.php | 22 +- tests/phpunit/tests/pomo/translationEntry.php | 4 +- tests/phpunit/tests/pomo/translations.php | 12 +- tests/phpunit/tests/post.php | 184 ++--- tests/phpunit/tests/post/attachments.php | 38 +- tests/phpunit/tests/post/filtering.php | 16 +- tests/phpunit/tests/post/formats.php | 6 +- tests/phpunit/tests/post/getPageUri.php | 6 +- tests/phpunit/tests/post/getPages.php | 10 +- tests/phpunit/tests/post/meta.php | 70 +- tests/phpunit/tests/post/nav-menu.php | 22 +- tests/phpunit/tests/post/objects.php | 18 +- tests/phpunit/tests/post/output.php | 8 +- tests/phpunit/tests/post/query.php | 24 +- tests/phpunit/tests/post/revisions.php | 75 +- tests/phpunit/tests/post/slashes.php | 16 +- tests/phpunit/tests/post/template.php | 4 +- tests/phpunit/tests/post/types.php | 8 +- tests/phpunit/tests/post/wpUniquePostSlug.php | 2 +- tests/phpunit/tests/query/commentCount.php | 2 +- tests/phpunit/tests/query/conditionals.php | 84 +-- tests/phpunit/tests/query/date.php | 8 +- tests/phpunit/tests/query/dateQuery.php | 6 +- tests/phpunit/tests/query/isTerm.php | 16 +- tests/phpunit/tests/query/metaQuery.php | 2 +- tests/phpunit/tests/query/results.php | 44 +- tests/phpunit/tests/query/search.php | 6 +- tests/phpunit/tests/query/taxQuery.php | 28 +- tests/phpunit/tests/rest-api.php | 32 +- .../rest-api/rest-attachments-controller.php | 60 +- .../rest-api/rest-categories-controller.php | 10 +- .../rest-api/rest-comments-controller.php | 34 +- .../tests/rest-api/rest-pages-controller.php | 12 +- .../tests/rest-api/rest-post-meta-fields.php | 4 +- .../rest-post-statuses-controller.php | 4 +- .../rest-api/rest-post-types-controller.php | 4 +- .../tests/rest-api/rest-posts-controller.php | 38 +- .../rest-api/rest-revisions-controller.php | 8 +- tests/phpunit/tests/rest-api/rest-server.php | 14 +- .../rest-api/rest-settings-controller.php | 10 +- .../tests/rest-api/rest-tags-controller.php | 20 +- .../rest-api/rest-taxonomies-controller.php | 6 +- .../tests/rest-api/rest-users-controller.php | 56 +- tests/phpunit/tests/rewrite.php | 8 +- tests/phpunit/tests/rewrite/numericSlugs.php | 4 +- tests/phpunit/tests/shortcode.php | 36 +- tests/phpunit/tests/taxonomy.php | 36 +- tests/phpunit/tests/term.php | 10 +- tests/phpunit/tests/term/cache.php | 4 +- tests/phpunit/tests/term/getTerms.php | 70 +- tests/phpunit/tests/term/query.php | 4 +- tests/phpunit/tests/term/slashes.php | 4 +- tests/phpunit/tests/term/taxQuery.php | 2 +- tests/phpunit/tests/term/termExists.php | 4 +- .../phpunit/tests/term/wpGenerateTagCloud.php | 14 +- tests/phpunit/tests/term/wpGetObjectTerms.php | 12 +- tests/phpunit/tests/term/wpInsertTerm.php | 18 +- tests/phpunit/tests/term/wpSetObjectTerms.php | 52 +- tests/phpunit/tests/theme.php | 51 +- tests/phpunit/tests/theme/WPTheme.php | 30 +- tests/phpunit/tests/theme/support.php | 4 +- tests/phpunit/tests/theme/themeDir.php | 18 +- tests/phpunit/tests/upload.php | 12 +- tests/phpunit/tests/url.php | 27 +- tests/phpunit/tests/user.php | 102 +-- tests/phpunit/tests/user/author.php | 4 +- tests/phpunit/tests/user/capabilities.php | 267 ++++--- tests/phpunit/tests/user/countUsers.php | 20 +- tests/phpunit/tests/user/multisite.php | 10 +- tests/phpunit/tests/user/query.php | 20 +- tests/phpunit/tests/user/slashes.php | 24 +- tests/phpunit/tests/user/wpDeleteUser.php | 6 +- tests/phpunit/tests/user/wpDropdownUsers.php | 8 +- .../tests/user/wpGetUsersWithNoRole.php | 18 +- tests/phpunit/tests/walker.php | 14 +- tests/phpunit/tests/widgets.php | 10 +- tests/phpunit/tests/widgets/text-widget.php | 6 +- tests/phpunit/tests/xmlrpc/basic.php | 8 +- tests/phpunit/tests/xmlrpc/mw/editPost.php | 14 +- tests/phpunit/tests/xmlrpc/mw/getPost.php | 6 +- .../tests/xmlrpc/mw/getRecentPosts.php | 6 +- tests/phpunit/tests/xmlrpc/mw/newPost.php | 2 +- tests/phpunit/tests/xmlrpc/wp/editPost.php | 48 +- tests/phpunit/tests/xmlrpc/wp/editProfile.php | 2 +- tests/phpunit/tests/xmlrpc/wp/getComment.php | 4 +- tests/phpunit/tests/xmlrpc/wp/getComments.php | 2 +- .../phpunit/tests/xmlrpc/wp/getMediaItem.php | 4 +- tests/phpunit/tests/xmlrpc/wp/getOptions.php | 8 +- tests/phpunit/tests/xmlrpc/wp/getPage.php | 4 +- tests/phpunit/tests/xmlrpc/wp/getPost.php | 8 +- tests/phpunit/tests/xmlrpc/wp/getPostType.php | 12 +- .../phpunit/tests/xmlrpc/wp/getPostTypes.php | 2 +- tests/phpunit/tests/xmlrpc/wp/getPosts.php | 22 +- .../phpunit/tests/xmlrpc/wp/getRevisions.php | 2 +- tests/phpunit/tests/xmlrpc/wp/getTerm.php | 4 +- tests/phpunit/tests/xmlrpc/wp/getTerms.php | 23 +- tests/phpunit/tests/xmlrpc/wp/getUser.php | 6 +- tests/phpunit/tests/xmlrpc/wp/getUsers.php | 8 +- tests/phpunit/tests/xmlrpc/wp/newComment.php | 4 +- tests/phpunit/tests/xmlrpc/wp/newPost.php | 10 +- .../tests/xmlrpc/wp/restoreRevision.php | 5 +- tests/phpunit/tests/xmlrpc/wp/setOptions.php | 2 +- tests/phpunit/tests/xmlrpc/wp/uploadFile.php | 4 +- tests/phpunit/wp-mail-real-test.php | 16 +- tests/qunit/fixtures/customize-menus.js | 10 +- tests/qunit/fixtures/updates.js | 4 +- tests/qunit/fixtures/wp-api.js | 2 +- tests/qunit/wp-admin/js/customize-base.js | 4 +- tests/qunit/wp-admin/js/customize-controls.js | 22 +- .../qunit/wp-admin/js/customize-nav-menus.js | 29 +- .../wp-admin/js/password-strength-meter.js | 2 +- tests/qunit/wp-admin/js/updates.js | 2 +- .../js/widgets/test-media-image-widget.js | 2 +- tests/qunit/wp-includes/js/shortcode.js | 24 +- .../tinymce/plugins/wptextpattern/plugin.js | 8 +- wp-tests-config-sample.php | 26 +- 810 files changed, 9893 insertions(+), 8384 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 58350bfa5b..0ed08c39b8 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -43,7 +43,7 @@ module.exports = function(grunt) { // Load tasks. require('matchdep').filterDev(['grunt-*', '!grunt-legacy-util']).forEach( grunt.loadNpmTasks ); - // Load legacy utils + // Load legacy utils. grunt.util = require('grunt-legacy-util'); // Project configuration. @@ -144,7 +144,7 @@ module.exports = function(grunt) { '!assets/**', // Assets is extracted into separate copy tasks. '!js/**', // JavaScript is extracted into separate copy tasks. '!.{svn,git}', // Exclude version control folders. - '!wp-includes/version.php', // Exclude version.php + '!wp-includes/version.php', // Exclude version.php. '!**/*.map', // The build doesn't need .map files. '!index.php', '!wp-admin/index.php', '!_index.php', '!wp-admin/_index.php' @@ -168,7 +168,7 @@ module.exports = function(grunt) { [ WORKING_DIR + 'wp-includes/js/clipboard.js' ]: [ './node_modules/clipboard/dist/clipboard.js' ], [ WORKING_DIR + 'wp-includes/js/hoverIntent.js' ]: [ './node_modules/jquery-hoverintent/jquery.hoverIntent.js' ], - // Renamed to avoid conflict with jQuery hoverIntent.min.js (after minifying) + // Renamed to avoid conflict with jQuery hoverIntent.min.js (after minifying). [ WORKING_DIR + 'wp-includes/js/hoverintent-js.min.js' ]: [ './node_modules/hoverintent/dist/hoverintent.min.js' ], [ WORKING_DIR + 'wp-includes/js/imagesloaded.min.js' ]: [ './node_modules/imagesloaded/imagesloaded.pkgd.min.js' ], [ WORKING_DIR + 'wp-includes/js/jquery/jquery-migrate.js' ]: [ './node_modules/jquery-migrate/dist/jquery-migrate.js' ], @@ -448,7 +448,7 @@ module.exports = function(grunt) { }, rtlcss: { options: { - // rtlcss options + // rtlcss options. opts: { clean: false, processUrls: { atrule: true, decl: false }, @@ -516,7 +516,7 @@ module.exports = function(grunt) { '!wp-includes/css/*.min.css', '!wp-includes/css/dist', - // Exceptions + // Exceptions. '!wp-includes/css/dashicons.css', '!wp-includes/css/wp-embed-template.css', '!wp-includes/css/wp-embed-template-ie.css' @@ -558,7 +558,7 @@ module.exports = function(grunt) { src: [ 'twenty*/**/*.js', '!twenty{eleven,twelve,thirteen}/**', - // Third party scripts + // Third party scripts. '!twenty{fourteen,fifteen,sixteen}/js/html5.js', '!twentyseventeen/assets/js/html5.js', '!twentyseventeen/assets/js/jquery.scrollTo.js', @@ -575,35 +575,36 @@ module.exports = function(grunt) { cwd: SOURCE_DIR, src: [ 'js/_enqueues/**/*.js', - // Third party scripts + // Third party scripts. '!js/_enqueues/vendor/**/*.js' ], - // Remove once other JSHint errors are resolved + // Remove once other JSHint errors are resolved. options: { curly: false, eqeqeq: false }, - // Limit JSHint's run to a single specified file: - // - // grunt jshint:core --file=filename.js - // - // Optionally, include the file path: - // - // grunt jshint:core --file=path/to/filename.js - // + /* + * Limit JSHint's run to a single specified file: + * + * grunt jshint:core --file=filename.js + * + * Optionally, include the file path: + * + * grunt jshint:core --file=path/to/filename.js + */ filter: function( filepath ) { var index, file = grunt.option( 'file' ); - // Don't filter when no target file is specified + // Don't filter when no target file is specified. if ( ! file ) { return true; } - // Normalize filepath for Windows + // Normalize filepath for Windows. filepath = filepath.replace( /\\/g, '/' ); index = filepath.lastIndexOf( '/' + file ); - // Match only the filename passed from cli + // Match only the filename passed from cli. if ( filepath === file || ( -1 !== index && index === filepath.length - ( file.length + 1 ) ) ) { return true; } @@ -618,14 +619,15 @@ module.exports = function(grunt) { '**/*.js', '!**/*.min.js' ], - // Limit JSHint's run to a single specified plugin directory: - // - // grunt jshint:plugins --dir=foldername - // + /* + * Limit JSHint's run to a single specified plugin directory: + * + * grunt jshint:plugins --dir=foldername + */ filter: function( dirpath ) { var index, dir = grunt.option( 'dir' ); - // Don't filter when no target folder is specified + // Don't filter when no target folder is specified. if ( ! dir ) { return true; } @@ -633,7 +635,7 @@ module.exports = function(grunt) { dirpath = dirpath.replace( /\\/g, '/' ); index = dirpath.lastIndexOf( '/' + dir ); - // Match only the folder name passed from cli + // Match only the folder name passed from cli. if ( -1 !== index ) { return true; } @@ -703,12 +705,12 @@ module.exports = function(grunt) { 'wp-includes/js/tinymce/plugins/wordpress/plugin.js', 'wp-includes/js/tinymce/plugins/wp*/plugin.js', - // Exceptions + // Exceptions. '!**/*.min.js', '!wp-admin/js/custom-header.js', // Why? We should minify this. '!wp-admin/js/farbtastic.js', '!wp-includes/js/swfobject.js', - '!wp-includes/js/wp-embed.js' // We have extra options for this, see uglify:embed + '!wp-includes/js/wp-embed.js' // We have extra options for this, see uglify:embed. ] }, embed: { @@ -1030,7 +1032,7 @@ module.exports = function(grunt) { grunt.log.writeln( 'Fetching list of Twemoji files...' ); - // Fetch a list of the files that Twemoji supplies + // Fetch a list of the files that Twemoji supplies. files = spawn( 'svn', [ 'ls', 'https://github.com/twitter/twemoji.git/trunk/assets/svg' ] ); if ( 0 !== files.status ) { grunt.fatal( 'Unable to fetch Twemoji file list' ); @@ -1038,33 +1040,33 @@ module.exports = function(grunt) { entities = files.stdout.toString(); - // Tidy up the file list + // Tidy up the file list. entities = entities.replace( /\.svg/g, '' ); entities = entities.replace( /^$/g, '' ); - // Convert the emoji entities to HTML entities + // Convert the emoji entities to HTML entities. partials = entities = entities.replace( /([a-z0-9]+)/g, '&#x$1;' ); - // Remove the hyphens between the HTML entities + // Remove the hyphens between the HTML entities. entities = entities.replace( /-/g, '' ); - // Sort the entities list by length, so the longest emoji will be found first + // Sort the entities list by length, so the longest emoji will be found first. emojiArray = entities.split( '\n' ).sort( function ( a, b ) { return b.length - a.length; } ); - // Convert the entities list to PHP array syntax + // Convert the entities list to PHP array syntax. entities = '\'' + emojiArray.filter( function( val ) { return val.length >= 8 ? val : false ; } ).join( '\', \'' ) + '\''; - // Create a list of all characters used by the emoji list + // Create a list of all characters used by the emoji list. partials = partials.replace( /-/g, '\n' ); - // Set automatically removes duplicates + // Set automatically removes duplicates. partialsSet = new Set( partials.split( '\n' ) ); - // Convert the partials list to PHP array syntax + // Convert the partials list to PHP array syntax. partials = '\'' + Array.from( partialsSet ).filter( function( val ) { return val.length >= 8 ? val : false ; } ).join( '\', \'' ) + '\''; @@ -1158,7 +1160,7 @@ module.exports = function(grunt) { } }); - // Allow builds to be minimal + // Allow builds to be minimal. if( grunt.option( 'minimal-copy' ) ) { var copyFilesOptions = grunt.config.get( 'copy.files.files' ); copyFilesOptions[0].src.push( '!wp-content/plugins/**' ); diff --git a/phpcompat.xml.dist b/phpcompat.xml.dist index 110b19cc63..727796c908 100644 --- a/phpcompat.xml.dist +++ b/phpcompat.xml.dist @@ -4,7 +4,7 @@ - + @@ -25,7 +25,7 @@ - + diff --git a/phpcs.xml.dist b/phpcs.xml.dist index b9dd8c5b99..2d9f152285 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -20,7 +20,7 @@ - + . @@ -48,7 +48,7 @@ - + @@ -62,14 +62,14 @@ - + - + - + @@ -77,7 +77,7 @@ - + @@ -89,11 +89,11 @@ - + - + - + @@ -102,7 +102,7 @@ ^build/* - + /node_modules/* /vendor/* @@ -140,7 +140,7 @@ /tests/phpunit/includes/speed-trap-listener\.php - + /tests/phpunit/build* /tests/phpunit/data/* @@ -214,7 +214,7 @@ - + @@ -229,7 +229,7 @@ - + @@ -238,7 +238,7 @@ - + @@ -270,7 +270,7 @@ - + * @@ -283,7 +283,7 @@ /tests/phpunit/tests/* - + /src/wp-admin/includes/class-wp-filesystem-ftpsockets\.php /src/wp-includes/class-wp-oembed\.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index eb1a1e7c46..b7da1303c1 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -5,12 +5,12 @@ beStrictAboutTestsThatDoNotTestAnything="true" > - + tests/phpunit/tests tests/phpunit/tests/rest-api/rest-autosaves-controller.php - + tests/phpunit/tests/rest-api/rest-autosaves-controller.php @@ -44,7 +44,7 @@ src - + src/wp-includes/ID3 src/wp-includes/IXR src/wp-includes/random_compat diff --git a/src/index.php b/src/index.php index 9e8f9ec856..c1be8ac3b0 100644 --- a/src/index.php +++ b/src/index.php @@ -29,7 +29,7 @@ require_once( ABSPATH . WPINC . '/version.php' ); wp_check_php_mysql_versions(); wp_load_translations_early(); -// Die with an error message +// Die with an error message. $die = sprintf( '

%s

', __( 'You are running WordPress without JavaScript and CSS files. These need to be built.' ) diff --git a/src/js/_enqueues/admin/comment.js b/src/js/_enqueues/admin/comment.js index f1fd2213a0..fd347d448b 100644 --- a/src/js/_enqueues/admin/comment.js +++ b/src/js/_enqueues/admin/comment.js @@ -70,7 +70,7 @@ jQuery(document).ready( function($) { * @param {Event} event The event object. * @return {void} */ - $timestampdiv.find('.save-timestamp').click( function( event ) { // crazyhorse - multiple ok cancels + $timestampdiv.find('.save-timestamp').click( function( event ) { // Crazyhorse - multiple OK cancels. var aa = $('#aa').val(), mm = $('#mm').val(), jj = $('#jj').val(), hh = $('#hh').val(), mn = $('#mn').val(), newD = new Date( aa, mm - 1, jj, hh, mn ); diff --git a/src/js/_enqueues/admin/common.js b/src/js/_enqueues/admin/common.js index 0541c8d0f2..75c77b3bac 100644 --- a/src/js/_enqueues/admin/common.js +++ b/src/js/_enqueues/admin/common.js @@ -168,7 +168,7 @@ window.validateForm = function( form ) { .length; }; -// stub for doing better warnings +// Stub for doing better warnings. /** * Shows message pop-up notice or confirmation message. * @@ -334,13 +334,13 @@ $('.contextual-help-tabs').delegate('a', 'click', function(e) { if ( link.is('.active a') ) return false; - // Links + // Links. $('.contextual-help-tabs .active').removeClass('active'); link.parent('li').addClass('active'); panel = $( link.attr('href') ); - // Panels + // Panels. $('.help-tab-content').not( panel ).removeClass('active').hide(); panel.addClass('active').show(); }); @@ -517,7 +517,7 @@ $document.ready( function() { $( '#collapse-button' ).on( 'click.collapse-menu', function() { var viewportWidth = getViewportWidth() || 961; - // reset any compensation for submenus near the bottom of the screen + // Reset any compensation for submenus near the bottom of the screen. $('#adminmenu div.wp-submenu').css('margin-top', ''); if ( viewportWidth < 960 ) { @@ -582,12 +582,12 @@ $document.ready( function() { menutop = $menuItem.offset().top; wintop = $window.scrollTop(); - maxtop = menutop - wintop - 30; // max = make the top of the sub almost touch admin bar + maxtop = menutop - wintop - 30; // max = make the top of the sub almost touch admin bar. - bottomOffset = menutop + $submenu.height() + 1; // Bottom offset of the menu - pageHeight = $wpwrap.height(); // Height of the entire page + bottomOffset = menutop + $submenu.height() + 1; // Bottom offset of the menu. + pageHeight = $wpwrap.height(); // Height of the entire page. adjustment = 60 + bottomOffset - pageHeight; - theFold = $window.height() + wintop - 50; // The fold + theFold = $window.height() + wintop - 50; // The fold. if ( theFold < ( bottomOffset - adjustment ) ) { adjustment = bottomOffset - theFold; @@ -604,8 +604,8 @@ $document.ready( function() { } } - if ( 'ontouchstart' in window || /IEMobile\/[1-9]/.test(navigator.userAgent) ) { // touch screen device - // iOS Safari works with touchstart, the rest work with click + if ( 'ontouchstart' in window || /IEMobile\/[1-9]/.test(navigator.userAgent) ) { // Touch screen device. + // iOS Safari works with touchstart, the rest work with click. mobileEvent = isIOS ? 'touchstart' : 'click'; /** @@ -639,9 +639,11 @@ $document.ready( function() { return; } - // Show the sub instead of following the link if: - // - the submenu is not open - // - the submenu is not shown inline or the menu is not folded + /* + * Show the sub instead of following the link if: + * - the submenu is not open. + * - the submenu is not shown inline or the menu is not folded. + */ if ( ! $menuItem.hasClass( 'opensub' ) && ( ! $menuItem.hasClass( 'wp-menu-open' ) || $menuItem.width() < 40 ) ) { event.preventDefault(); adjustSubmenu( $menuItem ); @@ -664,12 +666,12 @@ $document.ready( function() { $submenu = $menuItem.find( '.wp-submenu' ), top = parseInt( $submenu.css( 'top' ), 10 ); - if ( isNaN( top ) || top > -5 ) { // the submenu is visible + if ( isNaN( top ) || top > -5 ) { // The submenu is visible. return; } if ( $adminmenu.data( 'wp-responsive' ) ) { - // The menu is in responsive mode, bail + // The menu is in responsive mode, bail. return; } @@ -685,7 +687,7 @@ $document.ready( function() { */ out: function(){ if ( $adminmenu.data( 'wp-responsive' ) ) { - // The menu is in responsive mode, bail + // The menu is in responsive mode, bail. return; } @@ -705,7 +707,7 @@ $document.ready( function() { */ $adminmenu.on( 'focus.adminmenu', '.wp-submenu a', function( event ) { if ( $adminmenu.data( 'wp-responsive' ) ) { - // The menu is in responsive mode, bail + // The menu is in responsive mode, bail. return; } @@ -759,7 +761,7 @@ $document.ready( function() { $button = $( '' ), btnText = commonL10n.dismiss || ''; - // Ensure plain text + // Ensure plain text. $button.find( '.screen-reader-text' ).text( btnText ); $button.on( 'click.wp-dismiss-notice', function( event ) { event.preventDefault(); @@ -776,7 +778,7 @@ $document.ready( function() { $document.on( 'wp-updates-notice-added wp-plugin-install-error wp-plugin-update-error wp-plugin-delete-error wp-theme-install-error wp-theme-delete-error', makeNoticesDismissible ); - // Init screen meta + // Init screen meta. screenMeta.init(); /** @@ -902,7 +904,7 @@ $document.ready( function() { } }, '.has-row-actions' ); - // Toggle list table rows on small screens + // Toggle list table rows on small screens. $( 'tbody' ).on( 'click', '.toggle-row', function() { $( this ).closest( 'tr' ).toggleClass( 'is-expanded' ); }); @@ -925,7 +927,7 @@ $document.ready( function() { // After pressing escape key (keyCode: 27), the tab key should tab out of the textarea. if ( e.keyCode == 27 ) { - // when pressing Escape: Opera 12 and 27 blur form fields, IE 8 clears them + // When pressing Escape: Opera 12 and 27 blur form fields, IE 8 clears them. e.preventDefault(); $(el).data('tab-out', true); return; @@ -1276,7 +1278,7 @@ $document.ready( function() { this.maybeDisableSortables = this.maybeDisableSortables.bind( this ); - // Modify functionality based on custom activate/deactivate event + // Modify functionality based on custom activate/deactivate event. $document.on( 'wp-responsive-activate.wp-responsive', function() { self.activate(); }).on( 'wp-responsive-deactivate.wp-responsive', function() { @@ -1289,7 +1291,7 @@ $document.ready( function() { $( '#wp-admin-bar-menu-toggle' ).on( 'click.wp-responsive', function( event ) { event.preventDefault(); - // close any open toolbar submenus. + // Close any open toolbar submenus. $adminbar.find( '.hover' ).removeClass( 'hover' ); $wpwrap.toggleClass( 'wp-responsive-open' ); diff --git a/src/js/_enqueues/admin/edit-comments.js b/src/js/_enqueues/admin/edit-comments.js index 4391d50fef..1a64268b6a 100644 --- a/src/js/_enqueues/admin/edit-comments.js +++ b/src/js/_enqueues/admin/edit-comments.js @@ -192,7 +192,7 @@ var getCount, updateCount, updateCountText, updatePending, updateApproved, var newTitle, regExMatch, titleCount, commentFrag; titleRegEx = titleRegEx || new RegExp( adminCommentsL10n.docTitleCommentsCount.replace( '%s', '\\([0-9' + thousandsSeparator + ']+\\)' ) + '?' ); - // count funcs operate on a $'d element + // Count funcs operate on a $'d element. titleDiv = titleDiv || $( '
' ); newTitle = adminTitle; @@ -256,7 +256,7 @@ var getCount, updateCount, updateCountText, updatePending, updateApproved, return; } - // cache selectors to not get dupes + // Cache selectors to not get dupes. pending = $( 'span.' + pendingClass, postSelector ); noPending = $( 'span.' + noClass, postSelector ); @@ -444,7 +444,7 @@ window.setCommentsList = function() { a.click(function( e ){ e.preventDefault(); - e.stopPropagation(); // ticket #35904 + e.stopPropagation(); // Ticket #35904. list.wpList.del(this); $('#undo-' + id).css( {backgroundColor:'#ceb'} ).fadeOut(350, function(){ $(this).remove(); @@ -491,17 +491,19 @@ window.setCommentsList = function() { unapproved = commentRow.hasClass( 'unapproved' ), spammed = commentRow.hasClass( 'spam' ), trashed = commentRow.hasClass( 'trash' ), - undoing = false; // ticket #35904 + undoing = false; // Ticket #35904. updateDashboardText( newTotal ); updateInModerationText( newTotal ); - // the order of these checks is important - // .unspam can also have .approve or .unapprove - // .untrash can also have .approve or .unapprove + /* + * The order of these checks is important. + * .unspam can also have .approve or .unapprove. + * .untrash can also have .approve or .unapprove. + */ if ( targetParent.is( 'span.undo' ) ) { - // the comment was spammed + // The comment was spammed. if ( targetParent.hasClass( 'unspam' ) ) { spamDiff = -1; @@ -513,7 +515,7 @@ window.setCommentsList = function() { pendingDiff = 1; } - // the comment was trashed + // The comment was trashed. } else if ( targetParent.hasClass( 'untrash' ) ) { trashDiff = -1; @@ -528,32 +530,32 @@ window.setCommentsList = function() { undoing = true; - // user clicked "Spam" + // User clicked "Spam". } else if ( targetParent.is( 'span.spam' ) ) { - // the comment is currently approved + // The comment is currently approved. if ( approved ) { approvedDiff = -1; - // the comment is currently pending + // The comment is currently pending. } else if ( unapproved ) { pendingDiff = -1; - // the comment was in the trash + // The comment was in the trash. } else if ( trashed ) { trashDiff = -1; } - // you can't spam an item on the spam screen + // You can't spam an item on the Spam screen. spamDiff = 1; - // user clicked "Unspam" + // User clicked "Unspam". } else if ( targetParent.is( 'span.unspam' ) ) { if ( approved ) { pendingDiff = 1; } else if ( unapproved ) { approvedDiff = 1; } else if ( trashed ) { - // the comment was previously approved + // The comment was previously approved. if ( targetParent.hasClass( 'approve' ) ) { approvedDiff = 1; - // the comment was previously pending + // The comment was previously pending. } else if ( targetParent.hasClass( 'unapprove' ) ) { pendingDiff = 1; } @@ -565,23 +567,23 @@ window.setCommentsList = function() { pendingDiff = 1; } } - // you can Unspam an item on the spam screen + // You can unspam an item on the Spam screen. spamDiff = -1; - // user clicked "Trash" + // User clicked "Trash". } else if ( targetParent.is( 'span.trash' ) ) { if ( approved ) { approvedDiff = -1; } else if ( unapproved ) { pendingDiff = -1; - // the comment was in the spam queue + // The comment was in the spam queue. } else if ( spammed ) { spamDiff = -1; } - // you can't trash an item on the trash screen + // You can't trash an item on the Trash screen. trashDiff = 1; - // user clicked "Restore" + // User clicked "Restore". } else if ( targetParent.is( 'span.untrash' ) ) { if ( approved ) { pendingDiff = 1; @@ -594,21 +596,21 @@ window.setCommentsList = function() { pendingDiff = 1; } } - // you can't go from trash to spam - // you can untrash on the trash screen + // You can't go from Trash to Spam. + // You can untrash on the Trash screen. trashDiff = -1; - // User clicked "Approve" + // User clicked "Approve". } else if ( targetParent.is( 'span.approve:not(.unspam):not(.untrash)' ) ) { approvedDiff = 1; pendingDiff = -1; - // User clicked "Unapprove" + // User clicked "Unapprove". } else if ( targetParent.is( 'span.unapprove:not(.unspam):not(.untrash)' ) ) { approvedDiff = -1; pendingDiff = 1; - // User clicked "Delete Permanently" + // User clicked "Delete Permanently". } else if ( targetParent.is( 'span.delete' ) ) { if ( spammed ) { spamDiff = -1; @@ -713,17 +715,17 @@ window.setCommentsList = function() { if (ev) { theExtraList.empty(); - args.number = Math.min(8, per_page); // see WP_Comments_List_Table::prepare_items() @ class-wp-comments-list-table.php + args.number = Math.min(8, per_page); // See WP_Comments_List_Table::prepare_items() in class-wp-comments-list-table.php. } else { args.number = 1; - args.offset = Math.min(8, per_page) - 1; // fetch only the next item on the extra list + args.offset = Math.min(8, per_page) - 1; // Fetch only the next item on the extra list. } args.no_placeholder = true; args.paged ++; - // $.query.get() needs some correction to be sent into an ajax request + // $.query.get() needs some correction to be sent into an Ajax request. if ( true === args.comment_type ) args.comment_type = ''; @@ -781,9 +783,9 @@ window.commentReply = { /** * Initializes the comment reply functionality. * - * @memberof commentReply - * * @since 2.7.0 + * + * @memberof commentReply */ init : function() { var row = $('#replyrow'); @@ -798,7 +800,7 @@ window.commentReply = { } }); - // add events + // Add events. $('#the-comment-list .column-comment > p').dblclick(function(){ commentReply.toggle($(this).parent()); }); @@ -911,7 +913,7 @@ window.commentReply = { .focus(); } - // reset the Quicktags buttons + // Reset the Quicktags buttons. if ( typeof QTags != 'undefined' ) QTags.closeAllTags('replycontent'); @@ -1029,7 +1031,7 @@ window.commentReply = { $('#replycontent').focus().keyup(function(e){ if ( e.which == 27 ) - commentReply.revert(); // close on Escape + commentReply.revert(); // Close on Escape. }); }, 600); @@ -1130,7 +1132,7 @@ window.commentReply = { updateCountText( 'span.all-count', 1 ); } - c = $.trim(r.data); // Trim leading whitespaces + c = $.trim(r.data); // Trim leading whitespaces. $(c).hide(); $('#replyrow').after(c); diff --git a/src/js/_enqueues/admin/inline-edit-post.js b/src/js/_enqueues/admin/inline-edit-post.js index 85cc742844..70a57e1200 100644 --- a/src/js/_enqueues/admin/inline-edit-post.js +++ b/src/js/_enqueues/admin/inline-edit-post.js @@ -29,41 +29,42 @@ window.wp = window.wp || {}; /** * Initializes the inline and bulk post editor. * - * Binds event handlers to the escape key to close the inline editor + * Binds event handlers to the Escape key to close the inline editor * and to the save and close buttons. Changes DOM to be ready for inline * editing. Adds event handler to bulk edit. * - * @memberof inlineEditPost * @since 2.7.0 * + * @memberof inlineEditPost + * * @return {void} */ init : function(){ var t = this, qeRow = $('#inline-edit'), bulkRow = $('#bulk-edit'); t.type = $('table.widefat').hasClass('pages') ? 'page' : 'post'; - // Post id prefix. + // Post ID prefix. t.what = '#post-'; /** - * Binds the escape key to revert the changes and close the quick editor. + * Binds the Escape key to revert the changes and close the quick editor. * * @return {boolean} The result of revert. */ qeRow.keyup(function(e){ - // Revert changes if escape key is pressed. + // Revert changes if Escape key is pressed. if ( e.which === 27 ) { return inlineEditPost.revert(); } }); /** - * Binds the escape key to revert the changes and close the bulk editor. + * Binds the Escape key to revert the changes and close the bulk editor. * * @return {boolean} The result of revert. */ bulkRow.keyup(function(e){ - // Revert changes if escape key is pressed. + // Revert changes if Escape key is pressed. if ( e.which === 27 ) { return inlineEditPost.revert(); } @@ -88,7 +89,7 @@ window.wp = window.wp || {}; }); /** - * If enter is pressed, and the target is not the cancel button, save the post. + * If Enter is pressed, and the target is not the cancel button, save the post. * * @return {boolean} The result of save. */ @@ -157,9 +158,10 @@ window.wp = window.wp || {}; * Toggles the quick edit window, hiding it when it's active and showing it when * inactive. * - * @memberof inlineEditPost * @since 2.7.0 * + * @memberof inlineEditPost + * * @param {Object} el Element within a post table row. */ toggle : function(el){ @@ -170,8 +172,9 @@ window.wp = window.wp || {}; /** * Creates the bulk editor row to edit multiple posts at once. * - * @memberof inlineEditPost * @since 2.7.0 + * + * @memberof inlineEditPost */ setBulk : function(){ var te = '', type = this.type, c = true; @@ -242,9 +245,10 @@ window.wp = window.wp || {}; /** * Creates a quick edit window for the post that has been clicked. * - * @memberof inlineEditPost * @since 2.7.0 * + * @memberof inlineEditPost + * * @param {number|Object} id The id of the clicked post or an element within a post * table row. * @return {boolean} Always returns false at the end of execution. @@ -409,7 +413,7 @@ window.wp = window.wp || {}; fields = $('#edit-'+id).find(':input').serialize(); params = fields + '&' + $.param(params); - // Make ajax request. + // Make Ajax request. $.post( ajaxurl, params, function(r) { var $errorNotice = $( '#edit-' + id + ' .inline-edit-save .notice-error' ), @@ -450,9 +454,10 @@ window.wp = window.wp || {}; /** * Hides and empties the Quick Edit and/or Bulk Edit windows. * - * @memberof inlineEditPost * @since 2.7.0 * + * @memberof inlineEditPost + * * @return {boolean} Always returns false. */ revert : function(){ @@ -494,9 +499,10 @@ window.wp = window.wp || {}; * Gets the id for a the post that you want to quick edit from the row in the quick * edit table. * - * @memberof inlineEditPost * @since 2.7.0 * + * @memberof inlineEditPost + * * @param {Object} o DOM row object to get the id for. * @return {string} The post id extracted from the table row in the object. */ @@ -546,7 +552,7 @@ $( document ).on( 'heartbeat-tick.wp-check-locked-posts', function( e, data ) { } }).ready( function() { - // Set the heartbeat interval to 15 sec. + // Set the heartbeat interval to 15 seconds. if ( typeof wp !== 'undefined' && wp.heartbeat ) { wp.heartbeat.interval( 15 ); } diff --git a/src/js/_enqueues/admin/inline-edit-tax.js b/src/js/_enqueues/admin/inline-edit-tax.js index dcaa8d2bdc..5a3cad885c 100644 --- a/src/js/_enqueues/admin/inline-edit-tax.js +++ b/src/js/_enqueues/admin/inline-edit-tax.js @@ -43,12 +43,12 @@ window.inlineEditTax = { }); /** - * Cancels inline editing when pressing escape inside the inline editor. + * Cancels inline editing when pressing Escape inside the inline editor. * * @param {Object} e The keyup event that has been triggered. */ row.keyup( function( e ) { - // 27 = [escape] + // 27 = [Escape]. if ( e.which === 27 ) { return inlineEditTax.revert(); } @@ -69,10 +69,10 @@ window.inlineEditTax = { }); /** - * Saves the inline edits when pressing enter inside the inline editor. + * Saves the inline edits when pressing Enter inside the inline editor. */ $( 'input, select', row ).keydown( function( e ) { - // 13 = [enter] + // 13 = [Enter]. if ( e.which === 13 ) { return inlineEditTax.save( this ); } @@ -184,7 +184,7 @@ window.inlineEditTax = { fields = $('#edit-'+id).find(':input').serialize(); params = fields + '&' + $.param(params); - // Do the ajax request to save the data to the server. + // Do the Ajax request to save the data to the server. $.post( ajaxurl, params, /** * Handles the response from the server diff --git a/src/js/_enqueues/admin/link.js b/src/js/_enqueues/admin/link.js index 076d07c44f..02698e5eea 100644 --- a/src/js/_enqueues/admin/link.js +++ b/src/js/_enqueues/admin/link.js @@ -9,7 +9,7 @@ jQuery(document).ready( function($) { var newCat, noSyncChecks = false, syncChecks, catAddAfter; $('#link_name').focus(); - // postboxes + // Postboxes. postboxes.add_postbox_toggles('link'); /** @@ -33,7 +33,7 @@ jQuery(document).ready( function($) { if ( getUserSetting('cats') ) $('#category-tabs a[href="#categories-pop"]').click(); - // Ajax Cat + // Ajax Cat. newCat = $('#newcat').one( 'focus', function() { $(this).val( '' ).removeClass( 'form-input-tip' ); } ); /** diff --git a/src/js/_enqueues/admin/media-upload.js b/src/js/_enqueues/admin/media-upload.js index 3f45e2ef80..1a28f36d04 100644 --- a/src/js/_enqueues/admin/media-upload.js +++ b/src/js/_enqueues/admin/media-upload.js @@ -43,16 +43,16 @@ window.send_to_editor = function( html ) { editor = tinymce.get( wpActiveEditor ); } - // If the editor is set and not hidden, insert the HTML into the content of the - // editor. + // If the editor is set and not hidden, + // insert the HTML into the content of the editor. if ( editor && ! editor.isHidden() ) { editor.execCommand( 'mceInsertContent', false, html ); } else if ( hasQuicktags ) { // If quick tags are available, insert the HTML into its content. QTags.insertContent( html ); } else { - // If neither the TinyMCE editor and the quick tags are available, add the HTML - // to the current active editor. + // If neither the TinyMCE editor and the quick tags are available, + // add the HTML to the current active editor. document.getElementById( wpActiveEditor ).value += html; } diff --git a/src/js/_enqueues/admin/plugin-install.js b/src/js/_enqueues/admin/plugin-install.js index b6cd1d74e4..f9c2be395d 100644 --- a/src/js/_enqueues/admin/plugin-install.js +++ b/src/js/_enqueues/admin/plugin-install.js @@ -183,11 +183,12 @@ jQuery( document ).ready( function( $ ) { var tab = $( this ).attr( 'name' ); event.preventDefault(); - // Flip the tab + // Flip the tab. $( '#plugin-information-tabs a.current' ).removeClass( 'current' ); $( this ).addClass( 'current' ); - // Only show the fyi box in the description section, on smaller screen, where it's otherwise always displayed at the top. + // Only show the fyi box in the description section, on smaller screen, + // where it's otherwise always displayed at the top. if ( 'description' !== tab && $( window ).width() < 772 ) { $( '#plugin-information-content' ).find( '.fyi' ).hide(); } else { diff --git a/src/js/_enqueues/admin/post.js b/src/js/_enqueues/admin/post.js index d2e956b4e4..cc7cab1a72 100644 --- a/src/js/_enqueues/admin/post.js +++ b/src/js/_enqueues/admin/post.js @@ -91,9 +91,9 @@ window.wp = window.wp || {}; /** * Load the next batch of comments. * - * @param {int} total Total number of comments to load. - * * @memberof commentsBox + * + * @param {int} total Total number of comments to load. */ load: function(total){ this.st = jQuery('#the-comment-list tr.comment:visible').length; @@ -309,24 +309,24 @@ jQuery(document).ready( function($) { // Post locks: contain focus inside the dialog. If the dialog is shown, focus the first item. $('#post-lock-dialog .notification-dialog').on( 'keydown', function(e) { - // Don't do anything when [tab] is pressed. + // Don't do anything when [Tab] is pressed. if ( e.which != 9 ) return; var target = $(e.target); - // [shift] + [tab] on first tab cycles back to last tab. + // [Shift] + [Tab] on first tab cycles back to last tab. if ( target.hasClass('wp-tab-first') && e.shiftKey ) { $(this).find('.wp-tab-last').focus(); e.preventDefault(); - // [tab] on last tab cycles back to first tab. + // [Tab] on last tab cycles back to first tab. } else if ( target.hasClass('wp-tab-last') && ! e.shiftKey ) { $(this).find('.wp-tab-first').focus(); e.preventDefault(); } }).filter(':visible').find('.wp-tab-first').focus(); - // Set the heartbeat interval to 15 sec. if post lock dialogs are enabled. + // Set the heartbeat interval to 15 seconds if post lock dialogs are enabled. if ( wp.heartbeat && $('#post-lock-dialog').length ) { wp.heartbeat.interval( 15 ); } @@ -385,7 +385,7 @@ jQuery(document).ready( function($) { }); }); - // Submit the form saving a draft or an autosave, and show a preview in a new tab + // Submit the form saving a draft or an autosave, and show a preview in a new tab. $('#post-preview').on( 'click.post-preview', function( event ) { var $this = $(this), $form = $('form#post'), @@ -534,7 +534,7 @@ jQuery(document).ready( function($) { }); }); - // Multiple Taxonomies. + // Multiple taxonomies. if ( $('#tagsdiv-post_tag').length ) { window.tagBox && window.tagBox.init(); } else { @@ -559,7 +559,7 @@ jQuery(document).ready( function($) { settingName = 'cats'; } - // TODO: move to jQuery 1.3+, support for multiple hierarchical taxonomies, see wp-lists.js + // @todo Move to jQuery 1.3+, support for multiple hierarchical taxonomies, see wp-lists.js. $('a', '#' + taxonomy + '-tabs').click( function( e ) { e.preventDefault(); var t = $(this).attr('href'); @@ -581,7 +581,7 @@ jQuery(document).ready( function($) { $( this ).val( '' ).removeClass( 'form-input-tip' ); }); - // On [enter] submit the taxonomy. + // On [Enter] submit the taxonomy. $('#new' + taxonomy).keypress( function(event){ if( 13 === event.keyCode ) { event.preventDefault(); @@ -654,7 +654,7 @@ jQuery(document).ready( function($) { $('#in-' + taxonomy + '-' + id + ', #in-popular-' + taxonomy + '-' + id).prop( 'checked', c ); }); - }); // end cats + }); // End cats. // Custom Fields postbox. if ( $('#postcustom').length ) { @@ -796,7 +796,8 @@ jQuery(document).ready( function($) { // Update "Status:" to currently selected status. $('#post-status-display').text( - wp.sanitize.stripTagsAndEncodeText( $('option:selected', postStatus).text() ) // Remove any potential tags from post status text. + // Remove any potential tags from post status text. + wp.sanitize.stripTagsAndEncodeText( $('option:selected', postStatus).text() ) ); // Show or hide the "Save Draft" button. @@ -838,7 +839,7 @@ jQuery(document).ready( function($) { }); // Set the selected visibility as current. - $postVisibilitySelect.find('.save-post-visibility').click( function( event ) { // crazyhorse - multiple ok cancels + $postVisibilitySelect.find('.save-post-visibility').click( function( event ) { // Crazyhorse - multiple OK cancels. $postVisibilitySelect.slideUp('fast'); $('#visibility .edit-visibility').show().focus(); updateText(); @@ -886,7 +887,7 @@ jQuery(document).ready( function($) { }); // Save the changed timestamp. - $timestampdiv.find('.save-timestamp').click( function( event ) { // crazyhorse - multiple ok cancels + $timestampdiv.find('.save-timestamp').click( function( event ) { // Crazyhorse - multiple OK cancels. if ( updateText() ) { $timestampdiv.slideUp('fast'); $timestampdiv.siblings('a.edit-timestamp').show().focus(); @@ -1023,12 +1024,12 @@ jQuery(document).ready( function($) { $el.html( '' ).children( 'input' ).keydown( function( e ) { var key = e.which; - // On [enter], just save the new slug, don't save the post. + // On [Enter], just save the new slug, don't save the post. if ( 13 === key ) { e.preventDefault(); buttons.children( '.save' ).click(); } - // On [esc] cancel the editing. + // On [Esc] cancel the editing. if ( 27 === key ) { buttons.children( '.cancel' ).click(); } @@ -1173,7 +1174,7 @@ jQuery(document).ready( function($) { } }); - // When changing page template, change the editor body class + // When changing page template, change the editor body class. $( '#page_template' ).on( 'change.set-editor-class', function() { var editor, body, pageTemplate = $( this ).val() || ''; @@ -1191,9 +1192,9 @@ jQuery(document).ready( function($) { } - // Save on pressing [ctrl]/[command] + [s] in the Text editor. + // Save on pressing [Ctrl]/[Command] + [S] in the Text editor. $textarea.on( 'keydown.wp-autosave', function( event ) { - // Key [s] has code 83. + // Key [S] has code 83. if ( event.which === 83 ) { if ( event.shiftKey || event.altKey || ( isMac && ( ! event.metaKey || event.ctrlKey ) ) || ( ! isMac && ! event.ctrlKey ) ) { return; diff --git a/src/js/_enqueues/admin/postbox.js b/src/js/_enqueues/admin/postbox.js index 9789518b65..ff144777f9 100644 --- a/src/js/_enqueues/admin/postbox.js +++ b/src/js/_enqueues/admin/postbox.js @@ -32,7 +32,9 @@ * if the postbox has been closed. * * @since 4.4.0 + * * @memberof postboxes + * * @fires postboxes#postbox-toggled * * @return {void} @@ -90,6 +92,7 @@ * Adds event handlers to all postboxes and screen option on the current page. * * @since 2.7.0 + * * @memberof postboxes * * @param {string} page The page we are currently on. @@ -190,6 +193,7 @@ * Initializes all the postboxes, mainly their sortable behaviour. * * @since 2.7.0 + * * @memberof postboxes * * @param {string} page The page we are currently on. @@ -272,6 +276,7 @@ * hidden postboxes. * * @since 2.7.0 + * * @memberof postboxes * * @param {string} page The page we are currently on. @@ -303,6 +308,7 @@ * Sends a list of all postboxes inside a sortable area to the server. * * @since 2.8.0 + * * @memberof postboxes * * @param {string} page The page we are currently on. @@ -333,9 +339,10 @@ * present. * * @since 3.3.0 - * @memberof postboxes * @access private * + * @memberof postboxes + * * @return {void} */ _mark_area : function() { @@ -365,10 +372,12 @@ * Changes the amount of columns on the post edit page. * * @since 3.3.0 - * @memberof postboxes - * @fires postboxes#postboxes-columnchange * @access private * + * @memberof postboxes + * + * @fires postboxes#postboxes-columnchange + * * @param {number} n The amount of columns to divide the post edit page in. * @return {void} */ @@ -395,9 +404,10 @@ * orientation of the browser. * * @since 3.3.0 - * @memberof postboxes * @access private * + * @memberof postboxes + * * @return {void} */ _pb_change : function() { @@ -425,19 +435,20 @@ /** * @since 2.7.0 - * @memberof postboxes * @access public + * * @property {Function|boolean} pbshow A callback that is called when a postbox * is opened. + * @memberof postboxes */ pbshow : false, /** * @since 2.7.0 - * @memberof postboxes * @access public * @property {Function|boolean} pbhide A callback that is called when a postbox * is closed. + * @memberof postboxes */ pbhide : false }; diff --git a/src/js/_enqueues/admin/privacy-tools.js b/src/js/_enqueues/admin/privacy-tools.js index 802ec88f4b..90b3a49233 100644 --- a/src/js/_enqueues/admin/privacy-tools.js +++ b/src/js/_enqueues/admin/privacy-tools.js @@ -4,7 +4,7 @@ * @output wp-admin/js/privacy-tools.js */ -// Privacy request action handling +// Privacy request action handling. jQuery( document ).ready( function( $ ) { var strings = window.privacyToolsL10n || {}; @@ -111,7 +111,7 @@ jQuery( document ).ready( function( $ ) { if ( ! response.success ) { - // e.g. invalid request ID + // e.g. invalid request ID. onExportFailure( response.data ); return; } @@ -127,12 +127,12 @@ jQuery( document ).ready( function( $ ) { } }).fail( function( jqxhr, textStatus, error ) { - // e.g. Nonce failure + // e.g. Nonce failure. onExportFailure( error ); }); } - // And now, let's begin + // And now, let's begin. setActionState( $action, 'export-personal-data-processing' ); doNextExport( 1, 1 ); }); @@ -224,7 +224,7 @@ jQuery( document ).ready( function( $ ) { }); } - // And now, let's begin + // And now, let's begin. setActionState( $action, 'remove-personal-data-processing' ); doNextErasure( 1, 1 ); diff --git a/src/js/_enqueues/admin/site-health.js b/src/js/_enqueues/admin/site-health.js index 015b06c5ec..b0f24c7121 100644 --- a/src/js/_enqueues/admin/site-health.js +++ b/src/js/_enqueues/admin/site-health.js @@ -259,9 +259,11 @@ jQuery( document ).ready( function( $ ) { RecalculateProgression(); if ( delay > 3000 ) { - // We have announced that we're waiting. - // Announce that we're ready after giving at least 3 seconds for the first announcement - // to be read out, or the two may collide. + /* + * We have announced that we're waiting. + * Announce that we're ready after giving at least 3 seconds + * for the first announcement to be read out, or the two may collide. + */ if ( delay > 6000 ) { delay = 0; } else { diff --git a/src/js/_enqueues/admin/tags-box.js b/src/js/_enqueues/admin/tags-box.js index c4676f263e..40105e2d38 100644 --- a/src/js/_enqueues/admin/tags-box.js +++ b/src/js/_enqueues/admin/tags-box.js @@ -52,6 +52,7 @@ * Cleans up tags by removing redundant characters. * * @since 2.9.0 + * * @memberOf tagBox * * @param {string} tags Comma separated tags that need to be cleaned up. @@ -76,6 +77,7 @@ * Parses tags and makes them editable. * * @since 2.9.0 + * * @memberOf tagBox * * @param {Object} el The tag element to retrieve the ID from. @@ -110,6 +112,7 @@ * Creates clickable links, buttons and fields for adding or editing tags. * * @since 2.9.0 + * * @memberOf tagBox * * @param {Object} el The container HTML element. @@ -134,6 +137,7 @@ * Creates a delete button if tag editing is enabled, before adding it to the tag list. * * @since 2.5.0 + * * @memberOf tagBox * * @param {string} key The index of the current tag. @@ -209,6 +213,7 @@ * Also ensures that the quick links are properly generated. * * @since 2.9.0 + * * @memberOf tagBox * * @param {Object} el The container HTML element. @@ -262,6 +267,7 @@ * tagcloud. Clicking a tag will add it. * * @since 2.9.0 + * * @memberOf tagBox * * @param {string} id The ID to extract the taxonomy from. @@ -350,6 +356,7 @@ * retrieval of tag suggestions. * * @since 2.9.0 + * * @memberOf tagBox * * @return {void} diff --git a/src/js/_enqueues/admin/tags-suggest.js b/src/js/_enqueues/admin/tags-suggest.js index 50075a654b..c5ccf16eaf 100644 --- a/src/js/_enqueues/admin/tags-suggest.js +++ b/src/js/_enqueues/admin/tags-suggest.js @@ -89,8 +89,8 @@ focus: function( event, ui ) { $element.attr( 'aria-activedescendant', 'wp-tags-autocomplete-' + ui.item.id ); - // Don't empty the input field when using the arrow keys to - // highlight items. See api.jqueryui.com/autocomplete/#event-focus + // Don't empty the input field when using the arrow keys + // to highlight items. See api.jqueryui.com/autocomplete/#event-focus event.preventDefault(); }, select: function( event, ui ) { @@ -113,7 +113,7 @@ window.tagBox.flushTags( $( this ).closest( '.tagsdiv' ) ); } - // Do not close Quick Edit / Bulk Edit + // Do not close Quick Edit / Bulk Edit. event.preventDefault(); event.stopPropagation(); } @@ -175,14 +175,16 @@ .attr( 'role', 'listbox' ) .removeAttr( 'tabindex' ) // Remove the `tabindex=0` attribute added by jQuery UI. - // Looks like Safari and VoiceOver need an `aria-selected` attribute. See ticket #33301. - // The `menufocus` and `menublur` events are the same events used to add and remove - // the `ui-state-focus` CSS class on the menu items. See jQuery UI Menu Widget. + /* + * Looks like Safari and VoiceOver need an `aria-selected` attribute. See ticket #33301. + * The `menufocus` and `menublur` events are the same events used to add and remove + * the `ui-state-focus` CSS class on the menu items. See jQuery UI Menu Widget. + */ .on( 'menufocus', function( event, ui ) { ui.item.attr( 'aria-selected', 'true' ); }) .on( 'menublur', function() { - // The `menublur` event returns an object where the item is `null` + // The `menublur` event returns an object where the item is `null`, // so we need to find the active item with other means. $( this ).find( '[aria-selected="true"]' ).removeAttr( 'aria-selected' ); }); diff --git a/src/js/_enqueues/admin/tags.js b/src/js/_enqueues/admin/tags.js index df5b3f7e5d..d87b98174b 100644 --- a/src/js/_enqueues/admin/tags.js +++ b/src/js/_enqueues/admin/tags.js @@ -132,10 +132,14 @@ jQuery(document).ready(function($) { parent = form.find( 'select#parent' ).val(); - if ( parent > 0 && $('#tag-' + parent ).length > 0 ) // If the parent exists on this page, insert it below. Else insert it at the top of the list. - $( '.tags #tag-' + parent ).after( res.responses[0].supplemental.noparents ); // As the parent exists, Insert the version with - - - prefixed - else - $( '.tags' ).prepend( res.responses[0].supplemental.parents ); // As the parent is not visible, Insert the version with Parent - Child - ThisTerm + // If the parent exists on this page, insert it below. Else insert it at the top of the list. + if ( parent > 0 && $('#tag-' + parent ).length > 0 ) { + // As the parent exists, insert the version with - - - prefixed. + $( '.tags #tag-' + parent ).after( res.responses[0].supplemental.noparents ); + } else { + // As the parent is not visible, insert the version with Parent - Child - ThisTerm. + $( '.tags' ).prepend( res.responses[0].supplemental.parents ); + } $('.tags .no-items').remove(); @@ -143,7 +147,7 @@ jQuery(document).ready(function($) { // Parents field exists, Add new term to the list. term = res.responses[1].supplemental; - // Create an indent for the Parent field + // Create an indent for the Parent field. indent = ''; for ( i = 0; i < res.responses[1].position; i++ ) indent += '   '; diff --git a/src/js/_enqueues/admin/user-profile.js b/src/js/_enqueues/admin/user-profile.js index f737dde255..ff4830242c 100644 --- a/src/js/_enqueues/admin/user-profile.js +++ b/src/js/_enqueues/admin/user-profile.js @@ -196,7 +196,7 @@ resetToggle( false ); if ( $pass1Row.closest( 'form' ).is( '#your-profile' ) ) { - // Clear password field to prevent update + // Clear password field to prevent update. $pass1.val( '' ).trigger( 'pwupdate' ); $submitButtons.prop( 'disabled', false ); } @@ -342,7 +342,7 @@ $this.siblings( '.selected' ).removeClass( 'selected' ); $this.addClass( 'selected' ).find( 'input[type="radio"]' ).prop( 'checked', true ); - // Set color scheme + // Set color scheme. if ( user_id === current_user_id ) { // Load the colors stylesheet. // The default color scheme won't have one, so we'll need to create an element. @@ -351,7 +351,7 @@ } $stylesheet.attr( 'href', $this.children( '.css_url' ).val() ); - // repaint icons + // Repaint icons. if ( typeof wp !== 'undefined' && wp.svgPainter ) { try { colors = $.parseJSON( $this.children( '.icon_colors' ).val() ); @@ -363,7 +363,7 @@ } } - // update user option + // Update user option. $.post( ajaxurl, { action: 'save-user-color-scheme', color_scheme: $this.children( 'input[name="admin_color"]' ).val(), diff --git a/src/js/_enqueues/admin/widgets.js b/src/js/_enqueues/admin/widgets.js index 00ae62dbae..3d72db74e2 100644 --- a/src/js/_enqueues/admin/widgets.js +++ b/src/js/_enqueues/admin/widgets.js @@ -222,9 +222,9 @@ window.wpWidgets = { the_id = this.id; if ( chooser.length ) { - // Hide the chooser and move it out of the widget + // Hide the chooser and move it out of the widget. $( '#wpbody-content' ).append( chooser.hide() ); - // Delete the cloned chooser from the drag helper + // Delete the cloned chooser from the drag helper. ui.helper.find('.widgets-chooser').remove(); self.clearWidgetSelection(); } @@ -321,7 +321,7 @@ window.wpWidgets = { wpWidgets.hoveredSidebar = null; if ( $widget.hasClass('deleting') ) { - wpWidgets.save( $widget, 1, 0, 1 ); // delete widget + wpWidgets.save( $widget, 1, 0, 1 ); // Delete widget. $widget.remove(); return; } @@ -363,7 +363,7 @@ window.wpWidgets = { $children = $sidebar.children('.widget'); - // Make sure the dropped widget is at the top + // Make sure the dropped widget is at the top. if ( $children.length > 1 ) { child = $children.get(0); item = $widget.get(0); @@ -386,14 +386,14 @@ window.wpWidgets = { }, deactivate: function() { - // Remove all min-height added on "start" + // Remove all min-height added on "start". $(this).css( 'min-height', '' ).parent().removeClass( 'widget-hover' ); }, receive: function( event, ui ) { var $sender = $( ui.sender ); - // Don't add more widgets to orphaned sidebars + // Don't add more widgets to orphaned sidebars. if ( this.id.indexOf('orphaned_widgets') > -1 ) { $sender.sortable('cancel'); return; @@ -431,7 +431,7 @@ window.wpWidgets = { } }); - // Area Chooser + // Area Chooser. $( '#widgets-right .widgets-holder-wrap' ).each( function( index, element ) { var $element = $( element ), name = $element.find( '.sidebar-name h2' ).text(), @@ -465,7 +465,7 @@ window.wpWidgets = { toggleButton.attr( 'aria-expanded', 'false' ); self.closeChooser(); } else { - // Open the chooser + // Open the chooser. self.clearWidgetSelection(); $( '#widgets-left' ).addClass( 'chooser' ); // Add CSS class and insert the chooser after the widget description. @@ -486,7 +486,7 @@ window.wpWidgets = { } }); - // Add event handlers + // Add event handlers. chooser.on( 'click.widgets-chooser', function( event ) { var $target = $( event.target ); @@ -662,7 +662,7 @@ window.wpWidgets = { add = widget.find( 'input.add_new' ).val(); n = widget.find( 'input.multi_number' ).val(); - // Remove the cloned chooser from the widget + // Remove the cloned chooser from the widget. widget.find('.widgets-chooser').remove(); if ( 'multi' === add ) { @@ -689,7 +689,7 @@ window.wpWidgets = { sidebar.sortable('refresh'); wpWidgets.save( widget, 0, 0, 1 ); - // No longer "new" widget + // No longer "new" widget. widget.find( 'input.add_new' ).val(''); $document.trigger( 'widget-added', [ widget ] ); diff --git a/src/js/_enqueues/lib/accordion.js b/src/js/_enqueues/lib/accordion.js index 0bec1ce514..7eacbec966 100644 --- a/src/js/_enqueues/lib/accordion.js +++ b/src/js/_enqueues/lib/accordion.js @@ -35,11 +35,11 @@ // Expand/Collapse accordion sections on click. $( '.accordion-container' ).on( 'click keydown', '.accordion-section-title', function( e ) { - if ( e.type === 'keydown' && 13 !== e.which ) { // "return" key + if ( e.type === 'keydown' && 13 !== e.which ) { // "Return" key. return; } - e.preventDefault(); // Keep this AFTER the key filter above + e.preventDefault(); // Keep this AFTER the key filter above. accordionSwitch( $( this ) ); }); @@ -80,7 +80,7 @@ section.toggleClass( 'open' ); } - // We have to wait for the animations to finish + // We have to wait for the animations to finish. setTimeout(function(){ container.removeClass( 'opening' ); }, 150); diff --git a/src/js/_enqueues/lib/admin-bar.js b/src/js/_enqueues/lib/admin-bar.js index 3e4292f36a..537df2d98f 100644 --- a/src/js/_enqueues/lib/admin-bar.js +++ b/src/js/_enqueues/lib/admin-bar.js @@ -264,7 +264,7 @@ return; } - // (Old) IE doesn't support preventDefault, and does support returnValue + // (Old) IE doesn't support preventDefault, and does support returnValue. if ( event.preventDefault ) { event.preventDefault(); } @@ -451,7 +451,7 @@ }; } - // Get the closest matching elent + // Get the closest matching elent. for ( ; el && el !== document; el = el.parentNode ) { if ( el.matches( selector ) ) { return el; diff --git a/src/js/_enqueues/lib/ajax-response.js b/src/js/_enqueues/lib/ajax-response.js index fd71ff3702..f2eedf3732 100644 --- a/src/js/_enqueues/lib/ajax-response.js +++ b/src/js/_enqueues/lib/ajax-response.js @@ -17,7 +17,7 @@ window.wpAjax = jQuery.extend( { } return r; }, - parseAjaxResponse: function( x, r, e ) { // 1 = good, 0 = strange (bad data?), -1 = you lack permission + parseAjaxResponse: function( x, r, e ) { // 1 = good, 0 = strange (bad data?), -1 = you lack permission. var parsed = {}, re = jQuery('#' + r).empty(), err = ''; if ( x && typeof x == 'object' && x.getElementsByTagName('wp_ajax') ) { @@ -64,7 +64,7 @@ window.wpAjax = jQuery.extend( { } }, wpAjax || { noPerm: 'Sorry, you are not allowed to do that.', broken: 'Something went wrong.' } ); -// Basic form validation +// Basic form validation. jQuery(document).ready( function($){ $('form.validate').submit( function() { return wpAjax.validateForm( $(this) ); } ); }); diff --git a/src/js/_enqueues/lib/auth-check.js b/src/js/_enqueues/lib/auth-check.js index 158b6e1750..ef6d861de0 100644 --- a/src/js/_enqueues/lib/auth-check.js +++ b/src/js/_enqueues/lib/auth-check.js @@ -51,8 +51,8 @@ else parent.css( 'max-height', height + 40 + 'px' ); } else if ( ! body || ! body.length ) { - // Catch "silent" iframe origin exceptions in WebKit after another page is - // loaded in the iframe. + // Catch "silent" iframe origin exceptions in WebKit + // after another page is loaded in the iframe. wrap.addClass('fallback'); parent.css( 'max-height', '' ); form.remove(); @@ -68,9 +68,11 @@ if ( frame ) { frame.focus(); - // WebKit doesn't throw an error if the iframe fails to load because of - // "X-Frame-Options: DENY" header. - // Wait for 10 sec. and switch to the fallback text. + /* + * WebKit doesn't throw an error if the iframe fails to load + * because of "X-Frame-Options: DENY" header. + * Wait for 10 seconds and switch to the fallback text. + */ setTimeout( function() { if ( ! loaded ) { wrap.addClass('fallback'); @@ -92,8 +94,8 @@ function hide() { $(window).off( 'beforeunload.wp-auth-check' ); - // When on the Edit Post screen, speed up heartbeat after the user logs in to - // quickly refresh nonces. + // When on the Edit Post screen, speed up heartbeat + // after the user logs in to quickly refresh nonces. if ( typeof adminpage !== 'undefined' && ( adminpage === 'post-php' || adminpage === 'post-new-php' ) && typeof wp !== 'undefined' && wp.heartbeat ) { diff --git a/src/js/_enqueues/lib/color-picker.js b/src/js/_enqueues/lib/color-picker.js index 0a99ae00cc..18f2bc26dc 100644 --- a/src/js/_enqueues/lib/color-picker.js +++ b/src/js/_enqueues/lib/color-picker.js @@ -36,7 +36,6 @@ * Creates a color picker that only allows you to adjust the hue. * * @since 3.5.0 - * * @access private * * @return {void} @@ -80,7 +79,6 @@ * Creates the color picker, sets default values, css classes and wraps it all in HTML. * * @since 3.5.0 - * * @access private * * @return {void} @@ -209,7 +207,6 @@ * Binds event listeners to the color picker. * * @since 3.5.0 - * * @access private * * @return {void} diff --git a/src/js/_enqueues/lib/comment-reply.js b/src/js/_enqueues/lib/comment-reply.js index ea973f41e8..1ba9498f11 100644 --- a/src/js/_enqueues/lib/comment-reply.js +++ b/src/js/_enqueues/lib/comment-reply.js @@ -95,7 +95,7 @@ window.addComment = ( function( window ) { cancelElement.addEventListener( 'touchstart', cancelEvent ); cancelElement.addEventListener( 'click', cancelEvent ); - // Submit the comment form when the user types CTRL or CMD + 'Enter'. + // Submit the comment form when the user types [Ctrl] or [Cmd] + [Enter]. var submitFormHandler = function( e ) { if ( ( e.metaKey || e.ctrlKey ) && e.keyCode === 13 ) { commentFormElement.removeEventListener( 'keydown', submitFormHandler ); diff --git a/src/js/_enqueues/lib/cookies.js b/src/js/_enqueues/lib/cookies.js index ac74bdb3a8..66d920affa 100644 --- a/src/js/_enqueues/lib/cookies.js +++ b/src/js/_enqueues/lib/cookies.js @@ -115,7 +115,7 @@ window.wpCookies = { if ( typeof( expires ) === 'object' && expires.toGMTString ) { expires = expires.toGMTString(); } else if ( parseInt( expires, 10 ) ) { - d.setTime( d.getTime() + ( parseInt( expires, 10 ) * 1000 ) ); // time must be in milliseconds + d.setTime( d.getTime() + ( parseInt( expires, 10 ) * 1000 ) ); // Time must be in milliseconds. expires = d.toGMTString(); } else { expires = ''; @@ -153,9 +153,11 @@ window.getUserSetting = function( name, def ) { return ''; }; -// Both name and value must be only ASCII letters, numbers or underscore -// and the shorter, the better (cookies can store maximum 4KB). Not suitable to store text. -// The value is converted and stored as string. +/* + * Both name and value must be only ASCII letters, numbers or underscore + * and the shorter, the better (cookies can store maximum 4KB). Not suitable to store text. + * The value is converted and stored as string. + */ window.setUserSetting = function( name, value, _del ) { if ( 'object' !== typeof userSettings ) { return false; @@ -192,7 +194,7 @@ window.deleteUserSetting = function( name ) { return setUserSetting( name, '', 1 ); }; -// Returns all settings as js object. +// Returns all settings as JS object. window.getAllUserSettings = function() { if ( 'object' !== typeof userSettings ) { return {}; diff --git a/src/js/_enqueues/lib/gallery.js b/src/js/_enqueues/lib/gallery.js index 36cb08636b..dda3e33408 100644 --- a/src/js/_enqueues/lib/gallery.js +++ b/src/js/_enqueues/lib/gallery.js @@ -15,7 +15,7 @@ jQuery(document).ready(function($) { distance: 2, handle: 'div.filename', stop: function() { - // When an update has occurred, adjust the order for each item + // When an update has occurred, adjust the order for each item. var all = $('#media-items').sortable('toArray'), len = all.length; $.each(all, function(i, id) { var order = desc ? (len - i) : (1 + i); @@ -71,7 +71,7 @@ jQuery(document).ready(function($) { $('img.pinkynail').toggle(true); }); - // initialize sortable + // Initialize sortable. gallerySortableInit(); clearAll(); @@ -88,7 +88,7 @@ jQuery(document).ready(function($) { } }); -jQuery(window).unload( function () { window.tinymce = window.tinyMCE = window.wpgallery = null; } ); // Cleanup +jQuery(window).unload( function () { window.tinymce = window.tinyMCE = window.wpgallery = null; } ); // Cleanup. /* gallery settings */ window.tinymce = null; @@ -122,7 +122,7 @@ window.wpgallery = { document.domain = q.mce_rdomain; } - // Find window & API + // Find window & API. window.tinymce = w.tinymce; window.tinyMCE = w.tinyMCE; t.editor = tinymce.EditorManager.activeEditor; diff --git a/src/js/_enqueues/lib/image-edit.js b/src/js/_enqueues/lib/image-edit.js index 756d2e4da1..d2b0139bc1 100644 --- a/src/js/_enqueues/lib/image-edit.js +++ b/src/js/_enqueues/lib/image-edit.js @@ -48,8 +48,9 @@ /** * Converts a value to an integer. * + * @since 2.9.0 + * * @memberof imageEdit - * @since 2.9.0 * * @param {number} f The float value that should be converted. * @@ -66,8 +67,9 @@ /** * Adds the disabled attribute and class to a single form element or a field set. * + * @since 2.9.0 + * * @memberof imageEdit - * @since 2.9.0 * * @param {jQuery} el The element that should be modified. * @param {bool|number} s The state for the element. If set to true @@ -95,8 +97,9 @@ /** * Initializes the image editor. * + * @since 2.9.0 + * * @memberof imageEdit - * @since 2.9.0 * * @param {number} postid The post id. * @@ -121,12 +124,12 @@ $('input[type="text"]', '#imgedit-panel-' + postid).keypress(function(e) { var k = e.keyCode; - // Key codes 37 thru 40 are the arrow keys. + // Key codes 37 through 40 are the arrow keys. if ( 36 < k && k < 41 ) { $(this).blur(); } - // The key code 13 is the enter key. + // The key code 13 is the Enter key. if ( 13 === k ) { e.preventDefault(); e.stopPropagation(); @@ -138,8 +141,9 @@ /** * Toggles the wait/load icon in the editor. * + * @since 2.9.0 + * * @memberof imageEdit - * @since 2.9.0 * * @param {number} postid The post id. * @param {number} toggle Is 0 or 1, fades the icon in then 1 and out when 0. @@ -159,8 +163,9 @@ /** * Shows or hides the image edit help box. * + * @since 2.9.0 + * * @memberof imageEdit - * @since 2.9.0 * * @param {HTMLElement} el The element to create the help window in. * @@ -181,8 +186,9 @@ * The image edit target contains the image sizes where the (possible) changes * have to be applied to. * + * @since 2.9.0 + * * @memberof imageEdit - * @since 2.9.0 * * @param {number} postid The post id. * @@ -198,8 +204,9 @@ * * If the original image size is exceeded a red exclamation mark is shown. * + * @since 2.9.0 + * * @memberof imageEdit - * @since 2.9.0 * * @param {number} postid The current post id. * @param {number} x Is 0 when it applies the y-axis @@ -234,8 +241,9 @@ /** * Gets the selected aspect ratio. * + * @since 2.9.0 + * * @memberof imageEdit - * @since 2.9.0 * * @param {number} postid The post id. * @@ -261,8 +269,9 @@ * Removes the last action from the image edit history. * The history consist of (edit) actions performed on the image. * + * @since 2.9.0 + * * @memberof imageEdit - * @since 2.9.0 * * @param {number} postid The post id. * @param {number} setSize 0 or 1, when 1 the image resets to its original size. @@ -295,13 +304,13 @@ // Restore original 'o'. o = history[history.length - 1]; - // c = 'crop', r = 'rotate', f = 'flip' + // c = 'crop', r = 'rotate', f = 'flip'. o = o.c || o.r || o.f || false; if ( o ) { - // fw = Full image width + // fw = Full image width. this.hold.w = o.fw; - // fh = Full image height + // fh = Full image height. this.hold.h = o.fh; } } @@ -326,8 +335,9 @@ * * When the image source is reloaded the image will be reloaded. * + * @since 2.9.0 + * * @memberof imageEdit - * @since 2.9.0 * * @param {number} postid The post id. * @param {string} nonce The nonce to verify the request. @@ -371,7 +381,7 @@ parent.empty().append(img); - // w, h are the new full size dims + // w, h are the new full size dimensions. max1 = Math.max( t.hold.w, t.hold.h ); max2 = Math.max( $(img).width(), $(img).height() ); t.hold.sizer = max1 > max2 ? max2 / max1 : 1; @@ -399,8 +409,9 @@ /** * Performs an image edit action. * + * @since 2.9.0 + * * @memberof imageEdit - * @since 2.9.0 * * @param {number} postid The post id. * @param {string} nonce The nonce to verify the request. @@ -456,7 +467,7 @@ $.post(ajaxurl, data, function(r) { $('#image-editor-' + postid).empty().append(r); t.toggleEditor(postid, 0); - // refresh the attachment model so that changes propagate + // Refresh the attachment model so that changes propagate. if ( t._view ) { t._view.refresh(); } @@ -466,8 +477,9 @@ /** * Stores the changes that are made to the image. * + * @since 2.9.0 + * * @memberof imageEdit - * @since 2.9.0 * * @param {number} postid The post id to get the image from the database. * @param {string} nonce The nonce to verify the request. @@ -531,8 +543,9 @@ /** * Creates the image edit window. * + * @since 2.9.0 + * * @memberof imageEdit - * @since 2.9.0 * * @param {number} postid The post id for the image. * @param {string} nonce The nonce to verify the request. @@ -588,8 +601,9 @@ /** * Initializes the cropping tool and sets a default cropping selection. * + * @since 2.9.0 + * * @memberof imageEdit - * @since 2.9.0 * * @param {number} postid The post id. * @@ -614,8 +628,9 @@ /** * Initializes the cropping tool. * + * @since 2.9.0 + * * @memberof imageEdit - * @since 2.9.0 * * @param {number} postid The post id. * @param {HTMLElement} image The preview image. @@ -645,8 +660,8 @@ * @param {jQuery} img The preview image. */ onInit: function( img ) { - // Ensure that the imgAreaSelect wrapper elements are position:absolute. - // (even if we're in a position:fixed modal) + // Ensure that the imgAreaSelect wrapper elements are position:absolute + // (even if we're in a position:fixed modal). $img = $( img ); $img.next().css( 'position', 'absolute' ) .nextAll( '.imgareaselect-outer' ).css( 'position', 'absolute' ); @@ -715,8 +730,9 @@ /** * Stores the current crop selection. * + * @since 2.9.0 + * * @memberof imageEdit - * @since 2.9.0 * * @param {number} postid The post id. * @param {object} c The selection. @@ -746,8 +762,9 @@ /** * Closes the image editor. * + * @since 2.9.0 + * * @memberof imageEdit - * @since 2.9.0 * * @param {number} postid The post id. * @param {bool} warn Warning message. @@ -764,13 +781,14 @@ this.iasapi = {}; this.hold = {}; - // If we've loaded the editor in the context of a Media Modal, then switch to the previous view, - // whatever that might have been. + // If we've loaded the editor in the context of a Media Modal, + // then switch to the previous view, whatever that might have been. if ( this._view ){ this._view.back(); } - // In case we are not accessing the image editor in the context of a View, close the editor the old-skool way + // In case we are not accessing the image editor in the context of a View, + // close the editor the old-school way. else { $('#image-editor-' + postid).fadeOut('fast', function() { $( '#media-head-' + postid ).fadeIn( 'fast', function() { @@ -787,8 +805,9 @@ /** * Checks if the image edit history is saved. * + * @since 2.9.0 + * * @memberof imageEdit - * @since 2.9.0 * * @param {number} postid The post id. * @@ -811,8 +830,9 @@ /** * Adds an image edit action to the history. * + * @since 2.9.0 + * * @memberof imageEdit - * @since 2.9.0 * * @param {object} op The original position. * @param {number} postid The post id. @@ -830,7 +850,7 @@ history.pop(); pop--; } - undone.val(0); // reset + undone.val(0); // Reset. history.push(op); elem.val( JSON.stringify(history) ); @@ -844,8 +864,9 @@ /** * Rotates the image. * + * @since 2.9.0 + * * @memberof imageEdit - * @since 2.9.0 * * @param {string} angle The angle the image is rotated with. * @param {number} postid The post id. @@ -865,8 +886,9 @@ /** * Flips the image. * + * @since 2.9.0 + * * @memberof imageEdit - * @since 2.9.0 * * @param {number} axis The axle the image is flipped on. * @param {number} postid The post id. @@ -886,8 +908,9 @@ /** * Crops the image. * + * @since 2.9.0 + * * @memberof imageEdit - * @since 2.9.0 * * @param {number} postid The post id. * @param {string} nonce The nonce. @@ -915,8 +938,9 @@ /** * Undoes an image edit action. * + * @since 2.9.0 + * * @memberof imageEdit - * @since 2.9.0 * * @param {number} postid The post id. * @param {string} nonce The nonce. @@ -948,8 +972,9 @@ /** * Reverts a undo action. * + * @since 2.9.0 + * * @memberof imageEdit - * @since 2.9.0 * * @param {number} postid The post id. * @param {string} nonce The nonce. @@ -978,8 +1003,9 @@ /** * Sets the selection for the height and width in pixels. * + * @since 2.9.0 + * * @memberof imageEdit - * @since 2.9.0 * * @param {number} postid The post id. * @param {jQuery} el The element containing the values. @@ -1035,8 +1061,9 @@ /** * Rounds a number to a whole. * + * @since 2.9.0 + * * @memberof imageEdit - * @since 2.9.0 * * @param {number} num The number. * @@ -1064,8 +1091,9 @@ /** * Sets a locked aspect ratio for the selection. * + * @since 2.9.0 + * * @memberof imageEdit - * @since 2.9.0 * * @param {number} postid The post id. * @param {number} n The ratio to set. @@ -1108,8 +1136,9 @@ /** * Validates if a value in a jQuery.HTMLElement is numeric. * + * @since 4.6.0 + * * @memberof imageEdit - * @since 4.6 * * @param {jQuery} el The html element. * diff --git a/src/js/_enqueues/lib/link.js b/src/js/_enqueues/lib/link.js index 954d211131..1dfc1204e1 100644 --- a/src/js/_enqueues/lib/link.js +++ b/src/js/_enqueues/lib/link.js @@ -36,24 +36,24 @@ inputs.submit = $( '#wp-link-submit' ); inputs.close = $( '#wp-link-close' ); - // Input + // Input. inputs.text = $( '#wp-link-text' ); inputs.url = $( '#wp-link-url' ); inputs.nonce = $( '#_ajax_linking_nonce' ); inputs.openInNewTab = $( '#wp-link-target' ); inputs.search = $( '#wp-link-search' ); - // Build Rivers + // Build rivers. rivers.search = new River( $( '#search-results' ) ); rivers.recent = new River( $( '#most-recent-results' ) ); rivers.elements = inputs.dialog.find( '.query-results' ); - // Get search notice text + // Get search notice text. inputs.queryNotice = $( '#query-notice-message' ); inputs.queryNoticeTextDefault = inputs.queryNotice.find( '.query-notice-default' ); inputs.queryNoticeTextHint = inputs.queryNotice.find( '.query-notice-hint' ); - // Bind event handlers + // Bind event handlers. inputs.dialog.keydown( wpLink.keydown ); inputs.dialog.keyup( wpLink.keyup ); inputs.submit.click( function( event ) { @@ -68,7 +68,7 @@ rivers.elements.on( 'river-select', wpLink.updateFields ); - // Display 'hint' message when search field or 'query-results' box are focused + // Display 'hint' message when search field or 'query-results' box are focused. inputs.search.on( 'focus.wplink', function() { inputs.queryNoticeTextDefault.hide(); inputs.queryNoticeTextHint.removeClass( 'screen-reader-text' ).show(); @@ -91,7 +91,7 @@ inputs.url.on( 'blur', wpLink.correctURL ); }, - // If URL wasn't corrected last time and doesn't start with http:, https:, ? # or /, prepend http:// + // If URL wasn't corrected last time and doesn't start with http:, https:, ? # or /, prepend http://. correctURL: function () { var url = $.trim( inputs.url.val() ); @@ -154,24 +154,24 @@ refresh: function( url, text ) { var linkText = ''; - // Refresh rivers (clear links, check visibility) + // Refresh rivers (clear links, check visibility). rivers.search.refresh(); rivers.recent.refresh(); if ( wpLink.isMCE() ) { wpLink.mceRefresh( url, text ); } else { - // For the Text editor the "Link text" field is always shown + // For the Text editor the "Link text" field is always shown. if ( ! inputs.wrap.hasClass( 'has-text-field' ) ) { inputs.wrap.addClass( 'has-text-field' ); } if ( document.selection ) { - // Old IE + // Old IE. linkText = document.selection.createRange().text || text || ''; } else if ( typeof this.textarea.selectionStart !== 'undefined' && ( this.textarea.selectionStart !== this.textarea.selectionEnd ) ) { - // W3C + // W3C. text = this.textarea.value.substring( this.textarea.selectionStart, this.textarea.selectionEnd ) || text || ''; } @@ -180,12 +180,14 @@ } if ( isTouch ) { - // Close the onscreen keyboard + // Close the onscreen keyboard. inputs.url.focus().blur(); } else { - // Focus the URL field and highlight its contents. - // If this is moved above the selection changes, - // IE will show a flashing cursor over the dialog. + /* + * Focus the URL field and highlight its contents. + * If this is moved above the selection changes, + * IE will show a flashing cursor over the dialog. + */ window.setTimeout( function() { inputs.url[0].select(); inputs.url.focus(); @@ -203,7 +205,7 @@ hasSelectedText: function( linkNode ) { var node, nodes, i, html = editor.selection.getContent(); - // Partial html and not a fully selected anchor element + // Partial html and not a fully selected anchor element. if ( /]+>[^<]+<\/a>$/.test( html ) || html.indexOf('href=') === -1 ) ) { return false; } @@ -259,7 +261,7 @@ inputs.search.val( '' ); } - // Always reset the search + // Always reset the search. window.setTimeout( function() { wpLink.searchInternalLinks(); } ); @@ -358,11 +360,11 @@ html = wpLink.buildHtml(attrs); - // Insert HTML + // Insert HTML. if ( document.selection && wpLink.range ) { - // IE + // IE. // Note: If no text is selected, IE will not place the cursor - // inside the closing tag. + // inside the closing tag. textarea.focus(); wpLink.range.text = html + ( text || wpLink.range.text ) + ''; wpLink.range.moveToBookmark( wpLink.range.getBookmark() ); @@ -370,7 +372,7 @@ wpLink.range = null; } else if ( typeof textarea.selectionStart !== 'undefined' ) { - // W3C + // W3C. begin = textarea.selectionStart; end = textarea.selectionEnd; selection = text || textarea.value.substring( begin, end ); @@ -388,7 +390,7 @@ textarea.value.substring( end, textarea.value.length ) ); - // Update cursor position + // Update cursor position. textarea.selectionStart = textarea.selectionEnd = cursor; } @@ -484,10 +486,10 @@ selection = $.trim( selection ); if ( selection && emailRegexp.test( selection ) ) { - // Selection is email address + // Selection is email address. return 'mailto:' + selection; } else if ( selection && urlRegexp.test( selection ) ) { - // Selection is URL + // Selection is URL. return selection.replace( /&|�?38;/gi, '&' ); } @@ -553,7 +555,7 @@ id = event.target.id; // wp-link-submit must always be the last focusable element in the dialog. - // following focusable elements will be skipped on keyboard navigation. + // Following focusable elements will be skipped on keyboard navigation. if ( id === 'wp-link-submit' && ! event.shiftKey ) { inputs.close.focus(); event.preventDefault(); @@ -656,18 +658,18 @@ this.deselect(); this.selected = li.addClass( 'selected' ); - // Make sure the element is visible + // Make sure the element is visible. liHeight = li.outerHeight(); elHeight = this.element.height(); liTop = li.position().top; elTop = this.element.scrollTop(); - if ( liTop < 0 ) // Make first visible element + if ( liTop < 0 ) // Make first visible element. this.element.scrollTop( elTop + liTop ); - else if ( liTop + liHeight > elHeight ) // Make last visible element + else if ( liTop + liHeight > elHeight ) // Make last visible element. this.element.scrollTop( elTop + liTop - elHeight + liHeight ); - // Trigger the river-select event + // Trigger the river-select event. this.element.trigger( 'river-select', [ li, event, this ] ); }, deselect: function() { diff --git a/src/js/_enqueues/lib/nav-menu.js b/src/js/_enqueues/lib/nav-menu.js index 95b66c1a42..3a0bd642ef 100644 --- a/src/js/_enqueues/lib/nav-menu.js +++ b/src/js/_enqueues/lib/nav-menu.js @@ -69,7 +69,7 @@ }, jQueryExtensions : function() { - // jQuery extensions + // jQuery extensions. $.fn.extend({ menuItemDepth : function() { var margin = api.isRTL ? this.eq(0).css('margin-right') : this.eq(0).css('margin-left'); @@ -114,7 +114,7 @@ depth = t.menuItemDepth(), newDepth = depth + dir; - // Change .menu-item-depth-n class + // Change .menu-item-depth-n class. t.moveHorizontally( newDepth, depth ); }); }, @@ -125,10 +125,10 @@ diff = newDepth - depth, subItemText = t.find('.is-submenu'); - // Change .menu-item-depth-n class + // Change .menu-item-depth-n class. t.updateDepthClass( newDepth, depth ).updateParentMenuItemDBId(); - // If it has children, move those too + // If it has children, move those too. if ( children ) { children.each(function() { var t = $(this), @@ -138,7 +138,7 @@ }); } - // Show "Sub item" helper text + // Show "Sub item" helper text. if (0 === newDepth) subItemText.hide(); else @@ -153,7 +153,7 @@ parentDepth = depth - 1, parent = item.prevAll( '.menu-item-depth-' + parentDepth ).first(); - if ( 0 === depth ) { // Item is on the top level, has no parent + if ( 0 === depth ) { // Item is on the top level, has no parent. input.val(0); } else { // Find the parent item, and retrieve its object id. input.val( parent.find( '.menu-item-data-db-id' ).val() ); @@ -191,10 +191,10 @@ if ( !checkboxes.length ) return false; - // Show the ajax spinner + // Show the Ajax spinner. t.find( '.button-controls .spinner' ).addClass( 'is-active' ); - // Retrieve menu item data + // Retrieve menu item data. $(checkboxes).each(function(){ var t = $(this), listItemDBIDMatch = re.exec( t.attr('name') ), @@ -205,9 +205,9 @@ menuItems[listItemDBID] = t.closest('li').getItemData( 'add-menu-item', listItemDBID ); }); - // Add the items + // Add the items. api.addItemToMenu(menuItems, processMethod, function(){ - // Deselect the items and hide the ajax spinner + // Deselect the items and hide the Ajax spinner. checkboxes.prop( 'checked', false ); t.find( '.button-controls .select-all' ).prop( 'checked', false ); t.find( '.button-controls .spinner' ).removeClass( 'is-active' ); @@ -312,22 +312,22 @@ case 'up': newItemPosition = thisItemPosition - 1; - // Already at top + // Already at top. if ( 0 === thisItemPosition ) break; - // If a sub item is moved to top, shift it to 0 depth + // If a sub item is moved to top, shift it to 0 depth. if ( 0 === newItemPosition && 0 !== thisItemDepth ) thisItem.moveHorizontally( 0, thisItemDepth ); - // If prev item is sub item, shift to match depth + // If prev item is sub item, shift to match depth. if ( 0 !== prevItemDepth ) thisItem.moveHorizontally( prevItemDepth, thisItemDepth ); // Does this item have sub items? if ( thisItemChildren ) { items = thisItem.add( thisItemChildren ); - // Move the entire block + // Move the entire block. items.detach().insertBefore( menuItems.eq( newItemPosition ) ).updateParentMenuItemDBId(); } else { thisItem.detach().insertBefore( menuItems.eq( newItemPosition ) ).updateParentMenuItemDBId(); @@ -351,40 +351,40 @@ items.detach().insertAfter( menuItems.eq( thisItemPosition + items.length ) ).updateParentMenuItemDBId(); } else { - // If next item has sub items, shift depth + // If next item has sub items, shift depth. if ( 0 !== nextItemChildren.length ) thisItem.moveHorizontally( nextItemDepth, thisItemDepth ); - // Have we reached the bottom + // Have we reached the bottom? if ( menuItemsCount === thisItemPosition + 1 ) break; thisItem.detach().insertAfter( menuItems.eq( thisItemPosition + 1 ) ).updateParentMenuItemDBId(); } break; case 'top': - // Already at top + // Already at top. if ( 0 === thisItemPosition ) break; // Does this item have sub items? if ( thisItemChildren ) { items = thisItem.add( thisItemChildren ); - // Move the entire block + // Move the entire block. items.detach().insertBefore( menuItems.eq( 0 ) ).updateParentMenuItemDBId(); } else { thisItem.detach().insertBefore( menuItems.eq( 0 ) ).updateParentMenuItemDBId(); } break; case 'left': - // As far left as possible + // As far left as possible. if ( 0 === thisItemDepth ) break; thisItem.shiftHorizontally( -1 ); break; case 'right': - // Can't be sub item at top + // Can't be sub item at top. if ( 0 === thisItemPosition ) break; - // Already sub item of prevItem + // Already sub item of prevItem. if ( thisItemData['menu-item-parent-id'] === prevItemId ) break; thisItem.shiftHorizontally( 1 ); @@ -402,7 +402,7 @@ api.refreshKeyboardAccessibility(); api.refreshAdvancedAccessibility(); - // Refresh the accessibility when the user comes close to the item in any way + // Refresh the accessibility when the user comes close to the item in any way. menu.on( 'mouseenter.refreshAccessibility focus.refreshAccessibility touchstart.refreshAccessibility' , '.menu-item' , function(){ api.refreshAdvancedAccessibilityOfItem( $( this ).find( 'a.item-edit' ) ); } ); @@ -412,7 +412,7 @@ api.refreshAdvancedAccessibilityOfItem( $( this ) ); } ); - // Links for moving items + // Links for moving items. menu.on( 'click', '.menus-move', function () { var $this = $( this ), dir = $this.data( 'dir' ); @@ -433,7 +433,7 @@ */ refreshAdvancedAccessibilityOfItem : function( itemToRefresh ) { - // Only refresh accessibility when necessary + // Only refresh accessibility when necessary. if ( true !== $( itemToRefresh ).data( 'needs_accessibility_refresh' ) ) { return; } @@ -494,7 +494,7 @@ itemPosition = primaryItems.index( menuItem ) + 1, totalMenuItems = primaryItems.length, - // String together help text for primary menu items + // String together help text for primary menu items. title = menus.menuFocus.replace( '%1$s', itemName ).replace( '%2$d', itemPosition ).replace( '%3$d', totalMenuItems ); } else { parentItem = menuItem.prevAll( '.menu-item-depth-' + parseInt( depth - 1, 10 ) ).first(), @@ -503,13 +503,13 @@ subItems = $( '.menu-item .menu-item-data-parent-id[value="' + parentItemId + '"]' ), itemPosition = $( subItems.parents('.menu-item').get().reverse() ).index( menuItem ) + 1; - // String together help text for sub menu items + // String together help text for sub menu items. title = menus.subMenuFocus.replace( '%1$s', itemName ).replace( '%2$d', itemPosition ).replace( '%3$s', parentItemName ); } $this.attr( 'aria-label', title ); - // Mark this item's accessibility as refreshed + // Mark this item's accessibility as refreshed. $this.data( 'needs_accessibility_refresh', false ); }, @@ -523,10 +523,10 @@ // Hide all the move buttons by default. $( '.menu-item-settings .field-move .menus-move' ).hide(); - // Mark all menu items as unprocessed + // Mark all menu items as unprocessed. $( 'a.item-edit' ).data( 'needs_accessibility_refresh', true ); - // All open items have to be refreshed or they will show no links + // All open items have to be refreshed or they will show no links. $( '.menu-item-edit-active a.item-edit' ).each( function() { api.refreshAdvancedAccessibilityOfItem( this ); } ); @@ -541,18 +541,18 @@ thisItem = $this.parents( 'li.menu-item' ), thisItemData = thisItem.getItemData(); - // Bail if it's not an arrow key + // Bail if it's not an arrow key. if ( 37 != e.which && 38 != e.which && 39 != e.which && 40 != e.which ) return; - // Avoid multiple keydown events + // Avoid multiple keydown events. $this.off('keydown'); - // Bail if there is only one menu item + // Bail if there is only one menu item. if ( 1 === $('#menu-to-edit li').length ) return; - // If RTL, swap left/right arrows + // If RTL, swap left/right arrows. arrows = { '38': 'up', '40': 'down', '37': 'left', '39': 'right' }; if ( $('body').hasClass('rtl') ) arrows = { '38' : 'up', '40' : 'down', '39' : 'left', '37' : 'right' }; @@ -571,7 +571,7 @@ api.moveMenuItem( $this, 'right' ); break; } - // Put focus back on same menu item + // Put focus back on same menu item. $( '#edit-' + thisItemData['menu-item-db-id'] ).focus(); return false; }); @@ -594,10 +594,10 @@ }, initToggles : function() { - // init postboxes + // Init postboxes. postboxes.add_postbox_toggles('nav-menus'); - // adjust columns functions for menus UI + // Adjust columns functions for menus UI. columns.useCheckboxesForHidden(); columns.checked = function(field) { $('.field-' + field).removeClass('hidden-field'); @@ -605,7 +605,7 @@ columns.unchecked = function(field) { $('.field-' + field).addClass('hidden-field'); }; - // hide fields + // Hide fields. api.menuList.hideAdvancedMenuItemFields(); $('.hide-postbox-tog').click(function () { @@ -639,7 +639,7 @@ start: function(e, ui) { var height, width, parent, children, tempHolder; - // handle placement for rtl orientation + // Handle placement for RTL orientation. if ( api.isRTL ) ui.item[0].style.right = 'auto'; @@ -649,19 +649,19 @@ originalDepth = ui.item.menuItemDepth(); updateCurrentDepth(ui, originalDepth); - // Attach child elements to parent - // Skip the placeholder + // Attach child elements to parent. + // Skip the placeholder. parent = ( ui.item.next()[0] == ui.placeholder[0] ) ? ui.item.next() : ui.item; children = parent.childMenuItems(); transport.append( children ); // Update the height of the placeholder to match the moving item. height = transport.outerHeight(); - // If there are children, account for distance between top of children and parent + // If there are children, account for distance between top of children and parent. height += ( height > 0 ) ? (ui.placeholder.css('margin-top').slice(0, -2) * 1) : 0; height += ui.helper.outerHeight(); helperHeight = height; - height -= 2; // Subtract 2 for borders + height -= 2; // Subtract 2 for borders. ui.placeholder.height(height); // Update the width of the placeholder to match the moving item. @@ -670,18 +670,18 @@ var depth = $(this).menuItemDepth(); maxChildDepth = (depth > maxChildDepth) ? depth : maxChildDepth; }); - width = ui.helper.find('.menu-item-handle').outerWidth(); // Get original width - width += api.depthToPx(maxChildDepth - originalDepth); // Account for children - width -= 2; // Subtract 2 for borders + width = ui.helper.find('.menu-item-handle').outerWidth(); // Get original width. + width += api.depthToPx(maxChildDepth - originalDepth); // Account for children. + width -= 2; // Subtract 2 for borders. ui.placeholder.width(width); // Update the list of menu items. tempHolder = ui.placeholder.next( '.menu-item' ); - tempHolder.css( 'margin-top', helperHeight + 'px' ); // Set the margin to absorb the placeholder - ui.placeholder.detach(); // detach or jQuery UI will think the placeholder is a menu item - $(this).sortable( 'refresh' ); // The children aren't sortable. We should let jQ UI know. - ui.item.after( ui.placeholder ); // reattach the placeholder. - tempHolder.css('margin-top', 0); // reset the margin + tempHolder.css( 'margin-top', helperHeight + 'px' ); // Set the margin to absorb the placeholder. + ui.placeholder.detach(); // Detach or jQuery UI will think the placeholder is a menu item. + $(this).sortable( 'refresh' ); // The children aren't sortable. We should let jQuery UI know. + ui.item.after( ui.placeholder ); // Reattach the placeholder. + tempHolder.css('margin-top', 0); // Reset the margin. // Now that the element is complete, we can update... updateSharedVars(ui); @@ -690,31 +690,31 @@ var children, subMenuTitle, depthChange = currentDepth - originalDepth; - // Return child elements to the list + // Return child elements to the list. children = transport.children().insertAfter(ui.item); - // Add "sub menu" description + // Add "sub menu" description. subMenuTitle = ui.item.find( '.item-title .is-submenu' ); if ( 0 < currentDepth ) subMenuTitle.show(); else subMenuTitle.hide(); - // Update depth classes + // Update depth classes. if ( 0 !== depthChange ) { ui.item.updateDepthClass( currentDepth ); children.shiftDepthClass( depthChange ); updateMenuMaxDepth( depthChange ); } - // Register a change + // Register a change. api.registerChange(); // Update the item data. ui.item.updateParentMenuItemDBId(); - // address sortable's incorrectly-calculated top in opera + // Address sortable's incorrectly-calculated top in Opera. ui.item[0].style.top = 0; - // handle drop placement for rtl orientation + // Handle drop placement for rtl orientation. if ( api.isRTL ) { ui.item[0].style.left = 'auto'; ui.item[0].style.right = 0; @@ -736,9 +736,11 @@ edge = api.isRTL ? offset.left + ui.helper.width() : offset.left, depth = api.negateIfRTL * api.pxToDepth( edge - menuEdge ); - // Check and correct if depth is not within range. - // Also, if the dragged element is dragged upwards over - // an item, shift the placeholder to a child position. + /* + * Check and correct if depth is not within range. + * Also, if the dragged element is dragged upwards over an item, + * shift the placeholder to a child position. + */ if ( depth > maxDepth || offset.top < ( prevBottom - api.options.targetTolerance ) ) { depth = maxDepth; } else if ( depth < minDepth ) { @@ -748,7 +750,7 @@ if( depth != currentDepth ) updateCurrentDepth(ui, depth); - // If we overlap the next element, manually shift downwards + // If we overlap the next element, manually shift downwards. if( nextThreshold && offset.top + helperHeight > nextThreshold ) { next.after( ui.placeholder ); updateSharedVars( ui ); @@ -955,12 +957,12 @@ return false; } - // Show the ajax spinner + // Show the Ajax spinner. $( '.customlinkdiv .spinner' ).addClass( 'is-active' ); this.addLinkToMenu( url, label, processMethod, function() { - // Remove the ajax spinner + // Remove the Ajax spinner. $( '.customlinkdiv .spinner' ).removeClass( 'is-active' ); - // Set custom link form back to defaults + // Set custom link form back to defaults. $('#custom-menu-item-name').val('').blur(); $( '#custom-menu-item-url' ).val( '' ).attr( 'placeholder', 'https://' ); }); @@ -997,10 +999,10 @@ $.post( ajaxurl, params, function(menuMarkup) { var ins = $('#menu-instructions'); - menuMarkup = $.trim( menuMarkup ); // Trim leading whitespaces + menuMarkup = $.trim( menuMarkup ); // Trim leading whitespaces. processMethod(menuMarkup, params); - // Make it stand out a bit more visually, by adding a fadeIn + // Make it stand out a bit more visually, by adding a fadeIn. $( 'li.pending' ).hide().fadeIn('slow'); $( '.drag-instructions' ).show(); if( ! ins.hasClass( 'menu-instructions-inactive' ) && ins.siblings().length ) @@ -1051,7 +1053,7 @@ return navMenuL10n.saveAlert; }; } else { - // Make the post boxes read-only, as they can't be used yet + // Make the post boxes read-only, as they can't be used yet. $( '#menu-settings-column' ).find( 'input,select' ).end().find( 'a' ).attr( 'href', '#' ).unbind( 'click' ); } }, @@ -1071,7 +1073,7 @@ wrapper = target.parents('.accordion-section-content').first(); - // upon changing tabs, we want to uncheck all checkboxes + // Upon changing tabs, we want to uncheck all checkboxes. $( 'input', wrapper ).prop( 'checked', false ); $('.tabs-panel-active', wrapper).removeClass('tabs-panel-active').addClass('tabs-panel-inactive'); @@ -1080,7 +1082,7 @@ $('.tabs', wrapper).removeClass('tabs'); target.parent().addClass('tabs'); - // select the search bar + // Select the search bar. $('.quick-search', wrapper).focus(); // Hide controls in the search tab if no items found. @@ -1193,17 +1195,17 @@ var locs = '', menuName = $('#menu-name'), menuNameVal = menuName.val(); - // Cancel and warn if invalid menu name + // Cancel and warn if invalid menu name. if ( ! menuNameVal || ! menuNameVal.replace( /\s+/, '' ) ) { menuName.parent().addClass( 'form-invalid' ); return false; } - // Copy menu theme locations + // Copy menu theme locations. $('#nav-menu-theme-locations select').each(function() { locs += ''; }); $('#update-nav-menu').append( locs ); - // Update menu item position data + // Update menu item position data. api.menuList.find('.menu-item-data-position').val( function(index) { return index + 1; } ); window.onbeforeunload = null; @@ -1211,7 +1213,7 @@ }, eventOnClickMenuDelete : function() { - // Delete warning AYS + // Delete warning AYS. if ( window.confirm( navMenuL10n.warnDeleteMenu ) ) { window.onbeforeunload = null; return true; @@ -1253,7 +1255,7 @@ $items.each(function(){ $item = $(this); - // make a unique DB ID number + // Make a unique DB ID number. matched = pattern.exec($item.html()); if ( matched && matched[1] ) { diff --git a/src/js/_enqueues/lib/pointer.js b/src/js/_enqueues/lib/pointer.js index f841f82308..52524922c1 100644 --- a/src/js/_enqueues/lib/pointer.js +++ b/src/js/_enqueues/lib/pointer.js @@ -90,11 +90,11 @@ var o = this.options, tip = this.pointer; - // Handle document transfer + // Handle document transfer. if ( key === 'document' && value !== o.document ) { tip.detach().appendTo( value.body ); - // Handle class change + // Handle class change. } else if ( key === 'pointerClass' ) { tip.removeClass( o.pointerClass ).addClass( value ); } @@ -102,11 +102,11 @@ // Call super method. $.Widget.prototype._setOption.apply( this, arguments ); - // Reposition automatically + // Reposition automatically. if ( key === 'position' ) { this.reposition(); - // Update content automatically if pointer is open + // Update content automatically if pointer is open. } else if ( key === 'content' && this.active ) { this.update(); } @@ -234,7 +234,7 @@ }).show().position($.extend({ of: this.element, collision: 'fit none' - }, position )); // the object comes before this.options.position so the user can override position.of. + }, position )); // The object comes before this.options.position so the user can override position.of. this.repoint(); }, diff --git a/src/js/_enqueues/lib/quicktags.js b/src/js/_enqueues/lib/quicktags.js index f7bc488691..2224cbed84 100644 --- a/src/js/_enqueues/lib/quicktags.js +++ b/src/js/_enqueues/lib/quicktags.js @@ -20,7 +20,7 @@ * @output wp-includes/js/quicktags.js */ -// new edit toolbar used with permission +// New edit toolbar used with permission // by Alex King // http://www.alexking.org/ @@ -52,7 +52,7 @@ window.edToolbar = function(){}; /* jshint ignore:end */ (function(){ - // private stuff is prefixed with an underscore + // Private stuff is prefixed with an underscore. var _domReady = function(func) { var t, i, DOMContentLoaded, _tryReady; @@ -150,7 +150,7 @@ window.edToolbar = function(){}; t.settings = settings; if ( id === 'content' && typeof(adminpage) === 'string' && ( adminpage === 'post-new-php' || adminpage === 'post-php' ) ) { - // back compat hack :-( + // Back compat hack :-( window.edCanvas = canvas; toolbar_id = 'ed_toolbar'; } else { @@ -168,19 +168,19 @@ window.edToolbar = function(){}; canvas.parentNode.insertBefore(tb, canvas); t.toolbar = tb; - // listen for click events + // Listen for click events. onclick = function(e) { e = e || window.event; var target = e.target || e.srcElement, visible = target.clientWidth || target.offsetWidth, i; - // don't call the callback on pressing the accesskey when the button is not visible + // Don't call the callback on pressing the accesskey when the button is not visible. if ( !visible ) { return; } - // as long as it has the class ed_button, execute the callback + // As long as it has the class ed_button, execute the callback. if ( / ed_button /.test(' ' + target.className + ' ') ) { - // we have to reassign canvas here + // We have to reassign canvas here. t.canvas = canvas = document.getElementById(id); i = target.id.replace(name + '_', ''); @@ -261,7 +261,7 @@ window.edToolbar = function(){}; theButtons = {}; use = ''; - // set buttons + // Set buttons. if ( settings.buttons ) { use = ','+settings.buttons+','; } @@ -361,7 +361,7 @@ window.edToolbar = function(){}; return; } - if ( priority === -1 ) { // back-compat + if ( priority === -1 ) { // Back-compat. return btn; } @@ -376,7 +376,7 @@ window.edToolbar = function(){}; } if ( this.buttonsInitDone ) { - this._buttonsInit(); // add the button HTML to all instances toolbars if addButton() was called too late + this._buttonsInit(); // Add the button HTML to all instances toolbars if addButton() was called too late. } }; @@ -387,12 +387,12 @@ window.edToolbar = function(){}; return false; } - if ( document.selection ) { //IE + if ( document.selection ) { // IE. canvas.focus(); sel = document.selection.createRange(); sel.text = content; canvas.focus(); - } else if ( canvas.selectionStart || canvas.selectionStart === 0 ) { // FF, WebKit, Opera + } else if ( canvas.selectionStart || canvas.selectionStart === 0 ) { // FF, WebKit, Opera. text = canvas.value; startPos = canvas.selectionStart; endPos = canvas.selectionEnd; @@ -420,7 +420,7 @@ window.edToolbar = function(){}; return true; }; - // a plain, dumb button + // A plain, dumb button. qt.Button = function( id, display, access, title, instance, attr ) { this.id = id; this.display = display; @@ -450,7 +450,7 @@ window.edToolbar = function(){}; }; qt.Button.prototype.callback = function(){}; - // a button that inserts HTML tag + // A button that inserts HTML tag. qt.TagButton = function( id, display, tagStart, tagEnd, access, title, instance, attr ) { var t = this; qt.Button.call( t, id, display, access, title, instance, attr ); @@ -485,7 +485,7 @@ window.edToolbar = function(){}; element.setAttribute( 'aria-label', this.attr.ariaLabel ); } }; - // whether a tag is open or not. Returns false if not open, or current open depth of the tag + // Whether a tag is open or not. Returns false if not open, or current open depth of the tag. qt.TagButton.prototype.isOpen = function (ed) { var t = this, i = 0, ret = false; if ( ed.openTags ) { @@ -501,7 +501,7 @@ window.edToolbar = function(){}; qt.TagButton.prototype.callback = function(element, canvas, ed) { var t = this, startPos, endPos, cursorPos, scrollTop, v = canvas.value, l, r, i, sel, endTag = v ? t.tagEnd : '', event; - if ( document.selection ) { // IE + if ( document.selection ) { // IE. canvas.focus(); sel = document.selection.createRange(); if ( sel.text.length > 0 ) { @@ -522,7 +522,7 @@ window.edToolbar = function(){}; } } canvas.focus(); - } else if ( canvas.selectionStart || canvas.selectionStart === 0 ) { // FF, WebKit, Opera + } else if ( canvas.selectionStart || canvas.selectionStart === 0 ) { // FF, WebKit, Opera. startPos = canvas.selectionStart; endPos = canvas.selectionEnd; @@ -532,12 +532,12 @@ window.edToolbar = function(){}; cursorPos = endPos; scrollTop = canvas.scrollTop; - l = v.substring(0, startPos); // left of the selection - r = v.substring(endPos, v.length); // right of the selection - i = v.substring(startPos, endPos); // inside the selection + l = v.substring(0, startPos); // Left of the selection. + r = v.substring(endPos, v.length); // Right of the selection. + i = v.substring(startPos, endPos); // Inside the selection. if ( startPos !== endPos ) { if ( !t.tagEnd ) { - canvas.value = l + i + t.tagStart + r; // insert self closing tags after the selection + canvas.value = l + i + t.tagStart + r; // Insert self-closing tags after the selection. cursorPos += t.tagStart.length; } else { canvas.value = l + t.tagStart + i + endTag + r; @@ -562,7 +562,7 @@ window.edToolbar = function(){}; canvas.selectionEnd = cursorPos; canvas.scrollTop = scrollTop; canvas.focus(); - } else { // other browsers? + } else { // Other browsers? if ( !endTag ) { canvas.value += t.tagStart; } else if ( t.isOpen(ed) !== false ) { @@ -584,10 +584,10 @@ window.edToolbar = function(){}; } }; - // removed + // Removed. qt.SpellButton = function() {}; - // the close tags button + // The close tags button. qt.CloseButton = function() { qt.Button.call( this, 'close', quicktagsL10n.closeTags, '', quicktagsL10n.closeAllOpenTags ); }; @@ -621,7 +621,7 @@ window.edToolbar = function(){}; } }; - // the link button + // The link button. qt.LinkButton = function() { var attr = { ariaLabel: quicktagsL10n.link @@ -653,7 +653,7 @@ window.edToolbar = function(){}; } }; - // the img button + // The img button. qt.ImgButton = function() { var attr = { ariaLabel: quicktagsL10n.image @@ -704,14 +704,14 @@ window.edToolbar = function(){}; c.focus(); }; - // ensure backward compatibility + // Ensure backward compatibility. edButtons[10] = new qt.TagButton( 'strong', 'b', '', '', '', '', '', { ariaLabel: quicktagsL10n.strong, ariaLabelClose: quicktagsL10n.strongClose } ); edButtons[20] = new qt.TagButton( 'em', 'i', '', '', '', '', '', { ariaLabel: quicktagsL10n.em, ariaLabelClose: quicktagsL10n.emClose } ); - edButtons[30] = new qt.LinkButton(); // special case + edButtons[30] = new qt.LinkButton(); // Special case. edButtons[40] = new qt.TagButton( 'block', 'b-quote', '\n\n
', '
\n\n', '', '', '', { ariaLabel: quicktagsL10n.blockquote, ariaLabelClose: quicktagsL10n.blockquoteClose } ); edButtons[50] = new qt.TagButton( 'del', 'del', '', '', '', '', '', { ariaLabel: quicktagsL10n.del, ariaLabelClose: quicktagsL10n.delClose } ); edButtons[60] = new qt.TagButton( 'ins', 'ins', '', '', '', '', '', { ariaLabel: quicktagsL10n.ins, ariaLabelClose: quicktagsL10n.insClose } ); - edButtons[70] = new qt.ImgButton(); // special case + edButtons[70] = new qt.ImgButton(); // Special case. edButtons[80] = new qt.TagButton( 'ul', 'ul', '
    \n', '
\n\n', '', '', '', { ariaLabel: quicktagsL10n.ul, ariaLabelClose: quicktagsL10n.ulClose } ); edButtons[90] = new qt.TagButton( 'ol', 'ol', '
    \n', '
\n\n', '', '', '', { ariaLabel: quicktagsL10n.ol, ariaLabelClose: quicktagsL10n.olClose } ); edButtons[100] = new qt.TagButton( 'li', 'li', '\t
  • ', '
  • \n', '', '', '', { ariaLabel: quicktagsL10n.li, ariaLabelClose: quicktagsL10n.liClose } ); diff --git a/src/js/_enqueues/vendor/plupload/handlers.js b/src/js/_enqueues/vendor/plupload/handlers.js index 9116a64eac..9ed2cc687d 100644 --- a/src/js/_enqueues/vendor/plupload/handlers.js +++ b/src/js/_enqueues/vendor/plupload/handlers.js @@ -1,18 +1,18 @@ /* global plupload, pluploadL10n, ajaxurl, post_id, wpUploaderInit, deleteUserSetting, setUserSetting, getUserSetting, shortform */ var topWin = window.dialogArguments || opener || parent || top, uploader, uploader_init; -// progress and success handlers for media multi uploads +// Progress and success handlers for media multi uploads. function fileQueued( fileObj ) { - // Get rid of unused form + // Get rid of unused form. jQuery( '.media-blank' ).remove(); var items = jQuery( '#media-items' ).children(), postid = post_id || 0; - // Collapse a single item + // Collapse a single item. if ( items.length == 1 ) { items.removeClass( 'open' ).find( '.slidetoggle' ).slideUp( 200 ); } - // Create a progress bar containing the filename + // Create a progress bar containing the filename. jQuery( '
    ' ) .attr( 'id', 'media-item-' + fileObj.id ) .addClass( 'child-of-' + postid ) @@ -20,7 +20,7 @@ function fileQueued( fileObj ) { jQuery( '
    ' ).text( ' ' + fileObj.name ) ) .appendTo( jQuery( '#media-items' ) ); - // Disable submit + // Disable submit. jQuery( '#insert-gallery' ).prop( 'disabled', true ); } @@ -40,27 +40,27 @@ function uploadProgress( up, file ) { jQuery( '.percent', item ).html( file.percent + '%' ); } -// check to see if a large file failed to upload +// Check to see if a large file failed to upload. function fileUploading( up, file ) { var hundredmb = 100 * 1024 * 1024, max = parseInt( up.settings.max_file_size, 10 ); if ( max > hundredmb && file.size > hundredmb ) { setTimeout( function() { - if ( file.status < 3 && file.loaded === 0 ) { // not uploading + if ( file.status < 3 && file.loaded === 0 ) { // Not uploading. wpFileError( file, pluploadL10n.big_upload_failed.replace( '%1$s', '' ).replace( '%2$s', '' ) ); - up.stop(); // stops the whole queue + up.stop(); // Stop the whole queue. up.removeFile( file ); - up.start(); // restart the queue + up.start(); // Restart the queue. } - }, 10000 ); // wait for 10 sec. for the file to start uploading + }, 10000 ); // Wait for 10 seconds for the file to start uploading. } } function updateMediaForm() { var items = jQuery( '#media-items' ).children(); - // Just one file, no need for collapsible part + // Just one file, no need for collapsible part. if ( items.length == 1 ) { items.addClass( 'open' ).find( '.slidetoggle' ).show(); jQuery( '.insert-gallery' ).hide(); @@ -80,11 +80,12 @@ function updateMediaForm() { function uploadSuccess( fileObj, serverData ) { var item = jQuery( '#media-item-' + fileObj.id ); - // on success serverData should be numeric, fix bug in html4 runtime returning the serverData wrapped in a
     tag
    +	// On success serverData should be numeric,
    +	// fix bug in html4 runtime returning the serverData wrapped in a 
     tag.
     	if ( typeof serverData === 'string' ) {
     		serverData = serverData.replace( /^
    (\d+)<\/pre>$/, '$1' );
     
    -		// if async-upload returned an error message, place it in the media item div and return
    +		// If async-upload returned an error message, place it in the media item div and return.
     		if ( /media-upload-error|error-div/.test( serverData ) ) {
     			item.html( serverData );
     			return;
    @@ -129,25 +130,27 @@ function prepareMediaItem( fileObj, serverData ) {
     			topWin.jQuery( '#TB_overlay' ).click( topWin.tb_remove );
     	} catch( e ){}
     
    -	if ( isNaN( serverData ) || !serverData ) { // Old style: Append the HTML returned by the server -- thumbnail and form inputs
    +	if ( isNaN( serverData ) || !serverData ) {
    +		// Old style: Append the HTML returned by the server -- thumbnail and form inputs.
     		item.append( serverData );
     		prepareMediaItemInit( fileObj );
    -	} else { // New style: server data is just the attachment ID, fetch the thumbnail and form html from the server
    +	} else {
    +		// New style: server data is just the attachment ID, fetch the thumbnail and form html from the server.
     		item.load( 'async-upload.php', {attachment_id:serverData, fetch:f}, function(){prepareMediaItemInit( fileObj );updateMediaForm();});
     	}
     }
     
     function prepareMediaItemInit( fileObj ) {
     	var item = jQuery( '#media-item-' + fileObj.id );
    -	// Clone the thumbnail as a "pinkynail" -- a tiny image to the left of the filename
    +	// Clone the thumbnail as a "pinkynail" -- a tiny image to the left of the filename.
     	jQuery( '.thumbnail', item ).clone().attr( 'class', 'pinkynail toggle' ).prependTo( item );
     
    -	// Replace the original filename with the new (unique) one assigned during upload
    +	// Replace the original filename with the new (unique) one assigned during upload.
     	jQuery( '.filename.original', item ).replaceWith( jQuery( '.filename.new', item ) );
     
    -	// Bind AJAX to the new Delete button
    +	// Bind AJAX to the new Delete button.
     	jQuery( 'a.delete', item ).click( function(){
    -		// Tell the server to delete it. TODO: handle exceptions
    +		// Tell the server to delete it. TODO: Handle exceptions.
     		jQuery.ajax({
     			url: ajaxurl,
     			type: 'post',
    @@ -163,9 +166,9 @@ function prepareMediaItemInit( fileObj ) {
     		return false;
     	});
     
    -	// Bind AJAX to the new Undo button
    +	// Bind AJAX to the new Undo button.
     	jQuery( 'a.undo', item ).click( function(){
    -		// Tell the server to untrash it. TODO: handle exceptions
    +		// Tell the server to untrash it. TODO: Handle exceptions.
     		jQuery.ajax({
     			url: ajaxurl,
     			type: 'post',
    @@ -195,16 +198,16 @@ function prepareMediaItemInit( fileObj ) {
     		return false;
     	});
     
    -	// Open this item if it says to start open (e.g. to display an error)
    +	// Open this item if it says to start open (e.g. to display an error).
     	jQuery( '#media-item-' + fileObj.id + '.startopen' ).removeClass( 'startopen' ).addClass( 'open' ).find( 'slidetoggle' ).fadeIn();
     }
     
    -// generic error message
    +// Generic error message.
     function wpQueueError( message ) {
     	jQuery( '#media-upload-error' ).show().html( '

    ' + message + '

    ' ); } -// file-specific error messages +// File-specific error messages. function wpFileError( fileObj, message ) { itemAjaxError( fileObj.id, message ); } @@ -212,7 +215,7 @@ function wpFileError( fileObj, message ) { function itemAjaxError( id, message ) { var item = jQuery( '#media-item-' + id ), filename = item.find( '.filename' ).text(), last_err = item.data( 'last-err' ); - if ( last_err == id ) // prevent firing an error for the same file twice + if ( last_err == id ) // Prevent firing an error for the same file twice. return; item.html( '
    ' + @@ -274,7 +277,7 @@ function switchUploader( s ) { if ( typeof( uploader ) == 'object' ) uploader.refresh(); } else { - setUserSetting( 'uploader', '1' ); // 1 == html uploader + setUserSetting( 'uploader', '1' ); // 1 == html uploader. jQuery( '.media-upload-form' ).addClass( 'html-uploader' ); } } @@ -365,7 +368,7 @@ jQuery( document ).ready( function( $ ) { $( '.media-upload-form' ).bind( 'click.uploader', function( e ) { var target = $( e.target ), tr, c; - if ( target.is( 'input[type="radio"]' ) ) { // remember the last used image size and alignment + if ( target.is( 'input[type="radio"]' ) ) { // Remember the last used image size and alignment. tr = target.closest( 'tr' ); if ( tr.hasClass( 'align' ) ) @@ -373,7 +376,7 @@ jQuery( document ).ready( function( $ ) { else if ( tr.hasClass( 'image-size' ) ) setUserSetting( 'imgsize', target.val() ); - } else if ( target.is( 'button.button' ) ) { // remember the last used image link url + } else if ( target.is( 'button.button' ) ) { // Remember the last used image link url. c = e.target.className || ''; c = c.match( /url([^ '"]+)/ ); @@ -385,15 +388,15 @@ jQuery( document ).ready( function( $ ) { target.parents( '.media-item' ).fadeOut( 200, function() { $( this ).remove(); } ); - } else if ( target.is( '.upload-flash-bypass a' ) || target.is( 'a.uploader-html' ) ) { // switch uploader to html4 + } else if ( target.is( '.upload-flash-bypass a' ) || target.is( 'a.uploader-html' ) ) { // Switch uploader to html4. $( '#media-items, p.submit, span.big-file-warning' ).css( 'display', 'none' ); switchUploader( 0 ); e.preventDefault(); - } else if ( target.is( '.upload-html-bypass a' ) ) { // switch uploader to multi-file + } else if ( target.is( '.upload-html-bypass a' ) ) { // Switch uploader to multi-file. $( '#media-items, p.submit, span.big-file-warning' ).css( 'display', '' ); switchUploader( 1 ); e.preventDefault(); - } else if ( target.is( 'a.describe-toggle-on' ) ) { // Show + } else if ( target.is( 'a.describe-toggle-on' ) ) { // Show. target.parent().addClass( 'open' ); target.siblings( '.slidetoggle' ).fadeIn( 250, function() { var S = $( window ).scrollTop(), @@ -417,7 +420,7 @@ jQuery( document ).ready( function( $ ) { } ); e.preventDefault(); - } else if ( target.is( 'a.describe-toggle-off' ) ) { // Hide + } else if ( target.is( 'a.describe-toggle-off' ) ) { // Hide. target.siblings( '.slidetoggle' ).fadeOut( 250, function() { target.parent().removeClass( 'open' ); } ); @@ -450,9 +453,11 @@ jQuery( document ).ready( function( $ ) { times = tryAgainCount[ file.id ]; if ( times && times > 4 ) { - // The file may have been uploaded and attachment post created, - // but post-processing and resizing failed... - // Do a cleanup then tell the user to scale down the image and upload it again. + /* + * The file may have been uploaded and attachment post created, + * but post-processing and resizing failed... + * Do a cleanup then tell the user to scale down the image and upload it again. + */ $.ajax({ type: 'post', url: ajaxurl, @@ -514,7 +519,7 @@ jQuery( document ).ready( function( $ ) { }); } - // init and set the uploader + // Init and set the uploader. uploader_init = function() { uploader = new plupload.Uploader( wpUploaderInit ); diff --git a/src/js/_enqueues/vendor/plupload/wp-plupload.js b/src/js/_enqueues/vendor/plupload/wp-plupload.js index ea32444c7e..e42288fbe4 100644 --- a/src/js/_enqueues/vendor/plupload/wp-plupload.js +++ b/src/js/_enqueues/vendor/plupload/wp-plupload.js @@ -33,7 +33,7 @@ window.wp = window.wp || {}; */ Uploader = function( options ) { var self = this, - isIE, // not used, back-compat + isIE, // Not used, back-compat. elements = { container: 'container', browser: 'browse_button', @@ -60,10 +60,12 @@ window.wp = window.wp || {}; this.plupload = $.extend( true, { multipart_params: {} }, Uploader.defaults ); this.container = document.body; // Set default container. - // Extend the instance with options. - // - // Use deep extend to allow options.plupload to override individual - // default plupload keys. + /* + * Extend the instance with options. + * + * Use deep extend to allow options.plupload to override individual + * default plupload keys. + */ $.extend( true, this, options ); // Proxy all methods so this always refers to the current instance. @@ -138,9 +140,11 @@ window.wp = window.wp || {}; times = tryAgainCount[ file.id ]; if ( times && times > 4 ) { - // The file may have been uploaded and attachment post created, - // but post-processing and resizing failed... - // Do a cleanup then tell the user to scale down the image and upload it again. + /* + * The file may have been uploaded and attachment post created, + * but post-processing and resizing failed... + * Do a cleanup then tell the user to scale down the image and upload it again. + */ $.ajax({ type: 'post', url: ajaxurl, @@ -238,7 +242,7 @@ window.wp = window.wp || {}; fileUploaded = function( up, file, response ) { var complete; - // Remove the "uploading" UI elements + // Remove the "uploading" UI elements. _.each( ['file','loaded','size','percent'], function( key ) { file.attachment.unset( key ); } ); @@ -295,11 +299,13 @@ window.wp = window.wp || {}; }); dropzone.bind('dragleave.wp-uploader, drop.wp-uploader', function() { - // Using an instant timer prevents the drag-over class from - // being quickly removed and re-added when elements inside the - // dropzone are repositioned. - // - // @see https://core.trac.wordpress.org/ticket/21705 + /* + * Using an instant timer prevents the drag-over class + * from being quickly removed and re-added when elements + * inside the dropzone are repositioned. + * + * @see https://core.trac.wordpress.org/ticket/21705 + */ timer = setTimeout( function() { active = false; dropzone.trigger('dropzone:leave').removeClass('drag-over'); @@ -513,9 +519,11 @@ window.wp = window.wp || {}; node = node.parentNode; } - // If the browser node is not attached to the DOM, use a - // temporary container to house it, as the browser button - // shims require the button to exist in the DOM at all times. + /* + * If the browser node is not attached to the DOM, + * use a temporary container to house it, as the browser button shims + * require the button to exist in the DOM at all times. + */ if ( ! attached ) { id = 'wp-uploader-browser-' + this.uploader.id; diff --git a/src/js/_enqueues/vendor/tinymce/plugins/compat3x/plugin.js b/src/js/_enqueues/vendor/tinymce/plugins/compat3x/plugin.js index 92d433edcd..9be24f3e1a 100644 --- a/src/js/_enqueues/vendor/tinymce/plugins/compat3x/plugin.js +++ b/src/js/_enqueues/vendor/tinymce/plugins/compat3x/plugin.js @@ -44,7 +44,7 @@ this.add = function (callback, scope, prepend) { log('.on' + newEventName + ".add(..)"); - // Convert callback({arg1:x, arg2:x}) -> callback(arg1, arg2) + // Convert callback({arg1:x, arg2:x}) -> callback(arg1, arg2). function patchedEventCallback(e) { var callbackArgs = []; diff --git a/src/js/_enqueues/vendor/tinymce/plugins/wordpress/plugin.js b/src/js/_enqueues/vendor/tinymce/plugins/wordpress/plugin.js index b7848cd987..cbb320b146 100644 --- a/src/js/_enqueues/vendor/tinymce/plugins/wordpress/plugin.js +++ b/src/js/_enqueues/vendor/tinymce/plugins/wordpress/plugin.js @@ -1,6 +1,6 @@ /* global getUserSetting, setUserSetting */ ( function( tinymce ) { -// Set the minimum value for the modals z-index higher than #wpadminbar (100000) +// Set the minimum value for the modals z-index higher than #wpadminbar (100000). if ( ! tinymce.ui.FloatPanel.zIndex || tinymce.ui.FloatPanel.zIndex < 100100 ) { tinymce.ui.FloatPanel.zIndex = 100100; } @@ -88,7 +88,7 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { } }); - // Hide the toolbars after loading + // Hide the toolbars after loading. editor.on( 'PostRender', function() { if ( editor.getParam( 'wordpress_adv_hidden', true ) && getUserSetting( 'hidetb', '0' ) === '0' ) { toggleToolbars( 'hide' ); @@ -191,7 +191,7 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { } }); - // Display the tag name instead of img in element path + // Display the tag name instead of img in element path. editor.on( 'ResolveName', function( event ) { var attr; @@ -200,7 +200,7 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { } }); - // Register commands + // Register commands. editor.addCommand( 'WP_More', function( tag ) { var parent, html, title, classname = 'wp-more-tag', @@ -215,13 +215,13 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { html = ''; - // Most common case + // Most common case. if ( node === rootNode || ( node.nodeName === 'P' && node.parentNode === rootNode ) ) { editor.insertContent( html ); return; } - // Get the top level parent node + // Get the top level parent node. parent = dom.getParent( node, function( found ) { if ( found.parentNode && found.parentNode === rootNode ) { return true; @@ -328,7 +328,7 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { html = '
    '; - // Main section, default and additional shortcuts + // Main section, default and additional shortcuts. html = html + '

    ' + __( 'Default shortcuts,' ) + ' ' + meta + '

    ' + '' + @@ -342,7 +342,7 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { '
    '; if ( editor.plugins.wptextpattern && ( ! tinymce.Env.ie || tinymce.Env.ie > 8 ) ) { - // Text pattern section + // Text pattern section. html = html + '

    ' + __( 'When starting a new paragraph with one of these formatting shortcuts followed by a space, the formatting will be applied automatically. Press Backspace or Escape to undo.' ) + '

    ' + '' + @@ -363,7 +363,7 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { '
    '; } - // Focus management section + // Focus management section. html = html + '

    ' + __( 'Focus shortcuts:' ) + '

    ' + '' + @@ -413,7 +413,7 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { } }); - // Register buttons + // Register buttons. editor.addButton( 'wp_more', { tooltip: 'Insert Read More tag', onclick: function() { @@ -439,7 +439,7 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { stateSelector: 'code' }); - // Insert->Add Media + // Insert->Add Media. if ( wp && wp.media && wp.media.editor ) { editor.addButton( 'wp_add_media', { tooltip: 'Add Media', @@ -455,7 +455,7 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { }); } - // Insert "Read More..." + // Insert "Read More...". editor.addMenuItem( 'wp_more', { text: 'Insert Read More tag', icon: 'wp_more', @@ -465,7 +465,7 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { } }); - // Insert "Next Page" + // Insert "Next Page". editor.addMenuItem( 'wp_page', { text: 'Page break', icon: 'wp_page', @@ -496,7 +496,7 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { editor.on( 'init', function() { var env = tinymce.Env, - bodyClass = ['mceContentBody'], // back-compat for themes that use this in editor-style.css... + bodyClass = ['mceContentBody'], // Back-compat for themes that use this in editor-style.css... doc = editor.getDoc(), dom = editor.dom; @@ -531,7 +531,7 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { } }); - // Remove invalid parent paragraphs when inserting HTML + // Remove invalid parent paragraphs when inserting HTML. editor.on( 'BeforeSetContent', function( event ) { if ( event.content ) { event.content = event.content.replace( /

    \s*<(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre)( [^>]*)?>/gi, '<$1$2>' ) @@ -554,21 +554,21 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { if ( editor.getParam( 'wp_paste_filters', true ) ) { editor.on( 'PastePreProcess', function( event ) { - // Remove trailing
    added by WebKit browsers to the clipboard + // Remove trailing
    added by WebKit browsers to the clipboard. event.content = event.content.replace( /
    /gi, '' ); - // In WebKit this is handled by removeWebKitStyles() + // In WebKit this is handled by removeWebKitStyles(). if ( ! tinymce.Env.webkit ) { - // Remove all inline styles + // Remove all inline styles. event.content = event.content.replace( /(<[^>]+) style="[^"]*"([^>]*>)/gi, '$1$2' ); - // Put back the internal styles + // Put back the internal styles. event.content = event.content.replace(/(<[^>]+) data-mce-style=([^>]+>)/gi, '$1 style=$2' ); } }); editor.on( 'PastePostProcess', function( event ) { - // Remove empty paragraphs + // Remove empty paragraphs. editor.$( 'p', event.node ).each( function( i, node ) { if ( dom.isEmpty( node ) ) { dom.remove( node ); @@ -585,7 +585,7 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { }); editor.on( 'SaveContent', function( event ) { - // If editor is hidden, we just want the textarea's value to be saved + // If editor is hidden, we just want the textarea's value to be saved. if ( ! editor.inline && editor.isHidden() ) { event.content = event.element.value; return; @@ -700,7 +700,7 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { wpTooltips = {}; - // For MacOS: ctrl = \u2303, cmd = \u2318, alt = \u2325 + // For MacOS: ctrl = \u2303, cmd = \u2318, alt = \u2325. if ( tinymce.Env.mac ) { access = '\u2303\u2325'; meta = '\u2318'; @@ -761,7 +761,7 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { } function addShortcutsToListbox() { - // listbox for the "blocks" drop-down + // listbox for the "blocks" drop-down. each( editor.theme.panel.find( 'listbox' ), function( listbox ) { if ( listbox && listbox.settings.text === 'Paragraph' ) { each( listbox.settings.values, function( item ) { @@ -1118,9 +1118,11 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { event.type === 'resize' || event.type === 'scroll' ) && ! activeToolbar.blockHide ) { - // Showing a tooltip may trigger a `resize` event in Chromium browsers. - // That results in a flicketing inline menu; tooltips are shown on hovering over a button, - // which then hides the toolbar on `resize`, then it repeats as soon as the toolbar is shown again. + /* + * Showing a tooltip may trigger a `resize` event in Chromium browsers. + * That results in a flicketing inline menu; tooltips are shown on hovering over a button, + * which then hides the toolbar on `resize`, then it repeats as soon as the toolbar is shown again. + */ if ( event.type === 'resize' || event.type === 'resizewindow' ) { win = editor.getWin(); size = win.innerHeight + win.innerWidth; @@ -1187,7 +1189,7 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { function noop() {} - // Expose some functions (back-compat) + // Expose some functions (back-compat). return { _showButtons: noop, _hideButtons: noop, diff --git a/src/js/_enqueues/vendor/tinymce/plugins/wpautoresize/plugin.js b/src/js/_enqueues/vendor/tinymce/plugins/wpautoresize/plugin.js index 98905f6478..6e0a1a8d82 100644 --- a/src/js/_enqueues/vendor/tinymce/plugins/wpautoresize/plugin.js +++ b/src/js/_enqueues/vendor/tinymce/plugins/wpautoresize/plugin.js @@ -61,13 +61,13 @@ tinymce.PluginManager.add( 'wpautoresize', function( editor ) { if ( ! body || ( e && e.type === 'setcontent' && e.initial ) || isFullscreen() ) { if ( body && docElm ) { body.style.overflowY = 'auto'; - docElm.style.overflowY = 'auto'; // Old IE + docElm.style.overflowY = 'auto'; // Old IE. } return; } - // Calculate outer height of the body element using CSS styles + // Calculate outer height of the body element using CSS styles. marginTop = editor.dom.getStyle( body, 'margin-top', true ); marginBottom = editor.dom.getStyle( body, 'margin-bottom', true ); paddingTop = editor.dom.getStyle( body, 'padding-top', true ); @@ -83,36 +83,36 @@ tinymce.PluginManager.add( 'wpautoresize', function( editor ) { myHeight = docElm.offsetHeight; } - // Make sure we have a valid height + // Make sure we have a valid height. if ( isNaN( myHeight ) || myHeight <= 0 ) { - // Get height differently depending on the browser used + // Get height differently depending on the browser used. myHeight = tinymce.Env.ie ? body.scrollHeight : ( tinymce.Env.webkit && body.clientHeight === 0 ? 0 : body.offsetHeight ); } - // Don't make it smaller than the minimum height + // Don't make it smaller than the minimum height. if ( myHeight > settings.autoresize_min_height ) { resizeHeight = myHeight; } - // If a maximum height has been defined don't exceed this height + // If a maximum height has been defined don't exceed this height. if ( settings.autoresize_max_height && myHeight > settings.autoresize_max_height ) { resizeHeight = settings.autoresize_max_height; body.style.overflowY = 'auto'; - docElm.style.overflowY = 'auto'; // Old IE + docElm.style.overflowY = 'auto'; // Old IE. } else { body.style.overflowY = 'hidden'; - docElm.style.overflowY = 'hidden'; // Old IE + docElm.style.overflowY = 'hidden'; // Old IE. body.scrollTop = 0; } - // Resize content element + // Resize content element. if (resizeHeight !== oldSize) { deltaSize = resizeHeight - oldSize; DOM.setStyle( editor.iframeElement, 'height', resizeHeight + 'px' ); oldSize = resizeHeight; - // WebKit doesn't decrease the size of the body element until the iframe gets resized - // So we need to continue to resize the iframe down until the size gets fixed + // WebKit doesn't decrease the size of the body element until the iframe gets resized. + // So we need to continue to resize the iframe down until the size gets fixed. if ( tinymce.isWebKit && deltaSize < 0 ) { resize( e ); } @@ -137,17 +137,17 @@ tinymce.PluginManager.add( 'wpautoresize', function( editor ) { }, interval ); } - // Define minimum height + // Define minimum height. settings.autoresize_min_height = parseInt(editor.getParam( 'autoresize_min_height', editor.getElement().offsetHeight), 10 ); - // Define maximum height + // Define maximum height. settings.autoresize_max_height = parseInt(editor.getParam( 'autoresize_max_height', 0), 10 ); function on() { if ( ! editor.dom.hasClass( editor.getBody(), 'wp-autoresize' ) ) { isActive = true; editor.dom.addClass( editor.getBody(), 'wp-autoresize' ); - // Add appropriate listeners for resizing the content area + // Add appropriate listeners for resizing the content area. editor.on( 'nodechange setcontent keyup FullscreenStateChanged', resize ); resize(); } @@ -156,20 +156,20 @@ tinymce.PluginManager.add( 'wpautoresize', function( editor ) { function off() { var doc; - // Don't turn off if the setting is 'on' + // Don't turn off if the setting is 'on'. if ( ! settings.wp_autoresize_on ) { isActive = false; doc = editor.getDoc(); editor.dom.removeClass( editor.getBody(), 'wp-autoresize' ); editor.off( 'nodechange setcontent keyup FullscreenStateChanged', resize ); doc.body.style.overflowY = 'auto'; - doc.documentElement.style.overflowY = 'auto'; // Old IE + doc.documentElement.style.overflowY = 'auto'; // Old IE. oldSize = 0; } } if ( settings.wp_autoresize_on ) { - // Turn resizing on when the editor loads + // Turn resizing on when the editor loads. isActive = true; editor.on( 'init', function() { @@ -184,24 +184,24 @@ tinymce.PluginManager.add( 'wpautoresize', function( editor ) { if ( editor.getParam( 'autoresize_on_init', true ) ) { editor.on( 'init', function() { - // Hit it 10 times in 200 ms intervals + // Hit it 10 times in 200 ms intervals. wait( 10, 200, function() { - // Hit it 5 times in 1 sec intervals + // Hit it 5 times in 1 sec intervals. wait( 5, 1000 ); }); }); } } - // Reset the stored size + // Reset the stored size. editor.on( 'show', function() { oldSize = 0; }); - // Register the command + // Register the command. editor.addCommand( 'wpAutoResize', resize ); - // On/off + // On/off. editor.addCommand( 'wpAutoResizeOn', on ); editor.addCommand( 'wpAutoResizeOff', off ); }); diff --git a/src/js/_enqueues/vendor/tinymce/plugins/wpdialogs/plugin.js b/src/js/_enqueues/vendor/tinymce/plugins/wpdialogs/plugin.js index 8b9229fdbc..11c8d5fdc4 100644 --- a/src/js/_enqueues/vendor/tinymce/plugins/wpdialogs/plugin.js +++ b/src/js/_enqueues/vendor/tinymce/plugins/wpdialogs/plugin.js @@ -30,7 +30,7 @@ tinymce.WPWindowManager = tinymce.InlineWindowManager = function( editor ) { } if ( typeof jQuery === 'undefined' || ! jQuery.wp || ! jQuery.wp.wpdialog ) { - // wpdialog.js is not loaded + // wpdialog.js is not loaded. if ( window.console && window.console.error ) { window.console.error('wpdialog.js is not loaded. Please set "wpdialogs" as dependency for your script when calling wp_enqueue_script(). You may also want to enqueue the "wp-jquery-ui-dialog" stylesheet.'); } @@ -54,7 +54,7 @@ tinymce.WPWindowManager = tinymce.InlineWindowManager = function( editor ) { // Store selection. Takes a snapshot in the FocusManager of the selection before focus is moved to the dialog. editor.nodeChanged(); - // Create the dialog if necessary + // Create the dialog if necessary. if ( ! $element.data('wpdialog') ) { $element.wpdialog({ title: args.title, @@ -85,7 +85,7 @@ tinymce.WPWindowManager = tinymce.InlineWindowManager = function( editor ) { }; tinymce.PluginManager.add( 'wpdialogs', function( editor ) { - // Replace window manager + // Replace window manager. editor.on( 'init', function() { editor.windowManager = new tinymce.WPWindowManager( editor ); }); diff --git a/src/js/_enqueues/vendor/tinymce/plugins/wpeditimage/plugin.js b/src/js/_enqueues/vendor/tinymce/plugins/wpeditimage/plugin.js index 9142ed5717..ac6c83b427 100644 --- a/src/js/_enqueues/vendor/tinymce/plugins/wpeditimage/plugin.js +++ b/src/js/_enqueues/vendor/tinymce/plugins/wpeditimage/plugin.js @@ -18,7 +18,7 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) { } ); editor.addButton( 'wp_img_edit', { - tooltip: 'Edit|button', // '|button' is not displayed, only used for context + tooltip: 'Edit|button', // '|button' is not displayed, only used for context. icon: 'dashicon dashicons-edit', onclick: function() { editImage( editor.selection.getNode() ); @@ -146,7 +146,7 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) { caption = trim( img[2] ); img = trim( img[1] ); } else { - // old captions shortcode style + // Old captions shortcode style. caption = trim( b ).replace( /caption=['"]/, '' ).replace( /['"]$/, '' ); img = c; } @@ -214,18 +214,18 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) { } caption = caption.replace( /\r\n|\r/g, '\n' ).replace( /<[a-zA-Z0-9]+( [^<>]+)?>/g, function( a ) { - // no line breaks inside HTML tags + // No line breaks inside HTML tags. return a.replace( /[\r\n\t]+/, ' ' ); }); - // convert remaining line breaks to
    + // Convert remaining line breaks to
    . caption = caption.replace( /\s*\n\s*/g, '
    ' ); return '[caption id="' + id + '" align="' + align + '" width="' + width + '"' + classes + ']' + c + ' ' + caption + '[/caption]'; }); if ( out.indexOf('[caption') === -1 ) { - // the caption html seems broken, try to find the image that may be wrapped in a link + // The caption html seems broken, try to find the image that may be wrapped in a link // and may be followed by

    with the caption text. out = dl.replace( /[\s\S]*?((?:]+>)?]+>(?:<\/a>)?)(

    [\s\S]*<\/p>)?[\s\S]*/gi, '

    $1

    $2' ); } @@ -240,7 +240,7 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) { dom = editor.dom, isIntRegExp = /^\d+$/; - // default attributes + // Default attributes. metadata = { attachment_id: false, size: 'custom', @@ -292,7 +292,7 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) { metadata.extraClasses = extraClasses.join( ' ' ); - // Extract caption + // Extract caption. captionBlock = dom.getParents( imageNode, '.wp-caption' ); if ( captionBlock.length ) { @@ -318,7 +318,7 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) { } } - // Extract linkTo + // Extract linkTo. if ( imageNode.parentNode && imageNode.parentNode.nodeName === 'A' ) { link = imageNode.parentNode; metadata.linkUrl = dom.getAttrib( link, 'href' ); @@ -334,7 +334,7 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) { return node && !! ( node.textContent || node.innerText ).replace( /\ufeff/g, '' ); } - // Verify HTML in captions + // Verify HTML in captions. function verifyHTML( caption ) { if ( ! caption || ( caption.indexOf( '<' ) === -1 && caption.indexOf( '>' ) === -1 ) ) { return caption; @@ -404,7 +404,7 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) { }; if ( imageNode.parentNode && imageNode.parentNode.nodeName === 'A' && ! hasTextContent( imageNode.parentNode ) ) { - // Update or remove an existing link wrapped around the image + // Update or remove an existing link wrapped around the image. if ( imageData.linkUrl ) { dom.setAttribs( imageNode.parentNode, linkAttrs ); } else { @@ -413,11 +413,11 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) { } else if ( imageData.linkUrl ) { if ( linkNode = dom.getParent( imageNode, 'a' ) ) { // The image is inside a link together with other nodes, - // or is nested in another node, move it out + // or is nested in another node, move it out. dom.insertAfter( imageNode, linkNode ); } - // Add link wrapped around the image + // Add link wrapped around the image. linkNode = dom.create( 'a', linkAttrs ); imageNode.parentNode.insertBefore( linkNode, imageNode ); linkNode.appendChild( imageNode ); @@ -467,7 +467,7 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) { } else { id = id ? 'id="'+ id +'" ' : ''; - // should create a new function for generating the caption markup + // Should create a new function for generating the caption markup. html = '
    ' + '
    '+ imageData.caption +'
    '; @@ -486,7 +486,7 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) { } } } else if ( captionNode ) { - // Remove the caption wrapper and place the image in new paragraph + // Remove the caption wrapper and place the image in new paragraph. parent = dom.create( 'p' ); captionNode.parentNode.insertBefore( parent, captionNode ); parent.appendChild( node ); @@ -530,7 +530,7 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) { // Mark the image node so we can select it later. editor.$( img ).attr( 'data-wp-editing', 1 ); - // Manipulate the metadata by reference that is fed into the PostImage model used in the media modal + // Manipulate the metadata by reference that is fed into the PostImage model used in the media modal. wp.media.events.trigger( 'editor:image-edit', { editor: editor, metadata: metadata, @@ -558,9 +558,11 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) { editor.focus(); frame.detach(); - // `close` fires first... - // To be able to update the image node, we need to find it here, - // and use it in the callback. + /* + * `close` fires first... + * To be able to update the image node, we need to find it here, + * and use it in the callback. + */ imageNode = editor.$( 'img[data-wp-editing]' ) imageNode.removeAttr( 'data-wp-editing' ); }); @@ -600,12 +602,12 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) { dom.addClass( editor.getBody(), captionClass ); - // Prevent IE11 from making dl.wp-caption resizable + // Prevent IE11 from making dl.wp-caption resizable. if ( tinymce.Env.ie && tinymce.Env.ie > 10 ) { - // The 'mscontrolselect' event is supported only in IE11+ + // The 'mscontrolselect' event is supported only in IE11+. dom.bind( editor.getBody(), 'mscontrolselect', function( event ) { if ( event.target.nodeName === 'IMG' && dom.getParent( event.target, '.wp-caption' ) ) { - // Hide the thick border with resize handles around dl.wp-caption + // Hide the thick border with resize handles around dl.wp-caption. editor.getBody().focus(); // :( } else if ( event.target.nodeName === 'DL' && dom.hasClass( event.target, 'wp-caption' ) ) { // Trigger the thick border with resize handles... @@ -688,25 +690,31 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) { if ( cmd === 'mceInsertContent' ) { if ( pasteInCaption ) { pasteInCaption = false; - // We are in the caption element, and in 'paste' context, - // and the pasted HTML was cleaned up on 'pastePostProcess' above. - // Let it be pasted in the caption. + /* + * We are in the caption element, and in 'paste' context, + * and the pasted HTML was cleaned up on 'pastePostProcess' above. + * Let it be pasted in the caption. + */ return; } - // The paste is somewhere else in the caption DL element. - // Prevent pasting in there as it will break the caption. - // Make new paragraph under the caption DL and move the caret there. + /* + * The paste is somewhere else in the caption DL element. + * Prevent pasting in there as it will break the caption. + * Make new paragraph under the caption DL and move the caret there. + */ p = dom.create( 'p' ); dom.insertAfter( p, captionParent ); editor.selection.setCursorLocation( p, 0 ); - // If the image is selected and the user pastes "over" it, - // replace both the image and the caption elements with the pasted content. - // This matches the behavior when pasting over non-caption images. + /* + * If the image is selected and the user pastes "over" it, + * replace both the image and the caption elements with the pasted content. + * This matches the behavior when pasting over non-caption images. + */ if ( node.nodeName === 'IMG' ) { - editor.$( captionParent ).remove(); - } + editor.$( captionParent ).remove(); + } editor.nodeChanged(); } else { @@ -759,7 +767,7 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) { VK = tinymce.util.VK; if ( keyCode === VK.ENTER ) { - // When pressing Enter inside a caption move the caret to a new parapraph under it + // When pressing Enter inside a caption move the caret to a new parapraph under it. node = selection.getNode(); wrap = dom.getParent( node, 'div.mceTemp' ); @@ -802,9 +810,11 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) { } }); - // After undo/redo FF seems to set the image height very slowly when it is set to 'auto' in the CSS. - // This causes image.getBoundingClientRect() to return wrong values and the resize handles are shown in wrong places. - // Collapse the selection to remove the resize handles. + /* + * After undo/redo FF seems to set the image height very slowly when it is set to 'auto' in the CSS. + * This causes image.getBoundingClientRect() to return wrong values and the resize handles are shown in wrong places. + * Collapse the selection to remove the resize handles. + */ if ( tinymce.Env.gecko ) { editor.on( 'undo redo', function() { if ( editor.selection.getNode().nodeName === 'IMG' ) { @@ -878,7 +888,7 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) { } ); } )(); - // Add to editor.wp + // Add to editor.wp. editor.wp = editor.wp || {}; editor.wp.isPlaceholder = isPlaceholder; diff --git a/src/js/_enqueues/vendor/tinymce/plugins/wpemoji/plugin.js b/src/js/_enqueues/vendor/tinymce/plugins/wpemoji/plugin.js index 7d3e4baaef..84de774d70 100644 --- a/src/js/_enqueues/vendor/tinymce/plugins/wpemoji/plugin.js +++ b/src/js/_enqueues/vendor/tinymce/plugins/wpemoji/plugin.js @@ -56,18 +56,22 @@ } if ( isWin8 ) { - // Windows 8+ emoji can be "typed" with the onscreen keyboard. - // That triggers the normal keyboard events, but not the 'input' event. - // Thankfully it sets keyCode 231 when the onscreen keyboard inserts any emoji. + /* + * Windows 8+ emoji can be "typed" with the onscreen keyboard. + * That triggers the normal keyboard events, but not the 'input' event. + * Thankfully it sets keyCode 231 when the onscreen keyboard inserts any emoji. + */ editor.on( 'keyup', function( event ) { if ( event.keyCode === 231 ) { parseNode( editor.selection.getNode() ); } } ); } else if ( ! isWin ) { - // In MacOS inserting emoji doesn't trigger the stanradr keyboard events. - // Thankfully it triggers the 'input' event. - // This works in Android and iOS as well. + /* + * In MacOS inserting emoji doesn't trigger the stanradr keyboard events. + * Thankfully it triggers the 'input' event. + * This works in Android and iOS as well. + */ editor.on( 'keydown keyup', function( event ) { typing = ( event.type === 'keydown' ); } ); diff --git a/src/js/_enqueues/vendor/tinymce/plugins/wpgallery/plugin.js b/src/js/_enqueues/vendor/tinymce/plugins/wpgallery/plugin.js index d9723f2db5..54245efaa5 100644 --- a/src/js/_enqueues/vendor/tinymce/plugins/wpgallery/plugin.js +++ b/src/js/_enqueues/vendor/tinymce/plugins/wpgallery/plugin.js @@ -57,7 +57,7 @@ tinymce.PluginManager.add('wpgallery', function( editor ) { } } - // Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('...'); + // Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('...'). editor.addCommand( 'WP_Gallery', function() { editMedia( editor.selection.getNode() ); }); @@ -71,7 +71,7 @@ tinymce.PluginManager.add('wpgallery', function( editor ) { } if ( node.nodeName === 'IMG' && dom.getAttrib( node, 'data-wp-media' ) ) { - // Don't trigger on right-click + // Don't trigger on right-click. if ( event.button !== 2 ) { if ( dom.hasClass( node, 'wp-media-selected' ) ) { editMedia( node ); @@ -85,7 +85,7 @@ tinymce.PluginManager.add('wpgallery', function( editor ) { } }); - // Display gallery, audio or video instead of img in the element path + // Display gallery, audio or video instead of img in the element path. editor.on( 'ResolveName', function( event ) { var dom = editor.dom, node = event.target; @@ -98,7 +98,7 @@ tinymce.PluginManager.add('wpgallery', function( editor ) { }); editor.on( 'BeforeSetContent', function( event ) { - // 'wpview' handles the gallery shortcode when present + // 'wpview' handles the gallery shortcode when present. if ( ! editor.plugins.wpview || typeof wp === 'undefined' || ! wp.mce ) { event.content = replaceGalleryShortcodes( event.content ); } diff --git a/src/js/_enqueues/vendor/tinymce/plugins/wplink/plugin.js b/src/js/_enqueues/vendor/tinymce/plugins/wplink/plugin.js index 890ebe86c2..29f98a128f 100644 --- a/src/js/_enqueues/vendor/tinymce/plugins/wplink/plugin.js +++ b/src/js/_enqueues/vendor/tinymce/plugins/wplink/plugin.js @@ -37,9 +37,9 @@ url = this.url; } - // If the URL is longer that 40 chars, concatenate the beginning (after the domain) and ending with ... + // If the URL is longer that 40 chars, concatenate the beginning (after the domain) and ending with '...'. if ( url.length > 40 && ( index = url.indexOf( '/' ) ) !== -1 && ( lastIndex = url.lastIndexOf( '/' ) ) !== -1 && lastIndex !== index ) { - // If the beginning + ending are shorter that 40 chars, show more of the ending + // If the beginning + ending are shorter that 40 chars, show more of the ending. if ( index + url.length - lastIndex < 40 ) { lastIndex = -( 40 - ( index + 1 ) ); } @@ -297,10 +297,10 @@ editor.execCommand( 'wp_link_cancel' ); } ); - // WP default shortcuts + // WP default shortcuts. editor.addShortcut( 'access+a', '', 'WP_Link' ); editor.addShortcut( 'access+s', '', 'wp_unlink' ); - // The "de-facto standard" shortcut, see #27305 + // The "de-facto standard" shortcut, see #27305. editor.addShortcut( 'meta+k', '', 'WP_Link' ); editor.addButton( 'link', { @@ -565,7 +565,7 @@ } ); editor.addButton( 'wp_link_edit', { - tooltip: 'Edit|button', // '|button' is not displayed, only used for context + tooltip: 'Edit|button', // '|button' is not displayed, only used for context. icon: 'dashicon dashicons-edit', cmd: 'WP_Link' } ); diff --git a/src/js/_enqueues/vendor/tinymce/plugins/wptextpattern/plugin.js b/src/js/_enqueues/vendor/tinymce/plugins/wptextpattern/plugin.js index 236775034c..a11515acb1 100644 --- a/src/js/_enqueues/vendor/tinymce/plugins/wptextpattern/plugin.js +++ b/src/js/_enqueues/vendor/tinymce/plugins/wptextpattern/plugin.js @@ -149,9 +149,9 @@ var before = string.charAt( startOffset - 1 ); var after = string.charAt( startOffset + p.delimiter.length ); - // test*test* => format applied - // test *test* => applied - // test* test* => not applied + // test*test* => format applied. + // test *test* => applied. + // test* test* => not applied. if ( startOffset && /\S/.test( before ) ) { if ( /\s/.test( after ) || before === delimiterFirstChar ) { return; diff --git a/src/js/_enqueues/vendor/tinymce/plugins/wpview/plugin.js b/src/js/_enqueues/vendor/tinymce/plugins/wpview/plugin.js index 573ecb4167..1c21854786 100644 --- a/src/js/_enqueues/vendor/tinymce/plugins/wpview/plugin.js +++ b/src/js/_enqueues/vendor/tinymce/plugins/wpview/plugin.js @@ -52,7 +52,7 @@ var className = editor.getBody().className; editor.$( 'iframe[class="wpview-sandbox"]' ).each( function( i, iframe ) { - // Make sure it is a local iframe + // Make sure it is a local iframe. // jshint scripturl: true if ( ! iframe.src || iframe.src === 'javascript:""' ) { try { @@ -79,11 +79,11 @@ node = editor.selection.getNode(); if ( node && node !== editor.getBody() && /^\s*https?:\/\/\S+\s*$/i.test( event.content ) ) { - // When a url is pasted or inserted, only try to embed it when it is in an empty paragrapgh. + // When a url is pasted or inserted, only try to embed it when it is in an empty paragraph. node = editor.dom.getParent( node, 'p' ); if ( node && /^[\s\uFEFF\u00A0]*$/.test( editor.$( node ).text() || '' ) ) { - // Make sure there are no empty inline elements in the

    + // Make sure there are no empty inline elements in the

    . node.innerHTML = ''; } else { return; @@ -178,7 +178,7 @@ } ); editor.addButton( 'wp_view_edit', { - tooltip: 'Edit|button', // '|button' is not displayed, only used for context + tooltip: 'Edit|button', // '|button' is not displayed, only used for context. icon: 'dashicon dashicons-edit', onclick: function() { var node = editor.selection.getNode(); diff --git a/src/js/_enqueues/vendor/tinymce/wp-tinymce.php b/src/js/_enqueues/vendor/tinymce/wp-tinymce.php index 3d7b2347f6..213e9327b5 100644 --- a/src/js/_enqueues/vendor/tinymce/wp-tinymce.php +++ b/src/js/_enqueues/vendor/tinymce/wp-tinymce.php @@ -26,10 +26,10 @@ function get_file( $path ) { return @file_get_contents( $path ); } -$expires_offset = 31536000; // 1 year +$expires_offset = 31536000; // 1 year. header( 'Content-Type: application/javascript; charset=UTF-8' ); -header( 'Vary: Accept-Encoding' ); // Handle proxies +header( 'Vary: Accept-Encoding' ); // Handle proxies. header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expires_offset ) . ' GMT' ); header( "Cache-Control: public, max-age=$expires_offset" ); diff --git a/src/js/_enqueues/wp/api-request.js b/src/js/_enqueues/wp/api-request.js index 3ed1c68695..51df7f6f64 100644 --- a/src/js/_enqueues/wp/api-request.js +++ b/src/js/_enqueues/wp/api-request.js @@ -8,7 +8,7 @@ * - Sends the REST API nonce as a request header. * - Allows specifying only an endpoint namespace/path instead of a full URL. * - * @since 4.9.0 + * @since 4.9.0 * @output wp-includes/js/api-request.js */ @@ -42,8 +42,8 @@ apiRoot = wpApiSettings.root; path = path.replace( /^\//, '' ); - // API root may already include query parameter prefix if site is - // configured to use plain permalinks. + // API root may already include query parameter prefix + // if site is configured to use plain permalinks. if ( 'string' === typeof apiRoot && -1 !== apiRoot.indexOf( '?' ) ) { path = path.replace( '?', '&' ); } diff --git a/src/js/_enqueues/wp/api.js b/src/js/_enqueues/wp/api.js index cbd3d4bc6b..8233e4a52c 100644 --- a/src/js/_enqueues/wp/api.js +++ b/src/js/_enqueues/wp/api.js @@ -107,9 +107,11 @@ minutesOffset = 0, numericKeys = [ 1, 4, 5, 6, 7, 10, 11 ]; - // ES5 §15.9.4.2 states that the string should attempt to be parsed as a Date Time String Format string - // before falling back to any implementation-specific date parsing, so that’s what we do, even if native - // implementations could be faster. + /* + * ES5 §15.9.4.2 states that the string should attempt to be parsed as a Date Time String Format string + * before falling back to any implementation-specific date parsing, so that’s what we do, even if native + * implementations could be faster. + */ // 1 YYYY 2 MM 3 DD 4 HH 5 mm 6 ss 7 msec 8 Z 9 ± 10 tzHH 11 tzmm if ( ( struct = /^(\d{4}|[+\-]\d{6})(?:-(\d{2})(?:-(\d{2}))?)?(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{3}))?)?(?:(Z)|([+\-])(\d{2})(?::(\d{2}))?)?)?$/.exec( date ) ) ) { @@ -855,7 +857,7 @@ if ( _.isFunction( model.nonce ) && ! _.isEmpty( model.nonce() ) ) { beforeSend = options.beforeSend; - // @todo enable option for jsonp endpoints + // @todo Enable option for jsonp endpoints. // options.dataType = 'jsonp'; // Include the nonce with requests. @@ -1340,7 +1342,7 @@ } ); } else { - // This is a model without a parent in its route + // This is a model without a parent in its route. modelClassName = wp.api.utils.capitalizeAndCamelCaseDashes( routeName ); modelClassName = mapping.models[ modelClassName ] || modelClassName; loadingObjects.models[ modelClassName ] = wp.api.WPApiBaseModel.extend( { @@ -1514,7 +1516,7 @@ if ( ! initializedDeferreds[ attributes.apiRoot + attributes.versionString ] ) { - // Look for an existing copy of this endpoint + // Look for an existing copy of this endpoint. endpoint = wp.api.endpoints.findWhere( { 'apiRoot': attributes.apiRoot, 'versionString': attributes.versionString } ); if ( ! endpoint ) { endpoint = new Endpoint( attributes ); diff --git a/src/js/_enqueues/wp/autosave.js b/src/js/_enqueues/wp/autosave.js index a96ea97bf9..33c7e2d3b6 100644 --- a/src/js/_enqueues/wp/autosave.js +++ b/src/js/_enqueues/wp/autosave.js @@ -3,7 +3,7 @@ */ /* global tinymce, wpCookies, autosaveL10n, switchEditors */ -// Back-compat +// Back-compat. window.autosave = function() { return true; }; @@ -209,7 +209,7 @@ window.autosave = function() { */ function getStorage() { var stored_obj = false; - // Separate local storage containers for each blog_id + // Separate local storage containers for each blog_id. if ( hasStorage && blog_id ) { stored_obj = sessionStorage.getItem( 'wp-autosave-' + blog_id ); @@ -314,7 +314,7 @@ window.autosave = function() { /** * Saves post data for the current post. * - * Runs on a 15 sec. interval, saves when there are differences in the post title or content. + * Runs on a 15 seconds interval, saves when there are differences in the post title or content. * When the optional data is provided, updates the last saved post data. * * @since 3.9.0 @@ -378,9 +378,11 @@ window.autosave = function() { // Check if the local post data is different than the loaded post data. if ( $( '#wp-content-wrap' ).hasClass( 'tmce-active' ) ) { - // If TinyMCE loads first, check the post 1.5 sec. after it is ready. - // By this time the content has been loaded in the editor and 'saved' to the textarea. - // This prevents false positives. + /* + * If TinyMCE loads first, check the post 1.5 seconds after it is ready. + * By this time the content has been loaded in the editor and 'saved' to the textarea. + * This prevents false positives. + */ $document.on( 'tinymce-editor-init.autosave', function() { window.setTimeout( function() { checkPost(); @@ -390,7 +392,7 @@ window.autosave = function() { checkPost(); } - // Save every 15 sec. + // Save every 15 seconds. intervalTimer = window.setInterval( save, 15000 ); $( 'form#post' ).on( 'submit.autosave-local', function() { @@ -456,7 +458,7 @@ window.autosave = function() { if ( cookie === post_id + '-saved' ) { wpCookies.remove( 'wp-saving-post' ); - // The post was saved properly, remove old data and bail + // The post was saved properly, remove old data and bail. setData( false ); return; } @@ -519,7 +521,7 @@ window.autosave = function() { var editor; if ( postData ) { - // Set the last saved data + // Set the last saved data. lastCompareString = getCompareString( postData ); if ( $( '#title' ).val() !== postData.post_title ) { @@ -534,14 +536,14 @@ window.autosave = function() { postData.content = switchEditors.wpautop( postData.content ); } - // Make sure there's an undo level in the editor + // Make sure there's an undo level in the editor. editor.undoManager.transact( function() { editor.setContent( postData.content || '' ); editor.nodeChanged(); }); } else { - // Make sure the Text editor is selected + // Make sure the Text editor is selected. $( '#content-html' ).click(); $( '#content' ).focus(); @@ -558,9 +560,11 @@ window.autosave = function() { blog_id = typeof window.autosaveL10n !== 'undefined' && window.autosaveL10n.blog_id; - // Check if the browser supports sessionStorage and it's not disabled, - // then initialize and run checkPost(). - // Don't run if the post type supports neither 'editor' (textarea#content) nor 'excerpt'. + /* + * Check if the browser supports sessionStorage and it's not disabled, + * then initialize and run checkPost(). + * Don't run if the post type supports neither 'editor' (textarea#content) nor 'excerpt'. + */ if ( checkStorage() && blog_id && ( $('#content').length || $('#excerpt').length ) ) { $document.ready( run ); } @@ -652,7 +656,7 @@ window.autosave = function() { enableButtons(); if ( data.success ) { - // No longer an auto-draft + // No longer an auto-draft. $( '#auto_draft' ).val(''); } } @@ -698,7 +702,7 @@ window.autosave = function() { function save() { var postData, compareString; - // window.autosave() used for back-compat + // window.autosave() used for back-compat. if ( isSuspended || _blockSave || ! window.autosave() ) { return false; } @@ -710,12 +714,12 @@ window.autosave = function() { postData = getPostData(); compareString = getCompareString( postData ); - // First check + // First check. if ( typeof lastCompareString === 'undefined' ) { lastCompareString = initialCompareString; } - // No change + // No change. if ( compareString === lastCompareString ) { return false; } @@ -836,7 +840,7 @@ window.autosave = function() { } }).ready( function() { - // Set the initial compare string in case TinyMCE is not used or not loaded first + // Set the initial compare string in case TinyMCE is not used or not loaded first. initialCompareString = getCompareString(); }); diff --git a/src/js/_enqueues/wp/code-editor.js b/src/js/_enqueues/wp/code-editor.js index 15906ff55b..dd0feca956 100644 --- a/src/js/_enqueues/wp/code-editor.js +++ b/src/js/_enqueues/wp/code-editor.js @@ -79,7 +79,11 @@ if ( 'undefined' === typeof window.wp.codeEditor ) { options = $.extend( {}, options ); } - // Note that rules must be sent in the "deprecated" lint.options property to prevent linter from complaining about unrecognized options. See . + /* + * Note that rules must be sent in the "deprecated" lint.options property + * to prevent linter from complaining about unrecognized options. + * See . + */ if ( ! options.options ) { options.options = {}; } diff --git a/src/js/_enqueues/wp/custom-header.js b/src/js/_enqueues/wp/custom-header.js index 1c405990de..1f2c56f96e 100644 --- a/src/js/_enqueues/wp/custom-header.js +++ b/src/js/_enqueues/wp/custom-header.js @@ -79,7 +79,7 @@ * @return {boolean} */ supportsVideo: function() { - // Don't load video on small screens. @todo: consider bandwidth and other factors. + // Don't load video on small screens. @todo Consider bandwidth and other factors. if ( window.innerWidth < settings.minWidth || window.innerHeight < settings.minHeight ) { return false; } diff --git a/src/js/_enqueues/wp/customize/base.js b/src/js/_enqueues/wp/customize/base.js index 183b731ace..1d38d9b0dc 100644 --- a/src/js/_enqueues/wp/customize/base.js +++ b/src/js/_enqueues/wp/customize/base.js @@ -25,17 +25,21 @@ window.wp = window.wp || {}; inherits = function( parent, protoProps, staticProps ) { var child; - // The constructor function for the new subclass is either defined by you - // (the "constructor" property in your `extend` definition), or defaulted - // by us to simply call `super()`. + /* + * The constructor function for the new subclass is either defined by you + * (the "constructor" property in your `extend` definition), or defaulted + * by us to simply call `super()`. + */ if ( protoProps && protoProps.hasOwnProperty( 'constructor' ) ) { child = protoProps.constructor; } else { child = function() { - // Storing the result `super()` before returning the value - // prevents a bug in Opera where, if the constructor returns - // a function, Opera will reject the return value in favor of - // the original object. This causes all sorts of trouble. + /* + * Storing the result `super()` before returning the value + * prevents a bug in Opera where, if the constructor returns + * a function, Opera will reject the return value in favor of + * the original object. This causes all sorts of trouble. + */ var result = parent.apply( this, arguments ); return result; }; @@ -44,8 +48,8 @@ window.wp = window.wp || {}; // Inherit class (static) properties from parent. $.extend( child, parent ); - // Set the prototype chain to inherit from `parent`, without calling - // `parent`'s constructor function. + // Set the prototype chain to inherit from `parent`, + // without calling `parent`'s constructor function. ctor.prototype = parent.prototype; child.prototype = new ctor(); @@ -187,7 +191,7 @@ window.wp = window.wp || {}; * @param {object} options */ initialize: function( initial, options ) { - this._value = initial; // @todo: potentially change this to a this.set() call. + this._value = initial; // @todo Potentially change this to a this.set() call. this.callbacks = $.Callbacks(); this._dirty = false; @@ -496,7 +500,7 @@ window.wp = window.wp || {}; ids = slice.call( arguments ), dfd = $.Deferred(); - // If the last argument is a callback, bind it to .done() + // If the last argument is a callback, bind it to .done(). if ( $.isFunction( ids[ ids.length - 1 ] ) ) { dfd.done( ids.pop() ); } @@ -699,7 +703,7 @@ window.wp = window.wp || {}; return urlParser.protocol + '//' + urlParser.host.replace( /:(80|443)$/, '' ); }); - // first add with no value + // First add with no value. this.add( 'targetWindow', null ); // This avoids SecurityErrors when setting a window object in x-origin iframe'd scenarios. this.targetWindow.set = function( to ) { @@ -719,15 +723,17 @@ window.wp = window.wp || {}; return this; }; - // now set it + // Now set it. this.targetWindow( params.targetWindow || defaultTarget ); - // Since we want jQuery to treat the receive function as unique - // to this instance, we give the function a new guid. - // - // This will prevent every Messenger's receive function from being - // unbound when calling $.off( 'message', this.receive ); + /* + * Since we want jQuery to treat the receive function as unique + * to this instance, we give the function a new guid. + * + * This will prevent every Messenger's receive function from being + * unbound when calling $.off( 'message', this.receive ); + */ this.receive = $.proxy( this.receive, this ); this.receive.guid = $.guid++; diff --git a/src/js/_enqueues/wp/customize/controls.js b/src/js/_enqueues/wp/customize/controls.js index 6c92362410..8b8c1fd67e 100644 --- a/src/js/_enqueues/wp/customize/controls.js +++ b/src/js/_enqueues/wp/customize/controls.js @@ -578,7 +578,8 @@ return deferred.promise(); } - // A status would cause a revision to be made, and for this wp.customize.previewer.save() should be used. Status is also disallowed for revisions regardless. + // A status would cause a revision to be made, and for this wp.customize.previewer.save() should be used. + // Status is also disallowed for revisions regardless. if ( submittedArgs.status ) { return deferred.reject( { code: 'illegal_status_in_changeset_update' } ).promise(); } @@ -772,13 +773,13 @@ */ api.utils.areElementListsEqual = function ( listA, listB ) { var equal = ( - listA.length === listB.length && // if lists are different lengths, then naturally they are not equal - -1 === _.indexOf( _.map( // are there any false values in the list returned by map? - _.zip( listA, listB ), // pair up each element between the two lists + listA.length === listB.length && // If lists are different lengths, then naturally they are not equal. + -1 === _.indexOf( _.map( // Are there any false values in the list returned by map? + _.zip( listA, listB ), // Pair up each element between the two lists. function ( pair ) { - return $( pair[0] ).is( pair[1] ); // compare to see if each pair are equal + return $( pair[0] ).is( pair[1] ); // Compare to see if each pair is equal. } - ), false ) // check for presence of false in map's return value + ), false ) // Check for presence of false in map's return value. ); return equal; }; @@ -1128,7 +1129,8 @@ } if ( ! $.contains( document, headContainer.get( 0 ) ) ) { - // If the element is not in the DOM, then jQuery.fn.slideUp() does nothing. In this case, a hard toggle is required instead. + // If the element is not in the DOM, then jQuery.fn.slideUp() does nothing. + // In this case, a hard toggle is required instead. headContainer.toggle( active ); if ( args.completeCallback ) { args.completeCallback(); @@ -1479,7 +1481,7 @@ }); } ); } else { - // There is no panel, so embed the section in the root of the customizer + // There is no panel, so embed the section in the root of the customizer. parentContainer = api.ensure( section.containerPaneParent ); if ( ! section.headContainer.parent().is( parentContainer ) ) { parentContainer.append( section.headContainer ); @@ -1511,7 +1513,7 @@ if ( api.utils.isKeydownButNotEnterEvent( event ) ) { return; } - event.preventDefault(); // Keep this AFTER the key filter above + event.preventDefault(); // Keep this AFTER the key filter above. if ( section.expanded() ) { section.collapse(); @@ -1718,12 +1720,12 @@ var inject, section = this; - // Watch for changes to the panel state + // Watch for changes to the panel state. inject = function( panelId ) { var parentContainer; api.panel( panelId, function( panel ) { - // The panel has been registered, wait for it to become ready/initialized + // The panel has been registered, wait for it to become ready/initialized. panel.deferred.embedded.done( function() { parentContainer = panel.contentContainer; if ( ! section.headContainer.parent().is( parentContainer ) ) { @@ -1737,7 +1739,7 @@ } ); }; section.panel.bind( inject ); - inject( section.panel.get() ); // Since a section may never get a panel, assume that it won't ever get one + inject( section.panel.get() ); // Since a section may never get a panel, assume that it won't ever get one. }, /** @@ -1758,17 +1760,17 @@ return; } - // Pressing the right arrow key fires a theme:next event + // Pressing the right arrow key fires a theme:next event. if ( 39 === event.keyCode ) { section.nextTheme(); } - // Pressing the left arrow key fires a theme:previous event + // Pressing the left arrow key fires a theme:previous event. if ( 37 === event.keyCode ) { section.previousTheme(); } - // Pressing the escape key fires a theme:collapse event + // Pressing the escape key fires a theme:collapse event. if ( 27 === event.keyCode ) { if ( section.$body.hasClass( 'modal-open' ) ) { @@ -1818,7 +1820,7 @@ if ( api.utils.isKeydownButNotEnterEvent( event ) ) { return; } - event.preventDefault(); // Keep this AFTER the key filter above + event.preventDefault(); // Keep this AFTER the key filter above. section.collapse(); }); @@ -1957,11 +1959,11 @@ */ onChangeExpanded: function ( expanded, args ) { - // Note: there is a second argument 'args' passed + // Note: there is a second argument 'args' passed. var section = this, container = section.contentContainer.closest( '.customize-themes-full-container' ); - // Immediately call the complete callback if there were no changes + // Immediately call the complete callback if there were no changes. if ( args.unchanged ) { if ( args.completeCallback ) { args.completeCallback(); @@ -1976,7 +1978,7 @@ section.loadThemes(); } - // Collapse any sibling sections/panels + // Collapse any sibling sections/panels. api.section.each( function ( otherSection ) { var searchTerm; @@ -2123,7 +2125,8 @@ _.delay( section.renderScreenshots, 100 ); // Wait for the controls to become visible. - if ( 'local' === section.params.filter_type || 100 > themes.length ) { // If we have less than the requested 100 themes, it's the end of the list. + if ( 'local' === section.params.filter_type || 100 > themes.length ) { + // If we have less than the requested 100 themes, it's the end of the list. section.fullyLoaded = true; } } else { @@ -2202,7 +2205,9 @@ container = section.container.closest( '.customize-themes-full-container' ); bottom = container.scrollTop() + container.height(); - threshold = container.prop( 'scrollHeight' ) - 3000; // Use a fixed distance to the bottom of loaded results to avoid unnecessarily loading results sooner when using a percentage of scroll distance. + // Use a fixed distance to the bottom of loaded results to avoid unnecessarily + // loading results sooner when using a percentage of scroll distance. + threshold = container.prop( 'scrollHeight' ) - 3000; if ( bottom > threshold ) { section.loadThemes(); @@ -2614,15 +2619,15 @@ el.on( 'keydown', function( event ) { // Return if it's not the tab key - // When navigating with prev/next focus is already handled + // When navigating with prev/next focus is already handled. if ( 9 !== event.keyCode ) { return; } - // uses jQuery UI to get the tabbable elements + // Uses jQuery UI to get the tabbable elements. tabbables = $( ':tabbable', el ); - // Keep focus within the overlay + // Keep focus within the overlay. if ( tabbables.last()[0] === event.target && ! event.shiftKey ) { tabbables.first().focus(); return false; @@ -2797,7 +2802,7 @@ embed: function () { var panel = this, container = $( '#customize-theme-controls' ), - parentContainer = $( '.customize-pane-parent' ); // @todo This should be defined elsewhere, and to be configurable + parentContainer = $( '.customize-pane-parent' ); // @todo This should be defined elsewhere, and to be configurable. if ( ! panel.headContainer.parent().is( parentContainer ) ) { parentContainer.append( panel.headContainer ); @@ -2821,7 +2826,7 @@ if ( api.utils.isKeydownButNotEnterEvent( event ) ) { return; } - event.preventDefault(); // Keep this AFTER the key filter above + event.preventDefault(); // Keep this AFTER the key filter above. if ( ! panel.expanded() ) { panel.expand(); @@ -2833,7 +2838,7 @@ if ( api.utils.isKeydownButNotEnterEvent( event ) ) { return; } - event.preventDefault(); // Keep this AFTER the key filter above + event.preventDefault(); // Keep this AFTER the key filter above. if ( panel.expanded() ) { panel.collapse(); @@ -2908,7 +2913,7 @@ */ onChangeExpanded: function ( expanded, args ) { - // Immediately call the complete callback if there were no changes + // Immediately call the complete callback if there were no changes. if ( args.unchanged ) { if ( args.completeCallback ) { args.completeCallback(); @@ -2916,7 +2921,7 @@ return; } - // Note: there is a second argument 'args' passed + // Note: there is a second argument 'args' passed. var panel = this, accordionSection = panel.contentContainer, overlay = accordionSection.closest( '.wp-full-overlay' ), @@ -2927,7 +2932,7 @@ skipTransition; if ( expanded && ! accordionSection.hasClass( 'current-panel' ) ) { - // Collapse any sibling sections/panels + // Collapse any sibling sections/panels. api.section.each( function ( section ) { if ( panel.id !== section.panel() ) { section.collapse( { duration: 0 } ); @@ -3067,7 +3072,7 @@ // Attach regular panel events. api.Panel.prototype.attachEvents.apply( panel ); - // Temporary since supplying SFTP credentials does not work yet. See #42184 + // Temporary since supplying SFTP credentials does not work yet. See #42184. if ( api.settings.theme._canInstall && api.settings.theme._filesystemCredentialsNeeded ) { panel.notifications.add( new api.Notification( 'theme_install_unavailable', { message: api.l10n.themeInstallUnavailable, @@ -3140,7 +3145,7 @@ // Expand/collapse the panel normally. api.Panel.prototype.onChangeExpanded.apply( this, [ expanded, args ] ); - // Immediately call the complete callback if there were no changes + // Immediately call the complete callback if there were no changes. if ( args.unchanged ) { if ( args.completeCallback ) { args.completeCallback(); @@ -3682,15 +3687,15 @@ var control = this, inject; - // Watch for changes to the section state + // Watch for changes to the section state. inject = function ( sectionId ) { var parentContainer; - if ( ! sectionId ) { // @todo allow a control to be embedded without a section, for instance a control embedded in the front end. + if ( ! sectionId ) { // @todo Allow a control to be embedded without a section, for instance a control embedded in the front end. return; } - // Wait for the section to be registered + // Wait for the section to be registered. api.section( sectionId, function ( section ) { - // Wait for the section to be ready/initialized + // Wait for the section to be ready/initialized. section.deferred.embedded.done( function () { parentContainer = ( section.contentContainer.is( 'ul' ) ) ? section.contentContainer : section.contentContainer.find( 'ul:first' ); if ( ! control.container.parent().is( parentContainer ) ) { @@ -3724,7 +3729,7 @@ control.addNewPage(); }); control.container.on( 'keydown', '.create-item-input', function( e ) { - if ( 13 === e.which ) { // Enter + if ( 13 === e.which ) { // Enter. control.addNewPage(); } }); @@ -3909,7 +3914,7 @@ } if ( ! $.contains( document, this.container[0] ) ) { - // jQuery.fn.slideUp is not hiding an element if it is not in the DOM + // jQuery.fn.slideUp is not hiding an element if it is not in the DOM. this.container.toggle( active ); if ( args.completeCallback ) { args.completeCallback(); @@ -3957,7 +3962,7 @@ } }; - // Support the .dropdown class to open/close complex elements + // Support the .dropdown class to open/close complex elements. this.container.on( 'click keydown', '.dropdown', function( event ) { if ( api.utils.isKeydownButNotEnterEvent( event ) ) { return; @@ -3973,7 +3978,7 @@ control.container.parent().parent().find( 'li.library-selected' ).focus(); } - // Don't want to fire focus and click at same time + // Don't want to fire focus and click at same time. toggleFreeze = true; setTimeout(function () { toggleFreeze = false; @@ -4017,7 +4022,8 @@ templateId = control.templateSelector; - // Use default content template when a standard HTML type is used, there isn't a more specific template existing, and the control container is empty. + // Use default content template when a standard HTML type is used, + // there isn't a more specific template existing, and the control container is empty. if ( templateId === 'customize-control-' + control.params.type + '-content' && _.contains( standardTypes, control.params.type ) && ! document.getElementById( 'tmpl-' + templateId ) && @@ -4047,6 +4053,7 @@ * * @since 4.7.0 * @access private + * * @return {void} */ addNewPage: function () { @@ -4070,7 +4077,8 @@ input.removeClass( 'invalid' ); input.attr( 'disabled', 'disabled' ); - // The menus functions add the page, publish when appropriate, and also add the new page to the dropdown-pages controls. + // The menus functions add the page, publish when appropriate, + // and also add the new page to the dropdown-pages controls. promise = api.Menus.insertAutoDraftPost( { post_title: title, post_type: 'page' @@ -4199,7 +4207,7 @@ control.container.on( 'click keydown', '.remove-button', control.removeFile ); control.container.on( 'click keydown', '.remove-button', control.cleanupPlayer ); - // Resize the player controls when it becomes visible (ie when section is expanded) + // Resize the player controls when it becomes visible (ie when section is expanded). api.section( control.section() ).container .on( 'expanded', function() { if ( control.player ) { @@ -5128,7 +5136,7 @@ return; } - event.preventDefault(); // Keep this AFTER the key filter above + event.preventDefault(); // Keep this AFTER the key filter above. section = api.section( control.section() ); section.showDetails( control.params.theme, function() { @@ -5196,7 +5204,7 @@ control.params.priority = 101 - matchCount; // Sort results by match count. return true; } else { - control.deactivate(); // Hide control + control.deactivate(); // Hide control. control.params.priority = 101; return false; } @@ -6498,13 +6506,15 @@ urlParser.href = previewer.origin(); previewer.add( 'scheme', urlParser.protocol.replace( /:$/, '' ) ); - // Limit the URL to internal, front-end links. - // - // If the front end and the admin are served from the same domain, load the - // preview over ssl if the Customizer is being loaded over ssl. This avoids - // insecure content warnings. This is not attempted if the admin and front end - // are on different domains to avoid the case where the front end doesn't have - // ssl certs. + /* + * Limit the URL to internal, front-end links. + * + * If the front end and the admin are served from the same domain, load the + * preview over ssl if the Customizer is being loaded over ssl. This avoids + * insecure content warnings. This is not attempted if the admin and front end + * are on different domains to avoid the case where the front end doesn't have + * ssl certs. + */ previewer.add( 'previewUrl', params.previewUrl ).setter( function( to ) { var result = null, urlParser, queryParams, parsedAllowedUrl, parsedCandidateUrls = []; @@ -6735,12 +6745,13 @@ * * @since 3.4.0 * @access public + * * @return {void} */ refresh: function() { var previewer = this, onSettingChange; - // Display loading indicator + // Display loading indicator. previewer.send( 'loading-initiated' ); previewer.abort(); @@ -7013,7 +7024,7 @@ activeElement = $( document.activeElement ); } - // Sort the sections within each panel + // Sort the sections within each panel. api.panel.each( function ( panel ) { if ( 'themes' === panel.id ) { return; // Don't reflow theme sections, as doing so moves them after the themes container. @@ -7031,7 +7042,7 @@ } } ); - // Sort the controls within each section + // Sort the controls within each section. api.section.each( function ( section ) { var controls = section.controls(), controlContainers = _.pluck( controls, 'container' ); @@ -7047,10 +7058,10 @@ } } ); - // Sort the root panels and sections + // Sort the root panels and sections. rootNodes.sort( api.utils.prioritySort ); rootHeadContainers = _.pluck( rootNodes, 'headContainer' ); - appendContainer = $( '#customize-theme-controls .customize-pane-parent' ); // @todo This should be defined elsewhere, and to be configurable + appendContainer = $( '#customize-theme-controls .customize-pane-parent' ); // @todo This should be defined elsewhere, and to be configurable. if ( ! api.utils.areElementListsEqual( rootHeadContainers, appendContainer.children() ) ) { _( rootNodes ).each( function ( rootNode ) { appendContainer.append( rootNode.headContainer ); @@ -7058,7 +7069,7 @@ wasReflowed = true; } - // Now re-trigger the active Value callbacks to that the panels and sections can decide whether they can be rendered + // Now re-trigger the active Value callbacks so that the panels and sections can decide whether they can be rendered. api.panel.each( function ( panel ) { var value = panel.active(); panel.active.callbacks.fireWith( panel.active, [ value, value ] ); @@ -7068,7 +7079,7 @@ section.active.callbacks.fireWith( section.active, [ value, value ] ); } ); - // Restore focus if there was a reflow and there was an active (focused) element + // Restore focus if there was a reflow and there was an active (focused) element. if ( wasReflowed && activeElement ) { activeElement.focus(); } @@ -7208,9 +7219,11 @@ cancelScheduleButtonReminder = api.utils.highlightButton( btnWrapper, { delay: 1000, - // Only abort the reminder when the save button is focused. - // If the user clicks the settings button to toggle the - // settings closed, we'll still remind them. + /* + * Only abort the reminder when the save button is focused. + * If the user clicks the settings button to toggle the + * settings closed, we'll still remind them. + */ focusTarget: saveBtn } ); } @@ -7579,7 +7592,7 @@ if ( '0' === response ) { response = 'not_logged_in'; } else if ( '-1' === response ) { - // Back-compat in case any other check_ajax_referer() call is dying + // Back-compat in case any other check_ajax_referer() call is dying. response = 'invalid_nonce'; } @@ -7812,7 +7825,7 @@ api.previewer.send( 'nonce-refresh', nonce ); }); - // Create Settings + // Create Settings. $.each( api.settings.settings, function( id, data ) { var Constructor = api.settingConstructor[ data.type ] || api.Setting; api.add( new Constructor( id, data.value, { @@ -7822,28 +7835,31 @@ } ) ); }); - // Create Panels + // Create Panels. $.each( api.settings.panels, function ( id, data ) { var Constructor = api.panelConstructor[ data.type ] || api.Panel, options; - options = _.extend( { params: data }, data ); // Inclusion of params alias is for back-compat for custom panels that expect to augment this property. + // Inclusion of params alias is for back-compat for custom panels that expect to augment this property. + options = _.extend( { params: data }, data ); api.panel.add( new Constructor( id, options ) ); }); - // Create Sections + // Create Sections. $.each( api.settings.sections, function ( id, data ) { var Constructor = api.sectionConstructor[ data.type ] || api.Section, options; - options = _.extend( { params: data }, data ); // Inclusion of params alias is for back-compat for custom sections that expect to augment this property. + // Inclusion of params alias is for back-compat for custom sections that expect to augment this property. + options = _.extend( { params: data }, data ); api.section.add( new Constructor( id, options ) ); }); - // Create Controls + // Create Controls. $.each( api.settings.controls, function( id, data ) { var Constructor = api.controlConstructor[ data.type ] || api.Control, options; - options = _.extend( { params: data }, data ); // Inclusion of params alias is for back-compat for custom controls that expect to augment this property. + // Inclusion of params alias is for back-compat for custom controls that expect to augment this property. + options = _.extend( { params: data }, data ); api.control.add( new Constructor( id, options ) ); }); - // Focus the autofocused element + // Focus the autofocused element. _.each( [ 'panel', 'section', 'control' ], function( type ) { var id = api.settings.autofocus[ type ]; if ( ! id ) { @@ -7896,7 +7912,7 @@ api.notifications.render(); }); - // Save and activated states + // Save and activated states. (function( state ) { var saved = state.instance( 'saved' ), saving = state.instance( 'saving' ), @@ -8690,7 +8706,8 @@ }; }()); - // Previewed device bindings. (The api.previewedDevice property is how this Value was first introduced, but since it has moved to api.state.) + // Previewed device bindings. (The api.previewedDevice property + // is how this Value was first introduced, but since it has moved to api.state.) api.previewedDevice = api.state( 'previewedDevice' ); // Set the default device. @@ -8797,7 +8814,7 @@ api.state( 'selectedChangesetStatus' ).unbind( startPromptingBeforeUnload ); api.state( 'selectedChangesetDate' ).unbind( startPromptingBeforeUnload ); - // Prompt user with AYS dialog if leaving the Customizer with unsaved changes + // Prompt user with AYS dialog if leaving the Customizer with unsaved changes. $( window ).on( 'beforeunload.customize-confirm', function() { if ( ! isCleanState() && ! api.state( 'changesetLocked' ).get() ) { setTimeout( function() { @@ -8882,7 +8899,7 @@ }); } ); - // Pass titles to the parent + // Pass titles to the parent. api.bind( 'title', function( newTitle ) { parent.send( 'title', newTitle ); }); @@ -8894,7 +8911,7 @@ // Initialize the connection with the parent frame. parent.send( 'ready' ); - // Control visibility for default controls + // Control visibility for default controls. $.each({ 'background_image': { controls: [ 'background_preset', 'background_position', 'background_size', 'background_repeat', 'background_attachment' ], @@ -8926,7 +8943,7 @@ api.control( 'background_preset', function( control ) { var visibility, defaultValues, values, toggleVisibility, updateSettings, preset; - visibility = { // position, size, repeat, attachment + visibility = { // position, size, repeat, attachment. 'default': [ false, false, false, false ], 'fill': [ true, false, false, false ], 'fit': [ true, false, true, false ], @@ -8942,14 +8959,15 @@ _wpCustomizeBackground.defaults['default-attachment'] ]; - values = { // position_x, position_y, size, repeat, attachment + values = { // position_x, position_y, size, repeat, attachment. 'default': defaultValues, 'fill': [ 'left', 'top', 'cover', 'no-repeat', 'fixed' ], 'fit': [ 'left', 'top', 'contain', 'no-repeat', 'fixed' ], 'repeat': [ 'left', 'top', 'auto', 'repeat', 'scroll' ] }; - // @todo These should actually toggle the active state, but without the preview overriding the state in data.activeControls. + // @todo These should actually toggle the active state, + // but without the preview overriding the state in data.activeControls. toggleVisibility = function( preset ) { _.each( [ 'background_position', 'background_size', 'background_repeat', 'background_attachment' ], function( controlId, i ) { var control = api.control( controlId ); @@ -9009,7 +9027,7 @@ } ); } ); - // Juggle the two controls that use header_textcolor + // Juggle the two controls that use header_textcolor. api.control( 'display_header_text', function( control ) { var last = ''; diff --git a/src/js/_enqueues/wp/customize/loader.js b/src/js/_enqueues/wp/customize/loader.js index e27f1bc9c5..239d36824f 100644 --- a/src/js/_enqueues/wp/customize/loader.js +++ b/src/js/_enqueues/wp/customize/loader.js @@ -119,7 +119,7 @@ window.wp = window.wp || {}; return window.location = src; } - // Store the document title prior to opening the Live Preview + // Store the document title prior to opening the Live Preview. this.originalDocumentTitle = document.title; this.active = true; @@ -170,7 +170,7 @@ window.wp = window.wp || {}; } }); - // Prompt AYS dialog when navigating away + // Prompt AYS dialog when navigating away. $( window ).on( 'beforeunload', this.beforeunload ); this.messenger.bind( 'saved', function () { @@ -223,13 +223,13 @@ window.wp = window.wp || {}; self.active = false; self.trigger( 'close' ); - // Restore document title prior to opening the Live Preview + // Restore document title prior to opening the Live Preview. if ( self.originalDocumentTitle ) { document.title = self.originalDocumentTitle; } } else { - // Go forward since Customizer is exited by history.back() + // Go forward since Customizer is exited by history.back(). history.forward(); } self.messenger.unbind( 'confirmed-close', onConfirmClose ); @@ -286,6 +286,6 @@ window.wp = window.wp || {}; Loader.initialize(); }); - // Expose the API publicly on window.wp.customize.Loader + // Expose the API publicly on window.wp.customize.Loader. api.Loader = Loader; })( wp, jQuery ); diff --git a/src/js/_enqueues/wp/customize/models.js b/src/js/_enqueues/wp/customize/models.js index f11b3d04b8..0a8bca7f47 100644 --- a/src/js/_enqueues/wp/customize/models.js +++ b/src/js/_enqueues/wp/customize/models.js @@ -53,8 +53,8 @@ var data = this.get('header'), curr = api.HeaderTool.currentHeader.get('header').attachment_id; - // If the image we're removing is also the current header, unset - // the latter + // If the image we're removing is also the current header, + // unset the latter. if (curr && data.attachment_id === curr) { api.HeaderTool.currentHeader.trigger('hide'); } @@ -142,7 +142,7 @@ api.HeaderTool.ChoiceList = Backbone.Collection.extend({ model: api.HeaderTool.ImageModel, - // Ordered from most recently used to least + // Ordered from most recently used to least. comparator: function(model) { return -model.get('header').timestamp; }, @@ -151,18 +151,18 @@ var current = api.HeaderTool.currentHeader.get('choice').replace(/^https?:\/\//, ''), isRandom = this.isRandomChoice(api.get().header_image); - // Overridable by an extending class + // Overridable by an extending class. if (!this.type) { this.type = 'uploaded'; } - // Overridable by an extending class + // Overridable by an extending class. if (typeof this.data === 'undefined') { this.data = _wpCustomizeHeader.uploads; } if (isRandom) { - // So that when adding data we don't hide regular images + // So that when adding data we don't hide regular images. current = api.get().header_image; } diff --git a/src/js/_enqueues/wp/customize/nav-menus.js b/src/js/_enqueues/wp/customize/nav-menus.js index 309785d54c..7ca17acbe1 100644 --- a/src/js/_enqueues/wp/customize/nav-menus.js +++ b/src/js/_enqueues/wp/customize/nav-menus.js @@ -203,9 +203,11 @@ _.bindAll( this, 'close' ); - // If the available menu items panel is open and the customize controls are - // interacted with (other than an item being deleted), then close the - // available menu items panel. Also close on back button click. + /* + * If the available menu items panel is open and the customize controls + * are interacted with (other than an item being deleted), then close + * the available menu items panel. Also close on back button click. + */ $( '#customize-controls, .customize-section-back' ).on( 'click keydown', function( e ) { var isDeleteBtn = $( e.target ).is( '.item-delete, .item-delete *' ), isAddNewBtn = $( e.target ).is( '.add-new-menu-item, .add-new-menu-item *' ); @@ -252,7 +254,7 @@ } }); - // Close the panel if the URL in the preview changes + // Close the panel if the URL in the preview changes. api.previewer.bind( 'url', this.close ); self.delegateEvents(); @@ -496,7 +498,7 @@ // Submit handler for keypress and click on menu item. _submit: function( event ) { - // Only proceed with keypress if it is Enter or Spacebar + // Only proceed with keypress if it is Enter or Spacebar. if ( 'keypress' === event.type && ( 13 !== event.which && 32 !== event.which ) ) { return; } @@ -717,7 +719,7 @@ this.$search.focus(); }, - // Closes the panel + // Closes the panel. close: function( options ) { options = options || {}; @@ -741,7 +743,7 @@ isBackTab = ( 9 === event.which && event.shiftKey ), isSearchFocused = $( event.target ).is( this.$search ); - // If enter pressed but nothing entered, don't do anything + // If enter pressed but nothing entered, don't do anything. if ( isEnter && ! this.$search.val() ) { return; } @@ -781,7 +783,7 @@ } event.preventDefault(); - // Hide description + // Hide description. if ( content.not( ':hidden' ) ) { content.slideUp( 'fast' ); help.attr( 'aria-expanded', 'false' ); @@ -802,7 +804,7 @@ return false; } ); - // Help toggle + // Help toggle. help.on( 'click keydown', function( event ) { if ( api.utils.isKeydownButNotEnterEvent( event ) ) { return; @@ -1062,7 +1064,7 @@ menuAutoAddControl.active.set( true ); } - // Add the control for deleting the menu + // Add the control for deleting the menu. menuDeleteControlId = section.id + '[delete]'; menuDeleteControl = api.control( menuDeleteControlId ); if ( ! menuDeleteControl ) { @@ -1126,7 +1128,7 @@ wpNavMenu.menuList = section.contentContainer; wpNavMenu.targetList = wpNavMenu.menuList; - // Add attributes needed by wpNavMenu + // Add attributes needed by wpNavMenu. $( '#menu-to-edit' ).removeAttr( 'id' ); wpNavMenu.menuList.attr( 'id', 'menu-to-edit' ).addClass( 'menu' ); @@ -1145,7 +1147,8 @@ wpNavMenu.initSortables(); // Depends on menu-to-edit ID being set above. section.deferred.initSortables.resolve( wpNavMenu.menuList ); // Now MenuControl can extend the sortable. - // @todo Note that wp.customize.reflowPaneContents() is debounced, so this immediate change will show a slight flicker while priorities get updated. + // @todo Note that wp.customize.reflowPaneContents() is debounced, + // so this immediate change will show a slight flicker while priorities get updated. api.control( 'nav_menu[' + String( section.params.menu_id ) + ']' ).reflowMenuItems(); } if ( _.isFunction( completeCallback ) ) { @@ -1415,7 +1418,7 @@ navMenuLocationSetting = api( 'nav_menu_locations[' + checkbox.data( 'location-id' ) + ']' ); navMenuLocationSetting.set( menuSection.params.menu_id ); - // Reset state for next new menu + // Reset state for next new menu. checkbox.prop( 'checked', false ); } } ); @@ -1698,7 +1701,8 @@ control.elements.classes = new api.Element( control.container.find( '.edit-menu-item-classes' ) ); control.elements.xfn = new api.Element( control.container.find( '.edit-menu-item-xfn' ) ); control.elements.description = new api.Element( control.container.find( '.edit-menu-item-description' ) ); - // @todo allow other elements, added by plugins, to be automatically picked up here; allow additional values to be added to setting array. + // @todo Allow other elements, added by plugins, to be automatically picked up here; + // allow additional values to be added to setting array. _.each( control.elements, function( element, property ) { element.bind(function( value ) { @@ -1790,7 +1794,7 @@ $removeBtn = control.container.find( '.item-delete' ); $removeBtn.on( 'click', function() { - // Find an adjacent element to add focus to when this menu item goes away + // Find an adjacent element to add focus to when this menu item goes away. var addingItems = true, $adjacentFocusTarget, $next, $prev; if ( ! $( 'body' ).hasClass( 'adding-menu-items' ) ) { @@ -1811,7 +1815,7 @@ control.container.slideUp( function() { control.setting.set( false ); wp.a11y.speak( api.Menus.data.l10n.itemDeleted ); - $adjacentFocusTarget.focus(); // keyboard accessibility + $adjacentFocusTarget.focus(); // Keyboard accessibility. } ); control.setting.set( false ); @@ -2778,13 +2782,13 @@ action = sectionTitle.find( '.customize-action' ), name = displayNavMenuName( menu.name ); - // Update the control title + // Update the control title. controlTitle.text( name ); if ( location.length ) { location.appendTo( controlTitle ); } - // Update the section title + // Update the section title. sectionTitle.text( name ); if ( action.length ) { action.prependTo( sectionTitle ); @@ -2981,7 +2985,7 @@ position: position } ); - delete item.id; // only used by Backbone + delete item.id; // Only used by Backbone. placeholderId = api.Menus.generatePlaceholderAutoIncrementId(); customizeId = 'nav_menu_item[' + String( placeholderId ) + ']'; diff --git a/src/js/_enqueues/wp/customize/preview-widgets.js b/src/js/_enqueues/wp/customize/preview-widgets.js index f46456b28f..e00982d963 100644 --- a/src/js/_enqueues/wp/customize/preview-widgets.js +++ b/src/js/_enqueues/wp/customize/preview-widgets.js @@ -672,7 +672,7 @@ wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function( self.preview.send( 'highlight-widget-control', $( this ).prop( 'id' ) ); }); - // Open expand the widget control when shift+clicking the widget element + // Open expand the widget control when shift+clicking the widget element. $( document ).on( 'click', selector, function( e ) { if ( ! e.shiftKey ) { return; diff --git a/src/js/_enqueues/wp/customize/preview.js b/src/js/_enqueues/wp/customize/preview.js index 12c641c080..9e048dd0f6 100644 --- a/src/js/_enqueues/wp/customize/preview.js +++ b/src/js/_enqueues/wp/customize/preview.js @@ -232,8 +232,8 @@ * * @since 4.7.0 * @access protected - * * @access private + * * @return {void} */ api.addLinkPreviewing = function addLinkPreviewing() { @@ -337,7 +337,7 @@ api.prepareLinkPreview = function prepareLinkPreview( element ) { var queryParams, $element = $( element ); - // Skip elements with no href attribute. Check first to avoid more expensive checks down the road + // Skip elements with no href attribute. Check first to avoid more expensive checks down the road. if ( ! element.hasAttribute( 'href' ) ) { return; } @@ -357,7 +357,7 @@ element.protocol = 'https:'; } - // Ignore links with class wp-playlist-caption + // Ignore links with class wp-playlist-caption. if ( $element.hasClass( 'wp-playlist-caption' ) ) { return; } diff --git a/src/js/_enqueues/wp/customize/selective-refresh.js b/src/js/_enqueues/wp/customize/selective-refresh.js index ae9f9ffaf2..9fee9690d0 100644 --- a/src/js/_enqueues/wp/customize/selective-refresh.js +++ b/src/js/_enqueues/wp/customize/selective-refresh.js @@ -442,7 +442,7 @@ wp.customize.selectiveRefresh = ( function( $, api ) { if ( partial.params.containerInclusive ) { - // Note that content may be an empty string, and in this case jQuery will just remove the oldContainer + // Note that content may be an empty string, and in this case jQuery will just remove the oldContainer. newContainerElement = $( content ); // Merge the new context on top of the old context. diff --git a/src/js/_enqueues/wp/customize/widgets.js b/src/js/_enqueues/wp/customize/widgets.js index a2b800db72..8738c13b73 100644 --- a/src/js/_enqueues/wp/customize/widgets.js +++ b/src/js/_enqueues/wp/customize/widgets.js @@ -17,7 +17,7 @@ api.Widgets = api.Widgets || {}; api.Widgets.savedWidgetIds = {}; - // Link settings + // Link settings. api.Widgets.data = _wpCustomizeWidgetsSettings || {}; l10n = api.Widgets.data.l10n; @@ -59,16 +59,16 @@ model: api.Widgets.WidgetModel, // Controls searching on the current widget collection - // and triggers an update event + // and triggers an update event. doSearch: function( value ) { - // Don't do anything if we've already done this search - // Useful because the search handler fires multiple times per keystroke + // Don't do anything if we've already done this search. + // Useful because the search handler fires multiple times per keystroke. if ( this.terms === value ) { return; } - // Updates terms with the value passed + // Updates terms with the value passed. this.terms = value; // If we have terms, run a search... @@ -84,16 +84,16 @@ } }, - // Performs a search within the collection + // Performs a search within the collection. // @uses RegExp search: function( term ) { var match, haystack; - // Escape the term string for RegExp meta characters + // Escape the term string for RegExp meta characters. term = term.replace( /[-\/\\^$*+?.()|[\]{}]/g, '\\$&' ); // Consider spaces as word delimiters and match the whole string - // so matching terms can be combined + // so matching terms can be combined. term = term.replace( / /g, ')(?=.*' ); match = new RegExp( '^(?=.*' + term + ').+', 'i' ); @@ -150,10 +150,10 @@ 'keydown' : 'keyboardAccessible' }, - // Cache current selected widget + // Cache current selected widget. selected: null, - // Cache sidebar control which has opened panel + // Cache sidebar control which has opened panel. currentSidebarControl: null, $search: null, $clearResults: null, @@ -181,9 +181,11 @@ // Set the initial search count to the number of available widgets. this.searchMatchesCount = this.collection.length; - // If the available widgets panel is open and the customize controls are - // interacted with (i.e. available widgets panel is blurred) then close the - // available widgets panel. Also close on back button click. + /* + * If the available widgets panel is open and the customize controls + * are interacted with (i.e. available widgets panel is blurred) then + * close the available widgets panel. Also close on back button click. + */ $( '#customize-controls, #available-widgets .customize-section-title' ).on( 'click keydown', function( e ) { var isAddNewBtn = $( e.target ).is( '.add-new-widget, .add-new-widget *' ); if ( $( 'body' ).hasClass( 'adding-widget' ) && ! isAddNewBtn ) { @@ -197,7 +199,7 @@ self.collection.doSearch( '' ); } ); - // Close the panel if the URL in the preview changes + // Close the panel if the URL in the preview changes. api.previewer.bind( 'url', this.close ); }, @@ -213,19 +215,19 @@ // Announce how many search results. this.announceSearchMatches(); - // Remove a widget from being selected if it is no longer visible + // Remove a widget from being selected if it is no longer visible. if ( this.selected && ! this.selected.is( ':visible' ) ) { this.selected.removeClass( 'selected' ); this.selected = null; } - // If a widget was selected but the filter value has been cleared out, clear selection + // If a widget was selected but the filter value has been cleared out, clear selection. if ( this.selected && ! event.target.value ) { this.selected.removeClass( 'selected' ); this.selected = null; } - // If a filter has been entered and a widget hasn't been selected, select the first one shown + // If a filter has been entered and a widget hasn't been selected, select the first one shown. if ( ! this.selected && event.target.value ) { firstVisible = this.$el.find( '> .widget-tpl:visible:first' ); if ( firstVisible.length ) { @@ -301,7 +303,7 @@ * Handles submit for keypress and click on widget. */ _submit: function( event ) { - // Only proceed with keypress if it is Enter or Spacebar + // Only proceed with keypress if it is Enter or Spacebar. if ( event.type === 'keypress' && ( event.which !== 13 && event.which !== 32 ) ) { return; } @@ -345,7 +347,7 @@ open: function( sidebarControl ) { this.currentSidebarControl = sidebarControl; - // Wide widget controls appear over the preview, and so they need to be collapsed when the panel opens + // Wide widget controls appear over the preview, and so they need to be collapsed when the panel opens. _( this.currentSidebarControl.getWidgetFormControls() ).each( function( control ) { if ( control.params.is_wide ) { control.collapseForm(); @@ -360,7 +362,7 @@ this.$el.find( '.selected' ).removeClass( 'selected' ); - // Reset search + // Reset search. this.collection.doSearch( '' ); if ( ! api.settings.browser.mobile ) { @@ -428,7 +430,7 @@ return; } - // If enter pressed but nothing entered, don't do anything + // If enter pressed but nothing entered, don't do anything. if ( isEnter && ! this.$search.val() ) { return; } @@ -602,7 +604,7 @@ _setupModel: function() { var self = this, rememberSavedWidgetId; - // Remember saved widgets so we know which to trash (move to inactive widgets sidebar) + // Remember saved widgets so we know which to trash (move to inactive widgets sidebar). rememberSavedWidgetId = function() { api.Widgets.savedWidgetIds[self.params.widget_id] = true; }; @@ -613,7 +615,7 @@ this.isWidgetUpdating = false; this.liveUpdateMode = true; - // Update widget whenever model changes + // Update widget whenever model changes. this.setting.bind( function( to, from ) { if ( ! _( from ).isEqual( to ) && ! self.isWidgetUpdating ) { self.updateWidget( { instance: to } ); @@ -658,10 +660,10 @@ top; $widgetInside.css( 'max-height', windowHeight ); top = Math.max( - 0, // prevent top from going off screen + 0, // Prevent top from going off screen. Math.min( - Math.max( offsetTop, 0 ), // distance widget in panel is from top of screen - windowHeight - formHeight // flush up against bottom of screen + Math.max( offsetTop, 0 ), // Distance widget in panel is from top of screen. + windowHeight - formHeight // Flush up against bottom of screen. ) ); $widgetInside.css( 'top', top ); @@ -680,7 +682,7 @@ $themeControlsContainer.off( 'expanded collapsed', positionWidget ); } ); - // Reposition whenever a sidebar's widgets are changed + // Reposition whenever a sidebar's widgets are changed. api.each( function( setting ) { if ( 0 === setting.id.indexOf( 'sidebars_widgets[' ) ) { setting.bind( function() { @@ -711,7 +713,7 @@ $closeBtn = this.container.find( '.widget-control-close' ); $closeBtn.on( 'click', function() { self.collapse(); - self.container.find( '.widget-top .widget-action:first' ).focus(); // keyboard accessibility + self.container.find( '.widget-top .widget-action:first' ).focus(); // Keyboard accessibility. } ); }, @@ -838,7 +840,7 @@ wp.a11y.speak( l10n.widgetMovedDown ); } - $( this ).focus(); // re-focus after the container was moved + $( this ).focus(); // Re-focus after the container was moved. } } ); @@ -886,12 +888,12 @@ _setupHighlightEffects: function() { var self = this; - // Highlight whenever hovering or clicking over the form + // Highlight whenever hovering or clicking over the form. this.container.on( 'mouseenter click', function() { self.setting.previewer.send( 'highlight-widget', self.params.widget_id ); } ); - // Highlight when the setting is updated + // Highlight when the setting is updated. this.setting.bind( function() { self.setting.previewer.send( 'highlight-widget', self.params.widget_id ); } ); @@ -907,7 +909,7 @@ $widgetRoot = this.container.find( '.widget:first' ); $widgetContent = $widgetRoot.find( '.widget-content:first' ); - // Configure update button + // Configure update button. $saveBtn = this.container.find( '.widget-control-save' ); $saveBtn.val( l10n.saveBtnLabel ); $saveBtn.attr( 'title', l10n.saveBtnTooltip ); @@ -921,15 +923,15 @@ self.updateWidget(); }, 250 ); - // Trigger widget form update when hitting Enter within an input + // Trigger widget form update when hitting Enter within an input. $widgetContent.on( 'keydown', 'input', function( e ) { - if ( 13 === e.which ) { // Enter + if ( 13 === e.which ) { // Enter. e.preventDefault(); self.updateWidget( { ignoreActiveElement: true } ); } } ); - // Handle widgets that support live previews + // Handle widgets that support live previews. $widgetContent.on( 'change input propertychange', ':input', function( e ) { if ( ! self.liveUpdateMode ) { return; @@ -939,7 +941,7 @@ } } ); - // Remove loading indicators when the setting is saved and the preview updates + // Remove loading indicators when the setting is saved and the preview updates. this.setting.previewer.channel.bind( 'synced', function() { self.container.removeClass( 'previewer-loading' ); } ); @@ -972,7 +974,7 @@ * @param {function} args.completeCallback */ onChangeActive: function ( active, args ) { - // Note: there is a second 'args' parameter being passed, merged on top of this.defaultActiveArguments + // Note: there is a second 'args' parameter being passed, merged on top of this.defaultActiveArguments. this.container.toggleClass( 'widget-rendered', active ); if ( args.completeCallback ) { args.completeCallback(); @@ -985,10 +987,10 @@ _setupRemoveUI: function() { var self = this, $removeBtn, replaceDeleteWithRemove; - // Configure remove button + // Configure remove button. $removeBtn = this.container.find( '.widget-control-remove' ); $removeBtn.on( 'click', function() { - // Find an adjacent element to add focus to when this widget goes away + // Find an adjacent element to add focus to when this widget goes away. var $adjacentFocusTarget; if ( self.container.next().is( '.customize-control-widget_form' ) ) { $adjacentFocusTarget = self.container.next().find( '.widget-action:first' ); @@ -1015,12 +1017,12 @@ sidebarWidgetIds.splice( i, 1 ); sidebarsWidgetsControl.setting( sidebarWidgetIds ); - $adjacentFocusTarget.focus(); // keyboard accessibility + $adjacentFocusTarget.focus(); // Keyboard accessibility. } ); } ); replaceDeleteWithRemove = function() { - $removeBtn.text( l10n.removeBtnLabel ); // wp_widget_control() outputs the button as "Delete" + $removeBtn.text( l10n.removeBtnLabel ); // wp_widget_control() outputs the button as "Delete". $removeBtn.attr( 'title', l10n.removeBtnTooltip ); }; @@ -1105,7 +1107,7 @@ if ( ! $.isArray( state ) ) { state = []; } else { - // Make sure all state items are strings since the DOM value is a string + // Make sure all state items are strings since the DOM value is a string. state = _.map( state, function ( value ) { return String( value ); } ); @@ -1169,7 +1171,7 @@ $widgetRoot = this.container.find( '.widget:first' ); $widgetContent = $widgetRoot.find( '.widget-content:first' ); - // Remove a previous error message + // Remove a previous error message. $widgetContent.find( '.widget-error' ).remove(); this.container.addClass( 'widget-form-loading' ); @@ -1191,9 +1193,11 @@ data = $.param( params ); $inputs = this._getInputs( $widgetContent ); - // Store the value we're submitting in data so that when the response comes back, - // we know if it got sanitized; if there is no difference in the sanitized value, - // then we do not need to touch the UI and mess up the user's ongoing editing. + /* + * Store the value we're submitting in data so that when the response comes back, + * we know if it got sanitized; if there is no difference in the sanitized value, + * then we do not need to touch the UI and mess up the user's ongoing editing. + */ $inputs.each( function() { $( this ).data( 'state' + updateNumber, self._getInputState( this ) ); } ); @@ -1236,14 +1240,14 @@ $sanitizedInputs = self._getInputs( sanitizedForm ); hasSameInputsInResponse = self._getInputsSignature( $inputs ) === self._getInputsSignature( $sanitizedInputs ); - // Restore live update mode if sanitized fields are now aligned with the existing fields + // Restore live update mode if sanitized fields are now aligned with the existing fields. if ( hasSameInputsInResponse && ! self.liveUpdateMode ) { self.liveUpdateMode = true; self.container.removeClass( 'widget-form-disabled' ); self.container.find( 'input[name="savewidget"]' ).hide(); } - // Sync sanitized field states to existing fields if they are aligned + // Sync sanitized field states to existing fields if they are aligned. if ( hasSameInputsInResponse && self.liveUpdateMode ) { $inputs.each( function( i ) { var $input = $( this ), @@ -1262,13 +1266,13 @@ $( document ).trigger( 'widget-synced', [ $widgetRoot, r.data.form ] ); - // Otherwise, if sanitized fields are not aligned with existing fields, disable live update mode if enabled + // Otherwise, if sanitized fields are not aligned with existing fields, disable live update mode if enabled. } else if ( self.liveUpdateMode ) { self.liveUpdateMode = false; self.container.find( 'input[name="savewidget"]' ).show(); isLiveUpdateAborted = true; - // Otherwise, replace existing form with the sanitized form + // Otherwise, replace existing form with the sanitized form. } else { $widgetContent.html( r.data.form ); @@ -1284,11 +1288,11 @@ */ isChanged = ! isLiveUpdateAborted && ! _( self.setting() ).isEqual( r.data.instance ); if ( isChanged ) { - self.isWidgetUpdating = true; // suppress triggering another updateWidget + self.isWidgetUpdating = true; // Suppress triggering another updateWidget. self.setting( r.data.instance ); self.isWidgetUpdating = false; } else { - // no change was made, so stop the spinner now instead of when the preview would updates + // No change was made, so stop the spinner now instead of when the preview would updates. self.container.removeClass( 'previewer-loading' ); } @@ -1296,7 +1300,7 @@ completeCallback.call( self, null, { noChange: ! isChanged, ajaxFinished: true } ); } } else { - // General error message + // General error message. message = l10n.error; if ( r.data && r.data.message ) { @@ -1406,7 +1410,7 @@ self.embedWidgetContent(); } - // If the expanded state is unchanged only manipulate container expanded states + // If the expanded state is unchanged only manipulate container expanded states. if ( args.unchanged ) { if ( expanded ) { api.Control.prototype.expand.call( self, { @@ -1422,7 +1426,7 @@ expandControl = function() { - // Close all other widget controls before expanding this one + // Close all other widget controls before expanding this one. api.control.each( function( otherControl ) { if ( self.params.type === otherControl.params.type && self !== otherControl ) { otherControl.collapse(); @@ -1535,7 +1539,7 @@ i = this.getWidgetSidebarPosition(); sidebarWidgetsSetting = this.getSidebarWidgetsControl().setting; - sidebarWidgetIds = Array.prototype.slice.call( sidebarWidgetsSetting() ); // clone + sidebarWidgetIds = Array.prototype.slice.call( sidebarWidgetsSetting() ); // Clone. adjacentWidgetId = sidebarWidgetIds[i + offset]; sidebarWidgetIds[i + offset] = this.params.widget_id; sidebarWidgetIds[i] = adjacentWidgetId; @@ -1558,7 +1562,7 @@ } if ( showOrHide ) { - // reset the selected sidebar + // Reset the selected sidebar. $moveWidgetArea.find( '.selected' ).removeClass( 'selected' ); $moveWidgetArea.find( 'li' ).filter( function() { @@ -1781,7 +1785,7 @@ removedWidgetIds = _( oldWidgetIds ).difference( newWidgetIds ); - // Filter out any persistent widget IDs for widgets which have been deactivated + // Filter out any persistent widget IDs for widgets which have been deactivated. newWidgetIds = _( newWidgetIds ).filter( function( newWidgetId ) { var parsedWidgetId = parseWidgetId( newWidgetId ); @@ -1798,7 +1802,7 @@ return widgetFormControl; } ); - // Sort widget controls to their new positions + // Sort widget controls to their new positions. widgetFormControls.sort( function( a, b ) { var aIndex = _.indexOf( newWidgetIds, a.params.widget_id ), bIndex = _.indexOf( newWidgetIds, b.params.widget_id ); @@ -1811,25 +1815,26 @@ control.section( self.section() ); priority += 1; }); - self.priority( priority ); // Make sure sidebar control remains at end + self.priority( priority ); // Make sure sidebar control remains at end. - // Re-sort widget form controls (including widgets form other sidebars newly moved here) + // Re-sort widget form controls (including widgets form other sidebars newly moved here). self._applyCardinalOrderClassNames(); - // If the widget was dragged into the sidebar, make sure the sidebar_id param is updated + // If the widget was dragged into the sidebar, make sure the sidebar_id param is updated. _( widgetFormControls ).each( function( widgetFormControl ) { widgetFormControl.params.sidebar_id = self.params.sidebar_id; } ); - // Cleanup after widget removal + // Cleanup after widget removal. _( removedWidgetIds ).each( function( removedWidgetId ) { - // Using setTimeout so that when moving a widget to another sidebar, the other sidebars_widgets settings get a chance to update + // Using setTimeout so that when moving a widget to another sidebar, + // the other sidebars_widgets settings get a chance to update. setTimeout( function() { var removedControl, wasDraggedToAnotherSidebar, inactiveWidgets, removedIdBase, widget, isPresentInAnotherSidebar = false; - // Check if the widget is in another sidebar + // Check if the widget is in another sidebar. api.each( function( otherSetting ) { if ( otherSetting.id === self.setting.id || 0 !== otherSetting.id.indexOf( 'sidebars_widgets[' ) || otherSetting.id === 'sidebars_widgets[wp_inactive_widgets]' ) { return; @@ -1850,24 +1855,24 @@ removedControl = api.Widgets.getWidgetFormControlForWidget( removedWidgetId ); - // Detect if widget control was dragged to another sidebar + // Detect if widget control was dragged to another sidebar. wasDraggedToAnotherSidebar = removedControl && $.contains( document, removedControl.container[0] ) && ! $.contains( self.$sectionContent[0], removedControl.container[0] ); - // Delete any widget form controls for removed widgets + // Delete any widget form controls for removed widgets. if ( removedControl && ! wasDraggedToAnotherSidebar ) { api.control.remove( removedControl.id ); removedControl.container.remove(); } - // Move widget to inactive widgets sidebar (move it to trash) if has been previously saved - // This prevents the inactive widgets sidebar from overflowing with throwaway widgets + // Move widget to inactive widgets sidebar (move it to trash) if has been previously saved. + // This prevents the inactive widgets sidebar from overflowing with throwaway widgets. if ( api.Widgets.savedWidgetIds[removedWidgetId] ) { inactiveWidgets = api.value( 'sidebars_widgets[wp_inactive_widgets]' )().slice(); inactiveWidgets.push( removedWidgetId ); api.value( 'sidebars_widgets[wp_inactive_widgets]' )( _( inactiveWidgets ).unique() ); } - // Make old single widget available for adding again + // Make old single widget available for adding again. removedIdBase = parseWidgetId( removedWidgetId ).id_base; widget = api.Widgets.availableWidgets.findWhere( { id_base: removedIdBase } ); if ( widget && ! widget.get( 'is_multi' ) ) { @@ -1916,9 +1921,9 @@ over: function() { var section = api.section( self.section.get() ); section.expand({ - allowMultiple: true, // Prevent the section being dragged from to be collapsed + allowMultiple: true, // Prevent the section being dragged from to be collapsed. completeCallback: function () { - // @todo It is not clear when refreshPositions should be called on which sections, or if it is even needed + // @todo It is not clear when refreshPositions should be called on which sections, or if it is even needed. api.section.each( function ( otherSection ) { if ( otherSection.container.find( '.customize-control-sidebar_widgets' ).length ) { otherSection.container.find( '.accordion-section-content:first' ).sortable( 'refreshPositions' ); @@ -2079,7 +2084,7 @@ return false; } - // Set up new multi widget + // Set up new multi widget. if ( widget.get( 'is_multi' ) && ! widgetNumber ) { widget.set( 'multi_number', widget.get( 'multi_number' ) + 1 ); widgetNumber = widget.get( 'multi_number' ); @@ -2091,7 +2096,7 @@ return m.replace( /__i__|%i%/g, widgetNumber ); } ); } else { - widget.set( 'is_disabled', true ); // Prevent single widget from being added again now + widget.set( 'is_disabled', true ); // Prevent single widget from being added again now. } $widget = $( controlHtml ); @@ -2101,7 +2106,7 @@ .addClass( 'customize-control-' + controlType ) .append( $widget ); - // Remove icon which is visible inside the panel + // Remove icon which is visible inside the panel. controlContainer.find( '> .widget-icon' ).remove(); if ( widget.get( 'is_multi' ) ) { @@ -2111,7 +2116,7 @@ widgetId = controlContainer.find( '[name="widget-id"]' ).val(); - controlContainer.hide(); // to be slid-down below + controlContainer.hide(); // To be slid-down below. settingId = 'widget_' + widget.get( 'id_base' ); if ( widget.get( 'is_multi' ) ) { @@ -2119,7 +2124,7 @@ } controlContainer.attr( 'id', 'customize-control-' + settingId.replace( /\]/g, '' ).replace( /\[/g, '-' ) ); - // Only create setting if it doesn't already exist (if we're adding a pre-existing inactive widget) + // Only create setting if it doesn't already exist (if we're adding a pre-existing inactive widget). isExistingWidget = api.has( settingId ); if ( ! isExistingWidget ) { settingArgs = { @@ -2127,7 +2132,7 @@ previewer: this.setting.previewer }; setting = api.create( settingId, settingId, '', settingArgs ); - setting.set( {} ); // mark dirty, changing from '' to {} + setting.set( {} ); // Mark dirty, changing from '' to {}. } controlConstructor = api.controlConstructor[controlType]; @@ -2147,7 +2152,7 @@ } ); api.control.add( widgetFormControl ); - // Make sure widget is removed from the other sidebars + // Make sure widget is removed from the other sidebars. api.each( function( otherSetting ) { if ( otherSetting.id === self.setting.id ) { return; @@ -2166,7 +2171,7 @@ } } ); - // Add widget to this sidebar + // Add widget to this sidebar. sidebarWidgets = this.setting().slice(); if ( -1 === _.indexOf( sidebarWidgets, widgetId ) ) { sidebarWidgets.push( widgetId ); @@ -2185,7 +2190,7 @@ } } ); - // Register models for custom panel, section, and control types + // Register models for custom panel, section, and control types. $.extend( api.panelConstructor, { widgets: api.Widgets.WidgetsPanel }); @@ -2201,15 +2206,15 @@ * Init Customizer for widgets. */ api.bind( 'ready', function() { - // Set up the widgets panel + // Set up the widgets panel. api.Widgets.availableWidgetsPanel = new api.Widgets.AvailableWidgetsPanelView({ collection: api.Widgets.availableWidgets }); - // Highlight widget control + // Highlight widget control. api.previewer.bind( 'highlight-widget-control', api.Widgets.highlightWidgetFormControl ); - // Open and focus widget control + // Open and focus widget control. api.previewer.bind( 'focus-widget-control', api.Widgets.focusWidgetFormControl ); } ); @@ -2247,7 +2252,7 @@ api.Widgets.getSidebarWidgetControlContainingWidget = function( widgetId ) { var foundControl = null; - // @todo this can use widgetIdToSettingId(), then pass into wp.customize.control( x ).getSidebarWidgetsControl() + // @todo This can use widgetIdToSettingId(), then pass into wp.customize.control( x ).getSidebarWidgetsControl(). api.control.each( function( control ) { if ( control.params.type === 'sidebar_widgets' && -1 !== _.indexOf( control.setting(), widgetId ) ) { foundControl = control; @@ -2266,7 +2271,7 @@ api.Widgets.getWidgetFormControlForWidget = function( widgetId ) { var foundControl = null; - // @todo We can just use widgetIdToSettingId() here + // @todo We can just use widgetIdToSettingId() here. api.control.each( function( control ) { if ( control.params.type === 'widget_form' && control.params.widget_id === widgetId ) { foundControl = control; @@ -2343,7 +2348,7 @@ parsed.id_base = matches[1]; parsed.number = parseInt( matches[2], 10 ); } else { - // likely an old single widget + // Likely an old single widget. parsed.id_base = widgetId; } diff --git a/src/js/_enqueues/wp/editor/base.js b/src/js/_enqueues/wp/editor/base.js index 6159467b9c..602fad7355 100644 --- a/src/js/_enqueues/wp/editor/base.js +++ b/src/js/_enqueues/wp/editor/base.js @@ -112,7 +112,7 @@ window.wp = window.wp || {}; } if ( keepSelection ) { - // Save the selection + // Save the selection. addHTMLBookmarkInTextAreaContent( $textarea ); } @@ -131,7 +131,7 @@ window.wp = window.wp || {}; } if ( editor.getParam( 'wp_keep_scroll_position' ) ) { - // Restore the selection + // Restore the selection. focusHTMLBookmarkInVisualEditor( editor ); } } else { @@ -149,7 +149,8 @@ window.wp = window.wp || {}; } if ( editor ) { - // Don't resize the textarea in iOS. The iframe is forced to 100% height there, we shouldn't match it. + // Don't resize the textarea in iOS. + // The iframe is forced to 100% height there, we shouldn't match it. if ( ! tinymce.Env.iOS ) { iframe = editor.iframeElement; editorHeight = iframe ? parseInt( iframe.style.height, 10 ) : 0; @@ -177,7 +178,8 @@ window.wp = window.wp || {}; selectTextInTextArea( editor, selectionRange ); } } else { - // There is probably a JS error on the page. The TinyMCE editor instance doesn't exist. Show the textarea. + // There is probably a JS error on the page. + // The TinyMCE editor instance doesn't exist. Show the textarea. $textarea.css({ 'display': '', 'visibility': '' }); } @@ -209,7 +211,7 @@ window.wp = window.wp || {}; lastGtPos = content.lastIndexOf( '>', cursorPosition ); if ( lastLtPos > lastGtPos || content.substr( cursorPosition, 1 ) === '>' ) { - // find what the tag is + // Find what the tag is. var tagContent = content.substr( lastLtPos ), tagMatch = tagContent.match( /<\s*(\/)?(\w+|\!-{2}.*-{2})/ ); @@ -222,7 +224,7 @@ window.wp = window.wp || {}; return { ltPos: lastLtPos, - gtPos: lastLtPos + closingGt + 1, // offset by one to get the position _after_ the character, + gtPos: lastLtPos + closingGt + 1, // Offset by one to get the position _after_ the character. tagType: tagType, isClosingTag: !! tagMatch[1] }; @@ -248,7 +250,7 @@ window.wp = window.wp || {}; * @param {number} cursorPosition The cursor position to check. * * @return {(undefined|Object)} Undefined if the cursor is not wrapped in a shortcode tag. - * Information about the wrapping shortcode tag if it's wrapped in one. + * Information about the wrapping shortcode tag if it's wrapped in one. */ function getShortcodeWrapperInfo( content, cursorPosition ) { var contentShortcodes = getShortCodePositionsInText( content ); @@ -403,7 +405,7 @@ window.wp = window.wp || {}; var cursorStart = cursorPositions.cursorStart, cursorEnd = cursorPositions.cursorEnd, - // check if the cursor is in a tag and if so, adjust it + // Check if the cursor is in a tag and if so, adjust it. isCursorStartInTag = getContainingTagInfo( content, cursorStart ); if ( isCursorStartInTag ) { @@ -506,11 +508,11 @@ window.wp = window.wp || {}; } textArea.value = [ - textArea.value.slice( 0, htmlModeCursorStartPosition ), // text until the cursor/selection position - cursorMarkerSkeleton.clone() // cursor/selection start marker + textArea.value.slice( 0, htmlModeCursorStartPosition ), // Text until the cursor/selection position. + cursorMarkerSkeleton.clone() // Cursor/selection start marker. .addClass( 'mce_SELRES_start' )[0].outerHTML, - selectedText, // selected text with end cursor/position marker - textArea.value.slice( htmlModeCursorEndPosition ) // text from last cursor/selection position to end + selectedText, // Selected text with end cursor/position marker. + textArea.value.slice( htmlModeCursorEndPosition ) // Text from last cursor/selection position to end. ].join( '' ); } @@ -804,7 +806,7 @@ window.wp = window.wp || {}; endMatchIndex -= endMatch[1].length; } - // We need to adjust the end position to discard the length of the range start marker + // We need to adjust the end position to discard the length of the range start marker. endIndex = endMatchIndex - startMatchLength; } @@ -826,7 +828,7 @@ window.wp = window.wp || {}; * @param {Object} selection Selection data. */ function selectTextInTextArea( editor, selection ) { - // only valid in the text area mode and if we have selection + // Only valid in the text area mode and if we have selection. if ( ! selection ) { return; } @@ -836,11 +838,11 @@ window.wp = window.wp || {}; end = selection.end || selection.start; if ( textArea.focus ) { - // Wait for the Visual editor to be hidden, then focus and scroll to the position + // Wait for the Visual editor to be hidden, then focus and scroll to the position. setTimeout( function() { textArea.setSelectionRange( start, end ); if ( textArea.blur ) { - // defocus before focusing + // Defocus before focusing. textArea.blur(); } textArea.focus(); @@ -1249,7 +1251,7 @@ window.wp = window.wp || {}; defaults = wp.editor.getDefaultSettings(); - // Initialize TinyMCE by default + // Initialize TinyMCE by default. if ( ! settings ) { settings = { tinymce: true diff --git a/src/js/_enqueues/wp/editor/dfw.js b/src/js/_enqueues/wp/editor/dfw.js index 53ec6f594e..2fc580c1fe 100644 --- a/src/js/_enqueues/wp/editor/dfw.js +++ b/src/js/_enqueues/wp/editor/dfw.js @@ -246,10 +246,11 @@ function mceKeyup( event ) { var key = event.keyCode; - // Bail on special keys. Key code 47 is a / + // Bail on special keys. Key code 47 is a '/'. if ( key <= 47 && ! ( key === VK.SPACEBAR || key === VK.ENTER || key === VK.DELETE || key === VK.BACKSPACE || key === VK.UP || key === VK.LEFT || key === VK.DOWN || key === VK.UP ) ) { return; - // OS keys, function keys, num lock, scroll lock. Key code 91-93 are OS keys. Key code 112-123 are F1 to F12. Key code 144 is num lock. Key code 145 is scroll lock. + // OS keys, function keys, num lock, scroll lock. Key code 91-93 are OS keys. + // Key code 112-123 are F1 to F12. Key code 144 is num lock. Key code 145 is scroll lock. } else if ( ( key >= 91 && key <= 93 ) || ( key >= 112 && key <= 123 ) || key === 144 || key === 145 ) { return; } @@ -516,7 +517,7 @@ * If in visual mode, checks if the editorHeight is greater than the autoresizeMinHeight + topHeight. * If not in visual mode, checks if the editorHeight is greater than the autoresizeMinHeight + 20. */ - canPin = visual ? autoresizeMinHeight + topHeight : autoresizeMinHeight + 20; // 20px from textarea padding + canPin = visual ? autoresizeMinHeight + topHeight : autoresizeMinHeight + 20; // 20px from textarea padding. canPin = editorHeight > ( canPin + 5 ); if ( ! canPin ) { @@ -910,7 +911,7 @@ // Adjust when entering or exiting fullscreen mode. fullscreen && fullscreen.pubsub.unsubscribe( 'hidden', fullscreenHide ); - // Reset all css + // Reset all CSS. $.each( [ $visualTop, $textTop, $tools, $menuBar, $bottom, $statusBar, $contentWrap, $visualEditor, $textEditor, $sideSortables ], function( i, element ) { element && element.attr( 'style', '' ); }); @@ -1179,15 +1180,15 @@ // Return if any of the following keys or combinations of keys is pressed. if ( event && ( event.metaKey || ( event.ctrlKey && ! event.altKey ) || ( event.altKey && event.shiftKey ) || ( key && ( - // Special keys ( tab, ctrl, alt, esc, arrow keys... ) + // Special keys ( tab, ctrl, alt, esc, arrow keys... ). ( key <= 47 && key !== 8 && key !== 13 && key !== 32 && key !== 46 ) || - // Windows keys + // Windows keys. ( key >= 91 && key <= 93 ) || - // F keys + // F keys. ( key >= 112 && key <= 135 ) || - // Num Lock, Scroll Lock, OEM + // Num Lock, Scroll Lock, OEM. ( key >= 144 && key <= 150 ) || - // OEM or non-printable + // OEM or non-printable. key >= 224 ) ) ) ) { return; diff --git a/src/js/_enqueues/wp/emoji.js b/src/js/_enqueues/wp/emoji.js index 27882d1e27..c737bb17bf 100644 --- a/src/js/_enqueues/wp/emoji.js +++ b/src/js/_enqueues/wp/emoji.js @@ -9,8 +9,8 @@ /** * Replaces emoji with images when browsers don't support emoji. * - * @since 4.2.0 - * @access private + * @since 4.2.0 + * @access private * * @class * @@ -22,10 +22,10 @@ function wpEmoji() { var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver, - // Compression and maintain local scope + // Compression and maintain local scope. document = window.document, - // Private + // Private. twemoji, timer, loaded = false, count = 0, @@ -69,7 +69,7 @@ // Ensure twemoji is available on the global window before proceeding. if ( typeof window.twemoji === 'undefined' ) { - // Break if waiting for longer than 30 sec. + // Break if waiting for longer than 30 seconds. if ( count > 600 ) { return; } @@ -245,8 +245,8 @@ } if ( settings.supports.everythingExceptFlag && - ! /^1f1(?:e[6-9a-f]|f[0-9a-f])-1f1(?:e[6-9a-f]|f[0-9a-f])$/.test( icon ) && // Country flags - ! /^(1f3f3-fe0f-200d-1f308|1f3f4-200d-2620-fe0f)$/.test( icon ) // Rainbow and pirate flags + ! /^1f1(?:e[6-9a-f]|f[0-9a-f])-1f1(?:e[6-9a-f]|f[0-9a-f])$/.test( icon ) && // Country flags. + ! /^(1f3f3-fe0f-200d-1f308|1f3f4-200d-2620-fe0f)$/.test( icon ) // Rainbow and pirate flags. ) { return false; } diff --git a/src/js/_enqueues/wp/heartbeat.js b/src/js/_enqueues/wp/heartbeat.js index 98cba71c54..f55d2f87ca 100644 --- a/src/js/_enqueues/wp/heartbeat.js +++ b/src/js/_enqueues/wp/heartbeat.js @@ -62,7 +62,7 @@ // Connect interval (in seconds). mainInterval: 60, - // Used when the interval is set to 5 sec. temporarily. + // Used when the interval is set to 5 seconds temporarily. tempInterval: 0, // Used when the interval is reset. @@ -89,7 +89,7 @@ // Whether the current browser window is in focus and the user is active. hasFocus: true, - // Timestamp, last time the user was active. Checked every 30 sec. + // Timestamp, last time the user was active. Checked every 30 seconds. userActivity: 0, // Flag whether events tracking user activity were set. @@ -106,9 +106,8 @@ /** * Sets local variables and events, then starts the heartbeat. * - * @access private - * * @since 3.8.0 + * @access private * * @return {void} */ @@ -133,9 +132,8 @@ } /* - * The interval can be from 15 to 120 sec. and can be set temporarily to 5 sec. - * It can be set in the initial options or changed later through JS and/or - * through PHP. + * The interval can be from 15 to 120 seconds and can be set temporarily to 5 seconds. + * It can be set in the initial options or changed later through JS and/or through PHP. */ if ( options.interval ) { settings.mainInterval = options.interval; @@ -148,12 +146,12 @@ } /* - * Used to limit the number of AJAX requests. Overrides all other intervals if - * they are shorter. Needed for some hosts that cannot handle frequent requests - * and the user may exceed the allocated server CPU time, etc. The minimal - * interval can be up to 600 sec. however setting it to longer than 120 sec. - * will limit or disable some of the functionality (like post locks). Once set - * at initialization, minimalInterval cannot be changed/overridden. + * Used to limit the number of AJAX requests. Overrides all other intervals + * if they are shorter. Needed for some hosts that cannot handle frequent requests + * and the user may exceed the allocated server CPU time, etc. The minimal interval + * can be up to 600 seconds, however setting it to longer than 120 seconds + * will limit or disable some of the functionality (like post locks). + * Once set at initialization, minimalInterval cannot be changed/overridden. */ if ( options.minimalInterval ) { options.minimalInterval = parseInt( options.minimalInterval, 10 ); @@ -189,11 +187,11 @@ hidden = 'hidden'; visibilitychange = 'visibilitychange'; visibilityState = 'visibilityState'; - } else if ( typeof document.msHidden !== 'undefined' ) { // IE10 + } else if ( typeof document.msHidden !== 'undefined' ) { // IE10. hidden = 'msHidden'; visibilitychange = 'msvisibilitychange'; visibilityState = 'msVisibilityState'; - } else if ( typeof document.webkitHidden !== 'undefined' ) { // Android + } else if ( typeof document.webkitHidden !== 'undefined' ) { // Android. hidden = 'webkitHidden'; visibilitychange = 'webkitvisibilitychange'; visibilityState = 'webkitVisibilityState'; @@ -245,9 +243,8 @@ /** * Returns the current time according to the browser. * - * @access private - * * @since 3.6.0 + * @access private * * @return {number} Returns the current time. */ @@ -258,9 +255,8 @@ /** * Checks if the iframe is from the same origin. * - * @access private - * * @since 3.6.0 + * @access private * * @return {boolean} Returns whether or not the iframe is from the same origin. */ @@ -291,9 +287,8 @@ /** * Checks if the document's focus has changed. * - * @access private - * * @since 4.1.0 + * @access private * * @return {void} */ @@ -308,9 +303,8 @@ /** * Sets error state and fires an event on XHR errors or timeout. * - * @access private - * * @since 3.8.0 + * @access private * * @param {string} error The error type passed from the XHR. * @param {number} status The HTTP status code passed from jqXHR @@ -327,7 +321,7 @@ // Do nothing. break; case 'timeout': - // No response for 30 sec. + // No response for 30 seconds. trigger = true; break; case 'error': @@ -359,9 +353,8 @@ /** * Clears the error state and fires an event if there is a connection error. * - * @access private - * * @since 3.8.0 + * @access private * * @return {void} */ @@ -380,9 +373,8 @@ /** * Gathers the data and connects to the server. * - * @access private - * * @since 3.6.0 + * @access private * * @return {void} */ @@ -421,7 +413,7 @@ settings.xhr = $.ajax({ url: settings.url, type: 'post', - timeout: 30000, // throw an error if not completed after 30 sec. + timeout: 30000, // Throw an error if not completed after 30 seconds. data: ajaxData, dataType: 'json' }).always( function() { @@ -442,7 +434,7 @@ wp.hooks.doAction( 'heartbeat.nonces-expired' ); } - // Change the interval from PHP + // Change the interval from PHP. if ( response.heartbeat_interval ) { newInterval = response.heartbeat_interval; delete response.heartbeat_interval; @@ -464,7 +456,7 @@ $document.trigger( 'heartbeat-tick', [response, textStatus, jqXHR] ); wp.hooks.doAction( 'heartbeat.tick', response, textStatus, jqXHR ); - // Do this last. Can trigger the next XHR if connection time > 5 sec. and newInterval == 'fast'. + // Do this last. Can trigger the next XHR if connection time > 5 seconds and newInterval == 'fast'. if ( newInterval ) { interval( newInterval ); } @@ -480,9 +472,8 @@ * * Fires immediately if the connection time is longer than the interval. * - * @access private - * * @since 3.8.0 + * @access private * * @return {void} */ @@ -495,7 +486,7 @@ } if ( ! settings.hasFocus ) { - interval = 120000; // 120 sec. Post locks expire after 150 sec. + interval = 120000; // 120 seconds. Post locks expire after 150 seconds. } else if ( settings.countdown > 0 && settings.tempInterval ) { interval = settings.tempInterval; settings.countdown--; @@ -526,9 +517,8 @@ /** * Sets the internal state when the browser window becomes hidden or loses focus. * - * @access private - * * @since 3.6.0 + * @access private * * @return {void} */ @@ -539,16 +529,15 @@ /** * Sets the internal state when the browser window becomes visible or is in focus. * - * @access private - * * @since 3.6.0 + * @access private * * @return {void} */ function focused() { settings.userActivity = time(); - // Resume if suspended + // Resume if suspended. settings.suspend = false; if ( ! settings.hasFocus ) { @@ -560,9 +549,8 @@ /** * Runs when the user becomes active after a period of inactivity. * - * @access private - * * @since 3.6.0 + * @access private * * @return {void} */ @@ -582,26 +570,25 @@ /** * Checks for user activity. * - * Runs every 30 sec. Sets 'hasFocus = true' if user is active and the window is - * in the background. Sets 'hasFocus = false' if the user has been inactive - * (no mouse or keyboard activity) for 5 min. even when the window has focus. - * - * @access private + * Runs every 30 seconds. Sets 'hasFocus = true' if user is active and the window + * is in the background. Sets 'hasFocus = false' if the user has been inactive + * (no mouse or keyboard activity) for 5 minutes even when the window has focus. * * @since 3.8.0 + * @access private * * @return {void} */ function checkUserActivity() { var lastActive = settings.userActivity ? time() - settings.userActivity : 0; - // Throttle down when no mouse or keyboard activity for 5 min. + // Throttle down when no mouse or keyboard activity for 5 minutes. if ( lastActive > 300000 && settings.hasFocus ) { blurred(); } - // Suspend after 10 min. of inactivity when suspending is enabled. - // Always suspend after 60 min. of inactivity. This will release the post lock, etc. + // Suspend after 10 minutes of inactivity when suspending is enabled. + // Always suspend after 60 minutes of inactivity. This will release the post lock, etc. if ( ( settings.suspendEnabled && lastActive > 600000 ) || lastActive > 3600000 ) { settings.suspend = true; } @@ -672,9 +659,9 @@ * Disables suspending. * * Should be used only when Heartbeat is performing critical tasks like - * autosave, post-locking, etc. Using this on many screens may overload the - * user's hosting account if several browser windows/tabs are left open for a - * long time. + * autosave, post-locking, etc. Using this on many screens may overload + * the user's hosting account if several browser windows/tabs are left open + * for a long time. * * @since 3.8.0 * @@ -691,15 +678,15 @@ * * When setting to 'fast' or 5, the interval is 5 seconds for the next 30 ticks * (for 2 minutes and 30 seconds) by default. In this case the number of 'ticks' - * can be passed as second argument. If the window doesn't have focus, the - * interval slows down to 2 min. + * can be passed as second argument. If the window doesn't have focus, + * the interval slows down to 2 minutes. * * @since 3.6.0 * * @memberOf wp.heartbeat.prototype * - * @param {string|number} speed Interval: 'fast' or 5, 15, 30, 60, 120. Fast - * equals 5. + * @param {string|number} speed Interval: 'fast' or 5, 15, 30, 60, 120. + * Fast equals 5. * @param {string} ticks Tells how many ticks before the interval reverts * back. Used with speed = 'fast' or 5. * @@ -728,7 +715,7 @@ newInterval = 120000; break; case 'long-polling': - // Allow long polling, (experimental) + // Allow long polling (experimental). settings.mainInterval = 0; return 0; default: @@ -751,9 +738,11 @@ settings.mainInterval = newInterval; } - // Change the next connection time if new interval has been set. - // Will connect immediately if the time since the last connection - // is greater than the new interval. + /* + * Change the next connection time if new interval has been set. + * Will connect immediately if the time since the last connection + * is greater than the new interval. + */ if ( newInterval !== oldInterval ) { scheduleNextTick(); } diff --git a/src/js/_enqueues/wp/mce-view.js b/src/js/_enqueues/wp/mce-view.js index e0439c41c7..1fca3d6d35 100644 --- a/src/js/_enqueues/wp/mce-view.js +++ b/src/js/_enqueues/wp/mce-view.js @@ -565,10 +565,12 @@ dom.add( node, 'span', { 'class': 'wpview-end' } ); } ); - // Bail if the iframe node is not attached to the DOM. - // Happens when the view is dragged in the editor. - // There is a browser restriction when iframes are moved in the DOM. They get emptied. - // The iframe will be rerendered after dropping the view node at the new location. + /* + * Bail if the iframe node is not attached to the DOM. + * Happens when the view is dragged in the editor. + * There is a browser restriction when iframes are moved in the DOM. They get emptied. + * The iframe will be rerendered after dropping the view node at the new location. + */ if ( ! iframe.contentWindow ) { return; } diff --git a/src/js/_enqueues/wp/media/audiovideo.js b/src/js/_enqueues/wp/media/audiovideo.js index 75eee00d52..f0127cc507 100644 --- a/src/js/_enqueues/wp/media/audiovideo.js +++ b/src/js/_enqueues/wp/media/audiovideo.js @@ -53,7 +53,7 @@ wp.media.mixin = { return; } - // invoke features cleanup + // Invoke features cleanup. for ( featureIndex in t.options.features ) { feature = t.options.features[featureIndex]; if ( t['clean' + feature] ) { diff --git a/src/js/_enqueues/wp/media/editor.js b/src/js/_enqueues/wp/media/editor.js index 380dbe2ce2..a02ecf9376 100644 --- a/src/js/_enqueues/wp/media/editor.js +++ b/src/js/_enqueues/wp/media/editor.js @@ -430,9 +430,11 @@ _.extend( attrs, attachments[this.tag].toJSON() ); } - // Convert all gallery shortcodes to use the `ids` property. - // Ignore `post__in` and `post__not_in`; the attachments in - // the collection will already reflect those properties. + /* + * Convert all gallery shortcodes to use the `ids` property. + * Ignore `post__in` and `post__not_in`; the attachments in + * the collection will already reflect those properties. + */ attrs.ids = attachments.pluck('id'); // Copy the `uploadedTo` post ID. @@ -670,7 +672,7 @@ this.content.set( view ); - // after bringing in the frame, load the actual editor via an ajax call + // After bringing in the frame, load the actual editor via an Ajax call. view.loadEditor(); }, this._frame ); @@ -733,9 +735,11 @@ wpActiveEditor = window.wpActiveEditor; } - // Delegate to the global `send_to_editor` if it exists. - // This attempts to play nice with any themes/plugins that have - // overridden the insert functionality. + /* + * Delegate to the global `send_to_editor` if it exists. + * This attempts to play nice with any themes/plugins + * that have overridden the insert functionality. + */ if ( window.send_to_editor ) { return window.send_to_editor.apply( this, arguments ); } @@ -780,7 +784,7 @@ add: function( id, options ) { var workflow = this.get( id ); - // only add once: if exists return existing + // Only add once: if exists return existing. if ( workflow ) { return workflow; } @@ -1016,7 +1020,7 @@ workflow = this.get( id ); - // Redo workflow if state has changed + // Redo workflow if state has changed. if ( ! workflow || ( workflow.options && options.state !== workflow.options.state ) ) { workflow = this.add( id, options ); } diff --git a/src/js/_enqueues/wp/media/models.js b/src/js/_enqueues/wp/media/models.js index 308aea41c0..205616c36c 100644 --- a/src/js/_enqueues/wp/media/models.js +++ b/src/js/_enqueues/wp/media/models.js @@ -147,9 +147,11 @@ _.extend( media, /** @lends wp.media */{ maxHeight = dimensions.maxHeight, constraint; - // Compare ratios between the two values to determine which - // max to constrain by. If a max value doesn't exist, then the - // opposite side is the constraint. + /* + * Compare ratios between the two values to determine + * which max to constrain by. If a max value doesn't exist, + * then the opposite side is the constraint. + */ if ( ! _.isUndefined( maxWidth ) && ! _.isUndefined( maxHeight ) ) { constraint = ( width / height > maxWidth / maxHeight ) ? 'width' : 'height'; } else if ( _.isUndefined( maxHeight ) ) { @@ -236,7 +238,7 @@ media.query = function( props ) { }); }; -// Clean up. Prevents mobile browsers caching +// Clean up. Prevents mobile browsers caching. $(window).on('unload', function(){ window.wp = null; }); diff --git a/src/js/_enqueues/wp/media/views.js b/src/js/_enqueues/wp/media/views.js index d2c35078e6..2f98e029f5 100644 --- a/src/js/_enqueues/wp/media/views.js +++ b/src/js/_enqueues/wp/media/views.js @@ -18,7 +18,7 @@ delete l10n.settings; // Copy the `post` setting over to the model settings. media.model.settings.post = media.view.settings.post; -// Check if the browser supports CSS 3.0 transitions +// Check if the browser supports CSS 3.0 transitions. $.support.transition = (function(){ var style = document.documentElement.style, transitions = { diff --git a/src/js/_enqueues/wp/shortcode.js b/src/js/_enqueues/wp/shortcode.js index bf3e1e21a0..1818d20c51 100644 --- a/src/js/_enqueues/wp/shortcode.js +++ b/src/js/_enqueues/wp/shortcode.js @@ -13,13 +13,15 @@ window.wp = window.wp || {}; (function(){ wp.shortcode = { - // ### Find the next matching shortcode - // - // Given a shortcode `tag`, a block of `text`, and an optional starting - // `index`, returns the next matching shortcode or `undefined`. - // - // Shortcodes are formatted as an object that contains the match - // `content`, the matching `index`, and the parsed `shortcode` object. + /* + * ### Find the next matching shortcode. + * + * Given a shortcode `tag`, a block of `text`, and an optional starting + * `index`, returns the next matching shortcode or `undefined`. + * + * Shortcodes are formatted as an object that contains the match + * `content`, the matching `index`, and the parsed `shortcode` object. + */ next: function( tag, text, index ) { var re = wp.shortcode.regexp( tag ), match, result; @@ -57,15 +59,17 @@ window.wp = window.wp || {}; return result; }, - // ### Replace matching shortcodes in a block of text - // - // Accepts a shortcode `tag`, content `text` to scan, and a `callback` - // to process the shortcode matches and return a replacement string. - // Returns the `text` with all shortcodes replaced. - // - // Shortcode matches are objects that contain the shortcode `tag`, - // a shortcode `attrs` object, the `content` between shortcode tags, - // and a boolean flag to indicate if the match was a `single` tag. + /* + * ### Replace matching shortcodes in a block of text. + * + * Accepts a shortcode `tag`, content `text` to scan, and a `callback` + * to process the shortcode matches and return a replacement string. + * Returns the `text` with all shortcodes replaced. + * + * Shortcode matches are objects that contain the shortcode `tag`, + * a shortcode `attrs` object, the `content` between shortcode tags, + * and a boolean flag to indicate if the match was a `single` tag. + */ replace: function( tag, text, callback ) { return text.replace( wp.shortcode.regexp( tag ), function( match, left, tag, attrs, slash, content, closing, right ) { // If both extra brackets exist, the shortcode has been @@ -83,67 +87,75 @@ window.wp = window.wp || {}; }); }, - // ### Generate a string from shortcode parameters - // - // Creates a `wp.shortcode` instance and returns a string. - // - // Accepts the same `options` as the `wp.shortcode()` constructor, - // containing a `tag` string, a string or object of `attrs`, a boolean - // indicating whether to format the shortcode using a `single` tag, and a - // `content` string. + /* + * ### Generate a string from shortcode parameters. + * + * Creates a `wp.shortcode` instance and returns a string. + * + * Accepts the same `options` as the `wp.shortcode()` constructor, + * containing a `tag` string, a string or object of `attrs`, a boolean + * indicating whether to format the shortcode using a `single` tag, and a + * `content` string. + */ string: function( options ) { return new wp.shortcode( options ).string(); }, - // ### Generate a RegExp to identify a shortcode - // - // The base regex is functionally equivalent to the one found in - // `get_shortcode_regex()` in `wp-includes/shortcodes.php`. - // - // Capture groups: - // - // 1. An extra `[` to allow for escaping shortcodes with double `[[]]` - // 2. The shortcode name - // 3. The shortcode argument list - // 4. The self closing `/` - // 5. The content of a shortcode when it wraps some content. - // 6. The closing tag. - // 7. An extra `]` to allow for escaping shortcodes with double `[[]]` + /* + * ### Generate a RegExp to identify a shortcode. + * + * The base regex is functionally equivalent to the one found in + * `get_shortcode_regex()` in `wp-includes/shortcodes.php`. + * + * Capture groups: + * + * 1. An extra `[` to allow for escaping shortcodes with double `[[]]`. + * 2. The shortcode name. + * 3. The shortcode argument list. + * 4. The self closing `/`. + * 5. The content of a shortcode when it wraps some content. + * 6. The closing tag. + * 7. An extra `]` to allow for escaping shortcodes with double `[[]]`. + */ regexp: _.memoize( function( tag ) { return new RegExp( '\\[(\\[?)(' + tag + ')(?![\\w-])([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*(?:\\[(?!\\/\\2\\])[^\\[]*)*)(\\[\\/\\2\\]))?)(\\]?)', 'g' ); }), - // ### Parse shortcode attributes - // - // Shortcodes accept many types of attributes. These can chiefly be - // divided into named and numeric attributes: - // - // Named attributes are assigned on a key/value basis, while numeric - // attributes are treated as an array. - // - // Named attributes can be formatted as either `name="value"`, - // `name='value'`, or `name=value`. Numeric attributes can be formatted - // as `"value"` or just `value`. + /* + * ### Parse shortcode attributes. + * + * Shortcodes accept many types of attributes. These can chiefly be + * divided into named and numeric attributes: + * + * Named attributes are assigned on a key/value basis, while numeric + * attributes are treated as an array. + * + * Named attributes can be formatted as either `name="value"`, + * `name='value'`, or `name=value`. Numeric attributes can be formatted + * as `"value"` or just `value`. + */ attrs: _.memoize( function( text ) { var named = {}, numeric = [], pattern, match; - // This regular expression is reused from `shortcode_parse_atts()` - // in `wp-includes/shortcodes.php`. - // - // Capture groups: - // - // 1. An attribute name, that corresponds to... - // 2. a value in double quotes. - // 3. An attribute name, that corresponds to... - // 4. a value in single quotes. - // 5. An attribute name, that corresponds to... - // 6. an unquoted value. - // 7. A numeric attribute in double quotes. - // 8. A numeric attribute in single quotes. - // 9. An unquoted numeric attribute. + /* + * This regular expression is reused from `shortcode_parse_atts()` + * in `wp-includes/shortcodes.php`. + * + * Capture groups: + * + * 1. An attribute name, that corresponds to... + * 2. a value in double quotes. + * 3. An attribute name, that corresponds to... + * 4. a value in single quotes. + * 5. An attribute name, that corresponds to... + * 6. an unquoted value. + * 7. A numeric attribute in double quotes. + * 8. A numeric attribute in single quotes. + * 9. An unquoted numeric attribute. + */ pattern = /([\w-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w-]+)\s*=\s*'([^']*)'(?:\s|$)|([\w-]+)\s*=\s*([^\s'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|'([^']*)'(?:\s|$)|(\S+)(?:\s|$)/g; // Map zero-width spaces to actual spaces. @@ -172,10 +184,13 @@ window.wp = window.wp || {}; }; }), - // ### Generate a Shortcode Object from a RegExp match - // Accepts a `match` object from calling `regexp.exec()` on a `RegExp` - // generated by `wp.shortcode.regexp()`. `match` can also be set to the - // `arguments` from a callback passed to `regexp.replace()`. + /* + * ### Generate a Shortcode Object from a RegExp match. + * + * Accepts a `match` object from calling `regexp.exec()` on a `RegExp` + * generated by `wp.shortcode.regexp()`. `match` can also be set + * to the `arguments` from a callback passed to `regexp.replace()`. + */ fromMatch: function( match ) { var type; @@ -197,16 +212,18 @@ window.wp = window.wp || {}; }; - // Shortcode Objects - // ----------------- - // - // Shortcode objects are generated automatically when using the main - // `wp.shortcode` methods: `next()`, `replace()`, and `string()`. - // - // To access a raw representation of a shortcode, pass an `options` object, - // containing a `tag` string, a string or object of `attrs`, a string - // indicating the `type` of the shortcode ('single', 'self-closing', or - // 'closed'), and a `content` string. + /* + * Shortcode Objects + * ----------------- + * + * Shortcode objects are generated automatically when using the main + * `wp.shortcode` methods: `next()`, `replace()`, and `string()`. + * + * To access a raw representation of a shortcode, pass an `options` object, + * containing a `tag` string, a string or object of `attrs`, a string + * indicating the `type` of the shortcode ('single', 'self-closing', + * or 'closed'), and a `content` string. + */ wp.shortcode = _.extend( function( options ) { _.extend( this, _.pick( options || {}, 'tag', 'attrs', 'type', 'content' ) ); @@ -239,24 +256,28 @@ window.wp = window.wp || {}; }, wp.shortcode ); _.extend( wp.shortcode.prototype, { - // ### Get a shortcode attribute - // - // Automatically detects whether `attr` is named or numeric and routes - // it accordingly. + /* + * ### Get a shortcode attribute. + * + * Automatically detects whether `attr` is named or numeric and routes + * it accordingly. + */ get: function( attr ) { return this.attrs[ _.isNumber( attr ) ? 'numeric' : 'named' ][ attr ]; }, - // ### Set a shortcode attribute - // - // Automatically detects whether `attr` is named or numeric and routes - // it accordingly. + /* + * ### Set a shortcode attribute. + * + * Automatically detects whether `attr` is named or numeric and routes + * it accordingly. + */ set: function( attr, value ) { this.attrs[ _.isNumber( attr ) ? 'numeric' : 'named' ][ attr ] = value; return this; }, - // ### Transform the shortcode match into a string + // ### Transform the shortcode match into a string. string: function() { var text = '[' + this.tag; @@ -293,20 +314,24 @@ window.wp = window.wp || {}; }); }()); -// HTML utility functions -// ---------------------- -// -// Experimental. These functions may change or be removed in the future. +/* + * HTML utility functions + * ---------------------- + * + * Experimental. These functions may change or be removed in the future. + */ (function(){ wp.html = _.extend( wp.html || {}, { - // ### Parse HTML attributes. - // - // Converts `content` to a set of parsed HTML attributes. - // Utilizes `wp.shortcode.attrs( content )`, which is a valid superset of - // the HTML attribute specification. Reformats the attributes into an - // object that contains the `attrs` with `key:value` mapping, and a record - // of the attributes that were entered using `empty` attribute syntax (i.e. - // with no value). + /* + * ### Parse HTML attributes. + * + * Converts `content` to a set of parsed HTML attributes. + * Utilizes `wp.shortcode.attrs( content )`, which is a valid superset of + * the HTML attribute specification. Reformats the attributes into an + * object that contains the `attrs` with `key:value` mapping, and a record + * of the attributes that were entered using `empty` attribute syntax (i.e. + * with no value). + */ attrs: function( content ) { var result, attrs; diff --git a/src/js/_enqueues/wp/svg-painter.js b/src/js/_enqueues/wp/svg-painter.js index e0277f13f2..e697a0df28 100644 --- a/src/js/_enqueues/wp/svg-painter.js +++ b/src/js/_enqueues/wp/svg-painter.js @@ -13,7 +13,7 @@ wp.svgPainter = ( function( $, window, document, undefined ) { elements = []; $(document).ready( function() { - // detection for browser SVG capability + // Detection for browser SVG capability. if ( document.implementation.hasFeature( 'http://www.w3.org/TR/SVG11/feature#Image', '1.1' ) ) { $( document.body ).removeClass( 'no-svg' ).addClass( 'svg' ); wp.svgPainter.init(); @@ -148,24 +148,24 @@ wp.svgPainter = ( function( $, window, document, undefined ) { }, paint: function() { - // loop through all elements + // Loop through all elements. $.each( elements, function( index, $element ) { var $menuitem = $element.parent().parent(); if ( $menuitem.hasClass( 'current' ) || $menuitem.hasClass( 'wp-has-current-submenu' ) ) { - // paint icon in 'current' color + // Paint icon in 'current' color. painter.paintElement( $element, 'current' ); } else { - // paint icon in base color + // Paint icon in base color. painter.paintElement( $element, 'base' ); - // set hover callbacks + // Set hover callbacks. $menuitem.hover( function() { painter.paintElement( $element, 'focus' ); }, function() { - // Match the delay from hoverIntent + // Match the delay from hoverIntent. window.setTimeout( function() { painter.paintElement( $element, 'base' ); }, 100 ); @@ -184,7 +184,7 @@ wp.svgPainter = ( function( $, window, document, undefined ) { color = colorscheme[ colorType ]; - // only accept hex colors: #101 or #101010 + // Only accept hex colors: #101 or #101010. if ( ! color.match( /^(#[0-9a-f]{3}|#[0-9a-f]{6})$/i ) ) { return; } @@ -212,13 +212,13 @@ wp.svgPainter = ( function( $, window, document, undefined ) { } catch ( error ) {} if ( xml ) { - // replace `fill` attributes + // Replace `fill` attributes. xml = xml.replace( /fill="(.+?)"/g, 'fill="' + color + '"'); - // replace `style` attributes + // Replace `style` attributes. xml = xml.replace( /style="(.+?)"/g, 'style="fill:' + color + '"'); - // replace `fill` properties in ` #site-title a, @@ -398,7 +398,7 @@ if ( ! function_exists( 'twentyeleven_admin_header_style' ) ) : ' . __( 'Continue reading ', 'twentyeleven' ) . ''; } -endif; // twentyeleven_continue_reading_link +endif; // twentyeleven_continue_reading_link() /** * Replace "[...]" in the Read More link with an ellipsis. @@ -609,7 +609,7 @@ if ( ! function_exists( 'twentyeleven_content_nav' ) ) : <?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?> - +

    - - 'primary' ) ); ?> + 'primary' ) ); + ?> diff --git a/src/wp-content/themes/twentyeleven/image.php b/src/wp-content/themes/twentyeleven/image.php index 980bc3a002..8625991dda 100644 --- a/src/wp-content/themes/twentyeleven/image.php +++ b/src/wp-content/themes/twentyeleven/image.php @@ -75,32 +75,34 @@ get_header(); ?> } } - // If there is more than 1 attachment in a gallery + // If there is more than 1 attachment in a gallery... if ( count( $attachments ) > 1 ) { $k++; if ( isset( $attachments[ $k ] ) ) { - // get the URL of the next image attachment + // ...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 + } 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, get the URL of the image + // Or, if there's only 1 image, get the URL of the image. $next_attachment_url = wp_get_attachment_url(); } ?> - ID, array( $attachment_size, 1024 ) ); // filterable image width with 1024px limit for image height. - ?> + ID, array( $attachment_size, 1024 ) ); + ?> post_excerpt ) ) : ?> @@ -130,7 +132,7 @@ get_header(); ?> - + diff --git a/src/wp-content/themes/twentyeleven/inc/theme-customizer.js b/src/wp-content/themes/twentyeleven/inc/theme-customizer.js index 002fc97950..70cb6d8a7f 100644 --- a/src/wp-content/themes/twentyeleven/inc/theme-customizer.js +++ b/src/wp-content/themes/twentyeleven/inc/theme-customizer.js @@ -10,7 +10,7 @@ } ); } ); - // Header text color + // Header text color. wp.customize( 'header_textcolor', function( value ) { value.bind( function( to ) { if ( 'blank' === to ) { diff --git a/src/wp-content/themes/twentyeleven/inc/theme-options.php b/src/wp-content/themes/twentyeleven/inc/theme-options.php index 012eb326f3..cb0556d006 100644 --- a/src/wp-content/themes/twentyeleven/inc/theme-options.php +++ b/src/wp-content/themes/twentyeleven/inc/theme-options.php @@ -37,26 +37,26 @@ add_action( 'admin_print_styles-appearance_page_theme_options', 'twentyeleven_ad function twentyeleven_theme_options_init() { register_setting( - 'twentyeleven_options', // Options group, see settings_fields() call in twentyeleven_theme_options_render_page() - 'twentyeleven_theme_options', // Database option, see twentyeleven_get_theme_options() - 'twentyeleven_theme_options_validate' // The sanitization callback, see twentyeleven_theme_options_validate() + 'twentyeleven_options', // Options group, see settings_fields() call in twentyeleven_theme_options_render_page(). + 'twentyeleven_theme_options', // Database option, see twentyeleven_get_theme_options(). + 'twentyeleven_theme_options_validate' // The sanitization callback, see twentyeleven_theme_options_validate(). ); - // Register our settings field group + // Register our settings field group. add_settings_section( - 'general', // Unique identifier for the settings section - '', // Section title (we don't want one) - '__return_false', // Section callback (we don't want anything) - 'theme_options' // Menu slug, used to uniquely identify the page; see twentyeleven_theme_options_add_page() + 'general', // Unique identifier for the settings section. + '', // Section title (we don't want one). + '__return_false', // Section callback (we don't want anything). + 'theme_options' // Menu slug, used to uniquely identify the page; see twentyeleven_theme_options_add_page(). ); - // Register our individual settings fields + // Register our individual settings fields. add_settings_field( - 'color_scheme', // Unique identifier for the field for this section - __( 'Color Scheme', 'twentyeleven' ), // Setting field label - 'twentyeleven_settings_field_color_scheme', // Function that renders the settings field - 'theme_options', // Menu slug, used to uniquely identify the page; see twentyeleven_theme_options_add_page() - 'general' // Settings section. Same as the first argument in the add_settings_section() above + 'color_scheme', // Unique identifier for the field for this section. + __( 'Color Scheme', 'twentyeleven' ), // Setting field label. + 'twentyeleven_settings_field_color_scheme', // Function that renders the settings field. + 'theme_options', // Menu slug, used to uniquely identify the page; see twentyeleven_theme_options_add_page(). + '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' ); @@ -92,11 +92,11 @@ add_filter( 'option_page_capability_twentyeleven_options', 'twentyeleven_option_ */ function twentyeleven_theme_options_add_page() { $theme_page = add_theme_page( - __( 'Theme Options', 'twentyeleven' ), // Name of page - __( 'Theme Options', 'twentyeleven' ), // Label in menu - 'edit_theme_options', // Capability required - 'theme_options', // Menu slug, used to uniquely identify the page - 'twentyeleven_theme_options_render_page' // Function that renders the options page + __( 'Theme Options', 'twentyeleven' ), // Name of page. + __( 'Theme Options', 'twentyeleven' ), // Label in menu. + 'edit_theme_options', // Capability required. + 'theme_options', // Menu slug, used to uniquely identify the page. + 'twentyeleven_theme_options_render_page' // Function that renders the options page. ); if ( ! $theme_page ) { @@ -124,7 +124,7 @@ function twentyeleven_theme_options_help() { $screen = get_current_screen(); if ( method_exists( $screen, 'add_help_tab' ) ) { - // WordPress 3.3.0 + // WordPress 3.3.0. $screen->add_help_tab( array( 'title' => __( 'Overview', 'twentyeleven' ), @@ -135,7 +135,7 @@ function twentyeleven_theme_options_help() { $screen->set_help_sidebar( $sidebar ); } else { - // WordPress 3.2.0 + // WordPress 3.2.0. add_contextual_help( $screen, $help . $sidebar ); } } @@ -378,7 +378,7 @@ function twentyeleven_theme_options_validate( $input ) { $defaults = twentyeleven_get_default_theme_options(); $output = $defaults; - // Color scheme must be in our array of color scheme 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() ) ) { $output['color_scheme'] = $input['color_scheme']; } @@ -387,12 +387,12 @@ function twentyeleven_theme_options_validate( $input ) { $defaults['link_color'] = twentyeleven_get_default_link_color( $output['color_scheme'] ); $output['link_color'] = $defaults['link_color']; - // Link color must be 3 or 6 hexadecimal characters + // 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'] ) ) { $output['link_color'] = '#' . strtolower( ltrim( $input['link_color'], '#' ) ); } - // Theme layout must be in our array of theme layout options + // Theme layout must be in our array of theme layout options. if ( isset( $input['theme_layout'] ) && array_key_exists( $input['theme_layout'], twentyeleven_layouts() ) ) { $output['theme_layout'] = $input['theme_layout']; } @@ -582,7 +582,7 @@ function twentyeleven_customize_register( $wp_customize ) { ) ); - // Link Color (added to Color Scheme section in Customizer) + // Link Color (added to Color Scheme section in Customizer). $wp_customize->add_setting( 'twentyeleven_theme_options[link_color]', array( @@ -605,7 +605,7 @@ function twentyeleven_customize_register( $wp_customize ) { ) ); - // Default Layout + // Default Layout. $wp_customize->add_section( 'twentyeleven_layout', array( diff --git a/src/wp-content/themes/twentyeleven/inc/widgets.php b/src/wp-content/themes/twentyeleven/inc/widgets.php index ba4b4487d7..ec1ad74243 100644 --- a/src/wp-content/themes/twentyeleven/inc/widgets.php +++ b/src/wp-content/themes/twentyeleven/inc/widgets.php @@ -137,10 +137,10 @@ class Twenty_Eleven_Ephemera_Widget extends WP_Widget { echo $args['after_widget']; - // Reset the post globals as this query will have stomped on it + // Reset the post globals as this query will have stomped on it. wp_reset_postdata(); - // end check for ephemeral posts + // End check for ephemeral posts. endif; $cache[ $args['widget_id'] ] = ob_get_flush(); diff --git a/src/wp-content/themes/twentyeleven/index.php b/src/wp-content/themes/twentyeleven/index.php index a7e3c141db..a4a7c04f18 100644 --- a/src/wp-content/themes/twentyeleven/index.php +++ b/src/wp-content/themes/twentyeleven/index.php @@ -21,8 +21,8 @@ get_header(); ?> - diff --git a/src/wp-content/themes/twentyeleven/page.php b/src/wp-content/themes/twentyeleven/page.php index 4b322e84fa..eed2f13034 100644 --- a/src/wp-content/themes/twentyeleven/page.php +++ b/src/wp-content/themes/twentyeleven/page.php @@ -26,7 +26,7 @@ get_header(); ?> - + diff --git a/src/wp-content/themes/twentyeleven/search.php b/src/wp-content/themes/twentyeleven/search.php index 8ea996223d..f7902d35f0 100644 --- a/src/wp-content/themes/twentyeleven/search.php +++ b/src/wp-content/themes/twentyeleven/search.php @@ -25,8 +25,8 @@ get_header(); ?> - diff --git a/src/wp-content/themes/twentyeleven/showcase.php b/src/wp-content/themes/twentyeleven/showcase.php index d986182596..2931b4073e 100644 --- a/src/wp-content/themes/twentyeleven/showcase.php +++ b/src/wp-content/themes/twentyeleven/showcase.php @@ -15,7 +15,7 @@ * @since Twenty Eleven 1.0 */ -// Enqueue showcase script for the slider +// Enqueue showcase script for the slider. wp_enqueue_script( 'twentyeleven-showcase', get_template_directory_uri() . '/js/showcase.js', array( 'jquery' ), '20110429' ); get_header(); ?> @@ -62,7 +62,7 @@ get_header(); ?> // The Featured Posts query. $featured = new WP_Query( $featured_args ); - // Proceed only if published posts exist + // Proceed only if published posts exist. if ( $featured->have_posts() ) : /* @@ -91,13 +91,13 @@ get_header(); ?> $counter_slider++; /* - * We're going to add a class to our featured post for featured images - * by default it'll have the feature-text class. + * We're going to add a class to our featured post for featured images. + * By default it will have the feature-text class. */ $feature_class = 'feature-text'; if ( has_post_thumbnail() ) { - // ... but if it has a featured image let's add some class + // ...but if it has a featured image let's add some class. $feature_class = 'feature-image small'; // Hang on. Let's check this here image out. @@ -144,10 +144,10 @@ get_header(); ?>
      // Our new query for the Recent Posts section. $recent = new WP_Query( $recent_args ); - // The first Recent post is displayed normally + // The first Recent post is displayed normally. if ( $recent->have_posts() ) : $recent->the_post(); @@ -224,7 +224,7 @@ get_header(); ?> + // If we had some posts, close the
        . if ( $recent->post_count > 0 ) { echo '
      '; } @@ -245,7 +245,7 @@ get_header(); ?> ); ?> - + diff --git a/src/wp-content/themes/twentyeleven/sidebar-page.php b/src/wp-content/themes/twentyeleven/sidebar-page.php index a12f1a233f..4ed5cd6ca7 100644 --- a/src/wp-content/themes/twentyeleven/sidebar-page.php +++ b/src/wp-content/themes/twentyeleven/sidebar-page.php @@ -23,7 +23,7 @@ get_header(); ?> - + diff --git a/src/wp-content/themes/twentyeleven/sidebar.php b/src/wp-content/themes/twentyeleven/sidebar.php index 67fb7e5f11..df543cf73a 100644 --- a/src/wp-content/themes/twentyeleven/sidebar.php +++ b/src/wp-content/themes/twentyeleven/sidebar.php @@ -31,6 +31,6 @@ if ( 'content' != $current_layout ) :
    - + diff --git a/src/wp-content/themes/twentyeleven/single.php b/src/wp-content/themes/twentyeleven/single.php index b1ebd8a674..186bb378d8 100644 --- a/src/wp-content/themes/twentyeleven/single.php +++ b/src/wp-content/themes/twentyeleven/single.php @@ -27,7 +27,7 @@ get_header(); ?> - + diff --git a/src/wp-content/themes/twentyeleven/tag.php b/src/wp-content/themes/twentyeleven/tag.php index ab69a8c0ec..5d9e833a3c 100644 --- a/src/wp-content/themes/twentyeleven/tag.php +++ b/src/wp-content/themes/twentyeleven/tag.php @@ -39,8 +39,8 @@ get_header(); ?> - diff --git a/src/wp-content/themes/twentyfifteen/archive.php b/src/wp-content/themes/twentyfifteen/archive.php index 26a9a4b4ca..425a74ac71 100644 --- a/src/wp-content/themes/twentyfifteen/archive.php +++ b/src/wp-content/themes/twentyfifteen/archive.php @@ -31,14 +31,14 @@ get_header(); ?>

    diff --git a/src/wp-content/themes/twentyfifteen/content-link.php b/src/wp-content/themes/twentyfifteen/content-link.php index e3b260fd3c..2d442a1588 100644 --- a/src/wp-content/themes/twentyfifteen/content-link.php +++ b/src/wp-content/themes/twentyfifteen/content-link.php @@ -49,7 +49,7 @@
    @@ -77,7 +77,7 @@ get_header(); ?> 1 || is_preview() ) { - // This blog has more than 1 category so twentyfifteen_categorized_blog should return true. + // This blog has more than 1 category so twentyfifteen_categorized_blog() should return true. return true; } else { - // This blog has only 1 category so twentyfifteen_categorized_blog should return false. + // This blog has only 1 category so twentyfifteen_categorized_blog() should return false. return false; } } @@ -213,7 +213,7 @@ if ( ! function_exists( 'twentyfifteen_post_thumbnail' ) ) : the_post(); /* - * Include the Post-Format-specific template for the content. - * If you want to override this in a child theme, then include a file - * called content-___.php (where ___ is the Post Format name) and that will be used instead. + * Include the post format-specific template for the content. If you want + * to use this in a child theme, then include a file called content-___.php + * (where ___ is the post format) and that will be used instead. */ get_template_part( 'content', get_post_format() ); diff --git a/src/wp-content/themes/twentyfifteen/js/functions.js b/src/wp-content/themes/twentyfifteen/js/functions.js index f968885829..f554ceefd1 100644 --- a/src/wp-content/themes/twentyfifteen/js/functions.js +++ b/src/wp-content/themes/twentyfifteen/js/functions.js @@ -79,6 +79,7 @@ * * Uses jQuery's width() function to determine the size of the window and add * the default ARIA attributes for the menu toggle if it's visible. + * * @since Twenty Fifteen 1.1 */ function onResizeARIA() { diff --git a/src/wp-content/themes/twentyfifteen/single.php b/src/wp-content/themes/twentyfifteen/single.php index 4de3a493ad..2a4bb89366 100644 --- a/src/wp-content/themes/twentyfifteen/single.php +++ b/src/wp-content/themes/twentyfifteen/single.php @@ -18,8 +18,8 @@ get_header(); ?> the_post(); /* - * Include the post format-specific template for the content. If you want to - * use this in a child theme, then include a file called content-___.php + * Include the post format-specific template for the content. If you want + * to use this in a child theme, then include a file called content-___.php * (where ___ is the post format) and that will be used instead. */ get_template_part( 'content', get_post_format() ); diff --git a/src/wp-content/themes/twentyfourteen/archive.php b/src/wp-content/themes/twentyfourteen/archive.php index 82b79c0868..f11a57ff1a 100644 --- a/src/wp-content/themes/twentyfourteen/archive.php +++ b/src/wp-content/themes/twentyfourteen/archive.php @@ -44,13 +44,13 @@ get_header(); ?> " > @@ -72,7 +72,7 @@ get_header(); - + diff --git a/src/wp-content/themes/twentyfourteen/inc/custom-header.php b/src/wp-content/themes/twentyfourteen/inc/custom-header.php index 92382eaa5e..a459c0b003 100644 --- a/src/wp-content/themes/twentyfourteen/inc/custom-header.php +++ b/src/wp-content/themes/twentyfourteen/inc/custom-header.php @@ -91,7 +91,7 @@ if ( ! function_exists( 'twentyfourteen_header_style' ) ) : 1, ) ); - // Count the number of categories that are attached to the posts + // Count the number of categories that are attached to the posts. $all_the_cool_cats = count( $all_the_cool_cats ); set_transient( 'twentyfourteen_category_count', $all_the_cool_cats ); } if ( $all_the_cool_cats > 1 || is_preview() ) { - // This blog has more than 1 category so twentyfourteen_categorized_blog should return true + // This blog has more than 1 category so twentyfourteen_categorized_blog() should return true. return true; } else { - // This blog has only 1 category so twentyfourteen_categorized_blog should return false + // This blog has only 1 category so twentyfourteen_categorized_blog() should return false. return false; } } @@ -208,7 +208,7 @@ if ( ! function_exists( 'twentyfourteen_post_thumbnail' ) ) :
    diff --git a/src/wp-content/themes/twentyfourteen/page-templates/full-width.php b/src/wp-content/themes/twentyfourteen/page-templates/full-width.php index ea5fa58873..b75ac8882e 100644 --- a/src/wp-content/themes/twentyfourteen/page-templates/full-width.php +++ b/src/wp-content/themes/twentyfourteen/page-templates/full-width.php @@ -21,7 +21,7 @@ if ( is_front_page() && twentyfourteen_has_featured_posts() ) {
    \s*<', $svg ); // Remove white space between SVG tags. + $svg = preg_replace( '/>\s*<', $svg ); // Remove whitespace between SVG tags. return $svg; } return null; diff --git a/src/wp-content/themes/twentynineteen/comments.php b/src/wp-content/themes/twentynineteen/comments.php index d72ae857c8..d00ac46118 100644 --- a/src/wp-content/themes/twentynineteen/comments.php +++ b/src/wp-content/themes/twentynineteen/comments.php @@ -56,7 +56,7 @@ $discussion = twentynineteen_get_discussion_data(); ?> diff --git a/src/wp-content/themes/twentynineteen/inc/template-functions.php b/src/wp-content/themes/twentynineteen/inc/template-functions.php index 4ec88c42ca..6c5153f01b 100644 --- a/src/wp-content/themes/twentynineteen/inc/template-functions.php +++ b/src/wp-content/themes/twentynineteen/inc/template-functions.php @@ -238,7 +238,7 @@ add_filter( 'wp_nav_menu', 'twentynineteen_add_ellipses_to_nav', 10, 2 ); */ function twentynineteen_nav_menu_link_attributes( $atts, $item, $args, $depth ) { - // Add [aria-haspopup] and [aria-expanded] to menu items that have children + // Add [aria-haspopup] and [aria-expanded] to menu items that have children. $item_has_children = in_array( 'menu-item-has-children', $item->classes ); if ( $item_has_children ) { $atts['aria-haspopup'] = 'true'; @@ -274,7 +274,7 @@ function twentynineteen_add_dropdown_icons( $output, $item, $depth, $args ) { twentynineteen_get_icon_svg( 'chevron_left', 24 ) ); - // replace opening with + // Replace closing with . $output = preg_replace( '##i', '', diff --git a/src/wp-content/themes/twentynineteen/inc/template-tags.php b/src/wp-content/themes/twentynineteen/inc/template-tags.php index a77f731122..ae3e3b17a5 100644 --- a/src/wp-content/themes/twentynineteen/inc/template-tags.php +++ b/src/wp-content/themes/twentynineteen/inc/template-tags.php @@ -76,10 +76,10 @@ if ( ! function_exists( 'twentynineteen_entry_footer' ) ) : // Hide author, post date, category and tag text for pages. if ( 'post' === get_post_type() ) { - // Posted by + // Posted by. twentynineteen_posted_by(); - // Posted on + // Posted on. twentynineteen_posted_on(); /* translators: Used between list items, there is a space after the comma. */ @@ -243,7 +243,7 @@ if ( ! function_exists( 'wp_body_open' ) ) : /** * Fire the wp_body_open action. * - * Added for backwards compatibility to support pre 5.2.0 WordPress versions. + * Added for backward compatibility to support pre-5.2.0 WordPress versions. * * @since Twenty Nineteen 1.4 */ diff --git a/src/wp-content/themes/twentynineteen/js/customize-preview.js b/src/wp-content/themes/twentynineteen/js/customize-preview.js index 91b91f3e0c..260c3d42f8 100644 --- a/src/wp-content/themes/twentynineteen/js/customize-preview.js +++ b/src/wp-content/themes/twentynineteen/js/customize-preview.js @@ -18,10 +18,10 @@ color; if( 'custom' === to ){ - // If a custom primary color is selected, use the currently set primary_color_hue + // If a custom primary color is selected, use the currently set primary_color_hue. color = wp.customize.get().primary_color_hue; } else { - // If the "default" option is selected, get the default primary_color_hue + // If the "default" option is selected, get the default primary_color_hue. color = 199; } diff --git a/src/wp-content/themes/twentynineteen/js/priority-menu.js b/src/wp-content/themes/twentynineteen/js/priority-menu.js index 7cd6bb066b..85449b0e24 100644 --- a/src/wp-content/themes/twentynineteen/js/priority-menu.js +++ b/src/wp-content/themes/twentynineteen/js/priority-menu.js @@ -1,7 +1,7 @@ (function() { /** - * Debounce + * Debounce. * * @param {Function} func * @param {number} wait @@ -56,7 +56,7 @@ * @param {Element} element */ function showButton(element) { - // classList.remove is not supported in IE11 + // classList.remove is not supported in IE11. element.className = element.className.replace('is-empty', ''); } @@ -66,7 +66,7 @@ * @param {Element} element */ function hideButton(element) { - // classList.add is not supported in IE11 + // classList.add is not supported in IE11. if (!element.classList.contains('is-empty')) { element.className += ' is-empty'; } @@ -91,25 +91,25 @@ } /** - * Set menu container variable + * Set menu container variable. */ var navContainer = document.querySelector('.main-navigation'); var breaks = []; /** - * Let’s bail if we our menu doesn't exist + * Let’s bail if we our menu doesn't exist. */ if ( ! navContainer ) { return; } /** - * Refreshes the list item from the menu depending on the menu size + * Refreshes the list item from the menu depending on the menu size. */ function updateNavigationMenu( container ) { /** - * Let’s bail if our menu is empty + * Let’s bail if our menu is empty. */ if ( ! container.parentNode.querySelector('.main-menu[id]') ) { return; @@ -122,42 +122,42 @@ if ( isOverflowingNavivation( visibleList, toggleButton, container ) ) { - // Record the width of the list + // Record the width of the list. breaks.push( visibleList.offsetWidth ); - // Move last item to the hidden list + // Move last item to the hidden list. prependElement( hiddenList, ! visibleList.lastChild || null === visibleList.lastChild ? visibleList.previousElementSibling : visibleList.lastChild ); - // Show the toggle button + // Show the toggle button. showButton( toggleButton ); } else { - // There is space for another item in the nav + // There is space for another item in the nav. if ( getAvailableSpace( toggleButton, container ) > breaks[breaks.length - 1] ) { - // Move the item to the visible list + // Move the item to the visible list. visibleList.appendChild( hiddenList.firstChild.nextSibling ); breaks.pop(); } - // Hide the dropdown btn if hidden list is empty + // Hide the dropdown btn if hidden list is empty. if (breaks.length < 2) { hideButton( toggleButton ); } } - // Recur if the visible list is still overflowing the nav + // Recur if the visible list is still overflowing the nav. if ( isOverflowingNavivation( visibleList, toggleButton, container ) ) { updateNavigationMenu( container ); } } /** - * Run our priority+ function as soon as the document is `ready` + * Run our priority+ function as soon as the document is `ready`. */ document.addEventListener( 'DOMContentLoaded', function() { updateNavigationMenu( navContainer ); - // Also, run our priority+ function on selective refresh in the customizer + // Also, run our priority+ function on selective refresh in the customizer. var hasSelectiveRefresh = ( 'undefined' !== typeof wp && wp.customize && @@ -166,7 +166,7 @@ ); if ( hasSelectiveRefresh ) { - // Re-run our priority+ function on Nav Menu partial refreshes + // Re-run our priority+ function on Nav Menu partial refreshes. wp.customize.selectiveRefresh.bind( 'partial-content-rendered', function ( placement ) { var isNewNavMenu = ( @@ -184,14 +184,14 @@ }); /** - * Run our priority+ function on load + * Run our priority+ function on load. */ window.addEventListener( 'load', function() { updateNavigationMenu( navContainer ); }); /** - * Run our priority+ function every time the window resizes + * Run our priority+ function every time the window resizes. */ var isResizing = false; window.addEventListener( 'resize', @@ -209,7 +209,7 @@ ); /** - * Run our priority+ function + * Run our priority+ function. */ updateNavigationMenu( navContainer ); diff --git a/src/wp-content/themes/twentynineteen/js/touch-keyboard-navigation.js b/src/wp-content/themes/twentynineteen/js/touch-keyboard-navigation.js index 2fa1905624..c8d1dd02e6 100644 --- a/src/wp-content/themes/twentynineteen/js/touch-keyboard-navigation.js +++ b/src/wp-content/themes/twentynineteen/js/touch-keyboard-navigation.js @@ -7,7 +7,7 @@ (function() { /** - * Debounce + * Debounce. * * @param {Function} func * @param {number} wait @@ -43,7 +43,7 @@ } /** - * Add class + * Add class. * * @param {Object} el * @param {string} cls @@ -55,7 +55,7 @@ } /** - * Delete class + * Delete class. * * @param {Object} el * @param {string} cls @@ -80,7 +80,7 @@ } /** - * Toggle Aria Expanded state for screenreaders + * Toggle Aria Expanded state for screenreaders. * * @param {Object} ariaItem */ @@ -99,24 +99,24 @@ } /** - * Open sub-menu + * Open sub-menu. * * @param {Object} currentSubMenu */ function openSubMenu( currentSubMenu ) { 'use strict'; - // Update classes - // classList.add is not supported in IE11 + // Update classes. + // classList.add is not supported in IE11. currentSubMenu.parentElement.className += ' off-canvas'; currentSubMenu.parentElement.lastElementChild.className += ' expanded-true'; - // Update aria-expanded state + // Update aria-expanded state. toggleAriaExpandedState( currentSubMenu ); } /** - * Close sub-menu + * Close sub-menu. * * @param {Object} currentSubMenu */ @@ -127,32 +127,32 @@ var menuItemAria = menuItem.querySelector('a[aria-expanded]'); var subMenu = currentSubMenu.closest('.sub-menu'); - // If this is in a sub-sub-menu, go back to parent sub-menu + // If this is in a sub-sub-menu, go back to parent sub-menu. if ( getCurrentParent( currentSubMenu, 'ul' ).classList.contains( 'sub-menu' ) ) { - // Update classes - // classList.remove is not supported in IE11 + // Update classes. + // classList.remove is not supported in IE11. menuItem.className = menuItem.className.replace( 'off-canvas', '' ); subMenu.className = subMenu.className.replace( 'expanded-true', '' ); - // Update aria-expanded and :focus states + // Update aria-expanded and :focus states. toggleAriaExpandedState( menuItemAria ); - // Or else close all sub-menus + // Or else close all sub-menus. } else { - // Update classes - // classList.remove is not supported in IE11 + // Update classes. + // classList.remove is not supported in IE11. menuItem.className = menuItem.className.replace( 'off-canvas', '' ); menuItem.lastElementChild.className = menuItem.lastElementChild.className.replace( 'expanded-true', '' ); - // Update aria-expanded and :focus states + // Update aria-expanded and :focus states. toggleAriaExpandedState( menuItemAria ); } } /** - * Find first ancestor of an element by selector + * Find first ancestor of an element by selector. * * @param {Object} child * @param {String} selector @@ -181,7 +181,7 @@ } /** - * Remove all off-canvas states + * Remove all off-canvas states. */ function removeAllFocusStates() { 'use strict'; @@ -202,7 +202,7 @@ } /** - * Matches polyfill for IE11 + * Matches polyfill for IE11. */ if (!Element.prototype.matches) { Element.prototype.matches = Element.prototype.msMatchesSelector; @@ -219,31 +219,31 @@ var url = event.target.getAttribute( 'href' ) ? event.target.getAttribute( 'href' ) : ''; - // Open submenu if url is # + // Open submenu if URL is #. if ( '#' === url && event.target.nextSibling.matches('.submenu-expand') ) { openSubMenu( event.target ); } } - // Check if .submenu-expand is touched + // Check if .submenu-expand is touched. if ( event.target.matches('.submenu-expand') ) { openSubMenu(event.target); - // Check if child of .submenu-expand is touched + // Check if child of .submenu-expand is touched. } else if ( null != getCurrentParent( event.target, '.submenu-expand' ) && getCurrentParent( event.target, '.submenu-expand' ).matches( '.submenu-expand' ) ) { openSubMenu( getCurrentParent( event.target, '.submenu-expand' ) ); - // Check if .menu-item-link-return is touched + // Check if .menu-item-link-return is touched. } else if ( event.target.matches('.menu-item-link-return') ) { closeSubMenu( event.target ); - // Check if child of .menu-item-link-return is touched + // Check if child of .menu-item-link-return is touched. } else if ( null != getCurrentParent( event.target, '.menu-item-link-return' ) && getCurrentParent( event.target, '.menu-item-link-return' ).matches( '.menu-item-link-return' ) ) { closeSubMenu( event.target ); } - // Prevent default mouse/focus events + // Prevent default mouse/focus events. removeAllFocusStates(); }, false); @@ -253,7 +253,7 @@ var mainNav = getCurrentParent( event.target, '.main-navigation' ); if ( null != mainNav && hasClass( mainNav, '.main-navigation' ) ) { - // Prevent default mouse events + // Prevent default mouse events. event.preventDefault(); } else if ( @@ -263,11 +263,11 @@ event.target.matches('.menu-item-link-return') || null != getCurrentParent( event.target, '.menu-item-link-return' ) && getCurrentParent( event.target, '.menu-item-link-return' ).matches( '.menu-item-link-return' ) ) { - // Prevent default mouse events + // Prevent default mouse events. event.preventDefault(); } - // Prevent default mouse/focus events + // Prevent default mouse/focus events. removeAllFocusStates(); }, false); @@ -276,7 +276,7 @@ if ( event.target.matches('.main-navigation > div > ul > li a') ) { - // Remove Focused elements in sibling div + // Remove Focused elements in sibling div. var currentDiv = getCurrentParent( event.target, 'div', '.main-navigation' ); var currentDivSibling = currentDiv.previousElementSibling === null ? currentDiv.nextElementSibling : currentDiv.previousElementSibling; var focusedElement = currentDivSibling.querySelector( '.is-focused' ); @@ -288,17 +288,17 @@ deleteClass( focusedElement, focusedClass ); } - // Add .is-focused class to top-level li + // Add .is-focused class to top-level li. if ( getCurrentParent( event.target, '.main-navigation > div > ul > li', '.main-navigation' ) ) { addClass( getCurrentParent( event.target, '.main-navigation > div > ul > li', '.main-navigation' ), focusedClass ); } - // Check for previous li + // Check for previous li. if ( prevLi && hasClass( prevLi, focusedClass ) ) { deleteClass( prevLi, focusedClass ); } - // Check for next li + // Check for next li. if ( nextLi && hasClass( nextLi, focusedClass ) ) { deleteClass( nextLi, focusedClass ); } @@ -308,25 +308,25 @@ document.addEventListener('click', function(event) { - // Remove all focused menu states when clicking outside site branding + // Remove all focused menu states when clicking outside site branding. if ( event.target !== document.getElementsByClassName( 'site-branding' )[0] ) { removeAllFocusStates(); } else { - // nothing + // Nothing. } }, false); } /** - * Run our sub-menu function as soon as the document is `ready` + * Run our sub-menu function as soon as the document is `ready`. */ document.addEventListener( 'DOMContentLoaded', function() { toggleSubmenuDisplay(); }); /** - * Run our sub-menu function on selective refresh in the customizer + * Run our sub-menu function on selective refresh in the customizer. */ document.addEventListener( 'customize-preview-menu-refreshed', function( e, params ) { if ( 'menu-1' === params.wpNavMenuArgs.theme_location ) { @@ -335,7 +335,7 @@ }); /** - * Run our sub-menu function every time the window resizes + * Run our sub-menu function every time the window resizes. */ var isResizing = false; window.addEventListener( 'resize', function() { diff --git a/src/wp-content/themes/twentynineteen/page.php b/src/wp-content/themes/twentynineteen/page.php index 16abcb2399..757e049e5b 100644 --- a/src/wp-content/themes/twentynineteen/page.php +++ b/src/wp-content/themes/twentynineteen/page.php @@ -17,7 +17,7 @@ get_header();
    diff --git a/src/wp-content/themes/twentynineteen/search.php b/src/wp-content/themes/twentynineteen/search.php index 25ab5c245d..af9d26540c 100644 --- a/src/wp-content/themes/twentynineteen/search.php +++ b/src/wp-content/themes/twentynineteen/search.php @@ -32,7 +32,8 @@ get_header(); /* * Include the Post-Format-specific template for the content. * If you want to override this in a child theme, then include a file - * called content-___.php (where ___ is the Post Format name) and that will be used instead. + * called content-___.php (where ___ is the Post Format name) and that + * will be used instead. */ get_template_part( 'template-parts/content/content', 'excerpt' ); diff --git a/src/wp-content/themes/twentynineteen/single.php b/src/wp-content/themes/twentynineteen/single.php index 830850ef7d..a2d7eac00e 100644 --- a/src/wp-content/themes/twentynineteen/single.php +++ b/src/wp-content/themes/twentynineteen/single.php @@ -17,7 +17,7 @@ get_header(); diff --git a/src/wp-content/themes/twentynineteen/template-parts/header/entry-header.php b/src/wp-content/themes/twentynineteen/template-parts/header/entry-header.php index 77491f0285..163436d4b1 100644 --- a/src/wp-content/themes/twentynineteen/template-parts/header/entry-header.php +++ b/src/wp-content/themes/twentynineteen/template-parts/header/entry-header.php @@ -24,7 +24,7 @@ $discussion = ! is_page() && twentynineteen_can_show_post_thumbnail() ? twentyni if ( have_posts() ) : ?> '; - // Make sure there's more than one category before displaying. + // 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 . ''; } @@ -133,7 +133,9 @@ 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; } @@ -148,8 +150,13 @@ function twentyseventeen_front_page_section( $partial = null, $id = 0 ) { wp_reset_postdata(); } elseif ( is_customize_preview() ) { // The output placeholder anchor. - /* translators: %s: The section ID. */ - echo '
    ' . sprintf( __( 'Front Page Section %s Placeholder', 'twentyseventeen' ), $id ) . '
    '; + printf( + '
    ' . + '%2$s
    ', + $id, + /* translators: %s: The section ID. */ + sprintf( __( 'Front Page Section %s Placeholder', 'twentyseventeen' ), $id ) + ); } } @@ -204,7 +211,7 @@ if ( ! function_exists( 'wp_body_open' ) ) : /** * Fire the wp_body_open action. * - * Added for backwards compatibility to support pre 5.2.0 WordPress versions. + * Added for backward compatibility to support pre-5.2.0 WordPress versions. * * @since Twenty Seventeen 2.2 */ diff --git a/src/wp-content/themes/twentyseventeen/index.php b/src/wp-content/themes/twentyseventeen/index.php index 1b6375545f..5df8f0231f 100644 --- a/src/wp-content/themes/twentyseventeen/index.php +++ b/src/wp-content/themes/twentyseventeen/index.php @@ -34,14 +34,15 @@ get_header(); ?> comments_template(); endif; - endwhile; // End of the loop. + endwhile; // End the loop. ?> diff --git a/src/wp-content/themes/twentyseventeen/search.php b/src/wp-content/themes/twentyseventeen/search.php index a1fd451a4d..ee62b22112 100644 --- a/src/wp-content/themes/twentyseventeen/search.php +++ b/src/wp-content/themes/twentyseventeen/search.php @@ -32,7 +32,7 @@ get_header(); ?> */ get_template_part( 'template-parts/post/content', 'excerpt' ); - endwhile; // End of the loop. + endwhile; // End the loop. the_posts_pagination( array( diff --git a/src/wp-content/themes/twentyseventeen/single.php b/src/wp-content/themes/twentyseventeen/single.php index ec68d5f4eb..541e2d24a9 100644 --- a/src/wp-content/themes/twentyseventeen/single.php +++ b/src/wp-content/themes/twentyseventeen/single.php @@ -17,7 +17,7 @@ get_header(); ?>
    ) ); - endwhile; // End of the loop. + endwhile; // End the loop. ?>
    diff --git a/src/wp-content/themes/twentysixteen/archive.php b/src/wp-content/themes/twentysixteen/archive.php index 079730f314..68a97fc537 100644 --- a/src/wp-content/themes/twentysixteen/archive.php +++ b/src/wp-content/themes/twentysixteen/archive.php @@ -31,14 +31,15 @@ get_header(); ?>
    diff --git a/src/wp-content/themes/twentysixteen/inc/customizer.php b/src/wp-content/themes/twentysixteen/inc/customizer.php index 370935802f..41f52667bc 100644 --- a/src/wp-content/themes/twentysixteen/inc/customizer.php +++ b/src/wp-content/themes/twentysixteen/inc/customizer.php @@ -103,7 +103,7 @@ if ( ! function_exists( 'twentysixteen_header_style' ) ) : 1 || is_preview() ) { - // This blog has more than 1 category so twentysixteen_categorized_blog should return true. + // 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. + // This blog has only 1 category so twentysixteen_categorized_blog() should return false. return false; } } @@ -271,7 +271,7 @@ if ( ! function_exists( 'wp_body_open' ) ) : /** * Fire the wp_body_open action. * - * Added for backwards compatibility to support pre 5.2.0 WordPress versions. + * Added for backward compatibility to support pre-5.2.0 WordPress versions. * * @since Twenty Sixteen 2.0 */ diff --git a/src/wp-content/themes/twentysixteen/index.php b/src/wp-content/themes/twentysixteen/index.php index f6ec56c1db..0a1a3e0173 100644 --- a/src/wp-content/themes/twentysixteen/index.php +++ b/src/wp-content/themes/twentysixteen/index.php @@ -35,7 +35,8 @@ get_header(); ?> /* * Include the Post-Format-specific template for the content. * If you want to override this in a child theme, then include a file - * called content-___.php (where ___ is the Post Format name) and that will be used instead. + * called content-___.php (where ___ is the Post Format name) and that + * will be used instead. */ get_template_part( 'template-parts/content', get_post_format() ); diff --git a/src/wp-content/themes/twentysixteen/page.php b/src/wp-content/themes/twentysixteen/page.php index a232c9fce1..f5d6b7adb9 100644 --- a/src/wp-content/themes/twentysixteen/page.php +++ b/src/wp-content/themes/twentysixteen/page.php @@ -28,7 +28,7 @@ get_header(); ?> comments_template(); } - // End of the loop. + // End the loop. endwhile; ?> diff --git a/src/wp-content/themes/twentysixteen/single.php b/src/wp-content/themes/twentysixteen/single.php index 3454170335..77a44d8692 100644 --- a/src/wp-content/themes/twentysixteen/single.php +++ b/src/wp-content/themes/twentysixteen/single.php @@ -45,7 +45,7 @@ get_header(); ?> ); } - // End of the loop. + // End the loop. endwhile; ?> diff --git a/src/wp-content/themes/twentyten/404.php b/src/wp-content/themes/twentyten/404.php index 914ef01089..c67f6ca502 100644 --- a/src/wp-content/themes/twentyten/404.php +++ b/src/wp-content/themes/twentyten/404.php @@ -23,7 +23,7 @@ get_header(); ?> diff --git a/src/wp-content/themes/twentyten/archive.php b/src/wp-content/themes/twentyten/archive.php index 4efb055049..36c5e0b3e2 100644 --- a/src/wp-content/themes/twentyten/archive.php +++ b/src/wp-content/themes/twentyten/archive.php @@ -49,9 +49,9 @@ if ( have_posts() ) { ← Older Comments', 'twentyten' ) ); ?> - +
      ← Older Comments', 'twentyten' ) ); ?> - +

      - + diff --git a/src/wp-content/themes/twentyten/functions.php b/src/wp-content/themes/twentyten/functions.php index 97f018d4ab..96629d1074 100644 --- a/src/wp-content/themes/twentyten/functions.php +++ b/src/wp-content/themes/twentyten/functions.php @@ -27,7 +27,7 @@ * * add_action( 'after_setup_theme', 'my_child_theme_setup' ); * function my_child_theme_setup() { - * // We are providing our own filter for excerpt_length (or using the unfiltered value) + * // We are providing our own filter for excerpt_length (or using the unfiltered value). * remove_filter( 'excerpt_length', 'twentyten_excerpt_length' ); * ... * } @@ -119,15 +119,15 @@ if ( ! function_exists( 'twentyten_setup' ) ) : // 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 + // This theme uses post thumbnails. add_theme_support( 'post-thumbnails' ); - // Add default posts and comments RSS feed links to head + // 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 + * Translations can be filed in the /languages/ directory. */ load_theme_textdomain( 'twentyten', get_template_directory() . '/languages' ); @@ -200,7 +200,7 @@ if ( ! function_exists( 'twentyten_setup' ) ) : */ set_post_thumbnail_size( $custom_header_support['width'], $custom_header_support['height'], true ); - // ... and thus ends the custom header business. + // ...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( @@ -394,7 +394,7 @@ add_filter( 'use_default_gallery_style', '__return_false' ); function twentyten_remove_gallery_css( $css ) { return preg_replace( "##s", '', $css ); } -// Backwards compatibility with WordPress 3.0. +// Backward compatibility with WordPress 3.0. if ( version_compare( $GLOBALS['wp_version'], '3.1', '<' ) ) { add_filter( 'gallery_style', 'twentyten_remove_gallery_css' ); } @@ -740,7 +740,7 @@ if ( ! function_exists( 'wp_body_open' ) ) : /** * Fire the wp_body_open action. * - * Added for backwards compatibility to support pre 5.2.0 WordPress versions. + * Added for backward compatibility to support pre-5.2.0 WordPress versions. * * @since Twenty Ten 2.9 */ diff --git a/src/wp-content/themes/twentyten/header.php b/src/wp-content/themes/twentyten/header.php index 6f3330796e..0349d0489c 100644 --- a/src/wp-content/themes/twentyten/header.php +++ b/src/wp-content/themes/twentyten/header.php @@ -86,7 +86,7 @@ if ( is_singular() && get_option( 'thread_comments' ) ) { $header_image_width = HEADER_IMAGE_WIDTH; } - // Check if this is a post or page, if it has a thumbnail, and if it's a big one + // 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 ) ) { $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( $header_image_width, $header_image_width ) ); if ( $image && $image[1] >= $header_image_width ) { @@ -105,15 +105,19 @@ if ( is_singular() && get_option( 'thread_comments' ) ) { ?> - +
      diff --git a/src/wp-content/themes/twentythirteen/functions.php b/src/wp-content/themes/twentythirteen/functions.php index 92723d4ea6..cf9718c76c 100644 --- a/src/wp-content/themes/twentythirteen/functions.php +++ b/src/wp-content/themes/twentythirteen/functions.php @@ -494,7 +494,7 @@ if ( ! function_exists( 'twentythirteen_entry_meta' ) ) : echo '' . $tag_list . ''; } - // Post author + // Post author. if ( 'post' == get_post_type() ) { printf( '', @@ -592,11 +592,11 @@ if ( ! function_exists( 'twentythirteen_the_attached_image' ) ) : } } - // get the URL of the next image attachment... if ( $next_id ) { + // ...get the URL of the next image attachment. $next_attachment_url = get_attachment_link( $next_id ); } else { - // or get the URL of the first image attachment. + // ...or get the URL of the first image attachment. $next_attachment_url = get_attachment_link( reset( $attachment_ids ) ); } } @@ -812,7 +812,7 @@ if ( ! function_exists( 'wp_body_open' ) ) : /** * Fire the wp_body_open action. * - * Added for backwards compatibility to support pre 5.2.0 WordPress versions. + * Added for backward compatibility to support pre-5.2.0 WordPress versions. * * @since Twenty Thirteen 2.8 */ diff --git a/src/wp-content/themes/twentythirteen/image.php b/src/wp-content/themes/twentythirteen/image.php index 1ebbfc7af5..9404b1215e 100644 --- a/src/wp-content/themes/twentythirteen/image.php +++ b/src/wp-content/themes/twentythirteen/image.php @@ -15,7 +15,7 @@ get_header(); ?>
      @@ -94,7 +94,7 @@ get_header(); ?> - +
      diff --git a/src/wp-content/themes/twentythirteen/index.php b/src/wp-content/themes/twentythirteen/index.php index ec8de084dd..c68b3379e4 100644 --- a/src/wp-content/themes/twentythirteen/index.php +++ b/src/wp-content/themes/twentythirteen/index.php @@ -20,8 +20,8 @@ get_header(); ?>
      - diff --git a/src/wp-content/themes/twentythirteen/page.php b/src/wp-content/themes/twentythirteen/page.php index 5fad9750e0..3a95900951 100644 --- a/src/wp-content/themes/twentythirteen/page.php +++ b/src/wp-content/themes/twentythirteen/page.php @@ -16,8 +16,8 @@ get_header(); ?>
      - diff --git a/src/wp-content/themes/twentythirteen/search.php b/src/wp-content/themes/twentythirteen/search.php index 2193ed4771..a94d48a2c9 100644 --- a/src/wp-content/themes/twentythirteen/search.php +++ b/src/wp-content/themes/twentythirteen/search.php @@ -23,8 +23,8 @@ get_header(); ?> - diff --git a/src/wp-content/themes/twentythirteen/single.php b/src/wp-content/themes/twentythirteen/single.php index 587ae86561..a5f7eeaa3c 100644 --- a/src/wp-content/themes/twentythirteen/single.php +++ b/src/wp-content/themes/twentythirteen/single.php @@ -12,8 +12,8 @@ get_header(); ?>
      - diff --git a/src/wp-content/themes/twentythirteen/tag.php b/src/wp-content/themes/twentythirteen/tag.php index dd020d6e64..bda7ed7be4 100644 --- a/src/wp-content/themes/twentythirteen/tag.php +++ b/src/wp-content/themes/twentythirteen/tag.php @@ -25,13 +25,13 @@ get_header(); ?> ?> - +
      - diff --git a/src/wp-content/themes/twentythirteen/taxonomy-post_format.php b/src/wp-content/themes/twentythirteen/taxonomy-post_format.php index 18673dd360..646d410625 100644 --- a/src/wp-content/themes/twentythirteen/taxonomy-post_format.php +++ b/src/wp-content/themes/twentythirteen/taxonomy-post_format.php @@ -28,8 +28,8 @@ get_header(); ?> - diff --git a/src/wp-content/themes/twentytwelve/archive.php b/src/wp-content/themes/twentytwelve/archive.php index cb4d429f6b..b44a1c6c9f 100644 --- a/src/wp-content/themes/twentytwelve/archive.php +++ b/src/wp-content/themes/twentytwelve/archive.php @@ -43,12 +43,13 @@ get_header(); ?> @@ -77,8 +79,8 @@ get_header(); ?>
      - diff --git a/src/wp-content/themes/twentytwelve/category.php b/src/wp-content/themes/twentytwelve/category.php index 5d68df5454..ec8ce43f94 100644 --- a/src/wp-content/themes/twentytwelve/category.php +++ b/src/wp-content/themes/twentytwelve/category.php @@ -25,18 +25,19 @@ get_header(); ?> ?> - +
    - 1 && get_option( 'page_comments' ) ) : // are there comments to navigate through ?> + 1 && get_option( 'page_comments' ) ) : // Are there comments to navigate through? ?> - + - +
    @@ -58,7 +58,10 @@
    ', '' ); ?> - +
    diff --git a/src/wp-content/themes/twentytwelve/functions.php b/src/wp-content/themes/twentytwelve/functions.php index 04da105b06..86c5f1130f 100644 --- a/src/wp-content/themes/twentytwelve/functions.php +++ b/src/wp-content/themes/twentytwelve/functions.php @@ -120,7 +120,7 @@ function twentytwelve_setup() { // This theme uses a custom image size for featured images, displayed on "standard" posts. add_theme_support( 'post-thumbnails' ); - set_post_thumbnail_size( 624, 9999 ); // Unlimited height, soft crop + set_post_thumbnail_size( 624, 9999 ); // Unlimited height, soft crop. // Indicate widget sidebars can use selective refresh in the Customizer. add_theme_support( 'customize-selective-refresh-widgets' ); @@ -482,7 +482,7 @@ if ( ! function_exists( 'twentytwelve_comment' ) ) : if ( $attachment->ID == $post->ID ) { break; } -endforeach; + endforeach; - // If there is more than 1 attachment in a gallery + // If there is more than 1 attachment in a gallery... if ( count( $attachments ) > 1 ) : $k++; if ( isset( $attachments[ $k ] ) ) : - // get the URL of the next image attachment + // ...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 + // ...or get the URL of the first image attachment. $next_attachment_url = get_attachment_link( $attachments[0]->ID ); endif; -else : - // or, if there's only 1 image, get the URL of the image - $next_attachment_url = wp_get_attachment_url(); -endif; -?> + else : + // Or, if there's only 1 image, get the URL of the image. + $next_attachment_url = wp_get_attachment_url(); + endif; + ?> - ID, $attachment_size ); - ?> + ID, $attachment_size ); + ?> post_excerpt ) ) : ?> @@ -134,7 +134,7 @@ endif; - +
    diff --git a/src/wp-content/themes/twentytwelve/inc/custom-header.php b/src/wp-content/themes/twentytwelve/inc/custom-header.php index 636309b7c9..c985246f8b 100644 --- a/src/wp-content/themes/twentytwelve/inc/custom-header.php +++ b/src/wp-content/themes/twentytwelve/inc/custom-header.php @@ -70,7 +70,7 @@ add_action( 'admin_print_styles-appearance_page_custom-header', 'twentytwelve_cu function twentytwelve_header_style() { $text_color = get_header_textcolor(); - // If no custom options for text are set, let's bail + // If no custom options for text are set, let's bail. if ( $text_color == get_theme_support( 'custom-header', 'default-text-color' ) ) { return; } diff --git a/src/wp-content/themes/twentytwelve/index.php b/src/wp-content/themes/twentytwelve/index.php index c8bdc64a54..98649a8413 100644 --- a/src/wp-content/themes/twentytwelve/index.php +++ b/src/wp-content/themes/twentytwelve/index.php @@ -20,8 +20,8 @@ get_header(); ?>
    - @@ -63,11 +63,11 @@ get_header(); ?>

    - + - + diff --git a/src/wp-content/themes/twentytwelve/js/theme-customizer.js b/src/wp-content/themes/twentytwelve/js/theme-customizer.js index 8bf094be54..c388997da9 100644 --- a/src/wp-content/themes/twentytwelve/js/theme-customizer.js +++ b/src/wp-content/themes/twentytwelve/js/theme-customizer.js @@ -18,7 +18,7 @@ } ); } ); - // Header text color + // Header text color. wp.customize( 'header_textcolor', function( value ) { value.bind( function( to ) { if ( 'blank' === to ) { diff --git a/src/wp-content/themes/twentytwelve/page-templates/front-page.php b/src/wp-content/themes/twentytwelve/page-templates/front-page.php index 72efd0102b..28ce766b90 100644 --- a/src/wp-content/themes/twentytwelve/page-templates/front-page.php +++ b/src/wp-content/themes/twentytwelve/page-templates/front-page.php @@ -29,7 +29,7 @@ get_header(); ?> - + diff --git a/src/wp-content/themes/twentytwelve/page-templates/full-width.php b/src/wp-content/themes/twentytwelve/page-templates/full-width.php index 13a1b39be9..370e76eaf8 100644 --- a/src/wp-content/themes/twentytwelve/page-templates/full-width.php +++ b/src/wp-content/themes/twentytwelve/page-templates/full-width.php @@ -25,7 +25,7 @@ get_header(); ?> ?> - + diff --git a/src/wp-content/themes/twentytwelve/page.php b/src/wp-content/themes/twentytwelve/page.php index cf75606bd2..7107a61ce5 100644 --- a/src/wp-content/themes/twentytwelve/page.php +++ b/src/wp-content/themes/twentytwelve/page.php @@ -23,7 +23,7 @@ get_header(); ?> ?> - + diff --git a/src/wp-content/themes/twentytwelve/search.php b/src/wp-content/themes/twentytwelve/search.php index 51c84522a3..99acfe4034 100644 --- a/src/wp-content/themes/twentytwelve/search.php +++ b/src/wp-content/themes/twentytwelve/search.php @@ -25,8 +25,8 @@ get_header(); ?> - diff --git a/src/wp-content/themes/twentytwelve/single.php b/src/wp-content/themes/twentytwelve/single.php index 10165cec39..4cc6a43a4b 100644 --- a/src/wp-content/themes/twentytwelve/single.php +++ b/src/wp-content/themes/twentytwelve/single.php @@ -27,7 +27,7 @@ get_header(); ?> - + diff --git a/src/wp-content/themes/twentytwelve/tag.php b/src/wp-content/themes/twentytwelve/tag.php index 6d42da5bc3..041427729d 100644 --- a/src/wp-content/themes/twentytwelve/tag.php +++ b/src/wp-content/themes/twentytwelve/tag.php @@ -25,19 +25,19 @@ get_header(); ?> ?> - +
    +// for interaction media features. Adapted from . twentytwenty.touchEnabled = { init: function() { @@ -95,21 +95,21 @@ twentytwenty.coverModals = { init: function() { if ( document.querySelector( '.cover-modal' ) ) { - // Handle cover modals when they're toggled + // Handle cover modals when they're toggled. this.onToggle(); - // When toggled, untoggle if visitor clicks on the wrapping element of the modal + // When toggled, untoggle if visitor clicks on the wrapping element of the modal. this.outsideUntoggle(); - // Close on escape key press + // Close on escape key press. this.closeOnEscape(); - // Hide and show modals before and after their animations have played out + // Hide and show modals before and after their animations have played out. this.hideAndShowModals(); } }, - // Handle cover modals when they're toggled + // Handle cover modals when they're toggled. onToggle: function() { document.querySelectorAll( '.cover-modal' ).forEach( function( element ) { element.addEventListener( 'toggled', function( event ) { @@ -122,7 +122,7 @@ twentytwenty.coverModals = { body.classList.remove( 'showing-modal' ); body.classList.add( 'hiding-modal' ); - // Remove the hiding class after a delay, when animations have been run + // Remove the hiding class after a delay, when animations have been run. setTimeout( function() { body.classList.remove( 'hiding-modal' ); }, 500 ); @@ -131,7 +131,7 @@ twentytwenty.coverModals = { } ); }, - // Close modal on outside click + // Close modal on outside click. outsideUntoggle: function() { document.addEventListener( 'click', function( event ) { var target = event.target; @@ -143,7 +143,7 @@ twentytwenty.coverModals = { }.bind( this ) ); }, - // Close modal on escape key press + // Close modal on escape key press. closeOnEscape: function() { document.addEventListener( 'keydown', function( event ) { if ( event.keyCode === 27 ) { @@ -155,7 +155,7 @@ twentytwenty.coverModals = { }.bind( this ) ); }, - // Hide and show modals before and after their animations have played out + // Hide and show modals before and after their animations have played out. hideAndShowModals: function() { var _doc = document, _win = window, @@ -188,7 +188,7 @@ twentytwenty.coverModals = { }; } - // Show the modal + // Show the modal. modals.forEach( function( modal ) { modal.addEventListener( 'toggle-target-before-inactive', function( event ) { var styles = htmlStyles(), @@ -221,7 +221,7 @@ twentytwenty.coverModals = { modal.classList.add( 'show-modal' ); } ); - // Hide the modal after a delay, so animations have time to play out + // Hide the modal after a delay, so animations have time to play out. modal.addEventListener( 'toggle-target-after-inactive', function( event ) { if ( event.target !== modal ) { return; @@ -254,24 +254,24 @@ twentytwenty.coverModals = { } ); }, - // Untoggle a modal + // Untoggle a modal. untoggleModal: function( modal ) { var modalTargetClass, modalToggle = false; - // If the modal has specified the string (ID or class) used by toggles to target it, untoggle the toggles with that target string - // The modal-target-string must match the string toggles use to target the modal + // If the modal has specified the string (ID or class) used by toggles to target it, untoggle the toggles with that target string. + // The modal-target-string must match the string toggles use to target the modal. if ( modal.dataset.modalTargetString ) { modalTargetClass = modal.dataset.modalTargetString; modalToggle = document.querySelector( '*[data-toggle-target="' + modalTargetClass + '"]' ); } - // If a modal toggle exists, trigger it so all of the toggle options are included + // If a modal toggle exists, trigger it so all of the toggle options are included. if ( modalToggle ) { modalToggle.click(); - // If one doesn't exist, just hide the modal + // If one doesn't exist, just hide the modal. } else { modal.classList.remove( 'active' ); } @@ -298,23 +298,23 @@ twentytwenty.intrinsicRatioVideos = { var ratio, iTargetWidth, container = video.parentNode; - // Skip videos we want to ignore + // Skip videos we want to ignore. if ( video.classList.contains( 'intrinsic-ignore' ) || video.parentNode.classList.contains( 'intrinsic-ignore' ) ) { return true; } if ( ! video.dataset.origwidth ) { - // Get the video element proportions + // Get the video element proportions. video.setAttribute( 'data-origwidth', video.width ); video.setAttribute( 'data-origheight', video.height ); } iTargetWidth = container.offsetWidth; - // Get ratio from proportions + // Get ratio from proportions. ratio = iTargetWidth / video.dataset.origwidth; - // Scale based on ratio, thus retaining proportions + // Scale based on ratio, thus retaining proportions. video.style.width = iTargetWidth + 'px'; video.style.height = ( video.dataset.origheight * ratio ) + 'px'; } ); @@ -328,7 +328,7 @@ twentytwenty.intrinsicRatioVideos = { twentytwenty.modalMenu = { init: function() { - // If the current menu item is in a sub level, expand all the levels higher up on load + // If the current menu item is in a sub level, expand all the levels higher up on load. this.expandLevel(); this.keepFocusInModal(); }, @@ -462,13 +462,13 @@ twentytwenty.toggles = { clickedEl: false, init: function() { - // Do the toggle + // Do the toggle. this.toggle(); - // Check for toggle/untoggle on resize + // Check for toggle/untoggle on resize. this.resizeCheck(); - // Check for untoggle on escape key press + // Check for untoggle on escape key press. this.untoggleOnEscapeKeyPress(); }, @@ -476,12 +476,12 @@ twentytwenty.toggles = { var target, timeOutTime, classToToggle, self = this, _doc = document, - // Get our targets + // Get our targets. toggle = element, targetString = toggle.dataset.toggleTarget, activeClass = 'active'; - // Elements to focus after modals are closed + // Elements to focus after modals are closed. if ( ! _doc.querySelectorAll( '.show-modal' ).length ) { self.clickedEl = _doc.activeElement; } @@ -492,17 +492,17 @@ twentytwenty.toggles = { target = _doc.querySelector( targetString ); } - // Trigger events on the toggle targets before they are toggled + // Trigger events on the toggle targets before they are toggled. if ( target.classList.contains( activeClass ) ) { target.dispatchEvent( twentytwenty.createEvent( 'toggle-target-before-active' ) ); } else { target.dispatchEvent( twentytwenty.createEvent( 'toggle-target-before-inactive' ) ); } - // Get the class to toggle, if specified + // Get the class to toggle, if specified. classToToggle = toggle.dataset.classToToggle ? toggle.dataset.classToToggle : activeClass; - // For cover modals, set a short timeout duration so the class animations have time to play out + // For cover modals, set a short timeout duration so the class animations have time to play out. timeOutTime = 0; if ( target.classList.contains( 'cover-modal' ) ) { @@ -515,36 +515,36 @@ twentytwenty.toggles = { newTarget = subMenued ? toggle.closest( '.menu-item' ).querySelector( '.sub-menu' ) : target, duration = toggle.dataset.toggleDuration; - // Toggle the target of the clicked toggle + // Toggle the target of the clicked toggle. if ( toggle.dataset.toggleType === 'slidetoggle' && ! instantly && duration !== '0' ) { twentytwentyMenuToggle( newTarget, duration ); } else { newTarget.classList.toggle( classToToggle ); } - // If the toggle target is 'next', only give the clicked toggle the active class + // If the toggle target is 'next', only give the clicked toggle the active class. if ( targetString === 'next' ) { toggle.classList.toggle( activeClass ); } else if ( target.classList.contains( 'sub-menu' ) ) { toggle.classList.toggle( activeClass ); } else { - // If not, toggle all toggles with this toggle target + // If not, toggle all toggles with this toggle target. _doc.querySelector( '*[data-toggle-target="' + targetString + '"]' ).classList.toggle( activeClass ); } - // Toggle aria-expanded on the toggle + // Toggle aria-expanded on the toggle. twentytwentyToggleAttribute( toggle, 'aria-expanded', 'true', 'false' ); if ( self.clickedEl && -1 !== toggle.getAttribute( 'class' ).indexOf( 'close-' ) ) { twentytwentyToggleAttribute( self.clickedEl, 'aria-expanded', 'true', 'false' ); } - // Toggle body class + // Toggle body class. if ( toggle.dataset.toggleBodyClass ) { _doc.body.classList.toggle( toggle.dataset.toggleBodyClass ); } - // Check whether to set focus + // Check whether to set focus. if ( toggle.dataset.setFocus ) { focusElement = _doc.querySelector( toggle.dataset.setFocus ); @@ -557,10 +557,10 @@ twentytwenty.toggles = { } } - // Trigger the toggled event on the toggle target + // Trigger the toggled event on the toggle target. target.dispatchEvent( twentytwenty.createEvent( 'toggled' ) ); - // Trigger events on the toggle targets after they are toggled + // Trigger events on the toggle targets after they are toggled. if ( target.classList.contains( activeClass ) ) { target.dispatchEvent( twentytwenty.createEvent( 'toggle-target-after-active' ) ); } else { @@ -569,7 +569,7 @@ twentytwenty.toggles = { }, timeOutTime ); }, - // Do the toggle + // Do the toggle. toggle: function() { var self = this; @@ -581,7 +581,7 @@ twentytwenty.toggles = { } ); }, - // Check for toggle/untoggle on screen resize + // Check for toggle/untoggle on screen resize. resizeCheck: function() { if ( document.querySelectorAll( '*[data-untoggle-above], *[data-untoggle-below], *[data-toggle-above], *[data-toggle-below]' ).length ) { window.addEventListener( 'resize', function() { @@ -594,12 +594,12 @@ twentytwenty.toggles = { toggleAbove = toggle.dataset.toggleAbove, toggleBelow = toggle.dataset.toggleBelow; - // If no width comparison is set, continue + // If no width comparison is set, continue. if ( ! unToggleAbove && ! unToggleBelow && ! toggleAbove && ! toggleBelow ) { return; } - // If the toggle width comparison is true, toggle the toggle + // If the toggle width comparison is true, toggle the toggle. if ( ( ( ( unToggleAbove && winWidth > unToggleAbove ) || ( unToggleBelow && winWidth < unToggleBelow ) ) && @@ -615,7 +615,7 @@ twentytwenty.toggles = { } }, - // Close toggle on escape key press + // Close toggle on escape key press. untoggleOnEscapeKeyPress: function() { document.addEventListener( 'keyup', function( event ) { if ( event.key === 'Escape' ) { @@ -631,9 +631,9 @@ twentytwenty.toggles = { }; // twentytwenty.toggles /** - * Is the DOM ready + * Is the DOM ready? * - * this implementation is coming from https://gomakethings.com/a-native-javascript-equivalent-of-jquerys-ready-method/ + * This implementation is coming from https://gomakethings.com/a-native-javascript-equivalent-of-jquerys-ready-method/ * * @param {Function} fn Callback function to run. */ @@ -650,12 +650,12 @@ function twentytwentyDomReady( fn ) { } twentytwentyDomReady( function() { - twentytwenty.toggles.init(); // Handle toggles - twentytwenty.coverModals.init(); // Handle cover modals - twentytwenty.intrinsicRatioVideos.init(); // Retain aspect ratio of videos on window resize - twentytwenty.modalMenu.init(); // Modal Menu - twentytwenty.primaryMenu.init(); // Primary Menu - twentytwenty.touchEnabled.init(); // Add class to body if device is touch-enabled + twentytwenty.toggles.init(); // Handle toggles. + twentytwenty.coverModals.init(); // Handle cover modals. + twentytwenty.intrinsicRatioVideos.init(); // Retain aspect ratio of videos on window resize. + twentytwenty.modalMenu.init(); // Modal Menu. + twentytwenty.primaryMenu.init(); // Primary Menu. + twentytwenty.touchEnabled.init(); // Add class to body if device is touch-enabled. } ); /* ----------------------------------------------------------------------------------------------- @@ -717,9 +717,11 @@ function twentytwentyMenuToggle( target, duration ) { // The whole process happens without giving the browser a chance to render, so it's invisible. target.classList.toggle( 'active' ); - // Step 4: prepare animation. - // Position all the items with absolute offsets, at the same starting position. - // Shouldn't result in any visual changes if done right. + /* + * Step 4: prepare animation. + * Position all the items with absolute offsets, at the same starting position. + * Shouldn't result in any visual changes if done right. + */ menu.classList.add( 'is-toggling' ); target.classList.toggle( 'active' ); menuItems.forEach( function( menuItem, index ) { @@ -730,15 +732,19 @@ function twentytwentyMenuToggle( target, duration ) { menuItem.style.transform = 'translate(' + initialPosition.x + 'px, ' + initialPosition.y + 'px)'; } ); - // The double rAF is unfortunately needed, since we're toggling CSS classes, and - // the only way to ensure layout completion here across browsers is to wait twice. - // This just delays the start of the animation by 2 frames and is thus not an issue. + /* + * The double rAF is unfortunately needed, since we're toggling CSS classes, and + * the only way to ensure layout completion here across browsers is to wait twice. + * This just delays the start of the animation by 2 frames and is thus not an issue. + */ requestAnimationFrame( function() { requestAnimationFrame( function() { - // Step 5: start animation by moving everything to final position. - // All the layout work has already happened, while we were preparing for the animation. - // The animation now runs entirely in CSS, using cheap CSS properties (opacity and transform) - // that don't trigger the layout or paint stages. + /* + * Step 5: start animation by moving everything to final position. + * All the layout work has already happened, while we were preparing for the animation. + * The animation now runs entirely in CSS, using cheap CSS properties (opacity and transform) + * that don't trigger the layout or paint stages. + */ menu.classList.add( 'is-animating' ); menuItems.forEach( function( menuItem, index ) { var finalPosition = finalPositions[ index ]; @@ -774,7 +780,7 @@ function twentytwentyMenuToggle( target, duration ) { } /** - * traverses the DOM up to find elements matching the query + * Traverses the DOM up to find elements matching the query. * * @param {HTMLElement} target * @param {string} query @@ -783,7 +789,7 @@ function twentytwentyMenuToggle( target, duration ) { function twentytwentyFindParents( target, query ) { var parents = []; - // recursively go up the DOM adding matches to the parents array + // Recursively go up the DOM adding matches to the parents array. function traverse( item ) { var parent = item.parentNode; if ( parent instanceof HTMLElement ) { diff --git a/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-non-latin-languages.php b/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-non-latin-languages.php index ef1f2e66c2..df95c56a37 100644 --- a/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-non-latin-languages.php +++ b/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-non-latin-languages.php @@ -26,7 +26,7 @@ if ( ! class_exists( 'TwentyTwenty_Non_Latin_Languages' ) ) { */ public static function get_non_latin_css( $type = 'front-end' ) { - // Fetch users locale. + // Fetch site locale. $locale = get_bloginfo( 'language' ); // Define fallback fonts for non-latin languages. diff --git a/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-script-loader.php b/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-script-loader.php index 88ccf641f9..cc05187bcb 100644 --- a/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-script-loader.php +++ b/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-script-loader.php @@ -29,7 +29,7 @@ if ( ! class_exists( 'TwentyTwenty_Script_Loader' ) ) { * @return string Script HTML string. */ public function filter_script_loader_tag( $tag, $handle ) { - foreach ( [ 'async', 'defer' ] as $attr ) { + foreach ( array( 'async', 'defer' ) as $attr ) { if ( ! wp_scripts()->get_data( $handle, $attr ) ) { continue; } diff --git a/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-svg-icons.php b/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-svg-icons.php index 4dcf4d59f4..6193d3cd68 100644 --- a/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-svg-icons.php +++ b/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-svg-icons.php @@ -32,10 +32,10 @@ if ( ! class_exists( 'TwentyTwenty_SVG_Icons' ) ) { if ( array_key_exists( $icon, $arr ) ) { $repl = '\s*<', $svg ); // Remove white space between SVG tags. + $svg = preg_replace( '/>\s*<', $svg ); // Remove whitespace between SVG tags. return $svg; } return null; diff --git a/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-walker-comment.php b/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-walker-comment.php index 727817c75e..eda038e3c8 100644 --- a/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-walker-comment.php +++ b/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-walker-comment.php @@ -33,7 +33,7 @@ if ( ! class_exists( 'TwentyTwenty_Walker_Comment' ) ) { $tag = ( 'div' === $args['style'] ) ? 'div' : 'li'; ?> - < id="comment-" has_children ? 'parent' : '', $comment ); ?>> + < id="comment-" has_children ? 'parent' : '', $comment ); ?>>
    @@ -45,7 +45,7 @@ if ( ! class_exists( 'TwentyTwenty_Walker_Comment' ) ) { if ( empty( $comment_author_url ) ) { echo wp_kses_post( $avatar ); } else { - printf( '', $comment_author_url ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped --Escaped in https://developer.wordpress.org/reference/functions/get_comment_author_url/ + printf( '', $comment_author_url ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped --Escaped in https://developer.wordpress.org/reference/functions/get_comment_author_url/ echo wp_kses_post( $avatar ); } } @@ -65,7 +65,7 @@ if ( ! class_exists( 'TwentyTwenty_Walker_Comment' ) ) {
    '; @@ -2236,7 +2236,7 @@ function get_calendar( $initial = true, $echo = true ) { } if ( in_array( $day, $daywithpost ) ) { - // any posts today? + // Any posts today? $date_format = gmdate( _x( 'F j, Y', 'daily archives date format' ), strtotime( "{$thisyear}-{$thismonth}-{$day}" ) ); /* translators: Post calendar label. %s: Date. */ $label = sprintf( __( 'Posts published on %s' ), $date_format ); @@ -3339,7 +3339,7 @@ function user_can_richedit() { if ( ! isset( $wp_rich_edit ) ) { $wp_rich_edit = false; - if ( get_user_option( 'rich_editing' ) == 'true' || ! is_user_logged_in() ) { // default to 'true' for logged out users + if ( get_user_option( 'rich_editing' ) == 'true' || ! is_user_logged_in() ) { // Default to 'true' for logged out users. if ( $is_safari ) { $wp_rich_edit = ! wp_is_mobile() || ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && intval( $match[1] ) >= 534 ); } elseif ( $is_IE ) { @@ -3371,8 +3371,8 @@ function user_can_richedit() { * @return string Either 'tinymce', or 'html', or 'test' */ function wp_default_editor() { - $r = user_can_richedit() ? 'tinymce' : 'html'; // defaults - if ( wp_get_current_user() ) { // look for cookie + $r = user_can_richedit() ? 'tinymce' : 'html'; // Defaults. + if ( wp_get_current_user() ) { // Look for cookie. $ed = get_user_setting( 'editor', 'tinymce' ); $r = ( in_array( $ed, array( 'tinymce', 'html', 'test' ) ) ) ? $ed : $r; } @@ -4094,8 +4094,8 @@ function paginate_links( $args = '' ) { $format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%'; $defaults = array( - 'base' => $pagenum_link, // http://example.com/all_posts.php%_% : %_% is replaced by format (below) - 'format' => $format, // ?page=%#% : %#% is replaced by the page number + 'base' => $pagenum_link, // http://example.com/all_posts.php%_% : %_% is replaced by format (below). + 'format' => $format, // ?page=%#% : %#% is replaced by the page number. 'total' => $total, 'current' => $current, 'aria_current' => 'page', @@ -4106,7 +4106,7 @@ function paginate_links( $args = '' ) { 'end_size' => 1, 'mid_size' => 2, 'type' => 'plain', - 'add_args' => array(), // array of query args to add + 'add_args' => array(), // Array of query args to add. 'add_fragment' => '', 'before_page_number' => '', 'after_page_number' => '', @@ -4136,13 +4136,13 @@ function paginate_links( $args = '' ) { $args['add_args'] = array_merge( $args['add_args'], urlencode_deep( $url_query_args ) ); } - // Who knows what else people pass in $args + // Who knows what else people pass in $args. $total = (int) $args['total']; if ( $total < 2 ) { return; } $current = (int) $args['current']; - $end_size = (int) $args['end_size']; // Out of bounds? Make it the default. + $end_size = (int) $args['end_size']; // Out of bounds? Make it the default. if ( $end_size < 1 ) { $end_size = 1; } @@ -4313,7 +4313,7 @@ function register_admin_color_schemes() { ) ); - // Other color schemes are not available when running out of src + // Other color schemes are not available when running out of src. if ( false !== strpos( get_bloginfo( 'version' ), '-src' ) ) { return; } diff --git a/src/wp-includes/http.php b/src/wp-includes/http.php index 0e6a357927..0a91418e45 100644 --- a/src/wp-includes/http.php +++ b/src/wp-includes/http.php @@ -368,7 +368,7 @@ function wp_http_supports( $capabilities = array(), $url = null ) { $count = count( $capabilities ); - // If we have a numeric $capabilities array, spoof a wp_remote_request() associative $args array + // If we have a numeric $capabilities array, spoof a wp_remote_request() associative $args array. if ( $count && count( array_filter( array_keys( $capabilities ), 'is_numeric' ) ) == $count ) { $capabilities = array_combine( array_values( $capabilities ), array_fill( 0, $count, true ) ); } @@ -417,7 +417,7 @@ function get_allowed_http_origins() { $admin_origin = parse_url( admin_url() ); $home_origin = parse_url( home_url() ); - // @todo preserve port? + // @todo Preserve port? $allowed_origins = array_unique( array( 'http://' . $admin_origin['host'], @@ -549,7 +549,7 @@ function wp_http_validate_url( $url ) { $ip = $host; } else { $ip = gethostbyname( $host ); - if ( $ip === $host ) { // Error condition for gethostbyname() + if ( $ip === $host ) { // Error condition for gethostbyname(). return false; } } diff --git a/src/wp-includes/kses.php b/src/wp-includes/kses.php index 179aaebd5b..32a5a04f2a 100644 --- a/src/wp-includes/kses.php +++ b/src/wp-includes/kses.php @@ -1052,9 +1052,9 @@ function wp_kses_split2( $string, $allowed_html, $allowed_protocols ) { if ( $string == '' ) { return ''; } - // prevent multiple dashes in comments + // Prevent multiple dashes in comments. $string = preg_replace( '/--+/', '-', $string ); - // prevent three dashes closing a comment + // Prevent three dashes closing a comment. $string = preg_replace( '/-$/', '', $string ); return ""; } @@ -1119,11 +1119,11 @@ function wp_kses_attr( $element, $attr, $allowed_html, $allowed_protocols ) { return "<$element$xhtml_slash>"; } - // Split it + // Split it. $attrarr = wp_kses_hair( $attr, $allowed_protocols ); // Go through $attrarr, and save the allowed attributes for this element - // in $attr2 + // in $attr2. $attr2 = ''; foreach ( $attrarr as $arreach ) { if ( wp_kses_attr_check( $arreach['name'], $arreach['value'], $arreach['whole'], $arreach['vless'], $element, $allowed_html ) ) { @@ -1131,7 +1131,7 @@ function wp_kses_attr( $element, $attr, $allowed_html, $allowed_protocols ) { } } - // Remove any "<" or ">" characters + // Remove any "<" or ">" characters. $attr2 = preg_replace( '/[<>]/', '', $attr2 ); return "<$element$attr2$xhtml_slash>"; @@ -1204,7 +1204,7 @@ function wp_kses_attr_check( &$name, &$value, &$whole, $vless, $element, $allowe } if ( is_array( $allowed_attr[ $name_low ] ) ) { - // there are some checks + // There are some checks. foreach ( $allowed_attr[ $name_low ] as $currkey => $currval ) { if ( ! wp_kses_check_attr_val( $value, $vless, $currkey, $currval ) ) { $name = ''; @@ -1241,7 +1241,7 @@ function wp_kses_hair( $attr, $allowed_protocols ) { $attrname = ''; $uris = wp_kses_uri_attributes(); - // Loop through the whole attribute list + // Loop through the whole attribute list. while ( strlen( $attr ) != 0 ) { $working = 0; // Was the last operation successful? @@ -1258,14 +1258,14 @@ function wp_kses_hair( $attr, $allowed_protocols ) { break; case 1: - if ( preg_match( '/^\s*=\s*/', $attr ) ) { // equals sign + if ( preg_match( '/^\s*=\s*/', $attr ) ) { // Equals sign. $working = 1; $mode = 2; $attr = preg_replace( '/^\s*=\s*/', '', $attr ); break; } - if ( preg_match( '/^\s+/', $attr ) ) { // valueless + if ( preg_match( '/^\s+/', $attr ) ) { // Valueless. $working = 1; $mode = 0; if ( false === array_key_exists( $attrname, $attrarr ) ) { @@ -1346,17 +1346,17 @@ function wp_kses_hair( $attr, $allowed_protocols ) { } break; - } // switch + } // End switch. - if ( $working == 0 ) { // not well formed, remove and try again + if ( $working == 0 ) { // Not well-formed, remove and try again. $attr = wp_kses_html_error( $attr ); $mode = 0; } - } // while + } // End while. if ( $mode == 1 && false === array_key_exists( $attrname, $attrarr ) ) { - // special case, for when the attribute list ends with a valueless - // attribute like "selected" + // Special case, for when the attribute list ends with a valueless + // attribute like "selected". $attrarr[ $attrname ] = array( 'name' => $attrname, 'value' => '', @@ -1405,7 +1405,7 @@ function wp_kses_attr_parse( $element ) { $xhtml_slash = ''; } - // Split it + // Split it. $attrarr = wp_kses_hair_parse( $attr ); if ( false === $attrarr ) { return false; @@ -1444,14 +1444,14 @@ function wp_kses_hair_parse( $attr ) { . '\[\[?[^\[\]]+\]\]?' // Shortcode in the name position implies unfiltered_html. . ')' . '(?:' // Attribute value. - . '\s*=\s*' // All values begin with '=' + . '\s*=\s*' // All values begin with '='. . '(?:' - . '"[^"]*"' // Double-quoted + . '"[^"]*"' // Double-quoted. . '|' - . "'[^']*'" // Single-quoted + . "'[^']*'" // Single-quoted. . '|' - . '[^\s"\']+' // Non-quoted - . '(?:\s|$)' // Must have a space + . '[^\s"\']+' // Non-quoted. + . '(?:\s|$)' // Must have a space. . ')' . '|' . '(?:\s|$)' // If attribute has no value, space is required. @@ -1492,9 +1492,11 @@ function wp_kses_check_attr_val( $value, $vless, $checkname, $checkvalue ) { switch ( strtolower( $checkname ) ) { case 'maxlen': - // The maxlen check makes sure that the attribute value has a length not - // greater than the given value. This can be used to avoid Buffer Overflows - // in WWW clients and various Internet servers. + /* + * The maxlen check makes sure that the attribute value has a length not + * greater than the given value. This can be used to avoid Buffer Overflows + * in WWW clients and various Internet servers. + */ if ( strlen( $value ) > $checkvalue ) { $ok = false; @@ -1502,8 +1504,10 @@ function wp_kses_check_attr_val( $value, $vless, $checkname, $checkvalue ) { break; case 'minlen': - // The minlen check makes sure that the attribute value has a length not - // smaller than the given value. + /* + * The minlen check makes sure that the attribute value has a length not + * smaller than the given value. + */ if ( strlen( $value ) < $checkvalue ) { $ok = false; @@ -1511,11 +1515,13 @@ function wp_kses_check_attr_val( $value, $vless, $checkname, $checkvalue ) { break; case 'maxval': - // The maxval check does two things: it checks that the attribute value is - // an integer from 0 and up, without an excessive amount of zeroes or - // whitespace (to avoid Buffer Overflows). It also checks that the attribute - // value is not greater than the given value. - // This check can be used to avoid Denial of Service attacks. + /* + * The maxval check does two things: it checks that the attribute value is + * an integer from 0 and up, without an excessive amount of zeroes or + * whitespace (to avoid Buffer Overflows). It also checks that the attribute + * value is not greater than the given value. + * This check can be used to avoid Denial of Service attacks. + */ if ( ! preg_match( '/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value ) ) { $ok = false; @@ -1526,8 +1532,10 @@ function wp_kses_check_attr_val( $value, $vless, $checkname, $checkvalue ) { break; case 'minval': - // The minval check makes sure that the attribute value is a positive integer, - // and that it is not smaller than the given value. + /* + * The minval check makes sure that the attribute value is a positive integer, + * and that it is not smaller than the given value. + */ if ( ! preg_match( '/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value ) ) { $ok = false; @@ -1538,16 +1546,18 @@ function wp_kses_check_attr_val( $value, $vless, $checkname, $checkvalue ) { break; case 'valueless': - // The valueless check makes sure if the attribute has a value - // (like ``) or not (``) or not (`
  • ' . $args['link_before'] . $text . $args['link_after'] . '
  • '; - // If the front page is a page, add it to the exclude list + // 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'] ) ) { $list_args['exclude'] .= ','; @@ -1457,7 +1459,7 @@ function wp_page_menu( $args = array() ) { if ( $menu ) { - // wp_nav_menu doesn't set before and after + // wp_nav_menu() doesn't set before and after. if ( isset( $args['fallback_cb'] ) && 'wp_page_menu' === $args['fallback_cb'] && 'ul' !== $container ) { @@ -1499,7 +1501,7 @@ function wp_page_menu( $args = array() ) { } // -// Page helpers +// Page helpers. // /** @@ -1543,7 +1545,7 @@ function walk_page_tree( $pages, $depth, $current_page, $r ) { * @return string */ function walk_page_dropdown_tree( ...$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 { $walker = $args[2]['walker']; @@ -1553,7 +1555,7 @@ function walk_page_dropdown_tree( ...$args ) { } // -// Attachments +// Attachments. // /** @@ -1671,7 +1673,7 @@ function prepend_attachment( $content ) { $p = wp_audio_shortcode( array( 'src' => wp_get_attachment_url() ) ); } else { $p = '

    '; - // show the medium sized image representation of the attachment if available, and link to the raw file + // 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 .= '

    '; } @@ -1691,7 +1693,7 @@ function prepend_attachment( $content ) { } // -// Misc +// Misc. // /** @@ -1916,7 +1918,7 @@ function wp_list_post_revisions( $post_id = 0, $type = 'all' ) { return; } - // $args array with (parent, format, right, left, type) deprecated since 3.6 + // $args array with (parent, format, right, left, type) deprecated since 3.6. if ( is_array( $type ) ) { $type = ! empty( $type['type'] ) ? $type['type'] : $type; _deprecated_argument( __FUNCTION__, '3.6.0' ); diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 3799e73e0a..0e09610521 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -7,7 +7,7 @@ */ // -// Post Type Registration +// Post Type registration. // /** @@ -715,7 +715,7 @@ function get_children( $args = '', $output = OBJECT ) { * } */ function get_extended( $post ) { - //Match the new style more links. + // Match the new style more links. if ( preg_match( '//', $post, $matches ) ) { list($main, $extended) = explode( $matches[0], $post, 2 ); $more_text = $matches[1]; @@ -725,7 +725,7 @@ function get_extended( $post ) { $more_text = ''; } - // leading and trailing whitespace. + // 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 ); @@ -1416,7 +1416,7 @@ function register_post_type( $post_type, $args = array() ) { $wp_post_types = array(); } - // Sanitize post type name + // Sanitize post type name. $post_type = sanitize_key( $post_type ); if ( empty( $post_type ) || strlen( $post_type ) > 20 ) { @@ -1558,7 +1558,7 @@ function get_post_type_capabilities( $args ) { list( $singular_base, $plural_base ) = $args->capability_type; $default_capabilities = array( - // Meta capabilities + // Meta capabilities. 'edit_post' => 'edit_' . $singular_base, 'read_post' => 'read_' . $singular_base, 'delete_post' => 'delete_' . $singular_base, @@ -2033,7 +2033,7 @@ function get_posts( $args = null ) { } if ( ! empty( $parsed_args['include'] ) ) { $incposts = wp_parse_id_list( $parsed_args['include'] ); - $parsed_args['posts_per_page'] = count( $incposts ); // only the number of posts included + $parsed_args['posts_per_page'] = count( $incposts ); // Only the number of posts included. $parsed_args['post__in'] = $incposts; } elseif ( ! empty( $parsed_args['exclude'] ) ) { $parsed_args['post__not_in'] = wp_parse_id_list( $parsed_args['exclude'] ); @@ -2048,7 +2048,7 @@ function get_posts( $args = null ) { } // -// Post meta functions +// Post meta functions. // /** @@ -2713,7 +2713,7 @@ 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 ) + $post_mime_types = array( // array( adj, noun ) 'image' => array( __( 'Images' ), __( 'Manage Images' ), @@ -4274,7 +4274,7 @@ function check_and_publish_future_post( $post_id ) { // Uh oh, someone jumped the gun! if ( $time > time() ) { - wp_clear_scheduled_hook( 'publish_future_post', array( $post_id ) ); // clear anything else in the system + wp_clear_scheduled_hook( 'publish_future_post', array( $post_id ) ); // Clear anything else in the system. wp_schedule_single_event( $time, 'publish_future_post', array( $post_id ) ); return; } @@ -4832,7 +4832,7 @@ function trackback_url_list( $tb_list, $post_id ) { } // -// Page functions +// Page functions. // /** @@ -5266,7 +5266,7 @@ function get_pages( $args = array() ) { $inclusions = ''; if ( ! empty( $parsed_args['include'] ) ) { - $child_of = 0; //ignore child_of, parent, exclude, meta_key, and meta_value params if using include + $child_of = 0; // Ignore child_of, parent, exclude, meta_key, and meta_value params if using include. $parent = -1; $exclude = ''; $meta_key = ''; @@ -5292,7 +5292,7 @@ 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? + // Do we have an author id or an author login? if ( 0 == intval( $post_author ) ) { $post_author = get_user_by( 'login', $post_author ); if ( empty( $post_author ) ) { @@ -5321,7 +5321,7 @@ function get_pages( $args = array() ) { 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 and meta_value might be slashed. $meta_key = wp_unslash( $meta_key ); $meta_value = wp_unslash( $meta_value ); if ( '' !== $meta_key ) { @@ -5461,7 +5461,7 @@ function get_pages( $args = array() ) { wp_cache_set( $cache_key, $page_structure, 'posts' ); - // Convert to WP_Post instances + // Convert to WP_Post instances. $pages = array_map( 'get_post', $pages ); /** @@ -5476,7 +5476,7 @@ function get_pages( $args = array() ) { } // -// Attachment functions +// Attachment functions. // /** @@ -5833,7 +5833,7 @@ function wp_get_attachment_url( $attachment_id = 0 ) { // Replace file location with url location. $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) + // 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 ) ) . wp_basename( $file ); } else { // It's a newly-uploaded file, therefore $file is relative to the basedir. @@ -6353,8 +6353,8 @@ function get_posts_by_author_sql( $post_type, $full = true, $post_author = null, $post_status_sql .= " OR post_status = 'private' AND post_author = $id"; } elseif ( $id == (int) $post_author ) { $post_status_sql .= " OR post_status = 'private'"; - } // else none - } // else none + } // Else none. + } // Else none. } $post_type_clauses[] = "( post_type = '" . $post_type . "' AND ( $post_status_sql ) )"; @@ -6712,7 +6712,7 @@ function clean_attachment_cache( $id, $clean_terms = false ) { } // -// Hooks +// Hooks. // /** @@ -6874,7 +6874,7 @@ function wp_check_post_hierarchy_for_loops( $post_parent, $post_ID ) { // Now look for larger loops. $loop = wp_find_hierarchy_loop( 'wp_get_post_parent_id', $post_ID, $post_parent ); if ( ! $loop ) { - return $post_parent; // No loop + return $post_parent; // No loop. } // Setting $post_parent to the given value causes a loop. diff --git a/src/wp-includes/query.php b/src/wp-includes/query.php index 24b97990b0..f1053aac7b 100644 --- a/src/wp-includes/query.php +++ b/src/wp-includes/query.php @@ -998,7 +998,7 @@ function the_comment() { */ function wp_old_slug_redirect() { if ( is_404() && '' !== get_query_var( 'name' ) ) { - // Guess the current post_type based on the query vars. + // Guess the current post type based on the query vars. if ( get_query_var( 'post_type' ) ) { $post_type = get_query_var( 'post_type' ); } elseif ( get_query_var( 'attachment' ) ) { @@ -1016,7 +1016,7 @@ function wp_old_slug_redirect() { $post_type = reset( $post_type ); } - // Do not attempt redirect for hierarchical post types + // Do not attempt redirect for hierarchical post types. if ( is_post_type_hierarchical( $post_type ) ) { return; } @@ -1061,7 +1061,7 @@ function wp_old_slug_redirect() { return; } - wp_redirect( $link, 301 ); // Permanent redirect + wp_redirect( $link, 301 ); // Permanent redirect. exit; } } @@ -1084,8 +1084,8 @@ function _find_post_by_old_slug( $post_type ) { $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 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' ) ); } @@ -1133,7 +1133,7 @@ function _find_post_by_old_date( $post_type ) { $id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta AS pm_date, $wpdb->posts WHERE ID = post_id AND post_type = %s AND meta_key = '_wp_old_date' AND post_name = %s" . $date_query, $post_type, get_query_var( 'name' ) ) ); if ( ! $id ) { - // Check to see if an old slug matches the old date + // Check to see if an old slug matches the old date. $id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts, $wpdb->postmeta AS pm_slug, $wpdb->postmeta AS pm_date WHERE ID = pm_slug.post_id AND ID = pm_date.post_id AND post_type = %s AND pm_slug.meta_key = '_wp_old_slug' AND pm_slug.meta_value = %s AND pm_date.meta_key = '_wp_old_date'" . $date_query, $post_type, get_query_var( 'name' ) ) ); } } diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index 8fbf4b1342..93fef86042 100644 --- a/src/wp-includes/rest-api.php +++ b/src/wp-includes/rest-api.php @@ -73,6 +73,7 @@ function register_rest_route( $namespace, $route, $args = array(), $override = f 'callback' => null, 'args' => array(), ); + foreach ( $args as $key => &$arg_group ) { if ( ! is_numeric( $key ) ) { // Route option, skip here. @@ -360,7 +361,7 @@ function get_rest_url( $blog_id = null, $path = '/', $scheme = 'rest' ) { $url .= $path; } else { $url = trailingslashit( get_home_url( $blog_id, '', $scheme ) ); - // nginx only allows HTTP/1.0 methods when redirecting from / to /index.php + // nginx only allows HTTP/1.0 methods when redirecting from / to /index.php. // To work around this, we manually add index.php to the URL, avoiding the redirect. if ( 'index.php' !== substr( $url, 9 ) ) { $url .= 'index.php'; @@ -377,10 +378,11 @@ function get_rest_url( $blog_id = null, $path = '/', $scheme = 'rest' ) { } if ( is_admin() && force_ssl_admin() ) { - // In this situation the home URL may be http:, and `is_ssl()` may be - // false, but the admin is served over https: (one way or another), so - // REST API usage will be blocked by browsers unless it is also served - // over HTTPS. + /* + * In this situation the home URL may be http:, and `is_ssl()` may be false, + * but the admin is served over https: (one way or another), so REST API usage + * will be blocked by browsers unless it is also served over HTTPS. + */ $url = set_url_scheme( $url, 'https' ); } @@ -581,7 +583,7 @@ function rest_send_cors_headers( $value ) { $origin = get_http_origin(); if ( $origin ) { - // Requests from file:// and data: URLs send "Origin: null" + // Requests from file:// and data: URLs send "Origin: null". if ( 'null' !== $origin ) { $origin = esc_url_raw( $origin ); } @@ -632,7 +634,7 @@ function rest_handle_options_request( $response, $handler, $request ) { } foreach ( $endpoints as $endpoint ) { - // Remove the redundant preg_match argument. + // Remove the redundant preg_match() argument. unset( $args[0] ); $request->set_url_params( $args ); @@ -791,18 +793,20 @@ function rest_is_field_included( $field, $fields ) { if ( in_array( $field, $fields, true ) ) { return true; } + foreach ( $fields as $accepted_field ) { // Check to see if $field is the parent of any item in $fields. // A field "parent" should be accepted if "parent.child" is accepted. if ( strpos( $accepted_field, "$field." ) === 0 ) { return true; } - // Conversely, if "parent" is accepted, all "parent.child" fields should - // also be accepted. + // Conversely, if "parent" is accepted, all "parent.child" fields + // should also be accepted. if ( strpos( $field, "$accepted_field." ) === 0 ) { return true; } } + return false; } @@ -979,9 +983,11 @@ function rest_parse_date( $date, $force_utc = false ) { * null on failure. */ function rest_get_date_with_gmt( $date, $is_utc = false ) { - // Whether or not the original date actually has a timezone string - // changes the way we need to do timezone conversion. Store this info - // before parsing the date, and use it later. + /* + * Whether or not the original date actually has a timezone string + * changes the way we need to do timezone conversion. + * Store this info before parsing the date, and use it later. + */ $has_timezone = preg_match( '#(Z|[+-]\d{2}(:\d{2})?)$#', $date ); $date = rest_parse_date( $date ); @@ -990,10 +996,11 @@ function rest_get_date_with_gmt( $date, $is_utc = false ) { return null; } - // At this point $date could either be a local date (if we were passed a - // *local* date without a timezone offset) or a UTC date (otherwise). - // Timezone conversion needs to be handled differently between these two - // cases. + /* + * At this point $date could either be a local date (if we were passed + * a *local* date without a timezone offset) or a UTC date (otherwise). + * Timezone conversion needs to be handled differently between these two cases. + */ if ( ! $is_utc && ! $has_timezone ) { $local = gmdate( 'Y-m-d H:i:s', $date ); $utc = get_gmt_from_date( $local ); @@ -1228,10 +1235,12 @@ function rest_validate_value_from_schema( $value, $args, $param = '' ) { if ( ! is_null( $value ) ) { $value = wp_parse_list( $value ); } + if ( ! wp_is_numeric_array( $value ) ) { /* translators: 1: Parameter, 2: Type name. */ return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not of type %2$s.' ), $param, 'array' ) ); } + foreach ( $value as $index => $v ) { $is_valid = rest_validate_value_from_schema( $v, $args['items'], $param . '[' . $index . ']' ); if ( is_wp_error( $is_valid ) ) { @@ -1390,7 +1399,8 @@ function rest_validate_value_from_schema( $value, $args, $param = '' ) { */ function rest_sanitize_value_from_schema( $value, $args ) { if ( is_array( $args['type'] ) ) { - // Determine which type the value was validated against, and use that type when performing sanitization + // Determine which type the value was validated against, + // and use that type when performing sanitization. $validated_type = ''; foreach ( $args['type'] as $type ) { @@ -1414,12 +1424,13 @@ function rest_sanitize_value_from_schema( $value, $args ) { if ( empty( $args['items'] ) ) { return (array) $value; } + $value = wp_parse_list( $value ); foreach ( $value as $index => $v ) { $value[ $index ] = rest_sanitize_value_from_schema( $v, $args['items'] ); } - // Normalize to numeric array so nothing unexpected - // is in the keys. + + // Normalize to numeric array so nothing unexpected is in the keys. $value = array_values( $value ); return $value; } @@ -1474,9 +1485,7 @@ function rest_sanitize_value_from_schema( $value, $args ) { return sanitize_text_field( $value ); case 'email': - /* - * sanitize_email() validates, which would be unexpected. - */ + // sanitize_email() validates, which would be unexpected. return sanitize_text_field( $value ); case 'uri': @@ -1505,7 +1514,8 @@ function rest_sanitize_value_from_schema( $value, $args ) { * @return array Modified reduce accumulator. */ function rest_preload_api_request( $memo, $path ) { - // array_reduce() doesn't support passing an array in PHP 5.2, so we need to make sure we start with one. + // array_reduce() doesn't support passing an array in PHP 5.2, + // so we need to make sure we start with one. if ( ! is_array( $memo ) ) { $memo = array(); } diff --git a/src/wp-includes/rest-api/class-wp-rest-request.php b/src/wp-includes/rest-api/class-wp-rest-request.php index 757ab372d6..d6146127ed 100644 --- a/src/wp-includes/rest-api/class-wp-rest-request.php +++ b/src/wp-includes/rest-api/class-wp-rest-request.php @@ -446,7 +446,7 @@ class WP_REST_Request implements ArrayAccess { $params = array(); foreach ( $order as $type ) { - // array_merge / the "+" operator will mess up + // array_merge() / the "+" operator will mess up // numeric keys, so instead do a manual foreach. foreach ( (array) $this->params[ $type ] as $key => $value ) { $params[ $key ] = $value; @@ -674,6 +674,7 @@ class WP_REST_Request implements ArrayAccess { } $this->params['JSON'] = $params; + return true; } @@ -783,10 +784,12 @@ class WP_REST_Request implements ArrayAccess { if ( empty( $this->params[ $type ] ) ) { continue; } + foreach ( $this->params[ $type ] as $key => $value ) { if ( ! isset( $attributes['args'][ $key ] ) ) { continue; } + $param_args = $attributes['args'][ $key ]; // If the arg has a type but no sanitize_callback attribute, default to rest_parse_request_arg. @@ -988,7 +991,7 @@ class WP_REST_Request implements ArrayAccess { $api_url_part = substr( $url, strlen( untrailingslashit( $api_root ) ) ); $route = parse_url( $api_url_part, PHP_URL_PATH ); } elseif ( ! empty( $query_params['rest_route'] ) ) { - // ?rest_route=... set directly + // ?rest_route=... set directly. $route = $query_params['rest_route']; unset( $query_params['rest_route'] ); } diff --git a/src/wp-includes/rest-api/class-wp-rest-response.php b/src/wp-includes/rest-api/class-wp-rest-response.php index b13e923f51..1a077f17ea 100644 --- a/src/wp-includes/rest-api/class-wp-rest-response.php +++ b/src/wp-includes/rest-api/class-wp-rest-response.php @@ -154,6 +154,7 @@ class WP_REST_Response extends WP_HTTP_Response { if ( 'title' === $key ) { $value = '"' . $value . '"'; } + $header .= '; ' . $key . '=' . $value; } $this->header( 'Link', $header, false ); @@ -231,6 +232,7 @@ class WP_REST_Response extends WP_HTTP_Response { if ( is_array( $this->get_data() ) ) { $data = $this->get_data(); $error->add( $data['code'], $data['message'], $data['data'] ); + if ( ! empty( $data['additional_errors'] ) ) { foreach ( $data['additional_errors'] as $err ) { $error->add( $err['code'], $err['message'], $err['data'] ); @@ -285,6 +287,7 @@ class WP_REST_Response extends WP_HTTP_Response { * @param array $additional Additional CURIEs to register with the API. */ $additional = apply_filters( 'rest_response_link_curies', array() ); + return array_merge( $curies, $additional ); } } diff --git a/src/wp-includes/rest-api/class-wp-rest-server.php b/src/wp-includes/rest-api/class-wp-rest-server.php index bbd930051f..c869bdbc05 100644 --- a/src/wp-includes/rest-api/class-wp-rest-server.php +++ b/src/wp-includes/rest-api/class-wp-rest-server.php @@ -414,10 +414,16 @@ class WP_REST_Server { $result = wp_json_encode( $result ); $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] ); + $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] ); } if ( $jsonp_callback ) { @@ -428,6 +434,7 @@ class WP_REST_Server { echo $result; } } + return null; } @@ -453,6 +460,7 @@ class WP_REST_Server { // Convert links to part of the data. $data['_links'] = $links; } + if ( $embed ) { // Determine if this is a numeric array. if ( wp_is_numeric_array( $data ) ) { @@ -478,6 +486,7 @@ class WP_REST_Server { */ public static function get_response_links( $response ) { $links = $response->get_links(); + if ( empty( $links ) ) { return array(); } @@ -846,6 +855,7 @@ class WP_REST_Server { } $args = array(); + foreach ( $matches as $param => $value ) { if ( ! is_int( $param ) ) { $args[ $param ] = $value; @@ -866,7 +876,11 @@ class WP_REST_Server { } if ( ! is_callable( $callback ) ) { - $response = new WP_Error( 'rest_invalid_handler', __( 'The handler for the route is invalid' ), array( 'status' => 500 ) ); + $response = new WP_Error( + 'rest_invalid_handler', + __( 'The handler for the route is invalid' ), + array( 'status' => 500 ) + ); } if ( ! is_wp_error( $response ) ) { @@ -923,7 +937,11 @@ class WP_REST_Server { if ( is_wp_error( $permission ) ) { $response = $permission; } elseif ( false === $permission || null === $permission ) { - $response = new WP_Error( 'rest_forbidden', __( 'Sorry, you are not allowed to do that.' ), array( 'status' => rest_authorization_required_code() ) ); + $response = new WP_Error( + 'rest_forbidden', + __( 'Sorry, you are not allowed to do that.' ), + array( 'status' => rest_authorization_required_code() ) + ); } } } @@ -987,7 +1005,13 @@ class WP_REST_Server { } } - return $this->error_to_response( new WP_Error( 'rest_no_route', __( 'No route was found matching the URL and request method' ), array( 'status' => 404 ) ) ); + return $this->error_to_response( + new WP_Error( + 'rest_no_route', + __( 'No route was found matching the URL and request method' ), + array( 'status' => 404 ) + ) + ); } /** @@ -1069,7 +1093,11 @@ class WP_REST_Server { $namespace = $request['namespace']; if ( ! isset( $this->namespaces[ $namespace ] ) ) { - return new WP_Error( 'rest_invalid_namespace', __( 'The specified namespace could not be found.' ), array( 'status' => 404 ) ); + return new WP_Error( + 'rest_invalid_namespace', + __( 'The specified namespace could not be found.' ), + array( 'status' => 404 ) + ); } $routes = $this->namespaces[ $namespace ]; @@ -1186,6 +1214,7 @@ class WP_REST_Server { if ( isset( $callback['args'] ) ) { $endpoint_data['args'] = array(); + foreach ( $callback['args'] as $key => $opts ) { $arg_data = array( 'required' => ! empty( $opts['required'] ), diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php index 253b1f86e5..1d78928fc4 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php @@ -94,7 +94,11 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { } if ( ! current_user_can( 'upload_files' ) ) { - return new WP_Error( 'rest_cannot_create', __( 'Sorry, you are not allowed to upload media on this site.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_cannot_create', + __( 'Sorry, you are not allowed to upload media on this site.' ), + array( 'status' => 400 ) + ); } // Attaching media to a post requires ability to edit said post. @@ -103,7 +107,11 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { $post_parent_type = get_post_type_object( $parent->post_type ); if ( ! current_user_can( $post_parent_type->cap->edit_post, $request['post'] ) ) { - return new WP_Error( 'rest_cannot_edit', __( 'Sorry, you are not allowed to upload media to this post.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_edit', + __( 'Sorry, you are not allowed to upload media to this post.' ), + array( 'status' => rest_authorization_required_code() ) + ); } } @@ -119,9 +127,12 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { * @return WP_REST_Response|WP_Error Response object on success, WP_Error object on failure. */ public function create_item( $request ) { - if ( ! empty( $request['post'] ) && in_array( get_post_type( $request['post'] ), array( 'revision', 'attachment' ), true ) ) { - return new WP_Error( 'rest_invalid_param', __( 'Invalid parent type.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_invalid_param', + __( 'Invalid parent type.' ), + array( 'status' => 400 ) + ); } $insert = $this->insert_attachment( $request ); @@ -213,7 +224,7 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { // Include image functions to get access to wp_read_image_metadata(). require_once ABSPATH . 'wp-admin/includes/image.php'; - // use image exif/iptc data for title and caption defaults if possible + // Use image exif/iptc data for title and caption defaults if possible. $image_meta = wp_read_image_metadata( $file ); if ( ! empty( $image_meta ) ) { @@ -278,7 +289,11 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { */ public function update_item( $request ) { if ( ! empty( $request['post'] ) && in_array( get_post_type( $request['post'] ), array( 'revision', 'attachment' ), true ) ) { - return new WP_Error( 'rest_invalid_param', __( 'Invalid parent type.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_invalid_param', + __( 'Invalid parent type.' ), + array( 'status' => 400 ) + ); } $response = parent::update_item( $request ); @@ -357,7 +372,7 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { protected function prepare_item_for_database( $request ) { $prepared_attachment = parent::prepare_item_for_database( $request ); - // Attachment caption (post_excerpt internally) + // Attachment caption (post_excerpt internally). if ( isset( $request['caption'] ) ) { if ( is_string( $request['caption'] ) ) { $prepared_attachment->post_excerpt = $request['caption']; @@ -366,7 +381,7 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { } } - // Attachment description (post_content internally) + // Attachment description (post_content internally). if ( isset( $request['description'] ) ) { if ( is_string( $request['description'] ) ) { $prepared_attachment->post_content = $request['description']; @@ -539,8 +554,8 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { '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() + '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( @@ -562,8 +577,8 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { 'type' => 'object', 'context' => array( 'view', 'edit' ), '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() + '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( @@ -627,6 +642,7 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { unset( $schema['properties']['password'] ); $this->schema = $schema; + return $this->add_additional_fields_schema( $this->schema ); } @@ -641,21 +657,37 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { */ protected function upload_from_data( $data, $headers ) { if ( empty( $data ) ) { - return new WP_Error( 'rest_upload_no_data', __( 'No data supplied.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_upload_no_data', + __( 'No data supplied.' ), + array( 'status' => 400 ) + ); } if ( empty( $headers['content_type'] ) ) { - return new WP_Error( 'rest_upload_no_content_type', __( 'No Content-Type supplied.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_upload_no_content_type', + __( 'No Content-Type supplied.' ), + array( 'status' => 400 ) + ); } if ( empty( $headers['content_disposition'] ) ) { - return new WP_Error( 'rest_upload_no_content_disposition', __( 'No Content-Disposition supplied.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_upload_no_content_disposition', + __( 'No Content-Disposition supplied.' ), + array( 'status' => 400 ) + ); } $filename = self::get_filename_from_disposition( $headers['content_disposition'] ); if ( empty( $filename ) ) { - return new WP_Error( 'rest_upload_invalid_disposition', __( 'Invalid Content-Disposition supplied. Content-Disposition needs to be formatted as `attachment; filename="image.png"` or similar.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_upload_invalid_disposition', + __( 'Invalid Content-Disposition supplied. Content-Disposition needs to be formatted as `attachment; filename="image.png"` or similar.' ), + array( 'status' => 400 ) + ); } if ( ! empty( $headers['content_md5'] ) ) { @@ -664,7 +696,11 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { $actual = md5( $data ); if ( $expected !== $actual ) { - return new WP_Error( 'rest_upload_hash_mismatch', __( 'Content hash did not match expected.' ), array( 'status' => 412 ) ); + return new WP_Error( + 'rest_upload_hash_mismatch', + __( 'Content hash did not match expected.' ), + array( 'status' => 412 ) + ); } } @@ -680,7 +716,11 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { $fp = fopen( $tmpfname, 'w+' ); if ( ! $fp ) { - return new WP_Error( 'rest_upload_file_error', __( 'Could not open file handle.' ), array( 'status' => 500 ) ); + return new WP_Error( + 'rest_upload_file_error', + __( 'Could not open file handle.' ), + array( 'status' => 500 ) + ); } fwrite( $fp, $data ); @@ -708,7 +748,11 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { if ( isset( $sideloaded['error'] ) ) { @unlink( $tmpfname ); - return new WP_Error( 'rest_upload_sideload_error', $sideloaded['error'], array( 'status' => 500 ) ); + return new WP_Error( + 'rest_upload_sideload_error', + $sideloaded['error'], + array( 'status' => 500 ) + ); } return $sideloaded; @@ -824,7 +868,11 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { */ protected function upload_from_file( $files, $headers ) { if ( empty( $files ) ) { - return new WP_Error( 'rest_upload_no_data', __( 'No data supplied.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_upload_no_data', + __( 'No data supplied.' ), + array( 'status' => 400 ) + ); } // Verify hash, if given. @@ -834,7 +882,11 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { $actual = md5_file( $files['file']['tmp_name'] ); if ( $expected !== $actual ) { - return new WP_Error( 'rest_upload_hash_mismatch', __( 'Content hash did not match expected.' ), array( 'status' => 412 ) ); + return new WP_Error( + 'rest_upload_hash_mismatch', + __( 'Content hash did not match expected.' ), + array( 'status' => 412 ) + ); } } @@ -859,7 +911,11 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { $file = wp_handle_upload( $files['file'], $overrides ); if ( isset( $file['error'] ) ) { - return new WP_Error( 'rest_upload_unknown_error', $file['error'], array( 'status' => 500 ) ); + return new WP_Error( + 'rest_upload_unknown_error', + $file['error'], + array( 'status' => 500 ) + ); } return $file; @@ -912,22 +968,36 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { $space_left = get_upload_space_available(); $file_size = filesize( $file['tmp_name'] ); + if ( $space_left < $file_size ) { - /* translators: %s: Required disk space in kilobytes. */ - return new WP_Error( 'rest_upload_limited_space', sprintf( __( 'Not enough space to upload. %s KB needed.' ), number_format( ( $file_size - $space_left ) / KB_IN_BYTES ) ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_upload_limited_space', + /* translators: %s: Required disk space in kilobytes. */ + sprintf( __( 'Not enough space to upload. %s KB needed.' ), number_format( ( $file_size - $space_left ) / KB_IN_BYTES ) ), + array( 'status' => 400 ) + ); } if ( $file_size > ( KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 ) ) ) { - /* translators: %s: Maximum allowed file size in kilobytes. */ - return new WP_Error( 'rest_upload_file_too_big', sprintf( __( 'This file is too big. Files must be less than %s KB in size.' ), get_site_option( 'fileupload_maxk', 1500 ) ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_upload_file_too_big', + /* translators: %s: Maximum allowed file size in kilobytes. */ + sprintf( __( 'This file is too big. Files must be less than %s KB in size.' ), get_site_option( 'fileupload_maxk', 1500 ) ), + array( 'status' => 400 ) + ); } // Include admin function to get access to upload_is_user_over_quota(). require_once ABSPATH . 'wp-admin/includes/ms.php'; if ( upload_is_user_over_quota( false ) ) { - return new WP_Error( 'rest_upload_user_quota_exceeded', __( 'You have used your space quota. Please delete files before uploading.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_upload_user_quota_exceeded', + __( 'You have used your space quota. Please delete files before uploading.' ), + array( 'status' => 400 ) + ); } + return true; } diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php index a72541a1ee..af5f51f74f 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php @@ -161,8 +161,13 @@ class WP_REST_Autosaves_Controller extends WP_REST_Revisions_Controller { } $parent_post_type_obj = get_post_type_object( $parent->post_type ); + if ( ! current_user_can( $parent_post_type_obj->cap->edit_post, $parent->ID ) ) { - return new WP_Error( 'rest_cannot_read', __( 'Sorry, you are not allowed to view autosaves of this post.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_read', + __( 'Sorry, you are not allowed to view autosaves of this post.' ), + array( 'status' => rest_authorization_required_code() ) + ); } return true; @@ -181,8 +186,13 @@ class WP_REST_Autosaves_Controller extends WP_REST_Revisions_Controller { */ public function create_item_permissions_check( $request ) { $id = $request->get_param( 'id' ); + if ( empty( $id ) ) { - return new WP_Error( 'rest_post_invalid_id', __( 'Invalid item ID.' ), array( 'status' => 404 ) ); + return new WP_Error( + 'rest_post_invalid_id', + __( 'Invalid item ID.' ), + array( 'status' => 404 ) + ); } return $this->parent_controller->update_item_permissions_check( $request ); @@ -214,7 +224,7 @@ class WP_REST_Autosaves_Controller extends WP_REST_Revisions_Controller { if ( ( 'draft' === $post->post_status || 'auto-draft' === $post->post_status ) && $post->post_author == $user_id ) { // Draft posts for the same author: autosaving updates the post and does not create a revision. - // Convert the post object to an array and add slashes, wp_update_post expects escaped array. + // Convert the post object to an array and add slashes, wp_update_post() expects escaped array. $autosave_id = wp_update_post( wp_slash( (array) $prepared_post ), true ); } else { // Non-draft posts: create or update the post autosave. @@ -246,13 +256,21 @@ class WP_REST_Autosaves_Controller extends WP_REST_Revisions_Controller { $parent_id = (int) $request->get_param( 'parent' ); if ( $parent_id <= 0 ) { - return new WP_Error( 'rest_post_invalid_id', __( 'Invalid post parent ID.' ), array( 'status' => 404 ) ); + return new WP_Error( + 'rest_post_invalid_id', + __( 'Invalid post parent ID.' ), + array( 'status' => 404 ) + ); } $autosave = wp_get_post_autosave( $parent_id ); if ( ! $autosave ) { - return new WP_Error( 'rest_post_no_autosave', __( 'There is no autosave revision for this post.' ), array( 'status' => 404 ) ); + return new WP_Error( + 'rest_post_no_autosave', + __( 'There is no autosave revision for this post.' ), + array( 'status' => 404 ) + ); } $response = $this->prepare_item_for_response( $autosave, $request ); @@ -313,6 +331,7 @@ class WP_REST_Autosaves_Controller extends WP_REST_Revisions_Controller { ); $this->schema = $schema; + return $this->add_additional_fields_schema( $this->schema ); } @@ -357,13 +376,17 @@ class WP_REST_Autosaves_Controller extends WP_REST_Revisions_Controller { if ( ! $autosave_is_different ) { wp_delete_post_revision( $old_autosave->ID ); - return new WP_Error( 'rest_autosave_no_changes', __( 'There is nothing to save. The autosave and the post content are the same.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_autosave_no_changes', + __( 'There is nothing to save. The autosave and the post content are the same.' ), + array( 'status' => 400 ) + ); } /** This filter is documented in wp-admin/post.php */ do_action( 'wp_creating_autosave', $new_autosave ); - // wp_update_post expects escaped array. + // wp_update_post() expects escaped array. return wp_update_post( wp_slash( $new_autosave ) ); } diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-block-renderer-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-block-renderer-controller.php index b5b3323b4c..2f901f9230 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-block-renderer-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-block-renderer-controller.php @@ -150,6 +150,7 @@ class WP_REST_Block_Renderer_Controller extends WP_REST_Controller { $data = array( 'rendered' => $block->render( $request->get_param( 'attributes' ) ), ); + return rest_ensure_response( $data ); } @@ -178,6 +179,7 @@ class WP_REST_Block_Renderer_Controller extends WP_REST_Controller { ), ), ); + return $this->schema; } } diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php index e05f9802ea..fc9f03822b 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php @@ -127,15 +127,27 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { $post = get_post( $post_id ); if ( ! empty( $post_id ) && $post && ! $this->check_read_post_permission( $post, $request ) ) { - return new WP_Error( 'rest_cannot_read_post', __( 'Sorry, you are not allowed to read the post for this comment.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_read_post', + __( 'Sorry, you are not allowed to read the post for this comment.' ), + array( 'status' => rest_authorization_required_code() ) + ); } elseif ( 0 === $post_id && ! current_user_can( 'moderate_comments' ) ) { - return new WP_Error( 'rest_cannot_read', __( 'Sorry, you are not allowed to read comments without a post.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_read', + __( 'Sorry, you are not allowed to read comments without a post.' ), + array( 'status' => rest_authorization_required_code() ) + ); } } } if ( ! empty( $request['context'] ) && 'edit' === $request['context'] && ! current_user_can( 'moderate_comments' ) ) { - return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit comments.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_forbidden_context', + __( 'Sorry, you are not allowed to edit comments.' ), + array( 'status' => rest_authorization_required_code() ) + ); } if ( ! current_user_can( 'edit_posts' ) ) { @@ -322,7 +334,12 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { * @return WP_Comment|WP_Error Comment object if ID is valid, WP_Error otherwise. */ protected function get_comment( $id ) { - $error = new WP_Error( 'rest_comment_invalid_id', __( 'Invalid comment ID.' ), array( 'status' => 404 ) ); + $error = new WP_Error( + 'rest_comment_invalid_id', + __( 'Invalid comment ID.' ), + array( 'status' => 404 ) + ); + if ( (int) $id <= 0 ) { return $error; } @@ -335,8 +352,13 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { if ( ! empty( $comment->comment_post_ID ) ) { $post = get_post( (int) $comment->comment_post_ID ); + if ( empty( $post ) ) { - return new WP_Error( 'rest_post_invalid_id', __( 'Invalid post ID.' ), array( 'status' => 404 ) ); + return new WP_Error( + 'rest_post_invalid_id', + __( 'Invalid post ID.' ), + array( 'status' => 404 ) + ); } } @@ -358,17 +380,29 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { } if ( ! empty( $request['context'] ) && 'edit' === $request['context'] && ! current_user_can( 'moderate_comments' ) ) { - return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit comments.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_forbidden_context', + __( 'Sorry, you are not allowed to edit comments.' ), + array( 'status' => rest_authorization_required_code() ) + ); } $post = get_post( $comment->comment_post_ID ); if ( ! $this->check_read_permission( $comment, $request ) ) { - return new WP_Error( 'rest_cannot_read', __( 'Sorry, you are not allowed to read this comment.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_read', + __( 'Sorry, you are not allowed to read this comment.' ), + array( 'status' => rest_authorization_required_code() ) + ); } if ( $post && ! $this->check_read_post_permission( $post, $request ) ) { - return new WP_Error( 'rest_cannot_read_post', __( 'Sorry, you are not allowed to read the post for this comment.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_read_post', + __( 'Sorry, you are not allowed to read the post for this comment.' ), + array( 'status' => rest_authorization_required_code() ) + ); } return true; @@ -405,7 +439,11 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { public function create_item_permissions_check( $request ) { if ( ! is_user_logged_in() ) { if ( get_option( 'comment_registration' ) ) { - return new WP_Error( 'rest_comment_login_required', __( 'Sorry, you must be logged in to comment.' ), array( 'status' => 401 ) ); + return new WP_Error( + 'rest_comment_login_required', + __( 'Sorry, you must be logged in to comment.' ), + array( 'status' => 401 ) + ); } /** @@ -421,8 +459,13 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { * response. */ $allow_anonymous = apply_filters( 'rest_allow_anonymous_comments', false, $request ); + if ( ! $allow_anonymous ) { - return new WP_Error( 'rest_comment_login_required', __( 'Sorry, you must be logged in to comment.' ), array( 'status' => 401 ) ); + return new WP_Error( + 'rest_comment_login_required', + __( 'Sorry, you must be logged in to comment.' ), + array( 'status' => 401 ) + ); } } @@ -457,28 +500,53 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { } if ( empty( $request['post'] ) ) { - return new WP_Error( 'rest_comment_invalid_post_id', __( 'Sorry, you are not allowed to create this comment without a post.' ), array( 'status' => 403 ) ); + return new WP_Error( + 'rest_comment_invalid_post_id', + __( 'Sorry, you are not allowed to create this comment without a post.' ), + array( 'status' => 403 ) + ); } $post = get_post( (int) $request['post'] ); + if ( ! $post ) { - return new WP_Error( 'rest_comment_invalid_post_id', __( 'Sorry, you are not allowed to create this comment without a post.' ), array( 'status' => 403 ) ); + return new WP_Error( + 'rest_comment_invalid_post_id', + __( 'Sorry, you are not allowed to create this comment without a post.' ), + array( 'status' => 403 ) + ); } if ( 'draft' === $post->post_status ) { - return new WP_Error( 'rest_comment_draft_post', __( 'Sorry, you are not allowed to create a comment on this post.' ), array( 'status' => 403 ) ); + return new WP_Error( + 'rest_comment_draft_post', + __( 'Sorry, you are not allowed to create a comment on this post.' ), + array( 'status' => 403 ) + ); } if ( 'trash' === $post->post_status ) { - return new WP_Error( 'rest_comment_trash_post', __( 'Sorry, you are not allowed to create a comment on this post.' ), array( 'status' => 403 ) ); + return new WP_Error( + 'rest_comment_trash_post', + __( 'Sorry, you are not allowed to create a comment on this post.' ), + array( 'status' => 403 ) + ); } if ( ! $this->check_read_post_permission( $post, $request ) ) { - return new WP_Error( 'rest_cannot_read_post', __( 'Sorry, you are not allowed to read the post for this comment.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_read_post', + __( 'Sorry, you are not allowed to read the post for this comment.' ), + array( 'status' => rest_authorization_required_code() ) + ); } if ( ! comments_open( $post->ID ) ) { - return new WP_Error( 'rest_comment_closed', __( 'Sorry, comments are closed for this item.' ), array( 'status' => 403 ) ); + return new WP_Error( + 'rest_comment_closed', + __( 'Sorry, comments are closed for this item.' ), + array( 'status' => 403 ) + ); } return true; @@ -494,12 +562,20 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { */ public function create_item( $request ) { if ( ! empty( $request['id'] ) ) { - return new WP_Error( 'rest_comment_exists', __( 'Cannot create existing comment.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_comment_exists', + __( 'Cannot create existing comment.' ), + array( 'status' => 400 ) + ); } // Do not allow comments to be created with a non-default type. if ( ! empty( $request['type'] ) && 'comment' !== $request['type'] ) { - return new WP_Error( 'rest_invalid_comment_type', __( 'Cannot create a comment with that type.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_invalid_comment_type', + __( 'Cannot create a comment with that type.' ), + array( 'status' => 400 ) + ); } $prepared_comment = $this->prepare_item_for_database( $request ); @@ -514,7 +590,11 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { * comment_content. See wp_handle_comment_submission(). */ if ( empty( $prepared_comment['comment_content'] ) ) { - return new WP_Error( 'rest_comment_content_invalid', __( 'Invalid comment content.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_comment_content_invalid', + __( 'Invalid comment content.' ), + array( 'status' => 400 ) + ); } // Setting remaining values before wp_insert_comment so we can use wp_allow_comment(). @@ -540,7 +620,11 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { // Honor the discussion setting that requires a name and email address of the comment author. if ( get_option( 'require_name_email' ) ) { if ( empty( $prepared_comment['comment_author'] ) || empty( $prepared_comment['comment_author_email'] ) ) { - return new WP_Error( 'rest_comment_author_data_required', __( 'Creating a comment requires valid author name and email values.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_comment_author_data_required', + __( 'Creating a comment requires valid author name and email values.' ), + array( 'status' => 400 ) + ); } } @@ -557,9 +641,14 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { } $check_comment_lengths = wp_check_comment_data_max_lengths( $prepared_comment ); + if ( is_wp_error( $check_comment_lengths ) ) { $error_code = $check_comment_lengths->get_error_code(); - return new WP_Error( $error_code, __( 'Comment field exceeds maximum length allowed.' ), array( 'status' => 400 ) ); + return new WP_Error( + $error_code, + __( 'Comment field exceeds maximum length allowed.' ), + array( 'status' => 400 ) + ); } $prepared_comment['comment_approved'] = wp_allow_comment( $prepared_comment, true ); @@ -569,11 +658,19 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { $error_message = $prepared_comment['comment_approved']->get_error_message(); if ( 'comment_duplicate' === $error_code ) { - return new WP_Error( $error_code, $error_message, array( 'status' => 409 ) ); + return new WP_Error( + $error_code, + $error_message, + array( 'status' => 409 ) + ); } if ( 'comment_flood' === $error_code ) { - return new WP_Error( $error_code, $error_message, array( 'status' => 400 ) ); + return new WP_Error( + $error_code, + $error_message, + array( 'status' => 400 ) + ); } return $prepared_comment['comment_approved']; @@ -600,7 +697,11 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { $comment_id = wp_insert_comment( wp_filter_comment( wp_slash( (array) $prepared_comment ) ) ); if ( ! $comment_id ) { - return new WP_Error( 'rest_comment_failed_create', __( 'Creating comment failed.' ), array( 'status' => 500 ) ); + return new WP_Error( + 'rest_comment_failed_create', + __( 'Creating comment failed.' ), + array( 'status' => 500 ) + ); } if ( isset( $request['status'] ) ) { @@ -676,7 +777,11 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { } if ( ! $this->check_edit_permission( $comment ) ) { - return new WP_Error( 'rest_cannot_edit', __( 'Sorry, you are not allowed to edit this comment.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_edit', + __( 'Sorry, you are not allowed to edit this comment.' ), + array( 'status' => rest_authorization_required_code() ) + ); } return true; @@ -699,7 +804,11 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { $id = $comment->comment_ID; if ( isset( $request['type'] ) && get_comment_type( $id ) !== $request['type'] ) { - return new WP_Error( 'rest_comment_invalid_type', __( 'Sorry, you are not allowed to change the comment type.' ), array( 'status' => 404 ) ); + return new WP_Error( + 'rest_comment_invalid_type', + __( 'Sorry, you are not allowed to change the comment type.' ), + array( 'status' => 404 ) + ); } $prepared_args = $this->prepare_item_for_database( $request ); @@ -710,8 +819,13 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { if ( ! empty( $prepared_args['comment_post_ID'] ) ) { $post = get_post( $prepared_args['comment_post_ID'] ); + if ( empty( $post ) ) { - return new WP_Error( 'rest_comment_invalid_post_id', __( 'Invalid post ID.' ), array( 'status' => 403 ) ); + return new WP_Error( + 'rest_comment_invalid_post_id', + __( 'Invalid post ID.' ), + array( 'status' => 403 ) + ); } } @@ -720,7 +834,11 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { $change = $this->handle_status_param( $request['status'], $id ); if ( ! $change ) { - return new WP_Error( 'rest_comment_failed_edit', __( 'Updating comment status failed.' ), array( 'status' => 500 ) ); + return new WP_Error( + 'rest_comment_failed_edit', + __( 'Updating comment status failed.' ), + array( 'status' => 500 ) + ); } } elseif ( ! empty( $prepared_args ) ) { if ( is_wp_error( $prepared_args ) ) { @@ -728,21 +846,34 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { } if ( isset( $prepared_args['comment_content'] ) && empty( $prepared_args['comment_content'] ) ) { - return new WP_Error( 'rest_comment_content_invalid', __( 'Invalid comment content.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_comment_content_invalid', + __( 'Invalid comment content.' ), + array( 'status' => 400 ) + ); } $prepared_args['comment_ID'] = $id; $check_comment_lengths = wp_check_comment_data_max_lengths( $prepared_args ); + if ( is_wp_error( $check_comment_lengths ) ) { $error_code = $check_comment_lengths->get_error_code(); - return new WP_Error( $error_code, __( 'Comment field exceeds maximum length allowed.' ), array( 'status' => 400 ) ); + return new WP_Error( + $error_code, + __( 'Comment field exceeds maximum length allowed.' ), + array( 'status' => 400 ) + ); } $updated = wp_update_comment( wp_slash( (array) $prepared_args ) ); if ( false === $updated ) { - return new WP_Error( 'rest_comment_failed_edit', __( 'Updating comment failed.' ), array( 'status' => 500 ) ); + return new WP_Error( + 'rest_comment_failed_edit', + __( 'Updating comment failed.' ), + array( 'status' => 500 ) + ); } if ( isset( $request['status'] ) ) { @@ -796,7 +927,11 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { } if ( ! $this->check_edit_permission( $comment ) ) { - return new WP_Error( 'rest_cannot_delete', __( 'Sorry, you are not allowed to delete this comment.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_delete', + __( 'Sorry, you are not allowed to delete this comment.' ), + array( 'status' => rest_authorization_required_code() ) + ); } return true; } @@ -844,12 +979,20 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { } else { // If this type doesn't support trashing, error out. if ( ! $supports_trash ) { - /* translators: %s: force=true */ - return new WP_Error( 'rest_trash_not_supported', sprintf( __( "The comment does not support trashing. Set '%s' to delete." ), 'force=true' ), array( 'status' => 501 ) ); + return new WP_Error( + 'rest_trash_not_supported', + /* translators: %s: force=true */ + sprintf( __( "The comment does not support trashing. Set '%s' to delete." ), 'force=true' ), + array( 'status' => 501 ) + ); } if ( 'trash' === $comment->comment_approved ) { - return new WP_Error( 'rest_already_trashed', __( 'The comment has already been trashed.' ), array( 'status' => 410 ) ); + return new WP_Error( + 'rest_already_trashed', + __( 'The comment has already been trashed.' ), + array( 'status' => 410 ) + ); } $result = wp_trash_comment( $comment->comment_ID ); @@ -858,7 +1001,11 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { } if ( ! $result ) { - return new WP_Error( 'rest_cannot_delete', __( 'The comment cannot be deleted.' ), array( 'status' => 500 ) ); + return new WP_Error( + 'rest_cannot_delete', + __( 'The comment cannot be deleted.' ), + array( 'status' => 500 ) + ); } /** @@ -1155,7 +1302,11 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { $prepared_comment['comment_author_email'] = $user->user_email; $prepared_comment['comment_author_url'] = $user->user_url; } else { - return new WP_Error( 'rest_comment_author_invalid', __( 'Invalid comment author ID.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_comment_author_invalid', + __( 'Invalid comment author ID.' ), + array( 'status' => 400 ) + ); } } @@ -1247,7 +1398,7 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { 'context' => array( 'edit' ), 'arg_options' => array( 'sanitize_callback' => array( $this, 'check_comment_author_email' ), - 'validate_callback' => null, // skip built-in validation of 'email'. + 'validate_callback' => null, // Skip built-in validation of 'email'. ), ), 'author_ip' => array( @@ -1283,8 +1434,8 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { '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() + '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( @@ -1352,6 +1503,7 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { $avatar_properties = array(); $avatar_sizes = rest_get_avatar_sizes(); + foreach ( $avatar_sizes as $size ) { $avatar_properties[ $size ] = array( /* translators: %d: Avatar image size in pixels. */ @@ -1374,6 +1526,7 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { $schema['properties']['meta'] = $this->meta->get_field_schema(); $this->schema = $schema; + return $this->add_additional_fields_schema( $this->schema ); } diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php index 90b97f0f3b..dd40d93d2b 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php @@ -44,8 +44,12 @@ abstract class WP_REST_Controller { * @since 4.7.0 */ public function register_routes() { - /* translators: %s: register_routes() */ - _doing_it_wrong( 'WP_REST_Controller::register_routes', sprintf( __( "Method '%s' must be overridden." ), __METHOD__ ), '4.7' ); + _doing_it_wrong( + 'WP_REST_Controller::register_routes', + /* translators: %s: register_routes() */ + sprintf( __( "Method '%s' must be overridden." ), __METHOD__ ), + '4.7' + ); } /** @@ -57,8 +61,12 @@ abstract class WP_REST_Controller { * @return true|WP_Error True if the request has read access, WP_Error object otherwise. */ public function get_items_permissions_check( $request ) { - /* translators: %s: Method name. */ - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); + return new WP_Error( + 'invalid-method', + /* translators: %s: Method name. */ + sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), + array( 'status' => 405 ) + ); } /** @@ -70,8 +78,12 @@ abstract class WP_REST_Controller { * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. */ public function get_items( $request ) { - /* translators: %s: Method name. */ - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); + return new WP_Error( + 'invalid-method', + /* translators: %s: Method name. */ + sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), + array( 'status' => 405 ) + ); } /** @@ -83,8 +95,12 @@ abstract class WP_REST_Controller { * @return true|WP_Error True if the request has read access for the item, WP_Error object otherwise. */ public function get_item_permissions_check( $request ) { - /* translators: %s: Method name. */ - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); + return new WP_Error( + 'invalid-method', + /* translators: %s: Method name. */ + sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), + array( 'status' => 405 ) + ); } /** @@ -96,8 +112,12 @@ abstract class WP_REST_Controller { * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. */ public function get_item( $request ) { - /* translators: %s: Method name. */ - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); + return new WP_Error( + 'invalid-method', + /* translators: %s: Method name. */ + sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), + array( 'status' => 405 ) + ); } /** @@ -109,8 +129,12 @@ abstract class WP_REST_Controller { * @return true|WP_Error True if the request has access to create items, WP_Error object otherwise. */ public function create_item_permissions_check( $request ) { - /* translators: %s: Method name. */ - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); + return new WP_Error( + 'invalid-method', + /* translators: %s: Method name. */ + sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), + array( 'status' => 405 ) + ); } /** @@ -122,8 +146,12 @@ abstract class WP_REST_Controller { * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. */ public function create_item( $request ) { - /* translators: %s: Method name. */ - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); + return new WP_Error( + 'invalid-method', + /* translators: %s: Method name. */ + sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), + array( 'status' => 405 ) + ); } /** @@ -135,8 +163,12 @@ abstract class WP_REST_Controller { * @return true|WP_Error True if the request has access to update the item, WP_Error object otherwise. */ public function update_item_permissions_check( $request ) { - /* translators: %s: Method name. */ - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); + return new WP_Error( + 'invalid-method', + /* translators: %s: Method name. */ + sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), + array( 'status' => 405 ) + ); } /** @@ -148,8 +180,12 @@ abstract class WP_REST_Controller { * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. */ public function update_item( $request ) { - /* translators: %s: Method name. */ - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); + return new WP_Error( + 'invalid-method', + /* translators: %s: Method name. */ + sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), + array( 'status' => 405 ) + ); } /** @@ -161,8 +197,12 @@ abstract class WP_REST_Controller { * @return true|WP_Error True if the request has access to delete the item, WP_Error object otherwise. */ public function delete_item_permissions_check( $request ) { - /* translators: %s: Method name. */ - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); + return new WP_Error( + 'invalid-method', + /* translators: %s: Method name. */ + sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), + array( 'status' => 405 ) + ); } /** @@ -174,8 +214,12 @@ abstract class WP_REST_Controller { * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. */ public function delete_item( $request ) { - /* translators: %s: Method name. */ - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); + return new WP_Error( + 'invalid-method', + /* translators: %s: Method name. */ + sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), + array( 'status' => 405 ) + ); } /** @@ -187,8 +231,12 @@ abstract class WP_REST_Controller { * @return object|WP_Error The prepared item, or WP_Error object on failure. */ protected function prepare_item_for_database( $request ) { - /* translators: %s: Method name. */ - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); + return new WP_Error( + 'invalid-method', + /* translators: %s: Method name. */ + sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), + array( 'status' => 405 ) + ); } /** @@ -201,8 +249,12 @@ abstract class WP_REST_Controller { * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. */ public function prepare_item_for_response( $item, $request ) { - /* translators: %s: Method name. */ - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); + return new WP_Error( + 'invalid-method', + /* translators: %s: Method name. */ + sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), + array( 'status' => 405 ) + ); } /** @@ -391,7 +443,6 @@ abstract class WP_REST_Controller { $requested_fields = $this->get_fields_for_response( $request ); foreach ( $additional_fields as $field_name => $field_options ) { - if ( ! $field_options['get_callback'] ) { continue; } @@ -529,6 +580,7 @@ abstract class WP_REST_Controller { $properties = isset( $schema['properties'] ) ? $schema['properties'] : array(); $additional_fields = $this->get_additional_fields(); + foreach ( $additional_fields as $field_name => $field_options ) { // For back-compat, include any field with an empty schema // because it won't be present in $this->get_item_schema(). @@ -572,8 +624,8 @@ abstract class WP_REST_Controller { } // Check for nested fields if $field is not a direct match. $nested_fields = explode( '.', $field ); - // A nested field is included so long as its top-level property is - // present in the schema. + // A nested field is included so long as its top-level property + // is present in the schema. if ( in_array( $nested_fields[0], $fields, true ) ) { $response_fields[] = $field; } diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php index ccb44b7b80..fede70d6cf 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php @@ -90,7 +90,11 @@ class WP_REST_Post_Statuses_Controller extends WP_REST_Controller { } } - return new WP_Error( 'rest_cannot_view', __( 'Sorry, you are not allowed to manage post statuses.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_view', + __( 'Sorry, you are not allowed to manage post statuses.' ), + array( 'status' => rest_authorization_required_code() ) + ); } return true; @@ -135,13 +139,21 @@ class WP_REST_Post_Statuses_Controller extends WP_REST_Controller { $status = get_post_status_object( $request['status'] ); if ( empty( $status ) ) { - return new WP_Error( 'rest_status_invalid', __( 'Invalid status.' ), array( 'status' => 404 ) ); + return new WP_Error( + 'rest_status_invalid', + __( 'Invalid status.' ), + array( 'status' => 404 ) + ); } $check = $this->check_read_permission( $status ); if ( ! $check ) { - return new WP_Error( 'rest_cannot_read_status', __( 'Cannot view status.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_read_status', + __( 'Cannot view status.' ), + array( 'status' => rest_authorization_required_code() ) + ); } return true; @@ -185,7 +197,11 @@ class WP_REST_Post_Statuses_Controller extends WP_REST_Controller { $obj = get_post_status_object( $request['status'] ); if ( empty( $obj ) ) { - return new WP_Error( 'rest_status_invalid', __( 'Invalid status.' ), array( 'status' => 404 ) ); + return new WP_Error( + 'rest_status_invalid', + __( 'Invalid status.' ), + array( 'status' => 404 ) + ); } $data = $this->prepare_item_for_response( $obj, $request ); @@ -334,6 +350,7 @@ class WP_REST_Post_Statuses_Controller extends WP_REST_Controller { ); $this->schema = $schema; + return $this->add_additional_fields_schema( $this->schema ); } diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php index 9b079fbf0c..fd9759d79e 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php @@ -89,7 +89,11 @@ class WP_REST_Post_Types_Controller extends WP_REST_Controller { } } - return new WP_Error( 'rest_cannot_view', __( 'Sorry, you are not allowed to edit posts in this post type.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_view', + __( 'Sorry, you are not allowed to edit posts in this post type.' ), + array( 'status' => rest_authorization_required_code() ) + ); } return true; @@ -131,15 +135,27 @@ class WP_REST_Post_Types_Controller extends WP_REST_Controller { $obj = get_post_type_object( $request['type'] ); if ( empty( $obj ) ) { - return new WP_Error( 'rest_type_invalid', __( 'Invalid post type.' ), array( 'status' => 404 ) ); + return new WP_Error( + 'rest_type_invalid', + __( 'Invalid post type.' ), + array( 'status' => 404 ) + ); } if ( empty( $obj->show_in_rest ) ) { - return new WP_Error( 'rest_cannot_read_type', __( 'Cannot view post type.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_read_type', + __( 'Cannot view post type.' ), + array( 'status' => rest_authorization_required_code() ) + ); } if ( 'edit' === $request['context'] && ! current_user_can( $obj->cap->edit_posts ) ) { - return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit posts in this post type.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_forbidden_context', + __( 'Sorry, you are not allowed to edit posts in this post type.' ), + array( 'status' => rest_authorization_required_code() ) + ); } $data = $this->prepare_item_for_response( $obj, $request ); @@ -321,6 +337,7 @@ class WP_REST_Post_Types_Controller extends WP_REST_Controller { ); $this->schema = $schema; + return $this->add_additional_fields_schema( $this->schema ); } diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index ffac007c82..0f27070c3b 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -138,7 +138,11 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { $post_type = get_post_type_object( $this->post_type ); if ( 'edit' === $request['context'] && ! current_user_can( $post_type->cap->edit_posts ) ) { - return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit posts in this post type.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_forbidden_context', + __( 'Sorry, you are not allowed to edit posts in this post type.' ), + array( 'status' => rest_authorization_required_code() ) + ); } return true; @@ -156,12 +160,20 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { // Ensure a search string is set in case the orderby is set to 'relevance'. if ( ! empty( $request['orderby'] ) && 'relevance' === $request['orderby'] && empty( $request['search'] ) ) { - return new WP_Error( 'rest_no_search_term_defined', __( 'You need to define a search term to order by relevance.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_no_search_term_defined', + __( 'You need to define a search term to order by relevance.' ), + array( 'status' => 400 ) + ); } // Ensure an include parameter is set in case the orderby is set to 'include'. if ( ! empty( $request['orderby'] ) && 'include' === $request['orderby'] && empty( $request['include'] ) ) { - return new WP_Error( 'rest_orderby_include_missing_include', __( 'You need to define an include parameter to order by include.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_orderby_include_missing_include', + __( 'You need to define an include parameter to order by include.' ), + array( 'status' => 400 ) + ); } // Retrieve the list of registered collection query parameters. @@ -337,7 +349,11 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { $max_pages = ceil( $total_posts / (int) $posts_query->query_vars['posts_per_page'] ); if ( $page > $max_pages && $total_posts > 0 ) { - return new WP_Error( 'rest_post_invalid_page_number', __( 'The page number requested is larger than the number of pages available.' ), array( 'status' => 400 ) ); + 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 ); @@ -377,7 +393,12 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { * @return WP_Post|WP_Error Post object if ID is valid, WP_Error otherwise. */ protected function get_post( $id ) { - $error = new WP_Error( 'rest_post_invalid_id', __( 'Invalid post ID.' ), array( 'status' => 404 ) ); + $error = new WP_Error( + 'rest_post_invalid_id', + __( 'Invalid post ID.' ), + array( 'status' => 404 ) + ); + if ( (int) $id <= 0 ) { return $error; } @@ -405,13 +426,21 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { } if ( 'edit' === $request['context'] && $post && ! $this->check_update_permission( $post ) ) { - return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit this post.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_forbidden_context', + __( 'Sorry, you are not allowed to edit this post.' ), + array( 'status' => rest_authorization_required_code() ) + ); } if ( $post && ! empty( $request['password'] ) ) { // Check post password, and return error if invalid. if ( ! hash_equals( $post->post_password, $request['password'] ) ) { - return new WP_Error( 'rest_post_incorrect_password', __( 'Incorrect post password.' ), array( 'status' => 403 ) ); + return new WP_Error( + 'rest_post_incorrect_password', + __( 'Incorrect post password.' ), + array( 'status' => 403 ) + ); } } @@ -493,25 +522,45 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { */ public function create_item_permissions_check( $request ) { if ( ! empty( $request['id'] ) ) { - return new WP_Error( 'rest_post_exists', __( 'Cannot create existing post.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_post_exists', + __( 'Cannot create existing post.' ), + array( 'status' => 400 ) + ); } $post_type = get_post_type_object( $this->post_type ); if ( ! empty( $request['author'] ) && get_current_user_id() !== $request['author'] && ! current_user_can( $post_type->cap->edit_others_posts ) ) { - return new WP_Error( 'rest_cannot_edit_others', __( 'Sorry, you are not allowed to create posts as this user.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_edit_others', + __( 'Sorry, you are not allowed to create posts as this user.' ), + array( 'status' => rest_authorization_required_code() ) + ); } if ( ! empty( $request['sticky'] ) && ! current_user_can( $post_type->cap->edit_others_posts ) && ! current_user_can( $post_type->cap->publish_posts ) ) { - return new WP_Error( 'rest_cannot_assign_sticky', __( 'Sorry, you are not allowed to make posts sticky.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_assign_sticky', + __( 'Sorry, you are not allowed to make posts sticky.' ), + array( 'status' => rest_authorization_required_code() ) + ); } if ( ! current_user_can( $post_type->cap->create_posts ) ) { - return new WP_Error( 'rest_cannot_create', __( 'Sorry, you are not allowed to create posts as this user.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_create', + __( 'Sorry, you are not allowed to create posts as this user.' ), + array( 'status' => rest_authorization_required_code() ) + ); } if ( ! $this->check_assign_terms_permission( $request ) ) { - return new WP_Error( 'rest_cannot_assign_term', __( 'Sorry, you are not allowed to assign the provided terms.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_assign_term', + __( 'Sorry, you are not allowed to assign the provided terms.' ), + array( 'status' => rest_authorization_required_code() ) + ); } return true; @@ -527,7 +576,11 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { */ public function create_item( $request ) { if ( ! empty( $request['id'] ) ) { - return new WP_Error( 'rest_post_exists', __( 'Cannot create existing post.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_post_exists', + __( 'Cannot create existing post.' ), + array( 'status' => 400 ) + ); } $prepared_post = $this->prepare_item_for_database( $request ); @@ -650,19 +703,35 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { $post_type = get_post_type_object( $this->post_type ); if ( $post && ! $this->check_update_permission( $post ) ) { - return new WP_Error( 'rest_cannot_edit', __( 'Sorry, you are not allowed to edit this post.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_edit', + __( 'Sorry, you are not allowed to edit this post.' ), + array( 'status' => rest_authorization_required_code() ) + ); } if ( ! empty( $request['author'] ) && get_current_user_id() !== $request['author'] && ! current_user_can( $post_type->cap->edit_others_posts ) ) { - return new WP_Error( 'rest_cannot_edit_others', __( 'Sorry, you are not allowed to update posts as this user.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_edit_others', + __( 'Sorry, you are not allowed to update posts as this user.' ), + array( 'status' => rest_authorization_required_code() ) + ); } if ( ! empty( $request['sticky'] ) && ! current_user_can( $post_type->cap->edit_others_posts ) && ! current_user_can( $post_type->cap->publish_posts ) ) { - return new WP_Error( 'rest_cannot_assign_sticky', __( 'Sorry, you are not allowed to make posts sticky.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_assign_sticky', + __( 'Sorry, you are not allowed to make posts sticky.' ), + array( 'status' => rest_authorization_required_code() ) + ); } if ( ! $this->check_assign_terms_permission( $request ) ) { - return new WP_Error( 'rest_cannot_assign_term', __( 'Sorry, you are not allowed to assign the provided terms.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_assign_term', + __( 'Sorry, you are not allowed to assign the provided terms.' ), + array( 'status' => rest_authorization_required_code() ) + ); } return true; @@ -688,7 +757,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { return $post; } - // convert the post object to an array, otherwise wp_update_post will expect non-escaped input. + // Convert the post object to an array, otherwise wp_update_post() will expect non-escaped input. $post_id = wp_update_post( wp_slash( (array) $post ), true ); if ( is_wp_error( $post_id ) ) { @@ -779,7 +848,11 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { } if ( $post && ! $this->check_delete_permission( $post ) ) { - return new WP_Error( 'rest_cannot_delete', __( 'Sorry, you are not allowed to delete this post.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_delete', + __( 'Sorry, you are not allowed to delete this post.' ), + array( 'status' => rest_authorization_required_code() ) + ); } return true; @@ -823,7 +896,11 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { $supports_trash = apply_filters( "rest_{$this->post_type}_trashable", $supports_trash, $post ); if ( ! $this->check_delete_permission( $post ) ) { - return new WP_Error( 'rest_user_cannot_delete_post', __( 'Sorry, you are not allowed to delete this post.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_user_cannot_delete_post', + __( 'Sorry, you are not allowed to delete this post.' ), + array( 'status' => rest_authorization_required_code() ) + ); } $request->set_param( 'context', 'edit' ); @@ -842,24 +919,36 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { } else { // If we don't support trashing for this type, error out. if ( ! $supports_trash ) { - /* translators: %s: force=true */ - return new WP_Error( 'rest_trash_not_supported', sprintf( __( "The post does not support trashing. Set '%s' to delete." ), 'force=true' ), array( 'status' => 501 ) ); + return new WP_Error( + 'rest_trash_not_supported', + /* translators: %s: force=true */ + sprintf( __( "The post does not support trashing. Set '%s' to delete." ), 'force=true' ), + array( 'status' => 501 ) + ); } // Otherwise, only trash if we haven't already. if ( 'trash' === $post->post_status ) { - return new WP_Error( 'rest_already_trashed', __( 'The post has already been deleted.' ), array( 'status' => 410 ) ); + return new WP_Error( + 'rest_already_trashed', + __( 'The post has already been deleted.' ), + array( 'status' => 410 ) + ); } - // (Note that internally this falls through to `wp_delete_post` if - // the trash is disabled.) + // (Note that internally this falls through to `wp_delete_post()` + // if the trash is disabled.) $result = wp_trash_post( $id ); $post = get_post( $id ); $response = $this->prepare_item_for_response( $post, $request ); } if ( ! $result ) { - return new WP_Error( 'rest_cannot_delete', __( 'The post cannot be deleted.' ), array( 'status' => 500 ) ); + return new WP_Error( + 'rest_cannot_delete', + __( 'The post cannot be deleted.' ), + array( 'status' => 500 ) + ); } /** @@ -1064,7 +1153,11 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { $user_obj = get_userdata( $post_author ); if ( ! $user_obj ) { - return new WP_Error( 'rest_invalid_author', __( 'Invalid author ID.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_invalid_author', + __( 'Invalid author ID.' ), + array( 'status' => 400 ) + ); } } @@ -1077,18 +1170,30 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { if ( '' !== $request['password'] ) { if ( ! empty( $schema['properties']['sticky'] ) && ! empty( $request['sticky'] ) ) { - return new WP_Error( 'rest_invalid_field', __( 'A post can not be sticky and have a password.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_invalid_field', + __( 'A post can not be sticky and have a password.' ), + array( 'status' => 400 ) + ); } if ( ! empty( $prepared_post->ID ) && is_sticky( $prepared_post->ID ) ) { - return new WP_Error( 'rest_invalid_field', __( 'A sticky post can not be password protected.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_invalid_field', + __( 'A sticky post can not be password protected.' ), + array( 'status' => 400 ) + ); } } } if ( ! empty( $schema['properties']['sticky'] ) && ! empty( $request['sticky'] ) ) { if ( ! empty( $prepared_post->ID ) && post_password_required( $prepared_post->ID ) ) { - return new WP_Error( 'rest_invalid_field', __( 'A password protected post can not be set to sticky.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_invalid_field', + __( 'A password protected post can not be set to sticky.' ), + array( 'status' => 400 ) + ); } } @@ -1098,9 +1203,15 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { $prepared_post->post_parent = 0; } else { $parent = get_post( (int) $request['parent'] ); + if ( empty( $parent ) ) { - return new WP_Error( 'rest_post_invalid_id', __( 'Invalid post parent ID.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_post_invalid_id', + __( 'Invalid post parent ID.' ), + array( 'status' => 400 ) + ); } + $prepared_post->post_parent = (int) $parent->ID; } } @@ -1157,13 +1268,21 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { break; case 'private': if ( ! current_user_can( $post_type->cap->publish_posts ) ) { - return new WP_Error( 'rest_cannot_publish', __( 'Sorry, you are not allowed to create private posts in this post type.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_publish', + __( 'Sorry, you are not allowed to create private posts in this post type.' ), + array( 'status' => rest_authorization_required_code() ) + ); } break; case 'publish': case 'future': if ( ! current_user_can( $post_type->cap->publish_posts ) ) { - return new WP_Error( 'rest_cannot_publish', __( 'Sorry, you are not allowed to publish posts in this post type.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_publish', + __( 'Sorry, you are not allowed to publish posts in this post type.' ), + array( 'status' => rest_authorization_required_code() ) + ); } break; default: @@ -1193,7 +1312,11 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { if ( $result ) { return true; } else { - return new WP_Error( 'rest_invalid_featured_media', __( 'Invalid featured media ID.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_invalid_featured_media', + __( 'Invalid featured media ID.' ), + array( 'status' => 400 ) + ); } } else { return delete_post_thumbnail( $post_id ); @@ -1234,8 +1357,11 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { return true; } - /* translators: 1: Parameter, 2: List of valid values. */ - return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not one of %2$s.' ), 'template', implode( ', ', array_keys( $allowed_templates ) ) ) ); + return new WP_Error( + 'rest_invalid_param', + /* translators: 1: Parameter, 2: List of valid values. */ + sprintf( __( '%1$s is not one of %2$s.' ), 'template', implode( ', ', array_keys( $allowed_templates ) ) ) + ); } /** @@ -1463,10 +1589,12 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { } if ( rest_is_field_included( 'date_gmt', $fields ) ) { - // For drafts, `post_date_gmt` may not be set, indicating that the - // date of the draft should be updated each time it is saved (see - // #38883). In this case, shim the value based on the `post_date` - // field with the site's timezone offset applied. + /* + * For drafts, `post_date_gmt` may not be set, indicating that the date + * of the draft should be updated each time it is saved (see #38883). + * In this case, shim the value based on the `post_date` field + * with the site's timezone offset applied. + */ if ( '0000-00-00 00:00:00' === $post->post_date_gmt ) { $post_date_gmt = get_gmt_from_date( $post->post_date ); } else { @@ -1488,10 +1616,11 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { } if ( rest_is_field_included( 'modified_gmt', $fields ) ) { - // For drafts, `post_modified_gmt` may not be set (see - // `post_date_gmt` comments above). In this case, shim the value - // based on the `post_modified` field with the site's timezone - // offset applied. + /* + * For drafts, `post_modified_gmt` may not be set (see `post_date_gmt` comments + * above). In this case, shim the value based on the `post_modified` field + * with the site's timezone offset applied. + */ if ( '0000-00-00 00:00:00' === $post->post_modified_gmt ) { $post_modified_gmt = gmdate( 'Y-m-d H:i:s', strtotime( $post->post_modified ) - ( get_option( 'gmt_offset' ) * 3600 ) ); } else { @@ -2078,8 +2207,8 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { '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() + '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( @@ -2103,8 +2232,8 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { 'type' => 'object', 'context' => array( 'view', 'edit' ), '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() + '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( @@ -2148,8 +2277,8 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { '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() + '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( @@ -2241,6 +2370,7 @@ 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; @@ -2277,6 +2407,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { } $this->schema = $schema; + return $this->add_additional_fields_schema( $this->schema ); } @@ -2622,7 +2753,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { public function sanitize_post_statuses( $statuses, $request, $parameter ) { $statuses = wp_parse_slug_list( $statuses ); - // The default status is different in WP_REST_Attachments_Controller + // The default status is different in WP_REST_Attachments_Controller. $attributes = $request->get_attributes(); $default_status = $attributes['args']['status']['default']; @@ -2639,7 +2770,11 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { return $result; } } else { - return new WP_Error( 'rest_forbidden_status', __( 'Status is forbidden.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_forbidden_status', + __( 'Status is forbidden.' ), + array( 'status' => rest_authorization_required_code() ) + ); } } diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php index cffeda5e9a..c676882d97 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php @@ -138,7 +138,11 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller { * @return WP_Post|WP_Error Post object if ID is valid, WP_Error otherwise. */ protected function get_parent( $parent ) { - $error = new WP_Error( 'rest_post_invalid_parent', __( 'Invalid post parent ID.' ), array( 'status' => 404 ) ); + $error = new WP_Error( + 'rest_post_invalid_parent', + __( 'Invalid post parent ID.' ), + array( 'status' => 404 ) + ); if ( (int) $parent <= 0 ) { return $error; } @@ -166,8 +170,13 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller { } $parent_post_type_obj = get_post_type_object( $parent->post_type ); + if ( ! current_user_can( $parent_post_type_obj->cap->edit_post, $parent->ID ) ) { - return new WP_Error( 'rest_cannot_read', __( 'Sorry, you are not allowed to view revisions of this post.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_read', + __( 'Sorry, you are not allowed to view revisions of this post.' ), + array( 'status' => rest_authorization_required_code() ) + ); } return true; @@ -182,7 +191,12 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller { * @return WP_Post|WP_Error Revision post object if ID is valid, WP_Error otherwise. */ protected function get_revision( $id ) { - $error = new WP_Error( 'rest_post_invalid_id', __( 'Invalid revision ID.' ), array( 'status' => 404 ) ); + $error = new WP_Error( + 'rest_post_invalid_id', + __( 'Invalid revision ID.' ), + array( 'status' => 404 ) + ); + if ( (int) $id <= 0 ) { return $error; } @@ -211,12 +225,20 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller { // Ensure a search string is set in case the orderby is set to 'relevance'. if ( ! empty( $request['orderby'] ) && 'relevance' === $request['orderby'] && empty( $request['search'] ) ) { - return new WP_Error( 'rest_no_search_term_defined', __( 'You need to define a search term to order by relevance.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_no_search_term_defined', + __( 'You need to define a search term to order by relevance.' ), + array( 'status' => 400 ) + ); } // Ensure an include parameter is set in case the orderby is set to 'include'. if ( ! empty( $request['orderby'] ) && 'include' === $request['orderby'] && empty( $request['include'] ) ) { - return new WP_Error( 'rest_orderby_include_missing_include', __( 'You need to define an include parameter to order by include.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_orderby_include_missing_include', + __( 'You need to define an include parameter to order by include.' ), + array( 'status' => 400 ) + ); } if ( wp_revisions_enabled( $parent ) ) { @@ -281,9 +303,17 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller { if ( $total_revisions > 0 ) { if ( $offset >= $total_revisions ) { - return new WP_Error( 'rest_revision_invalid_offset_number', __( 'The offset number requested is larger than or equal to the number of available revisions.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_revision_invalid_offset_number', + __( 'The offset number requested is larger than or equal to the number of available revisions.' ), + array( 'status' => 400 ) + ); } elseif ( ! $offset && $page > $max_pages ) { - return new WP_Error( 'rest_revision_invalid_page_number', __( 'The page number requested is larger than the number of pages available.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_revision_invalid_page_number', + __( 'The page number requested is larger than the number of pages available.' ), + array( 'status' => 400 ) + ); } } } else { @@ -294,6 +324,7 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller { } $response = array(); + foreach ( $revisions as $revision ) { $data = $this->prepare_item_for_response( $revision, $request ); $response[] = $this->prepare_response_for_collection( $data ); @@ -354,8 +385,13 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller { } $parent_post_type = get_post_type_object( $parent->post_type ); + if ( ! current_user_can( $parent_post_type->cap->delete_post, $parent->ID ) ) { - return new WP_Error( 'rest_cannot_delete', __( 'Sorry, you are not allowed to delete revisions of this post.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_delete', + __( 'Sorry, you are not allowed to delete revisions of this post.' ), + array( 'status' => rest_authorization_required_code() ) + ); } $revision = $this->get_revision( $request['id'] ); @@ -394,7 +430,11 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller { $post_type = get_post_type_object( 'revision' ); if ( ! current_user_can( $post_type->cap->delete_post, $revision->ID ) ) { - return new WP_Error( 'rest_cannot_delete', __( 'Sorry, you are not allowed to delete this revision.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_delete', + __( 'Sorry, you are not allowed to delete this revision.' ), + array( 'status' => rest_authorization_required_code() ) + ); } return true; @@ -418,8 +458,12 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller { // We don't support trashing for revisions. if ( ! $force ) { - /* translators: %s: force=true */ - return new WP_Error( 'rest_trash_not_supported', sprintf( __( "Revisions do not support trashing. Set '%s' to delete." ), 'force=true' ), array( 'status' => 501 ) ); + return new WP_Error( + 'rest_trash_not_supported', + /* translators: %s: force=true */ + sprintf( __( "Revisions do not support trashing. Set '%s' to delete." ), 'force=true' ), + array( 'status' => 501 ) + ); } $previous = $this->prepare_item_for_response( $revision, $request ); @@ -439,7 +483,11 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller { do_action( 'rest_delete_revision', $result, $request ); if ( ! $result ) { - return new WP_Error( 'rest_cannot_delete', __( 'The post cannot be deleted.' ), array( 'status' => 500 ) ); + return new WP_Error( + 'rest_cannot_delete', + __( 'The post cannot be deleted.' ), + array( 'status' => 500 ) + ); } $response = new WP_REST_Response(); @@ -701,6 +749,7 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller { } $this->schema = $schema; + return $this->add_additional_fields_schema( $this->schema ); } diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php index b657311edd..b3e9db72b7 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php @@ -68,9 +68,12 @@ class WP_REST_Search_Controller extends WP_REST_Controller { foreach ( $search_handlers as $search_handler ) { if ( ! $search_handler instanceof WP_REST_Search_Handler ) { - - /* translators: %s: PHP class name. */ - _doing_it_wrong( __METHOD__, sprintf( __( 'REST search handlers must extend the %s class.' ), 'WP_REST_Search_Handler' ), '5.0.0' ); + _doing_it_wrong( + __METHOD__, + /* translators: %s: PHP class name. */ + sprintf( __( 'REST search handlers must extend the %s class.' ), 'WP_REST_Search_Handler' ), + '5.0.0' + ); continue; } @@ -130,12 +133,17 @@ class WP_REST_Search_Controller extends WP_REST_Controller { $result = $handler->search_items( $request ); if ( ! isset( $result[ WP_REST_Search_Handler::RESULT_IDS ] ) || ! is_array( $result[ WP_REST_Search_Handler::RESULT_IDS ] ) || ! isset( $result[ WP_REST_Search_Handler::RESULT_TOTAL ] ) ) { - return new WP_Error( 'rest_search_handler_error', __( 'Internal search handler error.' ), array( 'status' => 500 ) ); + return new WP_Error( + 'rest_search_handler_error', + __( 'Internal search handler error.' ), + array( 'status' => 500 ) + ); } $ids = array_map( 'absint', $result[ WP_REST_Search_Handler::RESULT_IDS ] ); $results = array(); + foreach ( $ids as $id ) { $data = $this->prepare_item_for_response( $id, $request ); $results[] = $this->prepare_response_for_collection( $data ); @@ -147,7 +155,11 @@ class WP_REST_Search_Controller extends WP_REST_Controller { $max_pages = ceil( $total / $per_page ); if ( $page > $max_pages && $total > 0 ) { - return new WP_Error( 'rest_search_invalid_page_number', __( 'The page number requested is larger than the number of pages available.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_search_invalid_page_number', + __( 'The page number requested is larger than the number of pages available.' ), + array( 'status' => 400 ) + ); } $response = rest_ensure_response( $results ); @@ -217,6 +229,7 @@ class WP_REST_Search_Controller extends WP_REST_Controller { $types = array(); $subtypes = array(); + foreach ( $this->search_handlers as $search_handler ) { $types[] = $search_handler->get_type(); $subtypes = array_merge( $subtypes, $search_handler->get_subtypes() ); @@ -267,6 +280,7 @@ class WP_REST_Search_Controller extends WP_REST_Controller { ); $this->schema = $schema; + return $this->add_additional_fields_schema( $this->schema ); } @@ -280,6 +294,7 @@ class WP_REST_Search_Controller extends WP_REST_Controller { public function get_collection_params() { $types = array(); $subtypes = array(); + foreach ( $this->search_handlers as $search_handler ) { $types[] = $search_handler->get_type(); $subtypes = array_merge( $subtypes, $search_handler->get_subtypes() ); @@ -356,7 +371,11 @@ class WP_REST_Search_Controller extends WP_REST_Controller { $type = $request->get_param( self::PROP_TYPE ); if ( ! $type || ! isset( $this->search_handlers[ $type ] ) ) { - return new WP_Error( 'rest_search_invalid_type', __( 'Invalid type parameter.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_search_invalid_type', + __( 'Invalid type parameter.' ), + array( 'status' => 400 ) + ); } return $this->search_handlers[ $type ]; diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php index c5cf1a7a4b..0fbdb4f5c9 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php @@ -131,6 +131,7 @@ class WP_REST_Settings_Controller extends WP_REST_Controller { if ( is_wp_error( rest_validate_value_from_schema( $value, $schema ) ) ) { return null; } + return rest_sanitize_value_from_schema( $value, $schema ); } @@ -294,6 +295,7 @@ class WP_REST_Settings_Controller extends WP_REST_Controller { } $this->schema = $schema; + return $this->add_additional_fields_schema( $this->schema ); } @@ -315,6 +317,7 @@ class WP_REST_Settings_Controller extends WP_REST_Controller { if ( is_null( $value ) ) { return $value; } + return rest_parse_request_arg( $value, $request, $param ); } @@ -336,6 +339,7 @@ class WP_REST_Settings_Controller extends WP_REST_Controller { foreach ( $schema['properties'] as $key => $child_schema ) { $schema['properties'][ $key ] = $this->set_additional_properties_to_false( $child_schema ); } + $schema['additionalProperties'] = false; break; case 'array': diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php index bc2a82e965..89544b9365 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php @@ -87,13 +87,20 @@ class WP_REST_Taxonomies_Controller extends WP_REST_Controller { } else { $taxonomies = get_taxonomies( '', 'objects' ); } + foreach ( $taxonomies as $taxonomy ) { if ( ! empty( $taxonomy->show_in_rest ) && current_user_can( $taxonomy->cap->assign_terms ) ) { return true; } } - return new WP_Error( 'rest_cannot_view', __( 'Sorry, you are not allowed to manage terms in this taxonomy.' ), array( 'status' => rest_authorization_required_code() ) ); + + return new WP_Error( + 'rest_cannot_view', + __( 'Sorry, you are not allowed to manage terms in this taxonomy.' ), + array( 'status' => rest_authorization_required_code() ) + ); } + return true; } @@ -115,11 +122,14 @@ class WP_REST_Taxonomies_Controller extends WP_REST_Controller { } else { $taxonomies = get_taxonomies( '', 'objects' ); } + $data = array(); + foreach ( $taxonomies as $tax_type => $value ) { if ( empty( $value->show_in_rest ) || ( 'edit' === $request['context'] && ! current_user_can( $value->cap->assign_terms ) ) ) { continue; } + $tax = $this->prepare_item_for_response( $value, $request ); $tax = $this->prepare_response_for_collection( $tax ); $data[ $tax_type ] = $tax; @@ -149,8 +159,13 @@ class WP_REST_Taxonomies_Controller extends WP_REST_Controller { if ( empty( $tax_obj->show_in_rest ) ) { return false; } + if ( 'edit' === $request['context'] && ! current_user_can( $tax_obj->cap->assign_terms ) ) { - return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to manage terms in this taxonomy.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_forbidden_context', + __( 'Sorry, you are not allowed to manage terms in this taxonomy.' ), + array( 'status' => rest_authorization_required_code() ) + ); } } @@ -167,10 +182,17 @@ class WP_REST_Taxonomies_Controller extends WP_REST_Controller { */ public function get_item( $request ) { $tax_obj = get_taxonomy( $request['taxonomy'] ); + if ( empty( $tax_obj ) ) { - return new WP_Error( 'rest_taxonomy_invalid', __( 'Invalid taxonomy.' ), array( 'status' => 404 ) ); + return new WP_Error( + 'rest_taxonomy_invalid', + __( 'Invalid taxonomy.' ), + array( 'status' => 404 ) + ); } + $data = $this->prepare_item_for_response( $tax_obj, $request ); + return rest_ensure_response( $data ); } @@ -379,6 +401,7 @@ class WP_REST_Taxonomies_Controller extends WP_REST_Controller { ); $this->schema = $schema; + return $this->add_additional_fields_schema( $this->schema ); } diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php index cbbf175738..63cede1080 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php @@ -144,12 +144,19 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { */ public function get_items_permissions_check( $request ) { $tax_obj = get_taxonomy( $this->taxonomy ); + if ( ! $tax_obj || ! $this->check_is_taxonomy_allowed( $this->taxonomy ) ) { return false; } + if ( 'edit' === $request['context'] && ! current_user_can( $tax_obj->cap->edit_terms ) ) { - return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit terms in this taxonomy.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_forbidden_context', + __( 'Sorry, you are not allowed to edit terms in this taxonomy.' ), + array( 'status' => rest_authorization_required_code() ) + ); } + return true; } @@ -258,7 +265,7 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { $total_terms = wp_count_terms( $this->taxonomy, $count_args ); - // wp_count_terms can return a falsy value when the term has no children. + // wp_count_terms() can return a falsy value when the term has no children. if ( ! $total_terms ) { $total_terms = 0; } @@ -312,7 +319,11 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { * @return WP_Term|WP_Error Term object if ID is valid, WP_Error otherwise. */ protected function get_term( $id ) { - $error = new WP_Error( 'rest_term_invalid', __( 'Term does not exist.' ), array( 'status' => 404 ) ); + $error = new WP_Error( + 'rest_term_invalid', + __( 'Term does not exist.' ), + array( 'status' => 404 ) + ); if ( ! $this->check_is_taxonomy_allowed( $this->taxonomy ) ) { return $error; @@ -340,13 +351,19 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { */ public function get_item_permissions_check( $request ) { $term = $this->get_term( $request['id'] ); + if ( is_wp_error( $term ) ) { return $term; } if ( 'edit' === $request['context'] && ! current_user_can( 'edit_term', $term->term_id ) ) { - return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit this term.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_forbidden_context', + __( 'Sorry, you are not allowed to edit this term.' ), + array( 'status' => rest_authorization_required_code() ) + ); } + return true; } @@ -384,11 +401,16 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { } $taxonomy_obj = get_taxonomy( $this->taxonomy ); + if ( ( is_taxonomy_hierarchical( $this->taxonomy ) && ! current_user_can( $taxonomy_obj->cap->edit_terms ) ) || ( ! is_taxonomy_hierarchical( $this->taxonomy ) && ! current_user_can( $taxonomy_obj->cap->assign_terms ) ) ) { - return new WP_Error( 'rest_cannot_create', __( 'Sorry, you are not allowed to create new terms.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_create', + __( 'Sorry, you are not allowed to create new terms.' ), + array( 'status' => rest_authorization_required_code() ) + ); } return true; @@ -405,13 +427,21 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { public function create_item( $request ) { if ( isset( $request['parent'] ) ) { if ( ! is_taxonomy_hierarchical( $this->taxonomy ) ) { - return new WP_Error( 'rest_taxonomy_not_hierarchical', __( 'Cannot set parent term, taxonomy is not hierarchical.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_taxonomy_not_hierarchical', + __( 'Cannot set parent term, taxonomy is not hierarchical.' ), + array( 'status' => 400 ) + ); } $parent = get_term( (int) $request['parent'], $this->taxonomy ); if ( ! $parent ) { - return new WP_Error( 'rest_term_invalid', __( 'Parent term does not exist.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_term_invalid', + __( 'Parent term does not exist.' ), + array( 'status' => 400 ) + ); } } @@ -502,12 +532,17 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { */ public function update_item_permissions_check( $request ) { $term = $this->get_term( $request['id'] ); + if ( is_wp_error( $term ) ) { return $term; } if ( ! current_user_can( 'edit_term', $term->term_id ) ) { - return new WP_Error( 'rest_cannot_update', __( 'Sorry, you are not allowed to edit this term.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_update', + __( 'Sorry, you are not allowed to edit this term.' ), + array( 'status' => rest_authorization_required_code() ) + ); } return true; @@ -529,13 +564,21 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { if ( isset( $request['parent'] ) ) { if ( ! is_taxonomy_hierarchical( $this->taxonomy ) ) { - return new WP_Error( 'rest_taxonomy_not_hierarchical', __( 'Cannot set parent term, taxonomy is not hierarchical.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_taxonomy_not_hierarchical', + __( 'Cannot set parent term, taxonomy is not hierarchical.' ), + array( 'status' => 400 ) + ); } $parent = get_term( (int) $request['parent'], $this->taxonomy ); if ( ! $parent ) { - return new WP_Error( 'rest_term_invalid', __( 'Parent term does not exist.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_term_invalid', + __( 'Parent term does not exist.' ), + array( 'status' => 400 ) + ); } } @@ -590,12 +633,17 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { */ public function delete_item_permissions_check( $request ) { $term = $this->get_term( $request['id'] ); + if ( is_wp_error( $term ) ) { return $term; } if ( ! current_user_can( 'delete_term', $term->term_id ) ) { - return new WP_Error( 'rest_cannot_delete', __( 'Sorry, you are not allowed to delete this term.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_delete', + __( 'Sorry, you are not allowed to delete this term.' ), + array( 'status' => rest_authorization_required_code() ) + ); } return true; @@ -619,8 +667,12 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { // We don't support trashing for terms. if ( ! $force ) { - /* translators: %s: force=true */ - return new WP_Error( 'rest_trash_not_supported', sprintf( __( "Terms do not support trashing. Set '%s' to delete." ), 'force=true' ), array( 'status' => 501 ) ); + return new WP_Error( + 'rest_trash_not_supported', + /* translators: %s: force=true */ + sprintf( __( "Terms do not support trashing. Set '%s' to delete." ), 'force=true' ), + array( 'status' => 501 ) + ); } $request->set_param( 'context', 'view' ); @@ -630,7 +682,11 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { $retval = wp_delete_term( $term->term_id, $term->taxonomy ); if ( ! $retval ) { - return new WP_Error( 'rest_cannot_delete', __( 'The term cannot be deleted.' ), array( 'status' => 500 ) ); + return new WP_Error( + 'rest_cannot_delete', + __( 'The term cannot be deleted.' ), + array( 'status' => 500 ) + ); } $response = new WP_REST_Response(); @@ -929,6 +985,7 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { $schema['properties']['meta'] = $this->meta->get_field_schema(); $this->schema = $schema; + return $this->add_additional_fields_schema( $this->schema ); } diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index 47491e7774..1d86d9938a 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -59,7 +59,11 @@ class WP_REST_Themes_Controller extends WP_REST_Controller { */ public function get_items_permissions_check( $request ) { if ( ! is_user_logged_in() || ! current_user_can( 'edit_posts' ) ) { - return new WP_Error( 'rest_user_cannot_view', __( 'Sorry, you are not allowed to view themes.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_user_cannot_view', + __( 'Sorry, you are not allowed to view themes.' ), + array( 'status' => rest_authorization_required_code() ) + ); } return true; @@ -182,6 +186,7 @@ class WP_REST_Themes_Controller extends WP_REST_Controller { ); $this->schema = $schema; + return $this->add_additional_fields_schema( $this->schema ); } diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php index 301d41dbf6..19e745a415 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php @@ -173,7 +173,11 @@ class WP_REST_Users_Controller extends WP_REST_Controller { return false; } - return new WP_Error( 'rest_invalid_param', __( 'Invalid user parameter(s).' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_invalid_param', + __( 'Invalid user parameter(s).' ), + array( 'status' => 400 ) + ); } /** @@ -187,15 +191,27 @@ class WP_REST_Users_Controller extends WP_REST_Controller { public function get_items_permissions_check( $request ) { // Check if roles is specified in GET request and if user can list users. if ( ! empty( $request['roles'] ) && ! current_user_can( 'list_users' ) ) { - return new WP_Error( 'rest_user_cannot_view', __( 'Sorry, you are not allowed to filter users by role.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_user_cannot_view', + __( 'Sorry, you are not allowed to filter users by role.' ), + array( 'status' => rest_authorization_required_code() ) + ); } if ( 'edit' === $request['context'] && ! current_user_can( 'list_users' ) ) { - return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_forbidden_context', + __( 'Sorry, you are not allowed to list users.' ), + array( 'status' => rest_authorization_required_code() ) + ); } if ( in_array( $request['orderby'], array( 'email', 'registered_date' ), true ) && ! current_user_can( 'list_users' ) ) { - return new WP_Error( 'rest_forbidden_orderby', __( 'Sorry, you are not allowed to order users by this parameter.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_forbidden_orderby', + __( 'Sorry, you are not allowed to order users by this parameter.' ), + array( 'status' => rest_authorization_required_code() ) + ); } if ( 'authors' === $request['who'] ) { @@ -208,7 +224,11 @@ class WP_REST_Users_Controller extends WP_REST_Controller { } } - return new WP_Error( 'rest_forbidden_who', __( 'Sorry, you are not allowed to query users by this parameter.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_forbidden_who', + __( 'Sorry, you are not allowed to query users by this parameter.' ), + array( 'status' => rest_authorization_required_code() ) + ); } return true; @@ -358,7 +378,12 @@ class WP_REST_Users_Controller extends WP_REST_Controller { * @return WP_User|WP_Error True if ID is valid, WP_Error otherwise. */ protected function get_user( $id ) { - $error = new WP_Error( 'rest_user_invalid_id', __( 'Invalid user ID.' ), array( 'status' => 404 ) ); + $error = new WP_Error( + 'rest_user_invalid_id', + __( 'Invalid user ID.' ), + array( 'status' => 404 ) + ); + if ( (int) $id <= 0 ) { return $error; } @@ -396,9 +421,17 @@ class WP_REST_Users_Controller extends WP_REST_Controller { } if ( 'edit' === $request['context'] && ! current_user_can( 'list_users' ) ) { - return new WP_Error( 'rest_user_cannot_view', __( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_user_cannot_view', + __( 'Sorry, you are not allowed to list users.' ), + array( 'status' => rest_authorization_required_code() ) + ); } elseif ( ! count_user_posts( $user->ID, $types ) && ! current_user_can( 'edit_user', $user->ID ) && ! current_user_can( 'list_users' ) ) { - return new WP_Error( 'rest_user_cannot_view', __( 'Sorry, you are not allowed to list users.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_user_cannot_view', + __( 'Sorry, you are not allowed to list users.' ), + array( 'status' => rest_authorization_required_code() ) + ); } return true; @@ -436,7 +469,11 @@ class WP_REST_Users_Controller extends WP_REST_Controller { $current_user_id = get_current_user_id(); if ( empty( $current_user_id ) ) { - return new WP_Error( 'rest_not_logged_in', __( 'You are not currently logged in.' ), array( 'status' => 401 ) ); + return new WP_Error( + 'rest_not_logged_in', + __( 'You are not currently logged in.' ), + array( 'status' => 401 ) + ); } $user = wp_get_current_user(); @@ -457,7 +494,11 @@ class WP_REST_Users_Controller extends WP_REST_Controller { public function create_item_permissions_check( $request ) { if ( ! current_user_can( 'create_users' ) ) { - return new WP_Error( 'rest_cannot_create_user', __( 'Sorry, you are not allowed to create new users.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_create_user', + __( 'Sorry, you are not allowed to create new users.' ), + array( 'status' => rest_authorization_required_code() ) + ); } return true; @@ -473,7 +514,11 @@ class WP_REST_Users_Controller extends WP_REST_Controller { */ public function create_item( $request ) { if ( ! empty( $request['id'] ) ) { - return new WP_Error( 'rest_user_exists', __( 'Cannot create existing user.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_user_exists', + __( 'Cannot create existing user.' ), + array( 'status' => 400 ) + ); } $schema = $this->get_item_schema(); @@ -492,12 +537,19 @@ class WP_REST_Users_Controller extends WP_REST_Controller { $ret = wpmu_validate_user_signup( $user->user_login, $user->user_email ); if ( is_wp_error( $ret['errors'] ) && $ret['errors']->has_errors() ) { - $error = new WP_Error( 'rest_invalid_param', __( 'Invalid user parameter(s).' ), array( 'status' => 400 ) ); + $error = new WP_Error( + 'rest_invalid_param', + __( 'Invalid user parameter(s).' ), + array( 'status' => 400 ) + ); + foreach ( $ret['errors']->errors as $code => $messages ) { foreach ( $messages as $message ) { $error->add( $code, $message ); } + $error_data = $error->get_error_data( $code ); + if ( $error_data ) { $error->add_data( $error_data, $code ); } @@ -510,7 +562,11 @@ class WP_REST_Users_Controller extends WP_REST_Controller { $user_id = wpmu_create_user( $user->user_login, $user->user_pass, $user->user_email ); if ( ! $user_id ) { - return new WP_Error( 'rest_user_create', __( 'Error creating new user.' ), array( 'status' => 500 ) ); + return new WP_Error( + 'rest_user_create', + __( 'Error creating new user.' ), + array( 'status' => 500 ) + ); } $user->ID = $user_id; @@ -602,7 +658,11 @@ class WP_REST_Users_Controller extends WP_REST_Controller { if ( ! empty( $request['roles'] ) ) { if ( ! current_user_can( 'promote_user', $user->ID ) ) { - return new WP_Error( 'rest_cannot_edit_roles', __( 'Sorry, you are not allowed to edit roles of this user.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_edit_roles', + __( 'Sorry, you are not allowed to edit roles of this user.' ), + array( 'status' => rest_authorization_required_code() ) + ); } $request_params = array_keys( $request->get_params() ); @@ -615,7 +675,11 @@ class WP_REST_Users_Controller extends WP_REST_Controller { } if ( ! current_user_can( 'edit_user', $user->ID ) ) { - return new WP_Error( 'rest_cannot_edit', __( 'Sorry, you are not allowed to edit this user.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_cannot_edit', + __( 'Sorry, you are not allowed to edit this user.' ), + array( 'status' => rest_authorization_required_code() ) + ); } return true; @@ -638,21 +702,37 @@ class WP_REST_Users_Controller extends WP_REST_Controller { $id = $user->ID; if ( ! $user ) { - return new WP_Error( 'rest_user_invalid_id', __( 'Invalid user ID.' ), array( 'status' => 404 ) ); + return new WP_Error( + 'rest_user_invalid_id', + __( 'Invalid user ID.' ), + array( 'status' => 404 ) + ); } $owner_id = email_exists( $request['email'] ); if ( $owner_id && $owner_id !== $id ) { - return new WP_Error( 'rest_user_invalid_email', __( 'Invalid email address.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_user_invalid_email', + __( 'Invalid email address.' ), + array( 'status' => 400 ) + ); } if ( ! empty( $request['username'] ) && $request['username'] !== $user->user_login ) { - return new WP_Error( 'rest_user_invalid_argument', __( "Username isn't editable." ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_user_invalid_argument', + __( "Username isn't editable." ), + array( 'status' => 400 ) + ); } if ( ! empty( $request['slug'] ) && $request['slug'] !== $user->user_nicename && get_user_by( 'slug', $request['slug'] ) ) { - return new WP_Error( 'rest_user_invalid_slug', __( 'Invalid slug.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_user_invalid_slug', + __( 'Invalid slug.' ), + array( 'status' => 400 ) + ); } if ( ! empty( $request['roles'] ) ) { @@ -754,7 +834,11 @@ class WP_REST_Users_Controller extends WP_REST_Controller { } if ( ! current_user_can( 'delete_user', $user->ID ) ) { - return new WP_Error( 'rest_user_cannot_delete', __( 'Sorry, you are not allowed to delete this user.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_user_cannot_delete', + __( 'Sorry, you are not allowed to delete this user.' ), + array( 'status' => rest_authorization_required_code() ) + ); } return true; @@ -771,9 +855,15 @@ class WP_REST_Users_Controller extends WP_REST_Controller { public function delete_item( $request ) { // We don't support delete requests in multisite. if ( is_multisite() ) { - return new WP_Error( 'rest_cannot_delete', __( 'The user cannot be deleted.' ), array( 'status' => 501 ) ); + return new WP_Error( + 'rest_cannot_delete', + __( 'The user cannot be deleted.' ), + array( 'status' => 501 ) + ); } + $user = $this->get_user( $request['id'] ); + if ( is_wp_error( $user ) ) { return $user; } @@ -784,13 +874,21 @@ class WP_REST_Users_Controller extends WP_REST_Controller { // We don't support trashing for users. if ( ! $force ) { - /* translators: %s: force=true */ - return new WP_Error( 'rest_trash_not_supported', sprintf( __( "Users do not support trashing. Set '%s' to delete." ), 'force=true' ), array( 'status' => 501 ) ); + return new WP_Error( + 'rest_trash_not_supported', + /* translators: %s: force=true */ + sprintf( __( "Users do not support trashing. Set '%s' to delete." ), 'force=true' ), + array( 'status' => 501 ) + ); } if ( ! empty( $reassign ) ) { if ( $reassign === $id || ! get_userdata( $reassign ) ) { - return new WP_Error( 'rest_user_invalid_reassign', __( 'Invalid user ID for reassignment.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_user_invalid_reassign', + __( 'Invalid user ID for reassignment.' ), + array( 'status' => 400 ) + ); } } @@ -804,7 +902,11 @@ class WP_REST_Users_Controller extends WP_REST_Controller { $result = wp_delete_user( $id, $reassign ); if ( ! $result ) { - return new WP_Error( 'rest_cannot_delete', __( 'The user cannot be deleted.' ), array( 'status' => 500 ) ); + return new WP_Error( + 'rest_cannot_delete', + __( 'The user cannot be deleted.' ), + array( 'status' => 500 ) + ); } $response = new WP_REST_Response(); @@ -1000,7 +1102,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller { $schema = $this->get_item_schema(); - // required arguments. + // Required arguments. if ( isset( $request['email'] ) && ! empty( $schema['properties']['email'] ) ) { $prepared_user->user_email = $request['email']; } @@ -1013,7 +1115,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller { $prepared_user->user_pass = $request['password']; } - // optional arguments. + // Optional arguments. if ( isset( $request['id'] ) ) { $prepared_user->ID = absint( $request['id'] ); } @@ -1050,7 +1152,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller { $prepared_user->locale = $request['locale']; } - // setting roles will be handled outside of this function. + // Setting roles will be handled outside of this function. if ( isset( $request['roles'] ) ) { $prepared_user->role = false; } @@ -1082,8 +1184,12 @@ class WP_REST_Users_Controller extends WP_REST_Controller { foreach ( $roles as $role ) { if ( ! isset( $wp_roles->role_objects[ $role ] ) ) { - /* translators: %s: Role key. */ - return new WP_Error( 'rest_user_invalid_role', sprintf( __( 'The role %s does not exist.' ), $role ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_user_invalid_role', + /* translators: %s: Role key. */ + sprintf( __( 'The role %s does not exist.' ), $role ), + array( 'status' => 400 ) + ); } $potential_role = $wp_roles->role_objects[ $role ]; @@ -1097,7 +1203,11 @@ class WP_REST_Users_Controller extends WP_REST_Controller { && get_current_user_id() === $user_id && ! $potential_role->has_cap( 'edit_users' ) ) { - return new WP_Error( 'rest_user_invalid_role', __( 'Sorry, you are not allowed to give users that role.' ), array( 'status' => rest_authorization_required_code() ) ); + return new WP_Error( + 'rest_user_invalid_role', + __( 'Sorry, you are not allowed to give users that role.' ), + array( 'status' => rest_authorization_required_code() ) + ); } /** Include admin functions to get access to get_editable_roles() */ @@ -1107,7 +1217,11 @@ class WP_REST_Users_Controller extends WP_REST_Controller { $editable_roles = get_editable_roles(); if ( empty( $editable_roles[ $role ] ) ) { - return new WP_Error( 'rest_user_invalid_role', __( 'Sorry, you are not allowed to give users that role.' ), array( 'status' => 403 ) ); + return new WP_Error( + 'rest_user_invalid_role', + __( 'Sorry, you are not allowed to give users that role.' ), + array( 'status' => 403 ) + ); } } @@ -1130,14 +1244,22 @@ class WP_REST_Users_Controller extends WP_REST_Controller { $username = (string) $value; if ( ! validate_username( $username ) ) { - return new WP_Error( 'rest_user_invalid_username', __( 'Username contains invalid characters.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_user_invalid_username', + __( 'Username contains invalid characters.' ), + array( 'status' => 400 ) + ); } /** This filter is documented in wp-includes/user.php */ $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); if ( in_array( strtolower( $username ), array_map( 'strtolower', $illegal_logins ), true ) ) { - return new WP_Error( 'rest_user_invalid_username', __( 'Sorry, that username is not allowed.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_user_invalid_username', + __( 'Sorry, that username is not allowed.' ), + array( 'status' => 400 ) + ); } return $username; @@ -1159,11 +1281,19 @@ class WP_REST_Users_Controller extends WP_REST_Controller { $password = (string) $value; if ( empty( $password ) ) { - return new WP_Error( 'rest_user_invalid_password', __( 'Passwords cannot be empty.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_user_invalid_password', + __( 'Passwords cannot be empty.' ), + array( 'status' => 400 ) + ); } if ( false !== strpos( $password, '\\' ) ) { - return new WP_Error( 'rest_user_invalid_password', __( 'Passwords cannot contain the "\\" character.' ), array( 'status' => 400 ) ); + return new WP_Error( + 'rest_user_invalid_password', + __( 'Passwords cannot contain the "\\" character.' ), + array( 'status' => 400 ) + ); } return $password; @@ -1338,6 +1468,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller { $schema['properties']['meta'] = $this->meta->get_field_schema(); $this->schema = $schema; + return $this->add_additional_fields_schema( $this->schema ); } diff --git a/src/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php b/src/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php index a59ee7f90a..a897d13c1b 100644 --- a/src/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php +++ b/src/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php @@ -79,15 +79,18 @@ abstract class WP_REST_Meta_Fields { foreach ( $fields as $meta_key => $args ) { $name = $args['name']; $all_values = get_metadata( $this->get_meta_type(), $object_id, $meta_key, false ); + if ( $args['single'] ) { if ( empty( $all_values ) ) { $value = $args['schema']['default']; } else { $value = $all_values[0]; } + $value = $this->prepare_value_for_response( $value, $request, $args ); } else { $value = array(); + foreach ( $all_values as $row ) { $value[] = $this->prepare_value_for_response( $row, $request, $args ); } @@ -132,6 +135,7 @@ abstract class WP_REST_Meta_Fields { */ public function update_value( $meta, $object_id ) { $fields = $this->get_registered_fields(); + foreach ( $fields as $meta_key => $args ) { $name = $args['name']; if ( ! array_key_exists( $name, $meta ) ) { @@ -210,6 +214,7 @@ abstract class WP_REST_Meta_Fields { */ protected function delete_meta_value( $object_id, $meta_key, $name ) { $meta_type = $this->get_meta_type(); + if ( ! current_user_can( "delete_{$meta_type}_meta", $object_id, $meta_key ) ) { return new WP_Error( 'rest_cannot_delete', @@ -251,6 +256,7 @@ abstract class WP_REST_Meta_Fields { */ protected function update_multi_meta_value( $object_id, $meta_key, $name, $values ) { $meta_type = $this->get_meta_type(); + if ( ! current_user_can( "edit_{$meta_type}_meta", $object_id, $meta_key ) ) { return new WP_Error( 'rest_cannot_update', @@ -286,9 +292,11 @@ abstract class WP_REST_Meta_Fields { unset( $to_add[ $add_key ] ); } - // `delete_metadata` removes _all_ instances of the value, so only call once. Otherwise, - // `delete_metadata` will return false for subsequent calls of the same value. - // Use serialization to produce a predictable string that can be used by array_unique. + /* + * `delete_metadata` removes _all_ instances of the value, so only call once. Otherwise, + * `delete_metadata` will return false for subsequent calls of the same value. + * Use serialization to produce a predictable string that can be used by array_unique. + */ $to_remove = array_map( 'maybe_unserialize', array_unique( array_map( 'maybe_serialize', $to_remove ) ) ); foreach ( $to_remove as $value ) { @@ -335,6 +343,7 @@ 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 ) ) { return new WP_Error( 'rest_cannot_update', @@ -494,7 +503,6 @@ abstract class WP_REST_Meta_Fields { * @return mixed Value prepared for output. If a non-JsonSerializable object, null. */ public static function prepare_value( $value, $request, $args ) { - if ( $args['single'] ) { $schema = $args['schema']; } else { diff --git a/src/wp-includes/revision.php b/src/wp-includes/revision.php index da038a21be..77fd8e98ac 100644 --- a/src/wp-includes/revision.php +++ b/src/wp-includes/revision.php @@ -29,7 +29,7 @@ function _wp_post_revision_fields( $post = array(), $deprecated = false ) { } if ( is_null( $fields ) ) { - // Allow these to be versioned + // Allow these to be versioned. $fields = array( 'post_title' => __( 'Title' ), 'post_content' => __( 'Content' ), @@ -55,7 +55,7 @@ function _wp_post_revision_fields( $post = array(), $deprecated = false ) { */ $fields = apply_filters( '_wp_post_revision_fields', $fields, $post ); - // WP uses these internally either in versioning or elsewhere - they cannot be versioned + // WP uses these internally either in versioning or elsewhere - they cannot be versioned. foreach ( array( 'ID', 'post_name', 'post_parent', 'post_date', 'post_date_gmt', 'post_status', 'post_type', 'comment_count', 'post_author' ) as $protect ) { unset( $fields[ $protect ] ); } @@ -90,7 +90,7 @@ function _wp_post_revision_data( $post = array(), $autosave = false ) { $revision_data['post_parent'] = $post['ID']; $revision_data['post_status'] = 'inherit'; $revision_data['post_type'] = 'revision'; - $revision_data['post_name'] = $autosave ? "$post[ID]-autosave-v1" : "$post[ID]-revision-v1"; // "1" is the revisioning system version + $revision_data['post_name'] = $autosave ? "$post[ID]-autosave-v1" : "$post[ID]-revision-v1"; // "1" is the revisioning system version. $revision_data['post_date'] = isset( $post['post_modified'] ) ? $post['post_modified'] : ''; $revision_data['post_date_gmt'] = isset( $post['post_modified_gmt'] ) ? $post['post_modified_gmt'] : ''; @@ -130,12 +130,14 @@ function wp_save_post_revision( $post_id ) { return; } - // Compare the proposed update with the last stored revision verifying that - // they are different, unless a plugin tells us to always save regardless. - // If no previous revisions, save one + /* + * Compare the proposed update with the last stored revision verifying that + * they are different, unless a plugin tells us to always save regardless. + * If no previous revisions, save one. + */ $revisions = wp_get_post_revisions( $post_id ); if ( $revisions ) { - // grab the last revision, but not an autosave + // Grab the last revision, but not an autosave. foreach ( $revisions as $revision ) { if ( false !== strpos( $revision->post_name, "{$revision->post_parent}-revision" ) ) { $last_revision = $revision; @@ -180,7 +182,7 @@ function wp_save_post_revision( $post_id ) { */ $post_has_changed = (bool) apply_filters( 'wp_save_post_revision_post_has_changed', $post_has_changed, $last_revision, $post ); - //don't save revision if post unchanged + // Don't save revision if post unchanged. if ( ! $post_has_changed ) { return; } @@ -311,7 +313,7 @@ function _wp_put_post_revision( $post = null, $autosave = false ) { } $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 ) ) { @@ -397,14 +399,14 @@ function wp_restore_post_revision( $revision_id, $fields = null ) { $update['ID'] = $revision['post_parent']; - $update = wp_slash( $update ); //since data is from db + $update = wp_slash( $update ); // Since data is from DB. $post_id = wp_update_post( $update ); if ( ! $post_id || is_wp_error( $post_id ) ) { return $post_id; } - // Update last edit user + // Update last edit user. update_post_meta( $post_id, '_edit_last', get_current_user_id() ); /** @@ -623,7 +625,7 @@ function _wp_preview_terms_filter( $terms, $post_id, $taxonomy ) { } else { $term = get_term_by( 'slug', 'post-format-' . sanitize_key( $_REQUEST['post_format'] ), 'post_format' ); if ( $term ) { - $terms = array( $term ); // Can only have one post format + $terms = array( $term ); // Can only have one post format. } } @@ -703,25 +705,25 @@ function _wp_get_post_revision_version( $revision ) { function _wp_upgrade_revisions_of_post( $post, $revisions ) { global $wpdb; - // Add post option exclusively + // Add post option exclusively. $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 + // If we couldn't get a lock, see how old the previous lock is. $locked = get_option( $lock ); if ( ! $locked ) { // Can't write to the lock, and can't read the lock. - // Something broken has happened + // Something broken has happened. return false; } if ( $locked > $now - 3600 ) { - // Lock is not too old: some other process may be upgrading this post. Bail. + // Lock is not too old: some other process may be upgrading this post. Bail. return false; } - // Lock is too old - update it (below) and continue + // Lock is too old - update it (below) and continue. } // If we could get a lock, re-"add" the option to fire all the correct filters. @@ -736,7 +738,7 @@ function _wp_upgrade_revisions_of_post( $post, $revisions ) { $this_revision_version = _wp_get_post_revision_version( $this_revision ); - // Something terrible happened + // Something terrible happened. if ( false === $this_revision_version ) { continue; } @@ -748,14 +750,16 @@ function _wp_upgrade_revisions_of_post( $post, $revisions ) { continue; } - // Always update the revision version + // Always update the revision version. $update = array( 'post_name' => preg_replace( '/^(\d+-(?:autosave|revision))[\d-]*$/', '$1-v1', $this_revision->post_name ), ); - // If this revision is the oldest revision of the post, i.e. no $prev_revision, - // the correct post_author is probably $post->post_author, but that's only a good guess. - // Update the revision version only and Leave the author as-is. + /* + * If this revision is the oldest revision of the post, i.e. no $prev_revision, + * the correct post_author is probably $post->post_author, but that's only a good guess. + * Update the revision version only and Leave the author as-is. + */ if ( $prev_revision ) { $prev_revision_version = _wp_get_post_revision_version( $prev_revision ); @@ -765,7 +769,7 @@ function _wp_upgrade_revisions_of_post( $post, $revisions ) { } } - // Upgrade this revision + // Upgrade this revision. $result = $wpdb->update( $wpdb->posts, $update, array( 'ID' => $this_revision->ID ) ); if ( $result ) { diff --git a/src/wp-includes/rewrite.php b/src/wp-includes/rewrite.php index a01b88b9dc..aa7d22371b 100644 --- a/src/wp-includes/rewrite.php +++ b/src/wp-includes/rewrite.php @@ -157,7 +157,7 @@ function add_rewrite_rule( $regex, $query, $after = 'bottom' ) { * @param string $query Optional. String to append to the rewritten query. Must end in '='. Default empty. */ function add_rewrite_tag( $tag, $regex, $query = '' ) { - // validate the tag's name + // Validate the tag's name. if ( strlen( $tag ) < 3 || $tag[0] != '%' || $tag[ strlen( $tag ) - 1 ] != '%' ) { return; } @@ -253,7 +253,7 @@ function add_feed( $feedname, $function ) { $hook = 'do_feed_' . $feedname; - // Remove default function hook + // Remove default function hook. remove_action( $hook, $hook ); add_action( $hook, $function, 10, 2 ); @@ -420,7 +420,7 @@ function wp_resolve_numeric_slug_conflicts( $query_vars = array() ) { } elseif ( 'monthnum' === $compare && isset( $query_vars['day'] ) ) { $maybe_page = $query_vars['day']; } - // Bug found in #11694 - 'page' was returning '/4' + // Bug found in #11694 - 'page' was returning '/4'. $maybe_page = (int) trim( $maybe_page, '/' ); $post_page_count = substr_count( $post->post_content, '' ) + 1; @@ -485,7 +485,7 @@ function url_to_postid( $url ) { return 0; } - // First, check to see if there is a 'p=N' or 'page_id=N' to match against + // 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 ) { @@ -493,11 +493,11 @@ function url_to_postid( $url ) { } } - // Get rid of the #anchor + // Get rid of the #anchor. $url_split = explode( '#', $url ); $url = $url_split[0]; - // Get rid of URL ?query=string + // Get rid of URL ?query=string. $url_split = explode( '?', $url ); $url = $url_split[0]; @@ -505,12 +505,12 @@ function url_to_postid( $url ) { $scheme = parse_url( home_url(), PHP_URL_SCHEME ); $url = set_url_scheme( $url, $scheme ); - // Add 'www.' if it is absent and should be there + // 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 ); } - // Strip 'www.' if it is present and shouldn't be + // Strip 'www.' if it is present and shouldn't be. if ( false === strpos( home_url(), '://www.' ) ) { $url = str_replace( '://www.', '://', $url ); } @@ -523,30 +523,30 @@ function url_to_postid( $url ) { } } - // Check to see if we are using rewrite rules + // Check to see if we are using rewrite rules. $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 + // Not using rewrite rules, and 'p=N' and 'page_id=N' methods failed, so we're out of options. if ( empty( $rewrite ) ) { return 0; } - // Strip 'index.php/' if we're not using path info permalinks + // Strip 'index.php/' if we're not using path info 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] + // Chop off http://domain.com/[path]. $url = str_replace( home_url(), '', $url ); } else { - // Chop off /path/to/blog + // 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 ) ); } - // Trim leading and lagging slashes + // Trim leading and lagging slashes. $url = trim( $url, '/' ); $request = $url; @@ -562,8 +562,8 @@ function url_to_postid( $url ) { $request_match = $request; foreach ( (array) $rewrite as $match => $query ) { - // If the requesting file is the anchor of the match, prepend it - // to the path info. + // 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 ) ) { $request_match = $url . '/' . $request; } @@ -591,7 +591,7 @@ function url_to_postid( $url ) { // Substitute the substring matches into the query. $query = addslashes( WP_MatchesMapRegex::apply( $query, $matches ) ); - // Filter out non-public query vars + // Filter out non-public query vars. global $wp; parse_str( $query, $query_vars ); $query = array(); @@ -608,7 +608,7 @@ function url_to_postid( $url ) { // Resolve conflicts between posts with numeric slugs and date archive queries. $query = wp_resolve_numeric_slug_conflicts( $query ); - // Do the query + // Do the query. $query = new WP_Query( $query ); if ( ! empty( $query->posts ) && $query->is_singular ) { return $query->post->ID; diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index 018cb777af..f45471d7e1 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -51,8 +51,8 @@ function wp_register_tinymce_scripts( &$scripts, $force_uncompressed = false ) { $compressed = $compress_scripts && $concatenate_scripts && isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) && false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip' ) && ! $force_uncompressed; - // Load tinymce.js when running from /src, otherwise load wp-tinymce.js.gz (in production) or - // tinymce.min.js (when SCRIPT_DEBUG is true). + // Load tinymce.js when running from /src, otherwise load wp-tinymce.js.gz (in production) + // or tinymce.min.js (when SCRIPT_DEBUG is true). if ( $compressed ) { $scripts->add( 'wp-tinymce', includes_url( 'js/tinymce/' ) . 'wp-tinymce.js', array(), $tinymce_version ); } else { @@ -198,9 +198,11 @@ function wp_get_script_polyfill( &$scripts, $tests ) { $polyfill .= ( // Test presence of feature... '( ' . $test . ' ) || ' . - // ...appending polyfill on any failures. Cautious viewers may balk - // at the `document.write`. Its caveat of synchronous mid-stream - // blocking write is exactly the behavior we need though. + /* + * ...appending polyfill on any failures. Cautious viewers may balk + * at the `document.write`. Its caveat of synchronous mid-stream + * blocking write is exactly the behavior we need though. + */ 'document.write( \'\n"; @@ -2293,7 +2300,7 @@ function wp_print_head_scripts() { global $wp_scripts; if ( ! ( $wp_scripts instanceof WP_Scripts ) ) { - return array(); // no need to run if nothing is queued + return array(); // No need to run if nothing is queued. } return print_head_scripts(); } diff --git a/src/wp-includes/shortcodes.php b/src/wp-includes/shortcodes.php index ecf1aeba39..5c425bc64a 100644 --- a/src/wp-includes/shortcodes.php +++ b/src/wp-includes/shortcodes.php @@ -217,7 +217,7 @@ function do_shortcode( $content, $ignore_html = false ) { $pattern = get_shortcode_regex( $tagnames ); $content = preg_replace_callback( "/$pattern/", 'do_shortcode_tag', $content ); - // Always restore square braces so we don't break things like - +

    diff --git a/src/wp-includes/theme-compat/header.php b/src/wp-includes/theme-compat/header.php index 461a85aec8..9aef7e98c0 100644 --- a/src/wp-includes/theme-compat/header.php +++ b/src/wp-includes/theme-compat/header.php @@ -30,11 +30,11 @@ _deprecated_file( ipsum"; $this->assertEquals( 'loremipsum', wp_strip_all_tags( $text ) ); - // test "marlformed" markup of contents + // Test "marlformed" markup of contents. $text = "loremipsum"; $this->assertEquals( 'loremipsum', wp_strip_all_tags( $text ) ); } diff --git a/tests/phpunit/tests/formatting/WPTargetedLinkRel.php b/tests/phpunit/tests/formatting/WPTargetedLinkRel.php index a7bcf91f2a..7f461ec87a 100644 --- a/tests/phpunit/tests/formatting/WPTargetedLinkRel.php +++ b/tests/phpunit/tests/formatting/WPTargetedLinkRel.php @@ -69,7 +69,7 @@ class Tests_Targeted_Link_Rel extends WP_UnitTestCase { /** * Ensure empty rel attributes are not added. * - * @ticket 45352. + * @ticket 45352 */ public function test_ignore_if_wp_targeted_link_rel_nulled() { add_filter( 'wp_targeted_link_rel', '__return_empty_string' ); @@ -81,7 +81,7 @@ class Tests_Targeted_Link_Rel extends WP_UnitTestCase { /** * Ensure default content filters are added. * - * @ticket 45292. + * @ticket 45292 */ public function test_wp_targeted_link_rel_filters_run() { $content = '

    Links: No rel

    '; diff --git a/tests/phpunit/tests/formatting/WPTexturize.php b/tests/phpunit/tests/formatting/WPTexturize.php index 24b0b26883..e6d6c5be4d 100644 --- a/tests/phpunit/tests/formatting/WPTexturize.php +++ b/tests/phpunit/tests/formatting/WPTexturize.php @@ -32,19 +32,25 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { } - //WP Ticket #1418 + /** + * @ticket 1418 + */ function test_bracketed_quotes_1418() { $this->assertEquals( '(“test”)', wptexturize( '("test")' ) ); $this->assertEquals( '(‘test’)', wptexturize( "('test')" ) ); $this->assertEquals( '(’twas)', wptexturize( "('twas)" ) ); } - //WP Ticket #3810 + /** + * @ticket 3810 + */ function test_bracketed_quotes_3810() { $this->assertEquals( 'A dog (“Hubertus”) was sent out.', wptexturize( 'A dog ("Hubertus") was sent out.' ) ); } - //WP Ticket #4539 + /** + * @ticket 4539 + */ function test_basic_quotes() { $this->assertEquals( 'test’s', wptexturize( 'test\'s' ) ); @@ -80,16 +86,16 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { */ function test_quotes() { $this->assertEquals( '“Quoted String”', wptexturize( '"Quoted String"' ) ); - //$this->assertEquals('Here is “a test with a link”', wptexturize('Here is "a test with a link"')); - //$this->assertEquals('Here is “a test with a link and a period”.', wptexturize('Here is "a test with a link and a period".')); + // $this->assertEquals( 'Here is “a test with a link”', wptexturize( 'Here is "a test with a link"' ) ); + // $this->assertEquals( 'Here is “a test with a link and a period”.', wptexturize( 'Here is "a test with a link and a period".' ) ); $this->assertEquals( 'Here is “a test with a link” and a space.', wptexturize( 'Here is "a test with a link" and a space.' ) ); $this->assertEquals( 'Here is “a test with a link and some text quoted”', wptexturize( 'Here is "a test with a link and some text quoted"' ) ); - //$this->assertEquals('Here is “a test with a link”, and a comma.', wptexturize('Here is "a test with a link", and a comma.')); - //$this->assertEquals('Here is “a test with a link”; and a semi-colon.', wptexturize('Here is "a test with a link"; and a semi-colon.')); - //$this->assertEquals('Here is “a test with a link”- and a dash.', wptexturize('Here is "a test with a link"- and a dash.')); - //$this->assertEquals('Here is “a test with a link”… and ellipses.', wptexturize('Here is "a test with a link"... and ellipses.')); - //$this->assertEquals('Here is “a test with a link”.', wptexturize('Here is "a test with a link".')); - //$this->assertEquals('Here is “a test with a link”and a work stuck to the end.', wptexturize('Here is "a test with a link"and a work stuck to the end.')); + // $this->assertEquals( 'Here is “a test with a link”, and a comma.', wptexturize( 'Here is "a test with a link", and a comma.' ) ); + // $this->assertEquals( 'Here is “a test with a link”; and a semi-colon.', wptexturize( 'Here is "a test with a link"; and a semi-colon.' ) ); + // $this->assertEquals( 'Here is “a test with a link”- and a dash.', wptexturize( 'Here is "a test with a link"- and a dash.' ) ); + // $this->assertEquals( 'Here is “a test with a link”… and ellipses.', wptexturize( 'Here is "a test with a link"... and ellipses.' ) ); + // $this->assertEquals( 'Here is “a test with a link”.', wptexturize( 'Here is "a test with a link".' ) ); + // $this->assertEquals( 'Here is “a test with a link”and a work stuck to the end.', wptexturize( 'Here is "a test with a link"and a work stuck to the end.' ) ); $this->assertEquals( 'A test with a finishing number, “like 23”.', wptexturize( 'A test with a finishing number, "like 23".' ) ); $this->assertEquals( 'A test with a number, “like 62”, is nice to have.', wptexturize( 'A test with a number, "like 62", is nice to have.' ) ); } @@ -131,7 +137,8 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { $this->assertEquals( ' “Class of ’99”;', wptexturize( " \"Class of '99\";" ) ); $this->assertEquals( ' “Class of ’99”!', wptexturize( " \"Class of '99\"!" ) ); $this->assertEquals( ' “Class of ’99”?', wptexturize( " \"Class of '99\"?" ) ); - $this->assertEquals( '}”Class of ’99″{', wptexturize( "}\"Class of '99\"{" ) ); // Not a quotation, may be between two other quotations. + // Not a quotation, may be between two other quotations. + $this->assertEquals( '}”Class of ’99″{', wptexturize( "}\"Class of '99\"{" ) ); } function test_quotes_after_numbers() { @@ -144,8 +151,8 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { */ function test_other_html() { $this->assertEquals( '‘', wptexturize( "'" ) ); - //$this->assertEquals('‘Quoted Text’,', wptexturize("'Quoted Text',")); - //$this->assertEquals('“Quoted Text”,', wptexturize('"Quoted Text",')); + // $this->assertEquals( '‘Quoted Text’,', wptexturize( "'Quoted Text'," ) ); + // $this->assertEquals( '“Quoted Text”,', wptexturize( '"Quoted Text",' ) ); } function test_x() { @@ -188,7 +195,7 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { */ function test_entity_quote_cuddling() { $this->assertEquals( ' “Testing”', wptexturize( ' "Testing"' ) ); - //$this->assertEquals('&“Testing”', wptexturize('&"Testing"')); + // $this->assertEquals( '&“Testing”', wptexturize( '&"Testing"' ) ); } /** @@ -341,7 +348,7 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { 'word ’99’s word', ), array( - "according to our source, '33 students scored less than 50' on the test.", // Apostrophes and primes have priority over quotes + "according to our source, '33 students scored less than 50' on the test.", // Apostrophes and primes have priority over quotes. 'according to our source, ’33 students scored less than 50′ on the test.', ), ); @@ -374,7 +381,7 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { 'word [‘word word', ), array( - "word <'word word", // Invalid HTML + "word <'word word", // Invalid HTML. "word <'word word", ), array( @@ -387,7 +394,7 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { ), array( "word \"'word word", - 'word “‘word word', // Two opening quotes + 'word “‘word word', // Two opening quotes. ), array( "'word word", @@ -415,7 +422,7 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { ), array( "word\"'word word", - 'word”‘word word', // Closing quote, then opening quote + 'word”‘word word', // Closing quote, then opening quote. ), array( "word ' word word", @@ -443,7 +450,7 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { ), array( "word \"' word word", - 'word “‘ word word', // Two opening quotes + 'word “‘ word word', // Two opening quotes. ), array( "' word word", @@ -471,7 +478,7 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { ), array( "word\"' word word", - 'word”‘ word word', // Closing quote, then opening quote + 'word”‘ word word', // Closing quote, then opening quote. ), ); } @@ -536,7 +543,7 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { 'word99′ word', ), array( - "word99'word", // Not a prime anymore. + "word99'word", // Not a prime anymore. 'word99’word', ), ); @@ -610,7 +617,7 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { 'word [“word word', ), array( - 'word <"word word', // Invalid HTML + 'word <"word word', // Invalid HTML. 'word <"word word', ), array( @@ -691,11 +698,11 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { 'word word”} word', ), array( - 'word word"> word', // Invalid HTML input? + 'word word"> word', // Invalid HTML input? 'word word”> word', ), array( - 'word word"> word', // Valid HTML should work + 'word word"> word', // Valid HTML should work. 'word word”> word', ), array( @@ -844,6 +851,7 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail. * * @ticket 22692 + * @ticket 30445 * @dataProvider data_multiplication */ function test_multiplication( $input, $output ) { @@ -1291,15 +1299,15 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { '[gallery ...]]', ), array( - '[/gallery ...]', // This would actually be ignored by the shortcode system. The decision to not texturize it is intentional, if not correct. - '[/gallery ...]', + '[/gallery ...]', // This would actually be ignored by the shortcode system. + '[/gallery ...]', // The decision to not texturize it is intentional, if not correct. ), array( - '[[gallery]]...[[/gallery]]', // Shortcode parsing will ignore the inner ]...[ part and treat this as a single escaped shortcode. + '[[gallery]]...[[/gallery]]', // Shortcode parsing will ignore the inner ']...[' part and treat this as a single escaped shortcode. '[[gallery]]…[[/gallery]]', ), array( - '[[[gallery]]]...[[[/gallery]]]', // Again, shortcode parsing matches, but only the [[gallery] and [/gallery]] parts. + '[[[gallery]]]...[[[/gallery]]]', // Again, shortcode parsing matches, but only the '[[gallery]' and '[/gallery]]' parts. '[[[gallery]]]…[[[/gallery]]]', ), array( @@ -1307,8 +1315,8 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { '[gallery …', ), array( - '[gallery
    ...]', // This tag is still valid. Shortcode 'attributes' are not considered in the initial parsing of shortcodes, and HTML is allowed. - '[gallery
    ...]', + '[gallery
    ...]', // This tag is still valid. Shortcode 'attributes' are not considered + '[gallery
    ...]', // in the initial parsing of shortcodes, and HTML is allowed. ), array( '
    ', @@ -1347,7 +1355,7 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { '[/gallery ...]]', ), array( - '[[gallery
    ...]]', // This gets parsed as an escaped shortcode with embedded HTML. Brains may explode. + '[[gallery
    ...]]', // This gets parsed as an escaped shortcode with embedded HTML. Brains may explode. '[[gallery
    ...]]', ), array( @@ -1443,7 +1451,7 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { '[ but also catches the styled “[quote]” here ]', ), array( - '[Let\'s get crazy[caption code="hello"]world]', // caption shortcode is invalid here because it contains [] chars. + '[Let\'s get crazy[caption code="hello"]world]', // [caption] shortcode is invalid here because it contains '[]' chars. '[Let’s get crazy[caption code=”hello“]world]', ), array( @@ -1490,7 +1498,7 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { 'word ’99; word', ), array( - "word '99' word", // For this pattern, prime doesn't make sense. Should get apos and a closing quote. + "word '99' word", // For this pattern, prime doesn't make sense. Should get apos and a closing quote. 'word ’99’ word', ), array( @@ -1855,15 +1863,15 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { '[a]a–b[audio]---[/audio]a–b[/a]', ), array( - '[code ...]...[/code]', // code is not a registered shortcode. + '[code ...]...[/code]', // '[code]' is not a registered shortcode. '[code …]…[/code]', ), array( - '[hello ...]...[/hello]', // hello is not a registered shortcode. + '[hello ...]...[/hello]', // '[hello]' is not a registered shortcode. '[hello …]…[/hello]', ), array( - '[...]...[/...]', // These are potentially usable shortcodes. + '[...]...[/...]', // These are potentially usable shortcodes. '[…]…[/…]', ), array( @@ -1875,13 +1883,13 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { '[randomthing param=”test”]', ), array( - '[[audio]...[/audio]...', // These are potentially usable shortcodes. Unfortunately, the meaning of [[audio] is ambiguous unless we run the entire shortcode regexp. - '[[audio]…[/audio]…', + '[[audio]...[/audio]...', // These are potentially usable shortcodes. + '[[audio]…[/audio]…', // Unfortunately, the meaning of [[audio] is ambiguous unless we run the entire shortcode regexp. ), array( - '[audio]...[/audio]]...', // These are potentially usable shortcodes. Unfortunately, the meaning of [/audio]] is ambiguous unless we run the entire shortcode regexp. - '[audio]...[/audio]]...', // This test would not pass in 3.9 because the extra brace was always ignored by texturize. - ), + '[audio]...[/audio]]...', // These are potentially usable shortcodes. + '[audio]...[/audio]]...', // Unfortunately, the meaning of [/audio]] is ambiguous unless we run the entire shortcode regexp. + ), // This test would not pass in 3.9 because the extra brace was always ignored by texturize. array( 'hello[/audio]---', 'hello[/audio]—', @@ -1934,7 +1942,7 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { 'The best year “was that time in 2012” when everyone partied, he said.', ), array( - "I need 4 x 20' = 80' of trim.", // Works only with a space before the = char. + "I need 4 x 20' = 80' of trim.", // Works only with a space before the '=' char. 'I need 4 x 20′ = 80′ of trim.', ), array( @@ -2030,7 +2038,7 @@ String with a number followed by a single quote ‘Expendables 3’ vest 'The best year !q2!was that time in 2012!q2! when everyone partied, he said.', ), array( - "I need 4 x 20' = 80' of trim.", // Works only with a space before the = char. + "I need 4 x 20' = 80' of trim.", // Works only with a space before the '=' char. 'I need 4 x 20!prime1! = 80!prime1! of trim.', ), array( @@ -2077,12 +2085,12 @@ String with a number followed by a single quote !q1!Expendables 3!q1! vestibulum function test_pcre_performance( $input ) { global $shortcode_tags; - // With Shortcodes Disabled + // With shortcodes disabled. $regex = _get_wptexturize_split_regex(); $result = benchmark_pcre_backtracking( $regex, $input, 'split' ); $this->assertLessThan( 200, $result ); - // With Shortcodes Enabled + // With shortcodes enabled. $shortcode_regex = _get_wptexturize_shortcode_regex( array_keys( $shortcode_tags ) ); $regex = _get_wptexturize_split_regex( $shortcode_regex ); $result = benchmark_pcre_backtracking( $regex, $input, 'split' ); diff --git a/tests/phpunit/tests/formatting/WPTrimWords.php b/tests/phpunit/tests/formatting/WPTrimWords.php index 7b7438de46..125bbcb9d2 100644 --- a/tests/phpunit/tests/formatting/WPTrimWords.php +++ b/tests/phpunit/tests/formatting/WPTrimWords.php @@ -35,7 +35,9 @@ class Tests_Formatting_WPTrimWords extends WP_UnitTestCase { $this->assertEquals( $trimmed, wp_trim_words( $text, 5 ) ); } - // #18726 + /** + * @ticket 18726 + */ function test_strips_script_and_style_content() { $trimmed = 'This text contains. It should go.'; diff --git a/tests/phpunit/tests/formatting/balanceTags.php b/tests/phpunit/tests/formatting/balanceTags.php index a660f45303..b5dedb11f4 100644 --- a/tests/phpunit/tests/formatting/balanceTags.php +++ b/tests/phpunit/tests/formatting/balanceTags.php @@ -80,7 +80,7 @@ class Tests_Formatting_BalanceTags extends WP_UnitTestCase { // Examples from the spec working document. array( 'math-α' ), array( 'emotion-😍' ), - // UNICODE ranges + // Unicode ranges. // 0x00b7 array( 'b-·' ), // Latin characters with accents/modifiers. diff --git a/tests/phpunit/tests/formatting/ent2ncr.php b/tests/phpunit/tests/formatting/ent2ncr.php index 4368246a97..ea9b8da073 100644 --- a/tests/phpunit/tests/formatting/ent2ncr.php +++ b/tests/phpunit/tests/formatting/ent2ncr.php @@ -21,7 +21,7 @@ class Tests_Formatting_Ent2NCR extends WP_UnitTestCase { $entities = file( DIR_TESTDATA . '/formatting/entities.txt' ); $data_provided = array(); foreach ( $entities as $line ) { - // comment + // Comment. $commentpos = strpos( $line, '###' ); if ( false !== $commentpos ) { $line = trim( substr( $line, 0, $commentpos ) ); diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php index a47fd021fd..2b9cf79b07 100644 --- a/tests/phpunit/tests/functions.php +++ b/tests/phpunit/tests/functions.php @@ -22,7 +22,7 @@ class Tests_Functions extends WP_UnitTestCase { } function test_wp_parse_args_array() { - // arrays + // Arrays. $a = array(); $this->assertEquals( array(), wp_parse_args( $a ) ); $b = array( @@ -140,22 +140,22 @@ class Tests_Functions extends WP_UnitTestCase { } function data_wp_normalize_path() { return array( - // Windows paths + // Windows paths. array( 'C:\\www\\path\\', 'C:/www/path/' ), array( 'C:\\www\\\\path\\', 'C:/www/path/' ), array( 'c:/www/path', 'C:/www/path' ), - array( 'c:\\www\\path\\', 'C:/www/path/' ), // uppercase drive letter + array( 'c:\\www\\path\\', 'C:/www/path/' ), // Uppercase drive letter. array( 'c:\\\\www\\path\\', 'C:/www/path/' ), array( '\\\\Domain\\DFSRoots\\share\\path\\', '//Domain/DFSRoots/share/path/' ), array( '\\\\Server\\share\\path', '//Server/share/path' ), array( '\\\\Server\\share', '//Server/share' ), - // Linux paths + // Linux paths. array( '/www/path/', '/www/path/' ), array( '/www/path/////', '/www/path/' ), array( '/www/path', '/www/path' ), - // PHP Stream wrappers + // PHP stream wrappers. array( 'php://input', 'php://input' ), array( 'http://example.com//path.ext', 'http://example.com/path.ext' ), array( 'file://c:\\www\\path\\', 'file://C:/www/path/' ), @@ -166,30 +166,30 @@ class Tests_Functions extends WP_UnitTestCase { $testdir = DIR_TESTDATA . '/images/'; - // sanity check + // Sanity check. $this->assertEquals( 'abcdefg.png', wp_unique_filename( $testdir, 'abcdefg.png' ), 'Sanitiy check failed' ); - // check number is appended for file already exists + // Check number is appended for file already exists. $this->assertFileExists( $testdir . 'test-image.png', 'Test image does not exist' ); $this->assertEquals( 'test-image-1.png', wp_unique_filename( $testdir, 'test-image.png' ), 'Number not appended correctly' ); $this->assertFileNotExists( $testdir . 'test-image-1.png' ); - // check special chars + // Check special chars. $this->assertEquals( 'testtést-imagé.png', wp_unique_filename( $testdir, 'testtést-imagé.png' ), 'Filename with special chars failed' ); - // check special chars with potential conflicting name + // Check special chars with potential conflicting name. $this->assertEquals( 'tést-imagé.png', wp_unique_filename( $testdir, 'tést-imagé.png' ), 'Filename with special chars failed' ); - // check with single quotes in name (somehow) + // Check with single quotes in name (somehow). $this->assertEquals( 'abcdefgh.png', wp_unique_filename( $testdir, "abcdefg'h.png" ), 'File with quote failed' ); - // check with single quotes in name (somehow) + // Check with double quotes in name (somehow). $this->assertEquals( 'abcdefgh.png', wp_unique_filename( $testdir, 'abcdefg"h.png' ), 'File with quote failed' ); - // test crazy name (useful for regression tests) + // Test crazy name (useful for regression tests). $this->assertEquals( '12af34567890@..^_qwerty-fghjkl-zx.png', wp_unique_filename( $testdir, '12%af34567890#~!@#$..%^&*()|_+qwerty fgh`jkl zx<>?:"{}[]="\'/?.png' ), 'Failed crazy file name' ); - // test slashes in names + // Test slashes in names. $this->assertEquals( 'abcdefg.png', wp_unique_filename( $testdir, 'abcde\fg.png' ), 'Slash not removed' ); $this->assertEquals( 'abcdefg.png', wp_unique_filename( $testdir, 'abcde\\fg.png' ), 'Double slashed not removed' ); $this->assertEquals( 'abcdefg.png', wp_unique_filename( $testdir, 'abcde\\\fg.png' ), 'Tripple slashed not removed' ); @@ -525,7 +525,7 @@ class Tests_Functions extends WP_UnitTestCase { $this->assertInternalType( 'array', $mimes ); $this->assertNotEmpty( $mimes ); - // upload_mimes shouldn't affect wp_get_mime_types() + // 'upload_mimes' should not affect wp_get_mime_types(). add_filter( 'upload_mimes', '__return_empty_array' ); $mimes = wp_get_mime_types(); $this->assertInternalType( 'array', $mimes ); @@ -646,47 +646,47 @@ class Tests_Functions extends WP_UnitTestCase { function data_device_can_upload() { return array( - // iPhone iOS 5.0.1, Safari 5.1 + // iPhone iOS 5.0.1, Safari 5.1. array( 'Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9A406)', false, ), - // iPad iOS 3.2, Safari 4.0.4 + // iPad iOS 3.2, Safari 4.0.4. array( 'Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10', false, ), - // iPod iOS 4.3.3, Safari 5.0.2 + // iPod iOS 4.3.3, Safari 5.0.2. array( 'Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3_3 like Mac OS X; ja-jp) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5', false, ), - // iPhone iOS 6.0.0, Safari 6.0 + // iPhone iOS 6.0.0, Safari 6.0. array( 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25', true, ), - // iPad iOS 6.0.0, Safari 6.0 + // iPad iOS 6.0.0, Safari 6.0. array( 'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25', true, ), - // Android 2.2, Android Webkit Browser + // Android 2.2, Android Webkit Browser. array( 'Mozilla/5.0 (Android 2.2; Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.19.4 (KHTML, like Gecko) Version/5.0.3 Safari/533.19.4', true, ), - // BlackBerry 9900, BlackBerry browser + // BlackBerry 9900, BlackBerry browser. array( 'Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.1.0.346 Mobile Safari/534.11+', true, ), - // Windows Phone 8.0, Internet Explorer 10.0; + // Windows Phone 8.0, Internet Explorer 10.0. array( 'Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 920)', true, ), - // Ubuntu desktop, Firefox 41.0 + // Ubuntu desktop, Firefox 41.0. array( 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:41.0) Gecko/20100101 Firefox/41.0', true, @@ -716,10 +716,10 @@ class Tests_Functions extends WP_UnitTestCase { 'http://българия.icom.museum', 'http://تشادر.icom.museum', 'http://中国.icom.museum', - #'http://القمر.icom.museum', // Comoros http://القمر.icom.museum - #'http://κυπρος.icom.museum', Cyprus http://κυπρος.icom.museum + // 'http://القمر.icom.museum', // Comoros http://القمر.icom.museum + // 'http://κυπρος.icom.museum', // Cyprus http://κυπρος.icom.museum 'http://českárepublika.icom.museum', - #'http://مصر.icom.museum', // Egypt http://مصر.icom.museum + // 'http://مصر.icom.museum', // Egypt http://مصر.icom.museum 'http://ελλάδα.icom.museum', 'http://magyarország.icom.museum', 'http://ísland.icom.museum', @@ -735,12 +735,12 @@ class Tests_Functions extends WP_UnitTestCase { 'http://ລາວ.icom.museum', 'http://لبنان.icom.museum', 'http://македонија.icom.museum', - #'http://موريتانيا.icom.museum', // Mauritania http://موريتانيا.icom.museum + // 'http://موريتانيا.icom.museum', // Mauritania http://موريتانيا.icom.museum 'http://méxico.icom.museum', 'http://монголулс.icom.museum', - #'http://المغرب.icom.museum', // Morocco http://المغرب.icom.museum + // 'http://المغرب.icom.museum', // Morocco http://المغرب.icom.museum 'http://नेपाल.icom.museum', - #'http://عمان.icom.museum', // Oman http://عمان.icom.museum + // 'http://عمان.icom.museum', // Oman http://عمان.icom.museum 'http://قطر.icom.museum', 'http://românia.icom.museum', 'http://россия.иком.museum', @@ -826,7 +826,7 @@ class Tests_Functions extends WP_UnitTestCase { $this->assertEquals( $original_urls, $urls ); $exploded = array_values( array_filter( array_map( 'trim', explode( "\n", $blob ) ) ) ); - // wp_extract_urls calls html_entity_decode + // wp_extract_urls() calls html_entity_decode(). $decoded = array_map( 'html_entity_decode', $exploded ); $this->assertEquals( $decoded, $urls ); @@ -1664,17 +1664,17 @@ class Tests_Functions extends WP_UnitTestCase { array( 1, false ), array( '00', false ), array( '30:-10', false ), - array( ':30:00', false ), // Missing HH. + array( ':30:00', false ), // Missing HH. array( 'MM:30:00', false ), // Invalid HH. array( '30:MM:00', false ), // Invalid ii. array( '30:30:MM', false ), // Invalid ss. - array( '30:MM', false ), // Invalid ss. - array( 'MM:00', false ), // Invalid ii. - array( 'MM:MM', false ), // Invalid ii and ss. - array( '10 :30', false ), // Containing a space. - array( '59:61', false ), // Out of bound. - array( '61:59', false ), // Out of bound. - array( '3:59:61', false ), // Out of bound. + array( '30:MM', false ), // Invalid ss. + array( 'MM:00', false ), // Invalid ii. + array( 'MM:MM', false ), // Invalid ii and ss. + array( '10 :30', false ), // Containing a space. + array( '59:61', false ), // Out of bound. + array( '61:59', false ), // Out of bound. + array( '3:59:61', false ), // Out of bound. array( '03:61:59', false ), // Out of bound. ); } diff --git a/tests/phpunit/tests/functions/allowedProtocols.php b/tests/phpunit/tests/functions/allowedProtocols.php index 992ccee86c..6ac0ec0f2f 100644 --- a/tests/phpunit/tests/functions/allowedProtocols.php +++ b/tests/phpunit/tests/functions/allowedProtocols.php @@ -38,26 +38,26 @@ class Tests_Functions_AllowedProtocols extends WP_UnitTestCase { */ function data_example_urls() { return array( - array( 'http', 'http://example.com' ), // RFC7230 - array( 'https', 'https://example.com' ), // RFC7230 - array( 'ftp', 'ftp://example.com' ), // RFC1738 + array( 'http', 'http://example.com' ), // RFC7230 + array( 'https', 'https://example.com' ), // RFC7230 + array( 'ftp', 'ftp://example.com' ), // RFC1738 array( 'ftps', 'ftps://example.com' ), - array( 'mailto', 'mailto://someone@example.com' ), // RFC6068 - array( 'news', 'news://news.server.example/example.group.this' ), // RFC5538 + array( 'mailto', 'mailto://someone@example.com' ), // RFC6068 + array( 'news', 'news://news.server.example/example.group.this' ), // RFC5538 array( 'irc', 'irc://example.com/wordpress' ), array( 'gopher', 'gopher://example.com/7a_gopher_selector%09foobar' ), // RFC4266 - array( 'nntp', 'nntp://news.server.example/example.group.this' ), // RFC5538 + array( 'nntp', 'nntp://news.server.example/example.group.this' ), // RFC5538 array( 'feed', 'feed://example.com/rss.xml' ), - array( 'telnet', 'telnet://user:password@example.com:80/' ), // RFC4248 + array( 'telnet', 'telnet://user:password@example.com:80/' ), // RFC4248 array( 'mms', 'mms://example.com:80/path' ), - array( 'rtsp', 'rtsp://media.example.com:554/wordpress/audiotrack' ), // RFC2326 + array( 'rtsp', 'rtsp://media.example.com:554/wordpress/audiotrack' ), // RFC2326 array( 'svn', 'svn://core.svn.wordpress.org/' ), - array( 'tel', 'tel:+1-234-567-8910' ), // RFC3966 - array( 'sms', 'sms:+1-234-567-8910' ), // RFC3966 - array( 'fax', 'fax:+123.456.78910' ), // RFC2806/RFC3966 - array( 'xmpp', 'xmpp://guest@example.com' ), // RFC5122 + array( 'tel', 'tel:+1-234-567-8910' ), // RFC3966 + array( 'sms', 'sms:+1-234-567-8910' ), // RFC3966 + array( 'fax', 'fax:+123.456.78910' ), // RFC2806/RFC3966 + array( 'xmpp', 'xmpp://guest@example.com' ), // RFC5122 array( 'webcal', 'webcal://example.com/calendar.ics' ), - array( 'urn', 'urn:uuid:6e8bc430-9c3a-11d9-9669-0800200c9a66' ), // RFC2141 + array( 'urn', 'urn:uuid:6e8bc430-9c3a-11d9-9669-0800200c9a66' ), // RFC2141 ); } } diff --git a/tests/phpunit/tests/functions/deprecated.php b/tests/phpunit/tests/functions/deprecated.php index 3bd6116f48..e4011ffbd6 100644 --- a/tests/phpunit/tests/functions/deprecated.php +++ b/tests/phpunit/tests/functions/deprecated.php @@ -153,7 +153,7 @@ class Test_Functions_Deprecated extends WP_UnitTestCase { $this->fail( 'jpeg support unavailable' ); } - // Call wp_save_image_file + // Call wp_save_image_file(). include_once( ABSPATH . 'wp-admin/includes/image-edit.php' ); $file = wp_tempnam(); $img = imagecreatefromjpeg( DIR_TESTDATA . '/images/canola.jpg' ); @@ -161,7 +161,7 @@ class Test_Functions_Deprecated extends WP_UnitTestCase { imagedestroy( $img ); unlink( $file ); - // Check if the arg was deprecated + // Check if the arg was deprecated. $check = $this->was_deprecated( 'argument', 'wp_save_image_file' ); $this->assertNotEmpty( $check ); } @@ -176,7 +176,7 @@ class Test_Functions_Deprecated extends WP_UnitTestCase { $this->fail( 'jpeg support unavailable' ); } - // Call wp_save_image_file + // Call wp_save_image_file(). include_once( ABSPATH . 'wp-admin/includes/image-edit.php' ); $file = wp_tempnam(); $img = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); @@ -184,7 +184,7 @@ class Test_Functions_Deprecated extends WP_UnitTestCase { unset( $img ); unlink( $file ); - // Check if the arg was deprecated + // Check if the arg was deprecated. $check = $this->was_deprecated( 'argument', 'wp_save_image_file' ); $this->assertFalse( $check ); } diff --git a/tests/phpunit/tests/functions/wpAuthCheck.php b/tests/phpunit/tests/functions/wpAuthCheck.php index 767b8a3101..b8e9d2c645 100644 --- a/tests/phpunit/tests/functions/wpAuthCheck.php +++ b/tests/phpunit/tests/functions/wpAuthCheck.php @@ -27,7 +27,7 @@ class Tests_Functions_WP_Auth_Check extends WP_UnitTestCase { * @ticket 41860 */ function test_wp_auth_check_user_logged_in() { - // log user in + // Log user in. wp_set_current_user( 1 ); $expected = array( @@ -44,7 +44,7 @@ class Tests_Functions_WP_Auth_Check extends WP_UnitTestCase { * @ticket 41860 */ function test_wp_auth_check_user_logged_in_login_grace_period_set() { - // log user in + // Log user in. wp_set_current_user( 1 ); $GLOBALS['login_grace_period'] = 1; @@ -55,7 +55,7 @@ class Tests_Functions_WP_Auth_Check extends WP_UnitTestCase { $actual = wp_auth_check( array() ); $logged_in = is_user_logged_in(); - // Leave the global state unchanged + // Leave the global state unchanged. unset( $GLOBALS['login_grace_period'] ); $this->assertTrue( $logged_in ); diff --git a/tests/phpunit/tests/general/paginateLinks.php b/tests/phpunit/tests/general/paginateLinks.php index dc7195c5f9..95692a0524 100644 --- a/tests/phpunit/tests/general/paginateLinks.php +++ b/tests/phpunit/tests/general/paginateLinks.php @@ -134,7 +134,7 @@ EXPECTED; */ function test_paginate_links_base_value() { - // Current page: 2 + // Current page: 2. $links = paginate_links( array( 'current' => 2, @@ -159,7 +159,7 @@ EXPECTED; $document = new DOMDocument(); $document->preserveWhiteSpace = false; - // The first two links should link to page 1 + // The first two links should link to page 1. foreach ( $expected_attributes as $link_idx => $attributes ) { $document->loadHTML( $links[ $link_idx ] ); @@ -174,7 +174,7 @@ EXPECTED; $this->assertEquals( $attributes['class'], $class ); } - // Current page: 1 + // Current page: 1. $links = paginate_links( array( 'current' => 1, @@ -340,7 +340,7 @@ EXPECTED; * @ticket 31939 */ public function test_custom_base_query_arg_should_be_stripped_from_current_url_before_generating_pag_links() { - // Fake the current URL: example.com?foo + // Fake the current URL: example.com?foo. $request_uri = $_SERVER['REQUEST_URI']; $_SERVER['REQUEST_URI'] = add_query_arg( 'foo', '', $request_uri ); diff --git a/tests/phpunit/tests/general/template.php b/tests/phpunit/tests/general/template.php index 0a6802cfdf..90d33ff85f 100644 --- a/tests/phpunit/tests/general/template.php +++ b/tests/phpunit/tests/general/template.php @@ -234,7 +234,7 @@ class Tests_General_Template extends WP_UnitTestCase { $upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); $this->site_icon_url = $upload['url']; - // Save the data + // Save the data. $this->site_icon_id = $this->_make_attachment( $upload ); return $this->site_icon_id; } @@ -445,7 +445,7 @@ class Tests_General_Template extends WP_UnitTestCase { * @since 4.6.0 */ function test_get_the_modified_time_failures_are_filtered() { - // Remove global post objet + // Remove global post object. $GLOBALS['post'] = null; $expected = 'filtered modified time failure result'; @@ -516,7 +516,7 @@ class Tests_General_Template extends WP_UnitTestCase { * @since 4.6.0 */ function test_get_the_modified_date_failures_are_filtered() { - // Remove global post objet + // Remove global post object. $GLOBALS['post'] = null; $expected = 'filtered modified date failure result'; diff --git a/tests/phpunit/tests/http/base.php b/tests/phpunit/tests/http/base.php index 4e4526aa57..d438056126 100644 --- a/tests/phpunit/tests/http/base.php +++ b/tests/phpunit/tests/http/base.php @@ -32,9 +32,9 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { // Disable all transports aside from this one. foreach ( array( 'curl', 'streams', 'fsockopen' ) as $t ) { - remove_filter( "use_{$t}_transport", '__return_false' ); // Just strip them all + remove_filter( "use_{$t}_transport", '__return_false' ); // Just strip them all... if ( $t !== $this->transport ) { - add_filter( "use_{$t}_transport", '__return_false' ); // and add it back if need be.. + add_filter( "use_{$t}_transport", '__return_false' ); // ...and add it back if need be. } } } @@ -52,7 +52,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { } function test_redirect_on_301() { - // 5 : 5 & 301 + // 5 : 5 & 301. $res = wp_remote_request( $this->redirection_script . '?code=301&rt=' . 5, array( 'redirection' => 5 ) ); $this->skipTestOnTimeout( $res ); @@ -61,7 +61,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { } function test_redirect_on_302() { - // 5 : 5 & 302 + // 5 : 5 & 302. $res = wp_remote_request( $this->redirection_script . '?code=302&rt=' . 5, array( 'redirection' => 5 ) ); $this->skipTestOnTimeout( $res ); @@ -73,7 +73,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { * @ticket 16855 */ function test_redirect_on_301_no_redirect() { - // 5 > 0 & 301 + // 5 > 0 & 301. $res = wp_remote_request( $this->redirection_script . '?code=301&rt=' . 5, array( 'redirection' => 0 ) ); $this->skipTestOnTimeout( $res ); @@ -85,7 +85,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { * @ticket 16855 */ function test_redirect_on_302_no_redirect() { - // 5 > 0 & 302 + // 5 > 0 & 302. $res = wp_remote_request( $this->redirection_script . '?code=302&rt=' . 5, array( 'redirection' => 0 ) ); $this->skipTestOnTimeout( $res ); @@ -94,7 +94,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { } function test_redirections_equal() { - // 5 - 5 + // 5 - 5. $res = wp_remote_request( $this->redirection_script . '?rt=' . 5, array( 'redirection' => 5 ) ); $this->skipTestOnTimeout( $res ); @@ -103,7 +103,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { } function test_no_head_redirections() { - // No redirections on HEAD request: + // No redirections on HEAD request. $res = wp_remote_request( $this->redirection_script . '?code=302&rt=' . 1, array( 'method' => 'HEAD' ) ); $this->skipTestOnTimeout( $res ); @@ -115,7 +115,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { * @ticket 16855 */ function test_redirect_on_head() { - // Redirections on HEAD request when Requested + // Redirections on HEAD request when Requested. $res = wp_remote_request( $this->redirection_script . '?rt=' . 5, array( @@ -130,7 +130,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { } function test_redirections_greater() { - // 10 > 5 + // 10 > 5. $res = wp_remote_request( $this->redirection_script . '?rt=' . 10, array( 'redirection' => 5 ) ); $this->skipTestOnTimeout( $res ); @@ -138,7 +138,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { } function test_redirections_greater_edgecase() { - // 6 > 5 (close edgecase) + // 6 > 5 (close edge case). $res = wp_remote_request( $this->redirection_script . '?rt=' . 6, array( 'redirection' => 5 ) ); $this->skipTestOnTimeout( $res ); @@ -146,7 +146,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { } function test_redirections_less_edgecase() { - // 4 < 5 (close edgecase) + // 4 < 5 (close edge case). $res = wp_remote_request( $this->redirection_script . '?rt=' . 4, array( 'redirection' => 5 ) ); $this->skipTestOnTimeout( $res ); @@ -157,7 +157,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { * @ticket 16855 */ function test_redirections_zero_redirections_specified() { - // 0 redirections asked for, Should return the document? + // 0 redirections asked for, should return the document? $res = wp_remote_request( $this->redirection_script . '?code=302&rt=' . 5, array( 'redirection' => 0 ) ); $this->skipTestOnTimeout( $res ); @@ -166,12 +166,12 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { } /** - * Do not redirect on non 3xx status codes + * Do not redirect on non 3xx status codes. * * @ticket 16889 */ function test_location_header_on_201() { - // Prints PASS on initial load, FAIL if the client follows the specified redirection + // Prints PASS on initial load, FAIL if the client follows the specified redirection. $res = wp_remote_request( $this->redirection_script . '?201-location=true' ); $this->skipTestOnTimeout( $res ); @@ -180,14 +180,14 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { } /** - * Test handling of PUT requests on redirects + * Test handling of PUT requests on redirects. * * @ticket 16889 */ function test_no_redirection_on_PUT() { $url = 'http://api.wordpress.org/core/tests/1.0/redirection.php?201-location=1'; - // Test 301 - POST to POST + // Test 301 - POST to POST. $res = wp_remote_request( $url, array( @@ -205,7 +205,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { * @ticket 11888 */ function test_send_headers() { - // Test that the headers sent are received by the server + // Test that the headers sent are received by the server. $headers = array( 'test1' => 'test', 'test2' => 0, @@ -230,7 +230,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { $this->assertTrue( isset( $headers['test2'] ) && '0' === $headers['test2'] ); // cURL/HTTP Extension Note: Will never pass, cURL does not pass headers with an empty value. // Should it be that empty headers with empty values are NOT sent? - //$this->assertTrue( isset($headers['test3']) && '' === $headers['test3'] ); + // $this->assertTrue( isset( $headers['test3'] ) && '' === $headers['test3'] ); } function test_file_stream() { @@ -242,7 +242,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { 'stream' => true, 'timeout' => 30, ) - ); //Auto generate the filename. + ); // Auto generate the filename. // Cleanup before we assert, as it'll return early. if ( ! is_wp_error( $res ) ) { @@ -253,9 +253,9 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { $this->skipTestOnTimeout( $res ); $this->assertNotWPError( $res ); $this->assertEquals( '', $res['body'] ); // The body should be empty. - $this->assertEquals( $size, $res['headers']['content-length'] ); // Check the headers are returned (and the size is the same..) - $this->assertEquals( $size, $filesize ); // Check that the file is written to disk correctly without any extra characters - $this->assertStringStartsWith( get_temp_dir(), $res['filename'] ); // Check it's saving within the temp dir + $this->assertEquals( $size, $res['headers']['content-length'] ); // Check the headers are returned (and the size is the same). + $this->assertEquals( $size, $filesize ); // Check that the file is written to disk correctly without any extra characters. + $this->assertStringStartsWith( get_temp_dir(), $res['filename'] ); // Check it's saving within the temp directory. } /** @@ -271,7 +271,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { 'timeout' => 30, 'limit_response_size' => $size, ) - ); //Auto generate the filename. + ); // Auto generate the filename. // Cleanup before we assert, as it'll return early. if ( ! is_wp_error( $res ) ) { @@ -281,12 +281,12 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { $this->skipTestOnTimeout( $res ); $this->assertNotWPError( $res ); - $this->assertEquals( $size, $filesize ); // Check that the file is written to disk correctly without any extra characters + $this->assertEquals( $size, $filesize ); // Check that the file is written to disk correctly without any extra characters. } /** - * Tests Limiting the response size when returning strings + * Tests limiting the response size when returning strings. * * @ticket 31172 */ @@ -308,7 +308,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { } /** - * Test POST redirection methods + * Test POST redirection methods. * * @dataProvider data_post_redirect_to_method_300 * @@ -325,22 +325,22 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { public function data_post_redirect_to_method_300() { return array( - // Test 300 - POST to POST + // Test 300 - POST to POST. array( 300, 'POST', ), - // Test 301 - POST to POST + // Test 301 - POST to POST. array( 301, 'POST', ), - // Test 302 - POST to GET + // Test 302 - POST to GET. array( 302, 'GET', ), - // Test 303 - POST to GET + // Test 303 - POST to GET. array( 303, 'GET', @@ -349,7 +349,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { } /** - * Test HTTP Requests using an IP url, with a HOST header specified + * Test HTTP Requests using an IP URL, with a HOST header specified. * * @ticket 24182 */ @@ -372,7 +372,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { } /** - * Test HTTP requests where SSL verification is disabled but the CA bundle is still populated + * Test HTTP requests where SSL verification is disabled but the CA bundle is still populated. * * @ticket 33978 */ @@ -394,7 +394,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { } /** - * Test HTTP Redirects with multiple Location headers specified + * Test HTTP Redirects with multiple Location headers specified. * * @ticket 16890 */ @@ -414,7 +414,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { } /** - * Test HTTP Cookie handling + * Test HTTP Cookie handling. * * @ticket 21182 */ @@ -428,7 +428,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { } /** - * Test if HTTPS support works + * Test if HTTPS support works. * * @group ssl * @ticket 25007 diff --git a/tests/phpunit/tests/http/functions.php b/tests/phpunit/tests/http/functions.php index 848085a30a..de272d9a0e 100644 --- a/tests/phpunit/tests/http/functions.php +++ b/tests/phpunit/tests/http/functions.php @@ -15,7 +15,7 @@ class Tests_HTTP_Functions extends WP_UnitTestCase { } function test_head_request() { - // this url give a direct 200 response + // This URL gives a direct 200 response. $url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg'; $response = wp_remote_head( $url ); @@ -31,7 +31,7 @@ class Tests_HTTP_Functions extends WP_UnitTestCase { } function test_head_redirect() { - // this url will 301 redirect + // This URL will 301 redirect. $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg'; $response = wp_remote_head( $url ); @@ -58,14 +58,14 @@ class Tests_HTTP_Functions extends WP_UnitTestCase { $this->assertInternalType( 'array', $response ); - // should return the same headers as a head request + // Should return the same headers as a HEAD request. $this->assertEquals( 'image/jpeg', $headers['content-type'] ); $this->assertEquals( '40148', $headers['content-length'] ); $this->assertEquals( '200', wp_remote_retrieve_response_code( $response ) ); } function test_get_redirect() { - // this will redirect to asdftestblog1.files.wordpress.com + // This will redirect to asdftestblog1.files.wordpress.com. $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg'; $response = wp_remote_get( $url ); @@ -74,17 +74,17 @@ class Tests_HTTP_Functions extends WP_UnitTestCase { $headers = wp_remote_retrieve_headers( $response ); - // should return the same headers as a head request + // Should return the same headers as a HEAD request. $this->assertEquals( 'image/jpeg', $headers['content-type'] ); $this->assertEquals( '40148', $headers['content-length'] ); $this->assertEquals( '200', wp_remote_retrieve_response_code( $response ) ); } function test_get_redirect_limit_exceeded() { - // this will redirect to asdftestblog1.files.wordpress.com + // This will redirect to asdftestblog1.files.wordpress.com. $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg'; - // pretend we've already redirected 5 times + // Pretend we've already redirected 5 times. $response = wp_remote_get( $url, array( 'redirection' => -1 ) ); $this->skipTestOnTimeout( $response ); @@ -183,7 +183,7 @@ class Tests_HTTP_Functions extends WP_UnitTestCase { * @ticket 43231 */ function test_get_cookie_host_only() { - // emulate WP_Http::request() internals + // Emulate WP_Http::request() internals. $requests_response = new Requests_Response(); $requests_response->cookies['test'] = Requests_Cookie::parse( 'test=foo; domain=.wordpress.org' ); @@ -194,12 +194,12 @@ class Tests_HTTP_Functions extends WP_UnitTestCase { $response = $http_response->to_array(); - // check the host_only flag in the resulting WP_Http_Cookie + // Check the host_only flag in the resulting WP_Http_Cookie. $cookie = wp_remote_retrieve_cookie( $response, 'test' ); $this->assertEquals( $cookie->domain, 'wordpress.org' ); $this->assertFalse( $cookie->host_only, 'host-only flag not set' ); - // regurgitate (Requests_Cookie -> WP_Http_Cookie -> Requests_Cookie) + // Regurgitate (Requests_Cookie -> WP_Http_Cookie -> Requests_Cookie). $cookies = WP_Http::normalize_cookies( wp_remote_retrieve_cookies( $response ) ); $this->assertFalse( $cookies['test']->flags['host-only'], 'host-only flag data lost' ); } diff --git a/tests/phpunit/tests/http/http.php b/tests/phpunit/tests/http/http.php index 49d3d87a87..f18e6b719f 100644 --- a/tests/phpunit/tests/http/http.php +++ b/tests/phpunit/tests/http/http.php @@ -17,29 +17,32 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase { } function make_absolute_url_testcases() { - // 0: The Location header, 1: The current url, 3: The expected url + // 0: The Location header, 1: The current URL, 3: The expected URL. return array( - array( 'http://site.com/', 'http://example.com/', 'http://site.com/' ), // Absolute URL provided - array( '/location', '', '/location' ), // No current url provided + // Absolute URL provided. + array( 'http://site.com/', 'http://example.com/', 'http://site.com/' ), + // No current URL provided. + array( '/location', '', '/location' ), - array( '', 'http://example.com', 'http://example.com/' ), // No location provided + // No location provided. + array( '', 'http://example.com', 'http://example.com/' ), - // Location provided relative to site root + // Location provided relative to site root. array( '/root-relative-link.ext', 'http://example.com/', 'http://example.com/root-relative-link.ext' ), array( '/root-relative-link.ext?with=query', 'http://example.com/index.ext?query', 'http://example.com/root-relative-link.ext?with=query' ), - // Location provided relative to current file/directory + // Location provided relative to current file/directory. array( 'relative-file.ext', 'http://example.com/', 'http://example.com/relative-file.ext' ), array( 'relative-file.ext', 'http://example.com/filename', 'http://example.com/relative-file.ext' ), array( 'relative-file.ext', 'http://example.com/directory/', 'http://example.com/directory/relative-file.ext' ), - // Location provided relative to current file/directory but in a parent directory + // Location provided relative to current file/directory but in a parent directory. array( '../file-in-parent.ext', 'http://example.com', 'http://example.com/file-in-parent.ext' ), array( '../file-in-parent.ext', 'http://example.com/filename', 'http://example.com/file-in-parent.ext' ), array( '../file-in-parent.ext', 'http://example.com/directory/', 'http://example.com/file-in-parent.ext' ), array( '../file-in-parent.ext', 'http://example.com/directory/filename', 'http://example.com/file-in-parent.ext' ), - // Location provided in muliple levels higher, including impossible to reach (../ below DOCROOT) + // Location provided in muliple levels higher, including impossible to reach (../ below DOCROOT). array( '../../file-in-grand-parent.ext', 'http://example.com', 'http://example.com/file-in-grand-parent.ext' ), array( '../../file-in-grand-parent.ext', 'http://example.com/filename', 'http://example.com/file-in-grand-parent.ext' ), array( '../../file-in-grand-parent.ext', 'http://example.com/directory/', 'http://example.com/file-in-grand-parent.ext' ), @@ -52,14 +55,14 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase { array( '?query=string', 'http://example.com/file.ext?existing=query-string', 'http://example.com/file.ext?query=string' ), array( 'otherfile.ext?query=string', 'http://example.com/file.ext?existing=query-string', 'http://example.com/otherfile.ext?query=string' ), - // A file with a leading dot + // A file with a leading dot. array( '.ext', 'http://example.com/', 'http://example.com/.ext' ), - // URls within URLs + // URLs within URLs. array( '/expected', 'http://example.com/sub/http://site.com/sub/', 'http://example.com/expected' ), array( '/expected/http://site.com/sub/', 'http://example.com/', 'http://example.com/expected/http://site.com/sub/' ), - // Schemeless URL's (Not valid in HTTP Headers, but may be used elsewhere) + // Schemeless URL's (not valid in HTTP Headers, but may be used elsewhere). array( '//example.com/sub/', 'https://example.net', 'https://example.com/sub/' ), ); } @@ -73,7 +76,7 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase { } function parse_url_testcases() { - // 0: The URL, 1: The expected resulting structure + // 0: The URL, 1: The expected resulting structure. return array( array( self::FULL_TEST_URL, @@ -97,7 +100,7 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase { ), ), - // < PHP 5.4.7: Schemeless URL + // < PHP 5.4.7: Schemeless URL. array( '//example.com/path/', array( @@ -141,7 +144,7 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase { ), ), - // PHP's parse_url() calls this an invalid url, we handle it as a path + // PHP's parse_url() calls this an invalid url, we handle it as a path. array( '/://example.com/', array( 'path' => '/://example.com/' ) ), // Schemeless URL containing colons cause parse errors in PHP 7+. @@ -243,10 +246,10 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase { array( '//fonts.googleapis.com/css?family=Open+Sans:400&subset=latin', PHP_URL_PORT, null ), array( '//fonts.googleapis.com/css?family=Open+Sans:400&subset=latin', PHP_URL_PATH, '/css' ), array( '//fonts.googleapis.com/css?family=Open+Sans:400&subset=latin', PHP_URL_QUERY, 'family=Open+Sans:400&subset=latin' ), - array( '//fonts.googleapis.com/css?family=Open+Sans:400', PHP_URL_HOST, 'fonts.googleapis.com' ), // 25 + array( '//fonts.googleapis.com/css?family=Open+Sans:400', PHP_URL_HOST, 'fonts.googleapis.com' ), // 25 array( '//fonts.googleapis.com/css?family=Open+Sans:400', PHP_URL_PORT, null ), - array( '//fonts.googleapis.com/css?family=Open+Sans:400', PHP_URL_PATH, '/css' ), //27 - array( '//fonts.googleapis.com/css?family=Open+Sans:400', PHP_URL_QUERY, 'family=Open+Sans:400' ), //28 + array( '//fonts.googleapis.com/css?family=Open+Sans:400', PHP_URL_PATH, '/css' ), // 27 + array( '//fonts.googleapis.com/css?family=Open+Sans:400', PHP_URL_QUERY, 'family=Open+Sans:400' ), // 28 // Empty string or non-string passed in. array( '', PHP_URL_PATH, '' ), @@ -339,7 +342,7 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase { ), array( 'http://example.com/', PHP_URL_HOST, 'example.com' ), array( 'http://example.com/', PHP_URL_USER, null ), - array( 'http:///example.com', -1, false ), // Malformed. + array( 'http:///example.com', -1, false ), // Malformed. array( 'http:///example.com', PHP_URL_HOST, null ), // Malformed. ); } diff --git a/tests/phpunit/tests/image/dimensions.php b/tests/phpunit/tests/image/dimensions.php index 87b494ba87..2dd75808f8 100644 --- a/tests/phpunit/tests/image/dimensions.php +++ b/tests/phpunit/tests/image/dimensions.php @@ -7,147 +7,147 @@ */ class Tests_Image_Dimensions extends WP_UnitTestCase { function test_400x400_no_crop() { - // landscape: resize 640x480 to fit 400x400: 400x300 + // Landscape: resize 640x480 to fit 400x400: 400x300. $out = image_resize_dimensions( 640, 480, 400, 400, false ); - // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h + // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. $this->assertEquals( array( 0, 0, 0, 0, 400, 300, 640, 480 ), $out ); - // portrait: resize 480x640 to fit 400x400: 300x400 + // Portrait: resize 480x640 to fit 400x400: 300x400. $out = image_resize_dimensions( 480, 640, 400, 400, false ); - // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h + // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. $this->assertEquals( array( 0, 0, 0, 0, 300, 400, 480, 640 ), $out ); } function test_400x0_no_crop() { - // landscape: resize 640x480 to fit 400w: 400x300 + // Landscape: resize 640x480 to fit 400w: 400x300. $out = image_resize_dimensions( 640, 480, 400, 0, false ); - // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h + // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. $this->assertEquals( array( 0, 0, 0, 0, 400, 300, 640, 480 ), $out ); - // portrait: resize 480x640 to fit 400w: 400x533 + // Portrait: resize 480x640 to fit 400w: 400x533. $out = image_resize_dimensions( 480, 640, 400, 0, false ); - // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h + // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. $this->assertEquals( array( 0, 0, 0, 0, 400, 533, 480, 640 ), $out ); } function test_0x400_no_crop() { - // landscape: resize 640x480 to fit 400h: 533x400 + // Landscape: resize 640x480 to fit 400h: 533x400. $out = image_resize_dimensions( 640, 480, 0, 400, false ); - // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h + // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. $this->assertEquals( array( 0, 0, 0, 0, 533, 400, 640, 480 ), $out ); - // portrait: resize 480x640 to fit 400h: 300x400 + // Portrait: resize 480x640 to fit 400h: 300x400. $out = image_resize_dimensions( 480, 640, 0, 400, false ); - // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h + // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. $this->assertEquals( array( 0, 0, 0, 0, 300, 400, 480, 640 ), $out ); } function test_800x800_no_crop() { - // landscape: resize 640x480 to fit 800x800 + // Landscape: resize 640x480 to fit 800x800. $out = image_resize_dimensions( 640, 480, 800, 800, false ); - // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h + // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. $this->assertEquals( false, $out ); - // portrait: resize 480x640 to fit 800x800 + // Portrait: resize 480x640 to fit 800x800. $out = image_resize_dimensions( 480, 640, 800, 800, false ); - // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h + // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. $this->assertEquals( false, $out ); } function test_800x0_no_crop() { - // landscape: resize 640x480 to fit 800w + // Landscape: resize 640x480 to fit 800w. $out = image_resize_dimensions( 640, 480, 800, 0, false ); - // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h + // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. $this->assertEquals( false, $out ); - // portrait: resize 480x640 to fit 800w + // Portrait: resize 480x640 to fit 800w. $out = image_resize_dimensions( 480, 640, 800, 0, false ); - // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h + // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. $this->assertEquals( false, $out ); } function test_0x800_no_crop() { - // landscape: resize 640x480 to fit 800h + // Landscape: resize 640x480 to fit 800h. $out = image_resize_dimensions( 640, 480, 0, 800, false ); - // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h + // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. $this->assertEquals( false, $out ); - // portrait: resize 480x640 to fit 800h + // Portrait: resize 480x640 to fit 800h. $out = image_resize_dimensions( 480, 640, 0, 800, false ); - // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h + // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. $this->assertEquals( false, $out ); } - // cropped versions + // Cropped versions. function test_400x400_crop() { - // landscape: crop 640x480 to fit 400x400: 400x400 taken from a 480x480 crop at (80. 0) + // Landscape: crop 640x480 to fit 400x400: 400x400 taken from a 480x480 crop at (80. 0). $out = image_resize_dimensions( 640, 480, 400, 400, true ); - // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h + // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. $this->assertEquals( array( 0, 0, 80, 0, 400, 400, 480, 480 ), $out ); - // portrait: resize 480x640 to fit 400x400: 400x400 taken from a 480x480 crop at (0. 80) + // Portrait: resize 480x640 to fit 400x400: 400x400 taken from a 480x480 crop at (0. 80). $out = image_resize_dimensions( 480, 640, 400, 400, true ); - // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h + // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. $this->assertEquals( array( 0, 0, 0, 80, 400, 400, 480, 480 ), $out ); } function test_400x0_crop() { - // landscape: resize 640x480 to fit 400w: 400x300 + // Landscape: resize 640x480 to fit 400w: 400x300. $out = image_resize_dimensions( 640, 480, 400, 0, true ); - // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h + // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. $this->assertEquals( array( 0, 0, 0, 0, 400, 300, 640, 480 ), $out ); - // portrait: resize 480x640 to fit 400w: 400x533 + // Portrait: resize 480x640 to fit 400w: 400x533. $out = image_resize_dimensions( 480, 640, 400, 0, true ); - // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h + // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. $this->assertEquals( array( 0, 0, 0, 0, 400, 533, 480, 640 ), $out ); } function test_0x400_crop() { - // landscape: resize 640x480 to fit 400h: 533x400 + // Landscape: resize 640x480 to fit 400h: 533x400. $out = image_resize_dimensions( 640, 480, 0, 400, true ); - // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h + // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. $this->assertEquals( array( 0, 0, 0, 0, 533, 400, 640, 480 ), $out ); - // portrait: resize 480x640 to fit 400h: 300x400 + // Portrait: resize 480x640 to fit 400h: 300x400. $out = image_resize_dimensions( 480, 640, 0, 400, true ); - // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h + // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. $this->assertEquals( array( 0, 0, 0, 0, 300, 400, 480, 640 ), $out ); } function test_400x500_crop() { - // landscape: crop 640x480 to fit 400x500: 400x400 taken from a 480x480 crop at (80. 0) + // Landscape: crop 640x480 to fit 400x500: 400x400 taken from a 480x480 crop at (80. 0). $out = image_resize_dimensions( 640, 480, 400, 500, true ); - // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h + // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. $this->assertEquals( array( 0, 0, 120, 0, 400, 480, 400, 480 ), $out ); - // portrait: resize 480x640 to fit 400x400: 400x400 taken from a 480x480 crop at (0. 80) + // Portrait: resize 480x640 to fit 400x400: 400x400 taken from a 480x480 crop at (0. 80). $out = image_resize_dimensions( 480, 640, 400, 500, true ); - // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h + // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. $this->assertEquals( array( 0, 0, 0, 20, 400, 500, 480, 600 ), $out ); } function test_640x480() { - // crop 640x480 to fit 640x480 (no change) + // Crop 640x480 to fit 640x480 (no change). $out = image_resize_dimensions( 640, 480, 640, 480, true ); $this->assertFalse( $out ); - // resize 640x480 to fit 640x480 (no change) + // Resize 640x480 to fit 640x480 (no change). $out = image_resize_dimensions( 640, 480, 640, 480, false ); $this->assertFalse( $out ); // Test with the filter override. add_filter( 'wp_image_resize_identical_dimensions', '__return_true' ); - // crop 640x480 to fit 640x480 (no change) + // Crop 640x480 to fit 640x480 (no change). $out = image_resize_dimensions( 640, 480, 640, 480, true ); - // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h + // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. $this->assertEquals( array( 0, 0, 0, 0, 640, 480, 640, 480 ), $out ); - // resize 640x480 to fit 640x480 (no change) + // Resize 640x480 to fit 640x480 (no change). $out = image_resize_dimensions( 640, 480, 640, 480, false ); - // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h + // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. $this->assertEquals( array( 0, 0, 0, 0, 640, 480, 640, 480 ), $out ); remove_filter( 'wp_image_resize_identical_dimensions', '__return_true' ); @@ -157,28 +157,28 @@ class Tests_Image_Dimensions extends WP_UnitTestCase { * @ticket 19393 */ function test_crop_anchors() { - // landscape: crop 640x480 to fit 400x500: 400x400 taken from a 480x480 crop - // src_x = 0 (left), src_y = 0 (top) + // Landscape: crop 640x480 to fit 400x500: 400x400 taken from a 480x480 crop. + // src_x = 0 (left), src_y = 0 (top). $out = image_resize_dimensions( 640, 480, 400, 500, array( 'left', 'top' ) ); - // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h + // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. $this->assertEquals( array( 0, 0, 0, 0, 400, 480, 400, 480 ), $out ); - // portrait: resize 480x640 to fit 400x400: 400x400 taken from a 480x480 crop - // src_x = 0 (left), src_y = 0 (top) + // Portrait: resize 480x640 to fit 400x400: 400x400 taken from a 480x480 crop. + // src_x = 0 (left), src_y = 0 (top). $out = image_resize_dimensions( 480, 640, 400, 500, array( 'left', 'top' ) ); - // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h + // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. $this->assertEquals( array( 0, 0, 0, 0, 400, 500, 480, 600 ), $out ); - // landscape: crop 640x480 to fit 400x500: 400x400 taken from a 480x480 crop - // src_x = 240 (left), src_y = 0 (due to landscape crop) + // Landscape: crop 640x480 to fit 400x500: 400x400 taken from a 480x480 crop. + // src_x = 240 (left), src_y = 0 (due to landscape crop). $out = image_resize_dimensions( 640, 480, 400, 500, array( 'right', 'bottom' ) ); - // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h + // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. $this->assertEquals( array( 0, 0, 240, 0, 400, 480, 400, 480 ), $out ); - // portrait: resize 480x640 to fit 400x400: 400x400 taken from a 480x480 crop - // src_x = 0 (due to portrait crop), src_y = 40 (bottom) + // Portrait: resize 480x640 to fit 400x400: 400x400 taken from a 480x480 crop. + // src_x = 0 (due to portrait crop), src_y = 40 (bottom). $out = image_resize_dimensions( 480, 640, 400, 500, array( 'right', 'bottom' ) ); - // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h + // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h. $this->assertEquals( array( 0, 0, 0, 40, 400, 500, 480, 600 ), $out ); } diff --git a/tests/phpunit/tests/image/editor.php b/tests/phpunit/tests/image/editor.php index 35242ad3e0..38aa223aea 100644 --- a/tests/phpunit/tests/image/editor.php +++ b/tests/phpunit/tests/image/editor.php @@ -69,11 +69,11 @@ class Tests_Image_Editor extends WP_Image_UnitTestCase { */ public function test_set_quality() { - // Get an editor + // Get an editor. $editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); $editor->set_mime_type( 'image/jpeg' ); // Ensure mime-specific filters act properly. - // Check default value + // Check default value. $this->assertEquals( 82, $editor->get_quality() ); // Ensure the quality filters do not have precedence if created after editor instantiation. @@ -85,11 +85,11 @@ class Tests_Image_Editor extends WP_Image_UnitTestCase { add_filter( 'jpeg_quality', $func_95_percent ); $this->assertEquals( 82, $editor->get_quality() ); - // Ensure set_quality() works and overrides the filters + // Ensure set_quality() works and overrides the filters. $this->assertTrue( $editor->set_quality( 75 ) ); $this->assertEquals( 75, $editor->get_quality() ); - // Get a new editor to clear default quality state + // Get a new editor to clear default quality state. unset( $editor ); $editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); $editor->set_mime_type( 'image/jpeg' ); // Ensure mime-specific filters act properly. @@ -97,7 +97,7 @@ class Tests_Image_Editor extends WP_Image_UnitTestCase { // Ensure jpeg_quality filter applies if it exists before editor instantiation. $this->assertEquals( 95, $editor->get_quality() ); - // Get a new editor to clear jpeg_quality state + // Get a new editor to clear jpeg_quality state. remove_filter( 'jpeg_quality', $func_95_percent ); unset( $editor ); $editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); @@ -105,7 +105,7 @@ class Tests_Image_Editor extends WP_Image_UnitTestCase { // Ensure wp_editor_set_quality filter applies if it exists before editor instantiation. $this->assertEquals( 100, $editor->get_quality() ); - // Clean up + // Clean up. remove_filter( 'wp_editor_set_quality', $func_100_percent ); } @@ -116,7 +116,7 @@ class Tests_Image_Editor extends WP_Image_UnitTestCase { */ public function test_generate_filename() { - // Get an editor + // Get an editor. $editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); $property = new ReflectionProperty( $editor, 'size' ); @@ -129,16 +129,16 @@ class Tests_Image_Editor extends WP_Image_UnitTestCase { ) ); - // Test with no parameters + // Test with no parameters. $this->assertEquals( 'canola-100x50.jpg', wp_basename( $editor->generate_filename() ) ); - // Test with a suffix only + // Test with a suffix only. $this->assertEquals( 'canola-new.jpg', wp_basename( $editor->generate_filename( 'new' ) ) ); - // Test with a destination dir only + // Test with a destination dir only. $this->assertEquals( trailingslashit( realpath( get_temp_dir() ) ), trailingslashit( realpath( dirname( $editor->generate_filename( null, get_temp_dir() ) ) ) ) ); - // Test with a suffix only + // Test with a suffix only. $this->assertEquals( 'canola-100x50.png', wp_basename( $editor->generate_filename( null, null, 'png' ) ) ); // Combo! @@ -154,10 +154,10 @@ class Tests_Image_Editor extends WP_Image_UnitTestCase { $editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); - // Size should be false by default + // Size should be false by default. $this->assertNull( $editor->get_size() ); - // Set a size + // Set a size. $size = array( 'height' => 50, 'width' => 100, @@ -177,10 +177,10 @@ class Tests_Image_Editor extends WP_Image_UnitTestCase { public function test_get_suffix() { $editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); - // Size should be false by default + // Size should be false by default. $this->assertFalse( $editor->get_suffix() ); - // Set a size + // Set a size. $size = array( 'height' => 50, 'width' => 100, diff --git a/tests/phpunit/tests/image/editorGd.php b/tests/phpunit/tests/image/editorGd.php index fdd0e9c96a..17e73de217 100644 --- a/tests/phpunit/tests/image/editorGd.php +++ b/tests/phpunit/tests/image/editorGd.php @@ -100,7 +100,7 @@ class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { $this->assertEquals( $expected_array, $resized ); - // Now, verify real dimensions are as expected + // Now, verify real dimensions are as expected. $image_path = DIR_TESTDATA . '/images/' . $resized[0]['file']; $this->assertImageDimensions( $image_path, @@ -375,7 +375,7 @@ class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { foreach ( $resized as $key => $image_data ) { $image_path = DIR_TESTDATA . '/images/' . $image_data['file']; - // Now, verify real dimensions are as expected + // Now, verify real dimensions are as expected. $this->assertImageDimensions( $image_path, $expected_array[ $key ]['width'], diff --git a/tests/phpunit/tests/image/editorImagick.php b/tests/phpunit/tests/image/editorImagick.php index ac531ff942..23e8dbd47f 100644 --- a/tests/phpunit/tests/image/editorImagick.php +++ b/tests/phpunit/tests/image/editorImagick.php @@ -93,7 +93,7 @@ class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { $this->assertEquals( $expected_array, $resized ); - // Now, verify real dimensions are as expected + // Now, verify real dimensions are as expected. $image_path = DIR_TESTDATA . '/images/' . $resized[0]['file']; $this->assertImageDimensions( $image_path, @@ -368,7 +368,7 @@ class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { foreach ( $resized as $key => $image_data ) { $image_path = DIR_TESTDATA . '/images/' . $image_data['file']; - // Now, verify real dimensions are as expected + // Now, verify real dimensions are as expected. $this->assertImageDimensions( $image_path, $expected_array[ $key ]['width'], diff --git a/tests/phpunit/tests/image/functions.php b/tests/phpunit/tests/image/functions.php index 8fa47c65a5..5e087ad13f 100644 --- a/tests/phpunit/tests/image/functions.php +++ b/tests/phpunit/tests/image/functions.php @@ -46,7 +46,7 @@ class Tests_Image_Functions extends WP_UnitTestCase { } function test_is_image_positive() { - // these are all image files recognized by php + // These are all image files recognized by PHP. $files = array( 'test-image-cmyk.jpg', 'test-image.bmp', @@ -72,7 +72,7 @@ class Tests_Image_Functions extends WP_UnitTestCase { } function test_is_image_negative() { - // these are actually image files but aren't recognized or usable by php + // These are actually image files but aren't recognized or usable by PHP. $files = array( 'test-image.pct', 'test-image.tga', @@ -85,7 +85,7 @@ class Tests_Image_Functions extends WP_UnitTestCase { } function test_is_displayable_image_positive() { - // these are all usable in typical web browsers + // These are all usable in typical web browsers. $files = array( 'test-image.gif', 'test-image.png', @@ -103,11 +103,11 @@ class Tests_Image_Functions extends WP_UnitTestCase { } function test_is_displayable_image_negative() { - // these are image files but aren't suitable for web pages because of compatibility or size issues + // These are image files but aren't suitable for web pages because of compatibility or size issues. $files = array( - // 'test-image-cmyk.jpg', Allowed in r9727 - // 'test-image.bmp', Allowed in r28589 - // 'test-image-grayscale.jpg', Allowed in r9727 + // 'test-image-cmyk.jpg', Allowed in r9727. + // 'test-image.bmp', Allowed in r28589. + // 'test-image-grayscale.jpg', Allowed in r9727. 'test-image.pct', 'test-image.tga', 'test-image.sgi', @@ -135,18 +135,18 @@ class Tests_Image_Functions extends WP_UnitTestCase { include_once( ABSPATH . 'wp-admin/includes/image-edit.php' ); - // Mime types + // Mime types. $mime_types = array( 'image/jpeg', 'image/gif', 'image/png', ); - // Test each image editor engine + // Test each image editor engine. $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' ); foreach ( $classes as $class ) { - // If the image editor isn't available, skip it + // If the image editor isn't available, skip it. if ( ! call_user_func( array( $class, 'test' ) ) ) { continue; } @@ -154,7 +154,7 @@ class Tests_Image_Functions extends WP_UnitTestCase { $img = new $class( DIR_TESTDATA . '/images/canola.jpg' ); $loaded = $img->load(); - // Save a file as each mime type, assert it works + // Save a file as each mime type, assert it works. foreach ( $mime_types as $mime_type ) { if ( ! $img->supports_mime_type( $mime_type ) ) { continue; @@ -166,12 +166,12 @@ class Tests_Image_Functions extends WP_UnitTestCase { $this->assertNotWPError( $ret ); $this->assertEquals( $mime_type, $this->get_mime_type( $ret['path'] ) ); - // Clean up + // Clean up. unlink( $file ); unlink( $ret['path'] ); } - // Clean up + // Clean up. unset( $img ); } } @@ -186,11 +186,11 @@ class Tests_Image_Functions extends WP_UnitTestCase { $this->markTestSkipped( 'The fileinfo PHP extension is not loaded.' ); } - // Test each image editor engine + // Test each image editor engine. $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' ); foreach ( $classes as $class ) { - // If the image editor isn't available, skip it + // If the image editor isn't available, skip it. if ( ! call_user_func( array( $class, 'test' ) ) ) { continue; } @@ -198,17 +198,17 @@ class Tests_Image_Functions extends WP_UnitTestCase { $img = new $class( DIR_TESTDATA . '/images/canola.jpg' ); $loaded = $img->load(); - // Save the file + // Save the file. $mime_type = 'image/gif'; $file = wp_tempnam( 'tmp.jpg' ); $ret = $img->save( $file, $mime_type ); - // Make assertions + // Make assertions. $this->assertNotEmpty( $ret ); $this->assertNotWPError( $ret ); $this->assertEquals( $mime_type, $this->get_mime_type( $ret['path'] ) ); - // Clean up + // Clean up. unlink( $file ); unlink( $ret['path'] ); unset( $img ); @@ -225,21 +225,21 @@ class Tests_Image_Functions extends WP_UnitTestCase { $this->markTestSkipped( 'The fileinfo PHP extension is not loaded.' ); } - // Mime types + // Mime types. $mime_types = array( 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'jpe' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png', - 'unk' => 'image/jpeg', // Default, unknown + 'unk' => 'image/jpeg', // Default, unknown. ); - // Test each image editor engine + // Test each image editor engine. $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' ); foreach ( $classes as $class ) { - // If the image editor isn't available, skip it + // If the image editor isn't available, skip it. if ( ! call_user_func( array( $class, 'test' ) ) ) { continue; } @@ -247,7 +247,7 @@ class Tests_Image_Functions extends WP_UnitTestCase { $img = new $class( DIR_TESTDATA . '/images/canola.jpg' ); $loaded = $img->load(); - // Save the image as each file extension, check the mime type + // Save the image as each file extension, check the mime type. $img = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); $this->assertNotWPError( $img ); @@ -265,7 +265,7 @@ class Tests_Image_Functions extends WP_UnitTestCase { unlink( $ret['path'] ); } - // Clean up + // Clean up. unset( $img ); } } @@ -278,7 +278,7 @@ class Tests_Image_Functions extends WP_UnitTestCase { */ public function test_load_directory() { - // First, test with deprecated wp_load_image function + // First, test with deprecated wp_load_image function. $editor1 = wp_load_image( DIR_TESTDATA ); $this->assertNotInternalType( 'resource', $editor1 ); @@ -288,7 +288,7 @@ class Tests_Image_Functions extends WP_UnitTestCase { // Then, test with editors. $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' ); foreach ( $classes as $class ) { - // If the image editor isn't available, skip it + // If the image editor isn't available, skip it. if ( ! call_user_func( array( $class, 'test' ) ) ) { continue; } diff --git a/tests/phpunit/tests/image/header.php b/tests/phpunit/tests/image/header.php index b166d0e2bb..ad9c20d8b1 100644 --- a/tests/phpunit/tests/image/header.php +++ b/tests/phpunit/tests/image/header.php @@ -88,7 +88,7 @@ class Tests_Image_Header extends WP_UnitTestCase { 'height' => 1200, ) ); - $this->assertEquals( 1500, $dimensions['dst_width'] ); // max width + $this->assertEquals( 1500, $dimensions['dst_width'] ); // Max width. $this->assertEquals( 230, $dimensions['dst_height'] ); } diff --git a/tests/phpunit/tests/image/intermediateSize.php b/tests/phpunit/tests/image/intermediateSize.php index ec0b818a9e..c7d8307afc 100644 --- a/tests/phpunit/tests/image/intermediateSize.php +++ b/tests/phpunit/tests/image/intermediateSize.php @@ -74,14 +74,14 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase { $file = DIR_TESTDATA . '/images/waffles.jpg'; $id = $this->_make_attachment( $file, 0 ); - // look for a size by name + // Look for a size by name. $image = image_get_intermediate_size( $id, 'test-size' ); - // cleanup + // Cleanup. remove_image_size( 'test-size' ); - // test for the expected string because the array will by definition - // return with the correct height and width attributes + // Test for the expected string because the array will by definition + // return with the correct height and width attributes. $this->assertTrue( strpos( $image['file'], '330x220' ) > 0 ); } @@ -89,7 +89,7 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase { * @ticket 17626 */ function test_get_intermediate_sizes_by_array_exact() { - // Only one dimention match shouldn't return false positive (see: 17626) + // Only one dimention match shouldn't return false positive (see: #17626). add_image_size( 'test-size', 330, 220, true ); add_image_size( 'false-height', 330, 400, true ); add_image_size( 'false-width', 600, 220, true ); @@ -97,12 +97,12 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase { $file = DIR_TESTDATA . '/images/waffles.jpg'; $id = $this->_make_attachment( $file, 0 ); - // look for a size by array that exists - // note: staying larger than 300px to miss default medium crop + // Look for a size by array that exists. + // Note: Staying larger than 300px to miss default medium crop. $image = image_get_intermediate_size( $id, array( 330, 220 ) ); - // test for the expected string because the array will by definition - // return with the correct height and width attributes + // Test for the expected string because the array will by definition + // return with the correct height and width attributes. $this->assertTrue( strpos( $image['file'], '330x220' ) > 0 ); } @@ -110,8 +110,8 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase { * @ticket 17626 */ function test_get_intermediate_sizes_by_array_nearest() { - // If an exact size is not found, it should be returned - // If not, find nearest size that is larger (see: 17626) + // If an exact size is not found, it should be returned. + // If not, find nearest size that is larger (see: #17626). add_image_size( 'test-size', 450, 300, true ); add_image_size( 'false-height', 330, 100, true ); add_image_size( 'false-width', 150, 220, true ); @@ -119,12 +119,12 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase { $file = DIR_TESTDATA . '/images/waffles.jpg'; $id = $this->_make_attachment( $file, 0 ); - // look for a size by array that doesn't exist - // note: staying larger than 300px to miss default medium crop + // Look for a size by array that doesn't exist. + // Note: Staying larger than 300px to miss default medium crop. $image = image_get_intermediate_size( $id, array( 330, 220 ) ); - // you have to test for the string because the image will by definition - // return with the correct height and width attributes + // Test for the expected string because the array will by definition + // return with the correct height and width attributes. $this->assertTrue( strpos( $image['file'], '450x300' ) > 0 ); } @@ -132,20 +132,20 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase { * @ticket 17626 */ function test_get_intermediate_sizes_by_array_nearest_false() { - // If an exact size is not found, it should be returned - // If not, find nearest size that is larger, otherwise return false (see: 17626) + // If an exact size is not found, it should be returned. + // If not, find nearest size that is larger, otherwise return false (see: #17626). add_image_size( 'false-height', 330, 100, true ); add_image_size( 'false-width', 150, 220, true ); $file = DIR_TESTDATA . '/images/waffles.jpg'; $id = $this->_make_attachment( $file, 0 ); - // look for a size by array that doesn't exist - // note: staying larger than 300px to miss default medium crop + // Look for a size by array that doesn't exist. + // Note: Staying larger than 300px to miss default medium crop. $image = image_get_intermediate_size( $id, array( 330, 220 ) ); - // you have to test for the string because the image will by definition - // return with the correct height and width attributes + // Test for the expected string because the array will by definition + // return with the correct height and width attributes. $this->assertFalse( $image ); } @@ -153,10 +153,10 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase { * @ticket 17626 */ function test_get_intermediate_sizes_by_array_zero_height() { - // Generate random width + // Generate random width. $random_w = rand( 300, 400 ); - // Only one dimention match shouldn't return false positive (see: 17626) + // Only one dimention match shouldn't return false positive (see: #17626). add_image_size( 'test-size', $random_w, 0, false ); add_image_size( 'false-height', $random_w, 100, true ); @@ -167,12 +167,12 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase { $image_w = $random_w; $image_h = round( ( $image_w / $original['width'] ) * $original['height'] ); - // look for a size by array that exists - // note: staying larger than 300px to miss default medium crop + // Look for a size by array that exists. + // Note: Staying larger than 300px to miss default medium crop. $image = image_get_intermediate_size( $id, array( $random_w, 0 ) ); - // test for the expected string because the array will by definition - // return with the correct height and width attributes + // Test for the expected string because the array will by definition + // return with the correct height and width attributes. $this->assertTrue( strpos( $image['file'], $image_w . 'x' . $image_h ) > 0 ); } @@ -184,7 +184,7 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase { // 202 is the smallest height that will trigger a miss for 'false-height'. $height = 202; - // Only one dimention match shouldn't return false positive (see: 17626) + // Only one dimention match shouldn't return false positive (see: #17626). add_image_size( 'test-size', 0, $height, false ); add_image_size( 'false-height', 300, $height, true ); @@ -195,12 +195,12 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase { $image_h = $height; $image_w = round( ( $image_h / $original['height'] ) * $original['width'] ); - // look for a size by array that exists - // note: staying larger than 300px to miss default medium crop + // Look for a size by array that exists. + // Note: Staying larger than 300px to miss default medium crop. $image = image_get_intermediate_size( $id, array( 0, $height ) ); - // test for the expected string because the array will by definition - // return with the correct height and width attributes + // Test for the expected string because the array will by definition + // return with the correct height and width attributes. $this->assertTrue( strpos( $image['file'], $image_w . 'x' . $image_h ) > 0 ); } @@ -221,8 +221,8 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase { $image_h = $height; $image_w = round( ( $image_h / $original['height'] ) * $original['width'] ); - // look for a size by array that exists - // note: staying larger than 300px to miss default medium crop + // Look for a size by array that exists. + // Note: Staying larger than 300px to miss default medium crop. $image = image_get_intermediate_size( $id, array( 0, $height ) ); $this->assertTrue( strpos( $image['file'], $width . 'x' . $height ) > 0 ); @@ -238,7 +238,7 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase { $file = DIR_TESTDATA . '/images/waffles.jpg'; $id = $this->_make_attachment( $file, 0 ); - // Request a size by array that doesn't exist and is smaller than the 'thumbnail' + // Request a size by array that doesn't exist and is smaller than the 'thumbnail'. $image = image_get_intermediate_size( $id, array( 50, 25 ) ); // We should get the 'test-size' file and not the thumbnail. @@ -255,7 +255,7 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase { $original = wp_get_attachment_metadata( $id ); $thumbnail_file = $original['sizes']['thumbnail']['file']; - // Request a size by array that doesn't exist and is smaller than the 'thumbnail' + // Request a size by array that doesn't exist and is smaller than the 'thumbnail'. $image = image_get_intermediate_size( $id, array( 50, 25 ) ); // We should get the 'thumbnail' file as a fallback. diff --git a/tests/phpunit/tests/image/meta.php b/tests/phpunit/tests/image/meta.php index 0d791b99e8..f22bcca845 100644 --- a/tests/phpunit/tests/image/meta.php +++ b/tests/phpunit/tests/image/meta.php @@ -18,7 +18,7 @@ class Tests_Image_Meta extends WP_UnitTestCase { } function test_exif_d70() { - // exif from a Nikon D70 + // Exif from a Nikon D70. $out = wp_read_image_metadata( DIR_TESTDATA . '/images/2004-07-22-DSC_0008.jpg' ); $this->assertEquals( 6.3, $out['aperture'] ); @@ -34,7 +34,7 @@ class Tests_Image_Meta extends WP_UnitTestCase { } function test_exif_d70_mf() { - // exif from a Nikon D70 - manual focus lens, so some data is unavailable + // Exif from a Nikon D70 - manual focus lens, so some data is unavailable. $out = wp_read_image_metadata( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG' ); $this->assertEquals( 0, $out['aperture'] ); @@ -44,14 +44,14 @@ class Tests_Image_Meta extends WP_UnitTestCase { $this->assertEquals( strtotime( '2007-06-17 21:18:00' ), $out['created_timestamp'] ); $this->assertEquals( '', $out['copyright'] ); $this->assertEquals( 0, $out['focal_length'] ); - $this->assertEquals( 0, $out['iso'] ); // interesting - a Nikon bug? + $this->assertEquals( 0, $out['iso'] ); // Interesting - a Nikon bug? $this->assertEquals( 1 / 500, $out['shutter_speed'] ); $this->assertEquals( '', $out['title'] ); - #$this->assertEquals(array('Flowers'), $out['keywords']); + // $this->assertEquals( array( 'Flowers' ), $out['keywords'] ); } function test_exif_d70_iptc() { - // exif from a Nikon D70 with IPTC data added later + // Exif from a Nikon D70 with IPTC data added later. $out = wp_read_image_metadata( DIR_TESTDATA . '/images/2004-07-22-DSC_0007.jpg' ); $this->assertEquals( 6.3, $out['aperture'] ); @@ -67,7 +67,7 @@ class Tests_Image_Meta extends WP_UnitTestCase { } function test_exif_fuji() { - // exif from a Fuji FinePix S5600 (thanks Mark) + // Exif from a Fuji FinePix S5600 (thanks Mark). $out = wp_read_image_metadata( DIR_TESTDATA . '/images/a2-small.jpg' ); $this->assertEquals( 4.5, $out['aperture'] ); @@ -87,9 +87,8 @@ class Tests_Image_Meta extends WP_UnitTestCase { * @ticket 6571 */ function test_exif_error() { - // https://core.trac.wordpress.org/ticket/6571 - // this triggers a warning mesage when reading the exif block + // This triggers a warning mesage when reading the Exif block. $out = wp_read_image_metadata( DIR_TESTDATA . '/images/waffles.jpg' ); $this->assertEquals( 0, $out['aperture'] ); @@ -105,7 +104,7 @@ class Tests_Image_Meta extends WP_UnitTestCase { } function test_exif_no_data() { - // no exif data in this image (from burningwell.org) + // No Exif data in this image (from burningwell.org). $out = wp_read_image_metadata( DIR_TESTDATA . '/images/canola.jpg' ); $this->assertEquals( 0, $out['aperture'] ); @@ -124,8 +123,7 @@ class Tests_Image_Meta extends WP_UnitTestCase { * @ticket 9417 */ function test_utf8_iptc_tags() { - - // trilingual UTF-8 text in the ITPC caption-abstract field + // Trilingual UTF-8 text in the ITPC caption-abstract field. $out = wp_read_image_metadata( DIR_TESTDATA . '/images/test-image-iptc.jpg' ); $this->assertEquals( 'This is a comment. / Это комментарий. / Βλέπετε ένα σχόλιο.', $out['caption'] ); diff --git a/tests/phpunit/tests/image/resize.php b/tests/phpunit/tests/image/resize.php index 2cbd5a2505..34660ae1e1 100644 --- a/tests/phpunit/tests/image/resize.php +++ b/tests/phpunit/tests/image/resize.php @@ -41,7 +41,7 @@ abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase function test_resize_png() { $image = $this->resize_helper( DIR_TESTDATA . '/images/test-image.png', 25, 25 ); - if ( ! is_string( $image ) ) { // WP_Error, stop GLib-GObject-CRITICAL assertion + if ( ! is_string( $image ) ) { // WP_Error, stop GLib-GObject-CRITICAL assertion. $this->fail( sprintf( 'No PNG support in the editor engine %s on this system', $this->editor_engine ) ); } @@ -57,7 +57,7 @@ abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase function test_resize_gif() { $image = $this->resize_helper( DIR_TESTDATA . '/images/test-image.gif', 25, 25 ); - if ( ! is_string( $image ) ) { // WP_Error, stop GLib-GObject-CRITICAL assertion + if ( ! is_string( $image ) ) { // WP_Error, stop GLib-GObject-CRITICAL assertion. $this->fail( sprintf( 'No GIF support in the editor engine %s on this system', $this->editor_engine ) ); } @@ -71,7 +71,7 @@ abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase } function test_resize_larger() { - // image_resize() should refuse to make an image larger + // image_resize() should refuse to make an image larger. $image = $this->resize_helper( DIR_TESTDATA . '/images/test-image.jpg', 100, 100 ); $this->assertInstanceOf( 'WP_Error', $image ); diff --git a/tests/phpunit/tests/image/siteIcon.php b/tests/phpunit/tests/image/siteIcon.php index dad3ddba52..2bae6de50b 100644 --- a/tests/phpunit/tests/image/siteIcon.php +++ b/tests/phpunit/tests/image/siteIcon.php @@ -56,7 +56,7 @@ class Tests_WP_Site_Icon extends WP_UnitTestCase { // Remove custom size. unset( $this->wp_site_icon->site_icon_sizes[ array_search( 321, $this->wp_site_icon->site_icon_sizes, true ) ] ); - // Remove the filter we added + // Remove the filter we added. remove_filter( 'site_icon_image_sizes', array( $this, '_custom_test_sizes' ) ); } diff --git a/tests/phpunit/tests/image/size.php b/tests/phpunit/tests/image/size.php index f7e4b992f5..0466cd066f 100644 --- a/tests/phpunit/tests/image/size.php +++ b/tests/phpunit/tests/image/size.php @@ -8,7 +8,7 @@ class Tests_Image_Size extends WP_UnitTestCase { function test_constrain_dims_zero() { - // no constraint - should have no effect + // No constraint - should have no effect. $out = wp_constrain_dimensions( 640, 480, 0, 0 ); $this->assertSame( array( 640, 480 ), $out ); @@ -23,7 +23,7 @@ class Tests_Image_Size extends WP_UnitTestCase { } function test_constrain_dims_smaller() { - // image size is smaller than the constraint - no effect + // Image size is smaller than the constraint - no effect. $out = wp_constrain_dimensions( 500, 600, 1024, 768 ); $this->assertSame( array( 500, 600 ), $out ); @@ -35,7 +35,7 @@ class Tests_Image_Size extends WP_UnitTestCase { } function test_constrain_dims_equal() { - // image size is equal to the constraint - no effect + // Image size is equal to the constraint - no effect. $out = wp_constrain_dimensions( 1024, 768, 1024, 768 ); $this->assertSame( array( 1024, 768 ), $out ); @@ -47,7 +47,7 @@ class Tests_Image_Size extends WP_UnitTestCase { } function test_constrain_dims_larger() { - // image size is larger than the constraint - result should be constrained + // Image size is larger than the constraint - result should be constrained. $out = wp_constrain_dimensions( 1024, 768, 500, 600 ); $this->assertSame( array( 500, 375 ), $out ); @@ -57,7 +57,7 @@ class Tests_Image_Size extends WP_UnitTestCase { $out = wp_constrain_dimensions( 1024, 768, 500, 0 ); $this->assertSame( array( 500, 375 ), $out ); - // also try a portrait oriented image + // Also try a portrait oriented image. $out = wp_constrain_dimensions( 300, 800, 500, 600 ); $this->assertSame( array( 225, 600 ), $out ); @@ -69,14 +69,14 @@ class Tests_Image_Size extends WP_UnitTestCase { } function test_constrain_dims_boundary() { - // one dimension is larger than the constraint, one smaller - result should be constrained + // One dimension is larger than the constraint, one smaller - result should be constrained. $out = wp_constrain_dimensions( 1024, 768, 500, 800 ); $this->assertSame( array( 500, 375 ), $out ); $out = wp_constrain_dimensions( 1024, 768, 2000, 700 ); $this->assertSame( array( 933, 700 ), $out ); - // portrait + // Portrait. $out = wp_constrain_dimensions( 768, 1024, 800, 500 ); $this->assertSame( array( 375, 500 ), $out ); @@ -99,7 +99,7 @@ class Tests_Image_Size extends WP_UnitTestCase { * @expectedDeprecated wp_shrink_dimensions */ function test_shrink_dimensions_smaller() { - // image size is smaller than the constraint - no effect + // Image size is smaller than the constraint - no effect. $out = wp_shrink_dimensions( 500, 600, 1024, 768 ); $this->assertSame( array( 500, 600 ), $out ); @@ -111,7 +111,7 @@ class Tests_Image_Size extends WP_UnitTestCase { * @expectedDeprecated wp_shrink_dimensions */ function test_shrink_dimensions_equal() { - // image size is equal to the constraint - no effect + // Image size is equal to the constraint - no effect. $out = wp_shrink_dimensions( 500, 600, 500, 600 ); $this->assertSame( array( 500, 600 ), $out ); @@ -123,7 +123,7 @@ class Tests_Image_Size extends WP_UnitTestCase { * @expectedDeprecated wp_shrink_dimensions */ function test_shrink_dimensions_larger() { - // image size is larger than the constraint - result should be constrained + // Image size is larger than the constraint - result should be constrained. $out = wp_shrink_dimensions( 1024, 768, 500, 600 ); $this->assertSame( array( 500, 375 ), $out ); @@ -135,14 +135,14 @@ class Tests_Image_Size extends WP_UnitTestCase { * @expectedDeprecated wp_shrink_dimensions */ function test_shrink_dimensions_boundary() { - // one dimension is larger than the constraint, one smaller - result should be constrained + // One dimension is larger than the constraint, one smaller - result should be constrained. $out = wp_shrink_dimensions( 1024, 768, 500, 800 ); $this->assertSame( array( 500, 375 ), $out ); $out = wp_shrink_dimensions( 1024, 768, 2000, 700 ); $this->assertSame( array( 933, 700 ), $out ); - // portrait + // Portrait. $out = wp_shrink_dimensions( 768, 1024, 800, 500 ); $this->assertSame( array( 375, 500 ), $out ); @@ -159,7 +159,7 @@ class Tests_Image_Size extends WP_UnitTestCase { } function test_constrain_size_for_editor_medium() { - // default max width is 500, no constraint on height + // Default max width is 500, no constraint on height. global $content_width; $_content_width = $content_width; @@ -177,7 +177,7 @@ class Tests_Image_Size extends WP_UnitTestCase { $out = image_constrain_size_for_editor( 64, 64, 'medium' ); $this->assertSame( array( 64, 64 ), $out ); - // content_width should be ignored + // $content_width should be ignored. $content_width = 350; $out = image_constrain_size_for_editor( 600, 400, 'medium' ); $this->assertSame( array( 500, 333 ), $out ); @@ -197,7 +197,7 @@ class Tests_Image_Size extends WP_UnitTestCase { $out = image_constrain_size_for_editor( 64, 64, 'full' ); $this->assertSame( array( 64, 64 ), $out ); - // content_width default is 500 + // $content_width default is 500. $content_width = 0; $out = image_constrain_size_for_editor( 600, 400, 'full' ); diff --git a/tests/phpunit/tests/import/base.php b/tests/phpunit/tests/import/base.php index 5897ce55fb..7d52aee69b 100644 --- a/tests/phpunit/tests/import/base.php +++ b/tests/phpunit/tests/import/base.php @@ -11,9 +11,9 @@ abstract class WP_Import_UnitTestCase extends WP_UnitTestCase { * * * $users = array( - * 'alice' => 1, // alice will be mapped to user ID 1 - * 'bob' => 'john', // bob will be transformed into john - * 'eve' => false // eve will be imported as is + * 'alice' => 1, // alice will be mapped to user ID 1. + * 'bob' => 'john', // bob will be transformed into john. + * 'eve' => false // eve will be imported as is. * ); * * @param string $filename Full path of the file to import @@ -32,8 +32,8 @@ abstract class WP_Import_UnitTestCase extends WP_UnitTestCase { $new = array(); $i = 0; - // each user is either mapped to a given ID, mapped to a new user - // with given login or imported using details in WXR file + // Each user is either mapped to a given ID, mapped to a new user + // with given login or imported using details in WXR file. foreach ( $users as $user => $map ) { $authors[ $i ] = $user; if ( is_int( $map ) ) { diff --git a/tests/phpunit/tests/import/import.php b/tests/phpunit/tests/import/import.php index e005826a18..8e28558d47 100644 --- a/tests/phpunit/tests/import/import.php +++ b/tests/phpunit/tests/import/import.php @@ -26,7 +26,7 @@ class Tests_Import_Import extends WP_Import_UnitTestCase { require_once DIR_TESTDATA . '/plugins/wordpress-importer/wordpress-importer.php'; global $wpdb; - // crude but effective: make sure there's no residual data in the main tables + // Crude but effective: make sure there's no residual data in the main tables. foreach ( array( 'posts', 'postmeta', 'comments', 'terms', 'term_taxonomy', 'term_relationships', 'users', 'usermeta' ) as $table ) { // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $wpdb->query( "DELETE FROM {$wpdb->$table}" ); @@ -49,7 +49,7 @@ class Tests_Import_Import extends WP_Import_UnitTestCase { ); $this->_import_wp( DIR_TESTDATA . '/export/small-export.xml', $authors ); - // ensure that authors were imported correctly + // Ensure that authors were imported correctly. $user_count = count_users(); $this->assertEquals( 3, $user_count['total_users'] ); $admin = get_user_by( 'login', 'admin' ); @@ -64,7 +64,7 @@ class Tests_Import_Import extends WP_Import_UnitTestCase { $this->assertEquals( 'author', $author->user_login ); $this->assertEquals( 'author@example.org', $author->user_email ); - // check that terms were imported correctly + // Check that terms were imported correctly. $this->assertEquals( 30, wp_count_terms( 'category' ) ); $this->assertEquals( 3, wp_count_terms( 'post_tag' ) ); $foo = get_term_by( 'slug', 'foo', 'category' ); @@ -73,7 +73,7 @@ class Tests_Import_Import extends WP_Import_UnitTestCase { $foo_bar = get_term_by( 'slug', 'foo-bar', 'category' ); $this->assertEquals( $bar->term_id, $foo_bar->parent ); - // check that posts/pages were imported correctly + // Check that posts/pages were imported correctly. $post_count = wp_count_posts( 'post' ); $this->assertEquals( 5, $post_count->publish ); $this->assertEquals( 1, $post_count->private ); @@ -250,7 +250,7 @@ class Tests_Import_Import extends WP_Import_UnitTestCase { function test_ordering_of_importers() { global $wp_importers; - $_wp_importers = $wp_importers; // Preserve global state + $_wp_importers = $wp_importers; // Preserve global state. $wp_importers = array( 'xyz1' => array( 'xyz1' ), 'XYZ2' => array( 'XYZ2' ), @@ -268,7 +268,7 @@ class Tests_Import_Import extends WP_Import_UnitTestCase { ), get_importers() ); - $wp_importers = $_wp_importers; // Restore global state + $wp_importers = $_wp_importers; // Restore global state. } /** @@ -294,6 +294,4 @@ class Tests_Import_Import extends WP_Import_UnitTestCase { ); $this->assertSame( 'Slashes aren\\\'t \"cool\"', $posts[0]->post_content ); } - - // function test_menu_import } diff --git a/tests/phpunit/tests/import/parser.php b/tests/phpunit/tests/import/parser.php index 8b198f31e4..c02c3f8817 100644 --- a/tests/phpunit/tests/import/parser.php +++ b/tests/phpunit/tests/import/parser.php @@ -27,7 +27,7 @@ class Tests_Import_Parser extends WP_Import_UnitTestCase { function test_malformed_wxr() { $file = DIR_TESTDATA . '/export/malformed.xml'; - // regex based parser cannot detect malformed XML + // Regex based parser cannot detect malformed XML. foreach ( array( 'WXR_Parser_SimpleXML', 'WXR_Parser_XML' ) as $p ) { $parser = new $p; $result = $parser->parse( $file ); @@ -296,5 +296,5 @@ class Tests_Import_Parser extends WP_Import_UnitTestCase { } } - // tags in CDATA #11574 + // Tags in CDATA #11574. } diff --git a/tests/phpunit/tests/import/postmeta.php b/tests/phpunit/tests/import/postmeta.php index dcae22d0bd..83eaa5dea6 100644 --- a/tests/phpunit/tests/import/postmeta.php +++ b/tests/phpunit/tests/import/postmeta.php @@ -83,9 +83,9 @@ class Tests_Import_Postmeta extends WP_Import_UnitTestCase { function test_serialized_postmeta_with_cdata() { $this->_import_wp( DIR_TESTDATA . '/export/test-serialized-postmeta-with-cdata.xml', array( 'johncoswell' => 'johncoswell' ) ); - //HTML in the CDATA should work with old WordPress version + // HTML in the CDATA should work with old WordPress version. $this->assertEquals( '
    some html
    ', get_post_meta( 10, 'contains-html', true ) ); - //Serialised will only work with 3.0 onwards. + // Serialised will only work with 3.0 onwards. $expected['special_post_title'] = 'A special title'; $expected['is_calendar'] = ''; $this->assertEquals( $expected, get_post_meta( 10, 'post-options', true ) ); @@ -96,7 +96,7 @@ class Tests_Import_Postmeta extends WP_Import_UnitTestCase { */ function test_serialized_postmeta_with_evil_stuff_in_cdata() { $this->_import_wp( DIR_TESTDATA . '/export/test-serialized-postmeta-with-cdata.xml', array( 'johncoswell' => 'johncoswell' ) ); - // evil content in the CDATA + // Evil content in the CDATA. $this->assertEquals( 'evil', get_post_meta( 10, 'evil', true ) ); } } diff --git a/tests/phpunit/tests/includes/helpers.php b/tests/phpunit/tests/includes/helpers.php index d96207606b..c17a7006ae 100644 --- a/tests/phpunit/tests/includes/helpers.php +++ b/tests/phpunit/tests/includes/helpers.php @@ -10,9 +10,9 @@ class Tests_TestHelpers extends WP_UnitTestCase { function data_assertEqualSets() { return array( array( - array( 1, 2, 3 ), // test expected - array( 1, 2, 3 ), // test actual - false, // exception expected + array( 1, 2, 3 ), // Test expected. + array( 1, 2, 3 ), // Test actual. + false, // Exception expected. ), array( array( 1, 2, 3 ), @@ -71,9 +71,9 @@ class Tests_TestHelpers extends WP_UnitTestCase { function data_assertEqualSetsWithIndex() { return array( array( - array( 1, 2, 3 ), // test expected - array( 1, 2, 3 ), // test actual - false, // exception expected + array( 1, 2, 3 ), // Test expected. + array( 1, 2, 3 ), // Test actual. + false, // Exception expected. ), array( array( diff --git a/tests/phpunit/tests/kses.php b/tests/phpunit/tests/kses.php index 17a5b95c78..a74903bd80 100644 --- a/tests/phpunit/tests/kses.php +++ b/tests/phpunit/tests/kses.php @@ -1034,7 +1034,7 @@ EOF; */ function data_wildcard_attribute_prefixes() { return array( - // Ends correctly + // Ends correctly. array( 'data-*', true ), // Does not end with trialing `-`. diff --git a/tests/phpunit/tests/link.php b/tests/phpunit/tests/link.php index 33fe4fce67..263da2fe50 100644 --- a/tests/phpunit/tests/link.php +++ b/tests/phpunit/tests/link.php @@ -30,29 +30,29 @@ class Tests_Link extends WP_UnitTestCase { $post_id = self::factory()->post->create(); $post_id2 = self::factory()->post->create(); - // Basic case + // Basic case. $this->assertEquals( get_permalink( $post_id ), wp_get_shortlink( $post_id, 'post' ) ); unset( $GLOBALS['post'] ); - // Global post is not set + // Global post is not set. $this->assertEquals( '', wp_get_shortlink( 0, 'post' ) ); $this->assertEquals( '', wp_get_shortlink( 0 ) ); $this->assertEquals( '', wp_get_shortlink() ); $GLOBALS['post'] = get_post( $post_id ); - // Global post is set + // Global post is set. $this->assertEquals( get_permalink( $post_id ), wp_get_shortlink( 0, 'post' ) ); $this->assertEquals( get_permalink( $post_id ), wp_get_shortlink( 0 ) ); $this->assertEquals( get_permalink( $post_id ), wp_get_shortlink() ); - // Not the global post + // Not the global post. $this->assertEquals( get_permalink( $post_id2 ), wp_get_shortlink( $post_id2, 'post' ) ); unset( $GLOBALS['post'] ); - // Global post is not set, once again + // Global post is not set, once again. $this->assertEquals( '', wp_get_shortlink( 0, 'post' ) ); $this->assertEquals( '', wp_get_shortlink( 0 ) ); $this->assertEquals( '', wp_get_shortlink() ); @@ -63,7 +63,7 @@ class Tests_Link extends WP_UnitTestCase { $this->assertNotEquals( get_permalink( $post_id ), wp_get_shortlink( $post_id, 'post' ) ); $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) ); - // Global post and permalink structure are set + // Global post and permalink structure are set. $GLOBALS['post'] = get_post( $post_id ); $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( 0, 'post' ) ); $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( 0 ) ); @@ -73,7 +73,7 @@ class Tests_Link extends WP_UnitTestCase { function test_wp_get_shortlink_with_page() { $post_id = self::factory()->post->create( array( 'post_type' => 'page' ) ); - // Basic case + // Basic case. // Don't test against get_permalink() since it uses ?page_id= for pages. $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) ); diff --git a/tests/phpunit/tests/link/getAdjacentPost.php b/tests/phpunit/tests/link/getAdjacentPost.php index 649d1547f4..97dbba38b9 100644 --- a/tests/phpunit/tests/link/getAdjacentPost.php +++ b/tests/phpunit/tests/link/getAdjacentPost.php @@ -10,7 +10,7 @@ class Tests_Link_GetAdjacentPost extends WP_UnitTestCase { * @ticket 17807 */ public function test_get_adjacent_post() { - // Need some sample posts to test adjacency + // Need some sample posts to test adjacency. $post_one = self::factory()->post->create_and_get( array( 'post_title' => 'First', @@ -39,14 +39,14 @@ class Tests_Link_GetAdjacentPost extends WP_UnitTestCase { ) ); - // Assign some terms + // Assign some terms. wp_set_object_terms( $post_one->ID, 'WordPress', 'category', false ); wp_set_object_terms( $post_three->ID, 'WordPress', 'category', false ); wp_set_object_terms( $post_two->ID, 'plugins', 'post_tag', false ); wp_set_object_terms( $post_four->ID, 'plugins', 'post_tag', false ); - // Test normal post adjacency + // Test normal post adjacency. $this->go_to( get_permalink( $post_two->ID ) ); $this->assertEquals( $post_one, get_adjacent_post( false, '', true ) ); @@ -55,31 +55,31 @@ class Tests_Link_GetAdjacentPost extends WP_UnitTestCase { $this->assertNotEquals( $post_two, get_adjacent_post( false, '', true ) ); $this->assertNotEquals( $post_two, get_adjacent_post( false, '', false ) ); - // Test category adjacency + // Test category adjacency. $this->go_to( get_permalink( $post_one->ID ) ); $this->assertEquals( '', get_adjacent_post( true, '', true, 'category' ) ); $this->assertEquals( $post_three, get_adjacent_post( true, '', false, 'category' ) ); - // Test tag adjacency + // Test tag adjacency. $this->go_to( get_permalink( $post_two->ID ) ); $this->assertEquals( '', get_adjacent_post( true, '', true, 'post_tag' ) ); $this->assertEquals( $post_four, get_adjacent_post( true, '', false, 'post_tag' ) ); - // Test normal boundary post + // Test normal boundary post. $this->go_to( get_permalink( $post_two->ID ) ); $this->assertEquals( array( $post_one ), get_boundary_post( false, '', true ) ); $this->assertEquals( array( $post_four ), get_boundary_post( false, '', false ) ); - // Test category boundary post + // Test category boundary post. $this->go_to( get_permalink( $post_one->ID ) ); $this->assertEquals( array( $post_one ), get_boundary_post( true, '', true, 'category' ) ); $this->assertEquals( array( $post_three ), get_boundary_post( true, '', false, 'category' ) ); - // Test tag boundary post + // Test tag boundary post. $this->go_to( get_permalink( $post_two->ID ) ); $this->assertEquals( array( $post_two ), get_boundary_post( true, '', true, 'post_tag' ) ); @@ -144,7 +144,7 @@ class Tests_Link_GetAdjacentPost extends WP_UnitTestCase { ) ); - // First post + // First post. $this->go_to( get_permalink( $one ) ); $this->assertEquals( $two, get_adjacent_post( false, array(), false ) ); $this->assertEquals( $three, get_adjacent_post( true, array(), false ) ); @@ -152,7 +152,7 @@ class Tests_Link_GetAdjacentPost extends WP_UnitTestCase { $this->assertEquals( $four, get_adjacent_post( true, array( $exclude ), false ) ); $this->assertEmpty( get_adjacent_post( false, array(), true ) ); - // Fourth post + // Fourth post. $this->go_to( get_permalink( $four ) ); $this->assertEquals( $five, get_adjacent_post( false, array(), false ) ); $this->assertEquals( $five, get_adjacent_post( true, array(), false ) ); @@ -164,7 +164,7 @@ class Tests_Link_GetAdjacentPost extends WP_UnitTestCase { $this->assertEquals( $two, get_adjacent_post( false, array( $exclude ), true ) ); $this->assertEmpty( get_adjacent_post( true, array( $exclude ), true ) ); - // Last post + // Last post. $this->go_to( get_permalink( $five ) ); $this->assertEquals( $four, get_adjacent_post( false, array(), true ) ); $this->assertEquals( $four, get_adjacent_post( true, array(), true ) ); diff --git a/tests/phpunit/tests/link/getAdjacentPostLink.php b/tests/phpunit/tests/link/getAdjacentPostLink.php index acaec3973b..6f5d5168aa 100644 --- a/tests/phpunit/tests/link/getAdjacentPostLink.php +++ b/tests/phpunit/tests/link/getAdjacentPostLink.php @@ -48,7 +48,7 @@ class Tests_Link_GetAdjacentPostLink extends WP_UnitTestCase { ) ); - //set current post (has 2 on each end) + // Set current post (has 2 on each end). global $GLOBALS; $GLOBALS['post'] = get_post( $this->post_ids[2] ); } diff --git a/tests/phpunit/tests/mail.php b/tests/phpunit/tests/mail.php index 39c6036d2c..e2db915265 100644 --- a/tests/phpunit/tests/mail.php +++ b/tests/phpunit/tests/mail.php @@ -101,10 +101,10 @@ class Tests_Mail extends WP_UnitTestCase { wp_mail( $to, $subject, $message, $headers ); - // WordPress 3.2 and later correctly split the address into the two parts and send them seperately to PHPMailer + // WordPress 3.2 and later correctly split the address into the two parts and send them separately to PHPMailer. // Earlier versions of PHPMailer were not touchy about the formatting of these arguments. - //retrieve the mailer instance + // Retrieve the mailer instance. $mailer = tests_retrieve_phpmailer_instance(); $this->assertEquals( 'address@tld.com', $mailer->get_recipient( 'to' )->address ); $this->assertEquals( 'Name', $mailer->get_recipient( 'to' )->name ); @@ -125,7 +125,7 @@ class Tests_Mail extends WP_UnitTestCase { wp_mail( $to, $subject, $message ); - // WordPress 3.2 and later correctly split the address into the two parts and send them seperately to PHPMailer + // WordPress 3.2 and later correctly split the address into the two parts and send them separately to PHPMailer. // Earlier versions of PHPMailer were not touchy about the formatting of these arguments. $mailer = tests_retrieve_phpmailer_instance(); $this->assertEquals( 'address@tld.com', $mailer->get_recipient( 'to' )->address ); @@ -167,13 +167,13 @@ class Tests_Mail extends WP_UnitTestCase { * @ticket 23642 */ function test_wp_mail_return_value() { - // No errors + // No errors. $this->assertTrue( wp_mail( 'valid@address.com', 'subject', 'body' ) ); - // Non-fatal errors + // Non-fatal errors. $this->assertTrue( wp_mail( 'valid@address.com', 'subject', 'body', "Cc: invalid-address\nBcc: @invalid.address", ABSPATH . '/non-existant-file.html' ) ); - // Fatal errors + // Fatal errors. $this->assertFalse( wp_mail( 'invalid.address', 'subject', 'body', '', array() ) ); } @@ -400,7 +400,7 @@ class Tests_Mail extends WP_UnitTestCase { 'phpmailer_exception_code' => 2, ); - //Retrieve the arguments passed to the 'wp_mail_failed' hook callbacks + // Retrieve the arguments passed to the 'wp_mail_failed' hook callbacks. $all_args = $ma->get_args(); $call_args = array_pop( $all_args ); diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index 9b99cf9106..e9dbd27db5 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -272,7 +272,7 @@ EOF; function data_autoembed() { return array( - // Should embed + // Should embed. array( 'https://w.org', '[embed]', @@ -308,7 +308,7 @@ test

    ',

    ', ), - // Should NOT embed + // Should NOT embed. array( 'test https://w.org

    ', ), @@ -336,7 +336,7 @@ https://w.org', } function test_wp_prepare_attachment_for_js() { - // Attachment without media + // Attachment without media. $id = wp_insert_attachment( array( 'post_status' => 'publish', @@ -353,18 +353,18 @@ https://w.org', $this->assertEquals( '', $prepped['mime'] ); $this->assertEquals( '', $prepped['type'] ); $this->assertEquals( '', $prepped['subtype'] ); - // #21963, there will be a guid always, so there will be a URL + // #21963, there will be a GUID always, so there will be a URL. $this->assertNotEquals( '', $prepped['url'] ); $this->assertEquals( site_url( 'wp-includes/images/media/default.png' ), $prepped['icon'] ); - // Fake a mime + // Fake a mime. $post->post_mime_type = 'image/jpeg'; $prepped = wp_prepare_attachment_for_js( $post ); $this->assertEquals( 'image/jpeg', $prepped['mime'] ); $this->assertEquals( 'image', $prepped['type'] ); $this->assertEquals( 'jpeg', $prepped['subtype'] ); - // Fake a mime without a slash. See #WP22532 + // Fake a mime without a slash. See #WP22532. $post->post_mime_type = 'image'; $prepped = wp_prepare_attachment_for_js( $post ); $this->assertEquals( 'image', $prepped['mime'] ); @@ -426,7 +426,7 @@ https://w.org', $gb = $mb * 1024; $tb = $gb * 1024; - // test if boundaries are correct + // Test if boundaries are correct. $this->assertEquals( '1TB', wp_convert_bytes_to_hr( $tb ) ); $this->assertEquals( '1GB', wp_convert_bytes_to_hr( $gb ) ); $this->assertEquals( '1MB', wp_convert_bytes_to_hr( $mb ) ); @@ -437,7 +437,7 @@ https://w.org', $this->assertEquals( '1 MB', size_format( $mb ) ); $this->assertEquals( '1 KB', size_format( $kb ) ); - // now some values around + // Now some values around. $hr = wp_convert_bytes_to_hr( $tb + $tb / 2 + $mb ); $this->assertEquals( 1.50000095367, (float) str_replace( ',', '.', $hr ), 'The values should be equal', 0.0001 ); @@ -450,7 +450,7 @@ https://w.org', $hr = wp_convert_bytes_to_hr( $gb - $mb - $kb ); $this->assertEquals( 1022.99902344, (float) str_replace( ',', '.', $hr ), 'The values should be equal', 0.0001 ); - // edge + // Edge. $this->assertEquals( '-1B', wp_convert_bytes_to_hr( -1 ) ); $this->assertEquals( '0B', wp_convert_bytes_to_hr( 0 ) ); } @@ -612,11 +612,11 @@ BLOB; $galleries = get_post_galleries( $post_id_two, false ); - // Set the global $post context + // Set the global $post context. $GLOBALS['post'] = get_post( $post_id_two ); $galleries_with_global_context = get_post_galleries( $post_id_two, false ); - // Check that the global post state doesn't affect the results + // Check that the global post state doesn't affect the results. $this->assertSame( $galleries, $galleries_with_global_context ); $this->assertNotEmpty( $galleries[0]['src'] ); @@ -1011,7 +1011,7 @@ VIDEO; $sizes = wp_get_additional_image_sizes(); - // Clean up + // Clean up. remove_image_size( 'test-size' ); $this->assertArrayHasKey( 'test-size', $sizes ); @@ -1036,7 +1036,7 @@ VIDEO; add_image_size( 'test-size', 200, 600 ); $this->assertTrue( has_image_size( 'test-size' ) ); - // Clean up + // Clean up. remove_image_size( 'test-size' ); } @@ -1141,7 +1141,7 @@ VIDEO; public function test_media_handle_upload_sets_post_excerpt() { $iptc_file = DIR_TESTDATA . '/images/test-image-iptc.jpg'; - // Make a copy of this file as it gets moved during the file upload + // Make a copy of this file as it gets moved during the file upload. $tmp_name = wp_tempnam( $iptc_file ); copy( $iptc_file, $tmp_name ); @@ -1180,7 +1180,7 @@ VIDEO; public function test_media_handle_upload_expected_titles() { $test_file = DIR_TESTDATA . '/images/test-image.jpg'; - // Make a copy of this file as it gets moved during the file upload + // Make a copy of this file as it gets moved during the file upload. $tmp_name = wp_tempnam( $test_file ); copy( $test_file, $tmp_name ); @@ -1496,7 +1496,7 @@ EOF; function test_wp_calculate_image_srcset_no_date_uploads() { $_wp_additional_image_sizes = wp_get_additional_image_sizes(); - // Disable date organized uploads + // Disable date organized uploads. add_filter( 'upload_dir', '_upload_dir_no_subdir' ); // Make an image. @@ -1534,7 +1534,7 @@ EOF; $this->assertSame( $expected_srcset, wp_calculate_image_srcset( $size_array, $image_url, $image_meta ) ); } - // Remove the attachment + // Remove the attachment. wp_delete_attachment( $id ); remove_filter( 'upload_dir', '_upload_dir_no_subdir' ); } @@ -1554,7 +1554,7 @@ EOF; $filename_base = wp_basename( $image_meta['file'], '.png' ); - // Add the hash to the image URL + // Add the hash to the image URL. $image_url = str_replace( $filename_base, $filename_base . '-' . $hash, $image_url ); // Replace file paths for full and medium sizes with hashed versions. @@ -1604,7 +1604,7 @@ EOF; // Add the full size width at the end. $expected .= $uploads_dir_url . $image_meta['file'] . ' ' . $image_meta['width'] . 'w'; - // Prepend an absolute path to simulate a pre-2.7 upload + // Prepend an absolute path to simulate a pre-2.7 upload. $image_meta['file'] = 'H:\home\wordpress\trunk/wp-content/uploads/' . $image_meta['file']; foreach ( $intermediates as $int ) { @@ -1621,7 +1621,7 @@ EOF; function test_wp_calculate_image_srcset_false() { $sizes = wp_calculate_image_srcset( array( 400, 300 ), 'file.png', array() ); - // For canola.jpg we should return + // For canola.jpg we should return. $this->assertFalse( $sizes ); } @@ -1776,7 +1776,7 @@ EOF; 1600 => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test.png 1600w', ); - // No sizes array + // No sizes array. $image_meta1 = $image_meta; unset( $image_meta1['sizes'] ); $this->assertFalse( wp_calculate_image_srcset( $size_array, $image_src, $image_meta1 ) ); @@ -1786,12 +1786,12 @@ EOF; $image_meta2['sizes'] = ''; $this->assertFalse( wp_calculate_image_srcset( $size_array, $image_src, $image_meta2 ) ); - // File name is incorrect + // File name is incorrect. $image_meta3 = $image_meta; $image_meta3['file'] = '/'; $this->assertFalse( wp_calculate_image_srcset( $size_array, $image_src, $image_meta3 ) ); - // File name is incorrect + // File name is incorrect. $image_meta4 = $image_meta; unset( $image_meta4['file'] ); $this->assertFalse( wp_calculate_image_srcset( $size_array, $image_src, $image_meta4 ) ); @@ -1855,7 +1855,7 @@ EOF; $_wp_additional_image_sizes = wp_get_additional_image_sizes(); $image_meta = wp_get_attachment_metadata( self::$large_id ); - $size_array = array( 1600, 1200 ); // full size + $size_array = array( 1600, 1200 ); // Full size. $srcset = wp_get_attachment_image_srcset( self::$large_id, $size_array, $image_meta ); @@ -1981,7 +1981,7 @@ EOF; $img_xhtml = str_replace( ' />', '/>', $img ); $img_html5 = str_replace( ' />', '>', $img ); - // Manually add srcset and sizes to the markup from get_image_tag(); + // Manually add srcset and sizes to the markup from get_image_tag(). $respimg = preg_replace( '|]+) />|', '', $img ); $respimg_no_size_in_class = preg_replace( '|]+) />|', '', $img_no_size_in_class ); $respimg_no_width_height = preg_replace( '|]+) />|', '', $img_no_width_height ); @@ -2031,7 +2031,7 @@ EOF; function test_wp_make_content_images_responsive_wrong() { $image = get_image_tag( self::$large_id, '', '', '', 'medium' ); - // Replace the src URL + // Replace the src URL. $image_wrong_src = preg_replace( '|src="[^"]+"|', 'src="http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/foo.jpg"', $image ); $this->assertSame( $image_wrong_src, wp_make_content_images_responsive( $image_wrong_src ) ); @@ -2432,7 +2432,7 @@ EOF; public function test_media_handle_upload_uses_post_parent_for_directory_date() { $iptc_file = DIR_TESTDATA . '/images/test-image-iptc.jpg'; - // Make a copy of this file as it gets moved during the file upload + // Make a copy of this file as it gets moved during the file upload. $tmp_name = wp_tempnam( $iptc_file ); copy( $iptc_file, $tmp_name ); @@ -2478,7 +2478,7 @@ EOF; public function test_media_handle_upload_ignores_page_parent_for_directory_date() { $iptc_file = DIR_TESTDATA . '/images/test-image-iptc.jpg'; - // Make a copy of this file as it gets moved during the file upload + // Make a copy of this file as it gets moved during the file upload. $tmp_name = wp_tempnam( $iptc_file ); copy( $iptc_file, $tmp_name ); diff --git a/tests/phpunit/tests/meta.php b/tests/phpunit/tests/meta.php index c2cc6663b9..30c154b982 100644 --- a/tests/phpunit/tests/meta.php +++ b/tests/phpunit/tests/meta.php @@ -27,46 +27,46 @@ class Tests_Meta extends WP_UnitTestCase { } function test_delete_metadata_by_mid() { - // Let's try and delete a non-existing ID, non existing meta + // Let's try and delete a non-existing ID, non existing meta. $this->assertFalse( delete_metadata_by_mid( 'user', 0 ) ); $this->assertFalse( delete_metadata_by_mid( 'non_existing_meta', $this->delete_meta_id ) ); - // Now let's delete the real meta data + // Now let's delete the real meta data. $this->assertTrue( delete_metadata_by_mid( 'user', $this->delete_meta_id ) ); - // And make sure it's been deleted + // And make sure it's been deleted. $this->assertFalse( get_metadata_by_mid( 'user', $this->delete_meta_id ) ); - // Make sure the caches are cleared + // Make sure the caches are cleared. $this->assertFalse( (bool) get_user_meta( $this->author->ID, 'delete_meta_key' ) ); } function test_update_metadata_by_mid() { - // Setup + // Setup. $meta = get_metadata_by_mid( 'user', $this->meta_id ); - // Update the meta value + // Update the meta value. $this->assertTrue( update_metadata_by_mid( 'user', $this->meta_id, 'meta_new_value' ) ); $meta = get_metadata_by_mid( 'user', $this->meta_id ); $this->assertEquals( 'meta_new_value', $meta->meta_value ); - // Update the meta value + // Update the meta value. $this->assertTrue( update_metadata_by_mid( 'user', $this->meta_id, 'meta_new_value', 'meta_new_key' ) ); $meta = get_metadata_by_mid( 'user', $this->meta_id ); $this->assertEquals( 'meta_new_key', $meta->meta_key ); - // Update the key and value + // Update the key and value. $this->assertTrue( update_metadata_by_mid( 'user', $this->meta_id, 'meta_value', 'meta_key' ) ); $meta = get_metadata_by_mid( 'user', $this->meta_id ); $this->assertEquals( 'meta_key', $meta->meta_key ); $this->assertEquals( 'meta_value', $meta->meta_value ); - // Update the value that has to be serialized + // Update the value that has to be serialized. $this->assertTrue( update_metadata_by_mid( 'user', $this->meta_id, array( 'first', 'second' ) ) ); $meta = get_metadata_by_mid( 'user', $this->meta_id ); $this->assertEquals( array( 'first', 'second' ), $meta->meta_value ); - // Let's try some invalid meta data + // Let's try some invalid meta data. $this->assertFalse( update_metadata_by_mid( 'user', 0, 'meta_value' ) ); $this->assertFalse( update_metadata_by_mid( 'user', $this->meta_id, 'meta_value', array( 'invalid', 'key' ) ) ); @@ -117,7 +117,7 @@ class Tests_Meta extends WP_UnitTestCase { function test_metadata_exists_with_filter() { // Let's see if it returns the correct value when adding a filter. add_filter( 'get_user_metadata', '__return_zero' ); - $this->assertFalse( metadata_exists( 'user', $this->author->ID, 'meta_key' ) ); // existing meta key + $this->assertFalse( metadata_exists( 'user', $this->author->ID, 'meta_key' ) ); // Existing meta key. $this->assertFalse( metadata_exists( 'user', 1234567890, 'meta_key' ) ); remove_filter( 'get_user_metadata', '__return_zero' ); } @@ -139,10 +139,10 @@ class Tests_Meta extends WP_UnitTestCase { $this->assertEquals( 1, count( $u ) ); - // User found is not locally defined author (it's the admin) + // User found is not locally defined author (it's the admin). $this->assertNotEquals( $this->author->user_login, $u[0]->user_login ); - // Test EXISTS and NOT EXISTS together, no users should be found + // Test EXISTS and NOT EXISTS together, no users should be found. $this->assertEquals( 0, count( @@ -219,7 +219,7 @@ class Tests_Meta extends WP_UnitTestCase { $this->assertSame( '', get_metadata( 'user', $this->author->ID, $key, true ) ); $this->assertFalse( metadata_exists( 'user', $this->author->ID, $key ) ); - // Test overslashing + // Test overslashing. $this->assertInternalType( 'int', add_metadata( 'user', $this->author->ID, $key, $value2 ) ); $this->assertEquals( $expected2, get_metadata( 'user', $this->author->ID, $key, true ) ); $this->assertTrue( delete_metadata( 'user', $this->author->ID, $key ) ); @@ -255,7 +255,7 @@ class Tests_Meta extends WP_UnitTestCase { $this->assertEquals( array( $post_id2, $post_id1 ), $posts->posts ); $this->assertEquals( 2, substr_count( $posts->request, 'CAST(' ) ); - // Make sure the newer meta_query syntax behaves in a consistent way + // Make sure the newer meta_query syntax behaves in a consistent way. $posts = new WP_Query( array( 'fields' => 'ids', diff --git a/tests/phpunit/tests/meta/query.php b/tests/phpunit/tests/meta/query.php index 4a22821ca9..417c59646f 100644 --- a/tests/phpunit/tests/meta/query.php +++ b/tests/phpunit/tests/meta/query.php @@ -45,8 +45,8 @@ class Tests_Meta_Query extends WP_UnitTestCase { public function test_invalid_query_clauses() { $query = new WP_Meta_Query( array( - 'foo', // empty string - 5, // int + 'foo', // Empty string. + 5, // int false, // bool array(), ) @@ -76,7 +76,7 @@ class Tests_Meta_Query extends WP_UnitTestCase { $this->assertEquals( 1, substr_count( $sql['join'], 'INNER JOIN' ) ); - // also check mixing key and key => value + // Also check mixing key and key => value. $query = new WP_Meta_Query( array( @@ -174,7 +174,7 @@ class Tests_Meta_Query extends WP_UnitTestCase { $query = new WP_Meta_Query(); - // just meta_value + // Just meta_value. $expected = array( 'relation' => 'OR', array( @@ -188,7 +188,7 @@ class Tests_Meta_Query extends WP_UnitTestCase { ); $this->assertEquals( $expected, $query->queries ); - // meta_key & meta_value + // meta_key & meta_value. $expected = array( 'relation' => 'OR', array( @@ -204,7 +204,7 @@ class Tests_Meta_Query extends WP_UnitTestCase { ); $this->assertEquals( $expected, $query->queries ); - // meta_compare + // meta_compare. $expected = array( 'relation' => 'OR', array( @@ -562,30 +562,30 @@ class Tests_Meta_Query extends WP_UnitTestCase { array( 'relation' => 'OR', - // Empty 'compare' + // Empty 'compare'. array( 'key' => 'foo', ), - // Non-empty 'compare' + // Non-empty 'compare'. array( 'key' => 'bar', 'compare' => '<', ), - // NOT EXISTS + // NOT EXISTS. array( 'key' => 'baz', 'compare' => 'NOT EXISTS', ), - // Has a value + // Has a value. array( 'key' => 'barry', 'value' => 'foo', ), - // Has no key + // Has no key. array( 'value' => 'bar', ), @@ -594,24 +594,24 @@ class Tests_Meta_Query extends WP_UnitTestCase { $sql = $query1->get_sql( 'post', $wpdb->posts, 'ID', $this ); - // 'foo' and 'bar' should be queried against the non-aliased table + // 'foo' and 'bar' should be queried against the non-aliased table. $this->assertSame( 1, substr_count( $sql['where'], "$wpdb->postmeta.meta_key = 'foo'" ) ); $this->assertSame( 1, substr_count( $sql['where'], "$wpdb->postmeta.meta_key = 'bar'" ) ); - // NOT EXISTS compare queries are not key-only so should not be non-aliased + // NOT EXISTS compare queries are not key-only so should not be non-aliased. $this->assertSame( 0, substr_count( $sql['where'], "$wpdb->postmeta.meta_key = 'baz'" ) ); - // 'AND' queries don't have key-only queries + // 'AND' queries don't have key-only queries. $query2 = new WP_Meta_Query( array( 'relation' => 'AND', - // Empty 'compare' + // Empty 'compare'. array( 'key' => 'foo', ), - // Non-empty 'compare' + // Non-empty 'compare'. array( 'key' => 'bar', 'compare' => '<', @@ -621,7 +621,7 @@ class Tests_Meta_Query extends WP_UnitTestCase { $sql = $query2->get_sql( 'post', $wpdb->posts, 'ID', $this ); - // Only 'foo' should be queried against the non-aliased table + // Only 'foo' should be queried against the non-aliased table. $this->assertSame( 1, substr_count( $sql['where'], "$wpdb->postmeta.meta_key = 'foo'" ) ); $this->assertSame( 0, substr_count( $sql['where'], "$wpdb->postmeta.meta_key = 'bar'" ) ); } diff --git a/tests/phpunit/tests/meta/slashes.php b/tests/phpunit/tests/meta/slashes.php index 52fcd1a400..d8ec881134 100644 --- a/tests/phpunit/tests/meta/slashes.php +++ b/tests/phpunit/tests/meta/slashes.php @@ -31,7 +31,7 @@ class Tests_Meta_Slashes extends WP_UnitTestCase { } /** - * Tests the controller function that expects slashed data + * Tests the controller function that expects slashed data. */ function test_edit_post() { $id = self::factory()->post->create(); @@ -40,7 +40,7 @@ class Tests_Meta_Slashes extends WP_UnitTestCase { $meta_2 = wp_add_post_meta( $id, 'slash_test_2', 'foo' ); $meta_3 = wp_add_post_meta( $id, 'slash_test_3', 'foo' ); } else { - // expects slashed data + // Expects slashed data. $meta_1 = add_post_meta( $id, 'slash_test_1', addslashes( 'foo' ) ); $meta_2 = add_post_meta( $id, 'slash_test_2', addslashes( 'foo' ) ); $meta_3 = add_post_meta( $id, 'slash_test_3', addslashes( 'foo' ) ); @@ -65,7 +65,8 @@ class Tests_Meta_Slashes extends WP_UnitTestCase { 'value' => $this->slash_4, ), ); - $_POST = add_magic_quotes( $_POST ); // the edit_post() function will strip slashes + + $_POST = add_magic_quotes( $_POST ); // The edit_post() function will strip slashes. edit_post(); $post = get_post( $id ); @@ -94,7 +95,8 @@ class Tests_Meta_Slashes extends WP_UnitTestCase { 'value' => $this->slash_5, ), ); - $_POST = add_magic_quotes( $_POST ); // the edit_post() function will strip slashes + + $_POST = add_magic_quotes( $_POST ); // The edit_post() function will strip slashes. edit_post(); $post = get_post( $id ); @@ -105,7 +107,7 @@ class Tests_Meta_Slashes extends WP_UnitTestCase { } /** - * Tests the legacy model function that expects slashed data + * Tests the legacy model function that expects slashed data. */ function test_add_post_meta() { $id = self::factory()->post->create(); @@ -119,7 +121,7 @@ class Tests_Meta_Slashes extends WP_UnitTestCase { } /** - * Tests the legacy model function that expects slashed data + * Tests the legacy model function that expects slashed data. */ function test_update_post_meta() { $id = self::factory()->post->create(); @@ -133,7 +135,7 @@ class Tests_Meta_Slashes extends WP_UnitTestCase { } /** - * Tests the model function that expects slashed data + * Tests the model function that expects slashed data. */ function test_add_comment_meta() { $id = self::$comment_id; @@ -156,7 +158,7 @@ class Tests_Meta_Slashes extends WP_UnitTestCase { } /** - * Tests the model function that expects slashed data + * Tests the model function that expects slashed data. */ function test_update_comment_meta() { $id = self::$comment_id; @@ -183,7 +185,7 @@ class Tests_Meta_Slashes extends WP_UnitTestCase { } /** - * Tests the model function that expects slashed data + * Tests the model function that expects slashed data. */ function test_add_user_meta() { $id = self::factory()->user->create(); @@ -206,7 +208,7 @@ class Tests_Meta_Slashes extends WP_UnitTestCase { } /** - * Tests the model function that expects slashed data + * Tests the model function that expects slashed data. */ function test_update_user_meta() { $id = self::factory()->user->create(); diff --git a/tests/phpunit/tests/multisite.php b/tests/phpunit/tests/multisite.php index c75b76eea5..e4150a2b0e 100644 --- a/tests/phpunit/tests/multisite.php +++ b/tests/phpunit/tests/multisite.php @@ -30,7 +30,7 @@ if ( is_multisite() ) : wpmu_log_new_registrations( 1, 1 ); - // currently there is no wrapper function for the registration_log + // Currently there is no wrapper function for the registration_log. $reg_blog = $wpdb->get_col( $wpdb->prepare( "SELECT email FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.blog_id = 1 AND IP LIKE %s", $ip ) ); $this->assertEquals( $user->user_email, $reg_blog[ count( $reg_blog ) - 1 ] ); } @@ -39,7 +39,7 @@ if ( is_multisite() ) : * @ticket 37392 */ function test_wp_count_sites() { - // create a random number of sites with each status. + // Create a random number of sites with each status. $site_ids = array( 'public' => self::factory()->blog->create_many( random_int( 0, 5 ), @@ -84,7 +84,7 @@ if ( is_multisite() ) : array( 'all' => array_sum( $counts_by_status ) ), $counts_by_status ); - // add 1 to all & public for the main site. + // Add 1 to all & public for the main site. $expected['all'] += 1; $expected['public'] += 1; diff --git a/tests/phpunit/tests/multisite/site.php b/tests/phpunit/tests/multisite/site.php index f77d425470..5afc0adf73 100644 --- a/tests/phpunit/tests/multisite/site.php +++ b/tests/phpunit/tests/multisite/site.php @@ -144,7 +144,7 @@ if ( is_multisite() ) : $this->assertInternalType( 'int', $blog_id ); $prefix = $wpdb->get_blog_prefix( $blog_id ); - // $get_all = false, only retrieve details from the blogs table + // $get_all = false, only retrieve details from the blogs table. $details = get_blog_details( $blog_id, false ); // Combine domain and path for a site specific cache key. @@ -152,14 +152,14 @@ if ( is_multisite() ) : $this->assertEquals( $details, wp_cache_get( $blog_id . 'short', 'blog-details' ) ); - // get_blogaddress_by_name() + // get_blogaddress_by_name(). $this->assertEquals( 'http://' . $details->domain . $details->path, get_blogaddress_by_name( trim( $details->path, '/' ) ) ); - // These are empty until get_blog_details() is called with $get_all = true + // These are empty until get_blog_details() is called with $get_all = true. $this->assertEquals( false, wp_cache_get( $blog_id, 'blog-details' ) ); $this->assertEquals( false, wp_cache_get( $key, 'blog-lookup' ) ); - // $get_all = true, populate the full blog-details cache and the blog slug lookup cache + // $get_all = true, populate the full blog-details cache and the blog slug lookup cache. $details = get_blog_details( $blog_id, true ); $this->assertEquals( $details, wp_cache_get( $blog_id, 'blog-details' ) ); $this->assertEquals( $details, wp_cache_get( $key, 'blog-lookup' ) ); @@ -187,7 +187,7 @@ if ( is_multisite() ) : } } - // update the blog count cache to use get_blog_count() + // Update the blog count cache to use get_blog_count(). wp_update_network_counts(); $this->assertEquals( 2, (int) get_blog_count() ); } @@ -350,7 +350,7 @@ if ( is_multisite() ) : // Delete the site without forcing a table drop. wpmu_delete_blog( $blog_id, false ); - // update the blog count cache to use get_blog_count() + // Update the blog count cache to use get_blog_count(). wp_update_network_counts(); $this->assertEquals( 1, get_blog_count() ); } @@ -364,7 +364,7 @@ if ( is_multisite() ) : // Delete the site and force a table drop. wpmu_delete_blog( $blog_id, true ); - // update the blog count cache to use get_blog_count() + // Update the blog count cache to use get_blog_count(). wp_update_network_counts(); $this->assertEquals( 1, get_blog_count() ); } @@ -405,7 +405,7 @@ if ( is_multisite() ) : wpmu_update_blogs_date(); - // compare the update time with the current time, allow delta < 2 + // Compare the update time with the current time, allow delta < 2. $blog = get_site( get_current_blog_id() ); $current_time = time(); $time_difference = $current_time - strtotime( $blog->last_updated ); @@ -919,7 +919,7 @@ if ( is_multisite() ) : $exists2 = domain_exists( 'foo', 'bar/' ); remove_filter( 'domain_exists', array( $this, '_domain_exists_cb' ), 10, 4 ); - // Make sure the same result is returned with or without a trailing slash + // Make sure the same result is returned with or without a trailing slash. $this->assertEquals( $exists1, $exists2 ); } @@ -2354,11 +2354,11 @@ if ( is_multisite() ) : * Populate options callback to warm cache for blog-details / site-details cache group */ public function populate_options_callback() { - // Cache blog details + // Cache blog details. $blog_id = get_current_blog_id(); get_blog_details( $blog_id ); get_site( $blog_id )->siteurl; - // Set siteurl + // Set siteurl. update_option( 'siteurl', 'http://testsite1.example.org/test' ); } @@ -2420,9 +2420,9 @@ if ( is_multisite() ) : */ protected function _get_next_site_id() { global $wpdb; - //create an entry + // Create an entry. static::factory()->blog->create(); - //get the ID after it + // Get the ID after it. return (int) $wpdb->get_var( 'SELECT blog_id FROM ' . $wpdb->blogs . ' ORDER BY blog_ID DESC LIMIT 1' ) + 1; } @@ -2438,8 +2438,8 @@ if ( is_multisite() ) : 'default values' => array( array(), array( - 'public' => 0, // `public` is one of the defaults metas in `wpmu_create_blog' function prior WordPress 5.1.0 - 'WPLANG' => 'en_US', // WPLANG is another default meta in `wpmu_create_blog` function prior WordPress 5.1.0. + 'public' => 0, // `public` is one of the default metas in `wpmu_create_blog()' function prior to WordPress 5.1.0. + 'WPLANG' => 'en_US', // WPLANG is another default meta in `wpmu_create_blog()` function prior to WordPress 5.1.0. ), ), 'public site' => array( diff --git a/tests/phpunit/tests/multisite/siteDetails.php b/tests/phpunit/tests/multisite/siteDetails.php index 477f8b5ad9..b705129054 100644 --- a/tests/phpunit/tests/multisite/siteDetails.php +++ b/tests/phpunit/tests/multisite/siteDetails.php @@ -134,7 +134,7 @@ if ( is_multisite() ) : $site = get_site( $id ); - // Trigger retrieving site details (post_count is not set on new sites) + // Trigger retrieving site details (post_count is not set on new sites). $post_count = $site->post_count; $cached_details = wp_cache_get( $site->id, 'site-details' ); diff --git a/tests/phpunit/tests/multisite/siteQuery.php b/tests/phpunit/tests/multisite/siteQuery.php index b3c7e3fb0c..ecabdbc8db 100644 --- a/tests/phpunit/tests/multisite/siteQuery.php +++ b/tests/phpunit/tests/multisite/siteQuery.php @@ -442,7 +442,7 @@ if ( is_multisite() ) : $this->assertEmpty( $found ); } - // archived, mature, spam, deleted, public + // archived, mature, spam, deleted, public. public function test_wp_site_query_by_archived() { $q = new WP_Site_Query(); diff --git a/tests/phpunit/tests/oembed/postEmbedUrl.php b/tests/phpunit/tests/oembed/postEmbedUrl.php index e6c478f26f..5432e5182b 100644 --- a/tests/phpunit/tests/oembed/postEmbedUrl.php +++ b/tests/phpunit/tests/oembed/postEmbedUrl.php @@ -89,7 +89,7 @@ class Tests_Post_Embed_URL extends WP_UnitTestCase { function test_static_front_page_conflicts_with_embed_slug() { $this->set_permalink_structure( '/%postname%/' ); - // Create a post with the 'embed' post_name + // Create a post with the 'embed' post_name. add_filter( 'wp_unique_post_slug', array( $this, 'filter_unique_post_slug' ) ); $post_embed_slug = self::factory()->post->create( array( 'post_name' => 'embed' ) ); remove_filter( 'wp_unique_post_slug', array( $this, 'filter_unique_post_slug' ) ); diff --git a/tests/phpunit/tests/option/multisite.php b/tests/phpunit/tests/option/multisite.php index a837053385..3ab4dd9184 100644 --- a/tests/phpunit/tests/option/multisite.php +++ b/tests/phpunit/tests/option/multisite.php @@ -31,34 +31,34 @@ if ( is_multisite() ) : $value2 = __FUNCTION__ . '_val2'; $this->assertFalse( get_blog_option( 1, 'doesnotexist' ) ); - $this->assertFalse( get_option( 'doesnotexist' ) ); // check get_option() + $this->assertFalse( get_option( 'doesnotexist' ) ); // Check get_option(). $this->assertTrue( add_blog_option( 1, $key, $value ) ); // Assert all values of $blog_id that means the current or main blog (the same here). $this->assertEquals( $value, get_blog_option( 1, $key ) ); $this->assertEquals( $value, get_blog_option( null, $key ) ); $this->assertEquals( $value, get_blog_option( '1', $key ) ); - $this->assertEquals( $value, get_option( $key ) ); // check get_option() + $this->assertEquals( $value, get_option( $key ) ); // Check get_option(). - $this->assertFalse( add_blog_option( 1, $key, $value ) ); // Already exists - $this->assertFalse( update_blog_option( 1, $key, $value ) ); // Value is the same + $this->assertFalse( add_blog_option( 1, $key, $value ) ); // Already exists. + $this->assertFalse( update_blog_option( 1, $key, $value ) ); // Value is the same. $this->assertTrue( update_blog_option( 1, $key, $value2 ) ); $this->assertEquals( $value2, get_blog_option( 1, $key ) ); - $this->assertEquals( $value2, get_option( $key ) ); // check get_option() + $this->assertEquals( $value2, get_option( $key ) ); // Check get_option(). $this->assertFalse( add_blog_option( 1, $key, $value ) ); $this->assertEquals( $value2, get_blog_option( 1, $key ) ); - $this->assertEquals( $value2, get_option( $key ) ); // check get_option() + $this->assertEquals( $value2, get_option( $key ) ); // Check get_option(). $this->assertTrue( delete_blog_option( 1, $key ) ); $this->assertFalse( get_blog_option( 1, $key ) ); - $this->assertFalse( get_option( $key ) ); // check get_option() + $this->assertFalse( get_option( $key ) ); // Check get_option(). $this->assertFalse( delete_blog_option( 1, $key ) ); $this->assertTrue( update_blog_option( 1, $key2, $value2 ) ); $this->assertEquals( $value2, get_blog_option( 1, $key2 ) ); - $this->assertEquals( $value2, get_option( $key2 ) ); // check get_option() + $this->assertEquals( $value2, get_option( $key2 ) ); // Check get_option(). $this->assertTrue( delete_blog_option( 1, $key2 ) ); $this->assertFalse( get_blog_option( 1, $key2 ) ); - $this->assertFalse( get_option( $key2 ) ); // check get_option() + $this->assertFalse( get_option( $key2 ) ); // Check get_option(). } function test_from_same_site_with_null_blog_id() { @@ -68,33 +68,33 @@ if ( is_multisite() ) : $value2 = __FUNCTION__ . '_val2'; $this->assertFalse( get_blog_option( null, 'doesnotexist' ) ); - $this->assertFalse( get_option( 'doesnotexist' ) ); // check get_option() + $this->assertFalse( get_option( 'doesnotexist' ) ); // Check get_option(). $this->assertTrue( add_blog_option( null, $key, $value ) ); // Assert all values of $blog_id that means the current or main blog (the same here). $this->assertEquals( $value, get_blog_option( null, $key ) ); $this->assertEquals( $value, get_blog_option( null, $key ) ); - $this->assertEquals( $value, get_option( $key ) ); // check get_option() + $this->assertEquals( $value, get_option( $key ) ); // Check get_option(). - $this->assertFalse( add_blog_option( null, $key, $value ) ); // Already exists - $this->assertFalse( update_blog_option( null, $key, $value ) ); // Value is the same + $this->assertFalse( add_blog_option( null, $key, $value ) ); // Already exists. + $this->assertFalse( update_blog_option( null, $key, $value ) ); // Value is the same. $this->assertTrue( update_blog_option( null, $key, $value2 ) ); $this->assertEquals( $value2, get_blog_option( null, $key ) ); - $this->assertEquals( $value2, get_option( $key ) ); // check get_option() + $this->assertEquals( $value2, get_option( $key ) ); // Check get_option(). $this->assertFalse( add_blog_option( null, $key, $value ) ); $this->assertEquals( $value2, get_blog_option( null, $key ) ); - $this->assertEquals( $value2, get_option( $key ) ); // check get_option() + $this->assertEquals( $value2, get_option( $key ) ); // Check get_option(). $this->assertTrue( delete_blog_option( null, $key ) ); $this->assertFalse( get_blog_option( null, $key ) ); - $this->assertFalse( get_option( $key ) ); // check get_option() + $this->assertFalse( get_option( $key ) ); // Check get_option(). $this->assertFalse( delete_blog_option( null, $key ) ); $this->assertTrue( update_blog_option( null, $key2, $value2 ) ); $this->assertEquals( $value2, get_blog_option( null, $key2 ) ); - $this->assertEquals( $value2, get_option( $key2 ) ); // check get_option() + $this->assertEquals( $value2, get_option( $key2 ) ); // Check get_option(). $this->assertTrue( delete_blog_option( null, $key2 ) ); $this->assertFalse( get_blog_option( null, $key2 ) ); - $this->assertFalse( get_option( $key2 ) ); // check get_option() + $this->assertFalse( get_option( $key2 ) ); // Check get_option(). } function test_with_another_site() { @@ -115,33 +115,33 @@ if ( is_multisite() ) : $value2 = __FUNCTION__ . '_val2'; $this->assertFalse( get_blog_option( $blog_id, 'doesnotexist' ) ); - //$this->assertFalse( get_option( 'doesnotexist' ) ); // check get_option() + // $this->assertFalse( get_option( 'doesnotexist' ) ); // Check get_option(). $this->assertTrue( add_blog_option( $blog_id, $key, $value ) ); // Assert all values of $blog_id that means the current or main blog (the same here). $this->assertEquals( $value, get_blog_option( $blog_id, $key ) ); $this->assertEquals( $value, get_blog_option( "$blog_id", $key ) ); - //$this->assertEquals( $value, get_option( $key ) ); // check get_option() + // $this->assertEquals( $value, get_option( $key ) ); // Check get_option(). - $this->assertFalse( add_blog_option( $blog_id, $key, $value ) ); // Already exists - $this->assertFalse( update_blog_option( $blog_id, $key, $value ) ); // Value is the same + $this->assertFalse( add_blog_option( $blog_id, $key, $value ) ); // Already exists. + $this->assertFalse( update_blog_option( $blog_id, $key, $value ) ); // Value is the same. $this->assertTrue( update_blog_option( $blog_id, $key, $value2 ) ); $this->assertEquals( $value2, get_blog_option( $blog_id, $key ) ); - //$this->assertEquals( $value2, get_option( $key ) ); // check get_option() + // $this->assertEquals( $value2, get_option( $key ) ); // Check get_option(). $this->assertFalse( add_blog_option( $blog_id, $key, $value ) ); $this->assertEquals( $value2, get_blog_option( $blog_id, $key ) ); - //$this->assertEquals( $value2, get_option( $key ) ); // check get_option() + // $this->assertEquals( $value2, get_option( $key ) ); // Check get_option(). $this->assertTrue( delete_blog_option( $blog_id, $key ) ); $this->assertFalse( get_blog_option( $blog_id, $key ) ); - //$this->assertFalse( get_option( $key ) ); // check get_option() + // $this->assertFalse( get_option( $key ) ); // Check get_option(). $this->assertFalse( delete_blog_option( $blog_id, $key ) ); $this->assertTrue( update_blog_option( $blog_id, $key2, $value2 ) ); $this->assertEquals( $value2, get_blog_option( $blog_id, $key2 ) ); - //$this->assertEquals( $value2, get_option( $key2 ) ); // check get_option() + // $this->assertEquals( $value2, get_option( $key2 ) ); // Check get_option(). $this->assertTrue( delete_blog_option( $blog_id, $key2 ) ); $this->assertFalse( get_blog_option( $blog_id, $key2 ) ); - //$this->assertFalse( get_option( $key2 ) ); // check get_option() + // $this->assertFalse( get_option( $key2 ) ); // Check get_option(). } /** diff --git a/tests/phpunit/tests/option/option.php b/tests/phpunit/tests/option/option.php index f61f59b88b..0d2f36595d 100644 --- a/tests/phpunit/tests/option/option.php +++ b/tests/phpunit/tests/option/option.php @@ -18,8 +18,8 @@ class Tests_Option_Option extends WP_UnitTestCase { $this->assertFalse( get_option( 'doesnotexist' ) ); $this->assertTrue( add_option( $key, $value ) ); $this->assertEquals( $value, get_option( $key ) ); - $this->assertFalse( add_option( $key, $value ) ); // Already exists - $this->assertFalse( update_option( $key, $value ) ); // Value is the same + $this->assertFalse( add_option( $key, $value ) ); // Already exists. + $this->assertFalse( update_option( $key, $value ) ); // Value is the same. $this->assertTrue( update_option( $key, $value2 ) ); $this->assertEquals( $value2, get_option( $key ) ); $this->assertFalse( add_option( $key, $value ) ); @@ -54,7 +54,7 @@ class Tests_Option_Option extends WP_UnitTestCase { $this->assertEquals( $value, get_option( 'doesnotexist', 'foo' ) ); remove_filter( 'default_option_doesnotexist', array( $this, '__return_foo' ) ); - // Cleanup + // Cleanup. $this->assertTrue( delete_option( 'doesnotexist' ) ); $this->assertFalse( get_option( 'doesnotexist' ) ); } diff --git a/tests/phpunit/tests/option/siteOption.php b/tests/phpunit/tests/option/siteOption.php index 3210f0eba3..67065019b8 100644 --- a/tests/phpunit/tests/option/siteOption.php +++ b/tests/phpunit/tests/option/siteOption.php @@ -133,18 +133,26 @@ class Tests_Option_SiteOption extends WP_UnitTestCase { $this->assertEquals( $value, get_site_option( $key ) ); } - // #15497 - ensure update_site_option will add options with false-y values + /** + * Ensure update_site_option() will add options with false-y values. + * + * @ticket 15497 + */ function test_update_adds_falsey_value() { $key = __FUNCTION__; $value = 0; delete_site_option( $key ); $this->assertTrue( update_site_option( $key, $value ) ); - $this->flush_cache(); // ensure we're getting the value from the DB + $this->flush_cache(); // Ensure we're getting the value from the DB. $this->assertEquals( $value, get_site_option( $key ) ); } - // #18955 - ensure get_site_option doesn't cache the default value for non-existent options + /** + * Ensure get_site_option() doesn't cache the default value for non-existent options. + * + * @ticket 18955 + */ function test_get_doesnt_cache_default_value() { $option = __FUNCTION__; $default = 'a default'; diff --git a/tests/phpunit/tests/option/slashes.php b/tests/phpunit/tests/option/slashes.php index 5b88768c32..5a7c9f6a5f 100644 --- a/tests/phpunit/tests/option/slashes.php +++ b/tests/phpunit/tests/option/slashes.php @@ -8,8 +8,8 @@ class Tests_Option_Slashes extends WP_UnitTestCase { function setUp() { parent::setUp(); - // it is important to test with both even and odd numbered slashes as - // kses does a strip-then-add slashes in some of its function calls + // It is important to test with both even and odd numbered slashes, + // as KSES does a strip-then-add slashes in some of its function calls. $this->slash_1 = 'String with 1 slash \\'; $this->slash_2 = 'String with 2 slashes \\\\'; $this->slash_3 = 'String with 3 slashes \\\\\\'; diff --git a/tests/phpunit/tests/option/transient.php b/tests/phpunit/tests/option/transient.php index dbeb4e1e92..90432a5e69 100644 --- a/tests/phpunit/tests/option/transient.php +++ b/tests/phpunit/tests/option/transient.php @@ -93,27 +93,27 @@ class Tests_Option_Transient extends WP_UnitTestCase { * @ticket 30380 */ function test_nonexistent_key_dont_delete_if_false() { - // Create a bogus a transient + // Create a bogus a transient. $key = 'test_transient'; set_transient( $key, 'test', 60 * 10 ); $this->assertEquals( 'test', get_transient( $key ) ); - // Useful variables for tracking + // Useful variables for tracking. $transient_timeout = '_transient_timeout_' . $key; - // Mock an action for tracking action calls + // Mock an action for tracking action calls. $a = new MockAction(); - // Make sure the timeout option returns false + // Make sure the timeout option returns false. add_filter( 'option_' . $transient_timeout, '__return_false' ); - // Add some actions to make sure options are _not_ deleted + // Add some actions to make sure options are _not_ deleted. add_action( 'delete_option', array( $a, 'action' ) ); - // Act + // Act. get_transient( $key ); - // Make sure delete option was not called for both the transient and the timeout + // Make sure 'delete_option' was not called for both the transient and the timeout. $this->assertEquals( 0, $a->get_call_count() ); } @@ -121,26 +121,26 @@ class Tests_Option_Transient extends WP_UnitTestCase { * @ticket 30380 */ function test_nonexistent_key_old_timeout() { - // Create a transient + // Create a transient. $key = 'test_transient'; set_transient( $key, 'test', 60 * 10 ); $this->assertEquals( 'test', get_transient( $key ) ); - // Make sure the timeout option returns false + // Make sure the timeout option returns false. $timeout = '_transient_timeout_' . $key; $transient_option = '_transient_' . $key; add_filter( 'option_' . $timeout, '__return_zero' ); - // Mock an action for tracking action calls + // Mock an action for tracking action calls. $a = new MockAction(); - // Add some actions to make sure options are deleted + // Add some actions to make sure options are deleted. add_action( 'delete_option', array( $a, 'action' ) ); - // Act + // Act. get_transient( $key ); - // Make sure delete option was called for both the transient and the timeout + // Make sure 'delete_option' was called for both the transient and the timeout. $this->assertEquals( 2, $a->get_call_count() ); $expected = array( diff --git a/tests/phpunit/tests/option/userSettings.php b/tests/phpunit/tests/option/userSettings.php index d96bcc6589..7e979de6e9 100644 --- a/tests/phpunit/tests/option/userSettings.php +++ b/tests/phpunit/tests/option/userSettings.php @@ -50,7 +50,7 @@ class Tests_User_Settings extends WP_UnitTestCase { $this->assertEquals( 'foobarbaz', get_user_setting( 'foo' ) ); } - // set_user_setting bails if `headers_sent()` is true + // set_user_setting() bails if `headers_sent()` is true. function set_user_setting( $name, $value ) { $all_user_settings = get_all_user_settings(); $all_user_settings[ $name ] = $value; diff --git a/tests/phpunit/tests/pluggable.php b/tests/phpunit/tests/pluggable.php index fd97a2dd77..73ca7de806 100644 --- a/tests/phpunit/tests/pluggable.php +++ b/tests/phpunit/tests/pluggable.php @@ -88,7 +88,7 @@ class Tests_Pluggable extends WP_UnitTestCase { 'wp-includes/pluggable.php', ); - // Pluggable function signatures are not tested when an external object cache is in use. #31491 + // Pluggable function signatures are not tested when an external object cache is in use. See #31491. if ( ! wp_using_ext_object_cache() ) { $test_files[] = 'wp-includes/cache.php'; } @@ -260,7 +260,7 @@ class Tests_Pluggable extends WP_UnitTestCase { 'install_global_terms' => array(), ); - // Pluggable function signatures are not tested when an external object cache is in use. #31491 + // Pluggable function signatures are not tested when an external object cache is in use. See #31491. if ( ! wp_using_ext_object_cache() ) { $signatures = array_merge( $signatures, diff --git a/tests/phpunit/tests/pomo/pluralForms.php b/tests/phpunit/tests/pomo/pluralForms.php index 2cd283cf95..ed79b35cba 100644 --- a/tests/phpunit/tests/pomo/pluralForms.php +++ b/tests/phpunit/tests/pomo/pluralForms.php @@ -110,7 +110,7 @@ class PluralFormsTest extends WP_UnitTestCase { ), ), array( - // Ternary + // Ternary. 'n ? 1 : 2', array( -1 => 1, @@ -120,7 +120,7 @@ class PluralFormsTest extends WP_UnitTestCase { ), ), array( - // Comparison + // Comparison. 'n > 1 ? 1 : 2', array( -2 => 2, @@ -163,9 +163,9 @@ class PluralFormsTest extends WP_UnitTestCase { public function data_exceptions() { return array( array( - 'n # 2', // Invalid expression to parse - 'Unknown symbol "#"', // Expected exception message - false, // Whether to call the get() method or not + 'n # 2', // Invalid expression to parse. + 'Unknown symbol "#"', // Expected exception message. + false, // Whether to call the get() method or not. ), array( 'n & 1', diff --git a/tests/phpunit/tests/pomo/po.php b/tests/phpunit/tests/pomo/po.php index 0bd6f461dc..81cc058932 100644 --- a/tests/phpunit/tests/pomo/po.php +++ b/tests/phpunit/tests/pomo/po.php @@ -7,7 +7,7 @@ class Tests_POMO_PO extends WP_UnitTestCase { function setUp() { parent::setUp(); require_once ABSPATH . '/wp-includes/pomo/po.php'; - // not so random wordpress.pot string -- multiple lines + // Not so random wordpress.pot string -- multiple lines. $this->mail = 'Your new WordPress blog has been successfully set up at: %1$s @@ -50,17 +50,17 @@ http://wordpress.org/ function test_poify() { $po = new PO(); - //simple + // Simple. $this->assertEquals( '"baba"', $po->poify( 'baba' ) ); - //long word + // Long word. $this->assertEquals( $this->po_a90, $po->poify( $this->a90 ) ); - // tab + // Tab. $this->assertEquals( '"ba\tba"', $po->poify( "ba\tba" ) ); - // do not add leading empty string of one-line string ending on a newline + // Do not add leading empty string of one-line string ending on a newline. $this->assertEquals( '"\\\\a\\\\n\\n"', $po->poify( "\a\\n\n" ) ); - // backslash + // Backslash. $this->assertEquals( '"ba\\\\ba"', $po->poify( 'ba\\ba' ) ); - // random wordpress.pot string + // Random wordpress.pot string. $src = 'Categories can be selectively converted to tags using the category to tag converter.'; $this->assertEquals( '"Categories can be selectively converted to tags using the category to tag converter."', $po->poify( $src ) ); @@ -73,7 +73,7 @@ http://wordpress.org/ $this->assertEquals( "baba\ngugu", $po->unpoify( '"baba\n"' . "\t\t\t\n" . '"gugu"' ) ); $this->assertEquals( $this->a90, $po->unpoify( $this->po_a90 ) ); $this->assertEquals( '\\t\\n', $po->unpoify( '"\\\\t\\\\n"' ) ); - // wordwrapped + // Wordwrapped. $this->assertEquals( 'babadyado', $po->unpoify( "\"\"\n\"baba\"\n\"dyado\"" ) ); $this->assertEqualsIgnoreEOL( $this->mail, $po->unpoify( $this->po_mail ) ); } @@ -82,7 +82,7 @@ http://wordpress.org/ $po = new PO(); $entry = new Translation_Entry( array( 'singular' => 'baba' ) ); $this->assertEquals( "msgid \"baba\"\nmsgstr \"\"", $po->export_entry( $entry ) ); - // plural + // Plural. $entry = new Translation_Entry( array( 'singular' => 'baba', @@ -181,7 +181,7 @@ msgstr[1] "кукуруку" msgstr[2] "бабаяга"', $po->export_entry( $entry ) ); - // context + // Context. $entry = new Translation_Entry( array( 'context' => 'ctxt', @@ -320,6 +320,6 @@ msgstr[2] "бабаяга"', $this->assertEquals( 1, count( $po->entries ) ); } - //TODO: add tests for bad files + // TODO: Add tests for bad files. } diff --git a/tests/phpunit/tests/pomo/translationEntry.php b/tests/phpunit/tests/pomo/translationEntry.php index 9a8ba46b53..0f68ba7cc2 100644 --- a/tests/phpunit/tests/pomo/translationEntry.php +++ b/tests/phpunit/tests/pomo/translationEntry.php @@ -6,12 +6,12 @@ class Tests_POMO_TranslationEntry extends WP_UnitTestCase { function test_create_entry() { - // no singular => empty object + // No singular => empty object. $entry = new Translation_Entry(); $this->assertNull( $entry->singular ); $this->assertNull( $entry->plural ); $this->assertFalse( $entry->is_plural ); - // args -> members + // args -> members. $entry = new Translation_Entry( array( 'singular' => 'baba', diff --git a/tests/phpunit/tests/pomo/translations.php b/tests/phpunit/tests/pomo/translations.php index 36b12fbf7b..c9f034b524 100644 --- a/tests/phpunit/tests/pomo/translations.php +++ b/tests/phpunit/tests/pomo/translations.php @@ -12,8 +12,8 @@ class Tests_POMO_Translations extends WP_UnitTestCase { $po = new Translations(); $po->add_entry( $entry ); $this->assertEquals( array( $entry->key() => $entry ), $po->entries ); - // add the same entry more than once - // we do not need to test proper key generation here, see test_key() + // Add the same entry more than once. + // We do not need to test proper key generation here, see test_key(). $po->add_entry( $entry ); $po->add_entry( $entry ); $this->assertEquals( array( $entry->key() => $entry ), $po->entries ); @@ -25,7 +25,7 @@ class Tests_POMO_Translations extends WP_UnitTestCase { ), $po->entries ); - // add empty entry + // Add empty entry. $this->assertEquals( false, $po->add_entry( $empty ) ); $this->assertEquals( array( @@ -35,7 +35,7 @@ class Tests_POMO_Translations extends WP_UnitTestCase { $po->entries ); - // give add_entry() the arguments and let it create the entry itself + // Give add_entry() the arguments and let it create the entry itself. $po = new Translations(); $po->add_entry( array( 'singular' => 'baba' ) ); $entries = array_values( $po->entries ); @@ -93,12 +93,12 @@ class Tests_POMO_Translations extends WP_UnitTestCase { $domain->add_entry( $entry_2 ); $this->assertEquals( 'other', $domain->translate_plural( 'other', 'others', 1 ) ); $this->assertEquals( 'others', $domain->translate_plural( 'other', 'others', 111 ) ); - // too few translations + cont logic + // Too few translations + cont logic. $this->assertEquals( 'babas', $domain->translate_plural( 'baba', 'babas', 2 ) ); $this->assertEquals( 'babas', $domain->translate_plural( 'baba', 'babas', 0 ) ); $this->assertEquals( 'babas', $domain->translate_plural( 'baba', 'babas', -1 ) ); $this->assertEquals( 'babas', $domain->translate_plural( 'baba', 'babas', 999 ) ); - // proper + // Proper. $this->assertEquals( 'dyadox', $domain->translate_plural( 'dyado', 'dyados', 1 ) ); $this->assertEquals( 'dyadoy', $domain->translate_plural( 'dyado', 'dyados', 0 ) ); $this->assertEquals( 'dyadoy', $domain->translate_plural( 'dyado', 'dyados', 18881 ) ); diff --git a/tests/phpunit/tests/post.php b/tests/phpunit/tests/post.php index dcd950e286..21a304bc44 100644 --- a/tests/phpunit/tests/post.php +++ b/tests/phpunit/tests/post.php @@ -39,12 +39,16 @@ class Tests_Post extends WP_UnitTestCase { $this->post_ids = array(); } - // helper function: return the timestamp(s) of cron jobs for the specified hook and post + /** + * Helper function: return the timestamp(s) of cron jobs for the specified hook and post. + */ function _next_schedule_for_post( $hook, $id ) { return wp_next_scheduled( 'publish_future_post', array( 0 => intval( $id ) ) ); } - // helper function, unsets current user globally + /** + * Helper function, unsets current user globally. + */ function _unset_current_user() { global $current_user, $user_ID; @@ -52,7 +56,9 @@ class Tests_Post extends WP_UnitTestCase { $user_ID = null; } - // test simple valid behavior: insert and get a post + /** + * Test simple valid behavior: insert and get a post. + */ function test_vb_insert_get_delete() { register_post_type( 'cpt', array( 'taxonomies' => array( 'post_tag', 'ctax' ) ) ); register_taxonomy( 'ctax', 'cpt' ); @@ -71,12 +77,12 @@ class Tests_Post extends WP_UnitTestCase { 'post_type' => $post_type, ); - // insert a post and make sure the ID is ok + // Insert a post and make sure the ID is OK. $id = wp_insert_post( $post ); $this->assertTrue( is_numeric( $id ) ); $this->assertTrue( $id > 0 ); - // fetch the post and make sure it matches + // Fetch the post and make sure it matches. $out = get_post( $id ); $this->assertEquals( $post['post_content'], $out->post_content ); @@ -84,7 +90,7 @@ class Tests_Post extends WP_UnitTestCase { $this->assertEquals( $post['post_status'], $out->post_status ); $this->assertEquals( $post['post_author'], $out->post_author ); - // test cache state + // Test cache state. $pcache = wp_cache_get( $id, 'posts' ); $this->assertInstanceOf( 'stdClass', $pcache ); $this->assertEquals( $id, $pcache->ID ); @@ -111,9 +117,10 @@ class Tests_Post extends WP_UnitTestCase { $GLOBALS['wp_taxonomies']['post_tag']->object_type = array( 'post' ); } + /** + * Insert a post with a future date, and make sure the status and cron schedule are correct. + */ function test_vb_insert_future() { - // insert a post with a future date, and make sure the status and cron schedule are correct - $future_date = strtotime( '+1 day' ); $post = array( @@ -124,14 +131,14 @@ class Tests_Post extends WP_UnitTestCase { 'post_date' => strftime( '%Y-%m-%d %H:%M:%S', $future_date ), ); - // insert a post and make sure the ID is ok + // Insert a post and make sure the ID is OK. $id = wp_insert_post( $post ); $this->post_ids[] = $id; - #dmp(_get_cron_array()); + // dmp( _get_cron_array() ); $this->assertTrue( is_numeric( $id ) ); $this->assertTrue( $id > 0 ); - // fetch the post and make sure it matches + // Fetch the post and make sure it matches. $out = get_post( $id ); $this->assertEquals( $post['post_content'], $out->post_content ); @@ -140,14 +147,15 @@ class Tests_Post extends WP_UnitTestCase { $this->assertEquals( $post['post_author'], $out->post_author ); $this->assertEquals( $post['post_date'], $out->post_date ); - // there should be a publish_future_post hook scheduled on the future date + // There should be a publish_future_post hook scheduled on the future date. $this->assertEquals( $future_date, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); } + /** + * Insert a post with a future date, and make sure the status and cron schedule are correct. + */ function test_vb_insert_future_over_dst() { - // insert a post with a future date, and make sure the status and cron schedule are correct - - // Some magic days - one dst one not + // Some magic days - one DST one not. $future_date_1 = strtotime( 'June 21st +1 year' ); $future_date_2 = strtotime( 'Jan 11th +1 year' ); @@ -159,38 +167,40 @@ class Tests_Post extends WP_UnitTestCase { 'post_date' => strftime( '%Y-%m-%d %H:%M:%S', $future_date_1 ), ); - // insert a post and make sure the ID is ok + // Insert a post and make sure the ID is OK. $id = wp_insert_post( $post ); $this->post_ids[] = $id; - // fetch the post and make sure has the correct date and status + // Fetch the post and make sure has the correct date and status. $out = get_post( $id ); $this->assertEquals( 'future', $out->post_status ); $this->assertEquals( $post['post_date'], $out->post_date ); - // check that there's a publish_future_post job scheduled at the right time + // Check that there's a publish_future_post job scheduled at the right time. $this->assertEquals( $future_date_1, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); - // now save it again with a date further in the future + // Now save it again with a date further in the future. $post['ID'] = $id; $post['post_date'] = strftime( '%Y-%m-%d %H:%M:%S', $future_date_2 ); $post['post_date_gmt'] = null; wp_update_post( $post ); - // fetch the post again and make sure it has the new post_date + // Fetch the post again and make sure it has the new post_date. $out = get_post( $id ); $this->assertEquals( 'future', $out->post_status ); $this->assertEquals( $post['post_date'], $out->post_date ); - // and the correct date on the cron job + // And the correct date on the cron job. $this->assertEquals( $future_date_2, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); } + /** + * Future post bug: posts get published at the wrong time if you edit the timestamp. + * + * @ticket 4710 + */ function test_vb_insert_future_edit_bug() { - // future post bug: posts get published at the wrong time if you edit the timestamp - // https://core.trac.wordpress.org/ticket/4710 - $future_date_1 = strtotime( '+1 day' ); $future_date_2 = strtotime( '+2 day' ); @@ -202,37 +212,38 @@ class Tests_Post extends WP_UnitTestCase { 'post_date' => strftime( '%Y-%m-%d %H:%M:%S', $future_date_1 ), ); - // insert a post and make sure the ID is ok + // Insert a post and make sure the ID is OK. $id = wp_insert_post( $post ); $this->post_ids[] = $id; - // fetch the post and make sure has the correct date and status + // Fetch the post and make sure has the correct date and status. $out = get_post( $id ); $this->assertEquals( 'future', $out->post_status ); $this->assertEquals( $post['post_date'], $out->post_date ); - // check that there's a publish_future_post job scheduled at the right time + // Check that there's a publish_future_post job scheduled at the right time. $this->assertEquals( $future_date_1, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); - // now save it again with a date further in the future + // Now save it again with a date further in the future. $post['ID'] = $id; $post['post_date'] = strftime( '%Y-%m-%d %H:%M:%S', $future_date_2 ); $post['post_date_gmt'] = null; wp_update_post( $post ); - // fetch the post again and make sure it has the new post_date + // Fetch the post again and make sure it has the new post_date. $out = get_post( $id ); $this->assertEquals( 'future', $out->post_status ); $this->assertEquals( $post['post_date'], $out->post_date ); - // and the correct date on the cron job + // And the correct date on the cron job. $this->assertEquals( $future_date_2, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); } + /** + * Insert a draft post with a future date, and make sure no cron schedule is set. + */ function test_vb_insert_future_draft() { - // insert a draft post with a future date, and make sure no cron schedule is set - $future_date = strtotime( '+1 day' ); $post = array( @@ -243,14 +254,14 @@ class Tests_Post extends WP_UnitTestCase { 'post_date' => strftime( '%Y-%m-%d %H:%M:%S', $future_date ), ); - // insert a post and make sure the ID is ok + // Insert a post and make sure the ID is OK. $id = wp_insert_post( $post ); $this->post_ids[] = $id; - #dmp(_get_cron_array()); + // dmp( _get_cron_array() ); $this->assertTrue( is_numeric( $id ) ); $this->assertTrue( $id > 0 ); - // fetch the post and make sure it matches + // Fetch the post and make sure it matches. $out = get_post( $id ); $this->assertEquals( $post['post_content'], $out->post_content ); @@ -259,13 +270,15 @@ class Tests_Post extends WP_UnitTestCase { $this->assertEquals( $post['post_author'], $out->post_author ); $this->assertEquals( $post['post_date'], $out->post_date ); - // there should be a publish_future_post hook scheduled on the future date + // There should be a publish_future_post hook scheduled on the future date. $this->assertEquals( false, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); } + /** + * Insert a future post, then edit and change it to draft, and make sure cron gets it right. + */ function test_vb_insert_future_change_to_draft() { - // insert a future post, then edit and change it to draft, and make sure cron gets it right $future_date_1 = strtotime( '+1 day' ); $post = array( @@ -276,35 +289,37 @@ class Tests_Post extends WP_UnitTestCase { 'post_date' => strftime( '%Y-%m-%d %H:%M:%S', $future_date_1 ), ); - // insert a post and make sure the ID is ok + // Insert a post and make sure the ID is OK. $id = wp_insert_post( $post ); $this->post_ids[] = $id; - // fetch the post and make sure has the correct date and status + // Fetch the post and make sure has the correct date and status. $out = get_post( $id ); $this->assertEquals( 'future', $out->post_status ); $this->assertEquals( $post['post_date'], $out->post_date ); - // check that there's a publish_future_post job scheduled at the right time + // Check that there's a publish_future_post job scheduled at the right time. $this->assertEquals( $future_date_1, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); - // now save it again with status set to draft + // Now save it again with status set to draft. $post['ID'] = $id; $post['post_status'] = 'draft'; wp_update_post( $post ); - // fetch the post again and make sure it has the new post_date + // Fetch the post again and make sure it has the new post_date. $out = get_post( $id ); $this->assertEquals( 'draft', $out->post_status ); $this->assertEquals( $post['post_date'], $out->post_date ); - // and the correct date on the cron job + // And the correct date on the cron job. $this->assertEquals( false, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); } + /** + * Insert a future post, then edit and change the status, and make sure cron gets it right. + */ function test_vb_insert_future_change_status() { - // insert a future post, then edit and change the status, and make sure cron gets it right $future_date_1 = strtotime( '+1 day' ); $statuses = array( 'draft', 'static', 'object', 'attachment', 'inherit', 'pending' ); @@ -318,37 +333,38 @@ class Tests_Post extends WP_UnitTestCase { 'post_date' => strftime( '%Y-%m-%d %H:%M:%S', $future_date_1 ), ); - // insert a post and make sure the ID is ok + // Insert a post and make sure the ID is OK. $id = wp_insert_post( $post ); $this->post_ids[] = $id; - // fetch the post and make sure has the correct date and status + // Fetch the post and make sure has the correct date and status. $out = get_post( $id ); $this->assertEquals( 'future', $out->post_status ); $this->assertEquals( $post['post_date'], $out->post_date ); - // check that there's a publish_future_post job scheduled at the right time + // Check that there's a publish_future_post job scheduled at the right time. $this->assertEquals( $future_date_1, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); - // now save it again with status changed + // Now save it again with status changed. $post['ID'] = $id; $post['post_status'] = $status; wp_update_post( $post ); - // fetch the post again and make sure it has the new post_date + // Fetch the post again and make sure it has the new post_date. $out = get_post( $id ); $this->assertEquals( $status, $out->post_status ); $this->assertEquals( $post['post_date'], $out->post_date ); - // and the correct date on the cron job + // And the correct date on the cron job. $this->assertEquals( false, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); } } + /** + * Insert a draft post with a future date, and make sure no cron schedule is set. + */ function test_vb_insert_future_private() { - // insert a draft post with a future date, and make sure no cron schedule is set - $future_date = strtotime( '+1 day' ); $post = array( @@ -359,14 +375,14 @@ class Tests_Post extends WP_UnitTestCase { 'post_date' => strftime( '%Y-%m-%d %H:%M:%S', $future_date ), ); - // insert a post and make sure the ID is ok + // Insert a post and make sure the ID is OK. $id = wp_insert_post( $post ); $this->post_ids[] = $id; - #dmp(_get_cron_array()); + // dmp( _get_cron_array() ); $this->assertTrue( is_numeric( $id ) ); $this->assertTrue( $id > 0 ); - // fetch the post and make sure it matches + // Fetch the post and make sure it matches. $out = get_post( $id ); $this->assertEquals( $post['post_content'], $out->post_content ); @@ -375,16 +391,16 @@ class Tests_Post extends WP_UnitTestCase { $this->assertEquals( $post['post_author'], $out->post_author ); $this->assertEquals( $post['post_date'], $out->post_date ); - // there should be a publish_future_post hook scheduled on the future date + // There should be a publish_future_post hook scheduled on the future date. $this->assertEquals( false, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); } /** + * Insert a post with an invalid date, make sure it fails. + * * @ticket 17180 */ function test_vb_insert_invalid_date() { - // insert a post with an invalid date, make sure it fails - $post = array( 'post_author' => self::$editor_id, 'post_status' => 'public', @@ -393,7 +409,7 @@ class Tests_Post extends WP_UnitTestCase { 'post_date' => '2012-02-30 00:00:00', ); - // Test both return paths with or without WP_Error + // Test both return paths with or without WP_Error. $insert_post = wp_insert_post( $post, true ); $this->assertWPError( $insert_post ); $this->assertEquals( 'invalid_date', $insert_post->get_error_code() ); @@ -402,8 +418,10 @@ class Tests_Post extends WP_UnitTestCase { $this->assertEquals( 0, $insert_post ); } + /** + * Insert a future post, then edit and change it to private, and make sure cron gets it right. + */ function test_vb_insert_future_change_to_private() { - // insert a future post, then edit and change it to private, and make sure cron gets it right $future_date_1 = strtotime( '+1 day' ); $post = array( @@ -414,30 +432,30 @@ class Tests_Post extends WP_UnitTestCase { 'post_date' => strftime( '%Y-%m-%d %H:%M:%S', $future_date_1 ), ); - // insert a post and make sure the ID is ok + // Insert a post and make sure the ID is OK. $id = wp_insert_post( $post ); $this->post_ids[] = $id; - // fetch the post and make sure has the correct date and status + // Fetch the post and make sure has the correct date and status. $out = get_post( $id ); $this->assertEquals( 'future', $out->post_status ); $this->assertEquals( $post['post_date'], $out->post_date ); - // check that there's a publish_future_post job scheduled at the right time + // Check that there's a publish_future_post job scheduled at the right time. $this->assertEquals( $future_date_1, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); - // now save it again with status set to draft + // Now save it again with status set to draft. $post['ID'] = $id; $post['post_status'] = 'private'; wp_update_post( $post ); - // fetch the post again and make sure it has the new post_date + // Fetch the post again and make sure it has the new post_date. $out = get_post( $id ); $this->assertEquals( 'private', $out->post_status ); $this->assertEquals( $post['post_date'], $out->post_date ); - // and the correct date on the cron job + // And the correct date on the cron job. $this->assertEquals( false, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); } @@ -505,10 +523,11 @@ class Tests_Post extends WP_UnitTestCase { } /** + * "When I delete a future post using wp_delete_post( $post->ID ) it does not update the cron correctly." + * * @ticket 5364 */ function test_delete_future_post_cron() { - // "When I delete a future post using wp_delete_post($post->ID) it does not update the cron correctly." $future_date = strtotime( '+1 day' ); $post = array( @@ -519,26 +538,27 @@ class Tests_Post extends WP_UnitTestCase { 'post_date' => strftime( '%Y-%m-%d %H:%M:%S', $future_date ), ); - // insert a post and make sure the ID is ok + // Insert a post and make sure the ID is OK. $id = wp_insert_post( $post ); $this->post_ids[] = $id; - // check that there's a publish_future_post job scheduled at the right time + // Check that there's a publish_future_post job scheduled at the right time. $this->assertEquals( $future_date, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); - // now delete the post and make sure the cron entry is removed + // Now delete the post and make sure the cron entry is removed. wp_delete_post( $id ); $this->assertFalse( $this->_next_schedule_for_post( 'publish_future_post', $id ) ); } /** + * Bug: permalink doesn't work if post title is empty. + * + * Might only fail if the post ID is greater than four characters. + * * @ticket 5305 */ function test_permalink_without_title() { - // bug: permalink doesn't work if post title is empty - // might only fail if the post ID is greater than four characters - $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); $post = array( @@ -549,13 +569,13 @@ class Tests_Post extends WP_UnitTestCase { 'post_date' => '2007-10-31 06:15:00', ); - // insert a post and make sure the ID is ok + // Insert a post and make sure the ID is OK. $id = wp_insert_post( $post ); $this->post_ids[] = $id; $plink = get_permalink( $id ); - // permalink should include the post ID at the end + // Permalink should include the post ID at the end. $this->assertEquals( get_option( 'siteurl' ) . '/2007/10/31/' . $id . '/', $plink ); } @@ -1106,7 +1126,7 @@ class Tests_Post extends WP_UnitTestCase { function test_user_without_publish_cannot_affect_sticky() { wp_set_current_user( self::$grammarian_id ); - // Sanity Check. + // Sanity check. $this->assertFalse( current_user_can( 'publish_posts' ) ); $this->assertTrue( current_user_can( 'edit_others_posts' ) ); $this->assertTrue( current_user_can( 'edit_published_posts' ) ); @@ -1120,7 +1140,7 @@ class Tests_Post extends WP_UnitTestCase { ); stick_post( $post->ID ); - // Sanity Check. + // Sanity check. $this->assertTrue( is_sticky( $post->ID ) ); // Edit the post. @@ -1151,17 +1171,17 @@ class Tests_Post extends WP_UnitTestCase { ); stick_post( $post->ID ); - // Sanity Check. + // Sanity check. $this->assertTrue( is_sticky( $post->ID ) ); wp_set_current_user( self::$grammarian_id ); - // Sanity Check. + // Sanity check. $this->assertFalse( current_user_can( 'publish_posts' ) ); $this->assertTrue( current_user_can( 'edit_others_posts' ) ); $this->assertTrue( current_user_can( 'edit_published_posts' ) ); - // Edit the post - The key 'sticky' is intentionally unset. + // Edit the post - the key 'sticky' is intentionally unset. $data = array( 'post_ID' => $post->ID, 'post_title' => 'Updated', @@ -1169,7 +1189,7 @@ class Tests_Post extends WP_UnitTestCase { ); edit_post( $data ); - // Make sure it's still sticky + // Make sure it's still sticky. $saved_post = get_post( $post->ID ); $this->assertTrue( is_sticky( $saved_post->ID ) ); $this->assertEquals( 'Updated', $saved_post->post_title ); @@ -1259,7 +1279,7 @@ class Tests_Post extends WP_UnitTestCase { 'post_date_gmt' => '2014-01-01 12:00:00', ); - // insert a post and make sure the ID is ok + // Insert a post and make sure the ID is OK. $id = wp_insert_post( $post ); $out = get_post( $id ); diff --git a/tests/phpunit/tests/post/attachments.php b/tests/phpunit/tests/post/attachments.php index 70255d5bec..86f167ef2d 100644 --- a/tests/phpunit/tests/post/attachments.php +++ b/tests/phpunit/tests/post/attachments.php @@ -23,7 +23,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase { function test_insert_image_no_thumb() { - // this image is smaller than the thumbnail size so it won't have one + // This image is smaller than the thumbnail size so it won't have one. $filename = ( DIR_TESTDATA . '/images/test-image.jpg' ); $contents = file_get_contents( $filename ); @@ -32,12 +32,12 @@ class Tests_Post_Attachments extends WP_UnitTestCase { $id = $this->_make_attachment( $upload ); - // intermediate copies should not exist + // Intermediate copies should not exist. $this->assertFalse( image_get_intermediate_size( $id, 'thumbnail' ) ); $this->assertFalse( image_get_intermediate_size( $id, 'medium' ) ); $this->assertFalse( image_get_intermediate_size( $id, 'medium_large' ) ); - // medium, medium_large, and full size will both point to the original + // medium, medium_large, and full size will both point to the original. $downsize = image_downsize( $id, 'medium' ); $this->assertEquals( wp_basename( $upload['file'] ), wp_basename( $downsize[0] ) ); $this->assertEquals( 50, $downsize[1] ); @@ -71,7 +71,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase { $id = $this->_make_attachment( $upload ); - // intermediate copies should exist: thumbnail only + // Intermediate copies should exist: thumbnail only. $thumb = image_get_intermediate_size( $id, 'thumbnail' ); $this->assertEquals( 'a2-small-150x150.jpg', $thumb['file'] ); @@ -81,16 +81,16 @@ class Tests_Post_Attachments extends WP_UnitTestCase { $this->assertFalse( image_get_intermediate_size( $id, 'medium' ) ); $this->assertFalse( image_get_intermediate_size( $id, 'medium_large' ) ); - // the thumb url should point to the thumbnail intermediate + // The thumb url should point to the thumbnail intermediate. $this->assertEquals( $thumb['url'], wp_get_attachment_thumb_url( $id ) ); - // image_downsize() should return the correct images and sizes + // image_downsize() should return the correct images and sizes. $downsize = image_downsize( $id, 'thumbnail' ); $this->assertEquals( 'a2-small-150x150.jpg', wp_basename( $downsize[0] ) ); $this->assertEquals( 150, $downsize[1] ); $this->assertEquals( 150, $downsize[2] ); - // medium, medium_large, and full will both point to the original + // medium, medium_large, and full will both point to the original. $downsize = image_downsize( $id, 'medium' ); $this->assertEquals( 'a2-small.jpg', wp_basename( $downsize[0] ) ); $this->assertEquals( 400, $downsize[1] ); @@ -128,7 +128,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase { $id = $this->_make_attachment( $upload ); $uploads = wp_upload_dir(); - // intermediate copies should exist: thumbnail and medium + // Intermediate copies should exist: thumbnail and medium. $thumb = image_get_intermediate_size( $id, 'thumbnail' ); $this->assertEquals( '2007-06-17DSC_4173-150x150.jpg', $thumb['file'] ); $this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $thumb['path'] ) ); @@ -141,10 +141,10 @@ class Tests_Post_Attachments extends WP_UnitTestCase { $this->assertEquals( '2007-06-17DSC_4173-600x904.jpg', $medium_large['file'] ); $this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $medium_large['path'] ) ); - // the thumb url should point to the thumbnail intermediate + // The thumb url should point to the thumbnail intermediate. $this->assertEquals( $thumb['url'], wp_get_attachment_thumb_url( $id ) ); - // image_downsize() should return the correct images and sizes + // image_downsize() should return the correct images and sizes. $downsize = image_downsize( $id, 'thumbnail' ); $this->assertEquals( '2007-06-17DSC_4173-150x150.jpg', wp_basename( $downsize[0] ) ); $this->assertEquals( 150, $downsize[1] ); @@ -187,7 +187,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase { $id = $this->_make_attachment( $upload ); $uploads = wp_upload_dir(); - // check that the file and intermediates exist + // Check that the file and intermediates exist. $thumb = image_get_intermediate_size( $id, 'thumbnail' ); $this->assertEquals( '2007-06-17DSC_4173-150x150.jpg', $thumb['file'] ); $this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $thumb['path'] ) ); @@ -204,7 +204,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase { $original = $meta['file']; $this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $original ) ); - // now delete the attachment and make sure all files are gone + // Now delete the attachment and make sure all files are gone. wp_delete_attachment( $id ); $this->assertFalse( is_file( $thumb['path'] ) ); @@ -220,7 +220,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase { * @ticket 21963 */ function test_insert_image_without_guid() { - // this image is smaller than the thumbnail size so it won't have one + // This image is smaller than the thumbnail size so it won't have one. $filename = ( DIR_TESTDATA . '/images/test-image.jpg' ); $contents = file_get_contents( $filename ); @@ -272,7 +272,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase { $attachment_id = $this->_make_attachment( $upload ); - // Assert that the attachment is an orphan + // Assert that the attachment is an orphan. $attachment = get_post( $attachment_id ); $this->assertEquals( $attachment->post_parent, 0 ); @@ -283,7 +283,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase { ) ); - // Assert that the attachment has a parent + // Assert that the attachment has a parent. wp_insert_attachment( $attachment, '', $post_id ); $attachment = get_post( $attachment_id ); $this->assertEquals( $attachment->post_parent, $post_id ); @@ -352,7 +352,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase { $upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); $this->assertTrue( empty( $upload['error'] ) ); - // Set attachment ID + // Set attachment ID. $attachment_id = $this->_make_attachment( $upload ); $_SERVER['HTTPS'] = 'on'; @@ -408,7 +408,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase { $upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); $this->assertTrue( empty( $upload['error'] ) ); - // Set attachment ID + // Set attachment ID. $attachment_id = $this->_make_attachment( $upload ); $_SERVER['HTTPS'] = 'on'; @@ -426,7 +426,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase { * @ticket 15928 */ public function test_wp_get_attachment_url_should_force_https_when_administering_over_https_and_siteurl_is_https() { - // Set https upload URL + // Set https upload URL. add_filter( 'upload_dir', '_upload_dir_https' ); $filename = ( DIR_TESTDATA . '/images/test-image.jpg' ); @@ -435,7 +435,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase { $upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); $this->assertTrue( empty( $upload['error'] ) ); - // Set attachment ID + // Set attachment ID. $attachment_id = $this->_make_attachment( $upload ); $_SERVER['HTTPS'] = 'on'; diff --git a/tests/phpunit/tests/post/filtering.php b/tests/phpunit/tests/post/filtering.php index dc88930215..937fdc3196 100644 --- a/tests/phpunit/tests/post/filtering.php +++ b/tests/phpunit/tests/post/filtering.php @@ -1,9 +1,11 @@ assertEquals( $expected, $post->post_content ); } - // a simple test to make sure unbalanced tags are fixed + // A simple test to make sure unbalanced tags are fixed. function test_post_content_unbalanced_tag() { $content = <<assertEquals( $expected, $post->post_content ); } - // test kses filtering of disallowed attribute + // Test KSES filtering of disallowed attribute. function test_post_content_disallowed_attr() { $content = <<assertEquals( $expected, $post->post_content ); } - // make sure unbalanced tags are untouched when the balance option is off + // Make sure unbalanced tags are untouched when the balance option is off. function test_post_content_nobalance_nextpage_more() { update_option( 'use_balanceTags', 0 ); diff --git a/tests/phpunit/tests/post/formats.php b/tests/phpunit/tests/post/formats.php index 961aa988e7..f18a821e4d 100644 --- a/tests/phpunit/tests/post/formats.php +++ b/tests/phpunit/tests/post/formats.php @@ -87,10 +87,10 @@ class Tests_Post_Formats extends WP_UnitTestCase { // Standard is a special case. It shows as false when set. $this->assertFalse( has_post_format( 'standard', $post_id ) ); - // Dummy format type + // Dummy format type. $this->assertFalse( has_post_format( 'dummy', $post_id ) ); - // Dummy post id + // Dummy post ID. $this->assertFalse( has_post_format( 'aside', 12345 ) ); } @@ -133,7 +133,7 @@ DATA; $content_link = get_url_in_content( get_post_field( 'post_content', $comm_post_id ) ); $this->assertEquals( false, $content_link ); - // Now with an href + // Now with an href. $href_post_id = self::factory()->post->create( array( 'post_content' => $href ) ); $content_link = get_url_in_content( get_post_field( 'post_content', $href_post_id ) ); $this->assertEquals( $link, $content_link ); diff --git a/tests/phpunit/tests/post/getPageUri.php b/tests/phpunit/tests/post/getPageUri.php index 8b82612b47..0c302914e6 100644 --- a/tests/phpunit/tests/post/getPageUri.php +++ b/tests/phpunit/tests/post/getPageUri.php @@ -40,13 +40,13 @@ class Tests_Post_getPageUri extends WP_UnitTestCase { ) ); - // check the parent for good measure + // Check the parent for good measure. $this->assertEquals( 'parent', get_page_uri( $parent_id ) ); - // try the child normally + // Try the child normally. $this->assertEquals( 'parent/child', get_page_uri( $child_id ) ); - // now delete the parent from the database and check + // Now delete the parent from the database and check. wp_delete_post( $parent_id, true ); $this->assertEquals( 'child', get_page_uri( $child_id ) ); } diff --git a/tests/phpunit/tests/post/getPages.php b/tests/phpunit/tests/post/getPages.php index b92ff088b9..e9e1126259 100644 --- a/tests/phpunit/tests/post/getPages.php +++ b/tests/phpunit/tests/post/getPages.php @@ -420,7 +420,7 @@ class Tests_Post_getPages extends WP_UnitTestCase { ) ); - $pages = get_pages(); // Defaults: hierarchical = true, parent = -1 + $pages = get_pages(); // Defaults: hierarchical = true, parent = -1. $pages_default_args = get_pages( array( 'hierarchical' => true, @@ -464,7 +464,7 @@ class Tests_Post_getPages extends WP_UnitTestCase { ) ); - $pages = get_pages(); // Defaults: hierarchical = true, child_of = '', parent = -1 + $pages = get_pages(); // Defaults: hierarchical = true, child_of = '', parent = -1. $default_args = get_pages( array( 'hierarchical' => true, @@ -510,7 +510,7 @@ class Tests_Post_getPages extends WP_UnitTestCase { ) ); - $pages = get_pages( array( 'hierarchical' => false ) ); // child_of = '', parent = -1 + $pages = get_pages( array( 'hierarchical' => false ) ); // child_of = '', parent = -1. /* * Page tree: @@ -713,13 +713,13 @@ class Tests_Post_getPages extends WP_UnitTestCase { $num_queries = $wpdb->num_queries; - $pages = get_pages(); // Database gets queried + $pages = get_pages(); // Database gets queried. $this->assertEquals( $num_queries + 1, $wpdb->num_queries ); $num_queries = $wpdb->num_queries; - $pages = get_pages(); // Database should not get queried + $pages = get_pages(); // Database should not get queried. $this->assertEquals( $num_queries, $wpdb->num_queries ); } diff --git a/tests/phpunit/tests/post/meta.php b/tests/phpunit/tests/post/meta.php index a79228c070..8876ce5cb0 100644 --- a/tests/phpunit/tests/post/meta.php +++ b/tests/phpunit/tests/post/meta.php @@ -45,51 +45,51 @@ class Tests_Post_Meta extends WP_UnitTestCase { } function test_unique_postmeta() { - // Add a unique post meta item + // Add a unique post meta item. $this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'unique', 'value', true ) ); - // Check unique is enforced + // Check unique is enforced. $this->assertFalse( add_post_meta( self::$post_id, 'unique', 'another value', true ) ); - //Check it exists + // Check it exists. $this->assertEquals( 'value', get_post_meta( self::$post_id, 'unique', true ) ); $this->assertEquals( array( 'value' ), get_post_meta( self::$post_id, 'unique', false ) ); - //Fail to delete the wrong value + // Fail to delete the wrong value. $this->assertFalse( delete_post_meta( self::$post_id, 'unique', 'wrong value' ) ); - //Delete it + // Delete it. $this->assertTrue( delete_post_meta( self::$post_id, 'unique', 'value' ) ); - //Check it is deleted + // Check it is deleted. $this->assertEquals( '', get_post_meta( self::$post_id, 'unique', true ) ); $this->assertEquals( array(), get_post_meta( self::$post_id, 'unique', false ) ); } function test_nonunique_postmeta() { - // Add two non unique post meta item + // Add two non-unique post meta items. $this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'nonunique', 'value' ) ); $this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'nonunique', 'another value' ) ); - //Check they exists + // Check they exist. $this->assertEquals( 'value', get_post_meta( self::$post_id, 'nonunique', true ) ); $this->assertEquals( array( 'value', 'another value' ), get_post_meta( self::$post_id, 'nonunique', false ) ); - //Fail to delete the wrong value + // Fail to delete the wrong value. $this->assertFalse( delete_post_meta( self::$post_id, 'nonunique', 'wrong value' ) ); - //Delete the first one + // Delete the first one. $this->assertTrue( delete_post_meta( self::$post_id, 'nonunique', 'value' ) ); - //Check the remainder exists + // Check the remainder exists. $this->assertEquals( 'another value', get_post_meta( self::$post_id, 'nonunique', true ) ); $this->assertEquals( array( 'another value' ), get_post_meta( self::$post_id, 'nonunique', false ) ); - //Add a third one + // Add a third one. $this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'nonunique', 'someother value' ) ); - //Check they exists + // Check they exist. $expected = array( 'someother value', 'another value', @@ -100,30 +100,30 @@ class Tests_Post_Meta extends WP_UnitTestCase { sort( $actual ); $this->assertEquals( $expected, $actual ); - //Delete the lot + // Delete the lot. $this->assertTrue( delete_post_meta_by_key( 'nonunique' ) ); } function test_update_post_meta() { - // Add a unique post meta item + // Add a unique post meta item. $this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'unique_update', 'value', true ) ); - // Add two non unique post meta item + // Add two non-unique post meta items. $this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'nonunique_update', 'value' ) ); $this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'nonunique_update', 'another value' ) ); - //Check they exists + // Check they exist. $this->assertEquals( 'value', get_post_meta( self::$post_id, 'unique_update', true ) ); $this->assertEquals( array( 'value' ), get_post_meta( self::$post_id, 'unique_update', false ) ); $this->assertEquals( 'value', get_post_meta( self::$post_id, 'nonunique_update', true ) ); $this->assertEquals( array( 'value', 'another value' ), get_post_meta( self::$post_id, 'nonunique_update', false ) ); - // Update them + // Update them. $this->assertTrue( update_post_meta( self::$post_id, 'unique_update', 'new', 'value' ) ); $this->assertTrue( update_post_meta( self::$post_id, 'nonunique_update', 'new', 'value' ) ); $this->assertTrue( update_post_meta( self::$post_id, 'nonunique_update', 'another new', 'another value' ) ); - //Check they updated + // Check they updated. $this->assertEquals( 'new', get_post_meta( self::$post_id, 'unique_update', true ) ); $this->assertEquals( array( 'new' ), get_post_meta( self::$post_id, 'unique_update', false ) ); $this->assertEquals( 'new', get_post_meta( self::$post_id, 'nonunique_update', true ) ); @@ -132,35 +132,35 @@ class Tests_Post_Meta extends WP_UnitTestCase { } function test_delete_post_meta() { - // Add a unique post meta item + // Add two unique post meta items. $this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'unique_delete', 'value', true ) ); $this->assertInternalType( 'integer', add_post_meta( self::$post_id_2, 'unique_delete', 'value', true ) ); - //Check they exists + // Check they exist. $this->assertEquals( 'value', get_post_meta( self::$post_id, 'unique_delete', true ) ); $this->assertEquals( 'value', get_post_meta( self::$post_id_2, 'unique_delete', true ) ); - //Delete one of them + // Delete one of them. $this->assertTrue( delete_post_meta( self::$post_id, 'unique_delete', 'value' ) ); - //Check the other still exitsts + // Check the other still exists. $this->assertEquals( 'value', get_post_meta( self::$post_id_2, 'unique_delete', true ) ); } function test_delete_post_meta_by_key() { - // Add a unique post meta item + // Add two unique post meta items. $this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'unique_delete_by_key', 'value', true ) ); $this->assertInternalType( 'integer', add_post_meta( self::$post_id_2, 'unique_delete_by_key', 'value', true ) ); - //Check they exist + // Check they exist. $this->assertEquals( 'value', get_post_meta( self::$post_id, 'unique_delete_by_key', true ) ); $this->assertEquals( 'value', get_post_meta( self::$post_id_2, 'unique_delete_by_key', true ) ); - //Delete one of them + // Delete one of them. $this->assertTrue( delete_post_meta_by_key( 'unique_delete_by_key' ) ); - //Check the other still exists + // Check the other still exists. $this->assertEquals( '', get_post_meta( self::$post_id_2, 'unique_delete_by_key', true ) ); $this->assertEquals( '', get_post_meta( self::$post_id_2, 'unique_delete_by_key', true ) ); } @@ -196,31 +196,31 @@ class Tests_Post_Meta extends WP_UnitTestCase { } function test_update_meta() { - // Add a unique post meta item + // Add a unique post meta item. $this->assertInternalType( 'integer', $mid1 = add_post_meta( self::$post_id, 'unique_update', 'value', true ) ); - // Add two non unique post meta item + // Add two non-unique post meta items. $this->assertInternalType( 'integer', $mid2 = add_post_meta( self::$post_id, 'nonunique_update', 'value' ) ); $this->assertInternalType( 'integer', $mid3 = add_post_meta( self::$post_id, 'nonunique_update', 'another value' ) ); - //Check they exist + // Check they exist. $this->assertEquals( 'value', get_post_meta( self::$post_id, 'unique_update', true ) ); $this->assertEquals( array( 'value' ), get_post_meta( self::$post_id, 'unique_update', false ) ); $this->assertEquals( 'value', get_post_meta( self::$post_id, 'nonunique_update', true ) ); $this->assertEquals( array( 'value', 'another value' ), get_post_meta( self::$post_id, 'nonunique_update', false ) ); - // Update them + // Update them. $this->assertTrue( update_meta( $mid1, 'unique_update', 'new' ) ); $this->assertTrue( update_meta( $mid2, 'nonunique_update', 'new' ) ); $this->assertTrue( update_meta( $mid3, 'nonunique_update', 'another new' ) ); - //Check they updated + // Check they updated. $this->assertEquals( 'new', get_post_meta( self::$post_id, 'unique_update', true ) ); $this->assertEquals( array( 'new' ), get_post_meta( self::$post_id, 'unique_update', false ) ); $this->assertEquals( 'new', get_post_meta( self::$post_id, 'nonunique_update', true ) ); $this->assertEquals( array( 'new', 'another new' ), get_post_meta( self::$post_id, 'nonunique_update', false ) ); - // Slashed update + // Slashed update. $data = "'quote and \slash"; $this->assertTrue( update_meta( $mid1, 'unique_update', addslashes( $data ) ) ); $meta = get_metadata_by_mid( 'post', $mid1 ); @@ -241,10 +241,10 @@ class Tests_Post_Meta extends WP_UnitTestCase { $classy->stringy = 'I love slashes\\\\ more'; $funky_meta[] = $classy; - // Add a post meta item + // Add a post meta item. $this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'test_funky_post_meta', $funky_meta, true ) ); - //Check they exists + // Check it exists. $this->assertEquals( $funky_meta, get_post_meta( self::$post_id, 'test_funky_post_meta', true ) ); } diff --git a/tests/phpunit/tests/post/nav-menu.php b/tests/phpunit/tests/post/nav-menu.php index 978580e186..0001bbce8a 100644 --- a/tests/phpunit/tests/post/nav-menu.php +++ b/tests/phpunit/tests/post/nav-menu.php @@ -83,7 +83,7 @@ class Test_Nav_Menus extends WP_UnitTestCase { ) ); - // Item without menu-item-object arg + // Item without menu-item-object arg. $post_2_insert = wp_update_nav_menu_item( $this->menu_id, 0, @@ -142,7 +142,7 @@ class Test_Nav_Menus extends WP_UnitTestCase { */ function test_orphan_nav_menu_item() { - // Create an orphan nav menu item + // Create an orphan nav menu item. $custom_item_id = wp_update_nav_menu_item( 0, 0, @@ -154,11 +154,11 @@ class Test_Nav_Menus extends WP_UnitTestCase { ) ); - // Confirm it saved properly + // Confirm it saved properly. $custom_item = wp_setup_nav_menu_item( get_post( $custom_item_id ) ); $this->assertEquals( 'Wordpress.org', $custom_item->title ); - // Update the orphan with an associated nav menu + // Update the orphan with an associated nav menu. wp_update_nav_menu_item( $this->menu_id, $custom_item_id, @@ -225,14 +225,14 @@ class Test_Nav_Menus extends WP_UnitTestCase { * @ticket 29460 */ function test_orderby_name_by_default() { - // We are going to create a random number of menus (min 2, max 10) + // We are going to create a random number of menus (min 2, max 10). $menus_no = rand( 2, 10 ); for ( $i = 0; $i <= $menus_no; $i++ ) { wp_create_nav_menu( rand_str() ); } - // This is the expected array of menu names + // This is the expected array of menu names. $expected_nav_menus_names = wp_list_pluck( get_terms( 'nav_menu', @@ -244,7 +244,7 @@ class Test_Nav_Menus extends WP_UnitTestCase { 'name' ); - // And this is what we got when calling wp_get_nav_menus() + // And this is what we got when calling wp_get_nav_menus(). $nav_menus_names = wp_list_pluck( wp_get_nav_menus(), 'name' ); $this->assertEquals( $nav_menus_names, $expected_nav_menus_names ); @@ -311,7 +311,7 @@ class Test_Nav_Menus extends WP_UnitTestCase { $post_type_archive_item = wp_setup_nav_menu_item( get_post( $post_type_archive_item_id ) ); $this->assertEquals( $post_type_slug, $post_type_archive_item->title ); - $this->assertEquals( $post_type_description, $post_type_archive_item->description ); //fail!!! + $this->assertEquals( $post_type_description, $post_type_archive_item->description ); // Fail! } /** @@ -459,11 +459,11 @@ class Test_Nav_Menus extends WP_UnitTestCase { ) ); - // The markup should include whitespace between
  • s + // The markup should include whitespace between
  • 's. $this->assertRegExp( '/\s|<\/li>\s/U', $menu ); $this->assertNotRegExp( '/<\/li>/U', $menu ); - // Whitepsace suppressed. + // Whitespace suppressed. $menu = wp_nav_menu( array( 'echo' => false, @@ -472,7 +472,7 @@ class Test_Nav_Menus extends WP_UnitTestCase { ) ); - // The markup should not include whitespace around
  • s + // The markup should not include whitespace around
  • 's. $this->assertNotRegExp( '/\s|<\/li>\s/U', $menu ); $this->assertRegExp( '/>|<\/li>assertTrue( isset( $post->ancestors ) ); $this->assertEquals( array(), $post->ancestors ); - // Unset and then verify that the magic method fills the property again + // Unset and then verify that the magic method fills the property again. unset( $post->ancestors ); $this->assertEquals( array(), $post->ancestors ); - // Magic get should make meta accessible as properties + // Magic get should make meta accessible as properties. add_post_meta( $id, 'test', 'test' ); $this->assertEquals( 'test', get_post_meta( $id, 'test', true ) ); $this->assertEquals( 'test', $post->test ); - // Make sure meta does not eclipse true properties + // Make sure meta does not eclipse true properties. add_post_meta( $id, 'post_type', 'dummy' ); $this->assertEquals( 'dummy', get_post_meta( $id, 'post_type', true ) ); $this->assertEquals( 'post', $post->post_type ); - // Excercise the output argument + // Excercise the output argument. $post = get_post( $id, ARRAY_A ); $this->assertInternalType( 'array', $post ); $this->assertEquals( 'post', $post['post_type'] ); @@ -44,12 +44,12 @@ class Tests_Post_Objects extends WP_UnitTestCase { $this->assertEquals( 'post', $post['post_type'] ); $this->assertEquals( $id, $post['ID'] ); - // Should default to OBJECT when given invalid output argument + // Should default to OBJECT when given invalid output argument. $post = get_post( $id, 'invalid-output-value' ); $this->assertInstanceOf( 'WP_Post', $post ); $this->assertEquals( $id, $post->ID ); - // Make sure stdClass in $GLOBALS['post'] is handled + // Make sure stdClass in $GLOBALS['post'] is handled. $post_std = $post->to_array(); $this->assertInternalType( 'array', $post_std ); $post_std = (object) $post_std; @@ -213,16 +213,16 @@ class Tests_Post_Objects extends WP_UnitTestCase { $id = self::factory()->post->create(); wp_cache_delete( $id, 'posts' ); - // get_post( stdClass ) should not prime the cache + // get_post( stdClass ) should not prime the cache. $post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $id ) ); $post = get_post( $post ); $this->assertEmpty( wp_cache_get( $id, 'posts' ) ); - // get_post( WP_Post ) should not prime the cache + // get_post( WP_Post ) should not prime the cache. get_post( $post ); $this->assertEmpty( wp_cache_get( $id, 'posts' ) ); - // get_post( ID ) should prime the cache + // get_post( ID ) should prime the cache. get_post( $post->ID ); $this->assertNotEmpty( wp_cache_get( $id, 'posts' ) ); } diff --git a/tests/phpunit/tests/post/output.php b/tests/phpunit/tests/post/output.php index 02be7ffa6e..3e6ae1ea9d 100644 --- a/tests/phpunit/tests/post/output.php +++ b/tests/phpunit/tests/post/output.php @@ -1,8 +1,8 @@ Mariat, D., Taourit, S., Guérin, G. (2003). . Genetics Selection Evolution, 35(1), 119-133. DOI: 10.1051/gse:2002039 EOF; @@ -156,7 +156,7 @@ EOF; kses_init_filters(); // http://bpr3.org/?p=87 - // the title attribute should make it through unfiltered + // The title attribute should make it through unfiltered. $post_content = <<foo EOF; diff --git a/tests/phpunit/tests/post/query.php b/tests/phpunit/tests/post/query.php index 4bac94c1bc..0659f2d613 100644 --- a/tests/phpunit/tests/post/query.php +++ b/tests/phpunit/tests/post/query.php @@ -95,19 +95,19 @@ class Tests_Post_Query extends WP_UnitTestCase { ) ); - // Fourth post added in filter + // Fourth post added in filter. $this->assertEquals( 4, count( $query->posts ) ); $this->assertEquals( 4, $query->post_count ); foreach ( $query->posts as $post ) { - // posts are WP_Post objects + // Posts are WP_Post objects. $this->assertTrue( is_a( $post, 'WP_Post' ) ); - // filters are raw + // Filters are raw. $this->assertEquals( 'raw', $post->filter ); - // custom data added in the_posts filter is preserved + // Custom data added in the_posts filter is preserved. $this->assertEquals( array( $post->ID, 'custom data' ), $post->custom_data ); } @@ -408,31 +408,31 @@ class Tests_Post_Query extends WP_UnitTestCase { * @ticket 29629 */ function test_orderby() { - // 'rand' is a valid value + // 'rand' is a valid value. $q = new WP_Query( array( 'orderby' => 'rand' ) ); $this->assertContains( 'ORDER BY RAND()', $q->request ); $this->assertNotContains( 'ASC', $q->request ); $this->assertNotContains( 'DESC', $q->request ); - // This isn't allowed + // This isn't allowed. $q2 = new WP_Query( array( 'order' => 'rand' ) ); $this->assertContains( 'ORDER BY', $q2->request ); $this->assertNotContains( 'RAND()', $q2->request ); $this->assertContains( 'DESC', $q2->request ); - // 'none' is a valid value + // 'none' is a valid value. $q3 = new WP_Query( array( 'orderby' => 'none' ) ); $this->assertNotContains( 'ORDER BY', $q3->request ); $this->assertNotContains( 'DESC', $q3->request ); $this->assertNotContains( 'ASC', $q3->request ); - // false is a valid value + // False is a valid value. $q4 = new WP_Query( array( 'orderby' => false ) ); $this->assertNotContains( 'ORDER BY', $q4->request ); $this->assertNotContains( 'DESC', $q4->request ); $this->assertNotContains( 'ASC', $q4->request ); - // empty array() is a valid value + // Empty array() is a valid value. $q5 = new WP_Query( array( 'orderby' => array() ) ); $this->assertNotContains( 'ORDER BY', $q5->request ); $this->assertNotContains( 'DESC', $q5->request ); @@ -566,11 +566,11 @@ class Tests_Post_Query extends WP_UnitTestCase { $this->post_id = self::factory()->post->create(); - // Prevent the DB query + // Prevent the DB query. add_filter( 'posts_request', '__return_empty_string' ); add_filter( 'found_posts_query', '__return_empty_string' ); - // Add the post and found_posts + // Add the post and found_posts. add_filter( 'the_posts', array( $this, 'filter_the_posts' ) ); add_filter( 'found_posts', array( $this, 'filter_found_posts' ) ); @@ -690,7 +690,7 @@ class Tests_Post_Query extends WP_UnitTestCase { } public function set_found_posts_provider() { - // count return 0 for null, but 1 for other data you may not expect + // Count return 0 for null, but 1 for other data you may not expect. return array( array( null, 0 ), array( '', 1 ), diff --git a/tests/phpunit/tests/post/revisions.php b/tests/phpunit/tests/post/revisions.php index b3927a537e..525dc2be88 100644 --- a/tests/phpunit/tests/post/revisions.php +++ b/tests/phpunit/tests/post/revisions.php @@ -32,7 +32,7 @@ class Tests_Post_Revisions extends WP_UnitTestCase { * @ticket 16215 */ function test_revision_restore_updates_edit_last_post_meta() { - //create a post as Author + // Create a post as Author. wp_set_current_user( self::$author_user_id ); $post = get_default_post_to_edit( 'post', true ); $post_id = $post->ID; @@ -45,7 +45,7 @@ class Tests_Post_Revisions extends WP_UnitTestCase { ) ); - //update post as Editor + // Update post as Editor. wp_set_current_user( self::$editor_user_id ); wp_update_post( array( @@ -54,7 +54,7 @@ class Tests_Post_Revisions extends WP_UnitTestCase { ) ); - //restore back as Admin + // Restore back as Admin. wp_set_current_user( self::$admin_user_id ); $revisions = wp_get_post_revisions( $post->ID ); $this->assertCount( 2, $revisions ); @@ -66,8 +66,8 @@ class Tests_Post_Revisions extends WP_UnitTestCase { wp_restore_post_revision( $lastrevision->ID ); - //is post_meta correctly set to revision author - $this->assertEquals( self::$admin_user_id, get_post_meta( $post_id, '_edit_last', true ) ); //after restoring user + // Is post_meta correctly set to revision author after restoring user? + $this->assertEquals( self::$admin_user_id, get_post_meta( $post_id, '_edit_last', true ) ); } /** @@ -89,37 +89,37 @@ class Tests_Post_Revisions extends WP_UnitTestCase { ) ); - $this->assertCount( 1, wp_get_post_revisions( $post_id ) ); // Just the initial revision + $this->assertCount( 1, wp_get_post_revisions( $post_id ) ); // Just the initial revision. - // First update + // First update. wp_update_post( array( 'post_content' => 'some updated content', 'ID' => $post_id, ) - ); + ); // First revision. - $this->assertCount( 2, wp_get_post_revisions( $post_id ) ); // should be 2 revisions so far + $this->assertCount( 2, wp_get_post_revisions( $post_id ) ); // Should be 2 revisions so far. - //update the post + // Update the post. wp_update_post( array( 'post_content' => 'new update for some updated content', 'ID' => $post_id, ) - ); //2nd revision - $this->assertCount( 3, wp_get_post_revisions( $post_id ) ); // should be 3 revision so far + ); // Second revision. + $this->assertCount( 3, wp_get_post_revisions( $post_id ) ); // Should be 3 revisions so far. - //next try to save another identical update, tests for patch that prevents storing duplicates + // Next, try to save another identical update, tests for patch that prevents storing duplicates. wp_update_post( array( 'post_content' => 'new update for some updated content', 'ID' => $post_id, ) - ); //content unchanged, shouldn't save - $this->assertCount( 3, wp_get_post_revisions( $post_id ) ); //should still be 3 revision + ); // Content unchanged, shouldn't save. + $this->assertCount( 3, wp_get_post_revisions( $post_id ) ); // Should still be 3 revisions. - //next try to save another update, same content, but new ttile, should save revision + // Next, try to save another update, same content, but new title, should save revision. wp_update_post( array( 'post_title' => 'some-post-changed', @@ -127,17 +127,17 @@ class Tests_Post_Revisions extends WP_UnitTestCase { 'ID' => $post_id, ) ); - $this->assertCount( 4, wp_get_post_revisions( $post_id ) ); //should be 4 revision + $this->assertCount( 4, wp_get_post_revisions( $post_id ) ); // Should be 4 revisions. - //next try to save another identical update + // Next, try to save another identical update. wp_update_post( array( 'post_title' => 'some-post-changed', 'post_content' => 'new update for some updated content', 'ID' => $post_id, ) - ); //content unchanged, shouldn't save - $this->assertCount( 4, wp_get_post_revisions( $post_id ) ); //should still be 4 revision + ); // Content unchanged, shouldn't save. + $this->assertCount( 4, wp_get_post_revisions( $post_id ) ); // Should still be 4 revisions. } /** @@ -164,33 +164,34 @@ class Tests_Post_Revisions extends WP_UnitTestCase { $this->assertCount( 1, wp_get_post_revisions( $post_id ) ); + // First update. wp_update_post( array( 'post_content' => 'some updated content', 'ID' => $post_id, ) - ); //1st revision + ); // First revision. $this->assertCount( 2, wp_get_post_revisions( $post_id ) ); - //update the post + // Update the post. wp_update_post( array( 'post_content' => 'new update for some updated content', 'ID' => $post_id, ) - ); //2nd revision + ); // Second revision. $this->assertCount( 3, wp_get_post_revisions( $post_id ) ); - //next try to save another identical update, tests for patch that prevents storing duplicates + // Next, try to save another identical update, tests for patch that prevents storing duplicates. wp_update_post( array( 'post_content' => 'new update for some updated content', 'ID' => $post_id, ) - ); //content unchanged, shouldn't save + ); // Content unchanged, shouldn't save. $this->assertCount( 4, wp_get_post_revisions( $post_id ) ); - //next try to save another update, same content, but new ttile, should save revision + // Next, try to save another update, same content, but new title, should save revision. wp_update_post( array( 'post_title' => 'some-post-changed', @@ -200,14 +201,14 @@ class Tests_Post_Revisions extends WP_UnitTestCase { ); $this->assertCount( 5, wp_get_post_revisions( $post_id ) ); - //next try to save another identical update + // Next, try to save another identical update. wp_update_post( array( 'post_title' => 'some-post-changed', 'post_content' => 'new update for some updated content', 'ID' => $post_id, ) - ); //content unchanged, shouldn't save + ); // Content unchanged, shouldn't save. $this->assertCount( 6, wp_get_post_revisions( $post_id ) ); remove_filter( 'wp_save_post_revision_check_for_changes', '__return_false' ); @@ -240,7 +241,7 @@ class Tests_Post_Revisions extends WP_UnitTestCase { $this->assertTrue( user_can( self::$editor_user_id, 'read_post', $revision->ID ) ); } - // Author should be able to view the revisions fine + // Author should be able to view the revisions fine. foreach ( $revisions as $revision ) { $this->assertTrue( user_can( self::$author_user_id, 'read_post', $revision->ID ) ); } @@ -271,7 +272,7 @@ class Tests_Post_Revisions extends WP_UnitTestCase { $this->assertTrue( user_can( self::$editor_user_id, 'edit_post', $revision->post_parent ) ); } - // Author shouldn't be able to restore the revisions + // Author shouldn't be able to restore the revisions. foreach ( $revisions as $revision ) { $this->assertFalse( user_can( self::$author_user_id, 'edit_post', $revision->post_parent ) ); } @@ -302,14 +303,14 @@ class Tests_Post_Revisions extends WP_UnitTestCase { ) ); - // Diff checks if you can read both left and right revisions + // Diff checks if you can read both left and right revisions. $revisions = wp_get_post_revisions( $post_id ); $this->assertCount( 2, $revisions ); foreach ( $revisions as $revision ) { $this->assertTrue( user_can( self::$editor_user_id, 'read_post', $revision->ID ) ); } - // Author should be able to diff the revisions fine + // Author should be able to diff the revisions fine. foreach ( $revisions as $revision ) { $this->assertTrue( user_can( self::$author_user_id, 'read_post', $revision->ID ) ); } @@ -351,7 +352,7 @@ class Tests_Post_Revisions extends WP_UnitTestCase { $this->assertTrue( user_can( self::$editor_user_id, 'read_post', $revision->ID ) ); } - // Author should be able to view the revisions fine + // Author should be able to view the revisions fine. foreach ( $revisions as $revision ) { $this->assertTrue( user_can( self::$author_user_id, 'read_post', $revision->ID ) ); } @@ -376,7 +377,7 @@ class Tests_Post_Revisions extends WP_UnitTestCase { $editor_user = new WP_User( self::$editor_user_id ); $editor_user->add_cap( 'edit_published_events' ); - //create a post as Editor + // Create a post as Editor. $post_id = self::factory()->post->create( array( 'post_type' => $this->post_type, @@ -396,7 +397,7 @@ class Tests_Post_Revisions extends WP_UnitTestCase { $this->assertTrue( user_can( self::$editor_user_id, 'edit_post', $revision->post_parent ) ); } - // Author shouldn't be able to restore the revisions + // Author shouldn't be able to restore the revisions. wp_set_current_user( self::$author_user_id ); foreach ( $revisions as $revision ) { $this->assertFalse( user_can( self::$author_user_id, 'edit_post', $revision->post_parent ) ); @@ -497,14 +498,14 @@ class Tests_Post_Revisions extends WP_UnitTestCase { ) ); - // Diff checks if you can read both left and right revisions + // Diff checks if you can read both left and right revisions. $revisions = wp_get_post_revisions( $post_id ); $this->assertCount( 2, $revisions ); foreach ( $revisions as $revision ) { $this->assertTrue( user_can( self::$editor_user_id, 'read_post', $revision->ID ) ); } - // Author should be able to diff the revisions fine + // Author should be able to diff the revisions fine. foreach ( $revisions as $revision ) { $this->assertTrue( user_can( self::$author_user_id, 'read_post', $revision->ID ) ); } diff --git a/tests/phpunit/tests/post/slashes.php b/tests/phpunit/tests/post/slashes.php index 8187b3cd3c..c50abd4267 100644 --- a/tests/phpunit/tests/post/slashes.php +++ b/tests/phpunit/tests/post/slashes.php @@ -12,8 +12,8 @@ class Tests_Post_Slashes extends WP_UnitTestCase { wp_set_current_user( $this->author_id ); - // it is important to test with both even and odd numbered slashes as - // kses does a strip-then-add slashes in some of its function calls + // It is important to test with both even and odd numbered slashes, + // as KSES does a strip-then-add slashes in some of its function calls. $this->slash_1 = 'String with 1 slash \\'; $this->slash_2 = 'String with 2 slashes \\\\'; $this->slash_3 = 'String with 3 slashes \\\\\\'; @@ -24,7 +24,7 @@ class Tests_Post_Slashes extends WP_UnitTestCase { } /** - * Tests the controller function that expects slashed data + * Tests the controller function that expects slashed data. */ function test_edit_post() { $id = self::factory()->post->create(); @@ -34,7 +34,8 @@ class Tests_Post_Slashes extends WP_UnitTestCase { $_POST['post_title'] = $this->slash_1; $_POST['content'] = $this->slash_5; $_POST['excerpt'] = $this->slash_7; - $_POST = add_magic_quotes( $_POST ); // the edit_post() function will strip slashes + + $_POST = add_magic_quotes( $_POST ); // The edit_post() function will strip slashes. $post_id = edit_post(); $post = get_post( $post_id ); @@ -48,7 +49,8 @@ class Tests_Post_Slashes extends WP_UnitTestCase { $_POST['post_title'] = $this->slash_2; $_POST['content'] = $this->slash_4; $_POST['excerpt'] = $this->slash_6; - $_POST = add_magic_quotes( $_POST ); + + $_POST = add_magic_quotes( $_POST ); // The edit_post() function will strip slashes. $post_id = edit_post(); $post = get_post( $post_id ); @@ -59,7 +61,7 @@ class Tests_Post_Slashes extends WP_UnitTestCase { } /** - * Tests the model function that expects slashed data + * Tests the model function that expects slashed data. */ function test_wp_insert_post() { $id = wp_insert_post( @@ -95,7 +97,7 @@ class Tests_Post_Slashes extends WP_UnitTestCase { } /** - * Tests the model function that expects slashed data + * Tests the model function that expects slashed data. */ function test_wp_update_post() { $id = self::factory()->post->create(); diff --git a/tests/phpunit/tests/post/template.php b/tests/phpunit/tests/post/template.php index 56d26cf77b..5f9b233067 100644 --- a/tests/phpunit/tests/post/template.php +++ b/tests/phpunit/tests/post/template.php @@ -424,7 +424,7 @@ NO; // After falling back, the 'after' argument should be set and output as ''. $this->assertRegExp( '/<\/ul><\/div>/', $menu ); - // After falling back, the markup should include whitespace around
  • s + // After falling back, the markup should include whitespace around
  • 's. $this->assertRegExp( '/\s|<\/li>\s/U', $menu ); $this->assertNotRegExp( '/>|<\/li>s + // After falling back, the markup should not include whitespace around
  • 's. $this->assertNotRegExp( '/\s|<\/li>\s/U', $menu ); $this->assertRegExp( '/>|<\/li>assertInstanceOf( 'WP_Post_Type', $pobj ); $this->assertEquals( 'foo', $pobj->name ); - // Test some defaults + // Test some defaults. $this->assertFalse( is_post_type_hierarchical( 'foo' ) ); $this->assertEquals( array(), get_object_taxonomies( 'foo' ) ); @@ -45,7 +45,7 @@ class Tests_Post_Types extends WP_UnitTestCase { * @expectedIncorrectUsage register_post_type */ function test_register_post_type_with_too_long_name() { - // post type too long + // Post type too long. $this->assertInstanceOf( 'WP_Error', register_post_type( 'abcdefghijklmnopqrstuvwxyz0123456789' ) ); } @@ -55,7 +55,7 @@ class Tests_Post_Types extends WP_UnitTestCase { * @expectedIncorrectUsage register_post_type */ function test_register_post_type_with_empty_name() { - // post type too short + // Post type too short. $this->assertInstanceOf( 'WP_Error', register_post_type( '' ) ); } @@ -333,7 +333,7 @@ class Tests_Post_Types extends WP_UnitTestCase { $this->assertTrue( unregister_post_type( 'foo' ) ); $this->assertNotContains( '%foo%', $wp_rewrite->rewritecode ); $this->assertNotContains( 'bar=', $wp_rewrite->queryreplace ); - $this->assertSame( -- $count_before, count( $wp_rewrite->rewritereplace ) ); // Array was reduced by one value. + $this->assertSame( --$count_before, count( $wp_rewrite->rewritereplace ) ); // Array was reduced by one value. } /** diff --git a/tests/phpunit/tests/post/wpUniquePostSlug.php b/tests/phpunit/tests/post/wpUniquePostSlug.php index eb6d637389..a18e0df940 100644 --- a/tests/phpunit/tests/post/wpUniquePostSlug.php +++ b/tests/phpunit/tests/post/wpUniquePostSlug.php @@ -121,7 +121,7 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { $this->assertEquals( 'image', get_post( $attachment )->post_name ); $this->assertEquals( 'image-2', get_post( $two )->post_name ); - // 'image' can be a child of image-2 + // 'image' can be a child of image-2. $this->assertEquals( 'image', wp_unique_post_slug( 'image', 0, 'publish', 'post-type-1', $two ) ); _unregister_post_type( 'post-type-1' ); diff --git a/tests/phpunit/tests/query/commentCount.php b/tests/phpunit/tests/query/commentCount.php index 3614f4e8c1..4f5f3f2572 100644 --- a/tests/phpunit/tests/query/commentCount.php +++ b/tests/phpunit/tests/query/commentCount.php @@ -5,7 +5,7 @@ class Tests_Query_CommentCount extends WP_UnitTestCase { static $post_ids = array(); public $q; - static $post_type = 'page'; // can be anything + static $post_type = 'page'; // Can be anything. public function setUp() { parent::setUp(); diff --git a/tests/phpunit/tests/query/conditionals.php b/tests/phpunit/tests/query/conditionals.php index a67c6f29fc..14ebf2d860 100644 --- a/tests/phpunit/tests/query/conditionals.php +++ b/tests/phpunit/tests/query/conditionals.php @@ -187,16 +187,16 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { $url = get_permalink( $page_id ); $this->go_to( "{$url}trackback/" ); - // make sure the correct wp_query flags are set + // Make sure the correct WP_Query flags are set. $this->assertQueryTrue( 'is_page', 'is_singular', 'is_trackback' ); - // make sure the correct page was fetched + // Make sure the correct page was fetched. global $wp_query; $this->assertEquals( $page_id, $wp_query->get_queried_object()->ID ); } } - //'(about)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?pagename=$matches[1]&feed=$matches[2]' + // '(about)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?pagename=$matches[1]&feed=$matches[2]' function test_page_feed() { $page_ids = array(); $page_id = self::factory()->post->create( @@ -226,10 +226,10 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { $url = get_permalink( $page_id ); $this->go_to( "{$url}feed/" ); - // make sure the correct wp_query flags are set + // Make sure the correct WP_Query flags are set. $this->assertQueryTrue( 'is_page', 'is_singular', 'is_feed', 'is_comment_feed' ); - // make sure the correct page was fetched + // Make sure the correct page was fetched. global $wp_query; $this->assertEquals( $page_id, $wp_query->get_queried_object()->ID ); } @@ -263,10 +263,10 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { $url = get_permalink( $page_id ); $this->go_to( "{$url}feed/" ); - // make sure the correct wp_query flags are set + // Make sure the correct WP_Query flags are set. $this->assertQueryTrue( 'is_page', 'is_singular', 'is_feed', 'is_comment_feed' ); - // make sure the correct page was fetched + // Make sure the correct page was fetched. global $wp_query; $this->assertEquals( $page_id, $wp_query->get_queried_object()->ID ); } @@ -303,10 +303,10 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { $url = get_permalink( $page_id ); $this->go_to( "{$url}feed/atom/" ); - // make sure the correct wp_query flags are set + // Make sure the correct WP_Query flags are set. $this->assertQueryTrue( 'is_page', 'is_singular', 'is_feed', 'is_comment_feed' ); - // make sure the correct page was fetched + // Make sure the correct page was fetched. global $wp_query; $this->assertEquals( $page_id, $wp_query->get_queried_object()->ID ); } @@ -323,10 +323,10 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { ); $this->go_to( '/about/page/2/' ); - // make sure the correct wp_query flags are set + // Make sure the correct WP_Query flags are set. $this->assertQueryTrue( 'is_page', 'is_singular', 'is_paged' ); - // make sure the correct page was fetched + // Make sure the correct page was fetched. global $wp_query; $this->assertEquals( $page_id, $wp_query->get_queried_object()->ID ); } @@ -342,10 +342,10 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { ); $this->go_to( '/about/page2/' ); - // make sure the correct wp_query flags are set + // Make sure the correct WP_Query flags are set. $this->assertQueryTrue( 'is_page', 'is_singular', 'is_paged' ); - // make sure the correct page was fetched + // Make sure the correct page was fetched. global $wp_query; $this->assertEquals( $page_id, $wp_query->get_queried_object()->ID ); } @@ -366,7 +366,7 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { $this->assertQueryTrue( 'is_home', 'is_posts_page' ); - // make sure the correct page was fetched + // Make sure the correct page was fetched. global $wp_query; $this->assertEquals( $page_id, $wp_query->get_queried_object()->ID ); @@ -374,7 +374,7 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { delete_option( 'page_for_posts' ); } - // FIXME: no tests for these yet + // FIXME: no tests for these yet: // 'about/attachment/([^/]+)/?$' => 'index.php?attachment=$matches[1]', // 'about/attachment/([^/]+)/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1', // 'about/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', @@ -386,13 +386,13 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { self::factory()->post->create(); // @test_404 $feeds = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); - // long version + // Long version. foreach ( $feeds as $feed ) { $this->go_to( "/feed/{$feed}/" ); $this->assertQueryTrue( 'is_feed' ); } - // short version + // Short version. foreach ( $feeds as $feed ) { $this->go_to( "/{$feed}/" ); $this->assertQueryTrue( 'is_feed' ); @@ -425,18 +425,18 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { $post_id = self::factory()->post->create( array( 'post_title' => 'hello-world' ) ); self::factory()->comment->create_post_comments( $post_id, 2 ); - // check the url as generated by get_post_comments_feed_link() + // Check the URL as generated by get_post_comments_feed_link(). $this->go_to( get_post_comments_feed_link( $post_id ) ); $this->assertQueryTrue( 'is_feed', 'is_single', 'is_singular', 'is_comment_feed' ); - // check the long form + // Check the long form. $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); foreach ( $types as $type ) { $this->go_to( "/comments/feed/{$type}" ); $this->assertQueryTrue( 'is_feed', 'is_comment_feed' ); } - // check the short form + // Check the short form. $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); foreach ( $types as $type ) { $this->go_to( "/comments/{$type}" ); @@ -448,14 +448,14 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { // 'search/(.+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?s=$matches[1]&feed=$matches[2]', // 'search/(.+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?s=$matches[1]&feed=$matches[2]', function test_search_feed() { - // check the long form + // Check the long form. $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); foreach ( $types as $type ) { $this->go_to( "/search/test/feed/{$type}" ); $this->assertQueryTrue( 'is_feed', 'is_search' ); } - // check the short form + // Сheck the short form. $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); foreach ( $types as $type ) { $this->go_to( "/search/test/{$type}" ); @@ -495,14 +495,14 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { ) ); - // check the long form + // Check the long form. $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); foreach ( $types as $type ) { $this->go_to( "/category/cat-a/feed/{$type}" ); $this->assertQueryTrue( 'is_archive', 'is_feed', 'is_category' ); } - // check the short form + // Check the short form. $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); foreach ( $types as $type ) { $this->go_to( "/category/cat-a/{$type}" ); @@ -539,14 +539,14 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { 'taxonomy' => 'post_tag', ) ); - // check the long form + // Check the long form. $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); foreach ( $types as $type ) { $this->go_to( "/tag/tag-a/feed/{$type}" ); $this->assertQueryTrue( 'is_archive', 'is_feed', 'is_tag' ); } - // check the short form + // Check the short form. $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); foreach ( $types as $type ) { $this->go_to( "/tag/tag-a/{$type}" ); @@ -593,14 +593,14 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { // 'author/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?author_name=$matches[1]&feed=$matches[2]', function test_author_feed() { self::factory()->user->create( array( 'user_login' => 'user-a' ) ); - // check the long form + // Check the long form. $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); foreach ( $types as $type ) { $this->go_to( "/author/user-a/feed/{$type}" ); $this->assertQueryTrue( 'is_archive', 'is_feed', 'is_author' ); } - // check the short form + // Check the short form. $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); foreach ( $types as $type ) { $this->go_to( "/author/user-a/{$type}" ); @@ -635,14 +635,14 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { // '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]', function test_ymd_feed() { self::factory()->post->create( array( 'post_date' => '2007-09-04 00:00:00' ) ); - // check the long form + // Check the long form. $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); foreach ( $types as $type ) { $this->go_to( "/2007/09/04/feed/{$type}" ); $this->assertQueryTrue( 'is_archive', 'is_feed', 'is_day', 'is_date' ); } - // check the short form + // Check the short form. $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); foreach ( $types as $type ) { $this->go_to( "/2007/09/04/{$type}" ); @@ -669,14 +669,14 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { // '([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]', function test_ym_feed() { self::factory()->post->create( array( 'post_date' => '2007-09-04 00:00:00' ) ); - // check the long form + // Check the long form. $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); foreach ( $types as $type ) { $this->go_to( "/2007/09/feed/{$type}" ); $this->assertQueryTrue( 'is_archive', 'is_feed', 'is_month', 'is_date' ); } - // check the short form + // Check the short form. $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); foreach ( $types as $type ) { $this->go_to( "/2007/09/{$type}" ); @@ -703,14 +703,14 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { // '([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?year=$matches[1]&feed=$matches[2]', function test_y_feed() { self::factory()->post->create( array( 'post_date' => '2007-09-04 00:00:00' ) ); - // check the long form + // Check the long form. $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); foreach ( $types as $type ) { $this->go_to( "/2007/feed/{$type}" ); $this->assertQueryTrue( 'is_archive', 'is_feed', 'is_year', 'is_date' ); } - // check the short form + // Check the short form. $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); foreach ( $types as $type ) { $this->go_to( "/2007/{$type}" ); @@ -746,14 +746,14 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { function test_post_comment_feed() { $post_id = self::factory()->post->create(); $permalink = get_permalink( $post_id ); - + // Check the long form. $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); foreach ( $types as $type ) { $this->go_to( "{$permalink}feed/{$type}" ); $this->assertQueryTrue( 'is_single', 'is_singular', 'is_feed', 'is_comment_feed' ); } - // check the short form + // Check the short form. $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); foreach ( $types as $type ) { $this->go_to( "{$permalink}{$type}" ); @@ -771,7 +771,7 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { ) ); $this->go_to( get_permalink( $post_id ) . '2/' ); - // should is_paged be true also? + // Should is_paged be true also? $this->assertQueryTrue( 'is_single', 'is_singular' ); } @@ -901,7 +901,7 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { * @ticket 16802 */ function test_is_single_with_parent() { - // Use custom hierarchical post type + // Use custom hierarchical post type. $post_type = 'test_hierarchical'; register_post_type( @@ -914,7 +914,7 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { ) ); - // Create parent and child posts + // Create parent and child posts. $parent_id = self::factory()->post->create( array( 'post_type' => $post_type, @@ -930,7 +930,7 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { ) ); - // Tests + // Tests. $this->go_to( "/?p=$post_id&post_type=$post_type" ); $post = get_queried_object(); @@ -1199,7 +1199,7 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { $post_id = self::factory()->post->create( array( 'post_type' => 'page' ) ); $this->go_to( "/?page_id=$post_id" ); - // override post ID to 0 temporarily for testing + // Override post ID to 0 temporarily for testing. $_id = $GLOBALS['wp_query']->post->ID; $GLOBALS['wp_query']->post->ID = 0; @@ -1210,7 +1210,7 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { $this->assertFalse( $q->is_page( 'sample-page' ) ); $this->assertFalse( $q->is_page( 'random-page-slug' ) ); - // revert $wp_query global change + // Revert $wp_query global change. $GLOBALS['wp_query']->post->ID = $_id; } diff --git a/tests/phpunit/tests/query/date.php b/tests/phpunit/tests/query/date.php index 73b6f3ca4a..b93bd8662a 100644 --- a/tests/phpunit/tests/query/date.php +++ b/tests/phpunit/tests/query/date.php @@ -55,9 +55,9 @@ class Tests_Query_Date extends WP_UnitTestCase { $args = wp_parse_args( $args, array( - 'post_status' => 'any', // For the future post - 'posts_per_page' => '-1', // To make sure results are accurate - 'orderby' => 'ID', // Same order they were created + 'post_status' => 'any', // For the future post. + 'posts_per_page' => '-1', // To make sure results are accurate. + 'orderby' => 'ID', // Same order they were created. 'order' => 'ASC', ) ); @@ -294,7 +294,7 @@ class Tests_Query_Date extends WP_UnitTestCase { $expected = $this->_get_query_result(); $posts = $this->_get_query_result( array( - 'm' => array( '1234' ), // ignored + 'm' => array( '1234' ), // Ignored. ) ); diff --git a/tests/phpunit/tests/query/dateQuery.php b/tests/phpunit/tests/query/dateQuery.php index ee9864593d..da7599bad6 100644 --- a/tests/phpunit/tests/query/dateQuery.php +++ b/tests/phpunit/tests/query/dateQuery.php @@ -23,9 +23,9 @@ class Tests_Query_DateQuery extends WP_UnitTestCase { $args = wp_parse_args( $args, array( - 'post_status' => 'any', // For the future post - 'posts_per_page' => '-1', // To make sure results are accurate - 'orderby' => 'ID', // Same order they were created + 'post_status' => 'any', // For the future post. + 'posts_per_page' => '-1', // To make sure results are accurate. + 'orderby' => 'ID', // Same order they were created. 'order' => 'ASC', 'update_post_meta_cache' => false, 'update_post_term_cache' => false, diff --git a/tests/phpunit/tests/query/isTerm.php b/tests/phpunit/tests/query/isTerm.php index dbd6c2a2f0..92edd97d02 100644 --- a/tests/phpunit/tests/query/isTerm.php +++ b/tests/phpunit/tests/query/isTerm.php @@ -77,7 +77,7 @@ class Tests_Query_IsTerm extends WP_UnitTestCase { } function test_tag_action_tax() { - // tag with tax added + // Tag with taxonomy added. $this->go_to( home_url( '/tag/tag-slug/' ) ); $this->assertQueryTrue( 'is_tag', 'is_archive' ); $this->assertNotEmpty( get_query_var( 'tax_query' ) ); @@ -88,7 +88,7 @@ class Tests_Query_IsTerm extends WP_UnitTestCase { } function test_tag_query_cat_action_tax() { - // tag + category with tax added + // Tag + category with taxonomy added. $this->go_to( home_url( "/tag/tag-slug/?cat=$this->cat_id" ) ); $this->assertQueryTrue( 'is_category', 'is_tag', 'is_archive' ); $this->assertNotEmpty( get_query_var( 'tax_query' ) ); @@ -100,7 +100,7 @@ class Tests_Query_IsTerm extends WP_UnitTestCase { } function test_tag_query_cat_query_tax_action_tax() { - // tag + category + tax with tax added + // Tag + category + tax with taxonomy added. $this->go_to( home_url( "/tag/tag-slug/?cat=$this->cat_id&testtax=tax-slug2" ) ); $this->assertQueryTrue( 'is_category', 'is_tag', 'is_tax', 'is_archive' ); $this->assertNotEmpty( get_query_var( 'tax_query' ) ); @@ -113,7 +113,7 @@ class Tests_Query_IsTerm extends WP_UnitTestCase { } function test_cat_action_tax() { - // category with tax added + // Category with taxonomy added. $this->go_to( home_url( '/category/cat-slug/' ) ); $this->assertQueryTrue( 'is_category', 'is_archive' ); $this->assertNotEmpty( get_query_var( 'cat' ) ); @@ -127,7 +127,7 @@ class Tests_Query_IsTerm extends WP_UnitTestCase { * @ticket 26627 */ function test_cat_uncat_action_tax() { - // category with tax added + // Category with taxonomy added. add_action( 'pre_get_posts', array( $this, '_cat_uncat_action_tax' ), 11 ); $this->go_to( home_url( '/category/uncategorized/' ) ); @@ -153,7 +153,7 @@ class Tests_Query_IsTerm extends WP_UnitTestCase { * @ticket 26728 */ function test_tax_action_tax() { - // tax with tax added + // Taxonomy with taxonomy added. $this->go_to( home_url( '/testtax/tax-slug2/' ) ); $this->assertQueryTrue( 'is_tax', 'is_archive' ); $this->assertNotEmpty( get_query_var( 'tax_query' ) ); @@ -163,7 +163,7 @@ class Tests_Query_IsTerm extends WP_UnitTestCase { } function test_tax_query_tag_action_tax() { - // tax + tag with tax added + // Taxonomy + tag with taxonomy added. $this->go_to( home_url( "/testtax/tax-slug2/?tag_id=$this->tag_id" ) ); $this->assertQueryTrue( 'is_tag', 'is_tax', 'is_archive' ); $this->assertNotEmpty( get_query_var( 'tax_query' ) ); @@ -174,7 +174,7 @@ class Tests_Query_IsTerm extends WP_UnitTestCase { } function test_tax_query_cat_action_tax() { - // tax + cat with tax added + // Taxonomy + category with taxonomy added. $this->go_to( home_url( "/testtax/tax-slug2/?cat=$this->cat_id" ) ); $this->assertQueryTrue( 'is_category', 'is_tax', 'is_archive' ); $this->assertNotEmpty( get_query_var( 'tax_query' ) ); diff --git a/tests/phpunit/tests/query/metaQuery.php b/tests/phpunit/tests/query/metaQuery.php index 9303e60b95..6b19d0c6b5 100644 --- a/tests/phpunit/tests/query/metaQuery.php +++ b/tests/phpunit/tests/query/metaQuery.php @@ -1563,7 +1563,7 @@ class Tests_Query_MetaQuery extends WP_UnitTestCase { * @ticket 16829 */ public function test_meta_default_compare() { - // compare should default to IN when meta_value is an array + // Compare should default to IN when meta_value is an array. $post_id = self::factory()->post->create(); add_post_meta( $post_id, 'foo', 'bar' ); $post_id2 = self::factory()->post->create(); diff --git a/tests/phpunit/tests/query/results.php b/tests/phpunit/tests/query/results.php index daa171efb9..35742f6547 100644 --- a/tests/phpunit/tests/query/results.php +++ b/tests/phpunit/tests/query/results.php @@ -304,7 +304,7 @@ class Tests_Query_Results extends WP_UnitTestCase { function test_query_default() { $posts = $this->q->query( '' ); - // the output should be the most recent 10 posts as listed here + // The output should be the most recent 10 posts as listed here. $expected = array( 0 => 'tags-a-and-c', 1 => 'tags-b-and-c', @@ -324,7 +324,7 @@ class Tests_Query_Results extends WP_UnitTestCase { function test_query_tag_a() { $posts = $this->q->query( 'tag=tag-a' ); - // there are 4 posts with Tag A + // There are 4 posts with Tag A. $this->assertCount( 4, $posts ); $this->assertEquals( 'tags-a-and-c', $posts[0]->post_name ); $this->assertEquals( 'tags-a-and-b', $posts[1]->post_name ); @@ -335,7 +335,7 @@ class Tests_Query_Results extends WP_UnitTestCase { function test_query_tag_b() { $posts = $this->q->query( 'tag=tag-b' ); - // there are 4 posts with Tag A + // There are 4 posts with Tag A. $this->assertCount( 4, $posts ); $this->assertEquals( 'tags-b-and-c', $posts[0]->post_name ); $this->assertEquals( 'tags-a-and-b', $posts[1]->post_name ); @@ -349,7 +349,7 @@ class Tests_Query_Results extends WP_UnitTestCase { function test_query_tag_nun() { $posts = $this->q->query( 'tag=tag-נ' ); - // there is 1 post with Tag נ + // There is 1 post with Tag נ. $this->assertCount( 1, $posts ); $this->assertEquals( 'tag-%d7%a0', $posts[0]->post_name ); } @@ -358,7 +358,7 @@ class Tests_Query_Results extends WP_UnitTestCase { $tag = tag_exists( 'tag-a' ); $posts = $this->q->query( 'tag_id=' . $tag['term_id'] ); - // there are 4 posts with Tag A + // There are 4 posts with Tag A. $this->assertCount( 4, $posts ); $this->assertEquals( 'tags-a-and-c', $posts[0]->post_name ); $this->assertEquals( 'tags-a-and-b', $posts[1]->post_name ); @@ -369,7 +369,7 @@ class Tests_Query_Results extends WP_UnitTestCase { function test_query_tag_slug__in() { $posts = $this->q->query( 'tag_slug__in[]=tag-b&tag_slug__in[]=tag-c' ); - // there are 4 posts with either Tag B or Tag C + // There are 4 posts with either Tag B or Tag C. $this->assertCount( 6, $posts ); $this->assertEquals( 'tags-a-and-c', $posts[0]->post_name ); $this->assertEquals( 'tags-b-and-c', $posts[1]->post_name ); @@ -385,7 +385,7 @@ class Tests_Query_Results extends WP_UnitTestCase { $tag_b = tag_exists( 'tag-b' ); $posts = $this->q->query( 'tag__in[]=' . $tag_a['term_id'] . '&tag__in[]=' . $tag_b['term_id'] ); - // there are 6 posts with either Tag A or Tag B + // There are 6 posts with either Tag A or Tag B. $this->assertCount( 6, $posts ); $this->assertEquals( 'tags-a-and-c', $posts[0]->post_name ); $this->assertEquals( 'tags-b-and-c', $posts[1]->post_name ); @@ -399,8 +399,8 @@ class Tests_Query_Results extends WP_UnitTestCase { $tag_a = tag_exists( 'tag-a' ); $posts = $this->q->query( 'tag__not_in[]=' . $tag_a['term_id'] ); - // the most recent 10 posts with Tag A excluded - // (note the different between this and test_query_default) + // The most recent 10 posts with Tag A excluded + // (note the different between this and test_query_default). $expected = array( 0 => 'tags-b-and-c', 1 => 'tag-c', @@ -422,7 +422,7 @@ class Tests_Query_Results extends WP_UnitTestCase { $tag_b = tag_exists( 'tag-b' ); $posts = $this->q->query( 'tag__in[]=' . $tag_a['term_id'] . '&tag__not_in[]=' . $tag_b['term_id'] ); - // there are 4 posts with Tag A, only 2 when we exclude Tag B + // There are 4 posts with Tag A, only 2 when we exclude Tag B. $this->assertCount( 2, $posts ); $this->assertEquals( 'tags-a-and-c', $posts[0]->post_name ); $this->assertEquals( 'tag-a', $posts[1]->post_name ); @@ -433,7 +433,7 @@ class Tests_Query_Results extends WP_UnitTestCase { function test_query_category_name() { $posts = $this->q->query( 'category_name=cat-a' ); - // there are 4 posts with Cat A, we'll check for them by name + // There are 4 posts with Cat A, we'll check for them by name. $this->assertCount( 4, $posts ); $this->assertEquals( 'cat-a', $posts[0]->post_name ); $this->assertEquals( 'cats-a-and-c', $posts[1]->post_name ); @@ -445,7 +445,7 @@ class Tests_Query_Results extends WP_UnitTestCase { $cat = category_exists( 'cat-b' ); $posts = $this->q->query( "cat=$cat" ); - // there are 4 posts with Cat B + // There are 4 posts with Cat B. $this->assertCount( 4, $posts ); $this->assertEquals( 'cat-b', $posts[0]->post_name ); $this->assertEquals( 'cats-b-and-c', $posts[1]->post_name ); @@ -528,7 +528,7 @@ class Tests_Query_Results extends WP_UnitTestCase { * @ticket 11056 */ function test_query_post_parent__in() { - // Query for first parent's children + // Query for first parent's children. $posts = $this->q->query( array( 'post_parent__in' => array( self::$parent_one ), @@ -545,7 +545,7 @@ class Tests_Query_Results extends WP_UnitTestCase { wp_list_pluck( $posts, 'post_title' ) ); - // Second parent's children + // Second parent's children. $posts = $this->q->query( array( 'post_parent__in' => array( self::$parent_two ), @@ -562,7 +562,7 @@ class Tests_Query_Results extends WP_UnitTestCase { wp_list_pluck( $posts, 'post_title' ) ); - // Both first and second parent's children + // Both first and second parent's children. $posts = $this->q->query( array( 'post_parent__in' => array( self::$parent_one, self::$parent_two ), @@ -581,7 +581,7 @@ class Tests_Query_Results extends WP_UnitTestCase { wp_list_pluck( $posts, 'post_title' ) ); - // Third parent's children + // Third parent's children. $posts = $this->q->query( array( 'post_parent__in' => array( self::$parent_three ), @@ -629,7 +629,7 @@ class Tests_Query_Results extends WP_UnitTestCase { ) ); - // order=desc does not influence the order of returned results (returns same order as order=asc) + // 'order=desc' does not influence the order of returned results (returns same order as 'order=asc'). $this->assertEquals( $expected_returned_array, wp_list_pluck( $posts, 'post_title' ) ); } @@ -648,7 +648,7 @@ class Tests_Query_Results extends WP_UnitTestCase { ) ); - // Expect post ids in the same order as post__in array when no 'order' param is passed in + // Expect post IDs in the same order as post__in array when no 'order' param is passed in. $this->assertSame( $expected_returned_array, $q->posts ); } @@ -668,7 +668,7 @@ class Tests_Query_Results extends WP_UnitTestCase { ) ); - // Expect post ids in the same order as post__in array when order=asc is passed in + // Expect post IDs in the same order as post__in array when order=asc is passed in. $this->assertSame( $expected_returned_array, $q->posts ); } @@ -688,8 +688,8 @@ class Tests_Query_Results extends WP_UnitTestCase { ) ); - // Note that results are returned in the order specified in the post__in array - // Order=desc does not have an effect on the order of returned results + // Note that results are returned in the order specified in the post__in array. + // 'order=desc' does not influence the order of returned results. $this->assertSame( $expected_returned_array, $q->posts ); } @@ -724,7 +724,7 @@ class Tests_Query_Results extends WP_UnitTestCase { ) ); - // order=desc does not influence the order of returned results (returns same order as order=asc) + // 'order=desc' does not influence the order of returned results (returns same order as 'order=asc'). $this->assertSame( $post_name__in_array, array_unique( wp_list_pluck( $q->posts, 'post_title' ) ) ); } diff --git a/tests/phpunit/tests/query/search.php b/tests/phpunit/tests/query/search.php index 84ea96030f..dea08f9fbb 100644 --- a/tests/phpunit/tests/query/search.php +++ b/tests/phpunit/tests/query/search.php @@ -80,7 +80,7 @@ class Tests_Query_Search extends WP_UnitTestCase { function test_disable_search_exclusion_prefix() { $title = '-HYPHENATION_TEST'; - // Create a post with a title which starts with a hyphen + // Create a post with a title which starts with a hyphen. $post_id = self::factory()->post->create( array( 'post_content' => $title, @@ -88,10 +88,10 @@ class Tests_Query_Search extends WP_UnitTestCase { ) ); - // By default, we can use the hyphen prefix to exclude results + // By default, we can use the hyphen prefix to exclude results. $this->assertEquals( array(), $this->get_search_results( $title ) ); - // After we disable the feature using the filter, we should get the result + // After we disable the feature using the filter, we should get the result. add_filter( 'wp_query_search_exclusion_prefix', '__return_false' ); $result = $this->get_search_results( $title ); $post = array_pop( $result ); diff --git a/tests/phpunit/tests/query/taxQuery.php b/tests/phpunit/tests/query/taxQuery.php index 42e73d779e..14637c801a 100644 --- a/tests/phpunit/tests/query/taxQuery.php +++ b/tests/phpunit/tests/query/taxQuery.php @@ -994,11 +994,11 @@ class Tests_Query_TaxQuery extends WP_UnitTestCase { } /** + * An empty tax query should return an empty array, not all posts. + * * @ticket 20604 */ public function test_tax_query_relation_or_both_clauses_empty_terms() { - // An empty tax query should return an empty array, not all posts. - self::factory()->post->create_many( 2 ); $query = new WP_Query( @@ -1029,11 +1029,11 @@ class Tests_Query_TaxQuery extends WP_UnitTestCase { } /** + * An empty tax query should return an empty array, not all posts. + * * @ticket 20604 */ public function test_tax_query_relation_or_one_clause_empty_terms() { - // An empty tax query should return an empty array, not all posts. - self::factory()->post->create_many( 2 ); $query = new WP_Query( @@ -1301,12 +1301,12 @@ class Tests_Query_TaxQuery extends WP_UnitTestCase { $cats = array(); $tags = array(); - // need term_taxonomy_ids in addition to term_ids, so no factory + // Need term_taxonomy_ids in addition to term_ids, so no factory. for ( $i = 0; $i < 5; $i++ ) { $cats[ $i ] = wp_insert_term( 'category-' . $i, 'category' ); $tags[ $i ] = wp_insert_term( 'tag-' . $i, 'post_tag' ); - // post 0 gets all terms + // Post 0 gets all terms. wp_set_object_terms( $posts[0], array( $cats[ $i ]['term_id'] ), 'category', true ); wp_set_object_terms( $posts[0], array( $tags[ $i ]['term_id'] ), 'post_tag', true ); } @@ -1394,13 +1394,13 @@ class Tests_Query_TaxQuery extends WP_UnitTestCase { $q = new WP_Query( array( 'tax_query' => array( - // Empty terms mean that this one should be skipped + // Empty terms mean that this one should be skipped. array( 'taxonomy' => 'bar', 'terms' => array(), ), - // Category and post tags should be skipped + // Category and post tags should be skipped. array( 'taxonomy' => 'category', 'terms' => array( $c ), @@ -1518,19 +1518,19 @@ class Tests_Query_TaxQuery extends WP_UnitTestCase { $q = new WP_Query( array( 'tax_query' => array( - // Non-category should be skipped + // Non-category should be skipped. array( 'taxonomy' => 'foo', 'terms' => array( $t ), ), - // Empty terms mean that this one should be skipped + // Empty terms mean that this one should be skipped. array( 'taxonomy' => 'category', 'terms' => array(), ), - // Category and post tags should be skipped + // Category and post tags should be skipped. array( 'taxonomy' => 'category', 'terms' => array( $c ), @@ -1565,19 +1565,19 @@ class Tests_Query_TaxQuery extends WP_UnitTestCase { $q = new WP_Query( array( 'tax_query' => array( - // Non-tag should be skipped + // Non-tag should be skipped. array( 'taxonomy' => 'foo', 'terms' => array( $t ), ), - // Empty terms mean that this one should be skipped + // Empty terms mean that this one should be skipped. array( 'taxonomy' => 'post_tag', 'terms' => array(), ), - // Category and post tags should be skipped + // Category and post tags should be skipped. array( 'taxonomy' => 'post_tag', 'terms' => array( $tag ), diff --git a/tests/phpunit/tests/rest-api.php b/tests/phpunit/tests/rest-api.php index 1efb81a348..38b4fe8aa0 100644 --- a/tests/phpunit/tests/rest-api.php +++ b/tests/phpunit/tests/rest-api.php @@ -316,9 +316,9 @@ class Tests_REST_API extends WP_UnitTestCase { } /** - * The 'methods' arg should a comma seperated string. + * The 'methods' arg should a comma-separated string. */ - public function test_route_method_comma_seperated() { + public function test_route_method_comma_separated() { register_rest_route( 'test-ns', '/test', @@ -708,32 +708,32 @@ class Tests_REST_API extends WP_UnitTestCase { set_current_screen( 'edit.php' ); $this->assertTrue( is_admin() ); - // Test an HTTP URL + // Test an HTTP URL. unset( $_SERVER['HTTPS'] ); $url = get_rest_url(); $this->assertSame( 'http', parse_url( $url, PHP_URL_SCHEME ) ); - // Test an HTTPS URL + // Test an HTTPS URL. $_SERVER['HTTPS'] = 'on'; $url = get_rest_url(); $this->assertSame( 'https', parse_url( $url, PHP_URL_SCHEME ) ); - // Switch to an admin request on a different domain name + // Switch to an admin request on a different domain name. $_SERVER['SERVER_NAME'] = 'admin.example.org'; update_option( 'siteurl', 'http://admin.example.org' ); $this->assertNotEquals( $_SERVER['SERVER_NAME'], parse_url( home_url(), PHP_URL_HOST ) ); - // // Test an HTTP URL + // Test an HTTP URL. unset( $_SERVER['HTTPS'] ); $url = get_rest_url(); $this->assertSame( 'http', parse_url( $url, PHP_URL_SCHEME ) ); - // // Test an HTTPS URL + // Test an HTTPS URL. $_SERVER['HTTPS'] = 'on'; $url = get_rest_url(); $this->assertSame( 'http', parse_url( $url, PHP_URL_SCHEME ) ); - // Reset + // Reset. update_option( 'siteurl', $_siteurl ); set_current_screen( 'front' ); @@ -768,13 +768,13 @@ class Tests_REST_API extends WP_UnitTestCase { public function jsonp_callback_provider() { return array( - // Standard names + // Standard names. array( 'Springfield', true ), array( 'shelby.ville', true ), array( 'cypress_creek', true ), array( 'KampKrusty1', true ), - // Invalid names + // Invalid names. array( 'ogden-ville', false ), array( 'north haverbrook', false ), array( "Terror['Lake']", false ), @@ -793,7 +793,7 @@ class Tests_REST_API extends WP_UnitTestCase { public function rest_date_provider() { return array( - // Valid dates with timezones + // Valid dates with timezones. array( '2017-01-16T11:30:00-05:00', gmmktime( 11, 30, 0, 1, 16, 2017 ) + 5 * HOUR_IN_SECONDS ), array( '2017-01-16T11:30:00-05:30', gmmktime( 11, 30, 0, 1, 16, 2017 ) + 5.5 * HOUR_IN_SECONDS ), array( '2017-01-16T11:30:00-05', gmmktime( 11, 30, 0, 1, 16, 2017 ) + 5 * HOUR_IN_SECONDS ), @@ -802,10 +802,10 @@ class Tests_REST_API extends WP_UnitTestCase { array( '2017-01-16T11:30:00+00', gmmktime( 11, 30, 0, 1, 16, 2017 ) ), array( '2017-01-16T11:30:00Z', gmmktime( 11, 30, 0, 1, 16, 2017 ) ), - // Valid dates without timezones + // Valid dates without timezones. array( '2017-01-16T11:30:00', gmmktime( 11, 30, 0, 1, 16, 2017 ) ), - // Invalid dates (TODO: support parsing partial dates as ranges, see #38641) + // Invalid dates (TODO: support parsing partial dates as ranges, see #38641). array( '2017-01-16T11:30:00-5', false ), array( '2017-01-16T11:30', false ), array( '2017-01-16T11', false ), @@ -825,7 +825,7 @@ class Tests_REST_API extends WP_UnitTestCase { public function rest_date_force_utc_provider() { return array( - // Valid dates with timezones + // Valid dates with timezones. array( '2017-01-16T11:30:00-05:00', gmmktime( 11, 30, 0, 1, 16, 2017 ) ), array( '2017-01-16T11:30:00-05:30', gmmktime( 11, 30, 0, 1, 16, 2017 ) ), array( '2017-01-16T11:30:00-05', gmmktime( 11, 30, 0, 1, 16, 2017 ) ), @@ -834,10 +834,10 @@ class Tests_REST_API extends WP_UnitTestCase { array( '2017-01-16T11:30:00+00', gmmktime( 11, 30, 0, 1, 16, 2017 ) ), array( '2017-01-16T11:30:00Z', gmmktime( 11, 30, 0, 1, 16, 2017 ) ), - // Valid dates without timezones + // Valid dates without timezones. array( '2017-01-16T11:30:00', gmmktime( 11, 30, 0, 1, 16, 2017 ) ), - // Invalid dates (TODO: support parsing partial dates as ranges, see #38641) + // Invalid dates (TODO: support parsing partial dates as ranges, see #38641). array( '2017-01-16T11:30:00-5', false ), array( '2017-01-16T11:30', false ), array( '2017-01-16T11', false ), diff --git a/tests/phpunit/tests/rest-api/rest-attachments-controller.php b/tests/phpunit/tests/rest-api/rest-attachments-controller.php index 60686523fd..b8b9e05975 100644 --- a/tests/phpunit/tests/rest-api/rest-attachments-controller.php +++ b/tests/phpunit/tests/rest-api/rest-attachments-controller.php @@ -87,12 +87,12 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control public static function disposition_provider() { return array( - // Types + // Types. array( 'attachment; filename="foo.jpg"', 'foo.jpg' ), array( 'inline; filename="foo.jpg"', 'foo.jpg' ), array( 'form-data; filename="foo.jpg"', 'foo.jpg' ), - // Formatting + // Formatting. array( 'attachment; filename="foo.jpg"', 'foo.jpg' ), array( 'attachment; filename=foo.jpg', 'foo.jpg' ), array( 'attachment;filename="foo.jpg"', 'foo.jpg' ), @@ -103,13 +103,13 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control array( "attachment;\tfilename\t=\tfoo.jpg", 'foo.jpg' ), array( 'attachment; filename = my foo picture.jpg', 'my foo picture.jpg' ), - // Extensions + // Extensions. array( 'form-data; name="myfile"; filename="foo.jpg"', 'foo.jpg' ), array( 'form-data; name="myfile"; filename="foo.jpg"; something="else"', 'foo.jpg' ), array( 'form-data; name=myfile; filename=foo.jpg; something=else', 'foo.jpg' ), array( 'form-data; name=myfile; filename=my foo.jpg; something=else', 'my foo.jpg' ), - // Invalid + // Invalid. array( 'filename="foo.jpg"', null ), array( 'filename-foo.jpg', null ), array( 'foo.jpg', null ), @@ -127,13 +127,13 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control } public function test_context_param() { - // Collection + // Collection. $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/media' ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); $this->assertEquals( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); - // Single + // Single. $attachment_id = $this->factory->attachment->create_object( $this->test_file, 0, @@ -329,11 +329,11 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); $this->assertEquals( $id1, $data[0]['id'] ); - // media_type=video + // 'media_type' => 'video'. $request->set_param( 'media_type', 'video' ); $response = rest_get_server()->dispatch( $request ); $this->assertCount( 0, $response->get_data() ); - // media_type=image + // 'media_type' => 'image'. $request->set_param( 'media_type', 'image' ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); @@ -352,11 +352,11 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); $this->assertEquals( $id1, $data[0]['id'] ); - // mime_type=image/png + // 'mime_type' => 'image/png'. $request->set_param( 'mime_type', 'image/png' ); $response = rest_get_server()->dispatch( $request ); $this->assertCount( 0, $response->get_data() ); - // mime_type=image/jpeg + // 'mime_type' => 'image/jpeg'. $request->set_param( 'mime_type', 'image/jpeg' ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); @@ -381,25 +381,25 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control 'post_excerpt' => 'A sample caption', ) ); - // all attachments + // All attachments. $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); $response = rest_get_server()->dispatch( $request ); $this->assertEquals( 2, count( $response->get_data() ) ); $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); - // attachments without a parent + // Attachments without a parent. $request->set_param( 'parent', 0 ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); $this->assertEquals( 1, count( $data ) ); $this->assertEquals( $attachment_id2, $data[0]['id'] ); - // attachments with parent=post_id + // Attachments with parent=post_id. $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); $request->set_param( 'parent', $post_id ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); $this->assertEquals( 1, count( $data ) ); $this->assertEquals( $attachment_id, $data[0]['id'] ); - // attachments with invalid parent + // Attachments with invalid parent. $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); $request->set_param( 'parent', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); $response = rest_get_server()->dispatch( $request ); @@ -427,7 +427,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control } public function test_get_items_private_status() { - // Logged out users can't make the request + // Logged out users can't make the request. wp_set_current_user( 0 ); $attachment_id1 = $this->factory->attachment->create_object( $this->test_file, @@ -442,7 +442,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control $request->set_param( 'status', 'private' ); $response = rest_get_server()->dispatch( $request ); $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); - // Properly authorized users can make the request + // Properly authorized users can make the request. wp_set_current_user( self::$editor_id ); $response = rest_get_server()->dispatch( $request ); $this->assertEquals( 200, $response->get_status() ); @@ -451,7 +451,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control } public function test_get_items_multiple_statuses() { - // Logged out users can't make the request + // Logged out users can't make the request. wp_set_current_user( 0 ); $attachment_id1 = $this->factory->attachment->create_object( $this->test_file, @@ -475,7 +475,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control $request->set_param( 'status', array( 'private', 'trash' ) ); $response = rest_get_server()->dispatch( $request ); $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); - // Properly authorized users can make the request + // Properly authorized users can make the request. wp_set_current_user( self::$editor_id ); $response = rest_get_server()->dispatch( $request ); $this->assertEquals( 200, $response->get_status() ); @@ -968,7 +968,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control } public function verify_attachment_roundtrip( $input = array(), $expected_output = array() ) { - // Create the post + // Create the post. $request = new WP_REST_Request( 'POST', '/wp/v2/media' ); $request->set_header( 'Content-Type', 'image/jpeg' ); $request->set_header( 'Content-Disposition', 'attachment; filename=canola.jpg' ); @@ -981,8 +981,8 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control $this->assertEquals( 201, $response->get_status() ); $actual_output = $response->get_data(); - // Remove

    from rendered description - // see https://core.trac.wordpress.org/ticket/38679 + // Remove

    from rendered description. + // See https://core.trac.wordpress.org/ticket/38679 $content = $actual_output['description']['rendered']; $content = explode( "\n", trim( $content ) ); if ( preg_match( '/^

    /', $content[0] ) ) { @@ -990,7 +990,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control $actual_output['description']['rendered'] = $content; } - // Compare expected API output to actual API output + // Compare expected API output to actual API output. $this->assertEquals( $expected_output['title']['raw'], $actual_output['title']['raw'] ); $this->assertEquals( $expected_output['title']['rendered'], trim( $actual_output['title']['rendered'] ) ); $this->assertEquals( $expected_output['description']['raw'], $actual_output['description']['raw'] ); @@ -998,13 +998,13 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control $this->assertEquals( $expected_output['caption']['raw'], $actual_output['caption']['raw'] ); $this->assertEquals( $expected_output['caption']['rendered'], trim( $actual_output['caption']['rendered'] ) ); - // Compare expected API output to WP internal values + // Compare expected API output to WP internal values. $post = get_post( $actual_output['id'] ); $this->assertEquals( $expected_output['title']['raw'], $post->post_title ); $this->assertEquals( $expected_output['description']['raw'], $post->post_content ); $this->assertEquals( $expected_output['caption']['raw'], $post->post_excerpt ); - // Update the post + // Update the post. $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/media/%d', $actual_output['id'] ) ); foreach ( $input as $name => $value ) { $request->set_param( $name, $value ); @@ -1013,8 +1013,8 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control $this->assertEquals( 200, $response->get_status() ); $actual_output = $response->get_data(); - // Remove

    from rendered description - // see https://core.trac.wordpress.org/ticket/38679 + // Remove

    from rendered description. + // See https://core.trac.wordpress.org/ticket/38679 $content = $actual_output['description']['rendered']; $content = explode( "\n", trim( $content ) ); if ( preg_match( '/^

    /', $content[0] ) ) { @@ -1022,7 +1022,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control $actual_output['description']['rendered'] = $content; } - // Compare expected API output to actual API output + // Compare expected API output to actual API output. $this->assertEquals( $expected_output['title']['raw'], $actual_output['title']['raw'] ); $this->assertEquals( $expected_output['title']['rendered'], trim( $actual_output['title']['rendered'] ) ); $this->assertEquals( $expected_output['description']['raw'], $actual_output['description']['raw'] ); @@ -1030,7 +1030,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control $this->assertEquals( $expected_output['caption']['raw'], $actual_output['caption']['raw'] ); $this->assertEquals( $expected_output['caption']['rendered'], trim( $actual_output['caption']['rendered'] ) ); - // Compare expected API output to WP internal values + // Compare expected API output to WP internal values. $post = get_post( $actual_output['id'] ); $this->assertEquals( $expected_output['title']['raw'], $post->post_title ); $this->assertEquals( $expected_output['description']['raw'], $post->post_content ); @@ -1247,7 +1247,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control ) ); - // Attempt trashing + // Attempt trashing. $request = new WP_REST_Request( 'DELETE', '/wp/v2/media/' . $attachment_id ); $response = rest_get_server()->dispatch( $request ); $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); @@ -1256,7 +1256,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control $response = rest_get_server()->dispatch( $request ); $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); - // Ensure the post still exists + // Ensure the post still exists. $post = get_post( $attachment_id ); $this->assertNotEmpty( $post ); } diff --git a/tests/phpunit/tests/rest-api/rest-categories-controller.php b/tests/phpunit/tests/rest-api/rest-categories-controller.php index 1f2228ff05..ecae01f880 100644 --- a/tests/phpunit/tests/rest-api/rest-categories-controller.php +++ b/tests/phpunit/tests/rest-api/rest-categories-controller.php @@ -113,13 +113,13 @@ class WP_Test_REST_Categories_Controller extends WP_Test_REST_Controller_Testcas } public function test_context_param() { - // Collection + // Collection. $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/categories' ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); $this->assertEqualSets( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); - // Single + // Single. $category1 = $this->factory->category->create( array( 'name' => 'Season 5' ) ); $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/categories/' . $category1 ); $response = rest_get_server()->dispatch( $request ); @@ -441,7 +441,7 @@ class WP_Test_REST_Categories_Controller extends WP_Test_REST_Controller_Testcas $data = $response->get_data(); $this->assertEquals( 3, count( $data ) ); - // Check ordered by name by default + // Check ordered by name by default. $names = wp_list_pluck( $data, 'name' ); $this->assertEquals( array( 'DC', 'Image', 'Marvel' ), $names ); } @@ -449,7 +449,7 @@ class WP_Test_REST_Categories_Controller extends WP_Test_REST_Controller_Testcas public function test_get_items_post_ordered_by_description() { $post_id = $this->post_with_categories(); - // Regular request + // Regular request. $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); $request->set_param( 'post', $post_id ); $request->set_param( 'orderby', 'description' ); @@ -461,7 +461,7 @@ class WP_Test_REST_Categories_Controller extends WP_Test_REST_Controller_Testcas $names = wp_list_pluck( $data, 'name' ); $this->assertEquals( array( 'Image', 'Marvel', 'DC' ), $names, 'Terms should be ordered by description' ); - // Flip the order + // Flip the order. $request->set_param( 'order', 'desc' ); $response = rest_get_server()->dispatch( $request ); $this->assertEquals( 200, $response->get_status() ); diff --git a/tests/phpunit/tests/rest-api/rest-comments-controller.php b/tests/phpunit/tests/rest-api/rest-comments-controller.php index 46738edc72..e061c1925d 100644 --- a/tests/phpunit/tests/rest-api/rest-comments-controller.php +++ b/tests/phpunit/tests/rest-api/rest-comments-controller.php @@ -168,13 +168,13 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase } public function test_context_param() { - // Collection + // Collection. $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/comments' ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); $this->assertEquals( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); - // Single + // Single. $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/comments/' . self::$approved_id ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); @@ -979,10 +979,8 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase $this->assertArrayHasKey( 96, $data['author_avatar_urls'] ); $comment = get_comment( self::$approved_id ); - /** - * Ignore the subdomain, since 'get_avatar_url randomly sets the Gravatar - * server when building the url string. - */ + // Ignore the subdomain, since get_avatar_url() randomly sets + // the Gravatar server when building the URL string. $this->assertEquals( substr( get_avatar_url( $comment->comment_author_email ), 9 ), substr( $data['author_avatar_urls'][96], 9 ) ); } @@ -1565,7 +1563,7 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase $data = $response->get_data(); $this->assertEquals( $user_id, $data['author'] ); - // Check author data matches + // Check author data matches. $author = get_user_by( 'id', $user_id ); $comment = get_comment( $data['id'] ); $this->assertEquals( $author->display_name, $comment->comment_author ); @@ -2072,8 +2070,8 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase } public function anonymous_comments_callback_null() { - // I'm a plugin developer who forgot to include a return value for some - // code path in my 'rest_allow_anonymous_comments' filter. + // I'm a plugin developer who forgot to include a return value + // for some code path in my 'rest_allow_anonymous_comments' filter. } public function test_allow_anonymous_comments_null() { @@ -2332,8 +2330,8 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); $request->set_param( 'post', $comment->comment_post_ID ); - // Run twice to make sure that the update still succeeds even if no DB - // rows are updated. + // Run twice to make sure that the update still succeeds + // even if no DB rows are updated. $response = rest_get_server()->dispatch( $request ); $this->assertEquals( 200, $response->get_status() ); @@ -2793,7 +2791,7 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase } public function verify_comment_roundtrip( $input = array(), $expected_output = array() ) { - // Create the comment + // Create the comment. $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); $request->set_param( 'author_email', 'cbg@androidsdungeon.com' ); $request->set_param( 'post', self::$post_id ); @@ -2804,7 +2802,7 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase $this->assertEquals( 201, $response->get_status() ); $actual_output = $response->get_data(); - // Compare expected API output to actual API output + // Compare expected API output to actual API output. $this->assertInternalType( 'array', $actual_output['content'] ); $this->assertArrayHasKey( 'raw', $actual_output['content'] ); $this->assertEquals( $expected_output['content']['raw'], $actual_output['content']['raw'] ); @@ -2812,31 +2810,31 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase $this->assertEquals( $expected_output['author_name'], $actual_output['author_name'] ); $this->assertEquals( $expected_output['author_user_agent'], $actual_output['author_user_agent'] ); - // Compare expected API output to WP internal values + // Compare expected API output to WP internal values. $comment = get_comment( $actual_output['id'] ); $this->assertEquals( $expected_output['content']['raw'], $comment->comment_content ); $this->assertEquals( $expected_output['author_name'], $comment->comment_author ); $this->assertEquals( $expected_output['author_user_agent'], $comment->comment_agent ); - // Update the comment + // Update the comment. $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', $actual_output['id'] ) ); foreach ( $input as $name => $value ) { $request->set_param( $name, $value ); } - // FIXME at least one value must change, or update fails + // FIXME At least one value must change, or update fails. // See https://core.trac.wordpress.org/ticket/38700 $request->set_param( 'author_ip', '127.0.0.2' ); $response = rest_get_server()->dispatch( $request ); $this->assertEquals( 200, $response->get_status() ); $actual_output = $response->get_data(); - // Compare expected API output to actual API output + // Compare expected API output to actual API output. $this->assertEquals( $expected_output['content']['raw'], $actual_output['content']['raw'] ); $this->assertEquals( $expected_output['content']['rendered'], trim( $actual_output['content']['rendered'] ) ); $this->assertEquals( $expected_output['author_name'], $actual_output['author_name'] ); $this->assertEquals( $expected_output['author_user_agent'], $actual_output['author_user_agent'] ); - // Compare expected API output to WP internal values + // Compare expected API output to WP internal values. $comment = get_comment( $actual_output['id'] ); $this->assertEquals( $expected_output['content']['raw'], $comment->comment_content ); $this->assertEquals( $expected_output['author_name'], $comment->comment_author ); diff --git a/tests/phpunit/tests/rest-api/rest-pages-controller.php b/tests/phpunit/tests/rest-api/rest-pages-controller.php index dc2d41f567..84b38cc30e 100644 --- a/tests/phpunit/tests/rest-api/rest-pages-controller.php +++ b/tests/phpunit/tests/rest-api/rest-pages-controller.php @@ -29,7 +29,7 @@ class WP_Test_REST_Pages_Controller extends WP_Test_REST_Post_Type_Controller_Te parent::setUp(); $this->has_setup_template = false; add_filter( 'theme_page_templates', array( $this, 'filter_theme_page_templates' ) ); - // reregister the route as we now have a template available. + // Re-register the route as we now have a template available. $GLOBALS['wp_rest_server']->override_by_default = true; $controller = new WP_REST_Posts_Controller( 'page' ); $controller->register_routes(); @@ -45,13 +45,13 @@ class WP_Test_REST_Pages_Controller extends WP_Test_REST_Post_Type_Controller_Te } public function test_context_param() { - // Collection + // Collection. $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/pages' ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); $this->assertEquals( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); - // Single + // Single. $page_id = $this->factory->post->create( array( 'post_type' => 'page' ) ); $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/pages/' . $page_id ); $response = rest_get_server()->dispatch( $request ); @@ -286,7 +286,7 @@ class WP_Test_REST_Pages_Controller extends WP_Test_REST_Post_Type_Controller_Te $response = rest_get_server()->dispatch( $request ); $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); $data = $response->get_data(); - // Safe format for 4.4 and 4.5 https://core.trac.wordpress.org/ticket/35028 + // Safe format for 4.4 and 4.5. See https://core.trac.wordpress.org/ticket/35028 $first_error = array_shift( $data['data']['params'] ); $this->assertContains( 'per_page must be between 1 (inclusive) and 100 (inclusive)', $first_error ); $request->set_param( 'per_page', 101 ); @@ -298,7 +298,7 @@ class WP_Test_REST_Pages_Controller extends WP_Test_REST_Post_Type_Controller_Te } public function test_get_items_private_filter_query_var() { - // Private query vars inaccessible to unauthorized users + // Private query vars inaccessible to unauthorized users. wp_set_current_user( 0 ); $page_id = $this->factory->post->create( array( @@ -317,7 +317,7 @@ class WP_Test_REST_Pages_Controller extends WP_Test_REST_Post_Type_Controller_Te $response = rest_get_server()->dispatch( $request ); $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); - // But they are accessible to authorized users + // But they are accessible to authorized users. wp_set_current_user( self::$editor_id ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); diff --git a/tests/phpunit/tests/rest-api/rest-post-meta-fields.php b/tests/phpunit/tests/rest-api/rest-post-meta-fields.php index 02f70545c5..126871131f 100644 --- a/tests/phpunit/tests/rest-api/rest-post-meta-fields.php +++ b/tests/phpunit/tests/rest-api/rest-post-meta-fields.php @@ -1538,7 +1538,7 @@ class WP_Test_REST_Post_Meta_Fields extends WP_Test_REST_TestCase { array( 'meta' => array( 'list_of_objects' => array( - // Meta 1 + // Meta 1. array( array( 'version' => '5.2', @@ -1549,7 +1549,7 @@ class WP_Test_REST_Post_Meta_Fields extends WP_Test_REST_TestCase { 'artist' => 'Betty', ), ), - // Meta 2 + // Meta 2. array( array( 'version' => '4.9', diff --git a/tests/phpunit/tests/rest-api/rest-post-statuses-controller.php b/tests/phpunit/tests/rest-api/rest-post-statuses-controller.php index 43b85289b7..3280a06217 100644 --- a/tests/phpunit/tests/rest-api/rest-post-statuses-controller.php +++ b/tests/phpunit/tests/rest-api/rest-post-statuses-controller.php @@ -18,13 +18,13 @@ class WP_Test_REST_Post_Statuses_Controller extends WP_Test_REST_Controller_Test } public function test_context_param() { - // Collection + // Collection. $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/statuses' ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); $this->assertEqualSets( array( 'embed', 'view', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); - // Single + // Single. $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/statuses/publish' ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); diff --git a/tests/phpunit/tests/rest-api/rest-post-types-controller.php b/tests/phpunit/tests/rest-api/rest-post-types-controller.php index d0b49c1e21..b321058639 100644 --- a/tests/phpunit/tests/rest-api/rest-post-types-controller.php +++ b/tests/phpunit/tests/rest-api/rest-post-types-controller.php @@ -18,13 +18,13 @@ class WP_Test_REST_Post_Types_Controller extends WP_Test_REST_Controller_Testcas } public function test_context_param() { - // Collection + // Collection. $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/types' ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); $this->assertEqualSets( array( 'view', 'edit', 'embed' ), $data['endpoints'][0]['args']['context']['enum'] ); - // Single + // Single. $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/types/post' ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php index cf8ade6eee..3735d1146a 100644 --- a/tests/phpunit/tests/rest-api/rest-posts-controller.php +++ b/tests/phpunit/tests/rest-api/rest-posts-controller.php @@ -61,7 +61,7 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te update_site_option( 'site_admins', array( 'superadmin' ) ); } - // Only support 'post' and 'gallery' + // Only support 'post' and 'gallery'. self::$supported_formats = get_theme_support( 'post-formats' ); add_theme_support( 'post-formats', array( 'post', 'gallery' ) ); @@ -150,13 +150,13 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te } public function test_context_param() { - // Collection + // Collection. $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); $this->assertEquals( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); - // Single + // Single. $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . self::$post_id ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); @@ -1454,7 +1454,7 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te * @ticket 39061 */ public function test_get_items_invalid_max_pages() { - // Out of bounds + // Out of bounds. $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); $request->set_param( 'page', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); $response = rest_get_server()->dispatch( $request ); @@ -2050,7 +2050,7 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te add_filter( 'theme_post_templates', array( $this, 'filter_theme_post_templates' ) ); - // reregister the route as we now have a template available. + // Re-register the route as we now have a template available. $GLOBALS['wp_rest_server']->override_by_default = true; $controller = new WP_REST_Posts_Controller( 'post' ); $controller->register_routes(); @@ -2152,8 +2152,8 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); $params = $this->set_post_data( array( - // This results in a special `post_date_gmt` value of - // '0000-00-00 00:00:00'. See #38883. + // This results in a special `post_date_gmt` value + // of '0000-00-00 00:00:00'. See #38883. 'status' => 'pending', ) ); @@ -2252,7 +2252,7 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te $new_post = get_post( $data['id'] ); $this->assertEquals( 'draft', $data['status'] ); $this->assertEquals( 'draft', $new_post->post_status ); - // Confirm dates are shimmed for gmt_offset + // Confirm dates are shimmed for gmt_offset. $post_modified_gmt = gmdate( 'Y-m-d H:i:s', strtotime( $new_post->post_modified ) + ( get_option( 'gmt_offset' ) * 3600 ) ); $post_date_gmt = gmdate( 'Y-m-d H:i:s', strtotime( $new_post->post_date ) + ( get_option( 'gmt_offset' ) * 3600 ) ); @@ -2775,8 +2775,8 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); $request->set_param( 'author', $post->post_author ); - // Run twice to make sure that the update still succeeds even if no DB - // rows are updated. + // Run twice to make sure that the update still succeeds + // even if no DB rows are updated. $response = rest_get_server()->dispatch( $request ); $this->check_update_post_response( $response ); @@ -3224,7 +3224,7 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te $post = get_post( $new_data['id'] ); $this->assertEquals( true, is_sticky( $post->ID ) ); - // Updating another field shouldn't change sticky status + // Updating another field shouldn't change sticky status. $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); $params = $this->set_post_data( array( @@ -3564,7 +3564,7 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te } public function verify_post_roundtrip( $input = array(), $expected_output = array() ) { - // Create the post + // Create the post. $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); foreach ( $input as $name => $value ) { $request->set_param( $name, $value ); @@ -3573,7 +3573,7 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te $this->assertEquals( 201, $response->get_status() ); $actual_output = $response->get_data(); - // Compare expected API output to actual API output + // Compare expected API output to actual API output. $this->assertEquals( $expected_output['title']['raw'], $actual_output['title']['raw'] ); $this->assertEquals( $expected_output['title']['rendered'], trim( $actual_output['title']['rendered'] ) ); $this->assertEquals( $expected_output['content']['raw'], $actual_output['content']['raw'] ); @@ -3581,13 +3581,13 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te $this->assertEquals( $expected_output['excerpt']['raw'], $actual_output['excerpt']['raw'] ); $this->assertEquals( $expected_output['excerpt']['rendered'], trim( $actual_output['excerpt']['rendered'] ) ); - // Compare expected API output to WP internal values + // Compare expected API output to WP internal values. $post = get_post( $actual_output['id'] ); $this->assertEquals( $expected_output['title']['raw'], $post->post_title ); $this->assertEquals( $expected_output['content']['raw'], $post->post_content ); $this->assertEquals( $expected_output['excerpt']['raw'], $post->post_excerpt ); - // Update the post + // Update the post. $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $actual_output['id'] ) ); foreach ( $input as $name => $value ) { $request->set_param( $name, $value ); @@ -3596,7 +3596,7 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te $this->assertEquals( 200, $response->get_status() ); $actual_output = $response->get_data(); - // Compare expected API output to actual API output + // Compare expected API output to actual API output. $this->assertEquals( $expected_output['title']['raw'], $actual_output['title']['raw'] ); $this->assertEquals( $expected_output['title']['rendered'], trim( $actual_output['title']['rendered'] ) ); $this->assertEquals( $expected_output['content']['raw'], $actual_output['content']['raw'] ); @@ -3604,7 +3604,7 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te $this->assertEquals( $expected_output['excerpt']['raw'], $actual_output['excerpt']['raw'] ); $this->assertEquals( $expected_output['excerpt']['rendered'], trim( $actual_output['excerpt']['rendered'] ) ); - // Compare expected API output to WP internal values + // Compare expected API output to WP internal values. $post = get_post( $actual_output['id'] ); $this->assertEquals( $expected_output['title']['raw'], $post->post_title ); $this->assertEquals( $expected_output['content']['raw'], $post->post_content ); @@ -3927,7 +3927,7 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te // Register a taxonomy with 'status' as name. register_taxonomy( 'status', 'post', array( 'show_in_rest' => true ) ); - // Re-initialize the controller + // Re-initialize the controller. $controller = new WP_REST_Posts_Controller( 'post' ); $controller->register_routes(); } @@ -4538,7 +4538,7 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te $request->set_param( 'context', 'edit' ); $response = rest_do_request( $request ); $links = $response->get_links(); - // Authors can't ever unfiltered html + // Authors can't ever unfiltered html. $this->assertArrayNotHasKey( 'https://api.w.org/action-unfiltered-html', $links ); } diff --git a/tests/phpunit/tests/rest-api/rest-revisions-controller.php b/tests/phpunit/tests/rest-api/rest-revisions-controller.php index b181c2d5ee..925870b129 100644 --- a/tests/phpunit/tests/rest-api/rest-revisions-controller.php +++ b/tests/phpunit/tests/rest-api/rest-revisions-controller.php @@ -106,13 +106,13 @@ class WP_Test_REST_Revisions_Controller extends WP_Test_REST_Controller_Testcase } public function test_context_param() { - // Collection + // Collection. $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . self::$post_id . '/revisions' ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); $this->assertEqualSets( array( 'view', 'edit', 'embed' ), $data['endpoints'][0]['args']['context']['enum'] ); - // Single + // Single. $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_1->ID ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); @@ -128,7 +128,7 @@ class WP_Test_REST_Revisions_Controller extends WP_Test_REST_Controller_Testcase $this->assertEquals( 200, $response->get_status() ); $this->assertCount( $this->total_revisions, $data ); - // Reverse chron + // Reverse chronology. $this->assertEquals( $this->revision_id3, $data[0]['id'] ); $this->check_get_revision_response( $data[0], $this->revision_3 ); @@ -281,7 +281,7 @@ class WP_Test_REST_Revisions_Controller extends WP_Test_REST_Controller_Testcase $response = rest_get_server()->dispatch( $request ); $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); - // Ensure the revision still exists + // Ensure the revision still exists. $this->assertNotNull( get_post( $this->revision_id1 ) ); } diff --git a/tests/phpunit/tests/rest-api/rest-server.php b/tests/phpunit/tests/rest-api/rest-server.php index 74d957cbe5..ec9870f033 100644 --- a/tests/phpunit/tests/rest-api/rest-server.php +++ b/tests/phpunit/tests/rest-api/rest-server.php @@ -13,7 +13,7 @@ class Tests_REST_Server extends WP_Test_REST_TestCase { public function setUp() { parent::setUp(); - // Reset REST server to ensure only our routes are registered + // Reset REST server to ensure only our routes are registered. $GLOBALS['wp_rest_server'] = null; add_filter( 'wp_rest_server_class', array( $this, 'filter_wp_rest_server_class' ) ); $GLOBALS['wp_rest_server'] = rest_get_server(); @@ -21,7 +21,7 @@ class Tests_REST_Server extends WP_Test_REST_TestCase { } public function tearDown() { - // Remove our temporary spy server + // Remove our temporary spy server. $GLOBALS['wp_rest_server'] = null; unset( $_REQUEST['_wpnonce'] ); @@ -909,7 +909,7 @@ class Tests_REST_Server extends WP_Test_REST_TestCase { $this->assertEquals( $value, $headers[ $header ] ); } - // Last-Modified should be unset as per #WP23021 + // Last-Modified should be unset as per #WP23021. $this->assertFalse( isset( $headers['Last-Modified'] ), 'Last-Modified should not be sent.' ); } @@ -962,7 +962,7 @@ class Tests_REST_Server extends WP_Test_REST_TestCase { ) ); - // WordPress internally will slash the superglobals on bootstrap + // WordPress internally will slash the superglobals on bootstrap. $_GET = wp_slash( array( 'data' => 'data\\with\\slashes', @@ -990,7 +990,7 @@ class Tests_REST_Server extends WP_Test_REST_TestCase { ) ); - // WordPress internally will slash the superglobals on bootstrap + // WordPress internally will slash the superglobals on bootstrap. $_POST = wp_slash( array( 'data' => 'data\\with\\slashes', @@ -1047,7 +1047,7 @@ class Tests_REST_Server extends WP_Test_REST_TestCase { ) ); - // WordPress internally will slash the superglobals on bootstrap + // WordPress internally will slash the superglobals on bootstrap. $_FILES = array( 'data' => array( 'name' => 'data\\with\\slashes', @@ -1075,7 +1075,7 @@ class Tests_REST_Server extends WP_Test_REST_TestCase { ) ); - // WordPress internally will slash the superglobals on bootstrap + // WordPress internally will slash the superglobals on bootstrap. $_SERVER['HTTP_X_MY_HEADER'] = wp_slash( 'data\\with\\slashes' ); $result = rest_get_server()->serve_request( '/test/data\\with\\slashes' ); diff --git a/tests/phpunit/tests/rest-api/rest-settings-controller.php b/tests/phpunit/tests/rest-api/rest-settings-controller.php index 73805b4d38..91db9adcac 100644 --- a/tests/phpunit/tests/rest-api/rest-settings-controller.php +++ b/tests/phpunit/tests/rest-api/rest-settings-controller.php @@ -104,7 +104,7 @@ class WP_Test_REST_Settings_Controller extends WP_Test_REST_Controller_Testcase public function test_get_item_value_is_cast_to_type() { wp_set_current_user( self::$administrator ); - update_option( 'posts_per_page', 'invalid_number' ); // this is cast to (int) 1 + update_option( 'posts_per_page', 'invalid_number' ); // This is cast to (int) 1. $request = new WP_REST_Request( 'GET', '/wp/v2/settings' ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); @@ -182,14 +182,14 @@ class WP_Test_REST_Settings_Controller extends WP_Test_REST_Controller_Testcase $data = $response->get_data(); $this->assertEquals( array(), $data['mycustomsetting'] ); - // Invalid value + // Invalid value. update_option( 'mycustomsetting', array( array( 1 ) ) ); $request = new WP_REST_Request( 'GET', '/wp/v2/settings' ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); $this->assertEquals( null, $data['mycustomsetting'] ); - // No option value + // No option value. delete_option( 'mycustomsetting' ); $request = new WP_REST_Request( 'GET', '/wp/v2/settings' ); $response = rest_get_server()->dispatch( $request ); @@ -238,7 +238,7 @@ class WP_Test_REST_Settings_Controller extends WP_Test_REST_Controller_Testcase $data = $response->get_data(); $this->assertEquals( array(), $data['mycustomsetting'] ); - // Invalid value + // Invalid value. update_option( 'mycustomsetting', array( @@ -379,7 +379,7 @@ class WP_Test_REST_Settings_Controller extends WP_Test_REST_Controller_Testcase public function update_setting_custom_callback( $result, $name, $value, $args ) { if ( 'title' === $name && 'The new title!' === $value ) { - // Do not allow changing the title in this case + // Do not allow changing the title in this case. return true; } diff --git a/tests/phpunit/tests/rest-api/rest-tags-controller.php b/tests/phpunit/tests/rest-api/rest-tags-controller.php index b842f811bc..b3804fefeb 100644 --- a/tests/phpunit/tests/rest-api/rest-tags-controller.php +++ b/tests/phpunit/tests/rest-api/rest-tags-controller.php @@ -131,13 +131,13 @@ class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { } public function test_context_param() { - // Collection + // Collection. $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/tags' ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); $this->assertEqualSets( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); - // Single + // Single. $tag1 = $this->factory->tag->create( array( 'name' => 'Season 5' ) ); $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/tags/' . $tag1 ); $response = rest_get_server()->dispatch( $request ); @@ -887,8 +887,8 @@ class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { $this->assertEquals( 200, $response->get_status() ); $request->set_param( 'slug', $term->slug ); - // Run twice to make sure that the update still succeeds even if no DB - // rows are updated. + // Run twice to make sure that the update still succeeds + // even if no DB rows are updated. $response = rest_get_server()->dispatch( $request ); $this->assertEquals( 200, $response->get_status() ); @@ -980,7 +980,7 @@ class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { } public function verify_tag_roundtrip( $input = array(), $expected_output = array() ) { - // Create the tag + // Create the tag. $request = new WP_REST_Request( 'POST', '/wp/v2/tags' ); foreach ( $input as $name => $value ) { $request->set_param( $name, $value ); @@ -989,16 +989,16 @@ class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { $this->assertEquals( 201, $response->get_status() ); $actual_output = $response->get_data(); - // Compare expected API output to actual API output + // Compare expected API output to actual API output. $this->assertEquals( $expected_output['name'], $actual_output['name'] ); $this->assertEquals( $expected_output['description'], $actual_output['description'] ); - // Compare expected API output to WP internal values + // Compare expected API output to WP internal values. $tag = get_term_by( 'id', $actual_output['id'], 'post_tag' ); $this->assertEquals( $expected_output['name'], $tag->name ); $this->assertEquals( $expected_output['description'], $tag->description ); - // Update the tag + // Update the tag. $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/tags/%d', $actual_output['id'] ) ); foreach ( $input as $name => $value ) { $request->set_param( $name, $value ); @@ -1007,11 +1007,11 @@ class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { $this->assertEquals( 200, $response->get_status() ); $actual_output = $response->get_data(); - // Compare expected API output to actual API output + // Compare expected API output to actual API output. $this->assertEquals( $expected_output['name'], $actual_output['name'] ); $this->assertEquals( $expected_output['description'], $actual_output['description'] ); - // Compare expected API output to WP internal values + // Compare expected API output to WP internal values. $tag = get_term_by( 'id', $actual_output['id'], 'post_tag' ); $this->assertEquals( $expected_output['name'], $tag->name ); $this->assertEquals( $expected_output['description'], $tag->description ); diff --git a/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php b/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php index 7b367b09a1..e75dcd66c9 100644 --- a/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php +++ b/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php @@ -33,13 +33,13 @@ class WP_Test_REST_Taxonomies_Controller extends WP_Test_REST_Controller_Testcas } public function test_context_param() { - // Collection + // Collection. $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/taxonomies' ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); $this->assertEqualSets( array( 'view', 'edit', 'embed' ), $data['endpoints'][0]['args']['context']['enum'] ); - // Single + // Single. $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/taxonomies/post_tag' ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); @@ -246,7 +246,7 @@ class WP_Test_REST_Taxonomies_Controller extends WP_Test_REST_Controller_Testcas * Utility function to filter down to only public taxonomies */ private function get_public_taxonomies( $taxonomies ) { - // Pass through array_values to re-index after filtering + // Pass through array_values to re-index after filtering. return array_values( array_filter( $taxonomies, array( $this, 'is_public' ) ) ); } diff --git a/tests/phpunit/tests/rest-api/rest-users-controller.php b/tests/phpunit/tests/rest-api/rest-users-controller.php index 6b1bd39854..955dd9220a 100644 --- a/tests/phpunit/tests/rest-api/rest-users-controller.php +++ b/tests/phpunit/tests/rest-api/rest-users-controller.php @@ -164,13 +164,13 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { } public function test_context_param() { - // Collection + // Collection. $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/users' ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); $this->assertEquals( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); - // Single + // Single. $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/users/' . self::$user ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); @@ -663,7 +663,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { $request->set_param( 'search', 'yololololo' ); $response = rest_get_server()->dispatch( $request ); $this->assertEquals( 1, count( $response->get_data() ) ); - // default to wildcard search + // Default to wildcard search. $adam_id = $this->factory->user->create( array( 'role' => 'author', @@ -788,7 +788,10 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { $this->assertEquals( array( 'taco', 'enchilada', 'burrito' ), $slugs ); } - // Note: Do not test using editor role as there is an editor role created in testing and it makes it hard to test this functionality. + /** + * Note: Do not test using editor role as there is an editor role created in testing, + * and it makes it hard to test this functionality. + */ public function test_get_items_roles() { wp_set_current_user( self::$user ); @@ -947,10 +950,8 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { $this->assertArrayHasKey( 96, $data['avatar_urls'] ); $user = get_user_by( 'id', self::$editor ); - /** - * Ignore the subdomain, since 'get_avatar_url randomly sets the Gravatar - * server when building the url string. - */ + // Ignore the subdomain, since get_avatar_url() randomly sets + // the Gravatar server when building the URL string. $this->assertEquals( substr( get_avatar_url( $user->user_email ), 9 ), substr( $data['avatar_urls'][96], 9 ) ); } @@ -1196,7 +1197,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { 'url' => 'http://example.com', ); - // Username rules are different (more strict) for multisite; see `wpmu_validate_user_signup` + // Username rules are different (more strict) for multisite; see `wpmu_validate_user_signup`. if ( is_multisite() ) { $params['username'] = 'no-dashes-allowed'; } @@ -1521,7 +1522,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { $this->check_add_edit_user_response( $response, true ); - // Check that the name has been updated correctly + // Check that the name has been updated correctly. $new_data = $response->get_data(); $this->assertEquals( 'New Name', $new_data['first_name'] ); $user = get_userdata( $user_id ); @@ -1546,8 +1547,8 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d', self::$editor ) ); $request->set_param( 'slug', $user->user_nicename ); - // Run twice to make sure that the update still succeeds even if no DB - // rows are updated. + // Run twice to make sure that the update still succeeds + // even if no DB rows are updated. $response = rest_get_server()->dispatch( $request ); $this->assertEquals( 200, $response->get_status() ); @@ -1768,7 +1769,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { $response = rest_get_server()->dispatch( $request ); $this->check_add_edit_user_response( $response, true ); - // Check that the name has been updated correctly + // Check that the name has been updated correctly. $new_data = $response->get_data(); $this->assertEquals( 'JSON Name', $new_data['first_name'] ); $this->assertEquals( 'New Last', $new_data['last_name'] ); @@ -2035,11 +2036,12 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { $response = rest_get_server()->dispatch( $request ); if ( is_multisite() ) { - // Site administrators can promote users, as verified by the - // previous test, but they cannot perform other user-editing - // operations. This also tests the branch of logic that verifies - // that no parameters other than 'id' and 'roles' are specified for - // a roles update. + /* + * Site administrators can promote users, as verified by the previous test, + * but they cannot perform other user-editing operations. + * This also tests the branch of logic that verifies that no parameters + * other than 'id' and 'roles' are specified for a roles update. + */ $this->assertErrorResponse( 'rest_cannot_edit', $response, 403 ); } else { $this->assertEquals( 200, $response->get_status() ); @@ -2066,10 +2068,10 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { public function verify_user_roundtrip( $input = array(), $expected_output = array() ) { if ( isset( $input['id'] ) ) { - // Existing user; don't try to create one + // Existing user; don't try to create one. $user_id = $input['id']; } else { - // Create a new user + // Create a new user. $request = new WP_REST_Request( 'POST', '/wp/v2/users' ); foreach ( $input as $name => $value ) { $request->set_param( $name, $value ); @@ -2079,7 +2081,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { $this->assertEquals( 201, $response->get_status() ); $actual_output = $response->get_data(); - // Compare expected API output to actual API output + // Compare expected API output to actual API output. $this->assertEquals( $expected_output['username'], $actual_output['username'] ); $this->assertEquals( $expected_output['name'], $actual_output['name'] ); $this->assertEquals( $expected_output['first_name'], $actual_output['first_name'] ); @@ -2088,7 +2090,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { $this->assertEquals( $expected_output['description'], $actual_output['description'] ); $this->assertEquals( $expected_output['nickname'], $actual_output['nickname'] ); - // Compare expected API output to WP internal values + // Compare expected API output to WP internal values. $user = get_userdata( $actual_output['id'] ); $this->assertEquals( $expected_output['username'], $user->user_login ); $this->assertEquals( $expected_output['name'], $user->display_name ); @@ -2102,7 +2104,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { $user_id = $actual_output['id']; } - // Update the user + // Update the user. $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d', $user_id ) ); foreach ( $input as $name => $value ) { if ( 'username' !== $name ) { @@ -2113,7 +2115,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { $this->assertEquals( 200, $response->get_status() ); $actual_output = $response->get_data(); - // Compare expected API output to actual API output + // Compare expected API output to actual API output. if ( isset( $expected_output['username'] ) ) { $this->assertEquals( $expected_output['username'], $actual_output['username'] ); } @@ -2124,7 +2126,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { $this->assertEquals( $expected_output['description'], $actual_output['description'] ); $this->assertEquals( $expected_output['nickname'], $actual_output['nickname'] ); - // Compare expected API output to WP internal values + // Compare expected API output to WP internal values. $user = get_userdata( $actual_output['id'] ); if ( isset( $expected_output['username'] ) ) { $this->assertEquals( $expected_output['username'], $user->user_login ); @@ -2387,7 +2389,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { $response = rest_get_server()->dispatch( $request ); $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); - // Ensure the user still exists + // Ensure the user still exists. $user = get_user_by( 'id', $user_id ); $this->assertNotEmpty( $user ); } @@ -2459,7 +2461,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { $this->assertEquals( 200, $response->get_status() ); - // Check that the post has been updated correctly + // Check that the post has been updated correctly. $post = get_post( $test_post ); $this->assertEquals( $reassign_id, $post->post_author ); } diff --git a/tests/phpunit/tests/rewrite.php b/tests/phpunit/tests/rewrite.php index 76c1cc4712..c6ddedd914 100644 --- a/tests/phpunit/tests/rewrite.php +++ b/tests/phpunit/tests/rewrite.php @@ -143,11 +143,11 @@ class Tests_Rewrite extends WP_UnitTestCase { // Cleanup. remove_filter( 'home_url', array( $this, '_filter_http_home_url' ), 10 ); - // Test the tests: + // Test the tests. $this->assertSame( 'http', parse_url( $permalink, PHP_URL_SCHEME ) ); $this->assertSame( 'https', parse_url( $network_home, PHP_URL_SCHEME ) ); - // Test that the url_to_postid() call matched: + // Test that the url_to_postid() call matched. $this->assertEquals( $post_id, $url_to_postid ); } @@ -371,7 +371,7 @@ class Tests_Rewrite extends WP_UnitTestCase { ) ); - // This url should NOT return a post ID + // This url should NOT return a post ID. $badurl = site_url( '/example-collision' ); $this->assertEquals( 0, url_to_postid( $badurl ) ); } @@ -392,7 +392,7 @@ class Tests_Rewrite extends WP_UnitTestCase { ) ); - // This url should NOT return a post ID + // This url should NOT return a post ID. $badurl = network_home_url( '/example-collision' ); $this->assertEquals( 0, url_to_postid( $badurl ) ); diff --git a/tests/phpunit/tests/rewrite/numericSlugs.php b/tests/phpunit/tests/rewrite/numericSlugs.php index 83e1443985..2cf315f0d0 100644 --- a/tests/phpunit/tests/rewrite/numericSlugs.php +++ b/tests/phpunit/tests/rewrite/numericSlugs.php @@ -35,7 +35,7 @@ class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { ) ); - // Force an ID that resembles a year format + // Force an ID that resembles a year format. $wpdb->update( $wpdb->posts, array( @@ -65,7 +65,7 @@ class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { ) ); - // Force an ID that resembles a year format + // Force an ID that resembles a year format. $wpdb->update( $wpdb->posts, array( diff --git a/tests/phpunit/tests/shortcode.php b/tests/phpunit/tests/shortcode.php index a978779c9a..d92bb8ff55 100644 --- a/tests/phpunit/tests/shortcode.php +++ b/tests/phpunit/tests/shortcode.php @@ -293,13 +293,13 @@ class Tests_Shortcode extends WP_UnitTestCase { $out = do_shortcode( '[[baztag foo="bar"]the content[/baztag]]' ); $this->assertEquals( '[baztag foo="bar"]the content[/baztag]', $out ); - // double escaped + // Double escaped. $out = do_shortcode( '[[[footag]]] [[[bartag foo="bar"]]]' ); $this->assertEquals( '[[footag]] [[bartag foo="bar"]]', $out ); } function test_tag_not_escaped() { - // these have square brackets on either end but aren't actually escaped + // These have square brackets on either end but aren't actually escaped. $out = do_shortcode( '[[footag] [bartag foo="bar"]]' ); $this->assertEquals( '[foo = foo = bar]', $out ); @@ -357,7 +357,7 @@ EOF; * @ticket 6562 */ function test_utf8_whitespace_1() { - // NO-BREAK SPACE: U+00A0 + // NO-BREAK SPACE: U+00A0. do_shortcode( "[test-shortcode-tag foo=\"bar\" \xC2\xA0baz=\"123\"]" ); $this->assertEquals( array( @@ -373,7 +373,7 @@ EOF; * @ticket 6562 */ function test_utf8_whitespace_2() { - // ZERO WIDTH SPACE: U+200B + // ZERO WIDTH SPACE: U+200B. do_shortcode( "[test-shortcode-tag foo=\"bar\" \xE2\x80\x8Babc=\"def\"]" ); $this->assertEquals( array( @@ -389,7 +389,7 @@ EOF; * @ticket 14050 */ function test_shortcode_unautop() { - // a blank line is added at the end, so test with it already there + // A blank line is added at the end, so test with it already there. $test_string = "[footag]\n"; $this->assertEquals( $test_string, shortcode_unautop( wpautop( $test_string ) ) ); } @@ -434,7 +434,7 @@ EOF; return array( 'gallery' ); } - // Store passed in shortcode_atts_{$shortcode} args + // Store passed in shortcode_atts_{$shortcode} args. function _filter_atts( $out, $pairs, $atts ) { $this->filter_atts_out = $out; $this->filter_atts_pairs = $pairs; @@ -442,14 +442,14 @@ EOF; return $out; } - // Filter shortcode atts in various ways + // Filter shortcode atts in various ways. function _filter_atts2( $out, $pairs, $atts ) { - // If foo attribute equals "foo1", change it to be default value + // If foo attribute equals "foo1", change it to be default value. if ( isset( $out['foo'] ) && 'foo1' === $out['foo'] ) { $out['foo'] = $pairs['foo']; } - // If baz attribute is set, remove it + // If baz attribute is set, remove it. if ( isset( $out['baz'] ) ) { unset( $out['baz'] ); } @@ -618,7 +618,7 @@ EOF; '', ), array( - '

    ', // Shortcodes will never be stripped inside elements. + '
    ', // Shortcodes will never be stripped inside elements. '
    ', ), array( @@ -781,23 +781,23 @@ EOF; * @ticket 37906 */ public function test_pre_do_shortcode_tag() { - // does nothing if no filters are set up + // Does nothing if no filters are set up. $str = 'pre_do_shortcode_tag'; add_shortcode( $str, array( $this, '_shortcode_pre_do_shortcode_tag' ) ); $result_nofilter = do_shortcode( "[{$str}]" ); $this->assertSame( 'foo', $result_nofilter ); - // short-circuit with filter + // Short-circuit with filter. add_filter( 'pre_do_shortcode_tag', array( $this, '_filter_pre_do_shortcode_tag_bar' ) ); $result_filter = do_shortcode( "[{$str}]" ); $this->assertSame( 'bar', $result_filter ); - // respect priority + // Respect priority. add_filter( 'pre_do_shortcode_tag', array( $this, '_filter_pre_do_shortcode_tag_p11' ), 11 ); $result_priority = do_shortcode( "[{$str}]" ); $this->assertSame( 'p11', $result_priority ); - // pass arguments + // Pass arguments. $arr = array( 'return' => 'p11', 'key' => $str, @@ -851,23 +851,23 @@ EOF; * @ticket 32790 */ public function test_do_shortcode_tag_filter() { - // does nothing if no filters are set up + // Does nothing if no filters are set up. $str = 'do_shortcode_tag'; add_shortcode( $str, array( $this, '_shortcode_do_shortcode_tag' ) ); $result_nofilter = do_shortcode( "[{$str}]" ); $this->assertSame( 'foo', $result_nofilter ); - // modify output with filter + // Modify output with filter. add_filter( 'do_shortcode_tag', array( $this, '_filter_do_shortcode_tag_replace' ) ); $result_filter = do_shortcode( "[{$str}]" ); $this->assertSame( 'fee', $result_filter ); - // respect priority + // Respect priority. add_filter( 'do_shortcode_tag', array( $this, '_filter_do_shortcode_tag_generate' ), 11 ); $result_priority = do_shortcode( "[{$str}]" ); $this->assertSame( 'foobar', $result_priority ); - // pass arguments + // Pass arguments. $arr = array( 'return' => 'foobar', 'key' => $str, diff --git a/tests/phpunit/tests/taxonomy.php b/tests/phpunit/tests/taxonomy.php index 6d30ccf778..62f098fe0a 100644 --- a/tests/phpunit/tests/taxonomy.php +++ b/tests/phpunit/tests/taxonomy.php @@ -16,7 +16,7 @@ class Tests_Taxonomy extends WP_UnitTestCase { * @ticket 5417 */ function test_get_unknown_taxonomies() { - // taxonomies for an unknown object type + // Taxonomies for an unknown object type. $this->assertEquals( array(), get_object_taxonomies( rand_str() ) ); $this->assertEquals( array(), get_object_taxonomies( '' ) ); $this->assertEquals( array(), get_object_taxonomies( 0 ) ); @@ -26,7 +26,7 @@ class Tests_Taxonomy extends WP_UnitTestCase { function test_get_post_taxonomy() { foreach ( get_object_taxonomies( 'post' ) as $taxonomy ) { $tax = get_taxonomy( $taxonomy ); - // should return an object with the correct taxonomy object type + // Should return an object with the correct taxonomy object type. $this->assertTrue( is_object( $tax ) ); $this->assertTrue( is_array( $tax->object_type ) ); $this->assertEquals( array( 'post' ), $tax->object_type ); @@ -108,7 +108,7 @@ class Tests_Taxonomy extends WP_UnitTestCase { function test_get_link_taxonomy() { foreach ( get_object_taxonomies( 'link' ) as $taxonomy ) { $tax = get_taxonomy( $taxonomy ); - // should return an object with the correct taxonomy object type + // Should return an object with the correct taxonomy object type. $this->assertTrue( is_object( $tax ) ); $this->assertTrue( is_array( $tax->object_type ) ); $this->assertEquals( array( 'link' ), $tax->object_type ); @@ -143,7 +143,7 @@ class Tests_Taxonomy extends WP_UnitTestCase { function test_register_taxonomy() { - // make up a new taxonomy name, and ensure it's unused + // Make up a new taxonomy name, and ensure it's unused. $tax = rand_str(); $this->assertFalse( taxonomy_exists( $tax ) ); @@ -151,13 +151,13 @@ class Tests_Taxonomy extends WP_UnitTestCase { $this->assertTrue( taxonomy_exists( $tax ) ); $this->assertFalse( is_taxonomy_hierarchical( $tax ) ); - // clean up + // Clean up. unset( $GLOBALS['wp_taxonomies'][ $tax ] ); } function test_register_hierarchical_taxonomy() { - // make up a new taxonomy name, and ensure it's unused + // Make up a new taxonomy name, and ensure it's unused. $tax = rand_str(); $this->assertFalse( taxonomy_exists( $tax ) ); @@ -165,7 +165,7 @@ class Tests_Taxonomy extends WP_UnitTestCase { $this->assertTrue( taxonomy_exists( $tax ) ); $this->assertTrue( is_taxonomy_hierarchical( $tax ) ); - // clean up + // Clean up. unset( $GLOBALS['wp_taxonomies'][ $tax ] ); } @@ -218,43 +218,43 @@ class Tests_Taxonomy extends WP_UnitTestCase { * @ticket 11058 */ function test_registering_taxonomies_to_object_types() { - // Create a taxonomy to test with + // Create a taxonomy to test with. $tax = 'test_tax'; $this->assertFalse( taxonomy_exists( $tax ) ); register_taxonomy( $tax, 'post', array( 'hierarchical' => true ) ); - // Create a post type to test with + // Create a post type to test with. $post_type = 'test_cpt'; $this->assertFalse( get_post_type( $post_type ) ); $this->assertObjectHasAttribute( 'name', register_post_type( $post_type ) ); - // Core taxonomy, core post type + // Core taxonomy, core post type. $this->assertTrue( unregister_taxonomy_for_object_type( 'category', 'post' ) ); $this->assertFalse( unregister_taxonomy_for_object_type( 'category', 'post' ) ); $this->assertTrue( register_taxonomy_for_object_type( 'category', 'post' ) ); - // Core taxonomy, non-core post type + // Core taxonomy, non-core post type. $this->assertTrue( register_taxonomy_for_object_type( 'category', $post_type ) ); $this->assertTrue( unregister_taxonomy_for_object_type( 'category', $post_type ) ); $this->assertFalse( unregister_taxonomy_for_object_type( 'category', $post_type ) ); $this->assertTrue( register_taxonomy_for_object_type( 'category', $post_type ) ); - // Core taxonomies, non-post object types + // Core taxonomies, non-post object types. $this->assertFalse( register_taxonomy_for_object_type( 'category', 'user' ) ); $this->assertFalse( unregister_taxonomy_for_object_type( 'category', 'user' ) ); - // Non-core taxonomy, core post type + // Non-core taxonomy, core post type. $this->assertTrue( unregister_taxonomy_for_object_type( $tax, 'post' ) ); $this->assertFalse( unregister_taxonomy_for_object_type( $tax, 'post' ) ); $this->assertTrue( register_taxonomy_for_object_type( $tax, 'post' ) ); - // Non-core taxonomy, non-core post type + // Non-core taxonomy, non-core post type. $this->assertTrue( register_taxonomy_for_object_type( $tax, $post_type ) ); $this->assertTrue( unregister_taxonomy_for_object_type( $tax, $post_type ) ); $this->assertFalse( unregister_taxonomy_for_object_type( $tax, $post_type ) ); $this->assertTrue( register_taxonomy_for_object_type( $tax, $post_type ) ); - // Non-core taxonomies, non-post object types + // Non-core taxonomies, non-post object types. $this->assertFalse( register_taxonomy_for_object_type( $tax, 'user' ) ); $this->assertFalse( unregister_taxonomy_for_object_type( $tax, 'user' ) ); @@ -396,12 +396,12 @@ class Tests_Taxonomy extends WP_UnitTestCase { function test_in_category() { $post = self::factory()->post->create_and_get(); - // in_category() returns false when first parameter is empty() + // in_category() returns false when first parameter is empty(). $this->assertFalse( in_category( '', $post ) ); $this->assertFalse( in_category( false, $post ) ); $this->assertFalse( in_category( null, $post ) ); - // Test expected behavior of in_category() + // Test expected behavior of in_category(). $term = wp_insert_term( 'Test', 'category' ); wp_set_object_terms( $post->ID, $term['term_id'], 'category' ); $this->assertTrue( in_category( $term['term_id'], $post ) ); @@ -947,7 +947,7 @@ class Tests_Taxonomy extends WP_UnitTestCase { 'post_type' => 'post', 'tax_input' => array( $taxonomy_name => array( - (string) $term_id, // Cast term_id as string to match whats sent in WP Admin. + (string) $term_id, // Cast term_id as string to match what's sent in WP Admin. ), ), ) diff --git a/tests/phpunit/tests/term.php b/tests/phpunit/tests/term.php index 0ab90d8189..4cc12a632c 100644 --- a/tests/phpunit/tests/term.php +++ b/tests/phpunit/tests/term.php @@ -50,14 +50,14 @@ class Tests_Term extends WP_UnitTestCase { * @ticket 5381 */ function test_is_term_type() { - // insert a term + // Insert a term. $term = rand_str(); $t = wp_insert_term( $term, $this->taxonomy ); $this->assertInternalType( 'array', $t ); $term_obj = get_term_by( 'name', $term, $this->taxonomy ); $this->assertEquals( $t['term_id'], term_exists( $term_obj->slug ) ); - // clean up + // Clean up. $this->assertTrue( wp_delete_term( $t['term_id'], $this->taxonomy ) ); } @@ -66,7 +66,7 @@ class Tests_Term extends WP_UnitTestCase { */ function test_wp_count_terms() { $count = wp_count_terms( 'category', array( 'hide_empty' => true ) ); - // there are 5 posts, all Uncategorized + // There are 5 posts, all Uncategorized. $this->assertEquals( 1, $count ); } @@ -135,11 +135,11 @@ class Tests_Term extends WP_UnitTestCase { $this->assertTrue( $t > 0 ); $this->assertEquals( $initial_count + 1, wp_count_terms( 'category' ) ); - // make sure the term exists + // Make sure the term exists. $this->assertTrue( term_exists( $term ) > 0 ); $this->assertTrue( term_exists( $t ) > 0 ); - // now delete it + // Now delete it. $this->assertTrue( wp_delete_category( $t ) ); $this->assertNull( term_exists( $term ) ); $this->assertNull( term_exists( $t ) ); diff --git a/tests/phpunit/tests/term/cache.php b/tests/phpunit/tests/term/cache.php index bfebe9338e..959c206f38 100644 --- a/tests/phpunit/tests/term/cache.php +++ b/tests/phpunit/tests/term/cache.php @@ -14,14 +14,14 @@ class Tests_Term_Cache extends WP_UnitTestCase { * @ticket 25711 */ function test_category_children_cache() { - // Test with only one Parent => Child + // Test with only one Parent => Child. $term_id1 = self::factory()->category->create(); $term_id1_child = self::factory()->category->create( array( 'parent' => $term_id1 ) ); $hierarchy = _get_term_hierarchy( 'category' ); $this->assertEquals( array( $term_id1 => array( $term_id1_child ) ), $hierarchy ); - // Add another Parent => Child + // Add another Parent => Child. $term_id2 = self::factory()->category->create(); $term_id2_child = self::factory()->category->create( array( 'parent' => $term_id2 ) ); $hierarchy = _get_term_hierarchy( 'category' ); diff --git a/tests/phpunit/tests/term/getTerms.php b/tests/phpunit/tests/term/getTerms.php index 6b8145e845..2c20a191eb 100644 --- a/tests/phpunit/tests/term/getTerms.php +++ b/tests/phpunit/tests/term/getTerms.php @@ -113,7 +113,7 @@ class Tests_Term_getTerms extends WP_UnitTestCase { $num_queries = $wpdb->num_queries; - // last_changed and num_queries should bump + // last_changed and num_queries should bump. $terms = get_terms( 'post_tag', array( 'update_term_meta_cache' => false ) ); $this->assertEquals( 3, count( $terms ) ); $time1 = wp_cache_get( 'last_changed', 'terms' ); @@ -137,7 +137,7 @@ class Tests_Term_getTerms extends WP_UnitTestCase { $this->set_up_three_posts_and_tags(); - // Prime cache + // Prime cache. $terms = get_terms( 'post_tag' ); $time1 = wp_cache_get( 'last_changed', 'terms' ); $num_queries = $wpdb->num_queries; @@ -165,7 +165,7 @@ class Tests_Term_getTerms extends WP_UnitTestCase { $this->set_up_three_posts_and_tags(); - // Prime cache + // Prime cache. $terms = get_terms( 'post_tag' ); $time1 = wp_cache_get( 'last_changed', 'terms' ); $num_queries = $wpdb->num_queries; @@ -775,7 +775,7 @@ class Tests_Term_getTerms extends WP_UnitTestCase { * @ticket 27123 */ function test_get_term_children_recursion() { - // Assume there is a way to insert a term with the parent pointing to itself + // Assume there is a way to insert a term with the parent pointing to itself. // See: https://core.trac.wordpress.org/changeset/15806 remove_filter( 'wp_update_term_parent', 'wp_check_term_hierarchy_for_loops', 10 ); @@ -926,7 +926,7 @@ class Tests_Term_getTerms extends WP_UnitTestCase { ); $this->assertEqualSets( array( $t ), $found ); - // array format. + // Array format. $found = get_terms( 'wptests_tax', array( @@ -1025,7 +1025,7 @@ class Tests_Term_getTerms extends WP_UnitTestCase { Montreal PEI */ - // Level 1 + // Level 1. $canada = self::factory()->term->create( array( 'name' => 'Canada', @@ -1033,7 +1033,7 @@ class Tests_Term_getTerms extends WP_UnitTestCase { ) ); - // Level 2 + // Level 2. $ontario = self::factory()->term->create( array( 'name' => 'Ontario', @@ -1056,7 +1056,7 @@ class Tests_Term_getTerms extends WP_UnitTestCase { ) ); - // Level 3 + // Level 3. $toronto = self::factory()->term->create( array( 'name' => 'Toronto', @@ -1079,7 +1079,7 @@ class Tests_Term_getTerms extends WP_UnitTestCase { ) ); - // Level 4 + // Level 4. $nepean = self::factory()->term->create( array( 'name' => 'Nepean', @@ -1107,7 +1107,7 @@ class Tests_Term_getTerms extends WP_UnitTestCase { $tax = 'location'; register_taxonomy( $tax, 'post', array( 'hierarchical' => true ) ); - // Level 1 + // Level 1. $canada = self::factory()->term->create( array( 'name' => 'Canada', @@ -1115,7 +1115,7 @@ class Tests_Term_getTerms extends WP_UnitTestCase { ) ); - // Level 2 + // Level 2. $ontario = self::factory()->term->create( array( 'name' => 'Ontario', @@ -1131,7 +1131,7 @@ class Tests_Term_getTerms extends WP_UnitTestCase { ) ); - // Level 3 + // Level 3. $laval = self::factory()->term->create( array( 'name' => 'Laval', @@ -1147,7 +1147,7 @@ class Tests_Term_getTerms extends WP_UnitTestCase { ) ); - // Level 4 + // Level 4. $dorval = self::factory()->term->create( array( 'name' => 'Dorval', @@ -2221,7 +2221,7 @@ class Tests_Term_getTerms extends WP_UnitTestCase { public function test_hierarchical_false_with_parent() { $initial_terms = $this->create_hierarchical_terms(); - // Case where hierarchical is false + // Case where hierarchical is false. $terms = get_terms( 'category', array( @@ -2230,7 +2230,7 @@ class Tests_Term_getTerms extends WP_UnitTestCase { ) ); - // Verify that there are no children + // Verify that there are no children. $this->assertEquals( 0, count( $terms ) ); } @@ -2240,7 +2240,7 @@ class Tests_Term_getTerms extends WP_UnitTestCase { public function test_hierarchical_true_with_parent() { $initial_terms = $this->create_hierarchical_terms(); - // Case where hierarchical is true + // Case where hierarchical is true. $terms = get_terms( 'category', array( @@ -2249,7 +2249,7 @@ class Tests_Term_getTerms extends WP_UnitTestCase { ) ); - // Verify that the children with non-empty descendants are returned + // Verify that the children with non-empty descendants are returned. $expected = array( $initial_terms['two_term']['term_id'], $initial_terms['five_term']['term_id'], @@ -2267,7 +2267,7 @@ class Tests_Term_getTerms extends WP_UnitTestCase { 'category' ); - // Case where hierarchical is false + // Case where hierarchical is false. $terms = get_terms( 'category', array( @@ -2287,7 +2287,7 @@ class Tests_Term_getTerms extends WP_UnitTestCase { public function test_hierarchical_false_with_child_of_should_not_return_grandchildren() { $initial_terms = $this->create_hierarchical_terms(); - // Case where hierarchical is false + // Case where hierarchical is false. $terms = get_terms( 'category', array( @@ -2296,14 +2296,14 @@ class Tests_Term_getTerms extends WP_UnitTestCase { ) ); - // Verify that there are no children + // Verify that there are no children. $this->assertEquals( 0, count( $terms ) ); } public function test_hierarchical_true_with_child_of_should_return_grandchildren() { $initial_terms = $this->create_hierarchical_terms(); - // Case where hierarchical is true + // Case where hierarchical is true. $terms = get_terms( 'category', array( @@ -2399,7 +2399,7 @@ class Tests_Term_getTerms extends WP_UnitTestCase { public function test_hierarchical_false_parent_should_override_child_of() { $initial_terms = $this->create_hierarchical_terms(); - // Case where hierarchical is false + // Case where hierarchical is false. $terms = get_terms( 'category', array( @@ -2409,7 +2409,7 @@ class Tests_Term_getTerms extends WP_UnitTestCase { ) ); - // hierarchical=false means that descendants are not fetched. + // 'hierarchical=false' means that descendants are not fetched. $this->assertEquals( 0, count( $terms ) ); } @@ -2419,7 +2419,7 @@ class Tests_Term_getTerms extends WP_UnitTestCase { public function test_hierarchical_true_parent_overrides_child_of() { $initial_terms = $this->create_hierarchical_terms(); - // Case where hierarchical is true + // Case where hierarchical is true. $terms = get_terms( 'category', array( @@ -2429,7 +2429,7 @@ class Tests_Term_getTerms extends WP_UnitTestCase { ) ); - // Verify that parent takes precedence over child_of + // Verify that parent takes precedence over child_of. $expected = array( $initial_terms['two_term']['term_id'], $initial_terms['five_term']['term_id'], @@ -2997,14 +2997,16 @@ class Tests_Term_getTerms extends WP_UnitTestCase { } protected function create_hierarchical_terms() { - // Set up the following hierarchy: - // - One - // - Two - // - Three (1) - // - Four - // - Five - // - Six (1) - // - Seven + /* + * Set up the following hierarchy: + * - One + * - Two + * - Three (1) + * - Four + * - Five + * - Six (1) + * - Seven + */ $one_term = wp_insert_term( 'One', 'category' @@ -3052,7 +3054,7 @@ class Tests_Term_getTerms extends WP_UnitTestCase { ) ); - // Ensure child terms are not empty + // Ensure child terms are not empty. $first_post_id = self::factory()->post->create(); $second_post_id = self::factory()->post->create(); wp_set_post_terms( $first_post_id, array( $three_term['term_id'] ), 'category' ); diff --git a/tests/phpunit/tests/term/query.php b/tests/phpunit/tests/term/query.php index 699330851b..67ac3c7d34 100644 --- a/tests/phpunit/tests/term/query.php +++ b/tests/phpunit/tests/term/query.php @@ -481,7 +481,7 @@ class Tests_Term_Query extends WP_UnitTestCase { wp_set_object_terms( $post_id, array( $term_ids[0], $term_ids[1] ), 'wptests_tax' ); $terms = get_the_terms( $post_id, 'wptests_tax' ); $this->assertEquals( array( $term_ids[0], $term_ids[1] ), wp_list_pluck( $terms, 'term_id' ) ); - // Flip the order + // Flip the order. wp_set_object_terms( $post_id, array( $term_ids[1], $term_ids[0] ), 'wptests_tax' ); $terms = get_the_terms( $post_id, 'wptests_tax' ); $this->assertEquals( array( $term_ids[1], $term_ids[0] ), wp_list_pluck( $terms, 'term_id' ) ); @@ -511,7 +511,7 @@ class Tests_Term_Query extends WP_UnitTestCase { wp_set_object_terms( $post_id, array( $term_ids[0], $term_ids[1] ), 'wptests_tax' ); $terms = wp_get_object_terms( $post_id, array( 'category', 'wptests_tax' ) ); $this->assertEquals( array( $term_ids[0], $term_ids[1], 1 ), wp_list_pluck( $terms, 'term_id' ) ); - // Flip the order + // Flip the order. wp_set_object_terms( $post_id, array( $term_ids[1], $term_ids[0] ), 'wptests_tax' ); $terms = wp_get_object_terms( $post_id, array( 'category', 'wptests_tax' ) ); $this->assertEquals( array( $term_ids[1], $term_ids[0], 1 ), wp_list_pluck( $terms, 'term_id' ) ); diff --git a/tests/phpunit/tests/term/slashes.php b/tests/phpunit/tests/term/slashes.php index 414b831238..e384d68499 100644 --- a/tests/phpunit/tests/term/slashes.php +++ b/tests/phpunit/tests/term/slashes.php @@ -22,7 +22,7 @@ class Tests_Term_Slashes extends WP_Ajax_UnitTestCase { } /** - * Tests the model function that expects slashed data + * Tests the model function that expects slashed data. */ function test_wp_insert_term() { $taxonomies = array( @@ -69,7 +69,7 @@ class Tests_Term_Slashes extends WP_Ajax_UnitTestCase { } /** - * Tests the model function that expects slashed data + * Tests the model function that expects slashed data. */ function test_wp_update_term() { $taxonomies = array( diff --git a/tests/phpunit/tests/term/taxQuery.php b/tests/phpunit/tests/term/taxQuery.php index 58b57599d7..b464dba3f0 100644 --- a/tests/phpunit/tests/term/taxQuery.php +++ b/tests/phpunit/tests/term/taxQuery.php @@ -256,7 +256,7 @@ class Tests_Term_Tax_Query extends WP_UnitTestCase { array( 'taxonomy' => 'category', 'terms' => array( $t1 ), - 'field' => 'foo', // Anything defaults to term_id + 'field' => 'foo', // Anything defaults to term_id. ), ) ); diff --git a/tests/phpunit/tests/term/termExists.php b/tests/phpunit/tests/term/termExists.php index a99aefbb76..27aa2791df 100644 --- a/tests/phpunit/tests/term/termExists.php +++ b/tests/phpunit/tests/term/termExists.php @@ -259,14 +259,14 @@ class Tests_TermExists extends WP_UnitTestCase { function test_term_exists_known() { register_taxonomy( 'wptests_tax', 'post' ); - // insert a term + // Insert a term. $term = rand_str(); $t = wp_insert_term( $term, 'wptests_tax' ); $this->assertInternalType( 'array', $t ); $this->assertEquals( $t['term_id'], term_exists( $t['term_id'] ) ); $this->assertEquals( $t['term_id'], term_exists( $term ) ); - // clean up + // Clean up. $this->assertTrue( wp_delete_term( $t['term_id'], 'wptests_tax' ) ); _unregister_taxonomy( 'wptests_tax' ); } diff --git a/tests/phpunit/tests/term/wpGenerateTagCloud.php b/tests/phpunit/tests/term/wpGenerateTagCloud.php index ef64bd7686..dec65d440e 100644 --- a/tests/phpunit/tests/term/wpGenerateTagCloud.php +++ b/tests/phpunit/tests/term/wpGenerateTagCloud.php @@ -43,23 +43,17 @@ class Tests_WP_Generate_Tag_Cloud extends WP_UnitTestCase { */ function empty_tags_data_provider() { return array( - /** - * when format => array, we should be getting an empty array back - */ + // When 'format' => 'array', we should be getting an empty array back. array( array(), array( 'format' => 'array' ), ), - /** - * List format returns an empty string - */ + // List format returns an empty string. array( '', array( 'format' => 'list' ), ), - /** - * $args can be an array or ''. Either should return an empty string - */ + // $args can be an array or ''. Either should return an empty string. array( '', array(), @@ -302,7 +296,7 @@ class Tests_WP_Generate_Tag_Cloud extends WP_UnitTestCase { $tags = array(); foreach ( $terms as $term ) { - //add the link + // Add the link. $term->link = get_term_link( $term ); $tags[] = $term; diff --git a/tests/phpunit/tests/term/wpGetObjectTerms.php b/tests/phpunit/tests/term/wpGetObjectTerms.php index 0c64872497..c998c88c28 100644 --- a/tests/phpunit/tests/term/wpGetObjectTerms.php +++ b/tests/phpunit/tests/term/wpGetObjectTerms.php @@ -18,11 +18,11 @@ class Tests_Term_WpGetObjectTerms extends WP_UnitTestCase { $terms_1 = array( 'Foo', 'Bar', 'Baz' ); $terms_1_slugs = array( 'foo', 'bar', 'baz' ); - // set the initial terms + // Set the initial terms. $tt_1 = wp_set_object_terms( $post_id, $terms_1, $this->taxonomy ); $this->assertEquals( 3, count( $tt_1 ) ); - // make sure they're correct + // Make sure they're correct. $terms = wp_get_object_terms( $post_id, $this->taxonomy, @@ -897,7 +897,7 @@ class Tests_Term_WpGetObjectTerms extends WP_UnitTestCase { public function filter_get_object_terms( $terms ) { $term_ids = wp_list_pluck( $terms, 'term_id' ); - // all terms should still be objects + // All terms should still be objects. return $terms; } @@ -941,14 +941,14 @@ class Tests_Term_WpGetObjectTerms extends WP_UnitTestCase { $terms = array( 'foo', 'bar', 'baz' ); $set = wp_set_object_terms( $post_id, $terms, $taxonomy ); - // Filter for maintaining term order + // Filter for maintaining term order. add_filter( 'wp_get_object_terms_args', array( $this, 'filter_wp_get_object_terms_args' ), 10, 3 ); - // Test directly + // Test directly. $get_object_terms = wp_get_object_terms( $post_id, $taxonomy, array( 'fields' => 'names' ) ); $this->assertEquals( $terms, $get_object_terms ); - // Test metabox taxonomy (admin advanced edit) + // Test metabox taxonomy (admin advanced edit). $terms_to_edit = get_terms_to_edit( $post_id, $taxonomy ); $this->assertEquals( implode( ',', $terms ), $terms_to_edit ); } diff --git a/tests/phpunit/tests/term/wpInsertTerm.php b/tests/phpunit/tests/term/wpInsertTerm.php index 160bbab62e..fb2ea1399e 100644 --- a/tests/phpunit/tests/term/wpInsertTerm.php +++ b/tests/phpunit/tests/term/wpInsertTerm.php @@ -8,8 +8,8 @@ class Tests_Term_WpInsertTerm extends WP_UnitTestCase { parent::setUp(); _clean_term_filters(); - // insert one term into every post taxonomy - // otherwise term_ids and term_taxonomy_ids might be identical, which could mask bugs + // Insert one term into every post taxonomy. + // Otherwise term_ids and term_taxonomy_ids might be identical, which could mask bugs. $term = 'seed_term'; foreach ( get_object_taxonomies( 'post' ) as $tax ) { wp_insert_term( $term, $tax ); @@ -20,7 +20,7 @@ class Tests_Term_WpInsertTerm extends WP_UnitTestCase { $taxonomy = 'wptests_tax'; register_taxonomy( $taxonomy, 'post' ); - // a new unused term + // A new unused term. $term = 'term'; $this->assertNull( term_exists( $term ) ); @@ -33,11 +33,11 @@ class Tests_Term_WpInsertTerm extends WP_UnitTestCase { $this->assertTrue( $t['term_taxonomy_id'] > 0 ); $this->assertEquals( $initial_count + 1, wp_count_terms( $taxonomy ) ); - // make sure the term exists + // Make sure the term exists. $this->assertTrue( term_exists( $term ) > 0 ); $this->assertTrue( term_exists( $t['term_id'] ) > 0 ); - // now delete it + // Now delete it. add_filter( 'delete_term', array( $this, 'deleted_term_cb' ), 10, 5 ); $this->assertTrue( wp_delete_term( $t['term_id'], $taxonomy ) ); remove_filter( 'delete_term', array( $this, 'deleted_term_cb' ), 10, 5 ); @@ -189,7 +189,7 @@ class Tests_Term_WpInsertTerm extends WP_UnitTestCase { $this->assertNotWPError( $term ); $this->assertTrue( empty( $term->errors ) ); - // Test existing term name with unique slug + // Test existing term name with unique slug. $term1 = self::factory()->tag->create( array( 'name' => 'Bozo', @@ -198,12 +198,12 @@ class Tests_Term_WpInsertTerm extends WP_UnitTestCase { ); $this->assertNotWPError( $term1 ); - // Test an existing term name + // Test an existing term name. $term2 = self::factory()->tag->create( array( 'name' => 'Bozo' ) ); $this->assertWPError( $term2 ); $this->assertNotEmpty( $term2->errors ); - // Test named terms ending in special characters + // Test named terms ending in special characters. $term3 = self::factory()->tag->create( array( 'name' => 'T$' ) ); $term4 = self::factory()->tag->create( array( 'name' => 'T$$' ) ); $term5 = self::factory()->tag->create( array( 'name' => 'T$$$' ) ); @@ -216,7 +216,7 @@ class Tests_Term_WpInsertTerm extends WP_UnitTestCase { $terms = array_map( 'get_tag', array( $term3, $term4, $term5, $term6 ) ); $this->assertCount( 4, array_unique( wp_list_pluck( $terms, 'slug' ) ) ); - // Test named terms with only special characters + // Test named terms with only special characters. $term8 = self::factory()->tag->create( array( 'name' => '$' ) ); $term9 = self::factory()->tag->create( array( 'name' => '$$' ) ); $term10 = self::factory()->tag->create( array( 'name' => '$$$' ) ); diff --git a/tests/phpunit/tests/term/wpSetObjectTerms.php b/tests/phpunit/tests/term/wpSetObjectTerms.php index c49899623f..c3d146b34d 100644 --- a/tests/phpunit/tests/term/wpSetObjectTerms.php +++ b/tests/phpunit/tests/term/wpSetObjectTerms.php @@ -18,7 +18,7 @@ class Tests_Term_WpSetObjectTerms extends WP_UnitTestCase { $non_hier = rand_str( 10 ); $hier = rand_str( 10 ); - // Register taxonomies + // Register taxonomies. register_taxonomy( $non_hier, array() ); register_taxonomy( $hier, array( 'hierarchical' => true ) ); @@ -112,17 +112,17 @@ class Tests_Term_WpSetObjectTerms extends WP_UnitTestCase { foreach ( $ids as $id ) { $tt = wp_set_object_terms( $id, array_values( $term_id ), $this->taxonomy ); - // should return three term taxonomy ids + // Should return three term taxonomy IDs. $this->assertEquals( 3, count( $tt ) ); } - // each term should be associated with every post + // Each term should be associated with every post. foreach ( $term_id as $term => $id ) { $actual = get_objects_in_term( $id, $this->taxonomy ); $this->assertEquals( $ids, array_map( 'intval', $actual ) ); } - // each term should have a count of 5 + // Each term should have a count of 5. foreach ( array_keys( $term_id ) as $term ) { $t = get_term_by( 'name', $term, $this->taxonomy ); $this->assertEquals( 5, $t->count ); @@ -140,22 +140,22 @@ class Tests_Term_WpSetObjectTerms extends WP_UnitTestCase { foreach ( $ids as $id ) { $tt = wp_set_object_terms( $id, $terms, $this->taxonomy ); - // should return three term taxonomy ids + // Should return three term taxonomy IDs. $this->assertEquals( 3, count( $tt ) ); - // remember which term has which term_id + // Remember which term has which term_id. for ( $i = 0; $i < 3; $i++ ) { $term = get_term_by( 'name', $terms[ $i ], $this->taxonomy ); $term_id[ $terms[ $i ] ] = intval( $term->term_id ); } } - // each term should be associated with every post + // Each term should be associated with every post. foreach ( $term_id as $term => $id ) { $actual = get_objects_in_term( $id, $this->taxonomy ); $this->assertEquals( $ids, array_map( 'intval', $actual ) ); } - // each term should have a count of 5 + // Each term should have a count of 5. foreach ( $terms as $term ) { $t = get_term_by( 'name', $term, $this->taxonomy ); $this->assertEquals( 5, $t->count ); @@ -163,7 +163,7 @@ class Tests_Term_WpSetObjectTerms extends WP_UnitTestCase { } function test_set_object_terms_invalid() { - // bogus taxonomy + // Bogus taxonomy. $result = wp_set_object_terms( self::$post_ids[0], array( rand_str() ), rand_str() ); $this->assertWPError( $result ); } @@ -243,12 +243,13 @@ class Tests_Term_WpSetObjectTerms extends WP_UnitTestCase { _unregister_taxonomy( 'wptests_tax' ); } + /** + * Set some terms on an object; then change them while leaving one intact. + */ function test_change_object_terms_by_id() { - // set some terms on an object; then change them while leaving one intact - $post_id = self::$post_ids[0]; - // first set: 3 terms + // First set: 3 terms. $terms_1 = array(); for ( $i = 0; $i < 3; $i++ ) { $term = "term_{$i}"; @@ -257,7 +258,7 @@ class Tests_Term_WpSetObjectTerms extends WP_UnitTestCase { $terms_1[ $i ] = $result['term_id']; } - // second set: one of the original terms, plus one new term + // Second set: one of the original terms, plus one new term. $terms_2 = array(); $terms_2[0] = $terms_1[1]; @@ -265,11 +266,11 @@ class Tests_Term_WpSetObjectTerms extends WP_UnitTestCase { $result = wp_insert_term( $term, $this->taxonomy ); $terms_2[1] = $result['term_id']; - // set the initial terms + // Set the initial terms. $tt_1 = wp_set_object_terms( $post_id, $terms_1, $this->taxonomy ); $this->assertEquals( 3, count( $tt_1 ) ); - // make sure they're correct + // Make sure they're correct. $terms = wp_get_object_terms( $post_id, $this->taxonomy, @@ -280,11 +281,11 @@ class Tests_Term_WpSetObjectTerms extends WP_UnitTestCase { ); $this->assertEquals( $terms_1, $terms ); - // change the terms + // Change the terms. $tt_2 = wp_set_object_terms( $post_id, $terms_2, $this->taxonomy ); $this->assertEquals( 2, count( $tt_2 ) ); - // make sure they're correct + // Make sure they're correct. $terms = wp_get_object_terms( $post_id, $this->taxonomy, @@ -295,24 +296,25 @@ class Tests_Term_WpSetObjectTerms extends WP_UnitTestCase { ); $this->assertEquals( $terms_2, $terms ); - // make sure the tt id for 'bar' matches + // Make sure the term taxonomy ID for 'bar' matches. $this->assertEquals( $tt_1[1], $tt_2[0] ); } + /** + * Set some terms on an object; then change them while leaving one intact. + */ function test_change_object_terms_by_name() { - // set some terms on an object; then change them while leaving one intact - $post_id = self::$post_ids[0]; $terms_1 = array( 'foo', 'bar', 'baz' ); $terms_2 = array( 'bar', 'bing' ); - // set the initial terms + // Set the initial terms. $tt_1 = wp_set_object_terms( $post_id, $terms_1, $this->taxonomy ); $this->assertEquals( 3, count( $tt_1 ) ); - // make sure they're correct + // Make sure they're correct. $terms = wp_get_object_terms( $post_id, $this->taxonomy, @@ -323,11 +325,11 @@ class Tests_Term_WpSetObjectTerms extends WP_UnitTestCase { ); $this->assertEquals( $terms_1, $terms ); - // change the terms + // Change the terms. $tt_2 = wp_set_object_terms( $post_id, $terms_2, $this->taxonomy ); $this->assertEquals( 2, count( $tt_2 ) ); - // make sure they're correct + // Make sure they're correct. $terms = wp_get_object_terms( $post_id, $this->taxonomy, @@ -338,7 +340,7 @@ class Tests_Term_WpSetObjectTerms extends WP_UnitTestCase { ); $this->assertEquals( $terms_2, $terms ); - // make sure the tt id for 'bar' matches + // Make sure the term taxonomy ID for 'bar' matches. $this->assertEquals( $tt_1[1], $tt_2[0] ); } diff --git a/tests/phpunit/tests/theme.php b/tests/phpunit/tests/theme.php index c20906a121..5cd6f968a4 100644 --- a/tests/phpunit/tests/theme.php +++ b/tests/phpunit/tests/theme.php @@ -91,7 +91,7 @@ class Tests_Theme extends WP_UnitTestCase { $this->assertInstanceOf( 'WP_Theme', $theme ); $this->assertFalse( $theme->errors() ); $_theme = wp_get_theme( $theme->get_stylesheet() ); - // This primes internal WP_Theme caches for the next assertion (headers_sanitized, textdomain_loaded) + // This primes internal WP_Theme caches for the next assertion (headers_sanitized, textdomain_loaded). $this->assertEquals( $theme->get( 'Name' ), $_theme->get( 'Name' ) ); $this->assertEquals( $theme, $_theme ); } @@ -102,7 +102,7 @@ class Tests_Theme extends WP_UnitTestCase { */ function test_get_themes_contents() { $themes = get_themes(); - // Generic tests that should hold true for any theme + // Generic tests that should hold true for any theme. foreach ( $themes as $k => $theme ) { // Don't run these checks for custom themes. if ( empty( $theme['Author'] ) || false === strpos( $theme['Author'], 'WordPress' ) ) { @@ -112,7 +112,7 @@ class Tests_Theme extends WP_UnitTestCase { $this->assertEquals( $theme['Name'], $k ); $this->assertNotEmpty( $theme['Title'] ); - // important attributes should all be set + // Important attributes should all be set. $default_headers = array( 'Title' => 'Theme Title', 'Version' => 'Version', @@ -125,7 +125,7 @@ class Tests_Theme extends WP_UnitTestCase { 'Description' => 'Description', 'Author' => 'Author', 'Tags' => 'Tags', - // Introduced in WordPress 2.9 + // Introduced in WordPress 2.9. 'Theme Root' => 'Theme Root', 'Theme Root URI' => 'Theme Root URI', ); @@ -133,17 +133,17 @@ class Tests_Theme extends WP_UnitTestCase { $this->assertTrue( isset( $theme[ $name ] ) ); } - // Make the tests work both for WordPress 2.8.5 and WordPress 2.9-rare + // Make the tests work both for WordPress 2.8.5 and WordPress 2.9-rare. $dir = isset( $theme['Theme Root'] ) ? '' : WP_CONTENT_DIR; - // important attributes should all not be empty as well + // Important attributes should all not be empty as well. $this->assertNotEmpty( $theme['Description'] ); $this->assertNotEmpty( $theme['Author'] ); $this->assertTrue( version_compare( $theme['Version'], 0 ) > 0 ); $this->assertNotEmpty( $theme['Template'] ); $this->assertNotEmpty( $theme['Stylesheet'] ); - // template files should all exist + // Template files should all exist. $this->assertTrue( is_array( $theme['Template Files'] ) ); $this->assertTrue( count( $theme['Template Files'] ) > 0 ); foreach ( $theme['Template Files'] as $file ) { @@ -151,7 +151,7 @@ class Tests_Theme extends WP_UnitTestCase { $this->assertTrue( is_readable( $dir . $file ) ); } - // css files should all exist + // CSS files should all exist. $this->assertTrue( is_array( $theme['Stylesheet Files'] ) ); $this->assertTrue( count( $theme['Stylesheet Files'] ) > 0 ); foreach ( $theme['Stylesheet Files'] as $file ) { @@ -270,7 +270,7 @@ class Tests_Theme extends WP_UnitTestCase { for ( $i = 0; $i < 3; $i++ ) { foreach ( $themes as $name => $theme ) { - // switch to this theme + // Switch to this theme. if ( 2 === $i ) { switch_theme( $theme['Template'], $theme['Stylesheet'] ); } else { @@ -279,7 +279,7 @@ class Tests_Theme extends WP_UnitTestCase { $this->assertEquals( $name, get_current_theme() ); - // make sure the various get_* functions return the correct values + // Make sure the various get_* functions return the correct values. $this->assertEquals( $theme['Template'], get_template() ); $this->assertEquals( $theme['Stylesheet'], get_stylesheet() ); @@ -292,24 +292,26 @@ class Tests_Theme extends WP_UnitTestCase { $this->assertEquals( $root_fs . '/' . get_stylesheet(), get_stylesheet_directory() ); $this->assertEquals( $root_uri . '/' . get_stylesheet(), get_stylesheet_directory_uri() ); $this->assertEquals( $root_uri . '/' . get_stylesheet() . '/style.css', get_stylesheet_uri() ); - # $this->assertEquals($root_uri . '/' . get_stylesheet(), get_locale_stylesheet_uri()); + // $this->assertEquals( $root_uri . '/' . get_stylesheet(), get_locale_stylesheet_uri() ); $this->assertEquals( $root_fs . '/' . get_template(), get_template_directory() ); $this->assertEquals( $root_uri . '/' . get_template(), get_template_directory_uri() ); - //get_query_template + // get_query_template() - // template file that doesn't exist + // Template file that doesn't exist. $this->assertEquals( '', get_query_template( rand_str() ) ); - // template files that do exist - //foreach ($theme['Template Files'] as $path) { - //$file = basename($path, '.php'); - // FIXME: untestable because get_query_template uses TEMPLATEPATH - //$this->assertEquals('', get_query_template($file)); - //} + // Template files that do exist. + /* + foreach ( $theme['Template Files'] as $path ) { + $file = basename($path, '.php'); + FIXME: untestable because get_query_template() uses TEMPLATEPATH. + $this->assertEquals('', get_query_template($file)); + } + */ - // these are kind of tautologies but at least exercise the code + // These are kind of tautologies but at least exercise the code. $this->assertEquals( get_404_template(), get_query_template( '404' ) ); $this->assertEquals( get_archive_template(), get_query_template( 'archive' ) ); $this->assertEquals( get_author_template(), get_query_template( 'author' ) ); @@ -324,14 +326,14 @@ class Tests_Theme extends WP_UnitTestCase { $this->assertEquals( get_tag_template(), get_query_template( 'tag' ) ); - // nb: this probably doesn't run because WP_INSTALLING is defined + // nb: This probably doesn't run because WP_INSTALLING is defined. $this->assertTrue( validate_current_theme() ); } } } function test_switch_theme_bogus() { - // try switching to a theme that doesn't exist + // Try switching to a theme that doesn't exist. $template = rand_str(); $style = rand_str(); update_option( 'template', $template ); @@ -342,7 +344,7 @@ class Tests_Theme extends WP_UnitTestCase { $this->assertNotFalse( $theme->errors() ); $this->assertFalse( $theme->exists() ); - // these return the bogus name - perhaps not ideal behaviour? + // These return the bogus name - perhaps not ideal behaviour? $this->assertEquals( $template, get_template() ); $this->assertEquals( $style, get_stylesheet() ); } @@ -370,7 +372,8 @@ class Tests_Theme extends WP_UnitTestCase { $wp_customize = new WP_Customize_Manager(); do_action( 'customize_register', $wp_customize ); - // The post_date for auto-drafts is bumped to match the changeset post_date whenever it is modified to keep them from from being garbage collected by wp_delete_auto_drafts(). + // The post_date for auto-drafts is bumped to match the changeset post_date whenever it is modified + // to keep them from from being garbage collected by wp_delete_auto_drafts(). $wp_customize->save_changeset_post( array( 'data' => $data, diff --git a/tests/phpunit/tests/theme/WPTheme.php b/tests/phpunit/tests/theme/WPTheme.php index 1761e1d721..b06ac49628 100644 --- a/tests/phpunit/tests/theme/WPTheme.php +++ b/tests/phpunit/tests/theme/WPTheme.php @@ -13,7 +13,7 @@ class Tests_Theme_WPTheme extends WP_UnitTestCase { add_filter( 'theme_root', array( $this, '_theme_root' ) ); add_filter( 'stylesheet_root', array( $this, '_theme_root' ) ); add_filter( 'template_root', array( $this, '_theme_root' ) ); - // clear caches + // Clear caches. wp_clean_themes_cache(); unset( $GLOBALS['wp_themes'] ); } @@ -28,14 +28,14 @@ class Tests_Theme_WPTheme extends WP_UnitTestCase { parent::tearDown(); } - // replace the normal theme root dir with our premade test dir + // Replace the normal theme root directory with our premade test directory. function _theme_root( $dir ) { return $this->theme_root; } function test_new_WP_Theme_top_level() { $theme = new WP_Theme( 'theme1', $this->theme_root ); - //Meta + // Meta. $this->assertEquals( 'My Theme', $theme->get( 'Name' ) ); $this->assertEquals( 'http://example.org/', $theme->get( 'ThemeURI' ) ); $this->assertEquals( 'An example theme', $theme->get( 'Description' ) ); @@ -46,7 +46,7 @@ class Tests_Theme_WPTheme extends WP_UnitTestCase { $this->assertEquals( 'publish', $theme->get( 'Status' ) ); $this->assertEquals( array(), $theme->get( 'Tags' ) ); - //Important + // Important. $this->assertEquals( 'theme1', $theme->get_stylesheet() ); $this->assertEquals( 'theme1', $theme->get_template() ); } @@ -54,7 +54,7 @@ class Tests_Theme_WPTheme extends WP_UnitTestCase { function test_new_WP_Theme_subdir() { $theme = new WP_Theme( 'subdir/theme2', $this->theme_root ); - //Meta + // Meta. $this->assertEquals( 'My Subdir Theme', $theme->get( 'Name' ) ); $this->assertEquals( 'http://example.org/', $theme->get( 'ThemeURI' ) ); $this->assertEquals( 'An example theme in a sub directory', $theme->get( 'Description' ) ); @@ -65,7 +65,7 @@ class Tests_Theme_WPTheme extends WP_UnitTestCase { $this->assertEquals( 'publish', $theme->get( 'Status' ) ); $this->assertEquals( array(), $theme->get( 'Tags' ) ); - //Important + // Important. $this->assertEquals( 'subdir/theme2', $theme->get_stylesheet() ); $this->assertEquals( 'subdir/theme2', $theme->get_template() ); } @@ -74,10 +74,10 @@ class Tests_Theme_WPTheme extends WP_UnitTestCase { * @ticket 20313 */ function test_new_WP_Theme_subdir_bad_root() { - // This is what get_theme_data() does when you pass it a style.css file for a theme in a subdir. + // This is what get_theme_data() does when you pass it a style.css file for a theme in a subdirectory. $theme = new WP_Theme( 'theme2', $this->theme_root . '/subdir' ); - //Meta + // Meta. $this->assertEquals( 'My Subdir Theme', $theme->get( 'Name' ) ); $this->assertEquals( 'http://example.org/', $theme->get( 'ThemeURI' ) ); $this->assertEquals( 'An example theme in a sub directory', $theme->get( 'Description' ) ); @@ -88,7 +88,7 @@ class Tests_Theme_WPTheme extends WP_UnitTestCase { $this->assertEquals( 'publish', $theme->get( 'Status' ) ); $this->assertEquals( array(), $theme->get( 'Tags' ) ); - //Important + // Important. $this->assertEquals( 'subdir/theme2', $theme->get_stylesheet() ); $this->assertEquals( 'subdir/theme2', $theme->get_template() ); } @@ -101,12 +101,12 @@ class Tests_Theme_WPTheme extends WP_UnitTestCase { // Make sure subdir/ is considered part of the stylesheet, as we must avoid encoding /'s. $this->assertEquals( 'subdir/theme with spaces', $theme->get_stylesheet() ); - // Check that in a URI path, we have raw url encoding (spaces become %20) + // Check that in a URI path, we have raw URL encoding (spaces become %20). // Don't try to verify the complete URI path. get_theme_root_uri() breaks down quickly. $this->assertEquals( 'theme%20with%20spaces', basename( $theme->get_stylesheet_directory_uri() ) ); $this->assertEquals( 'theme%20with%20spaces', basename( $theme->get_template_directory_uri() ) ); - // Check that wp_customize_url() uses url encoding, as it is a query arg (spaces become +) + // Check that wp_customize_url() uses URL encoding, as it is a query arg (spaces become +). $this->assertEquals( admin_url( 'customize.php?theme=theme+with+spaces' ), wp_customize_url( 'theme with spaces' ) ); } @@ -162,7 +162,7 @@ class Tests_Theme_WPTheme extends WP_UnitTestCase { $current_allowed_themes = get_site_option( 'allowedthemes' ); WP_Theme::network_enable_theme( $theme ); $new_allowed_themes = get_site_option( 'allowedthemes' ); - update_site_option( 'allowedthemes', $current_allowed_themes ); // reset previous value. + update_site_option( 'allowedthemes', $current_allowed_themes ); // Reset previous value. $current_allowed_themes['testtheme-1'] = true; // Add the new theme to the previous set. $this->assertEqualSetsWithIndex( $current_allowed_themes, $new_allowed_themes ); @@ -179,7 +179,7 @@ class Tests_Theme_WPTheme extends WP_UnitTestCase { $current_allowed_themes = get_site_option( 'allowedthemes' ); WP_Theme::network_enable_theme( $themes ); $new_allowed_themes = get_site_option( 'allowedthemes' ); - update_site_option( 'allowedthemes', $current_allowed_themes ); // reset previous value. + update_site_option( 'allowedthemes', $current_allowed_themes ); // Reset previous value. $current_allowed_themes = array_merge( $current_allowed_themes, array( @@ -210,7 +210,7 @@ class Tests_Theme_WPTheme extends WP_UnitTestCase { $disable_theme = 'existing-2'; WP_Theme::network_disable_theme( $disable_theme ); $new_allowed_themes = get_site_option( 'allowedthemes' ); - update_site_option( 'allowedthemes', $current_allowed_themes ); // reset previous value. + update_site_option( 'allowedthemes', $current_allowed_themes ); // Reset previous value. unset( $allowed_themes[ $disable_theme ] ); // Remove deleted theme from initial set. $this->assertEqualSetsWithIndex( $allowed_themes, $new_allowed_themes ); @@ -235,7 +235,7 @@ class Tests_Theme_WPTheme extends WP_UnitTestCase { $disable_themes = array( 'existing-4', 'existing-5' ); WP_Theme::network_disable_theme( $disable_themes ); $new_allowed_themes = get_site_option( 'allowedthemes' ); - update_site_option( 'allowedthemes', $current_allowed_themes ); // reset previous value. + update_site_option( 'allowedthemes', $current_allowed_themes ); // Reset previous value. unset( $allowed_themes['existing-4'] ); unset( $allowed_themes['existing-5'] ); diff --git a/tests/phpunit/tests/theme/support.php b/tests/phpunit/tests/theme/support.php index 86561a5c9b..ac33ce1445 100644 --- a/tests/phpunit/tests/theme/support.php +++ b/tests/phpunit/tests/theme/support.php @@ -78,7 +78,7 @@ class Tests_Theme_Support extends WP_UnitTestCase { // array of arguments, with the key of 'types' holding the post types. add_theme_support( 'post-thumbnails', array( 'types' => true ) ); $this->assertTrue( current_theme_supports( 'post-thumbnails' ) ); - $this->assertTrue( current_theme_supports( 'post-thumbnails', rand_str() ) ); // any type + $this->assertTrue( current_theme_supports( 'post-thumbnails', rand_str() ) ); // Any type. remove_theme_support( 'post-thumbnails' ); $this->assertFalse( current_theme_supports( 'post-thumbnails' ) ); } @@ -167,7 +167,7 @@ class Tests_Theme_Support extends WP_UnitTestCase { * @ticket 26900 */ function test_supports_menus() { - // Start fresh + // Start fresh. foreach ( get_registered_nav_menus() as $location => $desc ) { unregister_nav_menu( $location ); } diff --git a/tests/phpunit/tests/theme/themeDir.php b/tests/phpunit/tests/theme/themeDir.php index 51e5046bae..0b697ef492 100644 --- a/tests/phpunit/tests/theme/themeDir.php +++ b/tests/phpunit/tests/theme/themeDir.php @@ -19,7 +19,7 @@ class Tests_Theme_ThemeDir extends WP_UnitTestCase { add_filter( 'theme_root', array( $this, '_theme_root' ) ); add_filter( 'stylesheet_root', array( $this, '_theme_root' ) ); add_filter( 'template_root', array( $this, '_theme_root' ) ); - // clear caches + // Clear caches. wp_clean_themes_cache(); unset( $GLOBALS['wp_themes'] ); } @@ -34,7 +34,7 @@ class Tests_Theme_ThemeDir extends WP_UnitTestCase { parent::tearDown(); } - // replace the normal theme root dir with our premade test dir + // Replace the normal theme root directory with our premade test directory. function _theme_root( $dir ) { return $this->theme_root; } @@ -50,7 +50,7 @@ class Tests_Theme_ThemeDir extends WP_UnitTestCase { $this->assertFalse( empty( $theme ) ); - #echo gen_tests_array('theme', $theme); + // echo gen_tests_array( 'theme', $theme ); $this->assertEquals( 'WordPress Default', $theme['Name'] ); $this->assertEquals( 'WordPress Default', $theme['Title'] ); @@ -79,7 +79,7 @@ class Tests_Theme_ThemeDir extends WP_UnitTestCase { $this->assertFalse( empty( $theme ) ); - #echo gen_tests_array('theme', $theme); + // echo gen_tests_array( 'theme', $theme ); $this->assertEquals( 'Sandbox', $theme['Name'] ); $this->assertEquals( 'Sandbox', $theme['Title'] ); @@ -116,7 +116,7 @@ class Tests_Theme_ThemeDir extends WP_UnitTestCase { $theme = $themes['Stylesheet Only']; $this->assertFalse( empty( $theme ) ); - #echo gen_tests_array('theme', $theme); + // echo gen_tests_array( 'theme', $theme ); $this->assertEquals( 'Stylesheet Only', $theme['Name'] ); $this->assertEquals( 'Stylesheet Only', $theme['Title'] ); @@ -156,10 +156,10 @@ class Tests_Theme_ThemeDir extends WP_UnitTestCase { 'Sandbox', 'Stylesheet Only', 'My Theme', - 'My Theme/theme1', // duplicate theme should be given a unique name - 'My Subdir Theme', // theme in a subdirectory should work - 'Page Template Child Theme', // theme which inherits page templates - 'Page Template Theme', // theme with page templates for other test code + 'My Theme/theme1', // Duplicate theme should be given a unique name. + 'My Subdir Theme', // Theme in a subdirectory should work. + 'Page Template Child Theme', // Theme which inherits page templates. + 'Page Template Theme', // Theme with page templates for other test code. 'Theme with Spaces in the Directory', 'Internationalized Theme', 'camelCase', diff --git a/tests/phpunit/tests/upload.php b/tests/phpunit/tests/upload.php index 751bb709cd..dbf927059e 100644 --- a/tests/phpunit/tests/upload.php +++ b/tests/phpunit/tests/upload.php @@ -13,14 +13,14 @@ class Tests_Upload extends WP_UnitTestCase { } function _reset_options() { - // system defaults + // System defaults. update_option( 'upload_path', 'wp-content/uploads' ); update_option( 'upload_url_path', '' ); update_option( 'uploads_use_yearmonth_folders', 1 ); } function test_upload_dir_default() { - // wp_upload_dir() with default parameters + // wp_upload_dir() with default parameters. $info = wp_upload_dir(); $subdir = gmstrftime( '/%Y/%m' ); @@ -31,7 +31,7 @@ class Tests_Upload extends WP_UnitTestCase { } function test_upload_dir_relative() { - // wp_upload_dir() with a relative upload path that is not 'wp-content/uploads' + // wp_upload_dir() with a relative upload path that is not 'wp-content/uploads'. update_option( 'upload_path', 'foo/bar' ); $info = _wp_upload_dir(); $subdir = gmstrftime( '/%Y/%m' ); @@ -48,10 +48,10 @@ class Tests_Upload extends WP_UnitTestCase { function test_upload_dir_absolute() { $path = '/tmp/wp-unit-test'; - // wp_upload_dir() with an absolute upload path + // wp_upload_dir() with an absolute upload path. update_option( 'upload_path', $path ); - // doesn't make sense to use an absolute file path without setting the url path + // Doesn't make sense to use an absolute file path without setting the url path. update_option( 'upload_url_path', '/baz' ); // Use `_wp_upload_dir()` directly to bypass caching and work with the changed options. @@ -92,7 +92,7 @@ class Tests_Upload extends WP_UnitTestCase { } function test_upload_dir_empty() { - // upload path setting is empty - it should default to 'wp-content/uploads' + // Upload path setting is empty - it should default to 'wp-content/uploads'. update_option( 'upload_path', '' ); // Use `_wp_upload_dir()` directly to bypass caching and work with the changed options. diff --git a/tests/phpunit/tests/url.php b/tests/phpunit/tests/url.php index 66f4b77eb6..19e58a16ee 100644 --- a/tests/phpunit/tests/url.php +++ b/tests/phpunit/tests/url.php @@ -1,7 +1,8 @@ assertEquals( $home, home_url() ); $_SERVER['HTTPS'] = 'off'; $this->assertEquals( $home, home_url() ); - // If not in the admin, is_ssl() should determine the scheme + // If not in the admin, is_ssl() should determine the scheme. set_current_screen( 'front' ); $this->assertEquals( $home, home_url() ); $_SERVER['HTTPS'] = 'on'; $home = str_replace( 'http://', 'https://', $home ); $this->assertEquals( $home, home_url() ); - // Test with https in home + // Test with https in home. update_option( 'home', set_url_scheme( $home, 'https' ) ); - // Pretend to be in the site admin + // Pretend to be in the site admin. set_current_screen( 'dashboard' ); $home = get_option( 'home' ); - // home_url() should return whatever scheme is set in the home option when in the admin + // home_url() should return whatever scheme is set in the home option when in the admin. $_SERVER['HTTPS'] = 'on'; $this->assertEquals( $home, home_url() ); $_SERVER['HTTPS'] = 'off'; $this->assertEquals( $home, home_url() ); - // If not in the admin, is_ssl() should determine the scheme unless https hard-coded in home + // If not in the admin, is_ssl() should determine the scheme unless https hard-coded in home. set_current_screen( 'front' ); $this->assertEquals( $home, home_url() ); $_SERVER['HTTPS'] = 'on'; @@ -248,11 +249,11 @@ class Tests_URL extends WP_UnitTestCase { function test_network_home_url_from_admin() { $screen = get_current_screen(); - // Pretend to be in the site admin + // Pretend to be in the site admin. set_current_screen( 'dashboard' ); $home = network_home_url(); - // home_url() should return http when in the admin + // home_url() should return http when in the admin. $this->assertEquals( 0, strpos( $home, 'http://' ) ); $_SERVER['HTTPS'] = 'on'; $this->assertEquals( $home, network_home_url() ); @@ -260,7 +261,7 @@ class Tests_URL extends WP_UnitTestCase { $_SERVER['HTTPS'] = 'off'; $this->assertEquals( $home, network_home_url() ); - // If not in the admin, is_ssl() should determine the scheme + // If not in the admin, is_ssl() should determine the scheme. set_current_screen( 'front' ); $this->assertEquals( $home, network_home_url() ); $_SERVER['HTTPS'] = 'on'; @@ -349,12 +350,12 @@ class Tests_URL extends WP_UnitTestCase { $this->assertInstanceOf( 'WP_Post', $p ); $this->assertEquals( $post_id, $p->ID ); - // The same again to make sure a cached query returns the same result + // The same again to make sure a cached query returns the same result. $p = get_adjacent_post(); $this->assertInstanceOf( 'WP_Post', $p ); $this->assertEquals( $post_id, $p->ID ); - // Test next + // Test next. $p = get_adjacent_post( false, '', false ); $this->assertEquals( '', $p ); diff --git a/tests/phpunit/tests/user.php b/tests/phpunit/tests/user.php index 74c533b69d..704f8c518f 100644 --- a/tests/phpunit/tests/user.php +++ b/tests/phpunit/tests/user.php @@ -1,7 +1,8 @@ ID, $nusers, true ) ) { $found[] = $user->ID; } } - // make sure every user we created was returned + // Make sure every user we created was returned. $this->assertEqualSets( $nusers, $found ); } - // simple get/set tests for user_option functions + // Simple get/set tests for user_option functions. function test_user_option() { $key = rand_str(); $val = rand_str(); - // get an option that doesn't exist + // Get an option that doesn't exist. $this->assertFalse( get_user_option( $key, self::$author_id ) ); - // set and get + // Set and get. update_user_option( self::$author_id, $key, $val ); $this->assertEquals( $val, get_user_option( $key, self::$author_id ) ); - // change and get again + // Change and get again. $val2 = rand_str(); update_user_option( self::$author_id, $key, $val2 ); $this->assertEquals( $val2, get_user_option( $key, self::$author_id ) ); } - // simple tests for usermeta functions + /** + * Simple tests for usermeta functions. + */ function test_usermeta() { $key = 'key'; $val = 'value1'; - // get a meta key that doesn't exist + // Get a meta key that doesn't exist. $this->assertEquals( '', get_user_meta( self::$author_id, $key, true ) ); - // set and get + // Set and get. update_user_meta( self::$author_id, $key, $val ); $this->assertEquals( $val, get_user_meta( self::$author_id, $key, true ) ); - // change and get again + // Change and get again. $val2 = 'value2'; update_user_meta( self::$author_id, $key, $val2 ); $this->assertEquals( $val2, get_user_meta( self::$author_id, $key, true ) ); - // delete and get + // Delete and get. delete_user_meta( self::$author_id, $key ); $this->assertEquals( '', get_user_meta( self::$author_id, $key, true ) ); - // delete by key AND value + // Delete by key AND value. update_user_meta( self::$author_id, $key, $val ); - // incorrect key: key still exists + // Incorrect key: key still exists. delete_user_meta( self::$author_id, $key, rand_str() ); $this->assertEquals( $val, get_user_meta( self::$author_id, $key, true ) ); - // correct key: deleted + // Correct key: deleted. delete_user_meta( self::$author_id, $key, $val ); $this->assertEquals( '', get_user_meta( self::$author_id, $key, true ) ); } - // test usermeta functions in array mode + /** + * Test usermeta functions in array mode. + */ function test_usermeta_array() { - // some values to set + // Some values to set. $vals = array( rand_str() => 'val-' . rand_str(), rand_str() => 'val-' . rand_str(), rand_str() => 'val-' . rand_str(), ); - // there is already some stuff in the array + // There is already some stuff in the array. $this->assertTrue( is_array( get_user_meta( self::$author_id ) ) ); foreach ( $vals as $k => $v ) { update_user_meta( self::$author_id, $k, $v ); } - // get the complete usermeta array + // Get the complete usermeta array. $out = get_user_meta( self::$author_id ); - // for reasons unclear, the resulting array is indexed numerically; meta keys are not included anywhere. - // so we'll just check to make sure our values are included somewhere. + // For reasons unclear, the resulting array is indexed numerically; meta keys are not included anywhere. + // So we'll just check to make sure our values are included somewhere. foreach ( $vals as $k => $v ) { $this->assertTrue( isset( $out[ $k ] ) && $out[ $k ][0] === $v ); } - // delete one key and check again + // Delete one key and check again. $keys = array_keys( $vals ); $key_to_delete = array_pop( $keys ); delete_user_meta( self::$author_id, $key_to_delete ); $out = get_user_meta( self::$author_id ); - // make sure that key is excluded from the results + // Make sure that key is excluded from the results. foreach ( $vals as $k => $v ) { if ( $k === $key_to_delete ) { $this->assertFalse( isset( $out[ $k ] ) ); @@ -178,7 +183,9 @@ class Tests_User extends WP_UnitTestCase { } } - // Test property magic functions for property get/set/isset. + /** + * Test property magic functions for property get/set/isset. + */ function test_user_properties() { $user = new WP_User( self::$author_id ); @@ -191,7 +198,7 @@ class Tests_User extends WP_UnitTestCase { $user->$key = 'foo'; $this->assertEquals( 'foo', $user->$key ); - $this->assertEquals( 'foo', $user->data->$key ); // This will fail with WP < 3.3 + $this->assertEquals( 'foo', $user->data->$key ); // This will fail with WP < 3.3. foreach ( get_object_vars( $user ) as $key => $value ) { $this->assertEquals( $value, $user->$key ); @@ -199,7 +206,7 @@ class Tests_User extends WP_UnitTestCase { } /** - * Test the magic __unset method + * Test the magic __unset() method. * * @ticket 20043 */ @@ -207,7 +214,7 @@ class Tests_User extends WP_UnitTestCase { // phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase $user = new WP_User( self::$author_id ); - // Test custom fields + // Test custom fields. $user->customField = 123; $this->assertEquals( $user->customField, 123 ); unset( $user->customField ); @@ -217,12 +224,13 @@ class Tests_User extends WP_UnitTestCase { } /** + * Test 'id' (lowercase). + * * @depends test_user_unset * @expectedDeprecated WP_User->id * @ticket 20043 */ function test_user_unset_lowercase_id( $user ) { - // Test 'id' (lowercase) $id = $user->id; unset( $user->id ); $this->assertSame( $id, $user->id ); @@ -230,17 +238,20 @@ class Tests_User extends WP_UnitTestCase { } /** + * Test 'ID'. + * * @depends test_user_unset_lowercase_id * @ticket 20043 */ function test_user_unset_uppercase_id( $user ) { - // Test 'ID' $this->assertNotEmpty( $user->ID ); unset( $user->ID ); $this->assertNotEmpty( $user->ID ); } - // Test meta property magic functions for property get/set/isset. + /** + * Test meta property magic functions for property get/set/isset. + */ function test_user_meta_properties() { $user = new WP_User( self::$author_id ); @@ -358,10 +369,10 @@ class Tests_User extends WP_UnitTestCase { $user = new WP_User( self::$author_id ); $this->assertEquals( 'test user', $user->get( 'display_name' ) ); - // Make sure there is no collateral damage to fields not in $user_data + // Make sure there is no collateral damage to fields not in $user_data. $this->assertEquals( 'about me', $user->get( 'description' ) ); - // Pass as stdClass + // Pass as stdClass. $user_data = array( 'ID' => self::$author_id, 'display_name' => 'a test user', @@ -376,7 +387,7 @@ class Tests_User extends WP_UnitTestCase { $this->assertEquals( 'some test user', $user->get( 'display_name' ) ); - // Test update of fields in _get_additional_user_keys() + // Test update of fields in _get_additional_user_keys(). $user_data = array( 'ID' => self::$author_id, 'use_ssl' => 1, @@ -452,7 +463,7 @@ class Tests_User extends WP_UnitTestCase { 'post_type' => 'post', ); - // insert a post and make sure the ID is ok + // Insert a post and make sure the ID is OK. $post_id = wp_insert_post( $post ); $this->assertTrue( is_numeric( $post_id ) ); @@ -477,6 +488,9 @@ class Tests_User extends WP_UnitTestCase { $this->assertFalse( get_userdata( array( 'array' ) ) ); } + /** + * @ticket 23480 + */ function test_user_get_data_by_id() { $user = WP_User::get_data_by( 'id', self::$author_id ); $this->assertInstanceOf( 'stdClass', $user ); @@ -569,7 +583,7 @@ class Tests_User extends WP_UnitTestCase { $pwd_before = $user->user_pass; wp_update_user( $user ); - // Reload the data + // Reload the data. $pwd_after = get_userdata( $testuserid )->user_pass; $this->assertEquals( $pwd_before, $pwd_after ); } @@ -746,7 +760,7 @@ class Tests_User extends WP_UnitTestCase { array( 'testuser' ), ); - // Multisite doesn't allow mixed case logins ever + // Multisite doesn't allow mixed case logins ever. if ( ! is_multisite() ) { $data[] = array( 'TestUser' ); } @@ -1287,7 +1301,7 @@ class Tests_User extends WP_UnitTestCase { $existing_email = get_option( 'admin_email' ); $new_email = 'new-admin-email@test.dev'; - // Give the site a name containing HTML entities + // Give the site a name containing HTML entities. update_option( 'blogname', ''Test' blog's "name" has <html entities> &' ); update_option_new_admin_email( $existing_email, $new_email ); @@ -1297,10 +1311,10 @@ class Tests_User extends WP_UnitTestCase { $recipient = $mailer->get_recipient( 'to' ); $email = $mailer->get_sent(); - // Assert reciepient is correct + // Assert recipient is correct. $this->assertSame( $new_email, $recipient->address, 'Admin email change notification recipient not as expected' ); - // Assert that HTML entites have been decode in body and subject + // Assert that HTML entites have been decode in body and subject. $this->assertContains( '\'Test\' blog\'s "name" has &', $email->subject, 'Email subject does not contain the decoded HTML entities' ); $this->assertNotContains( ''Test' blog's "name" has <html entities> &', $email->subject, $email->subject, 'Email subject does contains HTML entities' ); } @@ -1573,7 +1587,7 @@ class Tests_User extends WP_UnitTestCase { reset_phpmailer_instance(); - // Give the site a name containing HTML entities + // Give the site a name containing HTML entities. update_option( 'blogname', ''Test' blog's "name" has <html entities> &' ); // Set $_POST['email'] with new e-mail and $_POST['user_id'] with user's ID. @@ -1587,10 +1601,10 @@ class Tests_User extends WP_UnitTestCase { $recipient = $mailer->get_recipient( 'to' ); $email = $mailer->get_sent(); - // Assert recipient is correct + // Assert recipient is correct. $this->assertSame( 'new-email@test.dev', $recipient->address, 'User email change confirmation recipient not as expected' ); - // Assert that HTML entites have been decoded in body and subject + // Assert that HTML entites have been decoded in body and subject. $this->assertContains( '\'Test\' blog\'s "name" has &', $email->subject, 'Email subject does not contain the decoded HTML entities' ); $this->assertNotContains( ''Test' blog's "name" has <html entities> &', $email->subject, 'Email subject does contains HTML entities' ); } diff --git a/tests/phpunit/tests/user/author.php b/tests/phpunit/tests/user/author.php index 9793f09b1c..7adb2196c6 100644 --- a/tests/phpunit/tests/user/author.php +++ b/tests/phpunit/tests/user/author.php @@ -61,7 +61,7 @@ class Tests_User_Author_Template extends WP_UnitTestCase { add_user_meta( self::$author_id, 'user_description', 'user description' ); $this->assertEquals( 'user description', get_user_meta( self::$author_id, 'user_description', true ) ); // user_description in meta is ignored. The content of description is returned instead. - // See #20285 + // See #20285. $this->assertEquals( 'test_author', get_the_author_meta( 'user_description' ) ); $this->assertEquals( 'test_author', trim( get_the_author_meta( 'description' ) ) ); update_user_meta( self::$author_id, 'user_description', '' ); @@ -80,7 +80,7 @@ class Tests_User_Author_Template extends WP_UnitTestCase { } function test_get_the_author_posts() { - // Test with no global post, result should be 0 because no author is found + // Test with no global post, result should be 0 because no author is found. $this->assertEquals( 0, get_the_author_posts() ); $GLOBALS['post'] = self::$post_id; $this->assertEquals( 1, get_the_author_posts() ); diff --git a/tests/phpunit/tests/user/capabilities.php b/tests/phpunit/tests/user/capabilities.php index 487dcf25bf..4e4ea12035 100644 --- a/tests/phpunit/tests/user/capabilities.php +++ b/tests/phpunit/tests/user/capabilities.php @@ -1,8 +1,8 @@ _flush_roles(); } @@ -54,8 +54,8 @@ class Tests_User_Capabilities extends WP_UnitTestCase { function _flush_roles() { - // we want to make sure we're testing against the db, not just in-memory data - // this will flush everything and reload it from the db + // We want to make sure we're testing against the DB, not just in-memory data. + // This will flush everything and reload it from the DB. unset( $GLOBALS['wp_user_roles'] ); global $wp_roles; $wp_roles = new WP_Roles(); @@ -334,7 +334,9 @@ class Tests_User_Capabilities extends WP_UnitTestCase { } } - // test the tests + /** + * Test the tests. + */ function test_single_and_multisite_cap_tests_match() { $single_primitive = array_keys( $this->_getSingleSitePrimitiveCaps() ); $multi_primitive = array_keys( $this->_getMultiSitePrimitiveCaps() ); @@ -349,26 +351,28 @@ class Tests_User_Capabilities extends WP_UnitTestCase { $this->assertEquals( $single_meta, $multi_meta ); } - // test the tests + /** + * Test the tests. + */ function test_all_caps_of_users_are_being_tested() { $caps = $this->getPrimitiveCapsAndRoles(); - // `manage_links` is a special case + // `manage_links` is a special case. $this->assertSame( '0', get_option( 'link_manager_enabled' ) ); - // `unfiltered_upload` is a special case + // `unfiltered_upload` is a special case. $this->assertFalse( defined( 'ALLOW_UNFILTERED_UPLOADS' ) ); foreach ( self::$users as $role => $user ) { - // make sure the user is valid + // Make sure the user is valid. $this->assertTrue( $user->exists(), "User with {$role} role does not exist" ); $user_caps = $user->allcaps; unset( - // `manage_links` is a special case + // `manage_links` is a special case. $user_caps['manage_links'], - // `unfiltered_upload` is a special case + // `unfiltered_upload` is a special case. $user_caps['unfiltered_upload'] ); @@ -406,9 +410,9 @@ class Tests_User_Capabilities extends WP_UnitTestCase { ); unset( - // `manage_links` is a special case in the caps tests: + // `manage_links` is a special case in the caps tests. $expected['manage_links'], - // `unfiltered_upload` is a special case in the caps tests: + // `unfiltered_upload` is a special case in the caps tests. $expected['unfiltered_upload'] ); @@ -505,16 +509,18 @@ class Tests_User_Capabilities extends WP_UnitTestCase { $this->assertSame( array(), $incorrect_meta_cap_checks, 'These capabilities are not meta' ); } - // test the default roles and caps + /** + * Test the default roles and caps. + */ function test_all_roles_and_caps() { $caps = $this->getAllCapsAndRoles(); foreach ( self::$users as $role => $user ) { - // make sure the user is valid + // Make sure the user is valid. $this->assertTrue( $user->exists(), "User with {$role} role does not exist" ); - // make sure the role name is correct + // Make sure the role name is correct. $this->assertEquals( array( $role ), $user->roles, "User should only have the {$role} role" ); foreach ( $caps as $cap => $roles ) { @@ -589,7 +595,9 @@ class Tests_User_Capabilities extends WP_UnitTestCase { return $allcaps; } - // special case for the link manager + /** + * Special case for the link manager. + */ function test_link_manager_caps() { $caps = array( 'manage_links' => array( 'administrator', 'editor' ), @@ -597,7 +605,7 @@ class Tests_User_Capabilities extends WP_UnitTestCase { $this->assertSame( '0', get_option( 'link_manager_enabled' ) ); - // no-one should have access to the link manager by default + // No-one should have access to the link manager by default. foreach ( self::$users as $role => $user ) { foreach ( $caps as $cap => $roles ) { $this->assertFalse( $user->has_cap( $cap ), "User with the {$role} role should not have the {$cap} capability" ); @@ -625,11 +633,13 @@ class Tests_User_Capabilities extends WP_UnitTestCase { } - // special case for unfiltered uploads + /** + * Special case for unfiltered uploads. + */ function test_unfiltered_upload_caps() { $this->assertFalse( defined( 'ALLOW_UNFILTERED_UPLOADS' ) ); - // no-one should have this cap + // No-one should have this cap. foreach ( self::$users as $role => $user ) { $this->assertFalse( $user->has_cap( 'unfiltered_upload' ), "User with the {$role} role should not have the unfiltered_upload capability" ); $this->assertFalse( user_can( $user, 'unfiltered_upload' ), "User with the {$role} role should not have the unfiltered_upload capability" ); @@ -741,14 +751,16 @@ class Tests_User_Capabilities extends WP_UnitTestCase { $this->assertFalse( user_can( $user, 'unfiltered_upload' ), 'Super Admins should not have the unfiltered_upload capability' ); } - // a role that doesn't exist + /** + * A role that doesn't exist. + */ function test_bogus_role() { $user = self::factory()->user->create_and_get( array( 'role' => 'invalid_role' ) ); - // make sure the user is valid + // Make sure the user is valid. $this->assertTrue( $user->exists(), 'User does not exist' ); - // make sure the role name is correct + // Make sure the role name is correct. $this->assertEquals( array(), $user->roles, 'User should not have any roles' ); $caps = $this->getAllCapsAndRoles(); @@ -759,16 +771,18 @@ class Tests_User_Capabilities extends WP_UnitTestCase { } } - // a user with multiple roles + /** + * A user with multiple roles. + */ function test_user_subscriber_contributor() { $user = self::$users['subscriber']; - // make sure the user is valid + // Make sure the user is valid. $this->assertTrue( $user->exists(), 'User does not exist' ); $user->add_role( 'contributor' ); - // user should have two roles now + // User should have two roles now. $this->assertEquals( array( 'subscriber', 'contributor' ), $user->roles ); $caps = $this->getAllCapsAndRoles(); @@ -784,12 +798,14 @@ class Tests_User_Capabilities extends WP_UnitTestCase { } $user->remove_role( 'contributor' ); - // user should have one role now + // User should have one role now. $this->assertEquals( array( 'subscriber' ), $user->roles ); } - // newly added empty role + /** + * Newly added empty role. + */ function test_add_empty_role() { global $wp_roles; @@ -801,10 +817,10 @@ class Tests_User_Capabilities extends WP_UnitTestCase { $user = self::factory()->user->create_and_get( array( 'role' => $role_name ) ); - // make sure the user is valid + // Make sure the user is valid. $this->assertTrue( $user->exists(), 'User does not exist' ); - // make sure the role name is correct + // Make sure the role name is correct. $this->assertEquals( array( $role_name ), $user->roles ); $caps = $this->getAllCapsAndRoles(); @@ -814,13 +830,15 @@ class Tests_User_Capabilities extends WP_UnitTestCase { $this->assertFalse( user_can( $user, $cap ), "User should not have the {$cap} capability" ); } - // clean up + // Clean up. remove_role( $role_name ); $this->_flush_roles(); $this->assertFalse( $wp_roles->is_role( $role_name ) ); } - // newly added role + /** + * Newly added role. + */ function test_add_role() { global $wp_roles; @@ -838,16 +856,16 @@ class Tests_User_Capabilities extends WP_UnitTestCase { $user = self::factory()->user->create_and_get( array( 'role' => $role_name ) ); - // make sure the user is valid + // Make sure the user is valid. $this->assertTrue( $user->exists(), 'User does not exist' ); - // make sure the role name is correct + // Make sure the role name is correct. $this->assertEquals( array( $role_name ), $user->roles ); $caps = $this->getPrimitiveCapsAndRoles(); foreach ( $caps as $cap => $roles ) { - // the user should have all the above caps + // The user should have all the above caps. if ( isset( $expected_caps[ $cap ] ) ) { $this->assertTrue( $user->has_cap( $cap ), "User should have the {$cap} capability" ); $this->assertTrue( user_can( $user, $cap ), "User should have the {$cap} capability" ); @@ -857,25 +875,27 @@ class Tests_User_Capabilities extends WP_UnitTestCase { } } - // clean up + // Clean up. remove_role( $role_name ); $this->_flush_roles(); $this->assertFalse( $wp_roles->is_role( $role_name ) ); } + /** + * Change the capabilites associated with a role and make sure the change + * is reflected in has_cap(). + */ function test_role_add_cap() { - // change the capabilites associated with a role and make sure the change is reflected in has_cap() - global $wp_roles; $role_name = 'janitor'; add_role( $role_name, 'Janitor', array( 'level_1' => true ) ); $this->_flush_roles(); $this->assertTrue( $wp_roles->is_role( $role_name ) ); - // assign a user to that role + // Assign a user to that role. $id = self::factory()->user->create( array( 'role' => $role_name ) ); - // now add a cap to the role + // Now add a cap to the role. $wp_roles->add_cap( $role_name, 'sweep_floor' ); $this->_flush_roles(); @@ -883,12 +903,12 @@ class Tests_User_Capabilities extends WP_UnitTestCase { $this->assertTrue( $user->exists(), "Problem getting user $id" ); $this->assertEquals( array( $role_name ), $user->roles ); - // the user should have all the above caps + // The user should have all the above caps. $this->assertTrue( $user->has_cap( $role_name ) ); $this->assertTrue( $user->has_cap( 'level_1' ) ); $this->assertTrue( $user->has_cap( 'sweep_floor' ) ); - // shouldn't have any other caps + // Shouldn't have any other caps. $caps = $this->getAllCapsAndRoles(); foreach ( $caps as $cap => $roles ) { if ( 'level_1' !== $cap ) { @@ -896,16 +916,18 @@ class Tests_User_Capabilities extends WP_UnitTestCase { } } - // clean up + // Clean up. remove_role( $role_name ); $this->_flush_roles(); $this->assertFalse( $wp_roles->is_role( $role_name ) ); } + /** + * Change the capabilites associated with a role and make sure the change + * is reflected in has_cap(). + */ function test_role_remove_cap() { - // change the capabilites associated with a role and make sure the change is reflected in has_cap() - global $wp_roles; $role_name = 'janitor'; add_role( @@ -920,10 +942,10 @@ class Tests_User_Capabilities extends WP_UnitTestCase { $this->_flush_roles(); $this->assertTrue( $wp_roles->is_role( $role_name ) ); - // assign a user to that role + // Assign a user to that role. $id = self::factory()->user->create( array( 'role' => $role_name ) ); - // now remove a cap from the role + // Now remove a cap from the role. $wp_roles->remove_cap( $role_name, 'polish_doorknobs' ); $this->_flush_roles(); @@ -931,48 +953,49 @@ class Tests_User_Capabilities extends WP_UnitTestCase { $this->assertTrue( $user->exists(), "Problem getting user $id" ); $this->assertEquals( array( $role_name ), $user->roles ); - // the user should have all the above caps + // The user should have all the above caps. $this->assertTrue( $user->has_cap( $role_name ) ); $this->assertTrue( $user->has_cap( 'level_1' ) ); $this->assertTrue( $user->has_cap( 'sweep_floor' ) ); - // shouldn't have the removed cap + // Shouldn't have the removed cap. $this->assertFalse( $user->has_cap( 'polish_doorknobs' ) ); - // clean up + // Clean up. remove_role( $role_name ); $this->_flush_roles(); $this->assertFalse( $wp_roles->is_role( $role_name ) ); } + /** + * Add an extra capability to a user. + */ function test_user_add_cap() { - // add an extra capability to a user - - // there are two contributors + // There are two contributors. $id_1 = self::factory()->user->create( array( 'role' => 'contributor' ) ); $id_2 = self::factory()->user->create( array( 'role' => 'contributor' ) ); - // user 1 has an extra capability + // User 1 has an extra capability. $user_1 = new WP_User( $id_1 ); $this->assertTrue( $user_1->exists(), "Problem getting user $id_1" ); $user_1->add_cap( 'publish_posts' ); - // re-fetch both users from the db + // Re-fetch both users from the DB. $user_1 = new WP_User( $id_1 ); $this->assertTrue( $user_1->exists(), "Problem getting user $id_1" ); $user_2 = new WP_User( $id_2 ); $this->assertTrue( $user_2->exists(), "Problem getting user $id_2" ); - // make sure they're both still contributors + // Make sure they're both still contributors. $this->assertEquals( array( 'contributor' ), $user_1->roles ); $this->assertEquals( array( 'contributor' ), $user_2->roles ); - // check the extra cap on both users + // Check the extra cap on both users. $this->assertTrue( $user_1->has_cap( 'publish_posts' ) ); $this->assertFalse( $user_2->has_cap( 'publish_posts' ) ); - // make sure the other caps didn't get messed up + // Make sure the other caps didn't get messed up. $caps = $this->getAllCapsAndRoles(); foreach ( $caps as $cap => $roles ) { if ( in_array( 'contributor', $roles, true ) || 'publish_posts' === $cap ) { @@ -984,107 +1007,110 @@ class Tests_User_Capabilities extends WP_UnitTestCase { } + /** + * Add an extra capability to a user then remove it. + */ function test_user_remove_cap() { - // add an extra capability to a user then remove it - - // there are two contributors + // There are two contributors. $id_1 = self::factory()->user->create( array( 'role' => 'contributor' ) ); $id_2 = self::factory()->user->create( array( 'role' => 'contributor' ) ); - // user 1 has an extra capability + // User 1 has an extra capability. $user_1 = new WP_User( $id_1 ); $this->assertTrue( $user_1->exists(), "Problem getting user $id_1" ); $user_1->add_cap( 'publish_posts' ); - // now remove the extra cap + // Now remove the extra cap. $user_1->remove_cap( 'publish_posts' ); - // re-fetch both users from the db + // Re-fetch both users from the DB. $user_1 = new WP_User( $id_1 ); $this->assertTrue( $user_1->exists(), "Problem getting user $id_1" ); $user_2 = new WP_User( $id_2 ); $this->assertTrue( $user_2->exists(), "Problem getting user $id_2" ); - // make sure they're both still contributors + // Make sure they're both still contributors. $this->assertEquals( array( 'contributor' ), $user_1->roles ); $this->assertEquals( array( 'contributor' ), $user_2->roles ); - // check the removed cap on both users + // Check the removed cap on both users. $this->assertFalse( $user_1->has_cap( 'publish_posts' ) ); $this->assertFalse( $user_2->has_cap( 'publish_posts' ) ); } + /** + * Make sure the user_level is correctly set and changed with the user's role. + */ function test_user_level_update() { - // make sure the user_level is correctly set and changed with the user's role - - // user starts as an author + // User starts as an author. $id = self::factory()->user->create( array( 'role' => 'author' ) ); $user = new WP_User( $id ); $this->assertTrue( $user->exists(), "Problem getting user $id" ); - // author = user level 2 + // Author = user level 2. $this->assertEquals( 2, $user->user_level ); - // they get promoted to editor - level should get bumped to 7 + // They get promoted to editor - level should get bumped to 7. $user->set_role( 'editor' ); $this->assertEquals( 7, $user->user_level ); - // demoted to contributor - level is reduced to 1 + // Demoted to contributor - level is reduced to 1. $user->set_role( 'contributor' ); $this->assertEquals( 1, $user->user_level ); - // if they have two roles, user_level should be the max of the two + // If they have two roles, user_level should be the max of the two. $user->add_role( 'editor' ); $this->assertEquals( array( 'contributor', 'editor' ), $user->roles ); $this->assertEquals( 7, $user->user_level ); } function test_user_remove_all_caps() { - // user starts as an author + // User starts as an author. $id = self::factory()->user->create( array( 'role' => 'author' ) ); $user = new WP_User( $id ); $this->assertTrue( $user->exists(), "Problem getting user $id" ); - // add some extra capabilities + // Add some extra capabilities. $user->add_cap( 'make_coffee' ); $user->add_cap( 'drink_coffee' ); - // re-fetch + // Re-fetch. $user = new WP_User( $id ); $this->assertTrue( $user->exists(), "Problem getting user $id" ); $this->assertTrue( $user->has_cap( 'make_coffee' ) ); $this->assertTrue( $user->has_cap( 'drink_coffee' ) ); - // all caps are removed + // All caps are removed. $user->remove_all_caps(); - // re-fetch + // Re-fetch. $user = new WP_User( $id ); $this->assertTrue( $user->exists(), "Problem getting user $id" ); - // all capabilities for the user should be gone + // All capabilities for the user should be gone. foreach ( $this->getAllCapsAndRoles() as $cap => $roles ) { $this->assertFalse( $user->has_cap( $cap ), "User should not have the {$cap} capability" ); } - // the extra capabilities should be gone + // The extra capabilities should be gone. $this->assertFalse( $user->has_cap( 'make_coffee' ) ); $this->assertFalse( $user->has_cap( 'drink_coffee' ) ); - // user level should be empty + // User level should be empty. $this->assertEmpty( $user->user_level ); } + /** + * Simple tests for some common meta capabilities. + */ function test_post_meta_caps() { - // simple tests for some common meta capabilities - - // Get our author + // Get our author. $author = self::$users['author']; - // make a post + // Make a post. $post = self::factory()->post->create( array( 'post_author' => $author->ID, @@ -1092,37 +1118,37 @@ class Tests_User_Capabilities extends WP_UnitTestCase { ) ); - // the author of the post + // The author of the post. $this->assertTrue( $author->exists(), "Problem getting user $author->ID" ); - // add some other users + // Add some other users. $admin = new WP_User( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); $author_2 = new WP_User( self::factory()->user->create( array( 'role' => 'author' ) ) ); $editor = new WP_User( self::factory()->user->create( array( 'role' => 'editor' ) ) ); $contributor = new WP_User( self::factory()->user->create( array( 'role' => 'contributor' ) ) ); - // administrators, editors and the post owner can edit it + // Administrators, editors and the post owner can edit it. $this->assertTrue( $admin->has_cap( 'edit_post', $post ) ); $this->assertTrue( $author->has_cap( 'edit_post', $post ) ); $this->assertTrue( $editor->has_cap( 'edit_post', $post ) ); - // other authors and contributors can't + // Other authors and contributors can't. $this->assertFalse( $author_2->has_cap( 'edit_post', $post ) ); $this->assertFalse( $contributor->has_cap( 'edit_post', $post ) ); - // administrators, editors and the post owner can delete it + // Administrators, editors and the post owner can delete it. $this->assertTrue( $admin->has_cap( 'delete_post', $post ) ); $this->assertTrue( $author->has_cap( 'delete_post', $post ) ); $this->assertTrue( $editor->has_cap( 'delete_post', $post ) ); - // other authors and contributors can't + // Other authors and contributors can't. $this->assertFalse( $author_2->has_cap( 'delete_post', $post ) ); $this->assertFalse( $contributor->has_cap( 'delete_post', $post ) ); - // administrators, editors, and authors can publish it + // Administrators, editors, and authors can publish it. $this->assertTrue( $admin->has_cap( 'publish_post', $post ) ); $this->assertTrue( $author->has_cap( 'publish_post', $post ) ); $this->assertTrue( $editor->has_cap( 'publish_post', $post ) ); $this->assertTrue( $author_2->has_cap( 'publish_post', $post ) ); - // contributors can't + // Contributors can't. $this->assertFalse( $contributor->has_cap( 'publish_post', $post ) ); register_post_type( 'something', array( 'capabilities' => array( 'edit_posts' => 'draw_somethings' ) ) ); @@ -1145,7 +1171,7 @@ class Tests_User_Capabilities extends WP_UnitTestCase { $this->assertEquals( 'create_somethings', $something->cap->create_posts ); _unregister_post_type( 'something' ); - // Test meta authorization callbacks + // Test meta authorization callbacks. if ( function_exists( 'register_meta' ) ) { $this->assertTrue( $admin->has_cap( 'edit_post_meta', $post ) ); $this->assertTrue( $admin->has_cap( 'add_post_meta', $post ) ); @@ -1180,7 +1206,7 @@ class Tests_User_Capabilities extends WP_UnitTestCase { * @dataProvider authorless_post_statuses */ function test_authorless_post( $status ) { - // Make a post without an author + // Make a post without an author. $post = self::factory()->post->create( array( 'post_author' => 0, @@ -1189,17 +1215,17 @@ class Tests_User_Capabilities extends WP_UnitTestCase { ) ); - // Add an editor and contributor + // Add an editor and contributor. $editor = self::$users['editor']; $contributor = self::$users['contributor']; - // editor can publish, edit, view, and trash + // Editor can publish, edit, view, and trash. $this->assertTrue( $editor->has_cap( 'publish_post', $post ) ); $this->assertTrue( $editor->has_cap( 'edit_post', $post ) ); $this->assertTrue( $editor->has_cap( 'delete_post', $post ) ); $this->assertTrue( $editor->has_cap( 'read_post', $post ) ); - // a contributor cannot (except read a published post) + // A contributor cannot (except read a published post). $this->assertFalse( $contributor->has_cap( 'publish_post', $post ) ); $this->assertFalse( $contributor->has_cap( 'edit_post', $post ) ); $this->assertFalse( $contributor->has_cap( 'delete_post', $post ) ); @@ -1216,7 +1242,7 @@ class Tests_User_Capabilities extends WP_UnitTestCase { $contributor = self::$users['contributor']; $subscriber = self::$users['subscriber']; - // create_posts isn't a real cap. + // 'create_posts' isn't a real cap. $this->assertFalse( $admin->has_cap( 'create_posts' ) ); $this->assertFalse( $author->has_cap( 'create_posts' ) ); $this->assertFalse( $editor->has_cap( 'create_posts' ) ); @@ -1236,7 +1262,7 @@ class Tests_User_Capabilities extends WP_UnitTestCase { _unregister_post_type( 'foobar' ); - // Primitive capability edit_foobars is not assigned to any users. + // Primitive capability 'edit_foobars' is not assigned to any users. register_post_type( 'foobar', array( 'capability_type' => array( 'foobar', 'foobars' ) ) ); $cap = get_post_type_object( 'foobar' )->cap; @@ -1248,7 +1274,7 @@ class Tests_User_Capabilities extends WP_UnitTestCase { $this->assertFalse( $contributor->has_cap( $cap->create_posts ) ); $this->assertFalse( $subscriber->has_cap( $cap->create_posts ) ); - // Add edit_foobars primitive cap to a user. + // Add 'edit_foobars' primitive cap to a user. $admin->add_cap( 'edit_foobars', true ); $admin = new WP_User( $admin->ID ); $this->assertTrue( $admin->has_cap( $cap->create_posts ) ); @@ -1272,13 +1298,14 @@ class Tests_User_Capabilities extends WP_UnitTestCase { $this->assertFalse( $subscriber->has_cap( $cap->create_posts ) ); } + /** + * Simple tests for some common meta capabilities. + */ function test_page_meta_caps() { - // simple tests for some common meta capabilities - - // Get our author + // Get our author. $author = self::$users['author']; - // make a page + // Make a page. $page = self::factory()->post->create( array( 'post_author' => $author->ID, @@ -1286,27 +1313,27 @@ class Tests_User_Capabilities extends WP_UnitTestCase { ) ); - // the author of the page + // The author of the page. $this->assertTrue( $author->exists(), 'Problem getting user ' . $author->ID ); - // add some other users + // Add some other users. $admin = self::$users['administrator']; $author_2 = new WP_User( self::factory()->user->create( array( 'role' => 'author' ) ) ); $editor = self::$users['editor']; $contributor = self::$users['contributor']; - // administrators, editors and the post owner can edit it + // Administrators, editors and the post owner can edit it. $this->assertTrue( $admin->has_cap( 'edit_page', $page ) ); $this->assertTrue( $editor->has_cap( 'edit_page', $page ) ); - // other authors and contributors can't + // Other authors and contributors can't. $this->assertFalse( $author->has_cap( 'edit_page', $page ) ); $this->assertFalse( $author_2->has_cap( 'edit_page', $page ) ); $this->assertFalse( $contributor->has_cap( 'edit_page', $page ) ); - // administrators, editors and the post owner can delete it + // Administrators, editors and the post owner can delete it. $this->assertTrue( $admin->has_cap( 'delete_page', $page ) ); $this->assertTrue( $editor->has_cap( 'delete_page', $page ) ); - // other authors and contributors can't + // Other authors and contributors can't. $this->assertFalse( $author->has_cap( 'delete_page', $page ) ); $this->assertFalse( $author_2->has_cap( 'delete_page', $page ) ); $this->assertFalse( $contributor->has_cap( 'delete_page', $page ) ); @@ -1544,7 +1571,7 @@ class Tests_User_Capabilities extends WP_UnitTestCase { } function _nullify_current_user() { - // Prevents fatal errors in ::tearDown()'s and other uses of restore_current_blog() + // Prevents fatal errors in ::tearDown()'s and other uses of restore_current_blog(). $function_stack = wp_debug_backtrace_summary( null, 0, false ); if ( in_array( 'restore_current_blog', $function_stack, true ) ) { return; @@ -1661,10 +1688,10 @@ class Tests_User_Capabilities extends WP_UnitTestCase { */ function test_contributor_cannot_edit_scheduled_post() { - // Add a contributor + // Add a contributor. $contributor = self::$users['contributor']; - // Give them a scheduled post + // Give them a scheduled post. $post = $this->factory->post->create_and_get( array( 'post_author' => $contributor->ID, @@ -1672,19 +1699,19 @@ class Tests_User_Capabilities extends WP_UnitTestCase { ) ); - // Ensure contributor can't edit or trash the post + // Ensure contributor can't edit or trash the post. $this->assertFalse( user_can( $contributor->ID, 'edit_post', $post->ID ) ); $this->assertFalse( user_can( $contributor->ID, 'delete_post', $post->ID ) ); - // Test the tests + // Test the tests. $this->assertTrue( defined( 'EMPTY_TRASH_DAYS' ) ); $this->assertNotEmpty( EMPTY_TRASH_DAYS ); - // Trash it + // Trash it. $trashed = wp_trash_post( $post->ID ); $this->assertNotEmpty( $trashed ); - // Ensure contributor can't edit, un-trash, or delete the post + // Ensure contributor can't edit, un-trash, or delete the post. $this->assertFalse( user_can( $contributor->ID, 'edit_post', $post->ID ) ); $this->assertFalse( user_can( $contributor->ID, 'delete_post', $post->ID ) ); @@ -1807,7 +1834,7 @@ class Tests_User_Capabilities extends WP_UnitTestCase { $this->assertFalse( current_user_can( $cap ), "Non-logged-in user should not have the {$cap} capability" ); } - // Special cases for link manager and unfiltered uploads: + // Special cases for link manager and unfiltered uploads. $this->assertFalse( current_user_can( 'manage_links' ), 'Non-logged-in user should not have the manage_links capability' ); $this->assertFalse( current_user_can( 'unfiltered_upload' ), 'Non-logged-in user should not have the unfiltered_upload capability' ); diff --git a/tests/phpunit/tests/user/countUsers.php b/tests/phpunit/tests/user/countUsers.php index 2f36ed75c8..72d18f81bd 100644 --- a/tests/phpunit/tests/user/countUsers.php +++ b/tests/phpunit/tests/user/countUsers.php @@ -12,7 +12,7 @@ class Tests_User_CountUsers extends WP_UnitTestCase { * @group ms-excluded */ public function test_count_users_is_accurate( $strategy ) { - // Setup users + // Setup users. $admin = self::factory()->user->create( array( 'role' => 'administrator', @@ -49,7 +49,7 @@ class Tests_User_CountUsers extends WP_UnitTestCase { ) ); - // Test user counts + // Test user counts. $count = count_users( $strategy ); $this->assertEquals( 8, $count['total_users'] ); @@ -76,7 +76,7 @@ class Tests_User_CountUsers extends WP_UnitTestCase { * @dataProvider data_count_users_strategies */ public function test_count_users_multisite_is_accurate( $strategy ) { - // Setup users + // Setup users. $admin = self::factory()->user->create( array( 'role' => 'administrator', @@ -113,7 +113,7 @@ class Tests_User_CountUsers extends WP_UnitTestCase { ) ); - // Setup blogs + // Setup blogs. $blog_1 = (int) self::factory()->blog->create( array( 'user_id' => $editor, @@ -125,11 +125,11 @@ class Tests_User_CountUsers extends WP_UnitTestCase { ) ); - // Add users to blogs + // Add users to blogs. add_user_to_blog( $blog_1, $subscriber, 'editor' ); add_user_to_blog( $blog_2, $none, 'contributor' ); - // Test users counts on root site + // Test users counts on root site. $count = count_users( $strategy ); $this->assertEquals( 8, $count['total_users'] ); @@ -145,7 +145,7 @@ class Tests_User_CountUsers extends WP_UnitTestCase { $count['avail_roles'] ); - // Test users counts on blog 1 + // Test users counts on blog 1. switch_to_blog( $blog_1 ); $count = count_users( $strategy ); restore_current_blog(); @@ -160,7 +160,7 @@ class Tests_User_CountUsers extends WP_UnitTestCase { $count['avail_roles'] ); - // Test users counts on blog 2 + // Test users counts on blog 2. switch_to_blog( $blog_2 ); $count = count_users( $strategy ); restore_current_blog(); @@ -213,7 +213,7 @@ class Tests_User_CountUsers extends WP_UnitTestCase { */ public function test_count_users_is_accurate_with_multiple_roles( $strategy ) { - // Setup users + // Setup users. $admin = self::factory()->user->create( array( 'role' => 'administrator', @@ -235,7 +235,7 @@ class Tests_User_CountUsers extends WP_UnitTestCase { get_userdata( $editor )->roles ); - // Test user counts + // Test user counts. $count = count_users( $strategy ); $this->assertEquals( 3, $count['total_users'] ); diff --git a/tests/phpunit/tests/user/multisite.php b/tests/phpunit/tests/user/multisite.php index dceee52505..a5eae8f65a 100644 --- a/tests/phpunit/tests/user/multisite.php +++ b/tests/phpunit/tests/user/multisite.php @@ -142,7 +142,7 @@ if ( is_multisite() ) : $this->assertSame( 0, $old_current ); - // test for "get current user" when not logged in + // Test for "get current user" when not logged in. $this->assertFalse( is_user_member_of_blog() ); wp_set_current_user( $user1_id ); @@ -158,9 +158,9 @@ if ( is_multisite() ) : $this->assertInternalType( 'int', $blog_id ); - // Current user gets added to new blogs + // Current user gets added to new blogs. $this->assertTrue( is_user_member_of_blog( $user1_id, $blog_id ) ); - // Other users should not + // Other users should not. $this->assertFalse( is_user_member_of_blog( $user2_id, $blog_id ) ); switch_to_blog( $blog_id ); @@ -168,10 +168,10 @@ if ( is_multisite() ) : $this->assertTrue( is_user_member_of_blog( $user1_id ) ); $this->assertFalse( is_user_member_of_blog( $user2_id ) ); - // Remove user 1 from blog + // Remove user 1 from blog. $this->assertTrue( remove_user_from_blog( $user1_id, $blog_id ) ); - // Add user 2 to blog + // Add user 2 to blog. $this->assertTrue( add_user_to_blog( $blog_id, $user2_id, 'subscriber' ) ); $this->assertFalse( is_user_member_of_blog( $user1_id ) ); diff --git a/tests/phpunit/tests/user/query.php b/tests/phpunit/tests/user/query.php index c094360ebc..9fe4144cbc 100644 --- a/tests/phpunit/tests/user/query.php +++ b/tests/phpunit/tests/user/query.php @@ -554,12 +554,12 @@ class Tests_User_Query extends WP_UnitTestCase { $this->assertNotEmpty( $query->query_vars ); $this->assertNotEquals( $_query_vars, $query->query_vars ); - // All values get reset + // All values get reset. $query->prepare_query( array( 'number' => 8 ) ); $this->assertNotEmpty( $query->query_limit ); $this->assertEquals( 'LIMIT 0, 8', $query->query_limit ); - // All values get reset + // All values get reset. $query->prepare_query( array( 'fields' => 'all' ) ); $this->assertEmpty( $query->query_limit ); $this->assertEquals( '', $query->query_limit ); @@ -1139,7 +1139,7 @@ class Tests_User_Query extends WP_UnitTestCase { ); $found_count = count( $q->get_results() ); - $expected_count = 10; // 13 total users minus 3 from query + $expected_count = 10; // 13 total users minus 3 from query. $this->assertContains( "AND user_nicename NOT IN ( 'peter','paul','mary' )", $q->query_where ); $this->assertEquals( $expected_count, $found_count ); @@ -1240,7 +1240,7 @@ class Tests_User_Query extends WP_UnitTestCase { ); $found_count = count( $q->get_results() ); - $expected_count = 10; // 13 total users minus 3 from query + $expected_count = 10; // 13 total users minus 3 from query. $this->assertContains( "AND user_login NOT IN ( '$user_login1','$user_login2','$user_login3' )", $q->query_where ); $this->assertEquals( $expected_count, $found_count ); @@ -1443,23 +1443,23 @@ class Tests_User_Query extends WP_UnitTestCase { * @ticket 22212 */ public function test_get_multiple_roles_with_meta() { - // Create administrator user + meta + // Create administrator user + meta. update_user_meta( self::$admin_ids[0], 'mk1', 1 ); update_user_meta( self::$admin_ids[0], 'mk2', 1 ); - // Create editor user + meta + // Create editor user + meta. update_user_meta( self::$editor_ids[0], 'mk1', 1 ); update_user_meta( self::$editor_ids[0], 'mk2', 2 ); - // Create subscriber user + meta + // Create subscriber user + meta. update_user_meta( self::$sub_ids[0], 'mk1', 1 ); update_user_meta( self::$sub_ids[0], 'mk2', 1 ); - // Create contributor user + meta + // Create contributor user + meta. update_user_meta( self::$contrib_id, 'mk1', 1 ); update_user_meta( self::$contrib_id, 'mk2', 2 ); - // Fetch users + // Fetch users. $users = get_users( array( 'role__in' => array( 'administrator', 'editor', 'subscriber' ), @@ -1481,7 +1481,7 @@ class Tests_User_Query extends WP_UnitTestCase { ) ); - // Check results + // Check results. $this->assertEquals( 1, count( $users ) ); $this->assertSame( self::$editor_ids[0], (int) $users[0]->ID ); } diff --git a/tests/phpunit/tests/user/slashes.php b/tests/phpunit/tests/user/slashes.php index 202d6a1622..0e811e84b1 100644 --- a/tests/phpunit/tests/user/slashes.php +++ b/tests/phpunit/tests/user/slashes.php @@ -12,8 +12,8 @@ class Tests_User_Slashes extends WP_UnitTestCase { wp_set_current_user( $this->author_id ); - // it is important to test with both even and odd numbered slashes as - // kses does a strip-then-add slashes in some of its function calls + // It is important to test with both even and odd numbered slashes, + // as KSES does a strip-then-add slashes in some of its function calls. $this->slash_1 = 'String with 1 slash \\'; $this->slash_2 = 'String with 2 slashes \\\\'; $this->slash_3 = 'String with 3 slashes \\\\\\'; @@ -24,7 +24,7 @@ class Tests_User_Slashes extends WP_UnitTestCase { } /** - * Tests the controller function that expects slashed data + * Tests the controller function that expects slashed data. */ function test_add_user() { $_POST = array(); @@ -40,7 +40,8 @@ class Tests_User_Slashes extends WP_UnitTestCase { $_POST['nickname'] = $this->slash_5; $_POST['display_name'] = $this->slash_7; $_POST['description'] = $this->slash_3; - $_POST = add_magic_quotes( $_POST ); // the edit_post() function will strip slashes + + $_POST = add_magic_quotes( $_POST ); // The add_user() function will strip slashes. $id = add_user(); $user = get_user_to_edit( $id ); @@ -64,7 +65,8 @@ class Tests_User_Slashes extends WP_UnitTestCase { $_POST['nickname'] = $this->slash_6; $_POST['display_name'] = $this->slash_2; $_POST['description'] = $this->slash_4; - $_POST = add_magic_quotes( $_POST ); // the edit_post() function will strip slashes + + $_POST = add_magic_quotes( $_POST ); // The add_user() function will strip slashes. $id = add_user(); $user = get_user_to_edit( $id ); @@ -77,7 +79,7 @@ class Tests_User_Slashes extends WP_UnitTestCase { } /** - * Tests the controller function that expects slashed data + * Tests the controller function that expects slashed data. */ function test_edit_user() { $id = self::factory()->user->create(); @@ -92,7 +94,8 @@ class Tests_User_Slashes extends WP_UnitTestCase { $_POST['nickname'] = $this->slash_5; $_POST['display_name'] = $this->slash_7; $_POST['description'] = $this->slash_3; - $_POST = add_magic_quotes( $_POST ); // the edit_post() function will strip slashes + + $_POST = add_magic_quotes( $_POST ); // The edit_user() function will strip slashes. $id = edit_user( $id ); $user = get_user_to_edit( $id ); @@ -113,7 +116,8 @@ class Tests_User_Slashes extends WP_UnitTestCase { $_POST['nickname'] = $this->slash_6; $_POST['display_name'] = $this->slash_2; $_POST['description'] = $this->slash_4; - $_POST = add_magic_quotes( $_POST ); // the edit_post() function will strip slashes + + $_POST = add_magic_quotes( $_POST ); // The edit_user() function will strip slashes. $id = edit_user( $id ); $user = get_user_to_edit( $id ); @@ -126,7 +130,7 @@ class Tests_User_Slashes extends WP_UnitTestCase { } /** - * Tests the model function that expects slashed data + * Tests the model function that expects slashed data. */ function test_wp_insert_user() { $id = wp_insert_user( @@ -173,7 +177,7 @@ class Tests_User_Slashes extends WP_UnitTestCase { } /** - * Tests the model function that expects slashed data + * Tests the model function that expects slashed data. */ function test_wp_update_user() { $id = self::factory()->user->create(); diff --git a/tests/phpunit/tests/user/wpDeleteUser.php b/tests/phpunit/tests/user/wpDeleteUser.php index bc9a53c54f..120f1d498b 100644 --- a/tests/phpunit/tests/user/wpDeleteUser.php +++ b/tests/phpunit/tests/user/wpDeleteUser.php @@ -65,7 +65,7 @@ class Tests_User_WpDeleteUser extends WP_UnitTestCase { 'post_type' => 'post', ); - // insert a post and make sure the ID is ok + // Insert a post and make sure the ID is OK. $post_id = wp_insert_post( $post ); $this->assertTrue( is_numeric( $post_id ) ); $this->assertTrue( $post_id > 0 ); @@ -81,7 +81,7 @@ class Tests_User_WpDeleteUser extends WP_UnitTestCase { 'post_type' => 'nav_menu_item', ); - // insert a post and make sure the ID is ok + // Insert a post and make sure the ID is OK. $nav_id = wp_insert_post( $post ); $this->assertTrue( is_numeric( $nav_id ) ); $this->assertTrue( $nav_id > 0 ); @@ -99,7 +99,7 @@ class Tests_User_WpDeleteUser extends WP_UnitTestCase { $this->assertNotNull( get_post( $post_id ) ); $this->assertEquals( 'trash', get_post( $post_id )->post_status ); - // nav_menu_item is delete_with_user = false so the nav post should remain published. + // 'nav_menu_item' is `delete_with_user = false` so the nav post should remain published. $this->assertNotNull( get_post( $nav_id ) ); $this->assertEquals( 'publish', get_post( $nav_id )->post_status ); wp_delete_post( $nav_id, true ); diff --git a/tests/phpunit/tests/user/wpDropdownUsers.php b/tests/phpunit/tests/user/wpDropdownUsers.php index d6ee6c3c43..4f6b89db77 100644 --- a/tests/phpunit/tests/user/wpDropdownUsers.php +++ b/tests/phpunit/tests/user/wpDropdownUsers.php @@ -12,7 +12,7 @@ class Tests_User_WpDropdownUsers extends WP_UnitTestCase { */ public function test_default_value_of_show_should_be_display_name() { - // create a user with a different display_name + // Create a user with a different display_name. $u = $this->factory->user->create( array( 'user_login' => 'foo', @@ -36,7 +36,7 @@ class Tests_User_WpDropdownUsers extends WP_UnitTestCase { */ public function test_show_should_display_display_name_show_is_specified_as_empty() { - // create a user with a different display_name + // Create a user with a different display_name. $u = $this->factory->user->create( array( 'user_login' => 'foo', @@ -62,7 +62,7 @@ class Tests_User_WpDropdownUsers extends WP_UnitTestCase { */ public function test_show_should_display_user_property_when_the_value_of_show_is_a_valid_user_property() { - // create a user with a different display_name + // Create a user with a different display_name. $u = $this->factory->user->create( array( 'user_login' => 'foo', @@ -88,7 +88,7 @@ class Tests_User_WpDropdownUsers extends WP_UnitTestCase { */ public function test_show_display_name_with_login() { - // create a user with a different display_name + // Create a user with a different display_name. $u = $this->factory->user->create( array( 'user_login' => 'foo', diff --git a/tests/phpunit/tests/user/wpGetUsersWithNoRole.php b/tests/phpunit/tests/user/wpGetUsersWithNoRole.php index 8decde8171..46b8bafbdb 100644 --- a/tests/phpunit/tests/user/wpGetUsersWithNoRole.php +++ b/tests/phpunit/tests/user/wpGetUsersWithNoRole.php @@ -10,7 +10,7 @@ class Tests_User_GetUsersWithNoRole extends WP_UnitTestCase { * @group ms-excluded */ public function test_get_users_with_no_role_is_accurate() { - // Setup users + // Setup users. $admin = self::factory()->user->create( array( 'role' => 'administrator', @@ -32,7 +32,7 @@ class Tests_User_GetUsersWithNoRole extends WP_UnitTestCase { ) ); - // Test users + // Test users. $users = wp_get_users_with_no_role(); $this->assertEquals( @@ -52,7 +52,7 @@ class Tests_User_GetUsersWithNoRole extends WP_UnitTestCase { * @group ms-required */ public function test_get_users_with_no_role_multisite_is_accurate() { - // Setup users + // Setup users. $admin = self::factory()->user->create( array( 'role' => 'administrator', @@ -69,17 +69,17 @@ class Tests_User_GetUsersWithNoRole extends WP_UnitTestCase { ) ); - // Setup blogs + // Setup blogs. $blog_1 = (int) self::factory()->blog->create( array( 'user_id' => $editor, ) ); - // Add editor to blog 1 + // Add editor to blog 1. add_user_to_blog( $blog_1, $editor, 'editor' ); - // Test users on root site + // Test users on root site. $users = wp_get_users_with_no_role(); $this->assertSame( array( @@ -88,14 +88,14 @@ class Tests_User_GetUsersWithNoRole extends WP_UnitTestCase { $users ); - // Test users counts on blog 1 + // Test users counts on blog 1. $users = wp_get_users_with_no_role( $blog_1 ); $this->assertSame( array(), $users ); - // Add admin to blog 1 with no role + // Add admin to blog 1 with no role. add_user_to_blog( $blog_1, $admin, '' ); - // Re-test users counts on blog 1 + // Re-test users counts on blog 1. $users = wp_get_users_with_no_role( $blog_1 ); $this->assertSame( array( diff --git a/tests/phpunit/tests/walker.php b/tests/phpunit/tests/walker.php index 0cb2ad232c..c38c1e314e 100644 --- a/tests/phpunit/tests/walker.php +++ b/tests/phpunit/tests/walker.php @@ -214,13 +214,13 @@ class Tests_Walker extends WP_UnitTestCase { $this->assertEquals( 0, $this->walker->get_number_of_root_elements( $items ) ); - // It's not clear what the output of this "should" be + // It's not clear what the output of this "should" be. - // Currently the item is simply returned + // Currently the item is simply returned. $this->assertEquals( '
  • 1
  • ', $output ); // But as we've only asked for the first depth maybe nothing should be returned? - //$this->assertEquals( '', $output ); + // $this->assertEquals( '', $output ); } @@ -269,16 +269,16 @@ class Tests_Walker extends WP_UnitTestCase { $this->assertEquals( 0, $this->walker->get_number_of_root_elements( $items ) ); - // It's not clear what the output of this "should" be + // It's not clear what the output of this "should" be. - // Currently the first item is simply returned + // Currently the first item is simply returned. $this->assertEquals( '
  • 4
  • ', $output ); // But as we've only asked for the first depth maybe nothing should be returned? - //$this->assertEquals( '', $output ); + // $this->assertEquals( '', $output ); // Or maybe all items which are missing parents should simply be treat top level? - //$this->assertEquals( '
  • 4
  • 5
  • 6
  • ', $output ); + // $this->assertEquals( '
  • 4
  • 5
  • 6
  • ', $output ); } diff --git a/tests/phpunit/tests/widgets.php b/tests/phpunit/tests/widgets.php index 9d5f547dc6..59a047620f 100644 --- a/tests/phpunit/tests/widgets.php +++ b/tests/phpunit/tests/widgets.php @@ -495,14 +495,14 @@ class Tests_Widgets extends WP_UnitTestCase { $this->assertEmpty( $wp_registered_widgets ); wp_widgets_init(); - // Note: We cannot use array_keys() here because $settings could be an ArrayIterator + // Note: We cannot use array_keys() here because $settings could be an ArrayIterator. foreach ( $settings as $widget_number => $instance ) { $widget_id = "search-$widget_number"; $this->assertArrayHasKey( $widget_id, $wp_registered_widgets ); } } - // @todo test WP_Widget::display_callback() + // @todo Test WP_Widget::display_callback(). /** * @see WP_Widget::is_preview() @@ -523,9 +523,9 @@ class Tests_Widgets extends WP_UnitTestCase { $this->assertTrue( $widget->is_preview() ); } - // @todo test WP_Widget::update_callback() - // @todo test WP_Widget::form_callback() - // @todo test WP_Widget::_register_one() + // @todo Test WP_Widget::update_callback(). + // @todo Test WP_Widget::form_callback(). + // @todo Test WP_Widget::_register_one(). /** * @see WP_Widget::get_settings() diff --git a/tests/phpunit/tests/widgets/text-widget.php b/tests/phpunit/tests/widgets/text-widget.php index eeb37c7ce3..8c2c9cff7f 100644 --- a/tests/phpunit/tests/widgets/text-widget.php +++ b/tests/phpunit/tests/widgets/text-widget.php @@ -333,7 +333,7 @@ class Test_WP_Widget_Text extends WP_UnitTestCase { 'filter' => false, ); - // Legacy Text Widget without wpautop. + // Legacy Text Widget without wpautop(). $instance = array_merge( $base_instance, array( @@ -350,7 +350,7 @@ class Test_WP_Widget_Text extends WP_UnitTestCase { $this->assertNotContains( '

    ' . $this->example_shortcode_content . '

    ', $output, 'Expected shortcode_unautop() to have run.' ); $this->assertNull( $this->post_during_shortcode ); - // Legacy Text Widget with wpautop. + // Legacy Text Widget with wpautop(). $instance = array_merge( $base_instance, array( @@ -388,7 +388,7 @@ class Test_WP_Widget_Text extends WP_UnitTestCase { ) ); - // Visual Text Widget with only core-added widget_text_content filter for do_shortcode. + // Visual Text Widget with only core-added widget_text_content filter for do_shortcode(). $this->assertFalse( has_filter( 'widget_text', 'do_shortcode' ) ); $this->assertEquals( 11, has_filter( 'widget_text_content', 'do_shortcode' ), 'Expected core to have set do_shortcode as widget_text_content filter.' ); $this->shortcode_render_count = 0; diff --git a/tests/phpunit/tests/xmlrpc/basic.php b/tests/phpunit/tests/xmlrpc/basic.php index 68c8e8f0df..703a3615c5 100644 --- a/tests/phpunit/tests/xmlrpc/basic.php +++ b/tests/phpunit/tests/xmlrpc/basic.php @@ -29,7 +29,7 @@ class Tests_XMLRPC_Basic extends WP_XMLRPC_UnitTestCase { $this->assertFalse( $this->myxmlrpcserver->login_pass_ok( 'username', 'password' ) ); $this->assertFalse( $this->myxmlrpcserver->login( 'username', 'password' ) ); - // The auth will still fail due to authentication blocking after the first failed attempt + // The auth will still fail due to authentication blocking after the first failed attempt. $this->assertFalse( $this->myxmlrpcserver->login_pass_ok( 'subscriber', 'subscriber' ) ); } @@ -45,7 +45,7 @@ class Tests_XMLRPC_Basic extends WP_XMLRPC_UnitTestCase { ); $method_calls = array( - // Valid login + // Valid login. array( 'methodName' => 'wp.editPost', 'params' => array( @@ -58,7 +58,7 @@ class Tests_XMLRPC_Basic extends WP_XMLRPC_UnitTestCase { ), ), ), - // *Invalid* login + // *Invalid* login. array( 'methodName' => 'wp.editPost', 'params' => array( @@ -71,7 +71,7 @@ class Tests_XMLRPC_Basic extends WP_XMLRPC_UnitTestCase { ), ), ), - // Valid login + // Valid login. array( 'methodName' => 'wp.editPost', 'params' => array( diff --git a/tests/phpunit/tests/xmlrpc/mw/editPost.php b/tests/phpunit/tests/xmlrpc/mw/editPost.php index 77653cfa86..73d4805558 100644 --- a/tests/phpunit/tests/xmlrpc/mw/editPost.php +++ b/tests/phpunit/tests/xmlrpc/mw/editPost.php @@ -145,32 +145,32 @@ class Tests_XMLRPC_mw_editPost extends WP_XMLRPC_UnitTestCase { $this->assertEquals( '', get_post_meta( $post_id, '_thumbnail_id', true ) ); - // create attachment + // Create attachment. $filename = ( DIR_TESTDATA . '/images/a2-small.jpg' ); $attachment_id = self::factory()->attachment->create_upload_object( $filename, $post_id ); - // add post thumbnail to post that does not have one + // Add post thumbnail to post that does not have one. $post2 = array( 'wp_post_thumbnail' => $attachment_id ); $result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'author', 'author', $post2 ) ); $this->assertNotIXRError( $result ); $this->assertEquals( $attachment_id, get_post_meta( $post_id, '_thumbnail_id', true ) ); - // edit the post without supplying a post_thumbnail and check that it didn't change + // Edit the post without supplying a post_thumbnail and check that it didn't change. $post3 = array( 'post_content' => 'Updated post' ); $result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'author', 'author', $post3 ) ); $this->assertNotIXRError( $result ); $this->assertEquals( $attachment_id, get_post_meta( $post_id, '_thumbnail_id', true ) ); - // create another attachment + // Create another attachment. $attachment2_id = self::factory()->attachment->create_upload_object( $filename, $post_id ); - // change the post's post_thumbnail + // Change the post's post_thumbnail. $post4 = array( 'wp_post_thumbnail' => $attachment2_id ); $result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'author', 'author', $post4 ) ); $this->assertNotIXRError( $result ); $this->assertEquals( $attachment2_id, get_post_meta( $post_id, '_thumbnail_id', true ) ); - // unset the post's post_thumbnail + // Unset the post's post_thumbnail. $post5 = array( 'wp_post_thumbnail' => '' ); $result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'author', 'author', $post5 ) ); $this->assertNotIXRError( $result ); @@ -246,7 +246,7 @@ class Tests_XMLRPC_mw_editPost extends WP_XMLRPC_UnitTestCase { $this->assertTrue( $result ); } - // Not allowed since [19914] + // Not allowed since [19914]. function test_change_post_type() { $contributor_id = $this->make_user_by_role( 'contributor' ); diff --git a/tests/phpunit/tests/xmlrpc/mw/getPost.php b/tests/phpunit/tests/xmlrpc/mw/getPost.php index d9389c1892..2a20416284 100644 --- a/tests/phpunit/tests/xmlrpc/mw/getPost.php +++ b/tests/phpunit/tests/xmlrpc/mw/getPost.php @@ -51,7 +51,7 @@ class Tests_XMLRPC_mw_getPost extends WP_XMLRPC_UnitTestCase { $result = $this->myxmlrpcserver->mw_getPost( array( self::$post_id, 'author', 'author' ) ); $this->assertNotIXRError( $result ); - // Check data types + // Check data types. $this->assertInternalType( 'string', $result['userid'] ); $this->assertInternalType( 'int', $result['postid'] ); $this->assertInternalType( 'string', $result['description'] ); @@ -76,7 +76,7 @@ class Tests_XMLRPC_mw_getPost extends WP_XMLRPC_UnitTestCase { $post_data = get_post( self::$post_id ); - // Check expected values + // Check expected values. $this->assertStringMatchesFormat( '%d', $result['userid'] ); $this->assertEquals( $post_data->post_title, $result['title'] ); $this->assertEquals( 'publish', $result['post_status'] ); @@ -92,7 +92,7 @@ class Tests_XMLRPC_mw_getPost extends WP_XMLRPC_UnitTestCase { function test_post_thumbnail() { add_theme_support( 'post-thumbnails' ); - // create attachment + // Create attachment. $filename = ( DIR_TESTDATA . '/images/a2-small.jpg' ); $attachment_id = self::factory()->attachment->create_upload_object( $filename ); diff --git a/tests/phpunit/tests/xmlrpc/mw/getRecentPosts.php b/tests/phpunit/tests/xmlrpc/mw/getRecentPosts.php index a976ffafa2..06350d00e1 100644 --- a/tests/phpunit/tests/xmlrpc/mw/getRecentPosts.php +++ b/tests/phpunit/tests/xmlrpc/mw/getRecentPosts.php @@ -57,7 +57,7 @@ class Tests_XMLRPC_mw_getRecentPosts extends WP_XMLRPC_UnitTestCase { foreach ( $results as $result ) { $post = get_post( $result['postid'] ); - // Check data types + // Check data types. $this->assertInternalType( 'string', $result['userid'] ); $this->assertInternalType( 'string', $result['postid'] ); $this->assertInternalType( 'string', $result['description'] ); @@ -79,7 +79,7 @@ class Tests_XMLRPC_mw_getRecentPosts extends WP_XMLRPC_UnitTestCase { $this->assertInternalType( 'array', $result['custom_fields'] ); $this->assertInternalType( 'string', $result['wp_post_format'] ); - // Check expected values + // Check expected values. $this->assertStringMatchesFormat( '%d', $result['userid'] ); $this->assertStringMatchesFormat( '%d', $result['postid'] ); $this->assertEquals( $post->post_title, $result['title'] ); @@ -97,7 +97,7 @@ class Tests_XMLRPC_mw_getRecentPosts extends WP_XMLRPC_UnitTestCase { function test_post_thumbnail() { add_theme_support( 'post-thumbnails' ); - // create attachment + // Create attachment. $filename = ( DIR_TESTDATA . '/images/a2-small.jpg' ); $attachment_id = self::factory()->attachment->create_upload_object( $filename, self::$post_id ); set_post_thumbnail( self::$post_id, $attachment_id ); diff --git a/tests/phpunit/tests/xmlrpc/mw/newPost.php b/tests/phpunit/tests/xmlrpc/mw/newPost.php index 7e29020a07..69e4c3c1f6 100644 --- a/tests/phpunit/tests/xmlrpc/mw/newPost.php +++ b/tests/phpunit/tests/xmlrpc/mw/newPost.php @@ -133,7 +133,7 @@ class Tests_XMLRPC_mw_newPost extends WP_XMLRPC_UnitTestCase { $this->make_user_by_role( 'author' ); - // create attachment + // Create attachment. $filename = ( DIR_TESTDATA . '/images/a2-small.jpg' ); $attachment_id = self::factory()->attachment->create_upload_object( $filename ); diff --git a/tests/phpunit/tests/xmlrpc/wp/editPost.php b/tests/phpunit/tests/xmlrpc/wp/editPost.php index fc822a251c..45ce7d6edf 100644 --- a/tests/phpunit/tests/xmlrpc/wp/editPost.php +++ b/tests/phpunit/tests/xmlrpc/wp/editPost.php @@ -145,45 +145,45 @@ class Tests_XMLRPC_wp_editPost extends WP_XMLRPC_UnitTestCase { $this->assertEquals( '', get_post_meta( $post_id, '_thumbnail_id', true ) ); - // create attachment + // Create attachment. $filename = ( DIR_TESTDATA . '/images/a2-small.jpg' ); $attachment_id = self::factory()->attachment->create_upload_object( $filename, $post_id ); - // add post thumbnail to post that does not have one + // Add post thumbnail to post that does not have one. $post2 = array( 'post_thumbnail' => $attachment_id ); $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'author', 'author', $post_id, $post2 ) ); $this->assertNotIXRError( $result ); $this->assertEquals( $attachment_id, get_post_meta( $post_id, '_thumbnail_id', true ) ); - // fetch the post to verify that it appears + // Fetch the post to verify that it appears. $result = $this->myxmlrpcserver->wp_getPost( array( 1, 'author', 'author', $post_id ) ); $this->assertNotIXRError( $result ); $this->assertArrayHasKey( 'post_thumbnail', $result ); $this->assertInternalType( 'array', $result['post_thumbnail'] ); $this->assertEquals( $attachment_id, $result['post_thumbnail']['attachment_id'] ); - // edit the post without supplying a post_thumbnail and check that it didn't change + // Edit the post without supplying a post_thumbnail and check that it didn't change. $post3 = array( 'post_content' => 'Updated post' ); $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'author', 'author', $post_id, $post3 ) ); $this->assertNotIXRError( $result ); $this->assertEquals( $attachment_id, get_post_meta( $post_id, '_thumbnail_id', true ) ); - // create another attachment + // Create another attachment. $attachment2_id = self::factory()->attachment->create_upload_object( $filename, $post_id ); - // change the post's post_thumbnail + // Change the post's post_thumbnail. $post4 = array( 'post_thumbnail' => $attachment2_id ); $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'author', 'author', $post_id, $post4 ) ); $this->assertNotIXRError( $result ); $this->assertEquals( $attachment2_id, get_post_meta( $post_id, '_thumbnail_id', true ) ); - // unset the post's post_thumbnail + // Unset the post's post_thumbnail. $post5 = array( 'post_thumbnail' => '' ); $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'author', 'author', $post_id, $post5 ) ); $this->assertNotIXRError( $result ); $this->assertEquals( '', get_post_meta( $post_id, '_thumbnail_id', true ) ); - // use invalid ID + // Use invalid ID. $post6 = array( 'post_thumbnail' => 398420983409 ); $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'author', 'author', $post_id, $post6 ) ); $this->assertIXRError( $result ); @@ -249,7 +249,7 @@ class Tests_XMLRPC_wp_editPost extends WP_XMLRPC_UnitTestCase { } function test_password_transition_unsticky() { - // when transitioning to private status or adding a post password, post should be un-stuck + // When transitioning to private status or adding a post password, post should be un-stuck. $editor_id = $this->make_user_by_role( 'editor' ); $post_id = self::factory()->post->create( array( 'post_author' => $editor_id ) ); stick_post( $post_id ); @@ -319,7 +319,7 @@ class Tests_XMLRPC_wp_editPost extends WP_XMLRPC_UnitTestCase { $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $struct ) ); $this->assertNotIXRError( $result ); - // Make sure that the post status is still inherit + // Make sure that the post status is still inherit. $this->assertEquals( 'inherit', get_post( $post_id )->post_status ); } @@ -338,7 +338,7 @@ class Tests_XMLRPC_wp_editPost extends WP_XMLRPC_UnitTestCase { $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $struct ) ); $this->assertNotIXRError( $result ); - // Make sure that the post status is still inherit + // Make sure that the post status is still inherit. $this->assertEquals( 'draft', get_post( $post_id )->post_status ); } @@ -404,24 +404,24 @@ class Tests_XMLRPC_wp_editPost extends WP_XMLRPC_UnitTestCase { * @ticket 23219 */ function test_add_enclosure_if_new() { - // Sample enclosure data + // Sample enclosure data. $enclosure = array( 'url' => 'http://example.com/sound.mp3', 'length' => 12345, 'type' => 'audio/mpeg', ); - // Second sample enclosure data array + // Second sample enclosure data array. $new_enclosure = array( 'url' => 'http://example.com/sound2.mp3', 'length' => 12345, 'type' => 'audio/mpeg', ); - // Create a test user + // Create a test user. $editor_id = $this->make_user_by_role( 'editor' ); - // Add a dummy post + // Add a dummy post. $post_id = self::factory()->post->create( array( 'post_title' => 'Post Enclosure Test', @@ -431,33 +431,33 @@ class Tests_XMLRPC_wp_editPost extends WP_XMLRPC_UnitTestCase { ) ); - // Add the enclosure as it is added in "do_enclose()" + // Add the enclosure as it is added in "do_enclose()". $enclosure_string = "{$enclosure['url']}\n{$enclosure['length']}\n{$enclosure['type']}\n"; add_post_meta( $post_id, 'enclosure', $enclosure_string ); - // Verify that the correct data is there + // Verify that the correct data is there. $this->assertEquals( $enclosure_string, get_post_meta( $post_id, 'enclosure', true ) ); - // Attempt to add the enclosure a second time + // Attempt to add the enclosure a second time. $this->myxmlrpcserver->add_enclosure_if_new( $post_id, $enclosure ); - // Verify that there is only a single value in the array and that a duplicate is not present + // Verify that there is only a single value in the array and that a duplicate is not present. $this->assertEquals( 1, count( get_post_meta( $post_id, 'enclosure' ) ) ); - // For good measure, check that the expected value is in the array + // For good measure, check that the expected value is in the array. $this->assertTrue( in_array( $enclosure_string, get_post_meta( $post_id, 'enclosure' ), true ) ); - // Attempt to add a brand new enclosure via XML-RPC + // Attempt to add a brand new enclosure via XML-RPC. $this->myxmlrpcserver->add_enclosure_if_new( $post_id, $new_enclosure ); - // Having added the new enclosure, 2 values are expected in the array + // Having added the new enclosure, 2 values are expected in the array. $this->assertEquals( 2, count( get_post_meta( $post_id, 'enclosure' ) ) ); - // Check that the new enclosure is in the enclosure meta + // Check that the new enclosure is in the enclosure meta. $new_enclosure_string = "{$new_enclosure['url']}\n{$new_enclosure['length']}\n{$new_enclosure['type']}\n"; $this->assertTrue( in_array( $new_enclosure_string, get_post_meta( $post_id, 'enclosure' ), true ) ); - // Check that the old enclosure is in the enclosure meta + // Check that the old enclosure is in the enclosure meta. $this->assertTrue( in_array( $enclosure_string, get_post_meta( $post_id, 'enclosure' ), true ) ); } diff --git a/tests/phpunit/tests/xmlrpc/wp/editProfile.php b/tests/phpunit/tests/xmlrpc/wp/editProfile.php index e637016ef9..f132c78c5e 100644 --- a/tests/phpunit/tests/xmlrpc/wp/editProfile.php +++ b/tests/phpunit/tests/xmlrpc/wp/editProfile.php @@ -28,7 +28,7 @@ class Tests_XMLRPC_wp_editProfile extends WP_XMLRPC_UnitTestCase { $this->assertNotIXRError( $result ); $this->assertTrue( $result ); - // verify that the new values were stored + // Verify that the new values were stored. $user_data = get_userdata( $subscriber_id ); $this->assertEquals( $new_data['first_name'], $user_data->first_name ); $this->assertEquals( $new_data['last_name'], $user_data->last_name ); diff --git a/tests/phpunit/tests/xmlrpc/wp/getComment.php b/tests/phpunit/tests/xmlrpc/wp/getComment.php index 200f71ec53..0c6b49d1a5 100644 --- a/tests/phpunit/tests/xmlrpc/wp/getComment.php +++ b/tests/phpunit/tests/xmlrpc/wp/getComment.php @@ -53,7 +53,7 @@ class Tests_XMLRPC_wp_getComment extends WP_XMLRPC_UnitTestCase { $result = $this->myxmlrpcserver->wp_getComment( array( 1, 'editor', 'editor', self::$parent_comment_id ) ); $this->assertNotIXRError( $result ); - // Check data types + // Check data types. $this->assertInternalType( 'string', $result['user_id'] ); $this->assertInternalType( 'string', $result['comment_id'] ); $this->assertInstanceOf( 'IXR_Date', $result['date_created_gmt'] ); @@ -69,7 +69,7 @@ class Tests_XMLRPC_wp_getComment extends WP_XMLRPC_UnitTestCase { $this->assertInternalType( 'string', $result['author_ip'] ); $this->assertInternalType( 'string', $result['type'] ); - // Check expected values + // Check expected values. $this->assertStringMatchesFormat( '%d', $result['user_id'] ); $this->assertStringMatchesFormat( '%d', $result['comment_id'] ); $this->assertStringMatchesFormat( '%d', $result['parent'] ); diff --git a/tests/phpunit/tests/xmlrpc/wp/getComments.php b/tests/phpunit/tests/xmlrpc/wp/getComments.php index 5d9278907e..b3b1d03e3a 100644 --- a/tests/phpunit/tests/xmlrpc/wp/getComments.php +++ b/tests/phpunit/tests/xmlrpc/wp/getComments.php @@ -76,7 +76,7 @@ class Tests_XMLRPC_wp_getComments extends WP_XMLRPC_UnitTestCase { ); $this->assertNotIXRError( $results ); - // if no 'number' filter is specified, default should be 10 + // If no 'number' filter is specified, default should be 10. $this->assertCount( 10, $results ); $results2 = $this->myxmlrpcserver->wp_getComments( diff --git a/tests/phpunit/tests/xmlrpc/wp/getMediaItem.php b/tests/phpunit/tests/xmlrpc/wp/getMediaItem.php index 7c46ded316..353371b445 100644 --- a/tests/phpunit/tests/xmlrpc/wp/getMediaItem.php +++ b/tests/phpunit/tests/xmlrpc/wp/getMediaItem.php @@ -49,7 +49,7 @@ class Tests_XMLRPC_wp_getMediaItem extends WP_XMLRPC_UnitTestCase { $result = $this->myxmlrpcserver->wp_getMediaItem( array( 1, 'author', 'author', $this->attachment_id, $fields ) ); $this->assertNotIXRError( $result ); - // Check data types + // Check data types. $this->assertInternalType( 'string', $result['attachment_id'] ); $this->assertInternalType( 'int', $result['parent'] ); $this->assertInternalType( 'string', $result['title'] ); @@ -60,7 +60,7 @@ class Tests_XMLRPC_wp_getMediaItem extends WP_XMLRPC_UnitTestCase { $this->assertInternalType( 'string', $result['thumbnail'] ); $this->assertInternalType( 'array', $result['metadata'] ); - // Check expected values + // Check expected values. $this->assertStringMatchesFormat( '%d', $result['attachment_id'] ); $this->assertEquals( $this->attachment_data['post_title'], $result['title'] ); $this->assertEquals( wp_get_attachment_url( $this->attachment_id ), $result['link'] ); diff --git a/tests/phpunit/tests/xmlrpc/wp/getOptions.php b/tests/phpunit/tests/xmlrpc/wp/getOptions.php index 6a5f1d172d..59b3636b3c 100644 --- a/tests/phpunit/tests/xmlrpc/wp/getOptions.php +++ b/tests/phpunit/tests/xmlrpc/wp/getOptions.php @@ -39,7 +39,7 @@ class Tests_XMLRPC_wp_getOptions extends WP_XMLRPC_UnitTestCase { $result = $this->myxmlrpcserver->wp_getOptions( array( 1, 'subscriber', 'subscriber' ) ); $this->assertInternalType( 'array', $result ); - // Read Only options + // Read-only options. $this->assertEquals( 'WordPress', $result['software_name']['value'] ); $this->assertTrue( $result['software_name']['readonly'] ); @@ -73,7 +73,7 @@ class Tests_XMLRPC_wp_getOptions extends WP_XMLRPC_UnitTestCase { $this->assertEquals( current_theme_supports( 'post-thumbnails' ), $result['post_thumbnail']['value'] ); $this->assertTrue( $result['post_thumbnail']['readonly'] ); - // Updatable options + // Updatable options. $this->assertEquals( get_option( 'gmt_offset' ), $result['time_zone']['value'] ); $this->assertTrue( $result['time_zone']['readonly'] ); @@ -128,7 +128,7 @@ class Tests_XMLRPC_wp_getOptions extends WP_XMLRPC_UnitTestCase { $result = $this->myxmlrpcserver->wp_getOptions( array( 1, 'administrator', 'administrator' ) ); $this->assertInternalType( 'array', $result ); - // Read Only options + // Read-only options. $this->assertEquals( 'WordPress', $result['software_name']['value'] ); $this->assertTrue( $result['software_name']['readonly'] ); @@ -162,7 +162,7 @@ class Tests_XMLRPC_wp_getOptions extends WP_XMLRPC_UnitTestCase { $this->assertEquals( current_theme_supports( 'post-thumbnails' ), $result['post_thumbnail']['value'] ); $this->assertTrue( $result['post_thumbnail']['readonly'] ); - // Updatable options + // Updatable options. $this->assertEquals( get_option( 'gmt_offset' ), $result['time_zone']['value'] ); $this->assertFalse( $result['time_zone']['readonly'] ); diff --git a/tests/phpunit/tests/xmlrpc/wp/getPage.php b/tests/phpunit/tests/xmlrpc/wp/getPage.php index 8ece6e1254..7991f5568d 100644 --- a/tests/phpunit/tests/xmlrpc/wp/getPage.php +++ b/tests/phpunit/tests/xmlrpc/wp/getPage.php @@ -45,7 +45,7 @@ class Tests_XMLRPC_wp_getPage extends WP_XMLRPC_UnitTestCase { $result = $this->myxmlrpcserver->wp_getPage( array( 1, self::$post_id, 'editor', 'editor' ) ); $this->assertNotIXRError( $result ); - // Check data types + // Check data types. $this->assertInternalType( 'string', $result['userid'] ); $this->assertInternalType( 'int', $result['page_id'] ); $this->assertInternalType( 'string', $result['page_status'] ); @@ -71,7 +71,7 @@ class Tests_XMLRPC_wp_getPage extends WP_XMLRPC_UnitTestCase { $post_data = get_post( self::$post_id ); - // Check expected values + // Check expected values. $this->assertStringMatchesFormat( '%d', $result['userid'] ); $this->assertEquals( 'future', $result['page_status'] ); $this->assertEquals( $post_data->post_title, $result['title'] ); diff --git a/tests/phpunit/tests/xmlrpc/wp/getPost.php b/tests/phpunit/tests/xmlrpc/wp/getPost.php index 8a3cf7469d..f0bdc0cc3f 100644 --- a/tests/phpunit/tests/xmlrpc/wp/getPost.php +++ b/tests/phpunit/tests/xmlrpc/wp/getPost.php @@ -41,7 +41,7 @@ class Tests_XMLRPC_wp_getPost extends WP_XMLRPC_UnitTestCase { $result = $this->myxmlrpcserver->wp_getPost( array( 1, 'author', 'author', $this->post_id, $fields ) ); $this->assertNotIXRError( $result ); - // Check data types + // Check data types. $this->assertInternalType( 'string', $result['post_id'] ); $this->assertInternalType( 'string', $result['post_title'] ); $this->assertInstanceOf( 'IXR_Date', $result['post_date'] ); @@ -63,7 +63,7 @@ class Tests_XMLRPC_wp_getPost extends WP_XMLRPC_UnitTestCase { $this->assertInternalType( 'array', $result['post_thumbnail'] ); $this->assertInternalType( 'array', $result['custom_fields'] ); - // Check expected values + // Check expected values. $this->assertStringMatchesFormat( '%d', $result['post_id'] ); $this->assertEquals( $this->post_data['post_title'], $result['post_title'] ); $this->assertEquals( 'draft', $result['post_status'] ); @@ -84,7 +84,7 @@ class Tests_XMLRPC_wp_getPost extends WP_XMLRPC_UnitTestCase { $result = $this->myxmlrpcserver->wp_getPost( array( 1, 'author', 'author', $this->post_id, $fields ) ); $this->assertNotIXRError( $result ); - // when no fields are requested, only the IDs should be returned + // When no fields are requested, only the IDs should be returned. $this->assertEquals( 1, count( $result ) ); $this->assertEquals( array( 'post_id' ), array_keys( $result ) ); } @@ -94,7 +94,7 @@ class Tests_XMLRPC_wp_getPost extends WP_XMLRPC_UnitTestCase { $this->assertNotIXRError( $result ); $this->assertArrayHasKey( 'post_id', $result ); - $this->assertArrayHasKey( 'link', $result ); // random field from 'posts' group + $this->assertArrayHasKey( 'link', $result ); // Random field from 'posts' group. $this->assertArrayHasKey( 'terms', $result ); $this->assertArrayHasKey( 'custom_fields', $result ); } diff --git a/tests/phpunit/tests/xmlrpc/wp/getPostType.php b/tests/phpunit/tests/xmlrpc/wp/getPostType.php index 1f5ffe621e..33a055b580 100644 --- a/tests/phpunit/tests/xmlrpc/wp/getPostType.php +++ b/tests/phpunit/tests/xmlrpc/wp/getPostType.php @@ -64,7 +64,7 @@ class Tests_XMLRPC_wp_getPostType extends WP_XMLRPC_UnitTestCase { $result = $this->myxmlrpcserver->wp_getPostType( array( 1, 'editor', 'editor', $this->cpt_name, array( 'labels', 'cap', 'menu', 'taxonomies' ) ) ); $this->assertNotIXRError( $result ); - // check data types + // Check data types. $this->assertInternalType( 'string', $result['name'] ); $this->assertInternalType( 'string', $result['label'] ); $this->assertInternalType( 'bool', $result['hierarchical'] ); @@ -80,7 +80,7 @@ class Tests_XMLRPC_wp_getPostType extends WP_XMLRPC_UnitTestCase { $this->assertInternalType( 'array', $result['taxonomies'] ); $this->assertInternalType( 'array', $result['supports'] ); - // check label data types + // Check label data types. $this->assertInternalType( 'string', $result['labels']['name'] ); $this->assertInternalType( 'string', $result['labels']['singular_name'] ); $this->assertInternalType( 'string', $result['labels']['add_new'] ); @@ -96,7 +96,7 @@ class Tests_XMLRPC_wp_getPostType extends WP_XMLRPC_UnitTestCase { $this->assertInternalType( 'string', $result['labels']['menu_name'] ); $this->assertInternalType( 'string', $result['labels']['name_admin_bar'] ); - // check cap data types + // Check cap data types. $this->assertInternalType( 'string', $result['cap']['edit_post'] ); $this->assertInternalType( 'string', $result['cap']['read_post'] ); $this->assertInternalType( 'string', $result['cap']['delete_post'] ); @@ -112,18 +112,18 @@ class Tests_XMLRPC_wp_getPostType extends WP_XMLRPC_UnitTestCase { $this->assertInternalType( 'string', $result['cap']['edit_private_posts'] ); $this->assertInternalType( 'string', $result['cap']['edit_published_posts'] ); - // check taxonomy data types + // Check taxonomy data types. foreach ( $result['taxonomies'] as $taxonomy ) { $this->assertInternalType( 'string', $taxonomy ); } - // check taxonomy data types + // Check support data types. foreach ( $result['supports'] as $key => $value ) { $this->assertInternalType( 'string', $key ); $this->assertInternalType( 'bool', $value ); } - // Check expected values + // Check expected values. $this->assertEquals( $this->cpt_name, $result['name'] ); foreach ( $this->cpt_args as $key => $value ) { $this->assertEquals( $value, $result[ $key ] ); diff --git a/tests/phpunit/tests/xmlrpc/wp/getPostTypes.php b/tests/phpunit/tests/xmlrpc/wp/getPostTypes.php index f0717adcfe..20f1092574 100644 --- a/tests/phpunit/tests/xmlrpc/wp/getPostTypes.php +++ b/tests/phpunit/tests/xmlrpc/wp/getPostTypes.php @@ -35,7 +35,7 @@ class Tests_XMLRPC_wp_getPostTypes extends WP_XMLRPC_UnitTestCase { $this->assertNotIXRError( $result ); $this->assertInternalType( 'array', $result ); - // verify that pages is in the result, and post is not + // Verify that page is in the result, and post is not. $result_names = wp_list_pluck( $result, 'name' ); $this->assertContains( 'page', $result_names ); $this->assertNotContains( 'post', $result_names ); diff --git a/tests/phpunit/tests/xmlrpc/wp/getPosts.php b/tests/phpunit/tests/xmlrpc/wp/getPosts.php index c9a1b4cce1..1cece0550a 100644 --- a/tests/phpunit/tests/xmlrpc/wp/getPosts.php +++ b/tests/phpunit/tests/xmlrpc/wp/getPosts.php @@ -64,7 +64,7 @@ class Tests_XMLRPC_wp_getPosts extends WP_XMLRPC_UnitTestCase { ) ); } - // get them all + // Get them all. $filter = array( 'post_type' => $cpt_name, 'number' => $num_posts + 10, @@ -73,7 +73,7 @@ class Tests_XMLRPC_wp_getPosts extends WP_XMLRPC_UnitTestCase { $this->assertNotIXRError( $results ); $this->assertEquals( $num_posts, count( $results ) ); - // page through results + // Page through results. $posts_found = array(); $filter['number'] = 2; $filter['offset'] = 0; @@ -82,16 +82,16 @@ class Tests_XMLRPC_wp_getPosts extends WP_XMLRPC_UnitTestCase { $posts_found = array_merge( $posts_found, wp_list_pluck( $presults, 'post_id' ) ); $filter['offset'] += $filter['number']; } while ( count( $presults ) > 0 ); - // verify that $post_ids matches $posts_found + // Verify that $post_ids matches $posts_found. $this->assertEquals( 0, count( array_diff( $post_ids, $posts_found ) ) ); - // add comments to some of the posts + // Add comments to some of the posts. foreach ( $post_ids as $key => $post_id ) { // Larger post IDs will get more comments. self::factory()->comment->create_post_comments( $post_id, $key ); } - // get results ordered by comment count + // Get results ordered by comment count. $filter2 = array( 'post_type' => $cpt_name, 'number' => $num_posts, @@ -107,7 +107,7 @@ class Tests_XMLRPC_wp_getPosts extends WP_XMLRPC_UnitTestCase { $last_comment_count = $comment_count; } - // set one of the posts to draft and get drafts + // Set one of the posts to draft and get drafts. $post = get_post( $post_ids[0] ); $post->post_status = 'draft'; wp_update_post( $post ); @@ -127,15 +127,15 @@ class Tests_XMLRPC_wp_getPosts extends WP_XMLRPC_UnitTestCase { $this->make_user_by_role( 'editor' ); self::factory()->post->create(); - // check default fields + // Check default fields. $results = $this->myxmlrpcserver->wp_getPosts( array( 1, 'editor', 'editor' ) ); $this->assertNotIXRError( $results ); - $expected_fields = array( 'post_id', 'post_title', 'terms', 'custom_fields', 'link' ); // subset of expected fields + $expected_fields = array( 'post_id', 'post_title', 'terms', 'custom_fields', 'link' ); // Subset of expected fields. foreach ( $expected_fields as $field ) { $this->assertArrayHasKey( $field, $results[0] ); } - // request specific fields and verify that only those are returned + // Request specific fields and verify that only those are returned. $filter = array(); $fields = array( 'post_name', 'post_author', 'enclosure' ); $results2 = $this->myxmlrpcserver->wp_getPosts( array( 1, 'editor', 'editor', $filter, $fields ) ); @@ -155,13 +155,13 @@ class Tests_XMLRPC_wp_getPosts extends WP_XMLRPC_UnitTestCase { $post_ids[] = self::factory()->post->create( array( 'post_title' => 'First: Hello, World!' ) ); $post_ids[] = self::factory()->post->create( array( 'post_title' => 'Second: Hello, World!' ) ); - // Search for none of them + // Search for none of them. $filter = array( 's' => 'Third' ); $results = $this->myxmlrpcserver->wp_getPosts( array( 1, 'editor', 'editor', $filter ) ); $this->assertNotIXRError( $results ); $this->assertEquals( 0, count( $results ) ); - // Search for one of them + // Search for one of them. $filter = array( 's' => 'First:' ); $results = $this->myxmlrpcserver->wp_getPosts( array( 1, 'editor', 'editor', $filter ) ); $this->assertNotIXRError( $results ); diff --git a/tests/phpunit/tests/xmlrpc/wp/getRevisions.php b/tests/phpunit/tests/xmlrpc/wp/getRevisions.php index 966c59f387..15b9287d75 100644 --- a/tests/phpunit/tests/xmlrpc/wp/getRevisions.php +++ b/tests/phpunit/tests/xmlrpc/wp/getRevisions.php @@ -38,7 +38,7 @@ class Tests_XMLRPC_wp_getRevisions extends WP_XMLRPC_UnitTestCase { 'ID' => $post_id, 'post_content' => 'Edit 1', ) - ); // Create the initial revision + ); // Create the initial revision. $result = $this->myxmlrpcserver->wp_getRevisions( array( 1, 'editor', 'editor', $post_id ) ); $this->assertInternalType( 'array', $result ); diff --git a/tests/phpunit/tests/xmlrpc/wp/getTerm.php b/tests/phpunit/tests/xmlrpc/wp/getTerm.php index 9266c47cb3..35910f6f5d 100644 --- a/tests/phpunit/tests/xmlrpc/wp/getTerm.php +++ b/tests/phpunit/tests/xmlrpc/wp/getTerm.php @@ -78,7 +78,7 @@ class Tests_XMLRPC_wp_getTerm extends WP_XMLRPC_UnitTestCase { $this->assertNotIXRError( $result ); $this->assertEquals( $result, $term ); - // Check DataTypes + // Check data types. $this->assertInternalType( 'string', $result['name'] ); $this->assertInternalType( 'string', $result['slug'] ); $this->assertInternalType( 'string', $result['taxonomy'] ); @@ -91,7 +91,7 @@ class Tests_XMLRPC_wp_getTerm extends WP_XMLRPC_UnitTestCase { $this->assertStringMatchesFormat( '%d', $result['term_taxonomy_id'] ); $this->assertStringMatchesFormat( '%d', $result['parent'] ); - // Check Data + // Check data. $this->assertEquals( 0, $result['count'] ); $this->assertEquals( $term['name'], $result['name'] ); $this->assertEquals( $term['slug'], $result['slug'] ); diff --git a/tests/phpunit/tests/xmlrpc/wp/getTerms.php b/tests/phpunit/tests/xmlrpc/wp/getTerms.php index 477bed7195..0dca65e409 100644 --- a/tests/phpunit/tests/xmlrpc/wp/getTerms.php +++ b/tests/phpunit/tests/xmlrpc/wp/getTerms.php @@ -41,7 +41,7 @@ class Tests_XMLRPC_wp_getTerms extends WP_XMLRPC_UnitTestCase { function test_valid_terms() { $this->make_user_by_role( 'editor' ); - // make sure there's at least one category + // Make sure there's at least one category. $cat = wp_insert_term( 'term_' . __FUNCTION__, 'category' ); $results = $this->myxmlrpcserver->wp_getTerms( array( 1, 'editor', 'editor', 'category' ) ); @@ -50,10 +50,11 @@ class Tests_XMLRPC_wp_getTerms extends WP_XMLRPC_UnitTestCase { foreach ( $results as $term ) { $this->assertInternalType( 'int', $term['count'] ); - // Check custom term meta + // Check custom term meta. $this->assertInternalType( 'array', $term['custom_fields'] ); - // We expect all other IDs to be strings not integers so we don't return something larger than an XMLRPC integer can describe. + // We expect all other IDs to be strings, not integers, + // so we don't return something larger than an XMLRPC integer can describe. $this->assertStringMatchesFormat( '%d', $term['term_id'] ); $this->assertStringMatchesFormat( '%d', $term['term_group'] ); $this->assertStringMatchesFormat( '%d', $term['term_taxonomy_id'] ); @@ -64,7 +65,7 @@ class Tests_XMLRPC_wp_getTerms extends WP_XMLRPC_UnitTestCase { function test_custom_taxonomy() { $this->make_user_by_role( 'editor' ); - // create a taxonomy and some terms for it + // Create a taxonomy and some terms for it. $tax_name = 'wp_getTerms_custom_taxonomy'; $num_terms = 12; register_taxonomy( $tax_name, 'post' ); @@ -72,7 +73,7 @@ class Tests_XMLRPC_wp_getTerms extends WP_XMLRPC_UnitTestCase { wp_insert_term( "term_{$i}", $tax_name ); } - // test fetching all terms + // Test fetching all terms. $results = $this->myxmlrpcserver->wp_getTerms( array( 1, 'editor', 'editor', $tax_name ) ); $this->assertNotIXRError( $results ); @@ -81,12 +82,12 @@ class Tests_XMLRPC_wp_getTerms extends WP_XMLRPC_UnitTestCase { $this->assertEquals( $tax_name, $term['taxonomy'] ); } - // test paged results + // Test paged results. $filter = array( 'number' => 5 ); $results2 = $this->myxmlrpcserver->wp_getTerms( array( 1, 'editor', 'editor', $tax_name, $filter ) ); $this->assertNotIXRError( $results ); $this->assertEquals( 5, count( $results2 ) ); - $this->assertEquals( $results[1]['term_id'], $results2[1]['term_id'] ); // check one of the terms + $this->assertEquals( $results[1]['term_id'], $results2[1]['term_id'] ); // Check one of the terms. $filter['offset'] = 10; $results3 = $this->myxmlrpcserver->wp_getTerms( array( 1, 'editor', 'editor', $tax_name, $filter ) ); @@ -94,7 +95,7 @@ class Tests_XMLRPC_wp_getTerms extends WP_XMLRPC_UnitTestCase { $this->assertEquals( $num_terms - 10, count( $results3 ) ); $this->assertEquals( $results[11]['term_id'], $results3[1]['term_id'] ); - // test hide_empty (since none have been attached to posts yet, all should be hidden + // Test hide_empty (since none have been attached to posts yet, all should be hidden. $filter = array( 'hide_empty' => true ); $results4 = $this->myxmlrpcserver->wp_getTerms( array( 1, 'editor', 'editor', $tax_name, $filter ) ); $this->assertNotIXRError( $results4 ); @@ -122,7 +123,7 @@ class Tests_XMLRPC_wp_getTerms extends WP_XMLRPC_UnitTestCase { foreach ( $results as $term ) { if ( $term['term_id'] === $cat1 ) { - break; // found cat1 first as expected + break; // Found cat1 first as expected. } elseif ( $term['term_id'] === $cat2 ) { $this->assertFalse( false, 'Incorrect category ordering.' ); } @@ -135,7 +136,7 @@ class Tests_XMLRPC_wp_getTerms extends WP_XMLRPC_UnitTestCase { $name = __FUNCTION__; $name_id = wp_create_category( $name ); - // search by full name + // Search by full name. $filter = array( 'search' => $name ); $results = $this->myxmlrpcserver->wp_getTerms( array( 1, 'editor', 'editor', 'category', $filter ) ); $this->assertNotIXRError( $results ); @@ -143,7 +144,7 @@ class Tests_XMLRPC_wp_getTerms extends WP_XMLRPC_UnitTestCase { $this->assertEquals( $name, $results[0]['name'] ); $this->assertEquals( $name_id, $results[0]['term_id'] ); - // search by partial name + // Search by partial name. $filter = array( 'search' => substr( $name, 0, 10 ) ); $results2 = $this->myxmlrpcserver->wp_getTerms( array( 1, 'editor', 'editor', 'category', $filter ) ); $this->assertNotIXRError( $results2 ); diff --git a/tests/phpunit/tests/xmlrpc/wp/getUser.php b/tests/phpunit/tests/xmlrpc/wp/getUser.php index b7361a125b..cc19496c9c 100644 --- a/tests/phpunit/tests/xmlrpc/wp/getUser.php +++ b/tests/phpunit/tests/xmlrpc/wp/getUser.php @@ -10,7 +10,7 @@ class Tests_XMLRPC_wp_getUser extends WP_XMLRPC_UnitTestCase { function setUp() { parent::setUp(); - // create a super-admin + // Create a super admin. $this->administrator_id = $this->make_user_by_role( 'administrator' ); if ( is_multisite() ) { grant_super_admin( $this->administrator_id ); @@ -75,7 +75,7 @@ class Tests_XMLRPC_wp_getUser extends WP_XMLRPC_UnitTestCase { $result = $this->myxmlrpcserver->wp_getUser( array( 1, 'administrator', 'administrator', $user_id ) ); $this->assertNotIXRError( $result ); - // check data types + // Check data types. $this->assertInternalType( 'string', $result['user_id'] ); $this->assertStringMatchesFormat( '%d', $result['user_id'] ); $this->assertInternalType( 'string', $result['username'] ); @@ -90,7 +90,7 @@ class Tests_XMLRPC_wp_getUser extends WP_XMLRPC_UnitTestCase { $this->assertInternalType( 'string', $result['display_name'] ); $this->assertInternalType( 'array', $result['roles'] ); - // check expected values + // Check expected values. $this->assertEquals( $user_id, $result['user_id'] ); $this->assertEquals( $user_data['user_login'], $result['username'] ); $this->assertEquals( $user_data['first_name'], $result['first_name'] ); diff --git a/tests/phpunit/tests/xmlrpc/wp/getUsers.php b/tests/phpunit/tests/xmlrpc/wp/getUsers.php index bddafcf39a..412a13b364 100644 --- a/tests/phpunit/tests/xmlrpc/wp/getUsers.php +++ b/tests/phpunit/tests/xmlrpc/wp/getUsers.php @@ -26,7 +26,7 @@ class Tests_XMLRPC_wp_getUsers extends WP_XMLRPC_UnitTestCase { $result = $this->myxmlrpcserver->wp_getUsers( array( 1, 'administrator', 'administrator' ) ); $this->assertNotIXRError( $result ); - // check data types + // Check data types. $this->assertInternalType( 'string', $result[0]['user_id'] ); $this->assertStringMatchesFormat( '%d', $result[0]['user_id'] ); $this->assertInternalType( 'string', $result[0]['username'] ); @@ -62,14 +62,14 @@ class Tests_XMLRPC_wp_getUsers extends WP_XMLRPC_UnitTestCase { grant_super_admin( $administrator_id ); } - // test a single role ('editor') + // Test a single role ('editor'). $filter = array( 'role' => 'editor' ); $results = $this->myxmlrpcserver->wp_getUsers( array( 1, 'administrator', 'administrator', $filter ) ); $this->assertNotIXRError( $results ); $this->assertCount( 1, $results ); $this->assertEquals( $editor_id, $results[0]['user_id'] ); - // test 'authors', which should return all non-subscribers + // Test 'authors', which should return all non-subscribers. $filter2 = array( 'who' => 'authors' ); $results2 = $this->myxmlrpcserver->wp_getUsers( array( 1, 'administrator', 'administrator', $filter2 ) ); $this->assertNotIXRError( $results2 ); @@ -101,7 +101,7 @@ class Tests_XMLRPC_wp_getUsers extends WP_XMLRPC_UnitTestCase { $filter['offset'] += $page_size; } while ( count( $presults ) > 0 ); - // verify that $user_ids matches $users_found + // Verify that $user_ids matches $users_found. $this->assertEquals( 0, count( array_diff( $user_ids, $users_found ) ) ); } diff --git a/tests/phpunit/tests/xmlrpc/wp/newComment.php b/tests/phpunit/tests/xmlrpc/wp/newComment.php index 4336e5b1e6..a44361ae60 100644 --- a/tests/phpunit/tests/xmlrpc/wp/newComment.php +++ b/tests/phpunit/tests/xmlrpc/wp/newComment.php @@ -84,11 +84,11 @@ class Tests_XMLRPC_wp_newComment extends WP_XMLRPC_UnitTestCase { ), ); - // First time it's a valid comment + // First time it's a valid comment. $result = $this->myxmlrpcserver->wp_newComment( $comment_args ); $this->assertNotIXRError( $result ); - // Run second time for duplication error + // Run second time for duplication error. $result = $this->myxmlrpcserver->wp_newComment( $comment_args ); $this->assertIXRError( $result ); diff --git a/tests/phpunit/tests/xmlrpc/wp/newPost.php b/tests/phpunit/tests/xmlrpc/wp/newPost.php index 7e37333254..675a47577e 100644 --- a/tests/phpunit/tests/xmlrpc/wp/newPost.php +++ b/tests/phpunit/tests/xmlrpc/wp/newPost.php @@ -150,7 +150,7 @@ class Tests_XMLRPC_wp_newPost extends WP_XMLRPC_UnitTestCase { $this->make_user_by_role( 'author' ); - // create attachment + // Create attachment. $filename = ( DIR_TESTDATA . '/images/a2-small.jpg' ); $attachment_id = self::factory()->attachment->create_upload_object( $filename ); @@ -312,7 +312,7 @@ class Tests_XMLRPC_wp_newPost extends WP_XMLRPC_UnitTestCase { $cat1 = wp_create_category( $cat1_name, $parent_cat ); $cat2_name = 'cat2'; - // first a post with valid categories; one that already exists and one to be created + // First a post with valid categories; one that already exists and one to be created. $post = array( 'post_title' => 'Test', 'terms_names' => array( @@ -321,15 +321,15 @@ class Tests_XMLRPC_wp_newPost extends WP_XMLRPC_UnitTestCase { ); $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) ); $this->assertNotIXRError( $result ); - // verify that cat2 was created + // Verify that cat2 was created. $cat2 = get_term_by( 'name', $cat2_name, 'category' ); $this->assertNotEmpty( $cat2 ); - // check that both categories were set on the post + // Check that both categories were set on the post. $post_cats = wp_get_object_terms( $result, 'category', array( 'fields' => 'ids' ) ); $this->assertContains( $cat1, $post_cats ); $this->assertContains( $cat2->term_id, $post_cats ); - // create a second post attempting to use the ambiguous name + // Create a second post attempting to use the ambiguous name. $post2 = array( 'post_title' => 'Test', 'terms_names' => array( diff --git a/tests/phpunit/tests/xmlrpc/wp/restoreRevision.php b/tests/phpunit/tests/xmlrpc/wp/restoreRevision.php index ca15a2d358..7b7021ecc4 100644 --- a/tests/phpunit/tests/xmlrpc/wp/restoreRevision.php +++ b/tests/phpunit/tests/xmlrpc/wp/restoreRevision.php @@ -10,7 +10,7 @@ class Tests_XMLRPC_wp_restoreRevision extends WP_XMLRPC_UnitTestCase { function setUp() { parent::setUp(); - $this->post_id = self::factory()->post->create( array( 'post_content' => 'edit1' ) ); // Not saved as a revision + $this->post_id = self::factory()->post->create( array( 'post_content' => 'edit1' ) ); // Not saved as a revision. // First saved revision on update, see https://core.trac.wordpress.org/changeset/24650 wp_insert_post( array( @@ -20,7 +20,8 @@ class Tests_XMLRPC_wp_restoreRevision extends WP_XMLRPC_UnitTestCase { ); $revisions = wp_get_post_revisions( $this->post_id ); - //$revision = array_shift( $revisions ); // First revision is empty - https://core.trac.wordpress.org/changeset/23842 + // First revision is empty, see https://core.trac.wordpress.org/changeset/23842 + // $revision = array_shift( $revisions ); // First revision is NOT empty, see https://core.trac.wordpress.org/changeset/24650 $revision = array_shift( $revisions ); $this->revision_id = $revision->ID; diff --git a/tests/phpunit/tests/xmlrpc/wp/setOptions.php b/tests/phpunit/tests/xmlrpc/wp/setOptions.php index 36e85a92c7..27ad135ddc 100644 --- a/tests/phpunit/tests/xmlrpc/wp/setOptions.php +++ b/tests/phpunit/tests/xmlrpc/wp/setOptions.php @@ -10,7 +10,7 @@ class Tests_XMLRPC_wp_setOptions extends WP_XMLRPC_UnitTestCase { function test_set_option_no_escape_strings() { $this->make_user_by_role( 'administrator' ); $string_with_quote = "Mary's Lamb Shop"; - $escaped_string_with_quote = esc_html( $string_with_quote ); // title is passed through esc_html() + $escaped_string_with_quote = esc_html( $string_with_quote ); // Title is passed through esc_html(). update_option( 'default_comment_status', 'closed' ); $this->assertEquals( 'closed', get_option( 'default_comment_status' ) ); diff --git a/tests/phpunit/tests/xmlrpc/wp/uploadFile.php b/tests/phpunit/tests/xmlrpc/wp/uploadFile.php index f11f15c77e..2f365d7f93 100644 --- a/tests/phpunit/tests/xmlrpc/wp/uploadFile.php +++ b/tests/phpunit/tests/xmlrpc/wp/uploadFile.php @@ -14,7 +14,7 @@ class Tests_XMLRPC_wp_uploadFile extends WP_XMLRPC_UnitTestCase { function test_valid_attachment() { $this->make_user_by_role( 'editor' ); - // create attachment + // Create attachment. $filename = ( DIR_TESTDATA . '/images/a2-small.jpg' ); $contents = file_get_contents( $filename ); $data = array( @@ -26,7 +26,7 @@ class Tests_XMLRPC_wp_uploadFile extends WP_XMLRPC_UnitTestCase { $result = $this->myxmlrpcserver->mw_newMediaObject( array( 0, 'editor', 'editor', $data ) ); $this->assertNotIXRError( $result ); - // check data types + // Check data types. $this->assertInternalType( 'string', $result['id'] ); $this->assertStringMatchesFormat( '%d', $result['id'] ); $this->assertInternalType( 'string', $result['file'] ); diff --git a/tests/phpunit/wp-mail-real-test.php b/tests/phpunit/wp-mail-real-test.php index 67da30ef86..f7be2055c3 100644 --- a/tests/phpunit/wp-mail-real-test.php +++ b/tests/phpunit/wp-mail-real-test.php @@ -5,7 +5,7 @@ * Test script for wp_mail with real addresses. */ -// parse options +// Parse options. $options = 'v:r:d'; if ( is_callable( 'getopt' ) ) { $opts = getopt( $options ); @@ -27,24 +27,24 @@ if ( ! empty( $opts['r'] ) ) { define( 'DIR_WP', DIR_TESTROOT . '/wordpress' ); } -// make sure all useful errors are displayed during setup +// Make sure all useful errors are displayed during setup. error_reporting( E_ALL & ~E_DEPRECATED ); ini_set( 'display_errors', true ); require_once( DIR_TESTROOT . '/wp-testlib/utils.php' ); -// configure wp +// Configure WP. require_once( DIR_TESTROOT . '/wp-config.php' ); define( 'ABSPATH', realpath( DIR_WP ) . '/' ); -// install wp +// Install WP. define( 'WP_BLOG_TITLE', rand_str() ); define( 'WP_USER_NAME', rand_str() ); define( 'WP_USER_EMAIL', rand_str() . '@example.com' ); -// initialize wp +// Initialize WP. define( 'WP_INSTALLING', 1 ); -$_SERVER['PATH_INFO'] = $_SERVER['SCRIPT_NAME']; // prevent a warning from some sloppy code in wp-settings.php +$_SERVER['PATH_INFO'] = $_SERVER['SCRIPT_NAME']; // Prevent a warning from some sloppy code in wp-settings.php. require_once( ABSPATH . 'wp-settings.php' ); drop_tables(); @@ -52,14 +52,14 @@ drop_tables(); require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); wp_install( WP_BLOG_TITLE, WP_USER_NAME, WP_USER_EMAIL, true ); -// make sure we're installed +// Make sure we're installed. assert( true === is_blog_installed() ); // phpcs:ignore Generic.NamingConventions.UpperCaseConstantName.ConstantNotUpperCase define( 'PHPUnit_MAIN_METHOD', false ); $original_wpdb = $GLOBALS['wpdb']; -// hide warnings during testing, since that's the normal WP behaviour +// Hide warnings during testing, since that's the normal WP behaviour. if ( ! WP_DEBUG ) { error_reporting( E_ALL ^ E_NOTICE ); } diff --git a/tests/qunit/fixtures/customize-menus.js b/tests/qunit/fixtures/customize-menus.js index 0525ac42ff..7ce6d6db7b 100644 --- a/tests/qunit/fixtures/customize-menus.js +++ b/tests/qunit/fixtures/customize-menus.js @@ -119,7 +119,7 @@ window._wpCustomizeSettings.panels.nav_menus = { 'instanceNumber': 2 }; -// Nav Menu Locations +// Nav Menu Locations. window._wpCustomizeSettings.sections.menu_locations = { 'id': 'menu_locations', 'description': '

    Your theme contains 1 menu location. Select which menu you would like to use.<\/p>

    You can also place menus in widget areas with the Custom Menu widget.<\/p>', @@ -169,7 +169,7 @@ window._wpCustomizeSettings.controls['nav_menu_locations[primary]'] = { 'type': 'nav_menu_location' }; -// Nav Menus +// Nav Menus. window._wpCustomizeSettings.sections['nav_menu[3]'] = { 'id': 'nav_menu[3]', 'description': '', @@ -218,7 +218,7 @@ window._wpCustomizeSettings.settings['nav_menu[2]'] = { 'dirty': false }; -// Menu items +// Menu items. window._wpCustomizeSettings.settings['nav_menu_item[2000]'] = { 'dirty': false, 'transport': 'postMessage', @@ -370,7 +370,7 @@ window._wpCustomizeSettings.controls['nav_menu_item[2002]'] = { 'xfn': '' }; -// Meta controls +// Meta controls. window._wpCustomizeSettings.sections.add_menu = { 'id': 'add_menu', 'description': '', @@ -395,7 +395,7 @@ window._wpCustomizeSettings.controls.new_menu_name = { 'instanceNumber': 46 }; -// From nav-menu.js +// From nav-menu.js. window.wpNavMenu = { 'options': { 'menuItemDepthPerLevel': 30, diff --git a/tests/qunit/fixtures/updates.js b/tests/qunit/fixtures/updates.js index b90bb6cd53..7e31370814 100644 --- a/tests/qunit/fixtures/updates.js +++ b/tests/qunit/fixtures/updates.js @@ -27,8 +27,8 @@ window._wpUpdatesSettings = { 'themeInstalled': 'Installed!', 'installFailedShort': 'Install Failed!', 'installFailed': 'Installation failed: %s', - 'pluginInstallingLabel': 'Installing %s...', // No ellipsis - 'themeInstallingLabel': 'Installing %s...', // No ellipsis + 'pluginInstallingLabel': 'Installing %s...', // No ellipsis. + 'themeInstallingLabel': 'Installing %s...', // No ellipsis. 'pluginInstalledLabel': '%s installed!', 'themeInstalledLabel': '%s installed!', 'pluginInstallFailedLabel': '%s installation failed', diff --git a/tests/qunit/fixtures/wp-api.js b/tests/qunit/fixtures/wp-api.js index 04c9dd1823..0c6db9b1a6 100644 --- a/tests/qunit/fixtures/wp-api.js +++ b/tests/qunit/fixtures/wp-api.js @@ -51,7 +51,7 @@ Backbone.ajax = function ( param ) { param.success( data ); var deferred = jQuery.Deferred(); - // Resolve the deferred with the mocked data + // Resolve the deferred with the mocked data. deferred.resolve( data ); // Return the deferred promise that will resolve with the expected data. diff --git a/tests/qunit/wp-admin/js/customize-base.js b/tests/qunit/wp-admin/js/customize-base.js index 9b40e29d08..2db95db23e 100644 --- a/tests/qunit/wp-admin/js/customize-base.js +++ b/tests/qunit/wp-admin/js/customize-base.js @@ -48,7 +48,7 @@ jQuery( function( $ ) { }); // @todo Test Class.applicator? - // @todo do we test object.instance? + // @todo Do we test object.instance? module( 'Customize Base: Subclass' ); @@ -82,7 +82,7 @@ jQuery( function( $ ) { }); - // Implements todo : Test Class.constructor() manipulation + // Implements todo: Test Class.constructor() manipulation. module( 'Customize Base: Constructor Manipulation' ); newConstructor = function ( instanceProps ) { diff --git a/tests/qunit/wp-admin/js/customize-controls.js b/tests/qunit/wp-admin/js/customize-controls.js index ed92f5a2cd..85d043f78f 100644 --- a/tests/qunit/wp-admin/js/customize-controls.js +++ b/tests/qunit/wp-admin/js/customize-controls.js @@ -462,7 +462,7 @@ jQuery( window ).load( function (){ id: sectionId, content: sectionContent, priority: 100, - active: true // @todo This should default to true + active: true // @todo This should default to true. }; testCustomizerModel( mockSection, sectionExpectedValues ); @@ -501,7 +501,7 @@ jQuery( window ).load( function (){ label: controlLabel, settings: { 'default': 'new_blogname' }, type: controlType, - active: true // @todo This should default to true + active: true // @todo This should default to true. }; mockControl = new wp.customize.Control( controlId, { @@ -566,7 +566,7 @@ jQuery( window ).load( function (){ content: panelContent, title: panelTitle, description: panelDescription, - active: true, // @todo This should default to true + active: true, // @todo This should default to true. type: 'default' }; @@ -743,7 +743,7 @@ jQuery( window ).load( function (){ day( '3' ); assert.ok( ! control.invalidDate ); - // Test control.parseDateTime(); + // Test control.parseDateTime(). control.params.twelveHourFormat = false; dateTimeArray = control.parseDateTime( datetime ); assert.deepEqual( dateTimeArray, { @@ -786,7 +786,7 @@ jQuery( window ).load( function (){ assert.equal( timeString, '2010-12-18' ); control.params.includeTime = true; - // Test control.updateDaysForMonth();. + // Test control.updateDaysForMonth(). year( 2017 ); month( 2 ); day( 28 ); @@ -810,7 +810,7 @@ jQuery( window ).load( function (){ control.toggleFutureDateNotification( false ); assert.notOk( control.notifications.has( 'not_future_date' ) ); - // Test control.populateDateInputs(); + // Test control.populateDateInputs(). control.setting._value = '2000-12-30 12:34:56'; control.populateDateInputs(); assert.equal( '2000', control.inputElements.year.get() ); @@ -820,7 +820,7 @@ jQuery( window ).load( function (){ assert.equal( '34', control.inputElements.minute.get() ); assert.equal( 'pm', control.inputElements.meridian.get() ); - // Test control.validateInputs(); + // Test control.validateInputs(). hour( 33 ); assert.ok( control.validateInputs() ); hour( 10 ); @@ -830,7 +830,7 @@ jQuery( window ).load( function (){ minute( 20 ); assert.notOk( control.validateInputs() ); - // Test control.populateSetting(); + // Test control.populateSetting(). day( 2 ); month( 11 ); year( 2018 ); @@ -848,7 +848,7 @@ jQuery( window ).load( function (){ control.populateSetting(); assert.equal( control.setting(), '2018-11-02 17:20:00' ); - // Test control.isFutureDate(); + // Test control.isFutureDate(). day( 2 ); month( 11 ); year( 2318 ); @@ -860,7 +860,7 @@ jQuery( window ).load( function (){ year( 2016 ); assert.notOk( control.isFutureDate() ); - // Tear Down. + // Tear down. wp.customize.control.remove( controlId ); }); @@ -895,7 +895,7 @@ jQuery( window ).load( function (){ assert.notOk( section.container.hasClass( 'open' ) ); // Ensure it does not affect other sections state. assert.ok( defaultSection.expanded() ); - // Tear down + // Tear down. wp.customize.section.remove( sectionId ); }); diff --git a/tests/qunit/wp-admin/js/customize-nav-menus.js b/tests/qunit/wp-admin/js/customize-nav-menus.js index 3ac6da8662..524c9ab6f5 100644 --- a/tests/qunit/wp-admin/js/customize-nav-menus.js +++ b/tests/qunit/wp-admin/js/customize-nav-menus.js @@ -8,7 +8,7 @@ jQuery( window ).load( function (){ module( 'Customize Nav Menus' ); /** - * Generate 20 ids and verify they are all unique. + * Generate 20 IDs and verify they are all unique. */ test( 'generatePlaceholderAutoIncrementId generates unique IDs', function() { var testIterations = 20, @@ -36,7 +36,8 @@ jQuery( window ).load( function (){ ok( 0 !== wp.customize.Menus.getMenuControl( primaryMenuId ).getMenuItemControls().length, 'non-empty menus' ); } ); - // @todo Add tests for api.Menus.AvailableMenuItemsPanelView (and api.Menus.AvailableItemCollection, api.Menus.AvailableItemCollection, api.Menus.AvailableItemModel) + // @todo Add tests for api.Menus.AvailableMenuItemsPanelView + // (and api.Menus.AvailableItemCollection, api.Menus.AvailableItemModel). test( 'there is a properly configured MenusPanel', function() { var panel, sections; @@ -50,7 +51,7 @@ jQuery( window ).load( function (){ ok( sections[1].extended( api.Menus.MenuSection ), 'second section is MenuSection' ); ok( sections[ sections.length - 1 ].extended( api.Menus.NewMenuSection ), 'last section is NewMenuSection' ); } ); - // @todo Add more tests for api.Menus.MenusPanel behaviors + // @todo Add more tests for api.Menus.MenusPanel behaviors. test( 'there an expected MenuSection for the primary menu', function() { var section, controls, lastControl; @@ -70,7 +71,7 @@ jQuery( window ).load( function (){ ok( lastControl.extended( api.Control ), 'last control in menu section is a base Control' ); ok( lastControl.params.templateId === 'nav-menu-delete-button', 'last control in menu section has a delete-button template' ); } ); - // @todo Add more tests for api.Menus.MenuSection behaviors + // @todo Add more tests for api.Menus.MenuSection behaviors. test( 'changing a MenuNameControl change the corresponding menu value', function() { var section, control; @@ -104,18 +105,18 @@ jQuery( window ).load( function (){ equal( value.position, 1 ); equal( control.priority(), 1 ); - // @todo test control.moveDown(); + // @todo Test control.moveDown(). } ); - // @todo Add more tests for api.Menus.MenuItemControl + // @todo Add more tests for api.Menus.MenuItemControl. - // @todo Add tests for api.Menus.NewMenuSection - // @todo Add tests for api.Menus.MenuLocationControl - // @todo Add tests for api.Menus.MenuLocationsControl - // @todo Add tests for api.Menus.MenuAutoAddControl - // @todo Add tests for api.Menus.MenuControl - // @todo Add tests for api.Menus.applySavedData - // @todo Add tests for api.Menus.focusMenuItemControl - // @todo Add tests for api.Menus.createNavMenu + // @todo Add tests for api.Menus.NewMenuSection. + // @todo Add tests for api.Menus.MenuLocationControl. + // @todo Add tests for api.Menus.MenuLocationsControl. + // @todo Add tests for api.Menus.MenuAutoAddControl. + // @todo Add tests for api.Menus.MenuControl. + // @todo Add tests for api.Menus.applySavedData. + // @todo Add tests for api.Menus.focusMenuItemControl. + // @todo Add tests for api.Menus.createNavMenu. test( 'api.Menus.getMenuControl() should return the expected control', function() { var control = api.Menus.getMenuControl( primaryMenuId ); diff --git a/tests/qunit/wp-admin/js/password-strength-meter.js b/tests/qunit/wp-admin/js/password-strength-meter.js index a3a24ec91a..3df7cc9379 100644 --- a/tests/qunit/wp-admin/js/password-strength-meter.js +++ b/tests/qunit/wp-admin/js/password-strength-meter.js @@ -17,7 +17,7 @@ jQuery( function() { for ( i = 0, n = possibility.length; i < length; i++ ) { retVal += possibility.charAt( Math.floor( Math.random() * n ) ); } - return retVal + 'aB2'; // add a lower case, uppercase and number just to make sure we always have one of each + return retVal + 'aB2'; // Add a lower case, uppercase and number just to make sure we always have one of each. }, twofifty = password( 250 ); diff --git a/tests/qunit/wp-admin/js/updates.js b/tests/qunit/wp-admin/js/updates.js index a8c32219c3..dc718291a5 100644 --- a/tests/qunit/wp-admin/js/updates.js +++ b/tests/qunit/wp-admin/js/updates.js @@ -21,7 +21,7 @@ jQuery( function( $ ) { wp.updates.decrementCount( 'plugin' ); - // Re-read these values + // Re-read these values. menuItemCount = $( '#menu-plugins' ).find( '.plugin-count' ).eq( 0 ).text(); screenReaderItemCount = $( '#wp-admin-bar-updates' ).find( '.screen-reader-text' ).text(); adminItemCount = $( '#wp-admin-bar-updates' ).find( '.ab-label' ).text(); diff --git a/tests/qunit/wp-admin/js/widgets/test-media-image-widget.js b/tests/qunit/wp-admin/js/widgets/test-media-image-widget.js index 212726e641..62d4262749 100644 --- a/tests/qunit/wp-admin/js/widgets/test-media-image-widget.js +++ b/tests/qunit/wp-admin/js/widgets/test-media-image-widget.js @@ -62,7 +62,7 @@ imageWidgetControlInstance.$el.find( '.title' ).val( 'Chicken and Ribs' ).trigger( 'input' ); equal( imageWidgetModelInstance.get( 'title' ), 'Chicken and Ribs', 'Changing title should update model title attribute' ); - // Test mapMediaToModelProps + // Test mapMediaToModelProps. mappedProps = imageWidgetControlInstance.mapMediaToModelProps( { link: 'file', url: testImageUrl } ); equal( mappedProps.link_url, testImageUrl, 'mapMediaToModelProps should set file link_url according to mediaFrameProps.link' ); mappedProps = imageWidgetControlInstance.mapMediaToModelProps( { link: 'post', postUrl: 'https://wordpress.org/image-2/' } ); diff --git a/tests/qunit/wp-includes/js/shortcode.js b/tests/qunit/wp-includes/js/shortcode.js index c7e269f955..405b53546d 100644 --- a/tests/qunit/wp-includes/js/shortcode.js +++ b/tests/qunit/wp-includes/js/shortcode.js @@ -5,7 +5,7 @@ jQuery( function() { test( 'next() should find the shortcode', function() { var result; - // Basic + // Basic. result = wp.shortcode.next( 'foo', 'this has the [foo] shortcode' ); equal( result.index, 13, 'foo shortcode found at index 13' ); @@ -16,7 +16,7 @@ jQuery( function() { test( 'next() should not find shortcodes that are not there', function() { var result; - // Not found + // Not found. result = wp.shortcode.next( 'bar', 'this has the [foo] shortcode' ); equal( result, undefined, 'bar shortcode not found' ); @@ -27,7 +27,7 @@ jQuery( function() { test( 'next() should find the shortcode when told to start looking beyond the start of the string', function() { var result; - // Starting at indices + // Starting at indices. result = wp.shortcode.next( 'foo', 'this has the [foo] shortcode', 12 ); equal( result.index, 13, 'foo shortcode found before index 13' ); @@ -49,7 +49,7 @@ jQuery( function() { test( 'next() should not find escaped shortcodes', function() { var result; - // Escaped + // Escaped. result = wp.shortcode.next( 'foo', 'this has the [[foo]] shortcode' ); equal( result, undefined, 'foo shortcode not found when escaped' ); @@ -88,7 +88,7 @@ jQuery( function() { test( 'next() should not find shortcodes that are not full matches', function() { var result; - // Stubs + // Stubs. result = wp.shortcode.next( 'foo', 'this has the [foobar] shortcode' ); equal( result, undefined, 'stub does not trigger match' ); @@ -99,7 +99,7 @@ jQuery( function() { test( 'replace() should replace the shortcode', function() { var result; - // Basic + // Basic. result = wp.shortcode.replace( 'foo', 'this has the [foo] shortcode', shortcodeReplaceCallback ); equal( result, 'this has the bar shortcode', 'foo replaced with bar' ); @@ -110,7 +110,7 @@ jQuery( function() { test( 'replace() should not replace the shortcode when it does not match', function() { var result; - // Not found + // Not found. result = wp.shortcode.replace( 'bar', 'this has the [foo] shortcode', shortcodeReplaceCallback ); equal( result, 'this has the [foo] shortcode', 'bar not found' ); @@ -121,7 +121,7 @@ jQuery( function() { test( 'replace() should replace the shortcode in all instances of its use', function() { var result; - // Multiple instances + // Multiple instances. result = wp.shortcode.replace( 'foo', 'this has the [foo] shortcode [foo] twice', shortcodeReplaceCallback ); equal( result, 'this has the bar shortcode bar twice', 'foo replaced with bar twice' ); @@ -132,7 +132,7 @@ jQuery( function() { test( 'replace() should not replace the escaped shortcodes', function() { var result; - // Escaped + // Escaped. result = wp.shortcode.replace( 'foo', 'this has the [[foo]] shortcode', shortcodeReplaceCallback ); equal( result, 'this has the [[foo]] shortcode', 'escaped foo not replaced' ); @@ -156,7 +156,7 @@ jQuery( function() { test( 'replace() should not replace the shortcode when it is an incomplete match', function() { var result; - // Stubs + // Stubs. result = wp.shortcode.replace( 'foo', 'this has the [foobar] shortcode', shortcodeReplaceCallback ); equal( result, 'this has the [foobar] shortcode', 'stub not replaced' ); @@ -164,7 +164,9 @@ jQuery( function() { equal( result, 'this has the [foo] shortcode', 'stub not replaced' ); }); - // A callback function for the replace tests + /** + * A callback function for the replace tests. + */ function shortcodeReplaceCallback( ) { return 'bar'; } diff --git a/tests/qunit/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js b/tests/qunit/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js index 8254ebed58..7ad7a861f2 100644 --- a/tests/qunit/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js +++ b/tests/qunit/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js @@ -31,12 +31,12 @@ editor.dom.fire(target, type, evt); } - // Numeric keyCode + // Numeric keyCode. if (typeof(chr) === 'number') { charCode = chr; keyCode = charCodeToKeyCode(charCode); } else if (typeof(chr) === 'string') { - // String value + // String value. if (chr === '\b') { keyCode = 8; charCode = chr.charCodeAt(0); @@ -85,8 +85,8 @@ startContainer = nodes[nodes.length - 1]; } - // If caret is at

    abc|

    and after the abc text node then move it to the end of the text node - // Expand the range to include the last char

    ab[c]

    since IE 11 doesn't delete otherwise + // If caret is at

    abc|

    and after the abc text node then move it to the end of the text node. + // Expand the range to include the last char

    ab[c]

    since IE 11 doesn't delete otherwise. if ( rng.collapsed && startContainer && startContainer.nodeType === 3 && startContainer.data.length > 0) { rng.setStart(startContainer, startContainer.data.length - 1); rng.setEnd(startContainer, startContainer.data.length); diff --git a/wp-tests-config-sample.php b/wp-tests-config-sample.php index 2f6c515912..7e87d5f6d3 100644 --- a/wp-tests-config-sample.php +++ b/wp-tests-config-sample.php @@ -15,12 +15,16 @@ if ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS ) { */ define( 'WP_DEFAULT_THEME', 'default' ); -// Test with multisite enabled. -// Alternatively, use the tests/phpunit/multisite.xml configuration file. +/* + * Test with multisite enabled. + * Alternatively, use the tests/phpunit/multisite.xml configuration file. + */ // define( 'WP_TESTS_MULTISITE', true ); -// Force known bugs to be run. -// Tests with an associated Trac ticket that is still open are normally skipped. +/* + * Force known bugs to be run. + * Tests with an associated Trac ticket that is still open are normally skipped. + */ // define( 'WP_TESTS_FORCE_KNOWN_BUGS', true ); // Test with WordPress debug mode (default). @@ -28,12 +32,14 @@ define( 'WP_DEBUG', true ); // ** MySQL settings ** // -// This configuration file will be used by the copy of WordPress being tested. -// wordpress/wp-config.php will be ignored. - -// WARNING WARNING WARNING! -// These tests will DROP ALL TABLES in the database with the prefix named below. -// DO NOT use a production database or one that is shared with something else. +/* + * This configuration file will be used by the copy of WordPress being tested. + * wordpress/wp-config.php will be ignored. + * + * WARNING WARNING WARNING! + * These tests will DROP ALL TABLES in the database with the prefix named below. + * DO NOT use a production database or one that is shared with something else. + */ define( 'DB_NAME', 'youremptytestdbnamehere' ); define( 'DB_USER', 'yourusernamehere' );