PluginProbe
Powerkit – Supercharge your WordPress Site / 2.9.0
Powerkit – Supercharge your WordPress Site v2.9.0
3.1.1 3.1.0 3.0.9 3.0.8 trunk 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 All 87 releases
powerkit / extensions / user / class-powerkit-user.php

class-powerkit-user.php in Powerkit – Supercharge your WordPress Site 2.9.0, at extensions/user/class-powerkit-user.php

123 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Gallery
4 *
5 * @package Powerkit
6 * @subpackage Extensions
7 */
8
9 if ( class_exists( 'Powerkit_Module' ) ) {
10 /**
11 * Init module
12 */
13 class Powerkit_User extends Powerkit_Module {
14
15 /**
16 * Register module
17 */
18 public function register() {
19 $this->name = 'user';
20 $this->slug = 'user';
21 $this->type = 'extension';
22 $this->category = 'basic';
23 $this->public = false;
24 $this->enabled = true;
25 }
26
27 /**
28 * Initialize module
29 */
30 public function initialize() {
31 // Helpers Functions for the module.
32 require_once dirname( __FILE__ ) . '/helpers/helper-powerkit-user.php';
33
34 // Filters.
35 add_filter( 'init', array( $this, 'powerkit_guest_support_meta' ) );
36 add_filter( 'pre_get_avatar', array( $this, 'powerkit_guest_support_avatar' ), 10, 3 );
37 add_filter( 'author_link', array( $this, 'powerkit_guest_support_link' ), 9999, 3 );
38 }
39
40 /**
41 * Add support meta info for guest authors.
42 */
43 public function powerkit_guest_support_meta() {
44 $fields = array(
45 'user_url',
46 'url',
47 'display_name',
48 'first_name',
49 'last_name',
50 'user_email',
51 'website',
52 'description',
53 );
54
55 foreach ( $fields as $field ) {
56 /**
57 * Filters the value of the requested user metadata.
58 *
59 * @param string $value The value of the metadata.
60 * @param int $user_id The user ID for the value.
61 * @param int|bool $original The original user ID, as passed to the function.
62 */
63 add_filter( 'get_the_author_' . $field, function( $value, $user_id, $original = null ) use ( $field ) {
64 if ( powerkit_is_guest( $user_id ) && empty( $value ) ) {
65 $guest_value = powerkit_get_guest_meta( $field, $user_id );
66 if ( $guest_value ) {
67 $value = $guest_value;
68 }
69 }
70 return $value;
71 }, 10, 3 );
72 }
73 }
74
75 /**
76 * Add support avatar for guest authors.
77 *
78 * @param string $link The URL to the author's page.
79 * @param int $author_id The author's id.
80 * @param string $author_nicename The author's nice name.
81 */
82 public function powerkit_guest_support_link( $link, $author_id, $author_nicename ) {
83 global $wp_rewrite;
84
85 if ( powerkit_is_guest( $author_id ) ) {
86 $guest = powerkit_get_guest_meta( 'user_login', $author_id );
87
88 if ( $guest ) {
89 $link = $wp_rewrite->get_author_permastruct();
90
91 $link = str_replace( '%author%', $guest, $link );
92
93 $link = home_url( user_trailingslashit( $link ) );
94 }
95 }
96 return $link;
97 }
98
99 /**
100 * Add support avatar for guest authors.
101 *
102 * @param string $avatar HTML for the user's avatar. Default null.
103 * @param mixed $id_or_email The Gravatar to retrieve.
104 * @param array $args Arguments passed to get_avatar_url(), after processing.
105 */
106 public function powerkit_guest_support_avatar( $avatar, $id_or_email, $args ) {
107 if ( powerkit_is_guest( $id_or_email ) && empty( $avatar ) ) {
108 $guest_avatar = coauthors_get_avatar( (object) array(
109 'ID' => $id_or_email,
110 'type' => 'guest-author',
111 ), $args['size'] );
112
113 if ( $guest_avatar ) {
114 $avatar = $guest_avatar;
115 }
116 }
117 return $avatar;
118 }
119 }
120
121 new Powerkit_User();
122 }
123