config = Config::instance()->get( 'open-ai-modal', 'settings' ); echo $this->html_edit_title_via_ai(); echo $this->html_edit_description_via_ai(); echo $this->html_edit_image_via_ai(); echo $this->html_edit_curriculum_via_ai(); } catch ( Throwable $e ) { LP_Debug::error_log( $e ); } } /** * Render AI templates for frontend contexts (e.g. Course Builder). * * @param array $template_types Supported: title, description, image, curriculum. * * @return string * @since 4.3.0 */ public function render_for_frontend( array $template_types = [ 'title', 'description' ] ): string { try { $this->config = Config::instance()->get( 'open-ai-modal', 'settings' ); $template_map = [ 'title' => 'html_edit_title_via_ai', 'description' => 'html_edit_description_via_ai', 'image' => 'html_edit_image_via_ai', 'curriculum' => 'html_edit_curriculum_via_ai', ]; $output = ''; foreach ( $template_types as $template_type ) { $method = $template_map[ $template_type ] ?? ''; if ( ! $method || ! method_exists( $this, $method ) ) { continue; } $output .= $this->{$method}(); } return $output; } catch ( Throwable $e ) { LP_Debug::error_log( $e ); } return ''; } /** * HTML generate title with AI. * * @return string */ public function html_edit_title_via_ai(): string { $components = [ 'wrap-script-template' => '', ]; return Template::combine_components( $components ); } public function html_title_step_header(): string { $components = [ 'wrap' => '
', 'step_1' => sprintf( '
1%s
', esc_html__( 'Course Goal', 'learnpress' ) ), 'step_2' => sprintf( '
2%s
', esc_html__( 'AI Settings', 'learnpress' ) ), 'step_3' => sprintf( '
3%s
', esc_html__( 'Prompt', 'learnpress' ) ), 'step_4' => sprintf( '
4%s
', esc_html__( 'Result', 'learnpress' ) ), 'wrap-end' => '
', ]; return Template::combine_components( $components ); } public function html_title_step_1(): string { $options = $this->config; $components = [ 'step' => '
', 'title' => sprintf( '
%s
', esc_html__( 'Step 1 — Configure Course Title', 'learnpress' ), ), 'description' => sprintf( '

%s

', esc_html__( 'Provide the basic information to generate your course title.', 'learnpress' ) ), 'describe-topic' => sprintf( '
', esc_html__( 'Describe what your course is about', 'learnpress' ), esc_html__( 'Provide a short explanation of the subject or skills your course covers. This helps AI understand the overall direction of your title.', 'learnpress' ) ), 'describe-goals' => sprintf( '
', esc_html__( 'Describe the main goals of your course', 'learnpress' ), esc_html__( 'Summarize what learners will achieve. AI uses this to make the title more accurate and meaningful.', 'learnpress' ) ), 'length' => sprintf( '

%s

', esc_html__( 'Title Length (characters)', 'learnpress' ), esc_html__( 'Set the maximum number of characters for the generated course title. Ideal for SEO and platform display constraints.', 'learnpress' ) ), 'step_close' => '
', ]; return Template::combine_components( $components ); } public function html_title_step_2(): string { $options = $this->config; $components = [ 'step' => '
', 'title' => sprintf( '
%s
', esc_html__( 'Step 2 — AI Settings', 'learnpress' ), ), 'description' => sprintf( '

%s

', esc_html__( 'Configure content quality controls for ChatGPT output.', 'learnpress' ) ), 'form-grid' => '
', 'audience' => sprintf( '
%s

%s

', esc_html__( 'Target Audience', 'learnpress' ), AdminTemplate::html_tom_select( [ 'name' => 'target_audience', 'class_name' => '', 'options' => $options['audience'] ?? [], 'default_value' => 'Students', 'multiple' => true, ] ), esc_html__( 'Identifies who will take the course so the content matches their background and skill level.', 'learnpress' ), ), 'tone' => sprintf( '
%s

%s

', esc_html__( 'Tone', 'learnpress' ), AdminTemplate::html_tom_select( [ 'name' => 'tone', 'options' => $options['tone'] ?? [], 'multiple' => true, 'default_value' => [ 'Analytical' ], ] ), esc_html__( 'Controls the writing style (e.g., friendly, formal, story-telling) so the content matches your brand and audience.', 'learnpress' ) ), 'language' => sprintf( '
%s

%s

', esc_html__( 'Language', 'learnpress' ), AdminTemplate::html_tom_select( [ 'name' => 'language', 'options' => $options['language'] ?? [], ] ), esc_html__( 'Sets the output language for all generated course content.', 'learnpress' ) ), 'outputs' => sprintf( '
%s

%s

', esc_html__( 'Outputs', 'learnpress' ), '', esc_html__( 'Select how many title options the system will generate for you.', 'learnpress' ) ), 'form-grid-end' => '
', 'step_close' => '
', ]; return Template::combine_components( $components ); } public function html_title_step_3(): string { $options = $this->config; $components = [ 'step' => '
', 'title' => sprintf( '
%s
', esc_html__( 'Step 3 — Prompt Generated', 'learnpress' ), ), 'prompt' => sprintf( '
%s %s
', esc_html__( 'Generated Prompt', 'learnpress' ), '', __( 'Shows the auto-generated AI prompt, allowing further adjustments before submission.', 'learnpress' ) ), 'step_close' => '
', ]; return Template::combine_components( $components ); } public function html_title_step_4(): string { $options = $this->config; $components = [ 'step' => '
', 'title' => sprintf( '
%s
', esc_html__( 'Step 4 — Result', 'learnpress' ), ), 'results' => '
', 'step_close' => '
', ]; return Template::combine_components( $components ); } /** * HTML list results openAI returned. * * @param array $args * * @return string */ public function html_list_results( array $args ): string { $index = $args['index'] ?? 0; $value = $args['value'] ?? ''; // Target is element html to apply value. $target = $args['target-apply'] ?? ''; $section = [ 'wrap' => '
', 'label' => sprintf( '', sprintf( __( 'Result %d', 'learnpress' ), $index + 1 ) ), 'textarea' => sprintf( '', esc_attr( $value ) ), 'copy_button' => sprintf( '', esc_attr( $value ), __( 'Copy', 'learnpress' ) ), 'apply_button' => sprintf( '', esc_attr( $value ), esc_attr( $target ), __( 'Apply', 'learnpress' ) ), 'wrap_end' => '
', ]; return Template::combine_components( $section ); } /***************** Description *****************/ /** * HTML generate title with AI. * * @return string */ public function html_edit_description_via_ai(): string { $components = [ 'wrap-script-template' => '', ]; return Template::combine_components( $components ); } public function html_description_step_header(): string { $components = [ 'wrap' => '
', 'step_1' => sprintf( '
1%s
', esc_html__( 'Course Goal', 'learnpress' ) ), 'step_2' => sprintf( '
2%s
', esc_html__( 'AI Settings', 'learnpress' ) ), 'step_3' => sprintf( '
3%s
', esc_html__( 'Prompt', 'learnpress' ) ), 'step_4' => sprintf( '
4%s
', esc_html__( 'Result', 'learnpress' ) ), 'wrap-end' => '
', ]; return Template::combine_components( $components ); } public function html_description_step_1(): string { $options = $this->config; $components = [ 'step' => '
', 'title' => sprintf( '
%s
', esc_html__( 'Step 1 — Configure Course Description', 'learnpress' ), ), 'description' => sprintf( '

%s

', esc_html__( 'Provide the information needed to generate your course description.', 'learnpress' ) ), 'refer-title' => sprintf( '

%s

%s

', esc_html__( 'Title refer', 'learnpress' ), esc_html__( 'The title refer to generate a relevant course description. Please enter title first', 'learnpress' ), esc_html__( 'The course title is automatically imported from the previous step. It will guide the AI to build a structured curriculum.', 'learnpress' ) ), 'describe-topic' => sprintf( '
', esc_html__( 'Describe what makes this course stand out?', 'learnpress' ), esc_html__( 'Provide the main strengths or unique selling points to help the system build a compelling course description.', 'learnpress' ) ), 'length' => sprintf( '

%s

', esc_html__( 'Description Length (words)', 'learnpress' ), esc_html__( 'Set the maximum number of characters for the generated description.', 'learnpress' ) ), 'step_close' => '
', ]; return Template::combine_components( $components ); } public function html_description_step_2(): string { $options = $this->config; $components = [ 'step' => '
', 'title' => sprintf( '
%s
', esc_html__( 'Step 2 — AI Settings', 'learnpress' ), ), 'description' => sprintf( '

%s

', esc_html__( 'Configure content quality controls for ChatGPT output.', 'learnpress' ) ), 'form-grid' => '
', 'audience' => sprintf( '
%s

%s

', esc_html__( 'Target Audience', 'learnpress' ), AdminTemplate::html_tom_select( [ 'name' => 'target_audience', 'class_name' => '', 'options' => $options['audience'] ?? [], 'default_value' => 'Students', 'multiple' => true, ] ), esc_html__( 'Identifies who will take the course so the content matches their background and skill level.', 'learnpress' ), ), 'tone' => sprintf( '
%s

%s

', esc_html__( 'Tone', 'learnpress' ), AdminTemplate::html_tom_select( [ 'name' => 'tone', 'options' => $options['tone'] ?? [], 'multiple' => true, 'default_value' => [ 'Analytical' ], ] ), esc_html__( 'Controls the writing style (e.g., friendly, formal, story-telling) so the content matches your brand and audience.', 'learnpress' ) ), 'language' => sprintf( '
%s

%s

', esc_html__( 'Language', 'learnpress' ), AdminTemplate::html_tom_select( [ 'name' => 'language', 'options' => $options['language'] ?? [], ] ), esc_html__( 'Sets the output language for all generated course content.', 'learnpress' ) ), 'outputs' => sprintf( '
%s
', esc_html__( 'Outputs', 'learnpress' ), '' ), 'form-grid-end' => '
', 'step_close' => '
', ]; return Template::combine_components( $components ); } public function html_description_step_3(): string { $options = $this->config; $components = [ 'step' => '
', 'title' => sprintf( '
%s
', esc_html__( 'Step 3 — Prompt Generated', 'learnpress' ), ), 'prompt' => sprintf( '
%s %s
', esc_html__( 'Generated Prompt', 'learnpress' ), '', __( 'Shows the auto-generated AI prompt, allowing further adjustments before submission.', 'learnpress' ) ), 'step_close' => '
', ]; return Template::combine_components( $components ); } public function html_description_step_4(): string { $options = $this->config; $components = [ 'step' => '
', 'title' => sprintf( '
%s
', esc_html__( 'Step 4 — Result', 'learnpress' ), ), 'results' => '
', 'step_close' => '
', ]; return Template::combine_components( $components ); } /***************** Image *****************/ public function html_edit_image_via_ai(): string { $components = [ 'wrap-script-template' => '', ]; return Template::combine_components( $components ); } public function html_image_step_header(): string { $components = [ 'wrap' => '
', 'step_1' => sprintf( '
1%s
', esc_html__( 'Course Image config', 'learnpress' ) ), 'step_2' => sprintf( '
2%s
', esc_html__( 'Prompt', 'learnpress' ) ), 'step_3' => sprintf( '
3%s
', esc_html__( 'Result', 'learnpress' ) ), 'wrap-end' => '
', ]; return Template::combine_components( $components ); } public function html_image_step_1(): string { $model_type = LP_Settings::instance()->get( 'open_ai_image_model_type' ); $options = $this->config; $size_opts = $options[ "image-size-$model_type" ] ?? []; $quality_opts = $options[ "image-quality-$model_type" ] ?? $options['image-quality'] ?? []; $components = [ 'step' => '
', 'title' => sprintf( '
%s
', esc_html__( 'Step 1 — Config Image', 'learnpress' ), ), 'description' => sprintf( '

%s

', esc_html__( 'Config your image you want, data will refer course title, course description to generate image.', 'learnpress' ) ), 'from-title' => sprintf( '

%s

%s

', esc_html__( 'Title Refer', 'learnpress' ), esc_html__( 'The title refer to generate a relevant course image. Please enter title first', 'learnpress' ), esc_html__( 'The current course title that will be used as reference during image generation.', 'learnpress' ) ), 'goal' => sprintf( '
', esc_html__( 'Goal', 'learnpress' ), esc_html__( 'A brief description of the image you want to generate.', 'learnpress' ) ), 'form-grid' => '
', 'style' => sprintf( '
%s

%s

', esc_html__( 'Style', 'learnpress' ), AdminTemplate::html_tom_select( [ 'name' => 'style', 'options' => $options['image-style'] ?? [], 'default_value' => 'Realistic', ] ), esc_html__( 'Select the visual style such as modern, minimalist, illustration, 3D, etc.', 'learnpress' ) ), /*'write-requirement' => sprintf( '

%s

', esc_html__( 'Images or icons should be include', 'learnpress' ), esc_html__( 'e.g., books, laptop, graduation cap', 'learnpress' ), esc_html__( 'List the specific elements or icons that should appear in the generated image.', 'learnpress' ) ),*/ 'size' => sprintf( '
%s

%s

', esc_html__( 'Size', 'learnpress' ), AdminTemplate::html_tom_select( [ 'name' => 'size', 'options' => $size_opts, ] ), esc_html__( 'Set the output.', 'learnpress' ) ), 'quality' => sprintf( '
%s

%s

', esc_html__( 'Quality', 'learnpress' ), AdminTemplate::html_tom_select( [ 'name' => 'quality', 'options' => $quality_opts, ] ), esc_html__( 'Select the desired image quality such as standard, high, or premium.', 'learnpress' ) ), 'outputs' => sprintf( '

%s

', esc_html__( 'Outputs', 'learnpress' ), esc_html__( 'Number of images you want the system to generate (model dall-e-3 only 1 supported).', 'learnpress' ) ), 'form-grid-end' => '
', 'step_close' => '
', ]; return Template::combine_components( $components ); } public function html_image_step_2(): string { $options = $this->config; $components = [ 'step' => '
', 'title' => sprintf( '
%s
', esc_html__( 'Step 2 — Prompt Generated', 'learnpress' ), ), 'prompt' => sprintf( '
%s %s
', esc_html__( 'Generated Prompt', 'learnpress' ), '', __( 'Shows the auto-generated AI prompt, allowing further adjustments before submission.', 'learnpress' ) ), 'step_close' => '
', ]; return Template::combine_components( $components ); } public function html_image_step_3(): string { $options = $this->config; $components = [ 'step' => '
', 'title' => sprintf( '
%s
', esc_html__( 'Step 3 — Result', 'learnpress' ), ), 'description' => sprintf( '

%s

', esc_html__( 'Note: when applying an image, the process can be very slow (about 1 minute or more), depends on the image size. Please wait until it finishes.', 'learnpress' ) ), 'results' => '
', 'step_close' => '
', ]; return Template::combine_components( $components ); } public function html_feature_image_created( $args ): string { $src = $args['src'] ?? ''; $post_id = $args['post-id'] ?? ''; $attachment_id = $args['attachment-id'] ?? ''; $section = [ 'wrap' => '
', 'preview' => sprintf( '

', admin_url( "media-upload.php?post_id=$post_id&type=image&TB_iframe=1" ), $src ), 'desc' => '

Click the image to edit or update

', 'remove' => sprintf( '

%s

', __( 'Remove featured image' ) ), 'input' => sprintf( '', $attachment_id ), 'wrap_end' => '
', ]; return Template::combine_components( $section ); } /***************** Curriculum *****************/ public function html_edit_curriculum_via_ai(): string { $components = [ 'wrap-script-template' => '', ]; return Template::combine_components( $components ); } }