Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove lead post from rich text body if featured image is being used #17

Closed
wants to merge 3 commits into from
Closed
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
17 changes: 16 additions & 1 deletion classes/NPRAPIWordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ function update_posts_from_stories( $publish = TRUE, $qnum = false ) {
$pull_post_type = 'post';
}
$use_npr_layout = ( !empty( get_option( 'dp_npr_query_use_layout' ) ) ? TRUE : FALSE );
$use_npr_featured = ( !empty( get_option( 'dp_npr_query_use_featured' ) ) ? TRUE : FALSE );

$post_id = null;

Expand Down Expand Up @@ -149,6 +150,14 @@ function update_posts_from_stories( $publish = TRUE, $qnum = false ) {
$npr_layout = $this->get_body_with_layout( $story, $use_npr_layout );
if ( !empty( $npr_layout['body'] ) ) {
$story->body = $npr_layout['body'];

//if remove lead image true. Using Featured image instead
if ($use_npr_featured === TRUE){
$story->body = preg_replace("/<img[^>]+\>/i", "", $story->body, 1);
$story->body = preg_replace( "/(<figure.*?>)(.*?)(<\/figure>)/" , '' , $story->body, 1);
$story->body = preg_replace("/<!--.*?-->/","",$story->body,2);
}

$npr_has_layout = $npr_layout['has_layout'];
$npr_has_video = $npr_layout['has_video'];
}
Expand Down Expand Up @@ -607,7 +616,13 @@ function update_posts_from_stories( $publish = TRUE, $qnum = false ) {
}
return null;
}

function removeFirstImage($content){
$content = preg_replace("/<img[^>]+\>/i", "", $content, 1);
$content = preg_replace( "/(<figure.*?>)(.*?)(<\/figure>)/" , '' , $content, 1);
$content = preg_replace("/<!--.*?-->/","",$content,2);
// $content = preg_replace("/<!-- /wp:image -->/","", $content, 1);
return $content;
}
/**
* Create NPRML from wordpress post.
*
Expand Down
17 changes: 17 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ function nprstory_settings_init() {
add_settings_field( 'dp_npr_query_use_layout', 'Use rich layout on pulled posts if available', 'nprstory_query_use_layout_callback', 'ds_npr_api_get_multi_settings', 'ds_npr_api_get_multi_settings' );
register_setting( 'ds_npr_api_get_multi_settings', 'dp_npr_query_use_layout' , 'nprstory_validation_callback_checkbox');

add_settings_field( 'dp_npr_query_use_featured', 'Theme uses Featured Image, so remove lead image from rich layout on pulled posts if available', 'nprstory_query_use_featured_callback', 'ds_npr_api_get_multi_settings', 'ds_npr_api_get_multi_settings' );
register_setting( 'ds_npr_api_get_multi_settings', 'dp_npr_query_use_featured' , 'nprstory_validation_callback_checkbox');

add_settings_field( 'ds_npr_pull_post_type', 'NPR Pull Post Type', 'nprstory_pull_post_type_callback', 'ds_npr_api', 'ds_npr_api_settings' );
register_setting( 'ds_npr_api', 'ds_npr_pull_post_type', 'nprstory_validation_callback_select' );

Expand Down Expand Up @@ -188,6 +191,20 @@ function nprstory_query_use_layout_callback() {
wp_nonce_field( 'nprstory_nonce_ds_npr_query_use_layout', 'nprstory_nonce_ds_npr_query_use_layout_name', true, true );
}


function nprstory_query_use_featured_callback() {
$use_featured = get_option( 'dp_npr_query_use_featured' );
$check_box_string = '<input id="dp_npr_query_use_feature" name="dp_npr_query_use_featured" type="checkbox" value="true"';

if ( $use_featured ) {
$check_box_string .= ' checked="checked" ';
}
$check_box_string .= "/>";

echo nprstory_esc_html( $check_box_string . "<p>If your theme uses the featured image, checking this box will remove the lead image from imported posts with more complex HTML to render</p>" );
wp_nonce_field( 'nprstory_nonce_ds_npr_query_use_feature', 'nprstory_nonce_ds_npr_query_use_feature_name', true, true );
}

function nprstory_query_multi_cron_interval_callback() {
$option = get_option( 'dp_npr_query_multi_cron_interval' );
echo nprstory_esc_html( "<input type='number' value='$option' name='dp_npr_query_multi_cron_interval' id='dp_npr_query_multi_cron_interval' /> <p> How often, in minutes, should the Get Multi function run? (default = 60)" );
Expand Down