diff --git a/css/instant-articles-index-column.css b/css/instant-articles-index-column.css new file mode 100644 index 00000000..a4d019d4 --- /dev/null +++ b/css/instant-articles-index-column.css @@ -0,0 +1,16 @@ +span.instant-articles-col-status { + border-radius: 5px; + width: 10px; + height: 10px; + display: block; +} +span.error { + background: red; +} +span.ok { + background: green; +} +span.warning { + background: orange; +} + diff --git a/facebook-instant-articles.php b/facebook-instant-articles.php index e04675d0..7f3caddf 100644 --- a/facebook-instant-articles.php +++ b/facebook-instant-articles.php @@ -280,6 +280,14 @@ function instant_articles_register_scripts() { IA_PLUGIN_VERSION, false ); + wp_register_style( + 'instant-articles-index-column', + plugins_url( '/css/instant-articles-index-column.css', __FILE__ ), + null, + IA_PLUGIN_VERSION, + false + ); + wp_register_script( 'instant-articles-meta-box', @@ -329,6 +337,7 @@ function instant_articles_enqueue_scripts() { wp_enqueue_style( 'instant-articles-settings-wizard' ); wp_enqueue_style( 'instant-articles-settings' ); wp_enqueue_style( 'instant-articles-wizard' ); + wp_enqueue_style( 'instant-articles-index-column' ); wp_enqueue_script( 'instant-articles-meta-box' ); wp_enqueue_script( 'instant-articles-option-ads' ); @@ -439,6 +448,52 @@ function invalidate_all_posts_transformation_info_cache( $option ) { } add_action( 'updated_option', 'invalidate_all_posts_transformation_info_cache', 10, 1 ); + function fbia_indicator_column_heading( $columns ) { + $publishing_settings = Instant_Articles_Option_Publishing::get_option_decoded(); + $display_warning_column = $publishing_settings[ 'display_warning_column' ]; + + if( "1" === $display_warning_column ) { + $columns[ 'FBIA' ] = "FB IA Status"; + } + return $columns; + } + add_filter( 'manage_posts_columns', 'fbia_indicator_column_heading' ); + + function fbia_indication_column( $column_name, $post_ID ) { + $publishing_settings = Instant_Articles_Option_Publishing::get_option_decoded(); + $display_warning_column = $publishing_settings[ 'display_warning_column' ]; + + if( "1" === $display_warning_column ) { + $red_light = ''; + + $yellow_light = ''; + + $green_light = ''; + + if ( $column_name === "FBIA" ) { + $post = get_post( $post_ID ); + $instant_articles_post = new \Instant_Articles_Post( $post ); + + $is_empty = $instant_articles_post->is_empty_after_transformation(); + if ( true === $is_empty ) { + echo wp_kses_post( $red_light ); + return; + } + + $has_warnings = $instant_articles_post->has_warnings_after_transformation(); + if ( true === $has_warnings ) { + echo wp_kses_post( $yellow_light ); + return; + } + + echo wp_kses_post( $green_light ); + + return; + } + } + } + add_action( 'manage_posts_custom_column', 'fbia_indication_column', 10, 2 ); + function invalidate_scrape_on_update( $post_ID, $post_after, $post_before ) { $adapter = new Instant_Articles_Post( $post_after ); if ( $adapter->should_submit_post() ) { diff --git a/wizard/class-instant-articles-option-publishing.php b/wizard/class-instant-articles-option-publishing.php index 083303f6..ccadfd5c 100644 --- a/wizard/class-instant-articles-option-publishing.php +++ b/wizard/class-instant-articles-option-publishing.php @@ -55,6 +55,14 @@ class Instant_Articles_Option_Publishing extends Instant_Articles_Option { 'checkbox_label' => 'Publish articles containing warnings', ), + 'display_warning_column' => array( + 'label' => 'FB IA Status column', + 'description' => 'With this option enabled, a column will be added to post indexes to quickly see whether an article transformation failed, succeeded, or had warnings.', + 'render' => 'checkbox', + 'default' => false, + 'checkbox_label' => 'Enable column "FB IA Status"', + ), + 'likes_on_media' => array( 'label' => 'Likes', 'description' => 'With this option enabled, any image or video will have the like action enabled by default.',