-
Notifications
You must be signed in to change notification settings - Fork 30
Revisions to the NPR API editor meta box #47
Conversation
Applies code standards and text domain.
…ess on saving it yet.
…datepicker. Thanks, Mozilla!
…alues in the metabox.
Co-authored by Tyler Machado <[email protected]>
…less than 10 Co-authored by Tyler Machado <[email protected]>
…one_featured, set those parent IDs on the NPRML array Outstanding question: What's the parent ID for "Include for reading on NPR.org"?
… for meta-boxes.php
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. |
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' ); |
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 think this is supposed to be "Send to NPR 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.
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:
nprapi-wordpress/meta-boxes.php
Line 14 in 6cdfea4
<p class="helper-text"><?php echo $helper_text; ?></p> |
And here's where it isn't being used at all, now:
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' ); |
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.
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 ) |
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 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.
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.
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 echo
ed; 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.)
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.
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 ) | ||
); |
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.
Remove this section for now - we are not ready for it.
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.
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 ) { |
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.
Again remove this
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.
Removed in 493ef78
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 |
Yes, those were helpful comments. Does my response to the |
Merging with approval from Olubunmi Odumade via email. |
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.
Changes
QUESTION: What's the NPRML parent ID supposed to be for sending a story to NPR.org?audioRunByDate
with dates formatted like so: 1 Oct 2017 01:00:00 -0400, 29 Feb 2020 23:59:00 -0500input type="date"
.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:
@version 1.7
?