Skip to content

Commit

Permalink
Restore fallback error, prep for wordpress.org
Browse files Browse the repository at this point in the history
  • Loading branch information
justinh-rahb committed Mar 24, 2023
1 parent de77ed4 commit 976efdc
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 54 deletions.
29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand All @@ -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.
78 changes: 46 additions & 32 deletions openai-moderation/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
15 changes: 9 additions & 6 deletions openai-moderation/includes/openai-moderation-moderate.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,22 @@ 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)) {
$violates_policies = true;
break;
}
}

if ($violates_policies) {
$error_page_id = get_option('openai_error_page');
if ($error_page_id) {
Expand All @@ -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;
}
}
2 changes: 1 addition & 1 deletion openai-moderation/openai-moderation.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/*
Plugin Name: OpenAI Moderation
Plugin URI: https://github.com/RAHB-REALTORS-Association/OpenAI-Moderation-WP
Plugin URI: https://wordpress.org/plugins/openai-moderation/
Description: A simple plugin that filters input fields in text areas using the <a href="https://platform.openai.com/docs/guides/moderation/overview" target="_blank">OpenAI Moderation API</a>.
Version: 1.2
Author: RAHB
Expand Down
4 changes: 2 additions & 2 deletions openai-moderation/partials/settings-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</tr>
<tr>
<th scope="row">
<label for="openai_error_page"><?php _e('Error Page', 'openai-moderation'); ?></label>
<label for="openai_error_page"><?php _e('Redirect Page', 'openai-moderation'); ?></label>
</th>
<td>
<?php
Expand All @@ -49,7 +49,7 @@
'option_none_value' => ''
));
?>
<p><?php _e('Select a page to redirect users to when their comment violates the policies.', 'openai-moderation'); ?></p>
<p><?php _e('Select a Page to redirect users to when their comment violates the policies.<br />A default WordPress error page will be displayed if no Page is selected.', 'openai-moderation'); ?></p>
</td>
</tr>
</table>
Expand Down

0 comments on commit 976efdc

Please sign in to comment.