├── LICENSE ├── README.md ├── css ├── jquery.ui.slider.css └── wp-user-avatar.css ├── custom-user-avatar.php ├── images ├── wpua-150x150.png ├── wpua-20x20.png ├── wpua-300x300.png ├── wpua-32x32.png ├── wpua-96x96.png ├── wpua-icon.png └── wpua.png ├── includes ├── class-wp-user-avatar-admin.php ├── class-wp-user-avatar-functions.php ├── class-wp-user-avatar-list-table.php ├── class-wp-user-avatar-resource-manager.php ├── class-wp-user-avatar-shortcode.php ├── class-wp-user-avatar-subscriber.php ├── class-wp-user-avatar-update.php ├── class-wp-user-avatar-widget.php ├── class-wp-user-avatar.php ├── tinymce │ ├── editor_plugin.js │ └── window.php ├── wpua-functions.php ├── wpua-globals.php ├── wpua-media-page.php ├── wpua-options-page.php └── wpua-tinymce.php ├── js ├── wp-user-avatar-admin.js ├── wp-user-avatar-user.js └── wp-user-avatar.js ├── readme.txt └── uninstall.php /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Custom User Avatar 2 | 3 | WordPress currently only allows you to use custom avatars that are uploaded through [Gravatar](http://gravatar.com/). Custom User Avatar enables you to use any photo uploaded into your Media Library as an avatar. This means you use the same uploader and library as your posts. No extra folders or image editing functions are necessary. 4 | 5 | **This is a fork of the popular WP User Avatar plugin, before it became ProfilePress, and is free of all advertising.** 6 | 7 | ## Why this was forked from WP User Avatar and what is different? ## 8 | 9 | The original WP User Avatar, popular amongst users wishing to simple manager their site avatars, was renamed to ProfilePress at version 3.0 and made into a full membership plugin. A lot of users, however, didn't want the new functionality. On top of this, some people reported increasing errors and decreasing site speed as a result. Indeed, the resulting up-roar even made [WP Tavern](https://wptavern.com/profilepress-rebrands-and-repurposes-wp-user-avatar-now-a-membership-plugin-users-revolt-via-the-wordpress-review-system). 10 | 11 | This, therefore, is a fork of the plugin before all that occurred, at version 2.2.16. 12 | 13 | What has changed from that? Apart from renaming it, all advertising has been removed (and will remain removed), along with some redundant files. It also now uses the automatic translation service which comes as being part of the plugin directory. Other than that, a few minor tweaks have been made, but nothing you are likely to (yet) notice. 14 | 15 | What has been retained is the old naming of functions and settings - what this means is that if you used WP User Avatar before, your existing configuration will automatically work with this plugin as well. Shortcodes and functions calls too remain exactly the same too. 16 | 17 | ## What are the future plans for this plugin? ## 18 | 19 | Please see the [Github issues page](https://github.com/dartiss/custom-user-avatar/issues "Github") for full details, but essentially... 20 | 21 | * Tidy up the existing code, including code quality 22 | * Compression of the plugin scripts 23 | * Improving the images being used by the plugin 24 | 25 | If you're aware of any bugs, please let me know, as I also want to get rid of many of those as possible. 26 | 27 | What you may notice is a lack of new features - that's not to say that won't happen, but I want to ensure stability. Let's improve the robustness of the code and consider new, shiny things after that. 28 | 29 |

 

-------------------------------------------------------------------------------- /css/wp-user-avatar.css: -------------------------------------------------------------------------------- 1 | #wpua-errors, #wpua-readable-size-error, .wpua-error { color: #c00 !important; font-weight: 700 !important; } 2 | #wpua-readable-size-error, #wpua-undo-button { display: none; } 3 | #wpua-preview, #wpua-preview-existing { margin-right: 10px; } 4 | #wpua-preview, #wpua-preview-existing, #wpua-thumbnail, #wpua-thumbnail-existing { display: inline-block; text-align: center; vertical-align: top; } 5 | #wpua-preview img, #wpua-thumbnail img, #wpua-preview-existing img, #wpua-thumbnail-existing img { max-height: 96px; border: 1px solid #dfdfdf; display: block; } 6 | .widget_wp_user_avatar #wpua-preview img, .widget_wp_user_avatar #wpua-thumbnail img, .widget_wp_user_avatar #wpua-preview-existing img, .widget_wp_user_avatar #wpua-thumbnail-existing img { max-height: 64px; } 7 | .defaultavatarpicker #wpua-preview, .defaultavatarpicker #wpua-preview-existing { width: 32px; height: 32px; margin-right: 0; display: inline-block; overflow: hidden; vertical-align: middle; } 8 | .defaultavatarpicker #wpua-preview img , .defaultavatarpicker #wpua-preview-existing img { width: 32px; height: auto; border: 0; } 9 | #wpua-edit #wpua-remove, #wpua-edit #wpua-undo, #wpua-edit-attachment { margin-left: 10px !important; } 10 | #wpua-slider { width: 22.75em; } 11 | #wpua-upload-messages span { display: block; } 12 | .wpua-hide { display: none !important; } 13 | .wpua-no-avatars { display: none; } 14 | -------------------------------------------------------------------------------- /custom-user-avatar.php: -------------------------------------------------------------------------------- 1 | _define_constants(); 41 | $this->_load_wp_includes(); 42 | $this->_load_wpua(); 43 | } 44 | 45 | /** 46 | * Define paths 47 | */ 48 | private function _define_constants() { 49 | define('WPUA_VERSION', '2.2.16'); 50 | define('WPUA_FOLDER', basename(dirname(__FILE__))); 51 | define('WPUA_DIR', plugin_dir_path(__FILE__)); 52 | define('WPUA_INC', WPUA_DIR.'includes'.'/'); 53 | define('WPUA_URL', plugin_dir_url(WPUA_FOLDER).WPUA_FOLDER.'/'); 54 | define('WPUA_INC_URL', WPUA_URL.'includes'.'/'); 55 | } 56 | 57 | /** 58 | * WordPress includes used in plugin 59 | * @uses is_admin() 60 | */ 61 | private function _load_wp_includes() { 62 | if(!is_admin()) { 63 | // wp_handle_upload 64 | require_once(ABSPATH.'wp-admin/includes/file.php'); 65 | // wp_generate_attachment_metadata 66 | require_once(ABSPATH.'wp-admin/includes/image.php'); 67 | // image_add_caption 68 | require_once(ABSPATH.'wp-admin/includes/media.php'); 69 | // submit_button 70 | require_once(ABSPATH.'wp-admin/includes/template.php'); 71 | } 72 | // add_screen_option 73 | require_once(ABSPATH.'wp-admin/includes/screen.php'); 74 | } 75 | 76 | /** 77 | * Load Custom User Avatar 78 | * @uses bool $wpua_tinymce 79 | * @uses is_admin() 80 | */ 81 | private function _load_wpua() { 82 | global $wpua_tinymce; 83 | require_once(WPUA_INC.'wpua-globals.php'); 84 | require_once(WPUA_INC.'wpua-functions.php'); 85 | require_once(WPUA_INC.'class-wp-user-avatar-admin.php'); 86 | require_once(WPUA_INC.'class-wp-user-avatar.php'); 87 | require_once(WPUA_INC.'class-wp-user-avatar-functions.php'); 88 | require_once(WPUA_INC.'class-wp-user-avatar-shortcode.php'); 89 | require_once(WPUA_INC.'class-wp-user-avatar-subscriber.php'); 90 | require_once(WPUA_INC.'class-wp-user-avatar-update.php'); 91 | require_once(WPUA_INC.'class-wp-user-avatar-widget.php'); 92 | 93 | // Load TinyMCE only if enabled 94 | if((bool) $wpua_tinymce == 1) { 95 | require_once(WPUA_INC.'wpua-tinymce.php'); 96 | } 97 | 98 | } 99 | } 100 | 101 | /** 102 | * Initialize 103 | */ 104 | new WP_User_Avatar_Setup(); 105 | -------------------------------------------------------------------------------- /images/wpua-150x150.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dartiss/custom-user-avatar/6e40c4fb150dd92d7c8edb41f6fe828b125452a0/images/wpua-150x150.png -------------------------------------------------------------------------------- /images/wpua-20x20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dartiss/custom-user-avatar/6e40c4fb150dd92d7c8edb41f6fe828b125452a0/images/wpua-20x20.png -------------------------------------------------------------------------------- /images/wpua-300x300.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dartiss/custom-user-avatar/6e40c4fb150dd92d7c8edb41f6fe828b125452a0/images/wpua-300x300.png -------------------------------------------------------------------------------- /images/wpua-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dartiss/custom-user-avatar/6e40c4fb150dd92d7c8edb41f6fe828b125452a0/images/wpua-32x32.png -------------------------------------------------------------------------------- /images/wpua-96x96.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dartiss/custom-user-avatar/6e40c4fb150dd92d7c8edb41f6fe828b125452a0/images/wpua-96x96.png -------------------------------------------------------------------------------- /images/wpua-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dartiss/custom-user-avatar/6e40c4fb150dd92d7c8edb41f6fe828b125452a0/images/wpua-icon.png -------------------------------------------------------------------------------- /images/wpua.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dartiss/custom-user-avatar/6e40c4fb150dd92d7c8edb41f6fe828b125452a0/images/wpua.png -------------------------------------------------------------------------------- /includes/class-wp-user-avatar-admin.php: -------------------------------------------------------------------------------- 1 | $value) 67 | { 68 | if(is_array($value)) 69 | { 70 | if(array_key_exists('wpua_has_gravatar_cron_hook',$value)) 71 | unset($cron[$key]); 72 | } 73 | } 74 | update_option('cron',$cron); 75 | } 76 | 77 | 78 | 79 | } 80 | 81 | /** 82 | * On deactivation 83 | * @uses int $blog_id 84 | * @uses object $wpdb 85 | * @uses get_blog_prefix() 86 | * @uses get_option() 87 | * @uses update_option() 88 | */ 89 | public function wpua_deactivate() { 90 | global $blog_id, $wpdb; 91 | $wp_user_roles = $wpdb->get_blog_prefix($blog_id).'user_roles'; 92 | // Get user roles and capabilities 93 | $user_roles = get_option($wp_user_roles); 94 | // Remove subscribers edit_posts capability 95 | unset($user_roles['subscriber']['capabilities']['edit_posts']); 96 | update_option($wp_user_roles, $user_roles); 97 | // Reset all default avatars to Mystery Man 98 | update_option('avatar_default', 'mystery'); 99 | 100 | } 101 | 102 | /** 103 | * Add options page and settings 104 | * @uses add_menu_page() 105 | * @uses add_submenu_page() 106 | */ 107 | public function wpua_admin() { 108 | add_menu_page(__('Custom User Avatar', 'wp-user-avatar'), __('Avatars', 'wp-user-avatar'), 'manage_options', 'wp-user-avatar', array($this, 'wpua_options_page'), WPUA_URL.'images/wpua-icon.png'); 109 | add_submenu_page('wp-user-avatar', __('Settings' , 'wp-user-avatar'), __('Settings' , 'wp-user-avatar'), 'manage_options', 'wp-user-avatar', array($this, 'wpua_options_page')); 110 | $hook = add_submenu_page('wp-user-avatar', __('Library','wp-user-avatar'), __('Library', 'wp-user-avatar'), 'manage_options', 'wp-user-avatar-library', array($this, 'wpua_media_page')); 111 | add_action("load-$hook", array($this, 'wpua_media_screen_option')); 112 | add_filter('set-screen-option', array($this, 'wpua_set_media_screen_option'), 10, 3); 113 | } 114 | 115 | /** 116 | * Checks if current page is settings page 117 | * @uses string $pagenow 118 | * @return bool 119 | */ 120 | public function wpua_is_menu_page() { 121 | global $pagenow; 122 | $is_menu_page = ($pagenow == 'admin.php' && isset($_GET['page']) && $_GET['page'] == 'wp-user-avatar') ? true : false; 123 | return (bool) $is_menu_page; 124 | } 125 | 126 | /** 127 | * Media page 128 | */ 129 | public function wpua_media_page() { 130 | require_once(WPUA_INC.'wpua-media-page.php'); 131 | } 132 | 133 | /** 134 | * Avatars per page 135 | * @uses add_screen_option() 136 | */ 137 | public function wpua_media_screen_option() { 138 | $option = 'per_page'; 139 | $args = array( 140 | 'label' => __('Avatars','wp-user-avatar'), 141 | 'default' => 10, 142 | 'option' => 'upload_per_page' 143 | ); 144 | add_screen_option($option, $args); 145 | } 146 | 147 | /** 148 | * Save per page setting 149 | * @param int $status 150 | * @param string $option 151 | * @param int $value 152 | * @return int $status 153 | */ 154 | public function wpua_set_media_screen_option($status, $option, $value) { 155 | $status = ($option == 'upload_per_page') ? $value : $status; 156 | return $status; 157 | } 158 | 159 | /** 160 | * Options page 161 | */ 162 | public function wpua_options_page() { 163 | require_once(WPUA_INC.'wpua-options-page.php'); 164 | } 165 | 166 | /** 167 | * Whitelist settings 168 | * @uses apply_filters() 169 | * @uses register_setting() 170 | * @return array 171 | */ 172 | public function wpua_register_settings() { 173 | $settings = array(); 174 | $settings[] = register_setting('wpua-settings-group', 'avatar_rating'); 175 | $settings[] = register_setting('wpua-settings-group', 'avatar_default'); 176 | $settings[] = register_setting('wpua-settings-group', 'avatar_default_wp_user_avatar'); 177 | $settings[] = register_setting('wpua-settings-group', 'show_avatars', 'intval'); 178 | $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_tinymce', 'intval'); 179 | $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_allow_upload', 'intval'); 180 | $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_disable_gravatar', 'intval'); 181 | $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_edit_avatar', 'intval'); 182 | $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_resize_crop', 'intval'); 183 | $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_resize_h', 'intval'); 184 | $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_resize_upload', 'intval'); 185 | $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_resize_w', 'intval'); 186 | $settings[] = register_setting('wpua-settings-group', 'wp_user_avatar_upload_size_limit', 'intval'); 187 | /** 188 | * Filter admin whitelist settings 189 | * @param array $settings 190 | */ 191 | return apply_filters('wpua_register_settings', $settings); 192 | } 193 | 194 | /** 195 | * Add default avatar 196 | * @uses string $avatar_default 197 | * @uses string $mustache_admin 198 | * @uses string $mustache_medium 199 | * @uses int $wpua_avatar_default 200 | * @uses bool $wpua_disable_gravatar 201 | * @uses object $wpua_functions 202 | * @uses get_avatar() 203 | * @uses remove_filter() 204 | * @uses wpua_attachment_is_image() 205 | * @uses wpua_get_attachment_image_src() 206 | * @return string 207 | */ 208 | public function wpua_add_default_avatar() { 209 | global $avatar_default, $mustache_admin, $mustache_medium, $wpua_avatar_default, $wpua_disable_gravatar, $wpua_functions; 210 | // Remove get_avatar filter 211 | remove_filter('get_avatar', array($wpua_functions, 'wpua_get_avatar_filter')); 212 | // Set avatar_list variable 213 | $avatar_list = ""; 214 | // Set avatar defaults 215 | $avatar_defaults = array( 216 | 'mystery' => __('Mystery Man','wp-user-avatar'), 217 | 'blank' => __('Blank','wp-user-avatar'), 218 | 'gravatar_default' => __('Gravatar Logo','wp-user-avatar'), 219 | 'identicon' => __('Identicon (Generated)','wp-user-avatar'), 220 | 'wavatar' => __('Wavatar (Generated)','wp-user-avatar'), 221 | 'monsterid' => __('MonsterID (Generated)','wp-user-avatar'), 222 | 'retro' => __('Retro (Generated)','wp-user-avatar') 223 | ); 224 | 225 | $avatar_defaults = apply_filters( 'avatar_defaults', $avatar_defaults ); 226 | 227 | // No Default Avatar, set to Mystery Man 228 | if(empty($avatar_default)) { 229 | $avatar_default = 'mystery'; 230 | } 231 | 232 | // Take avatar_defaults and get examples for unknown@gravatar.com 233 | foreach($avatar_defaults as $default_key => $default_name) { 234 | $avatar = get_avatar('unknown@gravatar.com', 32, $default_key); 235 | $selected = ($avatar_default == $default_key) ? 'checked="checked" ' : ""; 236 | $avatar_list .= "\n\t'; 239 | $avatar_list .= '
'; 240 | } 241 | // Show remove link if custom Default Avatar is set 242 | if(!empty($wpua_avatar_default) && $wpua_functions->wpua_attachment_is_image($wpua_avatar_default)) { 243 | $avatar_thumb_src = $wpua_functions->wpua_get_attachment_image_src($wpua_avatar_default, array(32,32)); 244 | $avatar_thumb = $avatar_thumb_src[0]; 245 | $hide_remove = ""; 246 | } else { 247 | $avatar_thumb = $mustache_admin; 248 | $hide_remove = ' class="wpua-hide"'; 249 | } 250 | // Default Avatar is wp_user_avatar, check the radio button next to it 251 | $selected_avatar = ((bool) $wpua_disable_gravatar == 1 || $avatar_default == 'wp_user_avatar') ? ' checked="checked" ' : ""; 252 | // Wrap WPUA in div 253 | $avatar_thumb_img = '
'; 254 | // Add WPUA to list 255 | $wpua_list = "\n\t'; 258 | $wpua_list .= '

'; 259 | $wpua_list .= ''.__('Remove','wp-user-avatar').''.__('Undo','wp-user-avatar').'

'; 260 | $wpua_list .= ''; 261 | $wpua_list .= '
'; 262 | if((bool) $wpua_disable_gravatar != 1) { 263 | return $wpua_list.'
'.$avatar_list.'
'; 264 | } else { 265 | return $wpua_list.''; 266 | } 267 | } 268 | 269 | /** 270 | * Add default avatar_default to whitelist 271 | * @param array $options 272 | * @return array $options 273 | */ 274 | public function wpua_whitelist_options($options) { 275 | $options['discussion'][] = 'avatar_default_wp_user_avatar'; 276 | return $options; 277 | } 278 | 279 | /** 280 | * Add actions links on plugin page 281 | * @param array $actions 282 | * @param string $plugin_file 283 | * @return array $links 284 | */ 285 | public function wpua_action_links( $actions, $plugin_file ) { 286 | 287 | // Make sure we only perform actions for this specific plugin! 288 | if ( strpos( $plugin_file, 'custom-user-avatar.php' ) !== false ) { 289 | 290 | // Add link to the settings page. 291 | array_unshift( $actions, '' . __( 'Settings', 'wp-user-avatar' ) . '' ); 292 | 293 | } 294 | 295 | return $actions; 296 | } 297 | 298 | /** 299 | * Add row meta on plugin page 300 | * @param array $links 301 | * @param string $file 302 | * @return array $links 303 | */ 304 | 305 | public function wpua_row_meta( $links, $file ) { 306 | 307 | if ( false !== strpos( $file, 'custom-user-avatar.php' ) ) { 308 | 309 | $links = array_merge( 310 | $links, 311 | array( '' . __( 'Github', 'wp-user-avatar' ) . '' ), 312 | array( '' . __( 'Support', 'wp-user-avatar' ) . '' ), 313 | array( '' . __( 'Donate', 'wp-user-avatar' ) . '' ), 314 | array( '' . __( 'Write a Review', 'wp-user-avatar' ) . ' ⭐️⭐️⭐️⭐️⭐️' ) 315 | ); 316 | } 317 | 318 | return $links; 319 | } 320 | 321 | /** 322 | * Add column to Users table 323 | * @param array $columns 324 | * @return array 325 | */ 326 | public function wpua_add_column($columns) { 327 | return $columns + array('wp-user-avatar' => __('Profile Picture','wp-user-avatar')); 328 | } 329 | 330 | /** 331 | * Show thumbnail in Users table 332 | * @param string $value 333 | * @param string $column_name 334 | * @param int $user_id 335 | * @uses int $blog_id 336 | * @uses object $wpdb 337 | * @uses object $wpua_functions 338 | * @uses get_blog_prefix() 339 | * @uses get_user_meta() 340 | * @uses wpua_get_attachment_image() 341 | * @return string $value 342 | */ 343 | public function wpua_show_column($value, $column_name, $user_id) { 344 | global $blog_id, $wpdb, $wpua_functions; 345 | $wpua = get_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', true); 346 | $wpua_image = $wpua_functions->wpua_get_attachment_image($wpua, array(32,32)); 347 | if($column_name == 'wp-user-avatar') { 348 | $value = $wpua_image; 349 | } 350 | return $value; 351 | } 352 | 353 | /** 354 | * Get list table 355 | * @param string $class 356 | * @param array $args 357 | * @return object 358 | */ 359 | public function _wpua_get_list_table($class, $args = array()) { 360 | require_once(WPUA_INC.'class-wp-user-avatar-list-table.php'); 361 | $args['screen'] = 'wp-user-avatar'; 362 | return new $class($args); 363 | } 364 | 365 | /** 366 | * Add media states 367 | * @param array $states 368 | * @uses object $post 369 | * @uses int $wpua_avatar_default 370 | * @uses apply_filters() 371 | * @uses get_post_custom_values() 372 | * @return array 373 | */ 374 | public function wpua_add_media_state($states) { 375 | global $post, $wpua_avatar_default; 376 | 377 | $is_wpua = isset($post->ID) ? get_post_custom_values('_wp_attachment_wp_user_avatar', $post->ID) : ''; 378 | 379 | if(!empty($is_wpua)) { 380 | $states[] = __('Profile Picture','wp-user-avatar'); 381 | } 382 | 383 | if(!empty($wpua_avatar_default) && isset($post->ID) && ($wpua_avatar_default == $post->ID)) { 384 | $states[] = __('Default Avatar','wp-user-avatar'); 385 | } 386 | /** 387 | * Filter media states 388 | * @param array $states 389 | */ 390 | return apply_filters('wpua_add_media_state', $states); 391 | } 392 | 393 | } 394 | 395 | /** 396 | * Initialize 397 | */ 398 | function wpua_admin_init() { 399 | global $wpua_admin; 400 | $wpua_admin = new WP_User_Avatar_Admin(); 401 | } 402 | add_action('init', 'wpua_admin_init'); 403 | -------------------------------------------------------------------------------- /includes/class-wp-user-avatar-functions.php: -------------------------------------------------------------------------------- 1 | comment_author_email)) { 37 | $user_id = $id_or_email->user_id; 38 | } 39 | 40 | }else{ 41 | if ( is_email( $id_or_email ) ) { 42 | $user = get_user_by( 'email', $id_or_email ); 43 | if($user){ 44 | $user_id = $user->ID; 45 | } 46 | } else { 47 | $user_id = $id_or_email; 48 | } 49 | } 50 | 51 | // First checking custom avatar. 52 | if( has_wp_user_avatar( $user_id ) ) { 53 | 54 | $url = $this->get_wp_user_avatar_src( $user_id ); 55 | 56 | } else if( $wpua_disable_gravatar ) { 57 | 58 | $url = $this->wpua_get_default_avatar_url($url, $id_or_email, $args); 59 | 60 | } else { 61 | 62 | $has_valid_url = $this->wpua_has_gravatar($id_or_email); 63 | if(!$has_valid_url){ 64 | $url = $this->wpua_get_default_avatar_url($url, $id_or_email, $args); 65 | } 66 | 67 | } 68 | /** 69 | * Filter get_avatar_url filter 70 | * @param string $url 71 | * @param int|string $id_or_email 72 | * @param array $args 73 | */ 74 | return apply_filters( 'wpua_get_avatar_filter_url', $url, $id_or_email); 75 | 76 | 77 | } 78 | 79 | 80 | function wpua_get_default_avatar_url($url, $id_or_email, $args){ 81 | 82 | global $avatar_default, $mustache_admin, $mustache_avatar, $mustache_medium, $mustache_original, $mustache_thumbnail, $post, $wpua_avatar_default, $wpua_disable_gravatar, $wpua_functions; 83 | 84 | $default_image_details = array(); 85 | 86 | $size = !empty($args['size'])?$args['size']:96; 87 | 88 | // Show custom Default Avatar 89 | if(!empty($wpua_avatar_default) && $wpua_functions->wpua_attachment_is_image($wpua_avatar_default)) { 90 | // Get image 91 | $wpua_avatar_default_image = $wpua_functions->wpua_get_attachment_image_src($wpua_avatar_default, array($size,$size)); 92 | // Image src 93 | $url = $wpua_avatar_default_image[0]; 94 | // Add dimensions if numeric size 95 | } else { 96 | // Get mustache image based on numeric size comparison 97 | if($size > get_option('medium_size_w')) { 98 | $url = $mustache_original; 99 | } elseif($size <= get_option('medium_size_w') && $size > get_option('thumbnail_size_w')) { 100 | $url = $mustache_medium; 101 | } elseif($size <= get_option('thumbnail_size_w') && $size > 96) { 102 | $url = $mustache_thumbnail; 103 | } elseif($size <= 96 && $size > 32) { 104 | $url = $mustache_avatar; 105 | } elseif($size <= 32) { 106 | $url = $mustache_admin; 107 | } 108 | // Add dimensions if numeric size 109 | } 110 | 111 | return $url; 112 | } 113 | 114 | /** 115 | * Returns Custom User Avatar or Gravatar-hosted image if user doesn't have Buddypress-uploaded image 116 | * @param string $avatar 117 | * @param array $params 118 | * @param int $item_id 119 | * @param string $avatar_dir 120 | * @param string $css_id 121 | * @param int $html_width 122 | * @param int $html_height 123 | * @param string $avatar_folder_url 124 | * @param string $avatar_folder_dir 125 | * @uses object $wpua_functions 126 | * @uses wpua_get_avatar_filter() 127 | */ 128 | 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=''){ 129 | global $wpua_functions; 130 | if(strpos($gravatar,'gravatar.com',0)>-1){ 131 | $avatar = $wpua_functions->wpua_get_avatar_filter($gravatar, ($params['object']=='user') ? $params['item_id'] : '', ($params['object']=='user') ? (($params['type']=='thumb') ? 50 :150) : 50, '', ''); 132 | return $avatar; 133 | } 134 | else 135 | return $gravatar; 136 | } 137 | 138 | /** 139 | * Returns WP user default local avatar URL or Gravatar-hosted image URL if user doesn't have Buddypress-uploaded image 140 | * @param string $avatar 141 | * @param array $params 142 | * @uses object $wpua_functions 143 | * @uses wpua_get_avatar_filter() 144 | */ 145 | public function wpua_bp_core_fetch_avatar_url_filter($gravatar,$params){ 146 | global $wpua_functions; 147 | if(strpos($gravatar,'gravatar.com',0)>-1){ 148 | $avatar = $this->wpua_get_avatar_url($gravatar, $params['email'], $params); 149 | return $avatar; 150 | } 151 | else 152 | return $gravatar; 153 | } 154 | 155 | /** 156 | * Returns true if user has Gravatar-hosted image 157 | * @param int|string $id_or_email 158 | * @param bool $has_gravatar 159 | * @param int|string $user 160 | * @param string $email 161 | * @uses get_user_by() 162 | * @uses is_wp_error() 163 | * @uses wp_cache_get() 164 | * @uses wp_cache_set() 165 | * @uses wp_remote_head() 166 | * @return bool $has_gravatar 167 | */ 168 | public function wpua_has_gravatar($id_or_email="", $has_gravatar=0, $user="", $email="") { 169 | 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; 170 | // User has WPUA 171 | //Decide if check gravatar required or not. 172 | if(trim($avatar_default)!='wp_user_avatar') 173 | return true; 174 | 175 | if(!is_object($id_or_email) && !empty($id_or_email)) { 176 | // Find user by ID or e-mail address 177 | $user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email); 178 | // Get registered user e-mail address 179 | $email = !empty($user) ? $user->user_email : ""; 180 | } 181 | 182 | if($email == ""){ 183 | 184 | if(!is_numeric($id_or_email) and !is_object($id_or_email)) 185 | $email = $id_or_email; 186 | elseif(!is_numeric($id_or_email) and is_object($id_or_email)) 187 | $email = $id_or_email->comment_author_email; 188 | } 189 | if($email!="") 190 | { 191 | $hash = md5(strtolower(trim($email))); 192 | //check if gravatar exists for hashtag using options 193 | 194 | if(is_array($wpua_hash_gravatar)){ 195 | 196 | 197 | if ( array_key_exists($hash, $wpua_hash_gravatar) and is_array($wpua_hash_gravatar[$hash]) and array_key_exists(date('m-d-Y'), $wpua_hash_gravatar[$hash]) ) 198 | { 199 | return (bool) $wpua_hash_gravatar[$hash][date('m-d-Y')]; 200 | } 201 | 202 | } 203 | 204 | //end 205 | if ( isset( $_SERVER['HTTPS'] ) && ( 'on' == $_SERVER['HTTPS'] || 1 == $_SERVER['HTTPS'] ) || isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && 'https' == $_SERVER['HTTP_X_FORWARDED_PROTO'] ) { 206 | $http='https'; 207 | }else{ 208 | $http='http'; 209 | } 210 | $gravatar = $http.'://www.gravatar.com/avatar/'.$hash.'?d=404'; 211 | 212 | $data = wp_cache_get($hash); 213 | 214 | if(false === $data) { 215 | $response = wp_remote_head($gravatar); 216 | $data = is_wp_error($response) ? 'not200' : $response['response']['code']; 217 | 218 | wp_cache_set($hash, $data, $group="", $expire=60*5); 219 | //here set if hashtag has avatar 220 | $has_gravatar = ($data == '200') ? true : false; 221 | if($wpua_hash_gravatar == false){ 222 | $wpua_hash_gravatar = []; 223 | $wpua_hash_gravatar[$hash][date('m-d-Y')] = (bool)$has_gravatar; 224 | add_option('wpua_hash_gravatar',serialize($wpua_hash_gravatar), '', false); 225 | } 226 | else{ 227 | 228 | if(is_array($wpua_hash_gravatar) && !empty($wpua_hash_gravatar)){ 229 | 230 | if (array_key_exists($hash, $wpua_hash_gravatar)){ 231 | 232 | unset($wpua_hash_gravatar[$hash]); 233 | $wpua_hash_gravatar[$hash][date('m-d-Y')] = (bool)$has_gravatar; 234 | update_option('wpua_hash_gravatar',serialize($wpua_hash_gravatar), false); 235 | } 236 | else 237 | { 238 | $wpua_hash_gravatar[$hash][date('m-d-Y')] = (bool)$has_gravatar; 239 | update_option('wpua_hash_gravatar',serialize($wpua_hash_gravatar), false); 240 | 241 | } 242 | 243 | } 244 | 245 | } 246 | //end 247 | } 248 | $has_gravatar = ($data == '200') ? true : false; 249 | 250 | } 251 | else 252 | $has_gravatar = false; 253 | 254 | // Check if Gravatar image returns 200 (OK) or 404 (Not Found) 255 | return (bool) $has_gravatar; 256 | } 257 | 258 | 259 | /** 260 | * Check if local image 261 | * @param int $attachment_id 262 | * @uses apply_filters() 263 | * @uses wp_attachment_is_image() 264 | * @return bool 265 | */ 266 | public function wpua_attachment_is_image($attachment_id) { 267 | $is_image = wp_attachment_is_image($attachment_id); 268 | /** 269 | * Filter local image check 270 | * @param bool $is_image 271 | * @param int $attachment_id 272 | */ 273 | $is_image = apply_filters('wpua_attachment_is_image', $is_image, $attachment_id); 274 | return (bool) $is_image; 275 | } 276 | 277 | /** 278 | * Get local image tag 279 | * @param int $attachment_id 280 | * @param int|string $size 281 | * @param bool $icon 282 | * @param string $attr 283 | * @uses apply_filters() 284 | * @uses wp_get_attachment_image() 285 | * @return string 286 | */ 287 | public function wpua_get_attachment_image($attachment_id, $size='thumbnail', $icon=0, $attr='') { 288 | $image = wp_get_attachment_image($attachment_id, $size, $icon, $attr); 289 | /** 290 | * Filter local image tag 291 | * @param string $image 292 | * @param int $attachment_id 293 | * @param int|string $size 294 | * @param bool $icon 295 | * @param string $attr 296 | */ 297 | return apply_filters('wpua_get_attachment_image', $image, $attachment_id, $size, $icon, $attr); 298 | } 299 | 300 | /** 301 | * Get local image src 302 | * @param int $attachment_id 303 | * @param int|string $size 304 | * @param bool $icon 305 | * @uses apply_filters() 306 | * @uses wp_get_attachment_image_src() 307 | * @return array 308 | */ 309 | public function wpua_get_attachment_image_src($attachment_id, $size='thumbnail', $icon=0) { 310 | $image_src_array = wp_get_attachment_image_src($attachment_id, $size, $icon); 311 | /** 312 | * Filter local image src 313 | * @param array $image_src_array 314 | * @param int $attachment_id 315 | * @param int|string $size 316 | * @param bool $icon 317 | */ 318 | return apply_filters('wpua_get_attachment_image_src', $image_src_array, $attachment_id, $size, $icon); 319 | } 320 | 321 | /** 322 | * Returns true if user has wp_user_avatar 323 | * @param int|string $id_or_email 324 | * @param bool $has_wpua 325 | * @param object $user 326 | * @param int $user_id 327 | * @uses int $blog_id 328 | * @uses object $wpdb 329 | * @uses int $wpua_avatar_default 330 | * @uses object $wpua_functions 331 | * @uses get_user_by() 332 | * @uses get_user_meta() 333 | * @uses get_blog_prefix() 334 | * @uses wpua_attachment_is_image() 335 | * @return bool 336 | */ 337 | public function has_wp_user_avatar($id_or_email="", $has_wpua=0, $user="", $user_id="") { 338 | global $blog_id, $wpdb, $wpua_avatar_default, $wpua_functions, $avatar_default; 339 | if(!is_object($id_or_email) && !empty($id_or_email)) { 340 | // Find user by ID or e-mail address 341 | 342 | $user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email); 343 | // Get registered user ID 344 | $user_id = !empty($user) ? $user->ID : ""; 345 | } 346 | $wpua = get_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', true); 347 | // Check if avatar is same as default avatar or on excluded list 348 | $has_wpua = !empty($wpua) && ($avatar_default!='wp_user_avatar' or $wpua != $wpua_avatar_default) && $wpua_functions->wpua_attachment_is_image($wpua) ? true : false; 349 | return (bool) $has_wpua; 350 | } 351 | /** 352 | Retrive default image url set by admin. 353 | */ 354 | public function wpua_default_image($size) 355 | { 356 | global $avatar_default, $mustache_admin, $mustache_avatar, $mustache_medium, $mustache_original, $mustache_thumbnail, $post, $wpua_avatar_default, $wpua_disable_gravatar, $wpua_functions; 357 | 358 | $default_image_details = array(); 359 | // Show custom Default Avatar 360 | if(!empty($wpua_avatar_default) && $wpua_functions->wpua_attachment_is_image($wpua_avatar_default)) { 361 | // Get image 362 | $wpua_avatar_default_image = $wpua_functions->wpua_get_attachment_image_src($wpua_avatar_default, array($size,$size)); 363 | // Image src 364 | $default = $wpua_avatar_default_image[0]; 365 | // Add dimensions if numeric size 366 | $default_image_details['dimensions'] = ' width="'.$wpua_avatar_default_image[1].'" height="'.$wpua_avatar_default_image[2].'"'; 367 | 368 | } else { 369 | // Get mustache image based on numeric size comparison 370 | if($size > get_option('medium_size_w')) { 371 | $default = $mustache_original; 372 | } elseif($size <= get_option('medium_size_w') && $size > get_option('thumbnail_size_w')) { 373 | $default = $mustache_medium; 374 | } elseif($size <= get_option('thumbnail_size_w') && $size > 96) { 375 | $default = $mustache_thumbnail; 376 | } elseif($size <= 96 && $size > 32) { 377 | $default = $mustache_avatar; 378 | } elseif($size <= 32) { 379 | $default = $mustache_admin; 380 | } 381 | // Add dimensions if numeric size 382 | $default_image_details['dimensions'] = ' width="'.$size.'" height="'.$size.'"'; 383 | } 384 | // Construct the img tag 385 | $default_image_details['size'] = $size; 386 | $default_image_details['src'] = $default; 387 | return $default_image_details; 388 | 389 | } 390 | 391 | /** 392 | * Replace get_avatar only in get_wp_user_avatar 393 | * 394 | * @param string $avatar 395 | * @param int|string $id_or_email 396 | * @param int|string $size 397 | * @param string $default 398 | * @param string $alt 399 | * @param array $args 400 | * 401 | * @return string $avatar 402 | * @uses string $avatar_default 403 | * @uses string $mustache_admin 404 | * @uses string $mustache_avatar 405 | * @uses string $mustache_medium 406 | * @uses string $mustache_original 407 | * @uses string $mustache_thumbnail 408 | * @uses object $post 409 | * @uses int $wpua_avatar_default 410 | * @uses bool $wpua_disable_gravatar 411 | * @uses object $wpua_functions 412 | * @uses apply_filters() 413 | * @uses get_wp_user_avatar() 414 | * @uses has_wp_user_avatar() 415 | * @uses wpua_has_gravatar() 416 | * @uses wpua_attachment_is_image() 417 | * @uses wpua_get_attachment_image_src() 418 | * @uses get_option() 419 | */ 420 | public function wpua_get_avatar_filter($avatar, $id_or_email="", $size="", $default="", $alt="", $args = []) { 421 | 422 | global $avatar_default, $mustache_admin, $mustache_avatar, $mustache_medium, $mustache_original, $mustache_thumbnail, $post, $wpua_avatar_default, $wpua_disable_gravatar, $wpua_functions; 423 | // User has WPUA 424 | 425 | if( $alt == '' ) { 426 | $alt = apply_filters('wpua_default_alt_tag',__("Avatar",'wp-user-avatar')); 427 | } 428 | 429 | $alt = esc_attr($alt); 430 | $size = esc_attr($size); 431 | 432 | $class = []; 433 | if ( isset($args['class']) ) { 434 | if ( is_array( $args['class'] ) ) { 435 | $class = array_merge( $class, $args['class'] ); 436 | } else { 437 | $class[] = $args['class']; 438 | } 439 | } 440 | 441 | $avatar = str_replace('gravatar_default','',$avatar); 442 | if(is_object($id_or_email)) { 443 | if(!empty($id_or_email->comment_author_email)) { 444 | $avatar = get_wp_user_avatar($id_or_email, $size, $default, $alt, $class); 445 | } else { 446 | 447 | $avatar = get_wp_user_avatar('unknown@gravatar.com', $size, $default, $alt, $class); 448 | } 449 | } else { 450 | if(has_wp_user_avatar($id_or_email)) { 451 | $avatar = get_wp_user_avatar($id_or_email, $size, $default, $alt, $class); 452 | // User has Gravatar and Gravatar is not disabled 453 | } elseif((bool) $wpua_disable_gravatar != 1 && $wpua_functions->wpua_has_gravatar($id_or_email)) { 454 | // find our src 455 | if(!empty($avatar)) { 456 | $output = preg_match_all('//i', $avatar, $matches, PREG_SET_ORDER); 457 | $wpua_avatar_image_src = !empty($matches) ? $matches [0] [1] : ""; 458 | $default_image_details = $this->wpua_default_image($size); 459 | $wpua_default_avatar_image_src = $default_image_details['src']; 460 | $wpua_final_avatar_image_src = str_replace('d=wp_user_avatar', 'd='.urlencode($wpua_default_avatar_image_src), $wpua_avatar_image_src); 461 | } 462 | 463 | $class_string = !empty($class) ? ' ' . esc_attr( implode( ' ', $class ) ) : ''; 464 | 465 | $avatar = ''.$alt.''; 466 | 467 | // User doesn't have WPUA or Gravatar and Default Avatar is wp_user_avatar, show custom Default Avatar 468 | } elseif($avatar_default == 'wp_user_avatar') { 469 | 470 | $default_image_details = $this->wpua_default_image($size); 471 | 472 | $class_string = !empty($class) ? ' ' . esc_attr( implode( ' ', $class ) ) : ''; 473 | 474 | $avatar = ''.$alt.''; 475 | 476 | return $avatar; 477 | 478 | } 479 | } 480 | /** 481 | * Filter get_avatar filter 482 | * @param string $avatar 483 | * @param int|string $id_or_email 484 | * @param int|string $size 485 | * @param string $default 486 | * @param string $alt 487 | */ 488 | return apply_filters('wpua_get_avatar_filter', $avatar, $id_or_email, $size, $default, $alt); 489 | } 490 | 491 | /** 492 | * Get original avatar, for when user removes wp_user_avatar 493 | * @param int|string $id_or_email 494 | * @param int|string $size 495 | * @param string $default 496 | * @param string $alt 497 | * @uses string $avatar_default 498 | * @uses string $mustache_avatar 499 | * @uses int $wpua_avatar_default 500 | * @uses bool $wpua_disable_gravatar 501 | * @uses object $wpua_functions 502 | * @uses wpua_attachment_is_image() 503 | * @uses wpua_get_attachment_image_src() 504 | * @uses wpua_has_gravatar() 505 | * @uses add_filter() 506 | * @uses apply_filters() 507 | * @uses get_avatar() 508 | * @uses remove_filter() 509 | * @return string $default 510 | */ 511 | public function wpua_get_avatar_original($id_or_email="", $size="", $default="", $alt="") { 512 | global $avatar_default, $mustache_avatar, $wpua_avatar_default, $wpua_disable_gravatar, $wpua_functions; 513 | // Remove get_avatar filter 514 | remove_filter('get_avatar', array($wpua_functions, 'wpua_get_avatar_filter')); 515 | if((bool) $wpua_disable_gravatar != 1) { 516 | // User doesn't have Gravatar and Default Avatar is wp_user_avatar, show custom Default Avatar 517 | if(!$wpua_functions->wpua_has_gravatar($id_or_email) && $avatar_default == 'wp_user_avatar') { 518 | // Show custom Default Avatar 519 | if(!empty($wpua_avatar_default) && $wpua_functions->wpua_attachment_is_image($wpua_avatar_default)) { 520 | // $wpua_avatar_default_image = $wpua_functions->wpua_get_attachment_image_src($wpua_avatar_default, array($size,$size)); 521 | $size_numeric_w_x_h = array( get_option( $size . '_size_w' ), get_option( $size . '_size_h' ) ); 522 | $wpua_avatar_default_image = $wpua_functions->wpua_get_attachment_image_src($wpua_avatar_default, $size_numeric_w_x_h); 523 | 524 | $default = $wpua_avatar_default_image[0]; 525 | } else { 526 | $default = $mustache_avatar; 527 | } 528 | } else { 529 | // Get image from Gravatar, whether it's the user's image or default image 530 | $wpua_image = get_avatar($id_or_email, $size); 531 | // Takes the img tag, extracts the src 532 | $output = preg_match_all('//i', $wpua_image, $matches, PREG_SET_ORDER); 533 | $default = !empty($matches) ? $matches [0] [1] : ""; 534 | } 535 | } else { 536 | if(!empty($wpua_avatar_default) && $wpua_functions->wpua_attachment_is_image($wpua_avatar_default)) { 537 | // $wpua_avatar_default_image = $wpua_functions->wpua_get_attachment_image_src($wpua_avatar_default, array($size,$size)); 538 | $size_numeric_w_x_h = array( get_option( $size . '_size_w' ), get_option( $size . '_size_h' ) ); 539 | $wpua_avatar_default_image = $wpua_functions->wpua_get_attachment_image_src($wpua_avatar_default, $size_numeric_w_x_h); 540 | 541 | $default = $wpua_avatar_default_image[0]; 542 | } else { 543 | $default = $mustache_avatar; 544 | } 545 | } 546 | // Enable get_avatar filter 547 | add_filter('get_avatar', array($wpua_functions, 'wpua_get_avatar_filter'), 10, 5); 548 | /** 549 | * Filter original avatar src 550 | * @param string $default 551 | */ 552 | return apply_filters('wpua_get_avatar_original', $default); 553 | } 554 | 555 | 556 | /** 557 | * Find WPUA, show get_avatar if empty 558 | * 559 | * @param int|string $id_or_email 560 | * @param int|string $size 561 | * @param string $align 562 | * @param string $alt 563 | * @param array $class 564 | * 565 | * @return string $avatar 566 | * @uses array $_wp_additional_image_sizes 567 | * @uses array $all_sizes 568 | * @uses string $avatar_default 569 | * @uses int $blog_id 570 | * @uses object $post 571 | * @uses object $wpdb 572 | * @uses int $wpua_avatar_default 573 | * @uses object $wpua_functions 574 | * @uses apply_filters() 575 | * @uses get_the_author_meta() 576 | * @uses get_blog_prefix() 577 | * @uses get_user_by() 578 | * @uses get_query_var() 579 | * @uses is_author() 580 | * @uses wpua_attachment_is_image() 581 | * @uses wpua_get_attachment_image_src() 582 | * @uses get_option() 583 | * @uses get_avatar() 584 | */ 585 | public function get_wp_user_avatar($id_or_email="", $size='96', $align="", $alt="", $class=[]) { 586 | global $all_sizes, $avatar_default, $blog_id, $post, $wpdb, $wpua_avatar_default, $wpua_functions, $_wp_additional_image_sizes; 587 | $email='unknown@gravatar.com'; 588 | // Checks if comment 589 | 590 | if( $alt == '' ) { 591 | $alt = apply_filters('wpua_default_alt_tag',__("Avatar",'wp-user-avatar')); 592 | } 593 | 594 | if(is_object($id_or_email)) { 595 | // Checks if comment author is registered user by user ID 596 | if($id_or_email->user_id != 0) { 597 | $email = $id_or_email->user_id; 598 | // Checks that comment author isn't anonymous 599 | } elseif(!empty($id_or_email->comment_author_email)) { 600 | // Checks if comment author is registered user by e-mail address 601 | $user = get_user_by('email', $id_or_email->comment_author_email); 602 | // Get registered user info from profile, otherwise e-mail address should be value 603 | $email = !empty($user) ? $user->ID : $id_or_email->comment_author_email; 604 | } 605 | $alt = $id_or_email->comment_author; 606 | } else { 607 | if(!empty($id_or_email)) { 608 | // Find user by ID or e-mail address 609 | $user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email); 610 | } else { 611 | // Find author's name if id_or_email is empty 612 | $author_name = get_query_var('author_name'); 613 | if(is_author()) { 614 | // On author page, get user by page slug 615 | $user = get_user_by('slug', $author_name); 616 | } else { 617 | // On post, get user by author meta 618 | $user_id = get_the_author_meta('ID'); 619 | $user = get_user_by('id', $user_id); 620 | } 621 | } 622 | // Set user's ID and name 623 | if(!empty($user)) { 624 | $email = $user->ID; 625 | $alt = $user->display_name; 626 | } 627 | } 628 | 629 | 630 | $alt = esc_attr($alt); 631 | $size = esc_attr($size); 632 | $class = esc_attr( implode( ' ', $class )); 633 | 634 | 635 | // Checks if user has WPUA 636 | $wpua_meta = get_the_author_meta($wpdb->get_blog_prefix($blog_id).'user_avatar', $email); 637 | // Add alignment class 638 | $alignclass = !empty($align) && ($align == 'left' || $align == 'right' || $align == 'center') ? ' align'.$align : ' alignnone'; 639 | // User has WPUA, check if on excluded list and bypass get_avatar 640 | if(!empty($wpua_meta) && $wpua_functions->wpua_attachment_is_image($wpua_meta)) { 641 | // Numeric size use size array 642 | $get_size = is_numeric($size) ? array($size,$size) : $size; 643 | // Get image src 644 | $wpua_image = $wpua_functions->wpua_get_attachment_image_src($wpua_meta, $get_size); 645 | // Add dimensions to img only if numeric size was specified 646 | $dimensions = is_numeric($size) ? ' width="'.$wpua_image[1].'" height="'.$wpua_image[2].'"' : ""; 647 | 648 | $class_string = !empty($class) ? ' ' . $class : ''; 649 | 650 | // Construct the img tag 651 | $avatar = ''.$alt.''; 652 | } else { 653 | // Check for custom image sizes 654 | if(in_array($size, $all_sizes)) { 655 | if(in_array($size, array('original', 'large', 'medium', 'thumbnail'))) { 656 | $get_size = ($size == 'original') ? get_option('large_size_w') : get_option($size.'_size_w'); 657 | } else { 658 | $get_size = $_wp_additional_image_sizes[$size]['width']; 659 | } 660 | } else { 661 | // Numeric sizes leave as-is 662 | $get_size = $size; 663 | } 664 | // User with no WPUA uses get_avatar 665 | $avatar = get_avatar($email, $get_size, $default="", $alt="", ['class' => $class]); 666 | // Remove width and height for non-numeric sizes 667 | if(in_array($size, array('original', 'large', 'medium', 'thumbnail'))) { 668 | $avatar = preg_replace('/(width|height)=\"\d*\"\s/', "", $avatar); 669 | $avatar = preg_replace("/(width|height)=\'\d*\'\s/", "", $avatar); 670 | } 671 | $replace = array('wp-user-avatar ', 'wp-user-avatar-'.$get_size.' ', 'wp-user-avatar-'.$size.' ', 'avatar-'.$get_size, ' photo'); 672 | $replacements = array("", "", "", 'avatar-'.$size, 'wp-user-avatar wp-user-avatar-'.$size.$alignclass.' photo'); 673 | $avatar = str_replace($replace, $replacements, $avatar); 674 | } 675 | /** 676 | * Filter get_wp_user_avatar 677 | * @param string $avatar 678 | * @param int|string $id_or_email 679 | * @param int|string $size 680 | * @param string $align 681 | * @param string $alt 682 | */ 683 | return apply_filters('get_wp_user_avatar', $avatar, $id_or_email, $size, $align, $alt); 684 | } 685 | 686 | /** 687 | * Return just the image src 688 | * @param int|string $id_or_email 689 | * @param int|string $size 690 | * @param string $align 691 | * @uses get_wp_user_avatar() 692 | * @return string 693 | */ 694 | public function get_wp_user_avatar_src($id_or_email="", $size="", $align="") { 695 | $wpua_image_src = ""; 696 | // Gets the avatar img tag 697 | $wpua_image = get_wp_user_avatar($id_or_email, $size, $align); 698 | // Takes the img tag, extracts the src 699 | if(!empty($wpua_image)) { 700 | $output = preg_match_all('//i', $wpua_image, $matches, PREG_SET_ORDER); 701 | $wpua_image_src = !empty($matches) ? $matches [0] [1] : ""; 702 | } 703 | return $wpua_image_src; 704 | } 705 | } 706 | 707 | /** 708 | * Initialize 709 | */ 710 | function wpua_functions_init() { 711 | global $wpua_functions; 712 | $wpua_functions = new WP_User_Avatar_Functions(); 713 | } 714 | add_action('plugins_loaded', 'wpua_functions_init'); 715 | -------------------------------------------------------------------------------- /includes/class-wp-user-avatar-list-table.php: -------------------------------------------------------------------------------- 1 | $paged, 27 | 'post_type' => 'attachment', 28 | 'post_status' => 'inherit', 29 | 'posts_per_page' => '-1', 30 | 'meta_query' => array( 31 | array( 32 | 'key' => '_wp_attachment_wp_user_avatar', 33 | 'value' => "", 34 | 'compare' => '!=' 35 | ) 36 | ) 37 | ); 38 | $avatars_wp_query = new WP_Query($q); 39 | $avatars = array(); 40 | while($avatars_wp_query->have_posts()) : $avatars_wp_query->the_post(); 41 | $avatars[] = $post->ID; 42 | endwhile; 43 | wp_reset_query(); 44 | // Include default avatar 45 | $avatars[] = $wpua_avatar_default; 46 | parent::__construct(array( 47 | 'plural' => 'media', 48 | 'screen' => isset($args['screen']) ? $args['screen'] : null 49 | )); 50 | } 51 | 52 | /** 53 | * Only users with edit_users capability can use this section 54 | * @uses current_user_can() 55 | */ 56 | public function ajax_user_can() { 57 | return current_user_can('edit_users'); 58 | } 59 | 60 | /** 61 | * Search form 62 | * @param string $text 63 | * @param int $input_id 64 | * @uses _admin_search_query() 65 | * @uses has_items() 66 | * @uses submit_button() 67 | */ 68 | public function search_box($text, $input_id) { 69 | if(empty($_REQUEST['s']) && !$this->has_items()) { 70 | return; 71 | } 72 | $input_id = $input_id.'-search-input'; 73 | if(!empty($_REQUEST['orderby'])) { 74 | echo ''; 75 | } 76 | if(!empty($_REQUEST['order'])) { 77 | echo ''; 78 | } 79 | if(!empty($_REQUEST['post_mime_type'])) { 80 | echo ''; 81 | } 82 | if(!empty($_REQUEST['detached'])) { 83 | echo ''; 84 | } 85 | ?> 86 | 92 | is_trash = isset($_REQUEST['status']) && $_REQUEST['status'] == 'trash'; 106 | $this->set_pagination_args(array( 107 | 'total_items' => $wp_query->found_posts, 108 | 'total_pages' => $wp_query->max_num_pages, 109 | 'per_page' => $wp_query->query_vars['posts_per_page'], 110 | )); 111 | } 112 | 113 | /** 114 | * Links to available table views 115 | * @uses array $avatars 116 | * @uses add_query_arg() 117 | * @uses number_format_i18n() 118 | * @return array 119 | */ 120 | public function get_views() { 121 | global $avatars; 122 | $type_links = array(); 123 | $_total_posts = count(array_filter($avatars)); 124 | $class = (empty($_GET['post_mime_type']) && !isset($_GET['status'])) ? ' class="current"' : ""; 125 | $type_links['all'] = sprintf('', esc_url(add_query_arg(array('page' => 'wp-user-avatar-library'), 'admin.php'))).sprintf(_nx('All (%s)', 'All (%s)', $_total_posts, 'uploaded files'), number_format_i18n($_total_posts)).''; 126 | return $type_links; 127 | } 128 | 129 | /** 130 | * Bulk action available with this table 131 | * @return array 132 | */ 133 | public function get_bulk_actions() { 134 | $actions = array(); 135 | $actions['delete'] = __('Delete Permanently','wp-user-avatar'); 136 | return $actions; 137 | } 138 | 139 | /** 140 | * Current action from bulk actions list 141 | * @uses current_action() 142 | * @return string|bool 143 | */ 144 | public function current_action() { 145 | return parent::current_action(); 146 | } 147 | 148 | /** 149 | * Checks whether table has items 150 | * @uses have_posts() 151 | * @return bool 152 | */ 153 | public function has_items() { 154 | return have_posts(); 155 | } 156 | 157 | /** 158 | * Message displayed when no items 159 | */ 160 | public function no_items() { 161 | _e('No media attachments found.','wp-user-avatar'); 162 | } 163 | 164 | /** 165 | * Columns in this table 166 | * @return array 167 | */ 168 | public function get_columns() { 169 | $columns = array(); 170 | $columns['cb'] = ''; 171 | $columns['icon'] = ""; 172 | $columns['title'] = _x('File', 'column name'); 173 | $columns['author'] = __('Author','wp-user-avatar'); 174 | $columns['parent'] = _x('Uploaded to', 'column name'); 175 | $columns['date'] = _x('Date', 'column name'); 176 | return $columns; 177 | } 178 | 179 | /** 180 | * Sortable columns in this table 181 | * @return array 182 | */ 183 | public function get_sortable_columns() { 184 | return array( 185 | 'title' => 'title', 186 | 'author' => 'author', 187 | 'date' => array('date', true) 188 | ); 189 | } 190 | 191 | /** 192 | * Display for rows in table 193 | * @uses object $post 194 | * @uses object $wpdb 195 | * @uses object $wpua_functions 196 | * @uses add_filter() 197 | * @uses _draft_or_post_title() 198 | * @uses _media_states() 199 | * @uses current_user_can() 200 | * @uses get_attached_file() 201 | * @uses get_current_user_id() 202 | * @uses get_edit_post_link() 203 | * @uses get_edit_user_link() 204 | * @uses get_post_mime_type() 205 | * @uses get_the_author() 206 | * @uses get_the_author_meta() 207 | * @uses get_userdata() 208 | * @uses have_posts() 209 | * @uses the_post() 210 | * @uses wpua_get_attachment_image() 211 | */ 212 | public function display_rows() { 213 | global $post, $wpdb, $wpua_functions; 214 | add_filter('the_title','esc_html'); 215 | $alt = ""; 216 | while (have_posts()) : the_post(); 217 | $user_can_edit = current_user_can('edit_post', $post->ID); 218 | if($this->is_trash && $post->post_status != 'trash' || !$this->is_trash && $post->post_status == 'trash') { 219 | continue; 220 | } 221 | $alt = ('alternate' == $alt) ? "" : 'alternate'; 222 | $post_owner = (get_current_user_id() == $post->post_author) ? 'self' : 'other'; 223 | $att_title = _draft_or_post_title(); 224 | ?> 225 | post_status); ?>' valign="top"> 226 | get_column_info(); 228 | foreach($columns as $column_name => $column_display_name) { 229 | $class = "class='$column_name column-$column_name'"; 230 | $style = ""; 231 | if(in_array($column_name, $hidden)) { 232 | $style = ' style="display:none;"'; 233 | } 234 | $attributes = $class.$style; 235 | switch($column_name) { 236 | case 'cb': 237 | ?> 238 | 239 | 240 | 241 | 242 | 243 | 244 | 249 | >wpua_get_attachment_image($post->ID, array(80, 60), true)) { 251 | if($this->is_trash || !$user_can_edit) { 252 | echo $thumb; 253 | } else { 254 | ?> 255 | 256 | 257 | 258 | 260 | 261 | 265 | > 266 | is_trash || !$user_can_edit) { 267 | echo $att_title; 268 | } else { ?> 269 | 271 | 272 | 274 |

275 | ID), $matches)) { 277 | echo esc_html(strtoupper($matches[1])); 278 | } else { 279 | echo strtoupper(str_replace('image/', "", get_post_mime_type())); 280 | } 281 | ?> 282 |

283 | row_actions($this->_get_row_actions($post, $att_title)); ?> 284 | 285 | 289 | > 290 | %s', 292 | esc_url(add_query_arg(array('author' => get_the_author_meta('ID')), 'upload.php')), 293 | get_the_author() 294 | ); ?> 295 | 296 | post_date) { 300 | $h_time = __('Unpublished','wp-user-avatar'); 301 | } else { 302 | $m_time = $post->post_date; 303 | $time = get_post_time('G', true, $post, false); 304 | if ((abs($t_diff = time() - $time)) < DAY_IN_SECONDS) { 305 | if ($t_diff < 0) 306 | $h_time = sprintf(__('%s from now','wp-user-avatar'), human_time_diff($time)); 307 | else 308 | $h_time = sprintf(__('%s ago','wp-user-avatar'), human_time_diff($time)); 309 | } else { 310 | $h_time = mysql2date(__('Y/m/d','wp-user-avatar'), $m_time); 311 | } 312 | } 313 | ?> 314 | > 315 | get_blog_prefix($blog_id).'user_avatar'; 321 | $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)); 322 | // Find users without WPUA 323 | $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, "")); 324 | $user_array = array(); 325 | ?> 326 | > 327 | 328 | user_id); 332 | $user_array[] = ''.$user->user_login.''; 333 | } 334 | } else { 335 | foreach($nowpuas as $usermeta) { 336 | $user = get_userdata($usermeta->ID); 337 | $user_array[] = ''.$user->user_login.''; 338 | } 339 | } 340 | ?> 341 | 342 | 343 | 344 | 349 | 350 | ID) && !$this->is_trash) { 367 | $actions['edit'] = ''.__('Edit','wp-user-avatar').''; 368 | } 369 | if(current_user_can('delete_post', $post->ID)) { 370 | if($this->is_trash) { 371 | $actions['untrash'] = "ID)."'>".__('Restore','wp-user-avatar').""; 372 | } elseif (EMPTY_TRASH_DAYS && MEDIA_TRASH) { 373 | $actions['trash'] = "ID)."'>".__('Trash','wp-user-avatar').""; 374 | } 375 | if($this->is_trash || !EMPTY_TRASH_DAYS || !MEDIA_TRASH) { 376 | $delete_ays = (!$this->is_trash && !MEDIA_TRASH) ? " onclick='return showNotice.warn();'" : ""; 377 | $actions['delete'] = "ID)."'>".__('Delete Permanently','wp-user-avatar').""; 378 | } 379 | } 380 | if(!$this->is_trash) { 381 | $title = _draft_or_post_title($post->post_parent); 382 | $actions['view'] = ''.__('View','wp-user-avatar').''; 383 | } 384 | return $actions; 385 | } 386 | } 387 | -------------------------------------------------------------------------------- /includes/class-wp-user-avatar-resource-manager.php: -------------------------------------------------------------------------------- 1 | '; 13 | 14 | var $buffer = ''; 15 | var $styles = ''; 16 | var $other_output = ''; 17 | var $wrote_footer = FALSE; 18 | var $run_shutdown = FALSE; 19 | var $valid_request = TRUE; 20 | 21 | /** 22 | * Start buffering all generated output. We'll then do two things with the buffer 23 | * 1) Find stylesheets lately enqueued and move them to the header 24 | * 2) Ensure that wp_print_footer_scripts() is called 25 | */ 26 | function __construct() { 27 | // Validate the request 28 | $this->validate_request(); 29 | add_action('init', array(&$this, 'start_buffer'), 1); 30 | add_action('wp_footer', array(&$this, 'print_marker'), -1); 31 | } 32 | 33 | /** 34 | * Created early as possible in the wp_footer action this is the string to which we 35 | * will move JS resources after 36 | */ 37 | function print_marker() { 38 | print $this->marker; 39 | } 40 | 41 | /** 42 | * Determines if the resource manager should perform its routines for this request 43 | * @return bool 44 | */ 45 | function validate_request() { 46 | $retval = TRUE; 47 | if(is_admin()) { 48 | if(isset($_REQUEST['page']) && !preg_match("#^(wp_user_avatar)#", $_REQUEST['page'])) { 49 | $retval = FALSE; 50 | } 51 | } 52 | if(strpos($_SERVER['REQUEST_URI'], 'wp-admin/update') !== FALSE) { 53 | $retval = FALSE; 54 | } elseif(isset($_GET['display_gallery_iframe'])) { 55 | $retval = FALSE; 56 | } elseif(defined('WP_ADMIN') && WP_ADMIN && defined('DOING_AJAX') && DOING_AJAX) { 57 | $retval = FALSE; 58 | } elseif(preg_match("/(js|css|xsl|xml|kml)$/", $_SERVER['REQUEST_URI'])) { 59 | $retval = FALSE; 60 | } elseif(preg_match("/\\.(\\w{3,4})$/", $_SERVER['REQUEST_URI'], $match)) { 61 | if(!in_array($match[1], array('htm', 'html', 'php'))) { 62 | $retval = FALSE; 63 | } 64 | } 65 | $this->valid_request = $retval; 66 | } 67 | 68 | /** 69 | * Start the output buffers 70 | */ 71 | function start_buffer() { 72 | if(defined('WPUA_DISABLE_RESOURCE_MANAGER') && WPUA_DISABLE_RESOURCE_MANAGER) { 73 | return; 74 | } 75 | if(apply_filters('run_wpua_resource_manager', $this->valid_request)) { 76 | ob_start(array(&$this, 'output_buffer_handler')); 77 | ob_start(array(&$this, 'get_buffer')); 78 | add_action('wp_print_footer_scripts', array(&$this, 'get_resources'), 1); 79 | add_action('admin_print_footer_scripts', array(&$this, 'get_resources'), 1); 80 | add_action('shutdown', array(&$this, 'shutdown')); 81 | } 82 | } 83 | 84 | /** 85 | * 86 | */ 87 | function get_resources() { 88 | ob_start(); 89 | wp_print_styles(); 90 | print_admin_styles(); 91 | $this->styles = ob_get_clean(); 92 | if(!is_admin()) { 93 | ob_start(); 94 | wp_print_scripts(); 95 | $this->scripts = ob_get_clean(); 96 | } 97 | $this->wrote_footer = TRUE; 98 | } 99 | 100 | /** 101 | * Output the buffer after PHP execution has ended (but before shutdown) 102 | * @param string $content 103 | * @return string 104 | */ 105 | function output_buffer_handler($content) { 106 | return $this->output_buffer(); 107 | } 108 | 109 | /** 110 | * Removes the closing tag from the output buffer. We'll then write our own closing tag 111 | * in the shutdown function after running wp_print_footer_scripts() 112 | * @param string $content 113 | * @return mixed 114 | */ 115 | function get_buffer($content) { 116 | $this->buffer = $content; 117 | return ''; 118 | } 119 | 120 | 121 | /** 122 | * Moves resources to their appropriate place 123 | */ 124 | function move_resources() { 125 | if($this->valid_request) { 126 | // Move stylesheets to head 127 | if($this->styles) { 128 | $this->buffer = str_ireplace('', $this->styles.'', $this->buffer); 129 | } 130 | // Move the scripts to the bottom of the page 131 | if($this->scripts) { 132 | $this->buffer = str_ireplace($this->marker, $this->marker.$this->scripts, $this->buffer); 133 | } 134 | if($this->other_output) { 135 | $this->buffer = str_replace($this->marker, $this->marker.$this->other_output, $this->buffer); 136 | } 137 | } 138 | } 139 | 140 | /** 141 | * When PHP has finished, we output the footer scripts and closing tags 142 | */ 143 | function output_buffer($in_shutdown=FALSE) { 144 | // If the footer scripts haven't been outputted, then 145 | // we need to take action - as they're required 146 | if(!$this->wrote_footer) { 147 | // If W3TC is installed and activated, we can't output the 148 | // scripts and manipulate the buffer, so we can only provide a warning 149 | if(defined('W3TC') && defined('WP_DEBUG') && WP_DEBUG && !is_admin()) { 150 | if(!defined('DONOTCACHEPAGE')) define('DONOTCACHEPAGE', TRUE); 151 | if(!did_action('wp_footer')) { 152 | error_log("We're sorry, but your theme's page template didn't make a call to wp_footer(), which is required by Custom User Avatar. Please add this call to your page templates."); 153 | } else { 154 | error_log("We're sorry, but your theme's page template didn't make a call to wp_print_footer_scripts(), which is required by Custom User Avatar. Please add this call to your page templates."); 155 | } 156 | // We don't want to manipulate the buffer if it doesn't contain HTML 157 | } elseif(strpos($this->buffer, '') === FALSE) { 158 | $this->valid_request = FALSE; 159 | } 160 | // The output_buffer() function has been called in the PHP shutdown callback 161 | // This will allow us to print the scripts ourselves and manipulate the buffer 162 | if($in_shutdown === TRUE) { 163 | ob_start(); 164 | if(!did_action('wp_footer')) { 165 | wp_footer(); 166 | } else { 167 | wp_print_footer_scripts(); 168 | } 169 | $this->other_output = ob_get_clean(); 170 | } 171 | // W3TC isn't activated and we're not in the shutdown callback. 172 | // We'll therefore add a shutdown callback to print the scripts 173 | else { 174 | $this->run_shutdown = TRUE; 175 | return ''; 176 | } 177 | } 178 | // Once we have the footer scripts, we can modify the buffer and 179 | // move the resources around 180 | if ($this->wrote_footer) $this->move_resources(); 181 | return $this->buffer; 182 | } 183 | 184 | /** 185 | * PHP shutdown callback. Manipulate and output the buffer 186 | */ 187 | function shutdown() { 188 | if($this->run_shutdown) echo $this->output_buffer(TRUE); 189 | } 190 | 191 | /** 192 | * 193 | */ 194 | static function init() { 195 | $klass = get_class(); 196 | return self::$instance = new $klass; 197 | } 198 | } 199 | -------------------------------------------------------------------------------- /includes/class-wp-user-avatar-shortcode.php: -------------------------------------------------------------------------------- 1 | "", 'size' => '96', 'align' => "", 'link' => "", 'target' => ""), $atts)); 55 | // Find user by ID, login, slug, or e-mail address 56 | if(!empty($user)) { 57 | if( $user == 'current' ) { 58 | $user = wp_get_current_user(); 59 | }else{ 60 | $user = is_numeric($user) ? get_user_by('id', $user) : get_user_by('login', $user); 61 | $user = empty($user) ? get_user_by('slug', $user) : $user; 62 | $user = empty($user) ? get_user_by('email', $user) : $user; 63 | } 64 | } else { 65 | // Find author's name if id_or_email is empty 66 | $author_name = get_query_var('author_name'); 67 | if(is_author()) { 68 | // On author page, get user by page slug 69 | $user = get_user_by('slug', $author_name); 70 | } else { 71 | // On post, get user by author meta 72 | $user_id = get_the_author_meta('ID'); 73 | $user = get_user_by('id', $user_id); 74 | } 75 | } 76 | // Numeric sizes leave as-is 77 | $get_size = $size; 78 | // Check for custom image sizes if there are captions 79 | if(!empty($content)) { 80 | if(in_array($size, $all_sizes)) { 81 | if(in_array($size, array('original', 'large', 'medium', 'thumbnail'))) { 82 | $get_size = ($size == 'original') ? get_option('large_size_w') : get_option($size.'_size_w'); 83 | } else { 84 | $get_size = $_wp_additional_image_sizes[$size]['width']; 85 | } 86 | } 87 | } 88 | // Get user ID 89 | $id_or_email = !empty($user) ? $user->ID : 'unknown@gravatar.com'; 90 | // Check if link is set 91 | if(!empty($link)) { 92 | // CSS class is same as link type, except for URL 93 | $link_class = $link; 94 | if($link == 'file') { 95 | // Get image src 96 | $link = get_wp_user_avatar_src($id_or_email, 'original'); 97 | } elseif($link == 'attachment') { 98 | // Get attachment URL 99 | $link = get_attachment_link(get_the_author_meta($wpdb->get_blog_prefix($blog_id).'user_avatar', $id_or_email)); 100 | } else { 101 | // URL 102 | $link_class = 'custom'; 103 | } 104 | // Open in new window 105 | $target_link = !empty($target) ? ' target="'.$target.'"' : ""; 106 | // Wrap the avatar inside the link 107 | $html = ''.get_wp_user_avatar($id_or_email, $get_size, $align).''; 108 | } else { 109 | $html = get_wp_user_avatar($id_or_email, $get_size, $align); 110 | } 111 | // Check if caption is set 112 | if(!empty($content)) { 113 | // Get attachment ID 114 | $wpua = get_user_meta($id_or_email, $wpdb->get_blog_prefix($blog_id).'user_avatar', true); 115 | // Clean up caption 116 | $content = trim($content); 117 | $content = preg_replace('/\r|\n/', "", $content); 118 | $content = preg_replace('/<\/p>

/', "", $content, 1); 119 | $content = preg_replace('/<\/p>

$/', "", $content); 120 | $content = str_replace('

', "

", $content); 121 | $avatar = do_shortcode(image_add_caption($html, $wpua, $content, $title="", $align, $link, $get_size, $alt="")); 122 | } else { 123 | $avatar = $html; 124 | } 125 | return $avatar; 126 | } 127 | 128 | /** 129 | * Update user 130 | * @param bool $user_id 131 | * @uses add_query_arg() 132 | * @uses apply_filters() 133 | * @uses do_action_ref_array() 134 | * @uses wp_get_referer() 135 | * @uses wp_redirect() 136 | * @uses wp_safe_redirect() 137 | */ 138 | private function wpua_edit_user($user_id=0) { 139 | $update = $user_id ? true : false; 140 | $user = new stdClass; 141 | $errors = new WP_Error(); 142 | do_action_ref_array('wpua_update_errors', array(&$errors, $update, &$user)); 143 | if($errors->get_error_codes()) { 144 | // Return with errors 145 | return $errors; 146 | } 147 | if($update) { 148 | // Redirect with updated variable 149 | $redirect_url = esc_url_raw(add_query_arg(array('updated' => '1'), wp_get_referer())); 150 | /** 151 | * Filter redirect URL 152 | * @param string $redirect_url 153 | */ 154 | $redirect_url = apply_filters('wpua_edit_user_redirect_url', $redirect_url); 155 | /** 156 | * Filter wp_safe_redirect or wp_redirect 157 | * @param bool $safe_redirect 158 | */ 159 | $safe_redirect = apply_filters('wpua_edit_user_safe_redirect', true); 160 | $safe_redirect ? wp_safe_redirect($redirect_url) : wp_redirect($redirect_url); 161 | exit; 162 | } 163 | } 164 | 165 | /** 166 | * Edit shortcode 167 | * @param array $atts 168 | * @uses $wp_user_avatar 169 | * @uses $wpua_allow_upload 170 | * @uses current_user_can() 171 | * @uses do_action() 172 | * @uses get_error_messages() 173 | * @uses get_user_by() 174 | * @uses is_user_logged_in() 175 | * @uses is_wp_error() 176 | * @uses shortcode_atts() 177 | * @uses wpua_edit_form() 178 | * @uses wpua_edit_user() 179 | * @uses wpua_is_author_or_above() 180 | * @return string 181 | */ 182 | public function wpua_edit_shortcode($atts) { 183 | global $current_user, $errors, $wp_user_avatar, $wpua_allow_upload; 184 | // Shortcode only works for users with permission 185 | if($wp_user_avatar->wpua_is_author_or_above() || ((bool) $wpua_allow_upload == 1 && is_user_logged_in())) { 186 | extract(shortcode_atts(array('user' => ""), $atts)); 187 | // Default user is current user 188 | $valid_user = $current_user; 189 | // Find user by ID, login, slug, or e-mail address 190 | if(!empty($user)) { 191 | $get_user = is_numeric($user) ? get_user_by('id', $user) : get_user_by('login', $user); 192 | $get_user = empty($get_user) ? get_user_by('slug', $user) : $get_user; 193 | $get_user = empty($get_user) ? get_user_by('email', $user) : $get_user; 194 | // Check if current user can edit this user 195 | $valid_user = current_user_can('edit_user', $get_user->ID) ? $get_user : null; 196 | } 197 | // Show form only for valid user 198 | if($valid_user) { 199 | // Save 200 | if(isset($_POST['submit']) && $_POST['submit'] && $_POST['wpua_action'] == 'update') { 201 | do_action('wpua_update', $valid_user->ID); 202 | // Check for errors 203 | $errors = $this->wpua_edit_user($valid_user->ID); 204 | } 205 | // Errors 206 | if(isset($errors) && is_wp_error($errors)) { 207 | echo '

'.implode("

\n

", $errors->get_error_messages()).'

'; 208 | } elseif(isset($_GET['updated']) && $_GET['updated'] == '1') { 209 | echo '

'.__('Profile updated.','wp-user-avatar').'

'; 210 | } 211 | // Edit form 212 | return $this->wpua_edit_form($valid_user); 213 | } 214 | } 215 | } 216 | 217 | /** 218 | * Edit form 219 | * @param object $user 220 | * @uses do_action() 221 | * @uses submit_button() 222 | * @uses wp_nonce_field() 223 | */ 224 | private function wpua_edit_form($user) { 225 | ob_start(); 226 | ?> 227 |
228 | 229 | 230 | 231 | ID); ?> 232 | 233 |
234 | get_blog_prefix($blog_id).'user_roles'; 45 | $user_roles = get_option($wp_user_roles); 46 | if(isset($user_roles['subscriber']['capabilities']['edit_posts'])){ 47 | unset($user_roles['subscriber']['capabilities']['edit_posts']); 48 | } 49 | update_option($wp_user_roles, $user_roles); 50 | } 51 | } 52 | 53 | /** 54 | * Initialize 55 | */ 56 | function wpua_subscriber_init() { 57 | global $wpua_subscriber; 58 | $wpua_subscriber = new WP_User_Avatar_Subscriber(); 59 | } 60 | add_action('init', 'wpua_subscriber_init'); 61 | -------------------------------------------------------------------------------- /includes/class-wp-user-avatar-update.php: -------------------------------------------------------------------------------- 1 | get_blog_prefix($blog_id).'user_avatar'; 67 | // If database tables start with something other than wp_ 68 | if($wpua_metakey != 'wp_user_avatar') { 69 | $users = get_users(); 70 | // Move current user metakeys to new metakeys 71 | foreach($users as $user) { 72 | $wpua = get_user_meta($user->ID, 'wp_user_avatar', true); 73 | if(!empty($wpua)) { 74 | update_user_meta($user->ID, $wpua_metakey, $wpua); 75 | delete_user_meta($user->ID, 'wp_user_avatar'); 76 | } 77 | } 78 | } 79 | update_option('wp_user_avatar_users_updated', '1'); 80 | } 81 | 82 | /** 83 | * Add media state to existing avatars 84 | * @uses int $blog_id 85 | * @uses object $wpdb 86 | * @uses add_post_meta() 87 | * @uses get_blog_prefix() 88 | * @uses get_results() 89 | * @uses update_option() 90 | */ 91 | public function wpua_media_state() { 92 | global $blog_id, $wpdb; 93 | // Find all users with WPUA 94 | $wpua_metakey = $wpdb->get_blog_prefix($blog_id).'user_avatar'; 95 | $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, "")); 96 | foreach($wpuas as $usermeta) { 97 | add_post_meta($usermeta->meta_value, '_wp_attachment_wp_user_avatar', $usermeta->user_id); 98 | } 99 | update_option('wp_user_avatar_media_updated', '1'); 100 | } 101 | } 102 | 103 | /** 104 | * Initialize 105 | */ 106 | function wpua_update_init() { 107 | global $wpua_update; 108 | $wpua_update = new WP_User_Avatar_Update(); 109 | } 110 | add_action('init', 'wpua_update_init'); 111 | -------------------------------------------------------------------------------- /includes/class-wp-user-avatar-widget.php: -------------------------------------------------------------------------------- 1 | 'widget_wp_user_avatar', 'description' => __('Insert').' '.__('[avatar_upload]', 'wp-user-avatar').'.'); 14 | parent::__construct('wp_user_avatar_profile', __('Custom User Avatar', 'wp-user-avatar'), $widget_ops); 15 | } 16 | 17 | /** 18 | * Add [avatar_upload] to widget 19 | * @param array $args 20 | * @param array $instance 21 | * @uses object $wp_user_avatar 22 | * @uses bool $wpua_allow_upload 23 | * @uses object $wpua_shortcode 24 | * @uses add_filter() 25 | * @uses apply_filters() 26 | * @uses is_user_logged_in() 27 | * @uses remove_filter() 28 | * @uses wpua_edit_shortcode() 29 | * @uses wpua_is_author_or_above() 30 | */ 31 | public function widget($args, $instance) { 32 | global $wp_user_avatar, $wpua_allow_upload, $wpua_shortcode; 33 | extract($args); 34 | $instance = apply_filters('wpua_widget_instance', $instance); 35 | $title = apply_filters('widget_title', empty($instance['title']) ? "" : $instance['title'], $instance, $this->id_base); 36 | $text = apply_filters('widget_text', empty($instance['text']) ? "" : $instance['text'], $instance); 37 | // Show widget only for users with permission 38 | if($wp_user_avatar->wpua_is_author_or_above() || ((bool) $wpua_allow_upload == 1 && is_user_logged_in())) { 39 | echo $before_widget; 40 | if(!empty($title)) { 41 | echo $before_title.$title.$after_title; 42 | } 43 | if(!empty($text)) { 44 | echo '
'; 45 | echo !empty($instance['filter']) ? wpautop($text) : $text; 46 | echo '
'; 47 | } 48 | // Remove profile title 49 | add_filter('wpua_profile_title', '__return_null'); 50 | // Get [avatar_upload] shortcode 51 | echo $wpua_shortcode->wpua_edit_shortcode(""); 52 | remove_filter('wpua_profile_title', '__return_null'); 53 | } 54 | } 55 | 56 | /** 57 | * Set title 58 | * @param array $instance 59 | * @uses wp_parse_args() 60 | */ 61 | public function form($instance) { 62 | $instance = wp_parse_args((array) $instance, array('title' => "", 'text' => "")); 63 | $title = strip_tags($instance['title']); 64 | $text = esc_textarea($instance['text']); 65 | ?> 66 |

67 | 70 | 71 |

72 | 73 | 74 |

75 | /> 76 | 79 |

80 | wpua_is_author_or_above() || ((bool) $wpua_allow_upload == 1 && is_user_logged_in())) { 26 | // Profile functions and scripts 27 | add_action('show_user_profile', function($user) { 28 | if(is_admin()) return; 29 | $this->wpua_action_show_user_profile($user); 30 | }); 31 | 32 | add_action('edit_user_profile', function($user) { 33 | if(is_admin()) return; 34 | $this->wpua_action_show_user_profile($user); 35 | }); 36 | 37 | add_action('personal_options_update', array($this, 'wpua_action_process_option_update')); 38 | add_action('edit_user_profile_update', array($this, 'wpua_action_process_option_update')); 39 | add_action('user_new_form', array($this, 'wpua_action_show_user_profile')); 40 | add_action('user_register', array($this, 'wpua_action_process_option_update')); 41 | 42 | // setting defaults for the filter callback fixes an error like https://wordpress.org/support/topic/error-missing-argument-2-for-wp_user_avatarclosure 43 | // see https://stackoverflow.com/questions/37779680/missing-argument-2-for-a-custom-function 44 | add_filter('user_profile_picture_description', function ($description = '', $profileuser = null) { 45 | ob_start(); 46 | echo ''; 47 | self::wpua_core_show_user_profile($profileuser); 48 | 49 | return ob_get_clean(); 50 | 51 | }, 9999999999999999999, 2); 52 | 53 | // Admin scripts 54 | $pages = array('profile.php', 'options-discussion.php', 'user-edit.php', 'user-new.php'); 55 | if(in_array($pagenow, $pages) || $wpua_admin->wpua_is_menu_page()) { 56 | add_action('admin_enqueue_scripts', array($this, 'wpua_media_upload_scripts')); 57 | } 58 | // Front pages 59 | if(!is_admin()) { 60 | add_action('show_user_profile', array('wp_user_avatar', 'wpua_media_upload_scripts')); 61 | add_action('edit_user_profile', array('wp_user_avatar', 'wpua_media_upload_scripts')); 62 | } 63 | if(!$this->wpua_is_author_or_above()) { 64 | // Upload errors 65 | add_action('user_profile_update_errors', array($this, 'wpua_upload_errors'), 10, 3); 66 | // Prefilter upload size 67 | add_filter('wp_handle_upload_prefilter', array($this, 'wpua_handle_upload_prefilter')); 68 | } 69 | } 70 | add_filter('media_view_settings', array($this, 'wpua_media_view_settings'), 10, 1); 71 | } 72 | 73 | /** 74 | * Avatars have no parent posts 75 | * 76 | * @param array $settings 77 | * 78 | * @return array 79 | * @uses object $post 80 | * @uses bool $wpua_is_profile 81 | * @uses is_admin() 82 | * array $settings 83 | */ 84 | public function wpua_media_view_settings($settings) { 85 | global $post, $wpua_is_profile; 86 | // Get post ID so not to interfere with media uploads 87 | $post_id = is_object($post) ? $post->ID : 0; 88 | // Don't use post ID on front pages if there's a WPUA uploader 89 | $settings['post']['id'] = (!is_admin() && $wpua_is_profile == 1) ? 0 : $post_id; 90 | return $settings; 91 | } 92 | 93 | /** 94 | * Media Uploader 95 | * @param object $user 96 | * @uses object $current_user 97 | * @uses string $mustache_admin 98 | * @uses string $pagenow 99 | * @uses object $post 100 | * @uses bool $show_avatars 101 | * @uses object $wp_user_avatar 102 | * @uses object $wpua_admin 103 | * @uses object $wpua_functions 104 | * @uses bool $wpua_is_profile 105 | * @uses int $wpua_upload_size_limit 106 | * @uses get_user_by() 107 | * @uses wp_enqueue_script() 108 | * @uses wp_enqueue_media() 109 | * @uses wp_enqueue_style() 110 | * @uses wp_localize_script() 111 | * @uses wp_max_upload_size() 112 | * @uses wpua_get_avatar_original() 113 | * @uses wpua_is_author_or_above() 114 | * @uses wpua_is_menu_page() 115 | */ 116 | public static function wpua_media_upload_scripts($user="") { 117 | global $current_user, $mustache_admin, $pagenow, $post, $show_avatars, $wp_user_avatar, $wpua_admin, $wpua_functions, $wpua_is_profile, $wpua_upload_size_limit; 118 | // This is a profile page 119 | $wpua_is_profile = 1; 120 | $user = ($pagenow == 'user-edit.php' && isset($_GET['user_id'])) ? get_user_by('id', $_GET['user_id']) : $current_user; 121 | wp_enqueue_style('wp-user-avatar', WPUA_URL.'css/wp-user-avatar.css', "", WPUA_VERSION); 122 | wp_enqueue_script('jquery'); 123 | if($wp_user_avatar->wpua_is_author_or_above()) { 124 | wp_enqueue_script('admin-bar'); 125 | wp_enqueue_media(array('post' => $post)); 126 | wp_enqueue_script('wp-user-avatar', WPUA_URL.'js/wp-user-avatar.js', array('jquery', 'media-editor'), WPUA_VERSION, true); 127 | } else { 128 | wp_enqueue_script('wp-user-avatar', WPUA_URL.'js/wp-user-avatar-user.js', array('jquery'), WPUA_VERSION, true); 129 | } 130 | // Admin scripts 131 | if($pagenow == 'options-discussion.php' || $wpua_admin->wpua_is_menu_page()) { 132 | // Size limit slider 133 | wp_enqueue_script('jquery-ui-slider'); 134 | wp_enqueue_style('wp-user-avatar-jqueryui', WPUA_URL.'css/jquery.ui.slider.css', "", null); 135 | // Default avatar 136 | wp_localize_script('wp-user-avatar', 'wpua_custom', array('avatar_thumb' => $mustache_admin)); 137 | // Settings control 138 | wp_enqueue_script('wp-user-avatar-admin', WPUA_URL.'js/wp-user-avatar-admin.js', array('wp-user-avatar'), WPUA_VERSION, true); 139 | wp_localize_script('wp-user-avatar-admin', 'wpua_admin', array('upload_size_limit' => $wpua_upload_size_limit, 'max_upload_size' => wp_max_upload_size())); 140 | } else { 141 | // Original user avatar 142 | $avatar_medium_src = (bool) $show_avatars == 1 ? $wpua_functions->wpua_get_avatar_original($user->user_email, 'medium') : includes_url().'images/blank.gif'; 143 | wp_localize_script('wp-user-avatar', 'wpua_custom', array('avatar_thumb' => $avatar_medium_src)); 144 | } 145 | } 146 | 147 | public static function wpua_core_show_user_profile($user) 148 | { 149 | global $blog_id, $current_user, $show_avatars, $wpdb, $wp_user_avatar, $wpua_edit_avatar, $wpua_functions, $wpua_upload_size_limit_with_units; 150 | 151 | $has_wp_user_avatar = has_wp_user_avatar(@$user->ID); 152 | // Get WPUA attachment ID 153 | $wpua = get_user_meta(@$user->ID, $wpdb->get_blog_prefix($blog_id) . 'user_avatar', true); 154 | // Show remove button if WPUA is set 155 | $hide_remove = ! $has_wp_user_avatar ? 'wpua-hide' : ""; 156 | // Hide image tags if show avatars is off 157 | $hide_images = ! $has_wp_user_avatar && (bool)$show_avatars == 0 ? 'wpua-no-avatars' : ""; 158 | // If avatars are enabled, get original avatar image or show blank 159 | $avatar_medium_src = (bool)$show_avatars == 1 ? $wpua_functions->wpua_get_avatar_original(@$user->user_email, 'medium') : includes_url() . 'images/blank.gif'; 160 | // Check if user has wp_user_avatar, if not show image from above 161 | $avatar_medium = $has_wp_user_avatar ? get_wp_user_avatar_src($user->ID, 'medium') : $avatar_medium_src; 162 | // Check if user has wp_user_avatar, if not show image from above 163 | $avatar_thumbnail = $has_wp_user_avatar ? get_wp_user_avatar_src($user->ID, 96) : $avatar_medium_src; 164 | $edit_attachment_link = esc_url(add_query_arg(array('post' => $wpua, 'action' => 'edit'), admin_url('post.php'))); 165 | // Chck if admin page 166 | ?> 167 | 168 | wpua_is_author_or_above()) : // Button to launch Media Uploader ?> 169 | 170 |

171 | 172 |

173 | 174 | wpua_is_author_or_above()) : // Upload button ?> 175 |

176 | 177 | 178 |

179 |

180 | 181 | : jpg jpeg png gif', 'wp-user-avatar'); ?> 182 |

183 | 184 |
185 |

186 | 187 | 188 |

189 |

190 | 191 | 192 |

193 |

194 | 195 |

196 |

197 | 198 |

199 |
200 | 237 | add('wpua_file_type', __('This file is not an image. Please try another.','wp-user-avatar')); 258 | } 259 | // Upload size limit 260 | if(!empty($size) && $size > $wpua_upload_size_limit) { 261 | $errors->add('wpua_file_size', __('Memory exceeded. Please try another smaller file.','wp-user-avatar')); 262 | } 263 | // Check if directory is writeable 264 | if(!is_writeable($upload_dir['path'])) { 265 | $errors->add('wpua_file_directory', sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?','wp-user-avatar'), $upload_dir['path'])); 266 | } 267 | } 268 | } 269 | 270 | /** 271 | * Set upload size limit 272 | * @param object $file 273 | * @uses int $wpua_upload_size_limit 274 | * @uses add_action() 275 | * @return object $file 276 | */ 277 | public function wpua_handle_upload_prefilter($file) { 278 | global $wpua_upload_size_limit; 279 | $size = $file['size']; 280 | if(!empty($size) && $size > $wpua_upload_size_limit) { 281 | /** 282 | * Error handling that only appears on front pages 283 | */ 284 | function wpua_file_size_error($errors, $update, $user) { 285 | $errors->add('wpua_file_size', __('Memory exceeded. Please try another smaller file.','wp-user-avatar')); 286 | } 287 | add_action('user_profile_update_errors', 'wpua_file_size_error', 10, 3); 288 | return; 289 | } 290 | return $file; 291 | } 292 | 293 | /** 294 | * Update user meta 295 | * @param int $user_id 296 | * @uses int $blog_id 297 | * @uses object $post 298 | * @uses object $wpdb 299 | * @uses object $wp_user_avatar 300 | * @uses bool $wpua_resize_crop 301 | * @uses int $wpua_resize_h 302 | * @uses bool $wpua_resize_upload 303 | * @uses int $wpua_resize_w 304 | * @uses add_post_meta() 305 | * @uses delete_metadata() 306 | * @uses get_blog_prefix() 307 | * @uses is_wp_error() 308 | * @uses update_post_meta() 309 | * @uses update_user_meta() 310 | * @uses wp_delete_attachment() 311 | * @uses wp_generate_attachment_metadata() 312 | * @uses wp_get_image_editor() 313 | * @uses wp_handle_upload() 314 | * @uses wp_insert_attachment() 315 | * @uses WP_Query() 316 | * @uses wp_read_image_metadata() 317 | * @uses wp_reset_query() 318 | * @uses wp_update_attachment_metadata() 319 | * @uses wp_upload_dir() 320 | * @uses wpua_is_author_or_above() 321 | * @uses object $wpua_admin 322 | * @uses wpua_has_gravatar() 323 | */ 324 | public static function wpua_action_process_option_update($user_id) { 325 | global $blog_id, $post, $wpdb, $wp_user_avatar, $wpua_resize_crop, $wpua_resize_h, $wpua_resize_upload, $wpua_resize_w, $wpua_admin; 326 | // Check if user has publish_posts capability 327 | if($wp_user_avatar->wpua_is_author_or_above()) { 328 | $wpua_id = isset($_POST['wp-user-avatar']) ? strip_tags($_POST['wp-user-avatar']) : ""; 329 | // Remove old attachment postmeta 330 | delete_metadata('post', null, '_wp_attachment_wp_user_avatar', $user_id, true); 331 | // Create new attachment postmeta 332 | add_post_meta($wpua_id, '_wp_attachment_wp_user_avatar', $user_id); 333 | // Update usermeta 334 | update_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', $wpua_id); 335 | } else { 336 | // Remove attachment info if avatar is blank 337 | if(isset($_POST['wp-user-avatar']) && empty($_POST['wp-user-avatar'])) { 338 | // Delete other uploads by user 339 | $q = array( 340 | 'author' => $user_id, 341 | 'post_type' => 'attachment', 342 | 'post_status' => 'inherit', 343 | 'posts_per_page' => '-1', 344 | 'meta_query' => array( 345 | array( 346 | 'key' => '_wp_attachment_wp_user_avatar', 347 | 'value' => "", 348 | 'compare' => '!=' 349 | ) 350 | ) 351 | ); 352 | $avatars_wp_query = new WP_Query($q); 353 | while($avatars_wp_query->have_posts()) : $avatars_wp_query->the_post(); 354 | wp_delete_attachment($post->ID); 355 | endwhile; 356 | wp_reset_query(); 357 | // Remove attachment postmeta 358 | delete_metadata('post', null, '_wp_attachment_wp_user_avatar', $user_id, true); 359 | // Remove usermeta 360 | update_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', ""); 361 | } 362 | // Create attachment from upload 363 | if(isset($_POST['submit']) && $_POST['submit'] && !empty($_FILES['wpua-file'])) { 364 | $name = $_FILES['wpua-file']['name']; 365 | $file = wp_handle_upload($_FILES['wpua-file'], array('test_form' => false)); 366 | $type = $_FILES['wpua-file']['type']; 367 | $upload_dir = wp_upload_dir(); 368 | if(is_writeable($upload_dir['path'])) { 369 | if(!empty($type) && preg_match('/(jpe?g|gif|png)$/i', $type)) { 370 | // Resize uploaded image 371 | if((bool) $wpua_resize_upload == 1) { 372 | // Original image 373 | $uploaded_image = wp_get_image_editor($file['file']); 374 | // Check for errors 375 | if(!is_wp_error($uploaded_image)) { 376 | // Resize image 377 | $uploaded_image->resize($wpua_resize_w, $wpua_resize_h, $wpua_resize_crop); 378 | // Save image 379 | $resized_image = $uploaded_image->save($file['file']); 380 | } 381 | } 382 | // Break out file info 383 | $name_parts = pathinfo($name); 384 | $name = trim(substr($name, 0, -(1 + strlen($name_parts['extension'])))); 385 | $url = $file['url']; 386 | $file = $file['file']; 387 | $title = $name; 388 | // Use image exif/iptc data for title if possible 389 | if($image_meta = @wp_read_image_metadata($file)) { 390 | if(trim($image_meta['title']) && !is_numeric(sanitize_title($image_meta['title']))) { 391 | $title = $image_meta['title']; 392 | } 393 | } 394 | // Construct the attachment array 395 | $attachment = array( 396 | 'guid' => $url, 397 | 'post_mime_type' => $type, 398 | 'post_title' => $title, 399 | 'post_content' => "" 400 | ); 401 | // This should never be set as it would then overwrite an existing attachment 402 | if(isset($attachment['ID'])) { 403 | unset($attachment['ID']); 404 | } 405 | // Save the attachment metadata 406 | $attachment_id = wp_insert_attachment($attachment, $file); 407 | if(!is_wp_error($attachment_id)) { 408 | // Delete other uploads by user 409 | $q = array( 410 | 'author' => $user_id, 411 | 'post_type' => 'attachment', 412 | 'post_status' => 'inherit', 413 | 'posts_per_page' => '-1', 414 | 'meta_query' => array( 415 | array( 416 | 'key' => '_wp_attachment_wp_user_avatar', 417 | 'value' => "", 418 | 'compare' => '!=' 419 | ) 420 | ) 421 | ); 422 | $avatars_wp_query = new WP_Query($q); 423 | while($avatars_wp_query->have_posts()) : $avatars_wp_query->the_post(); 424 | wp_delete_attachment($post->ID); 425 | endwhile; 426 | wp_reset_query(); 427 | wp_update_attachment_metadata($attachment_id, wp_generate_attachment_metadata($attachment_id, $file)); 428 | // Remove old attachment postmeta 429 | delete_metadata('post', null, '_wp_attachment_wp_user_avatar', $user_id, true); 430 | // Create new attachment postmeta 431 | update_post_meta($attachment_id, '_wp_attachment_wp_user_avatar', $user_id); 432 | // Update usermeta 433 | update_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', $attachment_id); 434 | } 435 | } 436 | } 437 | } 438 | } 439 | 440 | } 441 | 442 | /** 443 | * Check attachment is owned by user 444 | * @param int $attachment_id 445 | * @param int $user_id 446 | * @param bool $wpua_author 447 | * @uses get_post() 448 | * @return bool 449 | */ 450 | private function wpua_author($attachment_id, $user_id, $wpua_author=0) { 451 | $attachment = get_post($attachment_id); 452 | if(!empty($attachment) && $attachment->post_author == $user_id) { 453 | $wpua_author = true; 454 | } 455 | return (bool) $wpua_author; 456 | } 457 | 458 | /** 459 | * Check if current user has at least Author privileges 460 | * @uses current_user_can() 461 | * @uses apply_filters() 462 | * @return bool 463 | */ 464 | public function wpua_is_author_or_above() { 465 | $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; 466 | /** 467 | * Filter Author privilege check 468 | * @param bool $is_author_or_above 469 | */ 470 | return (bool) apply_filters('wpua_is_author_or_above', $is_author_or_above); 471 | } 472 | } 473 | 474 | /** 475 | * Initialize WP_User_Avatar 476 | */ 477 | function wpua_init() { 478 | global $wp_user_avatar; 479 | $wp_user_avatar = new WP_User_Avatar(); 480 | } 481 | add_action('init', 'wpua_init'); 482 | -------------------------------------------------------------------------------- /includes/tinymce/editor_plugin.js: -------------------------------------------------------------------------------- 1 | (function(){tinymce.create('tinymce.plugins.wpUserAvatar',{init:function(c,d){c.addCommand('mceWpUserAvatar',function(){c.windowManager.open({file:ajaxurl+'?action=wp_user_avatar_tinymce',width:500,height:360,inline:1},{plugin_url:d})});c.addButton('wpUserAvatar',{title:'Insert Custom User Avatar',cmd:'mceWpUserAvatar',image:d+'/../../images/wpua-20x20.png'});c.onNodeChange.add(function(a,b,n){b.setActive('wpUserAvatar',n.nodeName=='IMG')})},createControl:function(n,a){return null},getInfo:function(){return{longname:'Custom User Avatar',author:'David Artiss',authorurl:'httsp://artiss.blog/',infourl:'http://wordpress.org/plugins/custom-user-avatar/',version:"1.0"}}});tinymce.PluginManager.add('wpUserAvatar',tinymce.plugins.wpUserAvatar)})(); -------------------------------------------------------------------------------- /includes/tinymce/window.php: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | <?php _e('Custom User Avatar', 'wp-user-avatar'); ?> 20 | 21 | 22 | 23 | 24 | 25 | 104 | 117 | 118 | 119 |
120 |
    121 |
  • 122 |
  • 123 |
124 |
125 |
126 |

127 | 128 | 134 |

135 | 136 |

137 | 138 | 146 |

147 | 148 |

149 | 150 | 151 |

152 | 153 |

154 | 155 | 161 |

162 | 163 |

164 | 165 | 171 |

172 | 173 | 177 | 178 |

179 | 180 | 181 |

182 | 183 |

184 | 185 | 186 |

187 | 188 |
189 | 190 |
191 |
192 | 202 |
203 |
204 | 205 | 206 | -------------------------------------------------------------------------------- /includes/wpua-functions.php: -------------------------------------------------------------------------------- 1 | has_wp_user_avatar($id_or_email, $has_wpua, $user, $user_id); 20 | } 21 | 22 | /** 23 | * Find WPUA, show get_avatar if empty 24 | * 25 | * @param int|string $id_or_email 26 | * @param int|string $size 27 | * @param string $align 28 | * @param string $alt 29 | * @param array $class 30 | * 31 | * @return object get_wp_user_avatar() 32 | * @uses object $wpua_functions 33 | */ 34 | function get_wp_user_avatar($id_or_email="", $size="", $align="", $alt="",$class=[]) { 35 | global $wpua_functions; 36 | return $wpua_functions->get_wp_user_avatar($id_or_email, $size, $align, $alt, $class); 37 | } 38 | 39 | /** 40 | * Return just the image src 41 | * @param int|string $id_or_email 42 | * @param int|string $size 43 | * @param string $align 44 | * @uses object $wpua_functions 45 | * @return object get_wp_user_avatar_src() 46 | */ 47 | function get_wp_user_avatar_src($id_or_email="", $size="", $align="") { 48 | global $wpua_functions; 49 | return $wpua_functions->get_wp_user_avatar_src($id_or_email, $size, $align); 50 | } 51 | 52 | /** 53 | * Before wrapper for profile 54 | * @uses do_action() 55 | */ 56 | function wpua_before_avatar() { 57 | do_action('wpua_before_avatar'); 58 | } 59 | 60 | /** 61 | * After wrapper for profile 62 | * @uses do_action() 63 | */ 64 | function wpua_after_avatar() { 65 | do_action('wpua_after_avatar'); 66 | } 67 | 68 | /** 69 | * Before avatar container 70 | * @uses apply_filters() 71 | * @uses bbp_is_edit() 72 | * @uses wpuf_has_shortcode() 73 | */ 74 | function wpua_do_before_avatar() { 75 | $wpua_profile_title = '

'.__('Profile Picture','wp-user-avatar').'

'; 76 | /** 77 | * Filter profile title 78 | * @param string $wpua_profile_title 79 | */ 80 | $wpua_profile_title = apply_filters('wpua_profile_title', $wpua_profile_title); 81 | ?> 82 | 83 |

84 |
85 | 86 | 87 |
88 | 89 | 90 | 91 | 92 | 112 | 113 |
93 | 94 |
95 | 96 | 97 | 108 | 109 | 110 | 111 |
114 |
115 | 116 | 117 | 118 | 143 | 144 | 145 | 146 | 157 | 158 |
147 | 156 |
159 | 1024) { 85 | $upload_size_limit /= 1024; 86 | } 87 | $upload_size_limit_with_units = (int) $upload_size_limit.'KB'; 88 | 89 | // User upload size limit 90 | $wpua_user_upload_size_limit = get_option('wp_user_avatar_upload_size_limit'); 91 | if($wpua_user_upload_size_limit == 0 || $wpua_user_upload_size_limit > wp_max_upload_size()) { 92 | $wpua_user_upload_size_limit = wp_max_upload_size(); 93 | } 94 | // Value in bytes 95 | $wpua_upload_size_limit = $wpua_user_upload_size_limit; 96 | // Convert to KB 97 | if($wpua_user_upload_size_limit > 1024) { 98 | $wpua_user_upload_size_limit /= 1024; 99 | } 100 | $wpua_upload_size_limit_with_units = (int) $wpua_user_upload_size_limit.'KB'; 101 | 102 | // Check for custom image sizes 103 | $all_sizes = array_merge(get_intermediate_image_sizes(), array('original')); 104 | -------------------------------------------------------------------------------- /includes/wpua-media-page.php: -------------------------------------------------------------------------------- 1 | _wpua_get_list_table('WP_User_Avatar_List_Table'); 42 | $pagenum = $wp_list_table->get_pagenum(); 43 | 44 | // Handle bulk actions 45 | $doaction = $wp_list_table->current_action(); 46 | 47 | if($doaction) { 48 | check_admin_referer('bulk-media'); 49 | 50 | if(isset($_REQUEST['media'])) { 51 | $post_ids = $_REQUEST['media']; 52 | } elseif(isset($_REQUEST['ids'])) { 53 | $post_ids = explode(',', $_REQUEST['ids']); 54 | } 55 | 56 | $location = esc_url(add_query_arg(array('page' => 'wp-user-avatar-library'), 'admin.php')); 57 | if($referer = wp_get_referer()) { 58 | if(false !== strpos($referer, 'admin.php')) { 59 | $location = remove_query_arg(array('trashed', 'untrashed', 'deleted', 'message', 'ids', 'posted'), $referer); 60 | } 61 | } 62 | switch($doaction) { 63 | case 'delete': 64 | if(!isset($post_ids)) { 65 | break; 66 | } 67 | foreach((array) $post_ids as $post_id_del) { 68 | if(!current_user_can('delete_post', $post_id_del)) { 69 | wp_die(__('You are not allowed to delete this post.','wp-user-avatar')); 70 | } 71 | if(!wp_delete_attachment($post_id_del)) { 72 | wp_die(__('Error in deleting.','wp-user-avatar')); 73 | } 74 | } 75 | $location = esc_url_raw(add_query_arg('deleted', count($post_ids), $location)); 76 | break; 77 | } 78 | wp_redirect($location); 79 | exit; 80 | } elseif(!empty($_GET['_wp_http_referer'])) { 81 | wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), wp_unslash($_SERVER['REQUEST_URI']))); 82 | exit; 83 | } 84 | $wp_list_table->prepare_items(); 85 | wp_enqueue_script('wp-ajax-response'); 86 | wp_enqueue_script('jquery-ui-draggable'); 87 | wp_enqueue_script('media'); 88 | ?> 89 |
90 |

91 | '.__('Search results for “%s”','wp-user-avatar').'', get_search_query()); 94 | } 95 | ?> 96 |

97 | 104 |

105 | 106 | views(); ?> 107 |
108 | search_box(__('Search','wp-user-avatar'), 'media'); ?> 109 | display(); ?> 110 |
111 | 112 |
113 |
114 |
115 | -------------------------------------------------------------------------------- /includes/wpua-options-page.php: -------------------------------------------------------------------------------- 1 | 48 | 49 |
50 |

51 | 52 | 201 |
53 |
54 | 55 | 56 | 57 | 67 | 68 | 69 | 99 | 100 |
70 | 74 | 78 | '; 79 | $wpua_settings['upload'] ='
80 | 84 |
'; 85 | $wpua_settings['gravatar'] ='
86 | 90 |
'; 91 | /** 92 | * Filter main settings 93 | * @param array $wpua_settings 94 | */ 95 | $wpua_settings = apply_filters('wpua_settings', $wpua_settings); 96 | echo implode("", $wpua_settings); 97 | ?> 98 |
101 | 105 | 106 | 107 | 112 | 143 | 144 |
108 | 111 | 113 |
114 | '.__('Upload Size Limit', 'wp-user-avatar').' '. __('(only for Contributors & Subscribers)', 'wp-user-avatar').' 115 | 116 | '.$wpua_upload_size_limit_with_units.' 117 | '.sprintf(__('%s exceeds the maximum upload size for this site.','wp-user-avatar'), "").' 118 |
119 | '.sprintf(__('Maximum upload file size: %d%s.','wp-user-avatar'), esc_html(wp_max_upload_size()), esc_html(' bytes ('.$upload_size_limit_with_units.')')).' 120 |
121 |
122 | 126 |
127 |
128 | 132 |
133 |
134 | 135 | 136 | 137 | 138 |
139 | 140 | 141 |
142 |
145 | '; 146 | /** 147 | * Filter Subscriber settings 148 | * @param array $wpua_subscriber_settings 149 | */ 150 | $wpua_subscriber_settings = apply_filters('wpua_subscriber_settings', $wpua_subscriber_settings); 151 | echo implode("", $wpua_subscriber_settings); 152 | ?> 153 | 154 | 155 | 156 | 165 | 166 | > 167 | 168 | 185 | 186 | 187 | 188 | 195 | 196 |
157 |
158 | 159 | 163 |
164 |
169 |
170 | 171 | __('G — Suitable for all audiences','wp-user-avatar'), 174 | 'PG' => __('PG — Possibly offensive, usually for audiences 13 and above','wp-user-avatar'), 175 | 'R' => __('R — Intended for adult audiences above 17','wp-user-avatar'), 176 | 'X' => __('X — Even more mature than above','wp-user-avatar') 177 | ); 178 | foreach ($ratings as $key => $rating) : 179 | $selected = (get_option('avatar_rating') == $key) ? 'checked="checked"' : ""; 180 | echo "\n\t
"; 181 | endforeach; 182 | ?> 183 |
184 |
189 |
190 | 191 |
192 | wpua_add_default_avatar(); ?> 193 |
194 |
197 | 198 |
199 | 200 |
202 |
203 | -------------------------------------------------------------------------------- /includes/wpua-tinymce.php: -------------------------------------------------------------------------------- 1 | parseInt(wpua_admin.max_upload_size)); 37 | $('#wpua-readable-size').toggleClass('wpua-error', wpuaUploadSizeLimit > parseInt(wpua_admin.max_upload_size)); 38 | }); 39 | $('#wp_user_avatar_upload_size_limit').val($('#wpua-slider').slider('value')); 40 | }); 41 | -------------------------------------------------------------------------------- /js/wp-user-avatar-user.js: -------------------------------------------------------------------------------- 1 | jQuery(function($) { 2 | // Add enctype to form with JavaScript as backup 3 | $('#your-profile').attr('enctype', 'multipart/form-data'); 4 | // Store WP User Avatar ID 5 | var wpuaID = $('#wp-user-avatar').val(); 6 | // Store WP User Avatar src 7 | var wpuaSrc = $('#wpua-preview').find('img').attr('src'); 8 | $('#wpua-undo-button-existing').hide(); 9 | // Remove WP User Avatar 10 | $('body').on('click', '#wpua-remove', function(e) { 11 | e.preventDefault(); 12 | $('#wpua-original').remove(); 13 | $('#wpua-remove-button, #wpua-thumbnail').hide(); 14 | $('#wpua-preview').find('img:first').hide(); 15 | $('#wpua-preview').prepend(''); 16 | $('#wpua-original').attr('src', wpua_custom.avatar_thumb); 17 | $('#wp-user-avatar').val(""); 18 | $('#wpua-original, #wpua-undo-button').show(); 19 | $('#wp_user_avatar_radio').trigger('click'); 20 | }); 21 | // Undo WP User Avatar 22 | $('body').on('click', '#wpua-undo', function(e) { 23 | e.preventDefault(); 24 | $('#wpua-original').remove(); 25 | $('#wpua-images').removeAttr('style'); 26 | $('#wpua-undo-button').hide(); 27 | $('#wpua-remove-button, #wpua-thumbnail').show(); 28 | $('#wpua-preview').find('img:first').attr('src', wpuaSrc).show(); 29 | $('#wp-user-avatar').val(wpuaID); 30 | $('#wp_user_avatar_radio').trigger('click'); 31 | }); 32 | 33 | // Store WP Existing User Avatar ID 34 | var wpuaEID = $('#wp-user-avatar-existing').val(); 35 | // Store WP Existing User Avatar src 36 | var wpuaESrc = $('#wpua-preview-existing').find('img').attr('src'); 37 | // Remove WP Existing User Avatar 38 | $('body').on('click', '#wpua-remove-existing', function(e) { 39 | e.preventDefault(); 40 | $('#wpua-original-existing').remove(); 41 | $('#wpua-remove-button-existing, #wpua-thumbnail-existing').hide(); 42 | $('#wpua-preview-existing').find('img:first').hide(); 43 | $('#wpua-preview-existing').prepend(''); 44 | $('#wpua-original-existing').attr('src', wpua_custom.avatar_thumb); 45 | $('#wp-user-avatar-existing').val(""); 46 | $('#wpua-original-existing, #wpua-undo-button-existing').show(); 47 | $('#wp_user_avatar_radio-existing').trigger('click'); 48 | }); 49 | // Undo WP Existing User Avatar 50 | $('body').on('click', '#wpua-undo-existing', function(e) { 51 | e.preventDefault(); 52 | $('#wpua-original-existing').remove(); 53 | $('#wpua-images-existing').removeAttr('style'); 54 | $('#wpua-undo-button-existing').hide(); 55 | $('#wpua-remove-button-existing, #wpua-thumbnail-existing').show(); 56 | $('#wpua-preview-existing').find('img:first').attr('src', wpuaSrc).show(); 57 | $('#wp-user-avatar-existing').val(wpuaID); 58 | $('#wp_user_avatar_radio-existing').trigger('click'); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /js/wp-user-avatar.js: -------------------------------------------------------------------------------- 1 | (function($) { 2 | var id; 3 | wp.media.wpUserAvatar = { 4 | 5 | get: function() { 6 | return wp.media.view.settings.post.wpUserAvatarId 7 | }, 8 | set: function(a) { 9 | var b = wp.media.view.settings; 10 | b.post.wpUserAvatarId = a; 11 | b.post.wpUserAvatarSrc = $('div.attachment-info').find('img').attr('src'); 12 | if (b.post.wpUserAvatarId && b.post.wpUserAvatarSrc) { 13 | $('#wp-user-avatar'+id).val(b.post.wpUserAvatarId); 14 | $('#wpua-images'+id+', #wpua-undo-button'+id).show(); 15 | $('#wpua-preview'+id).find('img').attr('src', b.post.wpUserAvatarSrc).removeAttr('height', ""); 16 | $('#wpua-remove-button'+id+', #wpua-thumbnail'+id).hide(); 17 | $('#wp_user_avatar_radio').trigger('click') 18 | } 19 | wp.media.wpUserAvatar.frame().close() 20 | }, 21 | frame: function() { 22 | if (this._frame) { 23 | return this._frame 24 | } 25 | this._frame = wp.media({ 26 | library: { 27 | type: 'image' 28 | }, 29 | multiple: false, 30 | title: $('#wpua-add'+id).data('title') 31 | }); 32 | this._frame.on('open', function() { 33 | var a = $('#wp-user-avatar'+id).val(); 34 | if (a == "") { 35 | $('div.media-router').find('a:first').trigger('click') 36 | } else { 37 | var b = this.state().get('selection'); 38 | attachment = wp.media.attachment(a); 39 | attachment.fetch(); 40 | b.add(attachment ? [attachment] : []) 41 | } 42 | }, this._frame); 43 | this._frame.state('library').on('select', this.select); 44 | return this._frame 45 | }, 46 | select: function(a) { 47 | selection = this.get('selection').single(); 48 | wp.media.wpUserAvatar.set(selection ? selection.id : -1) 49 | }, 50 | init: function() { 51 | $('body').on('click', '#wpua-add', function(e) { 52 | e.preventDefault(); 53 | e.stopPropagation(); 54 | id=''; 55 | wp.media.wpUserAvatar.frame().open() 56 | }) 57 | $('body').on('click', '#wpua-add-existing', function(e) { 58 | e.preventDefault(); 59 | e.stopPropagation(); 60 | id='-existing'; 61 | wp.media.wpUserAvatar.frame().open() 62 | }) 63 | } 64 | } 65 | })(jQuery); 66 | jQuery(function($) { 67 | if (typeof(wp) != 'undefined') { 68 | wp.media.wpUserAvatar.init() 69 | } 70 | $('#your-profile').attr('enctype', 'multipart/form-data'); 71 | var a = $('#wp-user-avatar').val(); 72 | var b = $('#wpua-preview').find('img').attr('src'); 73 | $('body').on('click', '#wpua-remove', function(e) { 74 | e.preventDefault(); 75 | $('#wpua-original').remove(); 76 | $('#wpua-remove-button, #wpua-thumbnail').hide(); 77 | $('#wpua-preview').find('img:first').hide(); 78 | $('#wpua-preview').prepend(''); 79 | $('#wpua-original').attr('src', wpua_custom.avatar_thumb); 80 | $('#wp-user-avatar').val(""); 81 | $('#wpua-original, #wpua-undo-button').show(); 82 | $('#wp_user_avatar_radio').trigger('click') 83 | }); 84 | $('body').on('click', '#wpua-undo', function(e) { 85 | e.preventDefault(); 86 | $('#wpua-original').remove(); 87 | $('#wpua-images').removeAttr('style'); 88 | $('#wpua-undo-button').hide(); 89 | $('#wpua-remove-button, #wpua-thumbnail').show(); 90 | $('#wpua-preview').find('img:first').attr('src', b).show(); 91 | $('#wp-user-avatar').val(a); 92 | $('#wp_user_avatar_radio').trigger('click') 93 | }) 94 | }); 95 | jQuery(function($) { 96 | if (typeof(wp) != 'undefined') { 97 | wp.media.wpUserAvatar.init() 98 | } 99 | $('#your-profile').attr('enctype', 'multipart/form-data'); 100 | var a = $('#wp-user-avatar-existing').val(); 101 | var b = $('#wpua-preview-existing').find('img').attr('src'); 102 | $('#wpua-undo-button-existing').hide(); 103 | $('body').on('click', '#wpua-remove-existing', function(e) { 104 | e.preventDefault(); 105 | $('#wpua-original-existing').remove(); 106 | $('#wpua-remove-button-existing, #wpua-thumbnail-existing').hide(); 107 | $('#wpua-preview-existing').find('img:first').hide(); 108 | $('#wpua-preview-existing').prepend(''); 109 | $('#wpua-original-existing').attr('src', wpua_custom.avatar_thumb); 110 | $('#wp-user-avatar-existing').val(""); 111 | $('#wpua-original-existing, #wpua-undo-button-existing').show(); 112 | $('#wp_user_avatar_radio').trigger('click') 113 | }); 114 | $('body').on('click', '#wpua-undo-existing', function(e) { 115 | e.preventDefault(); 116 | $('#wpua-original-existing').remove(); 117 | $('#wpua-images-existing').removeAttr('style'); 118 | $('#wpua-undo-button-existing').hide(); 119 | $('#wpua-remove-button-existing, #wpua-thumbnail-existing').show(); 120 | $('#wpua-preview-existing').find('img:first').attr('src', b).show(); 121 | $('#wp-user-avatar-existing').val(a); 122 | $('#wp_user_avatar_radio').trigger('click') 123 | }) 124 | }); -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | === Custom User Avatar === 2 | Contributors: dartiss, properfraction, collizo4sky 3 | Tags: user profile, avatar, gravatar, author image, author photo, author avatar, bbPress, profile avatar, profile image, user avatar, user image, user photo, widget 4 | Requires at least: 4.0 5 | Tested up to: 5.7 6 | Stable tag: 1.0 7 | License: GPLv2 or later 8 | License URI: http://www.gnu.org/licenses/gpl-2.0.html 9 | 10 | 👤 Use any image from your WordPress Media Library as a custom user avatar or user profile picture. Add your own Default Avatar. 11 | 12 | == Description == 13 | 14 | WordPress currently only allows you to use custom avatars that are uploaded through [Gravatar](http://gravatar.com/). **Custom User Avatar** enables you to use any photo uploaded into your Media Library as an avatar. This means you use the same uploader and library as your posts. No extra folders or image editing functions are necessary. 15 | 16 | **This is a fork of the popular WP User Avatar plugin, before it became ProfilePress, and is free of all advertising. For details of what is different, please see the first item in the FAQ.** 17 | 18 | **Custom User Avatar** lets you: 19 | 20 | * Upload your own Default Avatar in your Custom User Avatar settings. 21 | * Show the user's [Gravatar](http://gravatar.com/) avatar or Default Avatar if the user doesn't have a Custom User Avatar image. 22 | * Disable [Gravatar](http://gravatar.com/) avatars and use only local avatars. 23 | * Use the [avatar_upload] shortcode to add a standalone uploader to a front page or widget. This uploader is only visible to logged-in users. 24 | * Use the [avatar] shortcode in your posts. These shortcodes will work with any theme, whether it has avatar support or not. 25 | * Allow Contributors and Subscribers to upload their own avatars. 26 | * Limit upload file size and image dimensions for Contributors and Subscribers. 27 | 28 | 👉 Please visit the [Github page](https://github.com/dartiss/custom-user-avatar "Github") for the latest code development, planned enhancements and known issues 👈 29 | 30 | == Installation == 31 | 32 | 1. Download, install, and activate the Custom User Avatar plugin. 33 | 2. On your profile edit page, click "Edit Image". 34 | 3. Choose an image, then click "Select Image". 35 | 4. Click "Update Profile". 36 | 5. Upload your own Default Avatar in your Custom User Avatar settings (optional). You can also allow Contributors & Subscribers to upload avatars and disable Gravatar. 37 | 6. Choose a theme that has avatar support. In your theme, manually replace get_avatar with get_wp_user_avatar or leave get_avatar as-is. [Read about the differences here](http://wordpress.org/extend/plugins/custom-user-avatar/faq/). 38 | 7. You can also use the [avatar_upload] and [avatar] shortcodes in your posts. These shortcodes will work with any theme, whether it has avatar support or not. 39 | 40 | **Example Usage** 41 | 42 | = Posts = 43 | 44 | Within [The Loop](http://codex.wordpress.org/The_Loop), you may be using: 45 | 46 | `` 47 | 48 | Replace this function with: 49 | 50 | `` 51 | 52 | You can also use the values "original", "large", "medium", or "thumbnail" for your avatar size: 53 | 54 | `` 55 | 56 | You can also add an alignment of "left", "right", or "center": 57 | 58 | `` 59 | 60 | = Author Page = 61 | 62 | On an author page outside of [The Loop](http://codex.wordpress.org/The_Loop), you may be using: 63 | 64 | `ID, 96); 67 | ?>` 68 | 69 | Replace this function with: 70 | 71 | `ID, 96); 74 | ?>` 75 | 76 | If you leave the options blank, Custom User Avatar will detect whether you're inside [The Loop](http://codex.wordpress.org/The_Loop) or on an author page and return the correct avatar in the default 96x96 size: 77 | 78 | `` 79 | 80 | The function get_wp_user_avatar can also fall back to get_avatar if there is no Custom User Avatar image. For this to work, "Show Avatars" must be checked in your Custom User Avatar settings. When this setting is enabled, you will see the user's [Gravatar](http://gravatar.com/) avatar or Default Avatar. 81 | 82 | = Comments = 83 | 84 | For comments, you might have in your template: 85 | 86 | `` 87 | 88 | Replace this function with: 89 | 90 | `` 91 | 92 | For comments, you must specify the $comment variable. 93 | 94 | **Other Available Functions** 95 | 96 | = [avatar_upload] shortcode = 97 | 98 | You can use the [avatar_upload] shortcode to add a standalone uploader to a front page or widget. This uploader is only visible to logged-in users. If you want to integrate the uploader into a profile edit page, see [Other Notes](http://wordpress.org/plugins/wp-user-avatar/other_notes/). 99 | 100 | You can specify a user with the shortcode, but you must have edit_user capability for that particular user. 101 | 102 | `[avatar_upload user="admin"]` 103 | 104 | = [avatar] shortcode = 105 | 106 | You can use the [avatar] shortcode in your posts. It will detect the author of the post or you can specify an author by username. You can specify a size, alignment, and link, but they are optional. For links, you can link to the original image file, attachment page, or a custom URL. 107 | 108 | `[avatar user="admin" size="medium" align="left" link="file" /]` 109 | 110 | You can also add a caption to the shortcode: 111 | 112 | `[avatar user="admin" size="medium" align="left" link="file"]Photo Credit: Your Name[/avatar]` 113 | 114 | **Note:** If you are using one shortcode without a caption and another shortcode with a caption on the same page, you must close the caption-less shortcode with a forward slash before the closing bracket: [avatar /] instead of [avatar] 115 | 116 | = get_wp_user_avatar_src = 117 | 118 | Works just like get_wp_user_avatar but returns just the image src. This is useful if you would like to link a thumbnail-sized avatar to a larger version of the image: 119 | 120 | ` 121 | 122 | ` 123 | 124 | = has_wp_user_avatar = 125 | 126 | Returns true if the user has a Custom User Avatar image. You must specify the user ID: 127 | 128 | `'; 133 | } 134 | ?>` 135 | 136 | == Frequently Asked Questions == 137 | 138 | = Why this was forked from WP User Avatar and what is different? = 139 | 140 | The original WP User Avatar, popular amongst users wishing to simple manager their site avatars, was renamed to ProfilePress at version 3.0 and made into a full membership plugin. A lot of users, however, didn't want the new functionality. On top of this, some people reported increasing errors and decreasing site speed as a result. Indeed, the resulting up-roar even made [WP Tavern](https://wptavern.com/profilepress-rebrands-and-repurposes-wp-user-avatar-now-a-membership-plugin-users-revolt-via-the-wordpress-review-system). 141 | 142 | This, therefore, is a fork of the plugin before all that occurred, at version 2.2.16. 143 | 144 | What has changed from that? Apart from renaming it, all advertising has been removed (and will remain removed), along with some redundant files. It also now uses the automatic translation service which comes as being part of the plugin directory. Other than that, a few minor tweaks have been made, but nothing you are likely to (yet) notice. 145 | 146 | What has been retained is the old naming of functions and settings - what this means is that if you used WP User Avatar before, your existing configuration will automatically work with this plugin as well. Shortcodes and functions calls too remain exactly the same too. 147 | 148 | = What are the future plans for this plugin? = 149 | 150 | Please see the [Github issues page](https://github.com/dartiss/custom-user-avatar/issues "Github") for full details, but essentially 151 | 152 | * Tidy up the existing code, including code quality 153 | * Compression of the plugin scripts 154 | * Improving the images being used by the plugin 155 | 156 | If you're aware of any bugs, please let me know, as I also want to get rid of many of those as possible. 157 | 158 | What you may notice is a lack of new features - that's not to say that won't happen, but I want to ensure stability. Let's improve the robustness of the code and consider new, shiny things after that. 159 | 160 | = How do I use Custom User Avatar? = 161 | 162 | First, choose a theme that has avatar support. In your theme, you have a choice of manually replacing get_avatar with get_wp_user_avatar, or leaving get_avatar as-is. Here are the differences: 163 | 164 | = get_wp_user_avatar = 165 | 166 | 1. Allows you to use the values "original", "large", "medium", or "thumbnail" for your avatar size. 167 | 2. Doesn't add a fixed width and height to the image if you use the aforementioned values. This will give you more flexibility to resize the image with CSS. 168 | 3. Allows you to use custom image sizes registered with [add_image_size](http://codex.wordpress.org/Function_Reference/add_image_size) (fixed width and height are added to the image). 169 | 4. Optionally adds CSS classes "alignleft", "alignright", or "aligncenter" to position your avatar. 170 | 5. Shows nothing if the user has no Custom User Avatar image. 171 | 6. Shows the user's [Gravatar](http://gravatar.com/) avatar or Default Avatar only if "Show Avatars" is enabled in your Custom User Avatar settings. 172 | 173 | = get_avatar = 174 | 175 | 1. Requires you to enable "Show Avatars" in your Custom User Avatar settings to show any avatars. 176 | 2. Accepts only numeric values for your avatar size. 177 | 3. Always adds a fixed width and height to your image. This may cause problems if you use responsive CSS in your theme. 178 | 4. Shows the user's [Gravatar](http://gravatar.com/) avatar or Default Avatar if the user doesn't have a Custom User Avatar image. (Choosing "Blank" as your Default Avatar still generates a transparent image file.) 179 | 5. Requires no changes to your theme files if you are currently using get_avatar. 180 | 181 | [Read more about get_avatar in the WordPress Function Reference](http://codex.wordpress.org/Function_Reference/get_avatar). 182 | 183 | = Can I create a custom Default Avatar? = 184 | In your Custom User Avatar settings, you can upload your own Default Avatar. 185 | 186 | = Can I disable all Gravatar avatars? = 187 | 188 | In your Custom User Avatar settings, you can select "Disable Gravatar — Use only local avatars" to disable all [Gravatar](http://gravatar.com/) avatars on your site and replace them with your Default Avatar. This will affect your registered users and non-registered comment authors. 189 | 190 | = Can Contributors or Subscribers choose their own Custom User Avatar image? = 191 | Yes, if you enable "Allow Contributors & Subscribers to upload avatars" in the Custom User Avatar settings. These users will see a slightly different interface because they are allowed only one image upload. 192 | 193 | = Will Custom User Avatar work with comment author avatars? = 194 | 195 | Yes, for registered users. Non-registered comment authors will show their [Gravatar](http://gravatar.com/) avatars or Default Avatar. 196 | 197 | = Will Custom User Avatar work with bbPress? = 198 | 199 | Yes! 200 | 201 | = Will Custom User Avatar work with BuddyPress? = 202 | 203 | No, BuddyPress has its own custom avatar functions and Custom User Avatar will override only some of them. It's best to use BuddyPress without Custom User Avatar. 204 | 205 | = How can I see which users have an avatar? = 206 | 207 | For Administrators, Custom User Avatar adds a column with avatar thumbnails to your Users list table. If "Show Avatars" is enabled in your Custom User Avatar settings, you will see avatars to the left of each username instead of in a new column. 208 | 209 | = Can I use the Custom User Avatar uploader in a front page or widget? = 210 | 211 | Yes, you can use the [avatar_upload] shortcode to put a standalone uploader in a front page or widget. This uploader is only visible to logged-in users. If you want to integrate the uploader into a profile edit page, see [Other Notes](http://wordpress.org/plugins/wp-user-avatar/other_notes/). 212 | 213 | You can specify a user with the shortcode, but you must have 'edit_user' capability to change the user's avatar. 214 | 215 | `[avatar_upload user="admin"]` 216 | 217 | = Can I insert Custom User Avatar directly into a post? = 218 | 219 | You can use the [avatar] shortcode in your posts. It will detect the author of the post or you can specify an author by username. You can specify a size, alignment, and link, but they are optional. For links, you can link to the original image file, attachment page, or a custom URL. 220 | 221 | `[avatar user="admin" size="96" align="left" link="file" /]` 222 | 223 | Outputs: 224 | 225 | ` 226 | 227 | ` 228 | 229 | If you have a caption, the output will be similar to how WordPress adds captions to other images. 230 | 231 | `[avatar user="admin" size="96" align="left" link="file"]Photo Credit: Your Name[/avatar]` 232 | 233 | Outputs: 234 | 235 | `
236 | 237 | 238 | 239 |

Photo Credit: Your Name

240 |
` 241 | 242 | **Note:** If you are using one shortcode without a caption and another shortcode with a caption on the same page, you must close the caption-less shortcode with a forward slash before the closing bracket: [avatar /] instead of [avatar] 243 | 244 | = What CSS can I use with Custom User Avatar? = 245 | 246 | Custom User Avatar will add the CSS classes "wp-user-avatar" and "wp-user-avatar-{size}" to your image. If you add an alignment, the corresponding alignment class will be added: 247 | 248 | `` 249 | 250 | Outputs: 251 | 252 | `` 253 | 254 | **Note:** "alignleft", "alignright", and aligncenter" are common WordPress CSS classes, but not every theme supports them. Contact the theme author to add those CSS classes. 255 | 256 | If you use the values "original", "large", "medium", or "thumbnail", no width or height will be added to the image. This will give you more flexibility to resize the image with CSS: 257 | 258 | `` 259 | 260 | Outputs: 261 | 262 | `` 263 | 264 | **Note:** WordPress adds more CSS classes to the avatar not listed here. 265 | 266 | If you use the [avatar] shortcode, Custom User Avatar will add the CSS class "wp-user-avatar-link" to the link. It will also add CSS classes based on link type. 267 | 268 | * Image File: wp-user-avatar-file 269 | * Attachment: wp-user-avatar-attachment 270 | * Custom URL: wp-user-avatar-custom 271 | 272 | `[avatar user="admin" size="96" align="left" link="attachment" /]` 273 | 274 | Outputs: 275 | 276 | ` 277 | 278 | ` 279 | 280 | = What other functions are available for Custom User Avatar? = 281 | * get_wp_user_avatar_src: retrieves just the image URL 282 | * has_wp_user_avatar: checks if the user has a Custom User Avatar image 283 | * [See example usage here](http://wordpress.org/extend/plugins/wp-user-avatar/installation/) 284 | 285 | == Advanced Settings == 286 | 287 | Visit [Custom User Avatar](http://wpuseravatar.com/) for more information and documentation. 288 | 289 | = Add Custom User Avatar to your own profile edit page = 290 | 291 | You can use the [avatar_upload] shortcode to add a standalone uploader to any page. It's best to use this uploader by itself and without other profile fields. 292 | 293 | If you're building your own profile edit page with other fields, Custom User Avatar is automatically added to the [show_user_profile](http://codex.wordpress.org/Plugin_API/Action_Reference/show_user_profile) and [edit_user_profile](http://codex.wordpress.org/Plugin_API/Action_Reference/show_user_profile) hooks. If you'd rather have Custom User Avatar in its own section, you could add another hook: 294 | 295 | `do_action('edit_user_avatar', $current_user);` 296 | 297 | Then, to add Custom User Avatar to that hook and remove it from the other hooks outside of the administration panel, you would add this code to the functions.php file of your theme: 298 | 299 | `function my_avatar_filter() { 300 | // Remove from show_user_profile hook 301 | remove_action('show_user_profile', array('wp_user_avatar', 'wpua_action_show_user_profile')); 302 | remove_action('show_user_profile', array('wp_user_avatar', 'wpua_media_upload_scripts')); 303 | 304 | // Remove from edit_user_profile hook 305 | remove_action('edit_user_profile', array('wp_user_avatar', 'wpua_action_show_user_profile')); 306 | remove_action('edit_user_profile', array('wp_user_avatar', 'wpua_media_upload_scripts')); 307 | 308 | // Add to edit_user_avatar hook 309 | add_action('edit_user_avatar', array('wp_user_avatar', 'wpua_action_show_user_profile')); 310 | add_action('edit_user_avatar', array('wp_user_avatar', 'wpua_media_upload_scripts')); 311 | } 312 | 313 | // Loads only outside of administration panel 314 | if(!is_admin()) { 315 | add_action('init','my_avatar_filter'); 316 | }` 317 | 318 | = HTML Wrapper = 319 | 320 | You can change the HTML wrapper of the Custom User Avatar section by using the functions wpua_before_avatar and wpua_after_avatar. By default, the avatar code is structured like this: 321 | 322 | `
323 |

Avatar

324 | 325 |

326 | 327 |

328 |

329 | 330 | Original Size 331 |

332 |

333 | 334 | Thumbnail 335 |

336 |

337 | 338 |

339 |

340 | 341 |

342 |
` 343 | 344 | To strip out the div container and h3 heading, you would add the following filters to the functions.php file in your theme: 345 | 346 | `remove_action('wpua_before_avatar', 'wpua_do_before_avatar'); 347 | remove_action('wpua_after_avatar', 'wpua_do_after_avatar');` 348 | 349 | To add your own wrapper, you could create something like this: 350 | 351 | `function my_before_avatar() { 352 | echo '
'; 353 | } 354 | add_action('wpua_before_avatar', 'my_before_avatar'); 355 | 356 | function my_after_avatar() { 357 | echo '
'; 358 | } 359 | add_action('wpua_after_avatar', 'my_after_avatar');` 360 | 361 | This would output: 362 | 363 | `
364 | 365 |

366 | 367 |

368 |

369 | 370 | Original Size 371 |

372 |

373 | 374 | Thumbnail 375 |

376 |

377 | 378 |

379 |

380 | 381 |

382 |
` 383 | 384 | == Screenshots == 385 | 386 | 1. Custom User Avatar admin settings. 387 | 2. Custom User Avatar lets you upload your own Default Avatar. 388 | 3. Custom User Avatar adds a field to your profile edit page. 389 | 4. After you've chosen a Custom User Avatar image, you will see the option to remove it. 390 | 391 | == Changelog == 392 | 393 | I use semantic versioning, with the first release being 1.0. 394 | 395 | = 1.0 = 396 | * Initial release 397 | 398 | == Upgrade Notice == 399 | 400 | = 1.0 = 401 | * Initial release -------------------------------------------------------------------------------- /uninstall.php: -------------------------------------------------------------------------------- 1 | ID, $wpdb->get_blog_prefix($blog->blog_id).'user_avatar'); 35 | } 36 | } 37 | foreach($blogs as $blog) { 38 | switch_to_blog($blog->blog_id); 39 | delete_option('avatar_default_wp_user_avatar'); 40 | delete_option('wp_user_avatar_allow_upload'); 41 | delete_option('wp_user_avatar_disable_gravatar'); 42 | delete_option('wp_user_avatar_edit_avatar'); 43 | delete_option('wp_user_avatar_load_scripts'); 44 | delete_option('wp_user_avatar_resize_crop'); 45 | delete_option('wp_user_avatar_resize_h'); 46 | delete_option('wp_user_avatar_resize_upload'); 47 | delete_option('wp_user_avatar_resize_w'); 48 | delete_option('wp_user_avatar_tinymce'); 49 | delete_option('wp_user_avatar_upload_size_limit'); 50 | delete_option('wp_user_avatar_default_avatar_updated'); 51 | delete_option('wp_user_avatar_media_updated'); 52 | delete_option('wp_user_avatar_users_updated'); 53 | delete_option('wpua_has_gravatar'); 54 | } 55 | } else { 56 | foreach($users as $user) { 57 | delete_user_meta($user->ID, $wpdb->get_blog_prefix($blog_id).'user_avatar'); 58 | } 59 | delete_option('avatar_default_wp_user_avatar'); 60 | delete_option('wp_user_avatar_allow_upload'); 61 | delete_option('wp_user_avatar_disable_gravatar'); 62 | delete_option('wp_user_avatar_edit_avatar'); 63 | delete_option('wp_user_avatar_load_scripts'); 64 | delete_option('wp_user_avatar_resize_crop'); 65 | delete_option('wp_user_avatar_resize_h'); 66 | delete_option('wp_user_avatar_resize_upload'); 67 | delete_option('wp_user_avatar_resize_w'); 68 | delete_option('wp_user_avatar_tinymce'); 69 | delete_option('wp_user_avatar_upload_size_limit'); 70 | delete_option('wp_user_avatar_default_avatar_updated'); 71 | delete_option('wp_user_avatar_media_updated'); 72 | delete_option('wp_user_avatar_users_updated'); 73 | delete_option('wpua_has_gravatar'); 74 | } 75 | 76 | // Delete post meta 77 | delete_post_meta_by_key('_wp_attachment_wp_user_avatar'); 78 | 79 | // Reset all default avatars to Mystery Man 80 | update_option('avatar_default', 'mystery'); 81 | --------------------------------------------------------------------------------