Skip to content

[Reviews] Extraneous metadata rows added for every post type #887

@actual-saurabh

Description

@actual-saurabh

The review metadata saving is hooked into saved posts and no post type is checked in

add_action( 'save_post', array( $this, 'save_review_meta_boxes' ) );
and
/**
* This function handles the logic to save the information that is contained
* in the custom metabox. It looks at each of the values, then makes sure that
* there are proper default values so that the program doesn't go crashy crashy
* (nobody likes crashy crashy)
*
* @return void
*/
public function save_review_meta_boxes() {
$enabled = (isset( $_POST['_llms_reviews_enabled'] )) ? $_POST['_llms_reviews_enabled'] : '';
$display = (isset( $_POST['_llms_display_reviews'] )) ? $_POST['_llms_display_reviews'] : '';
$num = (isset( $_POST['_llms_num_reviews'] )) ? $_POST['_llms_num_reviews'] : 0;
$multiple = (isset( $_POST['_llms_multiple_reviews_disabled'] )) ? $_POST['_llms_multiple_reviews_disabled'] : '';
if ( isset( $_POST['post_ID'] ) ) {
update_post_meta( $_POST['post_ID'], '_llms_reviews_enabled', $enabled );
}
if ( isset( $_POST['post_ID'] ) ) {
update_post_meta( $_POST['post_ID'], '_llms_display_reviews', $display );
}
if ( isset( $_POST['post_ID'] ) ) {
update_post_meta( $_POST['post_ID'], '_llms_num_reviews', $num );
}
if ( isset( $_POST['post_ID'] ) ) {
update_post_meta( $_POST['post_ID'], '_llms_multiple_reviews_disabled', $multiple );
}
}
}

Additionally, even for posts where there are no reviews (metadata value is empty), the metadata is saved anyway leading to useless rows in the postmeta table. This example is of a certificate:

Screenshot 2019-06-21 at 9 22 04 PM

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: BugBugs and errorsgood first issueIf you're a first time contributor this is a good issue for you!hacktoberfestPRs for this issue count towards Hacktoberfest contributions!help wantedLooking for contributors to assist with this issue

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions