-
-
Save MaryOJob/4d89e88c70a7706a1518dd143afa3f21 to your computer and use it in GitHub Desktop.
PMPro - Local Avatar on the Front-end and Not in the Back-end
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Shows local avatar on the front-end and doesn't allow on in the admin. | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function enqueue_media_uploader() { | |
wp_enqueue_media(); | |
} | |
add_action( 'wp_enqueue_scripts', 'enqueue_media_uploader' ); | |
function pmpro_simple_local_avatar_personal_options_update( $current_user ) { | |
if ( ! function_exists( 'media_handle_upload' ) ) { | |
require_once( ABSPATH . 'wp-admin/includes/image.php' ); | |
require_once( ABSPATH . 'wp-admin/includes/file.php' ); | |
require_once( ABSPATH . 'wp-admin/includes/media.php' ); | |
} | |
} | |
add_action( 'pmpro_personal_options_update', 'pmpro_simple_local_avatar_personal_options_update' ); | |
function pmpro_add_simple_local_avatars() { | |
if ( class_exists( 'simple_local_avatars' ) && ! is_admin() ) { | |
$my_avatar = new simple_local_avatars(); | |
add_action( 'pmpro_show_user_profile', array( $my_avatar, 'edit_user_profile' ) ); | |
add_action( 'pmpro_show_user_profile', 'pmpro_change_form_type', 11 ); | |
add_action( 'pmpro_personal_options_update', array( $my_avatar, 'edit_user_profile_update' ) ); | |
} | |
} | |
add_action( 'init', 'pmpro_add_simple_local_avatars' ); | |
function pmpro_change_form_type() { ?> | |
<script> | |
jQuery('#member-profile-edit').attr("enctype","multipart/form-data"); | |
</script> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment