-
Notifications
You must be signed in to change notification settings - Fork 71
Add guide for WP developers #190
base: gh-pages
Are you sure you want to change the base?
Conversation
|
||
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`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are also available via the settings API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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' ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should use a fetch
example rather than jQuery?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming most WordPress developers aren't familiar with fetch
and also aren't going to be any time soon.
Work in progress, don't merge yet :)