Create a list of words to be read by a plugin

Asked

Viewed 21 times

0

I need to create a group of words, to be set in a textarea, in the admin panel of Wordpress, in a configuration page 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 what words I define, but I don’t know how to create a table or field in the database that 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 it creates, I’m just in doubt even how to save this information in the bank and bring it into my array.

1 answer

0

I did, in trial and error, but I’m not sure this is the best practice.

First, I had to adapt the word search excerpt:

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

And in this section 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>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.