Create a list of words to be read by a plugin

0

I need to create a group of words, to be defined in a textarea, in the admin panel of Wordpress, in a page of configuration of my plugin.

I have the following code:

add_filter('pre_comment_content', 'palavras_indesejadas'); 
    function palavras_indesejadas($content { 
        //$palavras = get_comment_text();
        $palavras = array('teste', 'testando');

        foreach($palavras as $palavra) { 
            $content = str_replace($palavra, "******", $content); 
        } 
            return $content; 
        } 

It will identify in this array which words I define, but I do not know how to create a table or field in the database so I can save these words and then the plugin can search for them in the database.

As for the configuration page, I know more or less how to create it, I'm just in doubt about how to save this information in the database and bring it into my array.

    
asked by anonymous 09.02.2018 / 02:25

1 answer

0

I got it, in trial and error, but I'm not sure if this is the best practice.

First, I had to adapt the search phrase of the words:

$palavras = array( 
    explode( ',', get_option('palavras') ) 
);

And in this section I record the option

function palavras_indesejadas_config() {
   add_option('palavras', 'exemplos, de, palavras');
   register_setting('options', 'palavras', 'callback');
}
add_action( 'admin_init', 'palavras_indesejadas_config' );

And then I call settings_fields( 'options' ); inside the page of my plugin.

    <form method="post" action="options.php">
      <?php settings_fields( 'options' ); ?>
        <input type="text" id="palavras" name="palavras" 
        placeholder="<?php echo get_option('palavras'); ?>" />
    <?php submit_button(); ?>
    </form>
    
09.02.2018 / 03:53