Skip to content

Commit

Permalink
Check if we're dealing with real WP_Post object
Browse files Browse the repository at this point in the history
  • Loading branch information
delawski committed Jul 19, 2024
1 parent 275ed1d commit 269ca93
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
5 changes: 3 additions & 2 deletions classes/class-alert.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ class Alert {
/**
* Class constructor
*
* @param object $item Alert data.
* @param Plugin $plugin Instance of plugin object.
* @param ?object $item Alert data.
* @param Plugin $plugin Instance of plugin object.
*
* @return void
*/
public function __construct( $item, $plugin ) {
Expand Down
11 changes: 6 additions & 5 deletions classes/class-alerts.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,18 +410,19 @@ public function register_post_type() {
/**
* Return alert object of the given ID
*
* @param string $post_id Post ID for the alert.
* @param string|int $post_id Post ID for the alert.
*
* @return Alert
*/
public function get_alert( $post_id = '' ) {
if ( ! $post_id ) {
$obj = new Alert( null, $this->plugin );

return $obj;
return new Alert( null, $this->plugin );
}

$post = get_post( $post_id );
if ( ! ( $post instanceof \WP_Post ) ) {
return new Alert( null, $this->plugin );
}

$alert_type = get_post_meta( $post_id, 'alert_type', true );
$alert_meta = get_post_meta( $post_id, 'alert_meta', true );
Expand Down Expand Up @@ -565,7 +566,7 @@ public function load_alerts_settings() {
}
$alert = array();
$post_id = wp_stream_filter_input( INPUT_POST, 'post_id' );
if ( ! empty( $post_id ) ) {
if ( ! empty( $post_id ) && 'new' !== $post_id ) {
$alert = $this->get_alert( $post_id );
if ( false === $alert ) {
wp_send_json_error(
Expand Down

0 comments on commit 269ca93

Please sign in to comment.