<?php /** * Plugin Name: AI SEO Power-Up * Description: Automagically generate SEO-optimized metadata for your WordPress media library using OpenAI. * Version: 1.0.1 * Author: Horizons * Text Domain: ai-seo-powerup */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } define('AI_SEO_POWERUP_VERSION', '1.0.1'); define('AI_SEO_POWERUP_PLUGIN_DIR', plugin_dir_path(__FILE__)); define('AI_SEO_POWERUP_PLUGIN_URL', plugin_dir_url(__FILE__)); class AI_SEO_Power_Up { public function __construct() { add_action('admin_menu', array($this, 'add_admin_menu')); add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts')); } public function add_admin_menu() { add_menu_page( __('AI SEO Power-Up', 'ai-seo-powerup'), __('AI SEO Power-Up', 'ai-seo-powerup'), 'manage_options', 'ai-seo-powerup', array($this, 'render_admin_app'), 'dashicons-superhero', 99 ); } public function render_admin_app() { echo '<div class="wrap"><div id="ai-seo-powerup-root"></div></div>'; } public function enqueue_admin_scripts($hook) { if ('toplevel_page_ai-seo-powerup' !== $hook) { return; } // We assume the 'npm run build' command is run, which creates the dist folder. // For development, you would point to the Vite dev server. $script_path = 'dist/assets/index.js'; $style_path = 'dist/assets/index.css'; $script_url = AI_SEO_POWERUP_PLUGIN_URL . $script_path; $style_url = AI_SEO_POWERUP_PLUGIN_URL . $style_path; $react_app_dependencies = ['wp-element']; wp_enqueue_script( 'ai-seo-powerup-app', $script_url, $react_app_dependencies, AI_SEO_POWERUP_VERSION, true ); wp_enqueue_style( 'ai-seo-powerup-app-style', $style_url, array(), AI_SEO_POWERUP_VERSION ); // Pass data to our React app wp_localize_script('ai-seo-powerup-app', 'wpData', [ 'rest_url' => esc_url_raw(rest_url()), 'nonce' => wp_create_nonce('wp_rest'), 'open_ai_key' => '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' ]); } } new AI_SEO_Power_Up();