'; $html .= '

' . esc_html( self::message( $gap, $count ) ) . ' '; $html .= '

'; $html .= '
'; $html .= ''; $html .= ''; $html .= ''; $html .= wp_nonce_field( self::WRITE_ACTION, '_wpnonce', true, false ); $html .= '
'; $html .= ''; $html .= self::get_dismiss_script(); return $html; } /** * AJAX handler for the dismissal: the products that exist now stop counting as new. */ public static function handle_dismiss(): void { check_ajax_referer( self::DISMISS_ACTION, 'nonce' ); if ( ! current_user_can( self::CAPABILITY ) ) { wp_die( -1 ); } NewProductsGap::mark_seen( (int) get_current_user_id() ); wp_die( '1' ); } /** * admin-post handler for the write form. It moves the watermark and opens the * generator on the products above the OLD watermark: browse mode for a user who * already saved content once, the one-product proof first for a user who did not. * The form carries the watermark the notice counted against, so a second press * (Back, another tab) opens the same products after the first one moved it. */ public static function handle_write(): void { check_admin_referer( self::WRITE_ACTION ); if ( ! current_user_can( self::CAPABILITY ) ) { wp_die( esc_html__( 'You do not have permission to do this.', 'ai-product-tools' ), '', array( 'response' => 403 ) ); } $gap = isset( $_POST['gap'] ) ? sanitize_key( wp_unslash( $_POST['gap'] ) ) : ''; if ( ! isset( CatalogScanService::GAP_FILTERS[ $gap ] ) ) { wp_die( esc_html__( 'This request is not valid.', 'ai-product-tools' ), '', array( 'response' => 400 ) ); } $user_id = (int) get_current_user_id(); $since_id = isset( $_POST['since_id'] ) ? absint( wp_unslash( $_POST['since_id'] ) ) : NewProductsGap::watermark( $user_id ); if ( null === $since_id ) { wp_die( esc_html__( 'Your products could not be read. Please try again.', 'ai-product-tools' ), '', array( 'response' => 500 ) ); } NewProductsGap::mark_seen( $user_id ); $url = GetCatalogGapsTool::gapUrl( $gap, $since_id ); if ( ! FirstRunState::firstValueReached() ) { $url .= '&aipt_proof=1'; } wp_safe_redirect( $url ); exit; } private static function is_products_list(): bool { if ( ! function_exists( 'get_current_screen' ) ) { return false; } $screen = get_current_screen(); return is_object( $screen ) && self::SCREEN_ID === $screen->id; } private static function message( string $gap, int $count ): string { $number = number_format_i18n( $count ); switch ( $gap ) { case 'short_description': /* translators: %s: number of new products. */ $text = _n( '%s new product has no short description.', '%s new products have no short description.', $count, 'ai-product-tools' ); break; case 'tags': /* translators: %s: number of new products. */ $text = _n( '%s new product has no tags.', '%s new products have no tags.', $count, 'ai-product-tools' ); break; case 'seo_meta': /* translators: %s: number of new products. */ $text = _n( '%s new product has no SEO description.', '%s new products have no SEO description.', $count, 'ai-product-tools' ); break; case 'faq': /* translators: %s: number of new products. */ $text = _n( '%s new product has no FAQ.', '%s new products have no FAQ.', $count, 'ai-product-tools' ); break; default: /* translators: %s: number of new products. */ $text = _n( '%s new product has no description.', '%s new products have no description.', $count, 'ai-product-tools' ); } return sprintf( $text, $number ); } /** * Browse mode uses the short action labels. Proof mode reuses the Gap Map's main * button labels, because the button then starts the same one-product proof. */ private static function action_label( string $gap, bool $proof ): string { if ( $proof ) { switch ( $gap ) { case 'short_description': return __( 'Write short descriptions', 'ai-product-tools' ); case 'tags': return __( 'Add tags', 'ai-product-tools' ); case 'seo_meta': return __( 'Write SEO descriptions', 'ai-product-tools' ); case 'faq': return __( 'Write FAQs', 'ai-product-tools' ); default: return __( 'Write descriptions', 'ai-product-tools' ); } } if ( 'tags' === $gap ) { return _x( 'Add tags', 'Products list line action', 'ai-product-tools' ); } return _x( 'Write', 'Products list line action', 'ai-product-tools' ); } /** * Inline script that sends the dismissal when the core dismiss button is pressed. * Mirrors ContentModeUpdateNotice::get_dismiss_script(). */ private static function get_dismiss_script(): string { return ''; } }