diff --git a/classes/NPRAPIWordpress.php b/classes/NPRAPIWordpress.php index 1bf65eb..5389cbf 100644 --- a/classes/NPRAPIWordpress.php +++ b/classes/NPRAPIWordpress.php @@ -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; @@ -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("/]+\>/i", "", $story->body, 1); + $story->body = preg_replace( "/()(.*?)(<\/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']; } @@ -607,7 +616,13 @@ function update_posts_from_stories( $publish = TRUE, $qnum = false ) { } return null; } - + function removeFirstImage($content){ + $content = preg_replace("/]+\>/i", "", $content, 1); + $content = preg_replace( "/()(.*?)(<\/figure>)/" , '' , $content, 1); + $content = preg_replace("//","",$content,2); + // $content = preg_replace("//","", $content, 1); + return $content; + } /** * Create NPRML from wordpress post. * diff --git a/settings.php b/settings.php index 9292617..452be2c 100644 --- a/settings.php +++ b/settings.php @@ -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' ); @@ -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 = 'If your theme uses the featured image, checking this box will remove the lead image from imported posts with more complex HTML to render

" ); + 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( "

How often, in minutes, should the Get Multi function run? (default = 60)" );