Wordpress - Execute Command on New Post

陌路散爱 提交于 2019-12-25 06:50:13

问题


I have a localhost installed version of the latest WordPress on my server, and have begun designing my own plug, but am trying to learn a bit more about how WordPress works first.

I'm currently looking for a method to execute a terminal command (or just an application that runs on the server) every time a new post has been created. Even better if possible, to run a different command depending on what category the post was made in. Is something like this possible? Thanks in advance!


回答1:


Try writing the function and using the action hook with publish_post as described here http://codex.wordpress.org/Plugin_API/Action_Reference

So it would be like this:

<?php
    function my_custom_function(){
        //stuff to do on new post
    }
    add_action('publish_post', 'my_custom_function');
?>

Hope this helps. I am not sure about the terminal execution but @thenetimp seems to have a handle on that.




回答2:


You'd use the php command exec() or shell_exec() they are both slightly different please read the docs on both.

http://php.net/manual/en/function.shell-exec.php



来源:https://stackoverflow.com/questions/9181688/wordpress-execute-command-on-new-post

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!