PluginProbe
Gianism / trunk
Gianism vtrunk
4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.4.0 5.0.0 5.0.1 5.0.2 5.1.0 5.2.1 5.2.2 5.3.0 6.0.0 6.0.1 trunk 1.0 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 All 65 releases
gianism / app / Gianism / Controller / Profile.php

Profile.php in Gianism trunk, at app/Gianism/Controller/Profile.php

144 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Gianism\Controller;
4
5 use Gianism\Pattern\AbstractController;
6
7 /**
8 * Profile page controller
9 *
10 * @package Gianism
11 * @since 2.0.0
12 * @author Takahashi Fumiki
13 */
14 class Profile extends AbstractController {
15
16 /**
17 * Constructor
18 *
19 * @param array $argument
20 */
21 protected function __construct( array $argument = [] ) {
22 parent::__construct( $argument );
23 // If not enabled, skip.
24 if ( ! $this->option->is_enabled() ) {
25 return;
26 }
27 if ( $this->option->is_network_activated() && $this->network->is_child_site() ) {
28 // If this is network child, display parent site link.
29 add_action( 'show_user_profile', [ $this, 'parent_site_link' ] );
30 } else {
31 add_action( 'show_user_profile', [ $this, 'admin_connect_buttons' ] );
32 add_action( 'profile_update', [ $this, 'profile_updated' ], 10, 2 );
33 }
34 // Show connection button on admin screen.
35 }
36
37 /**
38 * Update password and delete meta
39 *
40 * @param int $user_id
41 * @param object $old_user_data
42 */
43 public function profile_updated( $user_id, $old_user_data ) {
44 $current_user = get_userdata( $user_id );
45 // Check if password is on your own.
46 if ( $this->profile_checker->is_password_unknown( $user_id ) && $current_user->user_pass !== $old_user_data->user_pass ) {
47 // Password changed
48 delete_user_meta( $user_id, '_wpg_unknown_password' );
49 $this->add_message( __( 'Your password is now on your own!', 'wp-gianism' ) );
50 }
51 // Check if email is proper and old one is pseudo
52 if ( $old_user_data->user_email !== $current_user->user_email && $this->profile_checker->is_pseudo_mail( $old_user_data->user_email ) ) {
53 if ( $this->profile_checker->is_pseudo_mail( $current_user->user_email ) ) {
54 // email isn't changed.
55 $this->add_message( $this->_( 'You mail address is still pseudo one! Please change it to valid one.' ), true );
56 } else {
57 // O.K.
58 $this->add_message( $this->_( 'Your email seems to be valid now.' ) );
59 }
60 }
61 }
62
63 /**
64 * Show connect buttons
65 *
66 * @param \WP_User $user
67 */
68 public function admin_connect_buttons( \WP_User $user ) {
69 $notices = $this->profile_notices( $user );
70 ?>
71 <h3 class="wpg-connect-header">
72 <i class="lsf lsf-link"></i> <?php $this->e( 'Connection with SNS' ); ?>
73 </h3>
74 <?php if ( ! empty( $notices->get_error_messages() ) ) : ?>
75 <ul class="wpg-notice">
76 <?php foreach ( $notices->get_error_messages() as $msg ) : ?>
77 <li><?php echo wp_kses_post( $msg ); ?></li>
78 <?php endforeach; ?>
79 </ul>
80 <?php endif; ?>
81 <table class="form-table wpg-connect-table">
82 <tbody>
83 <?php do_action( 'gianism_user_profile', $user ); ?>
84 </tbody>
85 </table>
86 <?php
87 }
88
89 /**
90 * Get error message to display.
91 *
92 * @param \WP_User $user
93 * @return \WP_Error
94 */
95 public function profile_notices( $user ) {
96 $error = new \WP_Error();
97 // show password notice
98 if ( get_user_meta( $user->ID, '_wpg_unknown_password', true ) ) {
99 $error->add( 'unknown_password', __( 'Your password is automatically generated. Please <strong><a href="#pass1">update password</a> to your own</strong> before disconnecting your account.', 'wp-gianism' ) );
100 }
101 // Check if mail address is pseudo
102 if ( $this->profile_checker->is_pseudo_mail( $user->user_email ) ) {
103 $error->add( 'invalid_email', __( 'Your mail address is automatically generated and is pseudo. <a href="#email">Changing it</a> to valid mail address is highly recommended, else <strong>you might be unable to log in</strong>.', 'wp-gianism' ) );
104 }
105 return apply_filters( 'gianism_user_profile_notices', $error, $user );
106 }
107
108 /**
109 * Display parent site link.
110 *
111 * @param \WP_User $user
112 */
113 public function parent_site_link( \WP_User $user ) {
114 ?>
115 <h3 class="wpg-connect-header">
116 <?php $this->e( 'Connection with SNS' ); ?>
117 </h3>
118 <p>
119 <?php
120 echo wp_kses_post(
121 sprintf(
122 // translators: %s is admin url.
123 __( 'Please setup SNS connection at <a href="%s">parent site\'s profile page</a>.', 'wp-gianism' ),
124 get_admin_url( $this->option->get_parent_blog_id(), 'profile.php' )
125 )
126 );
127 ?>
128 </p>
129 <?php
130 }
131
132 /**
133 * Detect if mail address contains @pseudo
134 *
135 * @param string $email
136 * @deprecated 4.2.0
137 *
138 * @return bool
139 */
140 private function has_pseudo_segment( $email ) {
141 return false !== strpos( $email, '@pseudo.' );
142 }
143 }
144