notices_enabled_pages ) ) { // Admin scripts add_action( 'admin_enqueue_scripts', [ $this, 'custom_admin_enqueue_scripts' ] ); // HTML render of notices add_action( 'admin_notices', [ $this, 'render_admin_error_notices' ] ); add_action( 'admin_notices', [ $this, 'render_admin_donation_notice' ] ); } } public static function init() { new self; } /** * Load CSS and JavaScript for wp-admin * * @since 1.0 * @return void */ public function custom_admin_enqueue_scripts() { // Get current user global $current_user; // Enqueue WordPress Media Library wp_enqueue_media(); // CSS for wp-admin wp_enqueue_style( 'sua', plugins_url( '/css/style.css', __FILE__ ), [], SUA_PLUGIN_VERSION, 'all' ); // JavaScript for wp-admin wp_enqueue_script( 'sua', plugins_url( '/js/scripts.js', __FILE__ ), [ 'jquery' ], SUA_PLUGIN_VERSION, true ); // Get default avatar URL by user_email $l10n = [ 'default_avatar_src' => $this->get_default_avatar_url_by_email( $current_user->user_email, $this->avatar_size ), 'default_avatar_srcset' => $this->get_default_avatar_url_by_email( $current_user->user_email, ( $this->avatar_size * 2 ) ) . ' 2x', 'input_name' => SUA_USER_META_KEY ]; wp_localize_script( 'sua', 'sua_obj', $l10n ); } /** * Default WordPress avatar URL by user email * * @since 2.8 * @return string */ private function get_default_avatar_url_by_email( $user_email = '', $size = 96 ) { // Check the email provided if ( empty($user_email) || !filter_var($user_email, FILTER_VALIDATE_EMAIL) ) { return null; } // Sanitize email and get md5 $user_email = sanitize_email( $user_email ); $md5_user_email = md5( $user_email ); // SSL Gravatar URL $url = 'https://secure.gravatar.com/avatar/' . $md5_user_email; // Add query args $url = add_query_arg( 's', $size, $url ); $url = add_query_arg( 'd', 'mm', $url ); $url = add_query_arg( 'r', 'g', $url ); return esc_url( $url ); } /** * Add table in user profile * * @since 1.0 * @return void */ public function render_custom_user_profile_fields( $user ) { // Get user meta $attachment_id = get_user_meta( $user->ID, SUA_USER_META_KEY, true ); ?> delete( $wpdb->usermeta, [ 'meta_key' => SUA_USER_META_KEY, 'meta_value' => (int)$post_id ], [ '%s', '%d' ] ); } /** * Admin notices for errors * * @since 3.9 * @return void */ public function render_admin_error_notices() { // Check if there is a GET error if ( isset( $_GET['error'] ) ) { // Notice error container $notice_error_container = '
%s
'; // Switch errors switch( $_GET['error'] ) { // Transient not saved case 'sua_transient_not_set': printf( $notice_error_container, sprintf( __( '

An error occurred while saving the transient. Please make sure this website can save transients.

', 'simple-user-avatar' ), esc_url( $this->reference_public_permalink ) ) ); break; } } } /** * Admin notice for donations, if transient not exists or is expired * * @since 2.6 * @return void */ public function render_admin_donation_notice() { // Get Current user global $current_user; // Get the transient $notice_is_expired = get_transient( SUA_TRANSIENT_NAME ); // Check the return of transient, if it's okay empty return if ( $notice_is_expired !== false && is_numeric($notice_is_expired) && $notice_is_expired == 1 ) { return; } // Set the nonce field $wp_nonce_field = wp_nonce_field( SUA_TRANSIENT_NAME, '_wpnonce', true, false ); $wp_nonce_field = preg_replace( '/id=("|\').*?("|\')/', '', $wp_nonce_field ); ?>

%s,
thank you for using my plugin Simple User Avatar! To support the development, also in the future, I invite you to support me. Even a small amount, such as 1$ for one coffee ☕, will be greatly appreciated.
Best regards, Matteo.', 'simple-user-avatar' ), sanitize_text_field( $current_user->display_name ), esc_url( $this->plugin_public_permalink ) ); ?>

notice_months_expiration; // Set the transient but, if an error has occurred, add query arg at redirect URL if ( set_transient( $transient, $value, $expiration ) === false ) { $redirect_url = add_query_arg( 'error', 'sua_transient_not_set', $redirect_url ); } } // Safe redirect if ( wp_safe_redirect( esc_url( $redirect_url ) ) ) { exit; } } } add_action( 'plugins_loaded', [ 'SimpleUserAvatar_Admin', 'init' ] ); }