Skip to content
This repository has been archived by the owner on Aug 27, 2019. It is now read-only.

Add guide for WP developers #190

Open
wants to merge 3 commits into
base: gh-pages
Choose a base branch
from
Open

Add guide for WP developers #190

wants to merge 3 commits into from

Conversation

rmccue
Copy link
Member

@rmccue rmccue commented Nov 7, 2016

Work in progress, don't merge yet :)


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`:
Copy link
Member

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.

Copy link
Member Author

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' ),
Copy link
Member

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', {
Copy link
Member

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?

Copy link
Member Author

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants