Gocodebox_Banner_Notifier::notification_test_check_option( bool $value, array $data )

Check against the WordPress options table.


Parameters Parameters

$value

(bool) (Required) The current test value.

$data

(array) (Required) Array from notification with plugin_file, comparison, and version to check. $data[0] is the option name, $data[1] is the comparison operator, and $data[2] is the value to compare against.


Top ↑

Source Source

File: libraries/banner-notifications/src/notifications.php

	function notification_test_check_option( $value, $data ) {
		// Ensure data is a valid array with at least three elements.
		if ( ! is_array( $data ) || count( $data ) < 3 ) {
			return false;
		}

		// Assign the option value, check type, and check value to variables for readability.
		$option_to_check = $data[0];
		$check_type      = $data[1];
		$check_value     = $data[2];

		// Get the option value.
		if ( strpos( $option_to_check, ':' ) === false ) {
			// This is the straightforward case where there are no sub-options to check.
			$option_value = get_option( $option_to_check );
		} else {
			// This is the case where we need to dig deeper into the array or object.
			while ( ! empty( $option_to_check ) ) {
				// Split the option_to_check into the top level option names and sub-options.
				list( $current_option_to_check, $option_keys_to_check ) = explode( ':', $option_to_check, 2 );

				// Get the option_value for this layer of the array or object.
				if ( ! isset( $option_value ) ) {
					// We have not yet retrieved the top level option value. Do it now.
					$option_value = get_option( $current_option_to_check );
				} elseif ( is_array( $option_value ) && isset( $option_value[ $current_option_to_check ] ) ) {
					// We have the sub_option we want to check.
					$option_value = $option_value[ $current_option_to_check ];
				} elseif ( is_object( $option_value ) && isset( $option_value->$current_option_to_check ) ) {
					// We have the sub_option we want to check.
					$option_value = $option_value->$current_option_to_check;
				} else {
					// If the sub_option doesn't exist, set the option_value to null and break out of the loop.
					$option_value = null;
					break;
				}

				// Update the option_to_check to the sub option or option_key.
				$option_to_check = $option_keys_to_check;
			}
		}

		return $this->notification_check_option_helper( $option_value, $check_type, $check_value );
	}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.