diff --git a/README.md b/README.md index 434cc39..78ab1c5 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,13 @@ This WordPress plugin filters input fields in text areas using the [OpenAI Moderation API](https://platform.openai.com/docs/guides/moderation/overview). It helps ensure that user-submitted content is respectful and allows you to control which content classifications are blocked on your website. -### Forever Free, No Pro Version +### Forever Free, No Pro Version! We’re proud to announce that this plugin will always be 100% free, with no plans for a “Pro” or paid version. Our goal is to provide a reliable and accessible solution for the community, and we’re committed to keeping it that way. +### Get It From WordPress.org: +### [wordpress.org/plugins/openai-moderation](https://wordpress.org/plugins/openai-moderation/) +# ## Features - Configure the OpenAI API key and allowed classifications. @@ -16,19 +19,19 @@ We’re proud to announce that this plugin will always be 100% free, with no pla ## Installation 1. Download the plugin's ZIP file and extract it to the `/wp-content/plugins/` directory, or install the plugin through the WordPress plugins screen directly. -2. Activate the plugin through the 'Plugins' screen in WordPress. -3. Navigate to the 'Settings' > 'OpenAI Moderation' screen to configure the plugin. +2. Activate the plugin through the **Plugins** screen in WordPress. +3. Navigate to the **Settings > OpenAI Moderation** screen to configure the plugin. ## Configuration -![Admin Settings](screenshots/admin_settings.png) +![Admin Settings Screen](screenshots/admin_settings.png) -1. Obtain an OpenAI API key by signing up at https://beta.openai.com/signup/ and going to this page https://platform.openai.com/account/api-keys. -2. Go to the 'Settings' > 'OpenAI Moderation' screen in your WordPress admin area. -3. Enter your OpenAI API key in the 'OpenAI API Key' field. -4. Select the content categories you want to block in the 'Disallowed Classifications' field. -5. Check the 'Enable OpenAI Moderation' checkbox to enable the plugin. -6. Select the page to redirect to in the 'Error Page' dropdown. -7. Click 'Save Changes' to save your settings. +1. Obtain an OpenAI API key by signing up at [beta.openai.com/signup](https://beta.openai.com/signup/), and going to this page: [platform.openai.com/account/api-keys](https://platform.openai.com/account/api-keys). +2. Go to the **Settings > OpenAI Moderation** screen in your WordPress admin area. +3. Enter your OpenAI API key in the **OpenAI API Key** field. +4. Select the content categories you want to block in the **Disallowed Classifications** field. +5. Check the **Enable OpenAI Moderation** checkbox to enable the plugin. +6. Select the page to redirect to in the **Redirect Page** dropdown. +7. Click **Save Changes** to save your settings. ## Usage @@ -43,10 +46,10 @@ If the plugin is not working as expected, make sure that your OpenAI API key is ## Support and Contributions -While we are thrilled to receive your pull requests and issue reports, please note that we cannot guarantee support or address all feedback. Our team will prioritize security-related reports, as outlined in our security policy. We appreciate your understanding, and we encourage you to contribute to the ongoing improvement of this plugin. +While we are thrilled to receive your pull requests and issue reports, please note that we cannot guarantee support or address all feedback. Our team will prioritize security-related reports, as outlined in our [security policy](SECURITY.md). We appreciate your understanding, and we encourage you to contribute to the ongoing improvement of this plugin. Thank you for using and supporting our plugin! ## License -This plugin is licensed under the GPLv2 license. See the LICENSE file for more information. +This plugin is licensed under the GPLv2 license. See the [LICENSE](LICENSE) file for more information. diff --git a/openai-moderation/README.txt b/openai-moderation/README.txt index d4a8513..329d065 100644 --- a/openai-moderation/README.txt +++ b/openai-moderation/README.txt @@ -6,54 +6,68 @@ Requires PHP: 5.4 License: GPLv2 License URI: https://www.gnu.org/licenses/gpl-2.0.html -# OpenAI Moderation WordPress Plugin - -This WordPress plugin filters input fields in text areas using the [OpenAI Moderation API](https://platform.openai.com/docs/guides/moderation/overview). It helps ensure that user-submitted content is respectful and allows you to control which content classifications are blocked on your website. - -### Forever Free, No Pro Version - -We’re proud to announce that this plugin will always be 100% free, with no plans for a “Pro” or paid version. Our goal is to provide a reliable and accessible solution for the community, and we’re committed to keeping it that way. - -## Features - +OpenAI Moderation WordPress Plugin +---------------------------------- +This WordPress plugin filters input fields in text areas using the OpenAI Moderation API: +https://platform.openai.com/docs/guides/moderation/overview +It helps ensure that user-submitted content is respectful and allows you to control which +content classifications are blocked on your website. + +Forever Free, No Pro Version +---------------------------- +We’re proud to announce that this plugin will always be 100% free, with no plans for a “Pro” +or paid version. Our goal is to provide a reliable and accessible solution for the community, +and we’re committed to keeping it that way. + +Features +-------- - Configure the OpenAI API key and allowed classifications. - Enable or disable the plugin easily from the settings page. - Moderate comments before they are saved in the database. -- Redirect users to a selected page when their comment contains content that violates the disallowed classifications. - -## Installation +- Redirect users to a selected page when their comment contains content that violates +the disallowed classifications. -1. Download the plugin's ZIP file and extract it to the `/wp-content/plugins/` directory, or install the plugin through the WordPress plugins screen directly. +Installation +------------ +1. Download the plugin's ZIP file and extract it to the `/wp-content/plugins/` directory, +or install the plugin through the WordPress plugins screen directly. 2. Activate the plugin through the 'Plugins' screen in WordPress. 3. Navigate to the 'Settings' > 'OpenAI Moderation' screen to configure the plugin. -## Configuration - -1. Obtain an OpenAI API key by signing up at https://beta.openai.com/signup/ and going to this page https://platform.openai.com/account/api-keys. +Configuration +------------- +1. Obtain an OpenAI API key by signing up at https://beta.openai.com/signup/ and going to +this page: https://platform.openai.com/account/api-keys. 2. Go to the 'Settings' > 'OpenAI Moderation' screen in your WordPress admin area. 3. Enter your OpenAI API key in the 'OpenAI API Key' field. -4. Select the content categories you want to block in the 'Disallowed Classifications' field. +4. Select the content categories you want to block in the 'Disallowed Classifications'field. 5. Check the 'Enable OpenAI Moderation' checkbox to enable the plugin. -6. Select the page to redirect to in the 'Error Page' dropdown. +6. Select the page to redirect to in the 'Redirect Page' dropdown. 7. Click 'Save Changes' to save your settings. -## Usage - -Once the plugin is enabled and configured, it will automatically moderate comments on your website. If a user tries to post a comment that contains content that violates the allowed +Usage +----- +Once the plugin is enabled and configured, it will automatically moderate comments on your +website. If a user tries to post a comment that contains content that violates the allowed classifications, they will be redirected to a page and the comment will not be posted. -You can extend the plugin to moderate other types of content, such as user-submitted posts, by using the appropriate hooks and filters in WordPress. - -## Troubleshooting +You can extend the plugin to moderate other types of content, such as user-submitted posts, +by using the appropriate hooks and filters in WordPress. -If the plugin is not working as expected, make sure that your OpenAI API key is valid and that the 'Enable OpenAI Moderation' checkbox is checked in the plugin settings. +Troubleshooting +--------------- +If the plugin is not working as expected, make sure that your OpenAI API key is valid +and that the 'Enable OpenAI Moderation' checkbox is checked in the plugin settings. -## Support and Contributions - -While we are thrilled to receive your pull requests and issue reports, please note that we cannot guarantee support or address all feedback. Our team will prioritize security-related reports, as outlined in our security policy. We appreciate your understanding, and we encourage you to contribute to the ongoing improvement of this plugin. +Support and Contributions +------------------------- +While we are thrilled to receive your pull requests and issue reports, please note that +we cannot guarantee support or address all feedback. Our team will prioritize +security-related reports, as outlined in `SECURITY.md`. We appreciate your understanding, +and we encourage you to contribute to the ongoing improvement of this plugin. Thank you for using and supporting our plugin! -## License - -This plugin is licensed under the GPLv2 license. See the LICENSE file for more information. +License +------- +This plugin is licensed under the GPLv2 license. See the `LICENSE` file for more information. diff --git a/openai-moderation/includes/openai-moderation-moderate.php b/openai-moderation/includes/openai-moderation-moderate.php index 6409129..aaf975e 100644 --- a/openai-moderation/includes/openai-moderation-moderate.php +++ b/openai-moderation/includes/openai-moderation-moderate.php @@ -45,14 +45,14 @@ public function moderate_comment($comment_data) { $content = $comment_data['comment_content']; $moderation_result = $this->moderate_content($content); - + if (!$moderation_result || !$moderation_result['flagged']) { return $comment_data; } - + $disallowed_classifications = get_option('openai_classifications'); $disallowed_classifications = array_map('trim', $disallowed_classifications); - + $violates_policies = false; foreach ($moderation_result['categories'] as $category => $flagged) { if ($flagged && in_array($category, $disallowed_classifications)) { @@ -60,7 +60,7 @@ public function moderate_comment($comment_data) break; } } - + if ($violates_policies) { $error_page_id = get_option('openai_error_page'); if ($error_page_id) { @@ -69,9 +69,12 @@ public function moderate_comment($comment_data) wp_safe_redirect($error_page_url); exit; } + } else { + // If no error page is configured, use the wp_die() fallback + wp_die(__('Your comment could not be posted as it contains content that violates our policies.', 'openai-moderation')); } - } - + } + return $comment_data; } } \ No newline at end of file diff --git a/openai-moderation/openai-moderation.php b/openai-moderation/openai-moderation.php index ae104e5..e1f6be3 100644 --- a/openai-moderation/openai-moderation.php +++ b/openai-moderation/openai-moderation.php @@ -1,7 +1,7 @@ OpenAI Moderation API. Version: 1.2 Author: RAHB diff --git a/openai-moderation/partials/settings-page.php b/openai-moderation/partials/settings-page.php index 5ab859a..4d124c8 100644 --- a/openai-moderation/partials/settings-page.php +++ b/openai-moderation/partials/settings-page.php @@ -36,7 +36,7 @@
A default WordPress error page will be displayed if no Page is selected.', 'openai-moderation'); ?>