/** * Sanitize saved settings fields */ public static function sanitize_settings($input) { $sanitized_input = array(); // Nullify any previously cached authentications PushUp_Notifications_Authentication::_set_cached_authentication(null); // handle username field $sanitized_input['username'] = empty($input['username']) ? '' : sanitize_text_field($input['username']); // set site push id to old value by default, to be cautious $sanitized_input['website-push-id'] = self::get_website_push_id(); // handle api key and site push id if (empty($input['api-key'])) { $sanitized_input['api-key'] = ''; } else { $sanitized_input['api-key'] = sanitize_text_field($input['api-key']); // we need to cache the website push ID here because it's used elsewhere in the site like for generating a // push package on the frontend // @todo if this hasn't been stored, we need to attempt to get it in other places if (!empty($sanitized_input['username'])) { $settings_data = PushUp_Notifications_JSON_API::get_settings_data($sanitized_input['username'], $sanitized_input['api-key']); // grab the push ID $push_id = !empty($settings_data['push.domain']['push_id']) ? $settings_data['push.domain']['push_id'] : false; $sanitized_input['website-push-id'] = sanitize_text_field($push_id); // we also need to cache the user ID here because it's used elsewhere in the site. $user_id = !empty($settings_data['push.user.id']) ? $settings_data['push.user.id'] : false; $sanitized_input['user-id'] = intval($user_id); } } // update website name over PushUp API if (!empty($input['website_name'])) { PushUp_Notifications_JSON_API::set_website_name($input['website_name'], $sanitized_input['username'], $sanitized_input['api-key']); // if field appeared but was left empty or upon first authentication nothing was already set on server side } elseif (isset($input['website_name']) || !PushUp_Notifications_JSON_API::get_website_name()) { PushUp_Notifications_JSON_API::set_website_name(get_bloginfo('name'), $sanitized_input['username'], $sanitized_input['api-key']); } // update post title if (!empty($input['post_title'])) { $sanitized_input['post_title'] = sanitize_text_field($input['post_title']); // if field is empty, use default text } elseif (isset($input['post_title'])) { $sanitized_input['post_title'] = __('Just published...', 'pushup'); } // save prompt configuration $sanitized_input['prompt'] = empty($input['prompt']) || $input['prompt'] != 'custom' ? 'visits' : 'custom'; $sanitized_input['prompt_views'] = empty($input['prompt_views']) ? 1 : (int) $input['prompt_views']; return $sanitized_input; }