Can you use add_filter() inside other function?

I’m new to WordPress, and currently developing my first plugin and currently having difficulties.

How I can insert the add_filter action inside my submit function? I want the add_filter action to process after the user click the submit button.

I have try this but it didn’t work.

if(isset($_POST['btn_submit'])) {

    function addContent($content="") {            
        $content .= "My content";

        return $content;
    }

    add_filter('the_content', 'addContent');
}

Any help would be greatly appreciated. Thanks!

3 Answers
3

I think what you’re ACTUALLY looking to do is to apply_filters(). add_filter() registers a new filter, whereas apply_filters() does the filters that have been registered.

If that’s not what you’re looking to do, then you need to be aware that add_filter() needs to be run every time you want the filter applied. This allows plugins to be removed without having to unregister all their filters and generally keeps a wordpress install pretty clean…it also helps with security. A better question might encompass a broader scope, where you state what you’re trying to do, rather than having us try and troubleshoot your implementation of it.

Leave a Comment