From ef98a7074b27374ba45b2b881310738cf3c09a9d Mon Sep 17 00:00:00 2001 From: Andrew Lima Date: Thu, 12 Dec 2024 11:38:34 +0200 Subject: [PATCH 1/2] Test wp_notification for notices * ENHANCEMENT: Added notification check for wp_option (general) option which will help for compatibility plugins AND any of our own pmpro related options that are arrays. TODO: Test this code. --- includes/notifications.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/includes/notifications.php b/includes/notifications.php index 5c19400f11..54fcaca9f2 100644 --- a/includes/notifications.php +++ b/includes/notifications.php @@ -435,6 +435,40 @@ function pmpro_notification_test_pmpro_setting( $data ) { } } +/** + * Test any wp_option setting for a specific value. + * @param array $data Array from the notification with [0] option name to check [1] value to check for. + * @returns bool true if an option if found with the specified name and value. + */ +function pmpro_notification_test_wp_option( $data ) { + if ( ! is_array( $data ) || !isset( $data[0] ) || !isset( $data[1] ) ) { + return false; + } + + $option_value = get_option( $data[0] ); + if ( isset( $option_value ) ) { + // If it's an array of data, check if if the value is correct. + if ( is_array( $option_value ) ) { + // in_array? + if ( in_array( $data[1], $option_value ) ) { + return true; + } else { + return false; + } + } + + // If it's a single value, check if it matches. + if ( $option_value == $data[1] ) { + return true; + } else { + return false; + } + + } else { // no option value found for the key. + return false; + } +} + /** * PMPro site URL test. * @param string $string String or array of strings to look for in the site URL From 412b794e1704f7598e3cee46837ef74635069af0 Mon Sep 17 00:00:00 2001 From: Andrew Lima Date: Fri, 13 Dec 2024 12:03:27 +0200 Subject: [PATCH 2/2] Update doc block comment. --- includes/notifications.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/notifications.php b/includes/notifications.php index 54fcaca9f2..f5fc7aa690 100644 --- a/includes/notifications.php +++ b/includes/notifications.php @@ -437,7 +437,7 @@ function pmpro_notification_test_pmpro_setting( $data ) { /** * Test any wp_option setting for a specific value. - * @param array $data Array from the notification with [0] option name to check [1] value to check for. + * @param array $data notification data that is passed through this function to check if the value (data[1]) is set for the key (data[0]) or in an array should the option be an array. * @returns bool true if an option if found with the specified name and value. */ function pmpro_notification_test_wp_option( $data ) {