89 /** |
89 /** |
90 * Retrieve user info by a given field |
90 * Retrieve user info by a given field |
91 * |
91 * |
92 * @since 2.8.0 |
92 * @since 2.8.0 |
93 * @since 4.4.0 Added 'ID' as an alias of 'id' for the `$field` parameter. |
93 * @since 4.4.0 Added 'ID' as an alias of 'id' for the `$field` parameter. |
|
94 * @since 5.8.0 Returns the global `$current_user` if it's the user being fetched. |
|
95 * |
|
96 * @global WP_User $current_user The current user object which holds the user data. |
94 * |
97 * |
95 * @param string $field The field to retrieve the user with. id | ID | slug | email | login. |
98 * @param string $field The field to retrieve the user with. id | ID | slug | email | login. |
96 * @param int|string $value A value for $field. A user ID, slug, email address, or login name. |
99 * @param int|string $value A value for $field. A user ID, slug, email address, or login name. |
97 * @return WP_User|false WP_User object on success, false on failure. |
100 * @return WP_User|false WP_User object on success, false on failure. |
98 */ |
101 */ |
99 function get_user_by( $field, $value ) { |
102 function get_user_by( $field, $value ) { |
|
103 global $current_user; |
|
104 |
100 $userdata = WP_User::get_data_by( $field, $value ); |
105 $userdata = WP_User::get_data_by( $field, $value ); |
101 |
106 |
102 if ( ! $userdata ) { |
107 if ( ! $userdata ) { |
103 return false; |
108 return false; |
|
109 } |
|
110 |
|
111 if ( $current_user instanceof WP_User && $current_user->ID === (int) $userdata->ID ) { |
|
112 return $current_user; |
104 } |
113 } |
105 |
114 |
106 $user = new WP_User; |
115 $user = new WP_User; |
107 $user->init( $userdata ); |
116 $user->init( $userdata ); |
108 |
117 |
156 * |
165 * |
157 * The default charset is based on the charset used on the blog. The charset can |
166 * The default charset is based on the charset used on the blog. The charset can |
158 * be set using the {@see 'wp_mail_charset'} filter. |
167 * be set using the {@see 'wp_mail_charset'} filter. |
159 * |
168 * |
160 * @since 1.2.1 |
169 * @since 1.2.1 |
|
170 * @since 5.5.0 is_email() is used for email validation, |
|
171 * instead of PHPMailer's default validator. |
161 * |
172 * |
162 * @global PHPMailer\PHPMailer\PHPMailer $phpmailer |
173 * @global PHPMailer\PHPMailer\PHPMailer $phpmailer |
163 * |
174 * |
164 * @param string|array $to Array or comma-separated list of email addresses to send message. |
175 * @param string|string[] $to Array or comma-separated list of email addresses to send message. |
165 * @param string $subject Email subject |
176 * @param string $subject Email subject. |
166 * @param string $message Message contents |
177 * @param string $message Message contents. |
167 * @param string|array $headers Optional. Additional headers. |
178 * @param string|string[] $headers Optional. Additional headers. |
168 * @param string|array $attachments Optional. Files to attach. |
179 * @param string|string[] $attachments Optional. Paths to files to attach. |
169 * @return bool Whether the email contents were sent successfully. |
180 * @return bool Whether the email was sent successfully. |
170 */ |
181 */ |
171 function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) { |
182 function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) { |
172 // Compact the input, apply the filters, and extract them back out. |
183 // Compact the input, apply the filters, and extract them back out. |
173 |
184 |
174 /** |
185 /** |
175 * Filters the wp_mail() arguments. |
186 * Filters the wp_mail() arguments. |
176 * |
187 * |
177 * @since 2.2.0 |
188 * @since 2.2.0 |
178 * |
189 * |
179 * @param array $args A compacted array of wp_mail() arguments, including the "to" email, |
190 * @param array $args { |
180 * subject, message, headers, and attachments values. |
191 * Array of the `wp_mail()` arguments. |
|
192 * |
|
193 * @type string|string[] $to Array or comma-separated list of email addresses to send message. |
|
194 * @type string $subject Email subject. |
|
195 * @type string $message Message contents. |
|
196 * @type string|string[] $headers Additional headers. |
|
197 * @type string|string[] $attachments Paths to files to attach. |
|
198 * } |
181 */ |
199 */ |
182 $atts = apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ); |
200 $atts = apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ); |
|
201 |
|
202 /** |
|
203 * Filters whether to preempt sending an email. |
|
204 * |
|
205 * Returning a non-null value will short-circuit {@see wp_mail()}, returning |
|
206 * that value instead. A boolean return value should be used to indicate whether |
|
207 * the email was successfully sent. |
|
208 * |
|
209 * @since 5.7.0 |
|
210 * |
|
211 * @param null|bool $return Short-circuit return value. |
|
212 * @param array $atts { |
|
213 * Array of the `wp_mail()` arguments. |
|
214 * |
|
215 * @type string|string[] $to Array or comma-separated list of email addresses to send message. |
|
216 * @type string $subject Email subject. |
|
217 * @type string $message Message contents. |
|
218 * @type string|string[] $headers Additional headers. |
|
219 * @type string|string[] $attachments Paths to files to attach. |
|
220 * } |
|
221 */ |
|
222 $pre_wp_mail = apply_filters( 'pre_wp_mail', null, $atts ); |
|
223 |
|
224 if ( null !== $pre_wp_mail ) { |
|
225 return $pre_wp_mail; |
|
226 } |
183 |
227 |
184 if ( isset( $atts['to'] ) ) { |
228 if ( isset( $atts['to'] ) ) { |
185 $to = $atts['to']; |
229 $to = $atts['to']; |
186 } |
230 } |
187 |
231 |
1130 * 2 if the nonce is valid and generated between 12-24 hours ago. |
1174 * 2 if the nonce is valid and generated between 12-24 hours ago. |
1131 * False if the nonce is invalid. |
1175 * False if the nonce is invalid. |
1132 */ |
1176 */ |
1133 function check_admin_referer( $action = -1, $query_arg = '_wpnonce' ) { |
1177 function check_admin_referer( $action = -1, $query_arg = '_wpnonce' ) { |
1134 if ( -1 === $action ) { |
1178 if ( -1 === $action ) { |
1135 _doing_it_wrong( __FUNCTION__, __( 'You should specify a nonce action to be verified by using the first parameter.' ), '3.2.0' ); |
1179 _doing_it_wrong( __FUNCTION__, __( 'You should specify an action to be verified by using the first parameter.' ), '3.2.0' ); |
1136 } |
1180 } |
1137 |
1181 |
1138 $adminurl = strtolower( admin_url() ); |
1182 $adminurl = strtolower( admin_url() ); |
1139 $referer = strtolower( wp_get_referer() ); |
1183 $referer = strtolower( wp_get_referer() ); |
1140 $result = isset( $_REQUEST[ $query_arg ] ) ? wp_verify_nonce( $_REQUEST[ $query_arg ], $action ) : false; |
1184 $result = isset( $_REQUEST[ $query_arg ] ) ? wp_verify_nonce( $_REQUEST[ $query_arg ], $action ) : false; |
1175 * 2 if the nonce is valid and generated between 12-24 hours ago. |
1219 * 2 if the nonce is valid and generated between 12-24 hours ago. |
1176 * False if the nonce is invalid. |
1220 * False if the nonce is invalid. |
1177 */ |
1221 */ |
1178 function check_ajax_referer( $action = -1, $query_arg = false, $die = true ) { |
1222 function check_ajax_referer( $action = -1, $query_arg = false, $die = true ) { |
1179 if ( -1 == $action ) { |
1223 if ( -1 == $action ) { |
1180 _doing_it_wrong( __FUNCTION__, __( 'You should specify a nonce action to be verified by using the first parameter.' ), '4.7' ); |
1224 _doing_it_wrong( __FUNCTION__, __( 'You should specify an action to be verified by using the first parameter.' ), '4.7.0' ); |
1181 } |
1225 } |
1182 |
1226 |
1183 $nonce = ''; |
1227 $nonce = ''; |
1184 |
1228 |
1185 if ( $query_arg && isset( $_REQUEST[ $query_arg ] ) ) { |
1229 if ( $query_arg && isset( $_REQUEST[ $query_arg ] ) ) { |
2721 $avatar = sprintf( |
2765 $avatar = sprintf( |
2722 "<img alt='%s' src='%s' srcset='%s' class='%s' height='%d' width='%d' %s/>", |
2766 "<img alt='%s' src='%s' srcset='%s' class='%s' height='%d' width='%d' %s/>", |
2723 esc_attr( $args['alt'] ), |
2767 esc_attr( $args['alt'] ), |
2724 esc_url( $url ), |
2768 esc_url( $url ), |
2725 esc_url( $url2x ) . ' 2x', |
2769 esc_url( $url2x ) . ' 2x', |
2726 esc_attr( join( ' ', $class ) ), |
2770 esc_attr( implode( ' ', $class ) ), |
2727 (int) $args['height'], |
2771 (int) $args['height'], |
2728 (int) $args['width'], |
2772 (int) $args['width'], |
2729 $extra_attr |
2773 $extra_attr |
2730 ); |
2774 ); |
2731 |
2775 |
2803 |
2847 |
2804 if ( ! $diff ) { |
2848 if ( ! $diff ) { |
2805 return ''; |
2849 return ''; |
2806 } |
2850 } |
2807 |
2851 |
2808 $r = "<table class='diff'>\n"; |
2852 $is_split_view = ! empty( $args['show_split_view'] ); |
2809 |
2853 $is_split_view_class = $is_split_view ? ' is-split-view' : ''; |
2810 if ( ! empty( $args['show_split_view'] ) ) { |
2854 |
2811 $r .= "<col class='content diffsplit left' /><col class='content diffsplit middle' /><col class='content diffsplit right' />"; |
2855 $r = "<table class='diff$is_split_view_class'>\n"; |
2812 } else { |
2856 |
2813 $r .= "<col class='content' />"; |
2857 if ( $args['title'] ) { |
2814 } |
2858 $r .= "<caption class='diff-title'>$args[title]</caption>\n"; |
2815 |
2859 } |
2816 if ( $args['title'] || $args['title_left'] || $args['title_right'] ) { |
2860 |
|
2861 if ( $args['title_left'] || $args['title_right'] ) { |
2817 $r .= '<thead>'; |
2862 $r .= '<thead>'; |
2818 } |
2863 } |
2819 if ( $args['title'] ) { |
2864 |
2820 $r .= "<tr class='diff-title'><th colspan='4'>$args[title]</th></tr>\n"; |
|
2821 } |
|
2822 if ( $args['title_left'] || $args['title_right'] ) { |
2865 if ( $args['title_left'] || $args['title_right'] ) { |
|
2866 $th_or_td_left = empty( $args['title_left'] ) ? 'td' : 'th'; |
|
2867 $th_or_td_right = empty( $args['title_right'] ) ? 'td' : 'th'; |
|
2868 |
2823 $r .= "<tr class='diff-sub-title'>\n"; |
2869 $r .= "<tr class='diff-sub-title'>\n"; |
2824 $r .= "\t<td></td><th>$args[title_left]</th>\n"; |
2870 $r .= "\t<$th_or_td_left>$args[title_left]</$th_or_td_left>\n"; |
2825 $r .= "\t<td></td><th>$args[title_right]</th>\n"; |
2871 if ( $is_split_view ) { |
|
2872 $r .= "\t<$th_or_td_right>$args[title_right]</$th_or_td_right>\n"; |
|
2873 } |
2826 $r .= "</tr>\n"; |
2874 $r .= "</tr>\n"; |
2827 } |
2875 } |
2828 if ( $args['title'] || $args['title_left'] || $args['title_right'] ) { |
2876 |
|
2877 if ( $args['title_left'] || $args['title_right'] ) { |
2829 $r .= "</thead>\n"; |
2878 $r .= "</thead>\n"; |
2830 } |
2879 } |
2831 |
2880 |
2832 $r .= "<tbody>\n$diff\n</tbody>\n"; |
2881 $r .= "<tbody>\n$diff\n</tbody>\n"; |
2833 $r .= '</table>'; |
2882 $r .= '</table>'; |