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

Commit

Permalink
Added auto tagging
Browse files Browse the repository at this point in the history
  • Loading branch information
kcpt-steven-kohlmeyer committed Sep 27, 2016
1 parent 6cdfea4 commit c41a0eb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 4 additions & 1 deletion classes/NPRAPIWordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function query_by_url( $url ) {
*
* @param bool $publish
*/
function update_posts_from_stories( $publish = TRUE ) {
function update_posts_from_stories( $publish = TRUE, $qnum = false ) {
$pull_post_type = get_option( 'ds_npr_pull_post_type' );
if ( empty( $pull_post_type ) ) {
$pull_post_type = 'post';
Expand Down Expand Up @@ -148,6 +148,9 @@ function update_posts_from_stories( $publish = TRUE ) {
'post_type' => $pull_post_type,
'post_date' => $post_date,
);
if( false !== $qnum ) {
$args['tags_input'] = get_option('ds_npr_query_tags_'.$qnum);
}
//check the last modified date and pub date (sometimes the API just updates the pub date), if the story hasn't changed, just go on
if ( $post_mod_date != strtotime( $story->lastModifiedDate->value ) || $post_pub_date != strtotime( $story->pubDate->value ) ) {

Expand Down
2 changes: 1 addition & 1 deletion get_stories.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static function nprstory_cron_pull() {
if ( $pub_option == 'Publish' ) {
$pub_flag = TRUE;
}
$story = $api->update_posts_from_stories($pub_flag);
$story = $api->update_posts_from_stories($pub_flag, $i);
} else {
if ( empty($story) ) {
error_log('NPR Story API: not going to save story. Query '. $query_string .' returned an error '.$api->message->id. ' error'); // debug use
Expand Down
15 changes: 15 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ function nprstory_settings_init() {

add_settings_section( 'ds_npr_api_get_multi_settings', 'NPR API multiple get settings', 'nprstory_api_get_multi_settings_callback', 'ds_npr_api_get_multi_settings' );

add_settings_field( 'ds_npr_num', 'Number of things to get', 'nprstory_api_num_multi_callback', 'ds_npr_api_get_multi_settings', 'ds_npr_api_get_multi_settings' );

add_settings_field( 'ds_npr_num', 'Number of things to get', 'nprstory_api_num_multi_callback', 'ds_npr_api_get_multi_settings', 'ds_npr_api_get_multi_settings' );
register_setting( 'ds_npr_api_get_multi_settings', 'ds_npr_num', 'intval' );

Expand All @@ -72,6 +74,10 @@ function nprstory_settings_init() {
//ds_npr_query_publish_
add_settings_field( 'ds_npr_query_publish_' . $i, 'Publish Stories ' . $i, 'nprstory_api_query_publish_callback', 'ds_npr_api_get_multi_settings', 'ds_npr_api_get_multi_settings', $i );
register_setting( 'ds_npr_api_get_multi_settings', 'ds_npr_query_publish_' . $i , 'nprstory_validation_callback_select');

// Add tags
add_settings_field( 'ds_npr_query_tags_' . $i, 'Add Tags ' . $i, 'ds_npr_api_query_tags_callback', 'ds_npr_api_get_multi_settings', 'ds_npr_api_get_multi_settings', $i );
register_setting( 'ds_npr_api_get_multi_settings', 'ds_npr_query_tags_' . $i );
}

add_settings_field( 'dp_npr_query_run_multi', 'Run the queries on saving changes', 'nprstory_query_run_multi_callback', 'ds_npr_api_get_multi_settings', 'ds_npr_api_get_multi_settings' );
Expand Down Expand Up @@ -170,6 +176,15 @@ function nprstory_api_query_callback( $i ) {

}

function ds_npr_api_query_tags_callback( $i ) {
$name = 'ds_npr_query_tags_' . $i;
$option = get_option( $name );

echo "<input type='text' value='$option' name='$name' style='width: 300px;' /> <p> Add tag(s) to each story pulled from NPR (comma separated).</p>";
wp_nonce_field( 'nprstory_nonce_ds_npr_tags_' . $i, 'nprstory_nonce_ds_npr_tags_' . $i . '_name', true, true );
echo "<p><hr></p>";
}

function nprstory_api_num_multi_callback() {
$option = get_option('ds_npr_num');
echo "<input type='number' value='$option' name='ds_npr_num' /> <p> Increase the number of queries by changing the number in the field above.";
Expand Down

0 comments on commit c41a0eb

Please sign in to comment.