Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 24 additions & 29 deletions inc/class-builder-post-meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

class Builder_Post_Meta extends Builder {

public $id = null;
public $plugin = null;
public $args = array();
public $id;
public $plugin;
public $args = array();
public $data;

public function init() {

Expand Down Expand Up @@ -75,18 +76,25 @@ public function output( $post ) {
}

public function save_post( $post_id ) {

$data = $this->get_post_data();

if ( $data ) {
if (
isset( $_POST[ $this->id . '-nonce' ] ) && // Input var okay.
wp_verify_nonce( sanitize_text_field( $_POST[ $this->id . '-nonce' ] ), $this->id ) // Input var okay.
) {
$data = $this->get_post_data();
$this->save_data( $post_id, $data );
}

}

public function wp_insert_post_data( $post_data, $postarr ) {
global $wpdb;

if (
! isset( $_POST[ $this->id . '-nonce' ] ) || // Input var okay.
! wp_verify_nonce( sanitize_text_field( $_POST[ $this->id . '-nonce' ] ), $this->id ) // Input var okay.
) {
return $post_data;
}

$data = $this->get_post_data();

if ( $data && ! empty( $postarr['ID'] ) ) {
Expand Down Expand Up @@ -290,33 +298,20 @@ public function get_supported_post_types() {
protected function get_post_data() {

if ( ! $this->is_allowed_for_screen() ) {
return false;
return null;
}

$nonce = null;
$data = null;

if ( isset( $_POST[ $this->id . '-nonce' ] ) ) {
$nonce = sanitize_text_field( $_POST[ $this->id . '-nonce' ] ); // Input var okay.
if ( $this->data ) {
return $this->data;
}

if ( isset( $_POST[ $this->id . '-data' ] ) ) {
$json = $_POST[ $this->id . '-data' ]; // Input var okay.
$data = json_decode( $json, true );

/**
* Data is sometimes already slashed, see https://core.trac.wordpress.org/ticket/35408
*/
if ( json_last_error() ) {
$data = json_decode( stripslashes( $json ), true );
}

if ( ! json_last_error() && $nonce && wp_verify_nonce( $nonce, $this->id ) ) {
return $data;
}
if ( ! isset( $_POST[ $this->id . '-data' ] ) ) { // Input var okay
return null;
}

return false;
$this->data = json_decode( stripslashes( $_POST[ $this->id . '-data' ] ), true ); // Input var okay.
return $this->data;

}

}