function jr_ps_validate_settings($input) { $valid = array(); $settings = get_option('jr_ps_settings'); if (isset($input['private_site']) && $input['private_site'] === 'true') { $valid['private_site'] = TRUE; } else { $valid['private_site'] = FALSE; } if (isset($input['reveal_registration']) && $input['reveal_registration'] === 'true') { $valid['reveal_registration'] = TRUE; } else { $valid['reveal_registration'] = FALSE; } if (isset($input['wplogin_php']) && $input['wplogin_php'] === 'true') { $valid['wplogin_php'] = TRUE; } else { $valid['wplogin_php'] = FALSE; } $url = jr_v1_sanitize_url($input['specific_url']); if ('' !== $url) { if (FALSE === $url) { /* Reset to previous URL value and generate an error message. */ $url = $settings['specific_url']; add_settings_error('jr_ps_settings', 'jr_ps_urlerror', 'Landing Location URL is not a valid URL<br /><code>' . sanitize_text_field($input['specific_url']) . '</code>', 'error'); } else { if (!jr_ps_site_url($url)) { /* Reset to previous URL value and generate an error message. */ $url = $settings['specific_url']; add_settings_error('jr_ps_settings', 'jr_ps_urlerror', 'Error in Landing Location URL. It must point to someplace on this WordPress web site<br /><code>' . sanitize_text_field($input['specific_url']) . '</code>', 'error'); } } } $valid['specific_url'] = $url; if ('url' === $input['landing']) { if ('' === $valid['specific_url']) { add_settings_error('jr_ps_settings', 'jr_ps_nourlerror', 'Error in Landing Location: <i>Go to Specific URL</i> selected but no URL specified. Set to default <i>Return to same URL</i>.', 'error'); $valid['landing'] = 'return'; } else { $valid['landing'] = 'url'; } } else { if ('' !== $valid['specific_url']) { add_settings_error('jr_ps_settings', 'jr_ps_nourlerror', 'Error in Landing Location: URL specified when not valid. URL deleted.', 'error'); $valid['specific_url'] = ''; } $valid['landing'] = $input['landing']; } $url = jr_v1_sanitize_url($input['login_url']); if ('' !== $url) { if (FALSE === $url) { /* Reset to previous URL value and generate an error message. */ $url = $settings['login_url']; add_settings_error('jr_ps_settings', 'jr_ps_urlerror', 'Custom Login URL is not a valid URL<br /><code>' . sanitize_text_field($input['login_url']) . '</code>', 'error'); } else { if (!jr_ps_site_url($url)) { /* Reset to previous URL value and generate an error message. */ $url = $settings['login_url']; add_settings_error('jr_ps_settings', 'jr_ps_urlerror', 'Error in Custom Login URL. It must point to someplace on this WordPress web site<br /><code>' . sanitize_text_field($input['login_url']) . '</code>', 'error'); } } } $valid['login_url'] = $url; if (isset($input['custom_login']) && $input['custom_login'] === 'true') { if ('' === $valid['login_url']) { add_settings_error('jr_ps_settings', 'jr_ps_nourlerror', 'Error in Custom Login: <i>Custom Login page?</i> checkbox selected but no URL specified. Checkbox deselected.', 'error'); $valid['custom_login'] = FALSE; } else { $valid['custom_login'] = TRUE; /* Was Custom Login just turned on? If so, be sure Landing Location is set to Omit. */ if (!$setting['custom_login'] && 'omit' !== $valid['landing']) { $valid['landing'] = 'omit'; add_settings_error('jr_ps_settings', 'jr_ps_setomit', 'Landing Location changed to "Omit", recommended for Custom Login pages.', 'updated'); } } } else { $valid['custom_login'] = FALSE; } if (isset($input['excl_home']) && $input['excl_home'] === 'true') { $valid['excl_home'] = TRUE; } else { $valid['excl_home'] = FALSE; } if (is_multisite()) { if (is_super_admin()) { if (isset($input['registrations'])) { update_site_option('registration', $input['registrations']); } } } else { if (isset($input['membership'])) { $mem = $input['membership']; } else { $mem = '0'; } update_option('users_can_register', $mem); } foreach (array('excl_url', 'excl_url_prefix') as $key) { if (isset($settings[$key])) { $valid[$key] = $settings[$key]; } else { $valid[$key] = array(); } /* Delete URLs to Exclude from Privacy. */ if (isset($input[$key . '_del'])) { foreach ($input[$key . '_del'] as $excl_url_del) { unset($valid[$key][$excl_url_del]); } } } /* Add a URL to Exclude from Privacy. */ $url = jr_v1_sanitize_url($input['excl_url_add']); if ('' !== $url) { if (FALSE === $url) { add_settings_error('jr_ps_settings', 'jr_ps_urlerror', 'Always Visible URL is not a valid URL<br /><code>' . sanitize_text_field($input['excl_url_add']) . '</code>', 'error'); } else { if (jr_ps_site_url($url)) { if (isset($input['excl_url_is_prefix']) && 'true' === $input['excl_url_is_prefix']) { $key = 'excl_url_prefix'; } else { $key = 'excl_url'; } $valid[$key][] = array($url, jr_v1_prep_url($url)); } else { add_settings_error('jr_ps_settings', 'jr_ps_urlerror', 'Error in Always Visible URL. It must point to someplace on this WordPress web site<br /><code>' . sanitize_text_field($input['excl_url_add']) . '</code>', 'error'); } } } if (isset($input['user_submenu']) && $input['user_submenu'] === 'true') { $valid['user_submenu'] = TRUE; } else { $valid['user_submenu'] = FALSE; } global $jr_ps_users_submenu; /* This conditional is really a poor solution, but it is the only thing I could find that worked. Anything else gave me zero or two Settings Saved messages, with the main problem being on the Settings submenu page when checkbox was filled for 'user_submenu' and Save Settings button hit. */ $errors = get_settings_errors(); if ($valid['user_submenu'] = TRUE || isset($jr_ps_users_submenu) && empty($errors)) { add_settings_error('jr_ps_settings', 'jr_ps_saved', 'Settings Saved', 'updated'); } return $valid; }
function jr_v1_same_prefix_url($prefix, $url) { if (is_string($prefix)) { $prefix = jr_v1_prep_url($prefix); } if (is_string($url)) { $url = jr_v1_prep_url($url); } if ($url['host'] === $prefix['host']) { if ($url['path'] === $prefix['path']) { /* Host and Path both exactly match for URL and Prefix specified. */ if (array() === $prefix['query']) { $match = TRUE; } else { /* Now the hard part: determining a legitimate prefix match for Query */ foreach ($prefix['query'] as $prefix_keyword => $prefix_value) { $one_match = FALSE; foreach ($url['query'] as $url_keyword => $url_value) { if ($prefix_keyword === jr_v1_substr($url_keyword, 0, jr_v1_strlen($prefix_keyword))) { if ($prefix_value === jr_v1_substr($url_value, 0, jr_v1_strlen($prefix_value))) { $one_match = TRUE; } } } /* All Prefix Queries must match. */ if (FALSE === $one_match) { return FALSE; } } $match = TRUE; } } else { /* Paths must exactly match if Prefix specifies Query */ if (array() === $prefix['query']) { /* No Query in Prefix, so check Path for Prefix match */ $match = $prefix['path'] === jr_v1_substr($url['path'], 0, jr_v1_strlen($prefix['path'])); } else { $match = FALSE; } } } else { if ('' === $prefix['path'] && array() === $prefix['query']) { /* No Path or Query in Prefix, so check Host for Prefix match */ $match = $prefix['host'] === jr_v1_substr($url['host'], 0, jr_v1_strlen($prefix['host'])); } else { /* Hosts must exactly match if Prefix specifies Path or Query */ $match = FALSE; } } return $match; }
function jr_ps_validate_settings($input) { $valid = array(); $settings = get_option('jr_ps_settings'); foreach (array('private_site', 'reveal_registration', 'wplogin_php', 'override_omit', 'custom_login', 'custom_login_onsite', 'excl_home') as $opt) { $valid[$opt] = isset($input[$opt]) && 'true' === $input[$opt]; } $url = jr_v1_sanitize_url($input['specific_url']); if ('' !== $url) { if (FALSE === $url) { /* Reset to previous URL value and generate an error message. */ $url = $settings['specific_url']; add_settings_error('jr_ps_settings', 'jr_ps_urlerror', 'Landing Location URL is not a valid URL<br /><code>' . sanitize_text_field($input['specific_url']) . '</code>', 'error'); } else { if (!jr_ps_site_url($url)) { /* Reset to previous URL value and generate an error message. */ $url = $settings['specific_url']; add_settings_error('jr_ps_settings', 'jr_ps_urlerror', 'Error in Landing Location URL. It must point to someplace on this WordPress web site<br /><code>' . sanitize_text_field($input['specific_url']) . '</code>', 'error'); } } } $valid['specific_url'] = $url; if ('url' === $input['landing']) { if ('' === $valid['specific_url']) { add_settings_error('jr_ps_settings', 'jr_ps_nourlerror', 'Error in Landing Location: <i>Go to Specific URL</i> selected but no URL specified. Set to default <i>Return to same URL</i>.', 'error'); $valid['landing'] = 'return'; } else { $valid['landing'] = 'url'; } } else { if ('' !== $valid['specific_url']) { add_settings_error('jr_ps_settings', 'jr_ps_nourlerror', 'Error in Landing Location: URL specified when not valid. URL deleted.', 'error'); $valid['specific_url'] = ''; } $valid['landing'] = $input['landing']; } /* Custom Login section */ if (FALSE === ($valid['login_url'] = jr_v1_sanitize_url($input['login_url']))) { /* Generate an error message. Then clear Custom Login checkbox and URL fields. */ add_settings_error('jr_ps_settings', 'jr_ps_urlerror', 'Custom Login URL is not a valid URL<br /><code>' . sanitize_text_field($input['login_url']) . '</code>', 'error'); $valid['login_url'] = ''; $valid['custom_login'] = FALSE; } else { if ('' !== $valid['login_url'] && $valid['custom_login_onsite'] && !jr_ps_site_url($url)) { /* Generate an error message. Then clear Custom Login checkbox and URL fields. */ add_settings_error('jr_ps_settings', 'jr_ps_urlerror', 'Error in Custom Login URL. It must point to someplace on this WordPress web site<br /><code>' . sanitize_text_field($input['login_url']) . '</code>', 'error'); $valid['login_url'] = ''; $valid['custom_login'] = FALSE; } else { if ('' !== $valid['login_url'] && !$valid['custom_login']) { /* URL specified but not Custom Login checkbox Generate an error message. Then clear Custom Login checkbox and URL fields. */ add_settings_error('jr_ps_settings', 'jr_ps_urlerror', 'Error in Custom Login: URL specified but <i>Custom Login page?</i> checkbox not selected.', 'error'); $valid['login_url'] = ''; $valid['custom_login'] = FALSE; } else { if ('' === $valid['login_url'] && $valid['custom_login']) { /* Custom Login checkbox specified but not URL Generate an error message. Then clear Custom Login checkbox and URL fields. */ add_settings_error('jr_ps_settings', 'jr_ps_nourlerror', 'Error in Custom Login: <i>Custom Login page?</i> checkbox selected but no URL specified. Checkbox deselected.', 'error'); $valid['login_url'] = ''; $valid['custom_login'] = FALSE; } } } } if ($valid['custom_login'] && !$valid['override_omit'] && 'omit' !== $valid['landing']) { $valid['landing'] = 'omit'; add_settings_error('jr_ps_settings', 'jr_ps_setomit', 'Landing Location changed to "Omit", recommended for Custom Login pages. See Advanced Settings to Override, but please read Warnings first.', 'updated'); } if (is_multisite()) { if (is_super_admin()) { if (isset($input['registrations'])) { update_site_option('registration', $input['registrations']); } } /* Only in Form in WordPress Network */ if (isset($input['check_role']) && $input['check_role'] === 'true') { $valid['check_role'] = TRUE; } else { $valid['check_role'] = FALSE; } } else { if (isset($input['membership'])) { $mem = $input['membership']; } else { $mem = '0'; } update_option('users_can_register', $mem); /* Not in Form except in WordPress Network */ $valid['check_role'] = $settings['check_role']; } foreach (array('excl_url', 'excl_url_prefix') as $key) { if (isset($settings[$key])) { $valid[$key] = $settings[$key]; } else { $valid[$key] = array(); } /* Delete URLs to Exclude from Privacy. */ if (isset($input[$key . '_del'])) { foreach ($input[$key . '_del'] as $excl_url_del) { unset($valid[$key][$excl_url_del]); } } } /* Add a URL to Exclude from Privacy. */ $url = jr_v1_sanitize_url($input['excl_url_add']); if ('' !== $url) { if (FALSE === $url) { add_settings_error('jr_ps_settings', 'jr_ps_urlerror', 'Always Visible URL is not a valid URL<br /><code>' . sanitize_text_field($input['excl_url_add']) . '</code>', 'error'); } else { if (jr_ps_site_url($url)) { if (isset($input['excl_url_is_prefix']) && 'true' === $input['excl_url_is_prefix']) { $key = 'excl_url_prefix'; } else { $key = 'excl_url'; } $valid[$key][] = array($url, jr_v1_prep_url($url)); } else { add_settings_error('jr_ps_settings', 'jr_ps_urlerror', 'Error in Always Visible URL. It must point to someplace on this WordPress web site<br /><code>' . sanitize_text_field($input['excl_url_add']) . '</code>', 'error'); } } } $errors = get_settings_errors(); if (isset($jr_ps_users_submenu) && empty($errors)) { add_settings_error('jr_ps_settings', 'jr_ps_saved', 'Settings Saved', 'updated'); } return $valid; }