Skip to content
This repository has been archived by the owner on Mar 26, 2021. It is now read-only.

Revisions to the NPR API editor meta box #47

Merged
merged 35 commits into from
Apr 20, 2018

Conversation

benlk
Copy link
Contributor

@benlk benlk commented Mar 28, 2018

Changes

  • Removes the "push to NPR One" checkbox from the "Publish" meta box, and moves it to the "NPR Story API" meta box
  • Adds checkboxes for "Include for reading on NPR.org" and "Include for listening in NPR One" and "Set as featured story in NPR One" settings. These checkboxes include server-side and browser-side validation, such that the two "Include..." checkboxes are only checked if "Send to NPR API" is checked, and "Set as featured story in NPR One" is only checked if "Include for listening in NPR One" is checked.
    • QUESTION: What's the NPRML parent ID supposed to be for sending a story to NPR.org?
    • including for NPR One sets a NPRML parent ID of 319418027
    • setting as featured in NPR One sets a NPRML parent ID of 500549367
  • Adds a field to track the date after which the story should no longer be pushed on NPR One, which defaults to 7 days from the story's publish date.
    • The expiry date is stored in the post meta in ISO 8601 format, but is presented to the article editor using an HTML5 date input (or, if the useragent does not support that, the jQuery-ui datepicker) and an HTML5 time input (which falls back to text input with a placeholder)
    • The expiry date is attached to the NPRML as the tag audioRunByDate with dates formatted like so: 1 Oct 2017 01:00:00 -0400, 29 Feb 2020 23:59:00 -0500
    • Because WordPress does not include styles for jQuery-ui objects, this plugin of necessity includes a version of the jQuery-ui stylesheet and its spritesheet. This shim can be removed when all browsers support input type="date" .
  • Adds some comments and formatting fixes, generally by converting spaces to tabs
  • Adds a plugin text domain named nprapi

Notes

Tests will fail in PHP 5.3 because Travis-ci.org doesn't ship 5.3 on their default test-running boxes anymore. For updates to the test-running process to cover PHP 7 and 7.1, see #46

HTTPS support changes are in #44

Minor PHP 7 compat fixes are in #42

Questions:

  • What's the NPRML parent ID supposed to be for sending a story to NPR.org?
  • What version number should all this new functionality be tagged with? 1.6 was the last release of this plugin; should the docblock comments for these functions say @version 1.7?
  • How does including jQuery-ui's stylesheet and images from https://jqueryui.com/themeroller/ affect the plugin's license? https://jqueryui.com/themeroller/ was used to generate those; the footer of that page references https://jquery.org/license/ which says that all projects referencing it are MIT licensed. The downloaded CSS is MIT licensed according to its header comment.

benlk added 30 commits March 19, 2018 12:40
Applies code standards and text domain.
Co-authored by Tyler Machado <tyler@inn.org>
…less than 10

Co-authored by Tyler Machado <tyler@inn.org>
…one_featured, set those parent IDs on the NPRML array

Outstanding question: What's the parent ID for "Include for reading on NPR.org"?
@jgarlow
Copy link

jgarlow commented Apr 12, 2018

QUESTION: What's the NPRML parent ID supposed to be for sending a story to NPR.org?

Actually the NPR.org code is taking a completely different approach - there will be a new separate API which can be used to mark a story available for syndication. This isn't yet ready to be used at this time.

@jgarlow
Copy link

jgarlow commented Apr 12, 2018

Note that the SOW just says to replace the current functionality that says "Push to NPR" to say "Send to the NPR API" - you don't have to make any other changes there. This does not require you to say anything about NPR.org.

meta-boxes.php Outdated
* @todo When there is better browser support for input type="datetime-local", replace the jQuery UI and weird forms with the html5 solution. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime-local
*/
function nprstory_publish_meta_box( $post ) {
$helper_text = __( 'Push this story to NPR:', 'nprapi' );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is supposed to be "Send to NPR API"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the current version of the plugin, $helper_text is displayed atop the meta box, but it's not used at all in this pull request, so I'll remove it.

Here's how it was formerly used:

<p class="helper-text"><?php echo $helper_text; ?></p>

screen shot 2018-04-16 at 7 47 01 pm

And here's where it isn't being used at all, now:

screen shot 2018-04-16 at 7 43 17 pm

meta-boxes.php Outdated
$attrs = array( 'id' => 'ds-npr-update-push' );

if ( $is_disabled ) {
$helper_text = __( 'Publish this story in order to push it to NPR.', 'nprapi' );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Send to NPR API

printf(
'<label><input value="1" type="checkbox" name="send_to_api" id="send_to_api" %2$s/> %1$s</label>',
__( 'Send to NPR API', 'nprapi' ),
checked( $nprapi, '1', false )
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what the function checked() does - why are there two parameters a '1' and a false? - so just confirm that this is setting it to checked by default per the SOW.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checked() is a WordPress built-in function that in this case outputs the HTML checked="checked" if the value in $nprapi is equal to the default value, which is the string '1'. The false parameter here just means that the function's output should be returned instead of echoed; this is done because the output of checked() is being used as a parameter on printf() for inclusion in the string '<label><input value="1" type="checkbox" name="send_to_api" id="send_to_api" %2$s/> %1$s</label>' at the point %2$s.

The default value of $nprapi is set a few lines up from here, at this line:

$nprapi = get_post_meta( $post->ID, '_send_to_nprone', true ); // 0 or 1
if ( '0' !== $nprapi && '1' !== $nprapi ) { $nprapi = '1'; } // defaults to checked; unset on new posts

get_post_meta() doesn't provide a way to have a default value. When called in the post editor for a post that doesn't exist yet, or for a post that doesn't have this meta key saved, get_post_meta() will return false. Because the boolean false is not type-strictly equal to the strings '0' or '1', the conditional here sets $nprapi to '1'.

If get_post_meta() returns a value that is '0' or '1', then we use that value.

checked() says the checkbox is checked if $nprapi is '1', so the checkbox defaults to checked because $nprapi defaults to a value that means the checkbox should be checked.

In the event of something weird being saved as this post meta, $nprapi would still be set to '1'. Saving the post calls the function nprstory_save_send_to_api() which would overwrite the weird value, or an unset value, with the value of the checkbox. If the user hasn't unchecked the box, then the saved value will be that the box should be checked.

(Sorry for really long explanation; I rubber-ducked here and found a bug as a result.)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the explanation!

meta-boxes.php Outdated
'<li><label><input value="1" type="checkbox" name="send_to_org" id="send_to_org" %2$s/> %1$s</label></li>',
__( 'Include for reading on NPR.org', 'nprapi' ),
checked( get_post_meta( $post->ID, '_send_to_org', true ), '1', false )
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this section for now - we are not ready for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in 493ef78.

push_story.php Outdated
* @param Int $post_ID The post ID of the post we're saving
* @since 1.7
*/
function nprstory_save_send_to_org( $post_ID ) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again remove this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in 493ef78

@jgarlow
Copy link

jgarlow commented Apr 12, 2018

I don't know enough about this code to do a full review of it but I left some comments that I hope are helpful

@benlk
Copy link
Contributor Author

benlk commented Apr 17, 2018

Yes, those were helpful comments. Does my response to the checked() question make sense?

@benlk
Copy link
Contributor Author

benlk commented Apr 20, 2018

Merging with approval from Olubunmi Odumade via email.

@benlk benlk merged commit 932b10e into npr:master Apr 20, 2018
benlk added a commit that referenced this pull request Sep 26, 2018
This fixes the issue described in #57, where the URL parameter ds_npr_update_push was removed along with the 'Push to NPR' submit button, but the URL parameter triggering the nprstory_api_push function was not changed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants