'sanitize_text_field' ) ); // Register selected CPTs register_setting( 'aigfp_image_generator_settings', 'aigfp_selected_cpts', array( 'sanitize_callback' => 'aigfp_sanitize_cpts' ) ); add_settings_section( 'aigfp_image_generator_section', esc_html__('Together API Key', 'ai-image-generator-for-posts'), 'aigfp_image_generator_section_callback', 'ai-image-generator-for-posts-settings' ); add_settings_field( 'aigfp_api_key', esc_html__('Together API Key', 'ai-image-generator-for-posts'), 'aigfp_image_generator_api_key_field_callback', 'ai-image-generator-for-posts-settings', 'aigfp_image_generator_section' ); add_settings_field( 'aigfp_selected_cpts', esc_html__('Select Post Types for AI Image Generator', 'ai-image-generator-for-posts'), 'aigfp_image_generator_cpts_field_callback', 'ai-image-generator-for-posts-settings', 'aigfp_image_generator_section' ); } /** * Outputs the settings section description for the Together API key field. * * Displays a message above the API key input field with a link to create a * new API key at Together AI. * * @since 1.0 */ function aigfp_image_generator_section_callback() { echo esc_html_e('Enter your Together API key below.', 'ai-image-generator-for-posts'); echo '
'; echo esc_html_e('Create your API Key here https://api.together.xyz/', 'ai-image-generator-for-posts'); } /** * Outputs the form field for the Together API key. * * Retrieves the current value of the 'aigfp_api_key' option and outputs an * input field with that value. The input field is given a class of * 'regular-text' to match the styling of other text input fields in the * WordPress admin. * * @since 1.0 */ function aigfp_image_generator_api_key_field_callback() { $api_key = get_option('aigfp_api_key'); echo ''; } /** * Outputs the form field for selecting custom post types. */ function aigfp_image_generator_cpts_field_callback() { $selected_cpts = get_option('aigfp_selected_cpts', array()); $post_types = get_post_types(array('public' => true), 'objects'); echo '
'; foreach ($post_types as $post_type) { $checked = in_array($post_type->name, $selected_cpts) ? 'checked' : ''; echo '
'; } echo '
'; } /** * Sanitizes the selected CPTs. */ function aigfp_sanitize_cpts($input) { return is_array($input) ? array_map('sanitize_text_field', $input) : array(); }