25f14345 by Jeff Balicki

WPO365 | CUSTOM USER FIELDS

Signed-off-by: Jeff <jeff@gotenzing.com>
1 parent d7b2bbe7
=== WPO365 | CUSTOM USER FIELDS ===
Contributors: wpo365
Tags: office 365, O365, Microsoft 365, avatar, user profile, Microsoft Graph
Requires at least: 5.0
Tested up to: 6.4
Stable tag: 25.1
Requires PHP: 5.6.40
== Description ==
Synchronize Azure AD user attributes e.g. department, job title etc. to WordPress user profiles (includes the PROFILE+ extension).
= Plugin Features =
- Synchronize Microsoft 365 / Azure AD profile fields e.g. job title, department or employee number to WordPress / BuddyPress.
= Prerequisites =
- The [WPO365 | LOGIN plugin](https://wordpress.org/plugins/wpo365-login/) must be installed and activated. See [online documentation](https://docs.wpo365.com/article/98-synchronize-microsoft-365-azure-ad-profile-fields) for configuration example.
= Support =
We will go to great length trying to support you if the plugin doesn't work as expected. Go to our [Support Page](https://www.wpo365.com/how-to-get-support/) to get in touch with us. We haven't been able to test our plugin in all endless possible Wordpress configurations and versions so we are keen to hear from you and happy to learn!
= Feedback =
We are keen to hear from you so share your feedback with us on [Twitter](https://twitter.com/WPO365) and help us get better!
== Installation ==
1. Purchase the plugin from the [website](https://www.wpo365.com/).
2. Navigate to [Your Account](https://www.wpo365.com/your-account/) to download the premium extension.
3. Go to WP Admin > Plugins > Add new and click Upload plugin.
4. Upload the plugin.
5. Wait until the installation finishes and then click Activate.
6. See [online documentation](https://docs.wpo365.com/article/98-synchronize-microsoft-365-azure-ad-profile-fields) for configuration example.
== Frequently Asked Questions ==
== Screenshots ==
== Upgrade Notice ==
== Changelog ==
Please check the [online change log](https://www.wpo365.com/change-log/) for changes.
\ No newline at end of file
<?php
namespace Wpo\Services;
use \Wpo\Core\WordPress_Helpers;
use \Wpo\Services\Log_Service;
use \Wpo\Services\Options_Service;
use \Wpo\Services\User_Details_Service;
// Prevent public access to this script
defined('ABSPATH') or die();
if (!class_exists('\Wpo\Services\BuddyPress_Service')) {
class BuddyPress_Service
{
/**
* Adds an additional section to the bottom of the user profile page
*
* @since 5.3
*
* @param WP_User $user whose profile is being shown
* @return void
*/
public static function bp_show_extra_user_fields($user)
{
if (false === Options_Service::get_global_boolean_var('graph_user_details')) {
Log_Service::write_log('DEBUG', __METHOD__ . ' -> Extra user fields disabled as per configuration');
return;
} elseif (true === Options_Service::get_global_boolean_var('use_bp_extended')) {
Log_Service::write_log('DEBUG', __METHOD__ . ' -> Extra user fields will be display on BuddyPress Extended Profile instead');
return;
} elseif (!class_exists('\Wpo\Services\User_Details_Service')) {
Log_Service::write_log('WARN', __METHOD__ . ' -> Cannot show extra BuddyPress fields because of missing dependency');
return;
} else {
echo ('<div class="bp-widget base">');
echo ('<h3 class="screen-heading profile-group-title">' . __('Directory Info', 'wpo365-login') . '</h3>');
echo ('<table class="profile-fields bp-tables-user"><tbody>');
\Wpo\Services\User_Custom_Fields_Service::process_extra_user_fields(function ($name, $title) use (&$user) {
$parsed_user_field_key = User_Details_Service::parse_user_field_key($name);
$name = $parsed_user_field_key[0];
$wp_user_meta_key = $parsed_user_field_key[1];
$value = get_user_meta(\bp_displayed_user_id(), $wp_user_meta_key, true);
echo ('<tr class="field_1 field_name required-field visibility-public field_type_textbox"><td class="label">' . esc_html($title) . '</td>');
if (is_array($value)) {
echo ('<td class="data">');
foreach ($value as $idx => $val)
echo ('<p>' . esc_html($val) . '</p>');
echo ('</td>');
} else
echo ('<td class="data"><p>' . esc_html($value) . '</p></td>');
echo ("</tr>");
});
echo ('</tbody></table></div>');
}
}
/**
* Helper method that returns the O365 avatar for Buddy Press.
*
* @since 9.0
*
* @param $avatar Image tag for the user's avatar.
* @return string Image tag for the user's avatar possibly with img URL replaced with O365 profile image URL.
*/
public static function fetch_buddy_press_avatar($bp_avatar, $params)
{
if (false === Options_Service::get_global_boolean_var('use_bp_avatar')) {
return $bp_avatar;
}
if (!is_array($params) || !isset($params['item_id'])) {
return $bp_avatar;
}
if (!class_exists('\Wpo\Services\Avatar_Service')) {
Log_Service::write_log('WARN', __METHOD__ . ' -> Cannot BuddyPress avatar because of missing dependency');
return $bp_avatar;
}
/**
* @since 10.5
*
* Don't return avatar if objec is not a user (e.g. but a group)
*/
if (is_array($params) && isset($params['object']) && false === WordPress_Helpers::stripos($params['object'], 'user')) {
return $bp_avatar;
}
$o365_avatar_url = \Wpo\Services\Avatar_Service::get_o365_avatar_url(intval($params['item_id']));
return empty($o365_avatar_url)
? $bp_avatar
: \preg_replace('/src=".+?"/', 'src="' . $o365_avatar_url . '"', $bp_avatar);
}
}
}
<?php
namespace Wpo\Services;
// Prevent public access to this script
defined('ABSPATH') or die();
use \Wpo\Services\Log_Service;
use \Wpo\Services\Options_Service;
if (!class_exists('\Wpo\Services\User_Create_Update_Service')) {
class User_Create_Update_Service
{
/**
* Updates a WordPress user.
*
* @since 11.0
*
* @param mixed $wp_user_id WordPress ID of the user that will be updated
* @param bool $is_deamon If true then actions that may sign out the user are ignored
* @param bool $exit_on_error If true the user my be signed out if an action fails
*
* @return int The WordPress ID of the user.
*/
public static function create_user(&$wpo_usr, $is_deamon = false, $exit_on_error = true)
{
Log_Service::write_log('DEBUG', '##### -> ' . __METHOD__);
$user_login = !empty($wpo_usr->preferred_username)
? $wpo_usr->preferred_username
: $wpo_usr->upn;
if (Options_Service::get_global_boolean_var('use_short_login_name') || Options_Service::get_global_string_var('user_name_preference') == 'short') {
$user_login = \stristr($user_login, '@', true);
}
if (!empty($wpo_usr->custom_username)) {
$user_login = $wpo_usr->custom_username;
}
/**
* @since 12.5
*
* Don't create a user when that user should not be added to a subsite in case of wpmu shared mode.
*/
if (!$is_deamon && is_multisite() && !Options_Service::mu_use_subsite_options() && !is_main_site() && Options_Service::get_global_boolean_var('skip_add_user_to_subsite')) {
$blog_id = get_current_blog_id();
// Not using subsite options and administrator has disabled automatic adding of users to subsites
Log_Service::write_log('WARN', __METHOD__ . " -> Skipped creating a user with login $user_login for blog with ID $blog_id because administrator has disabled adding a user to a subsite");
Authentication_Service::goodbye(Error_Service::USER_NOT_FOUND);
exit();
}
if (!$is_deamon && !Options_Service::get_global_boolean_var('create_and_add_users')) {
Log_Service::write_log('ERROR', __METHOD__ . ' -> User not found and settings prevented creating a new user on-demand for user ' . $user_login);
Authentication_Service::goodbye(Error_Service::USER_NOT_FOUND);
exit();
}
/**
* @since 23.0 Added possibility to hook up (custom) actions to pre-defined events for various WPO365 workloads.
*/
do_action(
'wpo365/user/creating',
$wpo_usr->preferred_username,
$wpo_usr->email,
$wpo_usr->groups
);
$usr_default_role = is_main_site()
? Options_Service::get_global_string_var('new_usr_default_role')
: Options_Service::get_global_string_var('mu_new_usr_default_role');
$password_length = Options_Service::get_global_numeric_var('password_length');
if (empty($password_length) || $password_length < 16) {
$password_length = 16;
}
$userdata = array(
'user_login' => $user_login,
'user_pass' => wp_generate_password($password_length, true, false),
'display_name' => $wpo_usr->full_name,
'user_email' => $wpo_usr->email,
'first_name' => $wpo_usr->first_name,
'last_name' => $wpo_usr->last_name,
'role' => $usr_default_role,
);
/**
* @since 9.4
*
* Optionally removing any user_register hooks as these more often than
* not interfer and cause unexpected behavior.
*/
$user_regiser_hooks = null;
if (Options_Service::get_global_boolean_var('skip_user_register_action') && isset($GLOBALS['wp_filter']) && isset($GLOBALS['wp_filter']['user_register'])) {
Log_Service::write_log('DEBUG', __METHOD__ . ' -> Temporarily removing all filters for the user_register action to avoid interference');
$user_regiser_hooks = $GLOBALS['wp_filter']['user_register'];
unset($GLOBALS['wp_filter']['user_register']);
}
$existing_registering = remove_filter('wp_pre_insert_user_data', '\Wpo\Services\Wp_To_Aad_Create_Update_Service::handle_user_registering', PHP_INT_MAX);
$existing_registered = remove_action('user_registered', '\Wpo\Services\Wp_To_Aad_Create_Update_Service::handle_user_registered', PHP_INT_MAX);
$wp_usr_id = wp_insert_user($userdata);
if ($existing_registering) {
add_filter('wp_pre_insert_user_data', '\Wpo\Services\Wp_To_Aad_Create_Update_Service::handle_user_registering', PHP_INT_MAX, 4);
}
if ($existing_registered) {
add_action('user_register', '\Wpo\Services\Wp_To_Aad_Create_Update_Service::handle_user_registered', PHP_INT_MAX, 1);
}
if (!empty($GLOBALS['wp_filter']) && !empty($user_regiser_hooks)) {
$GLOBALS['wp_filter']['user_register'] = $user_regiser_hooks;
}
if (is_wp_error($wp_usr_id)) {
Log_Service::write_log('ERROR', __METHOD__ . ' -> Could not create wp user. See next line for error information.');
Log_Service::write_log('ERROR', $wp_usr_id);
if ($exit_on_error) {
Authentication_Service::goodbye(Error_Service::CHECK_LOG);
exit();
}
return 0;
}
/**
* @since 15.0
*/
do_action('wpo365/user/created', $wp_usr_id);
$wpo_usr->created = true;
Log_Service::write_log('DEBUG', __METHOD__ . ' -> Created new user with ID ' . $wp_usr_id);
// WPMU -> Add user to current blog
if (\class_exists('\Wpo\Services\User_Create_Service') && \method_exists('\Wpo\Services\User_Create_Service', 'wpmu_add_user_to_blog')) {
\Wpo\Services\User_Create_Service::wpmu_add_user_to_blog($wp_usr_id, $wpo_usr->preferred_username);
}
if (\class_exists('\Wpo\Services\User_Role_Service') && \method_exists('\Wpo\Services\User_Role_Service', 'update_user_roles')) {
\Wpo\Services\User_Role_Service::update_user_roles($wp_usr_id, $wpo_usr);
}
add_filter('allow_password_reset', '\Wpo\Services\User_Create_Service::temporarily_allow_password_reset', PHP_INT_MAX, 1);
wp_new_user_notification($wp_usr_id, null, 'both');
remove_filter('allow_password_reset', '\Wpo\Services\User_Create_Service::temporarily_allow_password_reset', PHP_INT_MAX);
return $wp_usr_id;
}
/**
* Updates a WordPress user.
*
* @param mixed $wp_user_id WordPress ID of the user that will be updated
* @param mixed $wpo_usr Internal user representation (Graph and ID token data)
* @param bool $is_deamon If true then actions that may sign out the user are ignored
*
* @return void
*/
public static function update_user($wp_usr_id, $wpo_usr, $is_deamon = false)
{
Log_Service::write_log('DEBUG', '##### -> ' . __METHOD__);
// Save user's UPN
if (!empty($wpo_usr->upn)) {
update_user_meta($wp_usr_id, 'userPrincipalName', $wpo_usr->upn);
}
if (!$wpo_usr->created) {
if (!$is_deamon && \class_exists('\Wpo\Services\User_Create_Service') && \method_exists('\Wpo\Services\User_Create_Service', 'wpmu_add_user_to_blog')) {
\Wpo\Services\User_Create_Service::wpmu_add_user_to_blog($wp_usr_id, $wpo_usr->preferred_username);
}
if (\class_exists('\Wpo\Services\User_Role_Service') && \method_exists('\Wpo\Services\User_Role_Service', 'update_user_roles')) {
\Wpo\Services\User_Role_Service::update_user_roles($wp_usr_id, $wpo_usr);
}
}
// Update Avatar
if (Options_Service::get_global_boolean_var('use_avatar') && class_exists('\Wpo\Services\Avatar_Service')) {
$default_avatar = get_avatar($wp_usr_id);
}
// Update custom fields
if (class_exists('\Wpo\Services\User_Custom_Fields_Service')) {
if (Options_Service::get_global_boolean_var('use_saml') && Options_Service::get_global_string_var('extra_user_fields_source') == 'samlResponse') {
\Wpo\Services\User_Custom_Fields_Service::update_custom_fields_from_saml_attributes($wp_usr_id, $wpo_usr);
} else {
\Wpo\Services\User_Custom_Fields_Service::update_custom_fields($wp_usr_id, $wpo_usr);
}
}
// Update default WordPress user fields
self::update_wp_user($wp_usr_id, $wpo_usr);
}
/**
* @since 11.0
*/
private static function update_wp_user($wp_usr_id, $wpo_usr)
{
// Update "core" WP_User fields
$wp_user_data = array('ID' => $wp_usr_id);
if (!empty($wpo_usr->email)) {
$wp_user_data['user_email'] = $wpo_usr->email;
}
if (!empty($wpo_usr->first_name)) {
$wp_user_data['first_name'] = $wpo_usr->first_name;
}
if (!empty($wpo_usr->last_name)) {
$wp_user_data['last_name'] = $wpo_usr->last_name;
}
if (!empty($wpo_usr->full_name)) {
$wp_user_data['display_name'] = $wpo_usr->full_name;
}
$existing_registering = remove_filter('wp_pre_insert_user_data', '\Wpo\Services\Wp_To_Aad_Create_Update_Service::handle_user_registering', PHP_INT_MAX);
$existing_registered = remove_action('user_registered', '\Wpo\Services\Wp_To_Aad_Create_Update_Service::handle_user_registered', PHP_INT_MAX);
wp_update_user($wp_user_data);
if ($existing_registering) {
add_filter('wp_pre_insert_user_data', '\Wpo\Services\Wp_To_Aad_Create_Update_Service::handle_user_registering', PHP_INT_MAX, 4);
}
if ($existing_registered) {
add_action('user_register', '\Wpo\Services\Wp_To_Aad_Create_Update_Service::handle_user_registered', PHP_INT_MAX, 1);
}
}
}
}
<?php
namespace Wpo\Services;
// Prevent public access to this script
defined('ABSPATH') or die();
use \Wpo\Core\WordPress_Helpers;
use \Wpo\Services\Log_Service;
use \Wpo\Services\Options_Service;
use \Wpo\Services\Graph_Service;
use \Wpo\Services\Saml2_Service;
use \Wpo\Services\User_Service;
use \Wpo\Services\User_Details_Service;
if (!class_exists('\Wpo\Services\User_Custom_Fields_Service')) {
class User_Custom_Fields_Service
{
/**
* @since 11.0
*/
public static function update_custom_fields($wp_usr_id, $wpo_usr)
{
Log_Service::write_log('DEBUG', '##### -> ' . __METHOD__);
if (empty($wpo_usr->graph_resource)) {
Log_Service::write_log('DEBUG', __METHOD__ . ' -> Cannot update custom user fields because the graph resource has not been retrieved');
return;
}
// Check to see if expanded properties need to be loaded (currently only manager is supported)
$extra_user_fields = Options_Service::get_global_list_var('extra_user_fields');
$expanded_fields = array();
// Iterate over the configured graph fields and identify any supported expandable properties
array_map(function ($kv_pair) use (&$expanded_fields) {
if (false !== WordPress_Helpers::stripos($kv_pair['key'], 'manager')) {
$expanded_fields[] = 'manager';
}
}, $extra_user_fields);
// Query to expand property
if (in_array('manager', $expanded_fields)) {
$upn = User_Service::try_get_user_principal_name($wp_usr_id);
if (!empty($upn)) {
$user_manager = Graph_Service::fetch('/users/' . \rawurlencode($upn) . '/manager', 'GET', false, array('Accept: application/json;odata.metadata=minimal'));
// Expand user details
if (Graph_Service::is_fetch_result_ok($user_manager, 'Could not retrieve user manager details for user ' . $upn, 'WARN')) {
$wpo_usr->graph_resource['manager'] = $user_manager['payload'];
}
}
}
self::process_extra_user_fields(function ($name, $title) use (&$wpo_usr, &$wp_usr_id) {
$parsed_user_field_key = User_Details_Service::parse_user_field_key($name);
$name = $parsed_user_field_key[0];
$wp_user_meta_key = $parsed_user_field_key[1];
$name_arr = explode('.', $name);
$current = $wpo_usr->graph_resource;
$value = null;
if (sizeof($name_arr) > 1) {
$found = false;
for ($i = 0; $i < sizeof($name_arr); $i++) {
/**
* Found must be true for the last iteration therefore it resets every cycle
*/
$found = false;
/**
* Administrator has specified to get the nth element of an array / object
*/
if (is_array($current) && \is_numeric($name_arr[$i]) && $i < sizeof($current) && array_key_exists($name_arr[$i], $current)) {
$current = $current[$name_arr[$i]];
$found = true;
}
/**
* Administrator has specified to get the named element of an array / object
*/
else if (is_array($current) && array_key_exists($name_arr[$i], $current)) {
$current = $current[$name_arr[$i]];
$found = true;
}
}
if ($found) {
$value = $current;
}
}
/**
* Administrator has specified a simple non-nested property
*/
else if (array_key_exists($name, $current) && !empty($current[$name])) {
$value = $name == 'manager'
? self::parse_manager_details($current['manager'])
: $current[$name];
}
if (empty($value)) {
$value = '';
}
update_user_meta(
$wp_usr_id,
$wp_user_meta_key,
$value
);
if (function_exists('xprofile_set_field_data') && true === Options_Service::get_global_boolean_var('use_bp_extended')) {
xprofile_set_field_data($title, $wp_usr_id, $value);
}
});
}
/**
* Processes the extra user fields and tries to read them from the SAML attributes
* and if found saves their value as WordPress user meta.
*
* @since 20.0
*
* @param mixed $wp_usr_id
* @param mixed $wpo_usr
* @return void
*/
public static function update_custom_fields_from_saml_attributes($wp_usr_id, $wpo_usr)
{
Log_Service::write_log('DEBUG', '##### -> ' . __METHOD__);
if (empty($wpo_usr->saml_attributes)) {
Log_Service::write_log('DEBUG', __METHOD__ . ' -> Cannot update custom user fields because the SAML attributes are not found');
return;
}
self::process_extra_user_fields(function ($name, $title) use (&$wpo_usr, &$wp_usr_id) {
$parsed_user_field_key = User_Details_Service::parse_user_field_key($name);
$claim = $parsed_user_field_key[0];
$wp_user_meta_key = $parsed_user_field_key[1];
if (strcmp($claim, $wp_user_meta_key) === 0 && WordPress_Helpers::stripos($wp_user_meta_key, '/') > 0) {
$key_exploded = explode('/', $wp_user_meta_key);
$wp_user_meta_key = sprintf('saml_%s', array_pop($key_exploded));
}
$value = Saml2_Service::get_attribute($claim, $wpo_usr->saml_attributes);
update_user_meta(
$wp_usr_id,
$wp_user_meta_key,
$value
);
if (function_exists('xprofile_set_field_data') && true === Options_Service::get_global_boolean_var('use_bp_extended')) {
xprofile_set_field_data($title, $wp_usr_id, $value);
}
});
}
/**
*
* @param function callback with signature ( $name, $title ) => void
*
* @return void
*/
public static function process_extra_user_fields($callback)
{
$extra_user_fields = Options_Service::get_global_list_var('extra_user_fields');
if (sizeof($extra_user_fields) == 0)
return;
foreach ($extra_user_fields as $kv_pair)
$callback($kv_pair['key'], $kv_pair['value']);
}
/**
* Adds an additional section to the bottom of the user profile page
*
* @since 2.0
*
* @param WP_User $user whose profile is being shown
* @return void
*/
public static function show_extra_user_fields($user)
{
if (false === Options_Service::get_global_boolean_var('graph_user_details')) {
Log_Service::write_log('DEBUG', __METHOD__ . ' -> Extra user fields disabled as per configuration');
return;
} elseif (true === Options_Service::get_global_boolean_var('use_bp_extended')) {
Log_Service::write_log('DEBUG', __METHOD__ . ' -> Extra user fields will be display on BuddyPress Extended Profile instead');
return;
} else {
echo ("<h3>" . __('Office 365 Profile Information', 'wpo365-login') . "</h3>");
echo ("<table class=\"form-table\">");
self::process_extra_user_fields(function ($name, $title) use (&$user) {
$parsed_user_field_key = User_Details_Service::parse_user_field_key($name);
$name = $parsed_user_field_key[0];
$wp_user_meta_key = $parsed_user_field_key[1];
// The following may be true for SAML based custom attributes
if (strcmp($name, $wp_user_meta_key) === 0 && WordPress_Helpers::stripos($wp_user_meta_key, '/') > 0) {
$key_exploded = explode('/', $wp_user_meta_key);
$wp_user_meta_key = sprintf('saml_%s', array_pop($key_exploded));
}
$value = get_user_meta($user->ID, $wp_user_meta_key, true);
echo ('<tr><th><label for="' . esc_attr($wp_user_meta_key) . '">' . esc_html($title) . '</label></th>');
if (is_array($value)) {
echo ("<td>");
foreach ($value as $idx => $val) {
if (empty($val)) {
continue;
}
echo '<input type="text" name="' . esc_attr($wp_user_meta_key) . '__##__' . esc_attr($idx) . '" id="' . esc_attr($wp_user_meta_key) . esc_attr($idx) . '" value="' . esc_attr($val) . '" class="regular-text" /><br />';
}
echo ("</td>");
} else {
echo ('<td><input type="text" name="' . esc_attr($wp_user_meta_key) . '" id="' . esc_attr($wp_user_meta_key) . '" value="' . esc_attr($value) . '" class="regular-text" /><br/></td>');
}
echo ("</tr>");
});
echo ('</table>');
}
}
/**
* Allow users to save their updated extra user fields
*
* @since 4.0
*
* @return mixed(boolean|void)
*/
public static function save_user_details($user_id)
{
if (!current_user_can('edit_user', $user_id)) {
return false;
}
self::process_extra_user_fields(function ($name, $title) use (&$user_id) {
$parsed_user_field_key = User_Details_Service::parse_user_field_key($name);
$name = $parsed_user_field_key[0];
$wp_user_meta_key = $parsed_user_field_key[1];
// The following may be true for SAML based custom attributes
if (strcmp($name, $wp_user_meta_key) === 0 && WordPress_Helpers::stripos($wp_user_meta_key, '/') > 0) {
$key_exploded = explode('/', $wp_user_meta_key);
$wp_user_meta_key = sprintf('saml_%s', array_pop($key_exploded));
}
$lookup = str_replace('.', '_', $wp_user_meta_key); // '.' is changed to '_' when sent in a request
if (isset($_POST[$lookup])) {
update_user_meta(
$user_id,
$wp_user_meta_key,
sanitize_text_field($_POST[$lookup])
);
return;
}
$array_of_user_meta = array();
foreach ($_POST as $key => $value) {
if (false !== WordPress_Helpers::strpos($key, $lookup . "__##__")) {
$array_of_user_meta[$key] = $value;
}
}
if (false === empty($array_of_user_meta)) {
$array_of_user_meta_values = array_values($array_of_user_meta);
update_user_meta(
$user_id,
$wp_user_meta_key,
$array_of_user_meta_values
);
return;
}
});
}
/**
* Gets details of a user as an array with displayName, mail, officeLocation, department,
* businessPhones, mobilePhone.
*
* @since 15.0
*
* @param int $wp_usr_id
* @return array
*/
public static function get_manager_details_from_wp_user($wp_usr_id)
{
if (empty($wp_usr = get_user_by('ID', $wp_usr_id))) {
return array();
}
$displayName = $wp_usr->display_name;
$mail = $wp_usr->user_email;
$officeLocation = get_user_meta($wp_usr_id, 'officeLocation', true);
$department = get_user_meta($wp_usr_id, 'department', true);
$businessPhones = get_user_meta($wp_usr_id, 'businessPhones', true);
$mobilePhone = get_user_meta($wp_usr_id, 'mobilePhone', true);
return array(
'displayName' => $displayName,
'mail' => $mail,
'officeLocation' => !empty($officeLocation) ? $officeLocation : '',
'department' => !empty($department) ? $department : '',
'businessPhones' => !empty($businessPhones) ? $businessPhones : '',
'mobilePhone' => !empty($mobilePhone) ? $mobilePhone : '',
);
}
/**
* Parses the manager details fetched from Microsoft Graph.
*
* @since 7.17
*
* @return array Assoc. array with the most important manager details.
*/
private static function parse_manager_details($manager)
{
if (empty($manager)) {
return array();
}
$displayName = !empty($manager['displayName'])
? $manager['displayName']
: '';
$mail = !empty($manager['mail'])
? $manager['mail']
: '';
$officeLocation = !empty($manager['officeLocation'])
? $manager['officeLocation']
: '';
$department = !empty($manager['department'])
? $manager['department']
: '';
$businessPhones = !empty($manager['businessPhones'])
? $manager['businessPhones'][0]
: '';
$mobilePhone = !empty($manager['mobilePhone'])
? $manager['mobilePhone'][0]
: '';
return array(
'displayName' => $displayName,
'mail' => $mail,
'officeLocation' => $officeLocation,
'department' => $department,
'businessPhones' => $businessPhones,
'mobilePhone' => $mobilePhone,
);
}
}
}
<?php
namespace Wpo\Services;
// Prevent public access to this script
defined('ABSPATH') or die();
use \Wpo\Core\User;
use \Wpo\Core\WordPress_Helpers;
use \Wpo\Services\Log_Service;
use \Wpo\Services\Options_Service;
use \Wpo\Services\Graph_Service;
use \Wpo\Services\User_Service;
if (!class_exists('\Wpo\Services\User_Details_Service')) {
class User_Details_Service
{
/**
* @since 11.0
*/
public static function try_improve_core_fields(&$wpo_usr)
{
Log_Service::write_log('DEBUG', '##### -> ' . __METHOD__);
if (isset($wpo_usr->graph_resource['userPrincipalName'])) {
$wpo_usr->upn = $wpo_usr->graph_resource['userPrincipalName'];
}
if (isset($wpo_usr->graph_resource['mail'])) {
$wpo_usr->email = $wpo_usr->graph_resource['mail'];
}
if (isset($wpo_usr->graph_resource['givenName'])) {
$wpo_usr->first_name = $wpo_usr->graph_resource['givenName'];
}
if (isset($wpo_usr->graph_resource['surname'])) {
$wpo_usr->last_name = $wpo_usr->graph_resource['surname'];
}
if (isset($wpo_usr->graph_resource['displayName'])) {
$wpo_usr->full_name = $wpo_usr->graph_resource['displayName'];
}
$graph_display_name_format = Options_Service::get_global_string_var('graph_display_name_format');
if ($graph_display_name_format == 'skip') {
$wpo_usr->full_name = '';
} else {
if (!empty($wpo_usr->first_name) && !empty($wpo_usr->last_name)) {
if ($graph_display_name_format == 'givenNameSurname') {
$wpo_usr->full_name = sprintf('%s %s', $wpo_usr->first_name, $wpo_usr->last_name);
} elseif ($graph_display_name_format == 'surnameGivenName') {
$wpo_usr->full_name = sprintf('%s, %s', $wpo_usr->last_name, $wpo_usr->first_name);
}
}
}
}
/**
* Retrieves the user's AAD group memberships and adds them to the internally used User.
*
* @since 11.0
*
* @param string $resource_identifier Object ID or user principal name
* @param bool $use_me Deprecated, the method will decide for itself
* @param bool $use_delegated If the true the plugin will use a token with delegated permissions
* @param bool $return_error Whether the method should return the error if one occurs
*
* @return object The graph resource if request or else null
*/
public static function get_graph_user($resource_identifier = null, $use_me = false, $use_delegated = false, $return_error = false)
{
Log_Service::write_log('DEBUG', '##### -> ' . __METHOD__);
$query = empty($resource_identifier)
? '/me'
: '/users/' . \rawurlencode($resource_identifier);
$select_properties = Options_Service::get_global_list_var('graph_select_properties');
if (!empty($select_properties)) {
$default_properties = array('businessPhones', 'displayName', 'givenName', 'jobTitle', 'mail', 'mobilePhone', 'officeLocation', 'preferredLanguage', 'surname', 'userPrincipalName', 'id', 'city', 'companyName', 'country', 'department', 'employeeId', 'streetAddress', 'state', 'postalCode');
$select_properties = array_merge($select_properties, $default_properties);
$select_properties = array_map(function ($item) {
return \trim($item);
}, $select_properties);
$query = sprintf(
'%s?$select=%s',
$query,
\implode(',', $select_properties)
);
}
$headers = array(
'Accept: application/json;odata.metadata=minimal',
'Content-Type: application/json',
);
$graph_resource = Graph_Service::fetch($query, 'GET', false, $headers, $use_delegated);
if (Graph_Service::is_fetch_result_ok($graph_resource, 'Could not retrieve user details')) {
return $graph_resource['payload'];
}
return $return_error ? $graph_resource : null;
}
/**
* This helper will create a new member graph_resource on the wpo_usr parameter,
* populates it with fields from the ID token instead and eventually returns the
* wpo_usr.
*
* @since 18.0
*
* @param object &$wpo_usr By reference
* @param object $id_token
* @return void
*/
public static function update_wpo_usr_from_id_token(&$wpo_usr, $id_token)
{
$extra_user_fields = Options_Service::get_global_list_var('extra_user_fields');
$wpo_usr->graph_resource = array();
// Just copy these "core" fields for User_Details_Service::try_improve_core_fields
if (!empty($wpo_usr->email)) {
$wpo_usr->graph_resource['mail'] = $wpo_usr->email;
}
if (!empty($wpo_usr->first_name)) {
$wpo_usr->graph_resource['givenName'] = $wpo_usr->first_name;
}
if (!empty($wpo_usr->last_name)) {
$wpo_usr->graph_resource['surname'] = $wpo_usr->last_name;
}
// Now try to add custom user fields to the mocked graph_resource
if (!empty($extra_user_fields)) {
$id_token_props = get_object_vars($id_token);
foreach ($extra_user_fields as $index => $keyValuePair) {
if (empty($keyValuePair) || !is_array($keyValuePair) || empty($keyValuePair['key'])) {
continue;
}
$parsed_user_field_key = self::parse_user_field_key($keyValuePair['key']);
$name = $parsed_user_field_key[0];
$value = array_key_exists($name, $id_token_props)
? $id_token_props[$name]
: false;
if (empty($value)) {
continue;
}
$wpo_usr->graph_resource[$name] = $value;
}
}
}
/**
* This helper will create a new member graph_resource on the wpo_usr parameter,
* populates it with fields from the SAML response instead and eventually returns the
* wpo_usr.
*
* @since 20.0
*
* @param mixed $wpo_usr
* @param mixed $saml_attributes
* @return void
*/
public static function update_wpo_usr_from_saml_attributes(&$wpo_usr, $saml_attributes)
{
if (is_array($saml_attributes)) {
$wpo_usr->saml_attributes = $saml_attributes;
}
}
/**
* Parses the extra_user_fields key that since v19.5 may be a compound field that contains
* the name for the usermeta field in WordPress for the user attribute retrieved from Microsoft
* Graph.
*
* @since 20.0
*
* @param mixed $name The name of the Microsoft Graph property possibly combined with a proposed name for the key for the usermeta e.g. mobilePhone;#msGraphMobilePhone
* @return array The name of the Microsoft Graph property and the proposed name for the key for the usermeta.
*/
public static function parse_user_field_key($name)
{
if (false !== WordPress_Helpers::stripos($name, ';#')) {
$name_arr = explode(';#', $name);
$name = $name_arr[0];
if (sizeof($name_arr) > 1) {
$wp_user_meta_key = $name_arr[1];
}
}
$wp_user_meta_key = empty($wp_user_meta_key) ? $name : $wp_user_meta_key;
return array(
$name,
$wp_user_meta_key
);
}
/**
* Administrators can prevent WordPress from sending emails when their email changed.
* This is especially useful since WordPress doesn't compare new and old email addresses
* case insensitive.
*
* @since 11.9
*
* @return boolean Whether or not to send the email changed notification.
*/
public static function prevent_send_email_change_email()
{
Log_Service::write_log('DEBUG', '##### -> ' . __METHOD__);
if (Options_Service::get_global_boolean_var('prevent_send_email_change_email')) {
return false;
}
return true;
}
}
}
<?php
namespace Wpo\Services;
use WP_Role;
use \Wpo\Core\Permissions_Helpers;
use \Wpo\Services\Log_Service;
use \Wpo\Services\Options_Service;
// Prevent public access to this script
defined('ABSPATH') or die();
if (!class_exists('\Wpo\Services\User_Role_Service')) {
class User_Role_Service
{
public static function update_user_roles($wp_usr_id, $wpo_usr)
{
Log_Service::write_log('DEBUG', '##### -> ' . __METHOD__);
if (Options_Service::get_global_boolean_var('enable_audiences') && class_exists('\Wpo\Services\Audiences_Service')) {
// Optionally update audience assignments
\Wpo\Services\Audiences_Service::aad_group_x_audience($wp_usr_id, $wpo_usr);
}
if (class_exists('\Wpo\Services\Mapped_Itthinx_Groups_Service') && method_exists('\Wpo\Services\Mapped_Itthinx_Groups_Service', 'aad_group_x_itthinx_group')) {
// Optionally update itthinx group assignments
\Wpo\Services\Mapped_Itthinx_Groups_Service::aad_group_x_itthinx_group($wp_usr_id, $wpo_usr);
}
if (class_exists('\Wpo\Services\Mapped_Itthinx_Groups_Service') && method_exists('\Wpo\Services\Mapped_Itthinx_Groups_Service', 'custom_field_x_itthinx_group')) {
// Optionally update itthinx group assignments
\Wpo\Services\Mapped_Itthinx_Groups_Service::custom_field_x_itthinx_group($wp_usr_id, $wpo_usr);
}
/**
* @since 24.0 LearnDash Integration
*/
if (class_exists('\Wpo\Services\LearnDash_Integration_Service') && method_exists('\Wpo\Services\LearnDash_Integration_Service', 'update_ld_assignments')) {
\Wpo\Services\LearnDash_Integration_Service::update_ld_assignments($wp_usr_id, $wpo_usr->groups);
}
$update_strategy = strtolower(Options_Service::get_global_string_var('replace_or_update_user_roles'));
if ($update_strategy == 'skip') {
Log_Service::write_log('DEBUG', __METHOD__ . ' -> Target role for user could not be determined because the administrator configured the plugin to not update user roles');
return;
}
// Get all possible roles for user
$user_roles = self::get_user_roles($wp_usr_id, $wpo_usr);
$wp_usr = \get_user_by('ID', $wp_usr_id);
if (!Options_Service::get_global_boolean_var('update_admins') && (\in_array('administrator', $wp_usr->roles) || is_super_admin($wp_usr_id))) {
Log_Service::write_log('DEBUG', __METHOD__ . ' -> Not updating the role for a user that is already an administrator.');
return;
}
$usr_default_role = is_main_site()
? Options_Service::get_global_string_var('new_usr_default_role')
: Options_Service::get_global_string_var('mu_new_usr_default_role');
// Remove default role -> It will be added later if requested as fallback
if (in_array($usr_default_role, $wp_usr->roles)) {
$wp_usr->remove_role($usr_default_role);
// refresh the user meta for
$wp_usr = \get_user_by('ID', $wp_usr_id);
}
// Empty any existing roles when configured to do so
if ($update_strategy == 'replace') {
foreach ($wp_usr->roles as $current_user_role) {
/**
* @since 24.0 Filters whether the role should be removed.
*/
$skip_remove_role = apply_filters('wpo365/roles/remove', false, $current_user_role);
if (!$skip_remove_role) {
$wp_usr->remove_role($current_user_role);
}
}
// refresh the user meta for
$wp_usr = \get_user_by('ID', $wp_usr_id);
}
// Add from new roles if not already added
foreach ($user_roles as $user_role) {
if (false === in_array($user_role, $wp_usr->roles)) {
$wp_usr->add_role($user_role);
}
}
// refresh the user meta for
$wp_usr = \get_user_by('ID', $wp_usr_id);
// Add default role if needed / configured
if (empty($wp_usr->roles) || (!empty($wp_usr->roles) && false === Options_Service::get_global_boolean_var('default_role_as_fallback'))) {
if (!empty($usr_default_role)) {
$wp_role = self::get_wp_role_case($usr_default_role);
if (empty($wp_role)) {
Log_Service::write_log('ERROR', __METHOD__ . ' -> Trying to add the default role but it appears undefined');
} else {
$wp_usr->add_role($usr_default_role);
}
}
}
}
/**
* Find a WP role in an case insensitive matter.
*
* @since 24.0
*
* @param mixed $role_name
* @return WP_Role|null
*/
public static function get_wp_role_case($role_name)
{
$wp_roles_objects = wp_roles()->role_objects;
foreach ($wp_roles_objects as $wp_role) {
if (strcasecmp($wp_role->name, $role_name) === 0) {
return $wp_role;
}
}
return null;
}
/**
* Gets the user's default role or if a mapping exists overrides that default role
* and returns the role according to the mapping.
*
* @since 3.2
*
*
* @return mixed(array|WP_Error) user's role as string or an WP_Error if not defined
*/
private static function get_user_roles($wp_usr_id, $wpo_usr)
{
$user_roles = array();
// Graph user resource property x WP role
if (class_exists('\Wpo\Services\Mapped_Custom_Fields_Service') && method_exists('\Wpo\Services\Mapped_Custom_Fields_Service', 'custom_field_x_role')) {
\Wpo\Services\Mapped_Custom_Fields_Service::custom_field_x_role($user_roles, $wpo_usr);
}
// AAD group x WP role
if (class_exists('\Wpo\Services\Mapped_Aad_Groups_Service') && method_exists('\Wpo\Services\Mapped_Aad_Groups_Service', 'aad_group_x_role')) {
\Wpo\Services\Mapped_Aad_Groups_Service::aad_group_x_role($user_roles, $wpo_usr);
}
// AAD group x Super Admin
if (class_exists('\Wpo\Services\Mapped_Aad_Groups_Service') && method_exists('\Wpo\Services\Mapped_Aad_Groups_Service', 'aad_group_x_super_admin')) {
\Wpo\Services\Mapped_Aad_Groups_Service::aad_group_x_super_admin($wp_usr_id, $wpo_usr, true);
}
// Logon Domain x WP role
if (class_exists('\Wpo\Services\Mapped_Domains_Service') && method_exists('\Wpo\Services\Mapped_Domains_Service', 'domain_x_role')) {
\Wpo\Services\Mapped_Domains_Service::domain_x_role($user_roles, $wpo_usr);
}
return $user_roles;
}
}
}
{
"name": "wpo365/wpo365-custom-fields",
"type": "plugin",
"description": "Synchronize Azure AD user attributes e.g. department, job title etc. to WordPress user profiles (includes the PROFILE+ extension).",
"keywords": ["wordpress", "Office 365", "O365", "Azure AD"],
"homepage": "https://www.wpo365.com/",
"license": "",
"authors": [
{
"name": "Marco van Wieren",
"email": "support@wpo365.com",
"homepage": "https://www.wpo365.com/",
"role": "Developer"
}
],
"require": {
"php": ">=5.6.40"
},
"autoload": {
"psr-4": {
"Wpo\\": "",
"Wpo\\Services\\": "Services"
}
}
}
Downloads by van Wieren - WPO365 | EXTENSION
Copyright 2012 - 2014
End User License Agreement
Commercial use
After you have purchased the plus version of our plugin
and have downloaded the plugin as ZIP file, you are licensed
to install the plugin only into the number of website(s)
corresponding to the license you purchased plus into a
corresponding staging environments.
You may not duplicate the plugin in whole or in part,
except that you may make one copy of it for backup or
archival purposes.
You may terminate this license at any time by destroying the
original and all copies of the plugin in whatever form.
You may permanently transfer all of your rights under this
EULA provided you transfer all copies of the plugin (including
copies of all prior versions if the plugin is an upgrade) and
retain none, and the recipient agrees to the terms of this EULA.
You may not redistribute, modify or resold the plugin in any
way without the written permission of Downloads by van Wieren. You may not rent,
lease, or lend the plugin. You may not use the plugin in any
software or application that compete with products and services
of Downloads by van Wieren.
School / Non-profit
If you purchase the School / Non-profit license, Downloads by van Wieren may
request you to submit proof of your organization’s status in
writing.
Warranty
Plugins sold and distributed by Downloads by van Wieren are done so in the hope
that they will be useful, but WITHOUT ANY WARRANTY. Inasmuch as
WordPress functions correctly on a clean install of itself,
Downloads by van Wieren plugins are guaranteed to function on a clean install
of the minimum, stable and required version of WordPress for
the plugins. Because the number and variety of third-party
plugins and themes is vast and wide, we do not guarantee that
the plugin will function with all third-party plugins,
themes or browsers of any kind.
We do not assume responsibility and will not be held responsible
for any conflicts or compatibility issues that may occur due to
third-party software. We assume no responsibility for any data
loss as a result of installing or using Downloads by van Wieren plugins.
Should conflicts occur with third-party software, we may provide support
at our discretion.
Refund Policy
We firmly believe in and stand behind our products 100%, but
we understand that they cannot work perfectly for everyone all
of the time. If you would like to request a refund, please contact
us at info@wpo365.com.
When requesting a refund, we respectfully ask that you meet the
following refund policy conditions:
Eligibility conditions for a refund request:
- You are within the first 30 days of the original purchase of the plugin.
- We cannot grant refunds after the first 30 days of the original purchase.
- You have purchased the plugin and after installing and testing the plugin,
have found that it will not work for your business or required setup.
Or
- You have an issue that we are unable to resolve which makes the system unusable.
We may ask you questions regarding the nature of your refund request so we can
improve the plugin in the future.
- If your issue(s) comes from not being able to install the plugin properly
or get the plugin to perform its basic functions, we will happily consider
your refund request.
- You have contacted our support team and allowed us to attempt to resolve
your issue(s), or have explained why the plugin will not work for you.
Please note, technical issues caused by 3rd party plugins, themes or other
software will not provide grounds for a refund.
- You agree to deactivate and uninstall the plugin from your site if a refund
is granted.
- Refunds will be offered at our sole discretion. By purchasing plugin(s) from
our site, you agree to this refund policy and relinquish any rights to subject
it to any questions, judgment or legal actions. We are not liable to cover any
differences in exchange rates between the time you purchased and the time you are
refunded.
Restrictions
Prohibition on Reverse Engineering, Decompilation, and Disassembly. You may not
reverse engineer, decompile, or disassemble the plugin in any way without the
written permission of Downloads by van Wieren.
Copyright
The plugin is owned by Downloads by van Wieren, and is protected by copyright laws
and international copyright treaties, as well as other intellectual property laws
and treaties. The plugin is licensed, not sold, to You for use solely subject to
the terms and conditions of this Agreement.
Termination
Without prejudice to any other rights, Downloads by van Wieren may terminate this
EULA if you fail to comply with the terms and conditions of this EULA. In such event,
you must destroy all copies of the plugin.
\ No newline at end of file
<?php
// autoload.php @generated by Composer
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInitf106db3bb07a0cc7f373b495de3213f9::getLoader();
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Autoload;
/**
* ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
*
* $loader = new \Composer\Autoload\ClassLoader();
*
* // register classes with namespaces
* $loader->add('Symfony\Component', __DIR__.'/component');
* $loader->add('Symfony', __DIR__.'/framework');
*
* // activate the autoloader
* $loader->register();
*
* // to enable searching the include path (eg. for PEAR packages)
* $loader->setUseIncludePath(true);
*
* In this example, if you try to use a class in the Symfony\Component
* namespace or one of its children (Symfony\Component\Console for instance),
* the autoloader will first look for the class under the component/
* directory, and it will then fallback to the framework/ directory if not
* found before giving up.
*
* This class is loosely based on the Symfony UniversalClassLoader.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Jordi Boggiano <j.boggiano@seld.be>
* @see http://www.php-fig.org/psr/psr-0/
* @see http://www.php-fig.org/psr/psr-4/
*/
class ClassLoader
{
// PSR-4
private $prefixLengthsPsr4 = array();
private $prefixDirsPsr4 = array();
private $fallbackDirsPsr4 = array();
// PSR-0
private $prefixesPsr0 = array();
private $fallbackDirsPsr0 = array();
private $useIncludePath = false;
private $classMap = array();
private $classMapAuthoritative = false;
private $missingClasses = array();
private $apcuPrefix;
public function getPrefixes()
{
if (!empty($this->prefixesPsr0)) {
return call_user_func_array('array_merge', $this->prefixesPsr0);
}
return array();
}
public function getPrefixesPsr4()
{
return $this->prefixDirsPsr4;
}
public function getFallbackDirs()
{
return $this->fallbackDirsPsr0;
}
public function getFallbackDirsPsr4()
{
return $this->fallbackDirsPsr4;
}
public function getClassMap()
{
return $this->classMap;
}
/**
* @param array $classMap Class to filename map
*/
public function addClassMap(array $classMap)
{
if ($this->classMap) {
$this->classMap = array_merge($this->classMap, $classMap);
} else {
$this->classMap = $classMap;
}
}
/**
* Registers a set of PSR-0 directories for a given prefix, either
* appending or prepending to the ones previously set for this prefix.
*
* @param string $prefix The prefix
* @param array|string $paths The PSR-0 root directories
* @param bool $prepend Whether to prepend the directories
*/
public function add($prefix, $paths, $prepend = false)
{
if (!$prefix) {
if ($prepend) {
$this->fallbackDirsPsr0 = array_merge(
(array) $paths,
$this->fallbackDirsPsr0
);
} else {
$this->fallbackDirsPsr0 = array_merge(
$this->fallbackDirsPsr0,
(array) $paths
);
}
return;
}
$first = $prefix[0];
if (!isset($this->prefixesPsr0[$first][$prefix])) {
$this->prefixesPsr0[$first][$prefix] = (array) $paths;
return;
}
if ($prepend) {
$this->prefixesPsr0[$first][$prefix] = array_merge(
(array) $paths,
$this->prefixesPsr0[$first][$prefix]
);
} else {
$this->prefixesPsr0[$first][$prefix] = array_merge(
$this->prefixesPsr0[$first][$prefix],
(array) $paths
);
}
}
/**
* Registers a set of PSR-4 directories for a given namespace, either
* appending or prepending to the ones previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-4 base directories
* @param bool $prepend Whether to prepend the directories
*
* @throws \InvalidArgumentException
*/
public function addPsr4($prefix, $paths, $prepend = false)
{
if (!$prefix) {
// Register directories for the root namespace.
if ($prepend) {
$this->fallbackDirsPsr4 = array_merge(
(array) $paths,
$this->fallbackDirsPsr4
);
} else {
$this->fallbackDirsPsr4 = array_merge(
$this->fallbackDirsPsr4,
(array) $paths
);
}
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
// Register directories for a new namespace.
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
} elseif ($prepend) {
// Prepend directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
(array) $paths,
$this->prefixDirsPsr4[$prefix]
);
} else {
// Append directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
$this->prefixDirsPsr4[$prefix],
(array) $paths
);
}
}
/**
* Registers a set of PSR-0 directories for a given prefix,
* replacing any others previously set for this prefix.
*
* @param string $prefix The prefix
* @param array|string $paths The PSR-0 base directories
*/
public function set($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr0 = (array) $paths;
} else {
$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
}
}
/**
* Registers a set of PSR-4 directories for a given namespace,
* replacing any others previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-4 base directories
*
* @throws \InvalidArgumentException
*/
public function setPsr4($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr4 = (array) $paths;
} else {
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
}
}
/**
* Turns on searching the include path for class files.
*
* @param bool $useIncludePath
*/
public function setUseIncludePath($useIncludePath)
{
$this->useIncludePath = $useIncludePath;
}
/**
* Can be used to check if the autoloader uses the include path to check
* for classes.
*
* @return bool
*/
public function getUseIncludePath()
{
return $this->useIncludePath;
}
/**
* Turns off searching the prefix and fallback directories for classes
* that have not been registered with the class map.
*
* @param bool $classMapAuthoritative
*/
public function setClassMapAuthoritative($classMapAuthoritative)
{
$this->classMapAuthoritative = $classMapAuthoritative;
}
/**
* Should class lookup fail if not found in the current class map?
*
* @return bool
*/
public function isClassMapAuthoritative()
{
return $this->classMapAuthoritative;
}
/**
* APCu prefix to use to cache found/not-found classes, if the extension is enabled.
*
* @param string|null $apcuPrefix
*/
public function setApcuPrefix($apcuPrefix)
{
$this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
}
/**
* The APCu prefix in use, or null if APCu caching is not enabled.
*
* @return string|null
*/
public function getApcuPrefix()
{
return $this->apcuPrefix;
}
/**
* Registers this instance as an autoloader.
*
* @param bool $prepend Whether to prepend the autoloader or not
*/
public function register($prepend = false)
{
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
}
/**
* Unregisters this instance as an autoloader.
*/
public function unregister()
{
spl_autoload_unregister(array($this, 'loadClass'));
}
/**
* Loads the given class or interface.
*
* @param string $class The name of the class
* @return bool|null True if loaded, null otherwise
*/
public function loadClass($class)
{
if ($file = $this->findFile($class)) {
includeFile($file);
return true;
}
}
/**
* Finds the path to the file where the class is defined.
*
* @param string $class The name of the class
*
* @return string|false The path if found, false otherwise
*/
public function findFile($class)
{
// class map lookup
if (isset($this->classMap[$class])) {
return $this->classMap[$class];
}
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
return false;
}
if (null !== $this->apcuPrefix) {
$file = apcu_fetch($this->apcuPrefix.$class, $hit);
if ($hit) {
return $file;
}
}
$file = $this->findFileWithExtension($class, '.php');
// Search for Hack files if we are running on HHVM
if (false === $file && defined('HHVM_VERSION')) {
$file = $this->findFileWithExtension($class, '.hh');
}
if (null !== $this->apcuPrefix) {
apcu_add($this->apcuPrefix.$class, $file);
}
if (false === $file) {
// Remember that this class does not exist.
$this->missingClasses[$class] = true;
}
return $file;
}
private function findFileWithExtension($class, $ext)
{
// PSR-4 lookup
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
$first = $class[0];
if (isset($this->prefixLengthsPsr4[$first])) {
$subPath = $class;
while (false !== $lastPos = strrpos($subPath, '\\')) {
$subPath = substr($subPath, 0, $lastPos);
$search = $subPath . '\\';
if (isset($this->prefixDirsPsr4[$search])) {
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
foreach ($this->prefixDirsPsr4[$search] as $dir) {
if (file_exists($file = $dir . $pathEnd)) {
return $file;
}
}
}
}
}
// PSR-4 fallback dirs
foreach ($this->fallbackDirsPsr4 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
return $file;
}
}
// PSR-0 lookup
if (false !== $pos = strrpos($class, '\\')) {
// namespaced class name
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
} else {
// PEAR-like class name
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
}
if (isset($this->prefixesPsr0[$first])) {
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
if (0 === strpos($class, $prefix)) {
foreach ($dirs as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
}
}
}
// PSR-0 fallback dirs
foreach ($this->fallbackDirsPsr0 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
// PSR-0 include paths.
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
return $file;
}
return false;
}
}
/**
* Scope isolated include.
*
* Prevents access to $this/self from included files.
*/
function includeFile($file)
{
include $file;
}
Copyright (c) Nils Adermann, Jordi Boggiano
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
<?php
// autoload_classmap.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
);
<?php
// autoload_namespaces.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
);
<?php
// autoload_psr4.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'Wpo\\Services\\' => array($baseDir . '/Services'),
'Wpo\\' => array($baseDir . '/'),
);
<?php
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitf106db3bb07a0cc7f373b495de3213f9
{
private static $loader;
public static function loadClassLoader($class)
{
if ('Composer\Autoload\ClassLoader' === $class) {
require __DIR__ . '/ClassLoader.php';
}
}
/**
* @return \Composer\Autoload\ClassLoader
*/
public static function getLoader()
{
if (null !== self::$loader) {
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitf106db3bb07a0cc7f373b495de3213f9', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInitf106db3bb07a0cc7f373b495de3213f9', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require_once __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitf106db3bb07a0cc7f373b495de3213f9::getInitializer($loader));
} else {
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
$loader->set($namespace, $path);
}
$map = require __DIR__ . '/autoload_psr4.php';
foreach ($map as $namespace => $path) {
$loader->setPsr4($namespace, $path);
}
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
$loader->addClassMap($classMap);
}
}
$loader->register(true);
return $loader;
}
}
<?php
// autoload_static.php @generated by Composer
namespace Composer\Autoload;
class ComposerStaticInitf106db3bb07a0cc7f373b495de3213f9
{
public static $prefixLengthsPsr4 = array (
'W' =>
array (
'Wpo\\Services\\' => 13,
'Wpo\\' => 4,
),
);
public static $prefixDirsPsr4 = array (
'Wpo\\Services\\' =>
array (
0 => __DIR__ . '/../..' . '/Services',
),
'Wpo\\' =>
array (
0 => __DIR__ . '/../..' . '/',
),
);
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitf106db3bb07a0cc7f373b495de3213f9::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitf106db3bb07a0cc7f373b495de3213f9::$prefixDirsPsr4;
}, null, ClassLoader::class);
}
}
<?php
/**
* Plugin Name: WPO365 | CUSTOM USER FIELDS
* Plugin URI: https://www.wpo365.com/downloads/wpo365-custom-user-fields/
* Description: Synchronize Azure AD user attributes e.g. department, job title etc. to WordPress user profiles (includes the PROFILE+ extension).
* Version: 25.1
* Author: support@wpo365.com
* Author URI: https://www.wpo365.com
* License: See license.txt
*/
namespace Wpo;
require __DIR__ . '/vendor/autoload.php';
// Prevent public access to this script
defined('ABSPATH') or die();
if (!class_exists('\Wpo\Custom_Fields')) {
class Custom_Fields
{
public function __construct()
{
// Show admin notification when BASIC edition is not installed
add_action('admin_notices', array($this, 'ensure_wpo365_login'), 10, 0);
add_action('network_admin_notices', array($this, 'ensure_wpo365_login'), 10, 0);
add_action('plugins_loaded', array($this, 'ensure_wpo365_login'), 10, 0);
}
public function ensure_wpo365_login()
{
$version_exists = \class_exists('\Wpo\Core\Version') && isset(\Wpo\Core\Version::$current) && \Wpo\Core\Version::$current >= 20;
if (current_action() == 'plugins_loaded') {
if (!$version_exists) {
if (false === function_exists('deactivate_plugins')) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
deactivate_plugins(plugin_basename(__FILE__));
}
return;
}
$plugin_exists = \file_exists(dirname(__DIR__) . '/wpo365-login');
// Required version installed and activated
if ($version_exists) {
return;
}
// Required plugin not installed
if (!$plugin_exists) {
$install_url = wp_nonce_url(
add_query_arg(
array(
'action' => 'install-plugin',
'plugin' => 'wpo365-login',
'from' => 'plugins',
),
self_admin_url('update.php')
),
'install-plugin_wpo365-login'
);
echo '<div class="notice notice-error" style="margin-left: 2px;"><p>'
. sprintf(__('The %s plugin requires the latest version of %s to be installed and activated.', 'wpo365-login'), '<strong>WPO365 | CUSTOM USER FIELDS</strong>', '<strong>WPO365 | LOGIN (free)</strong>')
. '</p><p>'
. '<a class="button button-primary" href="' . esc_url($install_url) . '">' . __('Install plugin', 'wpo365-login') . '</a>.'
. '</p></div>';
return;
}
// Required plubin installed but must either be activated or upgraded
$activate_url = add_query_arg(
array(
'_wpnonce' => wp_create_nonce('activate-plugin_wpo365-login/wpo365-login.php'),
'action' => 'activate',
'plugin' => 'wpo365-login/wpo365-login.php',
),
network_admin_url('plugins.php')
);
if (is_network_admin()) {
$activate_url = add_query_arg(array('networkwide' => 1), $activate_url);
}
$update_url = wp_nonce_url(
self_admin_url('update.php?action=upgrade-plugin&plugin=') . 'wpo365-login/wpo365-login.php',
'upgrade-plugin_wpo365-login/wpo365-login.php'
);
echo '<div class="notice notice-error" style="margin-left: 2px;"><p>'
. sprintf(__('The %s plugin requires the latest version of %s to be installed and activated.', 'wpo365-login'), '<strong>WPO365 | CUSTOM USER FIELDS</strong>', '<strong>WPO365 | LOGIN (free)</strong>')
. '</p><p>'
. '<a class="button button-primary" href="' . esc_url($activate_url) . '">' . __('Activate plugin', 'wpo365-login') . '</a>&nbsp;'
. '<a class="button button-primary" href="' . esc_url($update_url) . '">' . __('Update plugin', 'wpo365-login') . '</a>'
. '</p></div>';
}
}
}
$wpo365_custom_fields = new Custom_Fields();