Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test wp_options values for notifications #3230

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions includes/notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,40 @@ function pmpro_notification_test_pmpro_setting( $data ) {
}
}

/**
* Test any wp_option setting for a specific value.
* @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 ) {
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
Expand Down