90,'headers'=>['Content-Type'=>'application/json','Authorization'=>'Bearer '.$key],'body'=>json_encode(['model'=>'gpt-4.1-mini','messages'=>[['role'=>'system','content'=>$sys],['role'=>'user','content'=>"Write SEO article for: \"$title\" with focus keyword: \"$keyword\". Keyword MUST appear verbatim in first sentence and in 2+ H2 headings."]],'max_tokens'=>2000,'temperature'=>0.7])]); if (is_wp_error($resp)) { wp_send_json_error('OpenAI error: '.$resp->get_error_message()); } $body = json_decode(wp_remote_retrieve_body($resp), true); $content = trim($body['choices'][0]['message']['content'] ?? ''); if (empty($content)) { wp_send_json_error('Empty content'); } $mr = wp_remote_post('https://api.openai.com/v1/chat/completions', ['timeout'=>30,'headers'=>['Content-Type'=>'application/json','Authorization'=>'Bearer '.$key],'body'=>json_encode(['model'=>'gpt-4.1-mini','messages'=>[['role'=>'user','content'=>"Write meta description 130-155 chars for \"$title\" with keyword \"$keyword\". Mention Orange County. Text only, no quotes."]],'max_tokens'=>80,'temperature'=>0.7])]); $mb = json_decode(wp_remote_retrieve_body($mr), true); $meta = trim($mb['choices'][0]['message']['content'] ?? '', '"'); wp_update_post(['ID'=>$post_id,'post_content'=>$content]); update_post_meta($post_id,'rank_math_focus_keyword',$keyword); update_post_meta($post_id,'rank_math_description',$meta); wp_send_json_success(['post_id'=>$post_id,'len'=>strlen($content),'meta'=>substr($meta,0,100)]); } function sparkle_do_get_low_scores() { if (!current_user_can('edit_posts')) { wp_send_json_error('Unauthorized', 403); } global $wpdb; $r = $wpdb->get_results("SELECT p.ID, p.post_title, p.post_type, MAX(CASE WHEN pm.meta_key='rank_math_seo_score' THEN pm.meta_value END) as score, MAX(CASE WHEN pm.meta_key='rank_math_focus_keyword' THEN pm.meta_value END) as keyword FROM {$wpdb->posts} p LEFT JOIN {$wpdb->postmeta} pm ON p.ID=pm.post_id WHERE p.post_status='publish' AND p.post_type IN('post','page') GROUP BY p.ID HAVING (score IS NULL OR CAST(score AS UNSIGNED)<80) ORDER BY score ASC LIMIT 100"); wp_send_json_success($r); }

CSLB – 945830 / IICRC – 65335

949-631-1001

714-641-6600

Celebrating 23 years in business badge for Sparkle Restoration, featuring bold orange text and a circular design with stars.