Plugin that changes text in the content for the value provided

The whole plugin that saves some text to the database and replace provided values in the content


  Plugin Name: Change content
  Description: Plugin that changes provided words for something different
  Version 1.0
  Author: Matineo
  Author URI:

if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

add_action('admin_menu', 'ourMenu');
add_filter('the_content', 'filterLogic');

function filterLogic($content) {
    $badWords = explode(',', get_option('myPluginDBopt'));
    $badWordsTrimmed = array_map('trim', $badWords);
    return str_ireplace($badWordsTrimmed, esc_html(get_option('myPluginDBoptReplace', '****')), $content);

  function ourMenu() {
    $mainPageHook = add_menu_page(
      'Change text plugin', 
      'Change text', 
    add_action("load-{$mainPageHook}", 'myPluginAssets');

  function myPluginAssets() {
    wp_enqueue_style('myPluginCss', plugin_dir_url(__FILE__) . 'mypluginstyle.css');

  function handleForm() {
    if (wp_verify_nonce($_POST['ourNonce'], 'saveMyText') AND current_user_can('manage_options')) {
      update_option('myPluginDBopt', sanitize_text_field($_POST['myplugin1'])); 
      update_option('myPluginDBoptReplace', sanitize_text_field($_POST['replaceText']));?>
      <div class="updated">
        <p>Your filtered words were saved.</p>
    <?php } else { ?>
      <div class="error">
        <p>Sorry, you do not have permission to perform that action.</p>
    <?php } 

  function myPluginCallBackFunc() { ?>
    <div class="wrap">
        <div class="mainDiv">
            <h1>Change text plugin</h1>
            <?php if ($_POST['justsubmitted'] == "true") {handleForm();} ?>
            <form method="POST">
            <input type="hidden" name="justsubmitted" value="true">
            <?php wp_nonce_field('saveMyText', 'ourNonce') ?>
                <label for="myplugin1"><p>Enter words, separated by coma</p></label>
                <div class="textArea">
                    <textarea name="myplugin1" id="myplugin1" placeholder="word1,word2,word3,word4,..."><?php echo esc_textarea(get_option('myPluginDBopt')) ?></textarea>
                <p>Change for this value</p>
                <input type="text" name="replaceText">
                <input type="submit" name="submit" id="submit" class="button button-primary" value="Save Changes">
  <?php }
Ask ChatGPT
Set ChatGPT API key
Find your Secret API key in your ChatGPT User settings and paste it here to connect ChatGPT with your Tutor LMS website.
Scroll to Top