Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#43362 closed defect (bug) (invalid)

wp-cron duplicate wp_insert_post

Reported by: jblara25 Owned by:
Priority: normal Milestone:
Component: Cron API Version: 4.9.4
Severity: normal Keywords:
Cc: Focuses: administration

Description

When trigger wp-cron to run. I found out that every post title with the tag < and > will be duplicate more. But if I will run it in the plugin itself, It`s not duplicating.
Any solution for this really appreciated. Thank you.
Here`s the function below :

<?php
function process_movie($movie){
    $already_insert = false;
    //check if movie already exist
    $movie_post = get_page_by_title($movie['MovieTitle'],OBJECT,'movieinfo');
    $movie_status =  get_post_status($movie_post->ID);
    if($movie_post->post_title == $movie['MovieTitle']){
         $already_insert = true;
        $movie_post_id = $movie_post->ID;
    }
    if( get_page_by_title($movie['MovieTitle'],OBJECT,'movieinfo') && $movie_status != 'trash'){
        $movie_post_id = $movie_post->ID;
    }
    else{

        $movie_post_id = $this->save_movie($movie);
    }

    return $movie_post_id;
}


function save_movie($movie){

    $postarr = array(
            "post_title"  => $movie['MovieTitle'],
            'post_type' => 'movieinfo',
            'post_status'=> 'publish'
    );
    $movie_post_id = wp_insert_post($postarr);

    foreach ($movie as $field_name => $value) {
        if(empty($value)){
            $value = '';
        }
        $field_key = array_search($field_name,$this->movieinfo_field_keys);
        update_field($field_key, $value, $movie_post_id);

    }
    unset($field_name);
    unset($value);

    return $movie_post_id;
}

Change History (1)

#1 @dd32
8 years ago

  • Milestone Awaiting Review
  • Resolutioninvalid
  • Status newclosed

Hi @jblara25,

The issue you're probably running into is Unfiltered HTML - If you're inserting < into the post_title it's probably being interprated as HTML and stripped. When running in the cron, it has no user context (So no HTML by default) but when run manually it's being run as an Administrator (which has HTML capabilities).
Encode your post_title or escape it and you'll probably find it'll stop happening.

However - WordPress trac is for reporting bugs in the open-source software WordPress, this appears to be a plugin/custom code issue. For further support the volunteers in the Support forums: https://wordpress.org/support/ may be able to help.

As this isn't obviously a core bug, I'm marking this as invalid. If you're able to reproduce the issue with a minimal code sniplet, please re-open it with further details which shows it's a core bug.

Note: See TracTickets for help on using tickets.