Идентификатор будущей должности не отображается


Я пытаюсь отправить уведомление по электронной почте, когда публикуется запланированная публикация. Я пробовал довольно много разных способов. Я получаю электронное письмо, но идентификатор (и другие случайные данные) не публикуются вместе с ним. Есть ли что-то, чего мне принципиально не хватает в этом коде? Я пробовал и снаружи, и внутри, и еще несколькими способами. Сообщение dap - это вымышленный пользовательский тип сообщения, который я изначально тестировал, а затем подумал, что это могут быть пользовательские типы сообщений.

Поэтому я использовал обычную почту и ничего. Я также отключил все плагины, кроме того, который содержит приведенный ниже код. По-прежнему ничего не получалось. Я смогу увидеть подробности, если опубликую их немедленно, но не с того момента, когда это запланировано.

add_action( 'init', 'create_dap_post_types' );

function create_dap_post_types() {
    register_post_type( 'dap', 
        array(
            'labels' => array(
                'name' => __( 'Daps' ),
                'singular_name' => __( 'Dap' )
            ),
            'public' => true,
        )
    );
}



function status_changes( $new_status, $old_status, $post ) {
 global $post;
 global $wpdb;
 global $wp_query;

 if ($new_status == 'publish') {
    //$post = get_post($id);
        $id = get_the_ID();
    $post = get_post($id);
    $post_title = $post->post_title;
      // $author = get_userdata($post->post_author);
     // the rest of your function here
     $link = get_permalink($post->ID);
    $date = mysql2date('M j Y', $post->post_date);
    $category = get_the_category($post->ID);
    //$category = $category[0]->cat_name;

    $to = "//left blank to void out email";
    $subject = $post_title;
    $message = "<br><h1> schedulenotificte </h1></br> Let's begin: author " . //$author .
                " the link? " . $link;
    wp_mail( $to, $subjet, $message);
 }


}  
//add_action( 'transition_post_status', 'status_changes', 100, 3 );


add_action('publish_'. $_POST['post_type'], 'scheduledNotification');
add_action('future_to_publish_dap', 'scheduledNotification');
add_action('new_to_publish_dap', 'scheduledNotification');
add_action('draft_to_publish_dap', 'scheduledNotification');
add_action('pending_to_publish_dap', 'scheduledNotification');
add_action('future_to_publish_dap', 'scheduledNotification');
add_action('auto-draft_to_publish_dap', 'scheduledNotification');
add_action('pending_to_future', 'scheduledNotification');
add_action('approved_to_future', 'scheduledNotification');

function scheduledNotification() {
  global $post;
  global $wp_query;
  $post = $wp_query->post;
  //$post = get_post($id);
  $my_postid = $post->ID;//This is page id or post id
  $content_post = get_post($my_postid);
  $content = $content_post->post_content;
  $content = apply_filters('the_content', $content);
  $content = str_replace(']]>', ']]&gt;', $content);

  $id = get_the_ID();
  $post = get_post($id);

  $link = get_permalink($post->ID);
  $date = mysql2date('M j Y', $post->post_date);
  $category = get_the_category($post->ID);


  $to = "//left blank";
  $subject = $post->post_title;
  $message = "<br><h1> schedulenot </h1></br> <h2><br>Let's begin shall we?:<h2></br>author " . //$author .
            " the link? " . $link . 
            "<br> this is the content </br>" . $content .
            "<br> this is the idea</br>" . $post->ID;
  wp_mail( $to, $subject, $message);
}

function hereIsATest ($post) {
  global $post;
  global $wp_query;
  $post = $wp_query->post;

  $my_postid = $post->ID;//This is page id or post id
  $content_post = get_post($my_postid);
  $content = $content_post->post_content;
  $content = apply_filters('the_content', $content);
  $content = str_replace(']]>', ']]&gt;', $content);



  $subject = $post->title;
  $message = "<br> hereisatest </br> this is the id " . $post->ID . 
        "This is content " . $post->content .
        "<br> the title </br>" . $post->post_title .
        "what else there" . $subject . 
        "<br> id </br>" . get_the_ID() . 
        "<br> id_ </br>" . $post->ID .
        "<br> id </br>" . $post->content_post;
   wp_mail("//blank", $subject , $message);
}

add_action('publish_'. $_POST['post_type'], 'hereIsATest');


add_action( 'transition_post_status', 'inLoop', 100, 3 );
add_action ('wp_transition_post_status', 'inLoop');

function inLoop($new_status, $old_status, $post) {
  global $post;
  $thePostID = $post->ID;

  if ($new_status == 'publish') {
    $to = "blank";
    $subject = $thePostID;
    $message = "<h1> This is insidethe loop</h1>" . $thePostID .
            "<br> the title ////" . get_the_title() .
            "<br> get the title </br>" . get_the_title() . 
            "<br> old status is: </br> " . $old_status . 
            "<br> new status is: </br> " . $new_status . 
            "<br> dump post: </br>" . $rpost;

    wp_mail($to, $subject, $message);
    }
}

add_action( 'transition_post_status', 'outLoop', 100, 3 );
add_action('wp_transition_post_status', 'outLoop');

function outLoop($new_status, $old_status, $post) {
  // Works in single posts outside of the loop
  global $wp_query;

  if ($new_status == 'publish') {
    $thePostID = $wp_query->post->ID;
    //$rpost = print_r($post, true);
    $to = "email";
    $subject = $thePostID;
    $message = "<h1> This is outside the loop</h1>" . $thePostID . 
            "<br> get the title </br>" . get_the_title() . 
            "<br> old status is: </br> " . $old_status . 
            "<br> new status is: </br> " . $new_status . 
            "<br> dump post: </br>";

    wp_mail($to, $subject, $message);
   }

}
Author: Chinmoy Kumar Paul, 2014-09-07

1 answers

Проблема в том, что вы используете get_the_ID() вне цикла. Кроме того, вы получаете global $post, переопределяющий объект $post, переданный функции, а затем переопределяющий его снова с помощью функции get_post(). Поскольку у вас уже есть объект $post, статус которого изменился, вам не нужно ничего из get_the_ID, get_post или global $post. Просто используйте объект $post, который у вас уже есть.

add_action( 'transition_post_status', 'status_changes', 100, 3 );
function status_changes( $new_status, $old_status, $post ) {

    if ($new_status == 'publish') {

        $post_title = $post->post_title;
        $author = get_userdata($post->post_author);
        $link = get_permalink($post->ID);
        $date = mysql2date('M j Y', $post->post_date);
        $category = get_the_category($post->ID);
        $category = $category[0]->cat_name;

        $to = "//left blank to void out email";
        $subject = $post_title;
        $message = "<br><h1> schedulenotificte </h1></br> Let's begin: author " . //$author .
            " the link? " . $link;
        wp_mail( $to, $subjet, $message);
     }


}
 1
Author: cybmeta, 2014-09-07 16:26:34