From 5d1b0117490b2b411a197e107bd32a0d36139f3c Mon Sep 17 00:00:00 2001 From: "Paulo H." Date: Tue, 16 Apr 2024 21:15:41 -0300 Subject: [PATCH] more linting and quality of life changes --- .vscode/settings.json | 3 + admin.php | 250 +++++++++++++++------------------------- auto-post.php | 154 +++++++++++++++++-------- css.css/admin-style.css | 38 ++++++ gpt.php | 42 ++++--- js/admin-script.js | 45 ++++++++ 6 files changed, 317 insertions(+), 215 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 css.css/admin-style.css create mode 100644 js/admin-script.js diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..51bcffd --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "docwriter.style": "Google" +} diff --git a/admin.php b/admin.php index 5293acc..4a11a6e 100644 --- a/admin.php +++ b/admin.php @@ -1,5 +1,17 @@ 0 ) ); + echo ''; +} + + +/** + * The function `abcc_openai_text_settings_page` is used to display and handle settings for an OpenAI + * blog post generator, including options for keywords, tone selection, and category selection. + */ function abcc_openai_text_settings_page() { - if ( isset( $_POST['submit'], $_POST['abcc_openai_nonce'] ) && wp_verify_nonce( $_POST['abcc_openai_nonce'], 'abcc_openai_generate_post' ) ) { - $keywords = isset( $_POST['openai_keywords'] ) ? sanitize_text_field( wp_unslash( $_POST['openai_keywords'] ) ) : ''; - $tone = isset( $_POST['openai_tone'] ) ? sanitize_text_field( wp_unslash( $_POST['openai_tone'] ) ) : ''; + if ( isset( $_POST['submit'], $_POST['abcc_openai_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['abcc_openai_nonce'] ), 'abcc_openai_generate_post' ) ) { + $keywords = isset( $_POST['openai_keywords'] ) ? sanitize_text_field( wp_unslash( $_POST['openai_keywords'] ) ) : ''; $selected_categories = isset( $_POST['openai_selected_categories'] ) ? array_map( 'intval', $_POST['openai_selected_categories'] ) : array(); + if ( isset( $_POST['openai_tone'] ) ) { + $openai_tone = sanitize_text_field( wp_unslash( $_POST['openai_tone'] ) ); + + if ( 'custom' === $openai_tone ) { + $custom_tone = isset( $_POST['custom_tone'] ) ? sanitize_text_field( wp_unslash( $_POST['custom_tone'] ) ) : ''; + update_option( 'custom_tone', $custom_tone ); + } + + update_option( 'openai_tone', $openai_tone ); + } + update_option( 'openai_keywords', wp_unslash( $keywords ) ); - update_option( 'openai_tone', wp_unslash( $tone ) ); update_option( 'openai_selected_categories', $selected_categories ); } - $categories = get_categories( array( 'hide_empty' => false ) ); $selected_categories = get_option( 'openai_selected_categories', array() ); - $openai_tone = get_option( 'openai_tone', 'default' ); - $keywords = get_option( 'openai_keywords', '' ); - $schedule_info = get_openai_event_schedule(); - $selected_value = get_option( 'openai_tone' ); // Obter o valor atualmente selecionado + $keywords = get_option( 'openai_keywords', '' ); + $schedule_info = get_openai_event_schedule(); + $tone = get_option( 'openai_tone', '' ); + if ( get_option( 'custom_tone' ) != '' ) { + $custom_tone_value = get_option( 'custom_tone' ); + } else { + $custom_tone_value = ''; + } if ( $schedule_info ) { echo '
@@ -61,49 +106,18 @@ function abcc_openai_text_settings_page() {
'; } + $tones = array( + 'default' => 'Use a default tone', + 'business' => 'Business-oriented', + 'academic' => 'Academic', + 'funny' => 'Funny', + 'epic' => 'Epic', + 'personal' => 'Personal', + 'custom' => 'Custom', + ); ?> - -
+

@@ -127,28 +141,23 @@ function abcc_openai_text_settings_page() { - + - > - - - > - - - > - - - > - - - > - - - > - - + $label ) : ?> + > + + + + + + style=""> @@ -156,14 +165,7 @@ function abcc_openai_text_settings_page() { - - -
- + @@ -183,38 +185,15 @@ class="button button-secondary">
- - - -

@@ -307,7 +245,8 @@ function abcc_openai_blog_post_options_page() {
+ if ( ! defined( 'OPENAI_API' ) ) { + ?> '; - } ?> + } + ?> + if ( ! defined( 'GEMINI_API' ) ) { + ?> '; - } ?> + } + ?>
'; echo 'Your OpenAI API key is already set in wp-config.php.'; echo '
'; echo 'Your Gemini API key is already set in wp-config.php.'; echo '