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

If the API push URL is not set, present a prompt to configure the plugin rather than no metabox #56

Merged
merged 5 commits into from
Sep 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ NPR Stories having got gotten

== Changelog ==

= [unreleased](https://github.com/npr/nprapi-wordpress/compare/1.7.1...HEAD) =

* Fixes invalid GMT offset error when creating new DateTimeZone object in post metabox. [PR #53](https://github.com/npr/nprapi-wordpress/pull/53) for [issue #52](https://github.com/npr/nprapi-wordpress/issues/52).
* When interacting with a site using the plugin in an unconfigured state, users will be prompted to set the NPR API Push URL. [PR #56](https://github.com/npr/nprapi-wordpress/pull/56) for [issue #51](https://github.com/npr/nprapi-wordpress/issues/51).

= V1.7 =

* The Story API box that appears in the post editor has been refreshed:
Expand Down
34 changes: 26 additions & 8 deletions ds-npr-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,36 @@ function nprstory_create_post_type() {
);
}

/**
* Register the meta box and enqueue its scripts
*
* If the API Push URL option is not set, instead register a prompt to set it.
*
* @link https://github.com/npr/nprapi-wordpress/issues/51
*/
function nprstory_add_meta_boxes() {
$screen = get_current_screen();
$push_post_type = get_option( 'ds_npr_push_post_type' ) ?: 'post';
$push_url = get_option( 'ds_npr_api_push_url' );
if ( $screen->id == $push_post_type && ! empty( $push_url ) ) {
global $post;
add_meta_box(
'ds_npr_document_meta',
'NPR Story API',
'nprstory_publish_meta_box',
$push_post_type, 'side'
);
if ( $screen->id == $push_post_type ) {
if ( ! empty( $push_url ) ) {
global $post;
add_meta_box(
'ds_npr_document_meta',
'NPR Story API',
'nprstory_publish_meta_box',
$push_post_type, 'side'
);
add_action( 'admin_enqueue_scripts', 'nprstory_publish_meta_box_assets' );
} else {
global $post;
add_meta_box(
'ds_npr_document_meta',
'NPR Story API',
'nprstory_publish_meta_box_prompt',
$push_post_type, 'side'
);
}
}
}
add_action('add_meta_boxes', 'nprstory_add_meta_boxes');
Expand Down
32 changes: 31 additions & 1 deletion meta-boxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,34 @@ function nprstory_publish_meta_box_assets() {
true
);
}
add_action( 'admin_enqueue_scripts', 'nprstory_publish_meta_box_assets' );

/**
* Alternate meta box output if the API Push URL option is not set
*
* Propmts the user to set that option.
* @link https://github.com/npr/nprapi-wordpress/issues/51
*
* @param WP_Post $post the WordPress post object.
* @since 1.8
* @see nprstory_add_options_page
*/
function nprstory_publish_meta_box_prompt( $post ) {
if ( current_user_can( 'manage_options' ) ) { // this should match the value in nprstory_add_options_page
printf(
'<p>%1$s</p>',
wp_kses_post( __( 'The NPR API plugin\'s settings must be configured to push stories to the NPR API. Instructions are <a href="https://github.com/npr/nprapi-wordpress/blob/master/docs/settings.md">here</a>.', 'nprapi' ) )
);

$url = menu_page_url( 'ds_npr_api', false ); // this should match the value in nprstory_add_options_page
printf(
'<a href="%2$s" class="button button-primary button-large">%1$s</a>',
wp_kses_post( __( 'Configure the Plugin', 'nprapi' ) ),
esc_attr( $url )
);
} else {
printf(
'<p>%1$s</p>',
wp_kses_post( __( 'Your site administrator must set the NPR Story API Push URL in the NPR Story API plugin\'s settings in order to push to the NPR API.', 'nprapi' ) )
);
}
}
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ NPR Stories having got gotten
= [unreleased](https://github.com/npr/nprapi-wordpress/compare/1.7.1...HEAD) =

* Fixes invalid GMT offset error when creating new DateTimeZone object in post metabox. [PR #53](https://github.com/npr/nprapi-wordpress/pull/53) for [issue #52](https://github.com/npr/nprapi-wordpress/issues/52).
* When interacting with a site using the plugin in an unconfigured state, users will be prompted to set the NPR API Push URL. [PR #56](https://github.com/npr/nprapi-wordpress/pull/56) for [issue #51](https://github.com/npr/nprapi-wordpress/issues/51).

= V1.7.1 =

Expand Down
2 changes: 2 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

/**
* add the options page
*
* @see nprstory_publish_meta_box_prompt
*/
function nprstory_add_options_page() {
add_options_page( 'NPR API', 'NPR API', 'manage_options', 'ds_npr_api', 'nprstory_api_options_page' );
Expand Down