public static function delete_duplicate(&$post)
 {
     global $wpdb;
     $key = isset($post['sp_key']) ? $post['sp_key'] : null;
     if (!$key) {
         $key = $post['post_title'];
     }
     $id = sp_array_value($post, 'post_ID', 'var');
     $title = sp_get_eos_safe_slug($key, $id);
     $check_sql = "SELECT ID FROM {$wpdb->posts} WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1";
     $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $title, $post['post_type'], $id));
     if ($post_name_check) {
         wp_delete_post($post_name_check, true);
         $post['post_status'] = 'draft';
     }
     return $post_name_check;
 }
function prosports_get_eos_safe_slug($title, $post_id = 'var')
{
    return sp_get_eos_safe_slug($title, $post_id);
}
 public static function get_post_array($post = array(), $post_type = null)
 {
     $post_array = array();
     if (is_string($post)) {
         $post_array['post_title'] = $post;
         $post_array['post_name'] = sp_get_eos_safe_slug($post_array['post_title']);
     } elseif (is_array($post)) {
         if (!array_key_exists('name', $post)) {
             $post_array = array();
         }
         $post_array['post_title'] = $post['name'];
         $post_array['post_name'] = sp_array_value($post, 'id', sp_get_eos_safe_slug($post_array['post_title']));
     }
     // Return empty array if post with same slug already exists
     if (get_page_by_path($post_array['post_name'], OBJECT, $post_type)) {
         return array();
     }
     // Set post type
     $post_array['post_type'] = $post_type;
     // Add post excerpt
     if (is_array($post) && array_key_exists('description', $post)) {
         $post_array['post_excerpt'] = $post['description'];
     }
     return $post_array;
 }
function sportspress_sanitize_title($title)
{
    if (isset($_POST) && array_key_exists('taxonomy', $_POST)) {
        return $title;
    } elseif (isset($_POST) && array_key_exists('post_type', $_POST) && is_sp_config_type($_POST['post_type'])) {
        $key = isset($_POST['sp_key']) ? $_POST['sp_key'] : null;
        if (!$key) {
            $key = isset($_POST['sp_default_key']) ? $_POST['sp_default_key'] : null;
        }
        if (!$key) {
            $key = $_POST['post_title'];
        }
        $id = sp_array_value($_POST, 'post_ID', 'var');
        $title = sp_get_eos_safe_slug($key, $id);
    } elseif (isset($_POST) && array_key_exists('post_type', $_POST) && $_POST['post_type'] == 'sp_event') {
        // Auto slug generation
        if ($_POST['post_title'] == '' && ($_POST['post_name'] == '' || is_int($_POST['post_name']))) {
            $title = '';
        }
    }
    return $title;
}