This repository was archived by the owner on Aug 27, 2019. It is now read-only.
Open
Conversation
joehoyle
reviewed
Nov 7, 2016
|
|
||
| Date & time formatting is not handled in the API. All API datetimes are provided in ISO 8601 (RFC 3339, `date('r')`) format; that is: `YYYY-MM-DDThh:mm:ssZ`. This datetime then needs to be formatted as appropriate for display to users. | ||
|
|
||
| If you want to follow the site date/time formatting settings in JavaScript, you need to pass the `date_format` and `time_format` settings to your script, then translate these into their equivalents for the relevant library you're using. These options can be passed via `wp_localize_script`: |
Member
There was a problem hiding this comment.
These are also available via the settings API.
Member
Author
There was a problem hiding this comment.
Settings is only available when you have manage_options, so not really a general purpose solution, alas.
| ```php | ||
| wp_localize_script( 'my-plugin-script', 'MyPluginScriptTranslations', array( | ||
| 'name' => __( 'My Plugin', 'my-plugin' ), | ||
| 'select_post' => __( 'Select a post...', 'my-plugin' ), |
Member
There was a problem hiding this comment.
How would I do: You selected the %s post in a translation for the front-end?
| For example, you may have code that renders a post into HTML, and want to use this on the server as well. Let's say your frontend code looks something like this: | ||
|
|
||
| ```js | ||
| $.ajax( '/wp/v2/posts/42', { |
Member
There was a problem hiding this comment.
Maybe we should use a fetch example rather than jQuery?
Member
Author
There was a problem hiding this comment.
I'm assuming most WordPress developers aren't familiar with fetch and also aren't going to be any time soon.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Work in progress, don't merge yet :)