initial commit
This commit is contained in:
@@ -0,0 +1,595 @@
|
||||
<?php
|
||||
/**
|
||||
* Defines all of administrative, activation, and deactivation settings.
|
||||
*
|
||||
* @package One User Avatar
|
||||
* @author Bangbay Siboliban
|
||||
* @author Flippercode
|
||||
* @author ProfilePress
|
||||
* @author One Designs
|
||||
* @copyright 2013-2014 Bangbay Siboliban
|
||||
* @copyright 2014-2020 Flippercode
|
||||
* @copyright 2020-2021 ProfilePress
|
||||
* @copyright 2021 One Designs
|
||||
* @version 2.3.9
|
||||
*/
|
||||
|
||||
class WP_User_Avatar_Admin {
|
||||
/**
|
||||
* Constructor
|
||||
* @since 1.8
|
||||
* @uses bool $show_avatars
|
||||
* @uses add_action()
|
||||
* @uses add_filter()
|
||||
* @uses load_plugin_textdomain()
|
||||
* @uses register_activation_hook()
|
||||
* @uses register_deactivation_hook()
|
||||
*/
|
||||
public function __construct() {
|
||||
global $show_avatars;
|
||||
|
||||
// Initialize default settings
|
||||
register_activation_hook( WPUA_DIR . 'wp-user-avatar.php', array( $this, 'wpua_options' ) );
|
||||
|
||||
// Settings saved to wp_options
|
||||
add_action( 'admin_init', array( $this, 'wpua_options' ) );
|
||||
|
||||
// Enqueue scripts
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'wpua_enqueue_scripts' ) );
|
||||
|
||||
// Perform bulk actions
|
||||
add_action( 'load-avatars_page_wp-user-avatar-library', array( $this, 'wpua_bulk_actions' ) );
|
||||
|
||||
// Translations
|
||||
load_plugin_textdomain( 'one-user-avatar', '', WPUA_FOLDER . '/languages' );
|
||||
|
||||
// Admin menu settings
|
||||
add_action( 'admin_init', array( $this, 'wpua_register_settings' ) );
|
||||
add_action( 'admin_menu', array( $this, 'wpua_admin' ) );
|
||||
|
||||
// Default avatar
|
||||
add_filter( 'default_avatar_select', array( $this, 'wpua_add_default_avatar' ) );
|
||||
|
||||
if ( function_exists('add_allowed_options' ) ) {
|
||||
add_filter( 'allowed_options', array( $this, 'wpua_whitelist_options' ) );
|
||||
} else {
|
||||
add_filter( 'whitelist_options', array( $this, 'wpua_whitelist_options' ) );
|
||||
}
|
||||
|
||||
// Additional plugin info
|
||||
add_filter( 'plugin_action_links', array( $this, 'wpua_action_links'), 10, 2 );
|
||||
add_filter( 'plugin_row_meta', array( $this, 'wpua_row_meta'), 10, 2 );
|
||||
|
||||
// Hide column in Users table if default avatars are enabled
|
||||
if ( 0 == (bool) $show_avatars ) {
|
||||
add_filter( 'manage_users_columns', array($this, 'wpua_add_column') );
|
||||
add_filter( 'manage_users_custom_column', array($this, 'wpua_show_column'), 10, 3 );
|
||||
}
|
||||
|
||||
// Media states
|
||||
add_filter( 'display_media_states', array($this, 'wpua_add_media_state') );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings saved to wp_options
|
||||
* @since 1.4
|
||||
* @uses add_option()
|
||||
*/
|
||||
public function wpua_options() {
|
||||
add_option( 'avatar_default_wp_user_avatar', '' );
|
||||
add_option( 'wp_user_avatar_allow_upload', '0' );
|
||||
add_option( 'wp_user_avatar_disable_um_avatars', '0' );
|
||||
add_option( 'wp_user_avatar_force_file_uploader', '0' );
|
||||
add_option( 'wp_user_avatar_disable_gravatar', '0' );
|
||||
add_option( 'wp_user_avatar_edit_avatar', '1' );
|
||||
add_option( 'wp_user_avatar_resize_crop', '0' );
|
||||
add_option( 'wp_user_avatar_resize_h', '96' );
|
||||
add_option( 'wp_user_avatar_resize_upload', '0' );
|
||||
add_option( 'wp_user_avatar_resize_w', '96' );
|
||||
add_option( 'wp_user_avatar_tinymce', '1' );
|
||||
add_option( 'wp_user_avatar_upload_size_limit', '0' );
|
||||
|
||||
if ( wp_next_scheduled( 'wpua_has_gravatar_cron_hook' ) ) {
|
||||
$cron = get_option( 'cron' );
|
||||
|
||||
$new_cron = '';
|
||||
|
||||
foreach ( $cron as $key => $value ) {
|
||||
if ( is_array( $value ) ) {
|
||||
if ( array_key_exists( 'wpua_has_gravatar_cron_hook', $value ) ) {
|
||||
unset($cron[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update_option( 'cron', $cron );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform avatars library bulk actions
|
||||
* @since 2.3.0
|
||||
* @uses wp_enqueue_script()
|
||||
*/
|
||||
public function wpua_enqueue_scripts( $hook_suffix ) {
|
||||
if ( 'avatars_page_wp-user-avatar-library' != $hook_suffix ) {
|
||||
return;
|
||||
}
|
||||
|
||||
wp_enqueue_style( 'wp-user-avatar', WPUA_CSS_URL . 'wp-user-avatar.css', '', WPUA_VERSION );
|
||||
|
||||
wp_enqueue_script( 'wp-ajax-response' );
|
||||
wp_enqueue_script( 'media' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform avatars library bulk actions
|
||||
* @since 2.3.0
|
||||
* @uses wp_delete_attachment()
|
||||
*/
|
||||
public function wpua_bulk_actions() {
|
||||
global $wpua_admin;
|
||||
|
||||
$wp_list_table = $wpua_admin->_wpua_get_list_table( 'WP_User_Avatar_List_Table' );
|
||||
|
||||
// Handle bulk actions
|
||||
$doaction = $wp_list_table->current_action();
|
||||
|
||||
if ( $doaction ) {
|
||||
check_admin_referer( 'bulk-media' );
|
||||
|
||||
$post_ids = array();
|
||||
$ids = array();
|
||||
|
||||
if ( isset( $_REQUEST['media'] ) && is_array( $_REQUEST['media'] ) ) {
|
||||
$ids = $_REQUEST['media'];
|
||||
}
|
||||
|
||||
foreach ( $ids as $post_id ) {
|
||||
$post = get_post( absint( $post_id ) );
|
||||
|
||||
if ( $post instanceof WP_Post ) {
|
||||
$post_ids[] = $post->ID;
|
||||
}
|
||||
}
|
||||
|
||||
$location = esc_url( add_query_arg( array( 'page' => 'wp-user-avatar-library' ), 'admin.php' ) );
|
||||
|
||||
if ( $referer = wp_get_referer() ) {
|
||||
if ( false !== strpos( $referer, 'admin.php' ) ) {
|
||||
$location = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'message', 'posted' ), $referer );
|
||||
}
|
||||
}
|
||||
|
||||
switch( $doaction ) {
|
||||
case 'delete':
|
||||
if ( empty( $post_ids ) ) {
|
||||
break;
|
||||
}
|
||||
|
||||
foreach ( $post_ids as $post_id_del ) {
|
||||
if ( ! current_user_can( 'delete_post', $post_id_del ) ) {
|
||||
wp_die( esc_html__( 'You are not allowed to delete this post.', 'one-user-avatar' ) );
|
||||
}
|
||||
|
||||
if ( ! wp_delete_attachment( $post_id_del ) ) {
|
||||
wp_die( esc_html__( 'Error in deleting.','one-user-avatar' ) );
|
||||
}
|
||||
}
|
||||
|
||||
$location = esc_url_raw( add_query_arg( 'deleted', count( $post_ids ), $location ) );
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
wp_redirect( $location );
|
||||
|
||||
exit;
|
||||
} elseif( ! empty( $_GET['_wp_http_referer'] ) ) {
|
||||
wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
|
||||
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* On deactivation
|
||||
* @since 1.4
|
||||
* @uses int $blog_id
|
||||
* @uses object $wpdb
|
||||
* @uses get_blog_prefix()
|
||||
* @uses get_option()
|
||||
* @uses update_option()
|
||||
*/
|
||||
public function wpua_deactivate() {
|
||||
global $blog_id, $wpdb;
|
||||
|
||||
$wp_user_roles = $wpdb->get_blog_prefix( $blog_id ) . 'user_roles';
|
||||
|
||||
// Get user roles and capabilities
|
||||
$user_roles = get_option( $wp_user_roles );
|
||||
|
||||
// Remove subscribers edit_posts capability
|
||||
unset( $user_roles['subscriber']['capabilities']['edit_posts'] );
|
||||
|
||||
update_option( $wp_user_roles, $user_roles );
|
||||
|
||||
// Reset all default avatars to Mystery Man
|
||||
update_option( 'avatar_default', 'mystery' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add options page and settings
|
||||
* @since 1.4
|
||||
* @uses add_menu_page()
|
||||
* @uses add_submenu_page()
|
||||
*/
|
||||
public function wpua_admin() {
|
||||
$svg = '
|
||||
<svg width="512.001" height="512.001" viewBox="0 0 135.467 135.467" xmlns="http://www.w3.org/2000/svg"><path style="display:inline;stroke-width:.999999" d="M180.002.174a17.987 17.987 0 0 0-18.025 18.025v98.602a131.325 188.897 0 0 0-4.612 7.365h-96.43a19.573 19.573 0 0 0-19.615 19.615v11.795a19.573 19.573 0 0 0 19.616 19.615h73.267a131.325 188.897 0 0 0-11.213 75.838 131.325 188.897 0 0 0 12.43 79.385 217.103 217.103 0 0 0-17.617 13.379c-5.428 4.581-15.387 13.939-14.553 13.676.254-.08 4.902-2.39 10.326-5.131a313.886 313.886 0 0 1 25.432-11.455 131.325 188.897 0 0 0 16.637 34.185H22.795A22.48 22.48 0 0 0 .265 397.6v112.545a22.48 22.48 0 0 0 22.53 22.53h466.674A22.482 22.482 0 0 0 512 510.146V397.6a22.482 22.482 0 0 0-22.531-22.532H352.986a131.325 188.897 0 0 0 16.36-33.38c10.991 4.467 22.222 9.58 29.336 13.544 2.668 1.487 5.05 2.725 5.293 2.75.673.07-3.04-3.618-9.452-9.388a220.278 220.278 0 0 0-21.664-17.155 131.325 188.897 0 0 0 12.782-80.41 131.325 188.897 0 0 0-11.213-75.838H453.7a19.573 19.573 0 0 0 19.615-19.615v-11.795a19.573 19.573 0 0 0-19.615-19.615H351.266a131.325 188.897 0 0 0-6.922-10.28V18.2c0-9.985-8.04-18.025-18.026-18.025zM149.725 175.19h208.718a116.879 171.16 0 0 1 12.52 76.352 116.879 171.16 0 0 1-10.791 71.719c-25.29-15.015-53.398-24.497-84.356-28.408-8.029-1.015-35.42-1.137-43.212-.194-31.229 3.78-59.46 13.1-84.844 27.953a116.879 171.16 0 0 1-10.555-71.07 116.879 171.16 0 0 1 12.52-76.352zm45.226 44.707a12.472 12.473 0 0 0-12.472 12.473 12.472 12.473 0 0 0 12.472 12.475 12.472 12.473 0 0 0 12.473-12.475 12.472 12.473 0 0 0-12.473-12.473zm120.113 0a12.472 12.472 0 0 0-12.472 12.473 12.472 12.472 0 0 0 12.472 12.473 12.472 12.472 0 0 0 12.471-12.473 12.472 12.472 0 0 0-12.47-12.473zm-63.097 99.147c34.639-.12 69.336 5.53 102.135 16.826.374.13.82.312 1.2.445a116.879 171.16 0 0 1-24.325 44.06 116.845 171.704 0 0 1-1.079 1.315 116.879 171.16 0 0 1-75.814 41.012 116.879 171.16 0 0 1-61.354-25.705 116.845 171.704 0 0 1-2.482-2.176 116.879 171.16 0 0 1-9.478-10.39 116.845 171.704 0 0 1-4.801-5.842 116.879 171.16 0 0 1-23.295-42.783 310.482 310.482 0 0 1 37.428-10.287c20.318-4.254 41.081-6.403 61.865-6.475z" transform="scale(.26458)"/></svg>';
|
||||
|
||||
add_menu_page(
|
||||
__( 'One User Avatar', 'one-user-avatar' ),
|
||||
__( 'Avatars', 'one-user-avatar' ),
|
||||
'manage_options',
|
||||
'one-user-avatar',
|
||||
array( $this, 'wpua_options_page' ),
|
||||
'data:image/svg+xml;base64,' . base64_encode( $svg )
|
||||
);
|
||||
|
||||
add_submenu_page(
|
||||
'one-user-avatar',
|
||||
__( 'Settings', 'one-user-avatar' ),
|
||||
__( 'Settings', 'one-user-avatar' ),
|
||||
'manage_options',
|
||||
'one-user-avatar',
|
||||
array( $this, 'wpua_options_page' )
|
||||
);
|
||||
|
||||
$hook = add_submenu_page(
|
||||
'one-user-avatar',
|
||||
__( 'Library', 'one-user-avatar' ),
|
||||
__( 'Library', 'one-user-avatar' ),
|
||||
'manage_options',
|
||||
'wp-user-avatar-library',
|
||||
array( $this, 'wpua_media_page' )
|
||||
);
|
||||
|
||||
add_action( "load-$hook", array( $this, 'wpua_media_screen_option' ) );
|
||||
add_filter( 'set-screen-option', array( $this, 'wpua_set_media_screen_option' ), 10, 3 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if current page is settings page
|
||||
* @since 1.8.3
|
||||
* @uses string $pagenow
|
||||
* @return bool
|
||||
*/
|
||||
public function wpua_is_menu_page() {
|
||||
global $pagenow;
|
||||
|
||||
$is_menu_page = ( 'admin.php' == $pagenow && isset( $_GET['page'] ) && 'one-user-avatar' == $_GET['page'] ) ? true : false;
|
||||
|
||||
return (bool) $is_menu_page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Media page
|
||||
* @since 1.8
|
||||
*/
|
||||
public function wpua_media_page() {
|
||||
require_once( WPUA_INC . 'wpua-media-page.php' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Avatars per page
|
||||
* @since 1.8.10
|
||||
* @uses add_screen_option()
|
||||
*/
|
||||
public function wpua_media_screen_option() {
|
||||
add_screen_option( 'per_page', array(
|
||||
'label' => __( 'Avatars', 'one-user-avatar' ),
|
||||
'default' => 10,
|
||||
'option' => 'upload_per_page'
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Save per page setting
|
||||
* @since 1.8.10
|
||||
* @param int $status
|
||||
* @param string $option
|
||||
* @param int $value
|
||||
* @return int $status
|
||||
*/
|
||||
public function wpua_set_media_screen_option( $status, $option, $value ) {
|
||||
$status = ( 'upload_per_page' == $option ) ? $value : $status;
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options page
|
||||
* @since 1.4
|
||||
*/
|
||||
public function wpua_options_page() {
|
||||
require_once( WPUA_INC . 'wpua-options-page.php' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Whitelist settings
|
||||
* @since 1.9
|
||||
* @uses apply_filters()
|
||||
* @uses register_setting()
|
||||
* @return array
|
||||
*/
|
||||
public function wpua_register_settings() {
|
||||
$settings = array();
|
||||
|
||||
$settings[] = register_setting( 'wpua-settings-group', 'avatar_rating' );
|
||||
$settings[] = register_setting( 'wpua-settings-group', 'avatar_default' );
|
||||
$settings[] = register_setting( 'wpua-settings-group', 'avatar_default_wp_user_avatar' );
|
||||
$settings[] = register_setting( 'wpua-settings-group', 'show_avatars', 'intval' );
|
||||
$settings[] = register_setting( 'wpua-settings-group', 'wp_user_avatar_tinymce', 'intval' );
|
||||
$settings[] = register_setting( 'wpua-settings-group', 'wp_user_avatar_allow_upload', 'intval' );
|
||||
$settings[] = register_setting( 'wpua-settings-group', 'wp_user_avatar_disable_um_avatars', 'intval' );
|
||||
$settings[] = register_setting( 'wpua-settings-group', 'wp_user_avatar_force_file_uploader', 'intval' );
|
||||
$settings[] = register_setting( 'wpua-settings-group', 'wp_user_avatar_disable_gravatar', 'intval' );
|
||||
$settings[] = register_setting( 'wpua-settings-group', 'wp_user_avatar_edit_avatar', 'intval' );
|
||||
$settings[] = register_setting( 'wpua-settings-group', 'wp_user_avatar_resize_crop', 'intval' );
|
||||
$settings[] = register_setting( 'wpua-settings-group', 'wp_user_avatar_resize_h', 'intval' );
|
||||
$settings[] = register_setting( 'wpua-settings-group', 'wp_user_avatar_resize_upload', 'intval' );
|
||||
$settings[] = register_setting( 'wpua-settings-group', 'wp_user_avatar_resize_w', 'intval' );
|
||||
$settings[] = register_setting( 'wpua-settings-group', 'wp_user_avatar_upload_size_limit', 'intval' );
|
||||
|
||||
/**
|
||||
* Filter admin whitelist settings
|
||||
* @since 1.9
|
||||
* @param array $settings
|
||||
*/
|
||||
return apply_filters( 'wpua_register_settings', $settings );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add default avatar
|
||||
* @since 1.4
|
||||
* @uses string $avatar_default
|
||||
* @uses string $mustache_admin
|
||||
* @uses string $mustache_medium
|
||||
* @uses int $wpua_avatar_default
|
||||
* @uses bool $wpua_disable_gravatar
|
||||
* @uses object $wpua_functions
|
||||
* @uses get_avatar()
|
||||
* @uses remove_filter()
|
||||
* @uses wpua_attachment_is_image()
|
||||
* @uses wpua_get_attachment_image_src()
|
||||
* @return string
|
||||
*/
|
||||
public function wpua_add_default_avatar() {
|
||||
global $avatar_default, $mustache_admin, $mustache_medium, $wpua_avatar_default, $wpua_disable_gravatar, $wpua_functions;
|
||||
|
||||
// Remove get_avatar filter
|
||||
remove_filter( 'get_avatar', array( $wpua_functions, 'wpua_get_avatar_filter' ) );
|
||||
|
||||
// Set avatar_list variable
|
||||
$avatar_list = '';
|
||||
|
||||
// Set avatar defaults
|
||||
$avatar_defaults = array(
|
||||
'mystery' => __( 'Mystery Man', 'one-user-avatar'),
|
||||
'blank' => __( 'Blank', 'one-user-avatar'),
|
||||
'gravatar_default' => __( 'Gravatar Logo', 'one-user-avatar'),
|
||||
'identicon' => __( 'Identicon (Generated)', 'one-user-avatar'),
|
||||
'wavatar' => __( 'Wavatar (Generated)', 'one-user-avatar'),
|
||||
'monsterid' => __( 'MonsterID (Generated)', 'one-user-avatar'),
|
||||
'retro' => __( 'Retro (Generated)', 'one-user-avatar')
|
||||
);
|
||||
|
||||
$avatar_defaults = apply_filters( 'avatar_defaults', $avatar_defaults );
|
||||
|
||||
// No Default Avatar, set to Mystery Man
|
||||
if ( empty( $avatar_default ) ) {
|
||||
$avatar_default = 'mystery';
|
||||
}
|
||||
|
||||
// Take avatar_defaults and get examples for unknown@gravatar.com
|
||||
foreach ( $avatar_defaults as $default_key => $default_name ) {
|
||||
$avatar = get_avatar( 'unknown@gravatar.com', 32, $default_key );
|
||||
$selected = ( $avatar_default == $default_key ) ? ' checked="checked" ' : '';
|
||||
|
||||
$avatar_list .= sprintf(
|
||||
'<label><input type="radio" name="avatar_default" id="avatar_%1$s" value="%1$s" %2$s/> ',
|
||||
esc_attr( $default_key ),
|
||||
$selected
|
||||
);
|
||||
$avatar_list .= preg_replace( "/src='(.+?)'/", "src='\$1&forcedefault=1'", $avatar );
|
||||
$avatar_list .= ' ' . $default_name . '</label>';
|
||||
$avatar_list .= '<br />';
|
||||
}
|
||||
|
||||
// Show remove link if custom Default Avatar is set
|
||||
if ( ! empty( $wpua_avatar_default ) && $wpua_functions->wpua_attachment_is_image( $wpua_avatar_default ) ) {
|
||||
$avatar_thumb_src = $wpua_functions->wpua_get_attachment_image_src( $wpua_avatar_default, array( 32, 32 ) );
|
||||
$avatar_thumb = $avatar_thumb_src[0];
|
||||
$hide_remove = '';
|
||||
} else {
|
||||
$avatar_thumb = $mustache_admin;
|
||||
$hide_remove = ' class="wpua-hide"';
|
||||
}
|
||||
|
||||
// Default Avatar is wp_user_avatar, check the radio button next to it
|
||||
$selected_avatar = ( 1 == (bool) $wpua_disable_gravatar || 'wp_user_avatar' == $avatar_default ) ? ' checked="checked" ' : '';
|
||||
|
||||
// Wrap WPUA in div
|
||||
$avatar_thumb_img = sprintf( '<div id="wpua-preview"><img src="%s" width="32" /></div>', esc_url( $avatar_thumb ) );
|
||||
|
||||
// Add WPUA to list
|
||||
$wpua_list = sprintf(
|
||||
'<label><input type="radio" name="avatar_default" id="wp_user_avatar_radio" value="wp_user_avatar" %s /> ',
|
||||
$selected_avatar
|
||||
);
|
||||
|
||||
$wpua_list .= preg_replace( "/src='(.+?)'/", "src='\$1'", $avatar_thumb_img );
|
||||
$wpua_list .= ' ' . __( 'One User Avatar', 'one-user-avatar' ) . '</label>';
|
||||
$wpua_list .= '<p id="wpua-edit"><button type="button" class="button" id="wpua-add" name="wpua-add" data-avatar_default="true" data-title="' . __( 'Choose Image', 'one-user-avatar' ) . ': ' . __( 'Default Avatar', 'one-user-avatar' ) . '">' . __( 'Choose Image', 'one-user-avatar' ) . '</button>';
|
||||
$wpua_list .= '<span id="wpua-remove-button"' . $hide_remove . '><a href="#" id="wpua-remove">' . __( 'Remove', 'one-user-avatar' ) . '</a></span><span id="wpua-undo-button"><a href="#" id="wpua-undo">' . __( 'Undo', 'one-user-avatar' ) . '</a></span></p>';
|
||||
$wpua_list .= '<input type="hidden" id="wp-user-avatar" name="avatar_default_wp_user_avatar" value="' . $wpua_avatar_default . '">';
|
||||
$wpua_list .= '<div id="wpua-modal"></div>';
|
||||
|
||||
if ( 1 != (bool) $wpua_disable_gravatar ) {
|
||||
return $wpua_list . '<div id="wp-avatars">' . $avatar_list . '</div>';
|
||||
} else {
|
||||
return $wpua_list . '<div id="wp-avatars" style="display:none;">' . $avatar_list . '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add default avatar_default to whitelist
|
||||
* @since 1.4
|
||||
* @param array $options
|
||||
* @return array $options
|
||||
*/
|
||||
public function wpua_whitelist_options( $options ) {
|
||||
$options['discussion'][] = 'avatar_default_wp_user_avatar';
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add actions links on plugin page
|
||||
* @since 1.6.6
|
||||
* @param array $links
|
||||
* @param string $file
|
||||
* @return array $links
|
||||
*/
|
||||
public function wpua_action_links( $links, $file ) {
|
||||
if( basename( dirname( $file ) ) == 'one-user-avatar' ) {
|
||||
$links[] = sprintf(
|
||||
'<a href="%s">%s</a>',
|
||||
esc_url( add_query_arg( array( 'page' => 'one-user-avatar' ), admin_url( 'admin.php' ) ) ),
|
||||
__( 'Settings', 'one-user-avatar' )
|
||||
);
|
||||
}
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add row meta on plugin page
|
||||
* @since 1.6.6
|
||||
* @param array $links
|
||||
* @param string $file
|
||||
* @return array $links
|
||||
*/
|
||||
public function wpua_row_meta( $links, $file ) {
|
||||
if ( 'one-user-avatar' == basename( dirname( $file ) ) ) {
|
||||
$links[] = sprintf(
|
||||
'<a href="%s" target="_blank">%s</a>',
|
||||
esc_url( __( 'https://onedesigns.com/support/forum/plugins/one-user-avatar/', 'one-user-avatar' ) ),
|
||||
__( 'Support Forums', 'one-user-avatar' )
|
||||
);
|
||||
}
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add column to Users table
|
||||
* @since 1.4
|
||||
* @param array $columns
|
||||
* @return array
|
||||
*/
|
||||
public function wpua_add_column($columns) {
|
||||
return $columns + array( 'one-user-avatar' => __( 'Profile Picture', 'one-user-avatar' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Show thumbnail in Users table
|
||||
* @since 1.4
|
||||
* @param string $value
|
||||
* @param string $column_name
|
||||
* @param int $user_id
|
||||
* @uses int $blog_id
|
||||
* @uses object $wpdb
|
||||
* @uses object $wpua_functions
|
||||
* @uses get_blog_prefix()
|
||||
* @uses get_user_meta()
|
||||
* @uses wpua_get_attachment_image()
|
||||
* @return string $value
|
||||
*/
|
||||
public function wpua_show_column( $value, $column_name, $user_id ) {
|
||||
global $blog_id, $wpdb, $wpua_functions;
|
||||
|
||||
$wpua = get_user_meta( $user_id, $wpdb->get_blog_prefix( $blog_id ) . 'user_avatar', true );
|
||||
$wpua_image = $wpua_functions->wpua_get_attachment_image( $wpua, array( 32, 32 ) );
|
||||
|
||||
if ( 'one-user-avatar' == $column_name ) {
|
||||
$value = $wpua_image;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list table
|
||||
* @since 1.8
|
||||
* @param string $class
|
||||
* @param array $args
|
||||
* @return object
|
||||
*/
|
||||
public function _wpua_get_list_table( $class, $args = array() ) {
|
||||
require_once( WPUA_INC . 'class-wp-user-avatar-list-table.php' );
|
||||
|
||||
$args['screen'] = 'one-user-avatar';
|
||||
|
||||
return new $class( $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add media states
|
||||
* @since 1.4
|
||||
* @param array $states
|
||||
* @uses object $post
|
||||
* @uses int $wpua_avatar_default
|
||||
* @uses apply_filters()
|
||||
* @uses get_post_custom_values()
|
||||
* @return array
|
||||
*/
|
||||
public function wpua_add_media_state($states) {
|
||||
global $post, $wpua_avatar_default;
|
||||
|
||||
$is_wpua = isset( $post->ID ) ? get_post_custom_values( '_wp_attachment_wp_user_avatar', $post->ID ) : '';
|
||||
|
||||
if ( ! empty( $is_wpua ) ) {
|
||||
$states[] = __( 'Profile Picture', 'one-user-avatar' );
|
||||
}
|
||||
|
||||
if ( ! empty ( $wpua_avatar_default ) && isset( $post->ID ) && ( $wpua_avatar_default == $post->ID ) ) {
|
||||
$states[] = __( 'Default Avatar', 'one-user-avatar' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter media states
|
||||
* @since 1.4
|
||||
* @param array $states
|
||||
*/
|
||||
return apply_filters( 'wpua_add_media_state', $states );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize
|
||||
* @since 1.9.2
|
||||
*/
|
||||
function wpua_admin_init() {
|
||||
global $wpua_admin;
|
||||
|
||||
if ( ! isset( $wpua_admin ) ) {
|
||||
$wpua_admin = new WP_User_Avatar_Admin();
|
||||
}
|
||||
|
||||
return $wpua_admin;
|
||||
}
|
||||
add_action( 'init', 'wpua_admin_init' );
|
@@ -0,0 +1,915 @@
|
||||
<?php
|
||||
/**
|
||||
* Core user functions.
|
||||
*
|
||||
* @package One User Avatar
|
||||
* @author Bangbay Siboliban
|
||||
* @author Flippercode
|
||||
* @author ProfilePress
|
||||
* @author One Designs
|
||||
* @copyright 2013-2014 Bangbay Siboliban
|
||||
* @copyright 2014-2020 Flippercode
|
||||
* @copyright 2020-2021 ProfilePress
|
||||
* @copyright 2021 One Designs
|
||||
* @version 2.3.9
|
||||
*/
|
||||
|
||||
class WP_User_Avatar_Functions {
|
||||
/**
|
||||
* Constructor
|
||||
* @since 1.8
|
||||
* @uses add_filter()
|
||||
* @uses register_activation_hook()
|
||||
* @uses register_deactivation_hook()
|
||||
*/
|
||||
public function __construct() {
|
||||
add_filter( 'get_avatar', array( $this, 'wpua_get_avatar_filter' ), 10, 6 );
|
||||
|
||||
add_filter( 'get_avatar_url', array( $this, 'wpua_get_avatar_url' ), 10, 3 );
|
||||
|
||||
// Filter to display One User Avatar at Buddypress
|
||||
add_filter( 'bp_core_fetch_avatar', array( $this, 'wpua_bp_core_fetch_avatar_filter' ), 10, 5 );
|
||||
|
||||
// Filter to display One User Avatar by URL at Buddypress
|
||||
add_filter( 'bp_core_fetch_avatar_url', array( $this, 'wpua_bp_core_fetch_avatar_url_filter' ), 10, 5 );
|
||||
|
||||
// Maybe replace the custom avatars functionality in the Ultimate Member plugin
|
||||
add_action( 'init', array( $this, 'wpua_maybe_disable_um_avatars' ), 10, 0 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
function wpua_get_avatar_url( $url, $id_or_email, $args ){
|
||||
global $wpua_disable_gravatar;
|
||||
|
||||
$user_id = null;
|
||||
|
||||
if ( is_object( $id_or_email ) ) {
|
||||
if ( ! empty( $id_or_email->comment_author_email ) ) {
|
||||
$user_id = $id_or_email->user_id;
|
||||
}
|
||||
} else {
|
||||
if ( is_email( $id_or_email ) ) {
|
||||
$user = get_user_by( 'email', $id_or_email );
|
||||
|
||||
if ( $user ) {
|
||||
$user_id = $user->ID;
|
||||
}
|
||||
} else {
|
||||
$user_id = $id_or_email;
|
||||
}
|
||||
}
|
||||
|
||||
// First checking custom avatar.
|
||||
if ( has_wp_user_avatar( $user_id ) ) {
|
||||
$url = $this->get_wp_user_avatar_src( $user_id );
|
||||
} else if( $wpua_disable_gravatar ) {
|
||||
$url = $this->wpua_get_default_avatar_url( $url, $id_or_email, $args );
|
||||
} else {
|
||||
$has_valid_url = $this->wpua_has_gravatar( $id_or_email );
|
||||
|
||||
if ( ! $has_valid_url ) {
|
||||
$url = $this->wpua_get_default_avatar_url( $url, $id_or_email, $args );
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Filter get_avatar_url filter
|
||||
* @since 4.1.9
|
||||
* @param string $url
|
||||
* @param int|string $id_or_email
|
||||
* @param array $args
|
||||
*/
|
||||
return apply_filters( 'wpua_get_avatar_filter_url', $url, $id_or_email );
|
||||
}
|
||||
|
||||
|
||||
function wpua_get_default_avatar_url( $url, $id_or_email, $args ){
|
||||
global $avatar_default,
|
||||
$mustache_admin,
|
||||
$mustache_avatar,
|
||||
$mustache_medium,
|
||||
$mustache_original,
|
||||
$mustache_thumbnail,
|
||||
$post,
|
||||
$wpua_avatar_default,
|
||||
$wpua_disable_gravatar,
|
||||
$wpua_functions;
|
||||
|
||||
$default_image_details = array();
|
||||
|
||||
$size = ! empty( $args['size'] ) ? $args['size'] : 96;
|
||||
|
||||
// Show custom Default Avatar
|
||||
if ( ! empty( $wpua_avatar_default ) && $wpua_functions->wpua_attachment_is_image( $wpua_avatar_default ) ) {
|
||||
// Get image
|
||||
$wpua_avatar_default_image = $wpua_functions->wpua_get_attachment_image_src(
|
||||
$wpua_avatar_default,
|
||||
array( $size, $size )
|
||||
);
|
||||
|
||||
// Image src
|
||||
$url = $wpua_avatar_default_image[0];
|
||||
} else {
|
||||
// Get mustache image based on numeric size comparison
|
||||
if ( $size > get_option( 'medium_size_w' ) ) {
|
||||
$url = $mustache_original;
|
||||
} elseif ( $size <= get_option( 'medium_size_w' ) && $size > get_option( 'thumbnail_size_w' ) ) {
|
||||
$url = $mustache_medium;
|
||||
} elseif ( $size <= get_option( 'thumbnail_size_w' ) && 96 < $size ) {
|
||||
$url = $mustache_thumbnail;
|
||||
} elseif ( 96 >= $size && 32 < $size ) {
|
||||
$url = $mustache_avatar;
|
||||
} elseif ( 32 >= $size ) {
|
||||
$url = $mustache_admin;
|
||||
}
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns One User Avatar or Gravatar-hosted image if user doesn't have Buddypress-uploaded image
|
||||
* @param string $avatar
|
||||
* @param array $params
|
||||
* @param int $item_id
|
||||
* @param string $avatar_dir
|
||||
* @param string $css_id
|
||||
* @param int $html_width
|
||||
* @param int $html_height
|
||||
* @param string $avatar_folder_url
|
||||
* @param string $avatar_folder_dir
|
||||
* @uses object $wpua_functions
|
||||
* @uses wpua_get_avatar_filter()
|
||||
*/
|
||||
public function wpua_bp_core_fetch_avatar_filter( $gravatar, $params, $item_id = '', $avatar_dir = '', $css_id = '', $html_width = '', $html_height =' ', $avatar_folder_url = '', $avatar_folder_dir = '') {
|
||||
global $wpua_functions;
|
||||
|
||||
if ( -1 < strpos( $gravatar, 'gravatar.com' , 0 ) ) {
|
||||
$avatar = $wpua_functions->wpua_get_avatar_filter(
|
||||
$gravatar,
|
||||
( 'user' == $params['object'] ) ? $params['item_id'] : '',
|
||||
( 'user' == $params['object'] ) ? ( ( 'thumb' == $params['type'] ) ? 50 :150 ) : 50,
|
||||
'',
|
||||
''
|
||||
);
|
||||
|
||||
return $avatar;
|
||||
}
|
||||
|
||||
return $gravatar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns WP user default local avatar URL or Gravatar-hosted image URL if user doesn't have Buddypress-uploaded image
|
||||
* @param string $avatar
|
||||
* @param array $params
|
||||
* @uses object $wpua_functions
|
||||
* @uses wpua_get_avatar_filter()
|
||||
*/
|
||||
public function wpua_bp_core_fetch_avatar_url_filter( $gravatar, $params ) {
|
||||
global $wpua_functions;
|
||||
|
||||
if ( -1 < strpos( $gravatar, 'gravatar.com', 0 ) ) {
|
||||
$avatar = $this->wpua_get_avatar_url( $gravatar, $params['email'], $params );
|
||||
|
||||
return $avatar;
|
||||
}
|
||||
|
||||
return $gravatar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if user has Gravatar-hosted image
|
||||
* @since 1.4
|
||||
* @param int|string $id_or_email
|
||||
* @param bool $has_gravatar
|
||||
* @param int|string $user
|
||||
* @param string $email
|
||||
* @uses get_user_by()
|
||||
* @uses is_wp_error()
|
||||
* @uses wp_cache_get()
|
||||
* @uses wp_cache_set()
|
||||
* @uses wp_remote_head()
|
||||
* @return bool $has_gravatar
|
||||
*/
|
||||
public function wpua_has_gravatar( $id_or_email = '', $has_gravatar = 0, $user = '', $email = '') {
|
||||
global $wpua_hash_gravatar,
|
||||
$avatar_default,
|
||||
$mustache_admin,
|
||||
$mustache_avatar,
|
||||
$mustache_medium,
|
||||
$mustache_original,
|
||||
$mustache_thumbnail,
|
||||
$post,
|
||||
$wpua_avatar_default,
|
||||
$wpua_disable_gravatar,
|
||||
$wpua_functions;
|
||||
|
||||
// User has WPUA
|
||||
// Decide if check gravatar required or not.
|
||||
if ( 'wp_user_avatar' != trim( $avatar_default ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( ! is_object( $id_or_email ) && ! empty( $id_or_email ) ) {
|
||||
// Find user by ID or e-mail address
|
||||
$user = is_numeric( $id_or_email ) ? get_user_by( 'id', $id_or_email ) : get_user_by( 'email', $id_or_email );
|
||||
|
||||
// Get registered user e-mail address
|
||||
$email = ! empty( $user ) ? $user->user_email : '';
|
||||
}
|
||||
|
||||
if ( '' == $email ) {
|
||||
if ( ! is_numeric( $id_or_email ) && ! is_object( $id_or_email ) ) {
|
||||
$email = $id_or_email;
|
||||
} elseif ( ! is_numeric( $id_or_email ) && is_object( $id_or_email ) ) {
|
||||
$email = $id_or_email->comment_author_email;
|
||||
}
|
||||
}
|
||||
|
||||
if ( '' != $email ) {
|
||||
$hash = md5( strtolower( trim( $email ) ) );
|
||||
|
||||
//check if gravatar exists for hashtag using options
|
||||
if ( is_array( $wpua_hash_gravatar ) ) {
|
||||
$date = date( 'm-d-Y' );
|
||||
|
||||
if (
|
||||
array_key_exists( $hash, $wpua_hash_gravatar ) &&
|
||||
is_array( $wpua_hash_gravatar[$hash] ) &&
|
||||
array_key_exists( $date, $wpua_hash_gravatar[ $hash ] )
|
||||
) {
|
||||
return (bool) $wpua_hash_gravatar[ $hash ][ $date ];
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
isset( $_SERVER['HTTPS'] ) &&
|
||||
( 'on' == $_SERVER['HTTPS'] || 1 == $_SERVER['HTTPS'] ) ||
|
||||
isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) &&
|
||||
'https' == $_SERVER['HTTP_X_FORWARDED_PROTO']
|
||||
) {
|
||||
$http = 'https';
|
||||
} else {
|
||||
$http = 'http';
|
||||
}
|
||||
|
||||
$gravatar = $http . '://www.gravatar.com/avatar/' . $hash . '?d=404';
|
||||
$data = wp_cache_get( $hash );
|
||||
|
||||
if ( false === $data ) {
|
||||
$response = wp_remote_head( $gravatar );
|
||||
$data = is_wp_error( $response ) ? 'not200' : $response['response']['code'];
|
||||
|
||||
wp_cache_set( $hash, $data, $group = '', $expire = 60 * 5 );
|
||||
|
||||
$has_gravatar = ( '200' == $data ) ? true : false;
|
||||
|
||||
if ( false == $wpua_hash_gravatar ) {
|
||||
$date = date( 'm-d-Y' );
|
||||
|
||||
$wpua_hash_gravatar = [];
|
||||
$wpua_hash_gravatar[ $hash ][ $date ] = (bool) $has_gravatar;
|
||||
|
||||
add_option( 'wpua_hash_gravatar', serialize( $wpua_hash_gravatar ), '', false );
|
||||
} else {
|
||||
if ( is_array( $wpua_hash_gravatar ) && ! empty( $wpua_hash_gravatar ) ) {
|
||||
$date = date( 'm-d-Y' );
|
||||
|
||||
if ( array_key_exists( $hash, $wpua_hash_gravatar ) ){
|
||||
unset( $wpua_hash_gravatar[ $hash ] );
|
||||
|
||||
$wpua_hash_gravatar[ $hash ][ $date ] = (bool) $has_gravatar;
|
||||
|
||||
update_option( 'wpua_hash_gravatar', serialize( $wpua_hash_gravatar ), false );
|
||||
}
|
||||
else {
|
||||
$wpua_hash_gravatar[ $hash ][ $date ] = (bool) $has_gravatar;
|
||||
|
||||
update_option( 'wpua_hash_gravatar', serialize( $wpua_hash_gravatar ), false );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$has_gravatar = ( '200' == $data ) ? true : false;
|
||||
} else {
|
||||
$has_gravatar = false;
|
||||
}
|
||||
|
||||
// Check if Gravatar image returns 200 (OK) or 404 (Not Found)
|
||||
return (bool) $has_gravatar;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if local image
|
||||
* @since 1.9.2
|
||||
* @param int $attachment_id
|
||||
* @uses apply_filters()
|
||||
* @uses wp_attachment_is_image()
|
||||
* @return bool
|
||||
*/
|
||||
public function wpua_attachment_is_image( $attachment_id ) {
|
||||
$is_image = wp_attachment_is_image( $attachment_id );
|
||||
|
||||
/**
|
||||
* Filter local image check
|
||||
* @since 1.9.2
|
||||
* @param bool $is_image
|
||||
* @param int $attachment_id
|
||||
*/
|
||||
$is_image = apply_filters( 'wpua_attachment_is_image', $is_image, $attachment_id );
|
||||
|
||||
return (bool) $is_image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get local image tag
|
||||
* @since 1.9.2
|
||||
* @param int $attachment_id
|
||||
* @param int|string $size
|
||||
* @param bool $icon
|
||||
* @param string $attr
|
||||
* @uses apply_filters()
|
||||
* @uses wp_get_attachment_image()
|
||||
* @return string
|
||||
*/
|
||||
public function wpua_get_attachment_image( $attachment_id, $size = 'thumbnail', $icon = 0, $attr = '' ) {
|
||||
$image = wp_get_attachment_image( $attachment_id, $size, $icon, $attr );
|
||||
|
||||
/**
|
||||
* Filter local image tag
|
||||
* @since 1.9.2
|
||||
* @param string $image
|
||||
* @param int $attachment_id
|
||||
* @param int|string $size
|
||||
* @param bool $icon
|
||||
* @param string $attr
|
||||
*/
|
||||
return apply_filters( 'wpua_get_attachment_image', $image, $attachment_id, $size, $icon, $attr );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get local image src
|
||||
* @since 1.9.2
|
||||
* @param int $attachment_id
|
||||
* @param int|string $size
|
||||
* @param bool $icon
|
||||
* @uses apply_filters()
|
||||
* @uses wp_get_attachment_image_src()
|
||||
* @return array
|
||||
*/
|
||||
public function wpua_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon = 0 ) {
|
||||
$image_src_array = wp_get_attachment_image_src( $attachment_id, $size, $icon );
|
||||
|
||||
/**
|
||||
* Filter local image src
|
||||
* @since 1.9.2
|
||||
* @param array $image_src_array
|
||||
* @param int $attachment_id
|
||||
* @param int|string $size
|
||||
* @param bool $icon
|
||||
*/
|
||||
return apply_filters( 'wpua_get_attachment_image_src', $image_src_array, $attachment_id, $size, $icon );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if user has wp_user_avatar
|
||||
* @since 1.1
|
||||
* @param int|string $id_or_email
|
||||
* @param bool $has_wpua
|
||||
* @param object $user
|
||||
* @param int $user_id
|
||||
* @uses int $blog_id
|
||||
* @uses object $wpdb
|
||||
* @uses int $wpua_avatar_default
|
||||
* @uses object $wpua_functions
|
||||
* @uses get_user_by()
|
||||
* @uses get_user_meta()
|
||||
* @uses get_blog_prefix()
|
||||
* @uses wpua_attachment_is_image()
|
||||
* @return bool
|
||||
*/
|
||||
public function has_wp_user_avatar($id_or_email = '', $has_wpua = 0, $user = '', $user_id = '') {
|
||||
global $blog_id, $wpdb, $wpua_avatar_default, $wpua_functions, $avatar_default;
|
||||
|
||||
if ( ! is_object ( $id_or_email ) && ! empty( $id_or_email ) ) {
|
||||
// Find user by ID or e-mail address
|
||||
$user = is_numeric( $id_or_email ) ? get_user_by( 'id', $id_or_email ) : get_user_by( 'email', $id_or_email );
|
||||
|
||||
// Get registered user ID
|
||||
$user_id = ! empty( $user ) ? $user->ID : '';
|
||||
}
|
||||
|
||||
$wpua = get_user_meta( $user_id, $wpdb->get_blog_prefix( $blog_id ) . 'user_avatar', true );
|
||||
|
||||
// Check if avatar is same as default avatar or on excluded list
|
||||
$has_wpua = ! empty( $wpua ) && ( 'wp_user_avatar' != $avatar_default || $wpua != $wpua_avatar_default ) && $wpua_functions->wpua_attachment_is_image( $wpua ) ? true : false;
|
||||
|
||||
return (bool) $has_wpua;
|
||||
}
|
||||
/**
|
||||
* Retrive default image url set by admin.
|
||||
*/
|
||||
public function wpua_default_image( $size ) {
|
||||
global $avatar_default,
|
||||
$mustache_admin,
|
||||
$mustache_avatar,
|
||||
$mustache_medium,
|
||||
$mustache_original,
|
||||
$mustache_thumbnail,
|
||||
$post,
|
||||
$wpua_avatar_default,
|
||||
$wpua_disable_gravatar,
|
||||
$wpua_functions;
|
||||
|
||||
$default_image_details = array();
|
||||
|
||||
// Show custom Default Avatar
|
||||
if ( !empty( $wpua_avatar_default ) && $wpua_functions->wpua_attachment_is_image( $wpua_avatar_default ) ) {
|
||||
// Get image
|
||||
$wpua_avatar_default_image = $wpua_functions->wpua_get_attachment_image_src(
|
||||
$wpua_avatar_default,
|
||||
array( $size, $size )
|
||||
);
|
||||
|
||||
// Image src
|
||||
$default = $wpua_avatar_default_image[0];
|
||||
|
||||
// Add dimensions if numeric size
|
||||
$default_image_details['dimensions'] = sprintf(
|
||||
' width="%s" height="%s"',
|
||||
esc_attr( $wpua_avatar_default_image[1] ),
|
||||
esc_attr( $wpua_avatar_default_image[2] )
|
||||
);
|
||||
} else {
|
||||
// Get mustache image based on numeric size comparison
|
||||
if ( $size > get_option( 'medium_size_w' ) ) {
|
||||
$default = $mustache_original;
|
||||
} elseif( $size <= get_option( 'medium_size_w' ) && $size > get_option( 'thumbnail_size_w' ) ) {
|
||||
$default = $mustache_medium;
|
||||
} elseif( $size <= get_option( 'thumbnail_size_w' ) && 96 < $size ) {
|
||||
$default = $mustache_thumbnail;
|
||||
} elseif( 96 >= $size && 32 < $size ) {
|
||||
$default = $mustache_avatar;
|
||||
} elseif( 32 >= $size ) {
|
||||
$default = $mustache_admin;
|
||||
}
|
||||
|
||||
// Add dimensions if numeric size
|
||||
$default_image_details['dimensions'] = sprintf( ' width="%1$s" height="%1$s"', esc_attr( $size ) );
|
||||
}
|
||||
|
||||
// Construct the img tag
|
||||
$default_image_details['size'] = $size;
|
||||
$default_image_details['src'] = $default;
|
||||
|
||||
return $default_image_details;
|
||||
|
||||
}
|
||||
/**
|
||||
* Replace get_avatar only in get_wp_user_avatar
|
||||
*
|
||||
* @param string $avatar
|
||||
* @param int|string $id_or_email
|
||||
* @param int|string $size
|
||||
* @param string $default
|
||||
* @param string $alt
|
||||
* @param array $args
|
||||
*
|
||||
* @return string $avatar
|
||||
* @since 1.4
|
||||
* @uses string $avatar_default
|
||||
* @uses string $mustache_admin
|
||||
* @uses string $mustache_avatar
|
||||
* @uses string $mustache_medium
|
||||
* @uses string $mustache_original
|
||||
* @uses string $mustache_thumbnail
|
||||
* @uses object $post
|
||||
* @uses int $wpua_avatar_default
|
||||
* @uses bool $wpua_disable_gravatar
|
||||
* @uses object $wpua_functions
|
||||
* @uses apply_filters()
|
||||
* @uses get_wp_user_avatar()
|
||||
* @uses has_wp_user_avatar()
|
||||
* @uses wpua_has_gravatar()
|
||||
* @uses wpua_attachment_is_image()
|
||||
* @uses wpua_get_attachment_image_src()
|
||||
* @uses get_option()
|
||||
* @return string $avatar
|
||||
*/
|
||||
public function wpua_get_avatar_filter( $avatar, $id_or_email = '', $size = '', $default = '', $alt = '', $args = null ) {
|
||||
global $avatar_default,
|
||||
$mustache_admin,
|
||||
$mustache_avatar,
|
||||
$mustache_medium,
|
||||
$mustache_original,
|
||||
$mustache_thumbnail,
|
||||
$post,
|
||||
$wpua_avatar_default,
|
||||
$wpua_disable_gravatar,
|
||||
$wpua_functions;
|
||||
|
||||
// User has WPUA
|
||||
if ( '' == $alt ) {
|
||||
$alt = apply_filters( 'wpua_default_alt_tag', esc_html__( 'Avatar', 'one-user-avatar' ) );
|
||||
}
|
||||
|
||||
$alt = esc_attr($alt);
|
||||
$size = esc_attr($size);
|
||||
$class = [];
|
||||
|
||||
if ( isset( $args['class'] ) ) {
|
||||
if ( is_array( $args['class'] ) ) {
|
||||
$class = array_merge( $class, $args['class'] );
|
||||
} else {
|
||||
$class[] = $args['class'];
|
||||
}
|
||||
}
|
||||
|
||||
$avatar = str_replace( 'gravatar_default', '', $avatar );
|
||||
|
||||
if ( is_object( $id_or_email ) ) {
|
||||
if ( ! empty( $id_or_email->comment_author_email ) ) {
|
||||
$avatar = get_wp_user_avatar( $id_or_email, $size, $default, $alt, $class );
|
||||
} else {
|
||||
$avatar = get_wp_user_avatar( 'unknown@gravatar.com', $size, $default, $alt, $class );
|
||||
}
|
||||
} else {
|
||||
if ( has_wp_user_avatar( $id_or_email ) ) {
|
||||
$avatar = get_wp_user_avatar( $id_or_email, $size, $default, $alt, $class );
|
||||
// User has Gravatar and Gravatar is not disabled
|
||||
} elseif( 1 != (bool) $wpua_disable_gravatar && $wpua_functions->wpua_has_gravatar( $id_or_email ) ) {
|
||||
// find our src
|
||||
if ( ! empty( $avatar ) ) {
|
||||
preg_match_all( '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $avatar, $matches, PREG_SET_ORDER );
|
||||
|
||||
$wpua_avatar_image_src = ! empty( $matches ) ? $matches[0][1] : '';
|
||||
$default_image_details = $this->wpua_default_image( $size );
|
||||
$wpua_default_avatar_image_src = $default_image_details['src'];
|
||||
$wpua_final_avatar_image_src = str_replace(
|
||||
'd=wp_user_avatar',
|
||||
'd=' . urlencode( $wpua_default_avatar_image_src ),
|
||||
$wpua_avatar_image_src
|
||||
);
|
||||
}
|
||||
|
||||
$class_string = ! empty( $class ) ? ' ' . esc_attr( implode( ' ', $class ) ) : '';
|
||||
$avatar = sprintf(
|
||||
'<img src="%1$s"%2$s alt="%3$s" class="avatar avatar-%4$s wp-user-avatar wp-user-avatar-%4$s photo avatar-default" />',
|
||||
esc_url( $wpua_final_avatar_image_src ),
|
||||
$default_image_details['dimensions'],
|
||||
esc_attr( $alt ),
|
||||
esc_attr( $size )
|
||||
);
|
||||
// User doesn't have WPUA or Gravatar and Default Avatar is wp_user_avatar, show custom Default Avatar
|
||||
} elseif ( 'wp_user_avatar' == $avatar_default ) {
|
||||
$default_image_details = $this->wpua_default_image( $size );
|
||||
$class_string = ! empty( $class ) ? ' ' . esc_attr( implode( ' ', $class ) ) : '';
|
||||
$avatar = sprintf(
|
||||
'<img src="%1$s"%2$s alt="%3$s" class="avatar avatar-%4$s wp-user-avatar wp-user-avatar-%4$s photo avatar-default" />',
|
||||
esc_url( $default_image_details['src'] ),
|
||||
$default_image_details['dimensions'],
|
||||
esc_attr( $alt ),
|
||||
esc_attr( $size )
|
||||
);
|
||||
|
||||
return $avatar;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter get_avatar filter
|
||||
* @since 1.9
|
||||
* @param string $avatar
|
||||
* @param int|string $id_or_email
|
||||
* @param int|string $size
|
||||
* @param string $default
|
||||
* @param string $alt
|
||||
*/
|
||||
return apply_filters( 'wpua_get_avatar_filter', $avatar, $id_or_email, $size, $default, $alt );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get original avatar, for when user removes wp_user_avatar
|
||||
* @since 1.4
|
||||
* @param int|string $id_or_email
|
||||
* @param int|string $size
|
||||
* @param string $default
|
||||
* @param string $alt
|
||||
* @uses string $avatar_default
|
||||
* @uses string $mustache_avatar
|
||||
* @uses int $wpua_avatar_default
|
||||
* @uses bool $wpua_disable_gravatar
|
||||
* @uses object $wpua_functions
|
||||
* @uses wpua_attachment_is_image()
|
||||
* @uses wpua_get_attachment_image_src()
|
||||
* @uses wpua_has_gravatar()
|
||||
* @uses add_filter()
|
||||
* @uses apply_filters()
|
||||
* @uses get_avatar()
|
||||
* @uses remove_filter()
|
||||
* @return string $default
|
||||
*/
|
||||
public function wpua_get_avatar_original( $id_or_email = '', $size = '', $default = '', $alt = '' ) {
|
||||
global $avatar_default,
|
||||
$mustache_avatar,
|
||||
$wpua_avatar_default,
|
||||
$wpua_disable_gravatar,
|
||||
$wpua_functions;
|
||||
|
||||
// Remove get_avatar filter
|
||||
remove_filter( 'get_avatar', array( $this, 'wpua_get_avatar_filter' ) );
|
||||
remove_filter( 'get_avatar_url', array( $this, 'wpua_get_avatar_url' ) );
|
||||
|
||||
if ( 1 != (bool) $wpua_disable_gravatar ) {
|
||||
// User doesn't have Gravatar and Default Avatar is wp_user_avatar, show custom Default Avatar
|
||||
if ( ! $wpua_functions->wpua_has_gravatar( $id_or_email ) && 'wp_user_avatar' == $avatar_default) {
|
||||
// Show custom Default Avatar
|
||||
if( ! empty( $wpua_avatar_default ) && $wpua_functions->wpua_attachment_is_image( $wpua_avatar_default ) ) {
|
||||
$size_numeric_w_x_h = array( get_option( $size . '_size_w' ), get_option( $size . '_size_h' ) );
|
||||
$wpua_avatar_default_image = $wpua_functions->wpua_get_attachment_image_src(
|
||||
$wpua_avatar_default,
|
||||
$size_numeric_w_x_h
|
||||
);
|
||||
|
||||
$default = $wpua_avatar_default_image[0];
|
||||
} else {
|
||||
$default = $mustache_avatar;
|
||||
}
|
||||
} else {
|
||||
// Get image from Gravatar, whether it's the user's image or default image
|
||||
$default = get_avatar_url( $id_or_email, array( 'size' => $size ) );
|
||||
}
|
||||
} else {
|
||||
if ( ! empty( $wpua_avatar_default ) && $wpua_functions->wpua_attachment_is_image( $wpua_avatar_default ) ) {
|
||||
$size_numeric_w_x_h = array( get_option( $size . '_size_w' ), get_option( $size . '_size_h' ) );
|
||||
$wpua_avatar_default_image = $wpua_functions->wpua_get_attachment_image_src(
|
||||
$wpua_avatar_default,
|
||||
$size_numeric_w_x_h
|
||||
);
|
||||
|
||||
$default = $wpua_avatar_default_image[0];
|
||||
} else {
|
||||
$default = $mustache_avatar;
|
||||
}
|
||||
}
|
||||
|
||||
// Enable get_avatar filter
|
||||
add_filter( 'get_avatar', array( $this, 'wpua_get_avatar_filter' ), 10, 6 );
|
||||
add_filter( 'get_avatar_url', array( $this, 'wpua_get_avatar_url' ), 10, 3 );
|
||||
|
||||
/**
|
||||
* Filter original avatar src
|
||||
* @since 1.9
|
||||
* @param string $default
|
||||
*/
|
||||
return apply_filters( 'wpua_get_avatar_original', $default );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find WPUA, show get_avatar if empty
|
||||
*
|
||||
* @param int|string $id_or_email
|
||||
* @param int|string $size
|
||||
* @param string $align
|
||||
* @param string $alt
|
||||
* @param array $class
|
||||
*
|
||||
* @return string $avatar
|
||||
* @since 1.0
|
||||
* @uses array $_wp_additional_image_sizes
|
||||
* @uses array $all_sizes
|
||||
* @uses string $avatar_default
|
||||
* @uses int $blog_id
|
||||
* @uses object $post
|
||||
* @uses object $wpdb
|
||||
* @uses int $wpua_avatar_default
|
||||
* @uses object $wpua_functions
|
||||
* @uses apply_filters()
|
||||
* @uses get_the_author_meta()
|
||||
* @uses get_blog_prefix()
|
||||
* @uses get_user_by()
|
||||
* @uses get_query_var()
|
||||
* @uses is_author()
|
||||
* @uses wpua_attachment_is_image()
|
||||
* @uses wpua_get_attachment_image_src()
|
||||
* @uses get_option()
|
||||
* @uses get_avatar()
|
||||
* @return string $avatar
|
||||
*/
|
||||
public function get_wp_user_avatar( $id_or_email = '', $size = '96', $align = '', $alt = '', $class = [] ) {
|
||||
global $all_sizes,
|
||||
$avatar_default,
|
||||
$blog_id,
|
||||
$post,
|
||||
$wpdb,
|
||||
$wpua_avatar_default,
|
||||
$wpua_functions,
|
||||
$_wp_additional_image_sizes;
|
||||
|
||||
$email = 'unknown@gravatar.com';
|
||||
|
||||
// Checks if comment
|
||||
if ( '' == $alt ) {
|
||||
$alt = apply_filters( 'wpua_default_alt_tag', esc_html__( 'Avatar', 'one-user-avatar' ) );
|
||||
}
|
||||
|
||||
if ( is_object( $id_or_email ) ) {
|
||||
// Checks if comment author is registered user by user ID
|
||||
if ( 0 != $id_or_email->user_id ) {
|
||||
$email = $id_or_email->user_id;
|
||||
// Checks that comment author isn't anonymous
|
||||
} elseif ( ! empty( $id_or_email->comment_author_email ) ) {
|
||||
// Checks if comment author is registered user by e-mail address
|
||||
$user = get_user_by( 'email', $id_or_email->comment_author_email );
|
||||
// Get registered user info from profile, otherwise e-mail address should be value
|
||||
$email = ! empty( $user ) ? $user->ID : $id_or_email->comment_author_email;
|
||||
}
|
||||
|
||||
$alt = $id_or_email->comment_author;
|
||||
} else {
|
||||
if ( ! empty( $id_or_email ) ) {
|
||||
// Find user by ID or e-mail address
|
||||
$user = is_numeric( $id_or_email ) ? get_user_by( 'id', $id_or_email ) : get_user_by( 'email', $id_or_email );
|
||||
} else {
|
||||
// Find author's name if id_or_email is empty
|
||||
$author_name = get_query_var( 'author_name' );
|
||||
|
||||
if ( is_author() ) {
|
||||
// On author page, get user by page slug
|
||||
$user = get_user_by( 'slug', $author_name );
|
||||
} else {
|
||||
// On post, get user by author meta
|
||||
$user_id = get_the_author_meta( 'ID' );
|
||||
$user = get_user_by( 'id', $user_id );
|
||||
}
|
||||
}
|
||||
|
||||
// Set user's ID and name
|
||||
if ( ! empty ( $user ) ) {
|
||||
$email = $user->ID;
|
||||
$alt = $user->display_name;
|
||||
}
|
||||
}
|
||||
|
||||
$alt = esc_attr( $alt );
|
||||
$size = esc_attr( $size );
|
||||
$class = esc_attr( implode( ' ', $class ) );
|
||||
|
||||
// Checks if user has WPUA
|
||||
$wpua_meta = get_the_author_meta( $wpdb->get_blog_prefix( $blog_id ) . 'user_avatar', $email );
|
||||
|
||||
// Add alignment class
|
||||
$alignclass = ! empty( $align ) && ( 'left' == $align || 'right' == $align || 'center' == $align ) ? ' align' . $align : ' alignnone';
|
||||
|
||||
$class_string = ! empty( $class ) ? ' ' . $class : '';
|
||||
|
||||
// User has WPUA, check if on excluded list and bypass get_avatar
|
||||
if ( ! empty( $wpua_meta ) && $wpua_functions->wpua_attachment_is_image( $wpua_meta ) ) {
|
||||
// Numeric size use size array
|
||||
$get_size = is_numeric( $size ) ? array( $size, $size ) : $size;
|
||||
|
||||
// Get image src
|
||||
$wpua_image = $wpua_functions->wpua_get_attachment_image_src( $wpua_meta, $get_size );
|
||||
|
||||
// Add dimensions to img only if numeric size was specified
|
||||
$dimensions = is_numeric( $size ) ? sprintf(
|
||||
' width="%s" height="%s"',
|
||||
esc_attr( $wpua_image[1] ),
|
||||
esc_attr( $wpua_image[2] )
|
||||
) : '';
|
||||
|
||||
// Construct the img tag
|
||||
$avatar = sprintf(
|
||||
'<img src="%1$s"%2$s alt="%3$s" class="avatar avatar-%4$s wp-user-avatar wp-user-avatar-%4$s%5$s photo%6$s" />',
|
||||
esc_url( $wpua_image[0] ),
|
||||
$dimensions,
|
||||
esc_attr( $alt ),
|
||||
esc_attr( $size ),
|
||||
esc_attr( $alignclass ),
|
||||
esc_attr( $class_string )
|
||||
);
|
||||
} else {
|
||||
// Check for custom image sizes
|
||||
if ( in_array( $size, $all_sizes ) ) {
|
||||
if ( in_array( $size, array( 'original', 'large', 'medium', 'thumbnail' ) ) ) {
|
||||
$get_size = ( 'original' == $size ) ? get_option( 'large_size_w' ) : get_option( $size . '_size_w' );
|
||||
} else {
|
||||
$get_size = $_wp_additional_image_sizes[ $size ]['width'];
|
||||
}
|
||||
} else {
|
||||
// Numeric sizes leave as-is
|
||||
$get_size = $size;
|
||||
}
|
||||
|
||||
// User with no WPUA uses get_avatar
|
||||
$avatar = get_avatar( $email, $get_size, $default = '', $alt = '', [ 'class' => $class ] );
|
||||
|
||||
// Remove width and height for non-numeric sizes
|
||||
if ( in_array( $size, array( 'original', 'large', 'medium', 'thumbnail' ) ) ) {
|
||||
$avatar = preg_replace( '/(width|height)=\"\d*\"\s/', '', $avatar );
|
||||
$avatar = preg_replace( "/(width|height)=\'\d*\'\s/", '', $avatar );
|
||||
}
|
||||
|
||||
$replace = array(
|
||||
'wp-user-avatar ',
|
||||
'wp-user-avatar-' . $get_size . ' ',
|
||||
'wp-user-avatar-' . $size . ' ',
|
||||
'avatar-'.$get_size,
|
||||
' photo'
|
||||
);
|
||||
|
||||
$replacements = array(
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'avatar-' . $size,
|
||||
'wp-user-avatar wp-user-avatar-' . esc_attr( $size ) . esc_attr( $alignclass ) . ' photo' . esc_attr( $class_string )
|
||||
);
|
||||
$avatar = str_replace( $replace, $replacements, $avatar );
|
||||
}
|
||||
/**
|
||||
* Filter get_wp_user_avatar
|
||||
* @since 1.9
|
||||
* @param string $avatar
|
||||
* @param int|string $id_or_email
|
||||
* @param int|string $size
|
||||
* @param string $align
|
||||
* @param string $alt
|
||||
*/
|
||||
return apply_filters( 'get_wp_user_avatar', $avatar, $id_or_email, $size, $align, $alt );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return just the image src
|
||||
* @since 1.1
|
||||
* @param int|string $id_or_email
|
||||
* @param int|string $size
|
||||
* @param string $align
|
||||
* @uses get_wp_user_avatar()
|
||||
* @return string
|
||||
*/
|
||||
public function get_wp_user_avatar_src( $id_or_email = '', $size = '', $align = '' ) {
|
||||
$wpua_image_src = '';
|
||||
|
||||
// Gets the avatar img tag
|
||||
$wpua_image = get_wp_user_avatar( $id_or_email, $size, $align );
|
||||
|
||||
// Takes the img tag, extracts the src
|
||||
if ( ! empty( $wpua_image ) ) {
|
||||
preg_match_all( '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $wpua_image, $matches, PREG_SET_ORDER );
|
||||
|
||||
$wpua_image_src = ! empty ( $matches ) ? $matches[0][1] : '';
|
||||
}
|
||||
|
||||
return $wpua_image_src;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maybe replace the custom avatars functionality in the Ultimate Member plugin
|
||||
* @since 1.1
|
||||
* @param int|string $id_or_email
|
||||
* @param int|string $size
|
||||
* @param string $align
|
||||
* @uses get_wp_user_avatar()
|
||||
* @return string
|
||||
*/
|
||||
public function wpua_maybe_disable_um_avatars() {
|
||||
global $wpua_disable_um_avatars;
|
||||
|
||||
if ( ! function_exists( 'um_get_avatar' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! $wpua_disable_um_avatars ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$priority = has_filter( 'get_avatar', 'um_get_avatar' );
|
||||
|
||||
if ( false === $priority ) {
|
||||
return;
|
||||
}
|
||||
|
||||
remove_filter( 'get_avatar', 'um_get_avatar', $priority );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize
|
||||
* @since 1.9.2
|
||||
*/
|
||||
function wpua_functions_init() {
|
||||
global $wpua_functions;
|
||||
|
||||
if ( ! isset( $wpua_functions ) ) {
|
||||
$wpua_functions = new WP_User_Avatar_Functions();
|
||||
}
|
||||
|
||||
return $wpua_functions;
|
||||
}
|
||||
add_action( 'plugins_loaded', 'wpua_functions_init' );
|
@@ -0,0 +1,562 @@
|
||||
<?php
|
||||
/**
|
||||
* Based on WP_Media_List_Table class.
|
||||
*
|
||||
* @package One User Avatar
|
||||
* @author Bangbay Siboliban
|
||||
* @author Flippercode
|
||||
* @author ProfilePress
|
||||
* @author One Designs
|
||||
* @copyright 2013-2014 Bangbay Siboliban
|
||||
* @copyright 2014-2020 Flippercode
|
||||
* @copyright 2020-2021 ProfilePress
|
||||
* @copyright 2021 One Designs
|
||||
* @version 2.3.9
|
||||
*/
|
||||
|
||||
class WP_User_Avatar_List_Table extends WP_List_Table {
|
||||
/**
|
||||
* Constructor
|
||||
* @since 1.8
|
||||
* @param array $args
|
||||
* @uses array $avatars
|
||||
* @uses object $post
|
||||
* @uses int $wpua_avatar_default
|
||||
* @uses get_query_var()
|
||||
* @uses have_posts()
|
||||
* @uses the_post()
|
||||
* @uses wp_edit_attachments_query
|
||||
* @uses WP_Query()
|
||||
* @uses wp_reset_query()
|
||||
*/
|
||||
public function __construct( $args = array() ) {
|
||||
global $avatars, $post, $wpua_avatar_default;
|
||||
|
||||
$paged = ( get_query_var('page') ) ? get_query_var(' page' ) : 1;
|
||||
|
||||
$q = array(
|
||||
'paged' => $paged,
|
||||
'post_type' => 'attachment',
|
||||
'post_status' => 'inherit',
|
||||
'posts_per_page' => '-1',
|
||||
'meta_query' => array(
|
||||
array(
|
||||
'key' => '_wp_attachment_wp_user_avatar',
|
||||
'value' => '',
|
||||
'compare' => '!='
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$avatars_wp_query = new WP_Query( $q );
|
||||
|
||||
$avatars = array();
|
||||
|
||||
while ( $avatars_wp_query->have_posts() ) {
|
||||
$avatars_wp_query->the_post();
|
||||
|
||||
$avatars[] = $post->ID;
|
||||
}
|
||||
|
||||
wp_reset_query();
|
||||
|
||||
// Include default avatar
|
||||
$avatars[] = $wpua_avatar_default;
|
||||
|
||||
parent::__construct( array(
|
||||
'plural' => 'media',
|
||||
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Only users with edit_users capability can use this section
|
||||
* @since 1.8
|
||||
* @uses current_user_can()
|
||||
*/
|
||||
public function ajax_user_can() {
|
||||
return current_user_can( 'edit_users' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Search form
|
||||
* @since 1.8
|
||||
* @param string $text
|
||||
* @param int $input_id
|
||||
* @uses _admin_search_query()
|
||||
* @uses has_items()
|
||||
* @uses submit_button()
|
||||
*/
|
||||
public function search_box( $text, $input_id ) {
|
||||
if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$input_id = $input_id . '-search-input';
|
||||
|
||||
if ( ! empty( $_REQUEST['orderby'] ) ) {
|
||||
printf( '<input type="hidden" name="orderby" value="%s" />', esc_attr( $_REQUEST['orderby'] ) );
|
||||
}
|
||||
|
||||
if ( ! empty( $_REQUEST['order'] ) ) {
|
||||
printf( '<input type="hidden" name="order" value="%s" />', esc_attr( $_REQUEST['order'] ) );
|
||||
}
|
||||
if ( ! empty( $_REQUEST['post_mime_type'] ) ) {
|
||||
printf( '<input type="hidden" name="post_mime_type" value="%s" />', esc_attr( $_REQUEST['post_mime_type'] ) );
|
||||
}
|
||||
if ( ! empty( $_REQUEST['detached'] ) ) {
|
||||
printf( '<input type="hidden" name="detached" value="%s" />', esc_attr( $_REQUEST['detached'] ) );
|
||||
}
|
||||
?>
|
||||
|
||||
<p class="search-box">
|
||||
<label class="screen-reader-text" for="<?php echo esc_attr( $input_id ); ?>"><?php echo esc_html( $text ); ?>:</label>
|
||||
|
||||
<input type="hidden" id="page" name="page" value="wp-user-avatar-library" />
|
||||
|
||||
<input type="search" id="<?php echo esc_attr( $input_id ); ?>" name="s" value="<?php _admin_search_query(); ?>" />
|
||||
|
||||
<?php submit_button( $text, 'button', false, false, array( 'id' => 'search-submit' ) ); ?>
|
||||
</p>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Return only avatars and paginate results
|
||||
* @since 1.8
|
||||
* @uses array $avatars
|
||||
* @uses wp_edit_attachments_query()
|
||||
*/
|
||||
public function prepare_items() {
|
||||
global $avail_post_mime_types, $avatars, $lost, $post, $post_mime_types, $wp_query, $wpdb;
|
||||
|
||||
$q = $_REQUEST;
|
||||
|
||||
if ( ! is_array( $q ) ) {
|
||||
$q = array();
|
||||
}
|
||||
|
||||
$q['post__in'] = $avatars;
|
||||
|
||||
list( $post_mime_types, $avail_post_mime_types ) = wp_edit_attachments_query( $q );
|
||||
|
||||
$this->is_trash = isset( $_REQUEST['status'] ) && 'trash' == $_REQUEST['status'];
|
||||
|
||||
$this->set_pagination_args( array(
|
||||
'total_items' => $wp_query->found_posts,
|
||||
'total_pages' => $wp_query->max_num_pages,
|
||||
'per_page' => $wp_query->query_vars['posts_per_page'],
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Links to available table views
|
||||
* @since 1.8
|
||||
* @uses array $avatars
|
||||
* @uses add_query_arg()
|
||||
* @uses number_format_i18n()
|
||||
* @return array
|
||||
*/
|
||||
public function get_views() {
|
||||
global $avatars;
|
||||
|
||||
$type_links = array();
|
||||
$_total_posts = count( array_filter( $avatars ) );
|
||||
$class = ( empty( $_GET['post_mime_type'] ) && ! isset( $_GET['status'] ) ) ? ' class="current"' : '';
|
||||
|
||||
$type_links['all'] = sprintf(
|
||||
' <a href="%s">',
|
||||
esc_url( add_query_arg( array(
|
||||
'page' => 'wp-user-avatar-library',
|
||||
), 'admin.php') )
|
||||
);
|
||||
$type_links['all'] .= sprintf(
|
||||
/* translators: uploaded files */
|
||||
_x( 'All %s', 'uploaded files', 'one-user-avatar' ),
|
||||
sprintf( '<span class="count">(%s)</span>', number_format_i18n( $_total_posts ) )
|
||||
);
|
||||
$type_links['all'] .= '</a>';
|
||||
|
||||
return $type_links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bulk action available with this table
|
||||
* @since 1.8
|
||||
* @return array
|
||||
*/
|
||||
public function get_bulk_actions() {
|
||||
$actions = array();
|
||||
|
||||
$actions['delete'] = esc_html__( 'Delete Permanently','one-user-avatar' );
|
||||
|
||||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Current action from bulk actions list
|
||||
* @since 1.8
|
||||
* @uses current_action()
|
||||
* @return string|bool
|
||||
*/
|
||||
public function current_action() {
|
||||
return parent::current_action();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether table has items
|
||||
* @since 1.8
|
||||
* @uses have_posts()
|
||||
* @return bool
|
||||
*/
|
||||
public function has_items() {
|
||||
return have_posts();
|
||||
}
|
||||
|
||||
/**
|
||||
* Message displayed when no items
|
||||
* @since 1.8
|
||||
*/
|
||||
public function no_items() {
|
||||
_e( 'No media attachments found.', 'one-user-avatar' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Columns in this table
|
||||
* @since 1.8
|
||||
* @return array
|
||||
*/
|
||||
public function get_columns() {
|
||||
$columns = array();
|
||||
|
||||
$columns['cb'] = '<input type="checkbox" />';
|
||||
$columns['icon'] = '';
|
||||
$columns['title'] = esc_html_x( 'File', 'column name', 'one-user-avatar' );
|
||||
$columns['author'] = esc_html__( 'Author','one-user-avatar', 'one-user-avatar' );
|
||||
$columns['parent'] = esc_html_x( 'Uploaded to', 'column name', 'one-user-avatar' );
|
||||
$columns['date'] = esc_html_x( 'Date', 'column name', 'one-user-avatar' );
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sortable columns in this table
|
||||
* @since 1.8
|
||||
* @return array
|
||||
*/
|
||||
public function get_sortable_columns() {
|
||||
return array(
|
||||
'title' => 'title',
|
||||
'author' => 'author',
|
||||
'date' => array( 'date', true ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display for rows in table
|
||||
* @since 1.8
|
||||
* @uses object $post
|
||||
* @uses object $wpdb
|
||||
* @uses object $wpua_functions
|
||||
* @uses add_filter()
|
||||
* @uses _draft_or_post_title()
|
||||
* @uses _media_states()
|
||||
* @uses current_user_can()
|
||||
* @uses get_attached_file()
|
||||
* @uses get_current_user_id()
|
||||
* @uses get_edit_post_link()
|
||||
* @uses get_edit_user_link()
|
||||
* @uses get_post_mime_type()
|
||||
* @uses get_the_author()
|
||||
* @uses get_the_author_meta()
|
||||
* @uses get_userdata()
|
||||
* @uses have_posts()
|
||||
* @uses the_post()
|
||||
* @uses wpua_get_attachment_image()
|
||||
*/
|
||||
public function display_rows() {
|
||||
global $post, $wpdb, $wpua_functions;
|
||||
|
||||
add_filter( 'the_title','esc_html' );
|
||||
|
||||
$alt = '';
|
||||
|
||||
while ( have_posts() ) :
|
||||
the_post();
|
||||
|
||||
$user_can_edit = current_user_can( 'edit_post', $post->ID );
|
||||
|
||||
if ( $this->is_trash && 'trash' != $post->post_status || ! $this->is_trash && 'trash' == $post->post_status ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$alt = ( 'alternate' == $alt ) ? '' : 'alternate';
|
||||
$post_owner = (get_current_user_id() == $post->post_author) ? 'self' : 'other';
|
||||
$tr_class = trim( $alt . ' author-' . $post_owner . ' status-' . $post->post_status );
|
||||
$att_title = _draft_or_post_title();
|
||||
?>
|
||||
|
||||
<tr id="post-<?php echo esc_attr( $post->ID ); ?>" class="<?php echo esc_attr( $tr_class ); ?>" valign="top">
|
||||
<?php
|
||||
list( $columns, $hidden ) = $this->get_column_info();
|
||||
|
||||
foreach ( $columns as $column_name => $column_display_name ) {
|
||||
$class = sprintf( '%1$s column-%1$s', esc_attr( $column_name ) );
|
||||
|
||||
if ( in_array( $column_name, $hidden ) ) {
|
||||
$class .= ' hidden';
|
||||
}
|
||||
|
||||
$class = sanitize_html_class( $class );
|
||||
|
||||
switch ( $column_name ) {
|
||||
case 'cb':
|
||||
?>
|
||||
|
||||
<th scope="row" class="check-column">
|
||||
<?php if ( $user_can_edit ) : ?>
|
||||
<label class="screen-reader-text" for="cb-select-<?php the_ID(); ?>">
|
||||
<?php
|
||||
/* translators: post title */
|
||||
echo esc_html( sprintf( __( 'Select %s','one-user-avatar' ), $att_title ) );
|
||||
?>
|
||||
</label>
|
||||
|
||||
<input type="checkbox" name="media[]" id="cb-select-<?php the_ID(); ?>" value="<?php the_ID(); ?>" />
|
||||
<?php endif; ?>
|
||||
</th>
|
||||
|
||||
<?php
|
||||
break;
|
||||
|
||||
case 'icon':
|
||||
?>
|
||||
|
||||
<td class="media-icon <?php echo esc_attr( $class ); ?>">
|
||||
<?php
|
||||
if ( $thumb = $wpua_functions->wpua_get_attachment_image( $post->ID, array( 80, 60 ), true ) ) {
|
||||
if ( $this->is_trash || ! $user_can_edit ) {
|
||||
echo wp_kses_post( $thumb );
|
||||
} else {
|
||||
?>
|
||||
<a href="<?php echo esc_url( get_edit_post_link( $post->ID, true ) ); ?>" title="<?php echo esc_attr( sprintf( __( 'Edit %s' ), sprintf( '“%s”', $att_title ) ) ); ?>">
|
||||
<?php echo wp_kses_post( $thumb ); ?>
|
||||
</a>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
|
||||
<?php
|
||||
break;
|
||||
|
||||
case 'title':
|
||||
?>
|
||||
|
||||
<td class="<?php echo esc_attr( $class ); ?>">
|
||||
<strong>
|
||||
<?php
|
||||
if ( $this->is_trash || ! $user_can_edit ) {
|
||||
echo esc_html( $att_title );
|
||||
} else {
|
||||
?>
|
||||
<a
|
||||
href="<?php echo esc_url( get_edit_post_link( $post->ID, true ) ); ?>"
|
||||
title="<?php echo esc_attr( sprintf( __( 'Edit %s' ), sprintf( '“%s”', $att_title ) ) ); ?>"
|
||||
>
|
||||
<?php echo esc_html( $att_title ); ?>
|
||||
</a>
|
||||
<?php
|
||||
}
|
||||
|
||||
_media_states( $post );
|
||||
?>
|
||||
</strong>
|
||||
|
||||
<p>
|
||||
<?php
|
||||
if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) ) {
|
||||
echo esc_html( strtoupper( $matches[1] ) );
|
||||
} else {
|
||||
echo esc_html( strtoupper( str_replace('image/', '', get_post_mime_type() ) ) );
|
||||
}
|
||||
?>
|
||||
</p>
|
||||
|
||||
<?php echo $this->row_actions( $this->_get_row_actions( $post, $att_title ) ); ?>
|
||||
</td>
|
||||
|
||||
<?php
|
||||
break;
|
||||
|
||||
case 'author':
|
||||
?>
|
||||
|
||||
<td class="<?php echo esc_attr( $class ); ?>">
|
||||
<?php
|
||||
printf(
|
||||
'<a href="%s">%s</a>',
|
||||
esc_url( add_query_arg( array( 'author' => get_the_author_meta( 'ID' ) ), 'upload.php' ) ),
|
||||
get_the_author()
|
||||
);
|
||||
?>
|
||||
</td>
|
||||
|
||||
<?php
|
||||
break;
|
||||
|
||||
case 'date':
|
||||
if( '0000-00-00 00:00:00' == $post->post_date ) {
|
||||
$h_time = __( 'Unpublished','one-user-avatar' );
|
||||
} else {
|
||||
$m_time = $post->post_date;
|
||||
$time = get_post_time( 'G', true, $post, false );
|
||||
if ( ( abs( $t_diff = time() - $time ) ) < DAY_IN_SECONDS ) {
|
||||
if ( 0 > $t_diff ) {
|
||||
$h_time = sprintf(
|
||||
/* translators: time from now */
|
||||
_x( '%s from now', 'time from now', 'one-user-avatar' ),
|
||||
human_time_diff( $time)
|
||||
);
|
||||
} else {
|
||||
$h_time = sprintf(
|
||||
/* translators: time ago */
|
||||
_x( '%s ago', 'time ago', 'one-user-avatar' ),
|
||||
human_time_diff( $time )
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$h_time = mysql2date( __( 'Y/m/d', 'one-user-avatar' ), $m_time );
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<td class="<?php echo esc_attr( $class ); ?>"><?php echo esc_html( $h_time); ?></td>
|
||||
|
||||
<?php
|
||||
break;
|
||||
|
||||
case 'parent':
|
||||
global $blog_id, $wpdb;
|
||||
|
||||
// Find all users with this WPUA
|
||||
$wpua_metakey = $wpdb->get_blog_prefix( $blog_id ) . 'user_avatar';
|
||||
$wpuas = $wpdb->get_results( $wpdb->prepare(
|
||||
"SELECT wpum.user_id FROM $wpdb->usermeta AS wpum, $wpdb->users AS wpu WHERE wpum.meta_key = %s AND wpum.meta_value = %d AND wpum.user_id = wpu.ID ORDER BY wpu.user_login",
|
||||
$wpua_metakey,
|
||||
$post->ID
|
||||
) );
|
||||
|
||||
// Find users without WPUA
|
||||
$nowpuas = $wpdb->get_results( $wpdb->prepare(
|
||||
"SELECT wpu.ID FROM $wpdb->users AS wpu, $wpdb->usermeta AS wpum WHERE wpum.meta_key = %s AND wpum.meta_value = %d AND wpum.user_id = wpu.ID ORDER BY wpu.user_login",
|
||||
$wpua_metakey,
|
||||
''
|
||||
) );
|
||||
|
||||
$user_array = array();
|
||||
?>
|
||||
|
||||
<td class="<?php echo esc_attr( $class ); ?>">
|
||||
<strong>
|
||||
<?php
|
||||
if ( ! empty( $wpuas ) ) {
|
||||
foreach ( $wpuas as $usermeta ) {
|
||||
$user = get_userdata( $usermeta->user_id );
|
||||
$user_array[] = sprintf(
|
||||
'<a href="%s">%s</a>',
|
||||
esc_url( get_edit_user_link( $user->ID ) ),
|
||||
$user->user_login
|
||||
);
|
||||
}
|
||||
} else {
|
||||
foreach ( $nowpuas as $usermeta ) {
|
||||
$user = get_userdata($usermeta->ID);
|
||||
$user_array[] = sprintf(
|
||||
'<a href="%s">%s</a>',
|
||||
esc_url( get_edit_user_link($user->ID) ),
|
||||
$user->user_login
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
echo wp_kses_post( implode( ', ', array_filter( $user_array ) ) );
|
||||
?>
|
||||
</strong>
|
||||
</td>
|
||||
|
||||
<?php
|
||||
break;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
endwhile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Actions for rows in table
|
||||
* @since 1.8
|
||||
* @uses object $post
|
||||
* @uses string $att_title
|
||||
* @uses _draft_or_post_title()
|
||||
* @uses current_user_can()
|
||||
* @uses get_edit_post_link()
|
||||
* @uses get_permalink()
|
||||
* @uses wp_nonce_url()
|
||||
* @return array
|
||||
*/
|
||||
public function _get_row_actions( $post, $att_title ) {
|
||||
$actions = array();
|
||||
|
||||
if ( current_user_can( 'edit_post', $post->ID ) && ! $this->is_trash ) {
|
||||
$actions['edit'] = sprintf(
|
||||
'<a href="%s">%s</a>',
|
||||
esc_url( get_edit_post_link( $post->ID, true ) ),
|
||||
__( 'Edit', 'one-user-avatar' )
|
||||
);
|
||||
}
|
||||
|
||||
if ( current_user_can( 'delete_post', $post->ID ) ) {
|
||||
if ( $this->is_trash ) {
|
||||
$actions['untrash'] = sprintf(
|
||||
'<a class="submitdelete" href="%s">%s</a>',
|
||||
wp_nonce_url( sprintf( 'post.php?action=untrash&post=%s', $post->ID ), 'untrash-post_' . $post->ID ),
|
||||
__( 'Restore', 'one-user-avatar' )
|
||||
);
|
||||
} elseif ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) {
|
||||
$actions['trash'] = sprintf(
|
||||
'<a class="submitdelete" href="%s">%s</a>',
|
||||
wp_nonce_url( sprintf( 'post.php?action=trash&post=%s', $post->ID ), 'trash-post_' . $post->ID),
|
||||
__( 'Trash', 'one-user-avatar' )
|
||||
);
|
||||
}
|
||||
|
||||
if ( $this->is_trash || ! EMPTY_TRASH_DAYS || ! MEDIA_TRASH ) {
|
||||
$actions['delete'] = sprintf(
|
||||
'<a class="submitdelete" href="%s">%s</a>',
|
||||
wp_nonce_url( sprintf( 'post.php?action=delete&post=%s', $post->ID ), 'delete-post_'.$post->ID ),
|
||||
__( 'Delete Permanently', 'one-user-avatar' )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $this->is_trash ) {
|
||||
$title = _draft_or_post_title( $post->post_parent );
|
||||
|
||||
$actions['view'] = sprintf(
|
||||
'<a href="%s" title="%s" rel="permalink">%s</a>',
|
||||
get_permalink( $post->ID ),
|
||||
esc_attr( sprintf( __( 'View %s' ), sprintf( '“%s”', $title ) ) ),
|
||||
__( 'View', 'one-user-avatar' )
|
||||
);
|
||||
}
|
||||
|
||||
return $actions;
|
||||
}
|
||||
}
|
@@ -0,0 +1,248 @@
|
||||
<?php
|
||||
/**
|
||||
* Move body CSS to head and JS to footer.
|
||||
* Borrowed from NextGEN Gallery C_Photocrati_Resource_Manager class.
|
||||
*
|
||||
* @package One User Avatar
|
||||
* @author Bangbay Siboliban
|
||||
* @author Flippercode
|
||||
* @author ProfilePress
|
||||
* @author One Designs
|
||||
* @copyright 2013-2014 Bangbay Siboliban
|
||||
* @copyright 2014-2020 Flippercode
|
||||
* @copyright 2020-2021 ProfilePress
|
||||
* @copyright 2021 One Designs
|
||||
* @version 2.3.9
|
||||
*/
|
||||
|
||||
class WP_User_Avatar_Resource_Manager {
|
||||
static $instance = null;
|
||||
|
||||
public $marker = '<!-- wp_user_avatar_resource_manager_marker -->';
|
||||
|
||||
var $buffer = '';
|
||||
var $styles = '';
|
||||
var $other_output = '';
|
||||
var $wrote_footer = false;
|
||||
var $run_shutdown = false;
|
||||
var $valid_request = true;
|
||||
|
||||
/**
|
||||
* Start buffering all generated output. We'll then do two things with the buffer
|
||||
* 1) Find stylesheets lately enqueued and move them to the header
|
||||
* 2) Ensure that wp_print_footer_scripts() is called
|
||||
* @since 1.9.5
|
||||
*/
|
||||
function __construct() {
|
||||
// Validate the request
|
||||
$this->validate_request();
|
||||
|
||||
add_action( 'init', array( &$this, 'start_buffer' ), 1 );
|
||||
add_action( 'wp_footer', array( &$this, 'print_marker' ), -1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Created early as possible in the wp_footer action this is the string to which we
|
||||
* will move JS resources after
|
||||
* @since 1.9.8
|
||||
*/
|
||||
function print_marker() {
|
||||
print $this->marker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the resource manager should perform its routines for this request
|
||||
* @since 1.9.5
|
||||
* @return bool
|
||||
*/
|
||||
function validate_request() {
|
||||
$retval = true;
|
||||
|
||||
if ( is_admin() ) {
|
||||
if ( isset($_REQUEST['page'] ) && ! preg_match( "#^(wp_user_avatar)#", $_REQUEST['page'] ) ) {
|
||||
$retval = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( false !== strpos( $_SERVER['REQUEST_URI'], 'wp-admin/update') ) {
|
||||
$retval = false;
|
||||
} elseif ( isset( $_GET['display_gallery_iframe'] ) ) {
|
||||
$retval = false;
|
||||
} elseif ( defined( 'WP_ADMIN' ) && WP_ADMIN && defined( 'DOING_AJAX' ) && DOING_AJAX ) {
|
||||
$retval = false;
|
||||
} elseif ( preg_match( "/(js|css|xsl|xml|kml)$/", $_SERVER['REQUEST_URI'] ) ) {
|
||||
$retval = false;
|
||||
} elseif ( preg_match( "/\\.(\\w{3,4})$/", $_SERVER['REQUEST_URI'], $match ) ) {
|
||||
if ( ! in_array( $match[1], array( 'htm', 'html', 'php' ) ) ) {
|
||||
$retval = false;
|
||||
}
|
||||
}
|
||||
|
||||
$this->valid_request = $retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the output buffers
|
||||
* @since 1.9.5
|
||||
*/
|
||||
function start_buffer() {
|
||||
if( defined( 'WPUA_DISABLE_RESOURCE_MANAGER' ) && WPUA_DISABLE_RESOURCE_MANAGER ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( apply_filters('run_wpua_resource_manager', $this->valid_request ) ) {
|
||||
ob_start( array( &$this, 'output_buffer_handler' ) );
|
||||
ob_start( array( &$this, 'get_buffer' ) );
|
||||
|
||||
add_action( 'wp_print_footer_scripts', array( &$this, 'get_resources'), 1 );
|
||||
add_action( 'admin_print_footer_scripts', array( &$this, 'get_resources'), 1 );
|
||||
|
||||
add_action( 'shutdown', array( &$this, 'shutdown' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.9.5
|
||||
*/
|
||||
function get_resources() {
|
||||
ob_start();
|
||||
|
||||
wp_print_styles();
|
||||
|
||||
print_admin_styles();
|
||||
|
||||
$this->styles = ob_get_clean();
|
||||
|
||||
if ( ! is_admin() ) {
|
||||
ob_start();
|
||||
|
||||
wp_print_scripts();
|
||||
|
||||
$this->scripts = ob_get_clean();
|
||||
}
|
||||
|
||||
$this->wrote_footer = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the buffer after PHP execution has ended (but before shutdown)
|
||||
* @since 1.9.5
|
||||
* @param string $content
|
||||
* @return string
|
||||
*/
|
||||
function output_buffer_handler($content) {
|
||||
return $this->output_buffer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the closing </html> tag from the output buffer. We'll then write our own closing tag
|
||||
* in the shutdown function after running wp_print_footer_scripts()
|
||||
* @since 1.9.5
|
||||
* @param string $content
|
||||
* @return mixed
|
||||
*/
|
||||
function get_buffer($content) {
|
||||
$this->buffer = $content;
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Moves resources to their appropriate place
|
||||
* @since 1.9.5
|
||||
*/
|
||||
function move_resources() {
|
||||
if ( $this->valid_request ) {
|
||||
// Move stylesheets to head
|
||||
if ( $this->styles ) {
|
||||
$this->buffer = str_ireplace( '</head>', $this->styles . '</head>', $this->buffer );
|
||||
}
|
||||
|
||||
// Move the scripts to the bottom of the page
|
||||
if ( $this->scripts ) {
|
||||
$this->buffer = str_ireplace( $this->marker, $this->marker.$this->scripts, $this->buffer );
|
||||
}
|
||||
|
||||
if( $this->other_output ) {
|
||||
$this->buffer = str_replace( $this->marker, $this->marker.$this->other_output, $this->buffer );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* When PHP has finished, we output the footer scripts and closing tags
|
||||
* @since 1.9.5
|
||||
*/
|
||||
function output_buffer( $in_shutdown = false ) {
|
||||
// If the footer scripts haven't been outputted, then
|
||||
// we need to take action - as they're required
|
||||
if ( ! $this->wrote_footer ) {
|
||||
// If W3TC is installed and activated, we can't output the
|
||||
// scripts and manipulate the buffer, so we can only provide a warning
|
||||
if ( defined( 'W3TC' ) && defined( 'WP_DEBUG' ) && WP_DEBUG && ! is_admin() ) {
|
||||
if ( ! defined( 'DONOTCACHEPAGE' ) ) {
|
||||
define( 'DONOTCACHEPAGE', true );
|
||||
}
|
||||
|
||||
error_log( sprintf(
|
||||
/* translators: either wp_footer() or wp_print_footer_scripts() hook. */
|
||||
__( "We're sorry, but your theme's page template didn't make a call to %s, which is required by One User Avatar. Please add this call to your page templates.", 'one-user-avatar' ),
|
||||
( did_action( 'wp_footer' ) ? 'wp_print_footer_scripts()' : 'wp_footer()' )
|
||||
) );
|
||||
// We don't want to manipulate the buffer if it doesn't contain HTML
|
||||
} elseif ( false === strpos( $this->buffer, '</body>' ) ) {
|
||||
$this->valid_request = false;
|
||||
}
|
||||
|
||||
// The output_buffer() function has been called in the PHP shutdown callback
|
||||
// This will allow us to print the scripts ourselves and manipulate the buffer
|
||||
if ( true === $in_shutdown ) {
|
||||
ob_start();
|
||||
|
||||
if ( ! did_action( 'wp_footer' ) ) {
|
||||
wp_footer();
|
||||
} else {
|
||||
wp_print_footer_scripts();
|
||||
}
|
||||
|
||||
$this->other_output = ob_get_clean();
|
||||
}
|
||||
|
||||
// W3TC isn't activated and we're not in the shutdown callback.
|
||||
// We'll therefore add a shutdown callback to print the scripts
|
||||
else {
|
||||
$this->run_shutdown = true;
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
// Once we have the footer scripts, we can modify the buffer and
|
||||
// move the resources around
|
||||
if ( $this->wrote_footer ) {
|
||||
$this->move_resources();
|
||||
}
|
||||
|
||||
return $this->buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP shutdown callback. Manipulate and output the buffer
|
||||
* @since 1.9.5
|
||||
*/
|
||||
function shutdown() {
|
||||
if ( $this->run_shutdown ) {
|
||||
echo $this->output_buffer( true );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.9.5
|
||||
*/
|
||||
static function init() {
|
||||
$klass = get_class();
|
||||
|
||||
return self::$instance = new $klass;
|
||||
}
|
||||
}
|
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
/**
|
||||
* Let's get started!
|
||||
*
|
||||
* @package One User Avatar
|
||||
* @author Bangbay Siboliban
|
||||
* @author Flippercode
|
||||
* @author ProfilePress
|
||||
* @author One Designs
|
||||
* @copyright 2013-2014 Bangbay Siboliban
|
||||
* @copyright 2014-2020 Flippercode
|
||||
* @copyright 2020-2021 ProfilePress
|
||||
* @copyright 2021 One Designs
|
||||
* @version 2.3.9
|
||||
*/
|
||||
|
||||
class WP_User_Avatar_Setup {
|
||||
/**
|
||||
* Constructor
|
||||
* @since 1.9.2
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->_define_constants();
|
||||
$this->_load_wp_includes();
|
||||
$this->_load_wpua();
|
||||
}
|
||||
|
||||
/**
|
||||
* Define paths
|
||||
* @since 1.9.2
|
||||
*/
|
||||
private function _define_constants() {
|
||||
define( 'WPUA_VERSION', '2.3.9' );
|
||||
define( 'WPUA_FOLDER', basename( dirname( One_User_Avatar::plugin_file_path() ) ) );
|
||||
define( 'WPUA_DIR', One_User_Avatar::plugin_dir_path() );
|
||||
define( 'WPUA_INC', WPUA_DIR . 'includes' . '/' );
|
||||
define( 'WPUA_URL', plugin_dir_url( WPUA_FOLDER ) . WPUA_FOLDER . '/' );
|
||||
define( 'WPUA_ASSETS_URL', WPUA_URL . 'assets'.'/' );
|
||||
define( 'WPUA_CSS_URL', WPUA_ASSETS_URL . 'css'.'/' );
|
||||
define( 'WPUA_JS_URL', WPUA_ASSETS_URL . 'js'.'/' );
|
||||
define( 'WPUA_IMG_URL', WPUA_ASSETS_URL . 'images'.'/' );
|
||||
define( 'WPUA_INC_URL', WPUA_URL . 'includes'.'/' );
|
||||
}
|
||||
|
||||
/**
|
||||
* WordPress includes used in plugin
|
||||
* @since 1.9.2
|
||||
* @uses is_admin()
|
||||
*/
|
||||
private function _load_wp_includes() {
|
||||
if ( ! is_admin() ) {
|
||||
// wp_handle_upload
|
||||
require_once( ABSPATH . 'wp-admin/includes/file.php' );
|
||||
|
||||
// wp_generate_attachment_metadata
|
||||
require_once( ABSPATH . 'wp-admin/includes/image.php' );
|
||||
|
||||
// image_add_caption
|
||||
require_once( ABSPATH . 'wp-admin/includes/media.php' );
|
||||
|
||||
// submit_button
|
||||
require_once( ABSPATH . 'wp-admin/includes/template.php' );
|
||||
}
|
||||
|
||||
// add_screen_option
|
||||
require_once( ABSPATH . 'wp-admin/includes/screen.php' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Load One User Avatar
|
||||
* @since 1.9.2
|
||||
* @uses bool $wpua_tinymce
|
||||
* @uses is_admin()
|
||||
*/
|
||||
private function _load_wpua() {
|
||||
global $wpua_tinymce;
|
||||
|
||||
require_once( WPUA_INC . 'wpua-globals.php' );
|
||||
require_once( WPUA_INC . 'wpua-functions.php' );
|
||||
require_once( WPUA_INC . 'class-wp-user-avatar-admin.php' );
|
||||
require_once( WPUA_INC . 'class-wp-user-avatar.php' );
|
||||
require_once( WPUA_INC . 'class-wp-user-avatar-functions.php' );
|
||||
require_once( WPUA_INC . 'class-wp-user-avatar-shortcode.php' );
|
||||
require_once( WPUA_INC . 'class-wp-user-avatar-subscriber.php' );
|
||||
require_once( WPUA_INC . 'class-wp-user-avatar-update.php' );
|
||||
require_once( WPUA_INC . 'class-wp-user-avatar-widget.php' );
|
||||
|
||||
// Load TinyMCE only if enabled
|
||||
if ( 1 == (bool) $wpua_tinymce ) {
|
||||
require_once( WPUA_INC.'wpua-tinymce.php' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function wp_user_avatar_setup() {
|
||||
global $wp_user_avatar_setup;
|
||||
|
||||
if ( ! isset( $wp_user_avatar_setup ) ) {
|
||||
$wp_user_avatar_setup = new WP_User_Avatar_Setup();
|
||||
}
|
||||
|
||||
return $wp_user_avatar_setup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize
|
||||
*/
|
||||
wp_user_avatar_setup();
|
@@ -0,0 +1,327 @@
|
||||
<?php
|
||||
/**
|
||||
* Defines shortcodes.
|
||||
*
|
||||
* @package One User Avatar
|
||||
* @author Bangbay Siboliban
|
||||
* @author Flippercode
|
||||
* @author ProfilePress
|
||||
* @author One Designs
|
||||
* @copyright 2013-2014 Bangbay Siboliban
|
||||
* @copyright 2014-2020 Flippercode
|
||||
* @copyright 2020-2021 ProfilePress
|
||||
* @copyright 2021 One Designs
|
||||
* @version 2.3.9
|
||||
*/
|
||||
|
||||
class WP_User_Avatar_Shortcode {
|
||||
/**
|
||||
* Constructor
|
||||
* @since 1.8
|
||||
* @uses object $wp_user_avatar
|
||||
* @uses add_action()
|
||||
* @uses add_shortcode()
|
||||
*/
|
||||
public function __construct() {
|
||||
global $wp_user_avatar;
|
||||
|
||||
add_shortcode( 'avatar', array( $this, 'wpua_shortcode' ) );
|
||||
add_shortcode( 'avatar_upload', array( $this, 'wpua_edit_shortcode' ) );
|
||||
|
||||
// Add avatar and scripts to avatar_upload
|
||||
add_action( 'wpua_show_profile', array( $wp_user_avatar, 'wpua_action_show_user_profile' ) );
|
||||
add_action( 'wpua_show_profile', array( $wp_user_avatar, 'wpua_media_upload_scripts' ) );
|
||||
add_action( 'wpua_update', array( $wp_user_avatar, 'wpua_action_process_option_update' ) );
|
||||
|
||||
// Add error messages to avatar_upload
|
||||
add_action( 'wpua_update_errors', array( $wp_user_avatar, 'wpua_upload_errors' ), 10, 3 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Display shortcode
|
||||
* @since 1.4
|
||||
* @param array $atts
|
||||
* @param string $content
|
||||
* @uses array $_wp_additional_image_sizes
|
||||
* @uses array $all_sizes
|
||||
* @uses int $blog_id
|
||||
* @uses object $post
|
||||
* @uses object $wpdb
|
||||
* @uses do_shortcode()
|
||||
* @uses get_attachment_link()
|
||||
* @uses get_blog_prefix()
|
||||
* @uses get_option()
|
||||
* @uses get_user_by()
|
||||
* @uses get_query_var()
|
||||
* @uses get_the_author_meta()
|
||||
* @uses get_user_meta()
|
||||
* @uses get_wp_user_avatar_src()
|
||||
* @uses get_wp_user_avatar()
|
||||
* @uses image_add_caption()
|
||||
* @uses is_author()
|
||||
* @uses shortcode_atts()
|
||||
* @return string
|
||||
*/
|
||||
public function wpua_shortcode( $atts, $content = null ) {
|
||||
global $all_sizes, $blog_id, $post, $wpdb;
|
||||
|
||||
// Set shortcode attributes
|
||||
extract( shortcode_atts( array(
|
||||
'user' => '',
|
||||
'size' => '96',
|
||||
'align' => '',
|
||||
'link' => '',
|
||||
'target' => '',
|
||||
), $atts ) );
|
||||
|
||||
// Find user by ID, login, slug, or e-mail address
|
||||
if ( ! empty( $user ) ) {
|
||||
if ( 'current' == $user ) {
|
||||
$user = wp_get_current_user();
|
||||
} else {
|
||||
$user = is_numeric( $user ) ? get_user_by( 'id', $user ) : get_user_by('login', $user);
|
||||
$user = empty( $user ) ? get_user_by( 'slug', $user ) : $user;
|
||||
$user = empty( $user ) ? get_user_by( 'email', $user ) : $user;
|
||||
}
|
||||
} else {
|
||||
// Find author's name if id_or_email is empty
|
||||
$author_name = get_query_var( 'author_name' );
|
||||
|
||||
if( is_author() ) {
|
||||
// On author page, get user by page slug
|
||||
$user = get_user_by( 'slug', $author_name );
|
||||
} else {
|
||||
// On post, get user by author meta
|
||||
$user_id = get_the_author_meta( 'ID' );
|
||||
$user = get_user_by( 'id', $user_id );
|
||||
}
|
||||
}
|
||||
|
||||
// Numeric sizes leave as-is
|
||||
$get_size = $size;
|
||||
|
||||
// Check for custom image sizes if there are captions
|
||||
if ( ! empty( $content ) ) {
|
||||
if ( in_array( $size, $all_sizes ) ) {
|
||||
if ( in_array( $size, array( 'original', 'large', 'medium', 'thumbnail' ) ) ) {
|
||||
$get_size = ( $size == 'original' ) ? get_option( 'large_size_w' ) : get_option( $size.'_size_w' );
|
||||
} else {
|
||||
$get_size = $_wp_additional_image_sizes[$size]['width'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get user ID
|
||||
$id_or_email = ! empty( $user ) ? $user->ID : 'unknown@gravatar.com';
|
||||
|
||||
// Check if link is set
|
||||
if ( ! empty( $link ) ) {
|
||||
// CSS class is same as link type, except for URL
|
||||
$link_class = $link;
|
||||
|
||||
if ( 'file' == $link ) {
|
||||
// Get image src
|
||||
$link = get_wp_user_avatar_src( $id_or_email, 'original' );
|
||||
} elseif ( $link == 'attachment' ) {
|
||||
// Get attachment URL
|
||||
$link = get_attachment_link( get_the_author_meta( $wpdb->get_blog_prefix( $blog_id ) . 'user_avatar', $id_or_email ) );
|
||||
} else {
|
||||
// URL
|
||||
$link_class = 'custom';
|
||||
}
|
||||
|
||||
// Link target
|
||||
if ( ! in_array( $target, array( '_blank', '_self', '_parent', '_top' ) ) ) {
|
||||
$target = '';
|
||||
}
|
||||
|
||||
// Wrap the avatar inside the link
|
||||
$html = sprintf(
|
||||
'<a href="%s" class="wp-user-avatar-link wp-user-avatar-%s"%s>%s</a>',
|
||||
esc_url( $link ),
|
||||
esc_attr( $link_class ),
|
||||
( $target ? sprintf( ' target="%s"', esc_attr( $target ) ) : '' ),
|
||||
get_wp_user_avatar( $id_or_email, $get_size, $align )
|
||||
);
|
||||
} else {
|
||||
$html = get_wp_user_avatar( $id_or_email, $get_size, $align );
|
||||
}
|
||||
|
||||
// Check if caption is set
|
||||
if ( ! empty( $content ) ) {
|
||||
// Get attachment ID
|
||||
$wpua = get_user_meta( $id_or_email, $wpdb->get_blog_prefix( $blog_id ) . 'user_avatar', true );
|
||||
|
||||
// Clean up caption
|
||||
$content = trim( $content );
|
||||
$content = preg_replace( '/\r|\n/', '', $content );
|
||||
$content = preg_replace( '/<\/p><p>/', '', $content, 1 );
|
||||
$content = preg_replace( '/<\/p><p>$/', '', $content );
|
||||
$content = str_replace( '</p><p>', '<br /><br />', $content );
|
||||
|
||||
$avatar = do_shortcode( image_add_caption( $html, $wpua, $content, $title = '', $align, $link, $get_size, $alt = ''));
|
||||
} else {
|
||||
$avatar = $html;
|
||||
}
|
||||
|
||||
return wp_kses_post( $avatar );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update user
|
||||
* @since 1.8
|
||||
* @param bool $user_id
|
||||
* @uses add_query_arg()
|
||||
* @uses apply_filters()
|
||||
* @uses do_action_ref_array()
|
||||
* @uses wp_get_referer()
|
||||
* @uses wp_redirect()
|
||||
* @uses wp_safe_redirect()
|
||||
*/
|
||||
private function wpua_edit_user( $user_id = 0 ) {
|
||||
$update = $user_id ? true : false;
|
||||
$user = new stdClass;
|
||||
$errors = new WP_Error();
|
||||
|
||||
do_action_ref_array( 'wpua_update_errors', array( &$errors, $update, &$user ) );
|
||||
|
||||
if ( $errors->get_error_codes() ) {
|
||||
// Return with errors
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit shortcode
|
||||
* @since 1.8
|
||||
* @param array $atts
|
||||
* @uses $wp_user_avatar
|
||||
* @uses $wpua_allow_upload
|
||||
* @uses current_user_can()
|
||||
* @uses do_action()
|
||||
* @uses get_error_messages()
|
||||
* @uses get_user_by()
|
||||
* @uses is_user_logged_in()
|
||||
* @uses is_wp_error()
|
||||
* @uses shortcode_atts()
|
||||
* @uses wpua_edit_form()
|
||||
* @uses wpua_edit_user()
|
||||
* @uses wpua_is_author_or_above()
|
||||
* @return string
|
||||
*/
|
||||
public function wpua_edit_shortcode( $atts ) {
|
||||
global $current_user, $errors, $wp_user_avatar, $wpua_allow_upload;
|
||||
|
||||
// Shortcode only works for users with permission
|
||||
if ( $wp_user_avatar->wpua_is_author_or_above() || ( 1 == (bool) $wpua_allow_upload && is_user_logged_in() ) ) {
|
||||
extract( shortcode_atts( array( 'user' => '' ), $atts ) );
|
||||
|
||||
// Default user is current user
|
||||
$valid_user = $current_user;
|
||||
|
||||
// Find user by ID, login, slug, or e-mail address
|
||||
if ( ! empty( $user ) ) {
|
||||
$get_user = is_numeric( $user ) ? get_user_by( 'id', $user ) : get_user_by( 'login', $user );
|
||||
$get_user = empty( $get_user ) ? get_user_by( 'slug', $user ) : $get_user;
|
||||
$get_user = empty( $get_user ) ? get_user_by( 'email', $user ) : $get_user;
|
||||
|
||||
// Check if current user can edit this user
|
||||
$valid_user = current_user_can( 'edit_user', $get_user->ID ) ? $get_user : null;
|
||||
}
|
||||
|
||||
$output = '';
|
||||
|
||||
// Show form only for valid user
|
||||
if ( $valid_user ) {
|
||||
// Save
|
||||
if (
|
||||
( isset( $_POST['submit'] ) && $_POST['submit'] )
|
||||
&&
|
||||
( isset( $_POST['wpua_action'] ) && 'update' == $_POST['wpua_action'] )
|
||||
&&
|
||||
( isset( $_POST[ '_wpnonce'] ) && wp_verify_nonce( $_POST[ '_wpnonce'], 'update-user_' . $valid_user->ID ) )
|
||||
) {
|
||||
ob_start();
|
||||
|
||||
do_action( 'wpua_update', $valid_user->ID );
|
||||
|
||||
// Check for errors
|
||||
$errors = $this->wpua_edit_user( $valid_user->ID );
|
||||
|
||||
// Errors
|
||||
if ( isset( $errors ) && is_wp_error( $errors ) ) {
|
||||
printf( '<div class="error"><p>%s</p></div>', implode( "</p>\n<p>", $errors->get_error_messages() ) );
|
||||
} else {
|
||||
printf( '<div class="success"><p><strong>%s</strong></p></div>', __( 'Profile updated.', 'one-user-avatar' ) );
|
||||
}
|
||||
|
||||
$output .= ob_get_clean();
|
||||
}
|
||||
|
||||
// Edit form
|
||||
$output .= $this->wpua_edit_form( $valid_user );
|
||||
|
||||
return wp_kses( $output, array_merge( wp_kses_allowed_html( 'post' ), array(
|
||||
'form' => array(
|
||||
'id' => true,
|
||||
'class' => true,
|
||||
'action' => true,
|
||||
'class' => true,
|
||||
'method' => true,
|
||||
'enctype' => true,
|
||||
),
|
||||
'input' => array(
|
||||
'type' => true,
|
||||
'name' => true,
|
||||
'id' => true,
|
||||
'class' => true,
|
||||
'value' => true,
|
||||
),
|
||||
) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit form
|
||||
* @since 1.8
|
||||
* @param object $user
|
||||
* @uses do_action()
|
||||
* @uses submit_button()
|
||||
* @uses wp_nonce_field()
|
||||
*/
|
||||
private function wpua_edit_form($user) {
|
||||
ob_start();
|
||||
?>
|
||||
|
||||
<form id="wpua-edit-<?php echo esc_attr( $user->ID ); ?>" class="wpua-edit" action="" method="post" enctype="multipart/form-data">
|
||||
<?php do_action( 'wpua_show_profile', $user ); ?>
|
||||
|
||||
<input type="hidden" name="wpua_action" value="update" />
|
||||
<input type="hidden" name="user_id" id="user_id" value="<?php echo esc_attr( $user->ID ); ?>" />
|
||||
|
||||
<?php wp_nonce_field( 'update-user_' . $user->ID ); ?>
|
||||
|
||||
<?php submit_button( __( 'Update Profile', 'one-user-avatar' ) ); ?>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize
|
||||
* @since 1.9.2
|
||||
*/
|
||||
function wpua_shortcode_init() {
|
||||
global $wpua_shortcode;
|
||||
|
||||
if ( ! isset( $wpua_shortcode ) ) {
|
||||
$wpua_shortcode = new WP_User_Avatar_Shortcode();
|
||||
}
|
||||
|
||||
return $wpua_shortcode;
|
||||
}
|
||||
add_action( 'init', 'wpua_shortcode_init' );
|
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* Settings only for subscribers and contributors.
|
||||
*
|
||||
* @package One User Avatar
|
||||
* @author Bangbay Siboliban
|
||||
* @author Flippercode
|
||||
* @author ProfilePress
|
||||
* @author One Designs
|
||||
* @copyright 2013-2014 Bangbay Siboliban
|
||||
* @copyright 2014-2020 Flippercode
|
||||
* @copyright 2020-2021 ProfilePress
|
||||
* @copyright 2021 One Designs
|
||||
* @version 2.3.9
|
||||
*/
|
||||
|
||||
class WP_User_Avatar_Subscriber {
|
||||
/**
|
||||
* Constructor
|
||||
* @since 1.8
|
||||
* @uses object $wp_user_avatar
|
||||
* @uses bool $wpua_allow_upload
|
||||
* @uses add_action()
|
||||
* @uses current_user_can()
|
||||
* @uses wpua_is_author_or_above()
|
||||
*/
|
||||
public function __construct() {
|
||||
global $wpua_allow_upload;
|
||||
|
||||
if ( 1 == (bool) $wpua_allow_upload ) {
|
||||
add_action( 'user_edit_form_tag', array( $this, 'wpua_add_edit_form_multipart_encoding' ) );
|
||||
}
|
||||
|
||||
add_action( 'admin_init', array( $this, 'wpua_subscriber_capability' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow multipart data in form
|
||||
* @since 1.4.1
|
||||
*/
|
||||
public function wpua_add_edit_form_multipart_encoding() {
|
||||
echo ' enctype="multipart/form-data"';
|
||||
}
|
||||
|
||||
/**
|
||||
* Give subscribers edit_posts capability
|
||||
* @since 1.8.3
|
||||
* @uses int $blog_id
|
||||
* @uses object $wpdb
|
||||
* @uses bool $wpua_allow_upload
|
||||
* @uses bool $wpua_edit_avatar
|
||||
* @uses get_blog_prefix()
|
||||
* @uses get_option()
|
||||
* @uses update_option()
|
||||
*/
|
||||
public function wpua_subscriber_capability() {
|
||||
global $blog_id, $wpdb, $wpua_allow_upload, $wpua_edit_avatar;
|
||||
|
||||
$wp_user_roles = $wpdb->get_blog_prefix( $blog_id ) . 'user_roles';
|
||||
|
||||
$user_roles = get_option( $wp_user_roles );
|
||||
|
||||
if ( isset( $user_roles['subscriber']['capabilities']['edit_posts'] ) ) {
|
||||
unset( $user_roles['subscriber']['capabilities']['edit_posts'] );
|
||||
}
|
||||
|
||||
update_option( $wp_user_roles, $user_roles );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize
|
||||
* @since 1.9.5
|
||||
*/
|
||||
function wpua_subscriber_init() {
|
||||
global $wpua_subscriber;
|
||||
|
||||
if ( ! isset( $wpua_subscriber ) ) {
|
||||
$wpua_subscriber = new WP_User_Avatar_Subscriber();
|
||||
}
|
||||
|
||||
return $wpua_subscriber;
|
||||
}
|
||||
add_action( 'init', 'wpua_subscriber_init' );
|
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
/**
|
||||
* Updates for legacy settings.
|
||||
*
|
||||
* @package One User Avatar
|
||||
* @author Bangbay Siboliban
|
||||
* @author Flippercode
|
||||
* @author ProfilePress
|
||||
* @author One Designs
|
||||
* @copyright 2013-2014 Bangbay Siboliban
|
||||
* @copyright 2014-2020 Flippercode
|
||||
* @copyright 2020-2021 ProfilePress
|
||||
* @copyright 2021 One Designs
|
||||
* @version 2.3.9
|
||||
*/
|
||||
|
||||
class WP_User_Avatar_Update {
|
||||
/**
|
||||
* Constructor
|
||||
* @since 1.8
|
||||
* @uses bool $wpua_default_avatar_updated
|
||||
* @uses bool $wpua_media_updated
|
||||
* @uses bool $wpua_users_updated
|
||||
* @uses add_action()
|
||||
*/
|
||||
public function __construct() {
|
||||
global $wpua_default_avatar_updated, $wpua_media_updated, $wpua_users_updated;
|
||||
|
||||
if ( empty( $wpua_default_avatar_updated ) ) {
|
||||
add_action( 'admin_init', array( $this, 'wpua_default_avatar' ) );
|
||||
}
|
||||
|
||||
if( empty( $wpua_users_updated ) ) {
|
||||
add_action( 'admin_init', array( $this, 'wpua_user_meta' ) );
|
||||
}
|
||||
|
||||
if ( empty( $wpua_media_updated ) ) {
|
||||
add_action( 'admin_init', array( $this, 'wpua_media_state' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update default avatar to new format
|
||||
* @since 1.4
|
||||
* @uses string $avatar_default
|
||||
* @uses string $mustache_original
|
||||
* @uses int $wpua_avatar_default
|
||||
* @uses update_option()
|
||||
* @uses wp_get_attachment_image_src()
|
||||
*/
|
||||
public function wpua_default_avatar() {
|
||||
global $avatar_default, $mustache_original, $wpua_avatar_default;
|
||||
|
||||
// If default avatar is the old mustache URL, update it
|
||||
if ( $avatar_default == $mustache_original ) {
|
||||
update_option( 'avatar_default', 'wp_user_avatar' );
|
||||
}
|
||||
|
||||
// If user had an image URL as the default avatar, replace with ID instead
|
||||
if ( ! empty( $wpua_avatar_default ) ) {
|
||||
$wpua_avatar_default_image = wp_get_attachment_image_src( $wpua_avatar_default, 'medium' );
|
||||
|
||||
if ( $avatar_default == $wpua_avatar_default_image[0] ) {
|
||||
update_option( 'avatar_default', 'wp_user_avatar' );
|
||||
}
|
||||
}
|
||||
|
||||
update_option( 'wp_user_avatar_default_avatar_updated', '1' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename user meta to match database settings
|
||||
* @since 1.4
|
||||
* @uses int $blog_id
|
||||
* @uses object $wpdb
|
||||
* @uses delete_user_meta()
|
||||
* @uses get_blog_prefix()
|
||||
* @uses get_user_meta()
|
||||
* @uses get_users()
|
||||
* @uses update_option()
|
||||
* @uses update_user_meta()
|
||||
*/
|
||||
public function wpua_user_meta() {
|
||||
global $blog_id, $wpdb;
|
||||
|
||||
$wpua_metakey = $wpdb->get_blog_prefix( $blog_id ) . 'user_avatar';
|
||||
|
||||
// If database tables start with something other than wp_
|
||||
if ( 'wp_user_avatar' != $wpua_metakey ) {
|
||||
$users = get_users();
|
||||
|
||||
// Move current user metakeys to new metakeys
|
||||
foreach ( $users as $user ) {
|
||||
$wpua = get_user_meta( $user->ID, 'wp_user_avatar', true );
|
||||
|
||||
if ( ! empty( $wpua ) ) {
|
||||
update_user_meta( $user->ID, $wpua_metakey, $wpua );
|
||||
delete_user_meta( $user->ID, 'wp_user_avatar' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update_option( 'wp_user_avatar_users_updated', '1' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add media state to existing avatars
|
||||
* @since 1.4
|
||||
* @uses int $blog_id
|
||||
* @uses object $wpdb
|
||||
* @uses add_post_meta()
|
||||
* @uses get_blog_prefix()
|
||||
* @uses get_results()
|
||||
* @uses update_option()
|
||||
*/
|
||||
public function wpua_media_state() {
|
||||
global $blog_id, $wpdb;
|
||||
|
||||
// Find all users with WPUA
|
||||
$wpua_metakey = $wpdb->get_blog_prefix( $blog_id ) . 'user_avatar';
|
||||
|
||||
$wpuas = $wpdb->get_results( $wpdb->prepare(
|
||||
"SELECT * FROM $wpdb->usermeta WHERE meta_key = %s AND meta_value != %d AND meta_value != %d",
|
||||
$wpua_metakey,
|
||||
0,
|
||||
''
|
||||
) );
|
||||
|
||||
foreach( $wpuas as $usermeta ) {
|
||||
add_post_meta( $usermeta->meta_value, '_wp_attachment_wp_user_avatar', $usermeta->user_id );
|
||||
}
|
||||
|
||||
update_option( 'wp_user_avatar_media_updated', '1' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize
|
||||
* @since 1.9.2
|
||||
*/
|
||||
function wpua_update_init() {
|
||||
global $wpua_update;
|
||||
|
||||
if ( ! isset( $wpua_update ) ) {
|
||||
$wpua_update = new WP_User_Avatar_Update();
|
||||
}
|
||||
|
||||
return $wpua_update;
|
||||
}
|
||||
add_action('init', 'wpua_update_init');
|
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
/**
|
||||
* Defines widgets.
|
||||
*
|
||||
* @package One User Avatar
|
||||
* @author Bangbay Siboliban
|
||||
* @author Flippercode
|
||||
* @author ProfilePress
|
||||
* @author One Designs
|
||||
* @copyright 2013-2014 Bangbay Siboliban
|
||||
* @copyright 2014-2020 Flippercode
|
||||
* @copyright 2020-2021 ProfilePress
|
||||
* @copyright 2021 One Designs
|
||||
* @version 2.3.9
|
||||
*/
|
||||
|
||||
class WP_User_Avatar_Profile_Widget extends WP_Widget {
|
||||
/**
|
||||
* Constructor
|
||||
* @since 1.9.4
|
||||
*/
|
||||
public function __construct() {
|
||||
$widget_ops = array(
|
||||
'classname' => 'widget_wp_user_avatar',
|
||||
'description' => sprintf(
|
||||
/* translators: [avatar_upload] shortcode */
|
||||
__( 'Insert %s', 'one-user-avatar' ),
|
||||
'[avatar_upload]'
|
||||
),
|
||||
);
|
||||
|
||||
parent::__construct( 'wp_user_avatar_profile', __( 'One User Avatar', 'one-user-avatar' ), $widget_ops );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add [avatar_upload] to widget
|
||||
* @since 1.9.4
|
||||
* @param array $args
|
||||
* @param array $instance
|
||||
* @uses object $wp_user_avatar
|
||||
* @uses bool $wpua_allow_upload
|
||||
* @uses object $wpua_shortcode
|
||||
* @uses add_filter()
|
||||
* @uses apply_filters()
|
||||
* @uses is_user_logged_in()
|
||||
* @uses remove_filter()
|
||||
* @uses wpua_edit_shortcode()
|
||||
* @uses wpua_is_author_or_above()
|
||||
*/
|
||||
public function widget($args, $instance) {
|
||||
global $wp_user_avatar, $wpua_allow_upload, $wpua_shortcode;
|
||||
|
||||
extract( $args );
|
||||
|
||||
$instance = apply_filters( 'wpua_widget_instance', $instance );
|
||||
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
|
||||
$text = apply_filters( 'widget_text', empty( $instance['text'] ) ? '' : $instance['text'], $instance );
|
||||
|
||||
// Show widget only for users with permission
|
||||
if ( $wp_user_avatar->wpua_is_author_or_above() || ( 1 == (bool) $wpua_allow_upload && is_user_logged_in() ) ) {
|
||||
echo $before_widget;
|
||||
|
||||
if ( ! empty( $title ) ) {
|
||||
echo $before_title . esc_html( $title ) . $after_title;
|
||||
}
|
||||
|
||||
if ( ! empty( $text ) ) {
|
||||
echo '<div class="textwidget">';
|
||||
echo wp_kses_post( ! empty( $instance['filter'] ) ? wpautop( $text ) : $text );
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
// Remove profile title
|
||||
add_filter( 'wpua_profile_title', '__return_null' );
|
||||
|
||||
// Get [avatar_upload] shortcode
|
||||
echo $wpua_shortcode->wpua_edit_shortcode( '' );
|
||||
|
||||
// Add back profile title
|
||||
remove_filter('wpua_profile_title', '__return_null');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set title
|
||||
* @since 1.9.4
|
||||
* @param array $instance
|
||||
* @uses wp_parse_args()
|
||||
*/
|
||||
public function form( $instance ) {
|
||||
$instance = wp_parse_args( (array) $instance, array(
|
||||
'title' => '',
|
||||
'text' => '',
|
||||
) );
|
||||
?>
|
||||
|
||||
<p>
|
||||
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>">
|
||||
<?php esc_html_e( 'Title:', 'one-user-avatar' ); ?>
|
||||
</label>
|
||||
|
||||
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name('title') ); ?>" type="text" value="<?php echo esc_attr( wp_kses( $instance['title'], 'data' ) ); ?>" />
|
||||
</p>
|
||||
|
||||
<label for="<?php echo esc_attr( $this->get_field_id( 'filter' ) ); ?>"><?php esc_html_e( 'Description:', 'one-user-avatar' ); ?></label>
|
||||
|
||||
<textarea class="widefat" rows="3" cols="20" id="<?php echo esc_attr( $this->get_field_id( 'text' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'text' ) ); ?>"><?php echo esc_textarea( $instance['text'] ); ?></textarea>
|
||||
|
||||
<p>
|
||||
<input id="<?php echo esc_attr( $this->get_field_id( 'filter' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'filter' ) ); ?>" type="checkbox" <?php checked( isset( $instance['filter'] ) ? $instance['filter'] : 0 ); ?> />
|
||||
|
||||
<label for="<?php echo esc_attr( $this->get_field_id( 'filter' ) ); ?>">
|
||||
<?php esc_html_e( 'Automatically add paragraphs', 'one-user-avatar' ); ?>
|
||||
</label>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Update widget
|
||||
* @since 1.9.4
|
||||
* @param array $new_instance
|
||||
* @param array $old_instance
|
||||
* @uses current_user_can()
|
||||
* @return array
|
||||
*/
|
||||
public function update( $new_instance, $old_instance ) {
|
||||
$instance = $old_instance;
|
||||
|
||||
$instance['title'] = wp_kses( $new_instance['title'], 'data' );
|
||||
|
||||
if ( current_user_can( 'unfiltered_html' ) ) {
|
||||
$instance['text'] = $new_instance['text'];
|
||||
} else {
|
||||
$instance['text'] = stripslashes( wp_filter_post_kses( addslashes( $new_instance['text'] ) ) );
|
||||
}
|
||||
|
||||
$instance['filter'] = isset( $new_instance['filter'] );
|
||||
|
||||
return $instance;
|
||||
}
|
||||
}
|
@@ -0,0 +1,689 @@
|
||||
<?php
|
||||
/**
|
||||
* Defines all profile and upload settings.
|
||||
*
|
||||
* @package One User Avatar
|
||||
* @author Bangbay Siboliban
|
||||
* @author Flippercode
|
||||
* @author ProfilePress
|
||||
* @author One Designs
|
||||
* @copyright 2013-2014 Bangbay Siboliban
|
||||
* @copyright 2014-2020 Flippercode
|
||||
* @copyright 2020-2021 ProfilePress
|
||||
* @copyright 2021 One Designs
|
||||
* @version 2.3.9
|
||||
*/
|
||||
|
||||
class WP_User_Avatar {
|
||||
/**
|
||||
* Constructor
|
||||
* @since 1.8
|
||||
* @uses string $pagenow
|
||||
* @uses bool $show_avatars
|
||||
* @uses object $wpua_admin
|
||||
* @uses bool $wpua_allow_upload
|
||||
* @uses add_action()
|
||||
* @uses add_filterI]()
|
||||
* @uses is_admin()
|
||||
* @uses is_user_logged_in()
|
||||
* @uses wpua_is_author_or_above()
|
||||
* @uses wpua_is_menu_page()
|
||||
*/
|
||||
public function __construct() {
|
||||
global $pagenow, $show_avatars, $wpua_admin, $wpua_allow_upload;
|
||||
|
||||
// Add WPUA to profile for users with permission
|
||||
if ( $this->wpua_is_author_or_above() || ( 1 == (bool) $wpua_allow_upload && is_user_logged_in() ) ) {
|
||||
// Profile functions and scripts
|
||||
add_action( 'show_user_profile', array( $this, 'wpua_maybe_show_user_profile' ) );
|
||||
add_action( 'edit_user_profile', array( $this, 'wpua_maybe_show_user_profile' ) );
|
||||
|
||||
add_action( 'personal_options_update', array( $this, 'wpua_action_process_option_update' ) );
|
||||
add_action( 'edit_user_profile_update', array( $this, 'wpua_action_process_option_update' ) );
|
||||
|
||||
add_action( 'user_new_form', array( $this, 'wpua_action_show_user_profile' ) );
|
||||
add_action( 'user_register', array( $this, 'wpua_action_process_option_update' ) );
|
||||
|
||||
add_filter( 'user_profile_picture_description', array( $this, 'wpua_description_show_user_profile' ), PHP_INT_MAX, 2 );
|
||||
|
||||
// Admin scripts
|
||||
$pages = array( 'profile.php', 'options-discussion.php', 'user-edit.php', 'user-new.php', 'admin.php' );
|
||||
|
||||
if ( in_array( $pagenow, $pages ) || $wpua_admin->wpua_is_menu_page() ) {
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'wpua_media_upload_scripts' ) );
|
||||
}
|
||||
|
||||
// Front pages
|
||||
if ( ! is_admin() ) {
|
||||
add_action( 'show_user_profile', array( 'wp_user_avatar', 'wpua_media_upload_scripts' ) );
|
||||
add_action( 'edit_user_profile', array( 'wp_user_avatar', 'wpua_media_upload_scripts' ) );
|
||||
}
|
||||
|
||||
if ( ! $this->wpua_is_author_or_above() ) {
|
||||
// Upload errors
|
||||
add_action( 'user_profile_update_errors', array( $this, 'wpua_upload_errors' ), 10, 3 );
|
||||
|
||||
// Prefilter upload size
|
||||
add_filter( 'wp_handle_upload_prefilter', array( $this, 'wpua_handle_upload_prefilter' ) );
|
||||
}
|
||||
}
|
||||
|
||||
add_filter( 'media_view_settings', array( $this, 'wpua_media_view_settings' ), 10, 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Avatars have no parent posts
|
||||
*
|
||||
* @param array $settings
|
||||
*
|
||||
* @return array
|
||||
* @uses object $post
|
||||
* @uses bool $wpua_is_profile
|
||||
* @uses is_admin()
|
||||
* array $settings
|
||||
* @since 1.8.4
|
||||
*/
|
||||
public function wpua_media_view_settings( $settings ) {
|
||||
global $post, $wpua_is_profile;
|
||||
|
||||
// Get post ID so not to interfere with media uploads
|
||||
$post_id = is_object( $post ) ? $post->ID : 0;
|
||||
|
||||
// Don't use post ID on front pages if there's a WPUA uploader
|
||||
$settings['post']['id'] = ( ! is_admin() && 1 == $wpua_is_profile ) ? 0 : $post_id;
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Media Uploader
|
||||
* @since 1.4
|
||||
* @param object $user
|
||||
* @uses object $current_user
|
||||
* @uses string $mustache_admin
|
||||
* @uses string $pagenow
|
||||
* @uses object $post
|
||||
* @uses bool $show_avatars
|
||||
* @uses object $wp_user_avatar
|
||||
* @uses object $wpua_admin
|
||||
* @uses object $wpua_functions
|
||||
* @uses bool $wpua_is_profile
|
||||
* @uses int $wpua_upload_size_limit
|
||||
* @uses get_user_by()
|
||||
* @uses wp_enqueue_script()
|
||||
* @uses wp_enqueue_media()
|
||||
* @uses wp_enqueue_style()
|
||||
* @uses wp_localize_script()
|
||||
* @uses wp_max_upload_size()
|
||||
* @uses wpua_get_avatar_original()
|
||||
* @uses wpua_is_author_or_above()
|
||||
* @uses wpua_is_menu_page()
|
||||
*/
|
||||
public static function wpua_media_upload_scripts( $user = '' ) {
|
||||
global $current_user,
|
||||
$mustache_admin,
|
||||
$pagenow,
|
||||
$plugin_page,
|
||||
$post,
|
||||
$show_avatars,
|
||||
$wp_user_avatar,
|
||||
$wpua_force_file_uploader,
|
||||
$wpua_admin,
|
||||
$wpua_functions,
|
||||
$wpua_is_profile,
|
||||
$wpua_upload_size_limit;
|
||||
|
||||
// This is a profile page
|
||||
$wpua_is_profile = 1;
|
||||
|
||||
$user = ( $pagenow == 'user-edit.php' && isset( $_GET['user_id'] ) ) ? get_user_by( 'id', absint( $_GET['user_id'] ) ) : $current_user;
|
||||
|
||||
wp_enqueue_style( 'wp-user-avatar', WPUA_CSS_URL . 'wp-user-avatar.css', '', WPUA_VERSION );
|
||||
|
||||
wp_enqueue_script( 'jquery' );
|
||||
|
||||
if ( ( $wp_user_avatar->wpua_is_author_or_above() && ! $wpua_force_file_uploader ) || 'options-discussion.php' == $pagenow ) {
|
||||
wp_enqueue_script( 'admin-bar' );
|
||||
wp_enqueue_media( array( 'post' => $post ) );
|
||||
wp_enqueue_script( 'wp-user-avatar', WPUA_JS_URL . 'wp-user-avatar.js', array( 'jquery', 'media-editor' ), WPUA_VERSION, true );
|
||||
} else {
|
||||
wp_enqueue_script( 'wp-user-avatar', WPUA_JS_URL . 'wp-user-avatar-user.js', array( 'jquery' ), WPUA_VERSION, true );
|
||||
}
|
||||
|
||||
// Admin scripts
|
||||
if ( 'options-discussion.php' == $pagenow || $wpua_admin->wpua_is_menu_page() ) {
|
||||
wp_localize_script( 'wp-user-avatar', 'wpua_custom', array(
|
||||
'avatar_thumb' => $mustache_admin,
|
||||
) );
|
||||
}
|
||||
|
||||
if (
|
||||
'options-discussion.php' == $pagenow
|
||||
||
|
||||
$wpua_admin->wpua_is_menu_page()
|
||||
||
|
||||
(
|
||||
'admin.php' == $pagenow
|
||||
&&
|
||||
isset( $plugin_page )
|
||||
&&
|
||||
'wp-user-avatar-library' == $plugin_page
|
||||
)
|
||||
) {
|
||||
// Settings control
|
||||
wp_enqueue_script( 'wp-user-avatar-admin', WPUA_JS_URL . 'wp-user-avatar-admin.js', array( 'wp-user-avatar' ), WPUA_VERSION, true );
|
||||
wp_localize_script( 'wp-user-avatar-admin', 'wpua_admin', array(
|
||||
'upload_size_limit' => $wpua_upload_size_limit,
|
||||
'max_upload_size' => wp_max_upload_size(),
|
||||
) );
|
||||
} else {
|
||||
// Original user avatar
|
||||
$avatar_medium_src = 1 == (bool) $show_avatars ? $wpua_functions->wpua_get_avatar_original( $user->user_email, 'medium' ) : includes_url() . 'images/blank.gif';
|
||||
|
||||
wp_localize_script( 'wp-user-avatar', 'wpua_custom', array(
|
||||
'avatar_thumb' => $avatar_medium_src,
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
public static function wpua_core_show_user_profile( $user ) {
|
||||
global $blog_id,
|
||||
$current_user,
|
||||
$show_avatars,
|
||||
$wpdb,
|
||||
$wp_user_avatar,
|
||||
$wpua_force_file_uploader,
|
||||
$wpua_edit_avatar,
|
||||
$wpua_functions,
|
||||
$wpua_upload_size_limit_with_units;
|
||||
|
||||
$has_wp_user_avatar = has_wp_user_avatar( @$user->ID );
|
||||
|
||||
// Get WPUA attachment ID
|
||||
$wpua = get_user_meta( @$user->ID, $wpdb->get_blog_prefix( $blog_id ) . 'user_avatar', true );
|
||||
|
||||
// Show remove button if WPUA is set
|
||||
$hide_remove = ! $has_wp_user_avatar ? 'wpua-hide' : '';
|
||||
|
||||
// Hide image tags if show avatars is off
|
||||
$hide_images = ! $has_wp_user_avatar && 0 == (bool) $show_avatars ? 'wpua-no-avatars' : '';
|
||||
|
||||
// If avatars are enabled, get original avatar image or show blank
|
||||
$avatar_medium_src = 1 == (bool) $show_avatars ? $wpua_functions->wpua_get_avatar_original( @$user->user_email, 'medium' ) : includes_url() . 'images/blank.gif';
|
||||
|
||||
// Check if user has wp_user_avatar, if not show image from above
|
||||
$avatar_medium = $has_wp_user_avatar ? get_wp_user_avatar_src( $user->ID, 'medium' ) : $avatar_medium_src;
|
||||
|
||||
// Check if user has wp_user_avatar, if not show image from above
|
||||
$avatar_thumbnail = $has_wp_user_avatar ? get_wp_user_avatar_src( $user->ID, 96 ) : $avatar_medium_src;
|
||||
$edit_attachment_link = esc_url( add_query_arg( array(
|
||||
'post' => $wpua,
|
||||
'action' => 'edit',
|
||||
), admin_url( 'post.php' ) ) );
|
||||
?>
|
||||
|
||||
<input type="hidden" name="wp-user-avatar" id="<?php echo esc_attr( ( 'add-new-user' == $user ) ? 'wp-user-avatar' : 'wp-user-avatar-existing' ) ?>" value="<?php echo esc_attr( $wpua ); ?>" />
|
||||
|
||||
<?php
|
||||
if ( $wp_user_avatar->wpua_is_author_or_above() && ! $wpua_force_file_uploader ) :
|
||||
// Button to launch Media Uploader
|
||||
?>
|
||||
|
||||
<p id="<?php echo esc_attr( ( 'add-new-user' == $user ) ? 'wpua-add-button' : 'wpua-add-button-existing' ); ?>">
|
||||
<button
|
||||
type="button"
|
||||
class="button"
|
||||
id="<?php echo esc_attr( ( 'add-new-user' == $user ) ? 'wpua-add' : 'wpua-add-existing' ); ?>"
|
||||
name="<?php echo esc_attr( ( 'add-new-user' == $user ) ? 'wpua-add' : 'wpua-add-existing' ); ?>"
|
||||
data-title="<?php printf(
|
||||
/* translators: user display name */
|
||||
__( 'Choose Image: %s', 'one-user-avatar' ),
|
||||
( ! empty( $user->display_name ) ? esc_attr( $user->display_name ) : '' )
|
||||
); ?>"
|
||||
>
|
||||
<?php esc_html_e( 'Choose Image', 'one-user-avatar' ); ?>
|
||||
</button>
|
||||
</p>
|
||||
|
||||
<?php
|
||||
elseif ( ! $wp_user_avatar->wpua_is_author_or_above() || $wpua_force_file_uploader ) :
|
||||
// Upload button
|
||||
?>
|
||||
|
||||
<p id="<?php echo esc_attr( ( 'add-new-user' == $user ) ? 'wpua-upload-button' : 'wpua-upload-button-existing' ); ?>">
|
||||
<input name="wpua-file" id="<?php echo esc_attr( ( 'add-new-user' == $user ) ? 'wpua-file' : 'wpua-file-existing' ); ?>" type="file" />
|
||||
|
||||
<button type="submit" class="button" id="<?php echo esc_attr( ( 'add-new-user' == $user ) ? 'wpua-upload' : 'wpua-upload-existing' ); ?>" name="submit" value="<?php esc_html_e( 'Upload', 'one-user-avatar' ); ?>">
|
||||
<?php esc_html_e( 'Upload', 'one-user-avatar' ); ?>
|
||||
</button>
|
||||
</p>
|
||||
|
||||
<p id="<?php echo esc_attr( ( 'add-new-user' == $user ) ? 'wpua-upload-messages' : 'wpua-upload-messages-existing' ); ?>">
|
||||
<span id="<?php echo esc_attr( ( $user == 'add-new-user') ? 'wpua-max-upload' : 'wpua-max-upload-existing' ); ?>" class="description">
|
||||
<?php
|
||||
printf(
|
||||
/* translators: file size in KB */
|
||||
__( 'Maximum upload file size: %s.', 'one-user-avatar' ),
|
||||
esc_html( $wpua_upload_size_limit_with_units . 'KB' )
|
||||
);
|
||||
?>
|
||||
</span>
|
||||
|
||||
<span id="<?php echo esc_attr( ( 'add-new-user' == $user ) ? 'wpua-allowed-files' : 'wpua-allowed-files-existing' ); ?>" class="description">
|
||||
<?php
|
||||
printf(
|
||||
/* translators: allowed file extensions */
|
||||
__( 'Allowed Files: %s', 'one-user-avatar' ),
|
||||
'<code>jpg jpeg png gif</code>'
|
||||
);
|
||||
?>
|
||||
</span>
|
||||
</p>
|
||||
|
||||
<?php
|
||||
endif;
|
||||
?>
|
||||
|
||||
<div id="<?php echo esc_attr( ( 'add-new-user' == $user ) ? 'wpua-images' : 'wpua-images-existing' ); ?>" class="<?php echo esc_attr( $hide_images ); ?>">
|
||||
<p id="<?php echo esc_attr( ( 'add-new-user' == $user ) ? 'wpua-preview' : 'wpua-preview-existing' ); ?>">
|
||||
<img src="<?php echo esc_url( $avatar_medium ); ?>" alt="<?php echo esc_attr( __( 'Original Size', 'one-user-avatar' ) ); ?>" />
|
||||
|
||||
<span class="description"><?php esc_html_e( 'Original Size', 'one-user-avatar' ); ?></span>
|
||||
</p>
|
||||
|
||||
<p id="<?php echo esc_attr( ( 'add-new-user' == $user ) ? 'wpua-thumbnail' : 'wpua-thumbnail-existing' ); ?>">
|
||||
<img src="<?php echo esc_url( $avatar_thumbnail ); ?>" alt="<?php echo esc_attr( __( 'Thumbnail', 'one-user-avatar' ) ); ?>"/>
|
||||
|
||||
<span class="description"><?php esc_html_e( 'Thumbnail', 'one-user-avatar' ); ?></span>
|
||||
</p>
|
||||
|
||||
<p id="<?php echo esc_attr( ( 'add-new-user' == $user ) ? 'wpua-remove-button' : 'wpua-remove-button-existing' ); ?>" class="<?php echo esc_attr( $hide_remove ); ?>">
|
||||
<button type="button" class="button" id="<?php echo esc_attr( ( 'add-new-user' == $user ) ? 'wpua-remove' : 'wpua-remove-existing' ); ?>" name="wpua-remove"><?php esc_html_e( 'Remove Image', 'one-user-avatar' ); ?></button>
|
||||
</p>
|
||||
|
||||
<p id="<?php echo esc_attr( ( 'add-new-user' == $user ) ? 'wpua-undo-button' : 'wpua-undo-button-existing' ); ?>">
|
||||
<button type="button" class="button" id="<?php echo esc_attr( ( 'add-new-user' == $user ) ? 'wpua-undo' : 'wpua-undo-existing' ); ?>" name="wpua-undo"><?php esc_html_e( 'Undo', 'one-user-avatar' ); ?></button>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Add to edit user profile
|
||||
*
|
||||
* @param object $user
|
||||
*
|
||||
* @since 1.4
|
||||
* @uses int $blog_id
|
||||
* @uses object $current_user
|
||||
* @uses bool $show_avatars
|
||||
* @uses object $wpdb
|
||||
* @uses object $wp_user_avatar
|
||||
* @uses bool $wpua_edit_avatar
|
||||
* @uses object $wpua_functions
|
||||
* @uses string $wpua_upload_size_limit_with_units
|
||||
* @uses add_query_arg()
|
||||
* @uses admin_url()
|
||||
* @uses do_action()
|
||||
* @uses get_blog_prefix()
|
||||
* @uses get_user_meta()
|
||||
* @uses get_wp_user_avatar_src()
|
||||
* @uses has_wp_user_avatar()
|
||||
* @uses is_admin()
|
||||
* @uses wpua_author()
|
||||
* @uses wpua_get_avatar_original()
|
||||
* @uses wpua_is_author_or_above()
|
||||
*/
|
||||
public static function wpua_action_show_user_profile( $user ) {
|
||||
$is_admin = is_admin() ? '_admin' : '';
|
||||
|
||||
do_action( 'wpua_before_avatar' . $is_admin );
|
||||
|
||||
self::wpua_core_show_user_profile( $user );
|
||||
|
||||
do_action( 'wpua_after_avatar' . $is_admin );
|
||||
}
|
||||
|
||||
public function wpua_maybe_show_user_profile( $user ) {
|
||||
if ( is_admin() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->wpua_action_show_user_profile( $user );
|
||||
}
|
||||
|
||||
// setting defaults for the filter callback fixes an error like https://wordpress.org/support/topic/error-missing-argument-2-for-wp_user_avatarclosure
|
||||
// see https://stackoverflow.com/questions/37779680/missing-argument-2-for-a-custom-function
|
||||
public function wpua_description_show_user_profile( $description = '', $profileuser = null ) {
|
||||
ob_start();
|
||||
|
||||
echo wp_specialchars_decode( wp_kses(
|
||||
'<style>.user-profile-picture > td > .avatar { display: none; }</style>',
|
||||
array(
|
||||
'style' => array(),
|
||||
)
|
||||
) );
|
||||
|
||||
self::wpua_core_show_user_profile( $profileuser );
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add upload error messages
|
||||
* @since 1.7.1
|
||||
* @param array $errors
|
||||
* @param bool $update
|
||||
* @param object $user
|
||||
* @uses int $wpua_upload_size_limit
|
||||
* @uses add()
|
||||
* @uses wp_upload_dir()
|
||||
*/
|
||||
public static function wpua_upload_errors( $errors, $update, $user ) {
|
||||
global $wpua_upload_size_limit;
|
||||
|
||||
if ( $update && ! empty( $_FILES['wpua-file'] ) ) {
|
||||
$file = $_FILES['wpua-file'];
|
||||
$size = isset( $file['size'] ) ? absint( $file['size'] ) : 0;
|
||||
$type = isset( $file['type'] ) ? sanitize_mime_type( $file['type'] ) : '';
|
||||
|
||||
$upload_dir = wp_upload_dir();
|
||||
|
||||
// Allow only JPG, GIF, PNG
|
||||
if ( ! empty( $type ) && ! preg_match( '/(jpe?g|gif|png)$/i', $type ) ) {
|
||||
$errors->add( 'wpua_file_type', __( 'This file is not an image. Please try another.', 'one-user-avatar' ) );
|
||||
}
|
||||
|
||||
// Upload size limit
|
||||
if ( ! empty( $size ) && $size > $wpua_upload_size_limit ) {
|
||||
$errors->add( 'wpua_file_size', __( 'Memory exceeded. Please try another smaller file.', 'one-user-avatar' ) );
|
||||
}
|
||||
|
||||
// Check if directory is writeable
|
||||
if ( ! is_writeable( $upload_dir['path'] ) ) {
|
||||
$errors->add( 'wpua_file_directory', sprintf(
|
||||
/* translators: directory path */
|
||||
__( 'Unable to create directory %s. Is its parent directory writable by the server?', 'one-user-avatar' ), $upload_dir['path']
|
||||
) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set upload size limit
|
||||
* @since 1.5
|
||||
* @param object $file
|
||||
* @uses int $wpua_upload_size_limit
|
||||
* @uses add_action()
|
||||
* @return object $file
|
||||
*/
|
||||
public function wpua_handle_upload_prefilter( $file ) {
|
||||
global $wpua_upload_size_limit;
|
||||
|
||||
$size = absint( $file['size'] );
|
||||
|
||||
if ( ! empty( $size ) && $size > $wpua_upload_size_limit ) {
|
||||
/**
|
||||
* Error handling that only appears on front pages
|
||||
* @since 1.7
|
||||
*/
|
||||
function wpua_file_size_error( $errors, $update, $user ) {
|
||||
$errors->add( 'wpua_file_size', __( 'Memory exceeded. Please try another smaller file.', 'one-user-avatar' ) );
|
||||
}
|
||||
|
||||
add_action( 'user_profile_update_errors', 'wpua_file_size_error', 10, 3 );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update user meta
|
||||
* @since 1.4
|
||||
* @param int $user_id
|
||||
* @uses int $blog_id
|
||||
* @uses object $post
|
||||
* @uses object $wpdb
|
||||
* @uses object $wp_user_avatar
|
||||
* @uses bool $wpua_resize_crop
|
||||
* @uses int $wpua_resize_h
|
||||
* @uses bool $wpua_resize_upload
|
||||
* @uses int $wpua_resize_w
|
||||
* @uses add_post_meta()
|
||||
* @uses delete_metadata()
|
||||
* @uses get_blog_prefix()
|
||||
* @uses is_wp_error()
|
||||
* @uses update_post_meta()
|
||||
* @uses update_user_meta()
|
||||
* @uses wp_delete_attachment()
|
||||
* @uses wp_generate_attachment_metadata()
|
||||
* @uses wp_get_image_editor()
|
||||
* @uses wp_handle_upload()
|
||||
* @uses wp_insert_attachment()
|
||||
* @uses WP_Query()
|
||||
* @uses wp_read_image_metadata()
|
||||
* @uses wp_reset_query()
|
||||
* @uses wp_update_attachment_metadata()
|
||||
* @uses wp_upload_dir()
|
||||
* @uses wpua_is_author_or_above()
|
||||
* @uses object $wpua_admin
|
||||
* @uses wpua_has_gravatar()
|
||||
*/
|
||||
public static function wpua_action_process_option_update( $user_id ) {
|
||||
global $blog_id,
|
||||
$post,
|
||||
$wpdb,
|
||||
$wp_user_avatar,
|
||||
$wpua_force_file_uploader,
|
||||
$wpua_resize_crop,
|
||||
$wpua_resize_h,
|
||||
$wpua_resize_upload,
|
||||
$wpua_resize_w,
|
||||
$wpua_admin;
|
||||
|
||||
// Check if user has publish_posts capability
|
||||
if ( $wp_user_avatar->wpua_is_author_or_above() && ! $wpua_force_file_uploader ) {
|
||||
$wpua_id = isset( $_POST['wp-user-avatar'] ) ? absint( $_POST['wp-user-avatar'] ) : 0;
|
||||
|
||||
// Remove old attachment postmeta
|
||||
delete_metadata( 'post', null, '_wp_attachment_wp_user_avatar', $user_id, true );
|
||||
|
||||
// Create new attachment postmeta
|
||||
add_post_meta( $wpua_id, '_wp_attachment_wp_user_avatar', $user_id );
|
||||
|
||||
// Update usermeta
|
||||
update_user_meta( $user_id, $wpdb->get_blog_prefix( $blog_id ) . 'user_avatar', $wpua_id );
|
||||
} else {
|
||||
// Remove attachment info if avatar is blank
|
||||
if ( isset( $_POST['wp-user-avatar'] ) && empty( $_POST['wp-user-avatar'] ) ) {
|
||||
// Delete other uploads by user
|
||||
$q = array(
|
||||
'author' => $user_id,
|
||||
'post_type' => 'attachment',
|
||||
'post_status' => 'inherit',
|
||||
'posts_per_page' => '-1',
|
||||
'meta_query' => array(
|
||||
array(
|
||||
'key' => '_wp_attachment_wp_user_avatar',
|
||||
'value' => "",
|
||||
'compare' => '!='
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$avatars_wp_query = new WP_Query( $q );
|
||||
|
||||
while( $avatars_wp_query->have_posts() ) {
|
||||
$avatars_wp_query->the_post();
|
||||
|
||||
wp_delete_attachment( $post->ID );
|
||||
}
|
||||
|
||||
wp_reset_query();
|
||||
|
||||
// Remove attachment postmeta
|
||||
delete_metadata( 'post', null, '_wp_attachment_wp_user_avatar', $user_id, true );
|
||||
|
||||
// Remove usermeta
|
||||
update_user_meta( $user_id, $wpdb->get_blog_prefix( $blog_id ) . 'user_avatar', '' );
|
||||
}
|
||||
|
||||
// Create attachment from upload
|
||||
if ( isset( $_POST['submit'] ) && $_POST['submit'] && ! empty( $_FILES['wpua-file'] ) ) {
|
||||
$file = $_FILES['wpua-file'];
|
||||
$name = isset( $file['name'] ) ? sanitize_file_name( $file['name'] ) : '';
|
||||
$type = isset( $file['type'] ) ? sanitize_mime_type( $file['type'] ) : '';
|
||||
$file = wp_handle_upload( $file, array(
|
||||
'test_form' => false,
|
||||
) );
|
||||
|
||||
if ( isset( $file['url'] ) ) {
|
||||
if ( ! empty( $type ) && preg_match( '/(jpe?g|gif|png)$/i' , $type ) ) {
|
||||
// Resize uploaded image
|
||||
if ( 1 == (bool) $wpua_resize_upload ) {
|
||||
// Original image
|
||||
$uploaded_image = wp_get_image_editor( $file['file'] );
|
||||
|
||||
// Check for errors
|
||||
if ( ! is_wp_error( $uploaded_image ) ) {
|
||||
// Resize image
|
||||
$uploaded_image->resize( $wpua_resize_w, $wpua_resize_h, $wpua_resize_crop );
|
||||
|
||||
// Save image
|
||||
$uploaded_image->save( $file['file'] );
|
||||
}
|
||||
}
|
||||
|
||||
// Break out file info
|
||||
$name_parts = pathinfo( $name );
|
||||
$name = trim( substr( $name, 0, -( 1 + strlen( $name_parts['extension'] ) ) ) );
|
||||
$url = $file['url'];
|
||||
$file = $file['file'];
|
||||
$title = $name;
|
||||
|
||||
// Use image exif/iptc data for title if possible
|
||||
if ( $image_meta = @wp_read_image_metadata( $file ) ) {
|
||||
if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) {
|
||||
$title = $image_meta['title'];
|
||||
}
|
||||
}
|
||||
|
||||
// Construct the attachment array
|
||||
$attachment = array(
|
||||
'guid' => $url,
|
||||
'post_mime_type' => $type,
|
||||
'post_title' => $title,
|
||||
'post_content' => '',
|
||||
);
|
||||
|
||||
// This should never be set as it would then overwrite an existing attachment
|
||||
if ( isset( $attachment['ID'] ) ) {
|
||||
unset( $attachment['ID'] );
|
||||
}
|
||||
|
||||
// Save the attachment metadata
|
||||
$attachment_id = wp_insert_attachment( $attachment, $file );
|
||||
|
||||
if ( ! is_wp_error( $attachment_id ) ) {
|
||||
// Delete other uploads by user
|
||||
$q = array(
|
||||
'author' => $user_id,
|
||||
'post_type' => 'attachment',
|
||||
'post_status' => 'inherit',
|
||||
'posts_per_page' => '-1',
|
||||
'meta_query' => array(
|
||||
array(
|
||||
'key' => '_wp_attachment_wp_user_avatar',
|
||||
'value' => '',
|
||||
'compare' => '!=',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$avatars_wp_query = new WP_Query( $q );
|
||||
|
||||
while ( $avatars_wp_query->have_posts() ){
|
||||
$avatars_wp_query->the_post();
|
||||
|
||||
wp_delete_attachment($post->ID);
|
||||
}
|
||||
|
||||
wp_reset_query();
|
||||
|
||||
wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) );
|
||||
|
||||
// Remove old attachment postmeta
|
||||
delete_metadata( 'post', null, '_wp_attachment_wp_user_avatar', $user_id, true );
|
||||
|
||||
// Create new attachment postmeta
|
||||
update_post_meta( $attachment_id, '_wp_attachment_wp_user_avatar', $user_id );
|
||||
|
||||
// Update usermeta
|
||||
update_user_meta( $user_id, $wpdb->get_blog_prefix( $blog_id ) . 'user_avatar', $attachment_id );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check attachment is owned by user
|
||||
* @since 1.4
|
||||
* @param int $attachment_id
|
||||
* @param int $user_id
|
||||
* @param bool $wpua_author
|
||||
* @uses get_post()
|
||||
* @return bool
|
||||
*/
|
||||
private function wpua_author( $attachment_id, $user_id, $wpua_author = 0 ) {
|
||||
$attachment = get_post( $attachment_id );
|
||||
|
||||
if ( ! empty( $attachment ) && $attachment->post_author == $user_id ) {
|
||||
$wpua_author = true;
|
||||
}
|
||||
|
||||
return (bool) $wpua_author;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if current user has at least Author privileges
|
||||
* @since 1.8.5
|
||||
* @uses current_user_can()
|
||||
* @uses apply_filters()
|
||||
* @return bool
|
||||
*/
|
||||
public function wpua_is_author_or_above() {
|
||||
$is_author_or_above = (
|
||||
current_user_can( 'edit_published_posts' ) &&
|
||||
current_user_can( 'upload_files' ) &&
|
||||
current_user_can( 'publish_posts') &&
|
||||
current_user_can( 'delete_published_posts')
|
||||
) ? true : false;
|
||||
|
||||
/**
|
||||
* Filter Author privilege check
|
||||
* @since 1.9.2
|
||||
* @param bool $is_author_or_above
|
||||
*/
|
||||
return (bool) apply_filters( 'wpua_is_author_or_above', $is_author_or_above );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize WP_User_Avatar
|
||||
* @since 1.8
|
||||
*/
|
||||
function wpua_init() {
|
||||
global $wp_user_avatar;
|
||||
|
||||
if ( ! isset( $wp_user_avatar ) ) {
|
||||
$wp_user_avatar = new WP_User_Avatar();
|
||||
}
|
||||
|
||||
return $wp_user_avatar;
|
||||
}
|
||||
add_action( 'init', 'wpua_init' );
|
@@ -0,0 +1,216 @@
|
||||
<?php
|
||||
/**
|
||||
* Public user functions.
|
||||
*
|
||||
* @package One User Avatar
|
||||
* @author Bangbay Siboliban
|
||||
* @author Flippercode
|
||||
* @author ProfilePress
|
||||
* @author One Designs
|
||||
* @copyright 2013-2014 Bangbay Siboliban
|
||||
* @copyright 2014-2020 Flippercode
|
||||
* @copyright 2020-2021 ProfilePress
|
||||
* @copyright 2021 One Designs
|
||||
* @version 2.3.9
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns true if user has wp_user_avatar
|
||||
* @since 1.8
|
||||
* @param int|string $id_or_email
|
||||
* @param bool $has_wpua
|
||||
* @param object $user
|
||||
* @param int $user_id
|
||||
* @uses object $wpua_functions
|
||||
* @return object has_wp_user_avatar()
|
||||
*/
|
||||
function has_wp_user_avatar( $id_or_email = '', $has_wpua = '', $user = '', $user_id = '' ) {
|
||||
global $wpua_functions;
|
||||
|
||||
return $wpua_functions->has_wp_user_avatar( $id_or_email, $has_wpua, $user, $user_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Find WPUA, show get_avatar if empty
|
||||
*
|
||||
* @param int|string $id_or_email
|
||||
* @param int|string $size
|
||||
* @param string $align
|
||||
* @param string $alt
|
||||
* @param array $class
|
||||
*
|
||||
* @return object get_wp_user_avatar()
|
||||
* @since 1.8
|
||||
* @uses object $wpua_functions
|
||||
*/
|
||||
function get_wp_user_avatar( $id_or_email = '', $size = '', $align = '', $alt = '', $class = [] ) {
|
||||
global $wpua_functions;
|
||||
|
||||
return $wpua_functions->get_wp_user_avatar( $id_or_email, $size, $align, $alt, $class );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return just the image src
|
||||
* @since 1.8
|
||||
* @param int|string $id_or_email
|
||||
* @param int|string $size
|
||||
* @param string $align
|
||||
* @uses object $wpua_functions
|
||||
* @return object get_wp_user_avatar_src()
|
||||
*/
|
||||
function get_wp_user_avatar_src( $id_or_email = '', $size = '', $align = '') {
|
||||
global $wpua_functions;
|
||||
|
||||
return $wpua_functions->get_wp_user_avatar_src( $id_or_email, $size, $align );
|
||||
}
|
||||
|
||||
/**
|
||||
* Before wrapper for profile
|
||||
* @since 1.6
|
||||
* @uses do_action()
|
||||
*/
|
||||
function wpua_before_avatar() {
|
||||
do_action( 'wpua_before_avatar' );
|
||||
}
|
||||
|
||||
/**
|
||||
* After wrapper for profile
|
||||
* @since 1.6
|
||||
* @uses do_action()
|
||||
*/
|
||||
function wpua_after_avatar() {
|
||||
do_action( 'wpua_after_avatar' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Before avatar container
|
||||
* @since 1.6
|
||||
* @uses apply_filters()
|
||||
* @uses bbp_is_edit()
|
||||
* @uses wpuf_has_shortcode()
|
||||
*/
|
||||
function wpua_do_before_avatar() {
|
||||
$wpua_profile_title = __( 'Profile Picture', 'one-user-avatar' );
|
||||
|
||||
/**
|
||||
* Filter profile title
|
||||
* @since 1.9.4
|
||||
* @param string $wpua_profile_title
|
||||
*/
|
||||
$wpua_profile_title = apply_filters( 'wpua_profile_title', $wpua_profile_title );
|
||||
?>
|
||||
|
||||
<?php if ( class_exists( 'bbPress' ) && bbp_is_edit() ) :
|
||||
// Add to bbPress profile with same style
|
||||
?>
|
||||
<h2 class="entry-title"><?php esc_html_e( 'Profile Picture', 'one-user-avatar' ); ?></h2>
|
||||
|
||||
<fieldset class="bbp-form">
|
||||
<legend><?php esc_html_e( 'Image', 'one-user-avatar' ); ?></legend>
|
||||
<?php elseif( class_exists( 'WPUF_Main' ) && wpuf_has_shortcode( 'wpuf_editprofile' ) ) :
|
||||
// Add to WP User Frontend profile with same style
|
||||
?>
|
||||
<fieldset>
|
||||
<legend><?php esc_html_e( 'Profile Picture', 'one-user-avatar' ); ?></legend>
|
||||
|
||||
<table class="wpuf-table">
|
||||
<tr>
|
||||
<th><label for="wp_user_avatar"><?php esc_html_e( 'Image', 'one-user-avatar' ); ?></label></th>
|
||||
|
||||
<td>
|
||||
<?php else :
|
||||
// Add to profile without table
|
||||
?>
|
||||
<div class="wpua-edit-container">
|
||||
<?php if ( ! empty( $wpua_profile_title ) ) : ?>
|
||||
<h3><?php echo esc_html( $wpua_profile_title ); ?></h3>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
}
|
||||
add_action( 'wpua_before_avatar', 'wpua_do_before_avatar' );
|
||||
|
||||
/**
|
||||
* After avatar container
|
||||
* @since 1.6
|
||||
* @uses bbp_is_edit()
|
||||
* @uses wpuf_has_shortcode()
|
||||
*/
|
||||
function wpua_do_after_avatar() {
|
||||
?>
|
||||
<?php if ( class_exists( 'bbPress' ) && bbp_is_edit() ) :
|
||||
// Add to bbPress profile with same style
|
||||
?>
|
||||
</fieldset>
|
||||
<?php elseif ( class_exists( 'WPUF_Main' ) && wpuf_has_shortcode( 'wpuf_editprofile' ) ) :
|
||||
// Add to WP User Frontend profile with same style
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</fieldset>
|
||||
<?php else :
|
||||
// Add to profile without table
|
||||
?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
}
|
||||
add_action( 'wpua_after_avatar', 'wpua_do_after_avatar' );
|
||||
|
||||
/**
|
||||
* Before wrapper for profile in admin section
|
||||
* @since 1.9.4
|
||||
* @uses do_action()
|
||||
*/
|
||||
function wpua_before_avatar_admin() {
|
||||
do_action( 'wpua_before_avatar_admin' );
|
||||
}
|
||||
|
||||
/**
|
||||
* After wrapper for profile in admin section
|
||||
* @since 1.9.4
|
||||
* @uses do_action()
|
||||
*/
|
||||
function wpua_after_avatar_admin() {
|
||||
do_action( 'wpua_after_avatar_admin' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Before avatar container in admin section
|
||||
* @since 1.9.4
|
||||
*/
|
||||
function wpua_do_before_avatar_admin() {
|
||||
?>
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th><label for="wp_user_avatar"><?php esc_html_e( 'Profile Picture', 'one-user-avatar' ); ?></label></th>
|
||||
|
||||
<td>
|
||||
<?php
|
||||
}
|
||||
add_action( 'wpua_before_avatar_admin', 'wpua_do_before_avatar_admin' );
|
||||
|
||||
/**
|
||||
* After avatar container in admin section
|
||||
* @since 1.9.4
|
||||
*/
|
||||
function wpua_do_after_avatar_admin() {
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php
|
||||
}
|
||||
add_action( 'wpua_after_avatar_admin', 'wpua_do_after_avatar_admin' );
|
||||
|
||||
/**
|
||||
* Register widget
|
||||
* @since 1.9.4
|
||||
* @uses register_widget()
|
||||
*/
|
||||
function wpua_widgets_init() {
|
||||
register_widget( 'WP_User_Avatar_Profile_Widget' );
|
||||
}
|
||||
add_action('widgets_init', 'wpua_widgets_init');
|
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
/**
|
||||
* Global variables used in plugin.
|
||||
*
|
||||
* @package One User Avatar
|
||||
* @author Bangbay Siboliban
|
||||
* @author Flippercode
|
||||
* @author ProfilePress
|
||||
* @author One Designs
|
||||
* @copyright 2013-2014 Bangbay Siboliban
|
||||
* @copyright 2014-2020 Flippercode
|
||||
* @copyright 2020-2021 ProfilePress
|
||||
* @copyright 2021 One Designs
|
||||
* @version 2.3.9
|
||||
*/
|
||||
|
||||
/**
|
||||
* @since 1.8
|
||||
* @uses get_intermediate_image_sizes()
|
||||
* @uses get_option()
|
||||
* @uses wp_max_upload_size()
|
||||
*/
|
||||
|
||||
// Define global variables
|
||||
global $avatar_default,
|
||||
$show_avatars,
|
||||
$wpua_allow_upload,
|
||||
$wpua_force_file_uploader,
|
||||
$wpua_disable_um_avatars,
|
||||
$wpua_avatar_default,
|
||||
$wpua_disable_gravatar,
|
||||
$wpua_edit_avatar,
|
||||
$wpua_resize_crop,
|
||||
$wpua_resize_h,
|
||||
$wpua_resize_upload,
|
||||
$wpua_resize_w,
|
||||
$wpua_tinymce,
|
||||
$mustache_original,
|
||||
$mustache_medium,
|
||||
$mustache_thumbnail,
|
||||
$mustache_avatar,
|
||||
$mustache_admin,
|
||||
$wpua_default_avatar_updated,
|
||||
$wpua_users_updated,
|
||||
$wpua_media_updated,
|
||||
$upload_size_limit,
|
||||
$upload_size_limit_with_units,
|
||||
$wpua_user_upload_size_limit,
|
||||
$wpua_upload_size_limit,
|
||||
$wpua_upload_size_limit_with_units,
|
||||
$all_sizes,
|
||||
$wpua_hash_gravatar;
|
||||
|
||||
// Store if hash has gravatar
|
||||
$wpua_hash_gravatar = get_option( 'wpua_hash_gravatar' );
|
||||
|
||||
if ( false != $wpua_hash_gravatar ) {
|
||||
$wpua_hash_gravatar = maybe_unserialize( $wpua_hash_gravatar );
|
||||
}
|
||||
|
||||
// Default avatar name
|
||||
$avatar_default = get_option( 'avatar_default' );
|
||||
|
||||
// Attachment ID of default avatar
|
||||
$wpua_avatar_default = get_option( 'avatar_default_wp_user_avatar' );
|
||||
|
||||
// Booleans
|
||||
$show_avatars = get_option( 'show_avatars' );
|
||||
$wpua_allow_upload = get_option( 'wp_user_avatar_allow_upload' );
|
||||
$wpua_disable_um_avatars = get_option( 'wp_user_avatar_disable_um_avatars' );
|
||||
$wpua_force_file_uploader = get_option( 'wp_user_avatar_force_file_uploader' );
|
||||
$wpua_disable_gravatar = get_option( 'wp_user_avatar_disable_gravatar' );
|
||||
$wpua_edit_avatar = get_option( 'wp_user_avatar_edit_avatar' );
|
||||
$wpua_resize_crop = get_option( 'wp_user_avatar_resize_crop' );
|
||||
$wpua_resize_upload = get_option( 'wp_user_avatar_resize_upload' );
|
||||
$wpua_tinymce = get_option( 'wp_user_avatar_tinymce' );
|
||||
|
||||
// Resize dimensions
|
||||
$wpua_resize_h = get_option( 'wp_user_avatar_resize_h' );
|
||||
$wpua_resize_w = get_option( 'wp_user_avatar_resize_w' );
|
||||
|
||||
// Default avatar 512x512
|
||||
$mustache_original = WPUA_IMG_URL . 'wpua.png';
|
||||
|
||||
// Default avatar 300x300
|
||||
$mustache_medium = WPUA_IMG_URL . 'wpua-300x300.png';
|
||||
|
||||
// Default avatar 150x150
|
||||
$mustache_thumbnail = WPUA_IMG_URL . 'wpua-150x150.png';
|
||||
|
||||
// Default avatar 96x96
|
||||
$mustache_avatar = WPUA_IMG_URL . 'wpua-96x96.png';
|
||||
|
||||
// Default avatar 32x32
|
||||
$mustache_admin = WPUA_IMG_URL . 'wpua-32x32.png';
|
||||
|
||||
// Check for updates
|
||||
$wpua_default_avatar_updated = get_option( 'wp_user_avatar_default_avatar_updated' );
|
||||
$wpua_users_updated = get_option( 'wp_user_avatar_users_updated' );
|
||||
$wpua_media_updated = get_option( 'wp_user_avatar_media_updated' );
|
||||
|
||||
// Server upload size limit
|
||||
$upload_size_limit = wp_max_upload_size();
|
||||
|
||||
// Convert to KB
|
||||
if ( 1024 < $upload_size_limit ) {
|
||||
$upload_size_limit /= 1024;
|
||||
}
|
||||
|
||||
$upload_size_limit_with_units = (int) $upload_size_limit . 'KB';
|
||||
|
||||
// User upload size limit
|
||||
$wpua_user_upload_size_limit = get_option( 'wp_user_avatar_upload_size_limit' );
|
||||
|
||||
if( 0 == $wpua_user_upload_size_limit || $wpua_user_upload_size_limit > wp_max_upload_size() ) {
|
||||
$wpua_user_upload_size_limit = wp_max_upload_size();
|
||||
}
|
||||
|
||||
// Value in bytes
|
||||
$wpua_upload_size_limit = $wpua_user_upload_size_limit;
|
||||
|
||||
// Convert to KB
|
||||
if ( 1024 < $wpua_user_upload_size_limit ) {
|
||||
$wpua_user_upload_size_limit /= 1024;
|
||||
}
|
||||
|
||||
$wpua_upload_size_limit_with_units = (int) $wpua_user_upload_size_limit . 'KB';
|
||||
|
||||
// Check for custom image sizes
|
||||
$all_sizes = array_merge( get_intermediate_image_sizes(), array( 'original' ) );
|
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
/**
|
||||
* Media Library view of all avatars in use.
|
||||
*
|
||||
* @package One User Avatar
|
||||
* @author Bangbay Siboliban
|
||||
* @author Flippercode
|
||||
* @author ProfilePress
|
||||
* @author One Designs
|
||||
* @copyright 2013-2014 Bangbay Siboliban
|
||||
* @copyright 2014-2020 Flippercode
|
||||
* @copyright 2020-2021 ProfilePress
|
||||
* @copyright 2021 One Designs
|
||||
* @version 2.3.9
|
||||
*/
|
||||
|
||||
/**
|
||||
* @since 1.8
|
||||
* @uses object $wpua_admin
|
||||
* @uses _wpua_get_list_table()
|
||||
* @uses add_query_arg()
|
||||
* @uses check_admin_referer()
|
||||
* @uses current_action()
|
||||
* @uses current_user_can()
|
||||
* @uses display()
|
||||
* @uses esc_url()
|
||||
* @uses find_posts_div()
|
||||
* @uses get_pagenum()
|
||||
* @uses get_search_query
|
||||
* @uses number_format_i18n()
|
||||
* @uses prepare_items()
|
||||
* @uses remove_query_arg()
|
||||
* @uses search_box()
|
||||
* @uses views()
|
||||
* @uses wp_delete_attachment()
|
||||
* @uses wp_die()
|
||||
* @uses wp_get_referer()
|
||||
* @uses wp_redirect()
|
||||
* @uses wp_unslash()
|
||||
*/
|
||||
|
||||
/** WordPress Administration Bootstrap */
|
||||
require_once( ABSPATH . 'wp-admin/admin.php' );
|
||||
|
||||
if ( ! current_user_can( 'upload_files' ) ) {
|
||||
wp_die( __( 'You do not have permission to upload files.', 'one-user-avatar' ) );
|
||||
}
|
||||
|
||||
global $wpua_admin;
|
||||
|
||||
$wp_list_table = $wpua_admin->_wpua_get_list_table( 'WP_User_Avatar_List_Table' );
|
||||
|
||||
$wp_list_table->prepare_items();
|
||||
|
||||
?>
|
||||
|
||||
<div class="wrap">
|
||||
<h2>
|
||||
<?php esc_html_e('Avatars','one-user-avatar'); ?>
|
||||
|
||||
<?php if ( ! empty( $_REQUEST['s'] ) ) : ?>
|
||||
<span class="subtitle">
|
||||
<?php
|
||||
printf(
|
||||
/* translators: search query */
|
||||
__( 'Search results for %s','one-user-avatar' ),
|
||||
sprintf( '“%s”', get_search_query() )
|
||||
);
|
||||
?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
</h2>
|
||||
|
||||
<?php
|
||||
$message = '';
|
||||
|
||||
if ( ! empty( $_GET['deleted'] ) && $deleted = absint( $_GET['deleted'] ) ) {
|
||||
$message = sprintf(
|
||||
_n(
|
||||
'Media attachment permanently deleted.',
|
||||
'%d media attachments permanently deleted.',
|
||||
$deleted
|
||||
),
|
||||
number_format_i18n( $_GET['deleted'] )
|
||||
);
|
||||
|
||||
$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'deleted' ), $_SERVER['REQUEST_URI'] );
|
||||
}
|
||||
?>
|
||||
|
||||
<?php if ( ! empty( $message ) ) : ?>
|
||||
<div id="message" class="updated"><p><?php echo esc_html( $message ); ?></p></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php $wp_list_table->views(); ?>
|
||||
|
||||
<form class="wpua-media-form" id="posts-filter" action="" method="get">
|
||||
<?php $wp_list_table->search_box( __('Search','one-user-avatar'), 'media' ); ?>
|
||||
|
||||
<?php $wp_list_table->display(); ?>
|
||||
|
||||
<div id="ajax-response"></div>
|
||||
|
||||
<?php find_posts_div(); ?>
|
||||
|
||||
<br class="clear" />
|
||||
</form>
|
||||
</div>
|
@@ -0,0 +1,369 @@
|
||||
<?php
|
||||
/**
|
||||
* Admin page to change plugin options.
|
||||
*
|
||||
* @package One User Avatar
|
||||
* @author Bangbay Siboliban
|
||||
* @author Flippercode
|
||||
* @author ProfilePress
|
||||
* @author One Designs
|
||||
* @copyright 2013-2014 Bangbay Siboliban
|
||||
* @copyright 2014-2020 Flippercode
|
||||
* @copyright 2020-2021 ProfilePress
|
||||
* @copyright 2021 One Designs
|
||||
* @version 2.3.9
|
||||
*/
|
||||
|
||||
/**
|
||||
* @since 1.4
|
||||
* @uses bool $show_avatars
|
||||
* @uses string $upload_size_limit_with_units
|
||||
* @uses object $wpua_admin
|
||||
* @uses bool $wpua_allow_upload
|
||||
* @uses bool $wpua_disable_gravatar
|
||||
* @uses bool $wpua_edit_avatar
|
||||
* @uses bool $wpua_resize_crop
|
||||
* @uses int int $wpua_resize_h
|
||||
* @uses bool $wpua_resize_upload
|
||||
* @uses int $wpua_resize_w
|
||||
* @uses object $wpua_subscriber
|
||||
* @uses bool $wpua_tinymce
|
||||
* @uses int $wpua_upload_size_limit
|
||||
* @uses string $wpua_upload_size_limit_with_units
|
||||
* @uses admin_url()
|
||||
* @uses apply_filters()
|
||||
* @uses checked()
|
||||
* @uses do_action()
|
||||
* @uses do_settings_fields()
|
||||
* @uses get_option()
|
||||
* @uses settings_fields()
|
||||
* @uses submit_button()
|
||||
* @uses wpua_add_default_avatar()
|
||||
*/
|
||||
|
||||
global $show_avatars,
|
||||
$upload_size_limit_with_units,
|
||||
$wpua_admin,
|
||||
$wpua_allow_upload,
|
||||
$wpua_disable_um_avatars,
|
||||
$wpua_force_file_uploader,
|
||||
$wpua_disable_gravatar,
|
||||
$wpua_edit_avatar,
|
||||
$wpua_resize_crop,
|
||||
$wpua_resize_h,
|
||||
$wpua_resize_upload,
|
||||
$wpua_resize_w,
|
||||
$wpua_subscriber,
|
||||
$wpua_tinymce,
|
||||
$wpua_upload_size_limit,
|
||||
$wpua_upload_size_limit_with_units;
|
||||
|
||||
$updated = false;
|
||||
|
||||
if ( isset( $_GET['settings-updated'] ) && 'true' == $_GET['settings-updated'] ) {
|
||||
$updated = true;
|
||||
}
|
||||
|
||||
$wpua_options_page_title = __( 'One User Avatar', 'one-user-avatar' );
|
||||
|
||||
/**
|
||||
* Filter admin page title
|
||||
* @since 1.9
|
||||
* @param string $wpua_options_page_title
|
||||
*/
|
||||
$wpua_options_page_title = apply_filters( 'wpua_options_page_title', $wpua_options_page_title );
|
||||
?>
|
||||
|
||||
<div class="wrap">
|
||||
<h2><?php echo esc_html( $wpua_options_page_title ); ?></h2>
|
||||
|
||||
<table>
|
||||
<tr valign="top">
|
||||
<td align="top">
|
||||
<form method="post" action="<?php echo esc_url( admin_url( 'options.php' ) ); ?>">
|
||||
|
||||
<?php settings_fields( 'wpua-settings-group' ); ?>
|
||||
|
||||
<?php do_settings_fields( 'wpua-settings-group', '' ); ?>
|
||||
|
||||
<table class="form-table">
|
||||
<?php
|
||||
// Format settings in table rows
|
||||
$wpua_before_settings = array();
|
||||
|
||||
/**
|
||||
* Filter settings at beginning of table
|
||||
* @since 1.9
|
||||
* @param array $wpua_before_settings
|
||||
*/
|
||||
$wpua_before_settings = apply_filters( 'wpua_before_settings', $wpua_before_settings );
|
||||
|
||||
echo wp_kses_post( implode( '', $wpua_before_settings ) );
|
||||
?>
|
||||
|
||||
<tr valign="top">
|
||||
<th scope="row"><?php esc_html_e( 'Settings', 'one-user-avatar' ); ?></th>
|
||||
|
||||
<td>
|
||||
<?php
|
||||
// Format settings in fieldsets
|
||||
$wpua_settings = array();
|
||||
|
||||
$wpua_settings['tinymce'] = sprintf(
|
||||
'<fieldset>
|
||||
<label for="wp_user_avatar_tinymce">
|
||||
<input name="wp_user_avatar_tinymce" type="checkbox" id="wp_user_avatar_tinymce" value="1" %s />
|
||||
%s
|
||||
</label>
|
||||
</fieldset>',
|
||||
checked( $wpua_tinymce, true, false ),
|
||||
__( 'Add avatar button to Visual Editor', 'one-user-avatar' )
|
||||
);
|
||||
|
||||
$wpua_settings['upload'] = sprintf(
|
||||
'<fieldset>
|
||||
<label for="wp_user_avatar_allow_upload">
|
||||
<input name="wp_user_avatar_allow_upload" type="checkbox" id="wp_user_avatar_allow_upload" value="1" %s />
|
||||
%s
|
||||
</label>
|
||||
</fieldset>',
|
||||
checked( $wpua_allow_upload, true, false ),
|
||||
__( 'Allow Contributors & Subscribers to upload avatars', 'one-user-avatar' )
|
||||
);
|
||||
|
||||
$wpua_settings['gravatar'] = sprintf(
|
||||
'<fieldset>
|
||||
<label for="wp_user_avatar_disable_gravatar">
|
||||
<input name="wp_user_avatar_disable_gravatar" type="checkbox" id="wp_user_avatar_disable_gravatar" value="1" %s />
|
||||
%s
|
||||
</label>
|
||||
</fieldset>',
|
||||
checked( $wpua_disable_gravatar, true, false ),
|
||||
__( 'Disable Gravatar and use only local avatars', 'one-user-avatar' )
|
||||
);
|
||||
|
||||
if ( function_exists( 'um_get_avatar' ) ) {
|
||||
$wpua_settings['disable_um_avatars'] = sprintf(
|
||||
'<fieldset>
|
||||
<label for="wp_user_avatar_disable_um_avatars">
|
||||
<input name="wp_user_avatar_disable_um_avatars" type="checkbox" id="wp_user_avatar_disable_um_avatars" value="1" %s />
|
||||
%s
|
||||
</label>
|
||||
</fieldset>',
|
||||
checked( $wpua_disable_um_avatars, true, false ),
|
||||
__( 'Replace the custom avatars functionality in the Ultimate Member plugin', 'one-user-avatar' )
|
||||
);
|
||||
}
|
||||
|
||||
$wpua_settings['force_file_uploader'] = sprintf(
|
||||
'<fieldset>
|
||||
<label for="wp_user_avatar_force_file_uploader">
|
||||
<input name="wp_user_avatar_force_file_uploader" type="checkbox" id="wp_user_avatar_force_file_uploader" value="1" %s />
|
||||
%s
|
||||
</label>
|
||||
<p class="description">%s</p>
|
||||
</fieldset>',
|
||||
checked( $wpua_force_file_uploader, true, false ),
|
||||
__( 'Always use the browser file uploader to upload avatars', 'one-user-avatar' ),
|
||||
__( 'Check this if another plugin is conflicting with the WordPress Media Uploader.', 'one-user-avatar' )
|
||||
);
|
||||
|
||||
/**
|
||||
* Filter main settings
|
||||
* @since 1.9
|
||||
* @param array $wpua_settings
|
||||
*/
|
||||
$wpua_settings = apply_filters( 'wpua_settings', $wpua_settings );
|
||||
|
||||
echo implode( '', $wpua_settings );
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<?php
|
||||
// Format settings in table
|
||||
$wpua_subscriber_settings = array();
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
|
||||
<div id="wpua-contributors-subscribers"<?php if ( true !== (bool) $wpua_allow_upload ) : ?> style="display: none;"<?php endif; ?>>
|
||||
<table class="form-table">
|
||||
<tr valign="top">
|
||||
<th scope="row">
|
||||
<label for="wp_user_avatar_upload_size_limit">'
|
||||
<?php esc_html_e( 'Upload Size Limit', 'one-user-avatar' ); ?>
|
||||
<?php esc_html_e( '(only for Contributors & Subscribers)', 'one-user-avatar' ); ?>
|
||||
</label>
|
||||
</th>
|
||||
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text">
|
||||
<span>
|
||||
<?php esc_html_e( 'Upload Size Limit', 'one-user-avatar' ); ?>
|
||||
<?php esc_html_e( '(only for Contributors & Subscribers)', 'one-user-avatar' ); ?>
|
||||
</span>
|
||||
</legend>
|
||||
|
||||
<input name="wp_user_avatar_upload_size_limit" type="range" id="wp_user_avatar_upload_size_limit" value="<?php echo esc_attr( $wpua_upload_size_limit ); ?>" min="0" max="<?php echo esc_attr( wp_max_upload_size() ); ?>" class="regular-text" />
|
||||
|
||||
<span id="wpua-readable-size"><?php echo esc_html( $wpua_upload_size_limit_with_units ); ?></span>
|
||||
|
||||
<span id="wpua-readable-size-error"><?php printf(
|
||||
/* translators: file name */
|
||||
__( '%s exceeds the maximum upload size for this site.', 'one-user-avatar' ),
|
||||
''
|
||||
); ?></span>
|
||||
|
||||
<p class="description">
|
||||
<?php
|
||||
printf(
|
||||
/* translators: file size in KB */
|
||||
__( 'Maximum upload file size: %s.', 'one-user-avatar' ),
|
||||
esc_html( wp_max_upload_size() ) . esc_html( sprintf( ' bytes (%s)', $upload_size_limit_with_units ) )
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<label for="wp_user_avatar_edit_avatar">
|
||||
<input name="wp_user_avatar_edit_avatar" type="checkbox" id="wp_user_avatar_edit_avatar" value="1" <?php checked( $wpua_edit_avatar ); ?> />
|
||||
|
||||
<?php esc_html_e( 'Allow users to edit avatars', 'one-user-avatar' ); ?>
|
||||
</label>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<label for="wp_user_avatar_resize_upload">
|
||||
<input name="wp_user_avatar_resize_upload" type="checkbox" id="wp_user_avatar_resize_upload" value="1" <?php checked( $wpua_resize_upload ); ?> />
|
||||
|
||||
<?php esc_html_e( 'Resize avatars on upload', 'one-user-avatar' ); ?>
|
||||
</label>
|
||||
</fieldset>
|
||||
|
||||
<fieldset id="wpua-resize-sizes"<?php if ( true !== (bool) $wpua_resize_upload ) : ?> style="display: none;"<?php endif; ?>>
|
||||
<label for="wp_user_avatar_resize_w"><?php esc_html_e( 'Width', 'one-user-avatar' ); ?></label>
|
||||
|
||||
<input name="wp_user_avatar_resize_w" type="number" step="1" min="0" id="wp_user_avatar_resize_w" value="<?php echo esc_attr( get_option( 'wp_user_avatar_resize_w' ) ); ?>" class="small-text" />
|
||||
|
||||
<label for="wp_user_avatar_resize_h"><?php esc_html_e( 'Height', 'one-user-avatar' ); ?></label>
|
||||
|
||||
<input name="wp_user_avatar_resize_h" type="number" step="1" min="0" id="wp_user_avatar_resize_h" value="<?php echo esc_attr( get_option( 'wp_user_avatar_resize_h' ) ); ?>" class="small-text" />
|
||||
|
||||
<br />
|
||||
|
||||
<input name="wp_user_avatar_resize_crop" type="checkbox" id="wp_user_avatar_resize_crop" value="1" <?php checked( '1', $wpua_resize_crop ); ?> />
|
||||
|
||||
<label for="wp_user_avatar_resize_crop"><?php esc_html_e( 'Crop avatars to exact dimensions', 'one-user-avatar' ); ?></label>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
$wpua_subscriber_settings['subscriber-settings'] = ob_get_clean();
|
||||
|
||||
/**
|
||||
* Filter Subscriber settings
|
||||
* @since 1.9
|
||||
* @param array $wpua_subscriber_settings
|
||||
*/
|
||||
$wpua_subscriber_settings = apply_filters( 'wpua_subscriber_settings', $wpua_subscriber_settings );
|
||||
|
||||
echo implode( '', $wpua_subscriber_settings );
|
||||
?>
|
||||
|
||||
<table class="form-table">
|
||||
<tr valign="top">
|
||||
<th scope="row"><?php esc_html_e( 'Avatar Display', 'one-user-avatar' ); ?></th>
|
||||
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text">
|
||||
<span>
|
||||
<?php esc_html_e( 'Avatar Display', 'one-user-avatar' ); ?>
|
||||
</span>
|
||||
</legend>
|
||||
|
||||
<label for="show_avatars">
|
||||
<input type="checkbox" id="show_avatars" name="show_avatars" value="1" <?php checked( $show_avatars ); ?> />
|
||||
|
||||
<?php esc_html_e( 'Show Avatars', 'one-user-avatar' ); ?>
|
||||
</label>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr valign="top" id="avatar-rating"<?php if ( true === (bool) $wpua_disable_gravatar ) : ?> style="display: none;"<?php endif; ?>>
|
||||
<th scope="row"><?php esc_html_e( 'Maximum Rating', 'one-user-avatar' ); ?></th>
|
||||
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text">
|
||||
<span>
|
||||
<?php esc_html_e( 'Maximum Rating', 'one-user-avatar' ); ?>
|
||||
</span>
|
||||
</legend>
|
||||
|
||||
<?php
|
||||
$ratings = array(
|
||||
'G' => __( 'G — Suitable for all audiences', 'one-user-avatar' ),
|
||||
'PG' => __( 'PG — Possibly offensive, usually for audiences 13 and above', 'one-user-avatar' ),
|
||||
'R' => __( 'R — Intended for adult audiences above 17', 'one-user-avatar' ),
|
||||
'X' => __( 'X — Even more mature than above', 'one-user-avatar' ),
|
||||
);
|
||||
|
||||
foreach ( $ratings as $key => $rating ) :
|
||||
?>
|
||||
<label>
|
||||
<input type="radio" name="avatar_rating" value="<?php echo esc_attr( $key ); ?>" <?php checked( $key, get_option( 'avatar_rating' ) ); ?> />
|
||||
<?php echo esc_html( $rating ); ?>
|
||||
</label>
|
||||
|
||||
<br />
|
||||
<?php
|
||||
endforeach;
|
||||
?>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr valign="top">
|
||||
<th scope="row"><?php esc_html_e( 'Default Avatar', 'one-user-avatar' ); ?></th>
|
||||
|
||||
<td class="defaultavatarpicker">
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text">
|
||||
<span>
|
||||
<?php esc_html_e( 'Default Avatar', 'one-user-avatar' ); ?>
|
||||
</span>
|
||||
</legend>
|
||||
|
||||
<?php esc_html_e( 'For users without a custom avatar of their own, you can either display a generic logo or a generated one based on their e-mail address.', 'one-user-avatar' ); ?>
|
||||
|
||||
<br />
|
||||
|
||||
<?php echo wp_kses( $wpua_admin->wpua_add_default_avatar(), array_merge( wp_kses_allowed_html( 'post' ), array(
|
||||
'input' => array(
|
||||
'type' => true,
|
||||
'name' => true,
|
||||
'id' => true,
|
||||
'class' => true,
|
||||
'value' => true,
|
||||
),
|
||||
) ) ); ?>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<?php submit_button(); ?>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
@@ -0,0 +1,198 @@
|
||||
<?php
|
||||
/**
|
||||
* TinyMCE modal window.
|
||||
*
|
||||
* @package One User Avatar
|
||||
* @author Bangbay Siboliban
|
||||
* @author Flippercode
|
||||
* @author ProfilePress
|
||||
* @author One Designs
|
||||
* @copyright 2013-2014 Bangbay Siboliban
|
||||
* @copyright 2014-2020 Flippercode
|
||||
* @copyright 2020-2021 ProfilePress
|
||||
* @copyright 2021 One Designs
|
||||
* @version 2.3.9
|
||||
*/
|
||||
|
||||
/**
|
||||
* @since 1.2.1
|
||||
* @uses get_users()
|
||||
*/
|
||||
|
||||
if ( ! defined('ABSPATH' ) ) {
|
||||
die( 'You are not allowed to call this page directly.' );
|
||||
}
|
||||
|
||||
$hook_suffix = 'one-user-avatar_tinymce-window';
|
||||
|
||||
?><!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title><?php esc_html_e( 'One User Avatar', 'one-user-avatar' ); ?></title>
|
||||
<meta http-equiv="Content-Type" content="<?php bloginfo( 'html_type' ); ?>; charset=<?php echo esc_attr( get_option( 'blog_charset' ) ); ?>" />
|
||||
<base target="_self" />
|
||||
<?php
|
||||
/**
|
||||
* Enqueue scripts.
|
||||
*
|
||||
* @since 2.3.0
|
||||
*
|
||||
* @param string $hook_suffix The current admin page.
|
||||
*/
|
||||
do_action( 'admin_enqueue_scripts', $hook_suffix );
|
||||
|
||||
/**
|
||||
* Fires when styles are printed for this specific page based on $hook_suffix.
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
do_action( "admin_print_styles-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
|
||||
|
||||
/**
|
||||
* Fires when styles are printed for all admin pages.
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
do_action( 'admin_print_styles' );
|
||||
|
||||
/**
|
||||
* Fires when scripts are printed for this specific page based on $hook_suffix.
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
do_action( "admin_print_scripts-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
|
||||
|
||||
/**
|
||||
* Fires when scripts are printed for all admin pages.
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
do_action( 'admin_print_scripts' );
|
||||
|
||||
/**
|
||||
* Fires in head section for this specific admin page.
|
||||
*
|
||||
* The dynamic portion of the hook, `$hook_suffix`, refers to the hook suffix
|
||||
* for the admin page.
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
do_action( "admin_head-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
|
||||
|
||||
/**
|
||||
* Fires in head section for all admin pages.
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
do_action( 'admin_head' );
|
||||
?>
|
||||
</head>
|
||||
|
||||
<body id="link" class="wp-core-ui" onload="document.body.style.display='';" style="display:none;">
|
||||
<div id="wpua-tabs">
|
||||
<ul>
|
||||
<li><a href="#wpua"><?php esc_html_e( 'Profile Picture', 'one-user-avatar' ); ?></a></li>
|
||||
<li><a href="#wpua-upload"><?php esc_html_e( 'Upload', 'one-user-avatar' ); ?></a></li>
|
||||
</ul>
|
||||
|
||||
<form name="wpUserAvatar" action="#">
|
||||
<div id="wpua">
|
||||
<p>
|
||||
<label for="<?php echo esc_attr( 'wp_user_avatar_user' ); ?>"><strong><?php esc_html_e( 'User Name', 'one-user-avatar' ); ?>:</strong></label>
|
||||
|
||||
<select id="<?php echo esc_attr( 'wp_user_avatar_user' ); ?>" name="<?php echo esc_attr( 'wp_user_avatar_user' ); ?>">
|
||||
<option value=""></option>
|
||||
|
||||
<?php
|
||||
$users = get_users();
|
||||
|
||||
foreach($users as $user) :
|
||||
?>
|
||||
|
||||
<option value="<?php echo esc_attr( $user->user_login ); ?>"><?php echo esc_html( $user->display_name ); ?></option>
|
||||
|
||||
<?php
|
||||
endforeach;
|
||||
?>
|
||||
</select>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="<?php echo esc_attr( 'wp_user_avatar_size' ); ?>"><strong><?php esc_html_e( 'Size:', 'one-user-avatar' ); ?></strong></label>
|
||||
|
||||
<select id="<?php echo esc_attr( 'wp_user_avatar_size' ); ?>" name="<?php echo esc_attr('wp_user_avatar_size'); ?>">
|
||||
<option value=""></option>
|
||||
<option value="original"><?php esc_html_e( 'Original Size', 'one-user-avatar' ); ?></option>
|
||||
<option value="large"><?php esc_html_e( 'Large', 'one-user-avatar' ); ?></option>
|
||||
<option value="medium"><?php esc_html_e( 'Medium', 'one-user-avatar' ); ?></option>
|
||||
<option value="thumbnail"><?php esc_html_e( 'Thumbnail', 'one-user-avatar' ); ?></option>
|
||||
<option value="custom"><?php esc_html_e( 'Custom', 'one-user-avatar' ); ?></option>
|
||||
</select>
|
||||
</p>
|
||||
|
||||
<p id="<?php echo esc_attr( 'wp_user_avatar_size_number_section' ); ?>">
|
||||
<label for="<?php echo esc_attr( 'wp_user_avatar_size_number' ); ?>"><?php esc_html_e( 'Size:', 'one-user-avatar' ); ?></label>
|
||||
|
||||
<input type="text" size="8" id="<?php echo esc_attr( 'wp_user_avatar_size_number' ); ?>" name="<?php echo esc_attr ( 'wp_user_avatar_size' ); ?>" value="" />
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="<?php echo esc_attr( 'wp_user_avatar_align' ); ?>"><strong><?php esc_html_e( 'Alignment:', 'one-user-avatar' ); ?></strong></label>
|
||||
|
||||
<select id="<?php echo esc_attr( 'wp_user_avatar_align' ); ?>" name="<?php echo esc_attr( 'wp_user_avatar_align' ); ?>">
|
||||
<option value=""></option>
|
||||
<option value="center"><?php esc_html_e( 'Center','one-user-avatar' ); ?></option>
|
||||
<option value="left"><?php esc_html_e( 'Left', 'one-user-avatar' ); ?></option>
|
||||
<option value="right"><?php esc_html_e( 'Right', 'one-user-avatar' ); ?></option>
|
||||
</select>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="<?php echo esc_attr( 'wp_user_avatar_link' ); ?>"><strong><?php esc_html_e( 'Link To:', 'one-user-avatar' ); ?></strong></label>
|
||||
|
||||
<select id="<?php echo esc_attr( 'wp_user_avatar_link' ); ?>" name="<?php echo esc_attr( 'wp_user_avatar_link' ); ?>">
|
||||
<option value=""></option>
|
||||
<option value="file"><?php esc_html_e('Image File', 'one-user-avatar'); ?></option>
|
||||
<option value="attachment"><?php esc_html_e('Attachment Page','one-user-avatar'); ?></option>
|
||||
<option value="custom-url"><?php esc_html_e('Custom URL', 'one-user-avatar'); ?></option>
|
||||
</select>
|
||||
</p>
|
||||
|
||||
<p id="<?php echo esc_attr( 'wp_user_avatar_link_external_section' ); ?>">
|
||||
<label for="<?php echo esc_attr( 'wp_user_avatar_link_external' ); ?>"><?php esc_html_e( 'URL:', 'one-user-avatar' ); ?></label>
|
||||
|
||||
<input type="text" size="36" id="<?php echo esc_attr( 'wp_user_avatar_link_external' ); ?>" name="<?php echo esc_attr( 'wp_user_avatar_link_external' ); ?>" value="" />
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="<?php echo esc_attr( 'wp_user_avatar_target' ); ?>"></label>
|
||||
|
||||
<input type="checkbox" id="<?php echo esc_attr( 'wp_user_avatar_target' ); ?>" name="<?php echo esc_attr( 'wp_user_avatar_target' ); ?>" value="_blank" /> <strong><?php esc_html_e( 'Open link in a new window', 'one-user-avatar' ); ?></strong>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="<?php echo esc_attr( 'wp_user_avatar_caption' ); ?>"><strong><?php esc_html_e( 'Caption', 'one-user-avatar' ); ?>:</strong></label>
|
||||
|
||||
<textarea cols="36" rows="2" id="<?php echo esc_attr( 'wp_user_avatar_caption' ); ?>" name="<?php echo esc_attr( 'wp_user_avatar_size' ); ?>"></textarea>
|
||||
</p>
|
||||
|
||||
<div class="mceActionPanel">
|
||||
<input type="submit" id="insert" class="button-primary" name="insert" value="<?php esc_html_e( 'Insert into Post', 'one-user-avatar' ); ?>" onclick="wpuaInsertAvatar();" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="wpua-upload" style="display:none;">
|
||||
<p id="<?php echo esc_attr( 'wp_user_avatar_upload' ); ?>">
|
||||
<label for="<?php echo esc_attr( 'wp_user_avatar_upload' ); ?>"><strong><?php esc_html_e( 'Upload', 'one-user-avatar' ); ?>:</strong></label>
|
||||
|
||||
<input type="text" size="36" id="<?php echo esc_attr( 'wp_user_avatar_upload' ); ?>" name="<?php echo esc_attr( 'wp_user_avatar_upload' ); ?>" value="<?php echo esc_attr( '[avatar_upload]' ); ?>" readonly="readonly" />
|
||||
</p>
|
||||
|
||||
<div class="mceActionPanel">
|
||||
<input type="submit" id="insert" class="button-primary" name="insert" value="<?php esc_html_e( 'Insert into Post', 'one-user-avatar' ); ?>" onclick="wpuaInsertAvatarUpload();" />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/**
|
||||
* TinyMCE button for Visual Editor.
|
||||
*
|
||||
* @package One User Avatar
|
||||
* @author Bangbay Siboliban
|
||||
* @author Flippercode
|
||||
* @author ProfilePress
|
||||
* @author One Designs
|
||||
* @copyright 2013-2014 Bangbay Siboliban
|
||||
* @copyright 2014-2020 Flippercode
|
||||
* @copyright 2020-2021 ProfilePress
|
||||
* @copyright 2021 One Designs
|
||||
* @version 2.3.9
|
||||
*/
|
||||
|
||||
/**
|
||||
* Add TinyMCE button
|
||||
* @since 1.9.5
|
||||
* @uses add_filter()
|
||||
* @uses get_user_option()
|
||||
*/
|
||||
function wpua_add_buttons() {
|
||||
// Add only in Rich Editor mode
|
||||
if ( 'true' == get_user_option( 'rich_editing' ) ) {
|
||||
add_filter( 'mce_external_plugins', 'wpua_add_tinymce_plugin' );
|
||||
add_filter( 'mce_buttons', 'wpua_register_button' );
|
||||
}
|
||||
}
|
||||
add_action( 'init', 'wpua_add_buttons' );
|
||||
|
||||
/**
|
||||
* Register TinyMCE button
|
||||
* @since 1.9.5
|
||||
* @param array $buttons
|
||||
* @return array
|
||||
*/
|
||||
function wpua_register_button( $buttons ) {
|
||||
array_push( $buttons, 'separator', 'wpUserAvatar' );
|
||||
|
||||
return $buttons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load TinyMCE plugin
|
||||
* @since 1.9.5
|
||||
* @param array $plugin_array
|
||||
* @return array
|
||||
*/
|
||||
function wpua_add_tinymce_plugin( $plugins ) {
|
||||
$plugins['wpUserAvatar'] = WPUA_JS_URL . 'tinymce-editor_plugin.js';
|
||||
|
||||
return $plugins;
|
||||
}
|
||||
|
||||
function wpua_tinymce_enqueue_scripts( $hook_suffix ) {
|
||||
switch ( $hook_suffix ) {
|
||||
case 'one-user-avatar_tinymce-window':
|
||||
wp_enqueue_style( 'one-user-avatar-tinymce-window', WPUA_CSS_URL . 'tinymce-window.css' );
|
||||
|
||||
wp_enqueue_script( 'jquery' );
|
||||
wp_enqueue_script( 'one-user-avatar-tinymce-popup', includes_url( 'js/tinymce/tiny_mce_popup.js' ) );
|
||||
wp_enqueue_script( 'one-user-avatar-tinymce-form-utils', includes_url( 'js/tinymce/utils/form_utils.js' ) );
|
||||
wp_enqueue_script( 'one-user-avatar-tinymce-window', WPUA_JS_URL . 'tinymce-window.js' );
|
||||
|
||||
break;
|
||||
|
||||
case 'post.php':
|
||||
wp_localize_script( 'editor', 'one_user_avatar_tinymce_editor_args', array(
|
||||
'insert_avatar' => __( 'Insert Avatar', 'one-user-avatar' ),
|
||||
) );
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
add_action( 'admin_enqueue_scripts', 'wpua_tinymce_enqueue_scripts' );
|
||||
|
||||
/**
|
||||
* Call TinyMCE window content via admin-ajax
|
||||
* @since 1.4
|
||||
*/
|
||||
function wpua_ajax_tinymce() {
|
||||
include_once( WPUA_INC . 'wpua-tinymce-window.php' );
|
||||
|
||||
die();
|
||||
}
|
||||
add_action( 'wp_ajax_wp_user_avatar_tinymce', 'wpua_ajax_tinymce' );
|
Reference in New Issue
Block a user