Plugin Directory

Changeset 1257235


Ignore:
Timestamp:
10/01/2015 08:45:33 AM (10 years ago)
Author:
aruljayarajs
Message:

Added pp_picture function

Location:
profile-picture
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • profile-picture/tags/1.0/class/class_pp.php

    r1250822 r1257235  
    9898        return $avatar;
    9999    }
     100   
     101    // Get the Profile Picture details
     102    public function pp_picture($id_or_email, $width='', $height='', $alt=''){
     103        $user = $avatar = false;
     104       
     105        if ( is_numeric( $id_or_email ) ) {
     106   
     107            $id = (int) $id_or_email;
     108            $user = get_user_by( 'id' , $id );
     109   
     110        } elseif ( is_object( $id_or_email ) ) {
     111   
     112            if ( ! empty( $id_or_email->user_id ) ) {
     113                $id = (int) $id_or_email->user_id;
     114                $user = get_user_by( 'id' , $id );
     115            }
     116   
     117        } else {           
     118            $user = get_user_by( 'email', $id_or_email );   
     119        }
     120       
     121        if ( $user && is_object( $user ) ) {
     122            $upload_dir = wp_upload_dir();
     123            $pp_url = get_user_meta($user->ID, 'pp_url', true);         
     124               
     125            if (isset($pp_url) && !empty($pp_url)) {
     126                if( !empty( $width ) && !empty( $height ) ){
     127                    $imgclass = ' avatar-'.$width.'x'.$height;
     128                }               
     129                $avatar['url'] = $upload_dir['baseurl'].$pp_url;
     130                $avatar['img'] = "<img alt='{$alt}' src='{$avatar['url']}' class='avatar photo{$imgclass}' height='{$height}' width='{$width}' />";                             
     131            }else{
     132                if( !empty( $width ) ){
     133                    $width = 150;   
     134                }                   
     135                if( ProfilePicture::is_version( '4.2' ) ){  // If WP version greater than 4.2
     136                    $args = get_avatar_data( $curauth->ID, $args=null );                                   
     137                    $avatar['url'] = $args['url'];             
     138                }else{  // If WP version less than 4.2
     139                    preg_match("/src='(.*?)'/i", get_avatar( $curauth->ID, $width ), $matches);                     
     140                    $avatar['url'] = $matches[1];
     141                }
     142                $avatar['img'] = get_avatar($user->ID);                             
     143            }
     144            $avatar['author_name'] = get_the_author();
     145            $avatar['author_url'] = get_author_posts_url( $user->ID );
     146   
     147        }       
     148        return $avatar;
     149    }
     150   
     151    # Check Version Support
     152    public function is_version( $version ) {
     153        global $wp_version;     
     154        if ( version_compare( $wp_version, $version, '>=' ) ) {
     155            return true;
     156        }
     157        return false;
     158    }
     159   
     160   
    100161
    101162}
  • profile-picture/tags/1.0/profile-picture.php

    r1251703 r1257235  
    55* Author: Arul Jayaraj
    66* Author URI: http://www.aruljayaraj.com
    7 * Description: Upload and set user's custom profile picture in your local, and allow user permission(Subscriber, Contributor) based on your needs
     7* Description: Upload and set user's custom profile picture in your local, and you may have options to allow (like Subscriber, Contributor) to upload their profile picture based on user permission
    88**/
    99if (!defined('WP_CONTENT_URL')){
  • profile-picture/tags/1.0/readme.txt

    r1251703 r1257235  
    1 === Plugin Name ===
     1=== Profile Picture ===
    22Contributors: aruljayarajs
    3 Tags: user profile, custom profile photo, profile picture, custom profile picture, profile photo
     3Tags: user profile picture, custom profile picture, user photo, profile picture, profile photo, user avatar, user profile
    44Requires at least: 3.0
    55Tested up to: 4.3.1
     
    1919In Front End when we use `<?php do_action('edit_user_profile',$current_user); ?>` on edit profile section, it would be placed on additonal user profile fields.
    2020
    21 *Future Updates: Display current user images alone, short code and bring up social media profile pictures.
     21*Future Updates: Display current user images alone, short code and migrate withsocial media profile pictures.
    2222
    2323== Installation ==
     
    25251. Upload `profile-picture` folder to the `/wp-content/plugins/` directory
    26262. Activate the plugin through the 'Plugins' menu in WordPress
    27 3. Go to Profile in admin end / Go to profile edit in front end
     273. Go to Profile in admin end / Go to profile edit in front end  
    2828
    2929Note: If you want to add this feature to default scbscribers and contributors, Enable this action hook `<?php add_action('admin_init', array($this,'allow_uploads_permission') ); ?>` from the `ProfilePicture` class.
     
    4040= How to show the profile image in frontend? =
    4141
    42 We can show our customized profile picture in front end whereever you want with registered image sizes.
     42We can show our customized profile picture in front end whereever you want with registered image sizes. You may use wordpress <strong>get_avatar() function by default, else user our customized one it serves by your wish.</strong>.
    4343`<?php
    44 $upload_dir = wp_upload_dir();
    45 $pp_url = get_user_meta($user->ID, 'pp_url', true);
    46 echo $upload_dir['baseurl'].$pp_url;
     44$ppimg = ProfilePicture::pp_picture($id_or_email, $width, $height, $alt);
    4745?>`
     46<strong> id_or_email </strong>
     47<strong> width </strong> (integer) (optional) Width of the image.
     48<strong> height </strong> (integer) (optional) Width of the image.
     49<strong> alt </strong> (string) (optional) alt title of image tag.
     50<strong> Return Values </strong> It would return profile picture details as array or false on failure.
    4851
    4952== Screenshots ==
  • profile-picture/trunk/class/class_pp.php

    r1250822 r1257235  
    9898        return $avatar;
    9999    }
     100   
     101    // Get the Profile Picture details
     102    public function pp_picture($id_or_email, $width='', $height='', $alt=''){
     103        $user = $avatar = false;
     104       
     105        if ( is_numeric( $id_or_email ) ) {
     106   
     107            $id = (int) $id_or_email;
     108            $user = get_user_by( 'id' , $id );
     109   
     110        } elseif ( is_object( $id_or_email ) ) {
     111   
     112            if ( ! empty( $id_or_email->user_id ) ) {
     113                $id = (int) $id_or_email->user_id;
     114                $user = get_user_by( 'id' , $id );
     115            }
     116   
     117        } else {           
     118            $user = get_user_by( 'email', $id_or_email );   
     119        }
     120       
     121        if ( $user && is_object( $user ) ) {
     122            $upload_dir = wp_upload_dir();
     123            $pp_url = get_user_meta($user->ID, 'pp_url', true);         
     124               
     125            if (isset($pp_url) && !empty($pp_url)) {
     126                if( !empty( $width ) && !empty( $height ) ){
     127                    $imgclass = ' avatar-'.$width.'x'.$height;
     128                }               
     129                $avatar['url'] = $upload_dir['baseurl'].$pp_url;
     130                $avatar['img'] = "<img alt='{$alt}' src='{$avatar['url']}' class='avatar photo{$imgclass}' height='{$height}' width='{$width}' />";                             
     131            }else{
     132                if( !empty( $width ) ){
     133                    $width = 150;   
     134                }                   
     135                if( ProfilePicture::is_version( '4.2' ) ){  // If WP version greater than 4.2
     136                    $args = get_avatar_data( $curauth->ID, $args=null );                                   
     137                    $avatar['url'] = $args['url'];             
     138                }else{  // If WP version less than 4.2
     139                    preg_match("/src='(.*?)'/i", get_avatar( $curauth->ID, $width ), $matches);                     
     140                    $avatar['url'] = $matches[1];
     141                }
     142                $avatar['img'] = get_avatar($user->ID);                             
     143            }
     144            $avatar['author_name'] = get_the_author();
     145            $avatar['author_url'] = get_author_posts_url( $user->ID );
     146   
     147        }       
     148        return $avatar;
     149    }
     150   
     151    # Check Version Support
     152    public function is_version( $version ) {
     153        global $wp_version;     
     154        if ( version_compare( $wp_version, $version, '>=' ) ) {
     155            return true;
     156        }
     157        return false;
     158    }
    100159
    101160
  • profile-picture/trunk/profile-picture.php

    r1250037 r1257235  
    55* Author: Arul Jayaraj
    66* Author URI: http://www.aruljayaraj.com
    7 * Description: Upload and set user's custom profile picture in your local, and allow user permission(Subscriber, Contributor) based on your needs
     7* Description: Upload and set user's custom profile picture in your local, and you may have options to allow (like Subscriber, Contributor) to upload their profile picture based on user permission
    88**/
    99if (!defined('WP_CONTENT_URL')){
  • profile-picture/trunk/readme.txt

    r1251703 r1257235  
    1 === Plugin Name ===
     1=== Profile Picture ===
    22Contributors: aruljayarajs
    3 Tags: user profile, custom profile photo, profile picture, custom profile picture, profile photo
     3Tags: user profile picture, custom profile picture, user photo, profile picture, profile photo, user avatar, user profile
    44Requires at least: 3.0
    55Tested up to: 4.3.1
     
    1919In Front End when we use `<?php do_action('edit_user_profile',$current_user); ?>` on edit profile section, it would be placed on additonal user profile fields.
    2020
    21 *Future Updates: Display current user images alone, short code and bring up social media profile pictures.
     21*Future Updates: Display current user images alone, short code and migrate withsocial media profile pictures.
    2222
    2323== Installation ==
     
    25251. Upload `profile-picture` folder to the `/wp-content/plugins/` directory
    26262. Activate the plugin through the 'Plugins' menu in WordPress
    27 3. Go to Profile in admin end / Go to profile edit in front end
     273. Go to Profile in admin end / Go to profile edit in front end  
    2828
    2929Note: If you want to add this feature to default scbscribers and contributors, Enable this action hook `<?php add_action('admin_init', array($this,'allow_uploads_permission') ); ?>` from the `ProfilePicture` class.
     
    4040= How to show the profile image in frontend? =
    4141
    42 We can show our customized profile picture in front end whereever you want with registered image sizes.
     42We can show our customized profile picture in front end whereever you want with registered image sizes. You may use wordpress <strong>get_avatar() function by default, else user our customized one it serves by your wish.</strong>.
    4343`<?php
    44 $upload_dir = wp_upload_dir();
    45 $pp_url = get_user_meta($user->ID, 'pp_url', true);
    46 echo $upload_dir['baseurl'].$pp_url;
     44$ppimg = ProfilePicture::pp_picture($id_or_email, $width, $height, $alt);
    4745?>`
     46<strong> id_or_email </strong>
     47<strong> width </strong> (integer) (optional) Width of the image.
     48<strong> height </strong> (integer) (optional) Width of the image.
     49<strong> alt </strong> (string) (optional) alt title of image tag.
     50<strong> Return Values </strong> It would return profile picture details as array or false on failure.
    4851
    4952== Screenshots ==
Note: See TracChangeset for help on using the changeset viewer.