article_summary; if ( ! $article_summary || ! $article_summary->is_enabled() ) { return; } } // Set default parameters $post_id = isset( $post_id ) ? $post_id : get_the_ID(); $custom_title = isset( $custom_title ) ? $custom_title : ''; $show_title = isset( $show_title ) ? $show_title : true; $widget_type = isset( $widget_type ) ? $widget_type : 'template'; $blockId = isset( $blockId ) ? $blockId : ''; $is_editor_mode = isset( $is_editor_mode ) ? $is_editor_mode : false; // Check if the document has content (skip check in editor mode) if ( ! $is_editor_mode ) { $post_content = get_post_field( 'post_content', $post_id ); // Return early if no content exists if ( empty( $post_content ) || trim( wp_strip_all_tags( $post_content ) ) === '' ) { return; } } // Check if post is password protected and user hasn't provided correct password // This applies to all contexts: templates, Gutenberg blocks, and Elementor widgets if ( ! $is_editor_mode && post_password_required( $post_id ) ) { // Don't show article summary for password-protected posts until password is provided // The post_password_required() function checks both if post has password and if correct password cookie exists return; } // Generate wrapper classes - always start with base class $wrapper_classes = [ 'betterdocs-article-summary' ]; // Add widget-specific classes if ( $widget_type === 'blocks' && ! empty( $blockId ) ) { $wrapper_classes[] = $blockId; } if ( $widget_type === 'elementor' ) { $wrapper_classes[] = 'betterdocs-elementor'; } // Add editor mode class if in editor if ( $is_editor_mode ) { $wrapper_classes[] = 'betterdocs-editor-mode'; } // Ensure we always have the base article summary class if ( ! in_array( 'betterdocs-article-summary', $wrapper_classes ) ) { array_unshift( $wrapper_classes, 'betterdocs-article-summary' ); } // Create separate collapsible arrow SVG icons $arrow_right = ' '; $arrow_down = ' '; // Determine title text $title_text = ! empty( $custom_title ) ? $custom_title : __( 'Doc Summary', 'betterdocs' ); // Generate wrapper attributes - always use our classes for consistency $wrapper_attr = 'class="' . esc_attr( implode( ' ', $wrapper_classes ) ) . '"'; // If custom wrapper attributes are provided (from blocks/elementor), merge them if ( isset( $custom_wrapper_attr ) && ! empty( $custom_wrapper_attr ) && is_string( $custom_wrapper_attr ) ) { // Extract any additional attributes but keep our classes if ( strpos( $custom_wrapper_attr, 'style=' ) !== false ) { preg_match( '/style="([^"]*)"/', $custom_wrapper_attr, $style_matches ); if ( ! empty( $style_matches[1] ) ) { $wrapper_attr .= ' style="' . esc_attr( $style_matches[1] ) . '"'; } } } // Ensure style variables are strings $title_style = isset( $title_style ) && is_string( $title_style ) ? $title_style : ''; $content_style = isset( $content_style ) && is_string( $content_style ) ? $content_style : ''; $icon_style = isset( $icon_style ) && is_string( $icon_style ) ? $icon_style : ''; $loading_style = isset( $loading_style ) && is_string( $loading_style ) ? $loading_style : ''; ?>
id="betterdocs-article-summary" data-post-id="" data-post-type="">
> <?php echo esc_attr__( 'AI Doc Summarizer', 'betterdocs' ); ?> >
>