在wordpress中发布新帖子时发送通知

时间:2015-05-15 13:19:10

标签: php wordpress

现在,当我在WordPress中创建新帖子时,我正在向Android应用程序用户发送通知。但问题在于,它还会在创建草稿并更新帖子时发送通知。我应该在发布新帖子时发出通知的条件?

这是我的代码,位于wp-admin / includes / post.php

function _wp_translate_postdata( $update = false, $post_data = null ) {
    if ( $update)
        $post_data['ID'] = (int) $post_data['post_ID'];

        $post_id =  $post_data['ID'];
        global $wpdb;

        $sel2 = mysql_query("select * from gcm_users");
        while($data1  = mysql_fetch_assoc($sel2)) 
        {

            $key = $data1['gcm_regid'];
            include_once '../blogdroid/config.php';
            include_once '../blogdroid/GCM.php';

            $gcm = new GCM();
            $sel = mysql_query("select * from ".$wpdb->prefix."posts where ID='$post_id'");
            $data = mysql_fetch_assoc($sel);
            $Pname = $data['post_title'];
            $registatoin_ids = array($key);
            if($Pname != 'Auto Draft')
            {
                    $message = array("blog" => 'New Blog Arrived '.$Pname );

                    $result = $gcm->send_notification($registatoin_ids,$message);
            }

        }
}

1 个答案:

答案 0 :(得分:0)

如前所述,你真的不应该编辑WP核心文件。要做你想做的事情,你可以创建一个函数并挂钩post status transitions,codex有一个关于它们如何工作的完美解释。