PluginProbe
WPCOM Member / 1.7.21
WPCOM Member v1.7.21
1.7.27 1.7.26 1.7.25 1.7.24 1.7.23 1.7.22 1.7.21 trunk 1.0.11 1.1.7 1.2.11 1.3.14 1.4.0 1.5.1.4 1.5.2.1 1.5.3.2 1.5.4 1.5.4.1 1.5.5 1.5.5.1 1.5.6 1.5.7 1.6.0 1.7.0 1.7.1 All 44 releases
wpcom-member / includes / functions.php

functions.php in WPCOM Member 1.7.21, at includes/functions.php

969 lines 36.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php defined('ABSPATH') || exit;
2
3 use WPCOM\Member;
4 use WPCOM\Themer\Session;
5 use WPCOM\Themer\Plugin;
6
7 add_action('after_setup_theme', 'wpmx_init', 9);
8 function wpmx_init() {
9 $wpmx_info = array(
10 'slug' => 'wpcom-member',
11 'name' => '用户中心',
12 'ver' => WPMX_VERSION,
13 'title' => '用户中心',
14 'icon' => 'dashicons-wpcom-logo',
15 'position' => 72,
16 'key' => 'wpmx_options',
17 'plugin_id' => 'wpmx',
18 'basename' => plugin_basename(__FILE__)
19 );
20
21 require_once WPCOM_ADMIN_FREE_PATH . 'load.php';
22 $panel_class = class_exists(Plugin\Panel_Free::class) ? Plugin\Panel_Free::class : \WPCOM_PLUGIN_PANEL_FREE::class;
23 $GLOBALS['wpmx'] = new $panel_class($wpmx_info);
24 $wpmx_options = get_option($wpmx_info['key']);
25 $GLOBALS[$wpmx_info['key']] = $wpmx_options;
26
27 load_plugin_textdomain( WPMX_TD, false, basename( WPMX_DIR ) . '/lang' );
28
29 require_once WPMX_DIR . 'includes/member-functions.php';
30 require_once WPMX_DIR . 'includes/form-validation.php';
31 require_once WPMX_DIR . 'includes/class-member.php';
32 $GLOBALS['wpcom_member'] = new Member\Member();
33 require_once WPMX_DIR . 'includes/link-template.php';
34 require_once WPMX_DIR . 'includes/nav-menu.php';
35 require_once WPMX_DIR . 'includes/required.php';
36 if( !class_exists('\WPCOM_Session') && !class_exists( Session::class ) ) {
37 require_once WPMX_DIR . 'includes/class-sesstion.php';
38 add_action( 'wpcom_sessions_clear', array( Session::class, 'cron') );
39 }else if( !class_exists( Session::class ) ){ // �
40 �容旧版本主题
41 require_once WPMX_DIR . 'includes/class-sesstion.php';
42 }
43
44 add_action('wp_enqueue_scripts', 'wpmx_scripts');
45 add_action('admin_enqueue_scripts', 'wpmx_scripts');
46 }
47
48 add_filter('pre_option_wpmx_options', function($pre_option, $option){
49 if(function_exists('wpcom_setup') && !defined('WPCOM_MP_VERSION')){
50 $alloptions = wp_load_alloptions();
51 if ( !isset( $alloptions[ $option ] ) ) $pre_option = 1;
52 }
53 return apply_filters( "option_{$option}", $pre_option, $option );
54 }, 5, 2);
55
56 add_filter('option_wpmx_options', 'wpmx_old_theme_options');
57 function wpmx_old_theme_options($value){
58 // 设置选项需要�
59 �容主题的设置选项
60 if(function_exists('wpcom_setup') && !defined('WPCOM_MP_VERSION')){
61 global $options, $wpcom_panel;
62 $options = $options ?: array();
63 // 插件原�
64 �有数据的话,则迁移到主题
65 if(!empty($value) && is_array($value)){
66 foreach($value as $k => $v){
67 $options[$k] = $v;
68 }
69 // �
70 空插件的设置数据
71 if($wpcom_panel->set_theme_options($options)) delete_option('wpmx_options');
72 }
73 $value = $options;
74 }else if(empty($value) && $options = get_option('izt_theme_options')){ // 设置选项为空,可能是刚安�
75 插件,检查下是否有原来主题的设置选项
76 if(is_string($options)) $options = json_decode($options, true);
77 if(!empty($options)) $value = $options;
78 }
79 return $value;
80 }
81
82 add_action( 'admin_init', 'wpmx_admin_setup' );
83 function wpmx_admin_setup(){
84 if (!wp_next_scheduled ( 'wpcom_sessions_clear' )) wp_schedule_event(time(), 'hourly', 'wpcom_sessions_clear');
85 }
86
87 add_action('admin_menu', 'wpmx_admin_menu', 20);
88 function wpmx_admin_menu(){
89 // 移除用户中心�
90 �费版�
91 �口
92 if(defined('WPCOM_MP_VERSION') || function_exists('wpcom_setup')) remove_menu_page('wpcom-member');
93 }
94
95 function wpmx_scripts(){
96 $action = current_filter();
97 if ($action === 'wp_enqueue_scripts') {
98 global $wpmx_options;
99 wp_enqueue_script('wpcom-member', WPMX_URI . 'js/index.js', array('jquery'), WPMX_VERSION, true);
100 wp_enqueue_style('wpcom-member', WPMX_URI . 'css/style.css', array(), WPMX_VERSION);
101
102 // 图标库版本处理,�
103 �容主题和�
104 �他插件
105 $load_icon = true;
106 $ver = '2.8.9';
107 if(wp_script_is('wpcom-icons')){
108 $cur_version = isset(wp_scripts()->registered['wpcom-icons']) ? wp_scripts()->registered['wpcom-icons']->ver : '';
109 if(!$cur_version || version_compare($cur_version, $ver, '<')){ // 当前版本低,需要替换
110 wp_deregister_script('wpcom-icons');
111 }else{ // 不替换不注册
112 $load_icon = false;
113 }
114 }
115 if($load_icon) wp_register_script('wpcom-icons', WPMX_URI . 'js/icons-' . $ver . '.js', array(), $ver, true);
116
117 wp_enqueue_script('wpcom-icons');
118
119 if(!function_exists('wpcom_setup')){
120 $color = isset($wpmx_options['member_color']) && $wpmx_options['member_color'] ? $wpmx_options['member_color'] : '#206be7';
121 $hover = isset($wpmx_options['member_hover_color']) && $wpmx_options['member_hover_color'] ? $wpmx_options['member_hover_color'] : '#1162e8';
122 if($color || $hover){
123 $custom_css = ':root{'.($color?'--member-color: '.$color.';':'').($hover?'--member-hover: '.$hover.';':'').'}';
124 wp_add_inline_style( 'wpcom-member', $custom_css );
125 }
126 }
127
128 $script = array(
129 'ajaxurl' => admin_url( 'admin-ajax.php'),
130 'plugin_url' => WPMX_URI,
131 'ver' => WPMX_VERSION,
132 'max_upload_size' => wp_max_upload_size()
133 );
134 if(is_singular()) $script['post_id'] = get_queried_object_id();
135 if($wpmx_options && isset($wpmx_options['sl_wechat_follow']) && $wpmx_options['sl_wechat_follow']){
136 foreach ($wpmx_options['sl_wechat_follow'] as $i => $f){
137 if($f) {
138 $script['wechat_follow'] = 1;
139 if(isset($wpmx_options['sl_wechat2_type']) && isset($wpmx_options['sl_wechat2_type'][$i]) && $wpmx_options['sl_wechat2_type'][$i]){
140 $script['wechat_follow_reply'] = isset($wpmx_options['sl_wechat2_keyword'][$i]) && $wpmx_options['sl_wechat2_keyword'][$i] ? $wpmx_options['sl_wechat2_keyword'][$i] : '登录';
141 }
142 break;
143 }
144 }
145 }
146 $wpmx_js = apply_filters('wpmx_localize_script', $script);
147 wp_localize_script( 'wpcom-member', '_wpmx_js', $wpmx_js );
148 }else{
149 wp_enqueue_style('wpcom-member', WPMX_URI . 'css/admin.css', array(), WPMX_VERSION);
150 }
151 }
152
153 function wpmx_icon($name, $echo = true, $class='', $alt='icon'){
154 if(class_exists('WPCOM')) return WPCOM::icon($name, $echo, $class, $alt);
155 $_name = explode(':', $name);
156 switch ($_name[0]){
157 case 'mti':
158 $name = preg_replace('/^mti:/i', '', $name);
159 $str = '<i class="wpcom-icon material-icons'.($class?' '.$class:'').'">'.$name.'</i>';
160 break;
161 case 'if':
162 $name = preg_replace('/^if:/i', '', $name);
163 $str = '<i class="wpcom-icon'.($class?' '.$class:'').'"><svg aria-hidden="true"><use xlink:href="#icon-'.$name.'"></use></svg></i>';
164 break;
165 case 'fa':
166 $name = preg_replace('/^fa:/i', '', $name);
167 $str = '<i class="wpcom-icon fa fa-'.$name.($class?' '.$class:'').'"></i>';
168 break;
169 case 'ri':
170 $name = preg_replace('/^ri:/i', '', $name);
171 $str = '<i class="wpcom-icon ri-'.$name.($class?' '.$class:'').'"></i>';
172 break;
173 case 'http':
174 case 'https':
175 $str = '<i class="wpcom-icon'.($class?' '.$class:'').'"><img class="j-lazy" src="' . esc_url($name) . '" alt="' . esc_attr($alt) . '" /></i>';
176 break;
177 default:
178 if(preg_match('/^\/\//', $name)){ // "//"开头的地址需要单独匹�
179
180 $str = '<i class="wpcom-icon'.($class?' '.$class:'').'"><img class="j-lazy" src="' . esc_url($name) . '" alt="' . esc_attr($alt) . '" /></i>';
181 }else{
182 $str = '<i class="wpcom-icon wi'.($class?' '.$class:'').'"><svg aria-hidden="true"><use xlink:href="#wi-'.$name.'"></use></svg></i>';
183 }
184 }
185
186 if($echo) {
187 echo wp_kses( $str, wpmx_allowed_html() );
188 } else {
189 return wp_kses( $str, wpmx_allowed_html() );
190 }
191 }
192
193 function wpmx_comment_status(){
194 $status = false;
195 if ( get_default_comment_status() === 'open' ) {
196 $status = true;
197 if(function_exists('wpcom_setup')){
198 global $options;
199 if( !(isset($options['comments_open']) && $options['comments_open']=='1') ){
200 $status = false;
201 }
202 }
203 }
204 return $status;
205 }
206
207 add_action( 'woocommerce_before_edit_account_address_form', 'wc_print_notices', 10 );
208 add_filter( 'woocommerce_account_menu_items', 'wpcom_woo_account_menu_items' );
209 function wpcom_woo_account_menu_items( $items ){
210 $items['orders'] = __('Orders', WPMX_TD);
211 $items['downloads'] = __('Downloads', WPMX_TD);
212 $items['edit-address'] = __('Addresses', WPMX_TD);
213 unset($items['dashboard']);
214 unset($items['edit-account']);
215 unset($items['customer-logout']);
216 return $items;
217 }
218
219 add_filter( 'woocommerce_get_cancel_order_url', 'wpcom_woo_cancel_order_url' );
220 function wpcom_woo_cancel_order_url( $url ){
221 preg_match('/order_id=([\d]+)/i', $url, $matches);
222 if(isset($matches[1]) && $matches[1]){
223 $order = wc_get_order( $matches[1] );
224 $url = wp_nonce_url(
225 add_query_arg(
226 array(
227 'cancel_order' => 'true',
228 'order' => $order->get_order_key(),
229 'order_id' => $order->get_id(),
230 'redirect' => wpcom_subpage_url('orders'),
231 ), $order->get_cancel_endpoint()
232 ), 'woocommerce-cancel_order'
233 );
234 }
235 return $url;
236 }
237
238 add_filter( 'woocommerce_is_account_page', 'wpcom_wc_is_account_page' );
239 function wpcom_wc_is_account_page( $res ){
240 return is_wpcom_member_page();
241 }
242
243 add_filter( 'wpcom_account_tabs', 'wpcom_woo_add_tabs' );
244 function wpcom_woo_add_tabs( $tabs ){
245 if( !function_exists('is_woocommerce') ) return $tabs;
246
247 $orders = get_option( 'woocommerce_myaccount_orders_endpoint', 'orders' );
248 $downloads = get_option( 'woocommerce_myaccount_downloads_endpoint', 'downloads' );
249 $edit_address = get_option( 'woocommerce_myaccount_edit_address_endpoint', 'edit-address' );
250 $view_order = get_option( 'woocommerce_myaccount_view_order_endpoint', 'view-order' );
251
252 if($orders) {
253 $tabs[25] = array(
254 'slug' => $orders,
255 'title' => defined('WPCOM_MP_VERSION') ? _x('Orders', 'shop', WPMX_TD) : __('Orders', WPMX_TD),
256 'icon' => defined('WPCOM_MP_VERSION') ? 'shop-orders' : 'order-circle',
257 'shadow' => defined('WPCOM_MP_VERSION')
258 );
259 add_action( 'wpcom_account_tabs_'.$orders, 'wpcom_account_tabs_orders' );
260 }
261
262 if($downloads) {
263 $tabs[26] = array(
264 'slug' => $downloads,
265 'title' => __('Downloads', WPMX_TD),
266 'icon' => 'download-circle'
267 );
268 add_action( 'wpcom_account_tabs_'.$downloads, 'wpcom_account_tabs_downloads' );
269 }
270 if($edit_address) {
271 $tabs[27] = array(
272 'slug' => $edit_address,
273 'title' => __('Addresses', WPMX_TD),
274 'icon' => 'address-circle'
275 );
276 add_action( 'wpcom_account_tabs_'.$edit_address, 'wpcom_account_tabs_address' );
277
278 }
279 if($view_order) {
280 $tabs[9999] = array(
281 'slug' => $view_order,
282 'title' => __('Orders', WPMX_TD),
283 'icon' => 'order-circle',
284 'parent' => 'orders'
285 );
286 add_action( 'wpcom_account_tabs_'.$view_order, 'wpcom_account_tabs_view_order' );
287 }
288
289 return $tabs;
290 }
291
292 add_filter('woocommerce_get_view_order_url', 'wpcom_woo_order_url', 10, 2);
293 function wpcom_woo_order_url($url, $that){
294 $permalink_structure = get_option('permalink_structure');
295 if(!$permalink_structure){ // 默认链接规则
296 $view_order = get_option( 'woocommerce_myaccount_view_order_endpoint', 'view-order' );
297 $page = wpcom_subpage_url($view_order);
298 $url = add_query_arg( 'pageid', $that->get_id(), $page );
299 }
300 return $url;
301 }
302
303 function wpcom_account_tabs_orders() {
304 $page = get_query_var('pageid') ? get_query_var('pageid') : 1;
305 ?>
306 <div class="woocommerce">
307 <?php do_action( 'woocommerce_account_orders_endpoint', $page ); ?>
308 </div>
309 <?php }
310
311 function wpcom_account_tabs_downloads() { ?>
312 <div class="woocommerce">
313 <?php do_action( 'woocommerce_account_downloads_endpoint' ); ?>
314 </div>
315 <?php }
316
317 function wpcom_account_tabs_address() { ?>
318 <div class="woocommerce">
319 <?php do_action( 'woocommerce_account_edit-address_endpoint', 'billing' ); ?>
320 </div>
321 <?php }
322
323 function wpcom_account_tabs_view_order() {
324 $order_id = get_query_var('pageid') ? get_query_var('pageid') : 0; ?>
325 <div class="woocommerce">
326 <?php woocommerce_order_details_table($order_id); ?>
327 </div>
328 <?php }
329
330 add_filter( 'woocommerce_get_myaccount_page_permalink', 'wpcom_woo_myaccount_page_permalink' );
331 function wpcom_woo_myaccount_page_permalink( $link ){
332 global $wpmx_options;
333 if( isset($wpmx_options['member_page_account']) && $wpmx_options['member_page_account'] ) {
334 return wpcom_account_url();
335 }
336 return $link;
337 }
338
339 add_filter('wpcom_settings', 'wpmx_add_theme_options', 20);
340 function wpmx_add_theme_options($options){
341 $addto = '&#xe7fd;';
342 if(defined('WPCOM_MP_VERSION')) {
343 $options = array_merge($options, array(
344 array(
345 'addto' => $addto,
346 'options' => array(
347 array(
348 't' => 'a',
349 'style' => 'success',
350 's' => '<div style="text-align:center;padding: 20px;font-size: 15px;">您已启用<b>用户中心高级版</b>插件,用户中心相�
351 �设置请进�
352 �后台<a href="admin.php?page=wpcom-member-pro">用户中心</a>下面操作。</div>'
353 )
354 )
355 )
356 ));
357 }else{
358 $_options = wpmx_admin_options();
359 $options = array_merge($options, array(
360 array(
361 'addto' => $addto,
362 'options' => $_options
363 )
364 ));
365 }
366
367 return $options;
368 }
369
370 add_filter('wpcom-member-pro_settings', 'wpmx_add_pro_options', 20);
371 function wpmx_add_pro_options($options){
372 $_options = wpmx_admin_options();
373 $options = array_merge($options, array(
374 array(
375 'title' => '常规设置',
376 'icon' => 'settings',
377 'index' => 0,
378 'options' => $_options
379 )
380 ));
381 if(!function_exists('wpcom_setup')){
382 $options = array_merge($options, array(
383 array(
384 'title' => '风格样式',
385 'icon' => 'style',
386 'options' => array(
387 array(
388 'name' => 'member_color',
389 'title' => '主色调',
390 'desc' => '网站主色调,比如链接颜色',
391 'type' => 'c'
392 ),
393 array(
394 'name' => 'member_hover_color',
395 'title' => '悬停颜色',
396 'desc' => '比图链接悬停颜色',
397 'type' => 'c'
398 )
399 )
400 )
401 ));
402 }
403 return $options;
404 }
405
406 add_filter('wpcom-member_form_options', 'wpmx_add_form_options', 5);
407 function wpmx_add_form_options($options){
408 if(defined('WPCOM_MP_VERSION') || function_exists('wpcom_setup')) return $options;
409 $_options = wpmx_admin_options();
410 $options = array(
411 array(
412 'title' => '常规设置',
413 'icon' => 'settings',
414 'options' => $_options
415 ),
416 array(
417 'title' => '风格样式',
418 'icon' => 'style',
419 'options' => array(
420 array(
421 'name' => 'member_color',
422 'title' => '主色调',
423 'desc' => '网站主色调,比如链接颜色',
424 'type' => 'c'
425 ),
426 array(
427 'name' => 'member_hover_color',
428 'title' => '悬停颜色',
429 'desc' => '比图链接悬停颜色',
430 'type' => 'c'
431 )
432 )
433 )
434 );
435 return $options;
436 }
437 function wpmx_admin_options(){
438 $type = apply_filters( 'wpcom_member_show_profile', true );
439 $options = array(
440 array(
441 'title' => '常规设置',
442 'desc' => '用户中心常规功能设置',
443 'type' => 'tt'
444 )
445 );
446 $options = array_merge($options, array(
447 array(
448 'name' => 'member_avatar',
449 'title' => '默认头像',
450 'desc' => '用户默认头像,不设置则默认头像为wordpress系统默认头像。建议图片比例 1:1,例如 300 * 300 px',
451 'type' => 'at'
452 )
453 ));
454 if($type){
455 $options = array_merge($options, array(
456 array(
457 'name' => 'member_cover',
458 'title' => '默认封面',
459 'desc' => '用户个人中心/资料卡默认封面图片,建议图片比例:2.7:1,例如 810*300 px',
460 'type' => 'u'
461 ),
462 array(
463 'name' => 'member_user_slug',
464 'title' => '用户链接',
465 'desc' => '个人中心页面链接地址格式',
466 'std' => '2',
467 'type' => 'r',
468 'ux' => 1,
469 'options' => array(
470 '1' => '用户名',
471 '2' => '用户ID'
472 )
473 )
474 ));
475 }
476
477 $options = array_merge($options, array(
478 array(
479 'name' => '_member_page',
480 'title' => '页面设置',
481 'desc' => '用户中心常用页面设置',
482 'type' => 'tt'
483 ),
484 array(
485 'name' => 'member_page_register',
486 'title' => '注册页面',
487 'desc' => '需要新建一个页面,并添加短代码<b>[wpcom-member type="form" action="register"]</b>',
488 'type' => 'p'
489 ),
490 array(
491 'name' => 'member_page_login',
492 'title' => '登录页面',
493 'desc' => '需要新建一个页面,并添加短代码<b>[wpcom-member type="form" action="login"]</b>',
494 'type' => 'p'
495 ),
496 array(
497 'name' => 'member_page_lostpassword',
498 'title' => '重置密码',
499 'desc' => '需要新建一个页面,并添加短代码<b>[wpcom-member type="lostpassword"]</b>',
500 'type' => 'p'
501 ),
502 array(
503 'name' => 'member_page_account',
504 'title' => '账号设置页面',
505 'desc' => '需要新建一个页面,并添加短代码<b>[wpcom-member type="account"]</b>',
506 'type' => 'p'
507 )
508 ));
509 if($type){
510 $options = array_merge($options, array(
511 array(
512 'name' => 'member_page_profile',
513 'title' => '个人中心页面',
514 'desc' => '需要新建一个页面,并添加短代码<b>[wpcom-member type="profile"]</b>',
515 'type' => 'p'
516 )
517 ));
518 }
519 $options = array_merge($options, array(
520 array(
521 'name' => 'member_page_terms',
522 'title' => '服务条款页面',
523 'desc' => '此页面可添加网站注册时的服务条款,可选',
524 'type' => 'p'
525 ),
526 array(
527 'title' => '注册登录选项',
528 'desc' => '用户注册登录相�
529 �设置选项',
530 'type' => 'tt'
531 ),
532 array(
533 'name' => 'login_logo',
534 'title' => '注册登录页LOGO',
535 'desc' => '可选,不设置则使用网站LOGO',
536 'type' => 'at'
537 ),
538 array(
539 'name' => 'login_modal',
540 'title' => '注册登录弹框',
541 'desc' => '开启后点击注册登录会以弹窗方式弹出',
542 'type' => 't'
543 ),
544 array(
545 'name' => 'member_reg_active',
546 'title' => '注册验证',
547 'desc' => '注册后的验证方式,主要针对邮箱,手机注册默认会有验证码进行验证',
548 'type' => 'r',
549 'ux' => 1,
550 'options' => array(
551 '0' => '无需验证',
552 '1' => '邮件激活验证',
553 '2' => '后台管理员审核'
554 )
555 ),
556 array(
557 'name' => 'member_reg_notice',
558 'title' => '验证提示文字',
559 'desc' => '如果选择了注册验证,则会显示这个选项设置的提示文字',
560 'std' => '感谢注册我们的网站。我们已经给你发送了一封激活邮件,你需要点击邮件中的激活链接来激活你的账号,激活完成后即可正常登录使用。',
561 'type' => 'ta',
562 'r' => 5
563 ),
564 array(
565 'name' => 'member_fill_login',
566 'title' => is_wpcom_enable_phone() ? '补�
567
568 手机号码' : '补�
569
570 电子邮箱',
571 'desc' => '针对社交登录注册及历史用户缺少手机号或�
572 邮箱信息时限制�
573 容发布,例如评论、投稿',
574 'type' => 't'
575 ),
576 array(
577 'name' => 'member_captcha',
578 'title' => '人机验证方式',
579 'desc' => '注册登录等表单人机验证方式',
580 'type' => 's',
581 'std' => '0',
582 'options' => array(
583 '' => '不开启人机验证',
584 '9' => 'WPCOM�
585 置人机验证 - �
586 �费',
587 '0' => '�
588 �讯云验证码',
589 '1' => '阿里云验证码1.0',
590 '2' => 'hCaptcha(适合海外站点,中国大陆地区可使用)',
591 '3' => 'Google reCAPTCHA v2(适合海外站点,中国大陆地区无法使用)',
592 '4' => '阿里云验证码2.0',
593 )
594 ),
595 array(
596 'type' => 'w',
597 'sub' => 1,
598 'filter' => 'member_captcha:0',
599 'options' => array(
600 array(
601 'title' => '�
602 �讯云验证码',
603 'type' => 'tt'
604 ),
605 array(
606 'name' => 'tc_appid',
607 'title' => 'App ID',
608 'desc' => '申请地址:<a href="https://console.cloud.tencent.com/captcha/graphical" target="_blank">点击此处进�
609 �</a>'
610 ),
611 array(
612 'name' => 'tc_appkey',
613 'title' => 'App Secret Key',
614 'desc' => '申请地址:<a href="https://console.cloud.tencent.com/captcha/graphical" target="_blank">点击此处进�
615 �</a>'
616 )
617 )
618 ),
619 array(
620 'type' => 'w',
621 'sub' => 1,
622 'filter' => 'member_captcha:1',
623 'options' => array(
624 array(
625 'title' => '阿里云验证码1.0',
626 'type' => 'tt'
627 ),
628 array(
629 'name' => 'nc_appkey',
630 'title' => 'appkey',
631 'desc' => '不填写则不开启,获取方法:进�
632 �阿里云后台【产品与服务-安�
633 �-验证码】�
634 �置管理列表,获取appkey一栏的数据'
635 ),
636 array(
637 'name' => 'nc_access_id',
638 'title' => 'AccessKey ID',
639 'desc' => '获取方法:阿里云后台右上角鼠标移到头像上,再点击<b>AccessKey 管理</b>进�
640 �获取'
641 ),
642 array(
643 'name' => 'nc_access_secret',
644 'title' => 'AccessKey Secret',
645 'desc' => '获取方法:阿里云后台右上角鼠标移到头像上,再点击<b>AccessKey 管理</b>进�
646 �获取'
647 )
648 )
649 ),
650 array(
651 'type' => 'w',
652 'sub' => 1,
653 'filter' => 'member_captcha:4',
654 'options' => array(
655 array(
656 'title' => '阿里云验证码2.0',
657 'type' => 'tt'
658 ),
659 array(
660 'name' => 'alic_prefix',
661 'title' => '身份标',
662 'desc' => '不填写则不开启,获取方法:进�
663 �阿里云后台【产品与服务-安�
664 �-验证码-概览】页面右侧“身份标”获取'
665 ),
666 array(
667 'name' => 'alic_sceneId',
668 'title' => '场景ID',
669 'desc' => '不填写则不开启,获取方法:进�
670 �阿里云后台【产品与服务-安�
671 �-验证码-场景管理】列表获取,如果没有则新建场景'
672 ),
673 array(
674 'name' => 'alic_access_id',
675 'title' => 'AccessKey ID',
676 'desc' => '获取方法:阿里云后台右上角鼠标移到头像上,再点击<b>AccessKey 管理</b>进�
677 �获取'
678 ),
679 array(
680 'name' => 'alic_access_secret',
681 'title' => 'AccessKey Secret',
682 'desc' => '获取方法:阿里云后台右上角鼠标移到头像上,再点击<b>AccessKey 管理</b>进�
683 �获取'
684 )
685 )
686 ),
687 array(
688 'type' => 'w',
689 'sub' => 1,
690 'filter' => 'member_captcha:2',
691 'options' => array(
692 array(
693 'title' => 'hCaptcha',
694 'type' => 'tt'
695 ),
696 array(
697 'name' => 'hc_sitekey',
698 'title' => 'Sitekey',
699 'desc' => '接口请进�
700 �<a href="https://hcaptcha.com/?r=297b29f2b398" target="_blank">hCaptcha官网</a>申请'
701 ),
702 array(
703 'name' => 'hc_secret',
704 'title' => 'Secret key',
705 'desc' => '接口请进�
706 �<a href="https://hcaptcha.com/?r=297b29f2b398" target="_blank">hCaptcha官网</a>申请'
707 )
708 )
709 ),
710 array(
711 'type' => 'w',
712 'sub' => 1,
713 'filter' => 'member_captcha:3',
714 'options' => array(
715 array(
716 'title' => 'reCAPTCHA',
717 'type' => 'tt'
718 ),
719 array(
720 'name' => 'gc_sitekey',
721 'title' => 'Sitekey / 网站密钥',
722 'desc' => '接口请进�
723 �<a href="https://developers.google.com/recaptcha" target="_blank">reCAPTCHA官网</a>申请'
724 ),
725 array(
726 'name' => 'gc_secret',
727 'title' => 'Secret key / 密钥',
728 'desc' => '接口请进�
729 �<a href="https://developers.google.com/recaptcha" target="_blank">reCAPTCHA官网</a>申请'
730 )
731 )
732 ),
733 array(
734 'name' => 'login_redirect',
735 'title' => '登录后跳转',
736 'desc' => '用户登录后跳转页面的链接地址,留空则默认跳转到上一页,如果没有上一页,则跳转到账号设置页面'
737 ),
738 array(
739 'title' => '社交登录',
740 'desc' => '社交登录接口信息�
741 �置',
742 'type' => 'tt'
743 ),
744 array(
745 'name' => 'social_login_on',
746 'title' => '开启社交登录',
747 'desc' => '是否开启此功能',
748 'std' => 0,
749 'type' => 't'
750 ),
751 array(
752 'type' => 'w',
753 'filter' => 'social_login_on:1',
754 'options' => array(
755 array(
756 'name' => 'social_login_page',
757 'title' => '社交绑定页面',
758 'desc' => '需要新建一个页面,并添加短代码<b>[wpcom-social-login]</b>',
759 'type' => 'p'
760 ),
761 array(
762 'type' => 'rp',
763 'title' => '登录方式',
764 'name' => '_social_login',
765 'options' => array(
766 array(
767 'name' => 'sl_type',
768 'title' => '登录方式',
769 'type' => 's',
770 'options' => array(
771 'qq' => '�
772 �讯QQ',
773 'weibo' => '新浪微博',
774 'wechat' => '微信开放平台',
775 'wechat2' => '微信�
776 �众号平台',
777 'weapp' => '微信小程序(依赖JustWeapp小程序)',
778 'google' => 'Google',
779 'facebook' => 'Facebook',
780 'twitter' => 'Twitter',
781 'github' => 'Github',
782 )
783 ),
784 array(
785 'name' => 'sl_id',
786 'title' => 'ID',
787 'desc' => 'APP ID、Client ID等,微博则填写App Key'
788 ),
789 array(
790 'name' => 'sl_key',
791 'title' => 'Key',
792 'desc' => 'APP Key、 Secret KEY、App Secret等'
793 ),
794 array(
795 'name' => 'sl_weapp_type',
796 'filter' => 'sl_type:weapp',
797 'title' => '国�
798 非个人主体',
799 'type' => 't',
800 'desc' => '国�
801 非个人主体小程序可获取<b>更好的移动端登录体验</b>,支持手机浏览器唤醒微信登录,当然如果移动端希望使用�
802 �众号接口也可以直接�
803 �闭此选项'
804 )
805 )
806 ),
807 array(
808 'name' => 'social_login_target',
809 'title' => '新窗口打开',
810 'std' => '1',
811 'type' => 't'
812 )
813 )
814 ),
815 array(
816 'title' => '选项设置',
817 'desc' => '部分字段选项的自定义设置',
818 'type' => 'tt'
819 ),
820 array(
821 'name' => 'display_name_length',
822 'title' => '昵称长度',
823 'desc' => '可选,针对昵称设置选项,可以限制昵称长度,默认20个字符,同时为确保昵称的合理性如果昵称长度设置低于4会无效',
824 ),
825 array(
826 'name' => 'description_length',
827 'title' => '个人说明长度',
828 'desc' => '可选,针对个人说明选项,可以限制昵称长度,默认200个字符,如果设置为0可�
829 �闭个人说明选项',
830 ),
831 array(
832 'name' => 'member_desc',
833 'title' => '默认个人说明',
834 'std' => '这个人很懒,什么都没有留下~'
835 ),
836 ));
837 if($type){
838 $options = array_merge($options, array(
839 array(
840 'name' => 'url_label',
841 'title' => '网址选项标题',
842 'desc' => '可选,留空则不开启选项,填写后会在<b>账号设置-基本资料</b>里面增加此选项,可用于文章评论用户昵称链接展示,适用于博客类网站使用',
843 )
844 ));
845 }
846 return apply_filters('wpmx_admin_options', $options);
847 }
848
849 function wpmx_allowed_html(){
850 require_once WPCOM_ADMIN_FREE_PATH . 'includes/class-utils.php';
851 $utils_class = class_exists(Plugin\Utils_Free::class) ? Plugin\Utils_Free::class : \WPCOM_ADMIN_UTILS_FREE::class;
852 return $utils_class::allowed_html();
853 }
854
855 function wpcom_wxmp_token($appid, $appsecret) {
856 $wxmp_token = is_multisite() ? get_network_option( 1, 'wxmp_token' ) : get_option('wxmp_token');
857 if($wxmp_token && isset($wxmp_token['access_token']) && $wxmp_token['access_token'] && $wxmp_token['appid'] === $appid && $wxmp_token['expires_in'] > time()+60){
858 return $wxmp_token['access_token'];
859 }else{
860 $access_token = apply_filters('wpcom_wxmp_token', '', $appid, $appsecret);
861 if($access_token && isset($access_token['access_token'])) {
862 $res = $access_token;
863 }else{
864 $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$appsecret;
865 $result = wp_remote_request($url, array('method' => 'get'));
866 if(is_array($result)){
867 $res = $result['body'];
868 $res = json_decode($res, true);
869 }
870 }
871
872 if(isset($res) && isset($res['access_token'])){
873 $res['appid'] = $appid;
874 $res['expires_in'] = time() + $res['expires_in'];
875 if(is_multisite()){
876 update_network_option( 1, 'wxmp_token', $res );
877 }else{
878 update_option('wxmp_token', $res);
879 }
880 return $res['access_token'];
881 }
882 return '';
883 }
884 }
885
886 function wpcom_back_home(){
887 if( function_exists('wpcom_setup') ){ ?>
888 <a href="<?php bloginfo('url'); ?>" class="wpcom-btn btn-primary btn-home"><?php wpmx_icon('home-fill'); _e('Go back to home', 'wpcom');?></a>
889 <?php }
890 }
891
892 function wpcom_need_fill_login($user_id){
893 $options = $GLOBALS['wpmx_options'];
894 if($user_id && isset($options['member_fill_login']) && $options['member_fill_login'] == 1 && !user_can($user_id, 'publish_posts')){
895 // 当前登录用户不是被判断的用户,比如管理员、编辑后台选择作�
896
897 if((int)get_current_user_id() !== (int)$user_id && current_user_can('edit_others_posts')){
898 return false;
899 }
900
901 $user = get_user_by('id', $user_id);
902 if($user && isset($user->ID) && $user->ID){
903 if(is_wpcom_enable_phone()){
904 $login = $user->mobile_phone;
905 }else{
906 $login = $user->user_email && !wpcom_is_empty_mail($user->user_email) ? $user->user_email : '';
907 }
908 if(!$login || trim($login) === '') return true;
909 }
910 }
911 return false;
912 }
913
914 function wpmx_image( $img, $alt = '', $class = '', $width = '', $height = '' ){
915 $class_html = $class ? ' class="' . $class . '"' : '';
916 $size = $width ? ' width="' . intval($width) . '"' : '';
917 $size .= $height ? ' height="' . intval($height) . '"' : '';
918 $size .= ' decoding="async"';
919
920 if(!function_exists('wpcom_get_img_lazyload') || wpcom_get_img_lazyload() == 1) $size .= ' loading="lazy"';
921 if(!preg_match('/^data:image\//i', $img) && class_exists('WPCOM') && method_exists('WPCOM', 'get_webp_url')) {
922 $webp = WPCOM::get_webp_url($img);
923 $img = esc_url($webp ?: $img);
924 }
925 $html = '<img' . $class_html . ' src="' . $img . '" alt="' . esc_attr($alt) . '"' . $size . '>';
926
927 return $html;
928 }
929
930 add_filter('eztoc_do_shortcode', function($isEligible){
931 if(wp_doing_ajax()) $isEligible = false;
932 return $isEligible;
933 });
934
935 add_filter('ez_toc_maybe_apply_the_content_filter', function($apply){
936 if($apply && ( is_wpcom_member_page('account') || is_wpcom_member_page('profile') ) ){
937 $apply = false;
938 }
939 return $apply;
940 });
941
942 add_filter('wpcom_page_can_cache', function($cache){
943 if($cache && (is_wpcom_member_page('login') || is_wpcom_member_page('register') || is_wpcom_member_page('lostpassword') || is_wpcom_member_page('social_login'))){
944 $cache = false;
945 }
946 return $cache;
947 });
948
949 add_action('wpcom_delete_post_cache', function($post_id){
950 $post = get_post($post_id);
951 if($post && isset($post->ID) && $post->post_author){
952 $author_url = get_author_posts_url($post->post_author);
953 if($author_url) wpcom_delete_cache_by_url($author_url);
954 }
955 });
956
957 add_filter('get_comment_author_url', function($comment_author_url, $comment_id, $comment){
958 if( $comment->user_id && $userdata = get_userdata( $comment->user_id )){
959 $options = $GLOBALS['wpmx_options'];
960 $url_label = isset($options['url_label']) && trim($options['url_label']) !== '' ? sanitize_text_field(trim($options['url_label'])) : '';
961
962 $comment_author_url = $url_label !== '' ? sanitize_url($userdata->user_url) : '';
963
964 if($comment_author_url === ''){
965 $comment_author_url = get_author_posts_url( $comment->user_id );
966 }
967 }
968 return $comment_author_url;
969 }, 20, 3);