Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/wpadverts/addons/contact-form/contact-form.php
+++ b/wpadverts/addons/contact-form/contact-form.php
@@ -539,7 +539,7 @@
"errors" => $errors
);
- echo json_encode( $response );
+ wp_send_json( $response );
exit;
}
--- a/wpadverts/addons/payments/includes/ajax.php
+++ b/wpadverts/addons/payments/includes/ajax.php
@@ -32,7 +32,7 @@
$nonce = sprintf( "adext-payment-%d-%d-%d", $payment_id, $listing_id, $object_id );
if( ! wp_verify_nonce( adverts_request( "nonce" ), $nonce ) ) {
- echo json_encode([
+ wp_send_json([
"result" => 0,
"html" => sprintf('<div>%s</div>', __("Incorrect user nonce.","wpadverts")),
"execute" => null
@@ -41,7 +41,7 @@
}
if( get_post_type( $payment_id ) !== "adverts-payment" ) {
- echo json_encode([
+ wp_send_json([
"result" => 0,
"html" => sprintf('<div>%s</div>', __("Incorrect object type.","wpadverts")),
"execute" => null
@@ -50,7 +50,7 @@
}
if( absint( get_post( $payment_id )->post_author ) !== absint( get_current_user_id() ) ) {
- echo json_encode([
+ wp_send_json([
"result" => 0,
"html" => sprintf('<div>%s</div>', __("You do not own this payment.","wpadverts")),
"execute" => null
@@ -123,7 +123,7 @@
);
}
- echo json_encode( $response );
+ wp_send_json( $response );
exit;
}
--- a/wpadverts/includes/ajax.php
+++ b/wpadverts/includes/ajax.php
@@ -126,7 +126,7 @@
}
- echo json_encode($status);
+ wp_send_json($status);
exit;
}
@@ -138,7 +138,7 @@
}
if( isset( $args["ignore-post-id"] ) && $args["ignore-post-id"] ) {
- echo json_encode( adverts_upload_file_data( $status, $post, $v->get_uniquid() ) );
+ wp_send_json( adverts_upload_file_data( $status, $post, $v->get_uniquid() ) );
exit;
}
@@ -146,7 +146,7 @@
if( $v->is_file() ) {
// move to "id" folder
- echo json_encode( adverts_upload_file_data( $status, $post, $v->get_uniquid() ) );
+ wp_send_json( adverts_upload_file_data( $status, $post, $v->get_uniquid() ) );
exit;
} else {
@@ -211,7 +211,7 @@
include_once ADVERTS_PATH . 'includes/gallery.php';
- echo json_encode( adverts_upload_item_data( $attach_id ) );
+ wp_send_json( adverts_upload_item_data( $attach_id ) );
exit;
}
};
@@ -242,7 +242,7 @@
$attach = get_post( $attach_id );
if( $attach->post_parent != $post_id ) {
- echo json_encode( array(
+ wp_send_json( array(
"result" => 0,
"error" => __( "Incorrect Post or Attachment ID.", "wpadverts" )
) );
@@ -256,7 +256,7 @@
));
if($result instanceof WP_Error) {
- echo json_encode( array( "result" => 0, "error" => $result->get_error_message() ) );
+ wp_send_json( array( "result" => 0, "error" => $result->get_error_message() ) );
exit;
}
@@ -268,7 +268,7 @@
delete_post_meta( $post_id, '_thumbnail_id' );
}
- echo json_encode( array( "result" => 1, "file" => adverts_upload_item_data( $attach_id ) ) );
+ wp_send_json( array( "result" => 1, "file" => adverts_upload_item_data( $attach_id ) ) );
exit;
}
@@ -313,7 +313,7 @@
update_post_meta( $post_id, $meta_key, $clean_ordered_keys_json );
- echo json_encode( array( "result" => 1 ) );
+ wp_send_json( array( "result" => 1 ) );
exit;
}
@@ -336,13 +336,13 @@
_adverts_ajax_check_post_ownership( $attach->post_parent );
if ( $attach === null ) {
- echo json_encode( array( "result" => 0, "error" => __( "Attachment does not exist.", "wpadverts" ) ) );
+ wp_send_json( array( "result" => 0, "error" => __( "Attachment does not exist.", "wpadverts" ) ) );
} elseif ( $attach->post_parent != absint( $post_id ) ) {
- echo json_encode( array( "result" => 0, "error" => __( "Incorrect attachment ID.", "wpadverts" ) ) );
+ wp_send_json( array( "result" => 0, "error" => __( "Incorrect attachment ID.", "wpadverts" ) ) );
} elseif ( wp_delete_attachment( $attach_id ) ) {
- echo json_encode( array( "result" => 1 ) );
+ wp_send_json( array( "result" => 1 ) );
} else {
- echo json_encode( array( "result" => 0, "error" => __( "File could not be deleted.", "wpadverts" ) ) );
+ wp_send_json( array( "result" => 0, "error" => __( "File could not be deleted.", "wpadverts" ) ) );
}
exit;
@@ -383,7 +383,7 @@
}
if( $field === null ) {
- echo json_encode( array( "result" => 0, "error" => __( "Incorrect field name.", "wpadverts" ) ) );
+ wp_send_json( array( "result" => 0, "error" => __( "Incorrect field name.", "wpadverts" ) ) );
exit;
}
@@ -411,7 +411,7 @@
} else if( file_exists( $file_tmp ) ) {
$file = $file_tmp;
} else {
- echo json_encode( array( "result" => 0, "error" => __( "File does not exist.", "wpadverts" ), "args" => array() ) );
+ wp_send_json( array( "result" => 0, "error" => __( "File does not exist.", "wpadverts" ), "args" => array() ) );
exit;
}
@@ -425,7 +425,7 @@
$files = glob( $file . "/*" );
} while( empty( $files ) );
- echo json_encode( array( "result" => 1 ) );
+ wp_send_json( array( "result" => 1 ) );
exit;
}
@@ -445,7 +445,7 @@
$post_id = _adverts_ajax_verify_post_id( true );
if( ! adverts_user_can_edit_image() ) {
- echo json_encode( array(
+ wp_send_json( array(
"result" => 0,
"error" => __( "You cannot edit images.", "wpadverts" )
) );
@@ -461,7 +461,7 @@
_adverts_ajax_check_post_ownership( $post_id );
if( $attach->post_parent != $post_id ) {
- echo json_encode( array(
+ wp_send_json( array(
"result" => 0,
"error" => __( "Incorrect Post or Attachment ID.", "wpadverts" )
) );
@@ -497,7 +497,7 @@
$image = wp_get_image_editor( $attached_file );
if( is_wp_error($image) ) {
- echo json_encode( array(
+ wp_send_json( array(
"result" => 0,
"error" => $image->get_error_message()
) );
@@ -542,7 +542,7 @@
$post_id = _adverts_ajax_verify_post_id( true );
if( ! adverts_user_can_edit_image() ) {
- echo json_encode( array(
+ wp_send_json( array(
"result" => 0,
"error" => __( "You cannot edit images.", "wpadverts" )
) );
@@ -557,7 +557,7 @@
$attach = get_post( $attach_id );
if( $attach->post_parent != $post_id ) {
- echo json_encode( array(
+ wp_send_json( array(
"result" => 0,
"error" => __( "Incorrect Post or Attachment ID.", "wpadverts" )
) );
@@ -591,7 +591,7 @@
$result->result = 1;
$result->file = adverts_upload_item_data( $attach_id );
- echo json_encode( $result );
+ wp_send_json( $result );
exit;
}
@@ -613,7 +613,7 @@
$post_id = _adverts_ajax_verify_post_id( true );
if( ! adverts_user_can_edit_image() ) {
- echo json_encode( array(
+ wp_send_json( array(
"result" => 0,
"error" => __( "You cannot edit images.", "wpadverts" )
) );
@@ -633,7 +633,7 @@
_adverts_ajax_check_post_ownership( $post_id );
if( $attach->post_parent != $post_id ) {
- echo json_encode( array(
+ wp_send_json( array(
"result" => 0,
"error" => __( "Incorrect Post or Attachment ID.", "wpadverts" )
) );
@@ -661,7 +661,7 @@
$image = wp_get_image_editor( $attached_file );
if( is_wp_error($image) ) {
- echo json_encode( array(
+ wp_send_json( array(
"result" => 0,
"error" => $image->get_error_message()
) );
@@ -722,7 +722,7 @@
$saved = $image->save( $new_path );
if(!$saved) {
- echo json_encode( array(
+ wp_send_json( array(
"result" => 0,
"error" => $image->get_error_message()
) );
@@ -809,7 +809,7 @@
$return->result = 1;
$return->file = adverts_upload_item_data( $attach_id );
- echo json_encode( $return );
+ wp_send_json( $return );
exit;
}
@@ -833,7 +833,7 @@
$post_id = _adverts_ajax_verify_post_id( true );
if( ! adverts_user_can_edit_image() ) {
- echo json_encode( array(
+ wp_send_json( array(
"result" => 0,
"error" => __( "You cannot edit images.", "wpadverts" )
) );
@@ -846,7 +846,7 @@
_adverts_ajax_check_post_ownership( $post_id );
if( $attach->post_parent != $post_id ) {
- echo json_encode( array(
+ wp_send_json( array(
"result" => 0,
"error" => __( "Incorrect Post or Attachment ID.", "wpadverts" )
) );
@@ -876,7 +876,7 @@
$ifp = @ fopen( $new_file, 'wb' );
if ( ! $ifp ) {
- echo json_encode( array(
+ wp_send_json( array(
"result" => 0,
"error" => sprintf( __( 'Could not write file %s' ), $new_file_name )
) );
@@ -903,7 +903,7 @@
// file not readable, delete it
wp_delete_file( $new_file );
- echo json_encode( array(
+ wp_send_json( array(
"result" => 0,
"error" => $image->get_error_message()
) );
@@ -950,7 +950,7 @@
$file = $image->save( dirname( $new_file ) . "/" . $interm_file_name );
if( is_wp_error( $file ) ) {
- echo json_encode( array(
+ wp_send_json( array(
"result" => 0,
"error" => $file->get_error_message()
) );
@@ -967,7 +967,7 @@
wp_update_attachment_metadata( $attach_id, $meta );
- echo json_encode( array(
+ wp_send_json( array(
"result" => 1,
"file" => adverts_upload_item_data( $attach_id )
) );
@@ -995,7 +995,7 @@
$nonce = sprintf( "wpadverts-show-contact-info--%d", absint( $id ) );
if( ! wp_verify_nonce( $security, $nonce ) ) {
- echo json_encode( array(
+ wp_send_json( array(
'result' => 0,
'error' => __("Invalid Nonce.", "wpadverts")
));
@@ -1003,7 +1003,7 @@
}
if( $post === null || ! wpadverts_post_type( $post ) ) {
- echo json_encode( array(
+ wp_send_json( array(
'result' => 0,
'error' => __("Post with given ID does not exist.", "wpadverts")
));
@@ -1033,9 +1033,9 @@
);
}
- echo json_encode( $result );
+ wp_send_json( $result );
} else {
- echo json_encode( array(
+ wp_send_json( array(
'result' => 1,
'email' => esc_html( get_post_meta( $id, 'adverts_email', true ) ),
'phone' => esc_html( get_post_meta( $id, 'adverts_phone', true ) )
@@ -1064,7 +1064,7 @@
$post = get_post($id);
if( $post === null || $post->post_status != adverts_tmp_post_status()) {
- echo json_encode( array(
+ wp_send_json( array(
'result' => 0,
'error' => __("Post with given ID does not exist.", "wpadverts")
));
@@ -1082,7 +1082,7 @@
adverts_delete_post( $id );
- echo json_encode( array(
+ wp_send_json( array(
'result' => 1
));
@@ -1126,7 +1126,7 @@
}
if( empty( $fields ) ) {
- echo json_encode( array( "result" => -1 ) );
+ wp_send_json( array( "result" => -1 ) );
exit;
}
@@ -1164,7 +1164,7 @@
} // endforeach
}
- echo json_encode( array( "result" => 1 ) );
+ wp_send_json( array( "result" => 1 ) );
exit;
}
@@ -1226,7 +1226,7 @@
if( $result !== null ) {
if( $is_ajax ) {
- echo json_encode( $result );
+ wp_send_json( $result );
exit;
} else {
wp_die( $result["error"] );
@@ -1249,7 +1249,7 @@
if(adverts_request("redirect_to") ) {
wp_redirect( adverts_request( "redirect_to" ) );
} else if( $is_ajax ) {
- echo json_encode( array(
+ wp_send_json( array(
"result" => 1,
"message" => sprintf( __( "Advert <strong>%s</strong> deleted.", "wpadverts" ), $post_title )
) );
@@ -1267,7 +1267,7 @@
if( ! current_user_can( "manage_options" ) ) {
$response["error"] = __( "You cannot access this page.", "wpadverts" );
- echo json_encode( $response );
+ wp_send_json( $response );
exit;
}
@@ -1276,7 +1276,7 @@
if( ! in_array( adverts_request( "param" ), $keys ) ) {
$response["error"] = __( "Invalid param name.", "wpadverts" );
- echo json_encode( $response );
+ wp_send_json( $response );
exit;
}
@@ -1301,7 +1301,7 @@
$response["status"] = 1;
- echo json_encode( $response );
+ wp_send_json( $response );
exit;
}
@@ -1314,7 +1314,7 @@
if( ! current_user_can( "manage_options" ) ) {
$response["error"] = __( "You cannot access this page.", "wpadverts" );
- echo json_encode( $response );
+ wp_send_json( $response );
exit;
}
@@ -1323,7 +1323,7 @@
if( ! in_array( adverts_request( "param" ), $keys ) ) {
$response["error"] = __( "Invalid param name.", "wpadverts" );
- echo json_encode( $response );
+ wp_send_json( $response );
exit;
}
@@ -1342,6 +1342,6 @@
$response["status"] = 1;
- echo json_encode( $response );
+ wp_send_json( $response );
exit;
}
No newline at end of file
--- a/wpadverts/includes/class-field-autocomplete.php
+++ b/wpadverts/includes/class-field-autocomplete.php
@@ -190,7 +190,7 @@
), $term );
}
- echo json_encode( $response );
+ wp_send_json( $response );
exit;
}
}
No newline at end of file
--- a/wpadverts/includes/functions.php
+++ b/wpadverts/includes/functions.php
@@ -3179,7 +3179,7 @@
$error = __( "Checksum does not exist. Please refresh the page and try again.", "wpadverts" );
}
- echo json_encode( array(
+ wp_send_json( array(
"result" => 0,
"error" => $error
) );
@@ -3230,7 +3230,7 @@
$post_id_nonce = adverts_request( "_post_id_nonce" );
if( $post_id > 0 && ! wp_verify_nonce( $post_id_nonce, "wpadverts-publish-" . $post_id ) ) {
- echo json_encode( array(
+ wp_send_json( array(
"result" => 0,
"error" => sprintf( __( "It seems you are not the post %d author. Please refresh the page and try again.", "wpadverts" ), $post_id )
) );
@@ -3238,7 +3238,7 @@
}
if( $is_required && $post_id < 1 ) {
- echo json_encode( array(
+ wp_send_json( array(
"result" => 0,
"error" => __( "Post ID not provided.", "wpadverts" )
) );
@@ -3274,7 +3274,7 @@
);
if( $return !== false ) {
- echo json_encode( $result );
+ wp_send_json( $result );
exit;
} else {
return $result;
@@ -3304,7 +3304,7 @@
if( $result !== null ) {
if( $return !== false ) {
- echo json_encode( $result );
+ wp_send_json( $result );
exit;
} else {
return $result;
@@ -3320,7 +3320,7 @@
}
if( $return !== false ) {
- echo json_encode( $result );
+ wp_send_json( $result );
exit;
} else {
return $result;
--- a/wpadverts/includes/shortcodes.php
+++ b/wpadverts/includes/shortcodes.php
@@ -680,14 +680,16 @@
return sprintf( "<strong>ERROR</strong> Only posts of type %s are allowed (%s given).", join(", ", $allowed_types), esc_html( $post->post_type ) );
}
- $allowed_stats = ["publish"];
+ if( apply_filters( "wpadverts_allow_unsafe_templates", false ) === false ) {
+ $allowed_stats = ["publish"];
- if( apply_filters( "wpadverts_allow_draft_templates", false ) === true ) {
- $allowed_stats[] = "draft";
- }
+ if( apply_filters( "wpadverts_allow_draft_templates", false ) === true ) {
+ $allowed_stats[] = "draft";
+ }
- if( !in_array( $post->post_status, $allowed_stats ) ) {
- return sprintf( "<strong>ERROR</strong> Only pages with status '%s' can be used as templates.", join( "', '", $allowed_stats ) );
+ if( !in_array( $post->post_status, $allowed_stats ) ) {
+ return sprintf( "<strong>ERROR</strong> Only pages with status '%s' can be used as templates.", join( "', '", $allowed_stats ) );
+ }
}
$post_content = get_post( $post_id )->post_content;
@@ -746,14 +748,16 @@
return sprintf( "<strong>ERROR</strong> Only posts of type %s are allowed (%s given).", join(", ", $allowed_types), esc_html( $post->post_type ) );
}
- $allowed_stats = ["publish"];
+ if( apply_filters( "wpadverts_allow_unsafe_templates", false ) === false ) {
+ $allowed_stats = ["publish"];
- if( apply_filters( "wpadverts_allow_draft_templates", false ) === true ) {
- $allowed_stats[] = "draft";
- }
+ if( apply_filters( "wpadverts_allow_draft_templates", false ) === true ) {
+ $allowed_stats[] = "draft";
+ }
- if( !in_array( $post->post_status, $allowed_stats ) ) {
- return sprintf( "<strong>ERROR</strong> Only pages with status '%s' can be used as templates.", join( "', '", $allowed_stats ) );
+ if( !in_array( $post->post_status, $allowed_stats ) ) {
+ return sprintf( "<strong>ERROR</strong> Only pages with status '%s' can be used as templates.", join( "', '", $allowed_stats ) );
+ }
}
return do_blocks( $post->post_content );
--- a/wpadverts/wpadverts.php
+++ b/wpadverts/wpadverts.php
@@ -6,7 +6,7 @@
* Author: Greg Winiarski
* Text Domain: wpadverts
* Domain Path: /languages
- * Version: 2.3.1
+ * Version: 2.3.2
*
* Adverts is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by