*/ class Ai_For_Wordpress_By_Upcasted_Admin { /** * The ID of this plugin. * * @since 1.0.0 * @access private * @var string $plugin_name The ID of this plugin. */ private $plugin_name; /** * The version of this plugin. * * @since 1.0.0 * @access private * @var string $version The current version of this plugin. */ private $version; /** @var UpcastedEncryption $encryption */ private $encryption; /** * Initialize the class and set its properties. * * @since 1.0.0 * @param string $plugin_name The name of this plugin. * @param string $version The version of this plugin. */ public function __construct($plugin_name, $version) { $this->plugin_name = $plugin_name; $this->version = $version; $this->encryption = UpcastedEncryption::getInstance(); } function add_admin_page() { add_submenu_page( 'upload.php', __('AI Image Generator', 'ai-wp-upcasted'), __('AI Generator', 'ai-wp-upcasted'), 'manage_options', 'ai-wp-upcasted', array($this, 'main_app') ); add_options_page( __('AI Image Generator Settings', 'ai-wp-upcasted'), __('AI Image Generator', 'ai-wp-upcasted'), 'manage_options', 'ai-wp-upcasted-options', array($this, 'settings_page') ); } function main_app() { ?>
encrypt( sanitize_text_field( $_POST['ai_wp_upcasted_api_key'] ) ) ); } if (isset($_POST['ai_wp_upcasted_resolution'])) { update_option( 'ai_wp_upcasted_resolution', sanitize_text_field( $_POST['ai_wp_upcasted_resolution'] ) ); } if (isset($_POST['ai_wp_upcasted_variations_num'])) { update_option( 'ai_wp_upcasted_variations_num', sanitize_text_field( intval($_POST['ai_wp_upcasted_variations_num']) ) ); } $api_key = get_option('ai_wp_upcasted_api_key', ''); $selected_option = get_option('ai_wp_upcasted_resolution'); $variations_num = get_option('ai_wp_upcasted_variations_num'); ?>

Where do I find my Secret API Key?

To get an API key you will need to create an account on OpenAI.com

OpenAI API Key set and ready! Change API key

'256x256', '512x512' => '512x512', '1024x1024' => '1024x1024' ); ?>
' . __('Configure the OpenAI Image Generation API settings', 'ai-wp-upcasted') . '

'; } /** * Render the API key setting. */ public function render_api_key_setting() { $option = get_option('ai_wp_upcasted_api_key'); echo ''; } /** * Render the resolution setting. */ public function render_resolution_setting() { $options = array( '256x256' => '256x256', '512x512' => '512x512', '1024x1024' => '1024x1024' ); $selected_option = get_option('ai_wp_upcasted_resolution'); echo ''; } /** * Render the number of images setting. */ public function render_variations_num_setting() { $option = get_option('ai_wp_upcasted_variations_num'); echo ''; } /** * Register the stylesheets for the admin area. * * @since 1.0.0 */ public function enqueue_styles() { /** * This function is provided for demonstration purposes only. * * An instance of this class should be passed to the run() function * defined in Ai_For_Wordpress_By_Upcasted_Loader as all of the hooks are defined * in that particular class. * * The Ai_For_Wordpress_By_Upcasted_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/ai-wp-upcasted-admin.css', array(), $this->version, 'all'); } /** * Register the JavaScript for the admin area. * * @since 1.0.0 */ public function enqueue_scripts() { /** * This function is provided for demonstration purposes only. * * An instance of this class should be passed to the run() function * defined in Ai_For_Wordpress_By_Upcasted_Loader as all of the hooks are defined * in that particular class. * * The Ai_For_Wordpress_By_Upcasted_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ $currentScreen = get_current_screen(); wp_enqueue_media(); wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/ai-wp-upcasted-admin.js', array('jquery'), $this->version, false); if ($currentScreen->base == 'media_page_ai-wp-upcasted') { wp_enqueue_script('ai-wp-upcasted-react', plugin_dir_url(__DIR__) . 'dist/ai-wp-upcasted-react.js', array('wp-element'), $this->version, false); wp_localize_script( 'ai-wp-upcasted-react', 'ai_wp_upcasted_object', array( 'noOfVariations' => get_option( 'ai_wp_upcasted_variations_num', '' ), 'resolution' => get_option( 'ai_wp_upcasted_resolution', '' ), 'security' => wp_create_nonce('_wpnonce') ) ); } if ($currentScreen->id === 'upload') { wp_enqueue_script('ai-wp-upcasted-media-library', plugin_dir_url(__DIR__) . 'admin/js/ai-wp-upcasted-media-library.js', array('jquery'), $this->version, true); wp_localize_script( 'ai-wp-upcasted-media-library', 'upcasted_media_library', array( 'buttonTitle' => __('Generate with AI', 'ai-wp-upcasted'), ) ); } } }