Skip to content

Commit

Permalink
Merge pull request #2098 from rtCamp/fix/null-warnings
Browse files Browse the repository at this point in the history
Fix: Null PHP Warning
  • Loading branch information
krishana7911 authored Jan 7, 2025
2 parents f98143f + 68a86cb commit fa86c28
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
36 changes: 29 additions & 7 deletions app/main/controllers/template/RTMediaTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
7 changes: 7 additions & 0 deletions app/main/routers/query/RTMediaQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit fa86c28

Please sign in to comment.