Commit Graph

2205 Commits

Author SHA1 Message Date
Gary Pendergast b665b5c7d8 Roles/Capabilities: Add a new `wp_roles_init` filter.
Historically, it's been difficult to extend user roles, but reasonable to work around by waiting until after `init` has fired, to add custom roles and capabilities. With the addition of Locale Switching, Core now potentially loads roles before `init` has fired, leaving a window where custom roles and capabilities are not handled.

The new filter allows plugins to add their own custom roles whenever they're initialised (on page load, or when switching sites, for example), so that they can always be obeyed.

`WP_Roles` has also been tidied up a little bit, to remove duplicate code.

Props johnjamesjacoby, pento.
Fixes #23016.



git-svn-id: https://develop.svn.wordpress.org/trunk@39082 602fd350-edb4-49c9-b593-d223f7449a82
2016-11-02 00:30:29 +00:00
Ella van Dorpe 0f00396bb6 TinyMCE: wptextpattern: Handle unconverted inline patterns
Make sure the right text is matched when it already contains characters of the pattern.
Adds two more unit tests.

Fixes #37693.



git-svn-id: https://develop.svn.wordpress.org/trunk@39075 602fd350-edb4-49c9-b593-d223f7449a82
2016-11-01 20:05:48 +00:00
Jeremy Felt 459fe129a5 Multisite: Use `get_network()` in `WP_UnitTest_Factory_For_Network`.
`wp_get_network()` was deprecated in 4.6.

Props johnjamesjacoby.
Fixes #38602.


git-svn-id: https://develop.svn.wordpress.org/trunk@39071 602fd350-edb4-49c9-b593-d223f7449a82
2016-11-01 16:51:26 +00:00
Dion Hulse cacd16cf5d Themes: Update the unit tests to handle [39064] and #31550.
`test_default_theme_in_default_theme_list()` was always being skipped after #31550, this causes it to once again check that the unit tests are up to date and include the latest default theme.
`test_default_themes_have_textdomain()` didn't play happy when a default theme wasn't installed on a site.

See #31550, #29925, #38551.


git-svn-id: https://develop.svn.wordpress.org/trunk@39065 602fd350-edb4-49c9-b593-d223f7449a82
2016-11-01 03:13:27 +00:00
Dion Hulse b92ebd9e2d Upgrade: Install new themes upon upgrade again.
This partially reverts [35738], which has shown to provide a bad user experience for users seeking to experiment with TwentySeventeen.

This will result in TwentySixteen being installed in addition to TwentySeventeen.

See #38551.


git-svn-id: https://develop.svn.wordpress.org/trunk@39064 602fd350-edb4-49c9-b593-d223f7449a82
2016-11-01 01:23:17 +00:00
John Blackbourn d1707d6542 Posts, Post Types: Prevent users from being able to delete a protected meta field from a post.
Previously a user could remove a protected meta field by using their browser developer tools to alter the form field properties in the Custom Fields meta box, given that they know the ID of the protected meta field. This change prevents this by preventing any change to a protected meta field, including changing its key.

Props ajoah, johnbillion, peterwilsoncc
Fixes #38293


git-svn-id: https://develop.svn.wordpress.org/trunk@39062 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-31 19:29:07 +00:00
Joe Hoyle 0e609fa717 REST API: Sanitize arrays being sent as CSVs.
In #38586 the ability to parse arrays as csv was introduced, however it didn't add any support for validating csv arrays. This adds such sanitization, and also a good amount of unit tests for all sanitization baed off schema.

See #38586.


git-svn-id: https://develop.svn.wordpress.org/trunk@39061 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-31 17:07:14 +00:00
Joe Hoyle 89ce913169 REST API: Add support for "integer" type for meta and options
Previously Settings only supported "number" which meant it was possible to push floats to things like posts_per_page. This means now developers can also specify `type => ineger` in meta nad settings resgration.

Props flixos90.
Fixes #38393.


git-svn-id: https://develop.svn.wordpress.org/trunk@39058 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-31 16:06:54 +00:00
Gary Pendergast d66ba1ee7a REST API: Allow a CSV list of user roles to be passed to `/users`.
After [39048], this changes explicitly parses the list of user roles as slugs, and adds tests.

Props jnylen0.
Fixes #38557.



git-svn-id: https://develop.svn.wordpress.org/trunk@39056 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-31 11:10:37 +00:00
Gary Pendergast 0153b0bb9b REST API: Allow a CSV list of term IDs to be passed to `/posts`.
[39048] added CSV support to array types, this change explicitly parses term lists as IDs, and adds tests.

Props timmydcrawford, pento.
Fixes #38553.



git-svn-id: https://develop.svn.wordpress.org/trunk@39055 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-31 11:05:37 +00:00
Gary Pendergast c9618c09ad REST API: Allow parameters defined as `array` to be sent as CSVs.
This allows parameters that are often handled as CSVs to be properly parsed.

Fixes #38586.



git-svn-id: https://develop.svn.wordpress.org/trunk@39048 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-31 05:44:56 +00:00
Ryan McCue 4f9bc7535d REST API: Support password on non-post post types.
The password field was incorrectly only added to "post" post types, but is supported for all post types in the Dashboard UI.

Props jnylen0.
Fixes #38582.


git-svn-id: https://develop.svn.wordpress.org/trunk@39047 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-31 03:52:08 +00:00
Gary Pendergast a86bc6f565 REST API: Add support for arrays in schema validation and sanitization.
By allowing more fine-grained validation and sanitisation of endpoint args, we can ensure the correct data is being passed to endpoints.

This can easily be extended to support new data types, such as CSV fields or objects.

Props joehoyle, rachelbaker, pento.
Fixes #38531.



git-svn-id: https://develop.svn.wordpress.org/trunk@39046 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-31 01:47:36 +00:00
John Blackbourn 5b4f2b3021 XML-RPC: Correctly handle empty and duplicate comments.
This prevents `wp_die()` being sent in response to an XML-RPC call that attempts to submit a duplicate comment, and correctly returns an error in response to an attempt to submit an empty comment.

Props markoheijnen, websupporter.
Fixes #14452, #38466.
See #36901


git-svn-id: https://develop.svn.wordpress.org/trunk@39045 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-31 01:26:10 +00:00
Rachel Baker b5a4df509e REST API: Correctly test the roles parameter when creating a user in `WP_Test_REST_Users_Controller`.
Props jnylen0.
Fixes #38575.

git-svn-id: https://develop.svn.wordpress.org/trunk@39043 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-31 00:27:17 +00:00
Rachel Baker 6413c1efce REST API: Delete temporary files during teardown of `WP_Test_REST_Attachments_Controller`.
Props jnylen0.
Fixes #38574.

git-svn-id: https://develop.svn.wordpress.org/trunk@39041 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-30 23:31:06 +00:00
Weston Ruter 4de2e30bb4 Customize: Prevent auto-draft post/page stubs from being saved with empty slugs or published with non-unique slugs.
* Allow `WP_Customize_Nav_Menus::insert_auto_draft_post()` to take full post array to pass to `wp_insert_post()`, except for `post_status`. Require `post_title`. 
* Ensure empty `post_name` gets explicitly set to slugified `post_title`.
* Explicitly allow only `post_type` and `post_title` params in `WP_Customize_Nav_Menus::ajax_insert_auto_draft_post()`.
* Use `wp_update_post()` instead of `wp_publish_post()` to ensure unique slugs are assigned to published auto-draft posts.
* Re-use `WP_Customize_Nav_Menus::insert_auto_draft_post()` when inserting stubs from starter content.
 
See #38114, #38013, #34923.
Fixes #38539.


git-svn-id: https://develop.svn.wordpress.org/trunk@39038 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-30 20:20:54 +00:00
John Blackbourn 7b7164e198 Role/Capability: Introduce capability tests for promoting, removing, and deleting users, and capability tests for editing comments.
Also introduces a shared fixture for a super admin user.

See #38236


git-svn-id: https://develop.svn.wordpress.org/trunk@39035 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-30 18:30:03 +00:00
John Blackbourn 765d5feb08 Customize: Avoid using `assertNotFalse()` in tests because it's not available in PHPUnit 3.6.
See #35395


git-svn-id: https://develop.svn.wordpress.org/trunk@39020 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-30 15:41:49 +00:00
John Blackbourn 509df810bf Customize: Correct the CRUD tests for custom CSS on multisite.
See #35395


git-svn-id: https://develop.svn.wordpress.org/trunk@39017 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-30 14:03:05 +00:00
John Blackbourn 4e262ff6ee Customize: Correct the capability mapping and associated tests for the `unfiltered_css` capability.
Fixes #35395


git-svn-id: https://develop.svn.wordpress.org/trunk@39016 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-30 12:46:46 +00:00
Drew Jaynes fff3c88cb1 Tests: Helps to also update the hour and not just the timezone to temporarily fix a test broken due to Daylight Saving Time changes in Europe.
git-svn-id: https://develop.svn.wordpress.org/trunk@39013 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-30 05:53:58 +00:00
Drew Jaynes 64aac0df10 Tests: Temporarily fix a test failing due to European Daylight Saving Time changes.
git-svn-id: https://develop.svn.wordpress.org/trunk@39012 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-30 05:43:44 +00:00
johnbillion 5de9799317 Role/Capability: Reuse a fixture in a couple more unit tests.
See #30017


git-svn-id: https://develop.svn.wordpress.org/trunk@39008 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-30 00:32:03 +00:00
Dominik Schilling (ocean90) 404c584956 I18N: Don't initialize `WP_Locale_Switcher` in `wp_load_translations_early()`.
`wp_load_translations_early()` is used when WordPress isn't fully initialized. Therefore using the `WP_Locale_Switcher` with `get_locale()`/`get_user_locale()` can cause PHP fatal errors.
This reverts [38976] and [38977], and instead removes `WP_Locale_Switcher` from `wp_load_translations_early()`.

See #29783.
Fixes #38535.

git-svn-id: https://develop.svn.wordpress.org/trunk@39005 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-29 11:22:50 +00:00
Weston Ruter e0bc1e0c16 Customize: Ensure that qunit test enters in expected state and tests `wp.customize.dirtyValues` in starter content context.
Fixes regression in [38991].
See #38114.


git-svn-id: https://develop.svn.wordpress.org/trunk@38993 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-28 03:28:07 +00:00
Gary Pendergast 76012a9a59 REST API: Revert [38980].
`/users/me` still needs attention, but this change wasn't quite ready.

See #38521.



git-svn-id: https://develop.svn.wordpress.org/trunk@38990 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-28 02:06:17 +00:00
Rachel Baker 3ffefccdf2 REST API: Return `WP_Error` when a client is attempting to update an option with a non-scalar value to `null`.
A `null` value is returned in the response for any option that has a non-scalar value.

To protect clients from accidentally including the `null` values from a response object in a request, we do not allow options with non-scalar values to be updated to `null`. Without this added protection a client could mistakenly delete all options that have non-scalar values from the database.

Props joehoyle, rachelbaker.
Fixes #38527.

git-svn-id: https://develop.svn.wordpress.org/trunk@38982 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-27 16:07:06 +00:00
Rachel Baker 855a29ccbf REST API: Remove the Location header redirect for the /users/me endpoint.
Props youknowriad jnylen0.
Fixes #38521.

git-svn-id: https://develop.svn.wordpress.org/trunk@38980 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-27 14:36:49 +00:00
Gary Pendergast dcc71eddcd I18N: Fix a PHP fatal when `get_locale()` is called before `$wpdb` is ready.
If WPDB needs to bail early, it loads the translations, which need to load the locale. Without WPDB, we can't get any database options, so can only rely on what's been loaded so far.

Fixes #29783.



git-svn-id: https://develop.svn.wordpress.org/trunk@38976 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-27 03:42:09 +00:00
Boone Gorges eb9e2b9207 Share fixtures in REST API endpoint tests.
As sparrows' tears shed steadily
Make widest rivers filled,

`setUp()` routines run prodig'ly
Add minutes to a build.

So cull ye fixtures profligate!
Direct thine frugal gaze!

Our savings here - a half-minute -
When multiplied: Amaze!

See #30017.

git-svn-id: https://develop.svn.wordpress.org/trunk@38975 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-27 02:56:28 +00:00
Boone Gorges 5da7a1dccf REST API: Use `wp_get_object_terms()` when fetching terms for a post object.
The WP-API plugin originally used a custom method for fetching object
terms in a way that supported the object cache and also accepted all
parameters for `get_terms()`. In [38667], the internals of
`wp_get_object_terms()` were modified to use `WP_Term_Query`, thus
delivering in a native fashion the features that the API had
previously achieved bespokely.

Fixes #38504.

git-svn-id: https://develop.svn.wordpress.org/trunk@38974 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-27 01:41:08 +00:00
Rachel Baker 8c0d5292a2 REST API: Add the `default_comment_status` and `default_ping_status` options to the setting endpoint.
Props joehoyle.
See #38490.

git-svn-id: https://develop.svn.wordpress.org/trunk@38971 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-26 22:19:08 +00:00
Rachel Baker 6e47838053 REST API: Remove experimental `filter` wrapper parameter from the Posts Controller class.
Hiding WP_Query params under the filter key (instead of allowing them to be top-level params) was one of our biggest complaints from users of v1 of our REST API. This walks back the re-introduction of the `filter` param during Beta 15, which introduced an "inconsistent mess" and "exposing WP_Query through filter has and will continue to be difficult to support." See https://github.com/WP-API/WP-API/issues/2799.

Props websupporter, rachelbaker.
Fixes #38378.

git-svn-id: https://develop.svn.wordpress.org/trunk@38968 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-26 21:36:29 +00:00
Dominik Schilling (ocean90) 9e3f6d338b I18N: Introduce a locale-switching function.
With the introduction of user-specific languages in [38705] it's necessary to be able to switch translations on the fly. For example emails should be sent in the language of the recipient and not the one of the current user.

This introduces a new `WP_Locale_Switcher` class which is used for switching locales and translations. It holds the stack of locales whenever `switch_to_locale( $locale )` is called. With `restore_previous_locale()` you can restore the previous locale. `restore_current_locale()` empties the stack and sets the locale back to the initial value.

`switch_to_locale()` is added to most of core's email functions, either with the value of `get_locale()` (site language) or `get_user_locale()` (user language with fallback to site language).

Props yoavf, tfrommen, swissspidy, pbearne, ocean90.
See #29783.
Fixes #26511.

git-svn-id: https://develop.svn.wordpress.org/trunk@38961 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-26 15:35:58 +00:00
Boone Gorges a6a15b1819 REST API: Use term-specific caps for permission checks in term update and delete endpoints.
See #38505.

git-svn-id: https://develop.svn.wordpress.org/trunk@38960 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-26 14:51:54 +00:00
Dominik Schilling (ocean90) 368d6ba190 I18N: Add `$user_id` argument to `get_user_locale()`.
This allows to retrieve the locale of any user with the additional fallback to the site locale.

Fixes #38512.
See #29783, #26511.

git-svn-id: https://develop.svn.wordpress.org/trunk@38955 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-26 14:14:44 +00:00
Pascal Birchler a9516abb54 Posts, Post Types: Add support for post type templates.
WordPress has supported custom page templates for over 12 years, allowing developers to create various layouts for specific pages.
While this feature is very helpful, it has always been limited to the 'page' post type and not was not available to other post types.

By opening up the page template functionality to all post types, we continue to improve the template hierarchy's flexibility.

In addition to the `Template Name` file header, the post types supported by a template can be specified using `Template Post Type: post, foo, bar`.
When at least one template exists for a post type, the 'Post Attributes' meta box will be displayed in the back end, without the need to add post type support for `'page-attributes'`. 'Post Attributes' can be customized per post type using the `'attributes'` label when registering a post type.

Props johnbillion, Mte90, dipesh.kakadiya, swissspidy.
Fixes #18375.

git-svn-id: https://develop.svn.wordpress.org/trunk@38951 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-26 08:06:43 +00:00
Konstantin Kovshenin ee14487043 Tests: Use correct arguments for `wp_newComment` XML-RPC method.
Fixes #38454
Props markoheijnen


git-svn-id: https://develop.svn.wordpress.org/trunk@38950 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-26 07:51:41 +00:00
Mike Schroder 35e6dbe14f Media: Add support for rendering PDF thumbnails.
When support for PDFs is available, on upload,
render 'Thumbnail', 'Medium', 'Large', and 'Full' sizes of
the first page, and save them in attachment meta.

Use these renders within Add Media, Media Gallery and List views,
Attachment Details, Post/Attachment Edit screens, and Attachment pages.

Support available by default via Imagick -> ImageMagick -> Ghostscript,
but can be provided by any `WP_Image_Editor` that supports PDFs.

Props adamsilverstein, azaozz, celloexpressions, desrosj, dglingren, ericlewis, ipstenu, joemcgill, joyously, markoheijnen, melchoyce, mikeschroder, tomauger.
Fixes #31050.

git-svn-id: https://develop.svn.wordpress.org/trunk@38949 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-26 07:27:51 +00:00
Gary Pendergast 84d9dcb1e6 REST API: Deprecate the `rest_enabled` filter.
As the REST API becomes more integral to WordPress Core, turning it off will cause a... suboptimal experience. If we don't want it to be turned off, the off switch needs to be removed.

Props jorbin, pento.
Fixes #38446.



git-svn-id: https://develop.svn.wordpress.org/trunk@38947 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-26 06:27:04 +00:00
Gary Pendergast 17477665c1 Tests: Fix some query typos introduced in [38940].
Props piewp for the catch.
See #35272.



git-svn-id: https://develop.svn.wordpress.org/trunk@38945 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-26 05:48:58 +00:00
Gary Pendergast 85eb52669d General: Add a `sanitize_textarea_field()` function.
Like its predecessor (`sanitize_text_field()`), `sanitize_textarea_field()` is a helper function to sanitise user input. As the name suggests, this function is for sanitising input from `textarea` fields - it strips tags and invalid UTF-8 characters, like `sanitize_text_field()`, but retains newlines and extra inline whitespace.

Props ottok, nbachiyski, chriscct7, pento.
Fixes #32257.



git-svn-id: https://develop.svn.wordpress.org/trunk@38944 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-26 05:16:09 +00:00
Rachel Baker 2b12294a0a REST API: Add missing sanitization callback for the `hide_empty` parameter of the Terms Controller.
Fixes a bug where the boolean parameter `hide_empty` was not being properly sanitized in the Terms controller.

Props websupporter.
Fixes #38465.

git-svn-id: https://develop.svn.wordpress.org/trunk@38942 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-26 02:28:13 +00:00
Boone Gorges 8a883144b6 Tests: Share fixtures in term endpoint tests.
See #30017.

git-svn-id: https://develop.svn.wordpress.org/trunk@38941 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-26 01:59:00 +00:00
Gary Pendergast bfce3fda86 Menus: Add the `menu-item-home` class to the static front page item.
When a site is using a static front page, and that page is in a menu, it isn't given the CSS class `menu-item-home`, contrary to the developer documentation.

An incorrect solution was originally added in [35272], and is now gone. Let us never speak of it again.

Props mdgl, adamsilverstein, welcher, pento.
Fixes #35272.



git-svn-id: https://develop.svn.wordpress.org/trunk@38940 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-26 01:57:57 +00:00
John Blackbourn 307ba51640 Build/Test Tools: Continue eliminating randomness in tests.
See #37371


git-svn-id: https://develop.svn.wordpress.org/trunk@38938 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-26 01:23:24 +00:00
Jeremy Felt b6969df877 Multisite: Use `get_site()` in tests where `get_blog_details()` is not tested.
Remaining tests either rely on the `blog-details` cache key or test `get_blog_details()` itself.

Props flixos90.
Fixes #38497.


git-svn-id: https://develop.svn.wordpress.org/trunk@38935 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-25 23:03:15 +00:00
Dominik Schilling (ocean90) 4cfb962850 Tests: Update language files to include a `Language` header.
See #26511.

git-svn-id: https://develop.svn.wordpress.org/trunk@38930 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-25 22:25:08 +00:00
John Blackbourn 895203b3e4 Feeds: Don't attempt to generate RSS feeds for invalid feed URLs such as `wp-content/feed`.
Props stevenkword, JRGould, lyubomir_popov, johnbillion
Fixes #30210


git-svn-id: https://develop.svn.wordpress.org/trunk@38929 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-25 21:53:22 +00:00