'', 'persona' => '', // expert persona/voice for the content 'length' => 'medium', // short, medium, long 'tone' => 'professional', // professional, casual, friendly, formal, conversational 'seo_keywords' => '', // comma-separated keywords 'custom_style' => '' // custom writing style from analyzed samples ); } /** * Execute the step * * @param AIGH_Pipeline_Context $context * @return AIGH_Pipeline_Context|WP_Error */ public function execute($context) { $this->log_start($context); // Get topic from config or context (allows override) $topic = $this->get_config_value('topic', ''); if (empty($topic)) { $topic = $context->get('topic', ''); } // Validate topic if (empty($topic)) { $this->log_end($context, false); return $this->create_error( 'empty_topic', 'Topic is required for content generation' ); } // Sanitize and validate length $length = $this->get_config_value('length', 'medium'); $valid_lengths = array('short', 'medium', 'long'); if (!in_array($length, $valid_lengths)) { $length = 'medium'; } // Sanitize and validate tone $tone = $this->get_config_value('tone', 'professional'); $valid_tones = array('professional', 'casual', 'friendly', 'formal', 'conversational'); if (!in_array($tone, $valid_tones)) { $tone = 'professional'; } // Get SEO keywords from config or context $seo_keywords = $this->get_config_value('seo_keywords', ''); if (empty($seo_keywords)) { $seo_keywords = $context->get('seo_keywords', ''); } // Get persona from config or context $persona = $this->get_config_value('persona', ''); if (empty($persona)) { $persona = $context->get('persona', ''); } // Set values in context $this->set_in_context($context, 'topic', sanitize_textarea_field($topic)); $this->set_in_context($context, 'length', $length); $this->set_in_context($context, 'tone', $tone); // Set persona if provided if (!empty($persona)) { $this->set_in_context($context, 'persona', sanitize_text_field($persona)); } // Set SEO keywords if provided (sanitize and normalize) if (!empty($seo_keywords)) { $seo_keywords = sanitize_text_field($seo_keywords); $this->set_in_context($context, 'seo_keywords', $seo_keywords); // Also parse into array for convenience $keywords_array = array_map('trim', explode(',', $seo_keywords)); $keywords_array = array_filter($keywords_array); // Remove empty values $this->set_in_context($context, 'seo_keywords_array', $keywords_array); } // Handle custom style if provided (from style samples analysis) $custom_style = $this->get_config_value('custom_style', ''); if (empty($custom_style)) { $custom_style = $context->get('custom_style', ''); } if (!empty($custom_style)) { $this->set_in_context($context, 'custom_style', $custom_style); } // Store length guide for later steps $length_guides = array( 'short' => '400-600 words', 'medium' => '800-1000 words', 'long' => '1200-1500 words' ); $this->set_in_context($context, 'length_guide', $length_guides[$length]); $this->log_end($context, true); return $context; } /** * Get configuration schema for UI rendering * * @return array */ public function get_config_schema() { return array( 'persona' => array( 'type' => 'text', 'label' => 'Persona', 'description' => 'Expert voice for the content (e.g., "Marketing strategist specialized in SaaS")', 'placeholder' => 'e.g., Fitness coach for busy professionals', 'required' => false ), 'topic' => array( 'type' => 'textarea', 'label' => 'Topic or Prompt', 'description' => 'What should the article be about?', 'required' => true, 'rows' => 4 ), 'length' => array( 'type' => 'select', 'label' => 'Article Length', 'description' => 'Approximate length of the generated content', 'options' => array( 'short' => 'Short (400-600 words)', 'medium' => 'Medium (800-1000 words)', 'long' => 'Long (1200-1500 words)' ), 'default' => 'medium' ), 'tone' => array( 'type' => 'select', 'label' => 'Tone', 'description' => 'Writing style for the content', 'options' => array( 'professional' => 'Professional', 'casual' => 'Casual', 'friendly' => 'Friendly', 'formal' => 'Formal', 'conversational' => 'Conversational' ), 'default' => 'professional' ), 'seo_keywords' => array( 'type' => 'text', 'label' => 'SEO Keywords', 'description' => 'Target keywords separated by commas (e.g., "best running shoes, running reviews")', 'placeholder' => 'keyword 1, keyword 2, keyword 3', 'required' => false ) ); } }