id != 'edit-' . LP_COURSE_CPT ) { return; } $this->config = Config::instance()->get( 'open-ai-modal', 'settings' ); echo $this->html_create_course_via_ai(); echo $this->html_creating_course(); echo $this->html_warning_enable_ai(); } catch ( Throwable $e ) { LP_Debug::error_log( $e ); } } /** * Render AI templates for non-admin contexts (e.g. Course Builder frontend). * * @return string */ public function render_for_frontend(): string { $this->config = Config::instance()->get( 'open-ai-modal', 'settings' ); return $this->html_create_course_via_ai() . $this->html_creating_course() . $this->html_warning_enable_ai(); } public function html_create_course_via_ai(): string { $components = [ 'wrap-script-template' => '', ]; return Template::combine_components( $components ); } public function html_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__( 'Course Structure', 'learnpress' ) ), 'step_4' => sprintf( '
4%s
', esc_html__( 'Prompt', 'learnpress' ) ), 'step_5' => sprintf( '
5 %s
', esc_html__( 'Create course', 'learnpress' ) ), 'wrap-end' => '
', ]; return Template::combine_components( $components ); } private function html_step_1(): string { $options = $this->config; $components = [ 'step' => '
', 'title' => sprintf( '
%s
', esc_html__( 'Step 1 — Course Goal', 'learnpress' ), ), 'description' => sprintf( '

%s

', '' ), 'role' => sprintf( '

%s

', esc_html__( 'Role / Persona', 'learnpress' ), esc_html__( 'Defines who is creating the course so AI can tailor tone, expertise, and perspective.', 'learnpress' ) ), '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' ) ), 'objective' => sprintf( '

%s

', esc_html__( 'Course objective', 'learnpress' ), esc_html__( 'Enter description about course you want AI generate', 'learnpress' ), esc_html__( 'Specifies what learners should achieve after completing the course, guiding AI to generate outcome-aligned content.', 'learnpress' ), ), 'step_close' => '
', ]; return Template::combine_components( $components ); } /** * Step 2 HTML. * * @return string */ public function html_step_2(): string { $options = $this->config; $grid_components = [ 'grid' => '
', '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' ) ), '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' ) ), 'reading_level' => sprintf( '
%s

%s

', esc_html__( 'Reading level', 'learnpress' ), AdminTemplate::html_tom_select( [ 'name' => 'reading_level', 'options' => $options['reading_level'] ?? [], ] ), esc_html__( 'Determines the complexity of language (e.g., foundational, intermediate, advanced) so the AI can generate content appropriate for the learners’ comprehension level.', 'learnpress' ) ), 'seo_emphasis' => sprintf( '

%s

', esc_html__( 'SEO emphasis', 'learnpress' ), esc_html__( 'Determines how strongly AI should optimize content for search engines.', 'learnpress' ), ), 'keywords' => sprintf( '

%s

', esc_html__( 'Target keywords (comma-separated)', 'learnpress' ), esc_html__( 'Lists the keywords AI should integrate to improve SEO performance across titles and descriptions.', 'learnpress' ) ), 'grid-end' => '
', ]; $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' => Template::combine_components( $grid_components ), 'step-end' => '
', ]; return Template::combine_components( $components ); } public function html_step_3(): string { $grid_components = [ 'grid' => '
', 'sections-number' => sprintf( '

%s

', esc_html__( 'Sections number', 'learnpress' ), esc_html__( 'Defines how many main sections/modules the course will include.', 'learnpress' ) ), /*'sections-title-length' => sprintf( '

%s

', esc_html__( 'Each section title length', 'learnpress' ), esc_html__( 'Specifies the word limit for section titles to maintain consistency and readability.', 'learnpress' ) ), 'sections-des-length' => sprintf( '

%s

', esc_html__( 'Each section description length', 'learnpress' ), esc_html__( 'Sets the word limit for section introductions to control depth and clarity.', 'learnpress' ) ),*/ 'lesson-number' => sprintf( '
', esc_html__( 'Lessons per Section', 'learnpress' ) ), /*'lesson-title-length' => sprintf( '
', esc_html__( 'Each lesson title length (words)', 'learnpress' ) ), 'lesson-des-length' => sprintf( '
', esc_html__( 'Each lesson description length', 'learnpress' ) ),*/ 'quizzes' => sprintf( '
', esc_html__( 'Quizzes per Section', 'learnpress' ) ), 'questions' => sprintf( '
', esc_html__( 'Questions per Quiz', 'learnpress' ) ), 'grid-end' => '
', ]; $components = [ 'step' => '
', 'title' => sprintf( '
%s
', esc_html__( 'Step 3 — Course Structure', 'learnpress' ), ), 'description' => sprintf( '

%s

', esc_html__( 'Define the LearnPress Curriculum structure. The Prompt will be generated based on these controls.', 'learnpress' ) ), 'form_grid' => Template::combine_components( $grid_components ), 'step-end' => '
', ]; return Template::combine_components( $components ); } /** * Generated prompt to submit OpenAI * * @return string */ public function html_step_4(): string { $components = [ 'step' => '
', 'title' => sprintf( '
%s
', esc_html__( 'Step 4 — Prompt Generated', 'learnpress' ), ), 'prompt' => sprintf( '
%s
', __( 'Shows the auto-generated AI prompt, allowing further adjustments before submission.', 'learnpress' ) ), 'step-end' => '
', ]; return Template::combine_components( $components ); } /** * Preview Course and create * * @return string */ public function html_step_5(): string { $components = [ 'step' => '
', 'title' => sprintf( '
%s
', esc_html__( 'Step 5 — Create Course', 'learnpress' ), ), 'description' => sprintf( '

%s

', esc_html__( 'Data preview before create course.', 'learnpress' ) ), 'preview' => '
', 'step-end' => '
', ]; return Template::combine_components( $components ); } /** * HTML preview with data received from OpenAI * * @param array $data_received * * @return string */ public static function html_preview_with_data( array $data_received ): string { $course_title = $data_received['course_title'] ?? ''; $course_description = $data_received['course_description'] ?? ''; $sections = $data_received['sections'] ?? []; $html_section = ''; foreach ( $sections as $section ) { $section_title = $section['section_title'] ?? ''; $section_des = $section['section_description'] ?? ''; $lessons = $section['lessons'] ?? []; $quizzes = $section['quizzes'] ?? []; $html_lessons = ''; foreach ( $lessons as $lesson ) { $lesson_title = $lesson['lesson_title'] ?? ''; $lesson_des = $lesson['lesson_description'] ?? ''; $arr_lesson_components = [ 'wrap' => '
  • ', 'title' => sprintf( '
    %s: %s
    ', __( 'Lesson', 'learnpress' ), esc_html( $lesson_title ) ), 'des' => sprintf( '
    %s
    ', esc_html( $lesson_des ) ), 'wrap-end' => '
  • ', ]; $html_lessons .= Template::combine_components( $arr_lesson_components ); } // Quizzes $html_quizzes = ''; foreach ( $quizzes as $quiz ) { $quiz_title = $quiz['quiz_title'] ?? ''; $quiz_des = $quiz['quiz_description'] ?? ''; $questions = $quiz['questions'] ?? []; $html_questions = ''; foreach ( $questions as $question ) { $question_title = $question['question_title'] ?? ''; $question_des = $question['question_description'] ?? ''; $options = $question['options'] ?? []; $html_options = ''; foreach ( $options as $option ) { $html_options .= sprintf( '
  • %s
  • ', esc_html( $option ) ); } $arr_question_components = [ 'wrap' => '
  • ', 'title' => sprintf( '
    %s: %s
    ', __( 'Question', 'learnpress' ), esc_html( $question_title ) ), 'desc' => sprintf( '
    %s
    ', esc_html( $question_des ) ), 'options' => sprintf( '', $html_options ), 'wrap-end' => '
  • ', ]; $html_questions .= Template::combine_components( $arr_question_components ); } $arr_quiz_components = [ 'wrap' => '
  • ', 'title' => sprintf( '
    %s: %s
    ', __( 'Quiz', 'learnpress' ), esc_html( $quiz_title ) ), 'des' => sprintf( '
    %s
    ', esc_html( $quiz_des ) ), 'questions' => sprintf( '', $html_questions ), 'wrap-end' => '
  • ', ]; $html_quizzes .= Template::combine_components( $arr_quiz_components ); } $arr_section_components = [ 'wrap' => '
  • ', 'title' => sprintf( '
    %s: %s
    ', __( 'Curriculum', 'learnpress' ), esc_html( $section_title ) ), 'des' => sprintf( '
    %s
    ', esc_html( $section_des ) ), 'ul-items' => '', 'wrap-end' => '
  • ', ]; $html_section .= Template::combine_components( $arr_section_components ); } $section = [ 'wrap' => '
    ', 'title' => sprintf( '
    %s
    ', esc_html( $course_title ) ), 'des' => sprintf( '
    %s
    ', esc_html( $course_description ) ), 'sections' => sprintf( '', $html_section ), 'wrap-end' => '
    ', ]; return Template::combine_components( $section ); } /** * HTML for Popup Creating course template * * @return string */ public function html_creating_course(): string { $components = [ 'wrap-script-template' => '', ]; return Template::combine_components( $components ); } /** * HTML for Popup warning enable AI * * @return string */ public function html_warning_enable_ai(): string { $components = [ 'wrap-script-template' => '', ]; return Template::combine_components( $components ); } }