PHP and Wordpress, run a script every time you make a new post

Asked

Viewed 324 times

0

Hello, I’m needing that every time I make a new post on Wordpress run a script. I don’t want to waste time making apps, just want to know which page is responsible for sending the posts in Wordpress. I also want to know if it is possible to catch the Título da postagem to pass as parameter every time you have a new post.

How do I do this quickly?

The reason for this? I need to execute a script that I myself made to send notifications push. I just need every time I do a new post run the script with Título da postagem.

If you can help me, thank you, thank you.

[EDIT] I discovered the name of the Wordpress file, is called post.php and is in the wp-admin folder, now I need to know where I put the email script and how I get the title of the post.php

1 answer

2


Use this function to return a value booleano:

function is_edit_page($new_edit = null){
    global $pagenow;
    //certifique-se de que estamos no backend
    if (!is_admin()) return false;


    if($new_edit == "edit")

        return in_array( $pagenow, array( 'post.php',  ) );

    elseif($new_edit == "new") //check for new post page
        return in_array( $pagenow, array( 'post-new.php' ) );

    else // verifica se há é uma nova postagem ou foi editada
        return in_array( $pagenow, array( 'post.php', 'post-new.php' ) );
}

Now we will use the conditionals to validate:

if (is_edit_page()){
   //sim, é uma edição ou nova página de postagem
}

Checking if it is a new post(HERE WOULD BE YOUR E-MAIL SCRIPT)

if (is_edit_page('new')){
   //sim é uma nova postagem

}

Checking if it was only edited:

if (is_edit_page('edit')){
   //sim é uma nova postagem
}

Read more...

  • Got it, but where do I put this code. would it be in the post.php? Or on a different page? I’m starting in Wordpress, this should run every time I make a new post. I have to send to the server the PUSH notification with the information of the new post.

  • The function is in the functions.php and the conditions in the archive post.php.

  • Got it, it’s working correctly. If I change theme can give problem when running the post.php? Can I do this directly from my theme? That is, change the post.php only when using that theme.

Browser other questions tagged

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