Make WordPress Core

Ticket #37406: 37406.patch

File 37406.patch, 1.4 KB (added by sgarza, 7 years ago)

Added suggested patch

  • wp-admin/includes/post.php

     
    664664}
    665665
    666666/**
    667  * Determine if a post exists based on title, content, and date
     667 * Determine if a post exists based on title, content, date and type.
    668668 *
    669669 * @since 2.0.0
    670670 *
     
    673673 * @param string $title Post title
    674674 * @param string $content Optional post content
    675675 * @param string $date Optional post date
     676 * @param string type Optional post type
    676677 * @return int Post ID if post exists, 0 otherwise.
    677678 */
    678 function post_exists($title, $content = '', $date = '') {
     679function post_exists( $title, $content = '', $date = '', $type = '' ) {
    679680        global $wpdb;
    680681
    681682        $post_title = wp_unslash( sanitize_post_field( 'post_title', $title, 0, 'db' ) );
    682683        $post_content = wp_unslash( sanitize_post_field( 'post_content', $content, 0, 'db' ) );
    683684        $post_date = wp_unslash( sanitize_post_field( 'post_date', $date, 0, 'db' ) );
     685        $post_type = wp_unslash( sanitize_post_field( 'post_type', $type, 0, 'db' ) );
    684686
    685687        $query = "SELECT ID FROM $wpdb->posts WHERE 1=1";
    686688        $args = array();
     
    699701                $query .= ' AND post_content = %s';
    700702                $args[] = $post_content;
    701703        }
     704       
     705        if ( !empty ( $type ) ) {
     706    $query .= ' AND post_type = %s';
     707    $args[] = $post_type;
     708  }
    702709
    703710        if ( !empty ( $args ) )
    704711                return (int) $wpdb->get_var( $wpdb->prepare($query, $args) );