query_vars['active_directory_thumbnails'] ) ){
if ( $_REQUEST['nonce'] != get_option('adt_nonce')) {
exit("No naughty business please"); /* ONLY DO THIS IF YOU ARE IN THE ENDPOINT, otherwise it just stops all queries withing the nonce */
}
if (empty($query->query_vars['active_directory_thumbnails'])) { /* If no ID is present then do the bulk */
self::$helper->adt_bulk_get_users_and_save_pics();
exit;
} else { /* If ID is present then do the individual process */
self::$helper->adt_get_user_photo($query->query_vars['active_directory_thumbnails']);
exit;
}
}
}
public static function deactivate() {
/* Redo rewrite rules to remove endpoint */
flush_rewrite_rules(false);
/* Deletes the database field */
delete_option('adt_ad_thumbnail');
delete_option('adt_replace_avatar');
delete_option('adt_replace_bp_avatar');
delete_option('adt_nonce');
/* Delete thumbnail folder */
self::$helper->adt_delete_folder(wp_upload_dir()['basedir'] . '/active-directory-thumbnails');
/* Deletes all database links to generated thumbs */
$aUsersID = self::$helper->adt_get_all_users();
foreach($aUsersID as $iUserID):
delete_user_meta($iUserID, 'adt_user_photo_url');
delete_user_meta($iUserID, 'adt_user_photo_filename');
endforeach; /* end the users loop. */
}
public function add_menu() {
add_users_page('Active Directory Thumbnails Options', 'Active Directory Thumbnails', 1, 'active-directory-thumbnails', array(&$this, 'plugin_settings_page'));
}
public function plugin_settings_page() {
if(!current_user_can('manage_options')) {
wp_die(__('You do not have sufficient permissions to access this page.'));
}
self::adt_enqueue();
include(sprintf("%s/lib/options.php", dirname(__FILE__)));
}
public function adt_register() {
wp_register_style( 'jquery-ui-theme', WP_PLUGIN_URL.'/active-directory-thumbnails/css/jquery-ui.css' );
wp_register_script( 'adt', plugins_url( '/js/adt.js', __FILE__ ), array('jquery'));
}
public function adt_enqueue() {
wp_enqueue_script( 'jquery-ui-core' );
wp_enqueue_script( 'jquery-ui-progressbar' );
wp_enqueue_style( 'jquery-ui-theme' );
/* Get strings ready to provide to the JavaScript Localize API in WordPress */
$alert_msg = __('Please do not close the browser while this process is ongoing. Please press OK to start.', 'active-directory-thumbnails');
$completed_msg = __('Done! Created image for', 'active-directory-thumbnails');
wp_localize_script( 'adt', 'adt_url_users', array(
'alert_msg' => $alert_msg,
'completed_msg' => $completed_msg,
'adt_nonce' => get_option('adt_nonce'),
'site_url' => site_url(), /* Also using the Translate API to pass some data we will need. */
'user_list' => self::$helper->adt_get_all_users() /* See above comment */
) );
wp_enqueue_script( 'adt' );
}
}
}
/* Runs when plugin is activated */
register_activation_hook(__FILE__, array('adt_i88', 'activate'));
/* Runs on plugin deactivation*/
register_deactivation_hook(__FILE__, array('adt_i88', 'deactivate'));
$wp_plugin_template = new adt_i88();
/* Add a link to the settings page onto the plugin page */
if(isset($wp_plugin_template)) {
/* Add the settings link to the plugins page */
function adt_i88_plugin_settings_link($links) {
$settings_translate = __('Settings', 'active-directory-thumbnails');
$settings_link = '' . $settings_translate . '';
$contribute_translate = __('Contribute on GitHub', 'active-directory-thumbnails');
$contribute_link = '' . $contribute_translate . '';
return array_merge( $links, array($settings_link, $contribute_link) );
}
$plugin = plugin_basename(__FILE__);
add_filter("plugin_action_links_$plugin", 'adt_i88_plugin_settings_link');
}
if (get_option('adt_replace_avatar', false)) {
add_filter( 'get_avatar' , 'adt_replace_avatar' , 20 , 5 );
}
function adt_replace_bp_avatar_core($avatar, $params) {
if ($params['object'] == 'user') {
$user = get_user_by( 'id' , $params['item_id'] );
$height = $params['height'];
$width = $params['width'];
$alt = $params['alt'];
return adt_return_user_photo($avatar, $user, $height, $width, '', $alt);
} else {
return $avatar;
}
}
if (get_option('adt_replace_bp_avatar',false)) {
add_filter('bp_core_fetch_avatar', 'adt_replace_bp_avatar_core', 20, 2);
}
function adt_replace_avatar( $avatar, $id_or_email, $size, $default, $alt ) {
$user = false;
if ( is_numeric( $id_or_email ) ) { /* Is it the ID? */
$id = (int) $id_or_email;
$user = get_user_by( 'id' , $id );
} elseif ( is_object( $id_or_email ) ) { /* Did someone pass the user object!? */
if ( ! empty( $id_or_email->user_id ) ) {
$id = (int) $id_or_email->user_id;
$user = get_user_by( 'id' , $id );
}
} else { /* Is it the email? */
$user = get_user_by( 'email', $id_or_email );
}
return adt_return_user_photo($avatar, $user, $size, $size, $default, $alt);
}
function adt_return_user_photo($avatar, $user, $height, $width, $default, $alt) {
if (isset($user->adt_user_photo_url)) {
$file_url = wp_upload_dir()['baseurl'] . '/active-directory-thumbnails/' . $user->adt_user_photo_filename;
$avatar = "
";
return $avatar;
} else {
return $avatar;
}
}