Ejemplo n.º 1
0
/**
 * Validates the Skimlinks options (via update_option() hook)
 */
function sl_validate_settings($option_name, $old_value, $new_value)
{
    switch ($option_name) {
        case 'sl_publisher_id':
            //convert the value to uppercase for 1234x5678
            if ($new_value !== strtoupper($new_value)) {
                $new_value = strtoupper($new_value);
                update_option($option_name, $new_value);
            }
            if ($new_value > '' && !sl_validate_publisher_id($new_value)) {
                update_option($option_name, sl_validate_publisher_id($old_value) ? $old_value : '');
                sl_add_setting_validation_error('sl_validation', $option_name, 'The Publisher ID you entered was not valid.');
            }
            break;
        case 'sl_subdomain':
            if ($new_value > '' && strpos($new_value, 'http') !== 0) {
                $new_value = 'http://' . $new_value;
                update_option($option_name, $new_value);
            }
            if ($new_value == '' && sl_is_subdomain_enabled()) {
                sl_add_setting_validation_error('sl_validation', $option_name, 'The subdomain information you entered was not valid');
                update_option('sl_enable_subdomain', '');
            } else {
                if ($new_value > '' && sl_is_subdomain_enabled() && !sl_validate_subdomain($new_value)) {
                    sl_add_setting_validation_error('sl_validation', $option_name, 'The subdomain information you entered was not valid');
                    if ($old_value > '') {
                        update_option($option_name, $old_value);
                    } else {
                        update_option($option_name, '');
                    }
                }
            }
            break;
    }
}
Ejemplo n.º 2
0
/**
 * Returns the domain_id part of Publisher ID
 * 
 * @return string || null if no pub id
 */
function sl_get_publisher_id_domain_id()
{
    $publisher_id = sl_get_publisher_id();
    if (!sl_validate_publisher_id($publisher_id)) {
        return null;
    }
    return end(explode('X', $publisher_id));
}