Execute function whenever modify, create, delete post [closed]

0

Good night, I need to run a function in wordpress whenever a post is included, deleted, edited and returned from the trash. Can anyone help me I do not know how to do this.

Thank you.

    
asked by anonymous 19.06.2015 / 01:48

1 answer

0

You are looking for actions . With them, you can link methods that you define to certain "events" that occur in WP. For example, if you put in your functions.php the code

add_action( 'admin_init', 'init_admin_custom_css' );
function init_admin_custom_css(){
    add_editor_style( get_stylesheet_directory_uri().'/css/meu_css.css' );
}

WP will insert this .css into the editor screen every time you enter the administration menu (i.e., the admin_init action). In your case, to perform an action every time a post is edited, for example, you can do

add_action('edit_post', 'minha_funcao');

and set

function minha_funcao(){
    .
    . #seu código
    .
}

See here for a list of the% s of% s that WP makes available, and choose them according to Your necessity. In this part of the codex, you can see the action , which will be part of your code. Read more about the wp_insert_post method, its peculiarities and its parameters here .

P.S. All 4 links are from the codex, which I highly recommend reading.

    
19.06.2015 / 04:24