Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../themes/Divi/includes/builder/feature
File: search-posts.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Handle ajax requests to search for posts.
[2] Fix | Delete
*
[3] Fix | Delete
* @since 3.26.7
[4] Fix | Delete
*
[5] Fix | Delete
* @return void
[6] Fix | Delete
*/
[7] Fix | Delete
function et_builder_ajax_search_posts() {
[8] Fix | Delete
et_core_security_check( 'edit_posts', 'et_builder_search_posts', 'nonce', '_GET' );
[9] Fix | Delete
[10] Fix | Delete
$current_page = isset( $_GET['page'] ) ? (int) $_GET['page'] : 0;
[11] Fix | Delete
$current_page = max( $current_page, 1 );
[12] Fix | Delete
$post_type = isset( $_GET['post_type'] ) ? sanitize_text_field( $_GET['post_type'] ) : '';
[13] Fix | Delete
$value = isset( $_GET['value'] ) ? sanitize_text_field( $_GET['value'] ) : '';
[14] Fix | Delete
$search = isset( $_GET['search'] ) ? sanitize_text_field( $_GET['search'] ) : '';
[15] Fix | Delete
$prepend_value = (int)$value > 0;
[16] Fix | Delete
$results_per_page = 20;
[17] Fix | Delete
$results = array(
[18] Fix | Delete
'results' => array(),
[19] Fix | Delete
'meta' => array(),
[20] Fix | Delete
);
[21] Fix | Delete
$include_current_post = '1' === (string) et_()->array_get( $_GET, 'include_current_post', '0' );
[22] Fix | Delete
$include_latest_post = '1' === (string) et_()->array_get( $_GET, 'include_latest_post', '0' );
[23] Fix | Delete
[24] Fix | Delete
$public_post_types = et_builder_get_public_post_types();
[25] Fix | Delete
[26] Fix | Delete
if ( ! isset( $public_post_types[ $post_type ] ) ) {
[27] Fix | Delete
$post_type = 'post';
[28] Fix | Delete
}
[29] Fix | Delete
[30] Fix | Delete
$post_type_object = get_post_type_object( $post_type );
[31] Fix | Delete
$post_type_label = $post_type_object ? $post_type_object->labels->singular_name : '';
[32] Fix | Delete
[33] Fix | Delete
$query = array(
[34] Fix | Delete
'post_type' => $post_type,
[35] Fix | Delete
'posts_per_page' => $results_per_page,
[36] Fix | Delete
'post_status' => 'attachment' === $post_type ? 'inherit' : 'publish',
[37] Fix | Delete
's' => $search,
[38] Fix | Delete
'orderby' => 'date',
[39] Fix | Delete
'order' => 'desc',
[40] Fix | Delete
'paged' => $current_page,
[41] Fix | Delete
);
[42] Fix | Delete
[43] Fix | Delete
if ( $prepend_value ) {
[44] Fix | Delete
$value_post = get_post( $value );
[45] Fix | Delete
[46] Fix | Delete
if ( $value_post && 'publish' === $value_post->post_status && $value_post->post_type === $post_type ) {
[47] Fix | Delete
$results['results'][] = array(
[48] Fix | Delete
'value' => $value,
[49] Fix | Delete
'label' => et_core_intentionally_unescaped( strip_tags( $value_post->post_title ), 'react_jsx' ),
[50] Fix | Delete
'meta' => array(
[51] Fix | Delete
'post_type' => et_core_intentionally_unescaped( $post_type_label, 'react_jsx' ),
[52] Fix | Delete
),
[53] Fix | Delete
);
[54] Fix | Delete
[55] Fix | Delete
// We will manually prepend the current value so we need to reduce the number of results.
[56] Fix | Delete
$query['posts_per_page'] -= 1;
[57] Fix | Delete
$query['post__not_in'] = array( $value );
[58] Fix | Delete
}
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
if ( 'attachment' === $post_type ) {
[62] Fix | Delete
add_filter( 'posts_join' , 'et_builder_ajax_search_posts_query_join' );
[63] Fix | Delete
add_filter( 'posts_where' , 'et_builder_ajax_search_posts_query_where' );
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
$posts = new WP_Query( $query );
[67] Fix | Delete
[68] Fix | Delete
if ( 'attachment' === $post_type ) {
[69] Fix | Delete
remove_filter( 'posts_join' , 'et_builder_ajax_search_posts_query_join' );
[70] Fix | Delete
remove_filter( 'posts_where' , 'et_builder_ajax_search_posts_query_where' );
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
if ( $include_current_post && ! empty( $posts->posts ) ) {
[74] Fix | Delete
$current_post_type = sanitize_text_field( et_()->array_get( $_GET, 'current_post_type', 'post' ) );
[75] Fix | Delete
$current_post_type = isset( $public_post_types[ $current_post_type ] ) ? $current_post_type : 'post';
[76] Fix | Delete
$current_post_type_object = get_post_type_object( $current_post_type );
[77] Fix | Delete
$current_post_type_label = $current_post_type_object ? $current_post_type_object->labels->singular_name : '';
[78] Fix | Delete
[79] Fix | Delete
$results['results'][] = array(
[80] Fix | Delete
'value' => 'current',
[81] Fix | Delete
// Translators: %1$s: Post type singular name.
[82] Fix | Delete
'label' => et_core_intentionally_unescaped( sprintf( __( 'This %1$s', 'et_builder' ), $current_post_type_label ), 'react_jsx' ),
[83] Fix | Delete
'meta' => array(
[84] Fix | Delete
'post_type' => et_core_intentionally_unescaped( $current_post_type_label, 'react_jsx' ),
[85] Fix | Delete
),
[86] Fix | Delete
);
[87] Fix | Delete
[88] Fix | Delete
$query['posts_per_page'] -= 1;
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
if ( $include_latest_post && ! empty( $posts->posts ) ) {
[92] Fix | Delete
$results['results'][] = array(
[93] Fix | Delete
'value' => 'latest',
[94] Fix | Delete
// Translators: %1$s: Post type singular name.
[95] Fix | Delete
'label' => et_core_intentionally_unescaped( sprintf( __( 'Latest %1$s', 'et_builder' ),
[96] Fix | Delete
$post_type_label ), 'react_jsx' ),
[97] Fix | Delete
'meta' => array(
[98] Fix | Delete
'post_type' => et_core_intentionally_unescaped( $post_type_label, 'react_jsx' ),
[99] Fix | Delete
),
[100] Fix | Delete
);
[101] Fix | Delete
[102] Fix | Delete
$query['posts_per_page'] -= 1;
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
foreach ( $posts->posts as $post ) {
[106] Fix | Delete
$results['results'][] = array(
[107] Fix | Delete
'value' => (int) $post->ID,
[108] Fix | Delete
'label' => et_core_intentionally_unescaped( strip_tags( $post->post_title ), 'react_jsx' ),
[109] Fix | Delete
'meta' => array(
[110] Fix | Delete
'post_type' => et_core_intentionally_unescaped( $post_type_label, 'react_jsx' ),
[111] Fix | Delete
),
[112] Fix | Delete
);
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
$results['meta']['pagination'] = array(
[116] Fix | Delete
'results' => array(
[117] Fix | Delete
'per_page' => (int) $results_per_page,
[118] Fix | Delete
'total' => (int) $posts->found_posts,
[119] Fix | Delete
),
[120] Fix | Delete
'pages' => array(
[121] Fix | Delete
'current' => (int) $current_page,
[122] Fix | Delete
'total' => (int) $posts->max_num_pages,
[123] Fix | Delete
),
[124] Fix | Delete
);
[125] Fix | Delete
[126] Fix | Delete
wp_send_json_success( $results );
[127] Fix | Delete
}
[128] Fix | Delete
add_action( 'wp_ajax_et_builder_search_posts', 'et_builder_ajax_search_posts' );
[129] Fix | Delete
[130] Fix | Delete
/**
[131] Fix | Delete
* Join the parent post for attachments queries.
[132] Fix | Delete
*
[133] Fix | Delete
* @since 3.27.3
[134] Fix | Delete
*
[135] Fix | Delete
* @param string $join
[136] Fix | Delete
*
[137] Fix | Delete
* @return string
[138] Fix | Delete
*/
[139] Fix | Delete
function et_builder_ajax_search_posts_query_join( $join ) {
[140] Fix | Delete
global $wpdb;
[141] Fix | Delete
[142] Fix | Delete
$join .= " LEFT JOIN `$wpdb->posts` AS `parent` ON `parent`.`ID` = `$wpdb->posts`.`post_parent` ";
[143] Fix | Delete
[144] Fix | Delete
return $join;
[145] Fix | Delete
}
[146] Fix | Delete
[147] Fix | Delete
/**
[148] Fix | Delete
* Filter attachments based on the parent post status, if any.
[149] Fix | Delete
*
[150] Fix | Delete
* @since 3.27.3
[151] Fix | Delete
*
[152] Fix | Delete
* @param string $where
[153] Fix | Delete
*
[154] Fix | Delete
* @return string
[155] Fix | Delete
*/
[156] Fix | Delete
function et_builder_ajax_search_posts_query_where( $where ) {
[157] Fix | Delete
global $wpdb;
[158] Fix | Delete
[159] Fix | Delete
$public_post_types = array_keys( et_builder_get_public_post_types() );
[160] Fix | Delete
[161] Fix | Delete
// Add an empty value to:
[162] Fix | Delete
// - Avoid syntax error for `IN ()` when there are no public post types.
[163] Fix | Delete
// - Cause the query to only return posts with no parent when there are no public post types.
[164] Fix | Delete
$public_post_types[] = '';
[165] Fix | Delete
[166] Fix | Delete
$where .= $wpdb->prepare( " AND (
[167] Fix | Delete
`parent`.`ID` IS NULL OR (
[168] Fix | Delete
`parent`.`post_status` = %s
[169] Fix | Delete
AND
[170] Fix | Delete
`parent`.`post_type` IN (" . implode( ',', array_fill( 0, count( $public_post_types ), '%s' ) ) . ")
[171] Fix | Delete
)
[172] Fix | Delete
)", array_merge( array( "publish" ), $public_post_types ) );
[173] Fix | Delete
[174] Fix | Delete
return $where;
[175] Fix | Delete
}
[176] Fix | Delete
[177] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function