Version Description
- Adding REST API endpoint
Download this release
Release Info
Developer | ronalfy |
Plugin | User Profile Picture |
Version | 1.3.0 |
Comparing to | |
See all releases |
Code changes from version 1.2.7 to 1.3.0
- metronet-profile-picture.php +72 -1
- readme.txt +18 -2
metronet-profile-picture.php
CHANGED
@@ -4,7 +4,7 @@ Plugin Name: User Profile Picture
|
|
4 |
Plugin URI: http://wordpress.org/extend/plugins/metronet-profile-picture/
|
5 |
Description: Use the native WP uploader on your user profile page.
|
6 |
Author: ronalfy
|
7 |
-
Version: 1.
|
8 |
Requires at least: 3.5
|
9 |
Author URI: http://www.ronalfy.com
|
10 |
Contributors: ronalfy
|
@@ -60,6 +60,9 @@ class Metronet_Profile_Picture {
|
|
60 |
|
61 |
//User Avatar override
|
62 |
add_filter( 'get_avatar', array( &$this, 'avatar_override' ), 10, 6 );
|
|
|
|
|
|
|
63 |
} //end constructor
|
64 |
|
65 |
/**
|
@@ -472,6 +475,74 @@ class Metronet_Profile_Picture {
|
|
472 |
public function print_media_styles() {
|
473 |
} //end print_media_styles
|
474 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
475 |
/**
|
476 |
* save_user_profile()
|
477 |
*
|
4 |
Plugin URI: http://wordpress.org/extend/plugins/metronet-profile-picture/
|
5 |
Description: Use the native WP uploader on your user profile page.
|
6 |
Author: ronalfy
|
7 |
+
Version: 1.3.0
|
8 |
Requires at least: 3.5
|
9 |
Author URI: http://www.ronalfy.com
|
10 |
Contributors: ronalfy
|
60 |
|
61 |
//User Avatar override
|
62 |
add_filter( 'get_avatar', array( &$this, 'avatar_override' ), 10, 6 );
|
63 |
+
|
64 |
+
//Rest API
|
65 |
+
add_action( 'rest_api_init', array( $this, 'rest_api_register' ) );
|
66 |
} //end constructor
|
67 |
|
68 |
/**
|
475 |
public function print_media_styles() {
|
476 |
} //end print_media_styles
|
477 |
|
478 |
+
/**
|
479 |
+
* rest_api_register()
|
480 |
+
*
|
481 |
+
* Registers REST API endpoint
|
482 |
+
**/
|
483 |
+
public function rest_api_register() {
|
484 |
+
register_rest_route(
|
485 |
+
'mpp/v1',
|
486 |
+
'/user/(?P<id>\d+)',
|
487 |
+
array(
|
488 |
+
'methods' => 'GET',
|
489 |
+
'callback' => array( $this, 'rest_api_get_profile' ),
|
490 |
+
'args' => array(
|
491 |
+
'id' => array(
|
492 |
+
'validate_callback' => array( $this, 'rest_api_validate' ),
|
493 |
+
'sanitize_callback' => array( $this, 'rest_api_sanitize' ),
|
494 |
+
)
|
495 |
+
)
|
496 |
+
)
|
497 |
+
);
|
498 |
+
}
|
499 |
+
|
500 |
+
/**
|
501 |
+
* rest_api_get_profile()
|
502 |
+
*
|
503 |
+
* Returns an attachment image ID and profile image if available
|
504 |
+
**/
|
505 |
+
public function rest_api_get_profile( $data ) {
|
506 |
+
$user_id = $data[ 'id' ];
|
507 |
+
$user = get_user_by( 'id', $user_id );
|
508 |
+
if ( ! $user ) {
|
509 |
+
return new WP_Error( 'mpp_no_user', __( 'User not found.', 'metronet-profile-picture' ), array( 'status' => 404 ) );
|
510 |
+
}
|
511 |
+
|
512 |
+
//Get attachment ID
|
513 |
+
$profile_post_id = absint( get_user_option( 'metronet_post_id', $user_id ) );
|
514 |
+
$post_thumbnail_id = get_post_thumbnail_id( $profile_post_id );
|
515 |
+
if ( ! $post_thumbnail_id ) {
|
516 |
+
return new WP_Error( 'mpp_no_profile_picture', __( 'Profile picture not found.', 'metronet-profile-picture' ), array( 'status' => 404 ) );
|
517 |
+
}
|
518 |
+
|
519 |
+
//Get attachment URL
|
520 |
+
$attachment_url = wp_get_attachment_url( $post_thumbnail_id );
|
521 |
+
|
522 |
+
return array(
|
523 |
+
'attachment_id' => $post_thumbnail_id,
|
524 |
+
'attachment_url' => $attachment_url
|
525 |
+
);
|
526 |
+
}
|
527 |
+
|
528 |
+
/**
|
529 |
+
* rest_api_validate()
|
530 |
+
*
|
531 |
+
* Makes sure the ID we are passed is numeric
|
532 |
+
**/
|
533 |
+
public function rest_api_validate( $param, $request, $key ) {
|
534 |
+
return is_numeric( $param );
|
535 |
+
}
|
536 |
+
|
537 |
+
/**
|
538 |
+
* rest_api_validate()
|
539 |
+
*
|
540 |
+
* Sanitizes user ID
|
541 |
+
**/
|
542 |
+
public function rest_api_sanitize( $param, $request, $key ) {
|
543 |
+
return absint( $param );
|
544 |
+
}
|
545 |
+
|
546 |
/**
|
547 |
* save_user_profile()
|
548 |
*
|
readme.txt
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
Contributors: ronalfy
|
3 |
Tags: users, user, user profile
|
4 |
Requires at least: 3.5
|
5 |
-
Tested up to: 4.
|
6 |
-
Stable tag: 1.
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
@@ -73,6 +73,16 @@ If you want the "Override Avatar" checkbox to be checked by default, drop this i
|
|
73 |
If you want to hide the "Override Avatar" checkbox, use this filter (the override functionality will be enabled by default):
|
74 |
`add_filter( 'mpp_hide_avatar_override', '__return_true' );`
|
75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
== Frequently Asked Questions ==
|
77 |
|
78 |
= How do you set a user profile image? =
|
@@ -105,6 +115,9 @@ Yes, but you'll have to set a new profile image per site. This is currently a l
|
|
105 |
|
106 |
== Changelog ==
|
107 |
|
|
|
|
|
|
|
108 |
= 1.2.7 =
|
109 |
* Updated 20 August 2015 for WP 4.3 compatibility
|
110 |
* Released 10 June 2015
|
@@ -196,6 +209,9 @@ Yes, but you'll have to set a new profile image per site. This is currently a l
|
|
196 |
|
197 |
== Upgrade Notice ==
|
198 |
|
|
|
|
|
|
|
199 |
= 1.2.7 =
|
200 |
Bug fix for warning message saying missing argument for avatar_override.
|
201 |
|
2 |
Contributors: ronalfy
|
3 |
Tags: users, user, user profile
|
4 |
Requires at least: 3.5
|
5 |
+
Tested up to: 4.5
|
6 |
+
Stable tag: 1.3.0
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
73 |
If you want to hide the "Override Avatar" checkbox, use this filter (the override functionality will be enabled by default):
|
74 |
`add_filter( 'mpp_hide_avatar_override', '__return_true' );`
|
75 |
|
76 |
+
The REST API is currently supported for versions of WordPress 4.4 and up.
|
77 |
+
|
78 |
+
The endpoint is: `http://www.yourdomain.com/wp-json/mpp/v1/user/{user_id}`
|
79 |
+
|
80 |
+
If a profile picture is found, it'll return JSON as follows:
|
81 |
+
|
82 |
+
`
|
83 |
+
{"attachment_id":"3638","attachment_url":"http:\/\/localhost\/ronalfy\/wp-content\/uploads\/2015\/12\/Leaderboard-All-Time.png"}
|
84 |
+
`
|
85 |
+
|
86 |
== Frequently Asked Questions ==
|
87 |
|
88 |
= How do you set a user profile image? =
|
115 |
|
116 |
== Changelog ==
|
117 |
|
118 |
+
= 1.3.0 =
|
119 |
+
* Adding REST API endpoint
|
120 |
+
|
121 |
= 1.2.7 =
|
122 |
* Updated 20 August 2015 for WP 4.3 compatibility
|
123 |
* Released 10 June 2015
|
209 |
|
210 |
== Upgrade Notice ==
|
211 |
|
212 |
+
= 1.3.0 =
|
213 |
+
Adding REST API endpoint.
|
214 |
+
|
215 |
= 1.2.7 =
|
216 |
Bug fix for warning message saying missing argument for avatar_override.
|
217 |
|