最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Custom Meta Boxes - Nonce Issue - Move to trash issue

programmeradmin2浏览0评论

Recently after updating Wordpress from 4.9.2 to 5.2, I have had to change a good bit of code to get my custom post type listings(or posts) to function and save data correctly. Specifically, with the custom meta boxes I have setup to handle my custom taxonomies(with a select drop down menu) rather than with the default check boxes.

NOTES: I can currently CREATE a new listing, UPDATE a listing, but DELETING the listing I have issues with.

When I go to my listings screen(or Listings custom post type), I try to check multiple check boxes and then click MOVE TO TRASH.

When I move to trash, it gives me the "The link you followed has expired." page. HOWEVER, when I refresh the page to go back to my listings, it appears the listing HAS been moved to the trash, but something is wrong since it shows me the "Link you followed is expired" page.

Any help would be greatly appreciated. This is being developed locally on WAMP, PHP version 7.0.1, Wordpress version 5.2.2 .

TO REVIEW MY CODE, GO TO MY GITHUB AND VIEW THE META_BOXES.PHP FILE.

Screenshots below:

Recently after updating Wordpress from 4.9.2 to 5.2, I have had to change a good bit of code to get my custom post type listings(or posts) to function and save data correctly. Specifically, with the custom meta boxes I have setup to handle my custom taxonomies(with a select drop down menu) rather than with the default check boxes.

NOTES: I can currently CREATE a new listing, UPDATE a listing, but DELETING the listing I have issues with.

When I go to my listings screen(or Listings custom post type), I try to check multiple check boxes and then click MOVE TO TRASH.

When I move to trash, it gives me the "The link you followed has expired." page. HOWEVER, when I refresh the page to go back to my listings, it appears the listing HAS been moved to the trash, but something is wrong since it shows me the "Link you followed is expired" page.

Any help would be greatly appreciated. This is being developed locally on WAMP, PHP version 7.0.1, Wordpress version 5.2.2 .

TO REVIEW MY CODE, GO TO MY GITHUB AND VIEW THE META_BOXES.PHP FILE. https://github/pcross1986/car-dealership

Screenshots below:

Share Improve this question asked Jul 1, 2019 at 6:43 PrestonPreston 114 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I had one more look at the code and I realized the save function was missing couple of checks. So replace meta_boxes.php:366 with this,

if ( empty( $_POST['nonce_car_details'] ) ) {
    return;
}
check_admin_referer( 'save_car_details_meta', 'nonce_car_details' );
if ( ! current_user_can( 'edit_post', $post_id ) ) {
  return;
}
if ( wp_is_post_autosave( $post_id ) ) {
  return;
}
if ( wp_is_post_revision( $post_id ) ) {
  return;
}

The key thing here is the empty check for nonce. Nonce value is probably not set when the post is trashed, which causes check_admin_referer to fail thus printing the error message. My apologies, this was my bad.

You could also switch to using the post type specific save action so the metabox saving functions gets only fired when the correct post type in question.

add_action('save_post_listings', 'wpt_save_details_meta', 1, 2);

P.S. on custom-taxonomies.php lines 3-29 should probably be inside create_listings_taxonomies() along with the other register_taxonomy calls.

发布评论

评论列表(0)

  1. 暂无评论