diff --git a/app/main/controllers/template/RTMediaTemplate.php b/app/main/controllers/template/RTMediaTemplate.php index 05c01a462..681f28dc4 100755 --- a/app/main/controllers/template/RTMediaTemplate.php +++ b/app/main/controllers/template/RTMediaTemplate.php @@ -228,7 +228,8 @@ public function add_hidden_fields_in_gallery() { public function check_return_json() { global $rtmedia_query; - if ( 'json' === $rtmedia_query->format ) { + // Ensure $rtmedia_query and its nested format property are set before checking the value. + if ( isset( $rtmedia_query ) && isset( $rtmedia_query->format ) && 'json' === $rtmedia_query->format ) { $this->json_output(); } } @@ -239,7 +240,11 @@ public function check_return_json() { public function check_return_upload() { global $rtmedia_query; - if ( 'upload' !== $rtmedia_query->action_query->action ) { + // Ensure the current action is 'upload' before proceeding. + if ( ! isset( $rtmedia_query ) + || ! isset( $rtmedia_query->action_query ) + || ! isset( $rtmedia_query->action_query->action ) + || 'upload' !== $rtmedia_query->action_query->action ) { return; } @@ -314,8 +319,13 @@ public function json_output() { public function check_return_edit() { global $rtmedia_query; - if ( 'edit' === $rtmedia_query->action_query->action && count( $_POST ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.NoNonceVerification - $this->save_edit(); + // Ensure the current action is 'edit' and POST data exists before proceeding. + if ( isset( $rtmedia_query ) + && isset( $rtmedia_query->action_query ) + && isset( $rtmedia_query->action_query->action ) + && 'edit' === $rtmedia_query->action_query->action + && count( $_POST ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.NoNonceVerification + $this->save_edit(); } return $this->get_default_template(); @@ -596,7 +606,11 @@ public function save_album_edit() { public function check_return_delete() { global $rtmedia_query; - if ( 'delete' !== $rtmedia_query->action_query->action ) { + // Ensure the current action query is 'delete', otherwise terminate. + if ( ! isset( $rtmedia_query ) + || ! isset( $rtmedia_query->action_query ) + || ! isset( $rtmedia_query->action_query->action ) + || 'delete' !== $rtmedia_query->action_query->action ) { return; } @@ -744,7 +758,11 @@ public function album_delete() { public function check_return_merge() { global $rtmedia_query, $bp; - if ( 'merge' !== $rtmedia_query->action_query->action ) { + // Ensure the current action query is 'merge', otherwise terminate. + if ( ! isset( $rtmedia_query ) + || ! isset( $rtmedia_query->action_query ) + || ! isset( $rtmedia_query->action_query->action ) + || 'merge' !== $rtmedia_query->action_query->action ) { return; } @@ -791,7 +809,11 @@ public function check_return_merge() { public function check_return_comments() { global $rtmedia_query; - if ( 'comment' !== $rtmedia_query->action_query->action ) { + // Check if $rtmedia_query and its nested properties are defined. + if ( ! isset( $rtmedia_query ) + || ! isset( $rtmedia_query->action_query ) + || ! isset( $rtmedia_query->action_query->action ) + || 'comment' !== $rtmedia_query->action_query->action ) { return; } diff --git a/app/main/routers/query/RTMediaQuery.php b/app/main/routers/query/RTMediaQuery.php index a8c17971e..aa7858652 100755 --- a/app/main/routers/query/RTMediaQuery.php +++ b/app/main/routers/query/RTMediaQuery.php @@ -143,6 +143,13 @@ class RTMediaQuery { */ public $query_vars; + /** + * Determines if the gallery shortcode is executed. + * + * @var bool + */ + public $is_gallery_shortcode = false; + /** * Initialise the query *