public function render() { $connect_nonce = wp_create_nonce(self::CONNECT_CLEF_OAUTH_ACTION); $redirect_url = add_query_arg(array('_wpnonce' => $connect_nonce, 'connect' => true), admin_url("/admin.php?page=" . $this->settings->settings_path)); echo ClefUtils::render_template('user_settings.tpl', array("options" => array("connected" => ClefUtils::user_has_clef(), "appID" => $this->settings->get('clef_settings_app_id'), "redirectURL" => $redirect_url, "clefJSURL" => CLEF_JS_URL, "state" => ClefUtils::get_state(), "nonces" => array("connectClef" => $connect_nonce, "disconnectClef" => wp_create_nonce(self::DISCONNECT_CLEF_ACTION))))); $this->rendered = true; }
public static function invite_users($users, $is_network_admin) { $errors = array(); foreach ($users as &$user) { if (!ClefUtils::user_has_clef($user)) { $invite = new ClefInvite($user, $is_network_admin); $invite->persist(); $success = $invite->send_email(); if (!$success) { $errors[] = $user->user_email; } } } if (count($errors) > 0) { if (count($errors) == count($filtered_users)) { $message = __("there was an error sending the invite email to all users. Copy and paste the preview email to your users and they'll be walked through a tutorial to connect with Clef", 'wpclef'); } else { $message = __("unable to send emails to the following users: ", 'wpclef'); $message .= join(", ", $errors); $message .= __(". Copy and paste the preview email to your users and they'll be walked through a tutorial to connect with Clef", 'wpclef'); } throw new Exception($message); } else { return true; } }
public static function validate(array $input) { $input = parent::validate($input); // sanitize inputs as text fields foreach ($input as $key => &$value) { $input[$key] = sanitize_text_field($value); } $attrs_to_escape = array('clef_settings_app_id', 'clef_settings_app_secret', 'customization_message', 'customization_logo'); foreach ($attrs_to_escape as $attr) { if (isset($input[$attr])) { $input[$attr] = esc_attr($input[$attr]); } } if (isset($input['clef_password_settings_force']) && $input['clef_password_settings_force'] == "1") { if (!ClefUtils::user_has_clef()) { unset($input['clef_password_settings_force']); $url = admin_url('admin.php?page=' . ClefAdmin::CONNECT_CLEF_PAGE); add_settings_error(CLEF_OPTIONS_NAME, 'clef_password_settings_force', sprintf(__("Please link your Clef account before you fully disable passwords. You can do this <a href='%s'>here</a>", "clef"), $url), "error"); } } return $input; }
/** * Returns whether passwords are disabled for a specific user based on * user roles. * * @param WP_User $user * @return bool */ public function passwords_are_disabled_for_user($user) { if (!$this->is_configured()) { return false; } if ($this->get('clef_password_settings_force')) { return true; } if ($this->get('clef_password_settings_disable_passwords') && ClefUtils::user_has_clef($user)) { return true; } $disable_certain_passwords = $this->get('clef_password_settings_disable_certain_passwords'); if ($disable_certain_passwords && $disable_certain_passwords != "") { $max_role = strtolower($disable_certain_passwords); if (ClefUtils::user_fulfills_role($user, $max_role)) { return true; } } $potential_custom_user_roles = (array) $user->roles; foreach ($potential_custom_user_roles as $role) { if ($this->get("clef_password_settings_disable_passwords_custom_role_{$role}")) { return true; } } return false; }
public function get_menu_badge() { $user_is_admin = current_user_can('manage_options'); $needs_setup_badge = $user_is_admin && !$this->settings->is_configured(); if ($needs_setup_badge) { return _('needs setup'); } $has_seen_user_setup_badge = get_user_meta(get_current_user_id(), self::HIDE_USER_SETUP_BADGE, true); $needs_connect_badge = !$user_is_admin && $this->settings->is_configured() && !ClefUtils::user_has_clef() && !$has_seen_user_setup_badge; if ($needs_connect_badge) { return _('add security'); } return false; }
public function render() { echo ClefUtils::render_template('user_settings.tpl', array("connect_error" => $this->connect_error, "options" => array("connected" => ClefUtils::user_has_clef(), "appID" => $this->settings->get('clef_settings_app_id'), "clefJSURL" => CLEF_JS_URL, "state" => ClefUtils::get_state(), "nonces" => array("disconnectClef" => wp_create_nonce(self::DISCONNECT_CLEF_ACTION))))); $this->rendered = true; }